@squoosh-kit/jxl 0.2.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/bridge.d.ts +16 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/index.browser.mjs +797 -0
- package/dist/index.browser.mjs.map +20 -0
- package/dist/index.bun.js +798 -0
- package/dist/index.bun.js.map +20 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.cjs +825 -0
- package/dist/index.node.cjs.map +20 -0
- package/dist/index.node.mjs +797 -0
- package/dist/index.node.mjs.map +20 -0
- package/dist/jxl.worker.browser.mjs +699 -0
- package/dist/jxl.worker.browser.mjs.map +18 -0
- package/dist/jxl.worker.bun.js +700 -0
- package/dist/jxl.worker.bun.js.map +18 -0
- package/dist/jxl.worker.d.ts +14 -0
- package/dist/jxl.worker.d.ts.map +1 -0
- package/dist/jxl.worker.node.cjs +718 -0
- package/dist/jxl.worker.node.cjs.map +18 -0
- package/dist/jxl.worker.node.mjs +699 -0
- package/dist/jxl.worker.node.mjs.map +18 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validators.d.ts +2 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/wasm/jxl-dec/jxl_dec.d.ts +7 -0
- package/dist/wasm/jxl-dec/jxl_dec.js +16 -0
- package/dist/wasm/jxl-dec/jxl_dec.wasm +0 -0
- package/dist/wasm/jxl-dec/jxl_node_dec.js +16 -0
- package/dist/wasm/jxl-dec/jxl_node_dec.wasm +0 -0
- package/dist/wasm/jxl-enc/jxl_enc.d.ts +23 -0
- package/dist/wasm/jxl-enc/jxl_enc.js +16 -0
- package/dist/wasm/jxl-enc/jxl_enc.wasm +0 -0
- package/dist/wasm/jxl-enc/jxl_enc_mt.d.ts +1 -0
- package/dist/wasm/jxl-enc/jxl_enc_mt.js +16 -0
- package/dist/wasm/jxl-enc/jxl_enc_mt.wasm +0 -0
- package/dist/wasm/jxl-enc/jxl_enc_mt.worker.js +1 -0
- package/dist/wasm/jxl-enc/jxl_enc_mt_simd.d.ts +1 -0
- package/dist/wasm/jxl-enc/jxl_enc_mt_simd.js +16 -0
- package/dist/wasm/jxl-enc/jxl_enc_mt_simd.wasm +0 -0
- package/dist/wasm/jxl-enc/jxl_enc_mt_simd.worker.js +1 -0
- package/dist/wasm/jxl-enc/jxl_node_enc.js +16 -0
- package/dist/wasm/jxl-enc/jxl_node_enc.wasm +0 -0
- package/package.json +49 -0
|
@@ -0,0 +1,797 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __returnValue = (v) => v;
|
|
3
|
+
function __exportSetter(name, newValue) {
|
|
4
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
+
}
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
set: __exportSetter.bind(all, name)
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
16
|
+
|
|
17
|
+
// ../runtime/src/env.ts
|
|
18
|
+
function isBun() {
|
|
19
|
+
return typeof Bun !== "undefined";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ../runtime/src/worker-call.ts
|
|
23
|
+
async function callWorker(worker, type, payload, signal, transfer) {
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const id = ++requestId;
|
|
26
|
+
if (signal?.aborted) {
|
|
27
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const handleMessage = (event) => {
|
|
31
|
+
const response = event.data;
|
|
32
|
+
if (response.id !== id)
|
|
33
|
+
return;
|
|
34
|
+
cleanup();
|
|
35
|
+
if (response.ok && response.data !== undefined) {
|
|
36
|
+
resolve(response.data);
|
|
37
|
+
} else {
|
|
38
|
+
reject(new Error(response.error || "Unknown worker error"));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const handleError = (error) => {
|
|
42
|
+
cleanup();
|
|
43
|
+
reject(new Error(`Worker error: ${error.message}`));
|
|
44
|
+
};
|
|
45
|
+
const handleAbort = () => {
|
|
46
|
+
cleanup();
|
|
47
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
48
|
+
};
|
|
49
|
+
const cleanup = () => {
|
|
50
|
+
worker.removeEventListener("message", handleMessage);
|
|
51
|
+
worker.removeEventListener("error", handleError);
|
|
52
|
+
signal?.removeEventListener("abort", handleAbort);
|
|
53
|
+
};
|
|
54
|
+
worker.addEventListener("message", handleMessage);
|
|
55
|
+
worker.addEventListener("error", handleError);
|
|
56
|
+
signal?.addEventListener("abort", handleAbort);
|
|
57
|
+
const request = { type, id, payload };
|
|
58
|
+
if (transfer && transfer.length > 0) {
|
|
59
|
+
worker.postMessage(request, transfer);
|
|
60
|
+
} else {
|
|
61
|
+
worker.postMessage(request);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
var requestId = 0;
|
|
66
|
+
|
|
67
|
+
// ../runtime/src/worker-helper.ts
|
|
68
|
+
function createCodecWorker(workerFilename, options) {
|
|
69
|
+
const normalizedName = workerFilename.endsWith(".js") ? workerFilename : `${workerFilename}.js`;
|
|
70
|
+
const workerMap = {
|
|
71
|
+
"resize.worker.js": {
|
|
72
|
+
package: "@squoosh-kit/resize",
|
|
73
|
+
specifier: "resize.worker.js"
|
|
74
|
+
},
|
|
75
|
+
"webp.worker.js": {
|
|
76
|
+
package: "@squoosh-kit/webp",
|
|
77
|
+
specifier: "webp.worker.js"
|
|
78
|
+
},
|
|
79
|
+
"avif.worker.js": {
|
|
80
|
+
package: "@squoosh-kit/avif",
|
|
81
|
+
specifier: "avif.worker.js"
|
|
82
|
+
},
|
|
83
|
+
"mozjpeg.worker.js": {
|
|
84
|
+
package: "@squoosh-kit/mozjpeg",
|
|
85
|
+
specifier: "mozjpeg.worker.js"
|
|
86
|
+
},
|
|
87
|
+
"jxl.worker.js": {
|
|
88
|
+
package: "@squoosh-kit/jxl",
|
|
89
|
+
specifier: "jxl.worker.js"
|
|
90
|
+
},
|
|
91
|
+
"oxipng.worker.js": {
|
|
92
|
+
package: "@squoosh-kit/oxipng",
|
|
93
|
+
specifier: "oxipng.worker.js"
|
|
94
|
+
},
|
|
95
|
+
"png.worker.js": {
|
|
96
|
+
package: "@squoosh-kit/png",
|
|
97
|
+
specifier: "png.worker.js"
|
|
98
|
+
},
|
|
99
|
+
"imagequant.worker.js": {
|
|
100
|
+
package: "@squoosh-kit/imagequant",
|
|
101
|
+
specifier: "imagequant.worker.js"
|
|
102
|
+
},
|
|
103
|
+
"qoi.worker.js": {
|
|
104
|
+
package: "@squoosh-kit/qoi",
|
|
105
|
+
specifier: "qoi.worker.js"
|
|
106
|
+
},
|
|
107
|
+
"wp2.worker.js": {
|
|
108
|
+
package: "@squoosh-kit/wp2",
|
|
109
|
+
specifier: "wp2.worker.js"
|
|
110
|
+
},
|
|
111
|
+
"hqx.worker.js": {
|
|
112
|
+
package: "@squoosh-kit/hqx",
|
|
113
|
+
specifier: "hqx.worker.js"
|
|
114
|
+
},
|
|
115
|
+
"rotate.worker.js": {
|
|
116
|
+
package: "@squoosh-kit/rotate",
|
|
117
|
+
specifier: "rotate.worker.js"
|
|
118
|
+
},
|
|
119
|
+
"visdif.worker.js": {
|
|
120
|
+
package: "@squoosh-kit/visdif",
|
|
121
|
+
specifier: "visdif.worker.js"
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const workerConfig = workerMap[normalizedName];
|
|
125
|
+
if (!workerConfig) {
|
|
126
|
+
throw new Error(`Unknown worker: ${normalizedName}. ` + `Supported workers: ${Object.keys(workerMap).join(", ")}`);
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
if (typeof window !== "undefined") {
|
|
130
|
+
const packageName = workerConfig.package.split("/")[1];
|
|
131
|
+
const workerFile = normalizedName.replace(".js", ".browser.mjs");
|
|
132
|
+
console.log(`[worker-helper] In browser environment. Trying to create worker:`);
|
|
133
|
+
console.log(`[worker-helper] - Package Name: ${packageName}`);
|
|
134
|
+
console.log(`[worker-helper] - Worker File: ${workerFile}`);
|
|
135
|
+
if (options?.assetPath) {
|
|
136
|
+
let normalizedAssetPath = options.assetPath;
|
|
137
|
+
if (!normalizedAssetPath.startsWith("/")) {
|
|
138
|
+
normalizedAssetPath = "/" + normalizedAssetPath;
|
|
139
|
+
}
|
|
140
|
+
if (normalizedAssetPath.endsWith("/")) {
|
|
141
|
+
normalizedAssetPath = normalizedAssetPath.slice(0, -1);
|
|
142
|
+
}
|
|
143
|
+
const workerPath = `${normalizedAssetPath}/${packageName}/${workerFile}`;
|
|
144
|
+
const workerUrl = new URL(workerPath, window.location.origin).href;
|
|
145
|
+
console.log(`[worker-helper] Using provided assetPath. Full Worker URL: ${workerUrl}`);
|
|
146
|
+
try {
|
|
147
|
+
const worker = new Worker(workerUrl, { type: "module" });
|
|
148
|
+
console.log(`[worker-helper] Successfully created worker with assetPath: ${workerUrl}`);
|
|
149
|
+
return worker;
|
|
150
|
+
} catch (e) {
|
|
151
|
+
console.error(`[worker-helper] Failed to load worker from assetPath URL: ${workerUrl}`, e);
|
|
152
|
+
throw new Error(`Worker failed to load from ${workerUrl}: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const pathStrategies = [
|
|
156
|
+
`../../${packageName}/dist/${workerFile}`,
|
|
157
|
+
`../../../node_modules/@squoosh-kit/${packageName}/dist/${workerFile}`,
|
|
158
|
+
`../../../${packageName}/dist/${workerFile}`
|
|
159
|
+
];
|
|
160
|
+
let lastError = null;
|
|
161
|
+
for (const relPath of pathStrategies) {
|
|
162
|
+
console.log("relPath:", relPath);
|
|
163
|
+
console.log("import.meta.url:", import.meta.url);
|
|
164
|
+
try {
|
|
165
|
+
const workerUrl = new URL(relPath, import.meta.url);
|
|
166
|
+
console.log(`[worker-helper] Trying path strategy. Full Worker URL: ${workerUrl.href}`);
|
|
167
|
+
const worker = new Worker(workerUrl, {
|
|
168
|
+
type: "module"
|
|
169
|
+
});
|
|
170
|
+
console.log(`[worker-helper] Successfully created worker with URL: ${workerUrl.href}`);
|
|
171
|
+
return worker;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.warn(`[worker-helper] Path strategy failed for ${relPath}:`, error);
|
|
174
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (lastError) {
|
|
178
|
+
console.error("[worker-helper] All path strategies failed.", lastError);
|
|
179
|
+
throw lastError;
|
|
180
|
+
}
|
|
181
|
+
throw new Error(`Could not resolve worker ${normalizedName} using any available path strategy`);
|
|
182
|
+
}
|
|
183
|
+
const platformExt = isBun() ? ".bun.js" : ".node.mjs";
|
|
184
|
+
const baseName = normalizedName.replace(".js", "");
|
|
185
|
+
const pkgName = workerConfig.package.split("/")[1];
|
|
186
|
+
const srcRelPath = `../../${pkgName}/src/${baseName}.ts`;
|
|
187
|
+
console.log("srcRelPath:", srcRelPath);
|
|
188
|
+
console.log("import.meta.url:", import.meta.url);
|
|
189
|
+
try {
|
|
190
|
+
return new Worker(new URL(srcRelPath, import.meta.url), {
|
|
191
|
+
type: "module"
|
|
192
|
+
});
|
|
193
|
+
} catch {
|
|
194
|
+
const distRelPath = `../../${pkgName}/dist/${baseName}.${platformExt.slice(1)}`;
|
|
195
|
+
console.log("distRelPath:", distRelPath);
|
|
196
|
+
console.log("import.meta.url:", import.meta.url);
|
|
197
|
+
try {
|
|
198
|
+
return new Worker(new URL(distRelPath, import.meta.url), {
|
|
199
|
+
type: "module"
|
|
200
|
+
});
|
|
201
|
+
} catch {
|
|
202
|
+
if (typeof import.meta.resolve === "function") {
|
|
203
|
+
try {
|
|
204
|
+
const resolved = import.meta.resolve(`${workerConfig.package}/${workerConfig.specifier}`);
|
|
205
|
+
console.log("resolved:", resolved);
|
|
206
|
+
return new Worker(resolved, { type: "module" });
|
|
207
|
+
} catch {}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
throw new Error(`Failed to create worker from ${normalizedName}. ` + `Tried TypeScript source, dist output, and import.meta.resolve. ` + `Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed.`);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
214
|
+
throw new Error(`Failed to create worker from ${normalizedName}: ${errorMessage}. ` + `Ensure the @squoosh-kit/resize and @squoosh-kit/webp packages are installed. ` + `If you're using Vite, ensure the worker files are not being optimized as dependencies.`, { cause: error });
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function createReadyWorker(workerFilename, options, timeoutMs = 1e4) {
|
|
218
|
+
return new Promise((resolve, reject) => {
|
|
219
|
+
const timeout = setTimeout(() => {
|
|
220
|
+
reject(new Error(`Worker initialization timeout after ${timeoutMs}ms. Worker file: ${workerFilename}`));
|
|
221
|
+
}, timeoutMs);
|
|
222
|
+
let worker;
|
|
223
|
+
try {
|
|
224
|
+
worker = createCodecWorker(workerFilename, options);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
clearTimeout(timeout);
|
|
227
|
+
reject(error);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const handleMessage = (event) => {
|
|
231
|
+
if (event.data?.type === "worker:ready") {
|
|
232
|
+
clearTimeout(timeout);
|
|
233
|
+
worker.removeEventListener("message", handleMessage);
|
|
234
|
+
worker.removeEventListener("error", handleError);
|
|
235
|
+
worker.removeEventListener("messageerror", handleMessageError);
|
|
236
|
+
resolve(worker);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const handleError = (event) => {
|
|
240
|
+
clearTimeout(timeout);
|
|
241
|
+
worker.removeEventListener("message", handleMessage);
|
|
242
|
+
worker.removeEventListener("error", handleError);
|
|
243
|
+
worker.removeEventListener("messageerror", handleMessageError);
|
|
244
|
+
reject(new Error(`Worker failed to start: ${event?.message || "Unknown error"}. Worker file: ${workerFilename}`));
|
|
245
|
+
};
|
|
246
|
+
const handleMessageError = () => {
|
|
247
|
+
clearTimeout(timeout);
|
|
248
|
+
worker.removeEventListener("message", handleMessage);
|
|
249
|
+
worker.removeEventListener("error", handleError);
|
|
250
|
+
worker.removeEventListener("messageerror", handleMessageError);
|
|
251
|
+
reject(new Error(`Worker message error during initialization. Worker file: ${workerFilename}`));
|
|
252
|
+
};
|
|
253
|
+
worker.addEventListener("message", handleMessage);
|
|
254
|
+
worker.addEventListener("error", handleError);
|
|
255
|
+
worker.addEventListener("messageerror", handleMessageError);
|
|
256
|
+
worker.postMessage({ type: "worker:ping" });
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
var init_worker_helper = () => {};
|
|
260
|
+
|
|
261
|
+
// ../runtime/src/wasm-loader.ts
|
|
262
|
+
async function loadWasmBinary(relativePath, baseUrlOverride) {
|
|
263
|
+
const baseUrl = baseUrlOverride ? typeof baseUrlOverride === "string" ? new URL(".", baseUrlOverride) : new URL(".", baseUrlOverride.href) : new URL(".", import.meta.url);
|
|
264
|
+
const fullUrl = new URL(relativePath, baseUrl);
|
|
265
|
+
console.log(`[WasmLoader] Loading WASM from relative path: ${relativePath}`);
|
|
266
|
+
console.log(`[WasmLoader] Base URL (import.meta.url): ${baseUrl.href}`);
|
|
267
|
+
console.log(`[WasmLoader] Constructed full URL: ${fullUrl.href}`);
|
|
268
|
+
try {
|
|
269
|
+
const response = await fetch(fullUrl.href);
|
|
270
|
+
console.log(`[WasmLoader] Fetch response status for ${fullUrl.href}: ${response.status}`);
|
|
271
|
+
if (!response.ok) {
|
|
272
|
+
const responseText = await response.text();
|
|
273
|
+
console.error(`[WasmLoader] Fetch response text (first 500 chars):`, responseText.substring(0, 500));
|
|
274
|
+
throw new Error(`Failed to fetch WASM module at ${fullUrl.href}: ${response.status} ${response.statusText}`);
|
|
275
|
+
}
|
|
276
|
+
const contentType = response.headers.get("content-type");
|
|
277
|
+
console.log(`[WasmLoader] Response Content-Type: ${contentType}`);
|
|
278
|
+
if (!contentType || !contentType.includes("application/wasm")) {
|
|
279
|
+
console.warn(`[WasmLoader] Warning: WASM module at ${fullUrl.href} served with incorrect MIME type: "${contentType}". Should be "application/wasm".`);
|
|
280
|
+
}
|
|
281
|
+
return await response.arrayBuffer();
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.error(`[WasmLoader] CRITICAL: Fetching WASM binary from ${fullUrl.href} failed.`, error);
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// ../runtime/src/validators.ts
|
|
289
|
+
function validateImageInput(image) {
|
|
290
|
+
if (!image || typeof image !== "object") {
|
|
291
|
+
throw new TypeError("image must be an object");
|
|
292
|
+
}
|
|
293
|
+
const imageObj = image;
|
|
294
|
+
if (!("data" in imageObj)) {
|
|
295
|
+
throw new TypeError("image.data is required");
|
|
296
|
+
}
|
|
297
|
+
const { data } = imageObj;
|
|
298
|
+
if (!(data instanceof Uint8Array || data instanceof Uint8ClampedArray)) {
|
|
299
|
+
throw new TypeError("image.data must be Uint8Array or Uint8ClampedArray");
|
|
300
|
+
}
|
|
301
|
+
if (!("width" in imageObj) || !("height" in imageObj)) {
|
|
302
|
+
throw new TypeError("image.width and image.height are required");
|
|
303
|
+
}
|
|
304
|
+
const { width, height } = imageObj;
|
|
305
|
+
if (typeof width !== "number" || !Number.isInteger(width) || width <= 0) {
|
|
306
|
+
throw new RangeError(`image.width must be a positive integer, got ${width}`);
|
|
307
|
+
}
|
|
308
|
+
if (typeof height !== "number" || !Number.isInteger(height) || height <= 0) {
|
|
309
|
+
throw new RangeError(`image.height must be a positive integer, got ${height}`);
|
|
310
|
+
}
|
|
311
|
+
const expectedSize = width * height * 4;
|
|
312
|
+
if (data.length < expectedSize) {
|
|
313
|
+
throw new RangeError(`image.data too small: ${data.length} bytes, expected at least ${expectedSize} bytes for ${width}x${height} RGBA image`);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// ../runtime/src/simd-detector.ts
|
|
317
|
+
var init_simd_detector = () => {};
|
|
318
|
+
|
|
319
|
+
// ../runtime/src/image-data-polyfill.ts
|
|
320
|
+
function polyfillImageData() {
|
|
321
|
+
if (typeof ImageData === "undefined") {
|
|
322
|
+
globalThis.ImageData = class {
|
|
323
|
+
data;
|
|
324
|
+
width;
|
|
325
|
+
height;
|
|
326
|
+
colorSpace = "srgb";
|
|
327
|
+
constructor(data, width, height) {
|
|
328
|
+
this.data = data;
|
|
329
|
+
this.width = width;
|
|
330
|
+
this.height = height;
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// ../runtime/src/index.ts
|
|
337
|
+
var init_src = __esm(() => {
|
|
338
|
+
init_worker_helper();
|
|
339
|
+
init_simd_detector();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// src/validators.ts
|
|
343
|
+
function validateJxlOptions(options) {
|
|
344
|
+
if (options === undefined) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (typeof options !== "object" || options === null) {
|
|
348
|
+
throw new TypeError("options must be an object or undefined");
|
|
349
|
+
}
|
|
350
|
+
const opts = options;
|
|
351
|
+
if ("quality" in opts && opts.quality !== undefined) {
|
|
352
|
+
const quality = opts.quality;
|
|
353
|
+
if (Number.isNaN(quality)) {
|
|
354
|
+
throw new RangeError("quality must be a valid number in the range 0-100, got NaN");
|
|
355
|
+
}
|
|
356
|
+
if (typeof quality !== "number") {
|
|
357
|
+
throw new TypeError("quality must be a number");
|
|
358
|
+
}
|
|
359
|
+
if (!Number.isFinite(quality) || !Number.isInteger(quality)) {
|
|
360
|
+
throw new RangeError("quality must be an integer in the range 0-100, got floating point");
|
|
361
|
+
}
|
|
362
|
+
if (quality < 0 || quality > 100) {
|
|
363
|
+
throw new RangeError(`quality must be in the range 0-100, got ${quality}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
if ("effort" in opts && opts.effort !== undefined) {
|
|
367
|
+
const effort = opts.effort;
|
|
368
|
+
if (typeof effort !== "number") {
|
|
369
|
+
throw new TypeError("effort must be a number");
|
|
370
|
+
}
|
|
371
|
+
if (!Number.isFinite(effort) || !Number.isInteger(effort)) {
|
|
372
|
+
throw new RangeError("effort must be an integer in the range 1-9");
|
|
373
|
+
}
|
|
374
|
+
if (effort < 1 || effort > 9) {
|
|
375
|
+
throw new RangeError(`effort must be in the range 1-9, got ${effort}`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if ("epf" in opts && opts.epf !== undefined) {
|
|
379
|
+
const epf = opts.epf;
|
|
380
|
+
if (typeof epf !== "number") {
|
|
381
|
+
throw new TypeError("epf must be a number");
|
|
382
|
+
}
|
|
383
|
+
if (!Number.isFinite(epf) || !Number.isInteger(epf)) {
|
|
384
|
+
throw new RangeError("epf must be an integer in the range -1 to 3");
|
|
385
|
+
}
|
|
386
|
+
if (epf < -1 || epf > 3) {
|
|
387
|
+
throw new RangeError(`epf must be in the range -1 to 3, got ${epf}`);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
if ("decodingSpeedTier" in opts && opts.decodingSpeedTier !== undefined) {
|
|
391
|
+
const decodingSpeedTier = opts.decodingSpeedTier;
|
|
392
|
+
if (typeof decodingSpeedTier !== "number") {
|
|
393
|
+
throw new TypeError("decodingSpeedTier must be a number");
|
|
394
|
+
}
|
|
395
|
+
if (!Number.isFinite(decodingSpeedTier) || !Number.isInteger(decodingSpeedTier)) {
|
|
396
|
+
throw new RangeError("decodingSpeedTier must be an integer in the range 0-4");
|
|
397
|
+
}
|
|
398
|
+
if (decodingSpeedTier < 0 || decodingSpeedTier > 4) {
|
|
399
|
+
throw new RangeError(`decodingSpeedTier must be in the range 0-4, got ${decodingSpeedTier}`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// src/jxl.worker.ts
|
|
405
|
+
var exports_jxl_worker = {};
|
|
406
|
+
__export(exports_jxl_worker, {
|
|
407
|
+
jxlEncodeClient: () => jxlEncodeClient,
|
|
408
|
+
jxlDecodeClient: () => jxlDecodeClient
|
|
409
|
+
});
|
|
410
|
+
function isNodeOrBun() {
|
|
411
|
+
return typeof process !== "undefined" && (process.versions?.bun !== undefined || process.versions?.node !== undefined);
|
|
412
|
+
}
|
|
413
|
+
async function loadJxlEncModule() {
|
|
414
|
+
if (cachedEncModule)
|
|
415
|
+
return cachedEncModule;
|
|
416
|
+
if (loadEncModulePromise)
|
|
417
|
+
return loadEncModulePromise;
|
|
418
|
+
loadEncModulePromise = (async () => {
|
|
419
|
+
const globalSelf = typeof self !== "undefined" ? self : globalThis;
|
|
420
|
+
if (!globalSelf.location) {
|
|
421
|
+
globalSelf.location = {
|
|
422
|
+
href: import.meta.url
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
if (typeof self === "undefined" && typeof globalThis !== "undefined") {
|
|
426
|
+
globalThis.self = globalThis;
|
|
427
|
+
}
|
|
428
|
+
const useNode = isNodeOrBun();
|
|
429
|
+
const modulePath = useNode ? "jxl-enc/jxl_node_enc.js" : "jxl-enc/jxl_enc.js";
|
|
430
|
+
try {
|
|
431
|
+
console.log("[JXL Worker] Initializing encoder. Node/Bun:", useNode);
|
|
432
|
+
console.log(`[JXL Worker] Attempting to import encoder module from path: ${modulePath}`);
|
|
433
|
+
let moduleFactory;
|
|
434
|
+
const isSource = import.meta.url.includes("/src/");
|
|
435
|
+
const pathsToTry = isSource ? ["../wasm/" + modulePath, "./wasm/" + modulePath] : ["./wasm/" + modulePath, "../wasm/" + modulePath];
|
|
436
|
+
let lastError = null;
|
|
437
|
+
for (const importPath of pathsToTry) {
|
|
438
|
+
try {
|
|
439
|
+
moduleFactory = (await import(importPath)).default;
|
|
440
|
+
console.log(`[JXL Worker] Successfully loaded encoder module from: ${importPath}`);
|
|
441
|
+
break;
|
|
442
|
+
} catch (error) {
|
|
443
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
444
|
+
console.warn(`[JXL Worker] Failed to load encoder from ${importPath}, trying next path...`);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (!moduleFactory) {
|
|
448
|
+
throw lastError || new Error("Could not load JXL encoder module from any path");
|
|
449
|
+
}
|
|
450
|
+
console.log("[JXL Worker] Encoder module factory loaded successfully.");
|
|
451
|
+
const wasmFile = useNode ? "jxl_node_enc.wasm" : "jxl_enc.wasm";
|
|
452
|
+
const wasmPathsToTry = isSource ? [`../wasm/jxl-enc/${wasmFile}`, `./wasm/jxl-enc/${wasmFile}`] : [`./wasm/jxl-enc/${wasmFile}`, `../wasm/jxl-enc/${wasmFile}`];
|
|
453
|
+
console.log(`[JXL Worker] Preparing to load encoder WASM binary. Will try paths: ${wasmPathsToTry.join(", ")}`);
|
|
454
|
+
const initModuleWithBinary = async (factory, wasmPaths) => {
|
|
455
|
+
const workerBaseUrl = new URL(".", import.meta.url);
|
|
456
|
+
let lastError2 = null;
|
|
457
|
+
for (const wasmPath of wasmPaths) {
|
|
458
|
+
try {
|
|
459
|
+
console.log(`[JXL Worker] Calling loadWasmBinary with path: ${wasmPath}`);
|
|
460
|
+
const wasmBinary = await loadWasmBinary(wasmPath, workerBaseUrl);
|
|
461
|
+
console.log(`[JXL Worker] Successfully fetched encoder WASM binary from ${wasmPath}. Size: ${wasmBinary.byteLength} bytes.`);
|
|
462
|
+
const globalSelf2 = typeof self !== "undefined" ? self : globalThis;
|
|
463
|
+
if (!globalSelf2.location) {
|
|
464
|
+
globalSelf2.location = {
|
|
465
|
+
href: import.meta.url
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
if (typeof self === "undefined" && typeof globalThis !== "undefined") {
|
|
469
|
+
globalThis.self = globalThis;
|
|
470
|
+
}
|
|
471
|
+
return await factory({
|
|
472
|
+
noInitialRun: true,
|
|
473
|
+
wasmBinary
|
|
474
|
+
});
|
|
475
|
+
} catch (err) {
|
|
476
|
+
lastError2 = err instanceof Error ? err : new Error(String(err));
|
|
477
|
+
console.warn(`[JXL Worker] Failed to load encoder WASM from ${wasmPath}, trying next path...`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
throw lastError2 || new Error("Could not load encoder WASM binary from any of the attempted paths");
|
|
481
|
+
};
|
|
482
|
+
cachedEncModule = await initModuleWithBinary(moduleFactory, wasmPathsToTry);
|
|
483
|
+
console.log("[JXL Worker] JXL encoder module initialized successfully.");
|
|
484
|
+
return cachedEncModule;
|
|
485
|
+
} catch (err) {
|
|
486
|
+
console.error(`[JXL Worker] CRITICAL: Failed to load JXL encoder module from path: ${modulePath}`, err);
|
|
487
|
+
throw err;
|
|
488
|
+
}
|
|
489
|
+
})().catch((err) => {
|
|
490
|
+
loadEncModulePromise = null;
|
|
491
|
+
throw err;
|
|
492
|
+
});
|
|
493
|
+
return loadEncModulePromise;
|
|
494
|
+
}
|
|
495
|
+
async function loadJxlDecModule() {
|
|
496
|
+
if (cachedDecModule)
|
|
497
|
+
return cachedDecModule;
|
|
498
|
+
if (loadDecModulePromise)
|
|
499
|
+
return loadDecModulePromise;
|
|
500
|
+
loadDecModulePromise = (async () => {
|
|
501
|
+
const globalSelf = typeof self !== "undefined" ? self : globalThis;
|
|
502
|
+
if (!globalSelf.location) {
|
|
503
|
+
globalSelf.location = {
|
|
504
|
+
href: import.meta.url
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
if (typeof self === "undefined" && typeof globalThis !== "undefined") {
|
|
508
|
+
globalThis.self = globalThis;
|
|
509
|
+
}
|
|
510
|
+
polyfillImageData();
|
|
511
|
+
const useNode = isNodeOrBun();
|
|
512
|
+
const modulePath = useNode ? "jxl-dec/jxl_node_dec.js" : "jxl-dec/jxl_dec.js";
|
|
513
|
+
try {
|
|
514
|
+
console.log("[JXL Worker] Initializing decoder. Node/Bun:", useNode);
|
|
515
|
+
console.log(`[JXL Worker] Attempting to import decoder module from path: ${modulePath}`);
|
|
516
|
+
let moduleFactory;
|
|
517
|
+
const isSource = import.meta.url.includes("/src/");
|
|
518
|
+
const pathsToTry = isSource ? ["../wasm/" + modulePath, "./wasm/" + modulePath] : ["./wasm/" + modulePath, "../wasm/" + modulePath];
|
|
519
|
+
let lastError = null;
|
|
520
|
+
for (const importPath of pathsToTry) {
|
|
521
|
+
try {
|
|
522
|
+
moduleFactory = (await import(importPath)).default;
|
|
523
|
+
console.log(`[JXL Worker] Successfully loaded decoder module from: ${importPath}`);
|
|
524
|
+
break;
|
|
525
|
+
} catch (error) {
|
|
526
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
527
|
+
console.warn(`[JXL Worker] Failed to load decoder from ${importPath}, trying next path...`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (!moduleFactory) {
|
|
531
|
+
throw lastError || new Error("Could not load JXL decoder module from any path");
|
|
532
|
+
}
|
|
533
|
+
console.log("[JXL Worker] Decoder module factory loaded successfully.");
|
|
534
|
+
const wasmFile = useNode ? "jxl_node_dec.wasm" : "jxl_dec.wasm";
|
|
535
|
+
const wasmPathsToTry = isSource ? [`../wasm/jxl-dec/${wasmFile}`, `./wasm/jxl-dec/${wasmFile}`] : [`./wasm/jxl-dec/${wasmFile}`, `../wasm/jxl-dec/${wasmFile}`];
|
|
536
|
+
console.log(`[JXL Worker] Preparing to load decoder WASM binary. Will try paths: ${wasmPathsToTry.join(", ")}`);
|
|
537
|
+
const initModuleWithBinary = async (factory, wasmPaths) => {
|
|
538
|
+
const workerBaseUrl = new URL(".", import.meta.url);
|
|
539
|
+
let lastError2 = null;
|
|
540
|
+
for (const wasmPath of wasmPaths) {
|
|
541
|
+
try {
|
|
542
|
+
console.log(`[JXL Worker] Calling loadWasmBinary with path: ${wasmPath}`);
|
|
543
|
+
const wasmBinary = await loadWasmBinary(wasmPath, workerBaseUrl);
|
|
544
|
+
console.log(`[JXL Worker] Successfully fetched decoder WASM binary from ${wasmPath}. Size: ${wasmBinary.byteLength} bytes.`);
|
|
545
|
+
const globalSelf2 = typeof self !== "undefined" ? self : globalThis;
|
|
546
|
+
if (!globalSelf2.location) {
|
|
547
|
+
globalSelf2.location = {
|
|
548
|
+
href: import.meta.url
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
if (typeof self === "undefined" && typeof globalThis !== "undefined") {
|
|
552
|
+
globalThis.self = globalThis;
|
|
553
|
+
}
|
|
554
|
+
return await factory({
|
|
555
|
+
noInitialRun: true,
|
|
556
|
+
wasmBinary
|
|
557
|
+
});
|
|
558
|
+
} catch (err) {
|
|
559
|
+
lastError2 = err instanceof Error ? err : new Error(String(err));
|
|
560
|
+
console.warn(`[JXL Worker] Failed to load decoder WASM from ${wasmPath}, trying next path...`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
throw lastError2 || new Error("Could not load decoder WASM binary from any of the attempted paths");
|
|
564
|
+
};
|
|
565
|
+
cachedDecModule = await initModuleWithBinary(moduleFactory, wasmPathsToTry);
|
|
566
|
+
console.log("[JXL Worker] JXL decoder module initialized successfully.");
|
|
567
|
+
return cachedDecModule;
|
|
568
|
+
} catch (err) {
|
|
569
|
+
console.error(`[JXL Worker] CRITICAL: Failed to load JXL decoder module from path: ${modulePath}`, err);
|
|
570
|
+
throw err;
|
|
571
|
+
}
|
|
572
|
+
})().catch((err) => {
|
|
573
|
+
loadDecModulePromise = null;
|
|
574
|
+
throw err;
|
|
575
|
+
});
|
|
576
|
+
return loadDecModulePromise;
|
|
577
|
+
}
|
|
578
|
+
function createEncodeOptions(options) {
|
|
579
|
+
return {
|
|
580
|
+
effort: options?.effort ?? 7,
|
|
581
|
+
quality: options?.quality ?? 75,
|
|
582
|
+
progressive: options?.progressive ?? false,
|
|
583
|
+
epf: options?.epf ?? -1,
|
|
584
|
+
lossyPalette: options?.lossyPalette ?? false,
|
|
585
|
+
decodingSpeedTier: options?.decodingSpeedTier ?? 0,
|
|
586
|
+
photonNoiseIso: options?.photonNoiseIso ?? 0,
|
|
587
|
+
lossyModular: options?.lossyModular ?? false
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
async function jxlEncodeClient(image, options, signal) {
|
|
591
|
+
validateImageInput(image);
|
|
592
|
+
validateJxlOptions(options);
|
|
593
|
+
if (signal?.aborted) {
|
|
594
|
+
throw new DOMException("Aborted", "AbortError");
|
|
595
|
+
}
|
|
596
|
+
const width = image.width;
|
|
597
|
+
const height = image.height;
|
|
598
|
+
const data = image.data;
|
|
599
|
+
if (!(data instanceof Uint8Array) && !(data instanceof Uint8ClampedArray)) {
|
|
600
|
+
throw new Error("Image data must be Uint8Array or Uint8ClampedArray");
|
|
601
|
+
}
|
|
602
|
+
const module = await loadJxlEncModule();
|
|
603
|
+
if (signal?.aborted) {
|
|
604
|
+
throw new DOMException("Aborted", "AbortError");
|
|
605
|
+
}
|
|
606
|
+
const encodeOptions = createEncodeOptions(options);
|
|
607
|
+
const dataArray = data instanceof Uint8ClampedArray ? new Uint8Array(data.buffer, data.byteOffset, data.length) : new Uint8Array(data.buffer, data.byteOffset, data.length);
|
|
608
|
+
const result = module.encode(dataArray, width, height, encodeOptions);
|
|
609
|
+
if (signal?.aborted) {
|
|
610
|
+
throw new DOMException("Aborted", "AbortError");
|
|
611
|
+
}
|
|
612
|
+
if (!result) {
|
|
613
|
+
throw new Error("JXL encoding failed");
|
|
614
|
+
}
|
|
615
|
+
return result;
|
|
616
|
+
}
|
|
617
|
+
async function jxlDecodeClient(data, signal) {
|
|
618
|
+
if (signal?.aborted) {
|
|
619
|
+
throw new DOMException("Aborted", "AbortError");
|
|
620
|
+
}
|
|
621
|
+
const module = await loadJxlDecModule();
|
|
622
|
+
if (signal?.aborted) {
|
|
623
|
+
throw new DOMException("Aborted", "AbortError");
|
|
624
|
+
}
|
|
625
|
+
const result = module.decode(data);
|
|
626
|
+
if (signal?.aborted) {
|
|
627
|
+
throw new DOMException("Aborted", "AbortError");
|
|
628
|
+
}
|
|
629
|
+
if (!result) {
|
|
630
|
+
throw new Error("JXL decoding failed");
|
|
631
|
+
}
|
|
632
|
+
return result;
|
|
633
|
+
}
|
|
634
|
+
var cachedEncModule = null, cachedDecModule = null, loadEncModulePromise = null, loadDecModulePromise = null;
|
|
635
|
+
var init_jxl_worker = __esm(() => {
|
|
636
|
+
init_src();
|
|
637
|
+
if (typeof self !== "undefined") {
|
|
638
|
+
self.onmessage = async (event) => {
|
|
639
|
+
const data = event.data;
|
|
640
|
+
if (data?.type === "worker:ping") {
|
|
641
|
+
await loadJxlEncModule();
|
|
642
|
+
self.postMessage({ type: "worker:ready" });
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
if (data?.type === "jxl:encode") {
|
|
646
|
+
const request = data;
|
|
647
|
+
const response = {
|
|
648
|
+
id: request.id,
|
|
649
|
+
ok: false
|
|
650
|
+
};
|
|
651
|
+
try {
|
|
652
|
+
const { image, options } = request.payload;
|
|
653
|
+
const result = await jxlEncodeClient(image, options);
|
|
654
|
+
response.ok = true;
|
|
655
|
+
response.data = result;
|
|
656
|
+
self.postMessage(response, {
|
|
657
|
+
transfer: [result.buffer]
|
|
658
|
+
});
|
|
659
|
+
} catch (error) {
|
|
660
|
+
response.error = error instanceof Error ? error.message : String(error);
|
|
661
|
+
self.postMessage(response);
|
|
662
|
+
}
|
|
663
|
+
} else if (data?.type === "jxl:decode") {
|
|
664
|
+
const request = data;
|
|
665
|
+
const response = {
|
|
666
|
+
id: request.id,
|
|
667
|
+
ok: false
|
|
668
|
+
};
|
|
669
|
+
try {
|
|
670
|
+
const result = await jxlDecodeClient(request.payload.data);
|
|
671
|
+
response.ok = true;
|
|
672
|
+
response.data = result;
|
|
673
|
+
self.postMessage(response, {
|
|
674
|
+
transfer: [result.data.buffer]
|
|
675
|
+
});
|
|
676
|
+
} catch (error) {
|
|
677
|
+
response.error = error instanceof Error ? error.message : String(error);
|
|
678
|
+
self.postMessage(response);
|
|
679
|
+
}
|
|
680
|
+
} else {
|
|
681
|
+
const request = data;
|
|
682
|
+
const response = {
|
|
683
|
+
id: request.id,
|
|
684
|
+
ok: false,
|
|
685
|
+
error: `Unknown message type: ${data?.type}`
|
|
686
|
+
};
|
|
687
|
+
self.postMessage(response);
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
// src/bridge.ts
|
|
694
|
+
init_src();
|
|
695
|
+
init_src();
|
|
696
|
+
|
|
697
|
+
class JxlClientBridge {
|
|
698
|
+
async encode(image, options, signal) {
|
|
699
|
+
const module = await Promise.resolve().then(() => (init_jxl_worker(), exports_jxl_worker));
|
|
700
|
+
const jxlEncodeClient2 = module.jxlEncodeClient;
|
|
701
|
+
return jxlEncodeClient2(image, options, signal);
|
|
702
|
+
}
|
|
703
|
+
async decode(data, signal) {
|
|
704
|
+
const module = await Promise.resolve().then(() => (init_jxl_worker(), exports_jxl_worker));
|
|
705
|
+
const jxlDecodeClient2 = module.jxlDecodeClient;
|
|
706
|
+
return jxlDecodeClient2(data, signal);
|
|
707
|
+
}
|
|
708
|
+
async terminate() {}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
class JxlWorkerBridge {
|
|
712
|
+
worker = null;
|
|
713
|
+
workerReady = null;
|
|
714
|
+
options;
|
|
715
|
+
constructor(options) {
|
|
716
|
+
console.log("[jxl/bridge] JxlWorkerBridge constructor called with options:", options);
|
|
717
|
+
this.options = options;
|
|
718
|
+
}
|
|
719
|
+
async getWorker() {
|
|
720
|
+
if (!this.workerReady) {
|
|
721
|
+
this.workerReady = this.createWorker();
|
|
722
|
+
}
|
|
723
|
+
return this.workerReady;
|
|
724
|
+
}
|
|
725
|
+
async createWorker() {
|
|
726
|
+
console.log("[jxl/bridge] createWorker called. Creating ready worker...");
|
|
727
|
+
this.worker = await createReadyWorker("jxl.worker.js", this.options);
|
|
728
|
+
console.log("[jxl/bridge] createWorker: Ready worker created successfully.");
|
|
729
|
+
return this.worker;
|
|
730
|
+
}
|
|
731
|
+
async encode(image, options, signal) {
|
|
732
|
+
const worker = await this.getWorker();
|
|
733
|
+
validateImageInput(image);
|
|
734
|
+
return callWorker(worker, "jxl:encode", { image, options }, signal);
|
|
735
|
+
}
|
|
736
|
+
async decode(data, signal) {
|
|
737
|
+
const worker = await this.getWorker();
|
|
738
|
+
return callWorker(worker, "jxl:decode", { data }, signal);
|
|
739
|
+
}
|
|
740
|
+
async terminate() {
|
|
741
|
+
if (this.worker) {
|
|
742
|
+
this.worker.terminate();
|
|
743
|
+
this.worker = null;
|
|
744
|
+
this.workerReady = null;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function createBridge(mode, options) {
|
|
749
|
+
console.log(`[jxl/bridge] createBridge called with mode: ${mode}`);
|
|
750
|
+
if (mode === "worker") {
|
|
751
|
+
return new JxlWorkerBridge(options);
|
|
752
|
+
}
|
|
753
|
+
return new JxlClientBridge;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// src/index.ts
|
|
757
|
+
var globalClientBridge = null;
|
|
758
|
+
async function encode(imageData, options, signal) {
|
|
759
|
+
if (!globalClientBridge) {
|
|
760
|
+
globalClientBridge = createBridge("worker");
|
|
761
|
+
}
|
|
762
|
+
return globalClientBridge.encode(imageData, options, signal);
|
|
763
|
+
}
|
|
764
|
+
async function decode(data, signal) {
|
|
765
|
+
if (!globalClientBridge) {
|
|
766
|
+
globalClientBridge = createBridge("worker");
|
|
767
|
+
}
|
|
768
|
+
return globalClientBridge.decode(data, signal);
|
|
769
|
+
}
|
|
770
|
+
function createJxlEncoder(mode = "worker", options) {
|
|
771
|
+
const bridge = createBridge(mode, options);
|
|
772
|
+
return Object.assign((imageData, encodeOptions, signal) => {
|
|
773
|
+
return bridge.encode(imageData, encodeOptions, signal);
|
|
774
|
+
}, {
|
|
775
|
+
terminate: async () => {
|
|
776
|
+
await bridge.terminate();
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
function createJxlDecoder(mode = "worker", options) {
|
|
781
|
+
const bridge = createBridge(mode, options);
|
|
782
|
+
return Object.assign((data, signal) => {
|
|
783
|
+
return bridge.decode(data, signal);
|
|
784
|
+
}, {
|
|
785
|
+
terminate: async () => {
|
|
786
|
+
await bridge.terminate();
|
|
787
|
+
}
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
export {
|
|
791
|
+
encode,
|
|
792
|
+
decode,
|
|
793
|
+
createJxlEncoder,
|
|
794
|
+
createJxlDecoder
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
//# debugId=A6CA6F67438BBF9164756E2164756E21
|