@pyscript/core 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +4 -0
  2. package/cjs/custom.js +3 -1
  3. package/cjs/interpreter/_python.js +8 -0
  4. package/cjs/interpreter/_utils.js +11 -1
  5. package/cjs/interpreter/micropython.js +10 -1
  6. package/cjs/interpreter/pyodide.js +4 -0
  7. package/cjs/interpreter/ruby-wasm-wasi.js +11 -1
  8. package/cjs/interpreter/wasmoon.js +12 -1
  9. package/cjs/listeners.js +2 -6
  10. package/cjs/script-handler.js +1 -2
  11. package/cjs/utils.js +2 -1
  12. package/cjs/worker/xworker.js +1 -1
  13. package/core.js +1 -1
  14. package/dev.cjs +33 -0
  15. package/docs/README.md +15 -36
  16. package/esm/custom.js +3 -1
  17. package/esm/interpreter/_python.js +6 -0
  18. package/esm/interpreter/_utils.js +10 -1
  19. package/esm/interpreter/micropython.js +10 -1
  20. package/esm/interpreter/pyodide.js +4 -0
  21. package/esm/interpreter/ruby-wasm-wasi.js +14 -1
  22. package/esm/interpreter/wasmoon.js +12 -1
  23. package/esm/listeners.js +2 -6
  24. package/esm/script-handler.js +1 -2
  25. package/esm/utils.js +2 -1
  26. package/esm/worker/xworker.js +1 -1
  27. package/package.json +4 -2
  28. package/pyscript.js +1 -1
  29. package/types/coincident/window.d.ts +6 -6
  30. package/types/pyscript/pyscript.core/esm/interpreter/_python.d.ts +2 -0
  31. package/types/pyscript/pyscript.core/esm/interpreter/_utils.d.ts +1 -0
  32. package/types/pyscript/pyscript.core/esm/interpreter/micropython.d.ts +4 -0
  33. package/types/pyscript/pyscript.core/esm/interpreter/pyodide.d.ts +4 -0
  34. package/types/pyscript/pyscript.core/esm/interpreter/ruby-wasm-wasi.d.ts +3 -0
  35. package/types/pyscript/pyscript.core/esm/interpreter/wasmoon.d.ts +3 -0
  36. package/types/pyscript/pyscript.core/esm/utils.d.ts +6 -0
