hyperbook 0.90.0 → 0.91.1
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/dist/assets/code-input/auto-close-brackets.min.js +1 -1
- package/dist/assets/code-input/code-input.min.css +1 -1
- package/dist/assets/code-input/code-input.min.js +12 -1
- package/dist/assets/code-input/indent.min.js +1 -1
- package/dist/assets/directive-excalidraw/hyperbook-excalidraw.umd.js +1 -1
- package/dist/assets/directive-onlineide/style.css +8 -0
- package/dist/assets/directive-p5/client.js +113 -0
- package/dist/assets/directive-p5/style.css +67 -3
- package/dist/assets/directive-pyide/client.js +1226 -146
- package/dist/assets/directive-pyide/style.css +183 -6
- package/dist/assets/directive-sqlide/style.css +8 -0
- package/dist/assets/directive-typst/client.js +154 -14
- package/dist/assets/directive-typst/style.css +65 -4
- package/dist/assets/directive-webide/client.js +114 -0
- package/dist/assets/directive-webide/style.css +61 -3
- package/dist/index.js +252 -54
- package/dist/locales/de.json +12 -0
- package/dist/locales/en.json +12 -0
- package/package.json +3 -3
- package/dist/assets/directive-pyide/webworker.js +0 -86
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
// Setup your project to serve `py-worker.js`. You should also serve
|
|
2
|
-
// `pyodide.js`, and all its associated `.asm.js`, `.json`,
|
|
3
|
-
// and `.wasm` files as well:
|
|
4
|
-
importScripts("https://cdn.jsdelivr.net/pyodide/v0.29.0/full/pyodide.js");
|
|
5
|
-
|
|
6
|
-
class StdinHandler {
|
|
7
|
-
constructor(results, options) {
|
|
8
|
-
this.results = results;
|
|
9
|
-
this.idx = 0;
|
|
10
|
-
Object.assign(this, options);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
stdin() {
|
|
14
|
-
return this.results[this.idx++];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function loadPyodideAndPackages() {
|
|
19
|
-
var pyodide = await loadPyodide();
|
|
20
|
-
self.pyodide = pyodide;
|
|
21
|
-
await self.pyodide.loadPackage([]);
|
|
22
|
-
}
|
|
23
|
-
let pyodideReadyPromise = loadPyodideAndPackages();
|
|
24
|
-
|
|
25
|
-
self.onmessage = async ({ data: { id, type, payload } }) => {
|
|
26
|
-
switch (type) {
|
|
27
|
-
case "run": {
|
|
28
|
-
// make sure loading is done
|
|
29
|
-
await pyodideReadyPromise;
|
|
30
|
-
// Don't bother yet with this line, suppose our API is built in such a way:
|
|
31
|
-
const { python, inputs, ...context } = payload;
|
|
32
|
-
// The worker copies the context in its own "memory" (an object mapping name to values)
|
|
33
|
-
for (const key of Object.keys(context)) {
|
|
34
|
-
self[key] = context[key];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
self.pyodide.setStdin(new StdinHandler(inputs));
|
|
38
|
-
|
|
39
|
-
self.pyodide.setStdout({
|
|
40
|
-
batched: (msg) => {
|
|
41
|
-
self.postMessage({ id, type: "stdout", payload: msg });
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
self.pyodide.setStderr({
|
|
46
|
-
batched: (msg) => {
|
|
47
|
-
self.postMessage({ id, type: "stderr", payload: msg });
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
// Now is the easy part, the one that is similar to working in the main thread:
|
|
52
|
-
const filename = "<exec>";
|
|
53
|
-
try {
|
|
54
|
-
await self.pyodide.loadPackagesFromImports(python);
|
|
55
|
-
const dict = self.pyodide.globals.get("dict");
|
|
56
|
-
const globals = dict();
|
|
57
|
-
let results = await self.pyodide.runPythonAsync(python, {
|
|
58
|
-
globals,
|
|
59
|
-
locals: globals,
|
|
60
|
-
filename,
|
|
61
|
-
});
|
|
62
|
-
globals.destroy();
|
|
63
|
-
dict.destroy();
|
|
64
|
-
self.postMessage({ type: "success", id, payload: results });
|
|
65
|
-
} catch (error) {
|
|
66
|
-
// clean up trackback
|
|
67
|
-
let message = error.message;
|
|
68
|
-
if (message.startsWith("Traceback")) {
|
|
69
|
-
const lines = message?.split("\n") || [];
|
|
70
|
-
const i = lines.findIndex((line) => line.includes(filename));
|
|
71
|
-
message = lines[0] + "\n" + lines.slice(i).join("\n");
|
|
72
|
-
self.postMessage({ type: "error", payload: message, id });
|
|
73
|
-
}
|
|
74
|
-
self.postMessage({ type: "error", payload: message, id });
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case "setInterruptBuffer": {
|
|
79
|
-
const { interruptBuffer } = payload;
|
|
80
|
-
// make sure loading is done
|
|
81
|
-
await pyodideReadyPromise;
|
|
82
|
-
self.pyodide.setInterruptBuffer(interruptBuffer);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|