let o;const a=new Array(128).fill(void 0);a.push(void 0,null,!0,!1);let d=a.length;function b(e){d===a.length&&a.push(a.length+1);const n=d;return d=a[n],a[n]=e,n}function y(e){return a[e]}function W(e){e<132||(a[e]=d,d=e)}function I(e){const n=y(e);return W(e),n}const m=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&m.decode();let f=null;function g(){return(f===null||f.byteLength===0)&&(f=new Uint8Array(o.memory.buffer)),f}function D(e,n){return e=e>>>0,m.decode(g().subarray(e,e+n))}let l=null;function T(){return(l===null||l.byteLength===0)&&(l=new Uint8ClampedArray(o.memory.buffer)),l}function M(e,n){return e=e>>>0,T().subarray(e/1,e/1+n)}let p=0;function R(e,n){const t=n(e.length*1,1)>>>0;return g().set(e,t/1),p=e.length,t}let u=null;function h(){return(u===null||u.byteLength===0)&&(u=new Int32Array(o.memory.buffer)),u}function E(e,n){return e=e>>>0,g().subarray(e/1,e/1+n)}function S(e,n,t,r){try{const w=o.__wbindgen_add_to_stack_pointer(-16),v=R(e,o.__wbindgen_malloc),U=p;o.encode(w,v,U,n,t,r);var i=h()[w/4+0],s=h()[w/4+1],c=E(i,s).slice();return o.__wbindgen_free(i,s*1,1),c}finally{o.__wbindgen_add_to_stack_pointer(16)}}async function k(e,n){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,n)}catch(r){if(e.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",r);else throw r}const t=await e.arrayBuffer();return await WebAssembly.instantiate(t,n)}else{const t=await WebAssembly.instantiate(e,n);return t instanceof WebAssembly.Instance?{instance:t,module:e}:t}}function C(){const e={};return e.wbg={},e.wbg.__wbindgen_memory=function(){const n=o.memory;return b(n)},e.wbg.__wbg_buffer_a448f833075b71ba=function(n){const t=y(n).buffer;return b(t)},e.wbg.__wbg_newwithbyteoffsetandlength_099217381c451830=function(n,t,r){const i=new Uint16Array(y(n),t>>>0,r>>>0);return b(i)},e.wbg.__wbindgen_object_drop_ref=function(n){I(n)},e.wbg.__wbg_newwithownedu8clampedarrayandsh_91db5987993a08fb=function(n,t,r,i){var s=M(n,t).slice();o.__wbindgen_free(n,t*1,1);const c=new ImageData(s,r>>>0,i>>>0);return b(c)},e.wbg.__wbindgen_throw=function(n,t){throw new Error(D(n,t))},e}function L(e,n){return o=e.exports,A.__wbindgen_wasm_module=n,u=null,f=null,l=null,o}async function A(e){if(o!==void 0)return o;typeof e>"u"&&(e=new URL("/assets/squoosh_png_bg-DAY7U9NW.wasm",import.meta.url));const n=C();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));const{instance:t,module:r}=await k(await e,n);return L(t,r)}const O=globalThis.ServiceWorkerGlobalScope!==void 0,j=O&&typeof self<"u"&&globalThis.caches&&globalThis.caches.default!==void 0,x=typeof process=="object"&&process.release&&process.release.name==="node";(j||x)&&(globalThis.ImageData||(globalThis.ImageData=class{constructor(n,t,r){this.data=n,this.width=t,this.height=r}}),import.meta.url===void 0&&(import.meta.url="https://localhost"),typeof self<"u"&&self.location===void 0&&(self.location={href:""}));let _;async function F(e){return _||(_=A(e)),_}async function q(e,n={}){var t;await F();const r=(t=n==null?void 0:n.bitDepth)!==null&&t!==void 0?t:8;if(r!==8&&r!==16)throw new Error("Invalid bit depth. Must be either 8 or 16.");const i=e.data instanceof Uint16Array;if(i&&r!==16)throw new Error("Invalid bit depth, must be 16 for Uint16Array or manually convert to RGB8 values with Uint8Array.");if(!i&&r===16)throw new Error("Invalid bit depth, must be 8 for Uint8Array or manually convert to RGB16 values with Uint16Array.");const s=new Uint8Array(e.data.buffer),c=await S(s,e.width,e.height,r);if(!c)throw new Error("Encoding error.");return c.buffer}export{q as encode};
