beautiful-image 0.1.3 → 0.1.5
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 +9 -1
- package/beautiful_image.d.ts +0 -36
- package/beautiful_image.js +5 -282
- package/beautiful_image_bg.js +193 -0
- package/beautiful_image_bg.wasm +0 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -25,7 +25,10 @@ npm i beautiful-image
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
|
-
import { optimizeImage, ResizeMode } from "beautiful-image";
|
|
28
|
+
import init, { optimizeImage, ResizeMode } from "beautiful-image";
|
|
29
|
+
|
|
30
|
+
// Initialize WASM (call once at app startup)
|
|
31
|
+
await init();
|
|
29
32
|
```
|
|
30
33
|
|
|
31
34
|
### API
|
|
@@ -45,6 +48,11 @@ optimizeImage(bytes, width, quality, mode)
|
|
|
45
48
|
### Examples
|
|
46
49
|
|
|
47
50
|
```javascript
|
|
51
|
+
import init, { optimizeImage, ResizeMode } from "beautiful-image";
|
|
52
|
+
|
|
53
|
+
// Initialize WASM
|
|
54
|
+
await init();
|
|
55
|
+
|
|
48
56
|
// Get image bytes from a file input
|
|
49
57
|
const file = document.getElementById('upload').files[0];
|
|
50
58
|
const arrayBuffer = await file.arrayBuffer();
|
package/beautiful_image.d.ts
CHANGED
|
@@ -9,39 +9,3 @@ export enum ResizeMode {
|
|
|
9
9
|
export function main_js(): void;
|
|
10
10
|
|
|
11
11
|
export function optimizeImage(bytes: Uint8Array, width: number, quality: number, mode?: ResizeMode | 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 main_js: () => void;
|
|
18
|
-
readonly optimizeImage: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
19
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
20
|
-
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
21
|
-
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
22
|
-
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
23
|
-
readonly __externref_table_dealloc: (a: number) => void;
|
|
24
|
-
readonly __wbindgen_start: () => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
31
|
-
* a precompiled `WebAssembly.Module`.
|
|
32
|
-
*
|
|
33
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
34
|
-
*
|
|
35
|
-
* @returns {InitOutput}
|
|
36
|
-
*/
|
|
37
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
41
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
42
|
-
*
|
|
43
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
44
|
-
*
|
|
45
|
-
* @returns {Promise<InitOutput>}
|
|
46
|
-
*/
|
|
47
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/beautiful_image.js
CHANGED
|
@@ -1,282 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
let cachedDataViewMemory0 = null;
|
|
9
|
-
function getDataViewMemory0() {
|
|
10
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
11
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
12
|
-
}
|
|
13
|
-
return cachedDataViewMemory0;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function getStringFromWasm0(ptr, len) {
|
|
17
|
-
ptr = ptr >>> 0;
|
|
18
|
-
return decodeText(ptr, len);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let cachedUint8ArrayMemory0 = null;
|
|
22
|
-
function getUint8ArrayMemory0() {
|
|
23
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
24
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
25
|
-
}
|
|
26
|
-
return cachedUint8ArrayMemory0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isLikeNone(x) {
|
|
30
|
-
return x === undefined || x === null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
34
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
35
|
-
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
36
|
-
WASM_VECTOR_LEN = arg.length;
|
|
37
|
-
return ptr;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
41
|
-
if (realloc === undefined) {
|
|
42
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
43
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
44
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
45
|
-
WASM_VECTOR_LEN = buf.length;
|
|
46
|
-
return ptr;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
let len = arg.length;
|
|
50
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
51
|
-
|
|
52
|
-
const mem = getUint8ArrayMemory0();
|
|
53
|
-
|
|
54
|
-
let offset = 0;
|
|
55
|
-
|
|
56
|
-
for (; offset < len; offset++) {
|
|
57
|
-
const code = arg.charCodeAt(offset);
|
|
58
|
-
if (code > 0x7F) break;
|
|
59
|
-
mem[ptr + offset] = code;
|
|
60
|
-
}
|
|
61
|
-
if (offset !== len) {
|
|
62
|
-
if (offset !== 0) {
|
|
63
|
-
arg = arg.slice(offset);
|
|
64
|
-
}
|
|
65
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
66
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
67
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
68
|
-
|
|
69
|
-
offset += ret.written;
|
|
70
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
WASM_VECTOR_LEN = offset;
|
|
74
|
-
return ptr;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function takeFromExternrefTable0(idx) {
|
|
78
|
-
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
79
|
-
wasm.__externref_table_dealloc(idx);
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
84
|
-
cachedTextDecoder.decode();
|
|
85
|
-
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
86
|
-
let numBytesDecoded = 0;
|
|
87
|
-
function decodeText(ptr, len) {
|
|
88
|
-
numBytesDecoded += len;
|
|
89
|
-
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
90
|
-
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
91
|
-
cachedTextDecoder.decode();
|
|
92
|
-
numBytesDecoded = len;
|
|
93
|
-
}
|
|
94
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const cachedTextEncoder = new TextEncoder();
|
|
98
|
-
|
|
99
|
-
if (!('encodeInto' in cachedTextEncoder)) {
|
|
100
|
-
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
101
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
102
|
-
view.set(buf);
|
|
103
|
-
return {
|
|
104
|
-
read: arg.length,
|
|
105
|
-
written: buf.length
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
let WASM_VECTOR_LEN = 0;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @enum {0 | 1}
|
|
114
|
-
*/
|
|
115
|
-
export const ResizeMode = Object.freeze({
|
|
116
|
-
Standard: 0, "0": "Standard",
|
|
117
|
-
HighQuality: 1, "1": "HighQuality",
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
export function main_js() {
|
|
121
|
-
wasm.main_js();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @param {Uint8Array} bytes
|
|
126
|
-
* @param {number} width
|
|
127
|
-
* @param {number} quality
|
|
128
|
-
* @param {ResizeMode | null} [mode]
|
|
129
|
-
* @returns {Uint8Array}
|
|
130
|
-
*/
|
|
131
|
-
export function optimizeImage(bytes, width, quality, mode) {
|
|
132
|
-
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
133
|
-
const len0 = WASM_VECTOR_LEN;
|
|
134
|
-
const ret = wasm.optimizeImage(ptr0, len0, width, quality, isLikeNone(mode) ? 2 : mode);
|
|
135
|
-
if (ret[3]) {
|
|
136
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
137
|
-
}
|
|
138
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
139
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
140
|
-
return v2;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
144
|
-
|
|
145
|
-
async function __wbg_load(module, imports) {
|
|
146
|
-
if (typeof Response === 'function' && module instanceof Response) {
|
|
147
|
-
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
148
|
-
try {
|
|
149
|
-
return await WebAssembly.instantiateStreaming(module, imports);
|
|
150
|
-
} catch (e) {
|
|
151
|
-
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
152
|
-
|
|
153
|
-
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
154
|
-
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);
|
|
155
|
-
|
|
156
|
-
} else {
|
|
157
|
-
throw e;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const bytes = await module.arrayBuffer();
|
|
163
|
-
return await WebAssembly.instantiate(bytes, imports);
|
|
164
|
-
} else {
|
|
165
|
-
const instance = await WebAssembly.instantiate(module, imports);
|
|
166
|
-
|
|
167
|
-
if (instance instanceof WebAssembly.Instance) {
|
|
168
|
-
return { instance, module };
|
|
169
|
-
} else {
|
|
170
|
-
return instance;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function __wbg_get_imports() {
|
|
176
|
-
const imports = {};
|
|
177
|
-
imports.wbg = {};
|
|
178
|
-
imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
|
|
179
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
180
|
-
};
|
|
181
|
-
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
182
|
-
let deferred0_0;
|
|
183
|
-
let deferred0_1;
|
|
184
|
-
try {
|
|
185
|
-
deferred0_0 = arg0;
|
|
186
|
-
deferred0_1 = arg1;
|
|
187
|
-
console.error(getStringFromWasm0(arg0, arg1));
|
|
188
|
-
} finally {
|
|
189
|
-
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
imports.wbg.__wbg_log_8bb45faa69851ee1 = function(arg0, arg1) {
|
|
193
|
-
console.log(getStringFromWasm0(arg0, arg1));
|
|
194
|
-
};
|
|
195
|
-
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
|
196
|
-
const ret = new Error();
|
|
197
|
-
return ret;
|
|
198
|
-
};
|
|
199
|
-
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
200
|
-
const ret = arg1.stack;
|
|
201
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
202
|
-
const len1 = WASM_VECTOR_LEN;
|
|
203
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
204
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
205
|
-
};
|
|
206
|
-
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
207
|
-
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
208
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
209
|
-
return ret;
|
|
210
|
-
};
|
|
211
|
-
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
212
|
-
const table = wasm.__wbindgen_externrefs;
|
|
213
|
-
const offset = table.grow(4);
|
|
214
|
-
table.set(0, undefined);
|
|
215
|
-
table.set(offset + 0, undefined);
|
|
216
|
-
table.set(offset + 1, null);
|
|
217
|
-
table.set(offset + 2, true);
|
|
218
|
-
table.set(offset + 3, false);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
return imports;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function __wbg_finalize_init(instance, module) {
|
|
225
|
-
wasm = instance.exports;
|
|
226
|
-
__wbg_init.__wbindgen_wasm_module = module;
|
|
227
|
-
cachedDataViewMemory0 = null;
|
|
228
|
-
cachedUint8ArrayMemory0 = null;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
wasm.__wbindgen_start();
|
|
232
|
-
return wasm;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function initSync(module) {
|
|
236
|
-
if (wasm !== undefined) return wasm;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (typeof module !== 'undefined') {
|
|
240
|
-
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
241
|
-
({module} = module)
|
|
242
|
-
} else {
|
|
243
|
-
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const imports = __wbg_get_imports();
|
|
248
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
249
|
-
module = new WebAssembly.Module(module);
|
|
250
|
-
}
|
|
251
|
-
const instance = new WebAssembly.Instance(module, imports);
|
|
252
|
-
return __wbg_finalize_init(instance, module);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
async function __wbg_init(module_or_path) {
|
|
256
|
-
if (wasm !== undefined) return wasm;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (typeof module_or_path !== 'undefined') {
|
|
260
|
-
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
261
|
-
({module_or_path} = module_or_path)
|
|
262
|
-
} else {
|
|
263
|
-
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (typeof module_or_path === 'undefined') {
|
|
268
|
-
module_or_path = new URL('beautiful_image_bg.wasm', import.meta.url);
|
|
269
|
-
}
|
|
270
|
-
const imports = __wbg_get_imports();
|
|
271
|
-
|
|
272
|
-
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
273
|
-
module_or_path = fetch(module_or_path);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
277
|
-
|
|
278
|
-
return __wbg_finalize_init(instance, module);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export { initSync };
|
|
282
|
-
export default __wbg_init;
|
|
1
|
+
import * as wasm from "./beautiful_image_bg.wasm";
|
|
2
|
+
export * from "./beautiful_image_bg.js";
|
|
3
|
+
import { __wbg_set_wasm } from "./beautiful_image_bg.js";
|
|
4
|
+
__wbg_set_wasm(wasm);
|
|
5
|
+
wasm.__wbindgen_start();
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
export function __wbg_set_wasm(val) {
|
|
3
|
+
wasm = val;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
7
|
+
ptr = ptr >>> 0;
|
|
8
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let cachedDataViewMemory0 = null;
|
|
12
|
+
function getDataViewMemory0() {
|
|
13
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
14
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
15
|
+
}
|
|
16
|
+
return cachedDataViewMemory0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getStringFromWasm0(ptr, len) {
|
|
20
|
+
ptr = ptr >>> 0;
|
|
21
|
+
return decodeText(ptr, len);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let cachedUint8ArrayMemory0 = null;
|
|
25
|
+
function getUint8ArrayMemory0() {
|
|
26
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
27
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
28
|
+
}
|
|
29
|
+
return cachedUint8ArrayMemory0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isLikeNone(x) {
|
|
33
|
+
return x === undefined || x === null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
37
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
38
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
39
|
+
WASM_VECTOR_LEN = arg.length;
|
|
40
|
+
return ptr;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
44
|
+
if (realloc === undefined) {
|
|
45
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
46
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
47
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
48
|
+
WASM_VECTOR_LEN = buf.length;
|
|
49
|
+
return ptr;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let len = arg.length;
|
|
53
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
54
|
+
|
|
55
|
+
const mem = getUint8ArrayMemory0();
|
|
56
|
+
|
|
57
|
+
let offset = 0;
|
|
58
|
+
|
|
59
|
+
for (; offset < len; offset++) {
|
|
60
|
+
const code = arg.charCodeAt(offset);
|
|
61
|
+
if (code > 0x7F) break;
|
|
62
|
+
mem[ptr + offset] = code;
|
|
63
|
+
}
|
|
64
|
+
if (offset !== len) {
|
|
65
|
+
if (offset !== 0) {
|
|
66
|
+
arg = arg.slice(offset);
|
|
67
|
+
}
|
|
68
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
69
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
70
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
71
|
+
|
|
72
|
+
offset += ret.written;
|
|
73
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
WASM_VECTOR_LEN = offset;
|
|
77
|
+
return ptr;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function takeFromExternrefTable0(idx) {
|
|
81
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
82
|
+
wasm.__externref_table_dealloc(idx);
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
87
|
+
cachedTextDecoder.decode();
|
|
88
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
89
|
+
let numBytesDecoded = 0;
|
|
90
|
+
function decodeText(ptr, len) {
|
|
91
|
+
numBytesDecoded += len;
|
|
92
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
93
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
94
|
+
cachedTextDecoder.decode();
|
|
95
|
+
numBytesDecoded = len;
|
|
96
|
+
}
|
|
97
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const cachedTextEncoder = new TextEncoder();
|
|
101
|
+
|
|
102
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
103
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
104
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
105
|
+
view.set(buf);
|
|
106
|
+
return {
|
|
107
|
+
read: arg.length,
|
|
108
|
+
written: buf.length
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let WASM_VECTOR_LEN = 0;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @enum {0 | 1}
|
|
117
|
+
*/
|
|
118
|
+
export const ResizeMode = Object.freeze({
|
|
119
|
+
Standard: 0, "0": "Standard",
|
|
120
|
+
HighQuality: 1, "1": "HighQuality",
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export function main_js() {
|
|
124
|
+
wasm.main_js();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param {Uint8Array} bytes
|
|
129
|
+
* @param {number} width
|
|
130
|
+
* @param {number} quality
|
|
131
|
+
* @param {ResizeMode | null} [mode]
|
|
132
|
+
* @returns {Uint8Array}
|
|
133
|
+
*/
|
|
134
|
+
export function optimizeImage(bytes, width, quality, mode) {
|
|
135
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
136
|
+
const len0 = WASM_VECTOR_LEN;
|
|
137
|
+
const ret = wasm.optimizeImage(ptr0, len0, width, quality, isLikeNone(mode) ? 2 : mode);
|
|
138
|
+
if (ret[3]) {
|
|
139
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
140
|
+
}
|
|
141
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
142
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
143
|
+
return v2;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function __wbg___wbindgen_throw_dd24417ed36fc46e(arg0, arg1) {
|
|
147
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export function __wbg_error_7534b8e9a36f1ab4(arg0, arg1) {
|
|
151
|
+
let deferred0_0;
|
|
152
|
+
let deferred0_1;
|
|
153
|
+
try {
|
|
154
|
+
deferred0_0 = arg0;
|
|
155
|
+
deferred0_1 = arg1;
|
|
156
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
157
|
+
} finally {
|
|
158
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export function __wbg_log_d96ecda19be22b83(arg0, arg1) {
|
|
163
|
+
console.log(getStringFromWasm0(arg0, arg1));
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export function __wbg_new_8a6f238a6ece86ea() {
|
|
167
|
+
const ret = new Error();
|
|
168
|
+
return ret;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
|
|
172
|
+
const ret = arg1.stack;
|
|
173
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
174
|
+
const len1 = WASM_VECTOR_LEN;
|
|
175
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
176
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
|
|
180
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
181
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
182
|
+
return ret;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export function __wbindgen_init_externref_table() {
|
|
186
|
+
const table = wasm.__wbindgen_externrefs;
|
|
187
|
+
const offset = table.grow(4);
|
|
188
|
+
table.set(0, undefined);
|
|
189
|
+
table.set(offset + 0, undefined);
|
|
190
|
+
table.set(offset + 1, null);
|
|
191
|
+
table.set(offset + 2, true);
|
|
192
|
+
table.set(offset + 3, false);
|
|
193
|
+
};
|
package/beautiful_image_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "beautiful-image",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "A Rust library for optimizing images for the web",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.5",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -11,11 +11,13 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"beautiful_image_bg.wasm",
|
|
13
13
|
"beautiful_image.js",
|
|
14
|
+
"beautiful_image_bg.js",
|
|
14
15
|
"beautiful_image.d.ts"
|
|
15
16
|
],
|
|
16
17
|
"main": "beautiful_image.js",
|
|
17
18
|
"types": "beautiful_image.d.ts",
|
|
18
19
|
"sideEffects": [
|
|
20
|
+
"./beautiful_image.js",
|
|
19
21
|
"./snippets/*"
|
|
20
22
|
]
|
|
21
23
|
}
|