@muxen/web 0.0.0-stage → 0.2.0
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/LICENSE +502 -0
- package/README.md +18 -2
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +515 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +107 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/worker.d.ts +17 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +340 -0
- package/dist/worker.js.map +1 -0
- package/package.json +65 -3
- package/src/index.ts +589 -0
- package/src/protocol.ts +40 -0
- package/src/worker.ts +415 -0
- package/wasm/muxen-mt.mjs +2 -0
- package/wasm/muxen-mt.wasm +0 -0
- package/wasm/muxen-st.mjs +2 -0
- package/wasm/muxen-st.wasm +0 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/** Messages between the page and a host worker. */
|
|
2
|
+
export type WorkerInput = {
|
|
3
|
+
kind: "blob";
|
|
4
|
+
blob: Blob;
|
|
5
|
+
format?: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: "bytes";
|
|
8
|
+
data: Uint8Array;
|
|
9
|
+
format?: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "http";
|
|
12
|
+
url: string;
|
|
13
|
+
size: number;
|
|
14
|
+
format?: string;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "path";
|
|
17
|
+
path: string;
|
|
18
|
+
format?: string;
|
|
19
|
+
};
|
|
20
|
+
export type WorkerOutput = {
|
|
21
|
+
kind: "memory";
|
|
22
|
+
format?: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "chunks";
|
|
25
|
+
format?: string;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "opfs";
|
|
28
|
+
handle: FileSystemFileHandle;
|
|
29
|
+
format?: string;
|
|
30
|
+
};
|
|
31
|
+
export interface WorkerJob {
|
|
32
|
+
threads: number;
|
|
33
|
+
progressInterval: number;
|
|
34
|
+
logLevel: string;
|
|
35
|
+
progress: boolean;
|
|
36
|
+
log: boolean;
|
|
37
|
+
}
|
|
38
|
+
export type ToWorker = {
|
|
39
|
+
t: "init";
|
|
40
|
+
variant: "mt" | "st";
|
|
41
|
+
base?: string;
|
|
42
|
+
warm?: number;
|
|
43
|
+
} | {
|
|
44
|
+
t: "caps";
|
|
45
|
+
id: number;
|
|
46
|
+
} | {
|
|
47
|
+
t: "run";
|
|
48
|
+
id: number;
|
|
49
|
+
task: string;
|
|
50
|
+
inputs: WorkerInput[];
|
|
51
|
+
output: WorkerOutput | null;
|
|
52
|
+
options: string;
|
|
53
|
+
job: WorkerJob;
|
|
54
|
+
} | {
|
|
55
|
+
t: "cancel";
|
|
56
|
+
id: number;
|
|
57
|
+
} | {
|
|
58
|
+
t: "open";
|
|
59
|
+
id: number;
|
|
60
|
+
kind: "frames" | "samples";
|
|
61
|
+
input: WorkerInput;
|
|
62
|
+
options: string;
|
|
63
|
+
job: WorkerJob;
|
|
64
|
+
}
|
|
65
|
+
/** `reader` is the open request's id; `id` is this request's own (a close may overtake an open or a next). */
|
|
66
|
+
| {
|
|
67
|
+
t: "next";
|
|
68
|
+
id: number;
|
|
69
|
+
reader: number;
|
|
70
|
+
} | {
|
|
71
|
+
t: "close";
|
|
72
|
+
id: number;
|
|
73
|
+
reader: number;
|
|
74
|
+
};
|
|
75
|
+
export type FromWorker = {
|
|
76
|
+
t: "ready";
|
|
77
|
+
version: string;
|
|
78
|
+
} | {
|
|
79
|
+
t: "progress";
|
|
80
|
+
id: number;
|
|
81
|
+
progress: import("@muxen/core").Progress;
|
|
82
|
+
} | {
|
|
83
|
+
t: "log";
|
|
84
|
+
id: number;
|
|
85
|
+
level: string;
|
|
86
|
+
message: string;
|
|
87
|
+
} | {
|
|
88
|
+
t: "chunk";
|
|
89
|
+
id: number;
|
|
90
|
+
data: Uint8Array;
|
|
91
|
+
} | {
|
|
92
|
+
t: "done";
|
|
93
|
+
id: number;
|
|
94
|
+
json: string;
|
|
95
|
+
data?: Uint8Array;
|
|
96
|
+
} | {
|
|
97
|
+
t: "error";
|
|
98
|
+
id: number;
|
|
99
|
+
code: string;
|
|
100
|
+
message: string;
|
|
101
|
+
}
|
|
102
|
+
/** The module is unusable (it aborted: out of memory, a trap): the page replaces the worker. */
|
|
103
|
+
| {
|
|
104
|
+
t: "fatal";
|
|
105
|
+
message: string;
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,mDAAmD;AAEnD,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5D;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpD,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,oBAAoB,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;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AAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,CAAC,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,aAAa,EAAE,QAAQ,CAAA;CAAE,GACvE;IAAE,CAAC,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,CAAC,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,GAC5C;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAE,GAC1D;IAAE,CAAC,EAAE,OAAO,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE;AAC3D,gGAAgG;GAC9F;IAAE,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The host worker: owns one WebAssembly instance and runs jobs on it.
|
|
3
|
+
*
|
|
4
|
+
* With threads (the -mt module) every job runs on its own pthread and this
|
|
5
|
+
* worker only dispatches, so several jobs share one instance and one heap,
|
|
6
|
+
* and a job is cancelled by setting a flag. Without threads (-st) a job runs
|
|
7
|
+
* here and blocks this worker until it ends; the main thread keeps a pool of
|
|
8
|
+
* these workers and cancels a job by terminating its worker.
|
|
9
|
+
*
|
|
10
|
+
* Inputs are read synchronously from here, which the core needs: a Blob
|
|
11
|
+
* through FileReaderSync, http(s) through synchronous range XHRs, bytes from
|
|
12
|
+
* memory. Never copied whole into the heap.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
package/dist/worker.js
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
// src/worker.ts
|
|
2
|
+
var scope = globalThis;
|
|
3
|
+
var isNode = typeof process !== "undefined" && !!process.versions?.node && typeof window === "undefined" && typeof globalThis.WorkerGlobalScope === "undefined";
|
|
4
|
+
var mod;
|
|
5
|
+
var heapView;
|
|
6
|
+
var sources = /* @__PURE__ */ new Map();
|
|
7
|
+
var sinks = /* @__PURE__ */ new Map();
|
|
8
|
+
var nextIoId = 1;
|
|
9
|
+
var waiting = /* @__PURE__ */ new Map();
|
|
10
|
+
var early = /* @__PURE__ */ new Map();
|
|
11
|
+
var starting;
|
|
12
|
+
var jobOf = /* @__PURE__ */ new Map();
|
|
13
|
+
function heap() {
|
|
14
|
+
const buf = mod.wasmMemory.buffer;
|
|
15
|
+
if (!heapView || heapView.buffer !== buf) heapView = new Uint8Array(buf);
|
|
16
|
+
return heapView;
|
|
17
|
+
}
|
|
18
|
+
function post(m, transfer = []) {
|
|
19
|
+
scope.postMessage(m, transfer);
|
|
20
|
+
}
|
|
21
|
+
function blobSource(blob) {
|
|
22
|
+
const reader = new FileReaderSync();
|
|
23
|
+
return {
|
|
24
|
+
size: blob.size,
|
|
25
|
+
read(offset, length) {
|
|
26
|
+
return new Uint8Array(reader.readAsArrayBuffer(blob.slice(offset, offset + length)));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function bytesSource(data) {
|
|
31
|
+
return { size: data.length, read: (o, l) => data.subarray(o, o + l) };
|
|
32
|
+
}
|
|
33
|
+
function httpSource(url, size) {
|
|
34
|
+
return {
|
|
35
|
+
size,
|
|
36
|
+
read(offset, length) {
|
|
37
|
+
const xhr = new XMLHttpRequest();
|
|
38
|
+
xhr.open("GET", url, false);
|
|
39
|
+
xhr.responseType = "arraybuffer";
|
|
40
|
+
xhr.setRequestHeader("Range", `bytes=${offset}-${Math.min(size, offset + length) - 1}`);
|
|
41
|
+
xhr.send();
|
|
42
|
+
if (xhr.status !== 206 && xhr.status !== 200) return null;
|
|
43
|
+
const buf = new Uint8Array(xhr.response);
|
|
44
|
+
return xhr.status === 200 ? buf.subarray(offset, offset + length) : buf;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function nativeInput(i) {
|
|
49
|
+
if (i.kind === "path") return { kind: "url", url: i.path, ...i.format ? { format: i.format } : {} };
|
|
50
|
+
const id = nextIoId++;
|
|
51
|
+
const src = i.kind === "blob" ? blobSource(i.blob) : i.kind === "bytes" ? bytesSource(i.data) : httpSource(i.url, i.size);
|
|
52
|
+
sources.set(id, src);
|
|
53
|
+
return { kind: "js", id, size: src.size, ...i.format ? { format: i.format } : {} };
|
|
54
|
+
}
|
|
55
|
+
function chunkSink(jobId) {
|
|
56
|
+
let parts = [];
|
|
57
|
+
let bytes = 0;
|
|
58
|
+
const flush = () => {
|
|
59
|
+
if (!bytes) return;
|
|
60
|
+
const out = new Uint8Array(bytes);
|
|
61
|
+
let o = 0;
|
|
62
|
+
for (const p of parts) {
|
|
63
|
+
out.set(p, o);
|
|
64
|
+
o += p.length;
|
|
65
|
+
}
|
|
66
|
+
parts = [];
|
|
67
|
+
bytes = 0;
|
|
68
|
+
post({ t: "chunk", id: jobId, data: out }, [out.buffer]);
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
seekable: false,
|
|
72
|
+
write(data) {
|
|
73
|
+
parts.push(data.slice());
|
|
74
|
+
bytes += data.length;
|
|
75
|
+
if (bytes >= 1 << 20) flush();
|
|
76
|
+
},
|
|
77
|
+
finish: flush
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async function opfsSink(handle2) {
|
|
81
|
+
const access = await handle2.createSyncAccessHandle();
|
|
82
|
+
access.truncate(0);
|
|
83
|
+
let pos = 0;
|
|
84
|
+
return {
|
|
85
|
+
seekable: true,
|
|
86
|
+
write(data) {
|
|
87
|
+
access.write(data, { at: pos });
|
|
88
|
+
pos += data.length;
|
|
89
|
+
},
|
|
90
|
+
seek(p) {
|
|
91
|
+
pos = p;
|
|
92
|
+
},
|
|
93
|
+
finish() {
|
|
94
|
+
access.flush();
|
|
95
|
+
access.close();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async function nativeOutput(o, jobId) {
|
|
100
|
+
if (!o) return { json: null };
|
|
101
|
+
const format = o.format ? { format: o.format } : {};
|
|
102
|
+
if (o.kind === "memory") return { json: { kind: "memory", ...format } };
|
|
103
|
+
const sink = o.kind === "opfs" ? await opfsSink(o.handle) : chunkSink(jobId);
|
|
104
|
+
const id = nextIoId++;
|
|
105
|
+
sinks.set(id, sink);
|
|
106
|
+
return { json: { kind: "sink", id, seekable: sink.seekable, ...format }, sink, id };
|
|
107
|
+
}
|
|
108
|
+
function str(s) {
|
|
109
|
+
return mod.stringToNewUTF8(s);
|
|
110
|
+
}
|
|
111
|
+
function withStrings(values, fn) {
|
|
112
|
+
const ptrs = values.map(str);
|
|
113
|
+
try {
|
|
114
|
+
return fn(...ptrs);
|
|
115
|
+
} finally {
|
|
116
|
+
for (const p of ptrs) mod._ffb_free(p);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function await_(nativeId) {
|
|
120
|
+
const e = early.get(nativeId);
|
|
121
|
+
if (e) {
|
|
122
|
+
early.delete(nativeId);
|
|
123
|
+
return Promise.resolve(e);
|
|
124
|
+
}
|
|
125
|
+
return new Promise((resolve) => waiting.set(nativeId, (ok, json, data, code) => resolve([ok, json, data, code])));
|
|
126
|
+
}
|
|
127
|
+
async function load(variant, base) {
|
|
128
|
+
let create;
|
|
129
|
+
if (base) {
|
|
130
|
+
const url = new URL(`muxen-${variant}.mjs`, base).href;
|
|
131
|
+
create = (await import(
|
|
132
|
+
/* @vite-ignore */
|
|
133
|
+
/* webpackIgnore: true */
|
|
134
|
+
url
|
|
135
|
+
)).default;
|
|
136
|
+
} else {
|
|
137
|
+
create = variant === "mt" ? (
|
|
138
|
+
// @ts-ignore: generated by Emscripten, untyped
|
|
139
|
+
(await import("../wasm/muxen-mt.mjs")).default
|
|
140
|
+
) : (
|
|
141
|
+
// @ts-ignore: generated by Emscripten, untyped
|
|
142
|
+
(await import("../wasm/muxen-st.mjs")).default
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const level = (n) => n <= 16 ? "error" : n <= 24 ? "warning" : n <= 32 ? "info" : n <= 40 ? "verbose" : "debug";
|
|
146
|
+
mod = await create({
|
|
147
|
+
...base ? { locateFile: (f) => new URL(f, base).href } : {},
|
|
148
|
+
// The module aborted (out of memory, a trap): nothing on it can run again.
|
|
149
|
+
onAbort(what) {
|
|
150
|
+
fatal(`aborted: ${String(what)}`);
|
|
151
|
+
},
|
|
152
|
+
ffbSourceRead(id, offset, dst, len) {
|
|
153
|
+
const s = sources.get(id);
|
|
154
|
+
if (!s) return -1;
|
|
155
|
+
try {
|
|
156
|
+
const bytes = s.read(offset, len);
|
|
157
|
+
if (!bytes) return -1;
|
|
158
|
+
heap().set(bytes, dst);
|
|
159
|
+
return bytes.length;
|
|
160
|
+
} catch {
|
|
161
|
+
return -1;
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
ffbSinkWrite(id, src, len) {
|
|
165
|
+
const s = sinks.get(id);
|
|
166
|
+
if (!s) return -1;
|
|
167
|
+
try {
|
|
168
|
+
s.write(heap().subarray(src, src + len));
|
|
169
|
+
return 0;
|
|
170
|
+
} catch {
|
|
171
|
+
return -1;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
ffbSinkSeek(id, pos) {
|
|
175
|
+
const s = sinks.get(id);
|
|
176
|
+
if (!s?.seek) return -1;
|
|
177
|
+
s.seek(pos);
|
|
178
|
+
return pos;
|
|
179
|
+
},
|
|
180
|
+
ffbEvent(nativeId, kind, text) {
|
|
181
|
+
const msg = mod.UTF8ToString(text);
|
|
182
|
+
mod._ffb_free(text);
|
|
183
|
+
const id = jobOf.get(nativeId) ?? starting;
|
|
184
|
+
if (id === void 0) return;
|
|
185
|
+
if (kind === 0) post({ t: "progress", id, progress: JSON.parse(msg) });
|
|
186
|
+
else {
|
|
187
|
+
const tab = msg.indexOf(" ");
|
|
188
|
+
post({ t: "log", id, level: level(Number(msg.slice(0, tab))), message: msg.slice(tab + 1) });
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
ffbComplete(nativeId, ok, json, data, len, code) {
|
|
192
|
+
const text = mod.UTF8ToString(json);
|
|
193
|
+
const c = mod.UTF8ToString(code);
|
|
194
|
+
const bytes = len > 0 ? heap().slice(data, data + len) : void 0;
|
|
195
|
+
mod._ffb_free(json);
|
|
196
|
+
mod._ffb_free(code);
|
|
197
|
+
if (data) mod._ffb_free(data);
|
|
198
|
+
const w = waiting.get(nativeId);
|
|
199
|
+
if (w) {
|
|
200
|
+
waiting.delete(nativeId);
|
|
201
|
+
w(ok === 1, text, bytes, c);
|
|
202
|
+
} else {
|
|
203
|
+
early.set(nativeId, [ok === 1, text, bytes, c]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
var nativeOf = /* @__PURE__ */ new Map();
|
|
209
|
+
var LEVELS = { quiet: -8, error: 16, warning: 24, info: 32, verbose: 40, debug: 48 };
|
|
210
|
+
function jobJson(job) {
|
|
211
|
+
return JSON.stringify({
|
|
212
|
+
threads: job.threads,
|
|
213
|
+
progressInterval: job.progressInterval,
|
|
214
|
+
logLevel: LEVELS[job.logLevel] ?? 24,
|
|
215
|
+
progress: job.progress,
|
|
216
|
+
log: job.log
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
async function handle(m) {
|
|
220
|
+
switch (m.t) {
|
|
221
|
+
case "init": {
|
|
222
|
+
try {
|
|
223
|
+
await load(m.variant, m.base);
|
|
224
|
+
const p = mod._ffb_version();
|
|
225
|
+
const version = mod.UTF8ToString(p);
|
|
226
|
+
mod._ffb_free(p);
|
|
227
|
+
post({ t: "ready", version });
|
|
228
|
+
if (m.warm) mod._ffb_warm?.(m.warm);
|
|
229
|
+
} catch (e) {
|
|
230
|
+
post({ t: "error", id: -1, code: "INTERNAL", message: `can't load the WebAssembly module: ${e.message}` });
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
case "caps": {
|
|
235
|
+
const p = mod._ffb_capabilities();
|
|
236
|
+
const json = mod.UTF8ToString(p);
|
|
237
|
+
mod._ffb_free(p);
|
|
238
|
+
post({ t: "done", id: m.id, json });
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
case "run": {
|
|
242
|
+
const ioIds = [];
|
|
243
|
+
let out;
|
|
244
|
+
try {
|
|
245
|
+
const inputs = m.inputs.map((i) => {
|
|
246
|
+
const n = nativeInput(i);
|
|
247
|
+
if (n.id) ioIds.push(n.id);
|
|
248
|
+
return n;
|
|
249
|
+
});
|
|
250
|
+
out = await nativeOutput(m.output, m.id);
|
|
251
|
+
const kinds = ["probe", "transcode", "thumbnail", "waveform"];
|
|
252
|
+
if (!kinds.includes(m.task)) throw new Error(`unknown task ${m.task}`);
|
|
253
|
+
starting = m.id;
|
|
254
|
+
const nativeId = withStrings(
|
|
255
|
+
[m.task, JSON.stringify(inputs), JSON.stringify(out.json), m.options, jobJson(m.job)],
|
|
256
|
+
(k, i, o, opt, j) => mod._ffb_start(k, i, o, opt, j)
|
|
257
|
+
);
|
|
258
|
+
starting = void 0;
|
|
259
|
+
jobOf.set(nativeId, m.id);
|
|
260
|
+
nativeOf.set(m.id, nativeId);
|
|
261
|
+
const [ok, json, data, code] = await await_(nativeId);
|
|
262
|
+
jobOf.delete(nativeId);
|
|
263
|
+
nativeOf.delete(m.id);
|
|
264
|
+
out.sink?.finish?.();
|
|
265
|
+
if (ok) post({ t: "done", id: m.id, json, ...data ? { data } : {} }, data ? [data.buffer] : []);
|
|
266
|
+
else post({ t: "error", id: m.id, code, message: json });
|
|
267
|
+
} catch (e) {
|
|
268
|
+
if (e instanceof WebAssembly.RuntimeError) throw e;
|
|
269
|
+
post({ t: "error", id: m.id, code: "INTERNAL", message: e.message });
|
|
270
|
+
} finally {
|
|
271
|
+
for (const id of ioIds) sources.delete(id);
|
|
272
|
+
if (out?.id) sinks.delete(out.id);
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
case "cancel": {
|
|
277
|
+
const n = nativeOf.get(m.id);
|
|
278
|
+
if (n !== void 0) mod._ffb_cancel(n);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
case "open": {
|
|
282
|
+
const n = nativeInput(m.input);
|
|
283
|
+
const nativeId = withStrings([m.kind, JSON.stringify(n), m.options, jobJson(m.job)], (k, i, o, j) => mod._ffb_reader_open(k, i, o, j));
|
|
284
|
+
nativeOf.set(m.id, nativeId);
|
|
285
|
+
readerIo.set(m.id, n.id);
|
|
286
|
+
const [ok, json, , code] = await await_(nativeId);
|
|
287
|
+
if (ok) post({ t: "done", id: m.id, json });
|
|
288
|
+
else post({ t: "error", id: m.id, code, message: json });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
case "next": {
|
|
292
|
+
const nativeId = nativeOf.get(m.reader);
|
|
293
|
+
if (nativeId === void 0) return post({ t: "done", id: m.id, json: "null" });
|
|
294
|
+
mod._ffb_reader_next(nativeId);
|
|
295
|
+
const [ok, json, data, code] = await await_(nativeId);
|
|
296
|
+
if (ok) post({ t: "done", id: m.id, json, ...data ? { data } : {} }, data ? [data.buffer] : []);
|
|
297
|
+
else post({ t: "error", id: m.id, code, message: json });
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
case "close": {
|
|
301
|
+
const nativeId = nativeOf.get(m.reader);
|
|
302
|
+
if (nativeId !== void 0) mod._ffb_reader_close(nativeId);
|
|
303
|
+
nativeOf.delete(m.reader);
|
|
304
|
+
const io = readerIo.get(m.reader);
|
|
305
|
+
if (io) sources.delete(io);
|
|
306
|
+
readerIo.delete(m.reader);
|
|
307
|
+
post({ t: "done", id: m.id, json: "null" });
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
var readerIo = /* @__PURE__ */ new Map();
|
|
313
|
+
var dead = false;
|
|
314
|
+
function fatal(message) {
|
|
315
|
+
if (dead) return;
|
|
316
|
+
dead = true;
|
|
317
|
+
post({ t: "fatal", message });
|
|
318
|
+
}
|
|
319
|
+
async function safely(m) {
|
|
320
|
+
try {
|
|
321
|
+
if (dead) throw new Error("the module aborted");
|
|
322
|
+
await handle(m);
|
|
323
|
+
} catch (e) {
|
|
324
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
325
|
+
if (e instanceof WebAssembly.RuntimeError || /^Aborted\(/.test(message)) fatal(message);
|
|
326
|
+
else if ("id" in m) post({ t: "error", id: m.id, code: "INTERNAL", message });
|
|
327
|
+
else fatal(message);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (isNode) {
|
|
331
|
+
const { parentPort } = await import(
|
|
332
|
+
/* @vite-ignore */
|
|
333
|
+
"worker_threads"
|
|
334
|
+
);
|
|
335
|
+
scope.postMessage = (m, t) => parentPort.postMessage(m, t);
|
|
336
|
+
parentPort.on("message", (m) => void safely(m));
|
|
337
|
+
} else {
|
|
338
|
+
scope.onmessage = (e) => void safely(e.data);
|
|
339
|
+
}
|
|
340
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/worker.ts"],"sourcesContent":["/**\n * The host worker: owns one WebAssembly instance and runs jobs on it.\n *\n * With threads (the -mt module) every job runs on its own pthread and this\n * worker only dispatches, so several jobs share one instance and one heap,\n * and a job is cancelled by setting a flag. Without threads (-st) a job runs\n * here and blocks this worker until it ends; the main thread keeps a pool of\n * these workers and cancels a job by terminating its worker.\n *\n * Inputs are read synchronously from here, which the core needs: a Blob\n * through FileReaderSync, http(s) through synchronous range XHRs, bytes from\n * memory. Never copied whole into the heap.\n *\n * @module\n */\n\n/// <reference lib=\"webworker\" />\n\nimport type { ToWorker, FromWorker, WorkerInput, WorkerJob, WorkerOutput } from \"./protocol.js\";\n\ntype Module = {\n _ffb_start(kind: number, inputs: number, output: number, options: number, job: number): number;\n _ffb_cancel(id: number): void;\n _ffb_reader_open(kind: number, input: number, options: number, job: number): number;\n _ffb_reader_next(id: number): void;\n _ffb_reader_close(id: number): void;\n _ffb_capabilities(): number;\n _ffb_version(): number;\n /** Absent from modules built before it (a CDN copy of an older build). */\n _ffb_warm?(threads: number): void;\n _ffb_free(p: number): void;\n UTF8ToString(p: number): string;\n stringToNewUTF8(s: string): number;\n wasmMemory: WebAssembly.Memory;\n};\n\ninterface Source {\n size: number;\n read(offset: number, length: number): Uint8Array | null;\n}\n\ninterface Sink {\n seekable: boolean;\n write(data: Uint8Array): void;\n seek?(pos: number): void;\n finish?(): void;\n}\n\nconst scope = globalThis as unknown as DedicatedWorkerGlobalScope & { postMessage(m: FromWorker, t?: Transferable[]): void };\nconst isNode = typeof process !== \"undefined\" && !!(process as { versions?: { node?: string } }).versions?.node && typeof window === \"undefined\" && typeof (globalThis as any).WorkerGlobalScope === \"undefined\";\n\nlet mod: Module | undefined;\nlet heapView: Uint8Array | undefined;\nconst sources = new Map<number, Source>();\nconst sinks = new Map<number, Sink>();\nlet nextIoId = 1;\n\n/** Completions by native id; st completions may arrive before we know the id. */\nconst waiting = new Map<number, (ok: boolean, json: string, data: Uint8Array | undefined, code: string) => void>();\nconst early = new Map<number, [boolean, string, Uint8Array | undefined, string]>();\n/** The job being started: a single-threaded build reports progress before _ffb_start returns. */\nlet starting: number | undefined;\n/** Native id → the main thread's job id, for progress and logs. */\nconst jobOf = new Map<number, number>();\n\nfunction heap(): Uint8Array {\n const buf = mod!.wasmMemory.buffer;\n if (!heapView || heapView.buffer !== buf) heapView = new Uint8Array(buf);\n return heapView;\n}\n\nfunction post(m: FromWorker, transfer: Transferable[] = []) {\n scope.postMessage(m, transfer);\n}\n\n// ---------------------------------------------------------------------------\n// Sources\n\nfunction blobSource(blob: Blob): Source {\n const reader = new FileReaderSync();\n return {\n size: blob.size,\n read(offset, length) {\n return new Uint8Array(reader.readAsArrayBuffer(blob.slice(offset, offset + length)));\n },\n };\n}\n\nfunction bytesSource(data: Uint8Array): Source {\n return { size: data.length, read: (o, l) => data.subarray(o, o + l) };\n}\n\nfunction httpSource(url: string, size: number): Source {\n return {\n size,\n read(offset, length) {\n const xhr = new XMLHttpRequest();\n xhr.open(\"GET\", url, false);\n xhr.responseType = \"arraybuffer\";\n xhr.setRequestHeader(\"Range\", `bytes=${offset}-${Math.min(size, offset + length) - 1}`);\n xhr.send();\n if (xhr.status !== 206 && xhr.status !== 200) return null;\n const buf = new Uint8Array(xhr.response as ArrayBuffer);\n // A server that ignored the range sent everything: cut our part out.\n return xhr.status === 200 ? buf.subarray(offset, offset + length) : buf;\n },\n };\n}\n\nfunction nativeInput(i: WorkerInput): object {\n if (i.kind === \"path\") return { kind: \"url\", url: i.path, ...(i.format ? { format: i.format } : {}) };\n const id = nextIoId++;\n const src = i.kind === \"blob\" ? blobSource(i.blob) : i.kind === \"bytes\" ? bytesSource(i.data) : httpSource(i.url, i.size);\n sources.set(id, src);\n return { kind: \"js\", id, size: src.size, ...(i.format ? { format: i.format } : {}) };\n}\n\n// ---------------------------------------------------------------------------\n// Sinks\n\nfunction chunkSink(jobId: number): Sink {\n // Batched to ~1 MiB per message: fewer, larger transfers.\n let parts: Uint8Array[] = [];\n let bytes = 0;\n const flush = () => {\n if (!bytes) return;\n const out = new Uint8Array(bytes);\n let o = 0;\n for (const p of parts) { out.set(p, o); o += p.length; }\n parts = [];\n bytes = 0;\n post({ t: \"chunk\", id: jobId, data: out }, [out.buffer]);\n };\n return {\n seekable: false,\n write(data) {\n parts.push(data.slice());\n bytes += data.length;\n if (bytes >= 1 << 20) flush();\n },\n finish: flush,\n };\n}\n\nasync function opfsSink(handle: FileSystemFileHandle): Promise<Sink> {\n const access = await (handle as any).createSyncAccessHandle();\n access.truncate(0);\n let pos = 0;\n return {\n seekable: true,\n write(data) {\n access.write(data, { at: pos });\n pos += data.length;\n },\n seek(p) { pos = p; },\n finish() { access.flush(); access.close(); },\n };\n}\n\nasync function nativeOutput(o: WorkerOutput | null, jobId: number): Promise<{ json: object | null; sink?: Sink; id?: number }> {\n if (!o) return { json: null };\n const format = o.format ? { format: o.format } : {};\n if (o.kind === \"memory\") return { json: { kind: \"memory\", ...format } };\n const sink = o.kind === \"opfs\" ? await opfsSink(o.handle) : chunkSink(jobId);\n const id = nextIoId++;\n sinks.set(id, sink);\n return { json: { kind: \"sink\", id, seekable: sink.seekable, ...format }, sink, id };\n}\n\n// ---------------------------------------------------------------------------\n// Native calls\n\nfunction str(s: string): number {\n return mod!.stringToNewUTF8(s);\n}\n\nfunction withStrings<T>(values: string[], fn: (...ptrs: number[]) => T): T {\n const ptrs = values.map(str);\n try {\n return fn(...ptrs);\n } finally {\n for (const p of ptrs) mod!._ffb_free(p);\n }\n}\n\nfunction await_(nativeId: number): Promise<[boolean, string, Uint8Array | undefined, string]> {\n const e = early.get(nativeId);\n if (e) {\n early.delete(nativeId);\n return Promise.resolve(e);\n }\n return new Promise((resolve) => waiting.set(nativeId, (ok, json, data, code) => resolve([ok, json, data, code])));\n}\n\nasync function load(variant: \"mt\" | \"st\", base: string | undefined) {\n type Create = (m: object) => Promise<Module>;\n let create: Create;\n if (base) {\n // Served from elsewhere (a CDN): load it from there, past the bundler.\n const url = new URL(`muxen-${variant}.mjs`, base).href;\n create = (await import(/* @vite-ignore */ /* webpackIgnore: true */ url)).default;\n } else {\n // Literal paths, so bundlers follow them: they emit the module, its .wasm\n // (new URL(\"muxen-*.wasm\", import.meta.url) inside) and its pthread workers.\n create =\n variant === \"mt\"\n ? // @ts-ignore: generated by Emscripten, untyped\n ((await import(\"../wasm/muxen-mt.mjs\")).default as Create)\n : // @ts-ignore: generated by Emscripten, untyped\n ((await import(\"../wasm/muxen-st.mjs\")).default as Create);\n }\n const level = (n: number) => (n <= 16 ? \"error\" : n <= 24 ? \"warning\" : n <= 32 ? \"info\" : n <= 40 ? \"verbose\" : \"debug\");\n mod = await create({\n ...(base ? { locateFile: (f: string) => new URL(f, base).href } : {}),\n // The module aborted (out of memory, a trap): nothing on it can run again.\n onAbort(what: unknown) {\n fatal(`aborted: ${String(what)}`);\n },\n ffbSourceRead(id: number, offset: number, dst: number, len: number): number {\n const s = sources.get(id);\n if (!s) return -1;\n try {\n const bytes = s.read(offset, len);\n if (!bytes) return -1;\n heap().set(bytes, dst);\n return bytes.length;\n } catch {\n return -1;\n }\n },\n ffbSinkWrite(id: number, src: number, len: number): number {\n const s = sinks.get(id);\n if (!s) return -1;\n try {\n s.write(heap().subarray(src, src + len));\n return 0;\n } catch {\n return -1;\n }\n },\n ffbSinkSeek(id: number, pos: number): number {\n const s = sinks.get(id);\n if (!s?.seek) return -1;\n s.seek(pos);\n return pos;\n },\n ffbEvent(nativeId: number, kind: number, text: number) {\n const msg = mod!.UTF8ToString(text);\n mod!._ffb_free(text);\n const id = jobOf.get(nativeId) ?? starting;\n if (id === undefined) return;\n if (kind === 0) post({ t: \"progress\", id, progress: JSON.parse(msg) });\n else {\n const tab = msg.indexOf(\"\\t\");\n post({ t: \"log\", id, level: level(Number(msg.slice(0, tab))), message: msg.slice(tab + 1) });\n }\n },\n ffbComplete(nativeId: number, ok: number, json: number, data: number, len: number, code: number) {\n const text = mod!.UTF8ToString(json);\n const c = mod!.UTF8ToString(code);\n const bytes = len > 0 ? heap().slice(data, data + len) : undefined;\n mod!._ffb_free(json);\n mod!._ffb_free(code);\n if (data) mod!._ffb_free(data);\n const w = waiting.get(nativeId);\n if (w) {\n waiting.delete(nativeId);\n w(ok === 1, text, bytes, c);\n } else {\n early.set(nativeId, [ok === 1, text, bytes, c]);\n }\n },\n });\n}\n\n/** Main-thread job id → native id, to cancel. */\nconst nativeOf = new Map<number, number>();\n\nconst LEVELS: Record<string, number> = { quiet: -8, error: 16, warning: 24, info: 32, verbose: 40, debug: 48 };\n\nfunction jobJson(job: WorkerJob): string {\n return JSON.stringify({\n threads: job.threads,\n progressInterval: job.progressInterval,\n logLevel: LEVELS[job.logLevel] ?? 24,\n progress: job.progress,\n log: job.log,\n });\n}\n\nasync function handle(m: ToWorker) {\n switch (m.t) {\n case \"init\": {\n try {\n await load(m.variant, m.base);\n const p = mod!._ffb_version();\n const version = mod!.UTF8ToString(p);\n mod!._ffb_free(p);\n post({ t: \"ready\", version });\n if (m.warm) mod!._ffb_warm?.(m.warm);\n } catch (e) {\n post({ t: \"error\", id: -1, code: \"INTERNAL\", message: `can't load the WebAssembly module: ${(e as Error).message}` });\n }\n return;\n }\n case \"caps\": {\n const p = mod!._ffb_capabilities();\n const json = mod!.UTF8ToString(p);\n mod!._ffb_free(p);\n post({ t: \"done\", id: m.id, json });\n return;\n }\n case \"run\": {\n const ioIds: number[] = [];\n let out: Awaited<ReturnType<typeof nativeOutput>> | undefined;\n try {\n const inputs = m.inputs.map((i) => {\n const n = nativeInput(i) as { id?: number };\n if (n.id) ioIds.push(n.id);\n return n;\n });\n out = await nativeOutput(m.output, m.id);\n const kinds = [\"probe\", \"transcode\", \"thumbnail\", \"waveform\"];\n if (!kinds.includes(m.task)) throw new Error(`unknown task ${m.task}`);\n starting = m.id;\n const nativeId = withStrings([m.task, JSON.stringify(inputs), JSON.stringify(out.json), m.options, jobJson(m.job)], (k, i, o, opt, j) =>\n mod!._ffb_start(k!, i!, o!, opt!, j!),\n );\n starting = undefined;\n jobOf.set(nativeId, m.id);\n nativeOf.set(m.id, nativeId);\n const [ok, json, data, code] = await await_(nativeId);\n jobOf.delete(nativeId);\n nativeOf.delete(m.id);\n out.sink?.finish?.();\n if (ok) post({ t: \"done\", id: m.id, json, ...(data ? { data } : {}) }, data ? [data.buffer] : []);\n else post({ t: \"error\", id: m.id, code, message: json });\n } catch (e) {\n if (e instanceof WebAssembly.RuntimeError) throw e;\n post({ t: \"error\", id: m.id, code: \"INTERNAL\", message: (e as Error).message });\n } finally {\n for (const id of ioIds) sources.delete(id);\n if (out?.id) sinks.delete(out.id);\n }\n return;\n }\n case \"cancel\": {\n const n = nativeOf.get(m.id);\n if (n !== undefined) mod!._ffb_cancel(n);\n return;\n }\n case \"open\": {\n const n = nativeInput(m.input) as { id?: number };\n const nativeId = withStrings([m.kind, JSON.stringify(n), m.options, jobJson(m.job)], (k, i, o, j) => mod!._ffb_reader_open(k!, i!, o!, j!));\n nativeOf.set(m.id, nativeId);\n readerIo.set(m.id, n.id);\n const [ok, json, , code] = await await_(nativeId);\n if (ok) post({ t: \"done\", id: m.id, json });\n else post({ t: \"error\", id: m.id, code, message: json });\n return;\n }\n case \"next\": {\n const nativeId = nativeOf.get(m.reader);\n if (nativeId === undefined) return post({ t: \"done\", id: m.id, json: \"null\" });\n mod!._ffb_reader_next(nativeId);\n const [ok, json, data, code] = await await_(nativeId);\n if (ok) post({ t: \"done\", id: m.id, json, ...(data ? { data } : {}) }, data ? [data.buffer] : []);\n else post({ t: \"error\", id: m.id, code, message: json });\n return;\n }\n case \"close\": {\n const nativeId = nativeOf.get(m.reader);\n if (nativeId !== undefined) mod!._ffb_reader_close(nativeId);\n nativeOf.delete(m.reader);\n const io = readerIo.get(m.reader);\n if (io) sources.delete(io);\n readerIo.delete(m.reader);\n post({ t: \"done\", id: m.id, json: \"null\" });\n return;\n }\n }\n}\n\nconst readerIo = new Map<number, number | undefined>();\n\nlet dead = false;\n/** Tells the page this worker is unusable; it rejects what ran here and replaces it. */\nfunction fatal(message: string) {\n if (dead) return;\n dead = true;\n post({ t: \"fatal\", message });\n}\n\n/** Every message gets an answer, even when handling it throws. */\nasync function safely(m: ToWorker) {\n try {\n if (dead) throw new Error(\"the module aborted\");\n await handle(m);\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n if (e instanceof WebAssembly.RuntimeError || /^Aborted\\(/.test(message)) fatal(message);\n else if (\"id\" in m) post({ t: \"error\", id: m.id, code: \"INTERNAL\", message });\n else fatal(message);\n }\n}\n\n// Messages are handled in order per kind, but a long job must not block the\n// next message (a cancel): handle() is async and never awaited here.\nif (isNode) {\n const { parentPort } = await import(/* @vite-ignore */ \"node:worker_threads\" as string);\n (scope as any).postMessage = (m: unknown, t?: Transferable[]) => parentPort.postMessage(m, t);\n parentPort.on(\"message\", (m: ToWorker) => void safely(m));\n} else {\n scope.onmessage = (e: MessageEvent<ToWorker>) => void safely(e.data);\n}\n"],"mappings":";AAgDA,IAAM,QAAQ;AACd,IAAM,SAAS,OAAO,YAAY,eAAe,CAAC,CAAE,QAA6C,UAAU,QAAQ,OAAO,WAAW,eAAe,OAAQ,WAAmB,sBAAsB;AAErM,IAAI;AACJ,IAAI;AACJ,IAAM,UAAU,oBAAI,IAAoB;AACxC,IAAM,QAAQ,oBAAI,IAAkB;AACpC,IAAI,WAAW;AAGf,IAAM,UAAU,oBAAI,IAA6F;AACjH,IAAM,QAAQ,oBAAI,IAA+D;AAEjF,IAAI;AAEJ,IAAM,QAAQ,oBAAI,IAAoB;AAEtC,SAAS,OAAmB;AAC1B,QAAM,MAAM,IAAK,WAAW;AAC5B,MAAI,CAAC,YAAY,SAAS,WAAW,IAAK,YAAW,IAAI,WAAW,GAAG;AACvE,SAAO;AACT;AAEA,SAAS,KAAK,GAAe,WAA2B,CAAC,GAAG;AAC1D,QAAM,YAAY,GAAG,QAAQ;AAC/B;AAKA,SAAS,WAAW,MAAoB;AACtC,QAAM,SAAS,IAAI,eAAe;AAClC,SAAO;AAAA,IACL,MAAM,KAAK;AAAA,IACX,KAAK,QAAQ,QAAQ;AACnB,aAAO,IAAI,WAAW,OAAO,kBAAkB,KAAK,MAAM,QAA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M,YAAY,QAAQ,CAAC;AAAA,QACvE,OAAM,OAAO;AAAA,EACpB;AACF;AAIA,IAAI,QAAQ;AACV,QAAM,EAAE,WAAW,IAAI,MAAM;AAAA;AAAA,IAA0B;AAAA,EAA+B;AACtF,EAAC,MAAc,cAAc,CAAC,GAAY,MAAuB,WAAW,YAAY,GAAG,CAAC;AAC5F,aAAW,GAAG,WAAW,CAAC,MAAgB,KAAK,OAAO,CAAC,CAAC;AAC1D,OAAO;AACL,QAAM,YAAY,CAAC,MAA8B,KAAK,OAAO,EAAE,IAAI;AACrE;","names":["handle"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@muxen/web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Muxen for the browser: One FFmpeg API for web, React Native and Node. FFmpeg compiled to WebAssembly in Web Workers, multi-threaded on cross-origin isolated pages; files are read in slices, never copied whole.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ffmpeg",
|
|
7
|
+
"video",
|
|
8
|
+
"audio",
|
|
9
|
+
"wasm",
|
|
10
|
+
"react-native",
|
|
11
|
+
"muxen",
|
|
12
|
+
"webassembly",
|
|
13
|
+
"ffmpeg.wasm",
|
|
14
|
+
"transcode",
|
|
15
|
+
"thumbnail",
|
|
16
|
+
"waveform",
|
|
17
|
+
"browser",
|
|
18
|
+
"web-worker"
|
|
19
|
+
],
|
|
20
|
+
"homepage": "https://muxen.dev",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/the-haus/muxen/issues"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/the-haus/muxen.git",
|
|
27
|
+
"directory": "packages/web"
|
|
28
|
+
},
|
|
29
|
+
"license": "LGPL-2.1-or-later",
|
|
30
|
+
"type": "module",
|
|
31
|
+
"module": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./worker": "./dist/worker.js",
|
|
39
|
+
"./wasm/*": "./wasm/*",
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"wasm/*.mjs",
|
|
46
|
+
"wasm/*.wasm",
|
|
47
|
+
"src",
|
|
48
|
+
"README.md"
|
|
49
|
+
],
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@muxen/core": "0.2.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@vitest/browser-playwright": "5.1.2",
|
|
55
|
+
"playwright": "1.65.2",
|
|
56
|
+
"vitest": "5.1.2"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build:native": "./build.sh",
|
|
63
|
+
"build": "tsup src/index.ts src/worker.ts --format esm --sourcemap --clean --target es2022 --external ../wasm/muxen-mt.mjs --external ../wasm/muxen-st.mjs && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
64
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"test:browser": "vitest run --config vitest.browser.config.ts"
|
|
67
|
+
}
|
|
6
68
|
}
|