rust-editor 0.1.0

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 ADDED
@@ -0,0 +1 @@
1
+ # rust-img-editor
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "rust-editor",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "files": [
6
+ "rust_editor_bg.wasm",
7
+ "rust_editor.js",
8
+ "rust_editor.d.ts"
9
+ ],
10
+ "main": "rust_editor.js",
11
+ "types": "rust_editor.d.ts",
12
+ "sideEffects": [
13
+ "./snippets/*"
14
+ ]
15
+ }
@@ -0,0 +1,55 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export function resize(image_data: Uint8Array, height: number, width: number): Uint8Array;
4
+ export function resize_exact(image_data: Uint8Array, width: number, height: number): Uint8Array;
5
+ export function resize_one_side(image_data: Uint8Array, width: number, height: number): Uint8Array;
6
+ export function crop(image_data: Uint8Array, x: number, y: number, width: number, height: number): Uint8Array;
7
+ export function change_scale_image(image_data: Uint8Array, scale: number): Uint8Array;
8
+ export function get_size(image_data: Uint8Array): Uint32Array;
9
+ export function switch_color(image_source: Uint8Array, image_reference: Uint8Array): Uint8Array;
10
+ export function blur(image_data: Uint8Array, radius: number): Uint8Array;
11
+ export function sharpen(image_data: Uint8Array, radius: number): Uint8Array;
12
+ export function fix_size_image(image_data: Uint8Array): Uint8Array;
13
+ export function coloring_grayscale(image_source: Uint8Array, image_reference: Uint8Array): void;
14
+
15
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
16
+
17
+ export interface InitOutput {
18
+ readonly memory: WebAssembly.Memory;
19
+ readonly resize: (a: number, b: number, c: number, d: number) => [number, number];
20
+ readonly resize_exact: (a: number, b: number, c: number, d: number) => [number, number];
21
+ readonly resize_one_side: (a: number, b: number, c: number, d: number) => [number, number];
22
+ readonly crop: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
23
+ readonly change_scale_image: (a: number, b: number, c: number) => [number, number];
24
+ readonly get_size: (a: number, b: number) => [number, number];
25
+ readonly switch_color: (a: number, b: number, c: number, d: number) => [number, number];
26
+ readonly blur: (a: number, b: number, c: number) => [number, number];
27
+ readonly sharpen: (a: number, b: number, c: number) => [number, number];
28
+ readonly fix_size_image: (a: number, b: number) => [number, number];
29
+ readonly coloring_grayscale: (a: number, b: number, c: number, d: number) => void;
30
+ readonly __wbindgen_export_0: WebAssembly.Table;
31
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
32
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
33
+ readonly __wbindgen_start: () => void;
34
+ }
35
+
36
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
37
+ /**
38
+ * Instantiates the given `module`, which can either be bytes or
39
+ * a precompiled `WebAssembly.Module`.
40
+ *
41
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
42
+ *
43
+ * @returns {InitOutput}
44
+ */
45
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
46
+
47
+ /**
48
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
49
+ * for everything else, calls `WebAssembly.instantiate` directly.
50
+ *
51
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
52
+ *
53
+ * @returns {Promise<InitOutput>}
54
+ */
55
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/rust_editor.js ADDED
@@ -0,0 +1,313 @@
1
+ let wasm;
2
+
3
+ let cachedUint8ArrayMemory0 = null;
4
+
5
+ function getUint8ArrayMemory0() {
6
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
7
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
8
+ }
9
+ return cachedUint8ArrayMemory0;
10
+ }
11
+
12
+ let WASM_VECTOR_LEN = 0;
13
+
14
+ function passArray8ToWasm0(arg, malloc) {
15
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
16
+ getUint8ArrayMemory0().set(arg, ptr / 1);
17
+ WASM_VECTOR_LEN = arg.length;
18
+ return ptr;
19
+ }
20
+
21
+ function getArrayU8FromWasm0(ptr, len) {
22
+ ptr = ptr >>> 0;
23
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
24
+ }
25
+ /**
26
+ * @param {Uint8Array} image_data
27
+ * @param {number} height
28
+ * @param {number} width
29
+ * @returns {Uint8Array}
30
+ */
31
+ export function resize(image_data, height, width) {
32
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
33
+ const len0 = WASM_VECTOR_LEN;
34
+ const ret = wasm.resize(ptr0, len0, height, width);
35
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
36
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
37
+ return v2;
38
+ }
39
+
40
+ /**
41
+ * @param {Uint8Array} image_data
42
+ * @param {number} width
43
+ * @param {number} height
44
+ * @returns {Uint8Array}
45
+ */
46
+ export function resize_exact(image_data, width, height) {
47
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
48
+ const len0 = WASM_VECTOR_LEN;
49
+ const ret = wasm.resize_exact(ptr0, len0, width, height);
50
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
51
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
52
+ return v2;
53
+ }
54
+
55
+ /**
56
+ * @param {Uint8Array} image_data
57
+ * @param {number} width
58
+ * @param {number} height
59
+ * @returns {Uint8Array}
60
+ */
61
+ export function resize_one_side(image_data, width, height) {
62
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
63
+ const len0 = WASM_VECTOR_LEN;
64
+ const ret = wasm.resize_one_side(ptr0, len0, width, height);
65
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
66
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
67
+ return v2;
68
+ }
69
+
70
+ /**
71
+ * @param {Uint8Array} image_data
72
+ * @param {number} x
73
+ * @param {number} y
74
+ * @param {number} width
75
+ * @param {number} height
76
+ * @returns {Uint8Array}
77
+ */
78
+ export function crop(image_data, x, y, width, height) {
79
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
80
+ const len0 = WASM_VECTOR_LEN;
81
+ const ret = wasm.crop(ptr0, len0, x, y, width, height);
82
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
83
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
84
+ return v2;
85
+ }
86
+
87
+ /**
88
+ * @param {Uint8Array} image_data
89
+ * @param {number} scale
90
+ * @returns {Uint8Array}
91
+ */
92
+ export function change_scale_image(image_data, scale) {
93
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
94
+ const len0 = WASM_VECTOR_LEN;
95
+ const ret = wasm.change_scale_image(ptr0, len0, scale);
96
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
97
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
98
+ return v2;
99
+ }
100
+
101
+ let cachedUint32ArrayMemory0 = null;
102
+
103
+ function getUint32ArrayMemory0() {
104
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
105
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
106
+ }
107
+ return cachedUint32ArrayMemory0;
108
+ }
109
+
110
+ function getArrayU32FromWasm0(ptr, len) {
111
+ ptr = ptr >>> 0;
112
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
113
+ }
114
+ /**
115
+ * @param {Uint8Array} image_data
116
+ * @returns {Uint32Array}
117
+ */
118
+ export function get_size(image_data) {
119
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
120
+ const len0 = WASM_VECTOR_LEN;
121
+ const ret = wasm.get_size(ptr0, len0);
122
+ var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
123
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
124
+ return v2;
125
+ }
126
+
127
+ /**
128
+ * @param {Uint8Array} image_source
129
+ * @param {Uint8Array} image_reference
130
+ * @returns {Uint8Array}
131
+ */
132
+ export function switch_color(image_source, image_reference) {
133
+ const ptr0 = passArray8ToWasm0(image_source, wasm.__wbindgen_malloc);
134
+ const len0 = WASM_VECTOR_LEN;
135
+ const ptr1 = passArray8ToWasm0(image_reference, wasm.__wbindgen_malloc);
136
+ const len1 = WASM_VECTOR_LEN;
137
+ const ret = wasm.switch_color(ptr0, len0, ptr1, len1);
138
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
139
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
140
+ return v3;
141
+ }
142
+
143
+ /**
144
+ * @param {Uint8Array} image_data
145
+ * @param {number} radius
146
+ * @returns {Uint8Array}
147
+ */
148
+ export function blur(image_data, radius) {
149
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
150
+ const len0 = WASM_VECTOR_LEN;
151
+ const ret = wasm.blur(ptr0, len0, radius);
152
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
153
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
154
+ return v2;
155
+ }
156
+
157
+ /**
158
+ * @param {Uint8Array} image_data
159
+ * @param {number} radius
160
+ * @returns {Uint8Array}
161
+ */
162
+ export function sharpen(image_data, radius) {
163
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
164
+ const len0 = WASM_VECTOR_LEN;
165
+ const ret = wasm.sharpen(ptr0, len0, radius);
166
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
167
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
168
+ return v2;
169
+ }
170
+
171
+ /**
172
+ * @param {Uint8Array} image_data
173
+ * @returns {Uint8Array}
174
+ */
175
+ export function fix_size_image(image_data) {
176
+ const ptr0 = passArray8ToWasm0(image_data, wasm.__wbindgen_malloc);
177
+ const len0 = WASM_VECTOR_LEN;
178
+ const ret = wasm.fix_size_image(ptr0, len0);
179
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
180
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
181
+ return v2;
182
+ }
183
+
184
+ /**
185
+ * @param {Uint8Array} image_source
186
+ * @param {Uint8Array} image_reference
187
+ */
188
+ export function coloring_grayscale(image_source, image_reference) {
189
+ const ptr0 = passArray8ToWasm0(image_source, wasm.__wbindgen_malloc);
190
+ const len0 = WASM_VECTOR_LEN;
191
+ const ptr1 = passArray8ToWasm0(image_reference, wasm.__wbindgen_malloc);
192
+ const len1 = WASM_VECTOR_LEN;
193
+ wasm.coloring_grayscale(ptr0, len0, ptr1, len1);
194
+ }
195
+
196
+ async function __wbg_load(module, imports) {
197
+ if (typeof Response === 'function' && module instanceof Response) {
198
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
199
+ try {
200
+ return await WebAssembly.instantiateStreaming(module, imports);
201
+
202
+ } catch (e) {
203
+ if (module.headers.get('Content-Type') != 'application/wasm') {
204
+ 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);
205
+
206
+ } else {
207
+ throw e;
208
+ }
209
+ }
210
+ }
211
+
212
+ const bytes = await module.arrayBuffer();
213
+ return await WebAssembly.instantiate(bytes, imports);
214
+
215
+ } else {
216
+ const instance = await WebAssembly.instantiate(module, imports);
217
+
218
+ if (instance instanceof WebAssembly.Instance) {
219
+ return { instance, module };
220
+
221
+ } else {
222
+ return instance;
223
+ }
224
+ }
225
+ }
226
+
227
+ function __wbg_get_imports() {
228
+ const imports = {};
229
+ imports.wbg = {};
230
+ imports.wbg.__wbindgen_init_externref_table = function() {
231
+ const table = wasm.__wbindgen_export_0;
232
+ const offset = table.grow(4);
233
+ table.set(0, undefined);
234
+ table.set(offset + 0, undefined);
235
+ table.set(offset + 1, null);
236
+ table.set(offset + 2, true);
237
+ table.set(offset + 3, false);
238
+ ;
239
+ };
240
+
241
+ return imports;
242
+ }
243
+
244
+ function __wbg_init_memory(imports, memory) {
245
+
246
+ }
247
+
248
+ function __wbg_finalize_init(instance, module) {
249
+ wasm = instance.exports;
250
+ __wbg_init.__wbindgen_wasm_module = module;
251
+ cachedUint32ArrayMemory0 = null;
252
+ cachedUint8ArrayMemory0 = null;
253
+
254
+
255
+ wasm.__wbindgen_start();
256
+ return wasm;
257
+ }
258
+
259
+ function initSync(module) {
260
+ if (wasm !== undefined) return wasm;
261
+
262
+
263
+ if (typeof module !== 'undefined') {
264
+ if (Object.getPrototypeOf(module) === Object.prototype) {
265
+ ({module} = module)
266
+ } else {
267
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
268
+ }
269
+ }
270
+
271
+ const imports = __wbg_get_imports();
272
+
273
+ __wbg_init_memory(imports);
274
+
275
+ if (!(module instanceof WebAssembly.Module)) {
276
+ module = new WebAssembly.Module(module);
277
+ }
278
+
279
+ const instance = new WebAssembly.Instance(module, imports);
280
+
281
+ return __wbg_finalize_init(instance, module);
282
+ }
283
+
284
+ async function __wbg_init(module_or_path) {
285
+ if (wasm !== undefined) return wasm;
286
+
287
+
288
+ if (typeof module_or_path !== 'undefined') {
289
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
290
+ ({module_or_path} = module_or_path)
291
+ } else {
292
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
293
+ }
294
+ }
295
+
296
+ if (typeof module_or_path === 'undefined') {
297
+ module_or_path = new URL('rust_editor_bg.wasm', import.meta.url);
298
+ }
299
+ const imports = __wbg_get_imports();
300
+
301
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
302
+ module_or_path = fetch(module_or_path);
303
+ }
304
+
305
+ __wbg_init_memory(imports);
306
+
307
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
308
+
309
+ return __wbg_finalize_init(instance, module);
310
+ }
311
+
312
+ export { initSync };
313
+ export default __wbg_init;
Binary file