const e=(e,t,n=globalThis)=>{const r=Symbol.for(e),s=r in n;return[s?n[r]:Object.defineProperty(n,r,{value:t})[r],s]};Promise.withResolvers||(Promise.withResolvers=function(){var e,t,n=new this((function(n,r){e=n,t=r}));return{resolve:e,reject:t,promise:n}});const t=(e,t=document)=>[...t.querySelectorAll(e)],n=(e,t=document)=>{const n=(new XPathEvaluator).createExpression(e).evaluate(t,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE),r=[];for(let e=0,{snapshotLength:t}=n;e"function"==typeof e,o={get:(e,t)=>r.hasOwnProperty(t)?((e,t,{get:n,value:r})=>n||!s(r)?e.then((e=>e[t])):(...n)=>e.then((e=>e[t](...n))))(e,t,r[t]):((e,t)=>s(t)?t.bind(e):t)(e,e[t])};var a=(e,...t)=>new Proxy(fetch(e,...t),o);const i="object"==typeof self?self:globalThis,l=e=>((e,t)=>{const n=(t,n)=>(e.set(n,t),t),r=s=>{if(e.has(s))return e.get(s);const[o,a]=t[s];switch(o){case 0:case-1:return n(a,s);case 1:{const e=n([],s);for(const t of a)e.push(r(t));return e}case 2:{const e=n({},s);for(const[t,n]of a)e[r(t)]=r(n);return e}case 3:return n(new Date(a),s);case 4:{const{source:e,flags:t}=a;return n(new RegExp(e,t),s)}case 5:{const e=n(new Map,s);for(const[t,n]of a)e.set(r(t),r(n));return e}case 6:{const e=n(new Set,s);for(const t of a)e.add(r(t));return e}case 7:{const{name:e,message:t}=a;return n(new i[e](t),s)}case 8:return n(BigInt(a),s);case"BigInt":return n(Object(BigInt(a)),s)}return n(new i[o](a),s)};return r})(new Map,e)(0),c="",{toString:p}={},{keys:f}=Object,u=e=>{const t=typeof e;if("object"!==t||!e)return[0,t];const n=p.call(e).slice(8,-1);switch(n){case"Array":return[1,c];case"Object":return[2,c];case"Date":return[3,c];case"RegExp":return[4,c];case"Map":return[5,c];case"Set":return[6,c]}return n.includes("Array")?[1,n]:n.includes("Error")?[7,n]:[2,n]},d=([e,t])=>0===e&&("function"===t||"symbol"===t),h=(e,{json:t,lossy:n}={})=>{const r=[];return((e,t,n,r)=>{const s=(e,t)=>{const s=r.push(e)-1;return n.set(t,s),s},o=r=>{if(n.has(r))return n.get(r);let[a,i]=u(r);switch(a){case 0:{let t=r;switch(i){case"bigint":a=8,t=r.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+i);t=null;break;case"undefined":return s([-1],r)}return s([a,t],r)}case 1:{if(i)return s([i,[...r]],r);const e=[],t=s([a,e],r);for(const t of r)e.push(o(t));return t}case 2:{if(i)switch(i){case"BigInt":return s([i,r.toString()],r);case"Boolean":case"Number":case"String":return s([i,r.valueOf()],r)}if(t&&"toJSON"in r)return o(r.toJSON());const n=[],l=s([a,n],r);for(const t of f(r))!e&&d(u(r[t]))||n.push([o(t),o(r[t])]);return l}case 3:return s([a,r.toISOString()],r);case 4:{const{source:e,flags:t}=r;return s([a,{source:e,flags:t}],r)}case 5:{const t=[],n=s([a,t],r);for(const[n,s]of r)(e||!d(u(n))&&!d(u(s)))&&t.push([o(n),o(s)]);return n}case 6:{const t=[],n=s([a,t],r);for(const n of r)!e&&d(u(n))||t.push(o(n));return n}}const{message:l}=r;return s([a,{name:i,message:l}],r)};return o})(!(t||n),!!t,new Map,r)(e),r},{parse:m,stringify:y}=JSON,g={json:!0,lossy:!0};var _=Object.freeze({__proto__:null,parse:e=>l(m(e)),stringify:e=>y(h(e,g))});const w="64e10b34-2bf7-4616-9668-f99de5aa046e",b="M"+w,v="T"+w,E="array",k="function",j="null",x="number",R="object",A="string",T="symbol",S="undefined",N="apply",O="construct",P="defineProperty",I="deleteProperty",$="get",M="getOwnPropertyDescriptor",F="getPrototypeOf",C="has",W="isExtensible",D="ownKeys",L="preventExtensions",H="set",B="setPrototypeOf",U="delete",{isArray:J}=Array;let{SharedArrayBuffer:q,window:G}=globalThis,{notify:z,wait:Y,waitAsync:V}=Atomics,K=null;V||(V=e=>({value:new Promise((t=>{let n=new Worker("data:application/javascript,onmessage%3D(%7Bdata%3Ab%7D)%3D%3E(Atomics.wait(b%2C0)%2CpostMessage(0))");n.onmessage=t,n.postMessage(e)}))}));try{new q(4)}catch(e){q=ArrayBuffer;const t=new WeakMap;if(G){const e=new Map,{prototype:{postMessage:n}}=Worker,r=t=>{const n=t.data?.[w];if(!J(n)){t.stopImmediatePropagation();const{id:r,sb:s}=n;e.get(r)(s)}};K=function(e,...s){const o=e?.[w];if(J(o)){const[e,n]=o;t.set(n,e),this.addEventListener("message",r)}return n.call(this,e,...s)},V=n=>({value:new Promise((r=>{e.set(t.get(n),r)})).then((r=>{e.delete(t.get(n)),t.delete(n);for(let e=0;e({[w]:{id:e,sb:t}});z=n=>{postMessage(e(t.get(n),n))},addEventListener("message",(e=>{const n=e.data?.[w];if(J(n)){const[e,r]=n;t.set(r,e)}}))}} /*! (c) Andrea Giammarchi - ISC */const{Int32Array:X,Map:Z,Uint16Array:Q}=globalThis,{BYTES_PER_ELEMENT:ee}=X,{BYTES_PER_ELEMENT:te}=Q,ne=new WeakSet,re=new WeakMap,se={value:{then:e=>e()}};let oe=0;const ae=(e,{parse:t=JSON.parse,stringify:n=JSON.stringify,transform:r,interrupt:s}=JSON)=>{if(!re.has(e)){const o=K||e.postMessage,a=(t,...n)=>o.call(e,{[w]:n},{transfer:t}),i=typeof s===k?s:s?.handler,l=s?.delay||42,c=new TextDecoder("utf-16"),p=(e,t)=>e?V(t,0):(i?((e,t,n)=>{for(;"timed-out"===Y(e,0,0,t);)n()})(t,l,i):Y(t,0),se);let f=!1;re.set(e,new Proxy(new Z,{[C]:(e,t)=>"string"==typeof t&&!t.startsWith("_"),[$]:(n,s)=>"then"===s?null:(...n)=>{const o=oe++;let i=new X(new q(2*ee)),l=[];ne.has(n.at(-1)||l)&&ne.delete(l=n.pop()),a(l,o,i,s,r?n.map(r):n);const u=e!==globalThis;let d=0;return f&&u&&(d=setTimeout(console.warn,1e3,`πŸ’€πŸ”’ - Possible deadlock if proxy.${s}(...args) is awaited`)),p(u,i).value.then((()=>{clearTimeout(d);const e=i[1];if(!e)return;const n=te*e;return i=new X(new q(n+n%ee)),a([],o,i),p(u,i).value.then((()=>t(c.decode(new Q(i.buffer).slice(0,e)))))}))},[H](t,s,o){const a=typeof o;if(a!==k)throw new Error(`Unable to assign ${s} as ${a}`);if(!t.size){const s=new Z;e.addEventListener("message",(async e=>{const o=e.data?.[w];if(J(o)){e.stopImmediatePropagation();const[a,i,...l]=o;let c;if(l.length){const[e,o]=l;if(t.has(e)){f=!0;try{const l=await t.get(e)(...o);if(void 0!==l){const e=n(r?r(l):l);s.set(a,e),i[1]=e.length}}catch(e){c=e}finally{f=!1}}else c=new Error(`Unsupported action: ${e}`);i[0]=1}else{const e=s.get(a);s.delete(a);for(let t=new Q(i.buffer),n=0;n(ne.add(e),e);const{isArray:ie}=Array,le=(e,t)=>t,ce=e=>typeof e===k?(e=>e())(e):e;function pe(){return this}const fe=(e,t)=>e===E?[t]:{t:e,v:t},ue=(e,t=le)=>{let n=typeof e,r=e;return n===R&&(ie(e)?(n=E,r=e.at(0)):({t:n,v:r}=e)),t(n,r)},de=(e,t)=>e===k?t:fe(e,t),he=(e,t=de)=>{const n=null===e?j:typeof e;return t(n===R&&ie(e)?E:n,e)},me=new FinalizationRegistry((([e,t,n])=>{n&&console.debug(`Held value ${String(t)} not relevant anymore`),e(t)})),ye=Object.create(null),ge=(e,t,{debug:n,handler:r,return:s,token:o=e}=ye)=>{const a=s||new Proxy(e,r||ye),i=[a,[t,e,!!n]];return!1!==o&&i.push(o),me.register(...i),a},{defineProperty:_e,deleteProperty:we,getOwnPropertyDescriptor:be,getPrototypeOf:ve,isExtensible:Ee,ownKeys:ke,preventExtensions:je,set:xe,setPrototypeOf:Re}=Reflect,{assign:Ae,create:Te}=Object,Se=ve(Int8Array),Ne=(e,t)=>{const{get:n,set:r,value:s}=e;return n&&(e.get=t(n)),r&&(e.set=t(r)),s&&(e.value=t(s)),e},Oe=e=>t=>he(t,((t,n)=>{switch(t){case j:return fe(j,n);case R:if(n===globalThis)return fe(t,null);case E:case k:return e(t,n);case"boolean":case x:case A:case S:case"bigint":return fe(t,n);case T:{if(Pe.has(n))return fe(t,Pe.get(n));let e=Symbol.keyFor(n);if(e)return fe(t,`.${e}`)}}throw new TypeError(`Unable to handle this ${t}: ${String(n)}`)})),Pe=new Map(ke(Symbol).filter((e=>typeof Symbol[e]===T)).map((e=>[Symbol[e],e]))),Ie=e=>{if(e.startsWith("."))return Symbol.for(e.slice(1));for(const[t,n]of Pe)if(n===e)return t},$e=e=>e;var Me=((e,t)=>{const n=new WeakMap;{const{addEventListener:e}=EventTarget.prototype;_e(EventTarget.prototype,"addEventListener",{value(t,r,...s){return s.at(0)?.invoke&&(n.has(this)||n.set(this,new Map),n.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,r,...s)}})}return function(t,r,s,...o){let a=0,i=this?.transform||$e;const l=new Map,c=new Map,{[s]:p}=t,f=o.length?Ae(Te(globalThis),...o):globalThis,u=Oe(((e,t)=>{if(!l.has(t)){let n;for(;c.has(n=a++););l.set(t,n),c.set(n,e===k?t:i(t))}return fe(e,l.get(t))})),d=e=>{p(U,fe(A,e))},h=(e,t)=>{switch(e){case R:if(null==t)return f;case E:if(typeof t===x)return c.get(t);if(!(t instanceof Se))for(const e in t)t[e]=m(t[e]);return t;case k:if(typeof t===A){const e=c.get(t)?.deref();if(e)return e;const r=function(...e){return e.at(0)instanceof Event&&(e=>{const{currentTarget:t,target:r,type:s}=e;for(const o of n.get(t||r)?.get(s)||[])e[o]()})(...e),p(N,fe(k,t),u(this),e.map(u))};return c.set(t,new WeakRef(r)),ge(t,d,{return:r,token:!1})}return c.get(t);case T:return Ie(t)}return t},m=e=>ue(e,h),y={[N]:(e,t,n)=>u(e.apply(t,n)),[O]:(e,t)=>u(new e(...t)),[P]:(e,t,n)=>u(_e(e,t,n)),[I]:(e,t)=>u(we(e,t)),[F]:e=>u(ve(e)),[$]:(e,t)=>u(e[t]),[M]:(e,t)=>{const n=be(e,t);return n?fe(R,Ne(n,u)):fe(S,n)},[C]:(e,t)=>u(t in e),[W]:e=>u(Ee(e)),[D]:e=>fe(E,ke(e).map(u)),[L]:e=>u(je(e)),[H]:(e,t,n)=>u(xe(e,t,n)),[B]:(e,t)=>u(Re(e,t)),[U](e){l.delete(c.get(e)),c.delete(e)}};return t[r]=(e,t,...n)=>{switch(e){case N:n[0]=m(n[0]),n[1]=n[1].map(m);break;case O:n[0]=n[0].map(m);break;case P:{const[e,t]=n;n[0]=m(e);const{get:r,set:s,value:o}=t;r&&(t.get=m(r)),s&&(t.set=m(s)),o&&(t.value=m(o));break}default:n=n.map(m)}return y[e](m(t),...n)},{proxy:t,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window"),Fe=(e=>{let t=0;const n=new Map,r=new Map,s=Symbol();return function(o,a,i){const l=this?.transform||$e,{[a]:c}=o,p=new Map,f=e=>{p.delete(e),c(U,u(e))},u=Oe(((e,o)=>{if(s in o)return ce(o[s]);if(e===k){if(o=l(o),!r.has(o)){let e;for(;r.has(e=String(t++)););n.set(o,e),r.set(e,o)}return fe(e,n.get(o))}if(!(o instanceof Se)){o=l(o);for(const e in o)o[e]=u(o[e])}return fe(e,o)})),d=(e,t,n)=>{const r=p.get(n)?.deref();if(r)return r;const s=t===k?(e=>pe.bind(e))(e):e,o=new Proxy(s,y);return p.set(n,new WeakRef(o)),ge(n,f,{return:o,token:!1})},h=e=>ue(e,((t,n)=>{switch(t){case R:if(null===n)return globalThis;case E:return typeof n===x?d(e,t,n):n;case k:return typeof n===A?r.get(n):d(e,t,n);case T:return Ie(n)}return n})),m=(e,t,...n)=>h(c(e,ce(t),...n)),y={[N]:(e,t,n)=>m(N,e,u(t),n.map(u)),[O]:(e,t)=>m(O,e,t.map(u)),[P]:(e,t,n)=>{const{get:r,set:s,value:o}=n;return typeof r===k&&(n.get=u(r)),typeof s===k&&(n.set=u(s)),typeof o===k&&(n.value=u(o)),m(P,e,u(t),n)},[I]:(e,t)=>m(I,e,u(t)),[F]:e=>m(F,e),[$]:(e,t)=>t===s?e:m($,e,u(t)),[M]:(e,t)=>{const n=m(M,e,u(t));return n&&Ne(n,h)},[C]:(e,t)=>t===s||m(C,e,u(t)),[W]:e=>m(W,e),[D]:e=>m(D,e).map(h),[L]:e=>m(L,e),[H]:(e,t,n)=>m(H,e,u(t),u(n)),[B]:(e,t)=>m(B,e,u(t))};o[i]=(e,t,s,o)=>{switch(e){case N:return h(t).apply(h(s),o.map(h));case U:{const e=h(t);n.delete(r.get(e)),r.delete(e)}}};const g=new Proxy(fe(R,null),y);return{[e.toLowerCase()]:g,[`is${e}Proxy`]:e=>typeof e===R&&!!e&&s in e,proxy:o}}})("Window"),Ce=typeof Worker===k?Worker:class{};const We=new WeakMap,De=(e,...t)=>{const n=ae(e,...t);if(!We.has(n)){const r=e instanceof Ce?Me:Fe;We.set(n,r.call(t.at(0),n,b,v))}return We.get(n)};De.transfer=ae.transfer;const{url:Le}=import.meta,He=/import\((['"])([^)]+?\.js)\1\)/g,Be=(e,t,n)=>`import(${t}${new URL(n,Le).href}${t})`;const Ue={object(...e){return this.string(function(e){for(var t=e[0],n=1,r=arguments.length;n",">":">","'":"'","'":"'",""":'"',""":'"'},ze=e=>Ge[e],Ye=new WeakMap,Ve=e=>{const t=e||console,n={buffered:Xe,stderr:(t.stderr||console.error).bind(t),stdout:(t.stdout||console.log).bind(t)};return{stderr:(...e)=>n.stderr(...e),stdout:(...e)=>n.stdout(...e),async get(e){const t=await e;return Ye.set(t,n),t}}},Ke=new TextDecoder,Xe=(e,t=10)=>{const n=[];return r=>{if(r instanceof Uint8Array)for(const s of r)s===t?e(Ke.decode(new Uint8Array(n.splice(0)))):n.push(s);else e(r)}},Ze=(e,...t)=>Ue[typeof e](e,...t),Qe=e=>Je.call(e,qe,ze),{isArray:et}=Array,{assign:tt,create:nt,defineProperties:rt,defineProperty:st,entries:ot}=Object,{all:at,resolve:it}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),lt=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href;let ct=0;const pt=(e,t)=>({id:e.id||(e.id=`${t}-w${ct++}`),tag:e.tagName}),ft=(e,t,n,r=!1,s=CustomEvent)=>{e.dispatchEvent(new s(`${t}:${n}`,{bubbles:!0,detail:{worker:r}}))},ut=(e,t,n,r)=>({type:t,config:n,interpreter:r,io:Ye.get(r),run:(t,...n)=>e.run(r,t,...n),runAsync:(t,...n)=>e.runAsync(r,t,...n),runEvent:(...t)=>e.runEvent(r,...t)}),dt=e=>e.replace(/^(?:\n|\r\n)/,""),ht=(e,t,n,r)=>{const s=e[t].bind(e);e[t]="run"===t?(e,t,...o)=>{n&&s(e,n,...o);const a=s(e,dt(t),...o);return r&&s(e,r,...o),a}:async(e,t,...o)=>{n&&await s(e,n,...o);const a=await s(e,dt(t),...o);return r&&await s(e,r,...o),a}},mt=Symbol.for("polyscript.js_modules"),yt=new Map;st(globalThis,mt,{value:yt});const gt=new Proxy(yt,{get:(e,t)=>e.get(t),has:(e,t)=>e.has(t),ownKeys:e=>[...e.keys()]}),_t=(e,t)=>!t.startsWith("_"),wt=(e,t)=>new Proxy(e,{has:_t,get:(e,n)=>e[t][n]}),bt=(e,t,n,r)=>{if("pyodide"===e)return;const s="polyscript.js_modules";for(const e of Reflect.ownKeys(r))t.registerJSModule(n,`${s}.${e}`,wt(r,e));t.registerJSModule(n,s,r)},vt=(e,t)=>import(e).then((e=>{yt.set(t,{...e})})),Et=e=>new Promise(((t,n)=>{document.querySelector(`link[href="${e}"]`)&&t(),document.head.append(tt(document.createElement("link"),{rel:"stylesheet",href:e,onload:t,onerror:n}))})),kt=e=>/\.css/i.test(new URL(e).pathname),jt=!globalThis.window,xt=({FS:e,PATH:t,PATH_FS:n},r,s)=>{const o=n.resolve(r),a=t.dirname(o);return e.mkdirTree?e.mkdirTree(a):At(e,a),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},Rt=e=>{const t=e.split("/");return t.pop(),t.join("/")},At=(e,t)=>{const n=[];for(const r of t.split("/"))"."!==r&&".."!==r&&(n.push(r),r&&e.mkdir(n.join("/")))},Tt=(e,t)=>{const n=[];for(const e of t.split("/"))switch(e){case"":case".":break;case"..":n.pop();break;default:n.push(e)}return[e.cwd()].concat(n).join("/").replace(/^\/+/,"/")},St=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Nt=(e,t)=>a(lt(t,Ot.get(e))).arrayBuffer(),Ot=new WeakMap,Pt=(e,t,n)=>at((e=>{for(const{files:t,to_file:n,from:r=""}of e){if(void 0!==t&&void 0!==n)throw new Error("Cannot use 'to_file' and 'files' parameters together!");if(void 0===t&&void 0===n&&r.endsWith("/"))throw new Error(`Couldn't determine the filename from the path ${r}, please supply 'to_file' parameter.`)}return e.flatMap((({from:e="",to_folder:t=".",to_file:n,files:r})=>{if(et(r))return r.map((n=>({url:St([e,n]),path:St([t,n])})));const s=n||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:St([t,s])}]}))})(n).map((({url:r,path:s})=>Nt(n,r).then((n=>e.writeFile(t,s,n)))))),It=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,$t=(e,t)=>e.replace(/\{.+?\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),Mt=(e,t,n)=>at((e=>{const t=new Map,n=new Set,r=[];for(const[s,o]of ot(e))if(/^\{.+\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,$t(o,t))}else{const e=$t(s,t),a=It(e,$t(o||"./",t));if(n.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);n.add(a),r.push({url:e,path:a})}return r})(n).map((({url:r,path:s})=>Nt(n,r).then((n=>e.writeFile(t,s,n,r)))))),Ft=({main:e,worker:t})=>{const n=[];if(t&&jt)for(let[e,r]of ot(t))e=lt(e,Ot.get(t)),n.push(vt(e,r));if(e&&!jt)for(let[t,r]of ot(e))t=lt(t,Ot.get(e)),kt(t)?Et(t):n.push(vt(t,r));return at(n)},Ct=new WeakMap,Wt=(e,t,n)=>{"polyscript"===t&&(n.lazy_py_modules=async(...t)=>(await Ct.get(e)(t),t.map((t=>e.pyimport(t))))),e.registerJsModule(t,n)},Dt=(e,t)=>{if(e.endsWith("/*")){if(/\.(zip|tar(?:\.gz)?)$/.test(t))return RegExp.$1;throw new Error(`Unsupported archive ${t}`)}return""},Lt=(e,t,...n)=>{try{return e.runPython(Ze(t),...n)}catch(t){Ye.get(e).stderr(t)}},Ht=async(e,t,...n)=>{try{return await e.runPythonAsync(Ze(t),...n)}catch(t){Ye.get(e).stderr(t)}},Bt=async(e,t,n)=>{const[r,...s]=t.split(".");let o,a=e.globals.get(r);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,n)}catch(t){Ye.get(e).stderr(t)}};var Ut=(new TextEncoder).encode('from uio import StringIO\nimport sys\n\nclass Response:\n def __init__(self, f):\n self.raw = f\n self.encoding = "utf-8"\n self._cached = None\n\n def close(self):\n if self.raw:\n self.raw.close()\n self.raw = None\n self._cached = None\n\n @property\n def content(self):\n if self._cached is None:\n try:\n self._cached = self.raw.read()\n finally:\n self.raw.close()\n self.raw = None\n return self._cached\n\n @property\n def text(self):\n return str(self.content, self.encoding)\n\n def json(self):\n import ujson\n\n return ujson.loads(self.content)\n\n\n# TODO try to support streaming xhr requests, a-la pyodide-http\nHEADERS_TO_IGNORE = ("user-agent",)\n\n\ntry:\n import js\nexcept Exception as err:\n raise OSError("This version of urequests can only be used in the browser")\n\n# TODO try to support streaming xhr requests, a-la pyodide-http\n\nHEADERS_TO_IGNORE = ("user-agent",)\n\n\ndef request(\n method,\n url,\n data=None,\n json=None,\n headers={},\n stream=None,\n auth=None,\n timeout=None,\n parse_headers=True,\n):\n from js import XMLHttpRequest\n\n xhr = XMLHttpRequest.new()\n xhr.withCredentials = False\n\n if auth is not None:\n import ubinascii\n\n username, password = auth\n xhr.open(method, url, False, username, password)\n else:\n xhr.open(method, url, False)\n\n for name, value in headers.items():\n if name.lower() not in HEADERS_TO_IGNORE:\n xhr.setRequestHeader(name, value)\n\n if timeout:\n xhr.timeout = int(timeout * 1000)\n\n if json is not None:\n assert data is None\n import ujson\n\n data = ujson.dumps(json)\n # s.write(b"Content-Type: application/json\\r\\n")\n xhr.setRequestHeader("Content-Type", "application/json")\n\n xhr.send(data)\n\n # Emulates the construction process in the original urequests\n resp = Response(StringIO(xhr.responseText))\n resp.status_code = xhr.status\n resp.reason = xhr.statusText\n resp.headers = xhr.getAllResponseHeaders()\n\n return resp\n\n\n# Other methods - head, post, put, patch, delete - are not used by\n# mip and therefore not included\n\n\ndef get(url, **kw):\n return request("GET", url, **kw)\n\n\n# Content below this line is from the Micropython MIP package and is covered\n# by the applicable MIT license:\n# \n# THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, \n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER \n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING \n# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \n# DEALINGS IN THE SOFTWARE.\n\n# MicroPython package installer\n# MIT license; Copyright (c) 2022 Jim Mussared\n\n\n_PACKAGE_INDEX = const("https://micropython.org/pi/v2")\n_CHUNK_SIZE = 128\n\n\n# This implements os.makedirs(os.dirname(path))\ndef _ensure_path_exists(path):\n import os\n\n split = path.split("/")\n\n # Handle paths starting with "/".\n if not split[0]:\n split.pop(0)\n split[0] = "/" + split[0]\n\n prefix = ""\n for i in range(len(split) - 1):\n prefix += split[i]\n try:\n os.stat(prefix)\n except:\n os.mkdir(prefix)\n prefix += "/"\n\n\n# Copy from src (stream) to dest (function-taking-bytes)\ndef _chunk(src, dest):\n buf = memoryview(bytearray(_CHUNK_SIZE))\n while True:\n n = src.readinto(buf)\n if n == 0:\n break\n dest(buf if n == _CHUNK_SIZE else buf[:n])\n\n\n# Check if the specified path exists and matches the hash.\ndef _check_exists(path, short_hash):\n import os\n\n try:\n import binascii\n import hashlib\n\n with open(path, "rb") as f:\n hs256 = hashlib.sha256()\n _chunk(f, hs256.update)\n existing_hash = str(binascii.hexlify(hs256.digest())[: len(short_hash)], "utf-8")\n return existing_hash == short_hash\n except:\n return False\n\n\ndef _rewrite_url(url, branch=None):\n if not branch:\n branch = "HEAD"\n if url.startswith("github:"):\n url = url[7:].split("/")\n url = (\n "https://raw.githubusercontent.com/"\n + url[0]\n + "/"\n + url[1]\n + "/"\n + branch\n + "/"\n + "/".join(url[2:])\n )\n return url\n\n\ndef _download_file(url, dest):\n response = get(url)\n try:\n if response.status_code != 200:\n print("Error", response.status_code, "requesting", url)\n return False\n\n print("Copying:", dest)\n _ensure_path_exists(dest)\n with open(dest, "wb") as f:\n _chunk(response.raw, f.write)\n\n return True\n finally:\n response.close()\n\n\ndef _install_json(package_json_url, index, target, version, mpy):\n response = get(_rewrite_url(package_json_url, version))\n try:\n if response.status_code != 200:\n print("Package not found:", package_json_url)\n return False\n\n package_json = response.json()\n finally:\n response.close()\n for target_path, short_hash in package_json.get("hashes", ()):\n fs_target_path = target + "/" + target_path\n if _check_exists(fs_target_path, short_hash):\n print("Exists:", fs_target_path)\n else:\n file_url = "{}/file/{}/{}".format(index, short_hash[:2], short_hash)\n if not _download_file(file_url, fs_target_path):\n print("File not found: {} {}".format(target_path, short_hash))\n return False\n for target_path, url in package_json.get("urls", ()):\n fs_target_path = target + "/" + target_path\n if not _download_file(_rewrite_url(url, version), fs_target_path):\n print("File not found: {} {}".format(target_path, url))\n return False\n for dep, dep_version in package_json.get("deps", ()):\n if not _install_package(dep, index, target, dep_version, mpy):\n return False\n return True\n\n\ndef _install_package(package, index, target, version, mpy):\n if (\n package.startswith("http://")\n or package.startswith("https://")\n or package.startswith("github:")\n ):\n if package.endswith(".py") or package.endswith(".mpy"):\n print("Downloading {} to {}".format(package, target))\n return _download_file(\n _rewrite_url(package, version), target + "/" + package.rsplit("/")[-1]\n )\n else:\n if not package.endswith(".json"):\n if not package.endswith("/"):\n package += "/"\n package += "package.json"\n print("Installing {} to {}".format(package, target))\n else:\n if not version:\n version = "latest"\n print("Installing {} ({}) from {} to {}".format(package, version, index, target))\n\n mpy_version = (\n sys.implementation._mpy & 0xFF if mpy and hasattr(sys.implementation, "_mpy") else "py"\n )\n\n package = "{}/package/{}/{}/{}.json".format(index, mpy_version, package, version)\n\n return _install_json(package, index, target, version, mpy)\n\n\ndef install(package, index=None, target=None, version=None, mpy=True):\n if not target:\n for p in sys.path:\n if p.endswith("/lib"):\n target = p\n break\n else:\n print("Unable to find lib dir in sys.path")\n return\n\n if not index:\n index = _PACKAGE_INDEX\n\n if _install_package(package, index.rstrip("/"), target, version, mpy):\n print("Done")\n else:\n print("Package may be partially installed")\n');const Jt=(e,t)=>{try{e.mkdir(t)}catch(e){}};var qt={type:"micropython",module:(e="1.22.0-356")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,n){const{stderr:r,stdout:s,get:o}=Ve({stderr:Xe(console.error),stdout:Xe(console.log)});n=n.replace(/\.m?js$/,".wasm");const a=await o(e({linebuffer:!1,stderr:r,stdout:s,url:n})),i=Gt.bind(a);return Ct.set(a,i),t.files&&await Mt(this,a,t.files),t.fetch&&await Pt(this,a,t.fetch),t.js_modules&&await Ft(t.js_modules),this.writeFile(a,"./mip.py",Ut),t.packages&&await i(t.packages),a},registerJSModule:Wt,run:Lt,runAsync:Ht,runEvent:Bt,transform:(e,t)=>e.PyProxy.toJs(t),writeFile:(e,t,n,r)=>{const{FS:s,_module:{PATH:o,PATH_FS:a}}=e,i={FS:s,PATH:o,PATH_FS:a},l=Dt(t,r);if(l){const r=t.slice(0,-1);switch("./"!==r&&s.mkdir(r),l){case"zip":{const e=new Blob([n],{type:"application/zip"});return import("./zip-D2yvzXKD.js").then((async({BlobReader:t,Uint8ArrayWriter:n,ZipReader:a})=>{const i=new a(new t(e));for(const e of await i.getEntries()){const{directory:t,filename:a}=e,i=r+a;if(t)Jt(s,i);else{Jt(s,o.dirname(i));const t=await e.getData(new n);s.writeFile(i,t,{canOwn:!0})}}i.close()}))}case"tar.gz":{const t="./_.tar.gz";return xt(i,t,n),void e.runPython(`\n import os, gzip, tarfile\n tar = tarfile.TarFile(fileobj=gzip.GzipFile(fileobj=open("${t}", "rb")))\n for f in tar:\n name = f"${r}{f.name}"\n if f.type == tarfile.DIRTYPE:\n if f.name != "./":\n os.mkdir(name.strip("/"))\n else:\n dir = os.path.dirname(name)\n if not os.path.exists(dir):\n os.mkdir(dir)\n source = tar.extractfile(f)\n with open(name, "wb") as dest:\n dest.write(source.read())\n dest.close()\n tar.close()\n os.remove("${t}")\n `)}}}return xt(i,t,n)}};async function Gt(e){const t=this.pyimport("mip");for(const n of e)t.install(n)}const zt={dict_converter:Object.fromEntries};let Yt=!1;const Vt=e=>(...t)=>{try{return Yt=!0,e(...t)}finally{Yt=!1}};let Kt=!1;const Xt=()=>{if(Kt)return;Kt=!0;const e=new WeakMap,t=e=>e.destroy(),n=n=>{for(let r=0;r`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,n){jt||"auto"!==t.experimental_create_proxy||Xt();const{stderr:r,stdout:s,get:o}=Ve(),a=n.slice(0,n.lastIndexOf("/")),i=await o(e({stderr:r,stdout:s,indexURL:a})),l=Qt.bind(i);return Ct.set(i,l),t.files&&await Mt(this,i,t.files),t.fetch&&await Pt(this,i,t.fetch),t.js_modules&&await Ft(t.js_modules),t.packages&&await l(t.packages),i},registerJSModule:Wt,run:Vt(Lt),runAsync:Vt(Ht),runEvent:Vt(Bt),transform:({ffi:{PyProxy:e}},t)=>t instanceof e?t.toJs(zt):t,writeFile:(e,t,n,r)=>{const s=Dt(t,r);if(s)return e.unpackArchive(n,s,{extractDir:t.slice(0,-1)});const{FS:o,PATH:a,_module:{PATH_FS:i}}=e;return xt({FS:o,PATH:a,PATH_FS:i},t,n)}};async function Qt(e){await this.loadPackage("micropip");const t=this.pyimport("micropip");await t.install(e,{keep_going:!0}),t.destroy()}const en="ruby-wasm-wasi",tn=en.replace(/\W+/g,"_");var nn={type:en,experimental:!0,module:(e="2.6.0")=>`https://cdn.jsdelivr.net/npm/@ruby/3.2-wasm-wasi@${e}/dist/browser/+esm`,async engine({DefaultRubyVM:e},t,n){n=n.replace(/\/browser\/\+esm$/,"/ruby.wasm");const r=await a(n).arrayBuffer(),s=await WebAssembly.compile(r),{vm:o}=await e(s);return t.files&&await Mt(this,o,t.files),t.fetch&&await Pt(this,o,t.fetch),t.js_modules&&await Ft(t.js_modules),o},registerJSModule(e,t,n){t=t.replace(/\W+/g,"__");const r=`__module_${tn}_${t}`;globalThis[r]=n,this.run(e,`require "js";$${t}=JS.global[:${r}]`),delete globalThis[r]},run:(e,t,...n)=>e.eval(Ze(t),...n),runAsync:(e,t,...n)=>e.evalAsync(Ze(t),...n),async runEvent(e,t,n){if(/^xworker\.(on\w+)$/.test(t)){const{$1:t}=RegExp,r=`__module_${tn}_event`;globalThis[r]=n,this.run(e,`require "js";$xworker.call("${t}",JS.global[:${r}])`),delete globalThis[r]}else{const r=this.run(e,`method(:${t})`);await r.call(t,e.wrap(n))}},transform:(e,t)=>t,writeFile:()=>{throw new Error(`writeFile is not supported in ${en}`)}};var rn={type:"wasmoon",module:(e="1.16.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},n){const{stderr:r,stdout:s,get:o}=Ve(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",r)})),n.files&&await Mt(this,a,n.files),n.fetch&&await Pt(this,a,n.fetch),n.js_modules&&await Ft(n.js_modules),a},registerJSModule:(e,t,n)=>{e.global.set(t,n)},run:(e,t,...n)=>{try{return e.doStringSync(Ze(t),...n)}catch(t){Ye.get(e).stderr(t)}},runAsync:async(e,t,...n)=>{try{return await e.doString(Ze(t),...n)}catch(t){Ye.get(e).stderr(t)}},runEvent:async(e,t,n)=>{const[r,...s]=t.split(".");let o,a=e.global.get(r);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,n)}catch(t){Ye.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,n)=>((e,t,n)=>(At(e,Rt(t)),t=Tt(e,t),e.writeFile(t,new Uint8Array(n),{canOwn:!0})))(e,t,n)};const sn=new WeakMap,on=async(e,t)=>{const{shelter:n,destroy:r,io:s}=sn.get(e),{output:o,result:a}=await n.captureR(Ze(t));for(const{type:e,data:t}of o)s[e](t);return ge(a,r,{token:!1})};var an={type:"webr",experimental:!0,module:(e="0.3.3")=>`https://cdn.jsdelivr.net/npm/webr@${e}/dist/webr.mjs`,async engine(e,t){const{get:n}=Ve(),r=new e.WebR;await n(r.init().then((()=>r)));const s=await new r.Shelter;return sn.set(r,{module:e,shelter:s,destroy:s.destroy.bind(s),io:Ye.get(r)}),t.files&&await Mt(this,r,t.files),t.fetch&&await Pt(this,r,t.fetch),t.js_modules&&await Ft(t.js_modules),r},registerJSModule(e,t){console.warn(`Experimental interpreter: module ${t} is not supported (yet)`)},run:on,runAsync:on,async runEvent(e,t,n){await e.evalRVoid(`${t}(event)`,{env:{event:{type:[n.type]}}})},transform:(e,t)=>(console.log("transforming",t),t),writeFile:()=>{}};const ln=new Map,cn=new Map,pn=[],fn=[],un=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[n,...r]=t.split("@"),s=ln.get(n),o=/^(?:\.?\.?\/|https?:\/\/)/i.test(r)?r.join("@"):s.module(...r);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:n,module:r,engine:s}=e.get(t);return(e,o)=>r.then((r=>{cn.set(t,e);for(const t of["files","fetch"]){const n=e?.[t];n&&Ot.set(n,o)}for(const t of["main","worker"]){const n=e?.js_modules?.[t];n&&Ot.set(n,o)}return s(r,e,n)}))}}),dn=e=>{for(const t of[].concat(e.type))ln.set(t,e),pn.push(`script[type="${t}"]`),fn.push(`${t}-`)};for(const e of[qt,Zt,nn,rn,an])dn(e);const hn=async e=>(await import("./toml-DiUM0_qs.js")).parse(e),mn=(e,t="./config.txt")=>{let n=typeof e;return"string"===n&&/\.(json|toml|txt)$/.test(e)?n=RegExp.$1:e=t,[lt(e),n]},yn=e=>{try{return JSON.parse(e)}catch(t){return hn(e)}},gn=(e,t,n,r={})=>{if(t){const[e,s]=mn(t,n);"json"===s?r=a(e).json():"toml"===s?r=a(e).text().then(hn):"string"===s?r=yn(t):"object"===s&&t?r=t:"txt"===s&&"string"==typeof r&&(r=yn(r)),t=e}return it(r).then((n=>un[e](n,t)))},_n=(e,t="")=>`${e}@${t}`.replace(/@$/,"");function wn(e=this){return String(e).replace(/^(async\s*)?(\bfunction\b)?(.*?)\(/,((e,t,n,r)=>r&&!n?`${t||""}function ${r}(`:e))}const bn="BeforeRun",vn="AfterRun",En=[`code${bn}`,`code${bn}Async`,`code${vn}`,`code${vn}Async`],kn=["onWorker","onReady",`on${bn}`,`on${bn}Async`,`on${vn}`,`on${vn}Async`];function jn(e,t){const{run:n,runAsync:r}=ln.get(this.type);return{...e,run:n.bind(this,t),runAsync:r.bind(this,t)}}const xn=(e,t,n,r,s,o)=>{if(s||o){const a=jn.bind(e,t),i=r?"runAsync":"run",l=e[i];e[i]=r?async function(e,t,...r){s&&await s.call(this,a(e),n);const i=await l.call(this,e,t,...r);return o&&await o.call(this,a(e),n),i}:function(e,t,...r){s&&s.call(this,a(e),n);const i=l.call(this,e,t,...r);return o&&o.call(this,a(e),n),i}}};let Rn=class{constructor(e,t={}){const{main:n,worker:r}=t;this.interpreter=e,this.onWorker=n?.onWorker;for(const e of kn.slice(1))this[e]=r?.[e];for(const e of En)this[e]=r?.[e]}toJSON(){const e={};for(const t of kn.slice(1))this[t]&&(e[t]=wn(this[t]));for(const t of En)this[t]&&(e[t]=Ze(this[t]()));return e}};var An=(...e)=>function(t,n){const r=new Worker(URL.createObjectURL(new Blob(['const e="object"==typeof self?self:globalThis,t=t=>((t,n)=>{const r=(e,n)=>(t.set(n,e),e),s=o=>{if(t.has(o))return t.get(o);const[a,i]=n[o];switch(a){case 0:case-1:return r(i,o);case 1:{const e=r([],o);for(const t of i)e.push(s(t));return e}case 2:{const e=r({},o);for(const[t,n]of i)e[s(t)]=s(n);return e}case 3:return r(new Date(i),o);case 4:{const{source:e,flags:t}=i;return r(new RegExp(e,t),o)}case 5:{const e=r(new Map,o);for(const[t,n]of i)e.set(s(t),s(n));return e}case 6:{const e=r(new Set,o);for(const t of i)e.add(s(t));return e}case 7:{const{name:t,message:n}=i;return r(new e[t](n),o)}case 8:return r(BigInt(i),o);case"BigInt":return r(Object(BigInt(i)),o)}return r(new e[a](i),o)};return s})(new Map,t)(0),n="",{toString:r}={},{keys:s}=Object,o=e=>{const t=typeof e;if("object"!==t||!e)return[0,t];const s=r.call(e).slice(8,-1);switch(s){case"Array":return[1,n];case"Object":return[2,n];case"Date":return[3,n];case"RegExp":return[4,n];case"Map":return[5,n];case"Set":return[6,n]}return s.includes("Array")?[1,s]:s.includes("Error")?[7,s]:[2,s]},a=([e,t])=>0===e&&("function"===t||"symbol"===t),i=(e,{json:t,lossy:n}={})=>{const r=[];return((e,t,n,r)=>{const i=(e,t)=>{const s=r.push(e)-1;return n.set(t,s),s},c=r=>{if(n.has(r))return n.get(r);let[l,p]=o(r);switch(l){case 0:{let t=r;switch(p){case"bigint":l=8,t=r.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+p);t=null;break;case"undefined":return i([-1],r)}return i([l,t],r)}case 1:{if(p)return i([p,[...r]],r);const e=[],t=i([l,e],r);for(const t of r)e.push(c(t));return t}case 2:{if(p)switch(p){case"BigInt":return i([p,r.toString()],r);case"Boolean":case"Number":case"String":return i([p,r.valueOf()],r)}if(t&&"toJSON"in r)return c(r.toJSON());const n=[],u=i([l,n],r);for(const t of s(r))!e&&a(o(r[t]))||n.push([c(t),c(r[t])]);return u}case 3:return i([l,r.toISOString()],r);case 4:{const{source:e,flags:t}=r;return i([l,{source:e,flags:t}],r)}case 5:{const t=[],n=i([l,t],r);for(const[n,s]of r)(e||!a(o(n))&&!a(o(s)))&&t.push([c(n),c(s)]);return n}case 6:{const t=[],n=i([l,t],r);for(const n of r)!e&&a(o(n))||t.push(c(n));return n}}const{message:u}=r;return i([l,{name:p,message:u}],r)};return c})(!(t||n),!!t,new Map,r)(e),r},{parse:c,stringify:l}=JSON,p={json:!0,lossy:!0};var u=Object.freeze({__proto__:null,parse:e=>t(c(e)),stringify:e=>l(i(e,p))});const f="64e10b34-2bf7-4616-9668-f99de5aa046e",d="M"+f,h="T"+f,g="array",y="function",w="null",m="number",_="object",b="string",E="symbol",v="undefined",k="apply",x="construct",T="defineProperty",S="deleteProperty",A="get",j="getOwnPropertyDescriptor",O="getPrototypeOf",R="has",P="isExtensible",$="ownKeys",M="preventExtensions",N="set",I="setPrototypeOf",F="delete",{isArray:W}=Array;let{SharedArrayBuffer:H,window:D}=globalThis,{notify:C,wait:L,waitAsync:U}=Atomics,B=null;U||(U=e=>({value:new Promise((t=>{let n=new Worker("data:application/javascript,onmessage%3D(%7Bdata%3Ab%7D)%3D%3E(Atomics.wait(b%2C0)%2CpostMessage(0))");n.onmessage=t,n.postMessage(e)}))}));try{new H(4)}catch(e){H=ArrayBuffer;const t=new WeakMap;if(D){const e=new Map,{prototype:{postMessage:n}}=Worker,r=t=>{const n=t.data?.[f];if(!W(n)){t.stopImmediatePropagation();const{id:r,sb:s}=n;e.get(r)(s)}};B=function(e,...s){const o=e?.[f];if(W(o)){const[e,n]=o;t.set(n,e),this.addEventListener("message",r)}return n.call(this,e,...s)},U=n=>({value:new Promise((r=>{e.set(t.get(n),r)})).then((r=>{e.delete(t.get(n)),t.delete(n);for(let e=0;e({[f]:{id:e,sb:t}});C=n=>{postMessage(e(t.get(n),n))},addEventListener("message",(e=>{const n=e.data?.[f];if(W(n)){const[e,r]=n;t.set(r,e)}}))}}\n/*! (c) Andrea Giammarchi - ISC */const{Int32Array:J,Map:q,Uint16Array:z}=globalThis,{BYTES_PER_ELEMENT:G}=J,{BYTES_PER_ELEMENT:K}=z,Y=new WeakSet,X=new WeakMap,V={value:{then:e=>e()}};let Z=0;const Q=(e,{parse:t=JSON.parse,stringify:n=JSON.stringify,transform:r,interrupt:s}=JSON)=>{if(!X.has(e)){const o=B||e.postMessage,a=(t,...n)=>o.call(e,{[f]:n},{transfer:t}),i=typeof s===y?s:s?.handler,c=s?.delay||42,l=new TextDecoder("utf-16"),p=(e,t)=>e?U(t,0):(i?((e,t,n)=>{for(;"timed-out"===L(e,0,0,t);)n()})(t,c,i):L(t,0),V);let u=!1;X.set(e,new Proxy(new q,{[R]:(e,t)=>"string"==typeof t&&!t.startsWith("_"),[A]:(n,s)=>"then"===s?null:(...n)=>{const o=Z++;let i=new J(new H(2*G)),c=[];Y.has(n.at(-1)||c)&&Y.delete(c=n.pop()),a(c,o,i,s,r?n.map(r):n);const f=e!==globalThis;let d=0;return u&&f&&(d=setTimeout(console.warn,1e3,`πŸ’€πŸ”’ - Possible deadlock if proxy.${s}(...args) is awaited`)),p(f,i).value.then((()=>{clearTimeout(d);const e=i[1];if(!e)return;const n=K*e;return i=new J(new H(n+n%G)),a([],o,i),p(f,i).value.then((()=>t(l.decode(new z(i.buffer).slice(0,e)))))}))},[N](t,s,o){const a=typeof o;if(a!==y)throw new Error(`Unable to assign ${s} as ${a}`);if(!t.size){const s=new q;e.addEventListener("message",(async e=>{const o=e.data?.[f];if(W(o)){e.stopImmediatePropagation();const[a,i,...c]=o;let l;if(c.length){const[e,o]=c;if(t.has(e)){u=!0;try{const c=await t.get(e)(...o);if(void 0!==c){const e=n(r?r(c):c);s.set(a,e),i[1]=e.length}}catch(e){l=e}finally{u=!1}}else l=new Error(`Unsupported action: ${e}`);i[0]=1}else{const e=s.get(a);s.delete(a);for(let t=new z(i.buffer),n=0;n(Y.add(e),e);const{isArray:ee}=Array,te=(e,t)=>t,ne=e=>typeof e===y?(e=>e())(e):e;function re(){return this}const se=(e,t)=>e===g?[t]:{t:e,v:t},oe=(e,t=te)=>{let n=typeof e,r=e;return n===_&&(ee(e)?(n=g,r=e.at(0)):({t:n,v:r}=e)),t(n,r)},ae=(e,t)=>e===y?t:se(e,t),ie=(e,t=ae)=>{const n=null===e?w:typeof e;return t(n===_&&ee(e)?g:n,e)},ce=new FinalizationRegistry((([e,t,n])=>{n&&console.debug(`Held value ${String(t)} not relevant anymore`),e(t)})),le=Object.create(null),pe=(e,t,{debug:n,handler:r,return:s,token:o=e}=le)=>{const a=s||new Proxy(e,r||le),i=[a,[t,e,!!n]];return!1!==o&&i.push(o),ce.register(...i),a},{defineProperty:ue,deleteProperty:fe,getOwnPropertyDescriptor:de,getPrototypeOf:he,isExtensible:ge,ownKeys:ye,preventExtensions:we,set:me,setPrototypeOf:_e}=Reflect,{assign:be,create:Ee}=Object,ve=he(Int8Array),ke=(e,t)=>{const{get:n,set:r,value:s}=e;return n&&(e.get=t(n)),r&&(e.set=t(r)),s&&(e.value=t(s)),e},xe=e=>t=>ie(t,((t,n)=>{switch(t){case w:return se(w,n);case _:if(n===globalThis)return se(t,null);case g:case y:return e(t,n);case"boolean":case m:case b:case v:case"bigint":return se(t,n);case E:{if(Te.has(n))return se(t,Te.get(n));let e=Symbol.keyFor(n);if(e)return se(t,`.${e}`)}}throw new TypeError(`Unable to handle this ${t}: ${String(n)}`)})),Te=new Map(ye(Symbol).filter((e=>typeof Symbol[e]===E)).map((e=>[Symbol[e],e]))),Se=e=>{if(e.startsWith("."))return Symbol.for(e.slice(1));for(const[t,n]of Te)if(n===e)return t},Ae=e=>e;var je=((e,t)=>{const n=new WeakMap;{const{addEventListener:e}=EventTarget.prototype;ue(EventTarget.prototype,"addEventListener",{value(t,r,...s){return s.at(0)?.invoke&&(n.has(this)||n.set(this,new Map),n.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,r,...s)}})}return function(t,r,s,...o){let a=0,i=this?.transform||Ae;const c=new Map,l=new Map,{[s]:p}=t,u=o.length?be(Ee(globalThis),...o):globalThis,f=xe(((e,t)=>{if(!c.has(t)){let n;for(;l.has(n=a++););c.set(t,n),l.set(n,e===y?t:i(t))}return se(e,c.get(t))})),d=e=>{p(F,se(b,e))},h=(e,t)=>{switch(e){case _:if(null==t)return u;case g:if(typeof t===m)return l.get(t);if(!(t instanceof ve))for(const e in t)t[e]=w(t[e]);return t;case y:if(typeof t===b){const e=l.get(t)?.deref();if(e)return e;const r=function(...e){return e.at(0)instanceof Event&&(e=>{const{currentTarget:t,target:r,type:s}=e;for(const o of n.get(t||r)?.get(s)||[])e[o]()})(...e),p(k,se(y,t),f(this),e.map(f))};return l.set(t,new WeakRef(r)),pe(t,d,{return:r,token:!1})}return l.get(t);case E:return Se(t)}return t},w=e=>oe(e,h),W={[k]:(e,t,n)=>f(e.apply(t,n)),[x]:(e,t)=>f(new e(...t)),[T]:(e,t,n)=>f(ue(e,t,n)),[S]:(e,t)=>f(fe(e,t)),[O]:e=>f(he(e)),[A]:(e,t)=>f(e[t]),[j]:(e,t)=>{const n=de(e,t);return n?se(_,ke(n,f)):se(v,n)},[R]:(e,t)=>f(t in e),[P]:e=>f(ge(e)),[$]:e=>se(g,ye(e).map(f)),[M]:e=>f(we(e)),[N]:(e,t,n)=>f(me(e,t,n)),[I]:(e,t)=>f(_e(e,t)),[F](e){c.delete(l.get(e)),l.delete(e)}};return t[r]=(e,t,...n)=>{switch(e){case k:n[0]=w(n[0]),n[1]=n[1].map(w);break;case x:n[0]=n[0].map(w);break;case T:{const[e,t]=n;n[0]=w(e);const{get:r,set:s,value:o}=t;r&&(t.get=w(r)),s&&(t.set=w(s)),o&&(t.value=w(o));break}default:n=n.map(w)}return W[e](w(t),...n)},{proxy:t,[e.toLowerCase()]:u,[`is${e}Proxy`]:()=>!1}}})("Window"),Oe=(e=>{let t=0;const n=new Map,r=new Map,s=Symbol();return function(o,a,i){const c=this?.transform||Ae,{[a]:l}=o,p=new Map,u=e=>{p.delete(e),l(F,f(e))},f=xe(((e,o)=>{if(s in o)return ne(o[s]);if(e===y){if(o=c(o),!r.has(o)){let e;for(;r.has(e=String(t++)););n.set(o,e),r.set(e,o)}return se(e,n.get(o))}if(!(o instanceof ve)){o=c(o);for(const e in o)o[e]=f(o[e])}return se(e,o)})),d=(e,t,n)=>{const r=p.get(n)?.deref();if(r)return r;const s=t===y?(e=>re.bind(e))(e):e,o=new Proxy(s,v);return p.set(n,new WeakRef(o)),pe(n,u,{return:o,token:!1})},h=e=>oe(e,((t,n)=>{switch(t){case _:if(null===n)return globalThis;case g:return typeof n===m?d(e,t,n):n;case y:return typeof n===b?r.get(n):d(e,t,n);case E:return Se(n)}return n})),w=(e,t,...n)=>h(l(e,ne(t),...n)),v={[k]:(e,t,n)=>w(k,e,f(t),n.map(f)),[x]:(e,t)=>w(x,e,t.map(f)),[T]:(e,t,n)=>{const{get:r,set:s,value:o}=n;return typeof r===y&&(n.get=f(r)),typeof s===y&&(n.set=f(s)),typeof o===y&&(n.value=f(o)),w(T,e,f(t),n)},[S]:(e,t)=>w(S,e,f(t)),[O]:e=>w(O,e),[A]:(e,t)=>t===s?e:w(A,e,f(t)),[j]:(e,t)=>{const n=w(j,e,f(t));return n&&ke(n,h)},[R]:(e,t)=>t===s||w(R,e,f(t)),[P]:e=>w(P,e),[$]:e=>w($,e).map(h),[M]:e=>w(M,e),[N]:(e,t,n)=>w(N,e,f(t),f(n)),[I]:(e,t)=>w(I,e,f(t))};o[i]=(e,t,s,o)=>{switch(e){case k:return h(t).apply(h(s),o.map(h));case F:{const e=h(t);n.delete(r.get(e)),r.delete(e)}}};const W=new Proxy(se(_,null),v);return{[e.toLowerCase()]:W,[`is${e}Proxy`]:e=>typeof e===_&&!!e&&s in e,proxy:o}}})("Window"),Re=typeof Worker===y?Worker:class{};const Pe=new WeakMap,$e=(e,...t)=>{const n=Q(e,...t);if(!Pe.has(n)){const r=e instanceof Re?je:Oe;Pe.set(n,r.call(t.at(0),n,d,h))}return Pe.get(n)};$e.transfer=Q.transfer;const Me={object(...e){return this.string(function(e){for(var t=e[0],n=1,r=arguments.length;n{const t=e||console,n={buffered:We,stderr:(t.stderr||console.error).bind(t),stdout:(t.stdout||console.log).bind(t)};return{stderr:(...e)=>n.stderr(...e),stdout:(...e)=>n.stdout(...e),async get(e){const t=await e;return Ne.set(t,n),t}}},Fe=new TextDecoder,We=(e,t=10)=>{const n=[];return r=>{if(r instanceof Uint8Array)for(const s of r)s===t?e(Fe.decode(new Uint8Array(n.splice(0)))):n.push(s);else e(r)}},He=(e,...t)=>Me[typeof e](e,...t),{isArray:De}=Array,{assign:Ce,create:Le,defineProperties:Ue,defineProperty:Be,entries:Je}=Object,{all:qe,resolve:ze}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Ge=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href,Ke=(e,t,n,r=!1,s=CustomEvent)=>{e.dispatchEvent(new s(`${t}:${n}`,{bubbles:!0,detail:{worker:r}}))},Ye=e=>Function(`\'use strict\';return (${e})`)(),Xe=e=>e.replace(/^(?:\\n|\\r\\n)/,""),Ve=Symbol.for("polyscript.js_modules"),Ze=new Map;Be(globalThis,Ve,{value:Ze}),new Proxy(Ze,{get:(e,t)=>e.get(t),has:(e,t)=>e.has(t),ownKeys:e=>[...e.keys()]});const Qe=(e,t)=>!t.startsWith("_"),et=(e,t)=>new Proxy(e,{has:Qe,get:(e,n)=>e[t][n]}),tt=(e,t)=>import(e).then((e=>{Ze.set(t,{...e})})),nt=e=>new Promise(((t,n)=>{document.querySelector(`link[href="${e}"]`)&&t(),document.head.append(Ce(document.createElement("link"),{rel:"stylesheet",href:e,onload:t,onerror:n}))})),rt=e=>/\\.css/i.test(new URL(e).pathname);Promise.withResolvers||(Promise.withResolvers=function(){var e,t,n=new this((function(n,r){e=n,t=r}));return{resolve:e,reject:t,promise:n}});const st=Object.getOwnPropertyDescriptors(Response.prototype),ot=e=>"function"==typeof e,at={get:(e,t)=>st.hasOwnProperty(t)?((e,t,{get:n,value:r})=>n||!ot(r)?e.then((e=>e[t])):(...n)=>e.then((e=>e[t](...n))))(e,t,st[t]):((e,t)=>ot(t)?t.bind(e):t)(e,e[t])};var it=(e,...t)=>new Proxy(fetch(e,...t),at);const ct=!globalThis.window,lt=({FS:e,PATH:t,PATH_FS:n},r,s)=>{const o=n.resolve(r),a=t.dirname(o);return e.mkdirTree?e.mkdirTree(a):ut(e,a),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},pt=e=>{const t=e.split("/");return t.pop(),t.join("/")},ut=(e,t)=>{const n=[];for(const r of t.split("/"))"."!==r&&".."!==r&&(n.push(r),r&&e.mkdir(n.join("/")))},ft=(e,t)=>{const n=[];for(const e of t.split("/"))switch(e){case"":case".":break;case"..":n.pop();break;default:n.push(e)}return[e.cwd()].concat(n).join("/").replace(/^\\/+/,"/")},dt=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},ht=(e,t)=>it(Ge(t,gt.get(e))).arrayBuffer(),gt=new WeakMap,yt=(e,t,n)=>qe((e=>{for(const{files:t,to_file:n,from:r=""}of e){if(void 0!==t&&void 0!==n)throw new Error("Cannot use \'to_file\' and \'files\' parameters together!");if(void 0===t&&void 0===n&&r.endsWith("/"))throw new Error(`Couldn\'t determine the filename from the path ${r}, please supply \'to_file\' parameter.`)}return e.flatMap((({from:e="",to_folder:t=".",to_file:n,files:r})=>{if(De(r))return r.map((n=>({url:dt([e,n]),path:dt([t,n])})));const s=n||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:dt([t,s])}]}))})(n).map((({url:r,path:s})=>ht(n,r).then((n=>e.writeFile(t,s,n)))))),wt=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,mt=(e,t)=>e.replace(/\\{.+?\\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),_t=(e,t,n)=>qe((e=>{const t=new Map,n=new Set,r=[];for(const[s,o]of Je(e))if(/^\\{.+\\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,mt(o,t))}else{const e=mt(s,t),a=wt(e,mt(o||"./",t));if(n.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);n.add(a),r.push({url:e,path:a})}return r})(n).map((({url:r,path:s})=>ht(n,r).then((n=>e.writeFile(t,s,n,r)))))),bt=({main:e,worker:t})=>{const n=[];if(t&&ct)for(let[e,r]of Je(t))e=Ge(e,gt.get(t)),n.push(tt(e,r));if(e&&!ct)for(let[t,r]of Je(e))t=Ge(t,gt.get(e)),rt(t)?nt(t):n.push(tt(t,r));return qe(n)},Et=(e,t)=>e.has(t),vt=e=>[...e.keys()];var kt=(e,t,n)=>{let r=globalThis[Ve],s="";if(n){s=gt.get(n);for(let[e,t]of Je(n)){let n=r.get(t);n&&!De(n)||(r.set(t,n||(n=[])),n.push(e))}}return((e,t,n,r)=>new Proxy(e,{has:Et,ownKeys:vt,get:(e,s)=>{let o=e.get(s);if(De(o)){let a=o;o=null;for(let e of a)e=Ge(e,r),rt(e)?n.importCSS(e):(n.importJS(e,s),o=t[Ve].get(s));e.set(s,o)}return o}}))(r,e,t,s)};const xt=new WeakMap,Tt=(e,t,n)=>{"polyscript"===t&&(n.lazy_py_modules=async(...t)=>(await xt.get(e)(t),t.map((t=>e.pyimport(t))))),e.registerJsModule(t,n)},St=(e,t)=>{if(e.endsWith("/*")){if(/\\.(zip|tar(?:\\.gz)?)$/.test(t))return RegExp.$1;throw new Error(`Unsupported archive ${t}`)}return""},At=(e,t,...n)=>{try{return e.runPython(He(t),...n)}catch(t){Ne.get(e).stderr(t)}},jt=async(e,t,...n)=>{try{return await e.runPythonAsync(He(t),...n)}catch(t){Ne.get(e).stderr(t)}},Ot=async(e,t,n)=>{const[r,...s]=t.split(".");let o,a=e.globals.get(r);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,n)}catch(t){Ne.get(e).stderr(t)}};var Rt=(new TextEncoder).encode(\'from uio import StringIO\\nimport sys\\n\\nclass Response:\\n def __init__(self, f):\\n self.raw = f\\n self.encoding = "utf-8"\\n self._cached = None\\n\\n def close(self):\\n if self.raw:\\n self.raw.close()\\n self.raw = None\\n self._cached = None\\n\\n @property\\n def content(self):\\n if self._cached is None:\\n try:\\n self._cached = self.raw.read()\\n finally:\\n self.raw.close()\\n self.raw = None\\n return self._cached\\n\\n @property\\n def text(self):\\n return str(self.content, self.encoding)\\n\\n def json(self):\\n import ujson\\n\\n return ujson.loads(self.content)\\n\\n\\n# TODO try to support streaming xhr requests, a-la pyodide-http\\nHEADERS_TO_IGNORE = ("user-agent",)\\n\\n\\ntry:\\n import js\\nexcept Exception as err:\\n raise OSError("This version of urequests can only be used in the browser")\\n\\n# TODO try to support streaming xhr requests, a-la pyodide-http\\n\\nHEADERS_TO_IGNORE = ("user-agent",)\\n\\n\\ndef request(\\n method,\\n url,\\n data=None,\\n json=None,\\n headers={},\\n stream=None,\\n auth=None,\\n timeout=None,\\n parse_headers=True,\\n):\\n from js import XMLHttpRequest\\n\\n xhr = XMLHttpRequest.new()\\n xhr.withCredentials = False\\n\\n if auth is not None:\\n import ubinascii\\n\\n username, password = auth\\n xhr.open(method, url, False, username, password)\\n else:\\n xhr.open(method, url, False)\\n\\n for name, value in headers.items():\\n if name.lower() not in HEADERS_TO_IGNORE:\\n xhr.setRequestHeader(name, value)\\n\\n if timeout:\\n xhr.timeout = int(timeout * 1000)\\n\\n if json is not None:\\n assert data is None\\n import ujson\\n\\n data = ujson.dumps(json)\\n # s.write(b"Content-Type: application/json\\\\r\\\\n")\\n xhr.setRequestHeader("Content-Type", "application/json")\\n\\n xhr.send(data)\\n\\n # Emulates the construction process in the original urequests\\n resp = Response(StringIO(xhr.responseText))\\n resp.status_code = xhr.status\\n resp.reason = xhr.statusText\\n resp.headers = xhr.getAllResponseHeaders()\\n\\n return resp\\n\\n\\n# Other methods - head, post, put, patch, delete - are not used by\\n# mip and therefore not included\\n\\n\\ndef get(url, **kw):\\n return request("GET", url, **kw)\\n\\n\\n# Content below this line is from the Micropython MIP package and is covered\\n# by the applicable MIT license:\\n# \\n# THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, \\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER \\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING \\n# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER \\n# DEALINGS IN THE SOFTWARE.\\n\\n# MicroPython package installer\\n# MIT license; Copyright (c) 2022 Jim Mussared\\n\\n\\n_PACKAGE_INDEX = const("https://micropython.org/pi/v2")\\n_CHUNK_SIZE = 128\\n\\n\\n# This implements os.makedirs(os.dirname(path))\\ndef _ensure_path_exists(path):\\n import os\\n\\n split = path.split("/")\\n\\n # Handle paths starting with "/".\\n if not split[0]:\\n split.pop(0)\\n split[0] = "/" + split[0]\\n\\n prefix = ""\\n for i in range(len(split) - 1):\\n prefix += split[i]\\n try:\\n os.stat(prefix)\\n except:\\n os.mkdir(prefix)\\n prefix += "/"\\n\\n\\n# Copy from src (stream) to dest (function-taking-bytes)\\ndef _chunk(src, dest):\\n buf = memoryview(bytearray(_CHUNK_SIZE))\\n while True:\\n n = src.readinto(buf)\\n if n == 0:\\n break\\n dest(buf if n == _CHUNK_SIZE else buf[:n])\\n\\n\\n# Check if the specified path exists and matches the hash.\\ndef _check_exists(path, short_hash):\\n import os\\n\\n try:\\n import binascii\\n import hashlib\\n\\n with open(path, "rb") as f:\\n hs256 = hashlib.sha256()\\n _chunk(f, hs256.update)\\n existing_hash = str(binascii.hexlify(hs256.digest())[: len(short_hash)], "utf-8")\\n return existing_hash == short_hash\\n except:\\n return False\\n\\n\\ndef _rewrite_url(url, branch=None):\\n if not branch:\\n branch = "HEAD"\\n if url.startswith("github:"):\\n url = url[7:].split("/")\\n url = (\\n "https://raw.githubusercontent.com/"\\n + url[0]\\n + "/"\\n + url[1]\\n + "/"\\n + branch\\n + "/"\\n + "/".join(url[2:])\\n )\\n return url\\n\\n\\ndef _download_file(url, dest):\\n response = get(url)\\n try:\\n if response.status_code != 200:\\n print("Error", response.status_code, "requesting", url)\\n return False\\n\\n print("Copying:", dest)\\n _ensure_path_exists(dest)\\n with open(dest, "wb") as f:\\n _chunk(response.raw, f.write)\\n\\n return True\\n finally:\\n response.close()\\n\\n\\ndef _install_json(package_json_url, index, target, version, mpy):\\n response = get(_rewrite_url(package_json_url, version))\\n try:\\n if response.status_code != 200:\\n print("Package not found:", package_json_url)\\n return False\\n\\n package_json = response.json()\\n finally:\\n response.close()\\n for target_path, short_hash in package_json.get("hashes", ()):\\n fs_target_path = target + "/" + target_path\\n if _check_exists(fs_target_path, short_hash):\\n print("Exists:", fs_target_path)\\n else:\\n file_url = "{}/file/{}/{}".format(index, short_hash[:2], short_hash)\\n if not _download_file(file_url, fs_target_path):\\n print("File not found: {} {}".format(target_path, short_hash))\\n return False\\n for target_path, url in package_json.get("urls", ()):\\n fs_target_path = target + "/" + target_path\\n if not _download_file(_rewrite_url(url, version), fs_target_path):\\n print("File not found: {} {}".format(target_path, url))\\n return False\\n for dep, dep_version in package_json.get("deps", ()):\\n if not _install_package(dep, index, target, dep_version, mpy):\\n return False\\n return True\\n\\n\\ndef _install_package(package, index, target, version, mpy):\\n if (\\n package.startswith("http://")\\n or package.startswith("https://")\\n or package.startswith("github:")\\n ):\\n if package.endswith(".py") or package.endswith(".mpy"):\\n print("Downloading {} to {}".format(package, target))\\n return _download_file(\\n _rewrite_url(package, version), target + "/" + package.rsplit("/")[-1]\\n )\\n else:\\n if not package.endswith(".json"):\\n if not package.endswith("/"):\\n package += "/"\\n package += "package.json"\\n print("Installing {} to {}".format(package, target))\\n else:\\n if not version:\\n version = "latest"\\n print("Installing {} ({}) from {} to {}".format(package, version, index, target))\\n\\n mpy_version = (\\n sys.implementation._mpy & 0xFF if mpy and hasattr(sys.implementation, "_mpy") else "py"\\n )\\n\\n package = "{}/package/{}/{}/{}.json".format(index, mpy_version, package, version)\\n\\n return _install_json(package, index, target, version, mpy)\\n\\n\\ndef install(package, index=None, target=None, version=None, mpy=True):\\n if not target:\\n for p in sys.path:\\n if p.endswith("/lib"):\\n target = p\\n break\\n else:\\n print("Unable to find lib dir in sys.path")\\n return\\n\\n if not index:\\n index = _PACKAGE_INDEX\\n\\n if _install_package(package, index.rstrip("/"), target, version, mpy):\\n print("Done")\\n else:\\n print("Package may be partially installed")\\n\');const Pt=(e,t)=>{try{e.mkdir(t)}catch(e){}};var $t={type:"micropython",module:(e="1.22.0-356")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,n){const{stderr:r,stdout:s,get:o}=Ie({stderr:We(console.error),stdout:We(console.log)});n=n.replace(/\\.m?js$/,".wasm");const a=await o(e({linebuffer:!1,stderr:r,stdout:s,url:n})),i=Mt.bind(a);return xt.set(a,i),t.files&&await _t(this,a,t.files),t.fetch&&await yt(this,a,t.fetch),t.js_modules&&await bt(t.js_modules),this.writeFile(a,"./mip.py",Rt),t.packages&&await i(t.packages),a},registerJSModule:Tt,run:At,runAsync:jt,runEvent:Ot,transform:(e,t)=>e.PyProxy.toJs(t),writeFile:(e,t,n,r)=>{const{FS:s,_module:{PATH:o,PATH_FS:a}}=e,i={FS:s,PATH:o,PATH_FS:a},c=St(t,r);if(c){const r=t.slice(0,-1);switch("./"!==r&&s.mkdir(r),c){case"zip":{const e=new Blob([n],{type:"application/zip"});return import("./zip-D2yvzXKD.js").then((async({BlobReader:t,Uint8ArrayWriter:n,ZipReader:a})=>{const i=new a(new t(e));for(const e of await i.getEntries()){const{directory:t,filename:a}=e,i=r+a;if(t)Pt(s,i);else{Pt(s,o.dirname(i));const t=await e.getData(new n);s.writeFile(i,t,{canOwn:!0})}}i.close()}))}case"tar.gz":{const t="./_.tar.gz";return lt(i,t,n),void e.runPython(`\\n import os, gzip, tarfile\\n tar = tarfile.TarFile(fileobj=gzip.GzipFile(fileobj=open("${t}", "rb")))\\n for f in tar:\\n name = f"${r}{f.name}"\\n if f.type == tarfile.DIRTYPE:\\n if f.name != "./":\\n os.mkdir(name.strip("/"))\\n else:\\n dir = os.path.dirname(name)\\n if not os.path.exists(dir):\\n os.mkdir(dir)\\n source = tar.extractfile(f)\\n with open(name, "wb") as dest:\\n dest.write(source.read())\\n dest.close()\\n tar.close()\\n os.remove("${t}")\\n `)}}}return lt(i,t,n)}};async function Mt(e){const t=this.pyimport("mip");for(const n of e)t.install(n)}const Nt={dict_converter:Object.fromEntries};let It=!1;const Ft=e=>(...t)=>{try{return It=!0,e(...t)}finally{It=!1}};let Wt=!1;const Ht=()=>{if(Wt)return;Wt=!0;const e=new WeakMap,t=e=>e.destroy(),n=n=>{for(let r=0;r`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,n){ct||"auto"!==t.experimental_create_proxy||Ht();const{stderr:r,stdout:s,get:o}=Ie(),a=n.slice(0,n.lastIndexOf("/")),i=await o(e({stderr:r,stdout:s,indexURL:a})),c=Ct.bind(i);return xt.set(i,c),t.files&&await _t(this,i,t.files),t.fetch&&await yt(this,i,t.fetch),t.js_modules&&await bt(t.js_modules),t.packages&&await c(t.packages),i},registerJSModule:Tt,run:Ft(At),runAsync:Ft(jt),runEvent:Ft(Ot),transform:({ffi:{PyProxy:e}},t)=>t instanceof e?t.toJs(Nt):t,writeFile:(e,t,n,r)=>{const s=St(t,r);if(s)return e.unpackArchive(n,s,{extractDir:t.slice(0,-1)});const{FS:o,PATH:a,_module:{PATH_FS:i}}=e;return lt({FS:o,PATH:a,PATH_FS:i},t,n)}};async function Ct(e){await this.loadPackage("micropip");const t=this.pyimport("micropip");await t.install(e,{keep_going:!0}),t.destroy()}const Lt="ruby-wasm-wasi",Ut=Lt.replace(/\\W+/g,"_");var Bt={type:Lt,experimental:!0,module:(e="2.6.0")=>`https://cdn.jsdelivr.net/npm/@ruby/3.2-wasm-wasi@${e}/dist/browser/+esm`,async engine({DefaultRubyVM:e},t,n){n=n.replace(/\\/browser\\/\\+esm$/,"/ruby.wasm");const r=await it(n).arrayBuffer(),s=await WebAssembly.compile(r),{vm:o}=await e(s);return t.files&&await _t(this,o,t.files),t.fetch&&await yt(this,o,t.fetch),t.js_modules&&await bt(t.js_modules),o},registerJSModule(e,t,n){t=t.replace(/\\W+/g,"__");const r=`__module_${Ut}_${t}`;globalThis[r]=n,this.run(e,`require "js";$${t}=JS.global[:${r}]`),delete globalThis[r]},run:(e,t,...n)=>e.eval(He(t),...n),runAsync:(e,t,...n)=>e.evalAsync(He(t),...n),async runEvent(e,t,n){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,r=`__module_${Ut}_event`;globalThis[r]=n,this.run(e,`require "js";$xworker.call("${t}",JS.global[:${r}])`),delete globalThis[r]}else{const r=this.run(e,`method(:${t})`);await r.call(t,e.wrap(n))}},transform:(e,t)=>t,writeFile:()=>{throw new Error(`writeFile is not supported in ${Lt}`)}};var Jt={type:"wasmoon",module:(e="1.16.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},n){const{stderr:r,stdout:s,get:o}=Ie(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",r)})),n.files&&await _t(this,a,n.files),n.fetch&&await yt(this,a,n.fetch),n.js_modules&&await bt(n.js_modules),a},registerJSModule:(e,t,n)=>{e.global.set(t,n)},run:(e,t,...n)=>{try{return e.doStringSync(He(t),...n)}catch(t){Ne.get(e).stderr(t)}},runAsync:async(e,t,...n)=>{try{return await e.doString(He(t),...n)}catch(t){Ne.get(e).stderr(t)}},runEvent:async(e,t,n)=>{const[r,...s]=t.split(".");let o,a=e.global.get(r);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,n)}catch(t){Ne.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,n)=>((e,t,n)=>(ut(e,pt(t)),t=ft(e,t),e.writeFile(t,new Uint8Array(n),{canOwn:!0})))(e,t,n)};const qt=new WeakMap,zt=async(e,t)=>{const{shelter:n,destroy:r,io:s}=qt.get(e),{output:o,result:a}=await n.captureR(He(t));for(const{type:e,data:t}of o)s[e](t);return pe(a,r,{token:!1})};var Gt={type:"webr",experimental:!0,module:(e="0.3.3")=>`https://cdn.jsdelivr.net/npm/webr@${e}/dist/webr.mjs`,async engine(e,t){const{get:n}=Ie(),r=new e.WebR;await n(r.init().then((()=>r)));const s=await new r.Shelter;return qt.set(r,{module:e,shelter:s,destroy:s.destroy.bind(s),io:Ne.get(r)}),t.files&&await _t(this,r,t.files),t.fetch&&await yt(this,r,t.fetch),t.js_modules&&await bt(t.js_modules),r},registerJSModule(e,t){console.warn(`Experimental interpreter: module ${t} is not supported (yet)`)},run:zt,runAsync:zt,async runEvent(e,t,n){await e.evalRVoid(`${t}(event)`,{env:{event:{type:[n.type]}}})},transform:(e,t)=>(console.log("transforming",t),t),writeFile:()=>{}};const Kt=new Map,Yt=new Map,Xt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[n,...r]=t.split("@"),s=Kt.get(n),o=/^(?:\\.?\\.?\\/|https?:\\/\\/)/i.test(r)?r.join("@"):s.module(...r);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:n,module:r,engine:s}=e.get(t);return(e,o)=>r.then((r=>{Yt.set(t,e);for(const t of["files","fetch"]){const n=e?.[t];n&>.set(n,o)}for(const t of["main","worker"]){const n=e?.js_modules?.[t];n&>.set(n,o)}return s(r,e,n)}))}}),Vt=e=>{for(const t of[].concat(e.type))Kt.set(t,e)};for(const e of[$t,Dt,Bt,Jt,Gt])Vt(e);const Zt=async e=>(await import("./toml-DiUM0_qs.js")).parse(e),Qt=e=>{try{return JSON.parse(e)}catch(t){return Zt(e)}},en=(e,t,n,r={})=>{if(t){const[e,s]=((e,t="./config.txt")=>{let n=typeof e;return"string"===n&&/\\.(json|toml|txt)$/.test(e)?n=RegExp.$1:e=t,[Ge(e),n]})(t,n);"json"===s?r=it(e).json():"toml"===s?r=it(e).text().then(Zt):"string"===s?r=Qt(t):"object"===s&&t?r=t:"txt"===s&&"string"==typeof r&&(r=Qt(r)),t=e}return ze(r).then((n=>Xt[e](n,t)))},tn="BeforeRun",nn="AfterRun",rn=[`code${tn}`,`code${tn}Async`,`code${nn}`,`code${nn}Async`],sn=["onWorker","onReady",`on${tn}`,`on${tn}Async`,`on${nn}`,`on${nn}Async`];function on(e,t){const{run:n,runAsync:r}=Kt.get(this.type);return{...e,run:n.bind(this,t),runAsync:r.bind(this,t)}}const an=(e,t,n,r,s,o)=>{if(s||o){const a=on.bind(e,t),i=r?"runAsync":"run",c=e[i];e[i]=r?async function(e,t,...r){s&&await s.call(this,a(e),n);const i=await c.call(this,e,t,...r);return o&&await o.call(this,a(e),n),i}:function(e,t,...r){s&&s.call(this,a(e),n);const i=c.call(this,e,t,...r);return o&&o.call(this,a(e),n),i}}};let cn,ln,pn;const un=(e,t)=>{addEventListener(e,t||(async t=>{try{await cn,ln(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:fn,stringify:dn}=u,{proxy:hn,window:gn,isWindowProxy:yn}=$e(self,{parse:fn,stringify:dn,transform:e=>pn?pn(e):e}),wn={sync:hn,window:gn,isWindowProxy:yn,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};un("message",(({data:{options:e,config:t,configURL:n,code:r,hooks:s}})=>{cn=(async()=>{try{const{id:o,tag:a,type:i,custom:c,version:l,config:p,async:u}=e,f=((e,t="")=>`${e}@${t}`.replace(/@$/,""))(i,l),d=await en(f,t,n,p),{js_modules:h,sync_main_only:g}=Yt.get(f),y=h?.main;let w=!g;try{new SharedArrayBuffer(4),w=!0}catch(e){if(w)throw new Error(["Unable to use SharedArrayBuffer due insecure environment.","Please read requirements in MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements"].join("\\n"))}const m=Le(Kt.get(i)),_=((e,t,n,r)=>({type:t,config:n,interpreter:r,io:Ne.get(r),run:(t,...n)=>e.run(r,t,...n),runAsync:(t,...n)=>e.runAsync(r,t,...n),runEvent:(...t)=>e.runEvent(r,...t)}))(m,c||i,p,d);let b="run";if(u&&(b+="Async"),s){let e,t,n="",r="";for(const e of rn){const t=s[e];if(t){const s=e.endsWith("Async");(s&&u||!s&&!u)&&(e.startsWith("codeBefore")?n=t:r=t)}}(n||r)&&((e,t,n,r)=>{const s=e[t].bind(e);e[t]="run"===t?(e,t,...o)=>{n&&s(e,n,...o);const a=s(e,Xe(t),...o);return r&&s(e,r,...o),a}:async(e,t,...o)=>{n&&await s(e,n,...o);const a=await s(e,Xe(t),...o);return r&&await s(e,r,...o),a}})(m,b,n,r);for(const n of sn.slice(2)){const r=s[n];if(r){const s=n.endsWith("Async");if(s&&u||!s&&!u){const s=Ye(r);n.startsWith("onBefore")?e=s:t=s}}}an(m,_,wn,u,e,t)}let E,v,k,x=null,T="";w&&(({CustomEvent:E,document:v}=gn),x=o&&v.getElementById(o)||null,k=e=>Ke(x,c||i,e,!0,E));const S=kt(gn,hn,y);return((e,t,n,r)=>{if("pyodide"===e)return;const s="polyscript.js_modules";for(const e of Reflect.ownKeys(r))t.registerJSModule(n,`${s}.${e}`,et(r,e));t.registerJSModule(n,s,r)})(i,m,d,S),m.registerJSModule(d,"polyscript",{xworker:wn,currentScript:x,config:_.config,js_modules:S,get target(){return!T&&x&&("SCRIPT"===a?x.after(Ce(v.createElement(`script-${c||i}`),{id:T=`${o}-target`})):(T=o,x.replaceChildren(),x.style.display="block")),T}}),ln=m.runEvent.bind(m,d),pn=m.transform.bind(m,d),x&&k("ready"),s?.onReady&&Ye(s?.onReady).call(m,on.call(m,_,d),wn),await m[b](d,r),x&&k("done"),postMessage("polyscript:done"),d}catch(e){postMessage(e)}})(),un("error"),un("message"),un("messageerror")}));\n'.replace(He,Be)],{type:"application/javascript"})),{type:"module"}),{postMessage:s}=r,o=this instanceof Rn;if(e.length){const[t,r]=e;(n=tt({},n||{type:t,version:r})).type||(n.type=t)}const[i]=mn(n.config,n.configURL),l=a(t).text().then((e=>{const t=o?this.toJSON():void 0;s.call(r,{options:n,config:i,code:e,hooks:t})})),c=tt(De(r,_).proxy,{importJS:vt,importCSS:Et}),p=Promise.withResolvers();return rt(r,{sync:{value:c},ready:{value:p.promise},postMessage:{value:(e,...t)=>l.then((()=>s.call(r,e,...t)))},onerror:{writable:!0,configurable:!0,value:console.error}}),r.addEventListener("message",(e=>{const{data:t}=e,n=t instanceof Error;(n||"polyscript:done"===t)&&(e.stopImmediatePropagation(),n?(p.reject(t),r.onerror(nt(e,{type:{value:"error"},error:{value:t}}))):p.resolve(r))})),o&&this.onWorker?.(this.interpreter,r),r};const Tn="Invalid content";var Sn=e=>{const{src:t,worker:n}=e.attributes;if(n){let{value:r}=n;if(r)throw new SyntaxError("Invalid worker attribute");if(r=t?.value,!r){if(t)throw new SyntaxError("Invalid worker attribute");if(e.childElementCount){const{innerHTML:t,localName:n,type:s}=e,o=s||n.replace(/-script$/,"");r=Qe(t),console.warn(`Deprecated: use