@squoosh-kit/resize 0.0.11 → 0.0.12

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.
@@ -1,4 +1,3 @@
1
- import{createRequire as V}from"node:module";var Y=Object.create;var{getPrototypeOf:Z,defineProperty:x,getOwnPropertyNames:d}=Object;var s=Object.prototype.hasOwnProperty;var F=(b,f,n)=>{n=b!=null?Y(Z(b)):{};let e=f||!b||!b.__esModule?x(n,"default",{value:b,enumerable:!0}):n;for(let w of d(b))if(!s.call(e,w))x(e,w,{get:()=>b[w],enumerable:!0});return e};var h=V(import.meta.url);async function N(b){try{if(typeof process<"u"&&process.versions?.node){let f=await import("fs/promises"),e=new URL(b,import.meta.url).pathname,w=await f.readFile(e);return w.buffer.slice(w.byteOffset,w.byteOffset+w.byteLength)}}catch(f){}try{let f=new URL(b,import.meta.url),n=await fetch(f);if(!n.ok)throw Error(`Failed to fetch WASM binary: ${n.status} ${n.statusText}`);return n.arrayBuffer()}catch(f){throw Error(`Failed to load WASM binary from "${b}": ${f instanceof Error?f.message:String(f)}`)}}function _(b){if(b instanceof SharedArrayBuffer)throw Error("SharedArrayBuffer is not supported. Use regular ArrayBuffer or Uint8Array instead.");if(!(b instanceof ArrayBuffer))throw TypeError("image.data.buffer must be an ArrayBuffer")}function g(b){if(!b||typeof b!=="object")throw TypeError("image must be an object");let f=b;if(!("data"in f))throw TypeError("image.data is required");let{data:n}=f;if(!(n instanceof Uint8Array||n instanceof Uint8ClampedArray))throw TypeError("image.data must be Uint8Array or Uint8ClampedArray");if(!("width"in f)||!("height"in f))throw TypeError("image.width and image.height are required");let{width:e,height:w}=f;if(typeof e!=="number"||!Number.isInteger(e)||e<=0)throw RangeError(`image.width must be a positive integer, got ${e}`);if(typeof w!=="number"||!Number.isInteger(w)||w<=0)throw RangeError(`image.height must be a positive integer, got ${w}`);let y=e*w*4;if(n.length<y)throw RangeError(`image.data too small: ${n.length} bytes, expected at least ${y} bytes for ${e}x${w} RGBA image`)}function L(b){if(typeof b!=="object"||b===null)throw TypeError("options must be an object");let f=b;if(f.width!==void 0){if(typeof f.width!=="number"||!Number.isInteger(f.width)||f.width<=0)throw RangeError(`options.width must be a positive integer, got ${f.width}`)}if(f.height!==void 0){if(typeof f.height!=="number"||!Number.isInteger(f.height)||f.height<=0)throw RangeError(`options.height must be a positive integer, got ${f.height}`)}if(f.method!==void 0){let n=["triangular","catrom","mitchell","lanczos3"];if(!n.includes(f.method))throw TypeError(`options.method must be one of: ${n.join(", ")}, got ${f.method}`)}if(f.premultiply!==void 0&&typeof f.premultiply!=="boolean")throw TypeError(`options.premultiply must be boolean, got ${typeof f.premultiply}`);if(f.linearRGB!==void 0&&typeof f.linearRGB!=="boolean")throw TypeError(`options.linearRGB must be boolean, got ${typeof f.linearRGB}`)}var E,q=null;function c(){if(q===null||q.buffer!==E.memory.buffer)q=new Uint8Array(E.memory.buffer);return q}var D=0;function z(b,f){let n=f(b.length*1);return c().set(b,n/1),D=b.length,n}var R=null;function I(){if(R===null||R.buffer!==E.memory.buffer)R=new Int32Array(E.memory.buffer);return R}var A=null;function v(){if(A===null||A.buffer!==E.memory.buffer)A=new Uint8ClampedArray(E.memory.buffer);return A}function U(b,f){return v().subarray(b/1,b/1+f)}function J(b,f,n,e,w,y,$,j){try{let T=E.__wbindgen_add_to_stack_pointer(-16);var k=z(b,E.__wbindgen_malloc),S=D;E.resize(T,k,S,f,n,e,w,y,$,j);var r=I()[T/4+0],l=I()[T/4+1],X=U(r,l).slice();return E.__wbindgen_free(r,l*1),X}finally{E.__wbindgen_add_to_stack_pointer(16)}}async function C(b,f){if(typeof Response==="function"&&b instanceof Response){if(typeof WebAssembly.instantiateStreaming==="function")try{return await WebAssembly.instantiateStreaming(b,f)}catch(e){if(b.headers.get("Content-Type")!="application/wasm")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);else throw e}let n=await b.arrayBuffer();return await WebAssembly.instantiate(n,f)}else{let n=await WebAssembly.instantiate(b,f);if(n instanceof WebAssembly.Instance)return{instance:n,module:b};else return n}}async function K(b){if(typeof b>"u")b=new URL("squoosh_resize_bg.wasm",import.meta.url);let f={};if(typeof b==="string"||typeof Request==="function"&&b instanceof Request||typeof URL==="function"&&b instanceof URL)b=fetch(b);let{instance:n,module:e}=await C(await b,f);return E=n.exports,K.__wbindgen_wasm_module=e,E}var O=K;var G=null,B=null;async function H(){if(G)return;if(B)return B;return B=(async()=>{try{let b=null,f=[new URL("./wasm/squoosh_resize_bg.wasm",import.meta.url).href,new URL("../wasm/squoosh_resize_bg.wasm",import.meta.url).href],n=null;for(let e of f)try{b=await N(e);break}catch(w){n=w instanceof Error?w:Error(String(w))}if(!b)throw n||Error("Could not load WASM binary from any path");await O(b),G=J}catch(b){throw B=null,Error(`Failed to initialize resize WASM module: ${b instanceof Error?b.message:String(b)}`)}})(),B}async function Q(b,f){if(g(b),L(f),await H(),!G)throw Error("Resize module not initialized");let{data:n,width:e,height:w}=b,y=f.width??e,$=f.height??w;if(f.width&&!f.height)$=Math.max(1,Math.round(w*f.width/e));else if(f.height&&!f.width)y=Math.max(1,Math.round(e*f.height/w));if(y<1||$<1)throw RangeError(`Output dimensions must be at least 1x1, got ${y}x${$}`);let j=n instanceof Uint8ClampedArray?new Uint8Array(n.buffer,n.byteOffset,n.length):new Uint8Array(n.buffer,n.byteOffset,n.length);return{data:G(j,e,w,y,$,W(f),f.premultiply??!0,f.linearRGB??!0),width:y,height:$}}async function m(b,f,n){if(n?.aborted)throw new DOMException("Aborted","AbortError");return Q(b,f)}function W(b){return{triangular:0,catrom:1,mitchell:2,lanczos3:3}[b?.method??"mitchell"]??2}if(typeof self<"u")self.onmessage=async(b)=>{let f=b.data;if(f?.type==="worker:ping"){self.postMessage({type:"worker:ready"});return}let{id:n,type:e,payload:w}=f,y={id:n,ok:!1};try{if(e!=="resize:run")throw Error(`Unknown message type: ${e}`);let $=await Q(w.image,w.options);y.ok=!0,y.data=$;let j=$.data.buffer;if(j)self.postMessage(y,[j]);else self.postMessage(y)}catch($){y.error=$ instanceof Error?$.message:String($),self.postMessage(y)}};export{m as resizeClient};
2
- export{_ as b,g as c,m as d};
1
+ import{b as W,c as b,e as H,f as I}from"./chunk-z14a3d02.js";async function B(j){try{if(typeof process<"u"&&process.versions?.node){let D=await import("fs/promises"),J=new URL(j,import.meta.url).pathname,K=await D.readFile(J);return K.buffer.slice(K.byteOffset,K.byteOffset+K.byteLength)}}catch(D){}try{let D=new URL(j,import.meta.url),G=await fetch(D);if(!G.ok)throw Error(`Failed to fetch WASM binary: ${G.status} ${G.statusText}`);return await G.arrayBuffer()}catch(D){throw Error(`Failed to load WASM binary from "${j}": ${D instanceof Error?D.message:String(D)}`)}}var Y,F=null;function v(){if(F===null||F.buffer!==Y.memory.buffer)F=new Uint8Array(Y.memory.buffer);return F}var A=0;function M(j,D){let G=D(j.length*1);return v().set(j,G/1),A=j.length,G}var k=null;function T(){if(k===null||k.buffer!==Y.memory.buffer)k=new Int32Array(Y.memory.buffer);return k}var q=null;function P(){if(q===null||q.buffer!==Y.memory.buffer)q=new Uint8ClampedArray(Y.memory.buffer);return q}function f(j,D){return P().subarray(j/1,j/1+D)}function R(j,D,G,J,K,Q,X,Z){try{let V=Y.__wbindgen_add_to_stack_pointer(-16);var L=M(j,Y.__wbindgen_malloc),E=A;Y.resize(V,L,E,D,G,J,K,Q,X,Z);var O=T()[V/4+0],S=T()[V/4+1],U=f(O,S).slice();return Y.__wbindgen_free(O,S*1),U}finally{Y.__wbindgen_add_to_stack_pointer(16)}}async function w(j,D){if(typeof Response==="function"&&j instanceof Response){if(typeof WebAssembly.instantiateStreaming==="function")try{return await WebAssembly.instantiateStreaming(j,D)}catch(J){if(j.headers.get("Content-Type")!="application/wasm")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",J);else throw J}let G=await j.arrayBuffer();return await WebAssembly.instantiate(G,D)}else{let G=await WebAssembly.instantiate(j,D);if(G instanceof WebAssembly.Instance)return{instance:G,module:j};else return G}}async function z(j){if(typeof j>"u")j=new URL("squoosh_resize_bg.wasm",import.meta.url);let D={};if(typeof j==="string"||typeof Request==="function"&&j instanceof Request||typeof URL==="function"&&j instanceof URL)j=fetch(j);let{instance:G,module:J}=await w(await j,D);return Y=G.exports,z.__wbindgen_wasm_module=J,Y}var x=z;var N=null,$=null;async function c(){if(N)return;if($)return $;return $=(async()=>{try{let j=null,D=[new URL("./wasm/squoosh_resize_bg.wasm",import.meta.url).href,new URL("../wasm/squoosh_resize_bg.wasm",import.meta.url).href],G=null;for(let J of D)try{j=await B(J);break}catch(K){G=K instanceof Error?K:Error(String(K))}if(!j)throw G||Error("Could not load WASM binary from any path");try{await x(j)}catch(J){if(J instanceof Error&&(J.message.includes("SharedArrayBuffer")||J.message.includes("first argument must be"))){if(typeof SharedArrayBuffer>"u")globalThis.SharedArrayBuffer=ArrayBuffer;try{await x(j)}catch(K){throw Error(`WASM module initialization failed even with polyfill: ${K instanceof Error?K.message:String(K)}`)}}else throw J}N=R}catch(j){throw $=null,Error(`Failed to initialize resize WASM module: ${j instanceof Error?j.message:String(j)}`)}})(),$}async function C(j,D){if(H(j),I(D),await c(),!N)throw Error("Resize module not initialized");let{data:G,width:J,height:K}=j,Q=D.width??J,X=D.height??K;if(D.width&&!D.height)X=Math.max(1,Math.round(K*D.width/J));else if(D.height&&!D.width)Q=Math.max(1,Math.round(J*D.height/K));if(Q<1||X<1)throw RangeError(`Output dimensions must be at least 1x1, got ${Q}x${X}`);let Z=G instanceof Uint8ClampedArray?new Uint8Array(G.buffer,G.byteOffset,G.length):new Uint8Array(G.buffer,G.byteOffset,G.length);return{data:N(Z,J,K,Q,X,y(D),D.premultiply??!0,D.linearRGB??!0),width:Q,height:X}}async function h(j,D,G){if(G?.aborted)throw new DOMException("Aborted","AbortError");return C(j,D)}function y(j){return{triangular:0,catrom:1,mitchell:2,lanczos3:3}[j?.method??"lanczos3"]??3}if(typeof self<"u")self.onmessage=async(j)=>{let D=j.data;if(D?.type==="worker:ping"){self.postMessage({type:"worker:ready"});return}let{id:G,type:J,payload:K}=D,Q={id:G,ok:!1};try{if(J!=="resize:run")throw Error(`Unknown message type: ${J}`);let X=await C(K.image,K.options);Q.ok=!0,Q.data=X;let Z=X.data.buffer;if(Z)self.postMessage(Q,[Z]);else self.postMessage(Q)}catch(X){Q.error=X instanceof Error?X.message:String(X),self.postMessage(Q)}};export{h as resizeClient};
3
2
 
4
- //# debugId=1086000BA6D2CFA164756E2164756E21
3
+ //# debugId=1EF3D28815B4A64864756E2164756E21
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../runtime/src/wasm-loader.ts", "../../runtime/src/validators.ts", "../wasm/squoosh_resize.js", "../src/resize.worker.ts"],
3
+ "sources": ["../../runtime/src/wasm-loader.ts", "../wasm/squoosh_resize.js", "../src/resize.worker.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Load WASM binary from various sources with fallback strategies\n *\n * Supports:\n * - Node.js (fs/promises)\n * - Browsers (fetch)\n * - Workers (fetch)\n */\nexport async function loadWasmBinary(\n relativePath: string\n): Promise<ArrayBuffer> {\n try {\n // Strategy 1: Try Node.js fs first (most reliable)\n if (typeof process !== 'undefined' && process.versions?.node) {\n const fsModule = await import(/* @vite-ignore */ 'fs/promises');\n const fileUrl = new URL(relativePath, import.meta.url);\n const filePath = fileUrl.pathname;\n const buffer = await fsModule.readFile(filePath);\n return buffer.buffer.slice(\n buffer.byteOffset,\n buffer.byteOffset + buffer.byteLength\n );\n }\n } catch (e) {\n // Fall through to fetch strategy\n }\n\n // Strategy 2: Fallback to fetch (works in browsers and workers)\n try {\n const url = new URL(/* @vite-ignore */ relativePath, import.meta.url);\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch WASM binary: ${response.status} ${response.statusText}`\n );\n }\n return response.arrayBuffer();\n } catch (error) {\n throw new Error(\n `Failed to load WASM binary from \"${relativePath}\": ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Load WASM JavaScript module with fallback strategies\n *\n * Strategy 1: Static relative import (works everywhere)\n * Strategy 2: import.meta.resolve (Node.js 22+)\n * Strategy 3: URL-based import (browsers/workers)\n */\nexport async function loadWasmModule(\n modulePath: string\n): Promise<WebAssembly.Module> {\n // Strategy 1: Try direct static import\n try {\n return await import(/* @vite-ignore */ modulePath);\n } catch (e1) {\n // Continue to next strategy\n }\n\n // Strategy 2: Try import.meta.resolve (Node.js 22+)\n try {\n const resolvedPath = await import.meta.resolve(modulePath);\n return await import(/* @vite-ignore */ resolvedPath);\n } catch (e2) {\n // Continue to next strategy\n }\n\n // Strategy 3: Try URL-based import\n try {\n const url = new URL(/* @vite-ignore */ modulePath, import.meta.url);\n return await import(/* @vite-ignore */ url.href);\n } catch (e3) {\n throw new Error(\n `Failed to load WASM module from \"${modulePath}\". ` +\n `Ensure WASM files are in the expected location and the module can be resolved.`\n );\n }\n}\n",
6
- "import type { ImageInput } from './types.js';\n\nexport function validateArrayBuffer(\n buffer: unknown\n): asserts buffer is ArrayBuffer {\n if (buffer instanceof SharedArrayBuffer) {\n throw new Error(\n 'SharedArrayBuffer is not supported. ' +\n 'Use regular ArrayBuffer or Uint8Array instead.'\n );\n }\n\n if (!(buffer instanceof ArrayBuffer)) {\n throw new TypeError('image.data.buffer must be an ArrayBuffer');\n }\n}\n\nexport function validateImageInput(\n image: unknown\n): asserts image is ImageInput {\n if (!image || typeof image !== 'object') {\n throw new TypeError('image must be an object');\n }\n\n const imageObj = image as Record<string, unknown>;\n\n if (!('data' in imageObj)) {\n throw new TypeError('image.data is required');\n }\n\n const { data } = imageObj;\n if (!(data instanceof Uint8Array || data instanceof Uint8ClampedArray)) {\n throw new TypeError('image.data must be Uint8Array or Uint8ClampedArray');\n }\n\n if (!('width' in imageObj) || !('height' in imageObj)) {\n throw new TypeError('image.width and image.height are required');\n }\n\n const { width, height } = imageObj;\n\n if (typeof width !== 'number' || !Number.isInteger(width) || width <= 0) {\n throw new RangeError(\n `image.width must be a positive integer, got ${width}`\n );\n }\n\n if (typeof height !== 'number' || !Number.isInteger(height) || height <= 0) {\n throw new RangeError(\n `image.height must be a positive integer, got ${height}`\n );\n }\n\n const expectedSize = width * height * 4;\n if (data.length < expectedSize) {\n throw new RangeError(\n `image.data too small: ${data.length} bytes, expected at least ${expectedSize} bytes for ${width}x${height} RGBA image`\n );\n }\n}\n\nexport function validateResizeOptions(options: unknown): asserts options is {\n width?: number;\n height?: number;\n method?: 'triangular' | 'catrom' | 'mitchell' | 'lanczos3';\n premultiply?: boolean;\n linearRGB?: boolean;\n} {\n if (typeof options !== 'object' || options === null) {\n throw new TypeError('options must be an object');\n }\n\n const opts = options as Record<string, unknown>;\n\n if (opts.width !== undefined) {\n if (\n typeof opts.width !== 'number' ||\n !Number.isInteger(opts.width) ||\n opts.width <= 0\n ) {\n throw new RangeError(\n `options.width must be a positive integer, got ${opts.width}`\n );\n }\n }\n\n if (opts.height !== undefined) {\n if (\n typeof opts.height !== 'number' ||\n !Number.isInteger(opts.height) ||\n opts.height <= 0\n ) {\n throw new RangeError(\n `options.height must be a positive integer, got ${opts.height}`\n );\n }\n }\n\n if (opts.method !== undefined) {\n const validMethods = ['triangular', 'catrom', 'mitchell', 'lanczos3'];\n if (!validMethods.includes(opts.method as string)) {\n throw new TypeError(\n `options.method must be one of: ${validMethods.join(', ')}, got ${opts.method}`\n );\n }\n }\n\n if (opts.premultiply !== undefined && typeof opts.premultiply !== 'boolean') {\n throw new TypeError(\n `options.premultiply must be boolean, got ${typeof opts.premultiply}`\n );\n }\n\n if (opts.linearRGB !== undefined && typeof opts.linearRGB !== 'boolean') {\n throw new TypeError(\n `options.linearRGB must be boolean, got ${typeof opts.linearRGB}`\n );\n }\n}\n\nexport function validateWebpOptions(options: unknown): asserts options is {\n quality?: number;\n lossless?: boolean;\n nearLossless?: boolean;\n} {\n if (\n options !== undefined &&\n (typeof options !== 'object' || options === null)\n ) {\n throw new TypeError('options must be an object or undefined');\n }\n\n if (options === undefined) {\n return;\n }\n\n const opts = options as Record<string, unknown>;\n\n if (opts.quality !== undefined) {\n if (\n typeof opts.quality !== 'number' ||\n !Number.isInteger(opts.quality) ||\n opts.quality < 0 ||\n opts.quality > 100\n ) {\n throw new RangeError(\n `options.quality must be an integer between 0 and 100, got ${opts.quality}`\n );\n }\n }\n\n if (opts.lossless !== undefined && typeof opts.lossless !== 'boolean') {\n throw new TypeError(\n `options.lossless must be boolean, got ${typeof opts.lossless}`\n );\n }\n\n if (\n opts.nearLossless !== undefined &&\n typeof opts.nearLossless !== 'boolean'\n ) {\n throw new TypeError(\n `options.nearLossless must be boolean, got ${typeof opts.nearLossless}`\n );\n }\n}\n",
5
+ "/**\n * Load WASM binary from various sources with fallback strategies\n *\n * Supports:\n * - Node.js (fs/promises)\n * - Browsers (fetch)\n * - Workers (fetch)\n */\nexport async function loadWasmBinary(\n relativePath: string\n): Promise<ArrayBuffer> {\n try {\n // Strategy 1: Try Node.js fs first (most reliable)\n if (typeof process !== 'undefined' && process.versions?.node) {\n const fsModule = await import(/* @vite-ignore */ 'fs/promises');\n const fileUrl = new URL(relativePath, import.meta.url);\n const filePath = fileUrl.pathname;\n const buffer = await fsModule.readFile(filePath);\n return buffer.buffer.slice(\n buffer.byteOffset,\n buffer.byteOffset + buffer.byteLength\n );\n }\n } catch (e) {\n // Fall through to fetch strategy\n }\n\n // Strategy 2: Fallback to fetch (works in browsers and workers)\n try {\n const url = new URL(/* @vite-ignore */ relativePath, import.meta.url);\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(\n `Failed to fetch WASM binary: ${response.status} ${response.statusText}`\n );\n }\n return await response.arrayBuffer();\n } catch (error) {\n throw new Error(\n `Failed to load WASM binary from \"${relativePath}\": ${error instanceof Error ? error.message : String(error)}`\n );\n }\n}\n\n/**\n * Load WASM JavaScript module with fallback strategies\n *\n * Strategy 1: Static relative import (works everywhere)\n * Strategy 2: import.meta.resolve (Node.js 22+)\n * Strategy 3: URL-based import (browsers/workers)\n */\nexport async function loadWasmModule(\n modulePath: string\n): Promise<WebAssembly.Module> {\n // Strategy 1: Try direct static import\n try {\n return await import(/* @vite-ignore */ modulePath);\n } catch (e1) {\n // Continue to next strategy\n }\n\n // Strategy 2: Try import.meta.resolve (Node.js 22+)\n try {\n const resolvedPath = await import.meta.resolve(modulePath);\n return await import(/* @vite-ignore */ resolvedPath);\n } catch (e2) {\n // Continue to next strategy\n }\n\n // Strategy 3: Try URL-based import\n try {\n const url = new URL(/* @vite-ignore */ modulePath, import.meta.url);\n return await import(/* @vite-ignore */ url.href);\n } catch (e3) {\n throw new Error(\n `Failed to load WASM module from \"${modulePath}\". ` +\n `Ensure WASM files are in the expected location and the module can be resolved.`\n );\n }\n}\n",
7
6
  "\nlet wasm;\n\nlet cachegetUint8Memory0 = null;\nfunction getUint8Memory0() {\n if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {\n cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachegetUint8Memory0;\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nfunction passArray8ToWasm0(arg, malloc) {\n const ptr = malloc(arg.length * 1);\n getUint8Memory0().set(arg, ptr / 1);\n WASM_VECTOR_LEN = arg.length;\n return ptr;\n}\n\nlet cachegetInt32Memory0 = null;\nfunction getInt32Memory0() {\n if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {\n cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);\n }\n return cachegetInt32Memory0;\n}\n\nlet cachegetUint8ClampedMemory0 = null;\nfunction getUint8ClampedMemory0() {\n if (cachegetUint8ClampedMemory0 === null || cachegetUint8ClampedMemory0.buffer !== wasm.memory.buffer) {\n cachegetUint8ClampedMemory0 = new Uint8ClampedArray(wasm.memory.buffer);\n }\n return cachegetUint8ClampedMemory0;\n}\n\nfunction getClampedArrayU8FromWasm0(ptr, len) {\n return getUint8ClampedMemory0().subarray(ptr / 1, ptr / 1 + len);\n}\n/**\n* @param {Uint8Array} input_image\n* @param {number} input_width\n* @param {number} input_height\n* @param {number} output_width\n* @param {number} output_height\n* @param {number} typ_idx\n* @param {boolean} premultiply\n* @param {boolean} color_space_conversion\n* @returns {Uint8ClampedArray}\n*/\nexport function resize(input_image, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion) {\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n var ptr0 = passArray8ToWasm0(input_image, wasm.__wbindgen_malloc);\n var len0 = WASM_VECTOR_LEN;\n wasm.resize(retptr, ptr0, len0, input_width, input_height, output_width, output_height, typ_idx, premultiply, color_space_conversion);\n var r0 = getInt32Memory0()[retptr / 4 + 0];\n var r1 = getInt32Memory0()[retptr / 4 + 1];\n var v1 = getClampedArrayU8FromWasm0(r0, r1).slice();\n wasm.__wbindgen_free(r0, r1 * 1);\n return v1;\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n }\n}\n\nasync function load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n\n } catch (e) {\n if (module.headers.get('Content-Type') != 'application/wasm') {\n 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);\n\n } else {\n throw e;\n }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n\n } else {\n return instance;\n }\n }\n}\n\nasync function init(input) {\n if (typeof input === 'undefined') {\n input = new URL('squoosh_resize_bg.wasm', import.meta.url);\n }\n const imports = {};\n\n\n if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {\n input = fetch(input);\n }\n\n\n\n const { instance, module } = await load(await input, imports);\n\n wasm = instance.exports;\n init.__wbindgen_wasm_module = module;\n\n return wasm;\n}\n\nexport default init;\n\n",
8
- "/**\n * Resize processor - single-source worker/client implementation\n */\n\nimport {\n type WorkerRequest,\n type WorkerResponse,\n type ImageInput,\n loadWasmBinary,\n validateImageInput,\n validateResizeOptions,\n} from '@squoosh-kit/runtime';\nimport type { ResizeOptions } from './types';\nimport * as squoosh_resize_module from '../wasm/squoosh_resize';\n\n// Define the type locally to avoid module resolution issues with the linter\ntype SquooshWasmResize = (\n input_image: Uint8Array,\n input_width: number,\n input_height: number,\n output_width: number,\n output_height: number,\n typ_idx: number,\n premultiply: boolean,\n color_space_conversion: boolean\n) => Uint8ClampedArray;\n\nlet wasmResize: SquooshWasmResize | null = null;\nlet initPromise: Promise<void> | null = null;\n\nasync function init(): Promise<void> {\n if (wasmResize) {\n return;\n }\n\n if (initPromise) {\n return initPromise;\n }\n\n initPromise = (async () => {\n try {\n // Load WASM binary with robust fallback strategies\n // Try multiple paths to support both development (../wasm) and npm installed (./wasm) scenarios\n let wasmBuffer: ArrayBuffer | null = null;\n const pathsToTry = [\n new URL(\n /* @vite-ignore */ './wasm/squoosh_resize_bg.wasm',\n import.meta.url\n ).href,\n new URL(\n /* @vite-ignore */ '../wasm/squoosh_resize_bg.wasm',\n import.meta.url\n ).href,\n ];\n\n let lastError: Error | null = null;\n for (const path of pathsToTry) {\n try {\n wasmBuffer = await loadWasmBinary(path);\n break;\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next path\n }\n }\n\n if (!wasmBuffer) {\n throw (\n lastError || new Error('Could not load WASM binary from any path')\n );\n }\n\n // Initialize WASM module with the binary buffer\n await squoosh_resize_module.default(wasmBuffer);\n // After initialization, the module's exported resize function is ready to use\n wasmResize = squoosh_resize_module.resize as unknown as SquooshWasmResize;\n } catch (error) {\n initPromise = null;\n throw new Error(\n `Failed to initialize resize WASM module: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n })();\n\n return initPromise;\n}\n\nasync function _resizeCore(\n image: ImageInput,\n options: ResizeOptions\n): Promise<ImageInput> {\n validateImageInput(image);\n validateResizeOptions(options);\n\n await init();\n if (!wasmResize) {\n throw new Error('Resize module not initialized');\n }\n\n const { data, width: inputWidth, height: inputHeight } = image;\n\n let outputWidth = options.width ?? inputWidth;\n let outputHeight = options.height ?? inputHeight;\n\n if (options.width && !options.height) {\n outputHeight = Math.max(\n 1,\n Math.round((inputHeight * options.width) / inputWidth)\n );\n } else if (options.height && !options.width) {\n outputWidth = Math.max(\n 1,\n Math.round((inputWidth * options.height) / inputHeight)\n );\n }\n\n if (outputWidth < 1 || outputHeight < 1) {\n throw new RangeError(\n `Output dimensions must be at least 1x1, got ${outputWidth}x${outputHeight}`\n );\n }\n\n // Create a zero-copy Uint8Array view if needed\n // (don't copy the buffer - just create a view on the same memory)\n const dataArray =\n data instanceof Uint8ClampedArray\n ? new Uint8Array(data.buffer as ArrayBuffer, data.byteOffset, data.length)\n : new Uint8Array(\n data.buffer as ArrayBuffer,\n data.byteOffset,\n data.length\n );\n\n const result = wasmResize(\n dataArray,\n inputWidth,\n inputHeight,\n outputWidth,\n outputHeight,\n getResizeMethod(options),\n options.premultiply ?? true,\n options.linearRGB ?? true\n );\n\n return {\n data: result,\n width: outputWidth,\n height: outputHeight,\n };\n}\n\nexport async function resizeClient(\n image: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n if (signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n return _resizeCore(image, options);\n}\n\n/**\n * Map ResizeOptions method to WASM typ_idx parameter\n * typ_idx values (from Squoosh):\n * 0: Triangular - fastest, lowest quality\n * 1: Catrom - medium quality and speed\n * 2: Mitchell - good balance (default)\n * 3: Lanczos3 - highest quality, slowest\n */\nfunction getResizeMethod(options?: ResizeOptions): number {\n const methodMap: Record<string, number> = {\n triangular: 0,\n catrom: 1,\n mitchell: 2,\n lanczos3: 3,\n };\n return methodMap[options?.method ?? 'mitchell'] ?? 2;\n}\n\n/**\n * Worker message handler\n */\nif (typeof self !== 'undefined') {\n self.onmessage = async (event: MessageEvent) => {\n const data = event.data;\n\n // Handle worker ping for initialization\n if (data?.type === 'worker:ping') {\n self.postMessage({ type: 'worker:ready' });\n return;\n }\n\n const { id, type, payload } = data as WorkerRequest<{\n image: ImageInput;\n options: ResizeOptions;\n }>;\n\n const response: WorkerResponse<ImageInput> = { id, ok: false };\n\n try {\n if (type !== 'resize:run') {\n throw new Error(`Unknown message type: ${type}`);\n }\n\n const resultImage = await _resizeCore(payload.image, payload.options);\n\n response.ok = true;\n response.data = resultImage;\n\n const transferable = resultImage.data.buffer;\n if (transferable) {\n self.postMessage(response, [transferable as ArrayBuffer]);\n } else {\n self.postMessage(response);\n }\n } catch (error) {\n response.error = error instanceof Error ? error.message : String(error);\n self.postMessage(response);\n }\n };\n}\n"
7
+ "/**\n * Resize processor - single-source worker/client implementation\n */\n\nimport {\n type WorkerRequest,\n type WorkerResponse,\n type ImageInput,\n loadWasmBinary,\n validateImageInput,\n validateResizeOptions,\n} from '@squoosh-kit/runtime';\nimport type { ResizeOptions } from './types';\nimport * as squoosh_resize_module from '../wasm/squoosh_resize';\n\n// Define the type locally to avoid module resolution issues with the linter\ntype SquooshWasmResize = (\n input_image: Uint8Array,\n input_width: number,\n input_height: number,\n output_width: number,\n output_height: number,\n typ_idx: number,\n premultiply: boolean,\n color_space_conversion: boolean\n) => Uint8ClampedArray;\n\nlet wasmResize: SquooshWasmResize | null = null;\nlet initPromise: Promise<void> | null = null;\n\nasync function init(): Promise<void> {\n if (wasmResize) {\n return;\n }\n\n if (initPromise) {\n return initPromise;\n }\n\n initPromise = (async () => {\n try {\n // Load WASM binary with robust fallback strategies\n // Try multiple paths to support both development (../wasm) and npm installed (./wasm) scenarios\n let wasmBuffer: ArrayBuffer | null = null;\n const pathsToTry = [\n new URL(\n /* @vite-ignore */ './wasm/squoosh_resize_bg.wasm',\n import.meta.url\n ).href,\n new URL(\n /* @vite-ignore */ '../wasm/squoosh_resize_bg.wasm',\n import.meta.url\n ).href,\n ];\n\n let lastError: Error | null = null;\n for (const path of pathsToTry) {\n try {\n wasmBuffer = await loadWasmBinary(path);\n break;\n } catch (error) {\n lastError = error instanceof Error ? error : new Error(String(error));\n // Continue to next path\n }\n }\n\n if (!wasmBuffer) {\n throw (\n lastError || new Error('Could not load WASM binary from any path')\n );\n }\n\n // Initialize WASM module with the binary buffer\n try {\n await squoosh_resize_module.default(wasmBuffer);\n } catch (initError: unknown) {\n // If initialization fails due to SharedArrayBuffer issues, try with polyfill\n if (\n initError instanceof Error &&\n (initError.message.includes('SharedArrayBuffer') ||\n initError.message.includes('first argument must be'))\n ) {\n // Apply polyfill and retry\n if (typeof SharedArrayBuffer === 'undefined') {\n (\n globalThis as unknown as Record<string, typeof ArrayBuffer>\n ).SharedArrayBuffer = ArrayBuffer;\n }\n // Reload the module with polyfill in place\n try {\n await squoosh_resize_module.default(wasmBuffer);\n } catch (retryError) {\n throw new Error(\n `WASM module initialization failed even with polyfill: ${retryError instanceof Error ? retryError.message : String(retryError)}`\n );\n }\n } else {\n throw initError;\n }\n }\n // After initialization, the module's exported resize function is ready to use\n wasmResize = squoosh_resize_module.resize as unknown as SquooshWasmResize;\n } catch (error) {\n initPromise = null;\n throw new Error(\n `Failed to initialize resize WASM module: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n })();\n\n return initPromise;\n}\n\nasync function _resizeCore(\n image: ImageInput,\n options: ResizeOptions\n): Promise<ImageInput> {\n validateImageInput(image);\n validateResizeOptions(options);\n\n await init();\n if (!wasmResize) {\n throw new Error('Resize module not initialized');\n }\n\n const { data, width: inputWidth, height: inputHeight } = image;\n\n let outputWidth = options.width ?? inputWidth;\n let outputHeight = options.height ?? inputHeight;\n\n if (options.width && !options.height) {\n outputHeight = Math.max(\n 1,\n Math.round((inputHeight * options.width) / inputWidth)\n );\n } else if (options.height && !options.width) {\n outputWidth = Math.max(\n 1,\n Math.round((inputWidth * options.height) / inputHeight)\n );\n }\n\n if (outputWidth < 1 || outputHeight < 1) {\n throw new RangeError(\n `Output dimensions must be at least 1x1, got ${outputWidth}x${outputHeight}`\n );\n }\n\n // Create a zero-copy Uint8Array view if needed\n // (don't copy the buffer - just create a view on the same memory)\n const dataArray =\n data instanceof Uint8ClampedArray\n ? new Uint8Array(data.buffer as ArrayBuffer, data.byteOffset, data.length)\n : new Uint8Array(\n data.buffer as ArrayBuffer,\n data.byteOffset,\n data.length\n );\n\n const result = wasmResize(\n dataArray,\n inputWidth,\n inputHeight,\n outputWidth,\n outputHeight,\n getResizeMethod(options),\n options.premultiply ?? true,\n options.linearRGB ?? true\n );\n\n return {\n data: result,\n width: outputWidth,\n height: outputHeight,\n };\n}\n\nexport async function resizeClient(\n image: ImageInput,\n options: ResizeOptions,\n signal?: AbortSignal\n): Promise<ImageInput> {\n if (signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n return _resizeCore(image, options);\n}\n\n/**\n * Map ResizeOptions method to WASM typ_idx parameter\n * typ_idx values (from Squoosh):\n * 0: Triangular - fastest, lowest quality\n * 1: Catrom - medium quality and speed\n * 2: Mitchell - good balance (default)\n * 3: Lanczos3 - highest quality, slowest\n */\nfunction getResizeMethod(options?: ResizeOptions): number {\n const methodMap: Record<string, number> = {\n triangular: 0,\n catrom: 1,\n mitchell: 2,\n lanczos3: 3,\n };\n return methodMap[options?.method ?? 'lanczos3'] ?? 3;\n}\n\n/**\n * Worker message handler\n */\nif (typeof self !== 'undefined') {\n self.onmessage = async (event: MessageEvent) => {\n const data = event.data;\n\n // Handle worker ping for initialization\n if (data?.type === 'worker:ping') {\n self.postMessage({ type: 'worker:ready' });\n return;\n }\n\n const { id, type, payload } = data as WorkerRequest<{\n image: ImageInput;\n options: ResizeOptions;\n }>;\n\n const response: WorkerResponse<ImageInput> = { id, ok: false };\n\n try {\n if (type !== 'resize:run') {\n throw new Error(`Unknown message type: ${type}`);\n }\n\n const resultImage = await _resizeCore(payload.image, payload.options);\n\n response.ok = true;\n response.data = resultImage;\n\n const transferable = resultImage.data.buffer;\n if (transferable) {\n self.postMessage(response, [transferable as ArrayBuffer]);\n } else {\n self.postMessage(response);\n }\n } catch (error) {\n response.error = error instanceof Error ? error.message : String(error);\n self.postMessage(response);\n }\n };\n}\n"
9
8
  ],
10
- "mappings": "4XAQA,eAAsB,CAAc,CAClC,EACsB,CACtB,GAAI,CAEF,GAAI,OAAO,QAAY,KAAe,QAAQ,UAAU,KAAM,CAC5D,IAAM,EAAW,KAAgC,uBAE3C,EADU,IAAI,IAAI,EAAc,YAAY,GAAG,EAC5B,SACnB,EAAS,MAAM,EAAS,SAAS,CAAQ,EAC/C,OAAO,EAAO,OAAO,MACnB,EAAO,WACP,EAAO,WAAa,EAAO,UAC7B,GAEF,MAAO,EAAG,EAKZ,GAAI,CACF,IAAM,EAAM,IAAI,IAAuB,EAAc,YAAY,GAAG,EAC9D,EAAW,MAAM,MAAM,CAAG,EAChC,GAAI,CAAC,EAAS,GACZ,MAAU,MACR,gCAAgC,EAAS,UAAU,EAAS,YAC9D,EAEF,OAAO,EAAS,YAAY,EAC5B,MAAO,EAAO,CACd,MAAU,MACR,oCAAoC,OAAkB,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,GAC7G,GCtCG,SAAS,CAAmB,CACjC,EAC+B,CAC/B,GAAI,aAAkB,kBACpB,MAAU,MACR,oFAEF,EAGF,GAAI,EAAE,aAAkB,aACtB,MAAU,UAAU,0CAA0C,EAI3D,SAAS,CAAkB,CAChC,EAC6B,CAC7B,GAAI,CAAC,GAAS,OAAO,IAAU,SAC7B,MAAU,UAAU,yBAAyB,EAG/C,IAAM,EAAW,EAEjB,GAAI,EAAE,SAAU,GACd,MAAU,UAAU,wBAAwB,EAG9C,IAAQ,QAAS,EACjB,GAAI,EAAE,aAAgB,YA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,EACb,EACA,EACA,EACA,EACA,EACA,EAAgB,CAAO,EACvB,EAAQ,aAAe,GACvB,EAAQ,WAAa,EACvB,EAIE,MAAO,EACP,OAAQ,CACV,EAGF,eAAsB,CAAY,CAChC,EACA,EACA,EACqB,CACrB,GAAI,GAAQ,QACV,MAAM,IAAI,aAAa,UAAW,YAAY,EAEhD,OAAO,EAAY,EAAO,CAAO,EAWnC,SAAS,CAAe,CAAC,EAAiC,CAOxD,MAN0C,CACxC,WAAY,EACZ,OAAQ,EACR,SAAU,EACV,SAAU,CACZ,EACiB,GAAS,QAAU,aAAe,EAMrD,GAAI,OAAO,KAAS,IAClB,KAAK,UAAY,MAAO,IAAwB,CAC9C,IAAM,EAAO,EAAM,KAGnB,GAAI,GAAM,OAAS,cAAe,CAChC,KAAK,YAAY,CAAE,KAAM,cAAe,CAAC,EACzC,OAGF,IAAQ,KAAI,OAAM,WAAY,EAKxB,EAAuC,CAAE,KAAI,GAAI,EAAM,EAE7D,GAAI,CACF,GAAI,IAAS,aACX,MAAU,MAAM,yBAAyB,GAAM,EAGjD,IAAM,EAAc,MAAM,EAAY,EAAQ,MAAO,EAAQ,OAAO,EAEpE,EAAS,GAAK,GACd,EAAS,KAAO,EAEhB,IAAM,EAAe,EAAY,KAAK,OACtC,GAAI,EACF,KAAK,YAAY,EAAU,CAAC,CAA2B,CAAC,EAExD,UAAK,YAAY,CAAQ,EAE3B,MAAO,EAAO,CACd,EAAS,MAAQ,aAAiB,MAAQ,EAAM,QAAU,OAAO,CAAK,EACtE,KAAK,YAAY,CAAQ",
10
+ "debugId": "1EF3D28815B4A64864756E2164756E21",
12
11
  "names": []
13
12
  }
package/dist/types.d.ts CHANGED
@@ -1,50 +1,12 @@
1
- /**
2
- * Type definitions for the Resize package
3
- */
4
- /**
5
- * Options for resizing an image.
6
- * All WASM parameters are fully exposed through this interface.
7
- */
1
+ import { resize } from '../wasm/squoosh_resize';
2
+ export type ResizeModule = {
3
+ resize: typeof resize;
4
+ };
8
5
  export type ResizeOptions = {
9
- /**
10
- * Target width of the resized image.
11
- * If only width is specified, height is calculated to maintain aspect ratio.
12
- * If both are specified, image is resized to exact dimensions.
13
- * Must be a positive integer (>= 1). Aspect ratio calculations will always preserve
14
- * at least 1 pixel for the missing dimension.
15
- * @default original image width
16
- */
17
6
  width?: number;
18
- /**
19
- * Target height of the resized image.
20
- * If only height is specified, width is calculated to maintain aspect ratio.
21
- * If both are specified, image is resized to exact dimensions.
22
- * Must be a positive integer (>= 1). Aspect ratio calculations will always preserve
23
- * at least 1 pixel for the missing dimension.
24
- * @default original image height
25
- */
26
7
  height?: number;
27
- /**
28
- * Resize algorithm to use - controls quality vs speed trade-off.
29
- * Maps directly to Squoosh WASM typ_idx parameter (0-3).
30
- * @default 'mitchell' - provides sensible balance between quality and performance
31
- */
32
8
  method?: 'triangular' | 'catrom' | 'mitchell' | 'lanczos3';
33
- /**
34
- * Pre-multiply alpha channel before resizing.
35
- * When true, alpha is multiplied into RGB values before the resize operation,
36
- * which can improve the quality of images with transparency.
37
- * Maps directly to WASM premultiply parameter.
38
- * @default false
39
- */
40
9
  premultiply?: boolean;
41
- /**
42
- * Use linear RGB color space for resizing instead of sRGB.
43
- * When true, applies proper color space conversion for more mathematically
44
- * accurate resizing of colors.
45
- * Maps directly to WASM color_space_conversion parameter.
46
- * @default false
47
- */
48
10
  linearRGB?: boolean;
49
11
  };
50
12
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;IAC3D;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,OAAO,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;IAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC"}
@@ -1,3 +1,3 @@
1
- var j={};module.exports=b(j);
1
+ var o={};module.exports=e(o);
2
2
 
3
- //# debugId=3FCFBA1BE409B74F64756E2164756E21
3
+ //# debugId=0F2D1FDC545AF92A64756E2164756E21
@@ -4,6 +4,6 @@
4
4
  "sourcesContent": [
5
5
  ],
6
6
  "mappings": "",
7
- "debugId": "3FCFBA1BE409B74F64756E2164756E21",
7
+ "debugId": "0F2D1FDC545AF92A64756E2164756E21",
8
8
  "names": []
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squoosh-kit/resize",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "type": "module",
5
5
  "description": "Image resize module for squoosh-kit.",
6
6
  "author": "Bartosz Nowak <bnowak008@gmail.com>",
@@ -45,6 +45,6 @@
45
45
  "test": "bun test"
46
46
  },
47
47
  "dependencies": {
48
- "@squoosh-kit/runtime": "0.0.10"
48
+ "@squoosh-kit/runtime": "0.0.12"
49
49
  }
50
50
  }