wasm-image-optimization 1.3.0 → 1.3.1

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.
@@ -712,8 +712,13 @@ var require_libImage = __commonJS({
712
712
  tty.output = [];
713
713
  }
714
714
  } } };
715
+ var zeroMemory = (ptr, size) => HEAPU8.fill(0, ptr, ptr + size);
716
+ var alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment;
715
717
  var mmapAlloc = (size) => {
716
- abort();
718
+ size = alignMemory(size, 65536);
719
+ var ptr = _emscripten_builtin_memalign(65536, size);
720
+ if (ptr) zeroMemory(ptr, size);
721
+ return ptr;
717
722
  };
718
723
  var MEMFS = { ops_table: null, mount(mount) {
719
724
  return MEMFS.createNode(null, "/", 16895, 0);
@@ -1861,7 +1866,7 @@ var require_libImage = __commonJS({
1861
1866
  opts.flags = opts.flags || 0;
1862
1867
  opts.encoding = opts.encoding || "binary";
1863
1868
  if (opts.encoding !== "utf8" && opts.encoding !== "binary") {
1864
- throw new Error(`Invalid encoding type "${opts.encoding}"`);
1869
+ abort(`Invalid encoding type "${opts.encoding}"`);
1865
1870
  }
1866
1871
  var stream = FS.open(path, opts.flags);
1867
1872
  var stat = FS.stat(path);
@@ -1882,7 +1887,7 @@ var require_libImage = __commonJS({
1882
1887
  if (ArrayBuffer.isView(data)) {
1883
1888
  FS.write(stream, data, 0, data.byteLength, void 0, opts.canOwn);
1884
1889
  } else {
1885
- throw new Error("Unsupported data type");
1890
+ abort("Unsupported data type");
1886
1891
  }
1887
1892
  FS.close(stream);
1888
1893
  }, cwd: () => FS.currentPath, chdir(path) {
@@ -2095,7 +2100,7 @@ var require_libImage = __commonJS({
2095
2100
  }, forceLoadFile(obj) {
2096
2101
  if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true;
2097
2102
  if (typeof XMLHttpRequest != "undefined") {
2098
- throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");
2103
+ abort("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");
2099
2104
  } else {
2100
2105
  try {
2101
2106
  obj.contents = readBinary(obj.url);
@@ -2122,7 +2127,7 @@ var require_libImage = __commonJS({
2122
2127
  var xhr = new XMLHttpRequest();
2123
2128
  xhr.open("HEAD", url, false);
2124
2129
  xhr.send(null);
2125
- if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr.status);
2130
+ if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status);
2126
2131
  var datalength = Number(xhr.getResponseHeader("Content-length"));
2127
2132
  var header;
2128
2133
  var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes";
@@ -2130,8 +2135,8 @@ var require_libImage = __commonJS({
2130
2135
  var chunkSize = 1024 * 1024;
2131
2136
  if (!hasByteServing) chunkSize = datalength;
2132
2137
  var doXHR = (from, to) => {
2133
- if (from > to) throw new Error("invalid range (" + from + ", " + to + ") or no bytes requested!");
2134
- if (to > datalength - 1) throw new Error("only " + datalength + " bytes available! programmer error!");
2138
+ if (from > to) abort("invalid range (" + from + ", " + to + ") or no bytes requested!");
2139
+ if (to > datalength - 1) abort("only " + datalength + " bytes available! programmer error!");
2135
2140
  var xhr2 = new XMLHttpRequest();
2136
2141
  xhr2.open("GET", url, false);
2137
2142
  if (datalength !== chunkSize) xhr2.setRequestHeader("Range", "bytes=" + from + "-" + to);
@@ -2140,7 +2145,7 @@ var require_libImage = __commonJS({
2140
2145
  xhr2.overrideMimeType("text/plain; charset=x-user-defined");
2141
2146
  }
2142
2147
  xhr2.send(null);
2143
- if (!(xhr2.status >= 200 && xhr2.status < 300 || xhr2.status === 304)) throw new Error("Couldn't load " + url + ". Status: " + xhr2.status);
2148
+ if (!(xhr2.status >= 200 && xhr2.status < 300 || xhr2.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr2.status);
2144
2149
  if (xhr2.response !== void 0) {
2145
2150
  return new Uint8Array(xhr2.response || []);
2146
2151
  }
@@ -2154,7 +2159,7 @@ var require_libImage = __commonJS({
2154
2159
  if (typeof lazyArray2.chunks[chunkNum] == "undefined") {
2155
2160
  lazyArray2.chunks[chunkNum] = doXHR(start, end);
2156
2161
  }
2157
- if (typeof lazyArray2.chunks[chunkNum] == "undefined") throw new Error("doXHR failed!");
2162
+ if (typeof lazyArray2.chunks[chunkNum] == "undefined") abort("doXHR failed!");
2158
2163
  return lazyArray2.chunks[chunkNum];
2159
2164
  });
2160
2165
  if (usesGzip || !datalength) {
@@ -2181,7 +2186,7 @@ var require_libImage = __commonJS({
2181
2186
  }
2182
2187
  }
2183
2188
  if (typeof XMLHttpRequest != "undefined") {
2184
- if (!ENVIRONMENT_IS_WORKER) throw "Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";
2189
+ if (!ENVIRONMENT_IS_WORKER) abort("Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc");
2185
2190
  var lazyArray = new LazyUint8Array();
2186
2191
  var properties = { isDevice: false, contents: lazyArray };
2187
2192
  } else {
@@ -3407,11 +3412,11 @@ var require_libImage = __commonJS({
3407
3412
  delta *= 80;
3408
3413
  break;
3409
3414
  default:
3410
- throw "unrecognized mouse wheel delta mode: " + event.deltaMode;
3415
+ abort("unrecognized mouse wheel delta mode: " + event.deltaMode);
3411
3416
  }
3412
3417
  break;
3413
3418
  default:
3414
- throw "unrecognized mouse wheel event: " + event.type;
3419
+ abort("unrecognized mouse wheel event: " + event.type);
3415
3420
  }
3416
3421
  return delta;
3417
3422
  }, mouseX: 0, mouseY: 0, mouseMovementX: 0, mouseMovementY: 0, touches: {}, lastTouches: {}, calculateMouseCoords(pageX, pageY) {
@@ -3548,7 +3553,6 @@ var require_libImage = __commonJS({
3548
3553
  };
3549
3554
  var _emscripten_has_asyncify = () => 0;
3550
3555
  var getHeapMax = () => 2147483648;
3551
- var alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment;
3552
3556
  var growMemory = (size) => {
3553
3557
  var oldHeapSize = wasmMemory.buffer.byteLength;
3554
3558
  var pages = (size - oldHeapSize + 65535) / 65536 | 0;
@@ -3578,7 +3582,7 @@ var require_libImage = __commonJS({
3578
3582
  return false;
3579
3583
  };
3580
3584
  var _emscripten_sleep = () => {
3581
- throw "Please compile your program with async support in order to use asynchronous operations like emscripten_sleep";
3585
+ abort("Please compile your program with async support in order to use asynchronous operations like emscripten_sleep");
3582
3586
  };
3583
3587
  var ENV = {};
3584
3588
  var getExecutableName = () => thisProgram || "./this.program";
@@ -3719,17 +3723,18 @@ var require_libImage = __commonJS({
3719
3723
  }
3720
3724
  }
3721
3725
  Module2["createContext"] = createContext;
3722
- var _malloc, _free, ___getTypeName, _fileno, _setThrew, __emscripten_stack_restore, _emscripten_stack_get_current;
3726
+ var _malloc, _free, ___getTypeName, _fileno, _emscripten_builtin_memalign, _setThrew, __emscripten_stack_restore, _emscripten_stack_get_current;
3723
3727
  function assignWasmExports(wasmExports2) {
3724
3728
  _malloc = wasmExports2["ja"];
3725
3729
  _free = wasmExports2["ka"];
3726
3730
  ___getTypeName = wasmExports2["la"];
3727
3731
  _fileno = wasmExports2["ma"];
3728
- _setThrew = wasmExports2["na"];
3729
- __emscripten_stack_restore = wasmExports2["oa"];
3730
- _emscripten_stack_get_current = wasmExports2["pa"];
3732
+ _emscripten_builtin_memalign = wasmExports2["na"];
3733
+ _setThrew = wasmExports2["oa"];
3734
+ __emscripten_stack_restore = wasmExports2["pa"];
3735
+ _emscripten_stack_get_current = wasmExports2["qa"];
3731
3736
  }
3732
- var wasmImports = { a: ___assert_fail, p: ___cxa_throw, x: ___syscall_fcntl64, P: ___syscall_ioctl, Q: ___syscall_openat, S: __abort_js, D: __embind_register_bigint, _: __embind_register_bool, Y: __embind_register_emval, B: __embind_register_float, n: __embind_register_function, i: __embind_register_integer, f: __embind_register_memory_view, Z: __embind_register_std_string, s: __embind_register_std_wstring, $: __embind_register_void, H: __emscripten_throw_longjmp, G: __emval_create_invoker, j: __emval_decref, E: __emval_invoke, y: __emval_new_cstring, fa: __emval_new_object, C: __emval_run_destructors, v: __emval_set_property, J: __localtime_js, K: __tzset_js, R: _emscripten_date_now, t: _emscripten_get_now, X: _emscripten_get_preloaded_image_data_from_FILE, U: _emscripten_has_asyncify, I: _emscripten_resize_heap, T: _emscripten_sleep, M: _environ_get, N: _environ_sizes_get, V: _exit, u: _fd_close, O: _fd_read, L: _fd_seek, w: _fd_write, e: invoke_ii, c: invoke_iii, l: invoke_iiii, m: invoke_iiiii, W: invoke_iiiiii, q: invoke_iiiiiiiii, z: invoke_iiiiiiiiii, ca: invoke_iiiiiiiiiii, ea: invoke_iiiiiiiiiiii, da: invoke_iiiijj, A: invoke_ji, r: invoke_jiji, d: invoke_vi, g: invoke_vii, h: invoke_viii, b: invoke_viiii, k: invoke_viiiii, o: invoke_viiiiiii, ba: invoke_viiiiiiii, F: invoke_viiiiiiiii, aa: invoke_viiiiiiiiiii };
3737
+ var wasmImports = { a: ___assert_fail, p: ___cxa_throw, w: ___syscall_fcntl64, P: ___syscall_ioctl, Q: ___syscall_openat, S: __abort_js, D: __embind_register_bigint, _: __embind_register_bool, Y: __embind_register_emval, B: __embind_register_float, n: __embind_register_function, i: __embind_register_integer, e: __embind_register_memory_view, Z: __embind_register_std_string, s: __embind_register_std_wstring, $: __embind_register_void, H: __emscripten_throw_longjmp, G: __emval_create_invoker, j: __emval_decref, E: __emval_invoke, y: __emval_new_cstring, fa: __emval_new_object, C: __emval_run_destructors, v: __emval_set_property, J: __localtime_js, K: __tzset_js, R: _emscripten_date_now, t: _emscripten_get_now, X: _emscripten_get_preloaded_image_data_from_FILE, U: _emscripten_has_asyncify, I: _emscripten_resize_heap, T: _emscripten_sleep, M: _environ_get, N: _environ_sizes_get, V: _exit, x: _fd_close, O: _fd_read, L: _fd_seek, u: _fd_write, f: invoke_ii, c: invoke_iii, l: invoke_iiii, m: invoke_iiiii, W: invoke_iiiiii, q: invoke_iiiiiiiii, z: invoke_iiiiiiiiii, ca: invoke_iiiiiiiiiii, ea: invoke_iiiiiiiiiiii, da: invoke_iiiijj, A: invoke_ji, r: invoke_jiji, d: invoke_vi, g: invoke_vii, h: invoke_viii, b: invoke_viiii, k: invoke_viiiii, o: invoke_viiiiiii, ba: invoke_viiiiiiii, F: invoke_viiiiiiiii, aa: invoke_viiiiiiiiiii };
3733
3738
  function invoke_viiiiiiiii(index, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
3734
3739
  var sp = stackSave();
3735
3740
  try {
@@ -10,7 +10,7 @@ export type OptimizeParams = {
10
10
  width?: number;
11
11
  height?: number;
12
12
  quality?: number;
13
- format?: "jpeg" | "png" | "webp" | "avif" | "none";
13
+ format?: "jpeg" | "png" | "webp" | "avif" | "thumbhash" | "raw" | "none";
14
14
  speed?: number;
15
15
  filter?: boolean;
16
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["export type OptimizeResult = {\n data: Uint8Array;\n originalWidth: number;\n originalHeight: number;\n width: number;\n height: number;\n};\n\nexport type OptimizeParams = {\n image: BufferSource | Buffer | string; // The input image data\n width?: number; // The desired output width (optional)\n height?: number; // The desired output height (optional)\n quality?: number; // The desired output quality (0-100, optional)\n format?: \"jpeg\" | \"png\" | \"webp\" | \"avif\" | \"none\"; // The desired output format (optional)\n speed?: number; // The desired speed (0-10, Slow-Fast, Optional)\n filter?: boolean; // resize filter (default true)\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"","sourcesContent":["export type OptimizeResult = {\n data: Uint8Array;\n originalWidth: number;\n originalHeight: number;\n width: number;\n height: number;\n};\n\nexport type OptimizeParams = {\n image: BufferSource | Buffer | string; // The input image data\n width?: number; // The desired output width (optional)\n height?: number; // The desired output height (optional)\n quality?: number; // The desired output quality (0-100, optional)\n format?: \"jpeg\" | \"png\" | \"webp\" | \"avif\" | \"thumbhash\" | \"raw\" | \"none\"; // The desired output format (optional)\n speed?: number; // The desired speed (0-10, Slow-Fast, Optional)\n filter?: boolean; // resize filter (default true)\n};\n"]}