beautiful-image 0.1.0 → 0.1.3
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 +40 -31
- package/beautiful_image.d.ts +37 -1
- package/beautiful_image.js +282 -5
- package/beautiful_image_bg.wasm +0 -0
- package/package.json +1 -3
- package/beautiful_image_bg.js +0 -193
package/README.md
CHANGED
|
@@ -18,50 +18,59 @@ Optimizes images by resizing and compressing them to JPEG format. Perfect for re
|
|
|
18
18
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
21
|
-
First, install [wasm-pack](https://rustwasm.github.io/wasm-pack/):
|
|
22
|
-
|
|
23
21
|
```bash
|
|
24
|
-
|
|
22
|
+
npm i beautiful-image
|
|
25
23
|
```
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
## Usage
|
|
28
26
|
|
|
29
|
-
```
|
|
30
|
-
|
|
27
|
+
```javascript
|
|
28
|
+
import { optimizeImage, ResizeMode } from "beautiful-image";
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### API
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
optimizeImage(bytes, width, quality, mode)
|
|
31
35
|
```
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
**Parameters:**
|
|
38
|
+
- `bytes` (Uint8Array): Image data as byte array
|
|
39
|
+
- `width` (number): Target width in pixels (maintains aspect ratio)
|
|
40
|
+
- `quality` (number): JPEG quality from 1-100 (higher = better quality, larger file)
|
|
41
|
+
- `mode` (ResizeMode): `ResizeMode.Standard` (fast) or `ResizeMode.HighQuality` (slower, better)
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
**Returns:** `Uint8Array` - Optimized JPEG image bytes
|
|
36
44
|
|
|
37
|
-
|
|
38
|
-
<script type="module">
|
|
39
|
-
import init, { optimize_image, ResizeMode } from "./pkg/beautiful_image.js";
|
|
45
|
+
### Examples
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
```javascript
|
|
48
|
+
// Get image bytes from a file input
|
|
49
|
+
const file = document.getElementById('upload').files[0];
|
|
50
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
51
|
+
const bytes = new Uint8Array(arrayBuffer);
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const arrayBuffer = await file.arrayBuffer();
|
|
48
|
-
const bytes = new Uint8Array(arrayBuffer);
|
|
53
|
+
// Example 1: High quality resize to 800px
|
|
54
|
+
const result1 = optimizeImage(bytes, 800, 85, ResizeMode.HighQuality);
|
|
49
55
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
bytes, // Image bytes
|
|
53
|
-
800, // New width in pixels
|
|
54
|
-
85, // Quality (0-100)
|
|
55
|
-
ResizeMode.HighQuality // Resize mode
|
|
56
|
-
);
|
|
56
|
+
// Example 2: Fast standard resize to 1200px with lower quality
|
|
57
|
+
const result2 = optimizeImage(bytes, 1200, 60, ResizeMode.Standard);
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const url = URL.createObjectURL(blob);
|
|
61
|
-
}
|
|
59
|
+
// Example 3: Small thumbnail with standard mode
|
|
60
|
+
const result3 = optimizeImage(bytes, 300, 70, ResizeMode.Standard);
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
// Create a blob to display or download
|
|
63
|
+
const blob = new Blob([result1], { type: "image/jpeg" });
|
|
64
|
+
const url = URL.createObjectURL(blob);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Building from Source
|
|
68
|
+
|
|
69
|
+
If you want to build the package yourself:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
cargo install wasm-pack
|
|
73
|
+
wasm-pack build --target web
|
|
65
74
|
```
|
|
66
75
|
|
|
67
76
|
## License
|
package/beautiful_image.d.ts
CHANGED
|
@@ -8,4 +8,40 @@ export enum ResizeMode {
|
|
|
8
8
|
|
|
9
9
|
export function main_js(): void;
|
|
10
10
|
|
|
11
|
-
export function
|
|
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,5 +1,282 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
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;
|
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.3",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -11,13 +11,11 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"beautiful_image_bg.wasm",
|
|
13
13
|
"beautiful_image.js",
|
|
14
|
-
"beautiful_image_bg.js",
|
|
15
14
|
"beautiful_image.d.ts"
|
|
16
15
|
],
|
|
17
16
|
"main": "beautiful_image.js",
|
|
18
17
|
"types": "beautiful_image.d.ts",
|
|
19
18
|
"sideEffects": [
|
|
20
|
-
"./beautiful_image.js",
|
|
21
19
|
"./snippets/*"
|
|
22
20
|
]
|
|
23
21
|
}
|
package/beautiful_image_bg.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
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} datos_entrada
|
|
129
|
-
* @param {number} new_width
|
|
130
|
-
* @param {number} quality
|
|
131
|
-
* @param {ResizeMode | null} [resize_mode]
|
|
132
|
-
* @returns {Uint8Array}
|
|
133
|
-
*/
|
|
134
|
-
export function optimize_image(datos_entrada, new_width, quality, resize_mode) {
|
|
135
|
-
const ptr0 = passArray8ToWasm0(datos_entrada, wasm.__wbindgen_malloc);
|
|
136
|
-
const len0 = WASM_VECTOR_LEN;
|
|
137
|
-
const ret = wasm.optimize_image(ptr0, len0, new_width, quality, isLikeNone(resize_mode) ? 2 : resize_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_2638f9d948a0513e(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
|
-
};
|