wasm-webp 0.0.1-beta.1 → 0.0.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/README.md +1 -3
- package/dist/cjs/index.js +10 -8
- package/dist/cjs/webp-wasm.js +13 -8
- package/dist/cjs/webp-wasm.wasm +0 -0
- package/dist/index.d.ts +3 -3
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -27,19 +27,21 @@ const encoderVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
27
27
|
exports.encoderVersion = encoderVersion;
|
|
28
28
|
const encodeRGB = (rgb, width, height, quality) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
29
|
const module = yield (0, webp_wasm_1.default)();
|
|
30
|
-
quality = typeof quality !== 'number' ? 100 : Math.min(Math.max(0, quality));
|
|
30
|
+
quality = typeof quality !== 'number' ? 100 : Math.min(100, Math.max(0, quality));
|
|
31
31
|
return module.encodeRGB(rgb, width, height, quality);
|
|
32
32
|
});
|
|
33
33
|
exports.encodeRGB = encodeRGB;
|
|
34
34
|
const encodeRGBA = (rgba, width, height, quality) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
const module = yield (0, webp_wasm_1.default)();
|
|
36
|
-
quality = typeof quality !== 'number' ? 100 : Math.min(Math.max(0, quality));
|
|
36
|
+
quality = typeof quality !== 'number' ? 100 : Math.min(100, Math.max(0, quality));
|
|
37
37
|
return module.encodeRGBA(rgba, width, height, quality);
|
|
38
38
|
});
|
|
39
39
|
exports.encodeRGBA = encodeRGBA;
|
|
40
40
|
const encode = (data, width, height, hasAlpha, config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
41
|
const module = yield (0, webp_wasm_1.default)();
|
|
42
42
|
const webpConfig = Object.assign(Object.assign({}, defaultWebpConfig), config);
|
|
43
|
+
webpConfig.lossless = Math.min(1, Math.max(0, webpConfig.lossless));
|
|
44
|
+
webpConfig.quality = Math.min(100, Math.max(0, webpConfig.quality));
|
|
43
45
|
return module.encode(data, width, height, hasAlpha, webpConfig);
|
|
44
46
|
});
|
|
45
47
|
exports.encode = encode;
|
|
@@ -50,7 +52,7 @@ const encodeAnimation = (width, height, hasAlpha, frames) => __awaiter(void 0, v
|
|
|
50
52
|
acc += frame.data.length;
|
|
51
53
|
return acc;
|
|
52
54
|
}, 0);
|
|
53
|
-
const data = new
|
|
55
|
+
const data = new Uint8Array(dataLength);
|
|
54
56
|
let offset = 0;
|
|
55
57
|
frames.forEach(frame => {
|
|
56
58
|
data.set(frame.data, offset);
|
|
@@ -65,18 +67,18 @@ const decoderVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
65
67
|
return module.decoder_version();
|
|
66
68
|
});
|
|
67
69
|
exports.decoderVersion = decoderVersion;
|
|
68
|
-
const decodeRGB = (
|
|
70
|
+
const decodeRGB = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
71
|
const module = yield (0, webp_wasm_1.default)();
|
|
70
|
-
return module.decodeRGB(
|
|
72
|
+
return module.decodeRGB(data);
|
|
71
73
|
});
|
|
72
74
|
exports.decodeRGB = decodeRGB;
|
|
73
|
-
const decodeRGBA = (
|
|
75
|
+
const decodeRGBA = (data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
76
|
const module = yield (0, webp_wasm_1.default)();
|
|
75
|
-
return module.decodeRGBA(
|
|
77
|
+
return module.decodeRGBA(data);
|
|
76
78
|
});
|
|
77
79
|
exports.decodeRGBA = decodeRGBA;
|
|
78
80
|
// TODO:
|
|
79
|
-
// export const decode = async (data:
|
|
81
|
+
// export const decode = async (data: Uint8Array, hasAlpha: boolean) => {
|
|
80
82
|
// const module = await Module()
|
|
81
83
|
// return module.decode(data, hasAlpha)
|
|
82
84
|
// }
|
package/dist/cjs/webp-wasm.js
CHANGED
|
@@ -2561,15 +2561,11 @@ function dbg(...args) {
|
|
|
2561
2561
|
return Emval.toHandle(handle[key]);
|
|
2562
2562
|
};
|
|
2563
2563
|
|
|
2564
|
-
var __emval_incref = (handle) => {
|
|
2565
|
-
if (handle > 9) {
|
|
2566
|
-
emval_handles[handle + 1] += 1;
|
|
2567
|
-
}
|
|
2568
|
-
};
|
|
2569
|
-
|
|
2570
2564
|
|
|
2571
2565
|
var __emval_new_cstring = (v) => Emval.toHandle(getStringOrSymbol(v));
|
|
2572
2566
|
|
|
2567
|
+
var __emval_new_object = () => Emval.toHandle({});
|
|
2568
|
+
|
|
2573
2569
|
|
|
2574
2570
|
var __emval_new_u8string = (v) => Emval.toHandle(UTF8ToString(v));
|
|
2575
2571
|
|
|
@@ -2581,6 +2577,13 @@ function dbg(...args) {
|
|
|
2581
2577
|
__emval_decref(handle);
|
|
2582
2578
|
};
|
|
2583
2579
|
|
|
2580
|
+
var __emval_set_property = (handle, key, value) => {
|
|
2581
|
+
handle = Emval.toValue(handle);
|
|
2582
|
+
key = Emval.toValue(key);
|
|
2583
|
+
value = Emval.toValue(value);
|
|
2584
|
+
handle[key] = value;
|
|
2585
|
+
};
|
|
2586
|
+
|
|
2584
2587
|
|
|
2585
2588
|
var __emval_take_value = (type, arg) => {
|
|
2586
2589
|
type = requireRegisteredType(type, '_emval_take_value');
|
|
@@ -2788,14 +2791,16 @@ var wasmImports = {
|
|
|
2788
2791
|
/** @export */
|
|
2789
2792
|
_emval_get_property: __emval_get_property,
|
|
2790
2793
|
/** @export */
|
|
2791
|
-
_emval_incref: __emval_incref,
|
|
2792
|
-
/** @export */
|
|
2793
2794
|
_emval_new_cstring: __emval_new_cstring,
|
|
2794
2795
|
/** @export */
|
|
2796
|
+
_emval_new_object: __emval_new_object,
|
|
2797
|
+
/** @export */
|
|
2795
2798
|
_emval_new_u8string: __emval_new_u8string,
|
|
2796
2799
|
/** @export */
|
|
2797
2800
|
_emval_run_destructors: __emval_run_destructors,
|
|
2798
2801
|
/** @export */
|
|
2802
|
+
_emval_set_property: __emval_set_property,
|
|
2803
|
+
/** @export */
|
|
2799
2804
|
_emval_take_value: __emval_take_value,
|
|
2800
2805
|
/** @export */
|
|
2801
2806
|
abort: _abort,
|
package/dist/cjs/webp-wasm.wasm
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { WebPConfig, Nullable, WebPAnimationFrame,
|
|
1
|
+
import type { WebPConfig, Nullable, WebPAnimationFrame, WebPDecodedImageData } from './types'
|
|
2
2
|
export declare const encoderVersion: () => Promise<string>
|
|
3
3
|
export declare const encodeRGB: (
|
|
4
4
|
rgb: Uint8Array,
|
|
@@ -26,5 +26,5 @@ export declare const encodeAnimation: (
|
|
|
26
26
|
frames: WebPAnimationFrame[]
|
|
27
27
|
) => Promise<Nullable<Uint8Array>>
|
|
28
28
|
export declare const decoderVersion: () => Promise<string>
|
|
29
|
-
export declare const decodeRGB: (data: Uint8Array) => Promise<Nullable<
|
|
30
|
-
export declare const decodeRGBA: (data: Uint8Array) => Promise<Nullable<
|
|
29
|
+
export declare const decodeRGB: (data: Uint8Array) => Promise<Nullable<WebPDecodedImageData>>
|
|
30
|
+
export declare const decodeRGBA: (data: Uint8Array) => Promise<Nullable<WebPDecodedImageData>>
|
package/dist/types.d.ts
CHANGED