beautiful-image 0.1.5 → 0.1.7

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 CHANGED
@@ -24,11 +24,10 @@ npm i beautiful-image
24
24
 
25
25
  ## Usage
26
26
 
27
- ```javascript
28
- import init, { optimizeImage, ResizeMode } from "beautiful-image";
27
+ Works with any modern bundler (Vite, Webpack, Rollup) and framework (React, Vue, Angular, Svelte).
29
28
 
30
- // Initialize WASM (call once at app startup)
31
- await init();
29
+ ```javascript
30
+ import { optimizeImage, ResizeMode } from "beautiful-image";
32
31
  ```
33
32
 
34
33
  ### API
@@ -48,10 +47,7 @@ optimizeImage(bytes, width, quality, mode)
48
47
  ### Examples
49
48
 
50
49
  ```javascript
51
- import init, { optimizeImage, ResizeMode } from "beautiful-image";
52
-
53
- // Initialize WASM
54
- await init();
50
+ import { optimizeImage, ResizeMode } from "beautiful-image";
55
51
 
56
52
  // Get image bytes from a file input
57
53
  const file = document.getElementById('upload').files[0];
@@ -78,7 +74,7 @@ If you want to build the package yourself:
78
74
 
79
75
  ```bash
80
76
  cargo install wasm-pack
81
- wasm-pack build --target web
77
+ wasm-pack build --target bundler --release
82
78
  ```
83
79
 
84
80
  ## License
@@ -6,6 +6,4 @@ export enum ResizeMode {
6
6
  HighQuality = 1,
7
7
  }
8
8
 
9
- export function main_js(): void;
10
-
11
9
  export function optimizeImage(bytes: Uint8Array, width: number, quality: number, mode?: ResizeMode | null): Uint8Array;
@@ -8,14 +8,6 @@ function getArrayU8FromWasm0(ptr, len) {
8
8
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
9
9
  }
10
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
11
  function getStringFromWasm0(ptr, len) {
20
12
  ptr = ptr >>> 0;
21
13
  return decodeText(ptr, len);
@@ -40,43 +32,6 @@ function passArray8ToWasm0(arg, malloc) {
40
32
  return ptr;
41
33
  }
42
34
 
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
35
  function takeFromExternrefTable0(idx) {
81
36
  const value = wasm.__wbindgen_externrefs.get(idx);
82
37
  wasm.__externref_table_dealloc(idx);
@@ -97,19 +52,6 @@ function decodeText(ptr, len) {
97
52
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
98
53
  }
99
54
 
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
55
  let WASM_VECTOR_LEN = 0;
114
56
 
115
57
  /**
@@ -120,10 +62,6 @@ export const ResizeMode = Object.freeze({
120
62
  HighQuality: 1, "1": "HighQuality",
121
63
  });
122
64
 
123
- export function main_js() {
124
- wasm.main_js();
125
- }
126
-
127
65
  /**
128
66
  * @param {Uint8Array} bytes
129
67
  * @param {number} width
@@ -147,35 +85,6 @@ export function __wbg___wbindgen_throw_dd24417ed36fc46e(arg0, arg1) {
147
85
  throw new Error(getStringFromWasm0(arg0, arg1));
148
86
  };
149
87
 
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
88
  export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
180
89
  // Cast intrinsic for `Ref(String) -> Externref`.
181
90
  const ret = getStringFromWasm0(arg0, arg1);
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",
5
+ "version": "0.1.7",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",