diff --git a/docs/index.js b/docs/index.js index 5fc77c71..79aea43e 100644 --- a/docs/index.js +++ b/docs/index.js @@ -1,2 +1,2 @@ -const e=(e,t=document)=>[...t.querySelectorAll(e)],t=(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,s={get:(e,t)=>n.hasOwnProperty(t)?((e,t,{get:n,value:s})=>n||!r(s)?e.then((e=>e[t])):(...n)=>e.then((e=>e[t](...n))))(e,t,n[t]):((e,t)=>r(t)?t.bind(e):t)(e,e[t])};var o=(e,...t)=>new Proxy(fetch(e,...t),s);const a=new Proxy(new Map,{get:(e,t)=>(e.has(t)||e.set(t,Promise.withResolvers()),e.get(t))}),i=new Set(["__dict__","constructor","get","has","includes","next","set","then"]),c=new Proxy(Object.freeze({}),{get:(e,t)=>"string"!=typeof t||i.has(t)?void 0:a[t].promise.then((e=>e.sync))}),l="object"==typeof self?self:globalThis,u=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 l[e](t),s)}case 8:return n(BigInt(a),s);case"BigInt":return n(Object(BigInt(a)),s)}return n(new l[o](a),s)};return r})(new Map,e)(0),p="",{toString:f}={},{keys:d}=Object,h=e=>{const t=typeof e;if("object"!==t||!e)return[0,t];const n=f.call(e).slice(8,-1);switch(n){case"Array":return[1,p];case"Object":return[2,p];case"Date":return[3,p];case"RegExp":return[4,p];case"Map":return[5,p];case"Set":return[6,p]}return n.includes("Array")?[1,n]:n.includes("Error")?[7,n]:[2,n]},y=([e,t])=>0===e&&("function"===t||"symbol"===t),w=(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]=h(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=[],c=s([a,n],r);for(const t of d(r))!e&&y(h(r[t]))||n.push([o(t),o(r[t])]);return c}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||!y(h(n))&&!y(h(s)))&&t.push([o(n),o(s)]);return n}case 6:{const t=[],n=s([a,t],r);for(const n of r)!e&&y(h(n))||t.push(o(n));return n}}const{message:c}=r;return s([a,{name:i,message:c}],r)};return o})(!(t||n),!!t,new Map,r)(e),r},{parse:g,stringify:m}=JSON,_={json:!0,lossy:!0};var A=Object.freeze({__proto__:null,parse:e=>u(g(e)),stringify:e=>m(w(e,_))});const b="array",v="function",E="null",k="number",j="object",x="string",$="symbol",S="undefined";let B=0;const P=new Map,T=new Map,M=e=>T.get(e),R=e=>{if(!P.has(e)){let t;for(;T.has(t=B++););P.set(e,t),T.set(t,e)}return P.get(e)},{ArrayBuffer:O,Atomics:F,Promise:C}=globalThis,{isArray:D}=Array,{create:W,getPrototypeOf:I,values:N}=Object,H=I(Int32Array),J=W(F),U=()=>C.withResolvers();let q=0;const L=new Map,z=(e,t)=>class extends e{constructor(e,...n){super(e,...n),e instanceof t&&L.set(this,[q++,0,U()])}},K=new WeakSet,G=e=>(K.add(e),e),X=(e,t)=>{const{data:n}=e,r=D(n)&&(n.at(0)===t||0===n.at(1)&&!t);return r&&(e.stopImmediatePropagation(),e.preventDefault()),r},Y=e=>null!==e&&"object"==typeof e&&!K.has(e),V=new WeakMap,Z=(e,t,n)=>{if(L.has(e))t.set(e,L.get(e)[0]);else if(!(e instanceof H||e instanceof O))for(const r of N(e))Y(r)&&!n.has(r)&&(n.add(r),Z(r,t,n))},Q=(...e)=>({value:new C((t=>{let n=new Worker("data:application/javascript,onmessage%3De%3D%3EpostMessage(!Atomics.wait(...e.data))");n.onmessage=()=>t("ok"),n.postMessage(e)}))}),ee=(e,t,n)=>{for(const[n,r]of t)V.set(n,[r,e.currentTarget]);(({currentTarget:e,type:t,origin:n,lastEventId:r,source:s,ports:o},a)=>{e.dispatchEvent(new MessageEvent(t,{data:a,origin:n,lastEventId:r,source:s,ports:o}))})(e,n)};let{BigInt64Array:te,Int32Array:ne,SharedArrayBuffer:re,Worker:se}=globalThis,oe=e=>e,ae=!1;const ie=e=>({...e,type:"module"});try{new re(4),se=class extends se{constructor(e,t){super(e,ie(t))}},J.waitAsync||(J.waitAsync=Q)}catch(e){const t=crypto.randomUUID(),n=new Map,r=(e,t,n,...r)=>{e.addEventListener(t,n,...r)},s=({serviceWorker:e},s,o)=>{let a,i=!0;r(e,"message",(e=>{if(X(e,t)){const[r,s,o]=e.data,i=[s,o].join(","),c=e=>{n.delete(i),a.postMessage([t,s,o,e])},l=n.get(i);if(l)c(l);else{const{promise:e,resolve:t}=U();n.set(i,t),e.then(c)}}})),e.getRegistration(s).then((t=>t??e.register(s))).then((function t(n){i=i&&!!e.controller,a=n.installing||n.waiting||n.active,"activated"===a.state?i?o():location.reload():r(a,"statechange",(()=>t(n)),{once:!0})}))};oe=G,ae=!0,J.notify=(e,r)=>{const[s,o]=(e=>V.get(e))(e),a=[s,r].join(","),i=n.get(a);return i?i(e):n.set(a,e),o.postMessage([t,1,e,s,r]),0},J.waitAsync=(e,...t)=>{const[n,r]=((e,t)=>{const n=L.get(e),[r,s,{promise:o}]=n;return n[1]=t,[r,o]})(e,...t);return{value:r}},re=class extends O{},te=z(te,re),ne=z(ne,re);let o=null;se=class extends se{constructor(e,n){let a=n?.serviceWorker||"";if(a){if(a=new URL(a,location.href).href,n={...n,serviceWorker:a},!o){const{promise:e,resolve:t}=U();s(navigator,a,t),o=e}o.then((()=>super.postMessage([t,3])))}super(e,ie(n)),super.postMessage([t,0,n]),r(this,"message",(e=>{if(X(e,t)){const[t,n,...r]=e.data;switch(n){case 1:((e,t,n)=>{for(const[r,[s,o,{resolve:a}]]of L)if(t===s&&n===o){for(let t=0;t{const n=new Map;return Y(t)&&Z(t,n,new Set),n.size?[e,2,n,t]:t})(t,e),...n)}}}const{BYTES_PER_ELEMENT:ce}=Int32Array,{BYTES_PER_ELEMENT:le}=Uint16Array,{notify:ue}=J,pe=new TextDecoder("utf-16"),fe=new WeakSet,de=(...e)=>(fe.add(e),e);let he="";let ye=0;const we=([e,t,n,r,s,o,a,i,c],l)=>(...u)=>{let p=""!==he,f=0;p&&"="!==he[0]&&"-"!==he[0]&&(f=((e,t)=>setTimeout(console.warn,3e3,`💀🔒 - proxy.${e}() in proxy.${t}()`))(l,he));const d=ye++,h=[];fe.has(u.at(-1)||h)&&fe.delete(h=u.pop());const y=n(i?u.map(i):u);let w=t(2*ce);return a([e,2,l,d,w,y,r],{transfer:h}),c(w,0).value.then((()=>{p&&clearTimeout(f);const n=w[1];if(!n)return;const r=le*n;return w=t(r+r%ce),a([e,1,d,w]),c(w,0).value.then((()=>{const e=new Uint16Array(w.buffer),t=o?e.subarray(0,n):e.slice(0,n);return s(pe.decode(t))}))}))};var ge=({parse:e,stringify:t,transform:n}=JSON)=>{const r=((e,t)=>async(n,r,[s,o,a,i,c])=>{c&&(he=s);try{const s=await n(...i);if(void 0!==s){const n=e(t?t(s):s);r.set(o,n),a[1]=n.length}}finally{c&&(he=""),a[0]=1,ue(a,0)}})(t,n),s=crypto.randomUUID();return{Worker:class extends se{constructor(t,o){const a=new Map,i=new Map;super(t,o),this.proxy=((e,t)=>new Proxy(t,{get:(t,n)=>{let r;return"then"!==n&&(r=t.get(n),r||(r=we(e,n),t.set(n,r))),r},set:(e,t,n)=>"then"!==t&&!!e.set(t,n)}))([s,e=>new ne(new re(e)),oe,!1,e,ae,(...e)=>this.postMessage(...e),n,J.waitAsync],a),this.postMessage(oe([s,0,o])),this.addEventListener("message",(e=>{if(X(e,s)){const[t,n,...s]=e.data;switch(n){case 2:((e,t,n,r)=>{const[s]=r,o=n.get(s);if(!o)throw new Error(`Unknown proxy.${s}()`);e(o,t,r)})(r,i,a,s);break;case 1:((e,[t,n])=>{const r=e.get(t);e.delete(t);for(let e=new Uint16Array(n.buffer),t=0,{length:s}=r;t[e,t])));const _e="ownKeys",Ae="destruct",{[_e]:be}=Reflect,ve=new Map(be(Symbol).filter((e=>typeof Symbol[e]===$)).map((e=>[Symbol[e],e]))),Ee=e=>ve.get(e)||`.${Symbol.keyFor(e)||""}`,ke="960fd6fe-ad03-40d1-a314-e58d84bce14f",je="="+ke,xe="-"+ke,$e=new FinalizationRegistry((([e,t,n])=>{n&&console.debug(`%c${String(t)}`,"font-weight:bold","collected"),e(t)})),Se=Object.create(null),Be=(e,t,{debug:n,handler:r,return:s,token:o=e}=Se)=>{const a=s||new Proxy(e,r||Se),i=[a,[t,e,!!n]];return!1!==o&&i.push(o),$e.register(...i),a},{addEventListener:Pe}=EventTarget.prototype,Te=new WeakMap;Reflect.defineProperty(EventTarget.prototype,"addEventListener",{value(e,t,...n){const r=n.at(0)?.invoke;if(r){let t=Te.get(this);t||(t=new Map,Te.set(this,t)),t.set(e,[].concat(r)),delete n[0].invoke}return Pe.call(this,e,t,...n)}});const{isArray:Me}=Array;const{url:Re}=import.meta,Oe=/import\((['"])([^)]+?\.js)\1\)/g,Fe=(e,t,n)=>`import(${t}${new URL(n,Re).href}${t})`,{Worker:Ce}=(e=>{const t=ge(e),n=e=>{const t=typeof e;switch(t){case j:return null===e?[me[E],e]:e===globalThis?[me[j],null]:Me(e)?[me[b],R(e)]:[me[j],e instanceof H?e:R(e)];case v:return[me[v],R(e)];case $:return[me[$],Ee(e)];default:return[me[t],e]}};class r extends t.Worker{constructor(e,t){const{proxy:r}=super(e,t),{[xe]:s}=r,o=new Map,a=e=>{o.delete(e),s(Ae,e)},i=([e,t])=>{switch(e){case me[j]:if(null===t)return globalThis;if(typeof t===k)return M(t);if(!(t instanceof H))for(const e in t)t[e]=i(t[e]);return t;case me[b]:return typeof t===k?M(t):t.map(i);case me[v]:switch(typeof t){case k:return M(t);case x:{let e=o.get(t)?.deref();return e||(e=Be(t,a,{token:!1,return:function(...e){return e.length&&e[0]instanceof Event&&(e=>{const{currentTarget:t,target:n,type:r}=e,s=Te.get(t||n)?.get(r);if(s)for(const t of s)e[t]()})(e[0]),s("apply",t,n(this),e.map(n)).then(i)}}),o.set(t,new WeakRef(e))),e}}case me[$]:return(e=>{if(e.startsWith("."))return Symbol.for(e.slice(1));for(const[t,n]of ve)if(n===e)return t})(t);default:return t}};r[je]=(e,t,...r)=>{if(e===Ae)(e=>{const[t,n]=typeof e===k?[T,P]:[P,T],r=t.has(e);r&&(n.delete(t.get(e)),t.delete(e))})(t);else{const s=Reflect[e],o=null==t?globalThis:M(t);switch(e){case"defineProperty":{const[e,t]=r.map(i);return n(s(o,e,t))}case"getOwnPropertyDescriptor":{const e=s(o,...r.map(i));if(e){const{get:t,set:r,value:s}=e;t&&(e.get=n(t)),r&&(e.set=n(r)),s&&(e.value=n(s))}return[me[e?j:S],e]}case _e:return[me[b],s(o).map(n)];default:return((e,t,r)=>n(e(t,...r.map(i))))(s,o,r)}}}}}return{...t,Worker:r}})(A);const De=new WeakMap,We=e=>{const t=e||console,n={buffered:Ne,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 De.set(t,n),t}}},Ie=new TextDecoder,Ne=(e,t=10)=>{const n=[];return r=>{if(r instanceof Uint8Array)for(const s of r)s===t?e(Ie.decode(new Uint8Array(n.splice(0)))):n.push(s);else e(r)}},He=new Map,Je=e=>He.get(e),Ue=(e,t)=>{try{return Function("require",t)(Je)}catch(t){De.get(e).stderr(t)}};var qe={type:"dummy",module:()=>"data:application/javascript,",engine:e=>We().get(e),registerJSModule(e,t,n){He.set(t,n)},run:Ue,runAsync:Ue,runEvent:async(e,t,n)=>{try{await Function("require","e",`return ${t}(e)`)(Je,n)}catch(t){De.get(e).stderr(t)}},transform:(e,t)=>t,writeFile(){}};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 Le={object(...e){return this.string(function(e){for(var t=e[0],n=1,r=arguments.length;n",">":">","'":"'","'":"'",""":'"',""":'"'},Xe=e=>Ge[e],Ye=(e,...t)=>Le[typeof e](e,...t),Ve=e=>ze.call(e,Ke,Xe),{isArray:Ze}=Array,{assign:Qe,create:et,defineProperties:tt,defineProperty:nt,entries:rt}=Object,{all:st,resolve:ot}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),at=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href;let it=0;const ct=(e,t)=>({id:e.id||(e.id=`${t}-w${it++}`),tag:e.tagName}),lt=(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:De.get(r),run:(t,...n)=>e.run(r,t,...n),runAsync:(t,...n)=>e.runAsync(r,t,...n),runEvent:(...t)=>e.runEvent(r,...t)}),pt=e=>e.replace(/^(?:\n|\r\n)/,""),ft=(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,pt(t),...o);return r&&s(e,r,...o),a}:async(e,t,...o)=>{n&&await s(e,n,...o);const a=await s(e,pt(t),...o);return r&&await s(e,r,...o),a}},dt=Symbol.for("polyscript.js_modules"),ht=new Map;nt(globalThis,dt,{value:ht});const yt=new Proxy(ht,{get:(e,t)=>e.get(t),has:(e,t)=>e.has(t),ownKeys:e=>[...e.keys()]}),wt=(e,t)=>!t.startsWith("_"),gt=(e,t)=>new Proxy(e,{has:wt,get:(e,n)=>e[t][n]}),mt=(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}`,gt(r,e));t.registerJSModule(n,s,r)},_t=(e,t)=>import(e).then((e=>{ht.set(t,{...e})})),At=e=>new Promise(((t,n)=>{document.querySelector(`link[rel="stylesheet"][href="${e}"]`)?t():document.head.append(Qe(document.createElement("link"),{rel:"stylesheet",href:e,onload:t,onerror:n}))})),bt=e=>/\.css$/i.test(new URL(e).pathname),vt=e=>/^(?:false|0|no)$/i.test(e.getAttribute("async")),Et=!globalThis.window,kt=({FS:e,PATH:t,PATH_FS:n},r,s)=>{const o=n.resolve(r),a=t.dirname(o);return e.mkdirTree?e.mkdirTree(a):xt(e,a),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},jt=e=>{const t=e.split("/");return t.pop(),t.join("/")},xt=(e,t)=>{const n=[];for(const r of t.split("/"))"."!==r&&".."!==r&&(n.push(r),r&&e.mkdir(n.join("/")))},$t=(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},Bt=(e,t)=>o(at(e,t)).arrayBuffer(),Pt=(e,t,n,r)=>st((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(Ze(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:n,path:s})=>Bt(n,r).then((n=>e.writeFile(t,s,n)))))),Tt=(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)})),Rt=(e,t,n,r)=>st((e=>{const t=new Map,n=new Set,r=[];for(const[s,o]of rt(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=Tt(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:n,path:s})=>Bt(n,r).then((r=>e.writeFile(t,s,r,n)))))),Ot=({main:e,worker:t},n)=>{const r=[];if(t&&Et)for(let[e,s]of rt(t))e=at(e,n),r.push(_t(e,s));if(e&&!Et)for(let[t,s]of rt(e))t=at(t,n),bt(t)?At(t):r.push(_t(t,s));return st(r)},{assign:Ft}=Object,Ct="entries",Dt="readonly",Wt="readwrite",It={durability:"default",prefix:"IDBMap"},Nt=({target:{result:e}})=>e;class Ht extends EventTarget{#e;#t;#n;async#r(e,t){const n=(await this.#e).transaction(Ct,t,this.#t);return new Promise(((t,r)=>Ft(e(n.objectStore(Ct)),{onsuccess:t,onerror:r})))}constructor(e,{durability:t=It.durability,prefix:n=It.prefix}=It){super(),this.#n=n,this.#t={durability:t},this.#e=new Promise(((t,n)=>{Ft(indexedDB.open(`${this.#n}/${e}`),{onupgradeneeded({target:{result:e,transaction:n}}){e.objectStoreNames.length||e.createObjectStore(Ct),n.oncomplete=()=>t(e)},onsuccess(e){t(Nt(e))},onerror(e){n(e),this.dispatchEvent(e)}})})).then((e=>{const t=this.dispatchEvent.bind(this);for(const n in e)n.startsWith("on")&&(e[n]=t);return e}))}dispatchEvent(e){const{type:t,message:n,isTrusted:r}=e;return super.dispatchEvent(r?Ft(new Event(t),{message:n}):e)}async close(){(await this.#e).close()}get size(){return this.#r((e=>e.count()),Dt).then(Nt)}async clear(){await this.#r((e=>e.clear()),Wt)}async delete(e){await this.#r((t=>t.delete(e)),Wt)}async entries(){const e=await this.keys();return Promise.all(e.map((e=>this.get(e).then((t=>[e,t])))))}async forEach(e,t=this){for(const[n,r]of await this.entries())await e.call(t,r,n,this)}async get(e){return await this.#r((t=>t.get(e)),Dt).then(Nt)}async has(e){return void 0!==await this.#r((t=>t.getKey(e)),Dt).then(Nt)}async keys(){return await this.#r((e=>e.getAllKeys()),Dt).then(Nt)}async set(e,t){return await this.#r((n=>n.put(t,e)),Wt),this}async values(){const e=await this.keys();return Promise.all(e.map((e=>this.get(e))))}get[Symbol.toStringTag](){return this.#n}}class Jt extends Map{#s;#o;constructor(...e){super(),this.#s=new Ht(...e),this.#o=this.#s.entries().then((e=>{for(const[t,n]of e)super.set(t,n)}))}async sync(){await this.#o}clear(){return this.#o=this.#o.then((()=>this.#s.clear())),super.clear()}delete(e){return this.#o=this.#o.then((()=>this.#s.delete(e))),super.delete(e)}set(e,t){return this.#o=this.#o.then((()=>this.#s.set(e,t))),super.set(e,t)}}const Ut=new WeakMap,qt=(e,t,n)=>{"polyscript"===t&&(n.lazy_py_modules=async(...t)=>(await Ut.get(e)(t),t.map((t=>e.pyimport(t)))),n.storage=async e=>{const t=new Jt(e);return await t.sync(),t},n.JSON=A),e.registerJsModule(t,n)},Lt=(e,t)=>{if(e.endsWith("/*")){if(/\.(zip|whl|tgz|tar(?:\.gz)?)$/.test(t))return RegExp.$1;throw new Error(`Unsupported archive ${t}`)}return""},zt=(e,t,...n)=>{try{return e.runPython(Ye(t),...n)}catch(t){De.get(e).stderr(t)}},Kt=async(e,t,...n)=>{try{return await e.runPythonAsync(Ye(t),...n)}catch(t){De.get(e).stderr(t)}},Gt=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){De.get(e).stderr(t)}};var Xt=(new TextEncoder).encode("_F='github:'\n_E='user-agent'\n_D=True\n_C=False\n_B='/'\n_A=None\nfrom uio import StringIO\nimport sys\nclass Response:\n\tdef __init__(A,f):A.raw=f;A.encoding='utf-8';A._cached=_A\n\tdef close(A):\n\t\tif A.raw:A.raw.close();A.raw=_A\n\t\tA._cached=_A\n\t@property\n\tdef content(self):\n\t\tA=self\n\t\tif A._cached is _A:\n\t\t\ttry:A._cached=A.raw.read()\n\t\t\tfinally:A.raw.close();A.raw=_A\n\t\treturn A._cached\n\t@property\n\tdef text(self):return str(self.content,self.encoding)\n\tdef json(A):import ujson;return ujson.loads(A.content)\nHEADERS_TO_IGNORE=_E,\ntry:import js\nexcept Exception as err:raise OSError('This version of urequests can only be used in the browser')\nHEADERS_TO_IGNORE=_E,\ndef request(method,url,data=_A,json=_A,headers={},stream=_A,auth=_A,timeout=_A,parse_headers=_D):\n\tE=timeout;D=method;C=data;from js import XMLHttpRequest as G;A=G.new();A.withCredentials=_C\n\tif auth is not _A:import ubinascii;H,I=auth;A.open(D,url,_C,H,I)\n\telse:A.open(D,url,_C)\n\tfor(F,J)in headers.items():\n\t\tif F.lower()not in HEADERS_TO_IGNORE:A.setRequestHeader(F,J)\n\tif E:A.timeout=int(E*1000)\n\tif json is not _A:assert C is _A;import ujson;C=ujson.dumps(json);A.setRequestHeader('Content-Type','application/json')\n\tA.send(C);B=Response(StringIO(A.responseText));B.status_code=A.status;B.reason=A.statusText;B.headers=A.getAllResponseHeaders();return B\ndef get(url,**A):return request('GET',url,**A)\n_PACKAGE_INDEX=const('https://micropython.org/pi/v2')\n_CHUNK_SIZE=128\ndef _ensure_path_exists(path):\n\timport os;A=path.split(_B)\n\tif not A[0]:A.pop(0);A[0]=_B+A[0]\n\tB=''\n\tfor C in range(len(A)-1):\n\t\tB+=A[C]\n\t\ttry:os.stat(B)\n\t\texcept:os.mkdir(B)\n\t\tB+=_B\ndef _chunk(src,dest):\n\tA=memoryview(bytearray(_CHUNK_SIZE))\n\twhile _D:\n\t\tB=src.readinto(A)\n\t\tif B==0:break\n\t\tdest(A if B==_CHUNK_SIZE else A[:B])\ndef _check_exists(path,short_hash):\n\tA=short_hash;import os\n\ttry:\n\t\timport binascii as C,hashlib as D\n\t\twith open(path,'rb')as E:B=D.sha256();_chunk(E,B.update);F=str(C.hexlify(B.digest())[:len(A)],'utf-8');return F==A\n\texcept:return _C\ndef _rewrite_url(url,branch=_A):\n\tB=branch;A=url\n\tif not B:B='HEAD'\n\tif A.startswith(_F):A=A[7:].split(_B);A='https://raw.githubusercontent.com/'+A[0]+_B+A[1]+_B+B+_B+_B.join(A[2:])\n\treturn A\ndef _download_file(url,dest):\n\tB=dest;A=get(url)\n\ttry:\n\t\tif A.status_code!=200:print('Error',A.status_code,'requesting',url);return _C\n\t\tprint('Copying:',B);_ensure_path_exists(B)\n\t\twith open(B,'wb')as C:_chunk(A.raw,C.write)\n\t\treturn _D\n\tfinally:A.close()\ndef _install_json(package_json_url,index,target,version,mpy):\n\tK='File not found: {} {}';I=version;H=index;G=package_json_url;D=target;E=get(_rewrite_url(G,I))\n\ttry:\n\t\tif E.status_code!=200:print('Package not found:',G);return _C\n\t\tF=E.json()\n\tfinally:E.close()\n\tfor(A,C)in F.get('hashes',()):\n\t\tB=D+_B+A\n\t\tif _check_exists(B,C):print('Exists:',B)\n\t\telse:\n\t\t\tL='{}/file/{}/{}'.format(H,C[:2],C)\n\t\t\tif not _download_file(L,B):print(K.format(A,C));return _C\n\tfor(A,J)in F.get('urls',()):\n\t\tB=D+_B+A\n\t\tif not _download_file(_rewrite_url(J,I),B):print(K.format(A,J));return _C\n\tfor(M,N)in F.get('deps',()):\n\t\tif not _install_package(M,H,D,N,mpy):return _C\n\treturn _D\ndef _install_package(package,index,target,version,mpy):\n\tD=index;C=target;B=version;A=package\n\tif A.startswith('http://')or A.startswith('https://')or A.startswith(_F):\n\t\tif A.endswith('.py')or A.endswith('.mpy'):print('Downloading {} to {}'.format(A,C));return _download_file(_rewrite_url(A,B),C+_B+A.rsplit(_B)[-1])\n\t\telse:\n\t\t\tif not A.endswith('.json'):\n\t\t\t\tif not A.endswith(_B):A+=_B\n\t\t\t\tA+='package.json'\n\t\t\tprint('Installing {} to {}'.format(A,C))\n\telse:\n\t\tif not B:B='latest'\n\t\tprint('Installing {} ({}) from {} to {}'.format(A,B,D,C));E=sys.implementation._mpy&255 if mpy and hasattr(sys.implementation,'_mpy')else'py';A='{}/package/{}/{}/{}.json'.format(D,'py',A,B)\n\treturn _install_json(A,D,C,B,mpy)\ndef install(package,index=_A,target=_A,version=_A,mpy=_D):\n\tB=target;A=index\n\tif not B:\n\t\tfor C in sys.path:\n\t\t\tif C.endswith('/lib'):B=C;break\n\t\telse:print('Unable to find lib dir in sys.path');return\n\tif not A:A=_PACKAGE_INDEX\n\tif _install_package(package,A.rstrip(_B),B,version,mpy):print('Done')\n\telse:print('Package may be partially installed')");const Yt=async e=>(await import("./toml-DiUM0_qs.js")).parse(e),Vt=(e,t)=>{try{e.mkdir(t)}catch(e){}};var Zt={type:"micropython",module:(e="1.24.0-preview-114")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,n,r){const{stderr:s,stdout:o,get:a}=We({stderr:Ne(console.error),stdout:Ne(console.log)});n=n.replace(/\.m?js$/,".wasm");const i=await a(e({linebuffer:!1,stderr:s,stdout:o,url:n})),c=Qt.bind(this,i,r);return Ut.set(i,c),t.files&&await Rt(this,i,t.files,r),t.fetch&&await Pt(this,i,t.fetch,r),t.js_modules&&await Ot(t.js_modules,r),this.writeFile(i,"./mip.py",Xt),t.packages&&await c(t.packages),i},registerJSModule:qt,run:zt,runAsync:Kt,runEvent:Gt,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=Lt(t,r);if(c){const r=t.slice(0,-1);switch("./"!==r&&s.mkdir(r),c){case"whl":case"zip":{const e=new Blob([n],{type:"application/zip"});return import("./zip-DrwYHuF9.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)Vt(s,i);else{Vt(s,o.dirname(i));const t=await e.getData(new n);s.writeFile(i,t,{canOwn:!0})}}i.close()}))}case"tgz":case"tar.gz":{const t="./_.tar.gz";return kt(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 kt(i,t,n)}};async function Qt(e,t,n){let r;for(const s of n)if(s.endsWith(".whl")){const n=at(s,t),r=await o(n).arrayBuffer();await this.writeFile(e,"./*",r,n)}else r||(r=e.pyimport("mip")),r.install(s)}const en={dict_converter:Object.fromEntries};let tn=!1;const nn=e=>(...t)=>{try{return tn=!0,e(...t)}finally{tn=!1}};let rn=!1;const sn=()=>{if(rn)return;rn=!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,r){Et||"auto"!==t.experimental_create_proxy||sn();const{stderr:s,stdout:o,get:a}=We(),i=n.slice(0,n.lastIndexOf("/")),c=await a(e({stderr:s,stdout:o,indexURL:i})),l=cn.bind(c);return Ut.set(c,l),t.files&&await Rt(this,c,t.files,r),t.fetch&&await Pt(this,c,t.fetch,r),t.js_modules&&await Ot(t.js_modules,r),t.packages&&await l(t.packages),c},registerJSModule:qt,run:nn(zt),runAsync:nn(Kt),runEvent:nn(Gt),transform:(e,t)=>an.call(e,t),writeFile:(e,t,n,r)=>{const s=Lt(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 kt({FS:o,PATH:a,PATH_FS:i},t,n)}};function an(e){const{ffi:{PyProxy:t}}=this;if(e&&"object"==typeof e){if(e instanceof t)return e.toJs(en);if(e instanceof Map)return new Map([...e.entries()]);if(Ze(e))return e.map(an,this)}return e}async function cn(e){await this.loadPackage("micropip");const t=this.pyimport("micropip");await t.install(e,{keep_going:!0}),t.destroy()}const ln="ruby-wasm-wasi",un=ln.replace(/\W+/g,"_");var pn={type:ln,experimental:!0,module:(e="2.6.2")=>`https://cdn.jsdelivr.net/npm/@ruby/3.2-wasm-wasi@${e}/dist/browser/+esm`,async engine({DefaultRubyVM:e},t,n,r){n=n.replace(/\/browser\/\+esm$/,"/ruby.wasm");const s=await o(n).arrayBuffer(),a=await WebAssembly.compile(s),{vm:i}=await e(a);return t.files&&await Rt(this,i,t.files,r),t.fetch&&await Pt(this,i,t.fetch,r),t.js_modules&&await Ot(t.js_modules,r),i},registerJSModule(e,t,n){t=t.replace(/\W+/g,"__");const r=`__module_${un}_${t}`;globalThis[r]=n,this.run(e,`require "js";$${t}=JS.global[:${r}]`),delete globalThis[r]},run:(e,t,...n)=>e.eval(Ye(t),...n),runAsync:(e,t,...n)=>e.evalAsync(Ye(t),...n),async runEvent(e,t,n){if(/^xworker\.(on\w+)$/.test(t)){const{$1:t}=RegExp,r=`__module_${un}_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 ${ln}`)}};var fn={type:"wasmoon",module:(e="1.16.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},n,r,s){const{stderr:o,stdout:a,get:i}=We(),c=await i((new e).createEngine());return c.global.getTable(t.Base,(e=>{c.global.setField(e,"print",a),c.global.setField(e,"printErr",o)})),n.files&&await Rt(this,c,n.files,s),n.fetch&&await Pt(this,c,n.fetch,s),n.js_modules&&await Ot(n.js_modules,s),c},registerJSModule:(e,t,n)=>{e.global.set(t,n)},run:(e,t,...n)=>{try{return e.doStringSync(Ye(t),...n)}catch(t){De.get(e).stderr(t)}},runAsync:async(e,t,...n)=>{try{return await e.doString(Ye(t),...n)}catch(t){De.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){De.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,n)=>((e,t,n)=>(xt(e,jt(t)),t=$t(e,t),e.writeFile(t,new Uint8Array(n),{canOwn:!0})))(e,t,n)};const dn=new WeakMap,hn=async(e,t)=>{const{shelter:n,destroy:r,io:s}=dn.get(e),{output:o,result:a}=await n.captureR(Ye(t));for(const{type:e,data:t}of o)s[e](t);return Be(a,r,{token:!1})};var yn={type:"webr",experimental:!0,module:(e="0.4.1")=>`https://cdn.jsdelivr.net/npm/webr@${e}/dist/webr.mjs`,async engine(e,t,n,r){const{get:s}=We(),o=new e.WebR;await s(o.init().then((()=>o)));const a=await new o.Shelter;return dn.set(o,{module:e,shelter:a,destroy:a.destroy.bind(a),io:De.get(o)}),t.files&&await Rt(this,o,t.files,r),t.fetch&&await Pt(this,o,t.fetch,r),t.js_modules&&await Ot(t.js_modules,r),o},registerJSModule(e,t){console.warn(`Experimental interpreter: module ${t} is not supported (yet)`)},run:hn,runAsync:hn,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 wn=new Map,gn=new Map,mn=[],_n=[],An=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[n,...r]=t.split("@"),s=wn.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=>(gn.set(t,e),s(r,e,n,o))))}}),bn=e=>{for(const t of[].concat(e.type))wn.set(t,e),mn.push(`script[type="${t}"]`),_n.push(`${t}-`)};for(const e of[qe,Zt,on,pn,fn,yn])bn(e);const{parse:vn}=JSON,En=(e,t="./config.txt")=>{let n=typeof e;return"string"===n&&/\.(json|toml|txt)$/.test(e)?n=RegExp.$1:e=t,[at(e),n]},kn=(e,t,n={})=>{const[r,s]=En(e,t);return"json"===s?n=o(r).json():"toml"===s?n=o(r).text().then(Yt):"string"===s?n=jn(e):"object"===s&&e?n=e:"txt"===s&&"string"==typeof n&&(n=jn(n)),[n,e=r]},jn=e=>{try{return vn(e)}catch(t){return Yt(e)}},xn=(e,t,n,r={})=>(t&&([r,t]=kn(t,n,r)),ot(r).then((n=>An[e](n,t)))),$n=(e,t="")=>`${e}@${t}`.replace(/@$/,"");function Sn(e=this){return String(e).replace(/^(async\s*)?(\bfunction\b)?(.*?)\(/,((e,t,n,r)=>r&&!n?`${t||""}function ${r}(`:e))}const Bn="BeforeRun",Pn="AfterRun",Tn=[`code${Bn}`,`code${Bn}Async`,`code${Pn}`,`code${Pn}Async`],Mn=["onWorker","onReady",`on${Bn}`,`on${Bn}Async`,`on${Pn}`,`on${Pn}Async`];function Rn(e,t){const{run:n,runAsync:r}=wn.get(this.type);return{...e,run:n.bind(this,t),runAsync:r.bind(this,t)}}const On=(e,t,n,r,s,o)=>{if(s||o){const a=Rn.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 Fn=class{constructor(e,t={}){const{main:n,worker:r}=t;this.interpreter=e,this.onWorker=n?.onWorker;for(const e of Mn.slice(1))this[e]=r?.[e];for(const e of Tn)this[e]=r?.[e]}toJSON(){const e={};for(const t of Mn.slice(1))this[t]&&(e[t]=Sn(this[t]));for(const t of Tn)this[t]&&(e[t]=Ye(this[t]()));return e}};var Cn=(...e)=>function(t,n){if(e.length){const[t,r]=e;(n=Qe({},n||{type:t,version:r})).type||(n.type=t)}const[r]=En(n.config,n.configURL),s=((...e)=>new Ce(URL.createObjectURL(new Blob(['const t="object"==typeof self?self:globalThis,e=e=>((e,n)=>{const r=(t,n)=>(e.set(n,t),t),s=o=>{if(e.has(o))return e.get(o);const[a,i]=n[o];switch(a){case 0:case-1:return r(i,o);case 1:{const t=r([],o);for(const e of i)t.push(s(e));return t}case 2:{const t=r({},o);for(const[e,n]of i)t[s(e)]=s(n);return t}case 3:return r(new Date(i),o);case 4:{const{source:t,flags:e}=i;return r(new RegExp(t,e),o)}case 5:{const t=r(new Map,o);for(const[e,n]of i)t.set(s(e),s(n));return t}case 6:{const t=r(new Set,o);for(const e of i)t.add(s(e));return t}case 7:{const{name:e,message:n}=i;return r(new t[e](n),o)}case 8:return r(BigInt(i),o);case"BigInt":return r(Object(BigInt(i)),o)}return r(new t[a](i),o)};return s})(new Map,e)(0),n="",{toString:r}={},{keys:s}=Object,o=t=>{const e=typeof t;if("object"!==e||!t)return[0,e];const s=r.call(t).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=([t,e])=>0===t&&("function"===e||"symbol"===e),i=(t,{json:e,lossy:n}={})=>{const r=[];return((t,e,n,r)=>{const i=(t,e)=>{const s=r.push(t)-1;return n.set(e,s),s},c=r=>{if(n.has(r))return n.get(r);let[l,u]=o(r);switch(l){case 0:{let e=r;switch(u){case"bigint":l=8,e=r.toString();break;case"function":case"symbol":if(t)throw new TypeError("unable to serialize "+u);e=null;break;case"undefined":return i([-1],r)}return i([l,e],r)}case 1:{if(u)return i([u,[...r]],r);const t=[],e=i([l,t],r);for(const e of r)t.push(c(e));return e}case 2:{if(u)switch(u){case"BigInt":return i([u,r.toString()],r);case"Boolean":case"Number":case"String":return i([u,r.valueOf()],r)}if(e&&"toJSON"in r)return c(r.toJSON());const n=[],p=i([l,n],r);for(const e of s(r))!t&&a(o(r[e]))||n.push([c(e),c(r[e])]);return p}case 3:return i([l,r.toISOString()],r);case 4:{const{source:t,flags:e}=r;return i([l,{source:t,flags:e}],r)}case 5:{const e=[],n=i([l,e],r);for(const[n,s]of r)(t||!a(o(n))&&!a(o(s)))&&e.push([c(n),c(s)]);return n}case 6:{const e=[],n=i([l,e],r);for(const n of r)!t&&a(o(n))||e.push(c(n));return n}}const{message:p}=r;return i([l,{name:u,message:p}],r)};return c})(!(e||n),!!e,new Map,r)(t),r},{parse:c,stringify:l}=JSON,u={json:!0,lossy:!0};var p=Object.freeze({__proto__:null,parse:t=>e(c(t)),stringify:t=>l(i(t,u))});const f="array",d="function",h="null",y="number",w="object",g="symbol",m="undefined",_="apply",A="construct",b="defineProperty",E="deleteProperty",v="get",j="getOwnPropertyDescriptor",x="getPrototypeOf",k="has",S="isExtensible",$="ownKeys",B="preventExtensions",P="set",T="setPrototypeOf";var O=Object.freeze({__proto__:null,APPLY:_,CONSTRUCT:A,DEFINE_PROPERTY:b,DELETE_PROPERTY:E,GET:v,GET_OWN_PROPERTY_DESCRIPTOR:j,GET_PROTOTYPE_OF:x,HAS:k,IS_EXTENSIBLE:S,OWN_KEYS:$,PREVENT_EXTENSION:B,SET:P,SET_PROTOTYPE_OF:T});function R(){return this}const M=new FinalizationRegistry((([t,e,n])=>{n&&console.debug(`Held value ${String(e)} not relevant anymore`),t(e)})),F=Object.create(null),{Object:C,Proxy:D,Reflect:I}=globalThis,{isArray:W}=Array,{ownKeys:H}=I,{create:N,hasOwn:J,values:q}=C,z=(t,e)=>e===f?t[0]:e===d?t():e===w?t.$:t,U=(t,e,n,r)=>{const s={type:{value:e}},o=J(t,"valueOf");for(const a of q(O)){let i=r(t[a]||I[a]);if(o&&a===v){const{valueOf:r}=t,{value:s}=i;i={value(t,o,...a){return o===n?r.call(this,z(t,e)):s.call(this,t,o,...a)}}}s[a]=i}return N(t,s)},L=(t,e,n,r=t)=>{if(r===t)switch(typeof t){case w:case m:r||(r=!1);case d:break;default:r=!1,e===t&&(e=C(t))}const s=new D(e,n),{destruct:o}=n;return o?((t,e,{debug:n,handler:r,return:s,token:o=t}=F)=>{const a=s||new Proxy(t,r||F),i=[a,[e,t,!!n]];return!1!==o&&i.push(o),M.register(...i),a})(t,o,{token:r,return:s}):s},K=t=>e=>{const n=typeof e;return n===w?e?t.get(e)?.[0]??(t=>W(t)?f:w)(e):h:n},G=t=>e=>{let n=typeof e;switch(n){case w:if(!e){n=h;break}case d:const r=t.get(e);r&&([n,e]=r)}return[n,e]},Y=t=>((t=>{M.unregister(t)})(t),t);var X=t=>{const e=new WeakMap,n=Symbol(),r={},s=(t,n,r)=>(e.set(t,[n,r]),t),o={proxy:r,release:Y,pair:G(e),typeOf:K(e),isProxy:t=>e.has(t),valueOf:t=>t[n]??t.valueOf()};for(const e of H(t)){if(J(o,e))continue;const a=t[e];switch(e){case f:{const t=U(a,e,n,(t=>({value([e],...n){return t.call(this,e,...n)}})));r[e]=(e,...n)=>s(L(e,[e],t,...n),f,e);break}case d:{const t=U(a,e,n,(t=>({value(e,...n){return t.call(this,e(),...n)}})));r[e]=(e,...n)=>{return s(L(e,(r=e,R.bind(r)),t,...n),d,e);var r};break}case w:{const t=U(a,e,n,(t=>({value({$:e},...n){return t.call(this,e,...n)}})));r[e]=(e,...n)=>s(L(e,{$:e},t,...n),w,e);break}default:{const t=U(a,e,n,(t=>({value:t})));r[e]=(n,...r)=>s(L(n,n,t,...r),e,n);break}}}return o};let Z=0;const V=new Map,Q=new Map,tt=t=>Q.get(t),et=t=>{if(!V.has(t)){let e;for(;Q.has(e=Z++););V.set(t,e),Q.set(e,t)}return V.get(t)},{ArrayBuffer:nt,Atomics:rt,Promise:st}=globalThis,{isArray:ot}=Array,{create:at,getPrototypeOf:it,values:ct}=Object,lt=it(Int32Array),ut=at(rt),pt=({currentTarget:t,type:e,origin:n,lastEventId:r,source:s,ports:o},a)=>t.dispatchEvent(new MessageEvent(e,{data:a,origin:n,lastEventId:r,source:s,ports:o})),ft=()=>st.withResolvers();let dt=0;const ht=new Map,yt=(t,e)=>class extends t{constructor(t,...n){super(t,...n),t instanceof e&&ht.set(this,[dt++,0,ft()])}},wt=new WeakSet,gt=t=>(wt.add(t),t),mt=(t,e)=>{const{data:n}=t,r=ot(n)&&(n.at(0)===e||0===n.at(1)&&!e);return r&&(t.stopImmediatePropagation(),t.preventDefault()),r},_t=t=>null!==t&&"object"==typeof t&&!wt.has(t),At=new WeakMap,bt=(t,e,n)=>{if(ht.has(t))e.set(t,ht.get(t)[0]);else if(!(t instanceof lt||t instanceof nt))for(const r of ct(t))_t(r)&&!n.has(r)&&(n.add(r),bt(r,e,n))},Et=(...t)=>({value:new st((e=>{let n=new Worker("data:application/javascript,onmessage%3De%3D%3EpostMessage(!Atomics.wait(...e.data))");n.onmessage=()=>e("ok"),n.postMessage(t)}))}),vt=(t,e)=>{const n=ht.get(t),[r,s,{promise:o}]=n;return n[1]=e,[r,o]};let{BigInt64Array:jt,Int32Array:xt,SharedArrayBuffer:kt,addEventListener:St,postMessage:$t}=globalThis,Bt=!0,Pt=t=>t,Tt=!1;const Ot=ft();try{new kt(4),ut.waitAsync||(ut.waitAsync=Et),Ot.resolve()}catch(t){const e=$t,n=St,r=[];let s="",o="";kt=class extends nt{},jt=yt(jt,kt),xt=yt(xt,kt),Pt=gt,Tt=!0,ut.notify=(t,n)=>{const[r]=(t=>At.get(t))(t);return e([s,1,t,r,n]),0},ut.waitAsync=(...t)=>{const[e,n]=vt(...t);return{value:n}},ut.wait=(t,e,...n)=>{const[r]=vt(t,e,...n),a=new XMLHttpRequest;a.responseType="json",a.open("POST",`${o}?sabayon`,!1),a.setRequestHeader("Content-Type","application/json"),a.send(`["${s}",${r},${e}]`);const{response:i}=a;ht.delete(t);for(let e=0;e{if(mt(t,s)){const[e,n,...r]=t.data;switch(n){case 0:s=e,o=r.at(0)?.serviceWorker||"",o||(ut.wait=null,Ot.resolve());break;case 1:((t,e,n)=>{for(const[r,[s,o,{resolve:a}]]of ht)if(e===s&&n===o){for(let e=0;e{for(const[n,r]of e)At.set(n,[r,t.currentTarget]);pt(t,n)})(t,...r);break;case 3:Ot.resolve()}}else if(Bt){const{currentTarget:e,type:n,origin:s,lastEventId:o,source:a,ports:i}=t;r.push([{currentTarget:e,type:n,origin:s,lastEventId:o,source:a,ports:i},t.data])}})),St=(t,...e)=>{if(n(t,...e),r.length)for(const t of r.splice(0))pt(...t)},$t=(t,...n)=>e(((t,e)=>{const n=new Map;return _t(e)&&bt(e,n,new Set),n.size?[t,2,n,e]:e})(s,t),...n)}await Ot.promise,Bt=!1;const{BYTES_PER_ELEMENT:Rt}=Int32Array,{BYTES_PER_ELEMENT:Mt}=Uint16Array,{notify:Ft}=ut,Ct=new TextDecoder("utf-16"),Dt=new WeakSet,It=(...t)=>(Dt.add(t),t);let Wt="";const Ht=(t,e,n,r)=>{const[s]=r,o=n.get(s);if(!o)throw new Error(`Unknown proxy.${s}()`);t(o,e,r)};let Nt=0;const Jt=([t,e,n,r,s,o,a,i,c],l)=>(...u)=>{let p=""!==Wt,f=0;p&&"="!==Wt[0]&&"-"!==Wt[0]&&(f=((t,e)=>setTimeout(console.warn,3e3,`💀🔒 - proxy.${t}() in proxy.${e}()`))(l,Wt));const d=Nt++,h=[];Dt.has(u.at(-1)||h)&&Dt.delete(h=u.pop());const y=n(i?u.map(i):u);let w=e(2*Rt);return a([t,2,l,d,w,y,r],{transfer:h}),c(w,0).value.then((()=>{p&&clearTimeout(f);const n=w[1];if(!n)return;const r=Mt*n;return w=e(r+r%Rt),a([t,1,d,w]),c(w,0).value.then((()=>{const t=new Uint16Array(w.buffer),e=o?t.subarray(0,n):t.slice(0,n);return s(Ct.decode(e))}))}))},qt=(t,e)=>new Proxy(e,{get:(e,n)=>{let r;return"then"!==n&&(r=e.get(n),r||(r=Jt(t,n),e.set(n,r))),r},set:(t,e,n)=>"then"!==e&&!!t.set(e,n)}),{wait:zt,waitAsync:Ut}=ut;var Lt=({parse:t,stringify:e,transform:n,interrupt:r}=JSON)=>{const s=((t,e)=>async(n,r,[s,o,a,i,c])=>{c&&(Wt=s);try{const s=await n(...i);if(void 0!==s){const n=t(e?e(s):s);r.set(o,n),a[1]=n.length}}finally{c&&(Wt=""),a[0]=1,Ft(a,0)}})(e,n),o=ft(),a=new Map,i=new Map;let c="",l=zt;if(zt&&r){const{handler:t,timeout:e=42}=r;l=(n,r,s)=>{for(;"timed-out"===(s=zt(n,r,0,e));)t();return s}}return St("message",(e=>{if(mt(e,c)){const[r,u,...p]=e.data;switch(u){case 0:{const e=!!zt;c=r,o.resolve({polyfill:Tt,sync:e,transfer:It,proxy:qt([c,t=>new xt(new kt(t)),Pt,e,t,Tt,$t,n,e?(...t)=>({value:{then:e=>e(l(...t))}}):Ut],a)});break}case 2:a.size?Ht(s,i,a,p):setTimeout(Ht,0,s,i,a,p);break;case 1:((t,[e,n])=>{const r=t.get(e);t.delete(e);for(let t=new Uint16Array(n.buffer),e=0,{length:s}=r;e[t,e])));const Gt="destruct",{[$]:Yt}=Reflect,Xt=new Map(Yt(Symbol).filter((t=>typeof Symbol[t]===g)).map((t=>[Symbol[t],t]))),Zt=t=>Xt.get(t)||`.${Symbol.keyFor(t)||""}`,Vt="960fd6fe-ad03-40d1-a314-e58d84bce14f",Qt="="+Vt,te="-"+Vt,{[_]:ee}=Reflect;const ne={object(...t){return this.string(function(t){for(var e=t[0],n=1,r=arguments.length;n{const e=t||console,n={buffered:ae,stderr:(e.stderr||console.error).bind(e),stdout:(e.stdout||console.log).bind(e)};return{stderr:(...t)=>n.stderr(...t),stdout:(...t)=>n.stdout(...t),async get(t){const e=await t;return re.set(e,n),e}}},oe=new TextDecoder,ae=(t,e=10)=>{const n=[];return r=>{if(r instanceof Uint8Array)for(const s of r)s===e?t(oe.decode(new Uint8Array(n.splice(0)))):n.push(s);else t(r)}},ie=(t,...e)=>ne[typeof t](t,...e),{isArray:ce}=Array,{assign:le,create:ue,defineProperties:pe,defineProperty:fe,entries:de}=Object,{all:he,resolve:ye}=new Proxy(Promise,{get:(t,e)=>t[e].bind(t)}),we=(t,e=location.href)=>new URL(t,e.replace(/^blob:/,"")).href,ge=(t,e,n,r=!1,s=CustomEvent)=>{t.dispatchEvent(new s(`${e}:${n}`,{bubbles:!0,detail:{worker:r}}))},me=t=>Function(`\'use strict\';return (${t})`)(),_e=t=>t.replace(/^(?:\\n|\\r\\n)/,""),Ae=Symbol.for("polyscript.js_modules"),be=new Map;fe(globalThis,Ae,{value:be}),new Proxy(be,{get:(t,e)=>t.get(e),has:(t,e)=>t.has(e),ownKeys:t=>[...t.keys()]});const Ee=(t,e)=>!e.startsWith("_"),ve=(t,e)=>new Proxy(t,{has:Ee,get:(t,n)=>t[e][n]}),je=(t,e)=>import(t).then((t=>{be.set(e,{...t})})),xe=t=>new Promise(((e,n)=>{document.querySelector(`link[rel="stylesheet"][href="${t}"]`)?e():document.head.append(le(document.createElement("link"),{rel:"stylesheet",href:t,onload:e,onerror:n}))})),ke=t=>/\\.css$/i.test(new URL(t).pathname),Se=(t,e)=>t.has(e),$e=t=>[...t.keys()];var Be=(t,e,n,r)=>{const s=globalThis[Ae];if(n)for(let[t,e]of de(n)){let n=s.get(e);n&&!ce(n)||(s.set(e,n||(n=[])),n.push(t))}return((t,e,n,r)=>new Proxy(t,{has:Se,ownKeys:$e,get:(t,s)=>{let o=t.get(s);if(ce(o)){let a=o;o=null;for(let t of a)t=we(t,r),ke(t)?n.importCSS(t):(n.importJS(t,s),o=e[Ae].get(s));t.set(s,o)}return o}}))(s,t,e,r)};const Pe=new Map,Te=t=>Pe.get(t),Oe=(t,e)=>{try{return Function("require",e)(Te)}catch(e){re.get(t).stderr(e)}};var Re={type:"dummy",module:()=>"data:application/javascript,",engine:t=>se().get(t),registerJSModule(t,e,n){Pe.set(e,n)},run:Oe,runAsync:Oe,runEvent:async(t,e,n)=>{try{await Function("require","e",`return ${e}(e)`)(Te,n)}catch(e){re.get(t).stderr(e)}},transform:(t,e)=>e,writeFile(){}};const Me=Object.getOwnPropertyDescriptors(Response.prototype),Fe=t=>"function"==typeof t,Ce={get:(t,e)=>Me.hasOwnProperty(e)?((t,e,{get:n,value:r})=>n||!Fe(r)?t.then((t=>t[e])):(...n)=>t.then((t=>t[e](...n))))(t,e,Me[e]):((t,e)=>Fe(e)?e.bind(t):e)(t,t[e])};var De=(t,...e)=>new Proxy(fetch(t,...e),Ce);Promise.withResolvers||(Promise.withResolvers=function(){var t,e,n=new this((function(n,r){t=n,e=r}));return{resolve:t,reject:e,promise:n}});const Ie=!globalThis.window,We=({FS:t,PATH:e,PATH_FS:n},r,s)=>{const o=n.resolve(r),a=e.dirname(o);return t.mkdirTree?t.mkdirTree(a):Ne(t,a),t.writeFile(o,new Uint8Array(s),{canOwn:!0})},He=t=>{const e=t.split("/");return e.pop(),e.join("/")},Ne=(t,e)=>{const n=[];for(const r of e.split("/"))"."!==r&&".."!==r&&(n.push(r),r&&t.mkdir(n.join("/")))},Je=(t,e)=>{const n=[];for(const t of e.split("/"))switch(t){case"":case".":break;case"..":n.pop();break;default:n.push(t)}return[t.cwd()].concat(n).join("/").replace(/^\\/+/,"/")},qe=t=>{const e=t.map((t=>t.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((t=>""!==t&&"."!==t)).join("/");return t[0].startsWith("/")?`/${e}`:e},ze=(t,e)=>De(we(t,e)).arrayBuffer(),Ue=(t,e,n,r)=>he((t=>{for(const{files:e,to_file:n,from:r=""}of t){if(void 0!==e&&void 0!==n)throw new Error("Cannot use \'to_file\' and \'files\' parameters together!");if(void 0===e&&void 0===n&&r.endsWith("/"))throw new Error(`Couldn\'t determine the filename from the path ${r}, please supply \'to_file\' parameter.`)}return t.flatMap((({from:t="",to_folder:e=".",to_file:n,files:r})=>{if(ce(r))return r.map((n=>({url:qe([t,n]),path:qe([e,n])})));const s=n||t.slice(1+t.lastIndexOf("/"));return[{url:t,path:qe([e,s])}]}))})(n).map((({url:n,path:s})=>ze(n,r).then((n=>t.writeFile(e,s,n)))))),Le=(t,e)=>e.endsWith("/")?`${e}${t.split("/").pop()}`:e,Ke=(t,e)=>t.replace(/\\{.+?\\}/g,(t=>{if(!e.has(t))throw new SyntaxError(`Invalid template: ${t}`);return e.get(t)})),Ge=(t,e,n,r)=>he((t=>{const e=new Map,n=new Set,r=[];for(const[s,o]of de(t))if(/^\\{.+\\}$/.test(s)){if(e.has(s))throw new SyntaxError(`Duplicated template: ${s}`);e.set(s,Ke(o,e))}else{const t=Ke(s,e),a=Le(t,Ke(o||"./",e));if(n.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);n.add(a),r.push({url:t,path:a})}return r})(n).map((({url:n,path:s})=>ze(n,r).then((r=>t.writeFile(e,s,r,n)))))),Ye=({main:t,worker:e},n)=>{const r=[];if(e&&Ie)for(let[t,s]of de(e))t=we(t,n),r.push(je(t,s));if(t&&!Ie)for(let[e,s]of de(t))e=we(e,n),ke(e)?xe(e):r.push(je(e,s));return he(r)},{assign:Xe}=Object,Ze="entries",Ve="readonly",Qe="readwrite",tn={durability:"default",prefix:"IDBMap"},en=({target:{result:t}})=>t;class nn extends EventTarget{#t;#e;#n;async#r(t,e){const n=(await this.#t).transaction(Ze,e,this.#e);return new Promise(((e,r)=>Xe(t(n.objectStore(Ze)),{onsuccess:e,onerror:r})))}constructor(t,{durability:e=tn.durability,prefix:n=tn.prefix}=tn){super(),this.#n=n,this.#e={durability:e},this.#t=new Promise(((e,n)=>{Xe(indexedDB.open(`${this.#n}/${t}`),{onupgradeneeded({target:{result:t,transaction:n}}){t.objectStoreNames.length||t.createObjectStore(Ze),n.oncomplete=()=>e(t)},onsuccess(t){e(en(t))},onerror(t){n(t),this.dispatchEvent(t)}})})).then((t=>{const e=this.dispatchEvent.bind(this);for(const n in t)n.startsWith("on")&&(t[n]=e);return t}))}dispatchEvent(t){const{type:e,message:n,isTrusted:r}=t;return super.dispatchEvent(r?Xe(new Event(e),{message:n}):t)}async close(){(await this.#t).close()}get size(){return this.#r((t=>t.count()),Ve).then(en)}async clear(){await this.#r((t=>t.clear()),Qe)}async delete(t){await this.#r((e=>e.delete(t)),Qe)}async entries(){const t=await this.keys();return Promise.all(t.map((t=>this.get(t).then((e=>[t,e])))))}async forEach(t,e=this){for(const[n,r]of await this.entries())await t.call(e,r,n,this)}async get(t){return await this.#r((e=>e.get(t)),Ve).then(en)}async has(t){return void 0!==await this.#r((e=>e.getKey(t)),Ve).then(en)}async keys(){return await this.#r((t=>t.getAllKeys()),Ve).then(en)}async set(t,e){return await this.#r((n=>n.put(e,t)),Qe),this}async values(){const t=await this.keys();return Promise.all(t.map((t=>this.get(t))))}get[Symbol.toStringTag](){return this.#n}}class rn extends Map{#s;#o;constructor(...t){super(),this.#s=new nn(...t),this.#o=this.#s.entries().then((t=>{for(const[e,n]of t)super.set(e,n)}))}async sync(){await this.#o}clear(){return this.#o=this.#o.then((()=>this.#s.clear())),super.clear()}delete(t){return this.#o=this.#o.then((()=>this.#s.delete(t))),super.delete(t)}set(t,e){return this.#o=this.#o.then((()=>this.#s.set(t,e))),super.set(t,e)}}const sn=new WeakMap,on=(t,e,n)=>{"polyscript"===e&&(n.lazy_py_modules=async(...e)=>(await sn.get(t)(e),e.map((e=>t.pyimport(e)))),n.storage=async t=>{const e=new rn(t);return await e.sync(),e},n.JSON=p),t.registerJsModule(e,n)},an=(t,e)=>{if(t.endsWith("/*")){if(/\\.(zip|whl|tgz|tar(?:\\.gz)?)$/.test(e))return RegExp.$1;throw new Error(`Unsupported archive ${e}`)}return""},cn=(t,e,...n)=>{try{return t.runPython(ie(e),...n)}catch(e){re.get(t).stderr(e)}},ln=async(t,e,...n)=>{try{return await t.runPythonAsync(ie(e),...n)}catch(e){re.get(t).stderr(e)}},un=async(t,e,n)=>{const[r,...s]=e.split(".");let o,a=t.globals.get(r);for(const t of s)[o,a]=[a,a[t]];try{await a.call(o,n)}catch(e){re.get(t).stderr(e)}};var pn=(new TextEncoder).encode("_F=\'github:\'\\n_E=\'user-agent\'\\n_D=True\\n_C=False\\n_B=\'/\'\\n_A=None\\nfrom uio import StringIO\\nimport sys\\nclass Response:\\n\\tdef __init__(A,f):A.raw=f;A.encoding=\'utf-8\';A._cached=_A\\n\\tdef close(A):\\n\\t\\tif A.raw:A.raw.close();A.raw=_A\\n\\t\\tA._cached=_A\\n\\t@property\\n\\tdef content(self):\\n\\t\\tA=self\\n\\t\\tif A._cached is _A:\\n\\t\\t\\ttry:A._cached=A.raw.read()\\n\\t\\t\\tfinally:A.raw.close();A.raw=_A\\n\\t\\treturn A._cached\\n\\t@property\\n\\tdef text(self):return str(self.content,self.encoding)\\n\\tdef json(A):import ujson;return ujson.loads(A.content)\\nHEADERS_TO_IGNORE=_E,\\ntry:import js\\nexcept Exception as err:raise OSError(\'This version of urequests can only be used in the browser\')\\nHEADERS_TO_IGNORE=_E,\\ndef request(method,url,data=_A,json=_A,headers={},stream=_A,auth=_A,timeout=_A,parse_headers=_D):\\n\\tE=timeout;D=method;C=data;from js import XMLHttpRequest as G;A=G.new();A.withCredentials=_C\\n\\tif auth is not _A:import ubinascii;H,I=auth;A.open(D,url,_C,H,I)\\n\\telse:A.open(D,url,_C)\\n\\tfor(F,J)in headers.items():\\n\\t\\tif F.lower()not in HEADERS_TO_IGNORE:A.setRequestHeader(F,J)\\n\\tif E:A.timeout=int(E*1000)\\n\\tif json is not _A:assert C is _A;import ujson;C=ujson.dumps(json);A.setRequestHeader(\'Content-Type\',\'application/json\')\\n\\tA.send(C);B=Response(StringIO(A.responseText));B.status_code=A.status;B.reason=A.statusText;B.headers=A.getAllResponseHeaders();return B\\ndef get(url,**A):return request(\'GET\',url,**A)\\n_PACKAGE_INDEX=const(\'https://micropython.org/pi/v2\')\\n_CHUNK_SIZE=128\\ndef _ensure_path_exists(path):\\n\\timport os;A=path.split(_B)\\n\\tif not A[0]:A.pop(0);A[0]=_B+A[0]\\n\\tB=\'\'\\n\\tfor C in range(len(A)-1):\\n\\t\\tB+=A[C]\\n\\t\\ttry:os.stat(B)\\n\\t\\texcept:os.mkdir(B)\\n\\t\\tB+=_B\\ndef _chunk(src,dest):\\n\\tA=memoryview(bytearray(_CHUNK_SIZE))\\n\\twhile _D:\\n\\t\\tB=src.readinto(A)\\n\\t\\tif B==0:break\\n\\t\\tdest(A if B==_CHUNK_SIZE else A[:B])\\ndef _check_exists(path,short_hash):\\n\\tA=short_hash;import os\\n\\ttry:\\n\\t\\timport binascii as C,hashlib as D\\n\\t\\twith open(path,\'rb\')as E:B=D.sha256();_chunk(E,B.update);F=str(C.hexlify(B.digest())[:len(A)],\'utf-8\');return F==A\\n\\texcept:return _C\\ndef _rewrite_url(url,branch=_A):\\n\\tB=branch;A=url\\n\\tif not B:B=\'HEAD\'\\n\\tif A.startswith(_F):A=A[7:].split(_B);A=\'https://raw.githubusercontent.com/\'+A[0]+_B+A[1]+_B+B+_B+_B.join(A[2:])\\n\\treturn A\\ndef _download_file(url,dest):\\n\\tB=dest;A=get(url)\\n\\ttry:\\n\\t\\tif A.status_code!=200:print(\'Error\',A.status_code,\'requesting\',url);return _C\\n\\t\\tprint(\'Copying:\',B);_ensure_path_exists(B)\\n\\t\\twith open(B,\'wb\')as C:_chunk(A.raw,C.write)\\n\\t\\treturn _D\\n\\tfinally:A.close()\\ndef _install_json(package_json_url,index,target,version,mpy):\\n\\tK=\'File not found: {} {}\';I=version;H=index;G=package_json_url;D=target;E=get(_rewrite_url(G,I))\\n\\ttry:\\n\\t\\tif E.status_code!=200:print(\'Package not found:\',G);return _C\\n\\t\\tF=E.json()\\n\\tfinally:E.close()\\n\\tfor(A,C)in F.get(\'hashes\',()):\\n\\t\\tB=D+_B+A\\n\\t\\tif _check_exists(B,C):print(\'Exists:\',B)\\n\\t\\telse:\\n\\t\\t\\tL=\'{}/file/{}/{}\'.format(H,C[:2],C)\\n\\t\\t\\tif not _download_file(L,B):print(K.format(A,C));return _C\\n\\tfor(A,J)in F.get(\'urls\',()):\\n\\t\\tB=D+_B+A\\n\\t\\tif not _download_file(_rewrite_url(J,I),B):print(K.format(A,J));return _C\\n\\tfor(M,N)in F.get(\'deps\',()):\\n\\t\\tif not _install_package(M,H,D,N,mpy):return _C\\n\\treturn _D\\ndef _install_package(package,index,target,version,mpy):\\n\\tD=index;C=target;B=version;A=package\\n\\tif A.startswith(\'http://\')or A.startswith(\'https://\')or A.startswith(_F):\\n\\t\\tif A.endswith(\'.py\')or A.endswith(\'.mpy\'):print(\'Downloading {} to {}\'.format(A,C));return _download_file(_rewrite_url(A,B),C+_B+A.rsplit(_B)[-1])\\n\\t\\telse:\\n\\t\\t\\tif not A.endswith(\'.json\'):\\n\\t\\t\\t\\tif not A.endswith(_B):A+=_B\\n\\t\\t\\t\\tA+=\'package.json\'\\n\\t\\t\\tprint(\'Installing {} to {}\'.format(A,C))\\n\\telse:\\n\\t\\tif not B:B=\'latest\'\\n\\t\\tprint(\'Installing {} ({}) from {} to {}\'.format(A,B,D,C));E=sys.implementation._mpy&255 if mpy and hasattr(sys.implementation,\'_mpy\')else\'py\';A=\'{}/package/{}/{}/{}.json\'.format(D,\'py\',A,B)\\n\\treturn _install_json(A,D,C,B,mpy)\\ndef install(package,index=_A,target=_A,version=_A,mpy=_D):\\n\\tB=target;A=index\\n\\tif not B:\\n\\t\\tfor C in sys.path:\\n\\t\\t\\tif C.endswith(\'/lib\'):B=C;break\\n\\t\\telse:print(\'Unable to find lib dir in sys.path\');return\\n\\tif not A:A=_PACKAGE_INDEX\\n\\tif _install_package(package,A.rstrip(_B),B,version,mpy):print(\'Done\')\\n\\telse:print(\'Package may be partially installed\')");const fn=async t=>(await import("./toml-DiUM0_qs.js")).parse(t),dn=(t,e)=>{try{t.mkdir(e)}catch(t){}};var hn={type:"micropython",module:(t="1.24.0-preview-114")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${t}/micropython.mjs`,async engine({loadMicroPython:t},e,n,r){const{stderr:s,stdout:o,get:a}=se({stderr:ae(console.error),stdout:ae(console.log)});n=n.replace(/\\.m?js$/,".wasm");const i=await a(t({linebuffer:!1,stderr:s,stdout:o,url:n})),c=yn.bind(this,i,r);return sn.set(i,c),e.files&&await Ge(this,i,e.files,r),e.fetch&&await Ue(this,i,e.fetch,r),e.js_modules&&await Ye(e.js_modules,r),this.writeFile(i,"./mip.py",pn),e.packages&&await c(e.packages),i},registerJSModule:on,run:cn,runAsync:ln,runEvent:un,transform:(t,e)=>t.PyProxy.toJs(e),writeFile:(t,e,n,r)=>{const{FS:s,_module:{PATH:o,PATH_FS:a}}=t,i={FS:s,PATH:o,PATH_FS:a},c=an(e,r);if(c){const r=e.slice(0,-1);switch("./"!==r&&s.mkdir(r),c){case"whl":case"zip":{const t=new Blob([n],{type:"application/zip"});return import("./zip-DrwYHuF9.js").then((async({BlobReader:e,Uint8ArrayWriter:n,ZipReader:a})=>{const i=new a(new e(t));for(const t of await i.getEntries()){const{directory:e,filename:a}=t,i=r+a;if(e)dn(s,i);else{dn(s,o.dirname(i));const e=await t.getData(new n);s.writeFile(i,e,{canOwn:!0})}}i.close()}))}case"tgz":case"tar.gz":{const e="./_.tar.gz";return We(i,e,n),void t.runPython(`\\n import os, gzip, tarfile\\n tar = tarfile.TarFile(fileobj=gzip.GzipFile(fileobj=open("${e}", "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("${e}")\\n `)}}}return We(i,e,n)}};async function yn(t,e,n){let r;for(const s of n)if(s.endsWith(".whl")){const n=we(s,e),r=await De(n).arrayBuffer();await this.writeFile(t,"./*",r,n)}else r||(r=t.pyimport("mip")),r.install(s)}const wn=new FinalizationRegistry((([t,e,n])=>{n&&console.debug(`%c${String(e)}`,"font-weight:bold","collected"),t(e)})),gn=Object.create(null),mn=(t,e,{debug:n,handler:r,return:s,token:o=t}=gn)=>{const a=s||new Proxy(t,r||gn),i=[a,[e,t,!!n]];return!1!==o&&i.push(o),wn.register(...i),a},_n={dict_converter:Object.fromEntries};let An=!1;const bn=t=>(...e)=>{try{return An=!0,t(...e)}finally{An=!1}};let En=!1;const vn=()=>{if(En)return;En=!0;const t=new WeakMap,e=t=>t.destroy(),n=n=>{for(let r=0;r`https://cdn.jsdelivr.net/pyodide/v${t}/full/pyodide.mjs`,async engine({loadPyodide:t},e,n,r){Ie||"auto"!==e.experimental_create_proxy||vn();const{stderr:s,stdout:o,get:a}=se(),i=n.slice(0,n.lastIndexOf("/")),c=await a(t({stderr:s,stdout:o,indexURL:i})),l=kn.bind(c);return sn.set(c,l),e.files&&await Ge(this,c,e.files,r),e.fetch&&await Ue(this,c,e.fetch,r),e.js_modules&&await Ye(e.js_modules,r),e.packages&&await l(e.packages),c},registerJSModule:on,run:bn(cn),runAsync:bn(ln),runEvent:bn(un),transform:(t,e)=>xn.call(t,e),writeFile:(t,e,n,r)=>{const s=an(e,r);if(s)return t.unpackArchive(n,s,{extractDir:e.slice(0,-1)});const{FS:o,PATH:a,_module:{PATH_FS:i}}=t;return We({FS:o,PATH:a,PATH_FS:i},e,n)}};function xn(t){const{ffi:{PyProxy:e}}=this;if(t&&"object"==typeof t){if(t instanceof e)return t.toJs(_n);if(t instanceof Map)return new Map([...t.entries()]);if(ce(t))return t.map(xn,this)}return t}async function kn(t){await this.loadPackage("micropip");const e=this.pyimport("micropip");await e.install(t,{keep_going:!0}),e.destroy()}const Sn="ruby-wasm-wasi",$n=Sn.replace(/\\W+/g,"_");var Bn={type:Sn,experimental:!0,module:(t="2.6.2")=>`https://cdn.jsdelivr.net/npm/@ruby/3.2-wasm-wasi@${t}/dist/browser/+esm`,async engine({DefaultRubyVM:t},e,n,r){n=n.replace(/\\/browser\\/\\+esm$/,"/ruby.wasm");const s=await De(n).arrayBuffer(),o=await WebAssembly.compile(s),{vm:a}=await t(o);return e.files&&await Ge(this,a,e.files,r),e.fetch&&await Ue(this,a,e.fetch,r),e.js_modules&&await Ye(e.js_modules,r),a},registerJSModule(t,e,n){e=e.replace(/\\W+/g,"__");const r=`__module_${$n}_${e}`;globalThis[r]=n,this.run(t,`require "js";$${e}=JS.global[:${r}]`),delete globalThis[r]},run:(t,e,...n)=>t.eval(ie(e),...n),runAsync:(t,e,...n)=>t.evalAsync(ie(e),...n),async runEvent(t,e,n){if(/^xworker\\.(on\\w+)$/.test(e)){const{$1:e}=RegExp,r=`__module_${$n}_event`;globalThis[r]=n,this.run(t,`require "js";$xworker.call("${e}",JS.global[:${r}])`),delete globalThis[r]}else{const r=this.run(t,`method(:${e})`);await r.call(e,t.wrap(n))}},transform:(t,e)=>e,writeFile:()=>{throw new Error(`writeFile is not supported in ${Sn}`)}};var Pn={type:"wasmoon",module:(t="1.16.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${t}/+esm`,async engine({LuaFactory:t,LuaLibraries:e},n,r,s){const{stderr:o,stdout:a,get:i}=se(),c=await i((new t).createEngine());return c.global.getTable(e.Base,(t=>{c.global.setField(t,"print",a),c.global.setField(t,"printErr",o)})),n.files&&await Ge(this,c,n.files,s),n.fetch&&await Ue(this,c,n.fetch,s),n.js_modules&&await Ye(n.js_modules,s),c},registerJSModule:(t,e,n)=>{t.global.set(e,n)},run:(t,e,...n)=>{try{return t.doStringSync(ie(e),...n)}catch(e){re.get(t).stderr(e)}},runAsync:async(t,e,...n)=>{try{return await t.doString(ie(e),...n)}catch(e){re.get(t).stderr(e)}},runEvent:async(t,e,n)=>{const[r,...s]=e.split(".");let o,a=t.global.get(r);for(const t of s)[o,a]=[a,a[t]];try{await a.call(o,n)}catch(e){re.get(t).stderr(e)}},transform:(t,e)=>e,writeFile:({cmodule:{module:{FS:t}}},e,n)=>((t,e,n)=>(Ne(t,He(e)),e=Je(t,e),t.writeFile(e,new Uint8Array(n),{canOwn:!0})))(t,e,n)};const Tn=new WeakMap,On=async(t,e)=>{const{shelter:n,destroy:r,io:s}=Tn.get(t),{output:o,result:a}=await n.captureR(ie(e));for(const{type:t,data:e}of o)s[t](e);return mn(a,r,{token:!1})};var Rn={type:"webr",experimental:!0,module:(t="0.4.1")=>`https://cdn.jsdelivr.net/npm/webr@${t}/dist/webr.mjs`,async engine(t,e,n,r){const{get:s}=se(),o=new t.WebR;await s(o.init().then((()=>o)));const a=await new o.Shelter;return Tn.set(o,{module:t,shelter:a,destroy:a.destroy.bind(a),io:re.get(o)}),e.files&&await Ge(this,o,e.files,r),e.fetch&&await Ue(this,o,e.fetch,r),e.js_modules&&await Ye(e.js_modules,r),o},registerJSModule(t,e){console.warn(`Experimental interpreter: module ${e} is not supported (yet)`)},run:On,runAsync:On,async runEvent(t,e,n){await t.evalRVoid(`${e}(event)`,{env:{event:{type:[n.type]}}})},transform:(t,e)=>(console.log("transforming",e),e),writeFile:()=>{}};const Mn=new Map,Fn=new Map,Cn=new Proxy(new Map,{get(t,e){if(!t.has(e)){const[n,...r]=e.split("@"),s=Mn.get(n),o=/^(?:\\.?\\.?\\/|https?:\\/\\/)/i.test(r)?r.join("@"):s.module(...r);t.set(e,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:n,module:r,engine:s}=t.get(e);return(t,o)=>r.then((r=>(Fn.set(e,t),s(r,t,n,o))))}}),Dn=t=>{for(const e of[].concat(t.type))Mn.set(e,t)};for(const t of[Re,hn,jn,Bn,Pn,Rn])Dn(t);const{parse:In}=JSON,Wn=(t,e,n={})=>{const[r,s]=((t,e="./config.txt")=>{let n=typeof t;return"string"===n&&/\\.(json|toml|txt)$/.test(t)?n=RegExp.$1:t=e,[we(t),n]})(t,e);return"json"===s?n=De(r).json():"toml"===s?n=De(r).text().then(fn):"string"===s?n=Hn(t):"object"===s&&t?n=t:"txt"===s&&"string"==typeof n&&(n=Hn(n)),[n,t=r]},Hn=t=>{try{return In(t)}catch(e){return fn(t)}},Nn="BeforeRun",Jn="AfterRun",qn=[`code${Nn}`,`code${Nn}Async`,`code${Jn}`,`code${Jn}Async`],zn=["onWorker","onReady",`on${Nn}`,`on${Nn}Async`,`on${Jn}`,`on${Jn}Async`];function Un(t,e){const{run:n,runAsync:r}=Mn.get(this.type);return{...t,run:n.bind(this,e),runAsync:r.bind(this,e)}}const Ln=(t,e,n,r,s,o)=>{if(s||o){const a=Un.bind(t,e),i=r?"runAsync":"run",c=t[i];t[i]=r?async function(t,e,...r){s&&await s.call(this,a(t),n);const i=await c.call(this,t,e,...r);return o&&await o.call(this,a(t),n),i}:function(t,e,...r){s&&s.call(this,a(t),n);const i=c.call(this,t,e,...r);return o&&o.call(this,a(t),n),i}}};let Kn,Gn,Yn;const Xn=(t,e)=>{addEventListener(t,e||(async e=>{try{await Kn,Gn(`xworker.on${t}`,e)}catch(t){postMessage(t)}}),!!e&&{once:!0})},{parse:Zn,stringify:Vn}=p,{proxy:Qn,sync:tr,polyfill:er,window:nr,isWindowProxy:rr}=await(async t=>{const e=await Lt(t),n=t?.transform||(t=>t),{[Qt]:r}=e.proxy,s=new Map,o=(t,e)=>{let n=s.get(t)?.deref();return n||s.set(t,new WeakRef(n=e(t))),n},a=([t,e])=>{switch(t){case Kt[w]:return null==e?globalThis:typeof e===y?o(e,p.object):e;case Kt[f]:return typeof e===y?o(e,p.array):e;case Kt[d]:return typeof e===y?o(e,p.function):tt(parseInt(e));case Kt[g]:return(t=>{if(t.startsWith("."))return Symbol.for(t.slice(1));for(const[e,n]of Xt)if(n===t)return e})(e);default:return e}},i=t=>{let[e,r]=m(t);switch(e){case w:if(r==globalThis||null==r)r=null;else if(typeof r===w&&!(r instanceof lt)){r=n(r);for(const t in r)r[t]=i(r[t])}return[Kt[w],r];case f:return[Kt[f],typeof r===y?r:n(r).map(i)];case d:return[Kt[d],typeof r===d?String(et(n(r))):r];case g:return[Kt[g],Zt(t)];default:return[Kt[e],r]}},c=(...t)=>a(r(...t)),l={[b]:(t,e,n)=>c(b,t,i(e),i(n)),[E]:(t,e)=>c(E,t,i(e)),[v]:(t,e)=>c(v,t,i(e)),[x]:t=>c(x,t),[j]:(t,e)=>{const n=c(j,t,i(e));if(n){const{get:t,set:e,value:r}=n;t&&(n.get=a(t)),e&&(n.set=a(e)),r&&(n.value=a(r))}return n},[k]:(t,e)=>c(k,t,i(e)),[S]:t=>c(S,t),[$]:t=>c($,t).map(a),[B]:t=>c(B,t),[P]:(t,e,n)=>c(P,t,i(e),i(n)),[T]:(t,e)=>c(T,t,i(e)),[Gt](t){s.delete(t),r(Gt,t)}},u={object:l,array:l,function:{...l,[_]:(t,...e)=>c(_,t,...e.map(i)),[A]:(t,...e)=>c(A,t,...e.map(i))}},{proxy:p,isProxy:h,pair:m}=X(u),O=p.object(null);return e.proxy[te]=async(t,e,...n)=>{const r=parseInt(e);switch(t){case _:{const[t,e]=n;return i(await ee(tt(r),a(t),e.map(a)))}case Gt:(t=>{const[e,n]=typeof t===y?[Q,V]:[V,Q],r=e.has(t);r&&(n.delete(e.get(t)),e.delete(t))})(r)}},{...e,window:O,isWindowProxy:h}})({parse:Zn,stringify:Vn,transform:t=>Yn?Yn(t):t}),sr={polyfill:er,sync:Qn,window:tr?nr:null,isWindowProxy:rr,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};Xn("message",(({data:{options:t,config:e,configURL:n,code:r,hooks:s}})=>{Kn=(async()=>{try{const{id:o,tag:a,type:i,custom:c,version:l,config:u,async:p}=t,f=((t,e="")=>`${t}@${e}`.replace(/@$/,""))(i,l),d=await((t,e,n,r={})=>(e&&([r,e]=Wn(e,n,r)),ye(r).then((n=>Cn[t](n,e)))))(f,e,n,u),{js_modules:h}=Fn.get(f),y=h?.main,w=ue(Mn.get(i)),g=((t,e,n,r)=>({type:e,config:n,interpreter:r,io:re.get(r),run:(e,...n)=>t.run(r,e,...n),runAsync:(e,...n)=>t.runAsync(r,e,...n),runEvent:(...e)=>t.runEvent(r,...e)}))(w,c||i,u||{},d);let m="run";if(p&&(m+="Async"),s){let t,e,n="",r="";for(const t of qn){const e=s[t];if(e){const s=t.endsWith("Async");(s&&p||!s&&!p)&&(t.startsWith("codeBefore")?n=e:r=e)}}(n||r)&&((t,e,n,r)=>{const s=t[e].bind(t);t[e]="run"===e?(t,e,...o)=>{n&&s(t,n,...o);const a=s(t,_e(e),...o);return r&&s(t,r,...o),a}:async(t,e,...o)=>{n&&await s(t,n,...o);const a=await s(t,_e(e),...o);return r&&await s(t,r,...o),a}})(w,m,n,r);for(const n of zn.slice(2)){const r=s[n];if(r){const s=n.endsWith("Async");if(s&&p||!s&&!p){const s=me(r);n.startsWith("onBefore")?t=s:e=s}}}Ln(w,g,sr,p,t,e)}let _,A,b,E=null,v="";tr&&(({CustomEvent:_,document:A}=nr),E=o&&A.getElementById(o)||null,b=t=>ge(E,c||i,t,!0,_));const j=Be(nr,Qn,y,e);if(((t,e,n,r)=>{if("pyodide"===t)return;const s="polyscript.js_modules";for(const t of Reflect.ownKeys(r))e.registerJSModule(n,`${s}.${t}`,ve(r,t));e.registerJSModule(n,s,r)})(i,w,d,j),w.registerJSModule(d,"polyscript",{xworker:sr,currentScript:E,config:g.config,js_modules:j,get target(){return!v&&E&&("SCRIPT"===a?E.after(le(A.createElement(`script-${c||i}`),{id:v=`${o}-target`})):(v=o,E.replaceChildren(),E.style.display="block")),v}}),Gn=w.runEvent.bind(w,d),Yn=w.transform.bind(w,d),E&&b("ready"),s?.onReady&&me(s?.onReady).call(w,Un.call(w,g,d),sr),await w[m](d,r),["micropython","pyodide"].includes(w.type)){const t="polyscript",e=`__${t}_workers__`,n="__export__";d.runPython([`import js as ${e}`,`${e}.${e} = "${n}" in locals() and ${n} or []`,`del ${e}`].join("\\n"));const r=[...globalThis[e]];delete globalThis[e],r.length&&d.runPython([`from ${t} import xworker as ${e}`,...r.map((t=>`${e}.sync.${t} = ${t}`)),`del ${e}`].join("\\n"))}return E&&b("done"),postMessage("polyscript:done"),d}catch(t){postMessage(t)}})(),Xn("error"),Xn("message"),Xn("messageerror")}));\n'.replace(Oe,Fe)],{type:"application/javascript"})),...e))({serviceWorker:n?.serviceWorker||n?.service_worker}),{postMessage:a}=s,i=this instanceof Fn,c=Qe(s.proxy,{importJS:_t,importCSS:At}),l=Promise.withResolvers();let u=o(t).text().then((e=>{const t=i?this.toJSON():void 0;a.call(s,{options:n,config:r,code:e,hooks:t})})).then((()=>{u={then:e=>e()}}));return tt(s,{sync:{value:c},ready:{value:l.promise},postMessage:{value:(e,...t)=>u.then((()=>a.call(s,e,...t)))},onerror:{writable:!0,configurable:!0,value:console.error}}),s.addEventListener("message",(e=>{const{data:t}=e,n=t instanceof Error;(n||"polyscript:done"===t)&&(e.stopImmediatePropagation(),n?(l.reject(t),s.onerror(et(e,{type:{value:"error"},error:{value:t}}))):l.resolve(s))})),i&&this.onWorker?.(this.interpreter,s),s};const Dn="Invalid content",Wn="Invalid worker attribute",In="Invalid worker attribute";var Nn=e=>{const{src:t,worker:n}=e.attributes;if(n){let{value:r}=n;if(r)throw new SyntaxError(In);if(r=t?.value,!r){if(t)throw new SyntaxError(Wn);if(e.childElementCount){const{innerHTML:t,localName:n,type:s}=e,o=s||n.replace(/-script$/,"");r=Ve(t),console.warn(`Deprecated: use diff --git a/test/index.js b/test/index.js index 484dea6e..5d7e5009 100644 --- a/test/index.js +++ b/test/index.js @@ -36,6 +36,7 @@ globalThis.indexedDB = { open: () => ({}) }; globalThis.document = document; globalThis.Element = window.Element; globalThis.CustomEvent = CustomEvent; +globalThis.dispatchEvent = Object; globalThis.MutationObserver = window.MutationObserver; globalThis.Worker = class {}; globalThis.XPathResult = {}; diff --git a/test/matplot.html b/test/matplot.html index 6ed14835..a52f9a7f 100644 --- a/test/matplot.html +++ b/test/matplot.html @@ -5,6 +5,7 @@ python + diff --git a/test/matplot.json.html b/test/matplot.json.html index dd67ccba..e35d4eb1 100644 --- a/test/matplot.json.html +++ b/test/matplot.json.html @@ -5,6 +5,7 @@ python + diff --git a/test/matplot.worker.html b/test/matplot.worker.html index ac4c22e0..85da3ff3 100644 --- a/test/matplot.worker.html +++ b/test/matplot.worker.html @@ -5,6 +5,7 @@ python + diff --git a/test/micropython.html b/test/micropython.html index f2bbd1c9..0f25d8b2 100644 --- a/test/micropython.html +++ b/test/micropython.html @@ -5,6 +5,7 @@ python + diff --git a/test/micropython/random.html b/test/micropython/random.html index 5e8efce1..7fb0d9c1 100644 --- a/test/micropython/random.html +++ b/test/micropython/random.html @@ -3,6 +3,7 @@ +