@pyscript/core 0.4.45 → 0.4.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{codemirror-Cuc1ujlq.js → codemirror-CdY86QAP.js} +2 -2
- package/dist/{codemirror-Cuc1ujlq.js.map → codemirror-CdY86QAP.js.map} +1 -1
- package/dist/{codemirror_commands-DrGPggEa.js → codemirror_commands-Cg5rCf1I.js} +2 -2
- package/dist/{codemirror_commands-DrGPggEa.js.map → codemirror_commands-Cg5rCf1I.js.map} +1 -1
- package/dist/codemirror_lang-python-BVX9Mc4s.js +2 -0
- package/dist/codemirror_lang-python-BVX9Mc4s.js.map +1 -0
- package/dist/{codemirror_language-w-S9uYcH.js → codemirror_language-BFA8854-.js} +2 -2
- package/dist/{codemirror_language-w-S9uYcH.js.map → codemirror_language-BFA8854-.js.map} +1 -1
- package/dist/codemirror_view-CH0UDCz6.js +2 -0
- package/dist/codemirror_view-CH0UDCz6.js.map +1 -0
- package/dist/core-CVoMgJtU.js +3 -0
- package/dist/core-CVoMgJtU.js.map +1 -0
- package/dist/core.js +1 -1
- package/dist/{deprecations-manager-Dp9f63Kl.js → deprecations-manager-_MT-zvjy.js} +2 -2
- package/dist/{deprecations-manager-Dp9f63Kl.js.map → deprecations-manager-_MT-zvjy.js.map} +1 -1
- package/dist/{error-i2BSJ2Z6.js → error-BcdCmvJU.js} +2 -2
- package/dist/{error-i2BSJ2Z6.js.map → error-BcdCmvJU.js.map} +1 -1
- package/dist/{index-B-A3jfDu.js → index-C02Lyjc0.js} +2 -2
- package/dist/index-C02Lyjc0.js.map +1 -0
- package/dist/{mpy-C5OOHWwo.js → mpy-Bfshdqz6.js} +2 -2
- package/dist/{mpy-C5OOHWwo.js.map → mpy-Bfshdqz6.js.map} +1 -1
- package/dist/{py-DsJxoJ3K.js → py-DuRZhMvB.js} +2 -2
- package/dist/{py-DsJxoJ3K.js.map → py-DuRZhMvB.js.map} +1 -1
- package/dist/{py-editor-C4428CRk.js → py-editor-C2f99cbd.js} +2 -2
- package/dist/{py-editor-C4428CRk.js.map → py-editor-C2f99cbd.js.map} +1 -1
- package/dist/{py-terminal-BzrNYA2l.js → py-terminal-CvFLFMwK.js} +2 -2
- package/dist/{py-terminal-BzrNYA2l.js.map → py-terminal-CvFLFMwK.js.map} +1 -1
- package/dist/xterm-readline-DjufFwfn.js +2 -0
- package/dist/xterm-readline-DjufFwfn.js.map +1 -0
- package/package.json +7 -5
- package/src/stdlib/pyscript/__init__.py +1 -0
- package/src/stdlib/pyscript/flatted.py +148 -0
- package/src/stdlib/pyscript/storage.py +60 -0
- package/src/stdlib/pyscript.js +3 -1
- package/types/stdlib/pyscript.d.ts +2 -0
- package/dist/codemirror_lang-python-CJNnzWx3.js +0 -2
- package/dist/codemirror_lang-python-CJNnzWx3.js.map +0 -1
- package/dist/codemirror_view-DfjLm8GV.js +0 -2
- package/dist/codemirror_view-DfjLm8GV.js.map +0 -1
- package/dist/core-BLQaGnG9.js +0 -3
- package/dist/core-BLQaGnG9.js.map +0 -1
- package/dist/index-B-A3jfDu.js.map +0 -1
- package/dist/xterm-readline-D247p8vq.js +0 -2
- package/dist/xterm-readline-D247p8vq.js.map +0 -1
- package/dist.zip +0 -0
package/dist/core-BLQaGnG9.js
DELETED
@@ -1,3 +0,0 @@
|
|
1
|
-
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<t;e++)r.push(n.snapshotItem(e));return r},r=Object.getOwnPropertyDescriptors(Response.prototype),s=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,d=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]},u=([e,t])=>0===e&&("function"===t||"symbol"===t),m=(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]=d(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&&u(d(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||!u(d(n))&&!u(d(s)))&&t.push([o(n),o(s)]);return n}case 6:{const t=[],n=s([a,t],r);for(const n of r)!e&&u(d(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:h,stringify:y}=JSON,g={json:!0,lossy:!0};var _=Object.freeze({__proto__:null,parse:e=>l(h(e)),stringify:e=>y(m(e,g))});const w="64e10b34-2bf7-4616-9668-f99de5aa046e",b="M"+w,v="T"+w,E="array",S="function",T="null",P="number",k="object",x="string",R="symbol",j="undefined",A="apply",J="construct",N="defineProperty",M="deleteProperty",O="get",W="getOwnPropertyDescriptor",I="getPrototypeOf",L="has",H="isExtensible",$="ownKeys",B="preventExtensions",U="set",F="setPrototypeOf",C="delete",{isArray:z}=Array;let{SharedArrayBuffer:D,window:q}=globalThis,{notify:G,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 D(4)}catch(e){D=ArrayBuffer;const t=new WeakMap;if(q){const e=new Map,{prototype:{postMessage:n}}=Worker,r=t=>{const n=t.data?.[w];if(!z(n)){t.stopImmediatePropagation();const{id:r,sb:s}=n;e.get(r)(s)}};K=function(e,...s){const o=e?.[w];if(z(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<r.length;e++)n[e]=r[e];return"ok"}))})}else{const e=(e,t)=>({[w]:{id:e,sb:t}});G=n=>{postMessage(e(t.get(n),n))},addEventListener("message",(e=>{const n=e.data?.[w];if(z(n)){const[e,r]=n;t.set(r,e)}}))}}
|
2
|
-
/*! (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===S?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,{[L]:(e,t)=>"string"==typeof t&&!t.startsWith("_"),[O]:(n,s)=>"then"===s?null:(...n)=>{const o=oe++;let i=new X(new D(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 d=e!==globalThis;let u=0;return f&&d&&(u=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),p(d,i).value.then((()=>{clearTimeout(u);const e=i[1];if(!e)return;const n=te*e;return i=new X(new D(n+n%ee)),a([],o,i),p(d,i).value.then((()=>t(c.decode(new Q(i.buffer).slice(0,e)))))}))},[U](t,s,o){const a=typeof o;if(a!==S)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(z(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<e.length;n++)t[n]=e.charCodeAt(n)}if(G(i,0),c)throw c}}))}return!!t.set(s,o)}}))}return re.get(e)};ae.transfer=(...e)=>(ne.add(e),e);const{isArray:ie}=Array,le=(e,t)=>t,ce=e=>typeof e===S?(e=>e())(e):e;function pe(){return this}const fe=(e,t)=>e===E?[t]:{t:e,v:t},de=(e,t=le)=>{let n=typeof e,r=e;return n===k&&(ie(e)?(n=E,r=e.at(0)):({t:n,v:r}=e)),t(n,r)},ue=(e,t)=>e===S?t:fe(e,t),me=(e,t=ue)=>{const n=null===e?T:typeof e;return t(n===k&&ie(e)?E:n,e)},he=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),he.register(...i),a},{defineProperty:_e,deleteProperty:we,getOwnPropertyDescriptor:be,getPrototypeOf:ve,isExtensible:Ee,ownKeys:Se,preventExtensions:Te,set:Pe,setPrototypeOf:ke}=Reflect,{assign:xe,create:Re}=Object,je=ve(Int8Array),Ae=(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},Je=e=>t=>me(t,((t,n)=>{switch(t){case T:return fe(T,n);case k:if(n===globalThis)return fe(t,null);case E:case S:return e(t,n);case"boolean":case P:case x:case j:case"bigint":return fe(t,n);case R:{if(Ne.has(n))return fe(t,Ne.get(n));let e=Symbol.keyFor(n);if(e)return fe(t,`.${e}`)}}throw new TypeError(`Unable to handle this ${t}: ${String(n)}`)})),Ne=new Map(Se(Symbol).filter((e=>typeof Symbol[e]===R)).map((e=>[Symbol[e],e]))),Me=e=>{if(e.startsWith("."))return Symbol.for(e.slice(1));for(const[t,n]of Ne)if(n===e)return t},Oe=e=>e;var We=((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||Oe;const l=new Map,c=new Map,{[s]:p}=t,f=o.length?xe(Re(globalThis),...o):globalThis,d=Je(((e,t)=>{if(!l.has(t)){let n;for(;c.has(n=a++););l.set(t,n),c.set(n,e===S?t:i(t))}return fe(e,l.get(t))})),u=e=>{p(C,fe(x,e))},m=(e,t)=>{switch(e){case k:if(null==t)return f;case E:if(typeof t===P)return c.get(t);if(!(t instanceof je))for(const e in t)t[e]=h(t[e]);return t;case S:if(typeof t===x){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(A,fe(S,t),d(this),e.map(d))};return c.set(t,new WeakRef(r)),ge(t,u,{return:r,token:!1})}return c.get(t);case R:return Me(t)}return t},h=e=>de(e,m),y={[A]:(e,t,n)=>d(e.apply(t,n)),[J]:(e,t)=>d(new e(...t)),[N]:(e,t,n)=>d(_e(e,t,n)),[M]:(e,t)=>d(we(e,t)),[I]:e=>d(ve(e)),[O]:(e,t)=>d(e[t]),[W]:(e,t)=>{const n=be(e,t);return n?fe(k,Ae(n,d)):fe(j,n)},[L]:(e,t)=>d(t in e),[H]:e=>d(Ee(e)),[$]:e=>fe(E,Se(e).map(d)),[B]:e=>d(Te(e)),[U]:(e,t,n)=>d(Pe(e,t,n)),[F]:(e,t)=>d(ke(e,t)),[C](e){l.delete(c.get(e)),c.delete(e)}};return t[r]=(e,t,...n)=>{switch(e){case A:n[0]=h(n[0]),n[1]=n[1].map(h);break;case J:n[0]=n[0].map(h);break;case N:{const[e,t]=n;n[0]=h(e);const{get:r,set:s,value:o}=t;r&&(t.get=h(r)),s&&(t.set=h(s)),o&&(t.value=h(o));break}default:n=n.map(h)}return y[e](h(t),...n)},{proxy:t,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window"),Ie=(e=>{let t=0;const n=new Map,r=new Map,s=Symbol();return function(o,a,i){const l=this?.transform||Oe,{[a]:c}=o,p=new Map,f=e=>{p.delete(e),c(C,d(e))},d=Je(((e,o)=>{if(s in o)return ce(o[s]);if(e===S){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 je)){o=l(o);for(const e in o)o[e]=d(o[e])}return fe(e,o)})),u=(e,t,n)=>{const r=p.get(n)?.deref();if(r)return r;const s=t===S?(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})},m=e=>de(e,((t,n)=>{switch(t){case k:if(null===n)return globalThis;case E:return typeof n===P?u(e,t,n):n;case S:return typeof n===x?r.get(n):u(e,t,n);case R:return Me(n)}return n})),h=(e,t,...n)=>m(c(e,ce(t),...n)),y={[A]:(e,t,n)=>h(A,e,d(t),n.map(d)),[J]:(e,t)=>h(J,e,t.map(d)),[N]:(e,t,n)=>{const{get:r,set:s,value:o}=n;return typeof r===S&&(n.get=d(r)),typeof s===S&&(n.set=d(s)),typeof o===S&&(n.value=d(o)),h(N,e,d(t),n)},[M]:(e,t)=>h(M,e,d(t)),[I]:e=>h(I,e),[O]:(e,t)=>t===s?e:h(O,e,d(t)),[W]:(e,t)=>{const n=h(W,e,d(t));return n&&Ae(n,m)},[L]:(e,t)=>t===s||h(L,e,d(t)),[H]:e=>h(H,e),[$]:e=>h($,e).map(m),[B]:e=>h(B,e),[U]:(e,t,n)=>h(U,e,d(t),d(n)),[F]:(e,t)=>h(F,e,d(t))};o[i]=(e,t,s,o)=>{switch(e){case A:return m(t).apply(m(s),o.map(m));case C:{const e=m(t);n.delete(r.get(e)),r.delete(e)}}};const g=new Proxy(fe(k,null),y);return{[e.toLowerCase()]:g,[`is${e}Proxy`]:e=>typeof e===k&&!!e&&s in e,proxy:o}}})("Window"),Le=typeof Worker===S?Worker:class{};const He=new WeakMap,$e=(e,...t)=>{const n=ae(e,...t);if(!He.has(n)){const r=e instanceof Le?We:Ie;He.set(n,r.call(t.at(0),n,b,v))}return He.get(n)};$e.transfer=ae.transfer;const{url:Be}=import.meta,Ue=/import\((['"])([^)]+?\.js)\1\)/g,Fe=(e,t,n)=>`import(${t}${new URL(n,Be).href}${t})`;const Ce={object(...e){return this.string(function(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}(...e))},string(e){for(const t of e.split(/[\r\n]+/))if(t.trim().length){/^(\s+)/.test(t)&&(e=e.replace(new RegExp("^"+RegExp.$1,"gm"),""));break}return e}},{replace:ze}="",De=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,qe={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'},Ge=e=>qe[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)=>Ce[typeof e](e,...t),Qe=e=>ze.call(e,De,Ge),{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}}))},dt=(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)}),ut=e=>e.replace(/^(?:\n|\r\n)/,""),mt=(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,ut(t),...o);return r&&s(e,r,...o),a}:async(e,t,...o)=>{n&&await s(e,n,...o);const a=await s(e,ut(t),...o);return r&&await s(e,r,...o),a}},ht=Symbol.for("polyscript.js_modules"),yt=new Map;st(globalThis,ht,{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}))})),St=e=>/\.css/i.test(new URL(e).pathname),Tt=!globalThis.window,Pt=({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})},kt=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("/")))},Rt=(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(/^\/+/,"/")},jt=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},At=(e,t)=>a(lt(t,Jt.get(e))).arrayBuffer(),Jt=new WeakMap,Nt=(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:jt([e,n]),path:jt([t,n])})));const s=n||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:jt([t,s])}]}))})(n).map((({url:r,path:s})=>At(n,r).then((n=>e.writeFile(t,s,n)))))),Mt=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,Ot=(e,t)=>e.replace(/\{.+?\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),Wt=(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,Ot(o,t))}else{const e=Ot(s,t),a=Mt(e,Ot(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})=>At(n,r).then((n=>e.writeFile(t,s,n,r)))))),It=({main:e,worker:t})=>{const n=[];if(t&&Tt)for(let[e,r]of ot(t))e=lt(e,Jt.get(t)),n.push(vt(e,r));if(e&&!Tt)for(let[t,r]of ot(e))t=lt(t,Jt.get(e)),St(t)?Et(t):n.push(vt(t,r));return at(n)},Lt=new WeakMap,Ht=(e,t,n)=>{"polyscript"===t&&(n.lazy_py_modules=async(...t)=>(await Lt.get(e)(t),t.map((t=>e.pyimport(t))))),e.registerJsModule(t,n)},$t=(e,t)=>{if(e.endsWith("/*")){if(/\.(zip|whl|tgz|tar(?:\.gz)?)$/.test(t))return RegExp.$1;throw new Error(`Unsupported archive ${t}`)}return""},Bt=(e,t,...n)=>{try{return e.runPython(Ze(t),...n)}catch(t){Ye.get(e).stderr(t)}},Ut=async(e,t,...n)=>{try{return await e.runPythonAsync(Ze(t),...n)}catch(t){Ye.get(e).stderr(t)}},Ft=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 Ct=(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 # WARNING: mpy_version fails miserably with 1.22.0-380\n package = "{}/package/{}/{}/{}.json".format(index, "py", 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 zt=(e,t)=>{try{e.mkdir(t)}catch(e){}};var Dt={type:"micropython",module:(e="1.23.0")=>`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}=Ve({stderr:Xe(console.error),stdout:Xe(console.log)});n=n.replace(/\.m?js$/,".wasm");const i=await a(e({linebuffer:!1,stderr:s,stdout:o,url:n})),l=qt.bind(this,i,r);return Lt.set(i,l),t.files&&await Wt(this,i,t.files),t.fetch&&await Nt(this,i,t.fetch),t.js_modules&&await It(t.js_modules),this.writeFile(i,"./mip.py",Ct),t.packages&&await l(t.packages),i},registerJSModule:Ht,run:Bt,runAsync:Ut,runEvent:Ft,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=$t(t,r);if(l){const r=t.slice(0,-1);switch("./"!==r&&s.mkdir(r),l){case"whl":case"zip":{const e=new Blob([n],{type:"application/zip"});return import("./zip-BxogYCy6.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)zt(s,i);else{zt(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 Pt(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 Pt(i,t,n)}};async function qt(e,t,n){let r;for(const s of n)if(s.endsWith(".whl")){const n=lt(s,t),r=await a(n).arrayBuffer();await this.writeFile(e,"./*",r,n)}else r||(r=e.pyimport("mip")),r.install(s)}const Gt={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<n.length;r++){const s=n[r];if("function"==typeof s&&"copy"in s){Yt=!1;let o=e.get(s)?.deref();if(!o)try{o=ge(s.copy(),t),e.set(s,new WeakRef(o))}catch(e){console.error(e)}o&&(n[r]=o),Yt=!0}}},{call:r}=Function,s=r.bind(r,r.apply);Object.defineProperties(Function.prototype,{apply:{value(e,t){return Yt&&n(t),s(this,e,t)}},call:{value(e,...t){return Yt&&n(t),s(this,e,t)}}})};var Zt={type:"pyodide",module:(e="0.26.0")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,n){Tt||"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 Lt.set(i,l),t.files&&await Wt(this,i,t.files),t.fetch&&await Nt(this,i,t.fetch),t.js_modules&&await It(t.js_modules),t.packages&&await l(t.packages),i},registerJSModule:Ht,run:Vt(Bt),runAsync:Vt(Ut),runEvent:Vt(Ft),transform:({ffi:{PyProxy:e}},t)=>t instanceof e?t.toJs(Gt):t,writeFile:(e,t,n,r)=>{const s=$t(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 Pt({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.1")=>`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 Wt(this,o,t.files),t.fetch&&await Nt(this,o,t.fetch),t.js_modules&&await It(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 Wt(this,a,n.files),n.fetch&&await Nt(this,a,n.fetch),n.js_modules&&await It(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)=>(xt(e,kt(t)),t=Rt(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 Wt(this,r,t.files),t.fetch&&await Nt(this,r,t.fetch),t.js_modules&&await It(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=[],dn=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&&Jt.set(n,o)}for(const t of["main","worker"]){const n=e?.js_modules?.[t];n&&Jt.set(n,o)}return s(r,e,n,o)}))}}),un=e=>{for(const t of[].concat(e.type))ln.set(t,e),pn.push(`script[type="${t}"]`),fn.push(`${t}-`)};for(const e of[Dt,Zt,nn,rn,an])un(e);const mn=async e=>(await import("./toml-DiUM0_qs.js")).parse(e),hn=(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 mn(e)}},gn=(e,t,n,r={})=>{if(t){const[e,s]=hn(t,n);"json"===s?r=a(e).json():"toml"===s?r=a(e).text().then(mn):"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=>dn[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`],Sn=["onWorker","onReady",`on${bn}`,`on${bn}Async`,`on${vn}`,`on${vn}Async`];function Tn(e,t){const{run:n,runAsync:r}=ln.get(this.type);return{...e,run:n.bind(this,t),runAsync:r.bind(this,t)}}const Pn=(e,t,n,r,s,o)=>{if(s||o){const a=Tn.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 kn=class{constructor(e,t={}){const{main:n,worker:r}=t;this.interpreter=e,this.onWorker=n?.onWorker;for(const e of Sn.slice(1))this[e]=r?.[e];for(const e of En)this[e]=r?.[e]}toJSON(){const e={};for(const t of Sn.slice(1))this[t]&&(e[t]=wn(this[t]));for(const t of En)this[t]&&(e[t]=Ze(this[t]()));return e}};var xn=(...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",R="getPrototypeOf",O="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:B}=Atomics,U=null;B||(B=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)}};U=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)},B=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<r.length;e++)n[e]=r[e];return"ok"}))})}else{const e=(e,t)=>({[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:z,Uint16Array:q}=globalThis,{BYTES_PER_ELEMENT:G}=J,{BYTES_PER_ELEMENT:K}=q,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=U||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?B(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 z,{[O]:(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 q(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 z;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 q(i.buffer),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)}if(C(i,0),l)throw l}}))}return!!t.set(s,o)}}))}return X.get(e)};Q.transfer=(...e)=>(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)),[R]: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)},[O]:(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"),Re=(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)),[R]:e=>w(R,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)},[O]:(e,t)=>t===s||w(O,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"),Oe=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 Oe?je:Re;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<r;n++)t+=arguments[n]+e[n];return t}(...e))},string(e){for(const t of e.split(/[\\r\\n]+/))if(t.trim().length){/^(\\s+)/.test(t)&&(e=e.replace(new RegExp("^"+RegExp.$1,"gm"),""));break}return e}},Ne=new WeakMap,Ie=e=>{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:Be,defineProperty:Ue,entries:Je}=Object,{all:ze,resolve:qe}=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;Ue(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)=>ze((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)=>ze((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 ze(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|whl|tgz|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)}},Rt=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 Ot=(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 # WARNING: mpy_version fails miserably with 1.22.0-380\\n package = "{}/package/{}/{}/{}.json".format(index, "py", 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.23.0")=>`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}=Ie({stderr:We(console.error),stdout:We(console.log)});n=n.replace(/\\.m?js$/,".wasm");const i=await a(e({linebuffer:!1,stderr:s,stdout:o,url:n})),c=Mt.bind(this,i,r);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),this.writeFile(i,"./mip.py",Ot),t.packages&&await c(t.packages),i},registerJSModule:Tt,run:At,runAsync:jt,runEvent:Rt,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"whl":case"zip":{const e=new Blob([n],{type:"application/zip"});return import("./zip-C3HUxQSo.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"tgz":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,t,n){let r;for(const s of n)if(s.endsWith(".whl")){const n=Ge(s,t),r=await it(n).arrayBuffer();await this.writeFile(e,"./*",r,n)}else r||(r=e.pyimport("mip")),r.install(s)}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<n.length;r++){const s=n[r];if("function"==typeof s&&"copy"in s){It=!1;let o=e.get(s)?.deref();if(!o)try{o=pe(s.copy(),t),e.set(s,new WeakRef(o))}catch(e){console.error(e)}o&&(n[r]=o),It=!0}}},{call:r}=Function,s=r.bind(r,r.apply);Object.defineProperties(Function.prototype,{apply:{value(e,t){return It&&n(t),s(this,e,t)}},call:{value(e,...t){return It&&n(t),s(this,e,t)}}})};var Dt={type:"pyodide",module:(e="0.26.0")=>`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(Rt),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",Bt=Lt.replace(/\\W+/g,"_");var Ut={type:Lt,experimental:!0,module:(e="2.6.1")=>`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_${Bt}_${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_${Bt}_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 zt=new WeakMap,qt=async(e,t)=>{const{shelter:n,destroy:r,io:s}=zt.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 zt.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:qt,runAsync:qt,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,o)}))}}),Vt=e=>{for(const t of[].concat(e.type))Kt.set(t,e)};for(const e of[$t,Dt,Ut,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 qe(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(Ue,Fe)],{type:"application/javascript"})),{type:"module"}),{postMessage:s}=r,o=this instanceof kn;if(e.length){const[t,r]=e;(n=tt({},n||{type:t,version:r})).type||(n.type=t)}const[i]=hn(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($e(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 Rn="Invalid content";var jn=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 <script type="${o}"> for an always safe content parsing:\n`,r)}else r=e.textContent;return URL.createObjectURL(new Blob([Ze(r)],{type:"text/plain"}))}return r}if(t&&e.textContent.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*(?:\/\/|#).*/gm,"").trim())throw new SyntaxError(Rn)};const An=(e,t)=>{const n=(e=>{let t=e;for(;t.parentNode;)t=t.parentNode;return t})(e);return n.getElementById(t)||((e,t=document)=>t.querySelector(e))(t,n)},Jn=new WeakMap,Nn={get(){let e=Jn.get(this);return e||(e=document.createElement(`${this.type}-script`),Jn.set(this,e),Ln(this)),e},set(e){"string"==typeof e?Jn.set(this,An(this,e)):(Jn.set(this,e),Ln(this))}},Mn=new WeakMap,On=new Map,Wn=(e,t)=>{const n=e?.value;return n?t+n:""},In=(e,t,n,r,s,o,a=e)=>{if(!On.has(t)){const i={interpreter:gn(n,s,o),queue:it(),XWorker:xn(e,r)};On.set(t,i),On.has(e)||On.set(e,i),On.has(a)||On.set(a,i)}return On.get(t)},Ln=async e=>{if(Mn.has(e)){const{target:t}=e;t&&(e.closest("head")?document.body.append(t):e.after(t))}else{const{attributes:{async:t,config:n,env:r,target:s,version:o},src:i,type:l}=e,c=o?.value,p=_n(l,c);let f=Wn(n,"|");const d=Wn(r,"")||`${p}${f}`;f=f.slice(1);const u=jn(e);if(u){const n=new(xn(l,c))(u,{...pt(e,l),async:!!t,config:f});return void Mn.set(st(e,"xworker",{value:n}),{xworker:n})}const m=Wn(s,""),h=In(l,d,p,c,f);Mn.set(st(e,"target",Nn),h),m&&Jn.set(e,An(e,m));const y=i?a(i).text():e.textContent;h.queue=h.queue.then((()=>(async(e,t,n,r)=>{const{type:s}=e,o=ln.get(s);o.experimental&&console.warn(`The ${s} interpreter is experimental`);const[a,i]=await at([Mn.get(e).interpreter,t]);try{st(document,"currentScript",{configurable:!0,get:()=>e}),bt(s,o,a,gt),o.registerJSModule(a,"polyscript",{XWorker:n,currentScript:e,js_modules:gt}),ft(e,s,"ready");const t=o[r?"runAsync":"run"](a,i),l=ft.bind(null,e,s,"done");return r?t.then(l):l(),t}finally{delete document.currentScript}})(e,y,h.XWorker,!!t)))}},Hn=new Proxy(nt(null),{get:(e,t)=>new Promise(queueMicrotask).then((()=>$n(t)))}),$n=async e=>{if(On.has(e)){const{interpreter:t,queue:n}=On.get(e);return(await at([t,n]))[0]}const t=On.size?`Available interpreters are: ${[...On.keys()].map((e=>`"${e}"`)).join(", ")}.`:"There are no interpreters in this page.";throw new Error(`The interpreter "${e}" was not found. ${t}`)},Bn=async e=>{const{type:t,currentTarget:r}=e;if(fn.length)for(let{name:s,value:o,ownerElement:a}of n(`./@*[${fn.map((e=>`name()="${e}${t}"`)).join(" or ")}]`,r)){s=s.slice(0,-(t.length+1));const n=await $n(a.getAttribute(`${s}-env`)||s);ln.get(s).runEvent(n,o,e)}},Un=e=>{if(fn.length)for(let{name:t,ownerElement:r}of n(`.//@*[${fn.map((e=>`starts-with(name(),"${e}")`)).join(" or ")}]`,e)){const e=t.lastIndexOf("-"),n=t.slice(e+1);"env"!==n&&(r.addEventListener(n,Bn),"disabled"in r&&!r.disabled&&(r.disabled=!0,Hn[t.slice(0,e)].then((()=>{r.disabled=!1}))))}},Fn=xn(),Cn=[],zn=new Map,Dn=new Map,qn=new Map,Gn=async e=>{for(const t of Cn)if(e.matches(t)){const n=Dn.get(t),r=Yn.get(n),{resolve:s}=qn.get(n),{options:o,known:a}=r;if(a.has(e))return;a.add(e);for(const[t,n]of zn)e.matches(t)&&await n(e);const{interpreter:i,configURL:l,config:c,version:p,env:f,onerror:d,hooks:u}=o;let m;try{const t=jn(e);if(t){const r=Fn.call(new kn(null,u),t,{...pt(e,n),version:p,configURL:l,type:i,custom:n,config:e.getAttribute("config")||c||{},async:e.hasAttribute("async")});return st(e,"xworker",{value:r}),void s({type:n,xworker:r})}}catch(e){m=e}const h=_n(i,p),y=f||`${h}${c?`|${c}`:""}`,{interpreter:g,XWorker:_}=In(n,y,h,p,c,l,i),w=await g,b=nt(ln.get(i)),v=new kn(w,u),E=function(...e){return _.apply(v,e)},S={...dt(b,n,structuredClone(cn.get(h)),w),XWorker:E};bt(i,b,w,gt),b.registerJSModule(w,"polyscript",{XWorker:E,config:S.config,currentScript:n.startsWith("_")?null:e,js_modules:gt});for(const t of["Run","RunAsync"]){let n,r,s="",o="";for(const e of En){const n=u?.main?.[e];n&&e.endsWith(t)&&(e.startsWith("codeBefore")?s=Ze(n()):o=Ze(n()))}(s||o)&&mt(b,`r${t.slice(1)}`,s,o);for(let e=2;e<Sn.length;e++){const s=Sn[e],o=u?.main?.[s];o&&s.endsWith(t)&&(s.startsWith("onBefore")?n=o:r=o)}Pn(b,S,e,t.endsWith("Async"),n,r)}r.queue=r.queue.then((()=>(s(S),m&&d?.(m,e),u?.main?.onReady?.(S,e))))}},Yn=new Map;let Vn=0;const Kn=e=>(qn.has(e)||qn.set(e,Promise.withResolvers()),qn.get(e).promise),[{customObserver:Xn,define:Zn,whenDefined:Qn,env:er,Hook:tr,XWorker:nr},rr]=e("polyscript",{customObserver:zn,define:(e,n)=>{let r=null==e;if(r)e="_ps"+Vn++;else if(ln.has(e)||Yn.has(e))throw new Error(`<script type="${e}"> already registered`);if(!ln.has(n?.interpreter))throw new Error("Unspecified interpreter");ln.set(e,ln.get(n.interpreter));const s=[`script[type="${e}"]`];if(Kn(e),r){const{hooks:t}=n,r=t?.main?.onReady;n={...n,hooks:{...t,main:{...t?.main,onReady(t,n){Cn.splice(Cn.indexOf(e),1),ln.delete(e),Yn.delete(e),qn.delete(e),n.remove(),r?.(t)}}}},document.head.append(tt(document.createElement("script"),{type:e}))}else s.push(`${e}-script`),fn.push(`${e}-`);for(const t of s)Dn.set(t,e);Cn.push(...s),Yn.set(e,{options:tt({env:e},n),known:new WeakSet,queue:Promise.resolve()}),r||Un(document),t(s.join(",")).forEach(Gn)},whenDefined:Kn,env:Hn,Hook:kn,XWorker:Fn});if(!rr){const e=new MutationObserver((e=>{const t=pn.join(",");for(const{type:r,target:s,attributeName:o,addedNodes:a}of e)if("attributes"!==r)for(const e of a)1===e.nodeType&&(Un(e),t&&e.matches(t)?Ln(e):n(t,e,!0));else{const e=o.lastIndexOf("-")+1;if(e){const t=o.slice(0,e);for(const n of fn)if(t===n){const t=o.slice(e);if("env"!==t){const e=s.hasAttribute(o)?"add":"remove";s[`${e}EventListener`](t,Bn)}break}}}})),n=(e,n,r)=>{e&&t(e,n).forEach(Ln),(e=Cn.join(","))&&(r&&Gn(n),t(e,n).forEach(Gn))},r=t=>(e.observe(t,{childList:!0,subtree:!0,attributes:!0}),t),{attachShadow:s}=Element.prototype;tt(Element.prototype,{attachShadow(e){return r(s.call(this,e))}}),queueMicrotask((()=>{Un(r(document)),n(pn.join(","),document,!1)}))}var sr=new Map([["py","pyodide"],["mpy","micropython"]]);const or=[];for(const[e]of sr){const t=[`script[type="${e}"]`,`${e}-script`];for(const n of document.querySelectorAll(t.join(","))){const{promise:t,resolve:r}=Promise.withResolvers();or.push(t),n.addEventListener(`${e}:done`,r,{once:!0})}}Promise.all(or).then((()=>{dispatchEvent(new Event("py:all-done"))}));var ar={"deprecations-manager":()=>import("./deprecations-manager-Dp9f63Kl.js"),error:()=>import("./error-i2BSJ2Z6.js"),"py-editor":()=>import("./py-editor-C4428CRk.js"),"py-terminal":()=>import("./py-terminal-BzrNYA2l.js")};const ir={GENERIC:"PY0000",CONFLICTING_CODE:"PY0409",BAD_CONFIG:"PY1000",MICROPIP_INSTALL_ERROR:"PY1001",BAD_PLUGIN_FILE_EXTENSION:"PY2000",NO_DEFAULT_EXPORT:"PY2001",TOP_LEVEL_AWAIT:"PY9000",FETCH_ERROR:"PY0001",FETCH_NAME_ERROR:"PY0002",FETCH_UNAUTHORIZED_ERROR:"PY0401",FETCH_FORBIDDEN_ERROR:"PY0403",FETCH_NOT_FOUND_ERROR:"PY0404",FETCH_SERVER_ERROR:"PY0500",FETCH_UNAVAILABLE_ERROR:"PY0503"};class lr extends Error{constructor(e,t="",n="text"){super(`(${e}): ${t}`),this.errorCode=e,this.messageType=n,this.name="UserError"}}class cr extends lr{constructor(e,t){super(e,t),this.name="FetchError"}}const pr=e=>e.text();async function fr(e,t){let n;try{n=await fetch(e,t)}catch(t){const n=t;let r;throw r=e.startsWith("http")?`Fetching from URL ${e} failed with error '${n.message}'. Are your filename and path correct?`:'Polyscript: Access to local files\n (using [[fetch]] configurations in <py-config>)\n is not available when directly opening a HTML file;\n you must use a webserver to serve the additional files.\n See <a style="text-decoration: underline;" href="https://github.com/pyscript/pyscript/issues/257#issuecomment-1119595062">this reference</a>\n on starting a simple webserver with Python.\n ',new cr(ir.FETCH_ERROR,r)}if(!n.ok){const t=`Fetching from URL ${e} failed with error ${n.status} (${n.statusText}). Are your filename and path correct?`;switch(n.status){case 404:throw new cr(ir.FETCH_NOT_FOUND_ERROR,t);case 401:throw new cr(ir.FETCH_UNAUTHORIZED_ERROR,t);case 403:throw new cr(ir.FETCH_FORBIDDEN_ERROR,t);case 500:throw new cr(ir.FETCH_SERVER_ERROR,t);case 503:throw new cr(ir.FETCH_UNAVAILABLE_ERROR,t);default:throw new cr(ir.FETCH_ERROR,t)}}return n}const{BAD_CONFIG:dr,CONFLICTING_CODE:ur}=ir,mr=async(e,t)=>{let n=e?.trim(),r="",s=!1,o=/^{/.test(n)&&/}$/.test(n);if(!o&&/\.(\w+)(?:\?\S*)?$/.test(n)){const e=RegExp.$1;"json"===e&&"toml"!==t?o=!0:"toml"===e&&"json"!==t?s=!0:((e,t="")=>{let n=`(${dr}): Invalid URL: ${e}`;throw t&&(n+=`\nexpected ${t} content`),new Error(n)})(n,t),r=n,n=(await fr(r).then(pr)).trim()}return{json:o,toml:s||!o&&!!n,text:n,url:r}},hr=e=>new Error(`(${ur}): ${e}`),yr=(e,t,{message:n})=>{let r=`(${dr}): Invalid ${e}`;return t&&(r+=` @ ${t}`),new SyntaxError(`${r}\n${n}`)},gr=new Map;for(const[e]of sr){let n,r,s,o,a,i,l,c=t(`${e}-config`),p=t([`script[type="${e}"][config]:not([worker])`,`${e}-script[config]:not([worker])`].join(","));if(c.length>1?s=hr(`Too many ${e}-config`):c.length&&p.length?s=hr(`Ambiguous ${e}-config VS config attribute`):c.length?([l]=c,a=l.getAttribute("src")||l.textContent,i=l.getAttribute("type")):p.length&&([l,...p]=p,a=l.getAttribute("config"),p.some((e=>e.getAttribute("config")!==a))&&(s=hr("Unable to use different configs on main"))),!s&&a)try{const{json:e,toml:t,text:n,url:l}=await mr(a,i);if(l&&(o=new URL(l,location.href).href),a=n,e||"json"===i)try{r=JSON.parse(n)}catch(e){s=yr("JSON",l,e)}else if(t||"toml"===i)try{const{parse:e}=await import("./toml-CvAfdf9_.js");r=e(n)}catch(e){s=yr("TOML",l,e)}}catch(e){s=e}const f=[];for(const[e,t]of Object.entries(ar))s?"error"===e&&t().then((({notify:e})=>e(s.message))):r?.plugins?.includes(`!${e}`)||f.push(t().then((({default:e})=>e)));n=Promise.all(f),gr.set(e,{config:r,configURL:o,plugins:n,error:s})}var _r={is_pyterminal:()=>!1,sleep:e=>new Promise((t=>setTimeout(t,1e3*e)))};const wr=e=>{st(document,"currentScript",{configurable:!0,get:()=>e})},br=()=>{delete document.currentScript};var vr=async(e,t,n,r)=>{const s=r.endsWith("Async");(r.startsWith("onBefore")?wr:br)(n);for(const o of e(r))s?await o(t,n):o(t,n)};const Er=()=>!0,Sr=e=>{throw new TypeError(e)},Tr=(e,t)=>{const n=[];if(e)for(const t of e.split(/\s*\|\s*/))"object"===t?n.push((e=>null!==e&&typeof e===t)):"null"===t?n.push((e=>null===e)):n.push((e=>typeof e===t));if(t)for(const e of[].concat(t))n.push((t=>t instanceof e));switch(n.length){case 0:return Er;case 1:return n[0];default:return e=>n.some((t=>t(e)))}},Pr=(e,t,n,r=Sr)=>s=>{const o=[`Invalid ${typeof s} ${n}: expected `];e&&(o.push(e),t&&o.push(" or ")),t&&(o.push("an instanceof "),o.push([].concat(t).map((({name:e})=>e)).join(" | "))),r(o.join(""),s)},kr=(e=>t=>{const[n,r]=((e,t="value")=>{const n=e?.typeof,r=e?.instanceof;return[Tr(n,r),Pr(n,r,t,e?.onerror)]})(t);return class extends e{add(e){return n(e)?super.add(e):r(e)}}})(Set);const{entries:xr}=Object,Rr=["import os as _os","from pathlib import Path as _Path","_path = None"],jr=new class extends Array{#e=!1;#t;#n;constructor(e,...t){super(),this.#n=e,this.#t=t}push(...e){return this.#e&&super.push(...e),this.#n.push(...e)}path(e){for(const t of this.#t)if(this.#e=e.startsWith(t))break}}(Rr,"-"),Ar=(e,t)=>{for(const[n,r]of xr(t))if(jr.path(`${e}/${n}`),jr.push(`_path = _Path("${e}/${n}")`),"string"==typeof r){const e=JSON.stringify(r);jr.push(`_path.write_text(${e},encoding="utf-8")`)}else jr.push(`if not _os.path.exists("${e}/${n}"):`),jr.push(" _path.mkdir(parents=True, exist_ok=True)"),Ar(`${e}/${n}`,r)};Ar(".",{pyscript:{"__init__.py":'# Some notes about the naming conventions and the relationship between various\n# similar-but-different names.\n#\n# import pyscript\n# this package contains the main user-facing API offered by pyscript. All\n# the names which are supposed be used by end users should be made\n# available in pyscript/__init__.py (i.e., this file)\n#\n# import _pyscript\n# this is an internal module implemented in JS. It is used internally by\n# the pyscript package, end users should not use it directly. For its\n# implementation, grep for `interpreter.registerJsModule("_pyscript",\n# ...)` in core.js\n#\n# import js\n# this is the JS globalThis, as exported by pyodide and/or micropython\'s\n# FFIs. As such, it contains different things in the main thread or in a\n# worker.\n#\n# import pyscript.magic_js\n# this submodule abstracts away some of the differences between the main\n# thread and the worker. In particular, it defines `window` and `document`\n# in such a way that these names work in both cases: in the main thread,\n# they are the "real" objects, in the worker they are proxies which work\n# thanks to coincident.\n#\n# from pyscript import window, document\n# these are just the window and document objects as defined by\n# pyscript.magic_js. This is the blessed way to access them from pyscript,\n# as it works transparently in both the main thread and worker cases.\n\nfrom polyscript import lazy_py_modules as py_import\nfrom pyscript.display import HTML, display\nfrom pyscript.fetch import fetch\nfrom pyscript.magic_js import (\n RUNNING_IN_WORKER,\n PyWorker,\n config,\n current_target,\n document,\n js_import,\n js_modules,\n sync,\n window,\n)\nfrom pyscript.websocket import WebSocket\n\ntry:\n from pyscript.event_handling import when\nexcept:\n # TODO: should we remove this? Or at the very least, we should capture\n # the traceback otherwise it\'s very hard to debug\n from pyscript.util import NotSupported\n\n when = NotSupported(\n "pyscript.when", "pyscript.when currently not available with this interpreter"\n )\n',"display.py":'import base64\nimport html\nimport io\nimport re\n\nfrom pyscript.magic_js import current_target, document, window\n\n_MIME_METHODS = {\n "savefig": "image/png",\n "_repr_javascript_": "application/javascript",\n "_repr_json_": "application/json",\n "_repr_latex": "text/latex",\n "_repr_png_": "image/png",\n "_repr_jpeg_": "image/jpeg",\n "_repr_pdf_": "application/pdf",\n "_repr_svg_": "image/svg+xml",\n "_repr_markdown_": "text/markdown",\n "_repr_html_": "text/html",\n "__repr__": "text/plain",\n}\n\n\ndef _render_image(mime, value, meta):\n # If the image value is using bytes we should convert it to base64\n # otherwise it will return raw bytes and the browser will not be able to\n # render it.\n if isinstance(value, bytes):\n value = base64.b64encode(value).decode("utf-8")\n\n # This is the pattern of base64 strings\n base64_pattern = re.compile(\n r"^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$"\n )\n # If value doesn\'t match the base64 pattern we should encode it to base64\n if len(value) > 0 and not base64_pattern.match(value):\n value = base64.b64encode(value.encode("utf-8")).decode("utf-8")\n\n data = f"data:{mime};charset=utf-8;base64,{value}"\n attrs = " ".join([\'{k}="{v}"\' for k, v in meta.items()])\n return f\'<img src="{data}" {attrs}></img>\'\n\n\ndef _identity(value, meta):\n return value\n\n\n_MIME_RENDERERS = {\n "text/plain": html.escape,\n "text/html": _identity,\n "image/png": lambda value, meta: _render_image("image/png", value, meta),\n "image/jpeg": lambda value, meta: _render_image("image/jpeg", value, meta),\n "image/svg+xml": _identity,\n "application/json": _identity,\n "application/javascript": lambda value, meta: f"<script>{value}<\\\\/script>",\n}\n\n\nclass HTML:\n """\n Wrap a string so that display() can render it as plain HTML\n """\n\n def __init__(self, html):\n self._html = html\n\n def _repr_html_(self):\n return self._html\n\n\ndef _eval_formatter(obj, print_method):\n """\n Evaluates a formatter method.\n """\n if print_method == "__repr__":\n return repr(obj)\n elif hasattr(obj, print_method):\n if print_method == "savefig":\n buf = io.BytesIO()\n obj.savefig(buf, format="png")\n buf.seek(0)\n return base64.b64encode(buf.read()).decode("utf-8")\n return getattr(obj, print_method)()\n elif print_method == "_repr_mimebundle_":\n return {}, {}\n return None\n\n\ndef _format_mime(obj):\n """\n Formats object using _repr_x_ methods.\n """\n if isinstance(obj, str):\n return html.escape(obj), "text/plain"\n\n mimebundle = _eval_formatter(obj, "_repr_mimebundle_")\n if isinstance(mimebundle, tuple):\n format_dict, _ = mimebundle\n else:\n format_dict = mimebundle\n\n output, not_available = None, []\n for method, mime_type in _MIME_METHODS.items():\n if mime_type in format_dict:\n output = format_dict[mime_type]\n else:\n output = _eval_formatter(obj, method)\n\n if output is None:\n continue\n elif mime_type not in _MIME_RENDERERS:\n not_available.append(mime_type)\n continue\n break\n if output is None:\n if not_available:\n window.console.warn(\n f"Rendered object requested unavailable MIME renderers: {not_available}"\n )\n output = repr(output)\n mime_type = "text/plain"\n elif isinstance(output, tuple):\n output, meta = output\n else:\n meta = {}\n return _MIME_RENDERERS[mime_type](output, meta), mime_type\n\n\ndef _write(element, value, append=False):\n html, mime_type = _format_mime(value)\n if html == "\\\\n":\n return\n\n if append:\n out_element = document.createElement("div")\n element.append(out_element)\n else:\n out_element = element.lastElementChild\n if out_element is None:\n out_element = element\n\n if mime_type in ("application/javascript", "text/html"):\n script_element = document.createRange().createContextualFragment(html)\n out_element.append(script_element)\n else:\n out_element.innerHTML = html\n\n\ndef display(*values, target=None, append=True):\n if target is None:\n target = current_target()\n elif not isinstance(target, str):\n raise TypeError(f"target must be str or None, not {target.__class__.__name__}")\n elif target == "":\n raise ValueError("Cannot have an empty target")\n elif target.startswith("#"):\n # note: here target is str and not None!\n # align with @when behavior\n target = target[1:]\n\n element = document.getElementById(target)\n\n # If target cannot be found on the page, a ValueError is raised\n if element is None:\n raise ValueError(\n f"Invalid selector with id={target}. Cannot be found in the page."\n )\n\n # if element is a <script type="py">, it has a \'target\' attribute which\n # points to the visual element holding the displayed values. In that case,\n # use that.\n if element.tagName == "SCRIPT" and hasattr(element, "target"):\n element = element.target\n\n for v in values:\n if not append:\n element.replaceChildren()\n _write(element, v, append=append)\n',"event_handling.py":'import inspect\n\ntry:\n from pyodide.ffi.wrappers import add_event_listener\n\nexcept ImportError:\n\n def add_event_listener(el, event_type, func):\n el.addEventListener(event_type, func)\n\n\nfrom pyscript.magic_js import document\n\n\ndef when(event_type=None, selector=None):\n """\n Decorates a function and passes py-* events to the decorated function\n The events might or not be an argument of the decorated function\n """\n\n def decorator(func):\n\n from pyscript.web.elements import Element, ElementCollection\n\n if isinstance(selector, str):\n elements = document.querySelectorAll(selector)\n else:\n # TODO: This is a hack that will be removed when pyscript becomes a package\n # and we can better manage the imports without circular dependencies\n if isinstance(selector, Element):\n elements = [selector._js]\n elif isinstance(selector, ElementCollection):\n elements = [el._js for el in selector]\n else:\n raise ValueError(\n f"Invalid selector: {selector}. Selector must"\n " be a string, a pydom.Element or a pydom.ElementCollection."\n )\n try:\n sig = inspect.signature(func)\n # Function doesn\'t receive events\n if not sig.parameters:\n\n def wrapper(*args, **kwargs):\n func()\n\n else:\n wrapper = func\n\n except AttributeError:\n # TODO: this is very ugly hack to get micropython working because inspect.signature\n # doesn\'t exist, but we need to actually properly replace inspect.signature.\n # It may be actually better to not try any magic for now and raise the error\n def wrapper(*args, **kwargs):\n try:\n return func(*args, **kwargs)\n except TypeError as e:\n if "takes" in str(e) and "positional arguments" in str(e):\n return func()\n\n raise\n\n for el in elements:\n add_event_listener(el, event_type, wrapper)\n\n return func\n\n return decorator\n',"fetch.py":'import json\n\nimport js\nfrom pyscript.util import as_bytearray\n\n\n### wrap the response to grant Pythonic results\nclass _Response:\n def __init__(self, response):\n self._response = response\n\n # grant access to response.ok and other fields\n def __getattr__(self, attr):\n return getattr(self._response, attr)\n\n # exposed methods with Pythonic results\n async def arrayBuffer(self):\n buffer = await self._response.arrayBuffer()\n # works in Pyodide\n if hasattr(buffer, "to_py"):\n return buffer.to_py()\n # shims in MicroPython\n return memoryview(as_bytearray(buffer))\n\n async def blob(self):\n return await self._response.blob()\n\n async def bytearray(self):\n buffer = await self._response.arrayBuffer()\n return as_bytearray(buffer)\n\n async def json(self):\n return json.loads(await self.text())\n\n async def text(self):\n return await self._response.text()\n\n\n### allow direct await to _Response methods\nclass _DirectResponse:\n @staticmethod\n def setup(promise, response):\n promise._response = _Response(response)\n return promise._response\n\n def __init__(self, promise):\n self._promise = promise\n promise._response = None\n promise.arrayBuffer = self.arrayBuffer\n promise.blob = self.blob\n promise.bytearray = self.bytearray\n promise.json = self.json\n promise.text = self.text\n\n async def _response(self):\n if not self._promise._response:\n await self._promise\n return self._promise._response\n\n async def arrayBuffer(self):\n response = await self._response()\n return await response.arrayBuffer()\n\n async def blob(self):\n response = await self._response()\n return await response.blob()\n\n async def bytearray(self):\n response = await self._response()\n return await response.bytearray()\n\n async def json(self):\n response = await self._response()\n return await response.json()\n\n async def text(self):\n response = await self._response()\n return await response.text()\n\n\ndef fetch(url, **kw):\n # workaround Pyodide / MicroPython dict <-> js conversion\n options = js.JSON.parse(json.dumps(kw))\n awaited = lambda response, *args: _DirectResponse.setup(promise, response)\n promise = js.fetch(url, options).then(awaited)\n _DirectResponse(promise)\n return promise\n',"ffi.py":'try:\n import js\n from pyodide.ffi import create_proxy as _cp\n from pyodide.ffi import to_js as _py_tjs\n\n from_entries = js.Object.fromEntries\n\n def _tjs(value, **kw):\n if not hasattr(kw, "dict_converter"):\n kw["dict_converter"] = from_entries\n return _py_tjs(value, **kw)\n\nexcept:\n from jsffi import create_proxy as _cp\n from jsffi import to_js as _tjs\n\ncreate_proxy = _cp\nto_js = _tjs\n',"magic_js.py":'import json\nimport sys\n\nimport js as globalThis\nfrom polyscript import config as _config\nfrom polyscript import js_modules\nfrom pyscript.util import NotSupported\n\nRUNNING_IN_WORKER = not hasattr(globalThis, "document")\n\nconfig = json.loads(globalThis.JSON.stringify(_config))\n\n\n# allow `from pyscript.js_modules.xxx import yyy`\nclass JSModule:\n def __init__(self, name):\n self.name = name\n\n def __getattr__(self, field):\n # avoid pyodide looking for non existent fields\n if not field.startswith("_"):\n return getattr(getattr(js_modules, self.name), field)\n\n\n# generate N modules in the system that will proxy the real value\nfor name in globalThis.Reflect.ownKeys(js_modules):\n sys.modules[f"pyscript.js_modules.{name}"] = JSModule(name)\nsys.modules["pyscript.js_modules"] = js_modules\n\nif RUNNING_IN_WORKER:\n import polyscript\n\n PyWorker = NotSupported(\n "pyscript.PyWorker",\n "pyscript.PyWorker works only when running in the main thread",\n )\n\n try:\n globalThis.SharedArrayBuffer.new(4)\n import js\n\n window = polyscript.xworker.window\n document = window.document\n js.document = document\n # this is the same as js_import on main and it lands modules on main\n js_import = window.Function(\n "return (...urls) => Promise.all(urls.map((url) => import(url)))"\n )()\n except:\n globalThis.console.debug("SharedArrayBuffer is not available")\n # in this scenario none of the utilities would work\n # as expected so we better export these as NotSupported\n window = NotSupported(\n "pyscript.window",\n "pyscript.window in workers works only via SharedArrayBuffer",\n )\n document = NotSupported(\n "pyscript.document",\n "pyscript.document in workers works only via SharedArrayBuffer",\n )\n\n sync = polyscript.xworker.sync\n\n # in workers the display does not have a default ID\n # but there is a sync utility from xworker\n def current_target():\n return polyscript.target\n\nelse:\n import _pyscript\n from _pyscript import PyWorker, js_import\n\n window = globalThis\n document = globalThis.document\n sync = NotSupported(\n "pyscript.sync", "pyscript.sync works only when running in a worker"\n )\n\n # in MAIN the current element target exist, just use it\n def current_target():\n return _pyscript.target\n',"util.py":'import js\n\n\ndef as_bytearray(buffer):\n ui8a = js.Uint8Array.new(buffer)\n size = ui8a.length\n ba = bytearray(size)\n for i in range(0, size):\n ba[i] = ui8a[i]\n return ba\n\n\nclass NotSupported:\n """\n Small helper that raises exceptions if you try to get/set any attribute on\n it.\n """\n\n def __init__(self, name, error):\n object.__setattr__(self, "name", name)\n object.__setattr__(self, "error", error)\n\n def __repr__(self):\n return f"<NotSupported {self.name} [{self.error}]>"\n\n def __getattr__(self, attr):\n raise AttributeError(self.error)\n\n def __setattr__(self, attr, value):\n raise AttributeError(self.error)\n\n def __call__(self, *args):\n raise TypeError(self.error)\n',web:{"__init__.py":"from . import elements\n\n# Ugly trick to hide the dom module in the web package since we want the module\n# to allow querying right away.\nfrom .dom import dom\n","dom.py":'from pyscript import document\nfrom pyscript.web.elements import Element, ElementCollection\n\n\nclass PyDom:\n # Add objects we want to expose to the DOM namespace since this class instance is being\n # remapped as "the module" itself\n ElementCollection = ElementCollection\n\n def __init__(self):\n self._js = document\n\n self.body = Element(document.body)\n self.head = Element(document.head)\n\n def __getitem__(self, key):\n elements = self._js.querySelectorAll(key)\n return ElementCollection([Element(el) for el in elements])\n\n\ndom = PyDom()\n',"elements.py":'import inspect\nimport sys\n\ntry:\n from typing import Any\nexcept ImportError:\n Any = "Any"\n\ntry:\n import warnings\nexcept ImportError:\n # TODO: For now it probably means we are in MicroPython. We should figure\n # out the "right" way to handle this. For now we just ignore the warning\n # and logging to console\n class warnings:\n @staticmethod\n def warn(*args, **kwargs):\n print("WARNING: ", *args, **kwargs)\n\n\ntry:\n from functools import cached_property\nexcept ImportError:\n # TODO: same comment about micropython as above\n cached_property = property\n\ntry:\n from pyodide.ffi import JsProxy\nexcept ImportError:\n # TODO: same comment about micropython as above\n def JsProxy(obj):\n return obj\n\n\nfrom pyscript import document, window\n\n# from pyscript.web import dom as pydom\n\n#: A flag to show if MicroPython is the current Python interpreter.\nis_micropython = "MicroPython" in sys.version\n\n\ndef getmembers_static(cls):\n """Cross-interpreter implementation of inspect.getmembers_static."""\n\n if is_micropython: # pragma: no cover\n return [(name, getattr(cls, name)) for name, _ in inspect.getmembers(cls)]\n\n return inspect.getmembers_static(cls)\n\n\nclass JSProperty:\n """JS property descriptor that directly maps to the property with the same\n name in the underlying JS component."""\n\n def __init__(self, name: str, allow_nones: bool = False):\n self.name = name\n self.allow_nones = allow_nones\n\n def __get__(self, obj, objtype=None):\n return getattr(obj._js, self.name)\n\n def __set__(self, obj, value):\n if not self.allow_nones and value is None:\n return\n setattr(obj._js, self.name, value)\n\n\n# ------ TODO: REMOVE!!!! pydom elements\n\n\nclass BaseElement:\n def __init__(self, js_element):\n self._js = js_element\n self._parent = None\n self.style = StyleProxy(self)\n self._proxies = {}\n\n def __eq__(self, obj):\n """Check if the element is the same as the other element by comparing\n the underlying JS element"""\n return isinstance(obj, BaseElement) and obj._js == self._js\n\n @property\n def parent(self):\n if self._parent:\n return self._parent\n\n if self._js.parentElement:\n # TODO: This should actually return the correct class (== to tagName)\n self._parent = Element(self._js.parentElement)\n\n return self._parent\n\n # @property\n # def __class(self):\n # return self.__class__ if self.__class__ != PyDom else Element\n\n def create(self, type_, is_child=True, classes=None, html=None, label=None):\n js_el = document.createElement(type_)\n element = self.__class(js_el)\n\n if classes:\n for class_ in classes:\n element.add_class(class_)\n\n if html is not None:\n element.html = html\n\n if label is not None:\n element.label = label\n\n if is_child:\n self.append(element)\n\n return element\n\n def find(self, selector):\n """Return an ElementCollection representing all the child elements that\n match the specified selector.\n\n Args:\n selector (str): A string containing a selector expression\n\n Returns:\n ElementCollection: A collection of elements matching the selector\n """\n elements = self._js.querySelectorAll(selector)\n if not elements:\n return None\n return ElementCollection([Element(el) for el in elements])\n\n\nclass Element(BaseElement):\n @property\n def children(self):\n return [self.__class__(el) for el in self._js.children]\n\n def append(self, child):\n # TODO: this is Pyodide specific for now!!!!!!\n # if we get passed a JSProxy Element directly we just map it to the\n # higher level Python element\n if inspect.isclass(JsProxy) and isinstance(child, JsProxy):\n return self.append(Element(child))\n\n elif isinstance(child, Element):\n self._js.appendChild(child._js)\n\n return child\n\n elif isinstance(child, ElementCollection):\n for el in child:\n self.append(el)\n\n # -------- Pythonic Interface to Element -------- #\n @property\n def html(self):\n return self._js.innerHTML\n\n @html.setter\n def html(self, value):\n self._js.innerHTML = value\n\n @property\n def text(self):\n return self._js.textContent\n\n @text.setter\n def text(self, value):\n self._js.textContent = value\n\n @property\n def content(self):\n # TODO: This breaks with with standard template elements. Define how to best\n # handle this specifica use case. Just not support for now?\n if self._js.tagName == "TEMPLATE":\n warnings.warn(\n "Content attribute not supported for template elements.", stacklevel=2\n )\n return None\n return self._js.innerHTML\n\n @content.setter\n def content(self, value):\n # TODO: (same comment as above)\n if self._js.tagName == "TEMPLATE":\n warnings.warn(\n "Content attribute not supported for template elements.", stacklevel=2\n )\n return\n\n display(value, target=self.id)\n\n @property\n def id(self):\n return self._js.id\n\n @id.setter\n def id(self, value):\n self._js.id = value\n\n @property\n def options(self):\n if "options" in self._proxies:\n return self._proxies["options"]\n\n if not self._js.tagName.lower() in {"select", "datalist", "optgroup"}:\n raise AttributeError(\n f"Element {self._js.tagName} has no options attribute."\n )\n self._proxies["options"] = OptionsProxy(self)\n return self._proxies["options"]\n\n @property\n def value(self):\n return self._js.value\n\n @value.setter\n def value(self, value):\n # in order to avoid confusion to the user, we don\'t allow setting the\n # value of elements that don\'t have a value attribute\n if not hasattr(self._js, "value"):\n raise AttributeError(\n f"Element {self._js.tagName} has no value attribute. If you want to "\n "force a value attribute, set it directly using the `_js.value = <value>` "\n "javascript API attribute instead."\n )\n self._js.value = value\n\n @property\n def selected(self):\n return self._js.selected\n\n @selected.setter\n def selected(self, value):\n # in order to avoid confusion to the user, we don\'t allow setting the\n # value of elements that don\'t have a value attribute\n if not hasattr(self._js, "selected"):\n raise AttributeError(\n f"Element {self._js.tagName} has no value attribute. If you want to "\n "force a value attribute, set it directly using the `_js.value = <value>` "\n "javascript API attribute instead."\n )\n self._js.selected = value\n\n def clone(self, new_id=None):\n clone = Element(self._js.cloneNode(True))\n clone.id = new_id\n\n return clone\n\n def remove_class(self, classname):\n classList = self._js.classList\n if isinstance(classname, list):\n classList.remove(*classname)\n else:\n classList.remove(classname)\n return self\n\n def add_class(self, classname):\n classList = self._js.classList\n if isinstance(classname, list):\n classList.add(*classname)\n else:\n self._js.classList.add(classname)\n return self\n\n @property\n def classes(self):\n classes = self._js.classList.values()\n return [x for x in classes]\n\n def show_me(self):\n self._js.scrollIntoView()\n\n def snap(\n self,\n to: BaseElement | str = None,\n width: int | None = None,\n height: int | None = None,\n ):\n """\n Captures a snapshot of a video element. (Only available for video elements)\n\n Inputs:\n\n * to: element where to save the snapshot of the video frame to\n * width: width of the image\n * height: height of the image\n\n Output:\n (Element) canvas element where the video frame snapshot was drawn into\n """\n if self._js.tagName != "VIDEO":\n raise AttributeError("Snap method is only available for video Elements")\n\n if to is None:\n canvas = self.create("canvas")\n if width is None:\n width = self._js.width\n if height is None:\n height = self._js.height\n canvas._js.width = width\n canvas._js.height = height\n\n elif isinstance(to, Element):\n if to._js.tagName != "CANVAS":\n raise TypeError("Element to snap to must a canvas.")\n canvas = to\n elif getattr(to, "tagName", "") == "CANVAS":\n canvas = Element(to)\n elif isinstance(to, str):\n # TODO (fpliger): This needs a better fix but doing a local import here for a quick fix\n from pyscript.web import dom\n\n canvas = dom[to][0]\n if canvas._js.tagName != "CANVAS":\n raise TypeError("Element to snap to must a be canvas.")\n\n canvas.draw(self, width, height)\n\n return canvas\n\n def download(self, filename: str = "snapped.png") -> None:\n """Download the current element (only available for canvas elements) with the filename\n provided in input.\n\n Inputs:\n * filename (str): name of the file being downloaded\n\n Output:\n None\n """\n if self._js.tagName != "CANVAS":\n raise AttributeError(\n "The download method is only available for canvas Elements"\n )\n\n link = self.create("a")\n link._js.download = filename\n link._js.href = self._js.toDataURL()\n link._js.click()\n\n def draw(self, what, width, height):\n """Draw `what` on the current element (only available for canvas elements).\n\n Inputs:\n\n * what (canvas image source): An element to draw into the context. The specification permits any canvas\n image source, specifically, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement,\n an HTMLCanvasElement, an ImageBitmap, an OffscreenCanvas, or a VideoFrame.\n """\n if self._js.tagName != "CANVAS":\n raise AttributeError(\n "The draw method is only available for canvas Elements"\n )\n\n if isinstance(what, Element):\n what = what._js\n\n # https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage\n self._js.getContext("2d").drawImage(what, 0, 0, width, height)\n\n\nclass OptionsProxy:\n """This class represents the options of a select element. It\n allows to access to add and remove options by using the `add` and `remove` methods.\n """\n\n def __init__(self, element: Element) -> None:\n self._element = element\n if self._element._js.tagName.lower() != "select":\n raise AttributeError(\n f"Element {self._element._js.tagName} has no options attribute."\n )\n\n def add(\n self,\n value: Any = None,\n html: str = None,\n text: str = None,\n before: Element | int = None,\n **kws,\n ) -> None:\n """Add a new option to the select element"""\n # create the option element and set the attributes\n option = document.createElement("option")\n if value is not None:\n kws["value"] = value\n if html is not None:\n option.innerHTML = html\n if text is not None:\n kws["text"] = text\n\n for key, value in kws.items():\n option.setAttribute(key, value)\n\n if before:\n if isinstance(before, Element):\n before = before._js\n\n self._element._js.add(option, before)\n\n def remove(self, item: int) -> None:\n """Remove the option at the specified index"""\n self._element._js.remove(item)\n\n def clear(self) -> None:\n """Remove all the options"""\n for i in range(len(self)):\n self.remove(0)\n\n @property\n def options(self):\n """Return the list of options"""\n return [Element(opt) for opt in self._element._js.options]\n\n @property\n def selected(self):\n """Return the selected option"""\n return self.options[self._element._js.selectedIndex]\n\n def __iter__(self):\n yield from self.options\n\n def __len__(self):\n return len(self.options)\n\n def __repr__(self):\n return f"{self.__class__.__name__} (length: {len(self)}) {self.options}"\n\n def __getitem__(self, key):\n return self.options[key]\n\n\nclass StyleProxy: # (dict):\n def __init__(self, element: Element) -> None:\n self._element = element\n\n @cached_property\n def _style(self):\n return self._element._js.style\n\n def __getitem__(self, key):\n return self._style.getPropertyValue(key)\n\n def __setitem__(self, key, value):\n self._style.setProperty(key, value)\n\n def remove(self, key):\n self._style.removeProperty(key)\n\n def set(self, **kws):\n for k, v in kws.items():\n self._element._js.style.setProperty(k, v)\n\n # CSS Properties\n # Reference: https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts#L3799C1-L5005C2\n # Following prperties automatically generated from the above reference using\n # tools/codegen_css_proxy.py\n @property\n def visible(self):\n return self._element._js.style.visibility\n\n @visible.setter\n def visible(self, value):\n self._element._js.style.visibility = value\n\n\n# --------- END OF PYDOM STUFF ------\n\n\nclass ElementBase(Element):\n tag = "div"\n\n # GLOBAL ATTRIBUTES\n # These are attribute that all elements have (this list is a subset of the official one)\n # We are trying to capture the most used ones\n accesskey = JSProperty("accesskey")\n autofocus = JSProperty("autofocus")\n autocapitalize = JSProperty("autocapitalize")\n className = JSProperty("className")\n contenteditable = JSProperty("contenteditable")\n draggable = JSProperty("draggable")\n enterkeyhint = JSProperty("enterkeyhint")\n hidden = JSProperty("hidden")\n id = JSProperty("id")\n lang = JSProperty("lang")\n nonce = JSProperty("nonce")\n part = JSProperty("part")\n popover = JSProperty("popover")\n slot = JSProperty("slot")\n spellcheck = JSProperty("spellcheck")\n tabindex = JSProperty("tabindex")\n title = JSProperty("title")\n translate = JSProperty("translate")\n virtualkeyboardpolicy = JSProperty("virtualkeyboardpolicy")\n\n def __init__(self, style=None, **kwargs):\n super().__init__(document.createElement(self.tag))\n\n # set all the style properties provided in input\n if isinstance(style, dict):\n for key, value in style.items():\n self.style[key] = value\n elif style is None:\n pass\n else:\n raise ValueError(\n f"Style should be a dictionary, received {style} (type {type(style)}) instead."\n )\n\n # IMPORTANT!!! This is used to auto-harvest all input arguments and set them as properties\n self._init_properties(**kwargs)\n\n def _init_properties(self, **kwargs):\n """Set all the properties (of type JSProperties) provided in input as properties\n of the class instance.\n\n Args:\n **kwargs: The properties to set\n """\n # Look at all the properties of the class and see if they were provided in kwargs\n for attr_name, attr in getmembers_static(self.__class__):\n # For each one, actually check if it is a property of the class and set it\n if isinstance(attr, JSProperty) and attr_name in kwargs:\n try:\n setattr(self, attr_name, kwargs[attr_name])\n except Exception as e:\n print(f"Error setting {attr_name} to {kwargs[attr_name]}: {e}")\n raise\n\n\nclass TextElementBase(ElementBase):\n def __init__(self, content=None, style=None, **kwargs):\n super().__init__(style=style, **kwargs)\n\n # If it\'s an element, append the element\n if isinstance(content, Element):\n self.append(content)\n # If it\'s a list of elements\n elif isinstance(content, list):\n for item in content:\n self.append(item)\n # If the content wasn\'t set just ignore\n elif content is None:\n pass\n else:\n # Otherwise, set content as the html of the element\n self.html = content\n\n\n# IMPORTANT: For all HTML components defined below, we are not mapping all\n# available attributes, just the global and the most common ones.\n# If you need to access a specific attribute, you can always use the `_js.<attribute>`\nclass a(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a"""\n\n tag = "a"\n\n download = JSProperty("download")\n href = JSProperty("href")\n referrerpolicy = JSProperty("referrerpolicy")\n rel = JSProperty("rel")\n target = JSProperty("target")\n type = JSProperty("type")\n\n\nclass abbr(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/abbr"""\n\n tag = "abbr"\n\n\nclass address(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/address"""\n\n tag = "address"\n\n\nclass area(ElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area"""\n\n tag = "area"\n\n alt = JSProperty("alt")\n coords = JSProperty("coords")\n download = JSProperty("download")\n href = JSProperty("href")\n ping = JSProperty("ping")\n referrerpolicy = JSProperty("referrerpolicy")\n rel = JSProperty("rel")\n shape = JSProperty("shape")\n target = JSProperty("target")\n\n\nclass article(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article"""\n\n tag = "article"\n\n\nclass aside(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside"""\n\n tag = "aside"\n\n\nclass audio(ElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio"""\n\n tag = "audio"\n\n autoplay = JSProperty("autoplay")\n controls = JSProperty("controls")\n controlslist = JSProperty("controlslist")\n crossorigin = JSProperty("crossorigin")\n disableremoteplayback = JSProperty("disableremoteplayback")\n loop = JSProperty("loop")\n muted = JSProperty("muted")\n preload = JSProperty("preload")\n src = JSProperty("src")\n\n\nclass b(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/b"""\n\n tag = "b"\n\n\nclass blockquote(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/blockquote"""\n\n tag = "blockquote"\n\n cite = JSProperty("cite")\n\n\nclass br(ElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br"""\n\n tag = "br"\n\n\nclass button(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button"""\n\n tag = "button"\n\n autofocus = JSProperty("autofocus")\n disabled = JSProperty("disabled")\n form = JSProperty("form")\n formaction = JSProperty("formaction")\n formenctype = JSProperty("formenctype")\n formmethod = JSProperty("formmethod")\n formnovalidate = JSProperty("formnovalidate")\n formtarget = JSProperty("formtarget")\n name = JSProperty("name")\n type = JSProperty("type")\n value = JSProperty("value")\n\n\nclass canvas(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas"""\n\n tag = "canvas"\n\n height = JSProperty("height")\n width = JSProperty("width")\n\n\nclass caption(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption"""\n\n tag = "caption"\n\n\nclass cite(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/cite"""\n\n tag = "cite"\n\n\nclass code(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code"""\n\n tag = "code"\n\n\nclass data(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data"""\n\n tag = "data"\n\n value = JSProperty("value")\n\n\nclass datalist(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist"""\n\n tag = "datalist"\n\n\nclass dd(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dd"""\n\n tag = "dd"\n\n\nclass del_(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del"""\n\n tag = "del"\n\n cite = JSProperty("cite")\n datetime = JSProperty("datetime")\n\n\nclass details(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details"""\n\n tag = "details"\n\n open = JSProperty("open")\n\n\nclass dialog(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog"""\n\n tag = "dialog"\n\n open = JSProperty("open")\n\n\nclass div(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div"""\n\n tag = "div"\n\n\nclass dl(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl"""\n\n tag = "dl"\n\n value = JSProperty("value")\n\n\nclass dt(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dt"""\n\n tag = "dt"\n\n\nclass em(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em"""\n\n tag = "em"\n\n\nclass embed(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed"""\n\n tag = "embed"\n\n height = JSProperty("height")\n src = JSProperty("src")\n type = JSProperty("type")\n width = JSProperty("width")\n\n\nclass fieldset(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset"""\n\n tag = "fieldset"\n\n disabled = JSProperty("disabled")\n form = JSProperty("form")\n name = JSProperty("name")\n\n\nclass figcaption(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption"""\n\n tag = "figcaption"\n\n\nclass figure(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure"""\n\n tag = "figure"\n\n\nclass footer(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer"""\n\n tag = "footer"\n\n\nclass form(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form"""\n\n tag = "form"\n\n accept_charset = JSProperty("accept-charset")\n action = JSProperty("action")\n autocapitalize = JSProperty("autocapitalize")\n autocomplete = JSProperty("autocomplete")\n enctype = JSProperty("enctype")\n name = JSProperty("name")\n method = JSProperty("method")\n nonvalidate = JSProperty("nonvalidate")\n rel = JSProperty("rel")\n target = JSProperty("target")\n\n\nclass h1(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h1"""\n\n tag = "h1"\n\n\nclass h2(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h2"""\n\n tag = "h2"\n\n\nclass h3(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h3"""\n\n tag = "h3"\n\n\nclass h4(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h4"""\n\n tag = "h4"\n\n\nclass h5(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h5"""\n\n tag = "h5"\n\n\nclass h6(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h6"""\n\n tag = "h6"\n\n\nclass header(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header"""\n\n tag = "header"\n\n\nclass hgroup(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hgroup"""\n\n tag = "hgroup"\n\n\nclass hr(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hr"""\n\n tag = "hr"\n\n\nclass i(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i"""\n\n tag = "i"\n\n\nclass iframe(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe"""\n\n tag = "iframe"\n\n allow = JSProperty("allow")\n allowfullscreen = JSProperty("allowfullscreen")\n height = JSProperty("height")\n loading = JSProperty("loading")\n name = JSProperty("name")\n referrerpolicy = JSProperty("referrerpolicy")\n sandbox = JSProperty("sandbox")\n src = JSProperty("src")\n srcdoc = JSProperty("srcdoc")\n width = JSProperty("width")\n\n\nclass img(ElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img"""\n\n tag = "img"\n\n alt = JSProperty("alt")\n crossorigin = JSProperty("crossorigin")\n decoding = JSProperty("decoding")\n fetchpriority = JSProperty("fetchpriority")\n height = JSProperty("height")\n ismap = JSProperty("ismap")\n loading = JSProperty("loading")\n referrerpolicy = JSProperty("referrerpolicy")\n sizes = JSProperty("sizes")\n src = JSProperty("src")\n width = JSProperty("width")\n\n\n# NOTE: Input is a reserved keyword in Python, so we use input_ instead\nclass input_(ElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input"""\n\n tag = "input"\n\n accept = JSProperty("accept")\n alt = JSProperty("alt")\n autofocus = JSProperty("autofocus")\n capture = JSProperty("capture")\n checked = JSProperty("checked")\n dirname = JSProperty("dirname")\n disabled = JSProperty("disabled")\n form = JSProperty("form")\n formaction = JSProperty("formaction")\n formenctype = JSProperty("formenctype")\n formmethod = JSProperty("formmethod")\n formnovalidate = JSProperty("formnovalidate")\n formtarget = JSProperty("formtarget")\n height = JSProperty("height")\n list = JSProperty("list")\n max = JSProperty("max")\n maxlength = JSProperty("maxlength")\n min = JSProperty("min")\n minlength = JSProperty("minlength")\n multiple = JSProperty("multiple")\n name = JSProperty("name")\n pattern = JSProperty("pattern")\n placeholder = JSProperty("placeholder")\n popovertarget = JSProperty("popovertarget")\n popovertargetaction = JSProperty("popovertargetaction")\n readonly = JSProperty("readonly")\n required = JSProperty("required")\n size = JSProperty("size")\n src = JSProperty("src")\n step = JSProperty("step")\n type = JSProperty("type")\n value = JSProperty("value")\n width = JSProperty("width")\n\n\nclass ins(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins"""\n\n tag = "ins"\n\n cite = JSProperty("cite")\n datetime = JSProperty("datetime")\n\n\nclass kbd(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd"""\n\n tag = "kbd"\n\n\nclass label(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label"""\n\n tag = "label"\n\n for_ = JSProperty("for")\n\n\nclass legend(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/legend"""\n\n tag = "legend"\n\n\nclass li(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li"""\n\n tag = "li"\n\n value = JSProperty("value")\n\n\nclass link(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link"""\n\n tag = "link"\n\n as_ = JSProperty("as")\n crossorigin = JSProperty("crossorigin")\n disabled = JSProperty("disabled")\n fetchpriority = JSProperty("fetchpriority")\n href = JSProperty("href")\n imagesizes = JSProperty("imagesizes")\n imagesrcset = JSProperty("imagesrcset")\n integrity = JSProperty("integrity")\n media = JSProperty("media")\n rel = JSProperty("rel")\n referrerpolicy = JSProperty("referrerpolicy")\n sizes = JSProperty("sizes")\n title = JSProperty("title")\n type = JSProperty("type")\n\n\nclass main(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/main"""\n\n tag = "main"\n\n\nclass map_(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map"""\n\n tag = "map"\n\n name = JSProperty("name")\n\n\nclass mark(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark"""\n\n tag = "mark"\n\n\nclass menu(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/menu"""\n\n tag = "menu"\n\n\nclass meter(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meter"""\n\n tag = "meter"\n\n form = JSProperty("form")\n high = JSProperty("high")\n low = JSProperty("low")\n max = JSProperty("max")\n min = JSProperty("min")\n optimum = JSProperty("optimum")\n value = JSProperty("value")\n\n\nclass nav(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nav"""\n\n tag = "nav"\n\n\nclass object_(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object"""\n\n tag = "object"\n\n data = JSProperty("data")\n form = JSProperty("form")\n height = JSProperty("height")\n name = JSProperty("name")\n type = JSProperty("type")\n usemap = JSProperty("usemap")\n width = JSProperty("width")\n\n\nclass ol(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol"""\n\n tag = "ol"\n\n reversed = JSProperty("reversed")\n start = JSProperty("start")\n type = JSProperty("type")\n\n\nclass optgroup(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup"""\n\n tag = "optgroup"\n\n disabled = JSProperty("disabled")\n label = JSProperty("label")\n\n\nclass option(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option"""\n\n tag = "option"\n\n disabled = JSProperty("value")\n label = JSProperty("label")\n selected = JSProperty("selected")\n value = JSProperty("value")\n\n\nclass output(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/output"""\n\n tag = "output"\n\n for_ = JSProperty("for")\n form = JSProperty("form")\n name = JSProperty("name")\n\n\nclass p(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p"""\n\n tag = "p"\n\n\nclass picture(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture"""\n\n tag = "picture"\n\n\nclass pre(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre"""\n\n tag = "pre"\n\n\nclass progress(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress"""\n\n tag = "progress"\n\n max = JSProperty("max")\n value = JSProperty("value")\n\n\nclass q(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q"""\n\n tag = "q"\n\n cite = JSProperty("cite")\n\n\nclass s(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/s"""\n\n tag = "s"\n\n\nclass script(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script"""\n\n tag = "script"\n\n # Let\'s add async manually since it\'s a reserved keyword in Python\n async_ = JSProperty("async")\n blocking = JSProperty("blocking")\n crossorigin = JSProperty("crossorigin")\n defer = JSProperty("defer")\n fetchpriority = JSProperty("fetchpriority")\n integrity = JSProperty("integrity")\n nomodule = JSProperty("nomodule")\n nonce = JSProperty("nonce")\n referrerpolicy = JSProperty("referrerpolicy")\n src = JSProperty("src")\n type = JSProperty("type")\n\n\nclass section(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section"""\n\n tag = "section"\n\n\nclass select(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select"""\n\n tag = "select"\n\n\nclass small(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/small"""\n\n tag = "small"\n\n\nclass source(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source"""\n\n tag = "source"\n\n media = JSProperty("media")\n sizes = JSProperty("sizes")\n src = JSProperty("src")\n srcset = JSProperty("srcset")\n type = JSProperty("type")\n\n\nclass span(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span"""\n\n tag = "span"\n\n\nclass strong(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strong"""\n\n tag = "strong"\n\n\nclass style(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style"""\n\n tag = "style"\n\n blocking = JSProperty("blocking")\n media = JSProperty("media")\n nonce = JSProperty("nonce")\n title = JSProperty("title")\n\n\nclass sub(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub"""\n\n tag = "sub"\n\n\nclass summary(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary"""\n\n tag = "summary"\n\n\nclass sup(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup"""\n\n tag = "sup"\n\n\nclass table(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table"""\n\n tag = "table"\n\n\nclass tbody(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody"""\n\n tag = "tbody"\n\n\nclass td(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td"""\n\n tag = "td"\n\n colspan = JSProperty("colspan")\n headers = JSProperty("headers")\n rowspan = JSProperty("rowspan")\n\n\nclass template(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template"""\n\n tag = "template"\n\n shadowrootmode = JSProperty("shadowrootmode")\n\n\nclass textarea(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea"""\n\n tag = "textarea"\n\n autocapitalize = JSProperty("autocapitalize")\n autocomplete = JSProperty("autocomplete")\n autofocus = JSProperty("autofocus")\n cols = JSProperty("cols")\n dirname = JSProperty("dirname")\n disabled = JSProperty("disabled")\n form = JSProperty("form")\n maxlength = JSProperty("maxlength")\n minlength = JSProperty("minlength")\n name = JSProperty("name")\n placeholder = JSProperty("placeholder")\n readonly = JSProperty("readonly")\n required = JSProperty("required")\n rows = JSProperty("rows")\n spellcheck = JSProperty("spellcheck")\n wrap = JSProperty("wrap")\n\n\nclass tfoot(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tfoot"""\n\n tag = "tfoot"\n\n\nclass th(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th"""\n\n tag = "th"\n\n\nclass thead(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/thead"""\n\n tag = "thead"\n\n\nclass time(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time"""\n\n tag = "time"\n\n datetime = JSProperty("datetime")\n\n\nclass title(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title"""\n\n tag = "title"\n\n\nclass tr(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr"""\n\n tag = "tr"\n\n abbr = JSProperty("abbr")\n colspan = JSProperty("colspan")\n headers = JSProperty("headers")\n rowspan = JSProperty("rowspan")\n scope = JSProperty("scope")\n\n\nclass track(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track"""\n\n tag = "track"\n\n default = JSProperty("default")\n kind = JSProperty("kind")\n label = JSProperty("label")\n src = JSProperty("src")\n srclang = JSProperty("srclang")\n\n\nclass u(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/u"""\n\n tag = "u"\n\n\nclass ul(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul"""\n\n tag = "ul"\n\n\nclass var(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/var"""\n\n tag = "var"\n\n\nclass video(TextElementBase):\n """Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video"""\n\n tag = "video"\n\n autoplay = JSProperty("autoplay")\n controls = JSProperty("controls")\n crossorigin = JSProperty("crossorigin")\n disablepictureinpicture = JSProperty("disablepictureinpicture")\n disableremoteplayback = JSProperty("disableremoteplayback")\n height = JSProperty("height")\n loop = JSProperty("loop")\n muted = JSProperty("muted")\n playsinline = JSProperty("playsinline")\n poster = JSProperty("poster")\n preload = JSProperty("preload")\n src = JSProperty("src")\n width = JSProperty("width")\n\n\n# Custom Elements\nclass grid(TextElementBase):\n tag = "div"\n\n def __init__(self, layout, content=None, gap=None, **kwargs):\n super().__init__(content, **kwargs)\n self.style["display"] = "grid"\n self.style["grid-template-columns"] = layout\n\n # TODO: This should be a property\n if not gap is None:\n self.style["gap"] = gap\n\n\nclass StyleCollection:\n def __init__(self, collection: "ElementCollection") -> None:\n self._collection = collection\n\n def __get__(self, obj, objtype=None):\n return obj._get_attribute("style")\n\n def __getitem__(self, key):\n return self._collection._get_attribute("style")[key]\n\n def __setitem__(self, key, value):\n for element in self._collection._elements:\n element.style[key] = value\n\n def remove(self, key):\n for element in self._collection._elements:\n element.style.remove(key)\n\n\nclass ElementCollection:\n def __init__(self, elements: [Element]) -> None:\n self._elements = elements\n self.style = StyleCollection(self)\n\n def __getitem__(self, key):\n # If it\'s an integer we use it to access the elements in the collection\n if isinstance(key, int):\n return self._elements[key]\n # If it\'s a slice we use it to support slice operations over the elements\n # in the collection\n elif isinstance(key, slice):\n return ElementCollection(self._elements[key])\n\n # If it\'s anything else (basically a string) we use it as a selector\n # TODO: Write tests!\n elements = self._element.querySelectorAll(key)\n return ElementCollection([Element(el) for el in elements])\n\n def __len__(self):\n return len(self._elements)\n\n def __eq__(self, obj):\n """Check if the element is the same as the other element by comparing\n the underlying JS element"""\n return isinstance(obj, ElementCollection) and obj._elements == self._elements\n\n def _get_attribute(self, attr, index=None):\n if index is None:\n return [getattr(el, attr) for el in self._elements]\n\n # As JQuery, when getting an attr, only return it for the first element\n return getattr(self._elements[index], attr)\n\n def _set_attribute(self, attr, value):\n for el in self._elements:\n setattr(el, attr, value)\n\n @property\n def html(self):\n return self._get_attribute("html")\n\n @html.setter\n def html(self, value):\n self._set_attribute("html", value)\n\n @property\n def value(self):\n return self._get_attribute("value")\n\n @value.setter\n def value(self, value):\n self._set_attribute("value", value)\n\n @property\n def children(self):\n return self._elements\n\n def __iter__(self):\n yield from self._elements\n\n def __repr__(self):\n return f"{self.__class__.__name__} (length: {len(self._elements)}) {self._elements}"\n',"media.py":'from pyodide.ffi import to_js\nfrom pyscript import window\n\n\nclass Device:\n """Device represents a media input or output device, such as a microphone,\n camera, or headset.\n """\n\n def __init__(self, device):\n self._js = device\n\n @property\n def id(self):\n return self._js.deviceId\n\n @property\n def group(self):\n return self._js.groupId\n\n @property\n def kind(self):\n return self._js.kind\n\n @property\n def label(self):\n return self._js.label\n\n def __getitem__(self, key):\n return getattr(self, key)\n\n @classmethod\n async def load(cls, audio=False, video=True):\n """Load the device stream."""\n options = window.Object.new()\n options.audio = audio\n if isinstance(video, bool):\n options.video = video\n else:\n # TODO: Think this can be simplified but need to check it on the pyodide side\n\n # TODO: this is pyodide specific. shouldn\'t be!\n options.video = window.Object.new()\n for k in video:\n setattr(\n options.video,\n k,\n to_js(video[k], dict_converter=window.Object.fromEntries),\n )\n\n stream = await window.navigator.mediaDevices.getUserMedia(options)\n return stream\n\n async def get_stream(self):\n key = self.kind.replace("input", "").replace("output", "")\n options = {key: {"deviceId": {"exact": self.id}}}\n\n return await self.load(**options)\n\n\nasync def list_devices() -> list[dict]:\n """\n Return the list of the currently available media input and output devices,\n such as microphones, cameras, headsets, and so forth.\n\n Output:\n\n list(dict) - list of dictionaries representing the available media devices.\n Each dictionary has the following keys:\n * deviceId: a string that is an identifier for the represented device\n that is persisted across sessions. It is un-guessable by other\n applications and unique to the origin of the calling application.\n It is reset when the user clears cookies (for Private Browsing, a\n different identifier is used that is not persisted across sessions).\n\n * groupId: a string that is a group identifier. Two devices have the same\n group identifier if they belong to the same physical device — for\n example a monitor with both a built-in camera and a microphone.\n\n * kind: an enumerated value that is either "videoinput", "audioinput"\n or "audiooutput".\n\n * label: a string describing this device (for example "External USB\n Webcam").\n\n Note: the returned list will omit any devices that are blocked by the document\n Permission Policy: microphone, camera, speaker-selection (for output devices),\n and so on. Access to particular non-default devices is also gated by the\n Permissions API, and the list will omit devices for which the user has not\n granted explicit permission.\n """\n # https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices\n return [\n Device(obj) for obj in await window.navigator.mediaDevices.enumerateDevices()\n ]\n'},"websocket.py":'import js\nfrom pyscript.util import as_bytearray\n\ncode = "code"\nprotocols = "protocols"\nreason = "reason"\n\n\nclass EventMessage:\n def __init__(self, event):\n self._event = event\n\n def __getattr__(self, attr):\n value = getattr(self._event, attr)\n\n if attr == "data" and not isinstance(value, str):\n if hasattr(value, "to_py"):\n return value.to_py()\n # shims in MicroPython\n return memoryview(as_bytearray(value))\n\n return value\n\n\nclass WebSocket(object):\n CONNECTING = 0\n OPEN = 1\n CLOSING = 2\n CLOSED = 3\n\n def __init__(self, **kw):\n url = kw["url"]\n if protocols in kw:\n socket = js.WebSocket.new(url, kw[protocols])\n else:\n socket = js.WebSocket.new(url)\n object.__setattr__(self, "_ws", socket)\n\n for t in ["onclose", "onerror", "onmessage", "onopen"]:\n if t in kw:\n socket[t] = kw[t]\n\n def __getattr__(self, attr):\n return getattr(self._ws, attr)\n\n def __setattr__(self, attr, value):\n if attr == "onmessage":\n self._ws[attr] = lambda e: value(EventMessage(e))\n else:\n self._ws[attr] = value\n\n def close(self, **kw):\n if code in kw and reason in kw:\n self._ws.close(kw[code], kw[reason])\n elif code in kw:\n self._ws.close(kw[code])\n else:\n self._ws.close()\n\n def send(self, data):\n if isinstance(data, str):\n self._ws.send(data)\n else:\n buffer = js.Uint8Array.new(len(data))\n for pos, b in enumerate(data):\n buffer[pos] = b\n self._ws.send(buffer)\n'}}),Rr.push("import pyscript as _pyscript"),Rr.push(...["_Path","_path","_os","_pyscript"].map((e=>`del ${e}`))),Rr.push("\n");const Jr=Rr.join("\n"),Nr=jr.join("\n"),Mr=e=>Ur.main[e],Or=e=>Ur.worker[e],Wr=(e,t,n,r)=>{e[n]=()=>{const e=r?[r]:[];return e.push(...t(n)),e.map(Ze).join("\n")}},Ir=(e,t)=>{const n="mpy"===t?Jr.replace(Nr,""):Jr,r={};return Wr(r,e,"codeBeforeRun",n),Wr(r,e,"codeBeforeRunAsync",n),Wr(r,e,"codeAfterRun"),Wr(r,e,"codeAfterRunAsync"),r},Lr=(e,t)=>{const n=[...Or(t)];if(n.length){const r=wn(e[`_${t}`]||(t.endsWith("Async")?async(e,t,...n)=>{for(const r of n)await r(e,t)}:(e,t,...n)=>{for(const r of n)r(e,t)})),s=n.map(wn).join(", ");return Function(`return(w,x)=>(${r})(w,x,...[${s}])`)()}},Hr=kr({typeof:"function"}),$r=kr({typeof:"string"}),Br='\n import builtins\n def input(prompt=""):\n raise Exception("\\n ".join([\n "input() doesn\'t work when PyScript runs in the main thread.",\n "Consider using the worker attribute: https://pyscript.github.io/docs/2023.11.2/user-guide/workers/"\n ]))\n\n builtins.input = input\n del builtins\n del input\n',Ur={main:{onWorker:new Hr,onReady:new Hr,onBeforeRun:new Hr,onBeforeRunAsync:new Hr,onAfterRun:new Hr,onAfterRunAsync:new Hr,codeBeforeRun:new $r([Br]),codeBeforeRunAsync:new $r,codeAfterRun:new $r,codeAfterRunAsync:new $r},worker:{onReady:new Hr,onBeforeRun:new Hr,onBeforeRunAsync:new Hr,onAfterRun:new Hr,onAfterRunAsync:new Hr,codeBeforeRun:new $r,codeBeforeRunAsync:new $r,codeAfterRun:new $r,codeAfterRunAsync:new $r}},Fr=({tagName:e})=>"SCRIPT"===e,[Cr,zr]=[...sr.entries()].map((([e,t])=>async function(n,r){await gr.get(e).plugins;const s=nr.call(new tr(null,Zr.get(e)),n,{...r,type:t});return tt(s.sync,_r),s.ready})),[{PyWorker:Dr,MPWorker:qr,hooks:Gr,config:Yr,whenDefined:Vr},Kr]=e("@pyscript/core",{PyWorker:Cr,MPWorker:zr,hooks:Ur,config:{},whenDefined:Qn}),Xr=e=>e?.interpreter&&new URL(e.interpreter,location.href).href,Zr=new Map;for(const[e,t]of sr){if(Kr)break;const n=(t,n,r)=>{n?r.then((()=>ft(t,e,"done"))):ft(t,e,"done")},{config:r,configURL:s,plugins:o,error:a}=gr.get(e);let i=0;const l=(t=e)=>`${t}-${i++}`,c=async(t,n,r)=>{if(t.hasAttribute("src"))try{return await fr(t.getAttribute("src")).then(pr)}catch(e){n.stderr(e)}if(r)return Ze(t.textContent);const s=Ze(Qe(t.innerHTML));return console.warn(`Deprecated: use <script type="${e}"> for an always safe content parsing:\n`,s),s};let p,f=!1;const d=({XWorker:e,interpreter:t,io:n})=>{f||(f=!0,t.registerJsModule("_pyscript",{PyWorker:function(...t){const r=e(...t);return r.onerror=({error:e})=>n.stderr(e),r},js_import:(...e)=>Promise.all(e.map((e=>import(e)))),get target(){return Fr(p)?p.target.id:p.id}}))};a||o.then((()=>{const o=new Map,a={main:{...Ir(Mr,e),async onReady(t,r){d(t);for(const e of Mr("onReady"))await e(t,r);if(o.has(r)){let{message:e}=o.get(r);o.delete(r);const n=e===Rn;return e=`(${ir.CONFLICTING_CODE}) ${e} for `,e+=r.cloneNode(n).outerHTML,void t.io.stderr(e)}if(Fr(r)){const{attributes:{async:s,target:o}}=r,a=!!o?.value,i=a?An(r,o.value):document.createElement("script-py");if(!a){const{head:e,body:t}=document;e.contains(r)?t.append(i):r.after(i)}i.id||(i.id=l()),st(r,"target",{value:i}),ft(r,e,"ready"),n(r,s,t["run"+(s?"Async":"")](await c(r,t.io,!0)))}else r._wrap.resolve(t);console.debug("[pyscript/main] PyScript Ready")},onWorker(e,t){tt(t.sync,_r);for(const n of Mr("onWorker"))n(e,t)},onBeforeRun(e,t){p=t,vr(Mr,e,t,"onBeforeRun")},onBeforeRunAsync:(e,t)=>(p=t,vr(Mr,e,t,"onBeforeRunAsync")),onAfterRun(e,t){vr(Mr,e,t,"onAfterRun")},onAfterRunAsync:(e,t)=>vr(Mr,e,t,"onAfterRunAsync")},worker:{...Ir(Or,e),get onReady(){return Lr(this,"onReady")},get onBeforeRun(){return Lr(this,"onBeforeRun")},get onBeforeRunAsync(){return Lr(this,"onBeforeRunAsync")},get onAfterRun(){return Lr(this,"onAfterRun")},get onAfterRunAsync(){return Lr(this,"onAfterRunAsync")}}};Zr.set(e,a),Zn(e,{config:r,configURL:s,interpreter:t,hooks:a,env:`${e}-script`,version:Xr(r),onerror(e,t){o.set(t,e)}}),customElements.define(`${e}-script`,class extends HTMLElement{constructor(){tt(super(),{_wrap:Promise.withResolvers(),srcCode:"",executed:!1})}get id(){return super.id||(super.id=l())}set id(e){super.id=e}async connectedCallback(){if(!this.executed){this.executed=!0;const t=this.hasAttribute("async"),{io:r,run:s,runAsync:o}=await this._wrap.promise;this.srcCode=await c(this,r,!this.childElementCount),this.replaceChildren(),this.style.display="block",ft(this,e,"ready"),n(this,t,(t?o:s)(this.srcCode))}}})})),Yr[e]=structuredClone(r)}export{tr as H,sr as T,nr as X,Ze as a,Nr as b,Xn as c,rt as d,Gr as e,Dr as f,qr as g,Yr as h,Br as i,Vr as j,Xr as o,Jr as s};
|
3
|
-
//# sourceMappingURL=core-BLQaGnG9.js.map
|