beautiful-image 0.2.1 → 0.2.2
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/package.json
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beautiful-image",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Eduar Castaño <hello@eduar.tech> (https://eduar.tech)",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
|
-
"wasm
|
|
11
|
-
"wasm/*.js",
|
|
12
|
-
"wasm/*.d.ts",
|
|
10
|
+
"wasm",
|
|
13
11
|
"LICENSE"
|
|
14
12
|
],
|
|
15
13
|
"main": "./dist/beautiful-image.umd.cjs",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export enum ResizeMode {
|
|
5
|
+
Standard = 0,
|
|
6
|
+
HighQuality = 1,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function processImage(rgba_data: Uint8Array, width: number, height: number, quality: number, sharpen_sigma: number | null | undefined, sharpen_threshold: number | null | undefined, blur_sigma: number | null | undefined, brightness: number | null | undefined, contrast: number | null | undefined, grayscale: boolean, invert: boolean, hue_rotate?: number | null): Uint8Array;
|
|
10
|
+
|
|
11
|
+
export function processImageFromBytes(image_data: Uint8Array, target_width: number | null | undefined, quality: number, sharpen_sigma: number | null | undefined, sharpen_threshold: number | null | undefined, blur_sigma: number | null | undefined, brightness: number | null | undefined, contrast: number | null | undefined, grayscale: boolean, invert: boolean, hue_rotate?: number | null): Uint8Array;
|
|
12
|
+
|
|
13
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
14
|
+
|
|
15
|
+
export interface InitOutput {
|
|
16
|
+
readonly memory: WebAssembly.Memory;
|
|
17
|
+
readonly processImage: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => [number, number, number, number];
|
|
18
|
+
readonly processImageFromBytes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number, number, number];
|
|
19
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
20
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
21
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
22
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
23
|
+
readonly __wbindgen_start: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
30
|
+
* a precompiled `WebAssembly.Module`.
|
|
31
|
+
*
|
|
32
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
33
|
+
*
|
|
34
|
+
* @returns {InitOutput}
|
|
35
|
+
*/
|
|
36
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
40
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
41
|
+
*
|
|
42
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
43
|
+
*
|
|
44
|
+
* @returns {Promise<InitOutput>}
|
|
45
|
+
*/
|
|
46
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
4
|
+
ptr = ptr >>> 0;
|
|
5
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function getStringFromWasm0(ptr, len) {
|
|
9
|
+
ptr = ptr >>> 0;
|
|
10
|
+
return decodeText(ptr, len);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let cachedUint8ArrayMemory0 = null;
|
|
14
|
+
function getUint8ArrayMemory0() {
|
|
15
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
16
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
17
|
+
}
|
|
18
|
+
return cachedUint8ArrayMemory0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isLikeNone(x) {
|
|
22
|
+
return x === undefined || x === null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
26
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
27
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
28
|
+
WASM_VECTOR_LEN = arg.length;
|
|
29
|
+
return ptr;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function takeFromExternrefTable0(idx) {
|
|
33
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
34
|
+
wasm.__externref_table_dealloc(idx);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
39
|
+
cachedTextDecoder.decode();
|
|
40
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
41
|
+
let numBytesDecoded = 0;
|
|
42
|
+
function decodeText(ptr, len) {
|
|
43
|
+
numBytesDecoded += len;
|
|
44
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
45
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
46
|
+
cachedTextDecoder.decode();
|
|
47
|
+
numBytesDecoded = len;
|
|
48
|
+
}
|
|
49
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let WASM_VECTOR_LEN = 0;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @enum {0 | 1}
|
|
56
|
+
*/
|
|
57
|
+
export const ResizeMode = Object.freeze({
|
|
58
|
+
Standard: 0, "0": "Standard",
|
|
59
|
+
HighQuality: 1, "1": "HighQuality",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @param {Uint8Array} rgba_data
|
|
64
|
+
* @param {number} width
|
|
65
|
+
* @param {number} height
|
|
66
|
+
* @param {number} quality
|
|
67
|
+
* @param {number | null | undefined} sharpen_sigma
|
|
68
|
+
* @param {number | null | undefined} sharpen_threshold
|
|
69
|
+
* @param {number | null | undefined} blur_sigma
|
|
70
|
+
* @param {number | null | undefined} brightness
|
|
71
|
+
* @param {number | null | undefined} contrast
|
|
72
|
+
* @param {boolean} grayscale
|
|
73
|
+
* @param {boolean} invert
|
|
74
|
+
* @param {number | null} [hue_rotate]
|
|
75
|
+
* @returns {Uint8Array}
|
|
76
|
+
*/
|
|
77
|
+
export function processImage(rgba_data, width, height, quality, sharpen_sigma, sharpen_threshold, blur_sigma, brightness, contrast, grayscale, invert, hue_rotate) {
|
|
78
|
+
const ptr0 = passArray8ToWasm0(rgba_data, wasm.__wbindgen_malloc);
|
|
79
|
+
const len0 = WASM_VECTOR_LEN;
|
|
80
|
+
const ret = wasm.processImage(ptr0, len0, width, height, quality, isLikeNone(sharpen_sigma) ? 0x100000001 : Math.fround(sharpen_sigma), isLikeNone(sharpen_threshold) ? 0x100000001 : (sharpen_threshold) >> 0, isLikeNone(blur_sigma) ? 0x100000001 : Math.fround(blur_sigma), isLikeNone(brightness) ? 0x100000001 : (brightness) >> 0, isLikeNone(contrast) ? 0x100000001 : Math.fround(contrast), grayscale, invert, isLikeNone(hue_rotate) ? 0x100000001 : (hue_rotate) >> 0);
|
|
81
|
+
if (ret[3]) {
|
|
82
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
83
|
+
}
|
|
84
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
85
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
86
|
+
return v2;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {Uint8Array} image_data
|
|
91
|
+
* @param {number | null | undefined} target_width
|
|
92
|
+
* @param {number} quality
|
|
93
|
+
* @param {number | null | undefined} sharpen_sigma
|
|
94
|
+
* @param {number | null | undefined} sharpen_threshold
|
|
95
|
+
* @param {number | null | undefined} blur_sigma
|
|
96
|
+
* @param {number | null | undefined} brightness
|
|
97
|
+
* @param {number | null | undefined} contrast
|
|
98
|
+
* @param {boolean} grayscale
|
|
99
|
+
* @param {boolean} invert
|
|
100
|
+
* @param {number | null} [hue_rotate]
|
|
101
|
+
* @returns {Uint8Array}
|
|
102
|
+
*/
|
|
103
|
+
export function processImageFromBytes(image_data, target_width, quality, sharpen_sigma, sharpen_threshold, blur_sigma, brightness, contrast, grayscale, invert, hue_rotate) {
|
|
104
|
+
const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
|
|
105
|
+
const len0 = WASM_VECTOR_LEN;
|
|
106
|
+
const ret = wasm.processImageFromBytes(ptr0, len0, isLikeNone(target_width) ? 0x100000001 : (target_width) >>> 0, quality, isLikeNone(sharpen_sigma) ? 0x100000001 : Math.fround(sharpen_sigma), isLikeNone(sharpen_threshold) ? 0x100000001 : (sharpen_threshold) >> 0, isLikeNone(blur_sigma) ? 0x100000001 : Math.fround(blur_sigma), isLikeNone(brightness) ? 0x100000001 : (brightness) >> 0, isLikeNone(contrast) ? 0x100000001 : Math.fround(contrast), grayscale, invert, isLikeNone(hue_rotate) ? 0x100000001 : (hue_rotate) >> 0);
|
|
107
|
+
if (ret[3]) {
|
|
108
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
109
|
+
}
|
|
110
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
111
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
112
|
+
return v2;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
116
|
+
|
|
117
|
+
async function __wbg_load(module, imports) {
|
|
118
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
119
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
120
|
+
try {
|
|
121
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
124
|
+
|
|
125
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
126
|
+
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);
|
|
127
|
+
|
|
128
|
+
} else {
|
|
129
|
+
throw e;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const bytes = await module.arrayBuffer();
|
|
135
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
136
|
+
} else {
|
|
137
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
138
|
+
|
|
139
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
140
|
+
return { instance, module };
|
|
141
|
+
} else {
|
|
142
|
+
return instance;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function __wbg_get_imports() {
|
|
148
|
+
const imports = {};
|
|
149
|
+
imports.wbg = {};
|
|
150
|
+
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
151
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
152
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
153
|
+
return ret;
|
|
154
|
+
};
|
|
155
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
156
|
+
const table = wasm.__wbindgen_externrefs;
|
|
157
|
+
const offset = table.grow(4);
|
|
158
|
+
table.set(0, undefined);
|
|
159
|
+
table.set(offset + 0, undefined);
|
|
160
|
+
table.set(offset + 1, null);
|
|
161
|
+
table.set(offset + 2, true);
|
|
162
|
+
table.set(offset + 3, false);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return imports;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function __wbg_finalize_init(instance, module) {
|
|
169
|
+
wasm = instance.exports;
|
|
170
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
171
|
+
cachedUint8ArrayMemory0 = null;
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
wasm.__wbindgen_start();
|
|
175
|
+
return wasm;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function initSync(module) {
|
|
179
|
+
if (wasm !== undefined) return wasm;
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
if (typeof module !== 'undefined') {
|
|
183
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
184
|
+
({module} = module)
|
|
185
|
+
} else {
|
|
186
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const imports = __wbg_get_imports();
|
|
191
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
192
|
+
module = new WebAssembly.Module(module);
|
|
193
|
+
}
|
|
194
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
195
|
+
return __wbg_finalize_init(instance, module);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function __wbg_init(module_or_path) {
|
|
199
|
+
if (wasm !== undefined) return wasm;
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
if (typeof module_or_path !== 'undefined') {
|
|
203
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
204
|
+
({module_or_path} = module_or_path)
|
|
205
|
+
} else {
|
|
206
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (typeof module_or_path === 'undefined') {
|
|
211
|
+
module_or_path = new URL('beautiful_image_bg.wasm', import.meta.url);
|
|
212
|
+
}
|
|
213
|
+
const imports = __wbg_get_imports();
|
|
214
|
+
|
|
215
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
216
|
+
module_or_path = fetch(module_or_path);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
220
|
+
|
|
221
|
+
return __wbg_finalize_init(instance, module);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { initSync };
|
|
225
|
+
export default __wbg_init;
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const processImage: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => [number, number, number, number];
|
|
5
|
+
export const processImageFromBytes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number, number, number];
|
|
6
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
8
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
9
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
10
|
+
export const __wbindgen_start: () => void;
|