polyscript
Advanced tools
Comparing version 0.4.14 to 0.4.15
'use strict'; | ||
const stickyModule = (m => /* c8 ignore start */ m.__esModule ? m.default : m /* c8 ignore stop */)(require('sticky-module')); | ||
const { $$ } = require('basic-devtools'); | ||
const { handle } = require('./script-handler.js'); | ||
const { assign, defineProperty } = require('./utils.js'); | ||
const { assign } = require('./utils.js'); | ||
const { selectors, prefixes } = require('./interpreters.js'); | ||
@@ -15,25 +16,22 @@ const { CUSTOM_SELECTORS, handleCustomType } = require('./custom.js'); | ||
const polyscript = Symbol.for('polyscript'); | ||
const alreadyLive = polyscript in globalThis; | ||
// avoid multiple initialization of the same library | ||
/* c8 ignore start */ | ||
const { define, whenDefined, env, Hook, XWorker } = ( | ||
alreadyLive ? | ||
globalThis[polyscript] : | ||
defineProperty( | ||
globalThis, | ||
polyscript, | ||
{ | ||
value: { | ||
define: $define, | ||
whenDefined: $whenDefined, | ||
env: $env, | ||
Hook: $Hook, | ||
XWorker: $XWorker | ||
} | ||
} | ||
)[polyscript] | ||
const [ | ||
{ | ||
define, | ||
whenDefined, | ||
env, | ||
Hook, | ||
XWorker | ||
}, | ||
alreadyLive | ||
] = stickyModule( | ||
'polyscript', | ||
{ | ||
define: $define, | ||
whenDefined: $whenDefined, | ||
env: $env, | ||
Hook: $Hook, | ||
XWorker: $XWorker | ||
} | ||
); | ||
/* c8 ignore stop */ | ||
@@ -40,0 +38,0 @@ exports.define = define; |
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 h="8db0a6b1-4d79-4ecd-8b7a-7ea5c1811764",g="M"+h,y="T"+h,w="object",m="function",b="number",v="string",S="undefined",E="symbol";var $=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:A,Map:k,SharedArrayBuffer:P,Uint16Array:x}=globalThis,{BYTES_PER_ELEMENT:M}=A,{BYTES_PER_ELEMENT:j}=x,{isArray:T}=Array,{notify:R,wait:_,waitAsync:O}=Atomics,{fromCharCode:W}=String,F=new WeakSet,I=new WeakMap,B={value:{then:e=>e()}},L=()=>{};let J=0;const C=(e,{parse:t=JSON.parse,stringify:r=JSON.stringify,transform:n,interrupt:s}=JSON)=>{if(!I.has(e)){const o=(t,...r)=>e.postMessage({[h]:r},{transfer:t}),a=typeof s===m?s:s?.handler||L,i=s?.delay||42,c=(e,t)=>e?(O||$)(t,0):(((e,t,r)=>{for(;"timed-out"===_(e,0,0,t);)r()})(t,i,a),B);let l=!1;I.set(e,new Proxy(new k,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,s)=>"then"===s?null:(...r)=>{const a=J++;let i=new A(new P(M)),u=[];F.has(r.at(-1)||u)&&F.delete(u=r.pop()),o(u,a,i,s,n?r.map(n):r);const f=e!==globalThis;let p=0;return l&&f&&(p=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),c(f,i).value.then((()=>{clearTimeout(p);const e=i[0];if(e<0)return;const r=j*e;return i=new A(new P(r+r%M)),o([],a,i),c(f,i).value.then((()=>t(W(...new x(i.buffer).slice(0,e)))))}))},set(t,s,o){const a=typeof o;if(a!==m)throw new Error(`Unable to assign ${s} as ${a}`);if(!t.size){const s=new k;e.addEventListener("message",(async e=>{const o=e.data?.[h];if(T(o)){e.stopImmediatePropagation();const[a,i,...c]=o;if(c.length){const[e,o]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);l=!0;try{const c=await t.get(e)(...o);if(void 0===c)i[0]=-1;else{const e=r(n?n(c):c);s.set(a,e),i[0]=e.length}}finally{l=!1}}else{const e=s.get(a);s.delete(a);for(let t=new x(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}R(i,0)}}))}return!!t.set(s,o)}}))}return I.get(e)};C.transfer=(...e)=>(F.add(e),e);const{defineProperty:H,getOwnPropertyDescriptor:N,getPrototypeOf:D,isExtensible:U,ownKeys:X,preventExtensions:q,set:z,setPrototypeOf:Y}=Reflect,{assign:G,create:V}=Object,K=D(Int8Array),Q="isArray",Z=(e,t)=>{const{get:r,set:n,value:s}=e;return r&&(e.get=t(r)),n&&(e.set=t(n)),s&&(e.value=t(s)),e},ee=(e,t)=>[e,t],te=e=>t=>{const r=typeof t;switch(r){case w:if(null==t)return ee("null",t);if(t===globalThis)return ee(w,null);case m:return e(r,t);case"boolean":case b:case v:case S:case"bigint":return ee(r,t);case E:if(re.has(t))return ee(r,re.get(t))}throw new Error(`Unable to handle this ${r} type`)},re=new Map(X(Symbol).filter((e=>typeof Symbol[e]===E)).map((e=>[Symbol[e],e]))),ne=e=>{for(const[t,r]of re)if(r===e)return t};function se(){return this}const oe="apply",ae="construct",ie="defineProperty",ce="deleteProperty",le="get",ue="getOwnPropertyDescriptor",fe="getPrototypeOf",pe="has",de="isExtensible",he="ownKeys",ge="preventExtensions",ye="set",we="setPrototypeOf",me="delete";var be=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;H(EventTarget.prototype,"addEventListener",{value(t,n,...s){return s.at(0)?.invoke&&(r.has(this)||r.set(this,new Map),r.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,n,...s)}})}const n=t&&(e=>{const{currentTarget:t,target:n,type:s}=e;for(const o of r.get(t||n)?.get(s)||[])e[o]()});return(r,s,o,...a)=>{let i=0;const c=new Map,l=new Map,{[o]:u}=r,f=a.length?G(V(globalThis),...a):globalThis,p=te(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return ee(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(me,ee(v,e))})),h=([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]=h(r[e]);return r;case m:if(typeof r===v){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(oe,ee(m,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 E:return ne(r)}return r},g={[oe]:(e,t,r)=>p(e.apply(t,r)),[ae]:(e,t)=>p(new e(...t)),[ie]:(e,t,r)=>p(H(e,t,r)),[ce]:(e,t)=>p(delete e[t]),[fe]:e=>p(D(e)),[le]:(e,t)=>p(e[t]),[ue]:(e,t)=>{const r=N(e,t);return r?ee(w,Z(r,p)):ee(S,r)},[pe]:(e,t)=>p(t in e),[de]:e=>p(U(e)),[he]:e=>ee(w,X(e).map(p)),[ge]:e=>p(q(e)),[ye]:(e,t,r)=>p(z(e,t,r)),[we]:(e,t)=>p(Y(e,t)),[me](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case oe:r[0]=h(r[0]),r[1]=r[1].map(h);break;case ae:r[0]=r[0].map(h);break;case ie:{const[e,t]=r;r[0]=h(e);const{get:n,set:s,value:o}=t;n&&(t.get=h(n)),s&&(t.set=h(s)),o&&(t.value=h(o));break}default:r=r.map(h)}return g[e](h(t),...r)},{proxy:r,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window",!0),ve=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===m?e():e,a=e=>typeof e===w&&!!e&&s in e,i=Array[Q],c=te(((e,a)=>{if(s in a)return o(a[s]);if(e===m){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return ee(e,r.get(a))}if(!(a instanceof K))for(const e in a)a[e]=c(a[e]);return ee(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(me,c(e))})),h=e=>{const[t,r]=e;if(!p.has(r)){const n=t===m?se.bind(e):e,s=new Proxy(n,S),o=new WeakRef(s);p.set(r,o),d.register(s,r,o)}return p.get(r).deref()},g=e=>{const[t,r]=e;switch(t){case w:return null===r?globalThis:typeof r===b?h(e):r;case m:return typeof r===v?n.get(r):h(e);case E:return ne(r)}return r},y=(e,t,...r)=>g(f(e,o(t),...r)),S={[oe]:(e,t,r)=>y(oe,e,c(t),r.map(c)),[ae]:(e,t)=>y(ae,e,t.map(c)),[ie]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===m&&(r.get=c(n)),typeof s===m&&(r.set=c(s)),typeof o===m&&(r.value=c(o)),y(ie,e,c(t),r)},[ce]:(e,t)=>y(ce,e,c(t)),[fe]:e=>y(fe,e),[le]:(e,t)=>t===s?e:y(le,e,c(t)),[ue]:(e,t)=>{const r=y(ue,e,c(t));return r&&Z(r,g)},[pe]:(e,t)=>t===s||y(pe,e,c(t)),[de]:e=>y(de,e),[he]:e=>y(he,e).map(g),[ge]:e=>y(ge,e),[ye]:(e,t,r)=>y(ye,e,c(t),c(r)),[we]:(e,t)=>y(we,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case oe:return g(t).apply(g(s),o.map(g));case me:{const e=g(t);r.delete(n.get(e)),n.delete(e)}}};const $=new Proxy([w,null],S),A=$.Array[Q];return H(Array,Q,{value:e=>a(e)?A(e):i(e)}),{[e.toLowerCase()]:$,[`is${e}Proxy`]:a,proxy:t}}})("Window"),Se=typeof Worker===m?Worker:class{};const Ee=new WeakMap,$e=(e,...t)=>{const r=C(e,...t);if(!Ee.has(r)){const t=e instanceof Se?be:ve;Ee.set(r,t(r,g,y))}return Ee.get(r)};$e.transfer=C.transfer;Promise.withResolvers||(Promise.withResolvers=function(){var e,t,r=new this((function(r,n){e=r,t=n}));return{resolve:e,reject:t,promise:r}});const Ae=e=>e.arrayBuffer(),ke=e=>e.json(),Pe=e=>e.text();const xe={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}},Me=(e,...t)=>xe[typeof e](e,...t),{replace:je}="",Te=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,Re={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'},_e=e=>Re[e],{isArray:Oe}=Array,{assign:We,create:Fe,defineProperties:Ie,defineProperty:Be,entries:Le}=Object,{all:Je,resolve:Ce}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),He=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href;let Ne=0;const De=(e,t)=>({id:e.id||(e.id=`${t}-w${Ne++}`),tag:e.tagName}),Ue=(e,t,r,n=!1,s=CustomEvent)=>{e.dispatchEvent(new s(`${t}:${r}`,{bubbles:!0,detail:{worker:n}}))},Xe=new WeakMap,qe=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 Xe.set(t,r),t}}},ze=({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})},Ye=e=>{const t=e.split("/");return t.pop(),t.join("/")},Ge=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Ve=(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(/^\/+/,"/")},Ke=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Qe=(e,t)=>fetch(He(t,Ze.get(e))),Ze=new WeakMap,et=(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(Oe(n))return n.map((r=>({url:Ke([e,r]),path:Ke([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:Ke([t,s])}]}))})(r).map((({url:n,path:s})=>Qe(r,n).then(Ae).then((r=>e.writeFile(t,s,r)))))),tt=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,rt=(e,t)=>e.replace(/\{.+?\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),nt=(e,t,r)=>Je((e=>{const t=new Map,r=new Set,n=[];for(const[s,o]of Object.entries(e))if(/^\{.+\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,rt(o,t))}else{const e=rt(s,t),a=tt(e,rt(o||"./",t));if(r.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);r.add(a),n.push({url:e,path:a})}return n})(r).map((({url:n,path:s})=>Qe(r,n).then(Ae).then((r=>e.writeFile(t,s,r)))))),st=(e,t,r)=>{e.registerJsModule(t,r)},ot=(e,t,...r)=>{try{return e.runPython(Me(t),...r)}catch(t){Xe.get(e).stderr(t)}},at=async(e,t,...r)=>{try{return await e.runPythonAsync(Me(t),...r)}catch(t){Xe.get(e).stderr(t)}},it=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){Xe.get(e).stderr(t)}};var ct={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}=qe();r=r.replace(/\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.files&&await nt(this,a,t.files),t.fetch&&await et(this,a,t.fetch),a},registerJSModule:st,run:ot,runAsync:at,runEvent:it,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>ze({FS:e,PATH:t,PATH_FS:r},n,s)};const lt={dict_converter:Object.fromEntries};var ut={type:"pyodide",module:(e="0.24.1")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=qe(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.files&&await nt(this,i,t.files),t.fetch&&await et(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:st,run:ot,runAsync:at,runEvent:it,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(lt):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>ze({FS:e,PATH:t,PATH_FS:r},n,s)};const ft="ruby-wasm-wasi",pt=ft.replace(/\W+/g,"_");var dt={type:ft,experimental:!0,module:(e="2.1.0")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,r){const n=await fetch(`${r.slice(0,r.lastIndexOf("/"))}/ruby.wasm`),s=await WebAssembly.compile(await n.arrayBuffer()),{vm:o}=await e(s);return t.files&&await nt(this,o,t.files),t.fetch&&await et(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${pt}_${t}`;globalThis[n]=r,this.run(e,`require "js";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval(Me(t),...r),runAsync:(e,t,...r)=>e.evalAsync(Me(t),...r),async runEvent(e,t,r){if(/^xworker\.(on\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${pt}_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 ${ft}`)}};var ht={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}=qe(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",n)})),r.files&&await nt(this,a,r.files),r.fetch&&await et(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync(Me(t),...r)}catch(t){Xe.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Me(t),...r)}catch(t){Xe.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){Xe.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Ge(e,Ye(t)),t=Ve(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const gt=new Map,yt=new Map,wt=[],mt=[],bt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=gt.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=>{yt.set(t,e);for(const t of["files","fetch"]){const r=e?.[t];r&&Ze.set(r,o)}return s(n,e,r)}))}}),vt=e=>{for(const t of[].concat(e.type))gt.set(t,e),wt.push(`script[type="${t}"]`),mt.push(`${t}-`)};for(const e of[ct,ut,dt,ht])vt(e);const St=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),Et=e=>{let t=typeof e;return"string"===t&&/\.(json|toml|txt)$/.test(e)?t=RegExp.$1:e="./config.txt",[He(e),t]},$t=(e,t,r={})=>{if(t){const[e,n]=Et(t);if("json"===n)r=fetch(e).then(ke);else if("toml"===n)r=fetch(e).then(Pe).then(St);else if("string"===n)try{r=JSON.parse(t)}catch(e){r=St(t)}else"object"===n&&t&&(r=t);t=e}return Ce(r).then((r=>bt[e](r,t)))},At=(e,t="")=>`${e}@${t}`.replace(/@$/,""),kt=[["beforeRun","codeBeforeRunWorker"],["beforeRunAsync","codeBeforeRunWorkerAsync"],["afterRun","codeAfterRunWorker"],["afterRunAsync","codeAfterRunWorkerAsync"]];let Pt=class{constructor(e,t){this.interpreter=e,this.onWorkerReady=t.onWorkerReady;for(const[e,r]of kt)this[e]=t[r]}get stringHooks(){const e={};for(const[t]of kt)this[t]&&(e[t]=Me(this[t]()));return e}};var xt=(...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="8db0a6b1-4d79-4ecd-8b7a-7ea5c1811764",d="M"+p,g="T"+p,y="object",h="function",w="number",m="string",b="undefined",v="symbol";var S=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:E,Map:$,SharedArrayBuffer:P,Uint16Array:A}=globalThis,{BYTES_PER_ELEMENT:M}=E,{BYTES_PER_ELEMENT:j}=A,{isArray:x}=Array,{notify:k,wait:T,waitAsync:_}=Atomics,{fromCharCode:O}=String,F=new WeakSet,R=new WeakMap,W={value:{then:e=>e()}},J=()=>{};let B=0;const I=(e,{parse:t=JSON.parse,stringify:r=JSON.stringify,transform:n,interrupt:s}=JSON)=>{if(!R.has(e)){const o=(t,...r)=>e.postMessage({[p]:r},{transfer:t}),a=typeof s===h?s:s?.handler||J,i=s?.delay||42,c=(e,t)=>e?(_||S)(t,0):(((e,t,r)=>{for(;"timed-out"===T(e,0,0,t);)r()})(t,i,a),W);let l=!1;R.set(e,new Proxy(new $,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,s)=>"then"===s?null:(...r)=>{const a=B++;let i=new E(new P(M)),u=[];F.has(r.at(-1)||u)&&F.delete(u=r.pop()),o(u,a,i,s,n?r.map(n):r);const f=e!==globalThis;let p=0;return l&&f&&(p=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),c(f,i).value.then((()=>{clearTimeout(p);const e=i[0];if(e<0)return;const r=j*e;return i=new E(new P(r+r%M)),o([],a,i),c(f,i).value.then((()=>t(O(...new A(i.buffer).slice(0,e)))))}))},set(t,s,o){const a=typeof o;if(a!==h)throw new Error(`Unable to assign ${s} as ${a}`);if(!t.size){const s=new $;e.addEventListener("message",(async e=>{const o=e.data?.[p];if(x(o)){e.stopImmediatePropagation();const[a,i,...c]=o;if(c.length){const[e,o]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);l=!0;try{const c=await t.get(e)(...o);if(void 0===c)i[0]=-1;else{const e=r(n?n(c):c);s.set(a,e),i[0]=e.length}}finally{l=!1}}else{const e=s.get(a);s.delete(a);for(let t=new A(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}k(i,0)}}))}return!!t.set(s,o)}}))}return R.get(e)};I.transfer=(...e)=>(F.add(e),e);const{defineProperty:C,getOwnPropertyDescriptor:L,getPrototypeOf:D,isExtensible:N,ownKeys:H,preventExtensions:U,set:z,setPrototypeOf:q}=Reflect,{assign:K,create:Y}=Object,G=D(Int8Array),V="isArray",Q=(e,t)=>{const{get:r,set:n,value:s}=e;return r&&(e.get=t(r)),n&&(e.set=t(n)),s&&(e.value=t(s)),e},X=(e,t)=>[e,t],Z=e=>t=>{const r=typeof t;switch(r){case y:if(null==t)return X("null",t);if(t===globalThis)return X(y,null);case h:return e(r,t);case"boolean":case w:case m:case b:case"bigint":return X(r,t);case v:if(ee.has(t))return X(r,ee.get(t))}throw new Error(`Unable to handle this ${r} type`)},ee=new Map(H(Symbol).filter((e=>typeof Symbol[e]===v)).map((e=>[Symbol[e],e]))),te=e=>{for(const[t,r]of ee)if(r===e)return t};function re(){return this}const ne="apply",se="construct",oe="defineProperty",ae="deleteProperty",ie="get",ce="getOwnPropertyDescriptor",le="getPrototypeOf",ue="has",fe="isExtensible",pe="ownKeys",de="preventExtensions",ge="set",ye="setPrototypeOf",he="delete";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;C(EventTarget.prototype,"addEventListener",{value(t,n,...s){return s.at(0)?.invoke&&(r.has(this)||r.set(this,new Map),r.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,n,...s)}})}const n=t&&(e=>{const{currentTarget:t,target:n,type:s}=e;for(const o of r.get(t||n)?.get(s)||[])e[o]()});return(r,s,o,...a)=>{let i=0;const c=new Map,l=new Map,{[o]:u}=r,f=a.length?K(Y(globalThis),...a):globalThis,p=Z(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return X(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(he,X(m,e))})),g=([e,r])=>{switch(e){case y:if(null==r)return f;if(typeof r===w)return l.get(r);if(!(r instanceof G))for(const e in r)r[e]=g(r[e]);return r;case h:if(typeof r===m){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(ne,X(h,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 v:return te(r)}return r},S={[ne]:(e,t,r)=>p(e.apply(t,r)),[se]:(e,t)=>p(new e(...t)),[oe]:(e,t,r)=>p(C(e,t,r)),[ae]:(e,t)=>p(delete e[t]),[le]:e=>p(D(e)),[ie]:(e,t)=>p(e[t]),[ce]:(e,t)=>{const r=L(e,t);return r?X(y,Q(r,p)):X(b,r)},[ue]:(e,t)=>p(t in e),[fe]:e=>p(N(e)),[pe]:e=>X(y,H(e).map(p)),[de]:e=>p(U(e)),[ge]:(e,t,r)=>p(z(e,t,r)),[ye]:(e,t)=>p(q(e,t)),[he](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case ne:r[0]=g(r[0]),r[1]=r[1].map(g);break;case se:r[0]=r[0].map(g);break;case oe:{const[e,t]=r;r[0]=g(e);const{get:n,set:s,value:o}=t;n&&(t.get=g(n)),s&&(t.set=g(s)),o&&(t.value=g(o));break}default:r=r.map(g)}return S[e](g(t),...r)},{proxy:r,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window",!0),me=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===h?e():e,a=e=>typeof e===y&&!!e&&s in e,i=Array[V],c=Z(((e,a)=>{if(s in a)return o(a[s]);if(e===h){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return X(e,r.get(a))}if(!(a instanceof G))for(const e in a)a[e]=c(a[e]);return X(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(he,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===h?re.bind(e):e,s=new Proxy(n,E),o=new WeakRef(s);p.set(r,o),d.register(s,r,o)}return p.get(r).deref()},b=e=>{const[t,r]=e;switch(t){case y:return null===r?globalThis:typeof r===w?g(e):r;case h:return typeof r===m?n.get(r):g(e);case v:return te(r)}return r},S=(e,t,...r)=>b(f(e,o(t),...r)),E={[ne]:(e,t,r)=>S(ne,e,c(t),r.map(c)),[se]:(e,t)=>S(se,e,t.map(c)),[oe]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===h&&(r.get=c(n)),typeof s===h&&(r.set=c(s)),typeof o===h&&(r.value=c(o)),S(oe,e,c(t),r)},[ae]:(e,t)=>S(ae,e,c(t)),[le]:e=>S(le,e),[ie]:(e,t)=>t===s?e:S(ie,e,c(t)),[ce]:(e,t)=>{const r=S(ce,e,c(t));return r&&Q(r,b)},[ue]:(e,t)=>t===s||S(ue,e,c(t)),[fe]:e=>S(fe,e),[pe]:e=>S(pe,e).map(b),[de]:e=>S(de,e),[ge]:(e,t,r)=>S(ge,e,c(t),c(r)),[ye]:(e,t)=>S(ye,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case ne:return b(t).apply(b(s),o.map(b));case he:{const e=b(t);r.delete(n.get(e)),n.delete(e)}}};const $=new Proxy([y,null],E),P=$.Array[V];return C(Array,V,{value:e=>a(e)?P(e):i(e)}),{[e.toLowerCase()]:$,[`is${e}Proxy`]:a,proxy:t}}})("Window"),be=typeof Worker===h?Worker:class{};const ve=new WeakMap,Se=(e,...t)=>{const r=I(e,...t);if(!ve.has(r)){const t=e instanceof be?we:me;ve.set(r,t(r,d,g))}return ve.get(r)};Se.transfer=I.transfer;const Ee={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}},$e=(e,...t)=>Ee[typeof e](e,...t),{isArray:Pe}=Array,{assign:Ae,create:Me,defineProperties:je,defineProperty:xe,entries:ke}=Object,{all:Te,resolve:_e}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Oe=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href,Fe=(e,t,r,n=!1,s=CustomEvent)=>{e.dispatchEvent(new s(`${t}:${r}`,{bubbles:!0,detail:{worker:n}}))};Promise.withResolvers||(Promise.withResolvers=function(){var e,t,r=new this((function(r,n){e=r,t=n}));return{resolve:e,reject:t,promise:r}});const Re=e=>e.arrayBuffer(),We=e=>e.json(),Je=e=>e.text(),Be=new WeakMap,Ie=e=>{const t=e||console,r={stderr:(t.stderr||console.error).bind(t),stdout:(t.stdout||console.log).bind(t)};return{stderr:(...e)=>r.stderr(...e),stdout:(...e)=>r.stdout(...e),async get(e){const t=await e;return Be.set(t,r),t}}},Ce=({FS:e,PATH:t,PATH_FS:r},n,s)=>{const o=r.resolve(n);return e.mkdirTree(t.dirname(o)),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},Le=e=>{const t=e.split("/");return t.pop(),t.join("/")},De=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Ne=(e,t)=>{const r=[];for(const e of t.split("/"))switch(e){case"":case".":break;case"..":r.pop();break;default:r.push(e)}return[e.cwd()].concat(r).join("/").replace(/^\\/+/,"/")},He=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Ue=(e,t)=>fetch(Oe(t,ze.get(e))),ze=new WeakMap,qe=(e,t,r)=>Te((e=>{for(const{files:t,to_file:r,from:n=""}of e){if(void 0!==t&&void 0!==r)throw new Error("Cannot use \'to_file\' and \'files\' parameters together!");if(void 0===t&&void 0===r&&n.endsWith("/"))throw new Error(`Couldn\'t determine the filename from the path ${n}, please supply \'to_file\' parameter.`)}return e.flatMap((({from:e="",to_folder:t=".",to_file:r,files:n})=>{if(Pe(n))return n.map((r=>({url:He([e,r]),path:He([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:He([t,s])}]}))})(r).map((({url:n,path:s})=>Ue(r,n).then(Re).then((r=>e.writeFile(t,s,r)))))),Ke=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,Ye=(e,t)=>e.replace(/\\{.+?\\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),Ge=(e,t,r)=>Te((e=>{const t=new Map,r=new Set,n=[];for(const[s,o]of Object.entries(e))if(/^\\{.+\\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,Ye(o,t))}else{const e=Ye(s,t),a=Ke(e,Ye(o||"./",t));if(r.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);r.add(a),n.push({url:e,path:a})}return n})(r).map((({url:n,path:s})=>Ue(r,n).then(Re).then((r=>e.writeFile(t,s,r)))))),Ve=(e,t,r)=>{e.registerJsModule(t,r)},Qe=(e,t,...r)=>{try{return e.runPython($e(t),...r)}catch(t){Be.get(e).stderr(t)}},Xe=async(e,t,...r)=>{try{return await e.runPythonAsync($e(t),...r)}catch(t){Be.get(e).stderr(t)}},Ze=async(e,t,r)=>{const[n,...s]=t.split(".");let o,a=e.globals.get(n);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,r)}catch(t){Be.get(e).stderr(t)}};var et={type:"micropython",module:(e="1.20.0-297")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,r){const{stderr:n,stdout:s,get:o}=Ie();r=r.replace(/\\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.files&&await Ge(this,a,t.files),t.fetch&&await qe(this,a,t.fetch),a},registerJSModule:Ve,run:Qe,runAsync:Xe,runEvent:Ze,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Ce({FS:e,PATH:t,PATH_FS:r},n,s)};const tt={dict_converter:Object.fromEntries};var rt={type:"pyodide",module:(e="0.24.1")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Ie(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.files&&await Ge(this,i,t.files),t.fetch&&await qe(this,i,t.fetch),t.packages){await i.loadPackage("micropip");const e=await i.pyimport("micropip");await e.install(t.packages),e.destroy()}return i},registerJSModule:Ve,run:Qe,runAsync:Xe,runEvent:Ze,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(tt):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Ce({FS:e,PATH:t,PATH_FS:r},n,s)};const nt="ruby-wasm-wasi",st=nt.replace(/\\W+/g,"_");var ot={type:nt,experimental:!0,module:(e="2.1.0")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,r){const n=await fetch(`${r.slice(0,r.lastIndexOf("/"))}/ruby.wasm`),s=await WebAssembly.compile(await n.arrayBuffer()),{vm:o}=await e(s);return t.files&&await Ge(this,o,t.files),t.fetch&&await qe(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${st}_${t}`;globalThis[n]=r,this.run(e,`require "js";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval($e(t),...r),runAsync:(e,t,...r)=>e.evalAsync($e(t),...r),async runEvent(e,t,r){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${st}_event`;globalThis[n]=r,this.run(e,`require "js";$xworker.call("${t}",JS.global[:${n}])`),delete globalThis[n]}else{const n=this.run(e,`method(:${t})`);await n.call(t,e.wrap(r))}},transform:(e,t)=>t,writeFile:()=>{throw new Error(`writeFile is not supported in ${nt}`)}};var at={type:"wasmoon",module:(e="1.15.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},r){const{stderr:n,stdout:s,get:o}=Ie(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",n)})),r.files&&await Ge(this,a,r.files),r.fetch&&await qe(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync($e(t),...r)}catch(t){Be.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString($e(t),...r)}catch(t){Be.get(e).stderr(t)}},runEvent:async(e,t,r)=>{const[n,...s]=t.split(".");let o,a=e.global.get(n);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,r)}catch(t){Be.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(De(e,Le(t)),t=Ne(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const it=new Map,ct=new Map,lt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=it.get(r),o=/^https?:\\/\\//i.test(n)?n.join("@"):s.module(...n);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:r,module:n,engine:s}=e.get(t);return(e,o)=>n.then((n=>{ct.set(t,e);for(const t of["files","fetch"]){const r=e?.[t];r&&ze.set(r,o)}return s(n,e,r)}))}}),ut=e=>{for(const t of[].concat(e.type))it.set(t,e)};for(const e of[et,rt,ot,at])ut(e);const ft=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),pt=(e,t,r={})=>{if(t){const[e,n]=(e=>{let t=typeof e;return"string"===t&&/\\.(json|toml|txt)$/.test(e)?t=RegExp.$1:e="./config.txt",[Oe(e),t]})(t);if("json"===n)r=fetch(e).then(We);else if("toml"===n)r=fetch(e).then(Je).then(ft);else if("string"===n)try{r=JSON.parse(t)}catch(e){r=ft(t)}else"object"===n&&t&&(r=t);t=e}return _e(r).then((r=>lt[e](r,t)))};try{new SharedArrayBuffer(4)}catch(e){throw new Error(["Unable to use SharedArrayBuffer due insecure environment.","Please read requirements in MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements"].join("\\n"))}let dt,gt,yt;const ht=(e,t)=>{addEventListener(e,t||(async t=>{try{await dt,gt(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:wt,stringify:mt}=f,{proxy:bt,window:vt,isWindowProxy:St}=Se(self,{parse:wt,stringify:mt,transform:e=>yt?yt(e):e}),Et={sync:bt,window:vt,isWindowProxy:St,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};ht("message",(({data:{options:e,config:t,code:r,hooks:n}})=>{dt=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await pt(((e,t="")=>`${e}@${t}`.replace(/@$/,""))(a,c),t,l),p=Me(it.get(a)),d="run"+(u?"Async":"");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=u?s:r,a=u?t:e;if(o){const e=p[d].bind(p);p[d]=(t,r,...n)=>e(t,`${r}\\n${o}`,...n)}if(a){const e=p[d].bind(p);p[d]=(t,r,...n)=>e(t,`${a}\\n${r}`,...n)}}const{CustomEvent:g,document:y}=vt,h=s&&y.getElementById(s)||null,w=e=>Fe(h,i||a,e,!0,g);let m="";return p.registerJSModule(f,"polyscript",{xworker:Et,get target(){return!m&&h&&("SCRIPT"===o?h.after(Ae(y.createElement(`script-${i||a}`),{id:m=`${s}-target`})):(m=s,h.replaceChildren(),h.style.display="block")),m}}),gt=p.runEvent.bind(p,f),yt=p.transform.bind(p,f),h&&w("ready"),await p[d](f,r),h&&w("done"),f}catch(e){postMessage(e)}})(),ht("error"),ht("message"),ht("messageerror")}));\n'],{type:"application/javascript"})),{type:"module"}),{postMessage:s}=n,o=this instanceof Pt;if(e.length){const[t,n]=e;(r=We({},r||{type:t,version:n})).type||(r.type=t)}const[a]=Et(r.config),i=fetch(t).then(Pe).then((e=>{const t=o?this.stringHooks:void 0;s.call(n,{options:r,config:a,code:e,hooks:t})}));return Ie(n,{postMessage:{value:(e,...t)=>i.then((()=>s.call(n,e,...t)))},sync:{value:$e(n,d).proxy},onerror:{writable:!0,configurable:!0,value:console.error}}),o&&this.onWorkerReady?.(this.interpreter,n),n.addEventListener("message",(e=>{const{data:t}=e;t instanceof Error&&(e.stopImmediatePropagation(),n.onerror(Object.create(e,{type:{value:"error"},error:{value:t}})))})),n};const Mt="Invalid content",jt="Invalid worker attribute",Tt="Invalid worker attribute";var Rt=e=>{const{src:t,worker:r}=e.attributes;if(r){let{value:s}=r;if(s)throw new SyntaxError(Tt);if(s=t?.value,!s){if(t)throw new SyntaxError(jt);if(e.childElementCount){const{innerHTML:t,localName:r,type:o}=e,a=o||r.replace(/-script$/,"");n=t,s=je.call(n,Te,_e),console.warn(`Deprecated: use <script type="${a}"> for an always safe content parsing:\n`,s)}else s=e.textContent;return URL.createObjectURL(new Blob([Me(s)],{type:"text/plain"}))}return s}var n;if(t&&e.textContent.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*(?:\/\/|#).*/gm,"").trim())throw new SyntaxError(Mt)};const _t=(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)},Ot=new WeakMap,Wt={get(){let e=Ot.get(this);return e||(e=document.createElement(`${this.type}-script`),Ot.set(this,e),Jt(this)),e},set(e){"string"==typeof e?Ot.set(this,_t(this,e)):(Ot.set(this,e),Jt(this))}},Ft=new WeakMap,It=new Map,Bt=(e,t)=>{const r=e?.value;return r?t+r:""},Lt=(e,t,r,n,s,o=e)=>{if(!It.has(t)){const a={interpreter:$t(r,s),queue:Ce(),XWorker:xt(e,n)};It.set(t,a),It.has(e)||It.set(e,a),It.has(o)||It.set(o,a)}return It.get(t)},Jt=async e=>{if(Ft.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=At(i,c);let u=Bt(r,"|");const f=Bt(n,"")||`${l}${u}`;u=u.slice(1);const p=Rt(e);if(p){const r=new(xt(i,c))(p,{...De(e,i),async:!!t,config:u});return void Ft.set(Be(e,"xworker",{value:r}),{xworker:r})}const d=Bt(s,""),h=Lt(i,f,l,c,u);Ft.set(Be(e,"target",Wt),h),d&&Ot.set(e,_t(e,d));const g=a?fetch(a).then(Pe):e.textContent;h.queue=h.queue.then((()=>(async(e,t,r,n)=>{const{type:s}=e,o=gt.get(s);o.experimental&&console.warn(`The ${s} interpreter is experimental`);const[a,i]=await Je([Ft.get(e).interpreter,t]);try{Be(document,"currentScript",{configurable:!0,get:()=>e}),o.registerJSModule(a,"polyscript",{XWorker:r}),Ue(e,s,"ready");const t=o[n?"runAsync":"run"](a,i),c=Ue.bind(null,e,s,"done");return n?t.then(c):c(),t}finally{delete document.currentScript}})(e,g,h.XWorker,!!t)))}},Ct=new Proxy(Fe(null),{get:(e,t)=>new Promise(queueMicrotask).then((()=>Ht(t)))}),Ht=async e=>{if(It.has(e)){const{interpreter:t,queue:r}=It.get(e);return(await Je([t,r]))[0]}const t=It.size?`Available interpreters are: ${[...It.keys()].map((e=>`"${e}"`)).join(", ")}.`:"There are no interpreters in this page.";throw new Error(`The interpreter "${e}" was not found. ${t}`)},Nt=async e=>{const{type:r,currentTarget:n}=e;if(mt.length)for(let{name:s,value:o,ownerElement:a}of t(`./@*[${mt.map((e=>`name()="${e}${r}"`)).join(" or ")}]`,n)){s=s.slice(0,-(r.length+1));const t=await Ht(a.getAttribute(`${s}-env`)||s);gt.get(s).runEvent(t,o,e)}},Dt=e=>{if(mt.length)for(let{name:r,ownerElement:n}of t(`.//@*[${mt.map((e=>`starts-with(name(),"${e}")`)).join(" or ")}]`,e)){const e=r.lastIndexOf("-"),t=r.slice(e+1);"env"!==t&&(n.addEventListener(t,Nt),"disabled"in n&&!n.disabled&&(n.disabled=!0,Ct[r.slice(0,e)].then((()=>{n.disabled=!1}))))}};var Ut=xt();const Xt=[],qt=new Map,zt=new Map,Yt=e=>{for(const t of Xt)if(e.matches(t)){const r=qt.get(t),{resolve:n}=zt.get(r),{options:s,known:o}=Gt.get(r);if(!o.has(e)){o.add(e);const{interpreter:t,config:a,version:i,env:c,onInterpreterReady:l,onerror:u}=s;let f;try{const o=Rt(e);if(o){const c=Ut.call(new Pt(null,s),o,{...De(e,r),version:i,type:t,custom:r,config:e.getAttribute("config")||a||{},async:e.hasAttribute("async")});return Be(e,"xworker",{value:c}),void n({type:r,xworker:c})}}catch(e){f=e}const p=At(t,i),d=c||`${p}${a?`|${a}`:""}`,{interpreter:h,XWorker:g}=Lt(r,d,p,i,a,t);h.then((o=>{const a=Fe(gt.get(t)),{onBeforeRun:i,onBeforeRunAsync:c,onAfterRun:d,onAfterRunAsync:h}=s,y=new Pt(o,s),w=function(...e){return g.apply(y,e)};for(const[t,[r,n]]of[["run",[i,d]]]){const s=a[t];a[t]=function(t,o,...a){r&&r.call(this,m,e);const i=s.call(this,t,o,...a);return n&&n.call(this,m,e),i}}for(const[t,[r,n]]of[["runAsync",[c,h]]]){const s=a[t];a[t]=async function(t,o,...a){r&&await r.call(this,m,e);const i=await s.call(this,t,o,...a);return n&&await n.call(this,m,e),i}}a.registerJSModule(o,"polyscript",{XWorker:w});const m={type:r,interpreter:o,XWorker:w,io:Xe.get(o),config:structuredClone(yt.get(p)),run:a.run.bind(a,o),runAsync:a.runAsync.bind(a,o),runEvent:a.runEvent.bind(a,o)};n(m),f&&u?.(f,e),l?.(m,e)}))}}},Gt=new Map;let Vt=0;const Kt=e=>(zt.has(e)||zt.set(e,Promise.withResolvers()),zt.get(e).promise),Qt=Symbol.for("polyscript"),Zt=Qt in globalThis,{define:er,whenDefined:tr,env:rr,Hook:nr,XWorker:sr}=Zt?globalThis[Qt]:Be(globalThis,Qt,{value:{define:(t,r)=>{let n=null==t;if(n)t="_ps"+Vt++;else if(gt.has(t)||Gt.has(t))throw new Error(`<script type="${t}"> already registered`);if(!gt.has(r?.interpreter))throw new Error("Unspecified interpreter");gt.set(t,gt.get(r.interpreter));const s=[`script[type="${t}"]`];if(Kt(t),n){const{onInterpreterReady:e}=r;r={...r,onInterpreterReady(r,n){Xt.splice(Xt.indexOf(t),1),gt.delete(t),Gt.delete(t),zt.delete(t),n.remove(),e?.(r)}},document.head.append(We(document.createElement("script"),{type:t}))}else s.push(`${t}-script`),mt.push(`${t}-`);for(const e of s)qt.set(e,t);Xt.push(...s),Gt.set(t,{options:We({env:t},r),known:new WeakSet}),n||Dt(document),e(s.join(",")).forEach(Yt)},whenDefined:Kt,env:Ct,Hook:Pt,XWorker:Ut}})[Qt];if(!Zt){const t=new MutationObserver((e=>{const t=wt.join(",");for(const{type:n,target:s,attributeName:o,addedNodes:a}of e)if("attributes"!==n)for(const e of a)1===e.nodeType&&(Dt(e),t&&e.matches(t)?Jt(e):r(t,e,!0));else{const e=o.lastIndexOf("-")+1;if(e){const t=o.slice(0,e);for(const r of mt)if(t===r){const t=o.slice(e);if("env"!==t){const e=s.hasAttribute(o)?"add":"remove";s[`${e}EventListener`](t,Nt)}break}}}})),r=(t,r,n)=>{t&&e(t,r).forEach(Jt),(t=Xt.join(","))&&(n&&Yt(r),e(t,r).forEach(Yt))},n=e=>(t.observe(e,{childList:!0,subtree:!0,attributes:!0}),e),{attachShadow:s}=Element.prototype;We(Element.prototype,{attachShadow(e){return n(s.call(this,e))}}),queueMicrotask((()=>{Dt(n(document)),r(wt.join(","),document,!1)}))}export{nr as Hook,Mt as INVALID_CONTENT,jt as INVALID_SRC_ATTR,Tt as INVALID_WORKER_ATTR,sr as XWorker,er as define,rr as env,tr as whenDefined}; | ||
/*! (c) Andrea Giammarchi - ISC */;const{Int32Array:A,Map:k,SharedArrayBuffer:P,Uint16Array:x}=globalThis,{BYTES_PER_ELEMENT:M}=A,{BYTES_PER_ELEMENT:j}=x,{isArray:T}=Array,{notify:R,wait:_,waitAsync:O}=Atomics,{fromCharCode:W}=String,F=new WeakSet,I=new WeakMap,B={value:{then:e=>e()}},L=()=>{};let J=0;const C=(e,{parse:t=JSON.parse,stringify:r=JSON.stringify,transform:n,interrupt:s}=JSON)=>{if(!I.has(e)){const o=(t,...r)=>e.postMessage({[h]:r},{transfer:t}),a=typeof s===m?s:s?.handler||L,i=s?.delay||42,c=(e,t)=>e?(O||$)(t,0):(((e,t,r)=>{for(;"timed-out"===_(e,0,0,t);)r()})(t,i,a),B);let l=!1;I.set(e,new Proxy(new k,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,s)=>"then"===s?null:(...r)=>{const a=J++;let i=new A(new P(M)),u=[];F.has(r.at(-1)||u)&&F.delete(u=r.pop()),o(u,a,i,s,n?r.map(n):r);const f=e!==globalThis;let p=0;return l&&f&&(p=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),c(f,i).value.then((()=>{clearTimeout(p);const e=i[0];if(e<0)return;const r=j*e;return i=new A(new P(r+r%M)),o([],a,i),c(f,i).value.then((()=>t(W(...new x(i.buffer).slice(0,e)))))}))},set(t,s,o){const a=typeof o;if(a!==m)throw new Error(`Unable to assign ${s} as ${a}`);if(!t.size){const s=new k;e.addEventListener("message",(async e=>{const o=e.data?.[h];if(T(o)){e.stopImmediatePropagation();const[a,i,...c]=o;if(c.length){const[e,o]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);l=!0;try{const c=await t.get(e)(...o);if(void 0===c)i[0]=-1;else{const e=r(n?n(c):c);s.set(a,e),i[0]=e.length}}finally{l=!1}}else{const e=s.get(a);s.delete(a);for(let t=new x(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}R(i,0)}}))}return!!t.set(s,o)}}))}return I.get(e)};C.transfer=(...e)=>(F.add(e),e);const{defineProperty:H,getOwnPropertyDescriptor:N,getPrototypeOf:D,isExtensible:U,ownKeys:X,preventExtensions:q,set:z,setPrototypeOf:Y}=Reflect,{assign:G,create:V}=Object,K=D(Int8Array),Q="isArray",Z=(e,t)=>{const{get:r,set:n,value:s}=e;return r&&(e.get=t(r)),n&&(e.set=t(n)),s&&(e.value=t(s)),e},ee=(e,t)=>[e,t],te=e=>t=>{const r=typeof t;switch(r){case w:if(null==t)return ee("null",t);if(t===globalThis)return ee(w,null);case m:return e(r,t);case"boolean":case b:case v:case S:case"bigint":return ee(r,t);case E:if(re.has(t))return ee(r,re.get(t))}throw new Error(`Unable to handle this ${r} type`)},re=new Map(X(Symbol).filter((e=>typeof Symbol[e]===E)).map((e=>[Symbol[e],e]))),ne=e=>{for(const[t,r]of re)if(r===e)return t};function se(){return this}const oe="apply",ae="construct",ie="defineProperty",ce="deleteProperty",le="get",ue="getOwnPropertyDescriptor",fe="getPrototypeOf",pe="has",de="isExtensible",he="ownKeys",ge="preventExtensions",ye="set",we="setPrototypeOf",me="delete";var be=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;H(EventTarget.prototype,"addEventListener",{value(t,n,...s){return s.at(0)?.invoke&&(r.has(this)||r.set(this,new Map),r.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,n,...s)}})}const n=t&&(e=>{const{currentTarget:t,target:n,type:s}=e;for(const o of r.get(t||n)?.get(s)||[])e[o]()});return(r,s,o,...a)=>{let i=0;const c=new Map,l=new Map,{[o]:u}=r,f=a.length?G(V(globalThis),...a):globalThis,p=te(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return ee(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(me,ee(v,e))})),h=([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]=h(r[e]);return r;case m:if(typeof r===v){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(oe,ee(m,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 E:return ne(r)}return r},g={[oe]:(e,t,r)=>p(e.apply(t,r)),[ae]:(e,t)=>p(new e(...t)),[ie]:(e,t,r)=>p(H(e,t,r)),[ce]:(e,t)=>p(delete e[t]),[fe]:e=>p(D(e)),[le]:(e,t)=>p(e[t]),[ue]:(e,t)=>{const r=N(e,t);return r?ee(w,Z(r,p)):ee(S,r)},[pe]:(e,t)=>p(t in e),[de]:e=>p(U(e)),[he]:e=>ee(w,X(e).map(p)),[ge]:e=>p(q(e)),[ye]:(e,t,r)=>p(z(e,t,r)),[we]:(e,t)=>p(Y(e,t)),[me](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case oe:r[0]=h(r[0]),r[1]=r[1].map(h);break;case ae:r[0]=r[0].map(h);break;case ie:{const[e,t]=r;r[0]=h(e);const{get:n,set:s,value:o}=t;n&&(t.get=h(n)),s&&(t.set=h(s)),o&&(t.value=h(o));break}default:r=r.map(h)}return g[e](h(t),...r)},{proxy:r,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window",!0),ve=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===m?e():e,a=e=>typeof e===w&&!!e&&s in e,i=Array[Q],c=te(((e,a)=>{if(s in a)return o(a[s]);if(e===m){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return ee(e,r.get(a))}if(!(a instanceof K))for(const e in a)a[e]=c(a[e]);return ee(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(me,c(e))})),h=e=>{const[t,r]=e;if(!p.has(r)){const n=t===m?se.bind(e):e,s=new Proxy(n,S),o=new WeakRef(s);p.set(r,o),d.register(s,r,o)}return p.get(r).deref()},g=e=>{const[t,r]=e;switch(t){case w:return null===r?globalThis:typeof r===b?h(e):r;case m:return typeof r===v?n.get(r):h(e);case E:return ne(r)}return r},y=(e,t,...r)=>g(f(e,o(t),...r)),S={[oe]:(e,t,r)=>y(oe,e,c(t),r.map(c)),[ae]:(e,t)=>y(ae,e,t.map(c)),[ie]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===m&&(r.get=c(n)),typeof s===m&&(r.set=c(s)),typeof o===m&&(r.value=c(o)),y(ie,e,c(t),r)},[ce]:(e,t)=>y(ce,e,c(t)),[fe]:e=>y(fe,e),[le]:(e,t)=>t===s?e:y(le,e,c(t)),[ue]:(e,t)=>{const r=y(ue,e,c(t));return r&&Z(r,g)},[pe]:(e,t)=>t===s||y(pe,e,c(t)),[de]:e=>y(de,e),[he]:e=>y(he,e).map(g),[ge]:e=>y(ge,e),[ye]:(e,t,r)=>y(ye,e,c(t),c(r)),[we]:(e,t)=>y(we,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case oe:return g(t).apply(g(s),o.map(g));case me:{const e=g(t);r.delete(n.get(e)),n.delete(e)}}};const $=new Proxy([w,null],S),A=$.Array[Q];return H(Array,Q,{value:e=>a(e)?A(e):i(e)}),{[e.toLowerCase()]:$,[`is${e}Proxy`]:a,proxy:t}}})("Window"),Se=typeof Worker===m?Worker:class{};const Ee=new WeakMap,$e=(e,...t)=>{const r=C(e,...t);if(!Ee.has(r)){const t=e instanceof Se?be:ve;Ee.set(r,t(r,g,y))}return Ee.get(r)};$e.transfer=C.transfer;Promise.withResolvers||(Promise.withResolvers=function(){var e,t,r=new this((function(r,n){e=r,t=n}));return{resolve:e,reject:t,promise:r}});const Ae=e=>e.arrayBuffer(),ke=e=>e.json(),Pe=e=>e.text();const xe={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}},Me=(e,...t)=>xe[typeof e](e,...t),{replace:je}="",Te=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g,Re={"&":"&","&":"&","<":"<","<":"<",">":">",">":">","'":"'","'":"'",""":'"',""":'"'},_e=e=>Re[e],{isArray:Oe}=Array,{assign:We,create:Fe,defineProperties:Ie,defineProperty:Be,entries:Le}=Object,{all:Je,resolve:Ce}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),He=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href;let Ne=0;const De=(e,t)=>({id:e.id||(e.id=`${t}-w${Ne++}`),tag:e.tagName}),Ue=(e,t,r,n=!1,s=CustomEvent)=>{e.dispatchEvent(new s(`${t}:${r}`,{bubbles:!0,detail:{worker:n}}))},Xe=new WeakMap,qe=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 Xe.set(t,r),t}}},ze=({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})},Ye=e=>{const t=e.split("/");return t.pop(),t.join("/")},Ge=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Ve=(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(/^\/+/,"/")},Ke=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Qe=(e,t)=>fetch(He(t,Ze.get(e))),Ze=new WeakMap,et=(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(Oe(n))return n.map((r=>({url:Ke([e,r]),path:Ke([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:Ke([t,s])}]}))})(r).map((({url:n,path:s})=>Qe(r,n).then(Ae).then((r=>e.writeFile(t,s,r)))))),tt=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,rt=(e,t)=>e.replace(/\{.+?\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),nt=(e,t,r)=>Je((e=>{const t=new Map,r=new Set,n=[];for(const[s,o]of Object.entries(e))if(/^\{.+\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,rt(o,t))}else{const e=rt(s,t),a=tt(e,rt(o||"./",t));if(r.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);r.add(a),n.push({url:e,path:a})}return n})(r).map((({url:n,path:s})=>Qe(r,n).then(Ae).then((r=>e.writeFile(t,s,r)))))),st=(e,t,r)=>{e.registerJsModule(t,r)},ot=(e,t,...r)=>{try{return e.runPython(Me(t),...r)}catch(t){Xe.get(e).stderr(t)}},at=async(e,t,...r)=>{try{return await e.runPythonAsync(Me(t),...r)}catch(t){Xe.get(e).stderr(t)}},it=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){Xe.get(e).stderr(t)}};var ct={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}=qe();r=r.replace(/\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.files&&await nt(this,a,t.files),t.fetch&&await et(this,a,t.fetch),a},registerJSModule:st,run:ot,runAsync:at,runEvent:it,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>ze({FS:e,PATH:t,PATH_FS:r},n,s)};const lt={dict_converter:Object.fromEntries};var ut={type:"pyodide",module:(e="0.24.1")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=qe(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.files&&await nt(this,i,t.files),t.fetch&&await et(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:st,run:ot,runAsync:at,runEvent:it,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(lt):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>ze({FS:e,PATH:t,PATH_FS:r},n,s)};const ft="ruby-wasm-wasi",pt=ft.replace(/\W+/g,"_");var dt={type:ft,experimental:!0,module:(e="2.1.0")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,r){const n=await fetch(`${r.slice(0,r.lastIndexOf("/"))}/ruby.wasm`),s=await WebAssembly.compile(await n.arrayBuffer()),{vm:o}=await e(s);return t.files&&await nt(this,o,t.files),t.fetch&&await et(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${pt}_${t}`;globalThis[n]=r,this.run(e,`require "js";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval(Me(t),...r),runAsync:(e,t,...r)=>e.evalAsync(Me(t),...r),async runEvent(e,t,r){if(/^xworker\.(on\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${pt}_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 ${ft}`)}};var ht={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}=qe(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",n)})),r.files&&await nt(this,a,r.files),r.fetch&&await et(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync(Me(t),...r)}catch(t){Xe.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString(Me(t),...r)}catch(t){Xe.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){Xe.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(Ge(e,Ye(t)),t=Ve(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const gt=new Map,yt=new Map,wt=[],mt=[],bt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=gt.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=>{yt.set(t,e);for(const t of["files","fetch"]){const r=e?.[t];r&&Ze.set(r,o)}return s(n,e,r)}))}}),vt=e=>{for(const t of[].concat(e.type))gt.set(t,e),wt.push(`script[type="${t}"]`),mt.push(`${t}-`)};for(const e of[ct,ut,dt,ht])vt(e);const St=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),Et=e=>{let t=typeof e;return"string"===t&&/\.(json|toml|txt)$/.test(e)?t=RegExp.$1:e="./config.txt",[He(e),t]},$t=(e,t,r={})=>{if(t){const[e,n]=Et(t);if("json"===n)r=fetch(e).then(ke);else if("toml"===n)r=fetch(e).then(Pe).then(St);else if("string"===n)try{r=JSON.parse(t)}catch(e){r=St(t)}else"object"===n&&t&&(r=t);t=e}return Ce(r).then((r=>bt[e](r,t)))},At=(e,t="")=>`${e}@${t}`.replace(/@$/,""),kt=[["beforeRun","codeBeforeRunWorker"],["beforeRunAsync","codeBeforeRunWorkerAsync"],["afterRun","codeAfterRunWorker"],["afterRunAsync","codeAfterRunWorkerAsync"]];let Pt=class{constructor(e,t){this.interpreter=e,this.onWorkerReady=t.onWorkerReady;for(const[e,r]of kt)this[e]=t[r]}get stringHooks(){const e={};for(const[t]of kt)this[t]&&(e[t]=Me(this[t]()));return e}};var xt=(...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="8db0a6b1-4d79-4ecd-8b7a-7ea5c1811764",d="M"+p,g="T"+p,y="object",h="function",w="number",m="string",b="undefined",v="symbol";var S=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:E,Map:$,SharedArrayBuffer:P,Uint16Array:A}=globalThis,{BYTES_PER_ELEMENT:M}=E,{BYTES_PER_ELEMENT:j}=A,{isArray:x}=Array,{notify:k,wait:T,waitAsync:_}=Atomics,{fromCharCode:O}=String,F=new WeakSet,R=new WeakMap,W={value:{then:e=>e()}},J=()=>{};let B=0;const I=(e,{parse:t=JSON.parse,stringify:r=JSON.stringify,transform:n,interrupt:s}=JSON)=>{if(!R.has(e)){const o=(t,...r)=>e.postMessage({[p]:r},{transfer:t}),a=typeof s===h?s:s?.handler||J,i=s?.delay||42,c=(e,t)=>e?(_||S)(t,0):(((e,t,r)=>{for(;"timed-out"===T(e,0,0,t);)r()})(t,i,a),W);let l=!1;R.set(e,new Proxy(new $,{has:(e,t)=>"string"==typeof t&&!t.startsWith("_"),get:(r,s)=>"then"===s?null:(...r)=>{const a=B++;let i=new E(new P(M)),u=[];F.has(r.at(-1)||u)&&F.delete(u=r.pop()),o(u,a,i,s,n?r.map(n):r);const f=e!==globalThis;let p=0;return l&&f&&(p=setTimeout(console.warn,1e3,`💀🔒 - Possible deadlock if proxy.${s}(...args) is awaited`)),c(f,i).value.then((()=>{clearTimeout(p);const e=i[0];if(e<0)return;const r=j*e;return i=new E(new P(r+r%M)),o([],a,i),c(f,i).value.then((()=>t(O(...new A(i.buffer).slice(0,e)))))}))},set(t,s,o){const a=typeof o;if(a!==h)throw new Error(`Unable to assign ${s} as ${a}`);if(!t.size){const s=new $;e.addEventListener("message",(async e=>{const o=e.data?.[p];if(x(o)){e.stopImmediatePropagation();const[a,i,...c]=o;if(c.length){const[e,o]=c;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);l=!0;try{const c=await t.get(e)(...o);if(void 0===c)i[0]=-1;else{const e=r(n?n(c):c);s.set(a,e),i[0]=e.length}}finally{l=!1}}else{const e=s.get(a);s.delete(a);for(let t=new A(i.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}k(i,0)}}))}return!!t.set(s,o)}}))}return R.get(e)};I.transfer=(...e)=>(F.add(e),e);const{defineProperty:C,getOwnPropertyDescriptor:L,getPrototypeOf:D,isExtensible:N,ownKeys:H,preventExtensions:U,set:z,setPrototypeOf:q}=Reflect,{assign:K,create:Y}=Object,G=D(Int8Array),V="isArray",Q=(e,t)=>{const{get:r,set:n,value:s}=e;return r&&(e.get=t(r)),n&&(e.set=t(n)),s&&(e.value=t(s)),e},X=(e,t)=>[e,t],Z=e=>t=>{const r=typeof t;switch(r){case y:if(null==t)return X("null",t);if(t===globalThis)return X(y,null);case h:return e(r,t);case"boolean":case w:case m:case b:case"bigint":return X(r,t);case v:if(ee.has(t))return X(r,ee.get(t))}throw new Error(`Unable to handle this ${r} type`)},ee=new Map(H(Symbol).filter((e=>typeof Symbol[e]===v)).map((e=>[Symbol[e],e]))),te=e=>{for(const[t,r]of ee)if(r===e)return t};function re(){return this}const ne="apply",se="construct",oe="defineProperty",ae="deleteProperty",ie="get",ce="getOwnPropertyDescriptor",le="getPrototypeOf",ue="has",fe="isExtensible",pe="ownKeys",de="preventExtensions",ge="set",ye="setPrototypeOf",he="delete";var we=((e,t)=>{const r=t&&new WeakMap;if(t){const{addEventListener:e}=EventTarget.prototype;C(EventTarget.prototype,"addEventListener",{value(t,n,...s){return s.at(0)?.invoke&&(r.has(this)||r.set(this,new Map),r.get(this).set(t,[].concat(s[0].invoke)),delete s[0].invoke),e.call(this,t,n,...s)}})}const n=t&&(e=>{const{currentTarget:t,target:n,type:s}=e;for(const o of r.get(t||n)?.get(s)||[])e[o]()});return(r,s,o,...a)=>{let i=0;const c=new Map,l=new Map,{[o]:u}=r,f=a.length?K(Y(globalThis),...a):globalThis,p=Z(((e,t)=>{if(!c.has(t)){let e;for(;l.has(e=i++););c.set(t,e),l.set(e,t)}return X(e,c.get(t))})),d=new FinalizationRegistry((e=>{u(he,X(m,e))})),g=([e,r])=>{switch(e){case y:if(null==r)return f;if(typeof r===w)return l.get(r);if(!(r instanceof G))for(const e in r)r[e]=g(r[e]);return r;case h:if(typeof r===m){if(!l.has(r)){const e=function(...e){return t&&e.at(0)instanceof Event&&n(...e),u(ne,X(h,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 v:return te(r)}return r},S={[ne]:(e,t,r)=>p(e.apply(t,r)),[se]:(e,t)=>p(new e(...t)),[oe]:(e,t,r)=>p(C(e,t,r)),[ae]:(e,t)=>p(delete e[t]),[le]:e=>p(D(e)),[ie]:(e,t)=>p(e[t]),[ce]:(e,t)=>{const r=L(e,t);return r?X(y,Q(r,p)):X(b,r)},[ue]:(e,t)=>p(t in e),[fe]:e=>p(N(e)),[pe]:e=>X(y,H(e).map(p)),[de]:e=>p(U(e)),[ge]:(e,t,r)=>p(z(e,t,r)),[ye]:(e,t)=>p(q(e,t)),[he](e){c.delete(l.get(e)),l.delete(e)}};return r[s]=(e,t,...r)=>{switch(e){case ne:r[0]=g(r[0]),r[1]=r[1].map(g);break;case se:r[0]=r[0].map(g);break;case oe:{const[e,t]=r;r[0]=g(e);const{get:n,set:s,value:o}=t;n&&(t.get=g(n)),s&&(t.set=g(s)),o&&(t.value=g(o));break}default:r=r.map(g)}return S[e](g(t),...r)},{proxy:r,[e.toLowerCase()]:f,[`is${e}Proxy`]:()=>!1}}})("Window",!0),me=(e=>{let t=0;const r=new Map,n=new Map,s=Symbol(),o=e=>typeof e===h?e():e,a=e=>typeof e===y&&!!e&&s in e,i=Array[V],c=Z(((e,a)=>{if(s in a)return o(a[s]);if(e===h){if(!n.has(a)){let e;for(;n.has(e=String(t++)););r.set(a,e),n.set(e,a)}return X(e,r.get(a))}if(!(a instanceof G))for(const e in a)a[e]=c(a[e]);return X(e,a)}));return(t,l,u)=>{const{[l]:f}=t,p=new Map,d=new FinalizationRegistry((e=>{p.delete(e),f(he,c(e))})),g=e=>{const[t,r]=e;if(!p.has(r)){const n=t===h?re.bind(e):e,s=new Proxy(n,E),o=new WeakRef(s);p.set(r,o),d.register(s,r,o)}return p.get(r).deref()},b=e=>{const[t,r]=e;switch(t){case y:return null===r?globalThis:typeof r===w?g(e):r;case h:return typeof r===m?n.get(r):g(e);case v:return te(r)}return r},S=(e,t,...r)=>b(f(e,o(t),...r)),E={[ne]:(e,t,r)=>S(ne,e,c(t),r.map(c)),[se]:(e,t)=>S(se,e,t.map(c)),[oe]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===h&&(r.get=c(n)),typeof s===h&&(r.set=c(s)),typeof o===h&&(r.value=c(o)),S(oe,e,c(t),r)},[ae]:(e,t)=>S(ae,e,c(t)),[le]:e=>S(le,e),[ie]:(e,t)=>t===s?e:S(ie,e,c(t)),[ce]:(e,t)=>{const r=S(ce,e,c(t));return r&&Q(r,b)},[ue]:(e,t)=>t===s||S(ue,e,c(t)),[fe]:e=>S(fe,e),[pe]:e=>S(pe,e).map(b),[de]:e=>S(de,e),[ge]:(e,t,r)=>S(ge,e,c(t),c(r)),[ye]:(e,t)=>S(ye,e,c(t))};t[u]=(e,t,s,o)=>{switch(e){case ne:return b(t).apply(b(s),o.map(b));case he:{const e=b(t);r.delete(n.get(e)),n.delete(e)}}};const $=new Proxy([y,null],E),P=$.Array[V];return C(Array,V,{value:e=>a(e)?P(e):i(e)}),{[e.toLowerCase()]:$,[`is${e}Proxy`]:a,proxy:t}}})("Window"),be=typeof Worker===h?Worker:class{};const ve=new WeakMap,Se=(e,...t)=>{const r=I(e,...t);if(!ve.has(r)){const t=e instanceof be?we:me;ve.set(r,t(r,d,g))}return ve.get(r)};Se.transfer=I.transfer;const Ee={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}},$e=(e,...t)=>Ee[typeof e](e,...t),{isArray:Pe}=Array,{assign:Ae,create:Me,defineProperties:je,defineProperty:xe,entries:ke}=Object,{all:Te,resolve:_e}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Oe=(e,t=location.href)=>new URL(e,t.replace(/^blob:/,"")).href,Fe=(e,t,r,n=!1,s=CustomEvent)=>{e.dispatchEvent(new s(`${t}:${r}`,{bubbles:!0,detail:{worker:n}}))};Promise.withResolvers||(Promise.withResolvers=function(){var e,t,r=new this((function(r,n){e=r,t=n}));return{resolve:e,reject:t,promise:r}});const Re=e=>e.arrayBuffer(),We=e=>e.json(),Je=e=>e.text(),Be=new WeakMap,Ie=e=>{const t=e||console,r={stderr:(t.stderr||console.error).bind(t),stdout:(t.stdout||console.log).bind(t)};return{stderr:(...e)=>r.stderr(...e),stdout:(...e)=>r.stdout(...e),async get(e){const t=await e;return Be.set(t,r),t}}},Ce=({FS:e,PATH:t,PATH_FS:r},n,s)=>{const o=r.resolve(n);return e.mkdirTree(t.dirname(o)),e.writeFile(o,new Uint8Array(s),{canOwn:!0})},Le=e=>{const t=e.split("/");return t.pop(),t.join("/")},De=(e,t)=>{const r=[];for(const n of t.split("/"))"."!==n&&(r.push(n),n&&e.mkdir(r.join("/")))},Ne=(e,t)=>{const r=[];for(const e of t.split("/"))switch(e){case"":case".":break;case"..":r.pop();break;default:r.push(e)}return[e.cwd()].concat(r).join("/").replace(/^\\/+/,"/")},He=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,""))).filter((e=>""!==e&&"."!==e)).join("/");return e[0].startsWith("/")?`/${t}`:t},Ue=(e,t)=>fetch(Oe(t,ze.get(e))),ze=new WeakMap,qe=(e,t,r)=>Te((e=>{for(const{files:t,to_file:r,from:n=""}of e){if(void 0!==t&&void 0!==r)throw new Error("Cannot use \'to_file\' and \'files\' parameters together!");if(void 0===t&&void 0===r&&n.endsWith("/"))throw new Error(`Couldn\'t determine the filename from the path ${n}, please supply \'to_file\' parameter.`)}return e.flatMap((({from:e="",to_folder:t=".",to_file:r,files:n})=>{if(Pe(n))return n.map((r=>({url:He([e,r]),path:He([t,r])})));const s=r||e.slice(1+e.lastIndexOf("/"));return[{url:e,path:He([t,s])}]}))})(r).map((({url:n,path:s})=>Ue(r,n).then(Re).then((r=>e.writeFile(t,s,r)))))),Ke=(e,t)=>t.endsWith("/")?`${t}${e.split("/").pop()}`:t,Ye=(e,t)=>e.replace(/\\{.+?\\}/g,(e=>{if(!t.has(e))throw new SyntaxError(`Invalid template: ${e}`);return t.get(e)})),Ge=(e,t,r)=>Te((e=>{const t=new Map,r=new Set,n=[];for(const[s,o]of Object.entries(e))if(/^\\{.+\\}$/.test(s)){if(t.has(s))throw new SyntaxError(`Duplicated template: ${s}`);t.set(s,Ye(o,t))}else{const e=Ye(s,t),a=Ke(e,Ye(o||"./",t));if(r.has(a))throw new SyntaxError(`Duplicated destination: ${a}`);r.add(a),n.push({url:e,path:a})}return n})(r).map((({url:n,path:s})=>Ue(r,n).then(Re).then((r=>e.writeFile(t,s,r)))))),Ve=(e,t,r)=>{e.registerJsModule(t,r)},Qe=(e,t,...r)=>{try{return e.runPython($e(t),...r)}catch(t){Be.get(e).stderr(t)}},Xe=async(e,t,...r)=>{try{return await e.runPythonAsync($e(t),...r)}catch(t){Be.get(e).stderr(t)}},Ze=async(e,t,r)=>{const[n,...s]=t.split(".");let o,a=e.globals.get(n);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,r)}catch(t){Be.get(e).stderr(t)}};var et={type:"micropython",module:(e="1.20.0-297")=>`https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@${e}/micropython.mjs`,async engine({loadMicroPython:e},t,r){const{stderr:n,stdout:s,get:o}=Ie();r=r.replace(/\\.m?js$/,".wasm");const a=await o(e({stderr:n,stdout:s,url:r}));return t.files&&await Ge(this,a,t.files),t.fetch&&await qe(this,a,t.fetch),a},registerJSModule:Ve,run:Qe,runAsync:Xe,runEvent:Ze,transform:(e,t)=>t,writeFile:({FS:e,_module:{PATH:t,PATH_FS:r}},n,s)=>Ce({FS:e,PATH:t,PATH_FS:r},n,s)};const tt={dict_converter:Object.fromEntries};var rt={type:"pyodide",module:(e="0.24.1")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Ie(),a=r.slice(0,r.lastIndexOf("/")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.files&&await Ge(this,i,t.files),t.fetch&&await qe(this,i,t.fetch),t.packages){await i.loadPackage("micropip");const e=await i.pyimport("micropip");await e.install(t.packages),e.destroy()}return i},registerJSModule:Ve,run:Qe,runAsync:Xe,runEvent:Ze,transform:(e,t)=>t instanceof e.ffi.PyProxy?t.toJs(tt):t,writeFile:({FS:e,PATH:t,_module:{PATH_FS:r}},n,s)=>Ce({FS:e,PATH:t,PATH_FS:r},n,s)};const nt="ruby-wasm-wasi",st=nt.replace(/\\W+/g,"_");var ot={type:nt,experimental:!0,module:(e="2.1.0")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,r){const n=await fetch(`${r.slice(0,r.lastIndexOf("/"))}/ruby.wasm`),s=await WebAssembly.compile(await n.arrayBuffer()),{vm:o}=await e(s);return t.files&&await Ge(this,o,t.files),t.fetch&&await qe(this,o,t.fetch),o},registerJSModule(e,t,r){const n=`__module_${st}_${t}`;globalThis[n]=r,this.run(e,`require "js";$${t}=JS.global[:${n}]`),delete globalThis[n]},run:(e,t,...r)=>e.eval($e(t),...r),runAsync:(e,t,...r)=>e.evalAsync($e(t),...r),async runEvent(e,t,r){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${st}_event`;globalThis[n]=r,this.run(e,`require "js";$xworker.call("${t}",JS.global[:${n}])`),delete globalThis[n]}else{const n=this.run(e,`method(:${t})`);await n.call(t,e.wrap(r))}},transform:(e,t)=>t,writeFile:()=>{throw new Error(`writeFile is not supported in ${nt}`)}};var at={type:"wasmoon",module:(e="1.15.0")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},r){const{stderr:n,stdout:s,get:o}=Ie(),a=await o((new e).createEngine());return a.global.getTable(t.Base,(e=>{a.global.setField(e,"print",s),a.global.setField(e,"printErr",n)})),r.files&&await Ge(this,a,r.files),r.fetch&&await qe(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{e.global.set(t,r)},run:(e,t,...r)=>{try{return e.doStringSync($e(t),...r)}catch(t){Be.get(e).stderr(t)}},runAsync:async(e,t,...r)=>{try{return await e.doString($e(t),...r)}catch(t){Be.get(e).stderr(t)}},runEvent:async(e,t,r)=>{const[n,...s]=t.split(".");let o,a=e.global.get(n);for(const e of s)[o,a]=[a,a[e]];try{await a.call(o,r)}catch(t){Be.get(e).stderr(t)}},transform:(e,t)=>t,writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(De(e,Le(t)),t=Ne(e,t),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const it=new Map,ct=new Map,lt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split("@"),s=it.get(r),o=/^https?:\\/\\//i.test(n)?n.join("@"):s.module(...n);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:r,module:n,engine:s}=e.get(t);return(e,o)=>n.then((n=>{ct.set(t,e);for(const t of["files","fetch"]){const r=e?.[t];r&&ze.set(r,o)}return s(n,e,r)}))}}),ut=e=>{for(const t of[].concat(e.type))it.set(t,e)};for(const e of[et,rt,ot,at])ut(e);const ft=async e=>(await import("https://cdn.jsdelivr.net/npm/basic-toml@0.3.1/es.js")).parse(e),pt=(e,t,r={})=>{if(t){const[e,n]=(e=>{let t=typeof e;return"string"===t&&/\\.(json|toml|txt)$/.test(e)?t=RegExp.$1:e="./config.txt",[Oe(e),t]})(t);if("json"===n)r=fetch(e).then(We);else if("toml"===n)r=fetch(e).then(Je).then(ft);else if("string"===n)try{r=JSON.parse(t)}catch(e){r=ft(t)}else"object"===n&&t&&(r=t);t=e}return _e(r).then((r=>lt[e](r,t)))};try{new SharedArrayBuffer(4)}catch(e){throw new Error(["Unable to use SharedArrayBuffer due insecure environment.","Please read requirements in MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements"].join("\\n"))}let dt,gt,yt;const ht=(e,t)=>{addEventListener(e,t||(async t=>{try{await dt,gt(`xworker.on${e}`,t)}catch(e){postMessage(e)}}),!!t&&{once:!0})},{parse:wt,stringify:mt}=f,{proxy:bt,window:vt,isWindowProxy:St}=Se(self,{parse:wt,stringify:mt,transform:e=>yt?yt(e):e}),Et={sync:bt,window:vt,isWindowProxy:St,onmessage:console.info,onerror:console.error,onmessageerror:console.warn,postMessage:postMessage.bind(self)};ht("message",(({data:{options:e,config:t,code:r,hooks:n}})=>{dt=(async()=>{try{const{id:s,tag:o,type:a,custom:i,version:c,config:l,async:u}=e,f=await pt(((e,t="")=>`${e}@${t}`.replace(/@$/,""))(a,c),t,l),p=Me(it.get(a)),d="run"+(u?"Async":"");if(n){const{beforeRun:e,beforeRunAsync:t,afterRun:r,afterRunAsync:s}=n,o=u?s:r,a=u?t:e;if(o){const e=p[d].bind(p);p[d]=(t,r,...n)=>e(t,`${r}\\n${o}`,...n)}if(a){const e=p[d].bind(p);p[d]=(t,r,...n)=>e(t,`${a}\\n${r}`,...n)}}const{CustomEvent:g,document:y}=vt,h=s&&y.getElementById(s)||null,w=e=>Fe(h,i||a,e,!0,g);let m="";return p.registerJSModule(f,"polyscript",{xworker:Et,get target(){return!m&&h&&("SCRIPT"===o?h.after(Ae(y.createElement(`script-${i||a}`),{id:m=`${s}-target`})):(m=s,h.replaceChildren(),h.style.display="block")),m}}),gt=p.runEvent.bind(p,f),yt=p.transform.bind(p,f),h&&w("ready"),await p[d](f,r),h&&w("done"),f}catch(e){postMessage(e)}})(),ht("error"),ht("message"),ht("messageerror")}));\n'],{type:"application/javascript"})),{type:"module"}),{postMessage:s}=n,o=this instanceof Pt;if(e.length){const[t,n]=e;(r=We({},r||{type:t,version:n})).type||(r.type=t)}const[a]=Et(r.config),i=fetch(t).then(Pe).then((e=>{const t=o?this.stringHooks:void 0;s.call(n,{options:r,config:a,code:e,hooks:t})}));return Ie(n,{postMessage:{value:(e,...t)=>i.then((()=>s.call(n,e,...t)))},sync:{value:$e(n,d).proxy},onerror:{writable:!0,configurable:!0,value:console.error}}),o&&this.onWorkerReady?.(this.interpreter,n),n.addEventListener("message",(e=>{const{data:t}=e;t instanceof Error&&(e.stopImmediatePropagation(),n.onerror(Object.create(e,{type:{value:"error"},error:{value:t}})))})),n};const Mt="Invalid content",jt="Invalid worker attribute",Tt="Invalid worker attribute";var Rt=e=>{const{src:t,worker:r}=e.attributes;if(r){let{value:s}=r;if(s)throw new SyntaxError(Tt);if(s=t?.value,!s){if(t)throw new SyntaxError(jt);if(e.childElementCount){const{innerHTML:t,localName:r,type:o}=e,a=o||r.replace(/-script$/,"");n=t,s=je.call(n,Te,_e),console.warn(`Deprecated: use <script type="${a}"> for an always safe content parsing:\n`,s)}else s=e.textContent;return URL.createObjectURL(new Blob([Me(s)],{type:"text/plain"}))}return s}var n;if(t&&e.textContent.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*(?:\/\/|#).*/gm,"").trim())throw new SyntaxError(Mt)};const _t=(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)},Ot=new WeakMap,Wt={get(){let e=Ot.get(this);return e||(e=document.createElement(`${this.type}-script`),Ot.set(this,e),Jt(this)),e},set(e){"string"==typeof e?Ot.set(this,_t(this,e)):(Ot.set(this,e),Jt(this))}},Ft=new WeakMap,It=new Map,Bt=(e,t)=>{const r=e?.value;return r?t+r:""},Lt=(e,t,r,n,s,o=e)=>{if(!It.has(t)){const a={interpreter:$t(r,s),queue:Ce(),XWorker:xt(e,n)};It.set(t,a),It.has(e)||It.set(e,a),It.has(o)||It.set(o,a)}return It.get(t)},Jt=async e=>{if(Ft.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=At(i,c);let u=Bt(r,"|");const f=Bt(n,"")||`${l}${u}`;u=u.slice(1);const p=Rt(e);if(p){const r=new(xt(i,c))(p,{...De(e,i),async:!!t,config:u});return void Ft.set(Be(e,"xworker",{value:r}),{xworker:r})}const d=Bt(s,""),h=Lt(i,f,l,c,u);Ft.set(Be(e,"target",Wt),h),d&&Ot.set(e,_t(e,d));const g=a?fetch(a).then(Pe):e.textContent;h.queue=h.queue.then((()=>(async(e,t,r,n)=>{const{type:s}=e,o=gt.get(s);o.experimental&&console.warn(`The ${s} interpreter is experimental`);const[a,i]=await Je([Ft.get(e).interpreter,t]);try{Be(document,"currentScript",{configurable:!0,get:()=>e}),o.registerJSModule(a,"polyscript",{XWorker:r}),Ue(e,s,"ready");const t=o[n?"runAsync":"run"](a,i),c=Ue.bind(null,e,s,"done");return n?t.then(c):c(),t}finally{delete document.currentScript}})(e,g,h.XWorker,!!t)))}},Ct=new Proxy(Fe(null),{get:(e,t)=>new Promise(queueMicrotask).then((()=>Ht(t)))}),Ht=async e=>{if(It.has(e)){const{interpreter:t,queue:r}=It.get(e);return(await Je([t,r]))[0]}const t=It.size?`Available interpreters are: ${[...It.keys()].map((e=>`"${e}"`)).join(", ")}.`:"There are no interpreters in this page.";throw new Error(`The interpreter "${e}" was not found. ${t}`)},Nt=async e=>{const{type:r,currentTarget:n}=e;if(mt.length)for(let{name:s,value:o,ownerElement:a}of t(`./@*[${mt.map((e=>`name()="${e}${r}"`)).join(" or ")}]`,n)){s=s.slice(0,-(r.length+1));const t=await Ht(a.getAttribute(`${s}-env`)||s);gt.get(s).runEvent(t,o,e)}},Dt=e=>{if(mt.length)for(let{name:r,ownerElement:n}of t(`.//@*[${mt.map((e=>`starts-with(name(),"${e}")`)).join(" or ")}]`,e)){const e=r.lastIndexOf("-"),t=r.slice(e+1);"env"!==t&&(n.addEventListener(t,Nt),"disabled"in n&&!n.disabled&&(n.disabled=!0,Ct[r.slice(0,e)].then((()=>{n.disabled=!1}))))}};var Ut=xt();const Xt=[],qt=new Map,zt=new Map,Yt=e=>{for(const t of Xt)if(e.matches(t)){const r=qt.get(t),{resolve:n}=zt.get(r),{options:s,known:o}=Gt.get(r);if(!o.has(e)){o.add(e);const{interpreter:t,config:a,version:i,env:c,onInterpreterReady:l,onerror:u}=s;let f;try{const o=Rt(e);if(o){const c=Ut.call(new Pt(null,s),o,{...De(e,r),version:i,type:t,custom:r,config:e.getAttribute("config")||a||{},async:e.hasAttribute("async")});return Be(e,"xworker",{value:c}),void n({type:r,xworker:c})}}catch(e){f=e}const p=At(t,i),d=c||`${p}${a?`|${a}`:""}`,{interpreter:h,XWorker:g}=Lt(r,d,p,i,a,t);h.then((o=>{const a=Fe(gt.get(t)),{onBeforeRun:i,onBeforeRunAsync:c,onAfterRun:d,onAfterRunAsync:h}=s,y=new Pt(o,s),w=function(...e){return g.apply(y,e)};for(const[t,[r,n]]of[["run",[i,d]]]){const s=a[t];a[t]=function(t,o,...a){r&&r.call(this,m,e);const i=s.call(this,t,o,...a);return n&&n.call(this,m,e),i}}for(const[t,[r,n]]of[["runAsync",[c,h]]]){const s=a[t];a[t]=async function(t,o,...a){r&&await r.call(this,m,e);const i=await s.call(this,t,o,...a);return n&&await n.call(this,m,e),i}}a.registerJSModule(o,"polyscript",{XWorker:w});const m={type:r,interpreter:o,XWorker:w,io:Xe.get(o),config:structuredClone(yt.get(p)),run:a.run.bind(a,o),runAsync:a.runAsync.bind(a,o),runEvent:a.runEvent.bind(a,o)};n(m),f&&u?.(f,e),l?.(m,e)}))}}},Gt=new Map;let Vt=0;const Kt=e=>(zt.has(e)||zt.set(e,Promise.withResolvers()),zt.get(e).promise),[{define:Qt,whenDefined:Zt,env:er,Hook:tr,XWorker:rr},nr]=((e,t,r=globalThis)=>{const n=Symbol.for(e),s=n in r;return[s?r[n]:Object.defineProperty(r,n,{value:t})[n],s]})("polyscript",{define:(t,r)=>{let n=null==t;if(n)t="_ps"+Vt++;else if(gt.has(t)||Gt.has(t))throw new Error(`<script type="${t}"> already registered`);if(!gt.has(r?.interpreter))throw new Error("Unspecified interpreter");gt.set(t,gt.get(r.interpreter));const s=[`script[type="${t}"]`];if(Kt(t),n){const{onInterpreterReady:e}=r;r={...r,onInterpreterReady(r,n){Xt.splice(Xt.indexOf(t),1),gt.delete(t),Gt.delete(t),zt.delete(t),n.remove(),e?.(r)}},document.head.append(We(document.createElement("script"),{type:t}))}else s.push(`${t}-script`),mt.push(`${t}-`);for(const e of s)qt.set(e,t);Xt.push(...s),Gt.set(t,{options:We({env:t},r),known:new WeakSet}),n||Dt(document),e(s.join(",")).forEach(Yt)},whenDefined:Kt,env:Ct,Hook:Pt,XWorker:Ut});if(!nr){const t=new MutationObserver((e=>{const t=wt.join(",");for(const{type:n,target:s,attributeName:o,addedNodes:a}of e)if("attributes"!==n)for(const e of a)1===e.nodeType&&(Dt(e),t&&e.matches(t)?Jt(e):r(t,e,!0));else{const e=o.lastIndexOf("-")+1;if(e){const t=o.slice(0,e);for(const r of mt)if(t===r){const t=o.slice(e);if("env"!==t){const e=s.hasAttribute(o)?"add":"remove";s[`${e}EventListener`](t,Nt)}break}}}})),r=(t,r,n)=>{t&&e(t,r).forEach(Jt),(t=Xt.join(","))&&(n&&Yt(r),e(t,r).forEach(Yt))},n=e=>(t.observe(e,{childList:!0,subtree:!0,attributes:!0}),e),{attachShadow:s}=Element.prototype;We(Element.prototype,{attachShadow(e){return n(s.call(this,e))}}),queueMicrotask((()=>{Dt(n(document)),r(wt.join(","),document,!1)}))}export{tr as Hook,Mt as INVALID_CONTENT,jt as INVALID_SRC_ATTR,Tt as INVALID_WORKER_ATTR,rr as XWorker,Qt as define,er as env,Zt as whenDefined}; | ||
//# sourceMappingURL=core.js.map |
@@ -0,5 +1,6 @@ | ||
import stickyModule from 'sticky-module'; | ||
import { $$ } from 'basic-devtools'; | ||
import { handle } from './script-handler.js'; | ||
import { assign, defineProperty } from './utils.js'; | ||
import { assign } from './utils.js'; | ||
import { selectors, prefixes } from './interpreters.js'; | ||
@@ -14,25 +15,22 @@ import { CUSTOM_SELECTORS, handleCustomType } from './custom.js'; | ||
const polyscript = Symbol.for('polyscript'); | ||
const alreadyLive = polyscript in globalThis; | ||
// avoid multiple initialization of the same library | ||
/* c8 ignore start */ | ||
const { define, whenDefined, env, Hook, XWorker } = ( | ||
alreadyLive ? | ||
globalThis[polyscript] : | ||
defineProperty( | ||
globalThis, | ||
polyscript, | ||
{ | ||
value: { | ||
define: $define, | ||
whenDefined: $whenDefined, | ||
env: $env, | ||
Hook: $Hook, | ||
XWorker: $XWorker | ||
} | ||
} | ||
)[polyscript] | ||
const [ | ||
{ | ||
define, | ||
whenDefined, | ||
env, | ||
Hook, | ||
XWorker | ||
}, | ||
alreadyLive | ||
] = stickyModule( | ||
'polyscript', | ||
{ | ||
define: $define, | ||
whenDefined: $whenDefined, | ||
env: $env, | ||
Hook: $Hook, | ||
XWorker: $XWorker | ||
} | ||
); | ||
/* c8 ignore stop */ | ||
@@ -39,0 +37,0 @@ export { define, whenDefined, env, Hook, XWorker }; |
{ | ||
"name": "polyscript", | ||
"version": "0.4.14", | ||
"version": "0.4.15", | ||
"description": "PyScript single core to rule them all", | ||
@@ -76,3 +76,4 @@ "main": "./cjs/index.js", | ||
"coincident": "^0.13.5", | ||
"html-escaper": "^3.0.3" | ||
"html-escaper": "^3.0.3", | ||
"sticky-module": "^0.1.0" | ||
}, | ||
@@ -79,0 +80,0 @@ "worker": { |
Sorry, the diff of this file is not supported yet
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
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
395813
82
3251
7
7
+ Addedsticky-module@^0.1.0
+ Addedsticky-module@0.1.1(transitive)