package/docs/README.md CHANGED
@@ -229,11 +229,11 @@ Please read the [Terminology](#terminology) **target** dedicated details to know
229
229
  <summary><strong>XWorker</strong></summary>
230
230
  <div>
231
231
 
232
- With or without access to the `document`, every (*non experimental*) interpreter will have defined, at the global level, a reference to the `XWorker` "_class_" (it's just a *function*!), which goal is to enable off-loading heavy operations on a worker, without blocking the main / UI thread (the current page) and allowing such worker to even reach the `document` or anything else available on the very same main / UI thread.
232
+ With or without access to the `document`, every (*non experimental*) interpreter will have defined, either at the global level or after an import (i.e.`from xworker import XWorker` in *Python* case), a reference to the `XWorker` "_class_" (it's just a *function*!), which goal is to enable off-loading heavy operations on a worker, without blocking the main / UI thread (the current page) and allowing such worker to even reach the `document` or anything else available on the very same main / UI thread.
233
233
 
234
234
  ```html
235
235
  <script type="micropython">
236
- # XWorker is globally defined
236
+ from xworker import XWorker
237
237
  print(XWorker != None)
238
238
  </script>
239
239
  ```
@@ -246,40 +246,19 @@ Please read the [XWorker](#xworker) dedicated section to know more.
246
246
 
247
247
  ## How Events Work
248
248
 
249
- Inspired by the current [HTML Standard](https://html.spec.whatwg.org/multipage/webappapis.html#event-handlers):
250
-
251
- > the event handler is exposed through a name, which is a string that always starts with "_on_" and is followed by the name of the event for which the handler is intended.
252
-
253
- We took a similar approach, replacing that `on` prefix with whatever *interpreter* or *custom type* is available on the page, plus a *dash* `-` to avoid clashing with standards:
249
+ The event should contain the *interpreter* or *custom type* prefix, followed by the *event* type it'd like to handle.
254
250
 
255
251
  ```html
256
252
  <script type="micropython">
257
- def print_type(event, double):
258
- # logs "click 4"
259
- print(f"{event.type} {double(2)}")
253
+ def print_type(event):
254
+ print(event.type)
260
255
  </script>
261
- <button micropython-click="print_type(event, lambda x: x * 2)">
262
- print type
263
- </button>
264
- ```
265
-
266
- If this example felt a bit verbose, be ensured custom types would work the same:
267
-
268
- ```html
269
- <!-- ℹ️ - requires py-script custom type -->
270
- <button py-click="print(event.type)">
256
+ <button micropython-click="print_type">
271
257
  print type
272
258
  </button>
273
259
  ```
274
260
 
275
- What is important to understand about *events* in PyScript is that the text within the attribute is executed just like any other inline or external content is, through the very same *interpreter*, with the notably extra feature that the `event` reference is made temporarily available as *global* by *core*.
276
-
277
- This really reflects how otherwise native Web inline events handlers work and we think it's a great feature to support ... *but*:
278
-
279
- * if your script runs *asynchronously* the `event` might be gone on the main / UI thread and by that time any of its `event.stopPropagation()` or `event.preventDefault()` goodness will be problematic, as too late to be executed
280
- * if your *interpreter* is *experimental*, or incapable of running *synchronous* events, the `event` reference might be less useful
281
-
282
- ℹ️ - Please note that if your code runs via *XWorker*, hence in a different thread, there are different caveats and constraints to consider. Please read the [XWorker](#xworker) dedicated section to know more.
261
+ Differently from *Web* inline events, there's no code evaluation at all within the attribute: it's just a globally available name that will receive the current event and nothing else.
283
262
 
284
263
  #### The type-env attribute
285
264
 
@@ -299,7 +278,7 @@ Just as the `env` attribute on a `<script>` tag specifies a specific instance of
299
278
  <!-- note the micropython-env value -->
300
279
  <button
301
280
  micropython-env="two"
302
- micropython-click="log()"
281
+ micropython-click="log"
303
282
  >
304
283
  log
305
284
  </button>
@@ -314,9 +293,9 @@ Whenever computing relatively expensive stuff, such as a *matplot* image, or lit
314
293
 
315
294
  `@pyscript/core` adds a functionality called `XWorker` to all of the interpreters it offers, which works in each language the way `Worker` does in JavaScript.
316
295
 
317
- In each Interpreter, `XWorker` is a global reference, with a counter `xworker` (lower case) global reference within the worker code.
296
+ In each Interpreter, `XWorker` is either global reference or an import (i.e.`from xworker import XWorker` in *Python* case) module's utility, with a counter `xworker` (lower case) global reference, or an import (i.e.`from xworker import xworker` in *Python* case) module's utility, within the worker code.
318
297
 
319
- In short, the `XWorker` global goal is to help, without much thinking, to run any desired interpreter out of a *Worker*, enabling extra features on the *worker*'s code side.
298
+ In short, the `XWorker` utility is to help, without much thinking, to run any desired interpreter out of a *Worker*, enabling extra features on the *worker*'s code side.
320
299
 
321
300
 
322
301
  ### Enabling XWorker
@@ -348,7 +327,7 @@ The returning *JS* reference to any `XWorker(...)` call is literally a `Worker`
348
327
 
349
328
  | name | example | behavior |
350
329
  | :-------- | :--------------------------------- | :--------|
351
- | sync | `sync = XWorker('./file.py').sync` | Allows exposure of callbacks that can be run synchronously from the worker file, even if the defined callback is *asynchronous*. This property is also available in the global `xworker` reference. |
330
+ | sync | `sync = XWorker('./file.py').sync` | Allows exposure of callbacks that can be run synchronously from the worker file, even if the defined callback is *asynchronous*. This property is also available in the `xworker` reference. |
352
331
 
353
332
  ```python
354
333
 
@@ -370,9 +349,9 @@ In the `xworker` counter part:
370
349
  xworker.sync.from_main(1, "two")
371
350
  ```
372
351
 
373
- ### The xworker global reference
352
+ ### The xworker reference
374
353
 
375
- The content of the file used to initialize any `XWorker` on the main thread can always reach the `xworker` counter part as globally available (that means: no *import ... form ...* is necessary, it is already there).
354
+ The content of the file used to initialize any `XWorker` on the main thread can always reach the `xworker` counter part as globally available or as import (i.e.`from xworker import xworker` in *Python* case) module's utility.
376
355
 
377
356
  Within a *Worker* execution context, the `xworker` exposes the following features:
378
357
 
@@ -380,7 +359,7 @@ Within a *Worker* execution context, the `xworker` exposes the following feature
380
359
  | :------------ | :------------------------------------------| :--------|
381
360
  | sync | `xworker.sync.from_main(1, "two")` | Executes the exposed `from_main` function in the main thread. Returns synchronously its result, if any. |
382
361
  | window | `xworker.window.document.title = 'Worker'` | Differently from *pyodide* or *micropython* `import js`, this field allows every single possible operation directly in the main thread. It does not refer to the local `js` environment the interpreter might have decided to expose, it is a proxy to handle otherwise impossible operations in the main thread, such as manipulating the *DOM*, reading `localStorage` otherwise not available in workers, change location or anything else usually possible to do in the main thread. |
383
- | isWindowProxy | `xworker.isWindowProxy(ref)` | **Advanced** - Allows introspection of *JS* references, helping differentiating between local worker references, and main thread global references. This is valid both for non primitive objects (array, dictionaries) as well as functions, as functions are also enabled via `xworker.window` in both ways: we can add a listener from the worker or invoke a function in the main. Please note that functions passed to the main thread will always be invoked asynchronously.
362
+ | isWindowProxy | `xworker.isWindowProxy(ref)` | **Advanced** - Allows introspection of *JS* references, helping differentiating between local worker references, and main thread global JS references. This is valid both for non primitive objects (array, dictionaries) as well as functions, as functions are also enabled via `xworker.window` in both ways: we can add a listener from the worker or invoke a function in the main. Please note that functions passed to the main thread will always be invoked asynchronously.
384
363
 
385
364
  ```python
386
365
  print(xworker.window.document.title)
@@ -472,7 +451,7 @@ In few words, while every *interpreter* is literally passed along to unlock its
472
451
  | :------------------------ | :-------------------------------------------- | :--------|
473
452
  | type | `wrap.type` | Return the current `type` (interpreter or custom type) used in the current code execution. |
474
453
  | interpreter | `wrap.interpreter` | Return the *interpreter* _AS-IS_ after being bootstrapped by the desired `config`. |
475
- | XWorker | `wrap.XWorker` | Refer to the global `XWorker` class available to the main thread code while executing. |
454
+ | XWorker | `wrap.XWorker` | Refer to the `XWorker` class available to the main thread code while executing. |
476
455
  | io | `wrap.io` | Allow to lazily define different `stdout` or `stderr` via the running *interpreter*. This `io` field can be lazily defined and restored back for any element currently running the code. |
477
456
  | config | `wrap.config` | It is the resolved *JSON* config and it is an own clone per each element running the code, usable also as "_state_" reference for the specific element, as changing it at run time will never affect any other element. |
478
457
  | run | `wrap.run(code)` | It abstracts away the need to know the exact method name used to run code synchronously, whenever the *interpreter* allows such operation, facilitating future migrations from an interpreter to another. |
package/esm/custom.js CHANGED
@@ -107,7 +107,9 @@ export const handleCustomType = (node) => {
107
107
  };
108
108
  }
109
109
 
110
- module.setGlobal(interpreter, "XWorker", XWorker);
110
+ module.registerJSModule(interpreter, "xworker", {
111
+ XWorker,
112
+ });
111
113
 
112
114
  const resolved = {
113
115
  type,
@@ -7,6 +7,8 @@ export const run = (interpreter, code) => interpreter.runPython(clean(code));
7
7
  export const runAsync = (interpreter, code) =>
8
8
  interpreter.runPythonAsync(clean(code));
9
9
 
10
+ export const getGlobal = (interpreter, name) => interpreter.globals.get(name);
11
+
10
12
  export const setGlobal = (interpreter, name, value) => {
11
13
  interpreter.globals.set(name, value);
12
14
  };
@@ -15,6 +17,10 @@ export const deleteGlobal = (interpreter, name) => {
15
17
  interpreter.globals.delete(name);
16
18
  };
17
19
 
20
+ export const registerJSModule = (interpreter, name, value) => {
21
+ interpreter.registerJsModule(name, value);
22
+ };
23
+
18
24
  export const writeFile = ({ FS }, path, buffer) =>
19
25
  writeFileUtil(FS, path, buffer);
20
26
  /* c8 ignore stop */
@@ -1,7 +1,7 @@
1
1
  import "@ungap/with-resolvers";
2
2
 
3
3
  import { getBuffer } from "../fetch-utils.js";
4
- import { absoluteURL } from "../utils.js";
4
+ import { absoluteURL, entries } from "../utils.js";
5
5
 
6
6
  /**
7
7
  * Trim code only if it's a single line that prettier or other tools might have modified.
@@ -131,3 +131,12 @@ export const fetchPaths = (module, interpreter, config_fetch) =>
131
131
  .then((buffer) => module.writeFile(interpreter, path, buffer)),
132
132
  ),
133
133
  );
134
+
135
+ // this is a fallback for interpreters unable to register JS modules
136
+ // all defined keys will end up as globally available references
137
+ // REQUIRES INTEGRATION TEST
138
+ /* c8 ignore start */
139
+ export function registerJSModule(interpreter, _, value) {
140
+ for (const [k, v] of entries(value)) this.setGlobal(interpreter, k, v);
141
+ }
142
+ /* c8 ignore stop */
@@ -1,5 +1,12 @@
1
1
  import { fetchPaths, stdio } from "./_utils.js";
2
- import { run, setGlobal, deleteGlobal, writeFile } from "./_python.js";
2
+ import {
3
+ run,
4
+ getGlobal,
5
+ setGlobal,
6
+ deleteGlobal,
7
+ registerJSModule,
8
+ writeFile,
9
+ } from "./_python.js";
3
10
 
4
11
  const type = "micropython";
5
12
 
@@ -16,8 +23,10 @@ export default {
16
23
  if (config.fetch) await fetchPaths(this, interpreter, config.fetch);
17
24
  return interpreter;
18
25
  },
26
+ getGlobal,
19
27
  setGlobal,
20
28
  deleteGlobal,
29
+ registerJSModule,
21
30
  run,
22
31
  // TODO: MicroPython doesn't have a Pyodide like top-level await,
23
32
  // this method should still not throw errors once invoked
@@ -2,8 +2,10 @@ import { fetchPaths, stdio } from "./_utils.js";
2
2
  import {
3
3
  run,
4
4
  runAsync,
5
+ getGlobal,
5
6
  setGlobal,
6
7
  deleteGlobal,
8
+ registerJSModule,
7
9
  writeFile,
8
10
  } from "./_python.js";
9
11
 
@@ -30,8 +32,10 @@ export default {
30
32
  }
31
33
  return interpreter;
32
34
  },
35
+ getGlobal,
33
36
  setGlobal,
34
37
  deleteGlobal,
38
+ registerJSModule,
35
39
  run,
36
40
  runAsync,
37
41
  writeFile,
@@ -1,4 +1,4 @@
1
- import { clean, fetchPaths } from "./_utils.js";
1
+ import { clean, fetchPaths, registerJSModule } from "./_utils.js";
2
2
 
3
3
  const type = "ruby-wasm-wasi";
4
4
 
@@ -23,6 +23,19 @@ export default {
23
23
  if (config.fetch) await fetchPaths(this, interpreter, config.fetch);
24
24
  return interpreter;
25
25
  },
26
+ registerJSModule,
27
+ getGlobal(interpreter, name) {
28
+ try {
29
+ return this.run(interpreter, name);
30
+ } catch (_) {
31
+ const method = this.run(interpreter, `method(:${name})`);
32
+ return (...args) =>
33
+ method.call(
34
+ name,
35
+ ...args.map((value) => interpreter.wrap(value)),
36
+ );
37
+ }
38
+ },
26
39
  setGlobal(interpreter, name, value) {
27
40
  const id = `__pyscript_ruby_wasm_wasi_${name}`;
28
41
  globalThis[id] = value;
@@ -1,7 +1,16 @@
1
- import { clean, fetchPaths, stdio, writeFileShim } from "./_utils.js";
1
+ import {
2
+ clean,
3
+ fetchPaths,
4
+ stdio,
5
+ registerJSModule,
6
+ writeFileShim,
7
+ } from "./_utils.js";
2
8
 
3
9
  const type = "wasmoon";
4
10
 
11
+ // MISSING:
12
+ // * I've no idea how to import packages
13
+
5
14
  // REQUIRES INTEGRATION TEST
6
15
  /* c8 ignore start */
7
16
  export default {
@@ -18,6 +27,8 @@ export default {
18
27
  if (config.fetch) await fetchPaths(this, interpreter, config.fetch);
19
28
  return interpreter;
20
29
  },
30
+ registerJSModule,
31
+ getGlobal: (interpreter, name) => interpreter.global.get(name),
21
32
  setGlobal(interpreter, name, value) {
22
33
  interpreter.global.set(name, value);
23
34
  },
package/esm/listeners.js CHANGED
@@ -41,12 +41,8 @@ export const listener = async (event) => {
41
41
  el.getAttribute(`${name}-env`) || name,
42
42
  );
43
43
  const handler = registry.get(name);
44
- try {
45
- handler.setGlobal(interpreter, "event", event);
46
- handler.run(interpreter, value);
47
- } finally {
48
- handler.deleteGlobal(interpreter, "event");
49
- }
44
+ const callback = handler.getGlobal(interpreter, value);
45
+ callback(event);
50
46
  }
51
47
  };
52
48
 
@@ -58,11 +58,10 @@ const execute = async (script, source, XWorker, isAsync) => {
58
58
  configurable: true,
59
59
  get: () => script,
60
60
  });
61
- module.setGlobal(interpreter, "XWorker", XWorker);
61
+ module.registerJSModule(interpreter, "xworker", { XWorker });
62
62
  return module[isAsync ? "runAsync" : "run"](interpreter, content);
63
63
  } finally {
64
64
  delete document.currentScript;
65
- module.deleteGlobal(interpreter, "XWorker");
66
65
  }
67
66
  };
68
67
 
package/esm/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const { isArray } = Array;
2
2
 
3
- const { assign, create, defineProperties, defineProperty } = Object;
3
+ const { assign, create, defineProperties, defineProperty, entries } = Object;
4
4
 
5
5
  const { all, resolve } = new Proxy(Promise, {
6
6
  get: ($, name) => $[name].bind($),
@@ -14,6 +14,7 @@ export {
14
14
  create,
15
15
  defineProperties,
16
16
  defineProperty,
17
+ entries,
17
18
  all,
18
19
  resolve,
19
20
  absoluteURL,
@@ -1,2 +1,2 @@
1
1
  /* c8 ignore next */
2
- 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))}),p=\"2f6fe6d4-8ba8-424a-83c5-8fadca1ea103\",d=e=>({value:new Promise((t=>{let r=new Worker(\"data:application/javascript,\"+encodeURIComponent(\"onmessage=({data:b})=>(Atomics.wait(b,0),postMessage(0))\"));r.onmessage=t,r.postMessage(e)}))})\n/*! (c) Andrea Giammarchi - ISC */;const{Int32Array:w,Map:y,SharedArrayBuffer:h,Uint16Array:g}=globalThis,{BYTES_PER_ELEMENT:m}=w,{BYTES_PER_ELEMENT:b}=g,{isArray:v}=Array,{notify:P,wait:E,waitAsync:S}=Atomics,{fromCharCode:j}=String,A=(e,t)=>e?(S||d)(t,0):(E(t,0),{value:{then:e=>e()}}),M=new WeakSet,k=new WeakMap;let x=0;const _=(e,{parse:t,stringify:r}=JSON)=>{if(!k.has(e)){const n=(t,...r)=>e.postMessage({[p]:r},{transfer:t});k.set(e,new Proxy(new y,{has:(e,t)=>\"string\"==typeof t&&!t.startsWith(\"_\"),get:(r,s)=>\"then\"===s?null:(...r)=>{const o=x++;let a=new w(new h(m)),i=[];M.has(r.at(-1)||i)&&M.delete(i=r.pop()),n(i,o,a,s,r);const c=e instanceof Worker;return A(c,a).value.then((()=>{const e=a[0];if(!e)return;const r=b*e;return a=new w(new h(r+r%m)),n([],o,a),A(c,a).value.then((()=>t(j(...new g(a.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new y;e.addEventListener(\"message\",(async e=>{const s=e.data?.[p];if(v(s)){e.stopImmediatePropagation();const[o,a,...i]=s;if(i.length){const[e,s]=i;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);{const i=r(await t.get(e)(...s));i&&(n.set(o,i),a[0]=i.length)}}else{const e=n.get(o);n.delete(o);for(let t=new g(a.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}P(a,0)}}))}return!!t.set(n,s)}}))}return k.get(e)};_.transfer=(...e)=>(M.add(e),e);const $=\"object\",O=\"function\",W=\"number\",R=\"string\",T=\"undefined\",F=\"symbol\",{defineProperty:B,getOwnPropertyDescriptor:I,getPrototypeOf:G,isExtensible:L,ownKeys:U,preventExtensions:N,set:z,setPrototypeOf:D}=Reflect,J=G(Int8Array),C=(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],K=e=>t=>{const r=typeof t;switch(r){case $:if(null==t)return q(\"null\",t);case O:return e(r,t);case\"boolean\":case W:case R:case T:case\"bigint\":return q(r,t);case F:if(Y.has(t))return q(r,Y.get(t))}throw new Error(`Unable to handle this ${r} type`)},Y=new Map(U(Symbol).filter((e=>typeof Symbol[e]===F)).map((e=>[Symbol[e],e]))),V=e=>{for(const[t,r]of Y)if(r===e)return t},H=\"apply\",Q=\"construct\",X=\"defineProperty\",Z=\"deleteProperty\",ee=\"get\",te=\"getOwnPropertyDescriptor\",re=\"getPrototypeOf\",ne=\"has\",se=\"isExtensible\",oe=\"ownKeys\",ae=\"preventExtensions\",ie=\"set\",ce=\"setPrototypeOf\",le=\"delete\";let ue=0;const fe=new Map,pe=new Map,de=new WeakMap;if(globalThis.window===globalThis){const{addEventListener:e}=EventTarget.prototype;B(EventTarget.prototype,\"addEventListener\",{value(t,r,...n){return n.at(0)?.invoke&&(de.has(this)||de.set(this,new Map),de.get(this).set(t,[].concat(n[0].invoke)),delete n[0].invoke),e.call(this,t,r,...n)}})}const we=K(((e,t)=>{if(!fe.has(t)){let e;for(;pe.has(e=ue++););fe.set(t,e),pe.set(e,t)}return q(e,fe.get(t))}));var ye=(e,t,r)=>{const{[r]:n}=e,s=new FinalizationRegistry((e=>{n(le,q(R,e))})),o=([e,t])=>{switch(e){case $:if(null==t)return globalThis;if(typeof t===W)return pe.get(t);if(!(t instanceof J))for(const e in t)t[e]=o(t[e]);return t;case O:if(typeof t===R){if(!pe.has(t)){const e=function(...e){return e.at(0)instanceof Event&&(e=>{const{currentTarget:t,target:r,type:n}=e;for(const s of de.get(t||r)?.get(n)||[])e[s]()})(...e),n(H,q(O,t),we(this),e.map(we))},r=new WeakRef(e);pe.set(t,r),s.register(e,t,r)}return pe.get(t).deref()}return pe.get(t);case F:return V(t)}return t},a={[H]:(e,t,r)=>we(e.apply(t,r)),[Q]:(e,t)=>we(new e(...t)),[X]:(e,t,r)=>we(B(e,t,r)),[Z]:(e,t)=>we(delete e[t]),[re]:e=>we(G(e)),[ee]:(e,t)=>we(e[t]),[te]:(e,t)=>{const r=I(e,t);return r?q($,C(r,we)):q(T,r)},[ne]:(e,t)=>we(t in e),[se]:e=>we(L(e)),[oe]:e=>q($,U(e).map(we)),[ae]:e=>we(N(e)),[ie]:(e,t,r)=>we(z(e,t,r)),[ce]:(e,t)=>we(D(e,t)),[le](e){fe.delete(pe.get(e)),pe.delete(e)}};return e[t]=(e,t,...r)=>{switch(e){case H:r[0]=o(r[0]),r[1]=r[1].map(o);break;case Q:r[0]=r[0].map(o);break;case X:{const[e,t]=r;r[0]=o(e);const{get:n,set:s,value:a}=t;n&&(t.get=o(n)),s&&(t.set=o(s)),a&&(t.value=o(a));break}default:r=r.map(o)}return a[e](o(t),...r)},{proxy:e,window:globalThis,isWindowProxy:()=>!1}};let he=0;const ge=new Map,me=new Map,be=Symbol(),ve=e=>typeof e===O?e():e,Pe=e=>typeof e===$&&!!e&&be in e,Ee=\"isArray\",Se=Array[Ee],je=K(((e,t)=>{if(be in t)return ve(t[be]);if(e===O){if(!me.has(t)){let e;for(;me.has(e=String(he++)););ge.set(t,e),me.set(e,t)}return q(e,ge.get(t))}if(!(t instanceof J))for(const e in t)t[e]=je(t[e]);return q(e,t)}));var Ae=(e,t,r)=>{const{[t]:n}=e,s=new Map,o=new FinalizationRegistry((e=>{s.delete(e),n(le,je(e))})),a=e=>{const[t,r]=e;if(!s.has(r)){const n=t===O?Me.bind(e):e,a=new Proxy(n,l),i=new WeakRef(a);s.set(r,i),o.register(a,r,i)}return s.get(r).deref()},i=e=>{const[t,r]=e;switch(t){case $:return typeof r===W?a(e):r;case O:return typeof r===R?me.get(r):a(e);case F:return V(r)}return r},c=(e,t,...r)=>i(n(e,ve(t),...r)),l={[H]:(e,t,r)=>c(H,e,je(t),r.map(je)),[Q]:(e,t)=>c(Q,e,t.map(je)),[X]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===O&&(r.get=je(n)),typeof s===O&&(r.set=je(s)),typeof o===O&&(r.value=je(o)),c(X,e,je(t),r)},[Z]:(e,t)=>c(Z,e,je(t)),[re]:e=>c(re,e),[ee]:(e,t)=>t===be?e:c(ee,e,je(t)),[te]:(e,t)=>{const r=c(te,e,je(t));return r&&C(r,i)},[ne]:(e,t)=>t===be||c(ne,e,je(t)),[se]:e=>c(se,e),[oe]:e=>c(oe,e).map(i),[ae]:e=>c(ae,e),[ie]:(e,t,r)=>c(ie,e,je(t),je(r)),[ce]:(e,t)=>c(ce,e,je(t))};e[r]=(e,t,r,n)=>{switch(e){case H:return i(t).apply(i(r),n.map(i));case le:{const e=i(t);ge.delete(me.get(e)),me.delete(e)}}};const u=new Proxy([$,null],l),f=u.Array[Ee];return B(Array,Ee,{value:e=>Pe(e)?f(e):Se(e)}),{window:u,isWindowProxy:Pe,proxy:e,get global(){return console.warn(\"Deprecated: please access `window` field instead\"),this.window},get isGlobal(){return function(e){return console.warn(\"Deprecated: please access `isWindowProxy` field instead\"),this.isWindowProxy(e)}.bind(this)}}};function Me(){return this}const ke=p+\"M\",xe=p+\"T\",_e=new WeakMap,$e=(e,...t)=>{const r=_(e,...t);if(!_e.has(r)){const t=e instanceof Worker?ye:Ae;_e.set(r,t(r,ke,xe))}return _e.get(r)};$e.transfer=_.transfer;const{isArray:Oe}=Array,{assign:We,create:Re,defineProperties:Te,defineProperty:Fe}=Object,{all:Be,resolve:Ie}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Ge=(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 Le=e=>e.arrayBuffer(),Ue=e=>e.json(),Ne=e=>e.text(),ze=e=>e.replace(/^[^\\r\\n]+$/,(e=>e.trim())),De=new WeakMap,Je=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}}},Ce=e=>{const t=e.split(\"/\");return t.pop(),t.join(\"/\")},qe=(e,t)=>{const r=[];for(const n of t.split(\"/\"))r.push(n),n&&e.mkdir(r.join(\"/\"))},Ke=(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},Ve=new WeakMap,He=(e,t,r)=>Be((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: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(Ge(t,Ve.get(e))))(r,n).then(Le).then((r=>e.writeFile(t,s,r)))))),Qe=(e,t)=>e.runPython(ze(t)),Xe=(e,t,r)=>{e.globals.set(t,r)},Ze=(e,t)=>{e.globals.delete(t)},et=({FS:e},t,r)=>((e,t,r)=>{const{parentPath:n,name:s}=e.analyzePath(t,!0);return e.mkdirTree(n),e.writeFile([n,s].join(\"/\"),new Uint8Array(r),{canOwn:!0})})(e,t,r);var tt={type:\"micropython\",module:(e=\"1.20.0-268\")=>`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}=Je();r=r.replace(/\\.m?js$/,\".wasm\");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await He(this,a,t.fetch),a},setGlobal:Xe,deleteGlobal:Ze,run:Qe,async runAsync(...e){return this.run(...e)},writeFile:et};var rt={type:\"pyodide\",module:(e=\"0.23.2\")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Je(),a=r.slice(0,r.lastIndexOf(\"/\")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(t.fetch&&await He(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},setGlobal:Xe,deleteGlobal:Ze,run:Qe,runAsync:(e,t)=>e.runPythonAsync(ze(t)),writeFile:et};const nt=\"ruby-wasm-wasi\";var st={type:nt,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 He(this,o,t.fetch),o},setGlobal(e,t,r){const n=`__pyscript_ruby_wasm_wasi_${t}`;globalThis[n]=r,this.run(e,`require \"js\";$${t}=JS::eval(\"return ${n}\")`)},deleteGlobal(e,t){const r=`__pyscript_ruby_wasm_wasi_${t}`;this.run(e,`$${t}=nil`),delete globalThis[r]},run:(e,t)=>e.eval(ze(t)),runAsync:(e,t)=>e.evalAsync(ze(t)),writeFile:()=>{throw new Error(`writeFile is not supported in ${nt}`)}};var ot={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}=Je(),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 He(this,a,r.fetch),a},setGlobal(e,t,r){e.global.set(t,r)},deleteGlobal(e,t){e.global.set(t,void 0)},run:(e,t)=>e.doStringSync(ze(t)),runAsync:(e,t)=>e.doString(ze(t)),writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(t=Ke(e,t),qe(e,Ce(t)),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const at=new Map,it=new Map,ct=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split(\"@\"),s=at.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=>{it.set(t,e);const a=e?.fetch;return a&&Ve.set(a,o),s(n,e,r)}))}}),lt=e=>{for(const t of[].concat(e.type))at.set(t,e)};for(const e of[tt,rt,st,ot])lt(e);const ut=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 ft,pt,dt;const wt=(e,t)=>{addEventListener(e,t||(async t=>{await ft,dt=t,pt(`xworker.on${e}(xworker.event);`,mt)}),!!t&&{once:!0})},{proxy:yt,window:ht,isWindowProxy:gt}=$e(self,f),mt={sync:yt,window:ht,isWindowProxy:gt,onerror(){},onmessage(){},onmessageerror(){},postMessage:postMessage.bind(self),get event(){const e=dt;if(!e)throw new Error(\"Unauthorized event access\");return dt=void 0,e}};wt(\"message\",(({data:{options:e,code:t,hooks:r}})=>{ft=(async()=>{const{type:n,version:s,config:o,async:a}=e,i=await((e,t)=>{let r={};if(t)if(t.endsWith(\".json\"))r=fetch(t).then(Ue);else if(t.endsWith(\".toml\"))r=fetch(t).then(Ne).then(ut);else{try{r=JSON.parse(t)}catch(e){r=ut(t)}t=Ge(\"./config.txt\")}return Ie(r).then((r=>ct[e](r,t)))})(((e,t=\"\")=>`${e}@${t}`.replace(/@$/,\"\"))(n,s),o),c=Re(at.get(n)),l=\"run\"+(a?\"Async\":\"\");if(r){const{beforeRun:e,beforeRunAsync:t,afterRun:n,afterRunAsync:s}=r,o=n||s,a=e||t;if(o){const e=c[l].bind(c);c[l]=(t,r)=>e(t,`${r}\\n${o}`)}if(a){const e=c[l].bind(c);c[l]=(t,r)=>e(t,`${a}\\n${r}`)}}return c.setGlobal(i,\"xworker\",mt),pt=c[l].bind(c,i),pt(t),i})(),wt(\"error\"),wt(\"message\"),wt(\"messageerror\")}));\n"],{type:'application/javascript'})),{type:'module'});
2
+ 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))}),p=\"2f6fe6d4-8ba8-424a-83c5-8fadca1ea103\",d=e=>({value:new Promise((t=>{let r=new Worker(\"data:application/javascript,\"+encodeURIComponent(\"onmessage=({data:b})=>(Atomics.wait(b,0),postMessage(0))\"));r.onmessage=t,r.postMessage(e)}))})\n/*! (c) Andrea Giammarchi - ISC */;const{Int32Array:w,Map:g,SharedArrayBuffer:h,Uint16Array:y}=globalThis,{BYTES_PER_ELEMENT:m}=w,{BYTES_PER_ELEMENT:b}=y,{isArray:v}=Array,{notify:S,wait:M,waitAsync:P}=Atomics,{fromCharCode:E}=String,j=(e,t)=>e?(P||d)(t,0):(M(t,0),{value:{then:e=>e()}}),A=new WeakSet,k=new WeakMap;let x=0;const $=(e,{parse:t,stringify:r}=JSON)=>{if(!k.has(e)){const n=(t,...r)=>e.postMessage({[p]:r},{transfer:t});k.set(e,new Proxy(new g,{has:(e,t)=>\"string\"==typeof t&&!t.startsWith(\"_\"),get:(r,s)=>\"then\"===s?null:(...r)=>{const o=x++;let a=new w(new h(m)),i=[];A.has(r.at(-1)||i)&&A.delete(i=r.pop()),n(i,o,a,s,r);const c=e instanceof Worker;return j(c,a).value.then((()=>{const e=a[0];if(!e)return;const r=b*e;return a=new w(new h(r+r%m)),n([],o,a),j(c,a).value.then((()=>t(E(...new y(a.buffer).slice(0,e)))))}))},set(t,n,s){if(!t.size){const n=new g;e.addEventListener(\"message\",(async e=>{const s=e.data?.[p];if(v(s)){e.stopImmediatePropagation();const[o,a,...i]=s;if(i.length){const[e,s]=i;if(!t.has(e))throw new Error(`Unsupported action: ${e}`);{const i=r(await t.get(e)(...s));i&&(n.set(o,i),a[0]=i.length)}}else{const e=n.get(o);n.delete(o);for(let t=new y(a.buffer),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)}S(a,0)}}))}return!!t.set(n,s)}}))}return k.get(e)};$.transfer=(...e)=>(A.add(e),e);const _=\"object\",O=\"function\",W=\"number\",R=\"string\",T=\"undefined\",F=\"symbol\",{defineProperty:G,getOwnPropertyDescriptor:B,getPrototypeOf:J,isExtensible:I,ownKeys:L,preventExtensions:U,set:N,setPrototypeOf:z}=Reflect,D=J(Int8Array),C=(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],K=e=>t=>{const r=typeof t;switch(r){case _:if(null==t)return q(\"null\",t);case O:return e(r,t);case\"boolean\":case W:case R:case T:case\"bigint\":return q(r,t);case F:if(Y.has(t))return q(r,Y.get(t))}throw new Error(`Unable to handle this ${r} type`)},Y=new Map(L(Symbol).filter((e=>typeof Symbol[e]===F)).map((e=>[Symbol[e],e]))),V=e=>{for(const[t,r]of Y)if(r===e)return t},H=\"apply\",Q=\"construct\",X=\"defineProperty\",Z=\"deleteProperty\",ee=\"get\",te=\"getOwnPropertyDescriptor\",re=\"getPrototypeOf\",ne=\"has\",se=\"isExtensible\",oe=\"ownKeys\",ae=\"preventExtensions\",ie=\"set\",ce=\"setPrototypeOf\",le=\"delete\";let ue=0;const fe=new Map,pe=new Map,de=new WeakMap;if(globalThis.window===globalThis){const{addEventListener:e}=EventTarget.prototype;G(EventTarget.prototype,\"addEventListener\",{value(t,r,...n){return n.at(0)?.invoke&&(de.has(this)||de.set(this,new Map),de.get(this).set(t,[].concat(n[0].invoke)),delete n[0].invoke),e.call(this,t,r,...n)}})}const we=K(((e,t)=>{if(!fe.has(t)){let e;for(;pe.has(e=ue++););fe.set(t,e),pe.set(e,t)}return q(e,fe.get(t))}));var ge=(e,t,r)=>{const{[r]:n}=e,s=new FinalizationRegistry((e=>{n(le,q(R,e))})),o=([e,t])=>{switch(e){case _:if(null==t)return globalThis;if(typeof t===W)return pe.get(t);if(!(t instanceof D))for(const e in t)t[e]=o(t[e]);return t;case O:if(typeof t===R){if(!pe.has(t)){const e=function(...e){return e.at(0)instanceof Event&&(e=>{const{currentTarget:t,target:r,type:n}=e;for(const s of de.get(t||r)?.get(n)||[])e[s]()})(...e),n(H,q(O,t),we(this),e.map(we))},r=new WeakRef(e);pe.set(t,r),s.register(e,t,r)}return pe.get(t).deref()}return pe.get(t);case F:return V(t)}return t},a={[H]:(e,t,r)=>we(e.apply(t,r)),[Q]:(e,t)=>we(new e(...t)),[X]:(e,t,r)=>we(G(e,t,r)),[Z]:(e,t)=>we(delete e[t]),[re]:e=>we(J(e)),[ee]:(e,t)=>we(e[t]),[te]:(e,t)=>{const r=B(e,t);return r?q(_,C(r,we)):q(T,r)},[ne]:(e,t)=>we(t in e),[se]:e=>we(I(e)),[oe]:e=>q(_,L(e).map(we)),[ae]:e=>we(U(e)),[ie]:(e,t,r)=>we(N(e,t,r)),[ce]:(e,t)=>we(z(e,t)),[le](e){fe.delete(pe.get(e)),pe.delete(e)}};return e[t]=(e,t,...r)=>{switch(e){case H:r[0]=o(r[0]),r[1]=r[1].map(o);break;case Q:r[0]=r[0].map(o);break;case X:{const[e,t]=r;r[0]=o(e);const{get:n,set:s,value:a}=t;n&&(t.get=o(n)),s&&(t.set=o(s)),a&&(t.value=o(a));break}default:r=r.map(o)}return a[e](o(t),...r)},{proxy:e,window:globalThis,isWindowProxy:()=>!1}};let he=0;const ye=new Map,me=new Map,be=Symbol(),ve=e=>typeof e===O?e():e,Se=e=>typeof e===_&&!!e&&be in e,Me=\"isArray\",Pe=Array[Me],Ee=K(((e,t)=>{if(be in t)return ve(t[be]);if(e===O){if(!me.has(t)){let e;for(;me.has(e=String(he++)););ye.set(t,e),me.set(e,t)}return q(e,ye.get(t))}if(!(t instanceof D))for(const e in t)t[e]=Ee(t[e]);return q(e,t)}));var je=(e,t,r)=>{const{[t]:n}=e,s=new Map,o=new FinalizationRegistry((e=>{s.delete(e),n(le,Ee(e))})),a=e=>{const[t,r]=e;if(!s.has(r)){const n=t===O?Ae.bind(e):e,a=new Proxy(n,l),i=new WeakRef(a);s.set(r,i),o.register(a,r,i)}return s.get(r).deref()},i=e=>{const[t,r]=e;switch(t){case _:return typeof r===W?a(e):r;case O:return typeof r===R?me.get(r):a(e);case F:return V(r)}return r},c=(e,t,...r)=>i(n(e,ve(t),...r)),l={[H]:(e,t,r)=>c(H,e,Ee(t),r.map(Ee)),[Q]:(e,t)=>c(Q,e,t.map(Ee)),[X]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===O&&(r.get=Ee(n)),typeof s===O&&(r.set=Ee(s)),typeof o===O&&(r.value=Ee(o)),c(X,e,Ee(t),r)},[Z]:(e,t)=>c(Z,e,Ee(t)),[re]:e=>c(re,e),[ee]:(e,t)=>t===be?e:c(ee,e,Ee(t)),[te]:(e,t)=>{const r=c(te,e,Ee(t));return r&&C(r,i)},[ne]:(e,t)=>t===be||c(ne,e,Ee(t)),[se]:e=>c(se,e),[oe]:e=>c(oe,e).map(i),[ae]:e=>c(ae,e),[ie]:(e,t,r)=>c(ie,e,Ee(t),Ee(r)),[ce]:(e,t)=>c(ce,e,Ee(t))};e[r]=(e,t,r,n)=>{switch(e){case H:return i(t).apply(i(r),n.map(i));case le:{const e=i(t);ye.delete(me.get(e)),me.delete(e)}}};const u=new Proxy([_,null],l),f=u.Array[Me];return G(Array,Me,{value:e=>Se(e)?f(e):Pe(e)}),{window:u,isWindowProxy:Se,proxy:e,get global(){return console.warn(\"Deprecated: please access `window` field instead\"),this.window},get isGlobal(){return function(e){return console.warn(\"Deprecated: please access `isWindowProxy` field instead\"),this.isWindowProxy(e)}.bind(this)}}};function Ae(){return this}const ke=p+\"M\",xe=p+\"T\",$e=new WeakMap,_e=(e,...t)=>{const r=$(e,...t);if(!$e.has(r)){const t=e instanceof Worker?ge:je;$e.set(r,t(r,ke,xe))}return $e.get(r)};_e.transfer=$.transfer;const{isArray:Oe}=Array,{assign:We,create:Re,defineProperties:Te,defineProperty:Fe,entries:Ge}=Object,{all:Be,resolve:Je}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Ie=(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 Le=e=>e.arrayBuffer(),Ue=e=>e.json(),Ne=e=>e.text(),ze=e=>e.replace(/^[^\\r\\n]+$/,(e=>e.trim())),De=new WeakMap,Ce=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=e=>{const t=e.split(\"/\");return t.pop(),t.join(\"/\")},Ke=(e,t)=>{const r=[];for(const n of t.split(\"/\"))r.push(n),n&&e.mkdir(r.join(\"/\"))},Ye=(e,t)=>{const r=[];for(const e of t.split(\"/\"))switch(e){case\"\":case\".\":break;case\"..\":r.pop();break;default:r.push(e)}return[e.cwd()].concat(r).join(\"/\").replace(/^\\/+/,\"/\")},Ve=e=>{const t=e.map((e=>e.trim().replace(/(^[/]*|[/]*$)/g,\"\"))).filter((e=>\"\"!==e&&\".\"!==e)).join(\"/\");return e[0].startsWith(\"/\")?`/${t}`:t},He=new WeakMap,Qe=(e,t,r)=>Be((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:Ve([e,r]),path:Ve([t,r])})));const s=r||e.slice(1+e.lastIndexOf(\"/\"));return[{url:e,path:Ve([t,s])}]}))})(r).map((({url:n,path:s})=>((e,t)=>fetch(Ie(t,He.get(e))))(r,n).then(Le).then((r=>e.writeFile(t,s,r))))));function Xe(e,t,r){for(const[t,n]of Ge(r))this.setGlobal(e,t,n)}const Ze=(e,t)=>e.runPython(ze(t)),et=(e,t)=>e.globals.get(t),tt=(e,t,r)=>{e.globals.set(t,r)},rt=(e,t)=>{e.globals.delete(t)},nt=(e,t,r)=>{e.registerJsModule(t,r)},st=({FS:e},t,r)=>((e,t,r)=>{const{parentPath:n,name:s}=e.analyzePath(t,!0);return e.mkdirTree(n),e.writeFile([n,s].join(\"/\"),new Uint8Array(r),{canOwn:!0})})(e,t,r);var ot={type:\"micropython\",module:(e=\"1.20.0-268\")=>`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}=Ce();r=r.replace(/\\.m?js$/,\".wasm\");const a=await o(e({stderr:n,stdout:s,url:r}));return t.fetch&&await Qe(this,a,t.fetch),a},getGlobal:et,setGlobal:tt,deleteGlobal:rt,registerJSModule:nt,run:Ze,async runAsync(...e){return this.run(...e)},writeFile:st};var at={type:\"pyodide\",module:(e=\"0.23.2\")=>`https://cdn.jsdelivr.net/pyodide/v${e}/full/pyodide.mjs`,async engine({loadPyodide:e},t,r){const{stderr:n,stdout:s,get:o}=Ce(),a=r.slice(0,r.lastIndexOf(\"/\")),i=await o(e({stderr:n,stdout:s,indexURL:a}));if(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},getGlobal:et,setGlobal:tt,deleteGlobal:rt,registerJSModule:nt,run:Ze,runAsync:(e,t)=>e.runPythonAsync(ze(t)),writeFile:st};const it=\"ruby-wasm-wasi\";var ct={type:it,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 Qe(this,o,t.fetch),o},registerJSModule:Xe,getGlobal(e,t){try{return this.run(e,t)}catch(r){const n=this.run(e,`method(:${t})`);return(...r)=>n.call(t,...r.map((t=>e.wrap(t))))}},setGlobal(e,t,r){const n=`__pyscript_ruby_wasm_wasi_${t}`;globalThis[n]=r,this.run(e,`require \"js\";$${t}=JS::eval(\"return ${n}\")`)},deleteGlobal(e,t){const r=`__pyscript_ruby_wasm_wasi_${t}`;this.run(e,`$${t}=nil`),delete globalThis[r]},run:(e,t)=>e.eval(ze(t)),runAsync:(e,t)=>e.evalAsync(ze(t)),writeFile:()=>{throw new Error(`writeFile is not supported in ${it}`)}};var lt={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}=Ce(),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 Qe(this,a,r.fetch),a},registerJSModule:Xe,getGlobal:(e,t)=>e.global.get(t),setGlobal(e,t,r){e.global.set(t,r)},deleteGlobal(e,t){e.global.set(t,void 0)},run:(e,t)=>e.doStringSync(ze(t)),runAsync:(e,t)=>e.doString(ze(t)),writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(t=Ye(e,t),Ke(e,qe(t)),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const ut=new Map,ft=new Map,pt=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split(\"@\"),s=ut.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=>{ft.set(t,e);const a=e?.fetch;return a&&He.set(a,o),s(n,e,r)}))}}),dt=e=>{for(const t of[].concat(e.type))ut.set(t,e)};for(const e of[ot,at,ct,lt])dt(e);const wt=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 gt,ht,yt;const mt=(e,t)=>{addEventListener(e,t||(async t=>{await gt,yt=t,ht(`xworker.on${e}(xworker.event);`,Mt)}),!!t&&{once:!0})},{proxy:bt,window:vt,isWindowProxy:St}=_e(self,f),Mt={sync:bt,window:vt,isWindowProxy:St,onerror(){},onmessage(){},onmessageerror(){},postMessage:postMessage.bind(self),get event(){const e=yt;if(!e)throw new Error(\"Unauthorized event access\");return yt=void 0,e}};mt(\"message\",(({data:{options:e,code:t,hooks:r}})=>{gt=(async()=>{const{type:n,version:s,config:o,async:a}=e,i=await((e,t)=>{let r={};if(t)if(t.endsWith(\".json\"))r=fetch(t).then(Ue);else if(t.endsWith(\".toml\"))r=fetch(t).then(Ne).then(wt);else{try{r=JSON.parse(t)}catch(e){r=wt(t)}t=Ie(\"./config.txt\")}return Je(r).then((r=>pt[e](r,t)))})(((e,t=\"\")=>`${e}@${t}`.replace(/@$/,\"\"))(n,s),o),c=Re(ut.get(n)),l=\"run\"+(a?\"Async\":\"\");if(r){const{beforeRun:e,beforeRunAsync:t,afterRun:n,afterRunAsync:s}=r,o=n||s,a=e||t;if(o){const e=c[l].bind(c);c[l]=(t,r)=>e(t,`${r}\\n${o}`)}if(a){const e=c[l].bind(c);c[l]=(t,r)=>e(t,`${a}\\n${r}`)}}return c.registerJSModule(i,\"xworker\",{xworker:Mt}),ht=c[l].bind(c,i),ht(t),i})(),mt(\"error\"),mt(\"message\"),mt(\"messageerror\")}));\n"],{type:'application/javascript'})),{type:'module'});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyscript/core",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "PyScript Next core",
5
5
  "main": "./cjs/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -8,6 +8,7 @@
