fixed wasm (LaserKaspar/go-wasm-pdfcpu), migrated to vite in backend, dynamic operators on frontend

446742b7de
This commit is contained in:
Felix Kaspar
2024-05-12 00:35:29 +02:00
parent 52fae8e41b
commit 9cb499c93f
13 changed files with 366 additions and 642 deletions

View File

@@ -0,0 +1,37 @@
import memfs from 'memfs';
globalThis.fs = memfs.fs;
import "./wasm_exec.js";
const encoder = new TextEncoder("utf-8");
const decoder = new TextDecoder("utf-8");
let outputBuf = "";
globalThis.fs.writeSyncOriginal = globalThis.fs.writeSync;
globalThis.fs.writeSync = function(fd, buf) {
if (fd === 1 || fd === 2) {
outputBuf += decoder.decode(buf);
const nl = outputBuf.lastIndexOf("\n");
if (nl != -1) {
console.log(outputBuf.substr(0, nl));
outputBuf = outputBuf.substr(nl + 1);
}
return buf.length;
} else {
return globalThis.fs.writeSyncOriginal(...arguments);
}
};
globalThis.fs.writeOriginal = globalThis.fs.write;
globalThis.fs.write = function(fd, buf, offset, length, position, callback) {
if (fd === 1 || fd === 2) {
if (offset !== 0 || length !== buf.length || position !== null) {
throw new Error("fs func not implemented");
}
const n = this.writeSync(fd, buf);
callback(null, n, buf);
} else {
return globalThis.fs.writeOriginal(...arguments);
}
};