polyscript
Advanced tools
Comparing version 0.3.0 to 0.3.1
'use strict'; | ||
const { clean, io } = require('./_utils.js'); | ||
const { dedent } = require('../utils.js'); | ||
const { io } = require('./_utils.js'); | ||
@@ -13,3 +14,3 @@ // REQUIRES INTEGRATION TEST | ||
try { | ||
return interpreter.runPython(clean(code), ...args); | ||
return interpreter.runPython(dedent(code), ...args); | ||
} | ||
@@ -24,3 +25,3 @@ catch (error) { | ||
try { | ||
return await interpreter.runPythonAsync(clean(code), ...args); | ||
return await interpreter.runPythonAsync(dedent(code), ...args); | ||
} | ||
@@ -27,0 +28,0 @@ catch (error) { |
@@ -7,11 +7,2 @@ 'use strict'; | ||
/** | ||
* Trim code only if it's a single line that prettier or other tools might have modified. | ||
* @param {string} code code that might be a single line | ||
* @returns {string} | ||
*/ | ||
const clean = (code) => | ||
code.replace(/^[^\r\n]+$/, (line) => line.trim()); | ||
exports.clean = clean; | ||
// REQUIRES INTEGRATION TEST | ||
@@ -18,0 +9,0 @@ /* c8 ignore start */ |
'use strict'; | ||
const { clean, fetchPaths } = require('./_utils.js'); | ||
const { dedent } = require('../utils.js'); | ||
const { fetchPaths } = require('./_utils.js'); | ||
@@ -35,4 +36,4 @@ const type = 'ruby-wasm-wasi'; | ||
}, | ||
run: (interpreter, code, ...args) => interpreter.eval(clean(code), ...args), | ||
runAsync: (interpreter, code, ...args) => interpreter.evalAsync(clean(code), ...args), | ||
run: (interpreter, code, ...args) => interpreter.eval(dedent(code), ...args), | ||
runAsync: (interpreter, code, ...args) => interpreter.evalAsync(dedent(code), ...args), | ||
async runEvent(interpreter, code, event) { | ||
@@ -39,0 +40,0 @@ // patch common xworker.onmessage/onerror cases |
'use strict'; | ||
const { clean, fetchPaths, io, stdio, writeFileShim } = require('./_utils.js'); | ||
const { dedent } = require('../utils.js'); | ||
const { fetchPaths, io, stdio, writeFileShim } = require('./_utils.js'); | ||
@@ -31,3 +32,3 @@ const type = 'wasmoon'; | ||
try { | ||
return interpreter.doStringSync(clean(code), ...args); | ||
return interpreter.doStringSync(dedent(code), ...args); | ||
} | ||
@@ -40,3 +41,3 @@ catch (error) { | ||
try { | ||
return await interpreter.doString(clean(code), ...args); | ||
return await interpreter.doString(dedent(code), ...args); | ||
} | ||
@@ -43,0 +44,0 @@ catch (error) { |
'use strict'; | ||
const dedent = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c8 ignore stop */)(require('codedent')); | ||
const { isArray } = Array; | ||
@@ -20,2 +22,3 @@ | ||
exports.dedent = dedent; | ||
exports.isArray = isArray; | ||
@@ -22,0 +25,0 @@ exports.assign = assign; |
'use strict'; | ||
const { dedent } = require('../utils.js'); | ||
// REQUIRES INTEGRATION TEST | ||
@@ -15,3 +17,4 @@ /* c8 ignore start */ | ||
this.onWorkerReady = options.onWorkerReady; | ||
for (const [key, value] of workerHooks) this[key] = options[value]?.(); | ||
for (const [key, value] of workerHooks) | ||
this[key] = options[value]?.(); | ||
} | ||
@@ -21,3 +24,3 @@ get stringHooks() { | ||
for (const [key] of workerHooks) { | ||
if (this[key]) hooks[key] = this[key]; | ||
if (this[key]) hooks[key] = dedent(this[key]); | ||
} | ||
@@ -24,0 +27,0 @@ return hooks; |
'use strict'; | ||
const { dedent } = require('../utils.js'); | ||
/* c8 ignore start */ // tested via integration | ||
@@ -20,15 +22,3 @@ module.exports = element => { | ||
// drop undesired indentation from the code | ||
for (const line of value.split(/[\r\n]+/)) { | ||
if (line.trim().length) { | ||
// if there's no indentation, avoid changing value | ||
if (/^(\s+)/.test(line)) { | ||
const trimStart = `^${RegExp.$1}`; | ||
value = value.replace(new RegExp(trimStart, 'gm'), ''); | ||
} | ||
break; | ||
} | ||
} | ||
const url = URL.createObjectURL(new Blob([value], { type: 'text/plain' })); | ||
const url = URL.createObjectURL(new Blob([dedent(value)], { type: 'text/plain' })); | ||
// TODO: should we really clean up this? debugging non-existent resources | ||
@@ -35,0 +25,0 @@ // at distance might be very problematic if the url is revoked. |
'use strict'; | ||
/* c8 ignore next */ | ||
module.exports = () => 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=\"891249cd-eb53-4bc8-ae48-b0a5a277d24a\",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:w,Map:h,SharedArrayBuffer:m,Uint16Array:b}=globalThis,{BYTES_PER_ELEMENT:v}=w,{BYTES_PER_ELEMENT:S}=b,{isArray:P}=Array,{notify:A,wait:E,waitAsync:M}=Atomics,{fromCharCode:$}=String,j=(e,t)=>e?(M||y)(t,0):(E(t,0),{value:{then:e=>e()}}),T=new WeakSet,k=new WeakMap;let _=0;const x=(e,{parse:t,stringify:r,transform:n}=JSON)=>{if(!k.has(e)){const s=(t,...r)=>e.postMessage({[p]:r},{transfer:t});let o=!1;k.set(e,new Proxy(new h,{has:(e,t)=>\"string\"==typeof t&&!t.startsWith(\"_\"),get:(r,a)=>\"then\"===a?null:(...r)=>{const i=_++;let c=new w(new m(v)),l=[];T.has(r.at(-1)||l)&&T.delete(l=r.pop()),s(l,i,c,a,n?r.map(n):r);const u=e!==globalThis;let f=0;return o&&u&&(f=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${a}(...args) is awaited`)),j(u,c).value.then((()=>{clearTimeout(f);const e=c[0];if(!e)return;const r=S*e;return c=new w(new m(r+r%v)),s([],i,c),j(u,c).value.then((()=>t($(...new b(c.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new h;e.addEventListener(\"message\",(async e=>{const s=e.data?.[p];if(P(s)){e.stopImmediatePropagation();const[a,i,...c]=s;if(c.length){const[e,s]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);o=!0;try{const o=await t.get(e)(...s);if(void 0!==o){const e=r(o);n.set(a,e),i[0]=e.length}}finally{o=!1}}else{const e=n.get(a);n.delete(a);for(let t=new b(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}A(i,0)}}))}return!!t.set(n,s)}}))}return k.get(e)};x.transfer=(...e)=>(T.add(e),e);const O=\"object\",F=\"function\",W=\"number\",R=\"string\",B=\"undefined\",J=\"symbol\",{defineProperty:I,getOwnPropertyDescriptor:L,getPrototypeOf:C,isExtensible:H,ownKeys:D,preventExtensions:N,set:U,setPrototypeOf:z}=Reflect,{assign:q,create:K}=Object,Y=C(Int8Array),G=\"isArray\",V=(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},Q=(e,t)=>[e,t],X=e=>t=>{const r=typeof t;switch(r){case O:if(null==t)return Q(\"null\",t);if(t===globalThis)return Q(O,null);case F:return e(r,t);case\"boolean\":case W:case R:case B:case\"bigint\":return Q(r,t);case J:if(Z.has(t))return Q(r,Z.get(t))}throw new Error(`Unable to handle this ${r} type`)},Z=new Map(D(Symbol).filter((e=>typeof Symbol[e]===J)).map((e=>[Symbol[e],e]))),ee=e=>{for(const[t,r]of Z)if(r===e)return t};function te(){return this}const re=\"apply\",ne=\"construct\",se=\"defineProperty\",oe=\"deleteProperty\",ae=\"get\",ie=\"getOwnPropertyDescriptor\",ce=\"getPrototypeOf\",le=\"has\",ue=\"isExtensible\",fe=\"ownKeys\",pe=\"preventExtensions\",de=\"set\",ge=\"setPrototypeOf\",ye=\"delete\";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;I(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?q(K(globalThis),...a):globalThis,p=X(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return Q(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(ye,Q(R,e))})),g=([e,r])=>{switch(e){case O:if(null==r)return f;if(typeof r===W)return l.get(r);if(!(r instanceof Y))for(const e in r)r[e]=g(r[e]);return r;case F:if(typeof r===R){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(re,Q(F,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 J:return ee(r)}return r},y={[re]:(e,t,r)=>p(e.apply(t,r)),[ne]:(e,t)=>p(new e(...t)),[se]:(e,t,r)=>p(I(e,t,r)),[oe]:(e,t)=>p(delete e[t]),[ce]:e=>p(C(e)),[ae]:(e,t)=>p(e[t]),[ie]:(e,t)=>{const r=L(e,t);return r?Q(O,V(r,p)):Q(B,r)},[le]:(e,t)=>p(t in e),[ue]:e=>p(H(e)),[fe]:e=>Q(O,D(e).map(p)),[pe]:e=>p(N(e)),[de]:(e,t,r)=>p(U(e,t,r)),[ge]:(e,t)=>p(z(e,t)),[ye](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case re:r[0]=g(r[0]),r[1]=r[1].map(g);break;case ne:r[0]=r[0].map(g);break;case se:{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),he=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===F?e():e,a=e=>typeof e===O&&!!e&&s in e,i=Array[G],c=X(((e,a)=>{if(s in a)return o(a[s]);if(e===F){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return Q(e,r.get(a))}if(!(a instanceof Y))for(const e in a)a[e]=c(a[e]);return Q(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(ye,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===F?te.bind(e):e,s=new Proxy(n,h),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 O:return null===r?globalThis:typeof r===W?g(e):r;case F:return typeof r===R?n.get(r):g(e);case J:return ee(r)}return r},w=(e,t,...r)=>y(f(e,o(t),...r)),h={[re]:(e,t,r)=>w(re,e,c(t),r.map(c)),[ne]:(e,t)=>w(ne,e,t.map(c)),[se]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===F&&(r.get=c(n)),typeof s===F&&(r.set=c(s)),typeof o===F&&(r.value=c(o)),w(se,e,c(t),r)},[oe]:(e,t)=>w(oe,e,c(t)),[ce]:e=>w(ce,e),[ae]:(e,t)=>t===s?e:w(ae,e,c(t)),[ie]:(e,t)=>{const r=w(ie,e,c(t));return r&&V(r,y)},[le]:(e,t)=>t===s||w(le,e,c(t)),[ue]:e=>w(ue,e),[fe]:e=>w(fe,e).map(y),[pe]:e=>w(pe,e),[de]:(e,t,r)=>w(de,e,c(t),c(r)),[ge]:(e,t)=>w(ge,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case re:return y(t).apply(y(s),o.map(y));case ye:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([O,null],h),b=m.Array[G];return I(Array,G,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})(\"Window\"),me=\"function\"==typeof Worker?Worker:class{};const be=new WeakMap,ve=(e,...t)=>{const r=x(e,...t);if(!be.has(r)){const t=e instanceof me?we:he;be.set(r,t(r,d,g))}return be.get(r)};ve.transfer=x.transfer;const{isArray:Se}=Array,{assign:Pe,create:Ae,defineProperties:Ee,defineProperty:Me,entries:$e}=Object,{all:je,resolve:Te}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),ke=(e,t=location.href)=>new URL(e,t).href;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 _e=e=>e.arrayBuffer(),xe=e=>e.json(),Oe=e=>e.text(),Fe=e=>e.replace(/^[^\\r\\n]+$/,(e=>e.trim())),We=new WeakMap,Re=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 We.set(t,r),t}}},Be=({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})},Je=e=>{const t=e.split(\"/\");return t.pop(),t.join(\"/\")},Ie=(e,t)=>{const r=[];for(const n of t.split(\"/\"))\".\"!==n&&(r.push(n),n&&e.mkdir(r.join(\"/\")))},Le=(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(/^\\/+/,\"/\")},Ce=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,\"\"))).filter((e=>\"\"!==e&&\".\"!==e)).join(\"/\");return e[0].startsWith(\"/\")?`/${t}`:t},He=new WeakMap,De=(e,t,r)=>je((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(Se(n))return n.map((r=>({url:Ce([e,r]),path:Ce([t,r])})));const s=r||e.slice(1+e.lastIndexOf(\"/\"));return[{url:e,path:Ce([t,s])}]}))})(r).map((({url:n,path:s})=>((e,t)=>fetch(ke(t,He.get(e))))(r,n).then(_e).then((r=>e.writeFile(t,s,r)))))),Ne=(e,t,r)=>{e.registerJsModule(t,r)},Ue=(e,t,...r)=>{try{return e.runPython(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},ze=async(e,t,...r)=>{try{return await e.runPythonAsync(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},qe=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){We.get(e).stderr(t)}};var Ke={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}=Re();r=r.replace(/\\.m?js$/,\".wasm\");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await De(this,a,t.fetch),a},registerJSModule:Ne,run:Ue,runAsync:ze,runEvent:qe,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Be({FS:e,PATH:t,PATH_FS:r},n,s)};const Ye={dict_converter:Object.fromEntries};var Ge={type:\"pyodide\",module:(e=\"0.23.4\")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Re(),a=r.slice(0,r.lastIndexOf(\"/\")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await De(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:Ne,run:Ue,runAsync:ze,runEvent:qe,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(Ye):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Be({FS:e,PATH:t,PATH_FS:r},n,s)};const Ve=\"ruby-wasm-wasi\",Qe=Ve.replace(/\\W+/g,\"_\");var Xe={type:Ve,experimental:!0,module:(e=\"2.0.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.fetch&&await De(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${Qe}_${t}`;globalThis[n]=r,this.run(e,`require \"js\";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval(Fe(t),...r),runAsync:(e,t,...r)=>e.evalAsync(Fe(t),...r),async runEvent(e,t,r){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${Qe}_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 ${Ve}`)}};var Ze={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}=Re(),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.fetch&&await De(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Fe(t),...r)}catch(t){We.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){We.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Ie(e,Je(t)),t=Le(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const et=new Map,tt=new Map,rt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split(\"@\"),s=et.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=>{tt.set(t,e);const a=e?.fetch;return a&&He.set(a,o),s(n,e,r)}))}}),nt=e=>{for(const t of[].concat(e.type))et.set(t,e)};for(const e of[Ke,Ge,Xe,Ze])nt(e);const st=async e=>(await import(\"https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js\")).parse(e);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 ot,at,it;const ct=(e,t)=>{addEventListener(e,t||(async t=>{try{await ot,at(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:lt,stringify:ut}=f,{proxy:ft,window:pt,isWindowProxy:dt}=ve(self,{parse:lt,stringify:ut,transform:e=>it?it(e):e}),gt={sync:ft,window:pt,isWindowProxy:dt,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};ct(\"message\",(({data:{options:e,config:t,code:r,hooks:n}})=>{ot=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await((e,t,r={})=>{if(t)if(t.endsWith(\".json\"))r=fetch(t).then(xe),t=ke(t);else if(t.endsWith(\".toml\"))r=fetch(t).then(Oe).then(st),t=ke(t);else if(!t.endsWith(\".txt\")){try{r=JSON.parse(t)}catch(e){r=st(t)}t=ke(\"./config.txt\")}return Te(r).then((r=>rt[e](r,t)))})(((e,t=\"\")=>`${e}@${t}`.replace(/@$/,\"\"))(a,c),t,l),p=Ae(et.get(a)),d=\"run\"+(u?\"Async\":\"\");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=r||s,a=e||t;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)}}let g=\"\";return p.registerJSModule(f,\"polyscript\",{xworker:gt,get target(){if(!g){const{document:e}=gt.window,t=e.getElementById(s);\"SCRIPT\"===o?t.after(Pe(e.createElement(`script-${i||a}`),{id:g=`${s}-target`})):(g=s,t.replaceChildren(),t.style.display=\"block\")}return g}}),at=p.runEvent.bind(p,f),it=p.transform.bind(p,f),await p[d](f,r),f}catch(e){postMessage(e)}})(),ct(\"error\"),ct(\"message\"),ct(\"messageerror\")}));\n"],{type:'application/javascript'})),{type:'module'}); | ||
module.exports = () => 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=\"891249cd-eb53-4bc8-ae48-b0a5a277d24a\",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:w,Map:h,SharedArrayBuffer:m,Uint16Array:b}=globalThis,{BYTES_PER_ELEMENT:v}=w,{BYTES_PER_ELEMENT:S}=b,{isArray:P}=Array,{notify:E,wait:A,waitAsync:M}=Atomics,{fromCharCode:$}=String,j=(e,t)=>e?(M||y)(t,0):(A(t,0),{value:{then:e=>e()}}),k=new WeakSet,x=new WeakMap;let T=0;const _=(e,{parse:t,stringify:r,transform:n}=JSON)=>{if(!x.has(e)){const s=(t,...r)=>e.postMessage({[p]:r},{transfer:t});let o=!1;x.set(e,new Proxy(new h,{has:(e,t)=>\"string\"==typeof t&&!t.startsWith(\"_\"),get:(r,a)=>\"then\"===a?null:(...r)=>{const i=T++;let c=new w(new m(v)),l=[];k.has(r.at(-1)||l)&&k.delete(l=r.pop()),s(l,i,c,a,n?r.map(n):r);const u=e!==globalThis;let f=0;return o&&u&&(f=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${a}(...args) is awaited`)),j(u,c).value.then((()=>{clearTimeout(f);const e=c[0];if(!e)return;const r=S*e;return c=new w(new m(r+r%v)),s([],i,c),j(u,c).value.then((()=>t($(...new b(c.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new h;e.addEventListener(\"message\",(async e=>{const s=e.data?.[p];if(P(s)){e.stopImmediatePropagation();const[a,i,...c]=s;if(c.length){const[e,s]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);o=!0;try{const o=await t.get(e)(...s);if(void 0!==o){const e=r(o);n.set(a,e),i[0]=e.length}}finally{o=!1}}else{const e=n.get(a);n.delete(a);for(let t=new b(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}E(i,0)}}))}return!!t.set(n,s)}}))}return x.get(e)};_.transfer=(...e)=>(k.add(e),e);const O=\"object\",F=\"function\",W=\"number\",R=\"string\",B=\"undefined\",J=\"symbol\",{defineProperty:I,getOwnPropertyDescriptor:L,getPrototypeOf:C,isExtensible:H,ownKeys:D,preventExtensions:N,set:U,setPrototypeOf:z}=Reflect,{assign:q,create:K}=Object,Y=C(Int8Array),G=\"isArray\",V=(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},Q=(e,t)=>[e,t],X=e=>t=>{const r=typeof t;switch(r){case O:if(null==t)return Q(\"null\",t);if(t===globalThis)return Q(O,null);case F:return e(r,t);case\"boolean\":case W:case R:case B:case\"bigint\":return Q(r,t);case J:if(Z.has(t))return Q(r,Z.get(t))}throw new Error(`Unable to handle this ${r} type`)},Z=new Map(D(Symbol).filter((e=>typeof Symbol[e]===J)).map((e=>[Symbol[e],e]))),ee=e=>{for(const[t,r]of Z)if(r===e)return t};function te(){return this}const re=\"apply\",ne=\"construct\",se=\"defineProperty\",oe=\"deleteProperty\",ae=\"get\",ie=\"getOwnPropertyDescriptor\",ce=\"getPrototypeOf\",le=\"has\",ue=\"isExtensible\",fe=\"ownKeys\",pe=\"preventExtensions\",de=\"set\",ge=\"setPrototypeOf\",ye=\"delete\";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;I(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?q(K(globalThis),...a):globalThis,p=X(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return Q(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(ye,Q(R,e))})),g=([e,r])=>{switch(e){case O:if(null==r)return f;if(typeof r===W)return l.get(r);if(!(r instanceof Y))for(const e in r)r[e]=g(r[e]);return r;case F:if(typeof r===R){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(re,Q(F,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 J:return ee(r)}return r},y={[re]:(e,t,r)=>p(e.apply(t,r)),[ne]:(e,t)=>p(new e(...t)),[se]:(e,t,r)=>p(I(e,t,r)),[oe]:(e,t)=>p(delete e[t]),[ce]:e=>p(C(e)),[ae]:(e,t)=>p(e[t]),[ie]:(e,t)=>{const r=L(e,t);return r?Q(O,V(r,p)):Q(B,r)},[le]:(e,t)=>p(t in e),[ue]:e=>p(H(e)),[fe]:e=>Q(O,D(e).map(p)),[pe]:e=>p(N(e)),[de]:(e,t,r)=>p(U(e,t,r)),[ge]:(e,t)=>p(z(e,t)),[ye](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case re:r[0]=g(r[0]),r[1]=r[1].map(g);break;case ne:r[0]=r[0].map(g);break;case se:{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),he=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===F?e():e,a=e=>typeof e===O&&!!e&&s in e,i=Array[G],c=X(((e,a)=>{if(s in a)return o(a[s]);if(e===F){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return Q(e,r.get(a))}if(!(a instanceof Y))for(const e in a)a[e]=c(a[e]);return Q(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(ye,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===F?te.bind(e):e,s=new Proxy(n,h),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 O:return null===r?globalThis:typeof r===W?g(e):r;case F:return typeof r===R?n.get(r):g(e);case J:return ee(r)}return r},w=(e,t,...r)=>y(f(e,o(t),...r)),h={[re]:(e,t,r)=>w(re,e,c(t),r.map(c)),[ne]:(e,t)=>w(ne,e,t.map(c)),[se]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===F&&(r.get=c(n)),typeof s===F&&(r.set=c(s)),typeof o===F&&(r.value=c(o)),w(se,e,c(t),r)},[oe]:(e,t)=>w(oe,e,c(t)),[ce]:e=>w(ce,e),[ae]:(e,t)=>t===s?e:w(ae,e,c(t)),[ie]:(e,t)=>{const r=w(ie,e,c(t));return r&&V(r,y)},[le]:(e,t)=>t===s||w(le,e,c(t)),[ue]:e=>w(ue,e),[fe]:e=>w(fe,e).map(y),[pe]:e=>w(pe,e),[de]:(e,t,r)=>w(de,e,c(t),c(r)),[ge]:(e,t)=>w(ge,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case re:return y(t).apply(y(s),o.map(y));case ye:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([O,null],h),b=m.Array[G];return I(Array,G,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})(\"Window\"),me=\"function\"==typeof Worker?Worker:class{};const be=new WeakMap,ve=(e,...t)=>{const r=_(e,...t);if(!be.has(r)){const t=e instanceof me?we:he;be.set(r,t(r,d,g))}return be.get(r)};ve.transfer=_.transfer;const Se={object(...e){return this.string(function(e){for(var t=e[0],r=1,n=arguments.length;r<n;r++)t+=arguments[r]+e[r];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}},Pe=(e,...t)=>Se[typeof e](e,...t),{isArray:Ee}=Array,{assign:Ae,create:Me,defineProperties:$e,defineProperty:je,entries:ke}=Object,{all:xe,resolve:Te}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),_e=(e,t=location.href)=>new URL(e,t).href;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 Oe=e=>e.arrayBuffer(),Fe=e=>e.json(),We=e=>e.text(),Re=new WeakMap,Be=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 Re.set(t,r),t}}},Je=({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})},Ie=e=>{const t=e.split(\"/\");return t.pop(),t.join(\"/\")},Le=(e,t)=>{const r=[];for(const n of t.split(\"/\"))\".\"!==n&&(r.push(n),n&&e.mkdir(r.join(\"/\")))},Ce=(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},De=new WeakMap,Ne=(e,t,r)=>xe((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(Ee(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})=>((e,t)=>fetch(_e(t,De.get(e))))(r,n).then(Oe).then((r=>e.writeFile(t,s,r)))))),Ue=(e,t,r)=>{e.registerJsModule(t,r)},ze=(e,t,...r)=>{try{return e.runPython(Pe(t),...r)}catch(t){Re.get(e).stderr(t)}},qe=async(e,t,...r)=>{try{return await e.runPythonAsync(Pe(t),...r)}catch(t){Re.get(e).stderr(t)}},Ke=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){Re.get(e).stderr(t)}};var Ye={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}=Be();r=r.replace(/\\.m?js$/,\".wasm\");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await Ne(this,a,t.fetch),a},registerJSModule:Ue,run:ze,runAsync:qe,runEvent:Ke,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Je({FS:e,PATH:t,PATH_FS:r},n,s)};const Ge={dict_converter:Object.fromEntries};var Ve={type:\"pyodide\",module:(e=\"0.23.4\")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Be(),a=r.slice(0,r.lastIndexOf(\"/\")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await Ne(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:Ue,run:ze,runAsync:qe,runEvent:Ke,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(Ge):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Je({FS:e,PATH:t,PATH_FS:r},n,s)};const Qe=\"ruby-wasm-wasi\",Xe=Qe.replace(/\\W+/g,\"_\");var Ze={type:Qe,experimental:!0,module:(e=\"2.0.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.fetch&&await Ne(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${Xe}_${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_${Xe}_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 ${Qe}`)}};var et={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}=Be(),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.fetch&&await Ne(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){Re.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Pe(t),...r)}catch(t){Re.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){Re.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Le(e,Ie(t)),t=Ce(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const tt=new Map,rt=new Map,nt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split(\"@\"),s=tt.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=>{rt.set(t,e);const a=e?.fetch;return a&&De.set(a,o),s(n,e,r)}))}}),st=e=>{for(const t of[].concat(e.type))tt.set(t,e)};for(const e of[Ye,Ve,Ze,et])st(e);const ot=async e=>(await import(\"https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js\")).parse(e);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 at,it,ct;const lt=(e,t)=>{addEventListener(e,t||(async t=>{try{await at,it(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:ut,stringify:ft}=f,{proxy:pt,window:dt,isWindowProxy:gt}=ve(self,{parse:ut,stringify:ft,transform:e=>ct?ct(e):e}),yt={sync:pt,window:dt,isWindowProxy:gt,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};lt(\"message\",(({data:{options:e,config:t,code:r,hooks:n}})=>{at=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await((e,t,r={})=>{if(t)if(t.endsWith(\".json\"))r=fetch(t).then(Fe),t=_e(t);else if(t.endsWith(\".toml\"))r=fetch(t).then(We).then(ot),t=_e(t);else if(!t.endsWith(\".txt\")){try{r=JSON.parse(t)}catch(e){r=ot(t)}t=_e(\"./config.txt\")}return Te(r).then((r=>nt[e](r,t)))})(((e,t=\"\")=>`${e}@${t}`.replace(/@$/,\"\"))(a,c),t,l),p=Me(tt.get(a)),d=\"run\"+(u?\"Async\":\"\");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=r||s,a=e||t;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)}}let g=\"\";return p.registerJSModule(f,\"polyscript\",{xworker:yt,get target(){if(!g){const{document:e}=yt.window,t=e.getElementById(s);\"SCRIPT\"===o?t.after(Ae(e.createElement(`script-${i||a}`),{id:g=`${s}-target`})):(g=s,t.replaceChildren(),t.style.display=\"block\")}return g}}),it=p.runEvent.bind(p,f),ct=p.transform.bind(p,f),await p[d](f,r),f}catch(e){postMessage(e)}})(),lt(\"error\"),lt(\"message\"),lt(\"messageerror\")}));\n"],{type:'application/javascript'})),{type:'module'}); |
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<t;e++)n.push(r.snapshotItem(e));return n},r="object"==typeof self?self:globalThis,n=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 g="891249cd-eb53-4bc8-ae48-b0a5a277d24a",y="M"+g,h="T"+g;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:A}=E,{isArray:k}=Array,{notify:$,wait:P,waitAsync:M}=Atomics,{fromCharCode:x}=String,j=(e,t)=>e?(M||w)(t,0):(P(t,0),{value:{then:e=>e()}}),T=new WeakSet,W=new WeakMap;let _=0;const R=(e,{parse:t,stringify:r,transform:n}=JSON)=>{if(!W.has(e)){const s=(t,...r)=>e.postMessage({[g]:r},{transfer:t});let o=!1;W.set(e,new Proxy(new b,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,a)=>"then"===a?null:(...r)=>{const i=_++;let c=new m(new v(S)),l=[];T.has(r.at(-1)||l)&&T.delete(l=r.pop()),s(l,i,c,a,n?r.map(n):r);const u=e!==globalThis;let f=0;return o&&u&&(f=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${a}(...args) is awaited`)),j(u,c).value.then((()=>{clearTimeout(f);const e=c[0];if(!e)return;const r=A*e;return c=new m(new v(r+r%S)),s([],i,c),j(u,c).value.then((()=>t(x(...new E(c.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new b;e.addEventListener("message",(async e=>{const s=e.data?.[g];if(k(s)){e.stopImmediatePropagation();const[a,i,...c]=s;if(c.length){const[e,s]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);o=!0;try{const o=await t.get(e)(...s);if(void 0!==o){const e=r(o);n.set(a,e),i[0]=e.length}}finally{o=!1}}else{const e=n.get(a);n.delete(a);for(let t=new E(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}$(i,0)}}))}return!!t.set(n,s)}}))}return W.get(e)};R.transfer=(...e)=>(T.add(e),e);const O="object",F="function",B="number",I="string",L="undefined",J="symbol",{defineProperty:C,getOwnPropertyDescriptor:N,getPrototypeOf:D,isExtensible:H,ownKeys:U,preventExtensions:q,set:z,setPrototypeOf:Q}=Reflect,{assign:X,create:Y}=Object,V=D(Int8Array),G="isArray",K=(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},Z=(e,t)=>[e,t],ee=e=>t=>{const r=typeof t;switch(r){case O:if(null==t)return Z("null",t);if(t===globalThis)return Z(O,null);case F:return e(r,t);case"boolean":case B:case I:case L:case"bigint":return Z(r,t);case J:if(te.has(t))return Z(r,te.get(t))}throw new Error(`Unable to handle this ${r} type`)},te=new Map(U(Symbol).filter((e=>typeof Symbol[e]===J)).map((e=>[Symbol[e],e]))),re=e=>{for(const[t,r]of te)if(r===e)return t};function ne(){return this}const se="apply",oe="construct",ae="defineProperty",ie="deleteProperty",ce="get",le="getOwnPropertyDescriptor",ue="getPrototypeOf",fe="has",pe="isExtensible",de="ownKeys",ge="preventExtensions",ye="set",he="setPrototypeOf",we="delete";var me=((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?X(Y(globalThis),...a):globalThis,p=ee(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return Z(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(we,Z(I,e))})),g=([e,r])=>{switch(e){case O:if(null==r)return f;if(typeof r===B)return l.get(r);if(!(r instanceof V))for(const e in r)r[e]=g(r[e]);return r;case F:if(typeof r===I){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(se,Z(F,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 J:return re(r)}return r},y={[se]:(e,t,r)=>p(e.apply(t,r)),[oe]:(e,t)=>p(new e(...t)),[ae]:(e,t,r)=>p(C(e,t,r)),[ie]:(e,t)=>p(delete e[t]),[ue]:e=>p(D(e)),[ce]:(e,t)=>p(e[t]),[le]:(e,t)=>{const r=N(e,t);return r?Z(O,K(r,p)):Z(L,r)},[fe]:(e,t)=>p(t in e),[pe]:e=>p(H(e)),[de]:e=>Z(O,U(e).map(p)),[ge]:e=>p(q(e)),[ye]:(e,t,r)=>p(z(e,t,r)),[he]:(e,t)=>p(Q(e,t)),[we](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case se:r[0]=g(r[0]),r[1]=r[1].map(g);break;case oe:r[0]=r[0].map(g);break;case ae:{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),be=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===F?e():e,a=e=>typeof e===O&&!!e&&s in e,i=Array[G],c=ee(((e,a)=>{if(s in a)return o(a[s]);if(e===F){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return Z(e,r.get(a))}if(!(a instanceof V))for(const e in a)a[e]=c(a[e]);return Z(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(we,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===F?ne.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 O:return null===r?globalThis:typeof r===B?g(e):r;case F:return typeof r===I?n.get(r):g(e);case J:return re(r)}return r},h=(e,t,...r)=>y(f(e,o(t),...r)),w={[se]:(e,t,r)=>h(se,e,c(t),r.map(c)),[oe]:(e,t)=>h(oe,e,t.map(c)),[ae]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===F&&(r.get=c(n)),typeof s===F&&(r.set=c(s)),typeof o===F&&(r.value=c(o)),h(ae,e,c(t),r)},[ie]:(e,t)=>h(ie,e,c(t)),[ue]:e=>h(ue,e),[ce]:(e,t)=>t===s?e:h(ce,e,c(t)),[le]:(e,t)=>{const r=h(le,e,c(t));return r&&K(r,y)},[fe]:(e,t)=>t===s||h(fe,e,c(t)),[pe]:e=>h(pe,e),[de]:e=>h(de,e).map(y),[ge]:e=>h(ge,e),[ye]:(e,t,r)=>h(ye,e,c(t),c(r)),[he]:(e,t)=>h(he,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case se:return y(t).apply(y(s),o.map(y));case we:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([O,null],w),b=m.Array[G];return C(Array,G,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})("Window"),ve="function"==typeof Worker?Worker:class{};const Ee=new WeakMap,Se=(e,...t)=>{const r=R(e,...t);if(!Ee.has(r)){const t=e instanceof ve?me:be;Ee.set(r,t(r,y,h))}return Ee.get(r)};Se.transfer=R.transfer;const{isArray:Ae}=Array,{assign:ke,create:$e,defineProperties:Pe,defineProperty:Me,entries:xe}=Object,{all:je,resolve:Te}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),We=(e,t=location.href)=>new URL(e,t).href;let _e=0;const Re=(e,t)=>({id:e.id||(e.id=`${t}-w${_e++}`),tag:e.tagName}),Oe=e=>e.arrayBuffer(),Fe=e=>e.json(),Be=e=>e.text(),Ie=[["beforeRun","codeBeforeRunWorker"],["beforeRunAsync","codeBeforeRunWorkerAsync"],["afterRun","codeAfterRunWorker"],["afterRunAsync","codeAfterRunWorkerAsync"]];class Le{constructor(e,t){this.interpreter=e,this.onWorkerReady=t.onWorkerReady;for(const[e,r]of Ie)this[e]=t[r]?.()}get stringHooks(){const e={};for(const[t]of Ie)this[t]&&(e[t]=this[t]);return e}}var Je=(...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="891249cd-eb53-4bc8-ae48-b0a5a277d24a",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:w,Map:h,SharedArrayBuffer:m,Uint16Array:b}=globalThis,{BYTES_PER_ELEMENT:v}=w,{BYTES_PER_ELEMENT:S}=b,{isArray:P}=Array,{notify:A,wait:E,waitAsync:M}=Atomics,{fromCharCode:$}=String,j=(e,t)=>e?(M||y)(t,0):(E(t,0),{value:{then:e=>e()}}),T=new WeakSet,k=new WeakMap;let _=0;const x=(e,{parse:t,stringify:r,transform:n}=JSON)=>{if(!k.has(e)){const s=(t,...r)=>e.postMessage({[p]:r},{transfer:t});let o=!1;k.set(e,new Proxy(new h,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,a)=>"then"===a?null:(...r)=>{const i=_++;let c=new w(new m(v)),l=[];T.has(r.at(-1)||l)&&T.delete(l=r.pop()),s(l,i,c,a,n?r.map(n):r);const u=e!==globalThis;let f=0;return o&&u&&(f=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${a}(...args) is awaited`)),j(u,c).value.then((()=>{clearTimeout(f);const e=c[0];if(!e)return;const r=S*e;return c=new w(new m(r+r%v)),s([],i,c),j(u,c).value.then((()=>t($(...new b(c.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new h;e.addEventListener("message",(async e=>{const s=e.data?.[p];if(P(s)){e.stopImmediatePropagation();const[a,i,...c]=s;if(c.length){const[e,s]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);o=!0;try{const o=await t.get(e)(...s);if(void 0!==o){const e=r(o);n.set(a,e),i[0]=e.length}}finally{o=!1}}else{const e=n.get(a);n.delete(a);for(let t=new b(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}A(i,0)}}))}return!!t.set(n,s)}}))}return k.get(e)};x.transfer=(...e)=>(T.add(e),e);const O="object",F="function",W="number",R="string",B="undefined",J="symbol",{defineProperty:I,getOwnPropertyDescriptor:L,getPrototypeOf:C,isExtensible:H,ownKeys:D,preventExtensions:N,set:U,setPrototypeOf:z}=Reflect,{assign:q,create:K}=Object,Y=C(Int8Array),G="isArray",V=(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},Q=(e,t)=>[e,t],X=e=>t=>{const r=typeof t;switch(r){case O:if(null==t)return Q("null",t);if(t===globalThis)return Q(O,null);case F:return e(r,t);case"boolean":case W:case R:case B:case"bigint":return Q(r,t);case J:if(Z.has(t))return Q(r,Z.get(t))}throw new Error(`Unable to handle this ${r} type`)},Z=new Map(D(Symbol).filter((e=>typeof Symbol[e]===J)).map((e=>[Symbol[e],e]))),ee=e=>{for(const[t,r]of Z)if(r===e)return t};function te(){return this}const re="apply",ne="construct",se="defineProperty",oe="deleteProperty",ae="get",ie="getOwnPropertyDescriptor",ce="getPrototypeOf",le="has",ue="isExtensible",fe="ownKeys",pe="preventExtensions",de="set",ge="setPrototypeOf",ye="delete";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;I(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?q(K(globalThis),...a):globalThis,p=X(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return Q(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(ye,Q(R,e))})),g=([e,r])=>{switch(e){case O:if(null==r)return f;if(typeof r===W)return l.get(r);if(!(r instanceof Y))for(const e in r)r[e]=g(r[e]);return r;case F:if(typeof r===R){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(re,Q(F,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 J:return ee(r)}return r},y={[re]:(e,t,r)=>p(e.apply(t,r)),[ne]:(e,t)=>p(new e(...t)),[se]:(e,t,r)=>p(I(e,t,r)),[oe]:(e,t)=>p(delete e[t]),[ce]:e=>p(C(e)),[ae]:(e,t)=>p(e[t]),[ie]:(e,t)=>{const r=L(e,t);return r?Q(O,V(r,p)):Q(B,r)},[le]:(e,t)=>p(t in e),[ue]:e=>p(H(e)),[fe]:e=>Q(O,D(e).map(p)),[pe]:e=>p(N(e)),[de]:(e,t,r)=>p(U(e,t,r)),[ge]:(e,t)=>p(z(e,t)),[ye](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case re:r[0]=g(r[0]),r[1]=r[1].map(g);break;case ne:r[0]=r[0].map(g);break;case se:{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),he=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===F?e():e,a=e=>typeof e===O&&!!e&&s in e,i=Array[G],c=X(((e,a)=>{if(s in a)return o(a[s]);if(e===F){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return Q(e,r.get(a))}if(!(a instanceof Y))for(const e in a)a[e]=c(a[e]);return Q(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(ye,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===F?te.bind(e):e,s=new Proxy(n,h),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 O:return null===r?globalThis:typeof r===W?g(e):r;case F:return typeof r===R?n.get(r):g(e);case J:return ee(r)}return r},w=(e,t,...r)=>y(f(e,o(t),...r)),h={[re]:(e,t,r)=>w(re,e,c(t),r.map(c)),[ne]:(e,t)=>w(ne,e,t.map(c)),[se]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===F&&(r.get=c(n)),typeof s===F&&(r.set=c(s)),typeof o===F&&(r.value=c(o)),w(se,e,c(t),r)},[oe]:(e,t)=>w(oe,e,c(t)),[ce]:e=>w(ce,e),[ae]:(e,t)=>t===s?e:w(ae,e,c(t)),[ie]:(e,t)=>{const r=w(ie,e,c(t));return r&&V(r,y)},[le]:(e,t)=>t===s||w(le,e,c(t)),[ue]:e=>w(ue,e),[fe]:e=>w(fe,e).map(y),[pe]:e=>w(pe,e),[de]:(e,t,r)=>w(de,e,c(t),c(r)),[ge]:(e,t)=>w(ge,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case re:return y(t).apply(y(s),o.map(y));case ye:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([O,null],h),b=m.Array[G];return I(Array,G,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})("Window"),me="function"==typeof Worker?Worker:class{};const be=new WeakMap,ve=(e,...t)=>{const r=x(e,...t);if(!be.has(r)){const t=e instanceof me?we:he;be.set(r,t(r,d,g))}return be.get(r)};ve.transfer=x.transfer;const{isArray:Se}=Array,{assign:Pe,create:Ae,defineProperties:Ee,defineProperty:Me,entries:$e}=Object,{all:je,resolve:Te}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),ke=(e,t=location.href)=>new URL(e,t).href;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 _e=e=>e.arrayBuffer(),xe=e=>e.json(),Oe=e=>e.text(),Fe=e=>e.replace(/^[^\\r\\n]+$/,(e=>e.trim())),We=new WeakMap,Re=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 We.set(t,r),t}}},Be=({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})},Je=e=>{const t=e.split("/");return t.pop(),t.join("/")},Ie=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Le=(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(/^\\/+/,"/")},Ce=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},He=new WeakMap,De=(e,t,r)=>je((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(Se(n))return n.map((r=>({url:Ce([e,r]),path:Ce([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:Ce([t,s])}]}))})(r).map((({url:n,path:s})=>((e,t)=>fetch(ke(t,He.get(e))))(r,n).then(_e).then((r=>e.writeFile(t,s,r)))))),Ne=(e,t,r)=>{e.registerJsModule(t,r)},Ue=(e,t,...r)=>{try{return e.runPython(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},ze=async(e,t,...r)=>{try{return await e.runPythonAsync(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},qe=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){We.get(e).stderr(t)}};var Ke={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}=Re();r=r.replace(/\\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await De(this,a,t.fetch),a},registerJSModule:Ne,run:Ue,runAsync:ze,runEvent:qe,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Be({FS:e,PATH:t,PATH_FS:r},n,s)};const Ye={dict_converter:Object.fromEntries};var Ge={type:"pyodide",module:(e="0.23.4")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Re(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await De(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:Ne,run:Ue,runAsync:ze,runEvent:qe,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(Ye):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Be({FS:e,PATH:t,PATH_FS:r},n,s)};const Ve="ruby-wasm-wasi",Qe=Ve.replace(/\\W+/g,"_");var Xe={type:Ve,experimental:!0,module:(e="2.0.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.fetch&&await De(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${Qe}_${t}`;globalThis[n]=r,this.run(e,`require "js";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval(Fe(t),...r),runAsync:(e,t,...r)=>e.evalAsync(Fe(t),...r),async runEvent(e,t,r){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${Qe}_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 ${Ve}`)}};var Ze={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}=Re(),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.fetch&&await De(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Fe(t),...r)}catch(t){We.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){We.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Ie(e,Je(t)),t=Le(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const et=new Map,tt=new Map,rt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=et.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=>{tt.set(t,e);const a=e?.fetch;return a&&He.set(a,o),s(n,e,r)}))}}),nt=e=>{for(const t of[].concat(e.type))et.set(t,e)};for(const e of[Ke,Ge,Xe,Ze])nt(e);const st=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e);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 ot,at,it;const ct=(e,t)=>{addEventListener(e,t||(async t=>{try{await ot,at(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:lt,stringify:ut}=f,{proxy:ft,window:pt,isWindowProxy:dt}=ve(self,{parse:lt,stringify:ut,transform:e=>it?it(e):e}),gt={sync:ft,window:pt,isWindowProxy:dt,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};ct("message",(({data:{options:e,config:t,code:r,hooks:n}})=>{ot=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await((e,t,r={})=>{if(t)if(t.endsWith(".json"))r=fetch(t).then(xe),t=ke(t);else if(t.endsWith(".toml"))r=fetch(t).then(Oe).then(st),t=ke(t);else if(!t.endsWith(".txt")){try{r=JSON.parse(t)}catch(e){r=st(t)}t=ke("./config.txt")}return Te(r).then((r=>rt[e](r,t)))})(((e,t="")=>`${e}@${t}`.replace(/@$/,""))(a,c),t,l),p=Ae(et.get(a)),d="run"+(u?"Async":"");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=r||s,a=e||t;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)}}let g="";return p.registerJSModule(f,"polyscript",{xworker:gt,get target(){if(!g){const{document:e}=gt.window,t=e.getElementById(s);"SCRIPT"===o?t.after(Pe(e.createElement(`script-${i||a}`),{id:g=`${s}-target`})):(g=s,t.replaceChildren(),t.style.display="block")}return g}}),at=p.runEvent.bind(p,f),it=p.transform.bind(p,f),await p[d](f,r),f}catch(e){postMessage(e)}})(),ct("error"),ct("message"),ct("messageerror")}));\n'],{type:"application/javascript"})),{type:"module"}),{postMessage:s}=n,o=this instanceof Le;if(e.length){const[t,n]=e;(r=ke({},r||{type:t,version:n})).type||(r.type=t)}const{config:a}=r,i=We(a&&"string"==typeof a?a:"./config.txt"),c=fetch(t).then(Be).then((e=>{const t=o?this.stringHooks:void 0;s.call(n,{options:r,config:i,code:e,hooks:t})}));return Pe(n,{postMessage:{value:(e,...t)=>c.then((()=>s.call(n,e,...t)))},sync:{value:Se(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},Ce=e=>{const{worker:t}=e.attributes;if(t){let{value:r}=t;if(!r){if(e.childElementCount){const{innerHTML:t,localName:n,type:s}=e,o=s||n.replace(/-script$/,"");console.warn(`Deprecated: use <script type="${o}"> for an always safe content parsing:\n`,t),r=t}else r=e.textContent;for(const e of r.split(/[\r\n]+/))if(e.trim().length){if(/^(\s+)/.test(e)){const e=`^${RegExp.$1}`;r=r.replace(new RegExp(e,"gm"),"")}break}return URL.createObjectURL(new Blob([r],{type:"text/plain"}))}return 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 Ne=e=>e.replace(/^[^\r\n]+$/,(e=>e.trim())),De=new WeakMap,He=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 De.set(t,r),t}}},Ue=({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})},qe=e=>{const t=e.split("/");return t.pop(),t.join("/")},ze=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Qe=(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(/^\/+/,"/")},Xe=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Ye=new WeakMap,Ve=(e,t,r)=>je((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(Ae(n))return n.map((r=>({url:Xe([e,r]),path:Xe([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:Xe([t,s])}]}))})(r).map((({url:n,path:s})=>((e,t)=>fetch(We(t,Ye.get(e))))(r,n).then(Oe).then((r=>e.writeFile(t,s,r)))))),Ge=(e,t,r)=>{e.registerJsModule(t,r)},Ke=(e,t,...r)=>{try{return e.runPython(Ne(t),...r)}catch(t){De.get(e).stderr(t)}},Ze=async(e,t,...r)=>{try{return await e.runPythonAsync(Ne(t),...r)}catch(t){De.get(e).stderr(t)}},et=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){De.get(e).stderr(t)}};var tt={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}=He();r=r.replace(/\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await Ve(this,a,t.fetch),a},registerJSModule:Ge,run:Ke,runAsync:Ze,runEvent:et,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Ue({FS:e,PATH:t,PATH_FS:r},n,s)};const rt={dict_converter:Object.fromEntries};var nt={type:"pyodide",module:(e="0.23.4")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=He(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await Ve(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:Ge,run:Ke,runAsync:Ze,runEvent:et,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(rt):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Ue({FS:e,PATH:t,PATH_FS:r},n,s)};const st="ruby-wasm-wasi",ot=st.replace(/\W+/g,"_");var at={type:st,experimental:!0,module:(e="2.0.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.fetch&&await Ve(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${ot}_${t}`;globalThis[n]=r,this.run(e,`require "js";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval(Ne(t),...r),runAsync:(e,t,...r)=>e.evalAsync(Ne(t),...r),async runEvent(e,t,r){if(/^xworker\.(on\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${ot}_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 ${st}`)}};var it={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}=He(),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.fetch&&await Ve(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync(Ne(t),...r)}catch(t){De.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Ne(t),...r)}catch(t){De.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){De.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(ze(e,qe(t)),t=Qe(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const ct=new Map,lt=new Map,ut=[],ft=[],pt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=ct.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=>{lt.set(t,e);const a=e?.fetch;return a&&Ye.set(a,o),s(n,e,r)}))}}),dt=e=>{for(const t of[].concat(e.type))ct.set(t,e),ut.push(`script[type="${t}"]`),ft.push(`${t}-`)};for(const e of[tt,nt,at,it])dt(e);const gt=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),yt=(e,t,r={})=>{if(t)if(t.endsWith(".json"))r=fetch(t).then(Fe),t=We(t);else if(t.endsWith(".toml"))r=fetch(t).then(Be).then(gt),t=We(t);else if(!t.endsWith(".txt")){try{r=JSON.parse(t)}catch(e){r=gt(t)}t=We("./config.txt")}return Te(r).then((r=>pt[e](r,t)))},ht=(e,t="")=>`${e}@${t}`.replace(/@$/,""),wt=(e,t)=>{const r=(e=>{let t=e;for(;t.parentNode;)t=t.parentNode;return t})(e);return r.getElementById(t)||((e,t=document)=>t.querySelector(e))(t,r)},mt=new WeakMap,bt={get(){let e=mt.get(this);return e||(e=document.createElement(`${this.type}-script`),mt.set(this,e),kt(this)),e},set(e){"string"==typeof e?mt.set(this,wt(this,e)):(mt.set(this,e),kt(this))}},vt=new WeakMap,Et=new Map,St=(e,t)=>{const r=e?.value;return r?t+r:""},At=(e,t,r,n,s,o=e)=>{if(!Et.has(t)){const a={interpreter:yt(r,s),queue:Te(),XWorker:Je(e,n)};Et.set(t,a),Et.has(e)||Et.set(e,a),Et.has(o)||Et.set(o,a)}return Et.get(t)},kt=async e=>{if(vt.has(e)){const{target:t}=e;t&&(e.closest("head")?document.body.append(t):e.after(t))}else{const{attributes:{async:t,config:r,env:n,target:s,version:o},src:a,type:i}=e,c=o?.value,l=ht(i,c);let u=St(r,"|");const f=St(n,"")||`${l}${u}`;u=u.slice(1);const p=Ce(e);if(p){const r=new(Je(i,c))(p,{...Re(e,i),async:!!t,config:u});return void vt.set(Me(e,"xworker",{value:r}),{xworker:r})}const d=St(s,""),g=At(i,f,l,c,u);vt.set(Me(e,"target",bt),g),d&&mt.set(e,wt(e,d));const y=a?fetch(a).then(Be):e.textContent;g.queue=g.queue.then((()=>(async(e,t,r,n)=>{const s=ct.get(e.type);s.experimental&&console.warn(`The ${e.type} interpreter is experimental`);const[o,a]=await je([vt.get(e).interpreter,t]);try{return Me(document,"currentScript",{configurable:!0,get:()=>e}),s.registerJSModule(o,"polyscript",{XWorker:r}),s[n?"runAsync":"run"](o,a)}finally{delete document.currentScript}})(e,y,g.XWorker,!!t)))}},$t=new Proxy($e(null),{get:(e,t)=>Pt(t)}),Pt=async e=>{if(Et.has(e)){const{interpreter:t,queue:r}=Et.get(e);return(await je([t,r]))[0]}const t=Et.size?`Available interpreters are: ${[...Et.keys()].map((e=>`"${e}"`)).join(", ")}.`:"There are no interpreters in this page.";throw new Error(`The interpreter "${e}" was not found. ${t}`)},Mt=async e=>{const{type:r,currentTarget:n}=e;for(let{name:s,value:o,ownerElement:a}of t(`./@*[${ft.map((e=>`name()="${e}${r}"`)).join(" or ")}]`,n)){s=s.slice(0,-(r.length+1));const t=await Pt(a.getAttribute(`${s}-env`)||s);ct.get(s).runEvent(t,o,e)}},xt=e=>{for(let{name:r,ownerElement:n}of t(`.//@*[${ft.map((e=>`starts-with(name(),"${e}")`)).join(" or ")}]`,e))r=r.slice(r.lastIndexOf("-")+1),"env"!==r&&n.addEventListener(r,Mt)},jt=[],Tt=new Map,Wt=new Map,_t=e=>{for(const t of jt)if(e.matches(t)){const r=Tt.get(t),{resolve:n}=Wt.get(r),{options:s,known:o}=Rt.get(r);if(!o.has(e)){o.add(e);const{interpreter:t,config:a,version:i,env:c,onInterpreterReady:l}=s,u=Ce(e);if(u){const o=It.call(new Le(null,s),u,{...Re(e,r),version:i,type:t,custom:r,config:a||{},async:e.hasAttribute("async")});return Me(e,"xworker",{value:o}),void n({type:r,xworker:o})}const f=ht(t,i),p=c||`${f}${a?`|${a}`:""}`,{interpreter:d,XWorker:g}=At(r,p,f,i,a,t);d.then((o=>{const a=$e(ct.get(t)),{onBeforeRun:i,onBeforeRunAsync:c,onAfterRun:u,onAfterRunAsync:p}=s,d=new Le(o,s),y=function(...e){return g.apply(d,e)};for(const[t,[r,n]]of[["run",[i,u]]]){const s=a[t];a[t]=function(t,o,...a){r&&r.call(this,h,e);const i=s.call(this,t,o,...a);return n&&n.call(this,h,e),i}}for(const[t,[r,n]]of[["runAsync",[c,p]]]){const s=a[t];a[t]=async function(t,o,...a){r&&await r.call(this,h,e);const i=await s.call(this,t,o,...a);return n&&await n.call(this,h,e),i}}a.registerJSModule(o,"polyscript",{XWorker:y});const h={type:r,interpreter:o,XWorker:y,io:De.get(o),config:structuredClone(lt.get(f)),run:a.run.bind(a,o),runAsync:a.runAsync.bind(a,o),runEvent:a.runEvent.bind(a,o)};n(h),l?.(h,e)}))}}},Rt=new Map;let Ot=0;const Ft=(t,r)=>{let n=null==t;if(n)t="_ps"+Ot++;else if(ct.has(t)||Rt.has(t))throw new Error(`<script type="${t}"> already registered`);if(!ct.has(r?.interpreter))throw new Error("Unspecified interpreter");ct.set(t,ct.get(r.interpreter));const s=[`script[type="${t}"]`];if(Bt(t),n){const{onInterpreterReady:e}=r;r={...r,onInterpreterReady(r,n){jt.splice(jt.indexOf(t),1),ct.delete(t),Rt.delete(t),Wt.delete(t),n.remove(),e?.(r)}},document.head.append(ke(document.createElement("script"),{type:t}))}else s.push(`${t}-script`),ft.push(`${t}-`);for(const e of s)Tt.set(e,t);jt.push(...s),Rt.set(t,{options:ke({env:t},r),known:new WeakSet}),n||xt(document),e(s.join(",")).forEach(_t)},Bt=e=>(Wt.has(e)||Wt.set(e,Promise.withResolvers()),Wt.get(e).promise),It=Je(),Lt=ut.join(","),Jt=new MutationObserver((t=>{for(const{type:r,target:n,attributeName:s,addedNodes:o}of t)if("attributes"!==r){for(const t of o)if(1===t.nodeType)if(xt(t),t.matches(Lt))kt(t);else{if(e(Lt,t).forEach(kt),!jt.length)continue;_t(t),e(jt.join(","),t).forEach(_t)}}else{const e=s.lastIndexOf("-")+1;if(e){const t=s.slice(0,e);for(const r of ft)if(t===r){const t=s.slice(e);if("env"!==t){const e=n.hasAttribute(s)?"add":"remove";n[`${e}EventListener`](t,Mt)}break}}}})),Ct=e=>(Jt.observe(e,{childList:!0,subtree:!0,attributes:!0}),e),{attachShadow:Nt}=Element.prototype;ke(Element.prototype,{attachShadow(e){return Ct(Nt.call(this,e))}}),xt(Ct(document)),e(Lt,document).forEach(kt);export{It as XWorker,Ft as define,$t as env,Bt as whenDefined}; | ||
/*! (c) Andrea Giammarchi - ISC */;const{Int32Array:m,Map:b,SharedArrayBuffer:v,Uint16Array:E}=globalThis,{BYTES_PER_ELEMENT:S}=m,{BYTES_PER_ELEMENT:A}=E,{isArray:P}=Array,{notify:k,wait:$,waitAsync:M}=Atomics,{fromCharCode:x}=String,j=(e,t)=>e?(M||w)(t,0):($(t,0),{value:{then:e=>e()}}),T=new WeakSet,R=new WeakMap;let _=0;const O=(e,{parse:t,stringify:r,transform:n}=JSON)=>{if(!R.has(e)){const s=(t,...r)=>e.postMessage({[g]:r},{transfer:t});let o=!1;R.set(e,new Proxy(new b,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,a)=>"then"===a?null:(...r)=>{const i=_++;let c=new m(new v(S)),l=[];T.has(r.at(-1)||l)&&T.delete(l=r.pop()),s(l,i,c,a,n?r.map(n):r);const u=e!==globalThis;let f=0;return o&&u&&(f=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${a}(...args) is awaited`)),j(u,c).value.then((()=>{clearTimeout(f);const e=c[0];if(!e)return;const r=A*e;return c=new m(new v(r+r%S)),s([],i,c),j(u,c).value.then((()=>t(x(...new E(c.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new b;e.addEventListener("message",(async e=>{const s=e.data?.[g];if(P(s)){e.stopImmediatePropagation();const[a,i,...c]=s;if(c.length){const[e,s]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);o=!0;try{const o=await t.get(e)(...s);if(void 0!==o){const e=r(o);n.set(a,e),i[0]=e.length}}finally{o=!1}}else{const e=n.get(a);n.delete(a);for(let t=new E(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}k(i,0)}}))}return!!t.set(n,s)}}))}return R.get(e)};O.transfer=(...e)=>(T.add(e),e);const W="object",F="function",B="number",I="string",L="undefined",J="symbol",{defineProperty:N,getOwnPropertyDescriptor:C,getPrototypeOf:H,isExtensible:D,ownKeys:U,preventExtensions:q,set:z,setPrototypeOf:Q}=Reflect,{assign:X,create:Y}=Object,K=H(Int8Array),G="isArray",V=(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},Z=(e,t)=>[e,t],ee=e=>t=>{const r=typeof t;switch(r){case W:if(null==t)return Z("null",t);if(t===globalThis)return Z(W,null);case F:return e(r,t);case"boolean":case B:case I:case L:case"bigint":return Z(r,t);case J:if(te.has(t))return Z(r,te.get(t))}throw new Error(`Unable to handle this ${r} type`)},te=new Map(U(Symbol).filter((e=>typeof Symbol[e]===J)).map((e=>[Symbol[e],e]))),re=e=>{for(const[t,r]of te)if(r===e)return t};function ne(){return this}const se="apply",oe="construct",ae="defineProperty",ie="deleteProperty",ce="get",le="getOwnPropertyDescriptor",ue="getPrototypeOf",fe="has",pe="isExtensible",de="ownKeys",ge="preventExtensions",ye="set",he="setPrototypeOf",we="delete";var me=((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?X(Y(globalThis),...a):globalThis,p=ee(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return Z(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(we,Z(I,e))})),g=([e,r])=>{switch(e){case W:if(null==r)return f;if(typeof r===B)return l.get(r);if(!(r instanceof K))for(const e in r)r[e]=g(r[e]);return r;case F:if(typeof r===I){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(se,Z(F,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 J:return re(r)}return r},y={[se]:(e,t,r)=>p(e.apply(t,r)),[oe]:(e,t)=>p(new e(...t)),[ae]:(e,t,r)=>p(N(e,t,r)),[ie]:(e,t)=>p(delete e[t]),[ue]:e=>p(H(e)),[ce]:(e,t)=>p(e[t]),[le]:(e,t)=>{const r=C(e,t);return r?Z(W,V(r,p)):Z(L,r)},[fe]:(e,t)=>p(t in e),[pe]:e=>p(D(e)),[de]:e=>Z(W,U(e).map(p)),[ge]:e=>p(q(e)),[ye]:(e,t,r)=>p(z(e,t,r)),[he]:(e,t)=>p(Q(e,t)),[we](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case se:r[0]=g(r[0]),r[1]=r[1].map(g);break;case oe:r[0]=r[0].map(g);break;case ae:{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),be=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===F?e():e,a=e=>typeof e===W&&!!e&&s in e,i=Array[G],c=ee(((e,a)=>{if(s in a)return o(a[s]);if(e===F){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return Z(e,r.get(a))}if(!(a instanceof K))for(const e in a)a[e]=c(a[e]);return Z(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(we,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===F?ne.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 W:return null===r?globalThis:typeof r===B?g(e):r;case F:return typeof r===I?n.get(r):g(e);case J:return re(r)}return r},h=(e,t,...r)=>y(f(e,o(t),...r)),w={[se]:(e,t,r)=>h(se,e,c(t),r.map(c)),[oe]:(e,t)=>h(oe,e,t.map(c)),[ae]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===F&&(r.get=c(n)),typeof s===F&&(r.set=c(s)),typeof o===F&&(r.value=c(o)),h(ae,e,c(t),r)},[ie]:(e,t)=>h(ie,e,c(t)),[ue]:e=>h(ue,e),[ce]:(e,t)=>t===s?e:h(ce,e,c(t)),[le]:(e,t)=>{const r=h(le,e,c(t));return r&&V(r,y)},[fe]:(e,t)=>t===s||h(fe,e,c(t)),[pe]:e=>h(pe,e),[de]:e=>h(de,e).map(y),[ge]:e=>h(ge,e),[ye]:(e,t,r)=>h(ye,e,c(t),c(r)),[he]:(e,t)=>h(he,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case se:return y(t).apply(y(s),o.map(y));case we:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([W,null],w),b=m.Array[G];return N(Array,G,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})("Window"),ve="function"==typeof Worker?Worker:class{};const Ee=new WeakMap,Se=(e,...t)=>{const r=O(e,...t);if(!Ee.has(r)){const t=e instanceof ve?me:be;Ee.set(r,t(r,y,h))}return Ee.get(r)};Se.transfer=O.transfer;const Ae={object(...e){return this.string(function(e){for(var t=e[0],r=1,n=arguments.length;r<n;r++)t+=arguments[r]+e[r];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}},Pe=(e,...t)=>Ae[typeof e](e,...t),{isArray:ke}=Array,{assign:$e,create:Me,defineProperties:xe,defineProperty:je,entries:Te}=Object,{all:Re,resolve:_e}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Oe=(e,t=location.href)=>new URL(e,t).href;let We=0;const Fe=(e,t)=>({id:e.id||(e.id=`${t}-w${We++}`),tag:e.tagName}),Be=e=>e.arrayBuffer(),Ie=e=>e.json(),Le=e=>e.text(),Je=[["beforeRun","codeBeforeRunWorker"],["beforeRunAsync","codeBeforeRunWorkerAsync"],["afterRun","codeAfterRunWorker"],["afterRunAsync","codeAfterRunWorkerAsync"]];class Ne{constructor(e,t){this.interpreter=e,this.onWorkerReady=t.onWorkerReady;for(const[e,r]of Je)this[e]=t[r]?.()}get stringHooks(){const e={};for(const[t]of Je)this[t]&&(e[t]=Pe(this[t]));return e}}var Ce=(...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="891249cd-eb53-4bc8-ae48-b0a5a277d24a",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:w,Map:h,SharedArrayBuffer:m,Uint16Array:b}=globalThis,{BYTES_PER_ELEMENT:v}=w,{BYTES_PER_ELEMENT:S}=b,{isArray:P}=Array,{notify:E,wait:A,waitAsync:M}=Atomics,{fromCharCode:$}=String,j=(e,t)=>e?(M||y)(t,0):(A(t,0),{value:{then:e=>e()}}),k=new WeakSet,x=new WeakMap;let T=0;const _=(e,{parse:t,stringify:r,transform:n}=JSON)=>{if(!x.has(e)){const s=(t,...r)=>e.postMessage({[p]:r},{transfer:t});let o=!1;x.set(e,new Proxy(new h,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,a)=>"then"===a?null:(...r)=>{const i=T++;let c=new w(new m(v)),l=[];k.has(r.at(-1)||l)&&k.delete(l=r.pop()),s(l,i,c,a,n?r.map(n):r);const u=e!==globalThis;let f=0;return o&&u&&(f=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${a}(...args) is awaited`)),j(u,c).value.then((()=>{clearTimeout(f);const e=c[0];if(!e)return;const r=S*e;return c=new w(new m(r+r%v)),s([],i,c),j(u,c).value.then((()=>t($(...new b(c.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new h;e.addEventListener("message",(async e=>{const s=e.data?.[p];if(P(s)){e.stopImmediatePropagation();const[a,i,...c]=s;if(c.length){const[e,s]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);o=!0;try{const o=await t.get(e)(...s);if(void 0!==o){const e=r(o);n.set(a,e),i[0]=e.length}}finally{o=!1}}else{const e=n.get(a);n.delete(a);for(let t=new b(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}E(i,0)}}))}return!!t.set(n,s)}}))}return x.get(e)};_.transfer=(...e)=>(k.add(e),e);const O="object",F="function",W="number",R="string",B="undefined",J="symbol",{defineProperty:I,getOwnPropertyDescriptor:L,getPrototypeOf:C,isExtensible:H,ownKeys:D,preventExtensions:N,set:U,setPrototypeOf:z}=Reflect,{assign:q,create:K}=Object,Y=C(Int8Array),G="isArray",V=(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},Q=(e,t)=>[e,t],X=e=>t=>{const r=typeof t;switch(r){case O:if(null==t)return Q("null",t);if(t===globalThis)return Q(O,null);case F:return e(r,t);case"boolean":case W:case R:case B:case"bigint":return Q(r,t);case J:if(Z.has(t))return Q(r,Z.get(t))}throw new Error(`Unable to handle this ${r} type`)},Z=new Map(D(Symbol).filter((e=>typeof Symbol[e]===J)).map((e=>[Symbol[e],e]))),ee=e=>{for(const[t,r]of Z)if(r===e)return t};function te(){return this}const re="apply",ne="construct",se="defineProperty",oe="deleteProperty",ae="get",ie="getOwnPropertyDescriptor",ce="getPrototypeOf",le="has",ue="isExtensible",fe="ownKeys",pe="preventExtensions",de="set",ge="setPrototypeOf",ye="delete";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;I(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?q(K(globalThis),...a):globalThis,p=X(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return Q(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(ye,Q(R,e))})),g=([e,r])=>{switch(e){case O:if(null==r)return f;if(typeof r===W)return l.get(r);if(!(r instanceof Y))for(const e in r)r[e]=g(r[e]);return r;case F:if(typeof r===R){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(re,Q(F,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 J:return ee(r)}return r},y={[re]:(e,t,r)=>p(e.apply(t,r)),[ne]:(e,t)=>p(new e(...t)),[se]:(e,t,r)=>p(I(e,t,r)),[oe]:(e,t)=>p(delete e[t]),[ce]:e=>p(C(e)),[ae]:(e,t)=>p(e[t]),[ie]:(e,t)=>{const r=L(e,t);return r?Q(O,V(r,p)):Q(B,r)},[le]:(e,t)=>p(t in e),[ue]:e=>p(H(e)),[fe]:e=>Q(O,D(e).map(p)),[pe]:e=>p(N(e)),[de]:(e,t,r)=>p(U(e,t,r)),[ge]:(e,t)=>p(z(e,t)),[ye](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case re:r[0]=g(r[0]),r[1]=r[1].map(g);break;case ne:r[0]=r[0].map(g);break;case se:{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),he=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===F?e():e,a=e=>typeof e===O&&!!e&&s in e,i=Array[G],c=X(((e,a)=>{if(s in a)return o(a[s]);if(e===F){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return Q(e,r.get(a))}if(!(a instanceof Y))for(const e in a)a[e]=c(a[e]);return Q(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(ye,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===F?te.bind(e):e,s=new Proxy(n,h),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 O:return null===r?globalThis:typeof r===W?g(e):r;case F:return typeof r===R?n.get(r):g(e);case J:return ee(r)}return r},w=(e,t,...r)=>y(f(e,o(t),...r)),h={[re]:(e,t,r)=>w(re,e,c(t),r.map(c)),[ne]:(e,t)=>w(ne,e,t.map(c)),[se]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===F&&(r.get=c(n)),typeof s===F&&(r.set=c(s)),typeof o===F&&(r.value=c(o)),w(se,e,c(t),r)},[oe]:(e,t)=>w(oe,e,c(t)),[ce]:e=>w(ce,e),[ae]:(e,t)=>t===s?e:w(ae,e,c(t)),[ie]:(e,t)=>{const r=w(ie,e,c(t));return r&&V(r,y)},[le]:(e,t)=>t===s||w(le,e,c(t)),[ue]:e=>w(ue,e),[fe]:e=>w(fe,e).map(y),[pe]:e=>w(pe,e),[de]:(e,t,r)=>w(de,e,c(t),c(r)),[ge]:(e,t)=>w(ge,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case re:return y(t).apply(y(s),o.map(y));case ye:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([O,null],h),b=m.Array[G];return I(Array,G,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})("Window"),me="function"==typeof Worker?Worker:class{};const be=new WeakMap,ve=(e,...t)=>{const r=_(e,...t);if(!be.has(r)){const t=e instanceof me?we:he;be.set(r,t(r,d,g))}return be.get(r)};ve.transfer=_.transfer;const Se={object(...e){return this.string(function(e){for(var t=e[0],r=1,n=arguments.length;r<n;r++)t+=arguments[r]+e[r];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}},Pe=(e,...t)=>Se[typeof e](e,...t),{isArray:Ee}=Array,{assign:Ae,create:Me,defineProperties:$e,defineProperty:je,entries:ke}=Object,{all:xe,resolve:Te}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),_e=(e,t=location.href)=>new URL(e,t).href;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 Oe=e=>e.arrayBuffer(),Fe=e=>e.json(),We=e=>e.text(),Re=new WeakMap,Be=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 Re.set(t,r),t}}},Je=({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})},Ie=e=>{const t=e.split("/");return t.pop(),t.join("/")},Le=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Ce=(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},De=new WeakMap,Ne=(e,t,r)=>xe((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(Ee(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})=>((e,t)=>fetch(_e(t,De.get(e))))(r,n).then(Oe).then((r=>e.writeFile(t,s,r)))))),Ue=(e,t,r)=>{e.registerJsModule(t,r)},ze=(e,t,...r)=>{try{return e.runPython(Pe(t),...r)}catch(t){Re.get(e).stderr(t)}},qe=async(e,t,...r)=>{try{return await e.runPythonAsync(Pe(t),...r)}catch(t){Re.get(e).stderr(t)}},Ke=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){Re.get(e).stderr(t)}};var Ye={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}=Be();r=r.replace(/\\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await Ne(this,a,t.fetch),a},registerJSModule:Ue,run:ze,runAsync:qe,runEvent:Ke,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Je({FS:e,PATH:t,PATH_FS:r},n,s)};const Ge={dict_converter:Object.fromEntries};var Ve={type:"pyodide",module:(e="0.23.4")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Be(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await Ne(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:Ue,run:ze,runAsync:qe,runEvent:Ke,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(Ge):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Je({FS:e,PATH:t,PATH_FS:r},n,s)};const Qe="ruby-wasm-wasi",Xe=Qe.replace(/\\W+/g,"_");var Ze={type:Qe,experimental:!0,module:(e="2.0.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.fetch&&await Ne(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${Xe}_${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_${Xe}_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 ${Qe}`)}};var et={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}=Be(),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.fetch&&await Ne(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){Re.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Pe(t),...r)}catch(t){Re.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){Re.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Le(e,Ie(t)),t=Ce(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const tt=new Map,rt=new Map,nt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=tt.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=>{rt.set(t,e);const a=e?.fetch;return a&&De.set(a,o),s(n,e,r)}))}}),st=e=>{for(const t of[].concat(e.type))tt.set(t,e)};for(const e of[Ye,Ve,Ze,et])st(e);const ot=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e);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 at,it,ct;const lt=(e,t)=>{addEventListener(e,t||(async t=>{try{await at,it(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:ut,stringify:ft}=f,{proxy:pt,window:dt,isWindowProxy:gt}=ve(self,{parse:ut,stringify:ft,transform:e=>ct?ct(e):e}),yt={sync:pt,window:dt,isWindowProxy:gt,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};lt("message",(({data:{options:e,config:t,code:r,hooks:n}})=>{at=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await((e,t,r={})=>{if(t)if(t.endsWith(".json"))r=fetch(t).then(Fe),t=_e(t);else if(t.endsWith(".toml"))r=fetch(t).then(We).then(ot),t=_e(t);else if(!t.endsWith(".txt")){try{r=JSON.parse(t)}catch(e){r=ot(t)}t=_e("./config.txt")}return Te(r).then((r=>nt[e](r,t)))})(((e,t="")=>`${e}@${t}`.replace(/@$/,""))(a,c),t,l),p=Me(tt.get(a)),d="run"+(u?"Async":"");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=r||s,a=e||t;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)}}let g="";return p.registerJSModule(f,"polyscript",{xworker:yt,get target(){if(!g){const{document:e}=yt.window,t=e.getElementById(s);"SCRIPT"===o?t.after(Ae(e.createElement(`script-${i||a}`),{id:g=`${s}-target`})):(g=s,t.replaceChildren(),t.style.display="block")}return g}}),it=p.runEvent.bind(p,f),ct=p.transform.bind(p,f),await p[d](f,r),f}catch(e){postMessage(e)}})(),lt("error"),lt("message"),lt("messageerror")}));\n'],{type:"application/javascript"})),{type:"module"}),{postMessage:s}=n,o=this instanceof Ne;if(e.length){const[t,n]=e;(r=$e({},r||{type:t,version:n})).type||(r.type=t)}const{config:a}=r,i=Oe(a&&"string"==typeof a?a:"./config.txt"),c=fetch(t).then(Le).then((e=>{const t=o?this.stringHooks:void 0;s.call(n,{options:r,config:i,code:e,hooks:t})}));return xe(n,{postMessage:{value:(e,...t)=>c.then((()=>s.call(n,e,...t)))},sync:{value:Se(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},He=e=>{const{worker:t}=e.attributes;if(t){let{value:r}=t;if(!r){if(e.childElementCount){const{innerHTML:t,localName:n,type:s}=e,o=s||n.replace(/-script$/,"");console.warn(`Deprecated: use <script type="${o}"> for an always safe content parsing:\n`,t),r=t}else r=e.textContent;return URL.createObjectURL(new Blob([Pe(r)],{type:"text/plain"}))}return 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 De=new WeakMap,Ue=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 De.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("/")},Qe=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Xe=(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(/^\/+/,"/")},Ye=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Ke=new WeakMap,Ge=(e,t,r)=>Re((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(ke(n))return n.map((r=>({url:Ye([e,r]),path:Ye([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:Ye([t,s])}]}))})(r).map((({url:n,path:s})=>((e,t)=>fetch(Oe(t,Ke.get(e))))(r,n).then(Be).then((r=>e.writeFile(t,s,r)))))),Ve=(e,t,r)=>{e.registerJsModule(t,r)},Ze=(e,t,...r)=>{try{return e.runPython(Pe(t),...r)}catch(t){De.get(e).stderr(t)}},et=async(e,t,...r)=>{try{return await e.runPythonAsync(Pe(t),...r)}catch(t){De.get(e).stderr(t)}},tt=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){De.get(e).stderr(t)}};var rt={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}=Ue();r=r.replace(/\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await Ge(this,a,t.fetch),a},registerJSModule:Ve,run:Ze,runAsync:et,runEvent:tt,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 nt={dict_converter:Object.fromEntries};var st={type:"pyodide",module:(e="0.23.4")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Ue(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await Ge(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:Ze,runAsync:et,runEvent:tt,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(nt):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>qe({FS:e,PATH:t,PATH_FS:r},n,s)};const ot="ruby-wasm-wasi",at=ot.replace(/\W+/g,"_");var it={type:ot,experimental:!0,module:(e="2.0.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.fetch&&await Ge(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${at}_${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_${at}_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 ${ot}`)}};var ct={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}=Ue(),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.fetch&&await Ge(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){De.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Pe(t),...r)}catch(t){De.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){De.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Qe(e,ze(t)),t=Xe(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const lt=new Map,ut=new Map,ft=[],pt=[],dt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=lt.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=>{ut.set(t,e);const a=e?.fetch;return a&&Ke.set(a,o),s(n,e,r)}))}}),gt=e=>{for(const t of[].concat(e.type))lt.set(t,e),ft.push(`script[type="${t}"]`),pt.push(`${t}-`)};for(const e of[rt,st,it,ct])gt(e);const yt=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),ht=(e,t,r={})=>{if(t)if(t.endsWith(".json"))r=fetch(t).then(Ie),t=Oe(t);else if(t.endsWith(".toml"))r=fetch(t).then(Le).then(yt),t=Oe(t);else if(!t.endsWith(".txt")){try{r=JSON.parse(t)}catch(e){r=yt(t)}t=Oe("./config.txt")}return _e(r).then((r=>dt[e](r,t)))},wt=(e,t="")=>`${e}@${t}`.replace(/@$/,""),mt=(e,t)=>{const r=(e=>{let t=e;for(;t.parentNode;)t=t.parentNode;return t})(e);return r.getElementById(t)||((e,t=document)=>t.querySelector(e))(t,r)},bt=new WeakMap,vt={get(){let e=bt.get(this);return e||(e=document.createElement(`${this.type}-script`),bt.set(this,e),kt(this)),e},set(e){"string"==typeof e?bt.set(this,mt(this,e)):(bt.set(this,e),kt(this))}},Et=new WeakMap,St=new Map,At=(e,t)=>{const r=e?.value;return r?t+r:""},Pt=(e,t,r,n,s,o=e)=>{if(!St.has(t)){const a={interpreter:ht(r,s),queue:_e(),XWorker:Ce(e,n)};St.set(t,a),St.has(e)||St.set(e,a),St.has(o)||St.set(o,a)}return St.get(t)},kt=async e=>{if(Et.has(e)){const{target:t}=e;t&&(e.closest("head")?document.body.append(t):e.after(t))}else{const{attributes:{async:t,config:r,env:n,target:s,version:o},src:a,type:i}=e,c=o?.value,l=wt(i,c);let u=At(r,"|");const f=At(n,"")||`${l}${u}`;u=u.slice(1);const p=He(e);if(p){const r=new(Ce(i,c))(p,{...Fe(e,i),async:!!t,config:u});return void Et.set(je(e,"xworker",{value:r}),{xworker:r})}const d=At(s,""),g=Pt(i,f,l,c,u);Et.set(je(e,"target",vt),g),d&&bt.set(e,mt(e,d));const y=a?fetch(a).then(Le):e.textContent;g.queue=g.queue.then((()=>(async(e,t,r,n)=>{const s=lt.get(e.type);s.experimental&&console.warn(`The ${e.type} interpreter is experimental`);const[o,a]=await Re([Et.get(e).interpreter,t]);try{return je(document,"currentScript",{configurable:!0,get:()=>e}),s.registerJSModule(o,"polyscript",{XWorker:r}),s[n?"runAsync":"run"](o,a)}finally{delete document.currentScript}})(e,y,g.XWorker,!!t)))}},$t=new Proxy(Me(null),{get:(e,t)=>Mt(t)}),Mt=async e=>{if(St.has(e)){const{interpreter:t,queue:r}=St.get(e);return(await Re([t,r]))[0]}const t=St.size?`Available interpreters are: ${[...St.keys()].map((e=>`"${e}"`)).join(", ")}.`:"There are no interpreters in this page.";throw new Error(`The interpreter "${e}" was not found. ${t}`)},xt=async e=>{const{type:r,currentTarget:n}=e;for(let{name:s,value:o,ownerElement:a}of t(`./@*[${pt.map((e=>`name()="${e}${r}"`)).join(" or ")}]`,n)){s=s.slice(0,-(r.length+1));const t=await Mt(a.getAttribute(`${s}-env`)||s);lt.get(s).runEvent(t,o,e)}},jt=e=>{for(let{name:r,ownerElement:n}of t(`.//@*[${pt.map((e=>`starts-with(name(),"${e}")`)).join(" or ")}]`,e))r=r.slice(r.lastIndexOf("-")+1),"env"!==r&&n.addEventListener(r,xt)},Tt=[],Rt=new Map,_t=new Map,Ot=e=>{for(const t of Tt)if(e.matches(t)){const r=Rt.get(t),{resolve:n}=_t.get(r),{options:s,known:o}=Wt.get(r);if(!o.has(e)){o.add(e);const{interpreter:t,config:a,version:i,env:c,onInterpreterReady:l}=s,u=He(e);if(u){const o=Lt.call(new Ne(null,s),u,{...Fe(e,r),version:i,type:t,custom:r,config:a||{},async:e.hasAttribute("async")});return je(e,"xworker",{value:o}),void n({type:r,xworker:o})}const f=wt(t,i),p=c||`${f}${a?`|${a}`:""}`,{interpreter:d,XWorker:g}=Pt(r,p,f,i,a,t);d.then((o=>{const a=Me(lt.get(t)),{onBeforeRun:i,onBeforeRunAsync:c,onAfterRun:u,onAfterRunAsync:p}=s,d=new Ne(o,s),y=function(...e){return g.apply(d,e)};for(const[t,[r,n]]of[["run",[i,u]]]){const s=a[t];a[t]=function(t,o,...a){r&&r.call(this,h,e);const i=s.call(this,t,o,...a);return n&&n.call(this,h,e),i}}for(const[t,[r,n]]of[["runAsync",[c,p]]]){const s=a[t];a[t]=async function(t,o,...a){r&&await r.call(this,h,e);const i=await s.call(this,t,o,...a);return n&&await n.call(this,h,e),i}}a.registerJSModule(o,"polyscript",{XWorker:y});const h={type:r,interpreter:o,XWorker:y,io:De.get(o),config:structuredClone(ut.get(f)),run:a.run.bind(a,o),runAsync:a.runAsync.bind(a,o),runEvent:a.runEvent.bind(a,o)};n(h),l?.(h,e)}))}}},Wt=new Map;let Ft=0;const Bt=(t,r)=>{let n=null==t;if(n)t="_ps"+Ft++;else if(lt.has(t)||Wt.has(t))throw new Error(`<script type="${t}"> already registered`);if(!lt.has(r?.interpreter))throw new Error("Unspecified interpreter");lt.set(t,lt.get(r.interpreter));const s=[`script[type="${t}"]`];if(It(t),n){const{onInterpreterReady:e}=r;r={...r,onInterpreterReady(r,n){Tt.splice(Tt.indexOf(t),1),lt.delete(t),Wt.delete(t),_t.delete(t),n.remove(),e?.(r)}},document.head.append($e(document.createElement("script"),{type:t}))}else s.push(`${t}-script`),pt.push(`${t}-`);for(const e of s)Rt.set(e,t);Tt.push(...s),Wt.set(t,{options:$e({env:t},r),known:new WeakSet}),n||jt(document),e(s.join(",")).forEach(Ot)},It=e=>(_t.has(e)||_t.set(e,Promise.withResolvers()),_t.get(e).promise),Lt=Ce(),Jt=ft.join(","),Nt=new MutationObserver((t=>{for(const{type:r,target:n,attributeName:s,addedNodes:o}of t)if("attributes"!==r){for(const t of o)if(1===t.nodeType)if(jt(t),t.matches(Jt))kt(t);else{if(e(Jt,t).forEach(kt),!Tt.length)continue;Ot(t),e(Tt.join(","),t).forEach(Ot)}}else{const e=s.lastIndexOf("-")+1;if(e){const t=s.slice(0,e);for(const r of pt)if(t===r){const t=s.slice(e);if("env"!==t){const e=n.hasAttribute(s)?"add":"remove";n[`${e}EventListener`](t,xt)}break}}}})),Ct=e=>(Nt.observe(e,{childList:!0,subtree:!0,attributes:!0}),e),{attachShadow:Ht}=Element.prototype;$e(Element.prototype,{attachShadow(e){return Ct(Ht.call(this,e))}}),jt(Ct(document)),e(Jt,document).forEach(kt);export{Lt as XWorker,Bt as define,$t as env,It as whenDefined}; |
@@ -1,2 +0,3 @@ | ||
import { clean, io } from './_utils.js'; | ||
import { dedent } from '../utils.js'; | ||
import { io } from './_utils.js'; | ||
@@ -11,3 +12,3 @@ // REQUIRES INTEGRATION TEST | ||
try { | ||
return interpreter.runPython(clean(code), ...args); | ||
return interpreter.runPython(dedent(code), ...args); | ||
} | ||
@@ -21,3 +22,3 @@ catch (error) { | ||
try { | ||
return await interpreter.runPythonAsync(clean(code), ...args); | ||
return await interpreter.runPythonAsync(dedent(code), ...args); | ||
} | ||
@@ -24,0 +25,0 @@ catch (error) { |
@@ -6,10 +6,2 @@ import '@ungap/with-resolvers'; | ||
/** | ||
* Trim code only if it's a single line that prettier or other tools might have modified. | ||
* @param {string} code code that might be a single line | ||
* @returns {string} | ||
*/ | ||
export const clean = (code) => | ||
code.replace(/^[^\r\n]+$/, (line) => line.trim()); | ||
// REQUIRES INTEGRATION TEST | ||
@@ -16,0 +8,0 @@ /* c8 ignore start */ |
@@ -1,2 +0,3 @@ | ||
import { clean, fetchPaths } from './_utils.js'; | ||
import { dedent } from '../utils.js'; | ||
import { fetchPaths } from './_utils.js'; | ||
@@ -34,4 +35,4 @@ const type = 'ruby-wasm-wasi'; | ||
}, | ||
run: (interpreter, code, ...args) => interpreter.eval(clean(code), ...args), | ||
runAsync: (interpreter, code, ...args) => interpreter.evalAsync(clean(code), ...args), | ||
run: (interpreter, code, ...args) => interpreter.eval(dedent(code), ...args), | ||
runAsync: (interpreter, code, ...args) => interpreter.evalAsync(dedent(code), ...args), | ||
async runEvent(interpreter, code, event) { | ||
@@ -38,0 +39,0 @@ // patch common xworker.onmessage/onerror cases |
@@ -1,2 +0,3 @@ | ||
import { clean, fetchPaths, io, stdio, writeFileShim } from './_utils.js'; | ||
import { dedent } from '../utils.js'; | ||
import { fetchPaths, io, stdio, writeFileShim } from './_utils.js'; | ||
@@ -30,3 +31,3 @@ const type = 'wasmoon'; | ||
try { | ||
return interpreter.doStringSync(clean(code), ...args); | ||
return interpreter.doStringSync(dedent(code), ...args); | ||
} | ||
@@ -39,3 +40,3 @@ catch (error) { | ||
try { | ||
return await interpreter.doString(clean(code), ...args); | ||
return await interpreter.doString(dedent(code), ...args); | ||
} | ||
@@ -42,0 +43,0 @@ catch (error) { |
@@ -0,1 +1,3 @@ | ||
import dedent from 'codedent'; | ||
const { isArray } = Array; | ||
@@ -20,2 +22,3 @@ | ||
export { | ||
dedent, | ||
isArray, | ||
@@ -22,0 +25,0 @@ assign, |
@@ -0,1 +1,3 @@ | ||
import { dedent } from '../utils.js'; | ||
// REQUIRES INTEGRATION TEST | ||
@@ -14,3 +16,4 @@ /* c8 ignore start */ | ||
this.onWorkerReady = options.onWorkerReady; | ||
for (const [key, value] of workerHooks) this[key] = options[value]?.(); | ||
for (const [key, value] of workerHooks) | ||
this[key] = options[value]?.(); | ||
} | ||
@@ -20,3 +23,3 @@ get stringHooks() { | ||
for (const [key] of workerHooks) { | ||
if (this[key]) hooks[key] = this[key]; | ||
if (this[key]) hooks[key] = dedent(this[key]); | ||
} | ||
@@ -23,0 +26,0 @@ return hooks; |
@@ -0,1 +1,3 @@ | ||
import { dedent } from '../utils.js'; | ||
/* c8 ignore start */ // tested via integration | ||
@@ -19,15 +21,3 @@ export default element => { | ||
// drop undesired indentation from the code | ||
for (const line of value.split(/[\r\n]+/)) { | ||
if (line.trim().length) { | ||
// if there's no indentation, avoid changing value | ||
if (/^(\s+)/.test(line)) { | ||
const trimStart = `^${RegExp.$1}`; | ||
value = value.replace(new RegExp(trimStart, 'gm'), ''); | ||
} | ||
break; | ||
} | ||
} | ||
const url = URL.createObjectURL(new Blob([value], { type: 'text/plain' })); | ||
const url = URL.createObjectURL(new Blob([dedent(value)], { type: 'text/plain' })); | ||
// TODO: should we really clean up this? debugging non-existent resources | ||
@@ -34,0 +24,0 @@ // at distance might be very problematic if the url is revoked. |
/* c8 ignore next */ | ||
export default () => 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=\"891249cd-eb53-4bc8-ae48-b0a5a277d24a\",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:w,Map:h,SharedArrayBuffer:m,Uint16Array:b}=globalThis,{BYTES_PER_ELEMENT:v}=w,{BYTES_PER_ELEMENT:S}=b,{isArray:P}=Array,{notify:A,wait:E,waitAsync:M}=Atomics,{fromCharCode:$}=String,j=(e,t)=>e?(M||y)(t,0):(E(t,0),{value:{then:e=>e()}}),T=new WeakSet,k=new WeakMap;let _=0;const x=(e,{parse:t,stringify:r,transform:n}=JSON)=>{if(!k.has(e)){const s=(t,...r)=>e.postMessage({[p]:r},{transfer:t});let o=!1;k.set(e,new Proxy(new h,{has:(e,t)=>\"string\"==typeof t&&!t.startsWith(\"_\"),get:(r,a)=>\"then\"===a?null:(...r)=>{const i=_++;let c=new w(new m(v)),l=[];T.has(r.at(-1)||l)&&T.delete(l=r.pop()),s(l,i,c,a,n?r.map(n):r);const u=e!==globalThis;let f=0;return o&&u&&(f=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${a}(...args) is awaited`)),j(u,c).value.then((()=>{clearTimeout(f);const e=c[0];if(!e)return;const r=S*e;return c=new w(new m(r+r%v)),s([],i,c),j(u,c).value.then((()=>t($(...new b(c.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new h;e.addEventListener(\"message\",(async e=>{const s=e.data?.[p];if(P(s)){e.stopImmediatePropagation();const[a,i,...c]=s;if(c.length){const[e,s]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);o=!0;try{const o=await t.get(e)(...s);if(void 0!==o){const e=r(o);n.set(a,e),i[0]=e.length}}finally{o=!1}}else{const e=n.get(a);n.delete(a);for(let t=new b(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}A(i,0)}}))}return!!t.set(n,s)}}))}return k.get(e)};x.transfer=(...e)=>(T.add(e),e);const O=\"object\",F=\"function\",W=\"number\",R=\"string\",B=\"undefined\",J=\"symbol\",{defineProperty:I,getOwnPropertyDescriptor:L,getPrototypeOf:C,isExtensible:H,ownKeys:D,preventExtensions:N,set:U,setPrototypeOf:z}=Reflect,{assign:q,create:K}=Object,Y=C(Int8Array),G=\"isArray\",V=(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},Q=(e,t)=>[e,t],X=e=>t=>{const r=typeof t;switch(r){case O:if(null==t)return Q(\"null\",t);if(t===globalThis)return Q(O,null);case F:return e(r,t);case\"boolean\":case W:case R:case B:case\"bigint\":return Q(r,t);case J:if(Z.has(t))return Q(r,Z.get(t))}throw new Error(`Unable to handle this ${r} type`)},Z=new Map(D(Symbol).filter((e=>typeof Symbol[e]===J)).map((e=>[Symbol[e],e]))),ee=e=>{for(const[t,r]of Z)if(r===e)return t};function te(){return this}const re=\"apply\",ne=\"construct\",se=\"defineProperty\",oe=\"deleteProperty\",ae=\"get\",ie=\"getOwnPropertyDescriptor\",ce=\"getPrototypeOf\",le=\"has\",ue=\"isExtensible\",fe=\"ownKeys\",pe=\"preventExtensions\",de=\"set\",ge=\"setPrototypeOf\",ye=\"delete\";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;I(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?q(K(globalThis),...a):globalThis,p=X(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return Q(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(ye,Q(R,e))})),g=([e,r])=>{switch(e){case O:if(null==r)return f;if(typeof r===W)return l.get(r);if(!(r instanceof Y))for(const e in r)r[e]=g(r[e]);return r;case F:if(typeof r===R){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(re,Q(F,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 J:return ee(r)}return r},y={[re]:(e,t,r)=>p(e.apply(t,r)),[ne]:(e,t)=>p(new e(...t)),[se]:(e,t,r)=>p(I(e,t,r)),[oe]:(e,t)=>p(delete e[t]),[ce]:e=>p(C(e)),[ae]:(e,t)=>p(e[t]),[ie]:(e,t)=>{const r=L(e,t);return r?Q(O,V(r,p)):Q(B,r)},[le]:(e,t)=>p(t in e),[ue]:e=>p(H(e)),[fe]:e=>Q(O,D(e).map(p)),[pe]:e=>p(N(e)),[de]:(e,t,r)=>p(U(e,t,r)),[ge]:(e,t)=>p(z(e,t)),[ye](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case re:r[0]=g(r[0]),r[1]=r[1].map(g);break;case ne:r[0]=r[0].map(g);break;case se:{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),he=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===F?e():e,a=e=>typeof e===O&&!!e&&s in e,i=Array[G],c=X(((e,a)=>{if(s in a)return o(a[s]);if(e===F){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return Q(e,r.get(a))}if(!(a instanceof Y))for(const e in a)a[e]=c(a[e]);return Q(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(ye,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===F?te.bind(e):e,s=new Proxy(n,h),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 O:return null===r?globalThis:typeof r===W?g(e):r;case F:return typeof r===R?n.get(r):g(e);case J:return ee(r)}return r},w=(e,t,...r)=>y(f(e,o(t),...r)),h={[re]:(e,t,r)=>w(re,e,c(t),r.map(c)),[ne]:(e,t)=>w(ne,e,t.map(c)),[se]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===F&&(r.get=c(n)),typeof s===F&&(r.set=c(s)),typeof o===F&&(r.value=c(o)),w(se,e,c(t),r)},[oe]:(e,t)=>w(oe,e,c(t)),[ce]:e=>w(ce,e),[ae]:(e,t)=>t===s?e:w(ae,e,c(t)),[ie]:(e,t)=>{const r=w(ie,e,c(t));return r&&V(r,y)},[le]:(e,t)=>t===s||w(le,e,c(t)),[ue]:e=>w(ue,e),[fe]:e=>w(fe,e).map(y),[pe]:e=>w(pe,e),[de]:(e,t,r)=>w(de,e,c(t),c(r)),[ge]:(e,t)=>w(ge,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case re:return y(t).apply(y(s),o.map(y));case ye:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([O,null],h),b=m.Array[G];return I(Array,G,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})(\"Window\"),me=\"function\"==typeof Worker?Worker:class{};const be=new WeakMap,ve=(e,...t)=>{const r=x(e,...t);if(!be.has(r)){const t=e instanceof me?we:he;be.set(r,t(r,d,g))}return be.get(r)};ve.transfer=x.transfer;const{isArray:Se}=Array,{assign:Pe,create:Ae,defineProperties:Ee,defineProperty:Me,entries:$e}=Object,{all:je,resolve:Te}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),ke=(e,t=location.href)=>new URL(e,t).href;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 _e=e=>e.arrayBuffer(),xe=e=>e.json(),Oe=e=>e.text(),Fe=e=>e.replace(/^[^\\r\\n]+$/,(e=>e.trim())),We=new WeakMap,Re=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 We.set(t,r),t}}},Be=({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})},Je=e=>{const t=e.split(\"/\");return t.pop(),t.join(\"/\")},Ie=(e,t)=>{const r=[];for(const n of t.split(\"/\"))\".\"!==n&&(r.push(n),n&&e.mkdir(r.join(\"/\")))},Le=(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(/^\\/+/,\"/\")},Ce=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,\"\"))).filter((e=>\"\"!==e&&\".\"!==e)).join(\"/\");return e[0].startsWith(\"/\")?`/${t}`:t},He=new WeakMap,De=(e,t,r)=>je((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(Se(n))return n.map((r=>({url:Ce([e,r]),path:Ce([t,r])})));const s=r||e.slice(1+e.lastIndexOf(\"/\"));return[{url:e,path:Ce([t,s])}]}))})(r).map((({url:n,path:s})=>((e,t)=>fetch(ke(t,He.get(e))))(r,n).then(_e).then((r=>e.writeFile(t,s,r)))))),Ne=(e,t,r)=>{e.registerJsModule(t,r)},Ue=(e,t,...r)=>{try{return e.runPython(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},ze=async(e,t,...r)=>{try{return await e.runPythonAsync(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},qe=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){We.get(e).stderr(t)}};var Ke={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}=Re();r=r.replace(/\\.m?js$/,\".wasm\");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await De(this,a,t.fetch),a},registerJSModule:Ne,run:Ue,runAsync:ze,runEvent:qe,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Be({FS:e,PATH:t,PATH_FS:r},n,s)};const Ye={dict_converter:Object.fromEntries};var Ge={type:\"pyodide\",module:(e=\"0.23.4\")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Re(),a=r.slice(0,r.lastIndexOf(\"/\")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await De(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:Ne,run:Ue,runAsync:ze,runEvent:qe,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(Ye):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Be({FS:e,PATH:t,PATH_FS:r},n,s)};const Ve=\"ruby-wasm-wasi\",Qe=Ve.replace(/\\W+/g,\"_\");var Xe={type:Ve,experimental:!0,module:(e=\"2.0.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.fetch&&await De(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${Qe}_${t}`;globalThis[n]=r,this.run(e,`require \"js\";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval(Fe(t),...r),runAsync:(e,t,...r)=>e.evalAsync(Fe(t),...r),async runEvent(e,t,r){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${Qe}_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 ${Ve}`)}};var Ze={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}=Re(),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.fetch&&await De(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync(Fe(t),...r)}catch(t){We.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Fe(t),...r)}catch(t){We.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){We.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Ie(e,Je(t)),t=Le(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const et=new Map,tt=new Map,rt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split(\"@\"),s=et.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=>{tt.set(t,e);const a=e?.fetch;return a&&He.set(a,o),s(n,e,r)}))}}),nt=e=>{for(const t of[].concat(e.type))et.set(t,e)};for(const e of[Ke,Ge,Xe,Ze])nt(e);const st=async e=>(await import(\"https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js\")).parse(e);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 ot,at,it;const ct=(e,t)=>{addEventListener(e,t||(async t=>{try{await ot,at(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:lt,stringify:ut}=f,{proxy:ft,window:pt,isWindowProxy:dt}=ve(self,{parse:lt,stringify:ut,transform:e=>it?it(e):e}),gt={sync:ft,window:pt,isWindowProxy:dt,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};ct(\"message\",(({data:{options:e,config:t,code:r,hooks:n}})=>{ot=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await((e,t,r={})=>{if(t)if(t.endsWith(\".json\"))r=fetch(t).then(xe),t=ke(t);else if(t.endsWith(\".toml\"))r=fetch(t).then(Oe).then(st),t=ke(t);else if(!t.endsWith(\".txt\")){try{r=JSON.parse(t)}catch(e){r=st(t)}t=ke(\"./config.txt\")}return Te(r).then((r=>rt[e](r,t)))})(((e,t=\"\")=>`${e}@${t}`.replace(/@$/,\"\"))(a,c),t,l),p=Ae(et.get(a)),d=\"run\"+(u?\"Async\":\"\");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=r||s,a=e||t;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)}}let g=\"\";return p.registerJSModule(f,\"polyscript\",{xworker:gt,get target(){if(!g){const{document:e}=gt.window,t=e.getElementById(s);\"SCRIPT\"===o?t.after(Pe(e.createElement(`script-${i||a}`),{id:g=`${s}-target`})):(g=s,t.replaceChildren(),t.style.display=\"block\")}return g}}),at=p.runEvent.bind(p,f),it=p.transform.bind(p,f),await p[d](f,r),f}catch(e){postMessage(e)}})(),ct(\"error\"),ct(\"message\"),ct(\"messageerror\")}));\n"],{type:'application/javascript'})),{type:'module'}); | ||
export default () => 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=\"891249cd-eb53-4bc8-ae48-b0a5a277d24a\",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:w,Map:h,SharedArrayBuffer:m,Uint16Array:b}=globalThis,{BYTES_PER_ELEMENT:v}=w,{BYTES_PER_ELEMENT:S}=b,{isArray:P}=Array,{notify:E,wait:A,waitAsync:M}=Atomics,{fromCharCode:$}=String,j=(e,t)=>e?(M||y)(t,0):(A(t,0),{value:{then:e=>e()}}),k=new WeakSet,x=new WeakMap;let T=0;const _=(e,{parse:t,stringify:r,transform:n}=JSON)=>{if(!x.has(e)){const s=(t,...r)=>e.postMessage({[p]:r},{transfer:t});let o=!1;x.set(e,new Proxy(new h,{has:(e,t)=>\"string\"==typeof t&&!t.startsWith(\"_\"),get:(r,a)=>\"then\"===a?null:(...r)=>{const i=T++;let c=new w(new m(v)),l=[];k.has(r.at(-1)||l)&&k.delete(l=r.pop()),s(l,i,c,a,n?r.map(n):r);const u=e!==globalThis;let f=0;return o&&u&&(f=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${a}(...args) is awaited`)),j(u,c).value.then((()=>{clearTimeout(f);const e=c[0];if(!e)return;const r=S*e;return c=new w(new m(r+r%v)),s([],i,c),j(u,c).value.then((()=>t($(...new b(c.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new h;e.addEventListener(\"message\",(async e=>{const s=e.data?.[p];if(P(s)){e.stopImmediatePropagation();const[a,i,...c]=s;if(c.length){const[e,s]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);o=!0;try{const o=await t.get(e)(...s);if(void 0!==o){const e=r(o);n.set(a,e),i[0]=e.length}}finally{o=!1}}else{const e=n.get(a);n.delete(a);for(let t=new b(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}E(i,0)}}))}return!!t.set(n,s)}}))}return x.get(e)};_.transfer=(...e)=>(k.add(e),e);const O=\"object\",F=\"function\",W=\"number\",R=\"string\",B=\"undefined\",J=\"symbol\",{defineProperty:I,getOwnPropertyDescriptor:L,getPrototypeOf:C,isExtensible:H,ownKeys:D,preventExtensions:N,set:U,setPrototypeOf:z}=Reflect,{assign:q,create:K}=Object,Y=C(Int8Array),G=\"isArray\",V=(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},Q=(e,t)=>[e,t],X=e=>t=>{const r=typeof t;switch(r){case O:if(null==t)return Q(\"null\",t);if(t===globalThis)return Q(O,null);case F:return e(r,t);case\"boolean\":case W:case R:case B:case\"bigint\":return Q(r,t);case J:if(Z.has(t))return Q(r,Z.get(t))}throw new Error(`Unable to handle this ${r} type`)},Z=new Map(D(Symbol).filter((e=>typeof Symbol[e]===J)).map((e=>[Symbol[e],e]))),ee=e=>{for(const[t,r]of Z)if(r===e)return t};function te(){return this}const re=\"apply\",ne=\"construct\",se=\"defineProperty\",oe=\"deleteProperty\",ae=\"get\",ie=\"getOwnPropertyDescriptor\",ce=\"getPrototypeOf\",le=\"has\",ue=\"isExtensible\",fe=\"ownKeys\",pe=\"preventExtensions\",de=\"set\",ge=\"setPrototypeOf\",ye=\"delete\";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;I(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?q(K(globalThis),...a):globalThis,p=X(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return Q(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(ye,Q(R,e))})),g=([e,r])=>{switch(e){case O:if(null==r)return f;if(typeof r===W)return l.get(r);if(!(r instanceof Y))for(const e in r)r[e]=g(r[e]);return r;case F:if(typeof r===R){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(re,Q(F,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 J:return ee(r)}return r},y={[re]:(e,t,r)=>p(e.apply(t,r)),[ne]:(e,t)=>p(new e(...t)),[se]:(e,t,r)=>p(I(e,t,r)),[oe]:(e,t)=>p(delete e[t]),[ce]:e=>p(C(e)),[ae]:(e,t)=>p(e[t]),[ie]:(e,t)=>{const r=L(e,t);return r?Q(O,V(r,p)):Q(B,r)},[le]:(e,t)=>p(t in e),[ue]:e=>p(H(e)),[fe]:e=>Q(O,D(e).map(p)),[pe]:e=>p(N(e)),[de]:(e,t,r)=>p(U(e,t,r)),[ge]:(e,t)=>p(z(e,t)),[ye](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case re:r[0]=g(r[0]),r[1]=r[1].map(g);break;case ne:r[0]=r[0].map(g);break;case se:{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),he=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===F?e():e,a=e=>typeof e===O&&!!e&&s in e,i=Array[G],c=X(((e,a)=>{if(s in a)return o(a[s]);if(e===F){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return Q(e,r.get(a))}if(!(a instanceof Y))for(const e in a)a[e]=c(a[e]);return Q(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(ye,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===F?te.bind(e):e,s=new Proxy(n,h),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 O:return null===r?globalThis:typeof r===W?g(e):r;case F:return typeof r===R?n.get(r):g(e);case J:return ee(r)}return r},w=(e,t,...r)=>y(f(e,o(t),...r)),h={[re]:(e,t,r)=>w(re,e,c(t),r.map(c)),[ne]:(e,t)=>w(ne,e,t.map(c)),[se]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===F&&(r.get=c(n)),typeof s===F&&(r.set=c(s)),typeof o===F&&(r.value=c(o)),w(se,e,c(t),r)},[oe]:(e,t)=>w(oe,e,c(t)),[ce]:e=>w(ce,e),[ae]:(e,t)=>t===s?e:w(ae,e,c(t)),[ie]:(e,t)=>{const r=w(ie,e,c(t));return r&&V(r,y)},[le]:(e,t)=>t===s||w(le,e,c(t)),[ue]:e=>w(ue,e),[fe]:e=>w(fe,e).map(y),[pe]:e=>w(pe,e),[de]:(e,t,r)=>w(de,e,c(t),c(r)),[ge]:(e,t)=>w(ge,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case re:return y(t).apply(y(s),o.map(y));case ye:{const e=y(t);r.delete(n.get(e)),n.delete(e)}}};const m=new Proxy([O,null],h),b=m.Array[G];return I(Array,G,{value:e=>a(e)?b(e):i(e)}),{[e.toLowerCase()]:m,[`is${e}Proxy`]:a,proxy:t}}})(\"Window\"),me=\"function\"==typeof Worker?Worker:class{};const be=new WeakMap,ve=(e,...t)=>{const r=_(e,...t);if(!be.has(r)){const t=e instanceof me?we:he;be.set(r,t(r,d,g))}return be.get(r)};ve.transfer=_.transfer;const Se={object(...e){return this.string(function(e){for(var t=e[0],r=1,n=arguments.length;r<n;r++)t+=arguments[r]+e[r];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}},Pe=(e,...t)=>Se[typeof e](e,...t),{isArray:Ee}=Array,{assign:Ae,create:Me,defineProperties:$e,defineProperty:je,entries:ke}=Object,{all:xe,resolve:Te}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),_e=(e,t=location.href)=>new URL(e,t).href;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 Oe=e=>e.arrayBuffer(),Fe=e=>e.json(),We=e=>e.text(),Re=new WeakMap,Be=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 Re.set(t,r),t}}},Je=({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})},Ie=e=>{const t=e.split(\"/\");return t.pop(),t.join(\"/\")},Le=(e,t)=>{const r=[];for(const n of t.split(\"/\"))\".\"!==n&&(r.push(n),n&&e.mkdir(r.join(\"/\")))},Ce=(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},De=new WeakMap,Ne=(e,t,r)=>xe((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(Ee(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})=>((e,t)=>fetch(_e(t,De.get(e))))(r,n).then(Oe).then((r=>e.writeFile(t,s,r)))))),Ue=(e,t,r)=>{e.registerJsModule(t,r)},ze=(e,t,...r)=>{try{return e.runPython(Pe(t),...r)}catch(t){Re.get(e).stderr(t)}},qe=async(e,t,...r)=>{try{return await e.runPythonAsync(Pe(t),...r)}catch(t){Re.get(e).stderr(t)}},Ke=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){Re.get(e).stderr(t)}};var Ye={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}=Be();r=r.replace(/\\.m?js$/,\".wasm\");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await Ne(this,a,t.fetch),a},registerJSModule:Ue,run:ze,runAsync:qe,runEvent:Ke,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Je({FS:e,PATH:t,PATH_FS:r},n,s)};const Ge={dict_converter:Object.fromEntries};var Ve={type:\"pyodide\",module:(e=\"0.23.4\")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Be(),a=r.slice(0,r.lastIndexOf(\"/\")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await Ne(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:Ue,run:ze,runAsync:qe,runEvent:Ke,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(Ge):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Je({FS:e,PATH:t,PATH_FS:r},n,s)};const Qe=\"ruby-wasm-wasi\",Xe=Qe.replace(/\\W+/g,\"_\");var Ze={type:Qe,experimental:!0,module:(e=\"2.0.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.fetch&&await Ne(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${Xe}_${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_${Xe}_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 ${Qe}`)}};var et={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}=Be(),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.fetch&&await Ne(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){Re.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Pe(t),...r)}catch(t){Re.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){Re.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Le(e,Ie(t)),t=Ce(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const tt=new Map,rt=new Map,nt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split(\"@\"),s=tt.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=>{rt.set(t,e);const a=e?.fetch;return a&&De.set(a,o),s(n,e,r)}))}}),st=e=>{for(const t of[].concat(e.type))tt.set(t,e)};for(const e of[Ye,Ve,Ze,et])st(e);const ot=async e=>(await import(\"https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js\")).parse(e);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 at,it,ct;const lt=(e,t)=>{addEventListener(e,t||(async t=>{try{await at,it(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:ut,stringify:ft}=f,{proxy:pt,window:dt,isWindowProxy:gt}=ve(self,{parse:ut,stringify:ft,transform:e=>ct?ct(e):e}),yt={sync:pt,window:dt,isWindowProxy:gt,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};lt(\"message\",(({data:{options:e,config:t,code:r,hooks:n}})=>{at=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await((e,t,r={})=>{if(t)if(t.endsWith(\".json\"))r=fetch(t).then(Fe),t=_e(t);else if(t.endsWith(\".toml\"))r=fetch(t).then(We).then(ot),t=_e(t);else if(!t.endsWith(\".txt\")){try{r=JSON.parse(t)}catch(e){r=ot(t)}t=_e(\"./config.txt\")}return Te(r).then((r=>nt[e](r,t)))})(((e,t=\"\")=>`${e}@${t}`.replace(/@$/,\"\"))(a,c),t,l),p=Me(tt.get(a)),d=\"run\"+(u?\"Async\":\"\");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=r||s,a=e||t;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)}}let g=\"\";return p.registerJSModule(f,\"polyscript\",{xworker:yt,get target(){if(!g){const{document:e}=yt.window,t=e.getElementById(s);\"SCRIPT\"===o?t.after(Ae(e.createElement(`script-${i||a}`),{id:g=`${s}-target`})):(g=s,t.replaceChildren(),t.style.display=\"block\")}return g}}),it=p.runEvent.bind(p,f),ct=p.transform.bind(p,f),await p[d](f,r),f}catch(e){postMessage(e)}})(),lt(\"error\"),lt(\"message\"),lt(\"messageerror\")}));\n"],{type:'application/javascript'})),{type:'module'}); |
{ | ||
"name": "polyscript", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "PyScript single core to rule them all", | ||
@@ -67,7 +67,8 @@ "main": "./cjs/index.js", | ||
"basic-devtools": "^0.1.6", | ||
"codedent": "^0.1.2", | ||
"coincident": "^0.11.5" | ||
}, | ||
"worker": { | ||
"blob": "sha256-1X+YHJpNeSE5LhTGk2vnw6J6pbxvv3zB4rdm4R5mScY=" | ||
"blob": "sha256-UO6bcRvj08x37gUDrrhWmjeYu/fNhGH/knnauODsieg=" | ||
} | ||
} |
# Polyscript | ||
[![build](https://github.com/pyscript/polyscript/actions/workflows/node.js.yml/badge.svg)](https://github.com/pyscript/polyscript/actions/workflows/node.js.yml) | ||
<sup>**[PyScript](https://github.com/pyscript/pyscript) single core to rule them all**</sup> | ||
@@ -4,0 +6,0 @@ |
@@ -1,2 +0,1 @@ | ||
export function clean(code: string): string; | ||
export const io: WeakMap<object, any>; | ||
@@ -3,0 +2,0 @@ export function stdio(init: any): { |
@@ -34,1 +34,2 @@ export const isArray: (arg: any) => arg is any[]; | ||
}; | ||
export { dedent }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
224758
95
5
2752
6
85
+ Addedcodedent@^0.1.2
+ Addedcodedent@0.1.2(transitive)
+ Addedplain-tag@0.1.3(transitive)