8
8
  "server": "npx static-handler --cors --coep --coop --corp .",
9
9
  "build": "npm run rollup:xworker && npm run rollup:core && npm run rollup:pyscript && eslint esm/ && npm run ts && npm run cjs && npm run test",
10
10
  "cjs": "ascjs --no-default esm cjs",
11
+ "dev": "node dev.cjs",
11
12
  "rollup:core": "rollup --config rollup/core.config.js",
12
13
  "rollup:pyscript": "rollup --config rollup/pyscript.config.js",
13
14
  "rollup:xworker": "rollup --config rollup/xworker.config.js",
@@ -32,6 +33,7 @@
32
33
  "@rollup/plugin-terser": "^0.4.3",
33
34
  "ascjs": "^5.0.1",
34
35
  "c8": "^8.0.0",
36
+ "chokidar": "^3.5.3",
35
37
  "eslint": "^8.43.0",
36
38
  "linkedom": "^0.14.26",
37
39
  "rollup": "^3.25.3",
@@ -64,6 +66,6 @@
64
66
  "coincident": "^0.8.3"
65
67
  },
66
68
  "worker": {
67
- "blob": "sha256-CaHDEAEttvghrbLR/GVAofT+zQZyy0Ri9tkpVTNBbiE="
69
+ "blob": "sha256-BqPm4/IdGDQduhprGUnwdf5iumpMmkkGNsPrPZXl+mU="
68
70
  }
69
71
  }