diff --git a/docs/README.md b/docs/README.md index c5484d7..aff8e6c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -11,6 +11,7 @@ * [XWorker](#xworker) - how `XWorker` class and its `xworker` reference work * [Custom Scripts](#custom-scripts) - how *custom types* can be defined and used to enrich any core feature * [Ready Event](#ready-event) - how to listen to the `type:ready` event + * [Done Event](#done-event) - how to listen to the `type:done` event * [Examples](#examples) - some *polyscript* based live example * [Interpreter Features](#interpreter-features) - current state of supported interpreters @@ -500,6 +501,10 @@ The [CustomEvent](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) The `worker` detail is essential to know if an `xworker` property is attached so that it's also easy to pollute its `sync` proxy utility. +## Done Event + +Whenever a *non-custom* script is going to run some code, or whenever *any worker* is going to run its own code, a `type:done` event is dispatched through the element *after* its code has fully executed. + ### Custom Types on Main The reason this event is not automatically dispatched on custom type elements or scripts is that these will have their own `onInterpreterReady` hook to eventually do more before desiring, or needing, to notify the "*readiness*" of such custom element and, in case of wanting the event to happen, this is the tiny boilerplate needed to simulate otherwise non-custom type events: diff --git a/docs/core.js b/docs/core.js index e96233a..d28c2b5 100644 --- a/docs/core.js +++ b/docs/core.js @@ -1,3 +1,3 @@ const e=(e,t=document)=>[...t.querySelectorAll(e)],t=(e,t=document)=>{const r=(new XPathEvaluator).createExpression(e).evaluate(t,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE),n=[];for(let e=0,{snapshotLength:t}=r;e((e,t)=>{const n=(t,r)=>(e.set(r,t),t),s=o=>{if(e.has(o))return e.get(o);const[a,i]=t[o];switch(a){case 0:case-1:return n(i,o);case 1:{const e=n([],o);for(const t of i)e.push(s(t));return e}case 2:{const e=n({},o);for(const[t,r]of i)e[s(t)]=s(r);return e}case 3:return n(new Date(i),o);case 4:{const{source:e,flags:t}=i;return n(new RegExp(e,t),o)}case 5:{const e=n(new Map,o);for(const[t,r]of i)e.set(s(t),s(r));return e}case 6:{const e=n(new Set,o);for(const t of i)e.add(s(t));return e}case 7:{const{name:e,message:t}=i;return n(new r[e](t),o)}case 8:return n(BigInt(i),o);case"BigInt":return n(Object(BigInt(i)),o)}return n(new r[a](i),o)};return s})(new Map,e)(0),s="",{toString:o}={},{keys:a}=Object,i=e=>{const t=typeof e;if("object"!==t||!e)return[0,t];const r=o.call(e).slice(8,-1);switch(r){case"Array":return[1,s];case"Object":return[2,s];case"Date":return[3,s];case"RegExp":return[4,s];case"Map":return[5,s];case"Set":return[6,s]}return r.includes("Array")?[1,r]:r.includes("Error")?[7,r]:[2,r]},c=([e,t])=>0===e&&("function"===t||"symbol"===t),l=(e,{json:t,lossy:r}={})=>{const n=[];return((e,t,r,n)=>{const s=(e,t)=>{const s=n.push(e)-1;return r.set(t,s),s},o=n=>{if(r.has(n))return r.get(n);let[l,u]=i(n);switch(l){case 0:{let t=n;switch(u){case"bigint":l=8,t=n.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+u);t=null;break;case"undefined":return s([-1],n)}return s([l,t],n)}case 1:{if(u)return s([u,[...n]],n);const e=[],t=s([l,e],n);for(const t of n)e.push(o(t));return t}case 2:{if(u)switch(u){case"BigInt":return s([u,n.toString()],n);case"Boolean":case"Number":case"String":return s([u,n.valueOf()],n)}if(t&&"toJSON"in n)return o(n.toJSON());const r=[],f=s([l,r],n);for(const t of a(n))!e&&c(i(n[t]))||r.push([o(t),o(n[t])]);return f}case 3:return s([l,n.toISOString()],n);case 4:{const{source:e,flags:t}=n;return s([l,{source:e,flags:t}],n)}case 5:{const t=[],r=s([l,t],n);for(const[r,s]of n)(e||!c(i(r))&&!c(i(s)))&&t.push([o(r),o(s)]);return r}case 6:{const t=[],r=s([l,t],n);for(const r of n)!e&&c(i(r))||t.push(o(r));return r}}const{message:f}=n;return s([l,{name:u,message:f}],n)};return o})(!(t||r),!!t,new Map,n)(e),n},{parse:u,stringify:f}=JSON,p={json:!0,lossy:!0};var d=Object.freeze({__proto__:null,parse:e=>n(u(e)),stringify:e=>f(l(e,p))});const h="5f50bb1c-57c3-47af-b36a-392fe80f8803",g="M"+h,y="T"+h;var w=e=>({value:new Promise((t=>{let r=new Worker("data:application/javascript,onmessage%3D(%7Bdata%3Ab%7D)%3D%3E(Atomics.wait(b%2C0)%2CpostMessage(0))");r.onmessage=t,r.postMessage(e)}))}) -/*! (c) Andrea Giammarchi - ISC */;const{Int32Array:m,Map:b,SharedArrayBuffer:v,Uint16Array:E}=globalThis,{BYTES_PER_ELEMENT:S}=m,{BYTES_PER_ELEMENT:$}=E,{isArray:A}=Array,{notify:P,wait:k,waitAsync:x}=Atomics,{fromCharCode:M}=String,j=new WeakSet,R=new WeakMap,T={value:{then:e=>e()}},O=()=>{};let _=0;const W=(e,{parse:t=JSON.parse,stringify:r=JSON.stringify,transform:n,interrupt:s}=JSON)=>{if(!R.has(e)){const o=(t,...r)=>e.postMessage({[h]:r},{transfer:t}),a="function"==typeof s?s:s?.handler||O,i=s?.delay||42,c=(e,t)=>e?(x||w)(t,0):(((e,t,r)=>{for(;"timed-out"===k(e,0,0,t);)r()})(t,i,a),T);let l=!1;R.set(e,new Proxy(new b,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,s)=>"then"===s?null:(...r)=>{const a=_++;let i=new m(new v(S)),u=[];j.has(r.at(-1)||u)&&j.delete(u=r.pop()),o(u,a,i,s,n?r.map(n):r);const f=e!==globalThis;let p=0;return l&&f&&(p=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),c(f,i).value.then((()=>{clearTimeout(p);const e=i[0];if(!e)return;const r=$*e;return i=new m(new v(r+r%S)),o([],a,i),c(f,i).value.then((()=>t(M(...new E(i.buffer).slice(0,e)))))}))},set(t,s,o){if(!t.size){const s=new b;e.addEventListener("message",(async e=>{const o=e.data?.[h];if(A(o)){e.stopImmediatePropagation();const[a,i,...c]=o;if(c.length){const[e,o]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);l=!0;try{const c=await t.get(e)(...o);if(void 0!==c){const e=r(n?n(c):c);s.set(a,e),i[0]=e.length}}finally{l=!1}}else{const e=s.get(a);s.delete(a);for(let t=new E(i.buffer),r=0;r(j.add(e),e);const F="object",I="function",B="number",J="string",L="undefined",C="symbol",{defineProperty:N,getOwnPropertyDescriptor:H,getPrototypeOf:D,isExtensible:U,ownKeys:X,preventExtensions:q,set:z,setPrototypeOf:Y}=Reflect,{assign:G,create:V}=Object,K=D(Int8Array),Q="isArray",Z=(e,t)=>{const{get:r,set:n,value:s}=e;return r&&(e.get=t(r)),n&&(e.set=t(n)),s&&(e.value=t(s)),e},ee=(e,t)=>[e,t],te=e=>t=>{const r=typeof t;switch(r){case F:if(null==t)return ee("null",t);if(t===globalThis)return ee(F,null);case I:return e(r,t);case"boolean":case B:case J:case L:case"bigint":return ee(r,t);case C:if(re.has(t))return ee(r,re.get(t))}throw new Error(`Unable to handle this ${r} type`)},re=new Map(X(Symbol).filter((e=>typeof Symbol[e]===C)).map((e=>[Symbol[e],e]))),ne=e=>{for(const[t,r]of re)if(r===e)return t};function se(){return this}const oe="apply",ae="construct",ie="defineProperty",ce="deleteProperty",le="get",ue="getOwnPropertyDescriptor",fe="getPrototypeOf",pe="has",de="isExtensible",he="ownKeys",ge="preventExtensions",ye="set",we="setPrototypeOf",me="delete";var be=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;N(EventTarget.prototype,"addEventListener",{value(t,n,...s){return s.at(0)?.invoke&&(r.has(this)||r.set(this,new Map),r.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,n,...s)}})}const n=t&&(e=>{const{currentTarget:t,target:n,type:s}=e;for(const o of r.get(t||n)?.get(s)||[])e[o]()});return(r,s,o,...a)=>{let i=0;const c=new Map,l=new Map,{[o]:u}=r,f=a.length?G(V(globalThis),...a):globalThis,p=te(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return ee(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(me,ee(J,e))})),h=([e,r])=>{switch(e){case F:if(null==r)return f;if(typeof r===B)return l.get(r);if(!(r instanceof K))for(const e in r)r[e]=h(r[e]);return r;case I:if(typeof r===J){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(oe,ee(I,r),p(this),e.map(p))},s=new WeakRef(e);l.set(r,s),d.register(e,r,s)}return l.get(r).deref()}return l.get(r);case C:return ne(r)}return r},g={[oe]:(e,t,r)=>p(e.apply(t,r)),[ae]:(e,t)=>p(new e(...t)),[ie]:(e,t,r)=>p(N(e,t,r)),[ce]:(e,t)=>p(delete e[t]),[fe]:e=>p(D(e)),[le]:(e,t)=>p(e[t]),[ue]:(e,t)=>{const r=H(e,t);return r?ee(F,Z(r,p)):ee(L,r)},[pe]:(e,t)=>p(t in e),[de]:e=>p(U(e)),[he]:e=>ee(F,X(e).map(p)),[ge]:e=>p(q(e)),[ye]:(e,t,r)=>p(z(e,t,r)),[we]:(e,t)=>p(Y(e,t)),[me](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case oe:r[0]=h(r[0]),r[1]=r[1].map(h);break;case ae:r[0]=r[0].map(h);break;case ie:{const[e,t]=r;r[0]=h(e);const{get:n,set:s,value:o}=t;n&&(t.get=h(n)),s&&(t.set=h(s)),o&&(t.value=h(o));break}default:r=r.map(h)}return g[e](h(t),...r)},{proxy:r,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window",!0),ve=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===I?e():e,a=e=>typeof e===F&&!!e&&s in e,i=Array[Q],c=te(((e,a)=>{if(s in a)return o(a[s]);if(e===I){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return ee(e,r.get(a))}if(!(a instanceof K))for(const e in a)a[e]=c(a[e]);return ee(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(me,c(e))})),h=e=>{const[t,r]=e;if(!p.has(r)){const n=t===I?se.bind(e):e,s=new Proxy(n,w),o=new WeakRef(s);p.set(r,o),d.register(s,r,o)}return p.get(r).deref()},g=e=>{const[t,r]=e;switch(t){case F:return null===r?globalThis:typeof r===B?h(e):r;case I:return typeof r===J?n.get(r):h(e);case C:return ne(r)}return r},y=(e,t,...r)=>g(f(e,o(t),...r)),w={[oe]:(e,t,r)=>y(oe,e,c(t),r.map(c)),[ae]:(e,t)=>y(ae,e,t.map(c)),[ie]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===I&&(r.get=c(n)),typeof s===I&&(r.set=c(s)),typeof o===I&&(r.value=c(o)),y(ie,e,c(t),r)},[ce]:(e,t)=>y(ce,e,c(t)),[fe]:e=>y(fe,e),[le]:(e,t)=>t===s?e:y(le,e,c(t)),[ue]:(e,t)=>{const r=y(ue,e,c(t));return r&&Z(r,g)},[pe]:(e,t)=>t===s||y(pe,e,c(t)),[de]:e=>y(de,e),[he]:e=>y(he,e).map(g),[ge]:e=>y(ge,e),[ye]:(e,t,r)=>y(ye,e,c(t),c(r)),[we]:(e,t)=>y(we,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case oe:return g(t).apply(g(s),o.map(g));case me:{const e=g(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([F,null],w),b=m.Array[Q];return N(Array,Q,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})("Window"),Ee="function"==typeof Worker?Worker:class{};const Se=new WeakMap,$e=(e,...t)=>{const r=W(e,...t);if(!Se.has(r)){const t=e instanceof Ee?be:ve;Se.set(r,t(r,g,y))}return Se.get(r)};$e.transfer=W.transfer;Promise.withResolvers||(Promise.withResolvers=function(){var e,t,r=new this((function(r,n){e=r,t=n}));return{resolve:e,reject:t,promise:r}});const Ae=e=>e.arrayBuffer(),Pe=e=>e.json(),ke=e=>e.text();const xe={object(...e){return this.string(function(e){for(var t=e[0],r=1,n=arguments.length;rxe[typeof e](e,...t),{replace:je}="",Re=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,Te={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'},Oe=e=>Te[e],{isArray:_e}=Array,{assign:We,create:Fe,defineProperties:Ie,defineProperty:Be,entries:Je}=Object,{all:Le,resolve:Ce}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Ne=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href;let He=0;const De=(e,t)=>({id:e.id||(e.id=`${t}-w${He++}`),tag:e.tagName}),Ue=new WeakMap,Xe=e=>{const t=e||console,r={stderr:(t.stderr||console.error).bind(t),stdout:(t.stdout||console.log).bind(t)};return{stderr:(...e)=>r.stderr(...e),stdout:(...e)=>r.stdout(...e),async get(e){const t=await e;return Ue.set(t,r),t}}},qe=({FS:e,PATH:t,PATH_FS:r},n,s)=>{const o=r.resolve(n);return e.mkdirTree(t.dirname(o)),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},ze=e=>{const t=e.split("/");return t.pop(),t.join("/")},Ye=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Ge=(e,t)=>{const r=[];for(const e of t.split("/"))switch(e){case"":case".":break;case"..":r.pop();break;default:r.push(e)}return[e.cwd()].concat(r).join("/").replace(/^\/+/,"/")},Ve=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Ke=(e,t)=>fetch(Ne(t,Qe.get(e))),Qe=new WeakMap,Ze=(e,t,r)=>Le((e=>{for(const{files:t,to_file:r,from:n=""}of e){if(void 0!==t&&void 0!==r)throw new Error("Cannot use 'to_file' and 'files' parameters together!");if(void 0===t&&void 0===r&&n.endsWith("/"))throw new Error(`Couldn't determine the filename from the path ${n}, please supply 'to_file' parameter.`)}return e.flatMap((({from:e="",to_folder:t=".",to_file:r,files:n})=>{if(_e(n))return n.map((r=>({url:Ve([e,r]),path:Ve([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:Ve([t,s])}]}))})(r).map((({url:n,path:s})=>Ke(r,n).then(Ae).then((r=>e.writeFile(t,s,r)))))),et=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,tt=(e,t)=>e.replace(/\{.+?\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),rt=(e,t,r)=>Le((e=>{const t=new Map,r=new Set,n=[];for(const[s,o]of Object.entries(e))if(/^\{.+\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,tt(o,t))}else{const e=tt(s,t),a=et(e,tt(o||"./",t));if(r.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);r.add(a),n.push({url:e,path:a})}return n})(r).map((({url:n,path:s})=>Ke(r,n).then(Ae).then((r=>e.writeFile(t,s,r)))))),nt=(e,t,r)=>{e.registerJsModule(t,r)},st=(e,t,...r)=>{try{return e.runPython(Me(t),...r)}catch(t){Ue.get(e).stderr(t)}},ot=async(e,t,...r)=>{try{return await e.runPythonAsync(Me(t),...r)}catch(t){Ue.get(e).stderr(t)}},at=async(e,t,r)=>{const[n,...s]=t.split(".");let o,a=e.globals.get(n);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,r)}catch(t){Ue.get(e).stderr(t)}};var it={type:"micropython",module:(e="1.20.0-297")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,r){const{stderr:n,stdout:s,get:o}=Xe();r=r.replace(/\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.files&&await rt(this,a,t.files),t.fetch&&await Ze(this,a,t.fetch),a},registerJSModule:nt,run:st,runAsync:ot,runEvent:at,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>qe({FS:e,PATH:t,PATH_FS:r},n,s)};const ct={dict_converter:Object.fromEntries};var lt={type:"pyodide",module:(e="0.24.1")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Xe(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.files&&await rt(this,i,t.files),t.fetch&&await Ze(this,i,t.fetch),t.packages){await i.loadPackage("micropip");const e=await i.pyimport("micropip");await e.install(t.packages),e.destroy()}return i},registerJSModule:nt,run:st,runAsync:ot,runEvent:at,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(ct):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>qe({FS:e,PATH:t,PATH_FS:r},n,s)};const ut="ruby-wasm-wasi",ft=ut.replace(/\W+/g,"_");var pt={type:ut,experimental:!0,module:(e="2.1.0")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,r){const n=await fetch(`${r.slice(0,r.lastIndexOf("/"))}/ruby.wasm`),s=await WebAssembly.compile(await n.arrayBuffer()),{vm:o}=await e(s);return t.files&&await rt(this,o,t.files),t.fetch&&await Ze(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${ft}_${t}`;globalThis[n]=r,this.run(e,`require "js";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval(Me(t),...r),runAsync:(e,t,...r)=>e.evalAsync(Me(t),...r),async runEvent(e,t,r){if(/^xworker\.(on\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${ft}_event`;globalThis[n]=r,this.run(e,`require "js";$xworker.call("${t}",JS.global[:${n}])`),delete globalThis[n]}else{const n=this.run(e,`method(:${t})`);await n.call(t,e.wrap(r))}},transform:(e,t)=>t,writeFile:()=>{throw new Error(`writeFile is not supported in ${ut}`)}};var dt={type:"wasmoon",module:(e="1.15.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},r){const{stderr:n,stdout:s,get:o}=Xe(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",n)})),r.files&&await rt(this,a,r.files),r.fetch&&await Ze(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync(Me(t),...r)}catch(t){Ue.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Me(t),...r)}catch(t){Ue.get(e).stderr(t)}},runEvent:async(e,t,r)=>{const[n,...s]=t.split(".");let o,a=e.global.get(n);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,r)}catch(t){Ue.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Ye(e,ze(t)),t=Ge(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const ht=new Map,gt=new Map,yt=[],wt=[],mt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=ht.get(r),o=/^https?:\/\//i.test(n)?n.join("@"):s.module(...n);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:r,module:n,engine:s}=e.get(t);return(e,o)=>n.then((n=>{gt.set(t,e);for(const t of["files","fetch"]){const r=e?.[t];r&&Qe.set(r,o)}return s(n,e,r)}))}}),bt=e=>{for(const t of[].concat(e.type))ht.set(t,e),yt.push(`script[type="${t}"]`),wt.push(`${t}-`)};for(const e of[it,lt,pt,dt])bt(e);const vt=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),Et=e=>{let t=typeof e;return"string"===t&&/\.(json|toml|txt)$/.test(e)?t=RegExp.$1:e="./config.txt",[Ne(e),t]},St=(e,t,r={})=>{if(t){const[e,n]=Et(t);if("json"===n)r=fetch(e).then(Pe);else if("toml"===n)r=fetch(e).then(ke).then(vt);else if("string"===n)try{r=JSON.parse(t)}catch(e){r=vt(t)}else"object"===n&&t&&(r=t);t=e}return Ce(r).then((r=>mt[e](r,t)))},$t=(e,t="")=>`${e}@${t}`.replace(/@$/,""),At=[["beforeRun","codeBeforeRunWorker"],["beforeRunAsync","codeBeforeRunWorkerAsync"],["afterRun","codeAfterRunWorker"],["afterRunAsync","codeAfterRunWorkerAsync"]];class Pt{constructor(e,t){this.interpreter=e,this.onWorkerReady=t.onWorkerReady;for(const[e,r]of At)this[e]=t[r]}get stringHooks(){const e={};for(const[t]of At)this[t]&&(e[t]=Me(this[t]()));return e}}var kt=(...e)=>function(t,r){const n=new Worker(URL.createObjectURL(new Blob(['const e="object"==typeof self?self:globalThis,t=t=>((t,r)=>{const n=(e,r)=>(t.set(r,e),e),s=o=>{if(t.has(o))return t.get(o);const[a,i]=r[o];switch(a){case 0:case-1:return n(i,o);case 1:{const e=n([],o);for(const t of i)e.push(s(t));return e}case 2:{const e=n({},o);for(const[t,r]of i)e[s(t)]=s(r);return e}case 3:return n(new Date(i),o);case 4:{const{source:e,flags:t}=i;return n(new RegExp(e,t),o)}case 5:{const e=n(new Map,o);for(const[t,r]of i)e.set(s(t),s(r));return e}case 6:{const e=n(new Set,o);for(const t of i)e.add(s(t));return e}case 7:{const{name:t,message:r}=i;return n(new e[t](r),o)}case 8:return n(BigInt(i),o);case"BigInt":return n(Object(BigInt(i)),o)}return n(new e[a](i),o)};return s})(new Map,t)(0),r="",{toString:n}={},{keys:s}=Object,o=e=>{const t=typeof e;if("object"!==t||!e)return[0,t];const s=n.call(e).slice(8,-1);switch(s){case"Array":return[1,r];case"Object":return[2,r];case"Date":return[3,r];case"RegExp":return[4,r];case"Map":return[5,r];case"Set":return[6,r]}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:r}={})=>{const n=[];return((e,t,r,n)=>{const i=(e,t)=>{const s=n.push(e)-1;return r.set(t,s),s},c=n=>{if(r.has(n))return r.get(n);let[l,u]=o(n);switch(l){case 0:{let t=n;switch(u){case"bigint":l=8,t=n.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+u);t=null;break;case"undefined":return i([-1],n)}return i([l,t],n)}case 1:{if(u)return i([u,[...n]],n);const e=[],t=i([l,e],n);for(const t of n)e.push(c(t));return t}case 2:{if(u)switch(u){case"BigInt":return i([u,n.toString()],n);case"Boolean":case"Number":case"String":return i([u,n.valueOf()],n)}if(t&&"toJSON"in n)return c(n.toJSON());const r=[],f=i([l,r],n);for(const t of s(n))!e&&a(o(n[t]))||r.push([c(t),c(n[t])]);return f}case 3:return i([l,n.toISOString()],n);case 4:{const{source:e,flags:t}=n;return i([l,{source:e,flags:t}],n)}case 5:{const t=[],r=i([l,t],n);for(const[r,s]of n)(e||!a(o(r))&&!a(o(s)))&&t.push([c(r),c(s)]);return r}case 6:{const t=[],r=i([l,t],n);for(const r of n)!e&&a(o(r))||t.push(c(r));return r}}const{message:f}=n;return i([l,{name:u,message:f}],n)};return c})(!(t||r),!!t,new Map,n)(e),n},{parse:c,stringify:l}=JSON,u={json:!0,lossy:!0};var f=Object.freeze({__proto__:null,parse:e=>t(c(e)),stringify:e=>l(i(e,u))});const p="5f50bb1c-57c3-47af-b36a-392fe80f8803",d="M"+p,g="T"+p;var y=e=>({value:new Promise((t=>{let r=new Worker("data:application/javascript,onmessage%3D(%7Bdata%3Ab%7D)%3D%3E(Atomics.wait(b%2C0)%2CpostMessage(0))");r.onmessage=t,r.postMessage(e)}))})\n/*! (c) Andrea Giammarchi - ISC */;const{Int32Array:h,Map:w,SharedArrayBuffer:m,Uint16Array:b}=globalThis,{BYTES_PER_ELEMENT:v}=h,{BYTES_PER_ELEMENT:S}=b,{isArray:E}=Array,{notify:P,wait:$,waitAsync:A}=Atomics,{fromCharCode:M}=String,j=new WeakSet,x=new WeakMap,k={value:{then:e=>e()}},T=()=>{};let _=0;const O=(e,{parse:t=JSON.parse,stringify:r=JSON.stringify,transform:n,interrupt:s}=JSON)=>{if(!x.has(e)){const o=(t,...r)=>e.postMessage({[p]:r},{transfer:t}),a="function"==typeof s?s:s?.handler||T,i=s?.delay||42,c=(e,t)=>e?(A||y)(t,0):(((e,t,r)=>{for(;"timed-out"===$(e,0,0,t);)r()})(t,i,a),k);let l=!1;x.set(e,new Proxy(new w,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,s)=>"then"===s?null:(...r)=>{const a=_++;let i=new h(new m(v)),u=[];j.has(r.at(-1)||u)&&j.delete(u=r.pop()),o(u,a,i,s,n?r.map(n):r);const f=e!==globalThis;let p=0;return l&&f&&(p=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),c(f,i).value.then((()=>{clearTimeout(p);const e=i[0];if(!e)return;const r=S*e;return i=new h(new m(r+r%v)),o([],a,i),c(f,i).value.then((()=>t(M(...new b(i.buffer).slice(0,e)))))}))},set(t,s,o){if(!t.size){const s=new w;e.addEventListener("message",(async e=>{const o=e.data?.[p];if(E(o)){e.stopImmediatePropagation();const[a,i,...c]=o;if(c.length){const[e,o]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);l=!0;try{const c=await t.get(e)(...o);if(void 0!==c){const e=r(n?n(c):c);s.set(a,e),i[0]=e.length}}finally{l=!1}}else{const e=s.get(a);s.delete(a);for(let t=new b(i.buffer),r=0;r(j.add(e),e);const F="object",R="function",W="number",J="string",B="undefined",I="symbol",{defineProperty:C,getOwnPropertyDescriptor:L,getPrototypeOf:D,isExtensible:N,ownKeys:H,preventExtensions:U,set:z,setPrototypeOf:q}=Reflect,{assign:K,create:Y}=Object,G=D(Int8Array),V="isArray",Q=(e,t)=>{const{get:r,set:n,value:s}=e;return r&&(e.get=t(r)),n&&(e.set=t(n)),s&&(e.value=t(s)),e},X=(e,t)=>[e,t],Z=e=>t=>{const r=typeof t;switch(r){case F:if(null==t)return X("null",t);if(t===globalThis)return X(F,null);case R:return e(r,t);case"boolean":case W:case J:case B:case"bigint":return X(r,t);case I:if(ee.has(t))return X(r,ee.get(t))}throw new Error(`Unable to handle this ${r} type`)},ee=new Map(H(Symbol).filter((e=>typeof Symbol[e]===I)).map((e=>[Symbol[e],e]))),te=e=>{for(const[t,r]of ee)if(r===e)return t};function re(){return this}const ne="apply",se="construct",oe="defineProperty",ae="deleteProperty",ie="get",ce="getOwnPropertyDescriptor",le="getPrototypeOf",ue="has",fe="isExtensible",pe="ownKeys",de="preventExtensions",ge="set",ye="setPrototypeOf",he="delete";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;C(EventTarget.prototype,"addEventListener",{value(t,n,...s){return s.at(0)?.invoke&&(r.has(this)||r.set(this,new Map),r.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,n,...s)}})}const n=t&&(e=>{const{currentTarget:t,target:n,type:s}=e;for(const o of r.get(t||n)?.get(s)||[])e[o]()});return(r,s,o,...a)=>{let i=0;const c=new Map,l=new Map,{[o]:u}=r,f=a.length?K(Y(globalThis),...a):globalThis,p=Z(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return X(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(he,X(J,e))})),g=([e,r])=>{switch(e){case F:if(null==r)return f;if(typeof r===W)return l.get(r);if(!(r instanceof G))for(const e in r)r[e]=g(r[e]);return r;case R:if(typeof r===J){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(ne,X(R,r),p(this),e.map(p))},s=new WeakRef(e);l.set(r,s),d.register(e,r,s)}return l.get(r).deref()}return l.get(r);case I:return te(r)}return r},y={[ne]:(e,t,r)=>p(e.apply(t,r)),[se]:(e,t)=>p(new e(...t)),[oe]:(e,t,r)=>p(C(e,t,r)),[ae]:(e,t)=>p(delete e[t]),[le]:e=>p(D(e)),[ie]:(e,t)=>p(e[t]),[ce]:(e,t)=>{const r=L(e,t);return r?X(F,Q(r,p)):X(B,r)},[ue]:(e,t)=>p(t in e),[fe]:e=>p(N(e)),[pe]:e=>X(F,H(e).map(p)),[de]:e=>p(U(e)),[ge]:(e,t,r)=>p(z(e,t,r)),[ye]:(e,t)=>p(q(e,t)),[he](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case ne:r[0]=g(r[0]),r[1]=r[1].map(g);break;case se:r[0]=r[0].map(g);break;case oe:{const[e,t]=r;r[0]=g(e);const{get:n,set:s,value:o}=t;n&&(t.get=g(n)),s&&(t.set=g(s)),o&&(t.value=g(o));break}default:r=r.map(g)}return y[e](g(t),...r)},{proxy:r,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window",!0),me=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===R?e():e,a=e=>typeof e===F&&!!e&&s in e,i=Array[V],c=Z(((e,a)=>{if(s in a)return o(a[s]);if(e===R){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return X(e,r.get(a))}if(!(a instanceof G))for(const e in a)a[e]=c(a[e]);return X(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(he,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===R?re.bind(e):e,s=new Proxy(n,w),o=new WeakRef(s);p.set(r,o),d.register(s,r,o)}return p.get(r).deref()},y=e=>{const[t,r]=e;switch(t){case F:return null===r?globalThis:typeof r===W?g(e):r;case R:return typeof r===J?n.get(r):g(e);case I:return te(r)}return r},h=(e,t,...r)=>y(f(e,o(t),...r)),w={[ne]:(e,t,r)=>h(ne,e,c(t),r.map(c)),[se]:(e,t)=>h(se,e,t.map(c)),[oe]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===R&&(r.get=c(n)),typeof s===R&&(r.set=c(s)),typeof o===R&&(r.value=c(o)),h(oe,e,c(t),r)},[ae]:(e,t)=>h(ae,e,c(t)),[le]:e=>h(le,e),[ie]:(e,t)=>t===s?e:h(ie,e,c(t)),[ce]:(e,t)=>{const r=h(ce,e,c(t));return r&&Q(r,y)},[ue]:(e,t)=>t===s||h(ue,e,c(t)),[fe]:e=>h(fe,e),[pe]:e=>h(pe,e).map(y),[de]:e=>h(de,e),[ge]:(e,t,r)=>h(ge,e,c(t),c(r)),[ye]:(e,t)=>h(ye,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case ne:return y(t).apply(y(s),o.map(y));case he:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([F,null],w),b=m.Array[V];return C(Array,V,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})("Window"),be="function"==typeof Worker?Worker:class{};const ve=new WeakMap,Se=(e,...t)=>{const r=O(e,...t);if(!ve.has(r)){const t=e instanceof be?we:me;ve.set(r,t(r,d,g))}return ve.get(r)};Se.transfer=O.transfer;const Ee={object(...e){return this.string(function(e){for(var t=e[0],r=1,n=arguments.length;rEe[typeof e](e,...t),{isArray:$e}=Array,{assign:Ae,create:Me,defineProperties:je,defineProperty:xe,entries:ke}=Object,{all:Te,resolve:_e}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Oe=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href,Fe=(e,t,r=!1,n=CustomEvent)=>{e.dispatchEvent(new n(`${t}:ready`,{bubbles:!0,detail:{worker:r}}))};Promise.withResolvers||(Promise.withResolvers=function(){var e,t,r=new this((function(r,n){e=r,t=n}));return{resolve:e,reject:t,promise:r}});const Re=e=>e.arrayBuffer(),We=e=>e.json(),Je=e=>e.text(),Be=new WeakMap,Ie=e=>{const t=e||console,r={stderr:(t.stderr||console.error).bind(t),stdout:(t.stdout||console.log).bind(t)};return{stderr:(...e)=>r.stderr(...e),stdout:(...e)=>r.stdout(...e),async get(e){const t=await e;return Be.set(t,r),t}}},Ce=({FS:e,PATH:t,PATH_FS:r},n,s)=>{const o=r.resolve(n);return e.mkdirTree(t.dirname(o)),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},Le=e=>{const t=e.split("/");return t.pop(),t.join("/")},De=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Ne=(e,t)=>{const r=[];for(const e of t.split("/"))switch(e){case"":case".":break;case"..":r.pop();break;default:r.push(e)}return[e.cwd()].concat(r).join("/").replace(/^\\/+/,"/")},He=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Ue=(e,t)=>fetch(Oe(t,ze.get(e))),ze=new WeakMap,qe=(e,t,r)=>Te((e=>{for(const{files:t,to_file:r,from:n=""}of e){if(void 0!==t&&void 0!==r)throw new Error("Cannot use \'to_file\' and \'files\' parameters together!");if(void 0===t&&void 0===r&&n.endsWith("/"))throw new Error(`Couldn\'t determine the filename from the path ${n}, please supply \'to_file\' parameter.`)}return e.flatMap((({from:e="",to_folder:t=".",to_file:r,files:n})=>{if($e(n))return n.map((r=>({url:He([e,r]),path:He([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:He([t,s])}]}))})(r).map((({url:n,path:s})=>Ue(r,n).then(Re).then((r=>e.writeFile(t,s,r)))))),Ke=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,Ye=(e,t)=>e.replace(/\\{.+?\\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),Ge=(e,t,r)=>Te((e=>{const t=new Map,r=new Set,n=[];for(const[s,o]of Object.entries(e))if(/^\\{.+\\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,Ye(o,t))}else{const e=Ye(s,t),a=Ke(e,Ye(o||"./",t));if(r.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);r.add(a),n.push({url:e,path:a})}return n})(r).map((({url:n,path:s})=>Ue(r,n).then(Re).then((r=>e.writeFile(t,s,r)))))),Ve=(e,t,r)=>{e.registerJsModule(t,r)},Qe=(e,t,...r)=>{try{return e.runPython(Pe(t),...r)}catch(t){Be.get(e).stderr(t)}},Xe=async(e,t,...r)=>{try{return await e.runPythonAsync(Pe(t),...r)}catch(t){Be.get(e).stderr(t)}},Ze=async(e,t,r)=>{const[n,...s]=t.split(".");let o,a=e.globals.get(n);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,r)}catch(t){Be.get(e).stderr(t)}};var et={type:"micropython",module:(e="1.20.0-297")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,r){const{stderr:n,stdout:s,get:o}=Ie();r=r.replace(/\\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.files&&await Ge(this,a,t.files),t.fetch&&await qe(this,a,t.fetch),a},registerJSModule:Ve,run:Qe,runAsync:Xe,runEvent:Ze,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Ce({FS:e,PATH:t,PATH_FS:r},n,s)};const tt={dict_converter:Object.fromEntries};var rt={type:"pyodide",module:(e="0.24.1")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Ie(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.files&&await Ge(this,i,t.files),t.fetch&&await qe(this,i,t.fetch),t.packages){await i.loadPackage("micropip");const e=await i.pyimport("micropip");await e.install(t.packages),e.destroy()}return i},registerJSModule:Ve,run:Qe,runAsync:Xe,runEvent:Ze,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(tt):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Ce({FS:e,PATH:t,PATH_FS:r},n,s)};const nt="ruby-wasm-wasi",st=nt.replace(/\\W+/g,"_");var ot={type:nt,experimental:!0,module:(e="2.1.0")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,r){const n=await fetch(`${r.slice(0,r.lastIndexOf("/"))}/ruby.wasm`),s=await WebAssembly.compile(await n.arrayBuffer()),{vm:o}=await e(s);return t.files&&await Ge(this,o,t.files),t.fetch&&await qe(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${st}_${t}`;globalThis[n]=r,this.run(e,`require "js";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval(Pe(t),...r),runAsync:(e,t,...r)=>e.evalAsync(Pe(t),...r),async runEvent(e,t,r){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${st}_event`;globalThis[n]=r,this.run(e,`require "js";$xworker.call("${t}",JS.global[:${n}])`),delete globalThis[n]}else{const n=this.run(e,`method(:${t})`);await n.call(t,e.wrap(r))}},transform:(e,t)=>t,writeFile:()=>{throw new Error(`writeFile is not supported in ${nt}`)}};var at={type:"wasmoon",module:(e="1.15.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},r){const{stderr:n,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",n)})),r.files&&await Ge(this,a,r.files),r.fetch&&await qe(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync(Pe(t),...r)}catch(t){Be.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Pe(t),...r)}catch(t){Be.get(e).stderr(t)}},runEvent:async(e,t,r)=>{const[n,...s]=t.split(".");let o,a=e.global.get(n);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,r)}catch(t){Be.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(De(e,Le(t)),t=Ne(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const it=new Map,ct=new Map,lt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=it.get(r),o=/^https?:\\/\\//i.test(n)?n.join("@"):s.module(...n);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:r,module:n,engine:s}=e.get(t);return(e,o)=>n.then((n=>{ct.set(t,e);for(const t of["files","fetch"]){const r=e?.[t];r&&ze.set(r,o)}return s(n,e,r)}))}}),ut=e=>{for(const t of[].concat(e.type))it.set(t,e)};for(const e of[et,rt,ot,at])ut(e);const ft=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),pt=(e,t,r={})=>{if(t){const[e,n]=(e=>{let t=typeof e;return"string"===t&&/\\.(json|toml|txt)$/.test(e)?t=RegExp.$1:e="./config.txt",[Oe(e),t]})(t);if("json"===n)r=fetch(e).then(We);else if("toml"===n)r=fetch(e).then(Je).then(ft);else if("string"===n)try{r=JSON.parse(t)}catch(e){r=ft(t)}else"object"===n&&t&&(r=t);t=e}return _e(r).then((r=>lt[e](r,t)))};try{new SharedArrayBuffer(4)}catch(e){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"))}let dt,gt,yt;const ht=(e,t)=>{addEventListener(e,t||(async t=>{try{await dt,gt(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:wt,stringify:mt}=f,{proxy:bt,window:vt,isWindowProxy:St}=Se(self,{parse:wt,stringify:mt,transform:e=>yt?yt(e):e}),Et={sync:bt,window:vt,isWindowProxy:St,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};ht("message",(({data:{options:e,config:t,code:r,hooks:n}})=>{dt=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await pt(((e,t="")=>`${e}@${t}`.replace(/@$/,""))(a,c),t,l),p=Me(it.get(a)),d="run"+(u?"Async":"");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=u?s:r,a=u?t:e;if(o){const e=p[d].bind(p);p[d]=(t,r,...n)=>e(t,`${r}\\n${o}`,...n)}if(a){const e=p[d].bind(p);p[d]=(t,r,...n)=>e(t,`${a}\\n${r}`,...n)}}const{CustomEvent:g,document:y}=vt,h=s&&y.getElementById(s)||null;let w="";return p.registerJSModule(f,"polyscript",{xworker:Et,get target(){return!w&&h&&("SCRIPT"===o?h.after(Ae(y.createElement(`script-${i||a}`),{id:w=`${s}-target`})):(w=s,h.replaceChildren(),h.style.display="block")),w}}),gt=p.runEvent.bind(p,f),yt=p.transform.bind(p,f),h&&Fe(h,i||a,!0,g),await p[d](f,r),f}catch(e){postMessage(e)}})(),ht("error"),ht("message"),ht("messageerror")}));\n'],{type:"application/javascript"})),{type:"module"}),{postMessage:s}=n,o=this instanceof Pt;if(e.length){const[t,n]=e;(r=We({},r||{type:t,version:n})).type||(r.type=t)}const[a]=Et(r.config),i=fetch(t).then(ke).then((e=>{const t=o?this.stringHooks:void 0;s.call(n,{options:r,config:a,code:e,hooks:t})}));return Ie(n,{postMessage:{value:(e,...t)=>i.then((()=>s.call(n,e,...t)))},sync:{value:$e(n,d).proxy},onerror:{writable:!0,configurable:!0,value:console.error}}),o&&this.onWorkerReady?.(this.interpreter,n),n.addEventListener("message",(e=>{const{data:t}=e;t instanceof Error&&(e.stopImmediatePropagation(),n.onerror(Object.create(e,{type:{value:"error"},error:{value:t}})))})),n},xt=kt();const Mt="Invalid content",jt="Invalid worker attribute",Rt="Invalid worker attribute";var Tt=e=>{const{src:t,worker:r}=e.attributes;if(r){let{value:s}=r;if(s)throw new SyntaxError(Rt);if(s=t?.value,!s){if(t)throw new SyntaxError(jt);if(e.childElementCount){const{innerHTML:t,localName:r,type:o}=e,a=o||r.replace(/-script$/,"");n=t,s=je.call(n,Re,Oe),console.warn(`Deprecated: use + + + + + + + + diff --git a/test/integration/micropython.js b/test/integration/micropython.js index 99cd61f..6e10f40 100644 --- a/test/integration/micropython.js +++ b/test/integration/micropython.js @@ -35,4 +35,6 @@ module.exports = (playwright, baseURL) => { const result = await page.evaluate(() => document.body.innerText); await expect(result.trim()).toBe('OK'); }); + + test('MicroPython ready-done events', python.waitForReadyDone(playwright, `${baseURL}/ready-done.html`)); };