@pyscript/core 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/cjs/custom.js +4 -1
- package/cjs/interpreter/_python.js +14 -8
- package/cjs/interpreter/_utils.js +1 -0
- package/cjs/interpreter/micropython.js +10 -8
- package/cjs/interpreter/pyodide.js +4 -4
- package/cjs/interpreter/ruby-wasm-wasi.js +28 -9
- package/cjs/interpreter/wasmoon.js +17 -5
- package/cjs/listeners.js +1 -6
- package/cjs/script-handler.js +1 -2
- package/cjs/utils.js +2 -1
- package/cjs/worker/xworker.js +1 -1
- package/core.js +1 -1
- package/dev.cjs +33 -0
- package/docs/README.md +17 -37
- package/esm/custom.js +4 -1
- package/esm/interpreter/_python.js +12 -6
- package/esm/interpreter/_utils.js +1 -0
- package/esm/interpreter/micropython.js +10 -8
- package/esm/interpreter/pyodide.js +4 -4
- package/esm/interpreter/ruby-wasm-wasi.js +28 -9
- package/esm/interpreter/wasmoon.js +17 -5
- package/esm/listeners.js +1 -6
- package/esm/script-handler.js +1 -2
- package/esm/utils.js +2 -1
- package/esm/worker/xworker.js +1 -1
- package/package.json +4 -2
- package/pyscript.js +1 -1
- package/types/coincident/window.d.ts +6 -6
- package/types/pyscript/pyscript.core/esm/interpreter/_python.d.ts +2 -2
- package/types/pyscript/pyscript.core/esm/interpreter/micropython.d.ts +6 -5
- package/types/pyscript/pyscript.core/esm/interpreter/pyodide.d.ts +4 -4
- package/types/pyscript/pyscript.core/esm/interpreter/ruby-wasm-wasi.d.ts +2 -2
- package/types/pyscript/pyscript.core/esm/interpreter/wasmoon.d.ts +2 -2
- 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
|
-
|
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
|
-
|
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
|
258
|
-
|
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
|
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
|
-
|
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
|
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`
|
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
|
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
|
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
|
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,11 +451,12 @@ 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
|
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. |
|
479
|
-
| runAsync | `wrap.
|
458
|
+
| runAsync | `wrap.runAsync(code)` | It abstracts away the need to know the exact method name used to run code asynchronously, whenever the *interpreter* allows such operation, facilitating future migrations from an interpreter to another. |
|
459
|
+
| runEvent | `wrap.runEvent(code, event)` | It abstracts away the need to know how an *interpreter* retrieves paths to execute an event handler. |
|
480
460
|
|
481
461
|
This is the `wrap` mentioned with most hooks and initializers previously described, and we're more than happy to learn if we are not passing along some extra helper.
|
482
462
|
|
package/esm/custom.js
CHANGED
@@ -107,7 +107,9 @@ export const handleCustomType = (node) => {
|
|
107
107
|
};
|
108
108
|
}
|
109
109
|
|
110
|
-
module.
|
110
|
+
module.registerJSModule(interpreter, "xworker", {
|
111
|
+
XWorker,
|
112
|
+
});
|
111
113
|
|
112
114
|
const resolved = {
|
113
115
|
type,
|
@@ -117,6 +119,7 @@ export const handleCustomType = (node) => {
|
|
117
119
|
config: structuredClone(configs.get(name)),
|
118
120
|
run: module.run.bind(module, interpreter),
|
119
121
|
runAsync: module.runAsync.bind(module, interpreter),
|
122
|
+
runEvent: module.runEvent.bind(module, interpreter),
|
120
123
|
};
|
121
124
|
|
122
125
|
resolve(resolved);
|
@@ -2,17 +2,23 @@ import { clean, writeFile as writeFileUtil } from "./_utils.js";
|
|
2
2
|
|
3
3
|
// REQUIRES INTEGRATION TEST
|
4
4
|
/* c8 ignore start */
|
5
|
+
export const registerJSModule = (interpreter, name, value) => {
|
6
|
+
interpreter.registerJsModule(name, value);
|
7
|
+
};
|
8
|
+
|
5
9
|
export const run = (interpreter, code) => interpreter.runPython(clean(code));
|
6
10
|
|
7
11
|
export const runAsync = (interpreter, code) =>
|
8
12
|
interpreter.runPythonAsync(clean(code));
|
9
13
|
|
10
|
-
export const
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
export const runEvent = async (interpreter, code, event) => {
|
15
|
+
// allows method(event) as well as namespace.method(event)
|
16
|
+
// it does not allow fancy brackets names for now
|
17
|
+
const [name, ...keys] = code.split(".");
|
18
|
+
let target = interpreter.globals.get(name);
|
19
|
+
let context;
|
20
|
+
for (const key of keys) [context, target] = [target, target[key]];
|
21
|
+
target.call(context, event);
|
16
22
|
};
|
17
23
|
|
18
24
|
export const writeFile = ({ FS }, path, buffer) =>
|
@@ -1,5 +1,11 @@
|
|
1
1
|
import { fetchPaths, stdio } from "./_utils.js";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
registerJSModule,
|
4
|
+
run,
|
5
|
+
runAsync,
|
6
|
+
runEvent,
|
7
|
+
writeFile,
|
8
|
+
} from "./_python.js";
|
3
9
|
|
4
10
|
const type = "micropython";
|
5
11
|
|
@@ -16,14 +22,10 @@ export default {
|
|
16
22
|
if (config.fetch) await fetchPaths(this, interpreter, config.fetch);
|
17
23
|
return interpreter;
|
18
24
|
},
|
19
|
-
|
20
|
-
deleteGlobal,
|
25
|
+
registerJSModule,
|
21
26
|
run,
|
22
|
-
|
23
|
-
|
24
|
-
async runAsync(...args) {
|
25
|
-
return this.run(...args);
|
26
|
-
},
|
27
|
+
runAsync,
|
28
|
+
runEvent,
|
27
29
|
writeFile,
|
28
30
|
};
|
29
31
|
/* c8 ignore stop */
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { fetchPaths, stdio } from "./_utils.js";
|
2
2
|
import {
|
3
|
+
registerJSModule,
|
3
4
|
run,
|
4
5
|
runAsync,
|
5
|
-
|
6
|
-
deleteGlobal,
|
6
|
+
runEvent,
|
7
7
|
writeFile,
|
8
8
|
} from "./_python.js";
|
9
9
|
|
@@ -30,10 +30,10 @@ export default {
|
|
30
30
|
}
|
31
31
|
return interpreter;
|
32
32
|
},
|
33
|
-
|
34
|
-
deleteGlobal,
|
33
|
+
registerJSModule,
|
35
34
|
run,
|
36
35
|
runAsync,
|
36
|
+
runEvent,
|
37
37
|
writeFile,
|
38
38
|
};
|
39
39
|
/* c8 ignore stop */
|
@@ -1,6 +1,8 @@
|
|
1
1
|
import { clean, fetchPaths } from "./_utils.js";
|
2
|
+
import { entries } from "../utils.js";
|
2
3
|
|
3
4
|
const type = "ruby-wasm-wasi";
|
5
|
+
const jsType = type.replace(/\W+/g, "_");
|
4
6
|
|
5
7
|
// MISSING:
|
6
8
|
// * there is no VFS apparently or I couldn't reach any
|
@@ -23,18 +25,35 @@ export default {
|
|
23
25
|
if (config.fetch) await fetchPaths(this, interpreter, config.fetch);
|
24
26
|
return interpreter;
|
25
27
|
},
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
// Fallback to globally defined module fields (i.e. $xworker)
|
29
|
+
registerJSModule(interpreter, _, value) {
|
30
|
+
const code = ['require "js"'];
|
31
|
+
for (const [k, v] of entries(value)) {
|
32
|
+
const id = `__module_${jsType}_${k}`;
|
33
|
+
globalThis[id] = v;
|
34
|
+
code.push(`$${k}=JS.global[:${id}]`);
|
35
|
+
}
|
36
|
+
this.run(interpreter, code.join(";"));
|
35
37
|
},
|
36
38
|
run: (interpreter, code) => interpreter.eval(clean(code)),
|
37
39
|
runAsync: (interpreter, code) => interpreter.evalAsync(clean(code)),
|
40
|
+
runEvent(interpreter, code, event) {
|
41
|
+
// patch common xworker.onmessage/onerror cases
|
42
|
+
if (/^xworker\.(on\w+)$/.test(code)) {
|
43
|
+
const { $1: name } = RegExp;
|
44
|
+
const id = `__module_${jsType}_event`;
|
45
|
+
globalThis[id] = event;
|
46
|
+
this.run(
|
47
|
+
interpreter,
|
48
|
+
`require "js";$xworker.call("${name}",JS.global[:${id}])`,
|
49
|
+
);
|
50
|
+
delete globalThis[id];
|
51
|
+
} else {
|
52
|
+
// Experimental: allows only events by fully qualified method name
|
53
|
+
const method = this.run(interpreter, `method(:${code})`);
|
54
|
+
method.call(code, interpreter.wrap(event));
|
55
|
+
}
|
56
|
+
},
|
38
57
|
writeFile: () => {
|
39
58
|
throw new Error(`writeFile is not supported in ${type}`);
|
40
59
|
},
|
@@ -1,7 +1,12 @@
|
|
1
1
|
import { clean, fetchPaths, stdio, writeFileShim } from "./_utils.js";
|
2
2
|
|
3
|
+
import { entries } from "../utils.js";
|
4
|
+
|
3
5
|
const type = "wasmoon";
|
4
6
|
|
7
|
+
// MISSING:
|
8
|
+
// * I've no idea how to import packages
|
9
|
+
|
5
10
|
// REQUIRES INTEGRATION TEST
|
6
11
|
/* c8 ignore start */
|
7
12
|
export default {
|
@@ -18,14 +23,21 @@ export default {
|
|
18
23
|
if (config.fetch) await fetchPaths(this, interpreter, config.fetch);
|
19
24
|
return interpreter;
|
20
25
|
},
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
deleteGlobal(interpreter, name) {
|
25
|
-
interpreter.global.set(name, void 0);
|
26
|
+
// Fallback to globally defined module fields
|
27
|
+
registerJSModule: (interpreter, _, value) => {
|
28
|
+
for (const [k, v] of entries(value)) interpreter.global.set(k, v);
|
26
29
|
},
|
27
30
|
run: (interpreter, code) => interpreter.doStringSync(clean(code)),
|
28
31
|
runAsync: (interpreter, code) => interpreter.doString(clean(code)),
|
32
|
+
runEvent: (interpreter, code, event) => {
|
33
|
+
// allows method(event) as well as namespace.method(event)
|
34
|
+
// it does not allow fancy brackets names for now
|
35
|
+
const [name, ...keys] = code.split(".");
|
36
|
+
let target = interpreter.global.get(name);
|
37
|
+
let context;
|
38
|
+
for (const key of keys) [context, target] = [target, target[key]];
|
39
|
+
target.call(context, event);
|
40
|
+
},
|
29
41
|
writeFile: (
|
30
42
|
{
|
31
43
|
cmodule: {
|
package/esm/listeners.js
CHANGED
@@ -41,12 +41,7 @@ export const listener = async (event) => {
|
|
41
41
|
el.getAttribute(`${name}-env`) || name,
|
42
42
|
);
|
43
43
|
const handler = registry.get(name);
|
44
|
-
|
45
|
-
handler.setGlobal(interpreter, "event", event);
|
46
|
-
handler.run(interpreter, value);
|
47
|
-
} finally {
|
48
|
-
handler.deleteGlobal(interpreter, "event");
|
49
|
-
}
|
44
|
+
handler.runEvent(interpreter, value, event);
|
50
45
|
}
|
51
46
|
};
|
52
47
|
|
package/esm/script-handler.js
CHANGED
@@ -58,11 +58,10 @@ const execute = async (script, source, XWorker, isAsync) => {
|
|
58
58
|
configurable: true,
|
59
59
|
get: () => script,
|
60
60
|
});
|
61
|
-
module.
|
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,
|
package/esm/worker/xworker.js
CHANGED
@@ -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:E,waitAsync:M}=Atomics,{fromCharCode:P}=String,j=(e,t)=>e?(M||d)(t,0):(E(t,0),{value:{then:e=>e()}}),k=new WeakSet,x=new WeakMap;let A=0;const $=(e,{parse:t,stringify:r}=JSON)=>{if(!x.has(e)){const n=(t,...r)=>e.postMessage({[p]:r},{transfer:t});x.set(e,new Proxy(new g,{has:(e,t)=>\"string\"==typeof t&&!t.startsWith(\"_\"),get:(r,s)=>\"then\"===s?null:(...r)=>{const o=A++;let a=new w(new h(m)),i=[];k.has(r.at(-1)||i)&&k.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(P(...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 x.get(e)};$.transfer=(...e)=>(k.add(e),e);const _=\"object\",W=\"function\",O=\"number\",R=\"string\",T=\"undefined\",F=\"symbol\",{defineProperty:B,getOwnPropertyDescriptor:J,getPrototypeOf:I,isExtensible:L,ownKeys:U,preventExtensions:N,set:D,setPrototypeOf:z}=Reflect,C=I(Int8Array),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},G=(e,t)=>[e,t],K=e=>t=>{const r=typeof t;switch(r){case _:if(null==t)return G(\"null\",t);case W:return e(r,t);case\"boolean\":case O:case R:case T:case\"bigint\":return G(r,t);case F:if(Y.has(t))return G(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 G(e,fe.get(t))}));var ge=(e,t,r)=>{const{[r]:n}=e,s=new FinalizationRegistry((e=>{n(le,G(R,e))})),o=([e,t])=>{switch(e){case _:if(null==t)return globalThis;if(typeof t===O)return pe.get(t);if(!(t instanceof C))for(const e in t)t[e]=o(t[e]);return t;case W: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,G(W,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(I(e)),[ee]:(e,t)=>we(e[t]),[te]:(e,t)=>{const r=J(e,t);return r?G(_,q(r,we)):G(T,r)},[ne]:(e,t)=>we(t in e),[se]:e=>we(L(e)),[oe]:e=>G(_,U(e).map(we)),[ae]:e=>we(N(e)),[ie]:(e,t,r)=>we(D(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===W?e():e,Se=e=>typeof e===_&&!!e&&be in e,Ee=\"isArray\",Me=Array[Ee],Pe=K(((e,t)=>{if(be in t)return ve(t[be]);if(e===W){if(!me.has(t)){let e;for(;me.has(e=String(he++)););ye.set(t,e),me.set(e,t)}return G(e,ye.get(t))}if(!(t instanceof C))for(const e in t)t[e]=Pe(t[e]);return G(e,t)}));var je=(e,t,r)=>{const{[t]:n}=e,s=new Map,o=new FinalizationRegistry((e=>{s.delete(e),n(le,Pe(e))})),a=e=>{const[t,r]=e;if(!s.has(r)){const n=t===W?ke.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===O?a(e):r;case W: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,Pe(t),r.map(Pe)),[Q]:(e,t)=>c(Q,e,t.map(Pe)),[X]:(e,t,r)=>{const{get:n,set:s,value:o}=r;return typeof n===W&&(r.get=Pe(n)),typeof s===W&&(r.set=Pe(s)),typeof o===W&&(r.value=Pe(o)),c(X,e,Pe(t),r)},[Z]:(e,t)=>c(Z,e,Pe(t)),[re]:e=>c(re,e),[ee]:(e,t)=>t===be?e:c(ee,e,Pe(t)),[te]:(e,t)=>{const r=c(te,e,Pe(t));return r&&q(r,i)},[ne]:(e,t)=>t===be||c(ne,e,Pe(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,Pe(t),Pe(r)),[ce]:(e,t)=>c(ce,e,Pe(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[Ee];return B(Array,Ee,{value:e=>Se(e)?f(e):Me(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 ke(){return this}const xe=p+\"M\",Ae=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,xe,Ae))}return $e.get(r)};_e.transfer=$.transfer;const{isArray:We}=Array,{assign:Oe,create:Re,defineProperties:Te,defineProperty:Fe,entries:Be}=Object,{all:Je,resolve:Ie}=new Proxy(Promise,{get:(e,t)=>e[t].bind(e)}),Le=(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 Ue=e=>e.arrayBuffer(),Ne=e=>e.json(),De=e=>e.text(),ze=e=>e.replace(/^[^\\r\\n]+$/,(e=>e.trim())),Ce=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 Ce.set(t,r),t}}},Ge=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)=>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(We(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(Le(t,He.get(e))))(r,n).then(Ue).then((r=>e.writeFile(t,s,r)))))),Xe=(e,t,r)=>{e.registerJsModule(t,r)},Ze=(e,t)=>e.runPython(ze(t)),et=(e,t)=>e.runPythonAsync(ze(t)),tt=async(e,t,r)=>{const[n,...s]=t.split(\".\");let o,a=e.globals.get(n);for(const e of s)[o,a]=[a,a[e]];a.call(o,r)},rt=({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 nt={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}=qe();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},registerJSModule:Xe,run:Ze,runAsync:et,runEvent:tt,writeFile:rt};var st={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}=qe(),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},registerJSModule:Xe,run:Ze,runAsync:et,runEvent:tt,writeFile:rt};const ot=\"ruby-wasm-wasi\",at=ot.replace(/\\W+/g,\"_\");var it={type:ot,experimental:!0,module:(e=\"2.0.0\")=>`https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@${e}/dist/browser.esm.js`,async engine({DefaultRubyVM:e},t,r){const n=await fetch(`${r.slice(0,r.lastIndexOf(\"/\"))}/ruby.wasm`),s=await WebAssembly.compile(await n.arrayBuffer()),{vm:o}=await e(s);return t.fetch&&await Qe(this,o,t.fetch),o},registerJSModule(e,t,r){const n=['require \"js\"'];for(const[e,t]of Be(r)){const r=`__module_${at}_${e}`;globalThis[r]=t,n.push(`$${e}=JS.global[:${r}]`)}this.run(e,n.join(\";\"))},run:(e,t)=>e.eval(ze(t)),runAsync:(e,t)=>e.evalAsync(ze(t)),runEvent(e,t,r){if(/^xworker\\.(on\\w+)$/.test(t)){const{$1:t}=RegExp,n=`__module_${at}_event`;globalThis[n]=r,this.run(e,`require \"js\";$xworker.call(\"${t}\",JS.global[:${n}])`),delete globalThis[n]}else{this.run(e,`method(:${t})`).call(t,e.wrap(r))}},writeFile:()=>{throw new Error(`writeFile is not supported in ${ot}`)}};var ct={type:\"wasmoon\",module:(e=\"1.15.0\")=>`https://cdn.jsdelivr.net/npm/wasmoon@${e}/+esm`,async engine({LuaFactory:e,LuaLibraries:t},r){const{stderr:n,stdout:s,get:o}=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.fetch&&await Qe(this,a,r.fetch),a},registerJSModule:(e,t,r)=>{for(const[t,n]of Be(r))e.global.set(t,n)},run:(e,t)=>e.doStringSync(ze(t)),runAsync:(e,t)=>e.doString(ze(t)),runEvent:(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]];a.call(o,r)},writeFile:({cmodule:{module:{FS:e}}},t,r)=>((e,t,r)=>(t=Ye(e,t),Ke(e,Ge(t)),e.writeFile(t,new Uint8Array(r),{canOwn:!0})))(e,t,r)};const lt=new Map,ut=new Map,ft=new Proxy(new Map,{get(e,t){if(!e.has(t)){const[r,...n]=t.split(\"@\"),s=lt.get(r),o=/^https?:\\/\\//i.test(n)?n.join(\"@\"):s.module(...n);e.set(t,{url:o,module:import(o),engine:s.engine.bind(s)})}const{url:r,module:n,engine:s}=e.get(t);return(e,o)=>n.then((n=>{ut.set(t,e);const a=e?.fetch;return a&&He.set(a,o),s(n,e,r)}))}}),pt=e=>{for(const t of[].concat(e.type))lt.set(t,e)};for(const e of[nt,st,it,ct])pt(e);const dt=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 wt,gt;const ht=(e,t)=>{addEventListener(e,t||(async t=>{await wt,gt(`xworker.on${e}`,t)}),!!t&&{once:!0})},{proxy:yt,window:mt,isWindowProxy:bt}=_e(self,f),vt={sync:yt,window:mt,isWindowProxy:bt,onerror(){},onmessage(){},onmessageerror(){},postMessage:postMessage.bind(self)};ht(\"message\",(({data:{options:e,code:t,hooks:r}})=>{wt=(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(Ne);else if(t.endsWith(\".toml\"))r=fetch(t).then(De).then(dt);else{try{r=JSON.parse(t)}catch(e){r=dt(t)}t=Le(\"./config.txt\")}return Ie(r).then((r=>ft[e](r,t)))})(((e,t=\"\")=>`${e}@${t}`.replace(/@$/,\"\"))(n,s),o),c=Re(lt.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:vt}),gt=c.runEvent.bind(c,i),await c[l](i,t),i})(),ht(\"error\"),ht(\"message\"),ht(\"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.
|
3
|
+
"version": "0.0.8",
|
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-
|
69
|
+
"blob": "sha256-JuwqC8WVlEqybo1Q4UB76PQ260TCqm7b5sSEj1/Tuc8="
|
68
70
|
}
|
69
71
|
}
|