@alauda/doom 0.13.0 → 0.13.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/lib/cli/merge-pdfs/index.js +7 -8
- package/package.json +2 -1
- package/pyodide/README.md +90 -0
- package/pyodide/console.html +259 -0
- package/pyodide/ffi.d.ts +1118 -0
- package/pyodide/micropip-0.8.0-py3-none-any.whl +0 -0
- package/pyodide/package.json +137 -0
- package/pyodide/packaging-24.2-py3-none-any.whl +0 -0
- package/pyodide/pyodide-lock.json +1 -0
- package/pyodide/pyodide.asm.js +17 -0
- package/pyodide/pyodide.asm.wasm +0 -0
- package/pyodide/pyodide.d.ts +1627 -0
- package/pyodide/pyodide.js +6 -0
- package/pyodide/pyodide.js.map +1 -0
- package/pyodide/pyodide.mjs +4 -0
- package/pyodide/pyodide.mjs.map +1 -0
- package/pyodide/pypdf-3.8.1-py3-none-any.whl +0 -0
- package/pyodide/python_stdlib.zip +0 -0
- package/pyodide/repodata.json +1 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, resolve } from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import x from './pyodide/pyodide.js';
|
|
5
2
|
import { yellowBright } from 'yoctocolors';
|
|
3
|
+
import _pyodide from '../../../pyodide/pyodide.js';
|
|
4
|
+
import { pkgResolve } from '../../utils/helpers.js';
|
|
6
5
|
import { formatDate } from './formatDate.js';
|
|
7
6
|
/**
|
|
8
7
|
* @see https://www.uuidgenerator.net/version4
|
|
@@ -10,26 +9,26 @@ import { formatDate } from './formatDate.js';
|
|
|
10
9
|
*/
|
|
11
10
|
export const MERGE_PDF_NAME = '66699f18-ad5a-43c2-a96e-97bddaef0e6b.pdf';
|
|
12
11
|
export const MOUNT_DIR = '/' + '991e729a-8f2e-472a-8402-c26bb03b5ea3';
|
|
13
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
12
|
export async function mergePDFs(entries) {
|
|
15
13
|
if (entries.length < 2) {
|
|
16
14
|
process.stdout.write(yellowBright('At least two PDF files.\n'));
|
|
17
15
|
process.exit(1);
|
|
18
16
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
17
|
+
const pyodideDir = pkgResolve('pyodide');
|
|
18
|
+
const pyodide = await _pyodide.loadPyodide({
|
|
19
|
+
indexURL: pyodideDir,
|
|
21
20
|
});
|
|
22
21
|
await pyodide.loadPackage('micropip');
|
|
23
22
|
const micropip = pyodide.pyimport('micropip');
|
|
24
23
|
pyodide.FS.mkdirTree(MOUNT_DIR);
|
|
25
24
|
pyodide.FS.mount(
|
|
26
25
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
27
|
-
pyodide.FS.filesystems.NODEFS, { root:
|
|
26
|
+
pyodide.FS.filesystems.NODEFS, { root: pyodideDir }, MOUNT_DIR);
|
|
28
27
|
/**
|
|
29
28
|
* @see https://github.com/pyodide/pyodide/issues/3246#issuecomment-1312210155
|
|
30
29
|
* You need to prefix the path with emfs: or it will be treated as a url
|
|
31
30
|
*/
|
|
32
|
-
await micropip.install(`emfs:${MOUNT_DIR}/
|
|
31
|
+
await micropip.install(`emfs:${MOUNT_DIR}/pypdf-3.8.1-py3-none-any.whl`);
|
|
33
32
|
const tempFileNameArr = [];
|
|
34
33
|
entries.forEach((filePath) => {
|
|
35
34
|
const tempFileName = `/${filePath.split('/').join('-')}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"assets",
|
|
22
22
|
"global.d.ts",
|
|
23
23
|
"lib",
|
|
24
|
+
"pyodide",
|
|
24
25
|
"styles",
|
|
25
26
|
"!lib/*.tsbuildinfo"
|
|
26
27
|
],
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Pyodide JavaScript package
|
|
2
|
+
|
|
3
|
+
<a href="https://www.npmjs.com/package/pyodide"><img src="https://img.shields.io/npm/v/pyodide" alt="npm"></a>
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Download and extract Pyodide packages from [Github
|
|
8
|
+
releases](https://github.com/pyodide/pyodide/releases)
|
|
9
|
+
(`pyodide-build-*.tar.bz2`). The version of the release needs to match exactly the version of this package.
|
|
10
|
+
|
|
11
|
+
Then you can load Pyodide in Node.js as follows,
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// hello_python.js
|
|
15
|
+
const { loadPyodide } = require("pyodide");
|
|
16
|
+
|
|
17
|
+
async function hello_python() {
|
|
18
|
+
let pyodide = await loadPyodide({
|
|
19
|
+
indexURL: "<pyodide artifacts folder>",
|
|
20
|
+
});
|
|
21
|
+
return pyodide.runPythonAsync("1+1");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
hello_python().then((result) => {
|
|
25
|
+
console.log("Python says that 1+1 =", result);
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
$ node hello_python.js
|
|
31
|
+
Loading distutils
|
|
32
|
+
Loaded distutils
|
|
33
|
+
Python says that 1+1= 2
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Or you can use the REPL. To start the Node.js REPL with support for top level
|
|
37
|
+
await, use `node --experimental-repl-await`:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
$ node --experimental-repl-await
|
|
41
|
+
Welcome to Node.js v18.5.0.
|
|
42
|
+
Type ".help" for more information.
|
|
43
|
+
> const { loadPyodide } = require("pyodide");
|
|
44
|
+
undefined
|
|
45
|
+
> let pyodide = await loadPyodide();
|
|
46
|
+
Loading distutils
|
|
47
|
+
Loaded distutils
|
|
48
|
+
undefined
|
|
49
|
+
> await pyodide.runPythonAsync("1+1");
|
|
50
|
+
2
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Node.js versions <0.17
|
|
54
|
+
|
|
55
|
+
- `Node.js` versions 14.x and 16.x: to use certain features of Pyodide you
|
|
56
|
+
need to manually install `node-fetch`, e.g. by doing `npm install node-fetch`.
|
|
57
|
+
|
|
58
|
+
- `Node.js v14.x`: you need to pass the option `--experimental-wasm-bigint`
|
|
59
|
+
when starting Node. Note that this flag is not documented by `node --help`
|
|
60
|
+
and moreover, if you pass `--experimental-wasm-bigint` to node >14 it is an
|
|
61
|
+
error:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
$ node -v
|
|
65
|
+
v14.20.0
|
|
66
|
+
|
|
67
|
+
$ node --experimental-wasm-bigint hello_python.js
|
|
68
|
+
warning: no blob constructor, cannot create blobs with mimetypes
|
|
69
|
+
warning: no BlobBuilder
|
|
70
|
+
Loading distutils
|
|
71
|
+
Loaded distutils
|
|
72
|
+
Python says that 1+1= 2
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
See the [documentation](https://pyodide.org/en/stable/) fore more details.
|
|
76
|
+
|
|
77
|
+
## Details
|
|
78
|
+
|
|
79
|
+
The JavaScript code in this package is responsible for the following tasks:
|
|
80
|
+
|
|
81
|
+
1. Defines the public [JavaScript API](https://pyodide.org/en/stable/usage/api/js-api.html)
|
|
82
|
+
- Package loading code to allow loading of other Python packages.
|
|
83
|
+
- Can load
|
|
84
|
+
[micropip](https://pyodide.org/en/stable/usage/api/micropip-api.html) to
|
|
85
|
+
bootstrap loading of pure Python wheels
|
|
86
|
+
2. Loads the CPython interpreter and the core/pyodide emscripten application
|
|
87
|
+
which embeds the interpreter.
|
|
88
|
+
3. Injects the `js/pyodide` JavaScript API into `sys.modules`. This is the
|
|
89
|
+
final runtime dependency for `core/pyodide` & `py/pyodide`, so after this step
|
|
90
|
+
the interpreter is fully up and running.
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<script src="https://cdn.jsdelivr.net/npm/jquery"></script>
|
|
6
|
+
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal@2.35.2/js/jquery.terminal.min.js"></script>
|
|
7
|
+
<script src="https://cdn.jsdelivr.net/npm/jquery.terminal@2.35.2/js/unix_formatting.min.js"></script>
|
|
8
|
+
<link
|
|
9
|
+
href="https://cdn.jsdelivr.net/npm/jquery.terminal@2.35.2/css/jquery.terminal.min.css"
|
|
10
|
+
rel="stylesheet"
|
|
11
|
+
/>
|
|
12
|
+
<style>
|
|
13
|
+
.terminal {
|
|
14
|
+
--size: 1.5;
|
|
15
|
+
--color: rgba(255, 255, 255, 0.8);
|
|
16
|
+
}
|
|
17
|
+
.noblink {
|
|
18
|
+
--animation: terminal-none;
|
|
19
|
+
}
|
|
20
|
+
body {
|
|
21
|
+
background-color: black;
|
|
22
|
+
}
|
|
23
|
+
#jquery-terminal-logo {
|
|
24
|
+
color: white;
|
|
25
|
+
border-color: white;
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 7px;
|
|
28
|
+
right: 18px;
|
|
29
|
+
z-index: 2;
|
|
30
|
+
}
|
|
31
|
+
#jquery-terminal-logo a {
|
|
32
|
+
color: gray;
|
|
33
|
+
text-decoration: none;
|
|
34
|
+
font-size: 0.7em;
|
|
35
|
+
}
|
|
36
|
+
#loading {
|
|
37
|
+
display: inline-block;
|
|
38
|
+
width: 50px;
|
|
39
|
+
height: 50px;
|
|
40
|
+
position: fixed;
|
|
41
|
+
top: 50%;
|
|
42
|
+
left: 50%;
|
|
43
|
+
border: 3px solid rgba(172, 237, 255, 0.5);
|
|
44
|
+
border-radius: 50%;
|
|
45
|
+
border-top-color: #fff;
|
|
46
|
+
animation: spin 1s ease-in-out infinite;
|
|
47
|
+
-webkit-animation: spin 1s ease-in-out infinite;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@keyframes spin {
|
|
51
|
+
to {
|
|
52
|
+
-webkit-transform: rotate(360deg);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
@-webkit-keyframes spin {
|
|
56
|
+
to {
|
|
57
|
+
-webkit-transform: rotate(360deg);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
</style>
|
|
61
|
+
</head>
|
|
62
|
+
<body>
|
|
63
|
+
<div id="jquery-terminal-logo">
|
|
64
|
+
<a href="https://terminal.jcubic.pl/">jQuery Terminal</a>
|
|
65
|
+
</div>
|
|
66
|
+
<div id="loading"></div>
|
|
67
|
+
<script>
|
|
68
|
+
"use strict";
|
|
69
|
+
|
|
70
|
+
function sleep(s) {
|
|
71
|
+
return new Promise((resolve) => setTimeout(resolve, s));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function main() {
|
|
75
|
+
let indexURL = "./";
|
|
76
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
77
|
+
const buildParam = urlParams.get("build");
|
|
78
|
+
if (buildParam) {
|
|
79
|
+
if (["full", "debug", "pyc"].includes(buildParam)) {
|
|
80
|
+
indexURL = indexURL.replace(
|
|
81
|
+
"/full/",
|
|
82
|
+
"/" + urlParams.get("build") + "/",
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
console.warn(
|
|
86
|
+
'Invalid URL parameter: build="' +
|
|
87
|
+
buildParam +
|
|
88
|
+
'". Using default "full".',
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const { loadPyodide } = await import(indexURL + "pyodide.mjs");
|
|
93
|
+
|
|
94
|
+
let term;
|
|
95
|
+
globalThis.pyodide = await loadPyodide({
|
|
96
|
+
stdin: () => {
|
|
97
|
+
let result = prompt();
|
|
98
|
+
echo(result);
|
|
99
|
+
return result;
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
let namespace = pyodide.globals.get("dict")();
|
|
103
|
+
pyodide.runPython(
|
|
104
|
+
`
|
|
105
|
+
import sys
|
|
106
|
+
from pyodide.ffi import to_js
|
|
107
|
+
from pyodide.console import PyodideConsole, repr_shorten, BANNER
|
|
108
|
+
import __main__
|
|
109
|
+
BANNER = "Welcome to the Pyodide terminal emulator 🐍\\n" + BANNER
|
|
110
|
+
pyconsole = PyodideConsole(__main__.__dict__)
|
|
111
|
+
import builtins
|
|
112
|
+
async def await_fut(fut):
|
|
113
|
+
res = await fut
|
|
114
|
+
if res is not None:
|
|
115
|
+
builtins._ = res
|
|
116
|
+
return to_js([res], depth=1)
|
|
117
|
+
def clear_console():
|
|
118
|
+
pyconsole.buffer = []
|
|
119
|
+
`,
|
|
120
|
+
{ globals: namespace },
|
|
121
|
+
);
|
|
122
|
+
let repr_shorten = namespace.get("repr_shorten");
|
|
123
|
+
let banner = namespace.get("BANNER");
|
|
124
|
+
let await_fut = namespace.get("await_fut");
|
|
125
|
+
let pyconsole = namespace.get("pyconsole");
|
|
126
|
+
let clear_console = namespace.get("clear_console");
|
|
127
|
+
const echo = (msg, ...opts) =>
|
|
128
|
+
term.echo(
|
|
129
|
+
msg
|
|
130
|
+
.replaceAll("]]", "]]")
|
|
131
|
+
.replaceAll("[[", "[["),
|
|
132
|
+
...opts,
|
|
133
|
+
);
|
|
134
|
+
namespace.destroy();
|
|
135
|
+
|
|
136
|
+
let ps1 = ">>> ",
|
|
137
|
+
ps2 = "... ";
|
|
138
|
+
|
|
139
|
+
async function lock() {
|
|
140
|
+
let resolve;
|
|
141
|
+
let ready = term.ready;
|
|
142
|
+
term.ready = new Promise((res) => (resolve = res));
|
|
143
|
+
await ready;
|
|
144
|
+
return resolve;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function interpreter(command) {
|
|
148
|
+
let unlock = await lock();
|
|
149
|
+
term.pause();
|
|
150
|
+
// multiline should be split (useful when pasting)
|
|
151
|
+
for (const c of command.split("\n")) {
|
|
152
|
+
const escaped = c.replaceAll(/\u00a0/g, " ");
|
|
153
|
+
let fut = pyconsole.push(escaped);
|
|
154
|
+
term.set_prompt(fut.syntax_check === "incomplete" ? ps2 : ps1);
|
|
155
|
+
switch (fut.syntax_check) {
|
|
156
|
+
case "syntax-error":
|
|
157
|
+
term.error(fut.formatted_error.trimEnd());
|
|
158
|
+
continue;
|
|
159
|
+
case "incomplete":
|
|
160
|
+
continue;
|
|
161
|
+
case "complete":
|
|
162
|
+
break;
|
|
163
|
+
default:
|
|
164
|
+
throw new Error(`Unexpected type ${ty}`);
|
|
165
|
+
}
|
|
166
|
+
// In JavaScript, await automatically also awaits any results of
|
|
167
|
+
// awaits, so if an async function returns a future, it will await
|
|
168
|
+
// the inner future too. This is not what we want so we
|
|
169
|
+
// temporarily put it into a list to protect it.
|
|
170
|
+
let wrapped = await_fut(fut);
|
|
171
|
+
// complete case, get result / error and print it.
|
|
172
|
+
try {
|
|
173
|
+
let [value] = await wrapped;
|
|
174
|
+
if (value !== undefined) {
|
|
175
|
+
echo(
|
|
176
|
+
repr_shorten.callKwargs(value, {
|
|
177
|
+
separator: "\n<long output truncated>\n",
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
if (value instanceof pyodide.ffi.PyProxy) {
|
|
182
|
+
value.destroy();
|
|
183
|
+
}
|
|
184
|
+
} catch (e) {
|
|
185
|
+
if (e.constructor.name === "PythonError") {
|
|
186
|
+
const message = fut.formatted_error || e.message;
|
|
187
|
+
term.error(message.trimEnd());
|
|
188
|
+
} else {
|
|
189
|
+
throw e;
|
|
190
|
+
}
|
|
191
|
+
} finally {
|
|
192
|
+
fut.destroy();
|
|
193
|
+
wrapped.destroy();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
term.resume();
|
|
197
|
+
await sleep(10);
|
|
198
|
+
unlock();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
term = $("body").terminal(interpreter, {
|
|
202
|
+
greetings: banner,
|
|
203
|
+
prompt: ps1,
|
|
204
|
+
completionEscape: false,
|
|
205
|
+
completion: function (command, callback) {
|
|
206
|
+
callback(pyconsole.complete(command).toJs()[0]);
|
|
207
|
+
},
|
|
208
|
+
keymap: {
|
|
209
|
+
"CTRL+C": async function (event, original) {
|
|
210
|
+
clear_console();
|
|
211
|
+
term.enter();
|
|
212
|
+
echo("KeyboardInterrupt");
|
|
213
|
+
term.set_command("");
|
|
214
|
+
term.set_prompt(ps1);
|
|
215
|
+
},
|
|
216
|
+
TAB: (event, original) => {
|
|
217
|
+
const command = term.before_cursor();
|
|
218
|
+
// Disable completion for whitespaces.
|
|
219
|
+
if (command.trim() === "") {
|
|
220
|
+
term.insert("\t");
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return original(event);
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
window.term = term;
|
|
228
|
+
pyconsole.stdout_callback = (s) => echo(s, { newline: false });
|
|
229
|
+
pyconsole.stderr_callback = (s) => {
|
|
230
|
+
term.error(s.trimEnd());
|
|
231
|
+
};
|
|
232
|
+
term.ready = Promise.resolve();
|
|
233
|
+
pyodide._api.on_fatal = async (e) => {
|
|
234
|
+
if (e.name === "Exit") {
|
|
235
|
+
term.error(e);
|
|
236
|
+
term.error("Pyodide exited and can no longer be used.");
|
|
237
|
+
} else {
|
|
238
|
+
term.error(
|
|
239
|
+
"Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers.",
|
|
240
|
+
);
|
|
241
|
+
term.error("The cause of the fatal error was:");
|
|
242
|
+
term.error(e);
|
|
243
|
+
term.error("Look in the browser console for more details.");
|
|
244
|
+
}
|
|
245
|
+
await term.ready;
|
|
246
|
+
term.pause();
|
|
247
|
+
await sleep(15);
|
|
248
|
+
term.pause();
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
252
|
+
if (searchParams.has("noblink")) {
|
|
253
|
+
$(".cmd-cursor").addClass("noblink");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
window.console_ready = main();
|
|
257
|
+
</script>
|
|
258
|
+
</body>
|
|
259
|
+
</html>
|