@squoosh-kit/oxipng 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 +15 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/index.browser.mjs +520 -0
- package/dist/index.browser.mjs.map +18 -0
- package/dist/index.bun.js +521 -0
- package/dist/index.bun.js.map +18 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.node.cjs +548 -0
- package/dist/index.node.cjs.map +18 -0
- package/dist/index.node.mjs +520 -0
- package/dist/index.node.mjs.map +18 -0
- package/dist/oxipng.worker.browser.mjs +452 -0
- package/dist/oxipng.worker.browser.mjs.map +16 -0
- package/dist/oxipng.worker.bun.js +453 -0
- package/dist/oxipng.worker.bun.js.map +16 -0
- package/dist/oxipng.worker.d.ts +7 -0
- package/dist/oxipng.worker.d.ts.map +1 -0
- package/dist/oxipng.worker.node.cjs +472 -0
- package/dist/oxipng.worker.node.cjs.map +16 -0
- package/dist/oxipng.worker.node.mjs +452 -0
- package/dist/oxipng.worker.node.mjs.map +16 -0
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validators.d.ts +7 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/wasm/oxipng/README.md +5 -0
- package/dist/wasm/oxipng/package.json +17 -0
- package/dist/wasm/oxipng/squoosh_oxipng.d.ts +31 -0
- package/dist/wasm/oxipng/squoosh_oxipng.js +120 -0
- package/dist/wasm/oxipng/squoosh_oxipng_bg.wasm +0 -0
- package/dist/wasm/oxipng/squoosh_oxipng_bg.wasm.d.ts +7 -0
- package/dist/wasm/oxipng-parallel/README.md +5 -0
- package/dist/wasm/oxipng-parallel/package.json +17 -0
- package/dist/wasm/oxipng-parallel/snippets/wasm-bindgen-rayon-3d2df09ebec17a22/src/workerHelpers.js +98 -0
- package/dist/wasm/oxipng-parallel/squoosh_oxipng.d.ts +64 -0
- package/dist/wasm/oxipng-parallel/squoosh_oxipng.js +220 -0
- package/dist/wasm/oxipng-parallel/squoosh_oxipng_bg.wasm +0 -0
- package/dist/wasm/oxipng-parallel/squoosh_oxipng_bg.wasm.d.ts +14 -0
- package/package.json +52 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
let wasm;
|
|
3
|
+
|
|
4
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
5
|
+
|
|
6
|
+
cachedTextDecoder.decode();
|
|
7
|
+
|
|
8
|
+
let cachegetUint8Memory0 = null;
|
|
9
|
+
function getUint8Memory0() {
|
|
10
|
+
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
|
|
11
|
+
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
12
|
+
}
|
|
13
|
+
return cachegetUint8Memory0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getStringFromWasm0(ptr, len) {
|
|
17
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let WASM_VECTOR_LEN = 0;
|
|
21
|
+
|
|
22
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
23
|
+
const ptr = malloc(arg.length * 1);
|
|
24
|
+
getUint8Memory0().set(arg, ptr / 1);
|
|
25
|
+
WASM_VECTOR_LEN = arg.length;
|
|
26
|
+
return ptr;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let cachegetInt32Memory0 = null;
|
|
30
|
+
function getInt32Memory0() {
|
|
31
|
+
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
32
|
+
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
33
|
+
}
|
|
34
|
+
return cachegetInt32Memory0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
38
|
+
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @param {Uint8ClampedArray} data
|
|
42
|
+
* @param {number} width
|
|
43
|
+
* @param {number} height
|
|
44
|
+
* @param {number} level
|
|
45
|
+
* @param {boolean} interlace
|
|
46
|
+
* @returns {Uint8Array}
|
|
47
|
+
*/
|
|
48
|
+
export function optimise(data, width, height, level, interlace) {
|
|
49
|
+
try {
|
|
50
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
51
|
+
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
52
|
+
var len0 = WASM_VECTOR_LEN;
|
|
53
|
+
wasm.optimise(retptr, ptr0, len0, width, height, level, interlace);
|
|
54
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
55
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
56
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
57
|
+
wasm.__wbindgen_free(r0, r1 * 1);
|
|
58
|
+
return v1;
|
|
59
|
+
} finally {
|
|
60
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function load(module, imports) {
|
|
65
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
66
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
67
|
+
try {
|
|
68
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
69
|
+
|
|
70
|
+
} catch (e) {
|
|
71
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
72
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
73
|
+
|
|
74
|
+
} else {
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const bytes = await module.arrayBuffer();
|
|
81
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
82
|
+
|
|
83
|
+
} else {
|
|
84
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
85
|
+
|
|
86
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
87
|
+
return { instance, module };
|
|
88
|
+
|
|
89
|
+
} else {
|
|
90
|
+
return instance;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function init(input) {
|
|
96
|
+
if (typeof input === 'undefined') {
|
|
97
|
+
input = new URL('squoosh_oxipng_bg.wasm', import.meta.url);
|
|
98
|
+
}
|
|
99
|
+
const imports = {};
|
|
100
|
+
imports.wbg = {};
|
|
101
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
102
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
|
106
|
+
input = fetch(input);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
const { instance, module } = await load(await input, imports);
|
|
112
|
+
|
|
113
|
+
wasm = instance.exports;
|
|
114
|
+
init.__wbindgen_wasm_module = module;
|
|
115
|
+
|
|
116
|
+
return wasm;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default init;
|
|
120
|
+
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export function optimise(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
|
|
5
|
+
export function __wbindgen_add_to_stack_pointer(a: number): number;
|
|
6
|
+
export function __wbindgen_malloc(a: number): number;
|
|
7
|
+
export function __wbindgen_free(a: number, b: number): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "squoosh-oxipng",
|
|
3
|
+
"collaborators": [
|
|
4
|
+
"Ingvar Stepanyan <me@rreverser.com>"
|
|
5
|
+
],
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"files": [
|
|
8
|
+
"squoosh_oxipng_bg.wasm",
|
|
9
|
+
"squoosh_oxipng.js",
|
|
10
|
+
"squoosh_oxipng.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"module": "squoosh_oxipng.js",
|
|
13
|
+
"types": "squoosh_oxipng.d.ts",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"./snippets/*"
|
|
16
|
+
]
|
|
17
|
+
}
|
package/dist/wasm/oxipng-parallel/snippets/wasm-bindgen-rayon-3d2df09ebec17a22/src/workerHelpers.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2021 Google Inc. All Rights Reserved.
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
* See the License for the specific language governing permissions and
|
|
11
|
+
* limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// Note: we use `wasm_bindgen_worker_`-prefixed message types to make sure
|
|
15
|
+
// we can handle bundling into other files, which might happen to have their
|
|
16
|
+
// own `postMessage`/`onmessage` communication channels.
|
|
17
|
+
//
|
|
18
|
+
// If we didn't take that into the account, we could send much simpler signals
|
|
19
|
+
// like just `0` or whatever, but the code would be less resilient.
|
|
20
|
+
|
|
21
|
+
function waitForMsgType(target, type) {
|
|
22
|
+
return new Promise(resolve => {
|
|
23
|
+
target.addEventListener('message', function onMsg({ data }) {
|
|
24
|
+
if (data == null || data.type !== type) return;
|
|
25
|
+
target.removeEventListener('message', onMsg);
|
|
26
|
+
resolve(data);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
waitForMsgType(self, 'wasm_bindgen_worker_init').then(async data => {
|
|
32
|
+
// # Note 1
|
|
33
|
+
// Our JS should have been generated in
|
|
34
|
+
// `[out-dir]/snippets/wasm-bindgen-rayon-[hash]/workerHelpers.js`,
|
|
35
|
+
// resolve the main module via `../../..`.
|
|
36
|
+
//
|
|
37
|
+
// This might need updating if the generated structure changes on wasm-bindgen
|
|
38
|
+
// side ever in the future, but works well with bundlers today. The whole
|
|
39
|
+
// point of this crate, after all, is to abstract away unstable features
|
|
40
|
+
// and temporary bugs so that you don't need to deal with them in your code.
|
|
41
|
+
//
|
|
42
|
+
// # Note 2
|
|
43
|
+
// This could be a regular import, but then some bundlers complain about
|
|
44
|
+
// circular deps.
|
|
45
|
+
//
|
|
46
|
+
// Dynamic import could be cheap if this file was inlined into the parent,
|
|
47
|
+
// which would require us just using `../../..` in `new Worker` below,
|
|
48
|
+
// but that doesn't work because wasm-pack unconditionally adds
|
|
49
|
+
// "sideEffects":false (see below).
|
|
50
|
+
//
|
|
51
|
+
// OTOH, even though it can't be inlined, it should be still reasonably
|
|
52
|
+
// cheap since the requested file is already in cache (it was loaded by
|
|
53
|
+
// the main thread).
|
|
54
|
+
const pkg = await import('../../..');
|
|
55
|
+
await pkg.default(data.module, data.memory);
|
|
56
|
+
postMessage({ type: 'wasm_bindgen_worker_ready' });
|
|
57
|
+
pkg.wbg_rayon_start_worker(data.receiver);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export async function startWorkers(module, memory, builder) {
|
|
61
|
+
const workerInit = {
|
|
62
|
+
type: 'wasm_bindgen_worker_init',
|
|
63
|
+
module,
|
|
64
|
+
memory,
|
|
65
|
+
receiver: builder.receiver()
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await Promise.all(
|
|
70
|
+
Array.from({ length: builder.numThreads() }, () => {
|
|
71
|
+
// Self-spawn into a new Worker.
|
|
72
|
+
//
|
|
73
|
+
// TODO: while `new URL('...', import.meta.url) becomes a semi-standard
|
|
74
|
+
// way to get asset URLs relative to the module across various bundlers
|
|
75
|
+
// and browser, ideally we should switch to `import.meta.resolve`
|
|
76
|
+
// once it becomes a standard.
|
|
77
|
+
//
|
|
78
|
+
// Note: we could use `../../..` as the URL here to inline workerHelpers.js
|
|
79
|
+
// into the parent entry instead of creating another split point -
|
|
80
|
+
// this would be preferable from optimization perspective -
|
|
81
|
+
// however, Webpack then eliminates all message handler code
|
|
82
|
+
// because wasm-pack produces "sideEffects":false in package.json
|
|
83
|
+
// unconditionally.
|
|
84
|
+
//
|
|
85
|
+
// The only way to work around that is to have side effect code
|
|
86
|
+
// in an entry point such as Worker file itself.
|
|
87
|
+
const worker = new Worker(new URL('./workerHelpers.js', import.meta.url), {
|
|
88
|
+
type: 'module'
|
|
89
|
+
});
|
|
90
|
+
worker.postMessage(workerInit);
|
|
91
|
+
return waitForMsgType(worker, 'wasm_bindgen_worker_ready');
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
builder.build();
|
|
95
|
+
} finally {
|
|
96
|
+
builder.free();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* @param {Uint8ClampedArray} data
|
|
5
|
+
* @param {number} width
|
|
6
|
+
* @param {number} height
|
|
7
|
+
* @param {number} level
|
|
8
|
+
* @param {boolean} interlace
|
|
9
|
+
* @returns {Uint8Array}
|
|
10
|
+
*/
|
|
11
|
+
export function optimise(data: Uint8ClampedArray, width: number, height: number, level: number, interlace: boolean): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* @param {number} num_threads
|
|
14
|
+
* @returns {Promise<any>}
|
|
15
|
+
*/
|
|
16
|
+
export function initThreadPool(num_threads: number): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* @param {number} receiver
|
|
19
|
+
*/
|
|
20
|
+
export function wbg_rayon_start_worker(receiver: number): void;
|
|
21
|
+
/**
|
|
22
|
+
*/
|
|
23
|
+
export class wbg_rayon_PoolBuilder {
|
|
24
|
+
free(): void;
|
|
25
|
+
/**
|
|
26
|
+
* @returns {number}
|
|
27
|
+
*/
|
|
28
|
+
numThreads(): number;
|
|
29
|
+
/**
|
|
30
|
+
* @returns {number}
|
|
31
|
+
*/
|
|
32
|
+
receiver(): number;
|
|
33
|
+
/**
|
|
34
|
+
*/
|
|
35
|
+
build(): void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
39
|
+
|
|
40
|
+
export interface InitOutput {
|
|
41
|
+
readonly optimise: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
42
|
+
readonly __wbg_wbg_rayon_poolbuilder_free: (a: number) => void;
|
|
43
|
+
readonly wbg_rayon_poolbuilder_numThreads: (a: number) => number;
|
|
44
|
+
readonly wbg_rayon_poolbuilder_receiver: (a: number) => number;
|
|
45
|
+
readonly wbg_rayon_poolbuilder_build: (a: number) => void;
|
|
46
|
+
readonly initThreadPool: (a: number) => number;
|
|
47
|
+
readonly wbg_rayon_start_worker: (a: number) => void;
|
|
48
|
+
readonly __wbindgen_export_0: WebAssembly.Memory;
|
|
49
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
50
|
+
readonly __wbindgen_malloc: (a: number) => number;
|
|
51
|
+
readonly __wbindgen_free: (a: number, b: number) => void;
|
|
52
|
+
readonly __wbindgen_start: () => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
57
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
58
|
+
*
|
|
59
|
+
* @param {InitInput | Promise<InitInput>} module_or_path
|
|
60
|
+
* @param {WebAssembly.Memory} maybe_memory
|
|
61
|
+
*
|
|
62
|
+
* @returns {Promise<InitOutput>}
|
|
63
|
+
*/
|
|
64
|
+
export default function init (module_or_path?: InitInput | Promise<InitInput>, maybe_memory?: WebAssembly.Memory): Promise<InitOutput>;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { startWorkers } from './snippets/wasm-bindgen-rayon-3d2df09ebec17a22/src/workerHelpers.js';
|
|
2
|
+
|
|
3
|
+
let wasm;
|
|
4
|
+
|
|
5
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
6
|
+
|
|
7
|
+
cachedTextDecoder.decode();
|
|
8
|
+
|
|
9
|
+
let cachegetUint8Memory0 = null;
|
|
10
|
+
function getUint8Memory0() {
|
|
11
|
+
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.__wbindgen_export_0.buffer) {
|
|
12
|
+
cachegetUint8Memory0 = new Uint8Array(wasm.__wbindgen_export_0.buffer);
|
|
13
|
+
}
|
|
14
|
+
return cachegetUint8Memory0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getStringFromWasm0(ptr, len) {
|
|
18
|
+
return cachedTextDecoder.decode(getUint8Memory0().slice(ptr, ptr + len));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const heap = new Array(32).fill(undefined);
|
|
22
|
+
|
|
23
|
+
heap.push(undefined, null, true, false);
|
|
24
|
+
|
|
25
|
+
let heap_next = heap.length;
|
|
26
|
+
|
|
27
|
+
function addHeapObject(obj) {
|
|
28
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
29
|
+
const idx = heap_next;
|
|
30
|
+
heap_next = heap[idx];
|
|
31
|
+
|
|
32
|
+
heap[idx] = obj;
|
|
33
|
+
return idx;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let WASM_VECTOR_LEN = 0;
|
|
37
|
+
|
|
38
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
39
|
+
const ptr = malloc(arg.length * 1);
|
|
40
|
+
getUint8Memory0().set(arg, ptr / 1);
|
|
41
|
+
WASM_VECTOR_LEN = arg.length;
|
|
42
|
+
return ptr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let cachegetInt32Memory0 = null;
|
|
46
|
+
function getInt32Memory0() {
|
|
47
|
+
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.__wbindgen_export_0.buffer) {
|
|
48
|
+
cachegetInt32Memory0 = new Int32Array(wasm.__wbindgen_export_0.buffer);
|
|
49
|
+
}
|
|
50
|
+
return cachegetInt32Memory0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
54
|
+
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @param {Uint8ClampedArray} data
|
|
58
|
+
* @param {number} width
|
|
59
|
+
* @param {number} height
|
|
60
|
+
* @param {number} level
|
|
61
|
+
* @param {boolean} interlace
|
|
62
|
+
* @returns {Uint8Array}
|
|
63
|
+
*/
|
|
64
|
+
export function optimise(data, width, height, level, interlace) {
|
|
65
|
+
try {
|
|
66
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
67
|
+
var ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
68
|
+
var len0 = WASM_VECTOR_LEN;
|
|
69
|
+
wasm.optimise(retptr, ptr0, len0, width, height, level, interlace);
|
|
70
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
71
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
72
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
73
|
+
wasm.__wbindgen_free(r0, r1 * 1);
|
|
74
|
+
return v1;
|
|
75
|
+
} finally {
|
|
76
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getObject(idx) { return heap[idx]; }
|
|
81
|
+
|
|
82
|
+
function dropObject(idx) {
|
|
83
|
+
if (idx < 36) return;
|
|
84
|
+
heap[idx] = heap_next;
|
|
85
|
+
heap_next = idx;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function takeObject(idx) {
|
|
89
|
+
const ret = getObject(idx);
|
|
90
|
+
dropObject(idx);
|
|
91
|
+
return ret;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @param {number} num_threads
|
|
95
|
+
* @returns {Promise<any>}
|
|
96
|
+
*/
|
|
97
|
+
export function initThreadPool(num_threads) {
|
|
98
|
+
var ret = wasm.initThreadPool(num_threads);
|
|
99
|
+
return takeObject(ret);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {number} receiver
|
|
104
|
+
*/
|
|
105
|
+
export function wbg_rayon_start_worker(receiver) {
|
|
106
|
+
wasm.wbg_rayon_start_worker(receiver);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
*/
|
|
111
|
+
export class wbg_rayon_PoolBuilder {
|
|
112
|
+
|
|
113
|
+
static __wrap(ptr) {
|
|
114
|
+
const obj = Object.create(wbg_rayon_PoolBuilder.prototype);
|
|
115
|
+
obj.ptr = ptr;
|
|
116
|
+
|
|
117
|
+
return obj;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
__destroy_into_raw() {
|
|
121
|
+
const ptr = this.ptr;
|
|
122
|
+
this.ptr = 0;
|
|
123
|
+
|
|
124
|
+
return ptr;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
free() {
|
|
128
|
+
const ptr = this.__destroy_into_raw();
|
|
129
|
+
wasm.__wbg_wbg_rayon_poolbuilder_free(ptr);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @returns {number}
|
|
133
|
+
*/
|
|
134
|
+
numThreads() {
|
|
135
|
+
var ret = wasm.wbg_rayon_poolbuilder_numThreads(this.ptr);
|
|
136
|
+
return ret >>> 0;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @returns {number}
|
|
140
|
+
*/
|
|
141
|
+
receiver() {
|
|
142
|
+
var ret = wasm.wbg_rayon_poolbuilder_receiver(this.ptr);
|
|
143
|
+
return ret;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
*/
|
|
147
|
+
build() {
|
|
148
|
+
wasm.wbg_rayon_poolbuilder_build(this.ptr);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function load(module, imports) {
|
|
153
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
154
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
155
|
+
try {
|
|
156
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
157
|
+
|
|
158
|
+
} catch (e) {
|
|
159
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
160
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
161
|
+
|
|
162
|
+
} else {
|
|
163
|
+
throw e;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const bytes = await module.arrayBuffer();
|
|
169
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
170
|
+
|
|
171
|
+
} else {
|
|
172
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
173
|
+
|
|
174
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
175
|
+
return { instance, module };
|
|
176
|
+
|
|
177
|
+
} else {
|
|
178
|
+
return instance;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function init(input, maybe_memory) {
|
|
184
|
+
if (typeof input === 'undefined') {
|
|
185
|
+
input = new URL('squoosh_oxipng_bg.wasm', import.meta.url);
|
|
186
|
+
}
|
|
187
|
+
const imports = {};
|
|
188
|
+
imports.wbg = {};
|
|
189
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
190
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
191
|
+
};
|
|
192
|
+
imports.wbg.__wbindgen_module = function() {
|
|
193
|
+
var ret = init.__wbindgen_wasm_module;
|
|
194
|
+
return addHeapObject(ret);
|
|
195
|
+
};
|
|
196
|
+
imports.wbg.__wbindgen_memory = function() {
|
|
197
|
+
var ret = wasm.__wbindgen_export_0;
|
|
198
|
+
return addHeapObject(ret);
|
|
199
|
+
};
|
|
200
|
+
imports.wbg.__wbg_startWorkers_914655bb4d5bb5e1 = function(arg0, arg1, arg2) {
|
|
201
|
+
var ret = startWorkers(takeObject(arg0), takeObject(arg1), wbg_rayon_PoolBuilder.__wrap(arg2));
|
|
202
|
+
return addHeapObject(ret);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
|
206
|
+
input = fetch(input);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
imports.wbg.memory = maybe_memory || new WebAssembly.Memory({initial:17,maximum:16384,shared:true});
|
|
210
|
+
|
|
211
|
+
const { instance, module } = await load(await input, imports);
|
|
212
|
+
|
|
213
|
+
wasm = instance.exports;
|
|
214
|
+
init.__wbindgen_wasm_module = module;
|
|
215
|
+
wasm.__wbindgen_start();
|
|
216
|
+
return wasm;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export default init;
|
|
220
|
+
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export function optimise(a: number, b: number, c: number, d: number, e: number, f: number, g: number): void;
|
|
4
|
+
export function __wbg_wbg_rayon_poolbuilder_free(a: number): void;
|
|
5
|
+
export function wbg_rayon_poolbuilder_numThreads(a: number): number;
|
|
6
|
+
export function wbg_rayon_poolbuilder_receiver(a: number): number;
|
|
7
|
+
export function wbg_rayon_poolbuilder_build(a: number): void;
|
|
8
|
+
export function initThreadPool(a: number): number;
|
|
9
|
+
export function wbg_rayon_start_worker(a: number): void;
|
|
10
|
+
export const __wbindgen_export_0: WebAssembly.Memory;
|
|
11
|
+
export function __wbindgen_add_to_stack_pointer(a: number): number;
|
|
12
|
+
export function __wbindgen_malloc(a: number): number;
|
|
13
|
+
export function __wbindgen_free(a: number, b: number): void;
|
|
14
|
+
export function __wbindgen_start(): void;
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@squoosh-kit/oxipng",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "OxiPNG codec for squoosh-kit, providing PNG optimization functionality.",
|
|
6
|
+
"author": "Bartosz Nowak <bnowak008@gmail.com>",
|
|
7
|
+
"license": "MIT AND Apache-2.0",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/bnowak008/squoosh-kit.git",
|
|
11
|
+
"directory": "packages/oxipng"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/bnowak008/squoosh-kit/tree/main/packages/oxipng#readme",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"browser": "./dist/index.browser.mjs",
|
|
24
|
+
"bun": "./dist/index.bun.js",
|
|
25
|
+
"import": "./dist/index.node.mjs",
|
|
26
|
+
"require": "./dist/index.node.cjs"
|
|
27
|
+
},
|
|
28
|
+
"./oxipng.worker.js": {
|
|
29
|
+
"types": "./dist/oxipng.worker.d.ts",
|
|
30
|
+
"browser": "./dist/oxipng.worker.browser.mjs",
|
|
31
|
+
"bun": "./dist/oxipng.worker.bun.js",
|
|
32
|
+
"import": "./dist/oxipng.worker.node.mjs",
|
|
33
|
+
"require": "./dist/oxipng.worker.node.cjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist/**",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"NOTICE"
|
|
41
|
+
],
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "bun run build.ts",
|
|
45
|
+
"clean:local": "rm -rf dist node_modules .bun/install/cache bun.lockb bun.lock *.tsbuildinfo",
|
|
46
|
+
"prepack": "bun run build && bun test",
|
|
47
|
+
"test": "bun test"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@squoosh-kit/runtime": "workspace:*"
|
|
51
|
+
}
|
|
52
|
+
}
|