UNPKG

onnxruntime-web

Version:

A Javascript library for running ONNX models on browsers

13 lines 116 kB
/*! * ONNX Runtime Web v1.23.2 * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var Vr=Object.defineProperty;var Cu=Object.getOwnPropertyDescriptor;var Eu=Object.getOwnPropertyNames;var _u=Object.prototype.hasOwnProperty;var Hr=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(i,s)=>(typeof require<"u"?require:i)[s]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var F=(a,i)=>()=>(a&&(i=a(a=0)),i);var _t=(a,i)=>{for(var s in i)Vr(a,s,{get:i[s],enumerable:!0})},Su=(a,i,s,n)=>{if(i&&typeof i=="object"||typeof i=="function")for(let f of Eu(i))!_u.call(a,f)&&f!==s&&Vr(a,f,{get:()=>i[f],enumerable:!(n=Cu(i,f))||n.enumerable});return a};var Gt=a=>Su(Vr({},"__esModule",{value:!0}),a);var $t,et,tt,Au,ji,Yr=F(()=>{"use strict";$t=new Map,et=[],tt=(a,i,s)=>{if(i&&typeof i.init=="function"&&typeof i.createInferenceSessionHandler=="function"){let n=$t.get(a);if(n===void 0)$t.set(a,{backend:i,priority:s});else{if(n.priority>s)return;if(n.priority===s&&n.backend!==i)throw new Error(`cannot register backend "${a}" using priority ${s}`)}if(s>=0){let f=et.indexOf(a);f!==-1&&et.splice(f,1);for(let d=0;d<et.length;d++)if($t.get(et[d]).priority<=s){et.splice(d,0,a);return}et.push(a)}return}throw new TypeError("not a valid backend")},Au=async a=>{let i=$t.get(a);if(!i)return"backend not found.";if(i.initialized)return i.backend;if(i.aborted)return i.error;{let s=!!i.initPromise;try{return s||(i.initPromise=i.backend.init(a)),await i.initPromise,i.initialized=!0,i.backend}catch(n){return s||(i.error=`${n}`,i.aborted=!0),i.error}finally{delete i.initPromise}}},ji=async a=>{let i=a.executionProviders||[],s=i.map(h=>typeof h=="string"?h:h.name),n=s.length===0?et:s,f,d=[],p=new Set;for(let h of n){let g=await Au(h);typeof g=="string"?d.push({name:h,err:g}):(f||(f=g),f===g&&p.add(h))}if(!f)throw new Error(`no available backend found. ERR: ${d.map(h=>`[${h.name}] ${h.err}`).join(", ")}`);for(let{name:h,err:g}of d)s.includes(h)&&console.warn(`removing requested execution provider "${h}" from session options because it is not available: ${g}`);let c=i.filter(h=>p.has(typeof h=="string"?h:h.name));return[f,new Proxy(a,{get:(h,g)=>g==="executionProviders"?c:Reflect.get(h,g)})]}});var Gi=F(()=>{"use strict";Yr()});var $i,zi=F(()=>{"use strict";$i="1.23.2"});var Vi,se,qr=F(()=>{"use strict";zi();Vi="warning",se={wasm:{},webgl:{},webgpu:{},versions:{common:$i},set logLevel(a){if(a!==void 0){if(typeof a!="string"||["verbose","info","warning","error","fatal"].indexOf(a)===-1)throw new Error(`Unsupported logging level: ${a}`);Vi=a}},get logLevel(){return Vi}};Object.defineProperty(se,"logLevel",{enumerable:!0})});var X,Hi=F(()=>{"use strict";qr();X=se});var Yi,qi,Ji=F(()=>{"use strict";Yi=(a,i)=>{let s=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);s.width=a.dims[3],s.height=a.dims[2];let n=s.getContext("2d");if(n!=null){let f,d;i?.tensorLayout!==void 0&&i.tensorLayout==="NHWC"?(f=a.dims[2],d=a.dims[3]):(f=a.dims[3],d=a.dims[2]);let p=i?.format!==void 0?i.format:"RGB",c=i?.norm,h,g;c===void 0||c.mean===void 0?h=[255,255,255,255]:typeof c.mean=="number"?h=[c.mean,c.mean,c.mean,c.mean]:(h=[c.mean[0],c.mean[1],c.mean[2],0],c.mean[3]!==void 0&&(h[3]=c.mean[3])),c===void 0||c.bias===void 0?g=[0,0,0,0]:typeof c.bias=="number"?g=[c.bias,c.bias,c.bias,c.bias]:(g=[c.bias[0],c.bias[1],c.bias[2],0],c.bias[3]!==void 0&&(g[3]=c.bias[3]));let v=d*f,C=0,T=v,S=v*2,U=-1;p==="RGBA"?(C=0,T=v,S=v*2,U=v*3):p==="RGB"?(C=0,T=v,S=v*2):p==="RBG"&&(C=0,S=v,T=v*2);for(let D=0;D<d;D++)for(let R=0;R<f;R++){let M=(a.data[C++]-g[0])*h[0],L=(a.data[T++]-g[1])*h[1],j=(a.data[S++]-g[2])*h[2],P=U===-1?255:(a.data[U++]-g[3])*h[3];n.fillStyle="rgba("+M+","+L+","+j+","+P+")",n.fillRect(R,D,1,1)}if("toDataURL"in s)return s.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},qi=(a,i)=>{let s=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),n;if(s!=null){let f,d,p;i?.tensorLayout!==void 0&&i.tensorLayout==="NHWC"?(f=a.dims[2],d=a.dims[1],p=a.dims[3]):(f=a.dims[3],d=a.dims[2],p=a.dims[1]);let c=i!==void 0&&i.format!==void 0?i.format:"RGB",h=i?.norm,g,v;h===void 0||h.mean===void 0?g=[255,255,255,255]:typeof h.mean=="number"?g=[h.mean,h.mean,h.mean,h.mean]:(g=[h.mean[0],h.mean[1],h.mean[2],255],h.mean[3]!==void 0&&(g[3]=h.mean[3])),h===void 0||h.bias===void 0?v=[0,0,0,0]:typeof h.bias=="number"?v=[h.bias,h.bias,h.bias,h.bias]:(v=[h.bias[0],h.bias[1],h.bias[2],0],h.bias[3]!==void 0&&(v[3]=h.bias[3]));let C=d*f;if(i!==void 0&&(i.format!==void 0&&p===4&&i.format!=="RGBA"||p===3&&i.format!=="RGB"&&i.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let T=4,S=0,U=1,D=2,R=3,M=0,L=C,j=C*2,P=-1;c==="RGBA"?(M=0,L=C,j=C*2,P=C*3):c==="RGB"?(M=0,L=C,j=C*2):c==="RBG"&&(M=0,j=C,L=C*2),n=s.createImageData(f,d);for(let z=0;z<d*f;S+=T,U+=T,D+=T,R+=T,z++)n.data[S]=(a.data[M++]-v[0])*g[0],n.data[U]=(a.data[L++]-v[1])*g[1],n.data[D]=(a.data[j++]-v[2])*g[2],n.data[R]=P===-1?255:(a.data[P++]-v[3])*g[3]}else throw new Error("Can not access image data");return n}});var Jr,Xi,Zi,Qi,Ki,eo,to=F(()=>{"use strict";zt();Jr=(a,i)=>{if(a===void 0)throw new Error("Image buffer must be defined");if(i.height===void 0||i.width===void 0)throw new Error("Image height and width must be defined");if(i.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:s,width:n}=i,f=i.norm??{mean:255,bias:0},d,p;typeof f.mean=="number"?d=[f.mean,f.mean,f.mean,f.mean]:d=[f.mean[0],f.mean[1],f.mean[2],f.mean[3]??255],typeof f.bias=="number"?p=[f.bias,f.bias,f.bias,f.bias]:p=[f.bias[0],f.bias[1],f.bias[2],f.bias[3]??0];let c=i.format!==void 0?i.format:"RGBA",h=i.tensorFormat!==void 0&&i.tensorFormat!==void 0?i.tensorFormat:"RGB",g=s*n,v=h==="RGBA"?new Float32Array(g*4):new Float32Array(g*3),C=4,T=0,S=1,U=2,D=3,R=0,M=g,L=g*2,j=-1;c==="RGB"&&(C=3,T=0,S=1,U=2,D=-1),h==="RGBA"?j=g*3:h==="RBG"?(R=0,L=g,M=g*2):h==="BGR"&&(L=0,M=g,R=g*2);for(let z=0;z<g;z++,T+=C,U+=C,S+=C,D+=C)v[R++]=(a[T]+p[0])/d[0],v[M++]=(a[S]+p[1])/d[1],v[L++]=(a[U]+p[2])/d[2],j!==-1&&D!==-1&&(v[j++]=(a[D]+p[3])/d[3]);return h==="RGBA"?new le("float32",v,[1,4,s,n]):new le("float32",v,[1,3,s,n])},Xi=async(a,i)=>{let s=typeof HTMLImageElement<"u"&&a instanceof HTMLImageElement,n=typeof ImageData<"u"&&a instanceof ImageData,f=typeof ImageBitmap<"u"&&a instanceof ImageBitmap,d=typeof a=="string",p,c=i??{},h=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},g=v=>typeof HTMLCanvasElement<"u"&&v instanceof HTMLCanvasElement||v instanceof OffscreenCanvas?v.getContext("2d"):null;if(s){let v=h();v.width=a.width,v.height=a.height;let C=g(v);if(C!=null){let T=a.height,S=a.width;if(i!==void 0&&i.resizedHeight!==void 0&&i.resizedWidth!==void 0&&(T=i.resizedHeight,S=i.resizedWidth),i!==void 0){if(c=i,i.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");c.tensorFormat="RGBA",c.height=T,c.width=S}else c.tensorFormat="RGBA",c.height=T,c.width=S;C.drawImage(a,0,0),p=C.getImageData(0,0,S,T).data}else throw new Error("Can not access image data")}else if(n){let v,C;if(i!==void 0&&i.resizedWidth!==void 0&&i.resizedHeight!==void 0?(v=i.resizedHeight,C=i.resizedWidth):(v=a.height,C=a.width),i!==void 0&&(c=i),c.format="RGBA",c.height=v,c.width=C,i!==void 0){let T=h();T.width=C,T.height=v;let S=g(T);if(S!=null)S.putImageData(a,0,0),p=S.getImageData(0,0,C,v).data;else throw new Error("Can not access image data")}else p=a.data}else if(f){if(i===void 0)throw new Error("Please provide image config with format for Imagebitmap");let v=h();v.width=a.width,v.height=a.height;let C=g(v);if(C!=null){let T=a.height,S=a.width;return C.drawImage(a,0,0,S,T),p=C.getImageData(0,0,S,T).data,c.height=T,c.width=S,Jr(p,c)}else throw new Error("Can not access image data")}else{if(d)return new Promise((v,C)=>{let T=h(),S=g(T);if(!a||!S)return C();let U=new Image;U.crossOrigin="Anonymous",U.src=a,U.onload=()=>{T.width=U.width,T.height=U.height,S.drawImage(U,0,0,T.width,T.height);let D=S.getImageData(0,0,T.width,T.height);c.height=T.height,c.width=T.width,v(Jr(D.data,c))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(p!==void 0)return Jr(p,c);throw new Error("Input data provided is not supported - aborted tensor creation")},Zi=(a,i)=>{let{width:s,height:n,download:f,dispose:d}=i,p=[1,n,s,4];return new le({location:"texture",type:"float32",texture:a,dims:p,download:f,dispose:d})},Qi=(a,i)=>{let{dataType:s,dims:n,download:f,dispose:d}=i;return new le({location:"gpu-buffer",type:s??"float32",gpuBuffer:a,dims:n,download:f,dispose:d})},Ki=(a,i)=>{let{dataType:s,dims:n,download:f,dispose:d}=i;return new le({location:"ml-tensor",type:s??"float32",mlTensor:a,dims:n,download:f,dispose:d})},eo=(a,i,s)=>new le({location:"cpu-pinned",type:a,data:i,dims:s??[i.length]})});var rt,St,ro,no,io=F(()=>{"use strict";rt=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),St=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),ro=!1,no=()=>{if(!ro){ro=!0;let a=typeof BigInt64Array<"u"&&BigInt64Array.from,i=typeof BigUint64Array<"u"&&BigUint64Array.from,s=globalThis.Float16Array,n=typeof s<"u"&&s.from;a&&(rt.set("int64",BigInt64Array),St.set(BigInt64Array,"int64")),i&&(rt.set("uint64",BigUint64Array),St.set(BigUint64Array,"uint64")),n?(rt.set("float16",s),St.set(s,"float16")):rt.set("float16",Uint16Array)}}});var oo,ao,so=F(()=>{"use strict";zt();oo=a=>{let i=1;for(let s=0;s<a.length;s++){let n=a[s];if(typeof n!="number"||!Number.isSafeInteger(n))throw new TypeError(`dims[${s}] must be an integer, got: ${n}`);if(n<0)throw new RangeError(`dims[${s}] must be a non-negative integer, got: ${n}`);i*=n}return i},ao=(a,i)=>{switch(a.location){case"cpu":return new le(a.type,a.data,i);case"cpu-pinned":return new le({location:"cpu-pinned",data:a.data,type:a.type,dims:i});case"texture":return new le({location:"texture",texture:a.texture,type:a.type,dims:i});case"gpu-buffer":return new le({location:"gpu-buffer",gpuBuffer:a.gpuBuffer,type:a.type,dims:i});case"ml-tensor":return new le({location:"ml-tensor",mlTensor:a.mlTensor,type:a.type,dims:i});default:throw new Error(`tensorReshape: tensor location ${a.location} is not supported`)}}});var le,zt=F(()=>{"use strict";Ji();to();io();so();le=class{constructor(i,s,n){no();let f,d;if(typeof i=="object"&&"location"in i)switch(this.dataLocation=i.location,f=i.type,d=i.dims,i.location){case"cpu-pinned":{let c=rt.get(f);if(!c)throw new TypeError(`unsupported type "${f}" to create tensor from pinned buffer`);if(!(i.data instanceof c))throw new TypeError(`buffer should be of type ${c.name}`);this.cpuData=i.data;break}case"texture":{if(f!=="float32")throw new TypeError(`unsupported type "${f}" to create tensor from texture`);this.gpuTextureData=i.texture,this.downloader=i.download,this.disposer=i.dispose;break}case"gpu-buffer":{if(f!=="float32"&&f!=="float16"&&f!=="int32"&&f!=="int64"&&f!=="uint32"&&f!=="uint8"&&f!=="bool"&&f!=="uint4"&&f!=="int4")throw new TypeError(`unsupported type "${f}" to create tensor from gpu buffer`);this.gpuBufferData=i.gpuBuffer,this.downloader=i.download,this.disposer=i.dispose;break}case"ml-tensor":{if(f!=="float32"&&f!=="float16"&&f!=="int32"&&f!=="int64"&&f!=="uint32"&&f!=="uint64"&&f!=="int8"&&f!=="uint8"&&f!=="bool"&&f!=="uint4"&&f!=="int4")throw new TypeError(`unsupported type "${f}" to create tensor from MLTensor`);this.mlTensorData=i.mlTensor,this.downloader=i.download,this.disposer=i.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let c,h;if(typeof i=="string")if(f=i,h=n,i==="string"){if(!Array.isArray(s))throw new TypeError("A string tensor's data must be a string array.");c=s}else{let g=rt.get(i);if(g===void 0)throw new TypeError(`Unsupported tensor type: ${i}.`);if(Array.isArray(s)){if(i==="float16"&&g===Uint16Array||i==="uint4"||i==="int4")throw new TypeError(`Creating a ${i} tensor from number array is not supported. Please use ${g.name} as data.`);i==="uint64"||i==="int64"?c=g.from(s,BigInt):c=g.from(s)}else if(s instanceof g)c=s;else if(s instanceof Uint8ClampedArray)if(i==="uint8")c=Uint8Array.from(s);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(i==="float16"&&s instanceof Uint16Array&&g!==Uint16Array)c=new globalThis.Float16Array(s.buffer,s.byteOffset,s.length);else throw new TypeError(`A ${f} tensor's data must be type of ${g}`)}else if(h=s,Array.isArray(i)){if(i.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let g=typeof i[0];if(g==="string")f="string",c=i;else if(g==="boolean")f="bool",c=Uint8Array.from(i);else throw new TypeError(`Invalid element type of data array: ${g}.`)}else if(i instanceof Uint8ClampedArray)f="uint8",c=Uint8Array.from(i);else{let g=St.get(i.constructor);if(g===void 0)throw new TypeError(`Unsupported type for tensor data: ${i.constructor}.`);f=g,c=i}if(h===void 0)h=[c.length];else if(!Array.isArray(h))throw new TypeError("A tensor's dims must be a number array");d=h,this.cpuData=c,this.dataLocation="cpu"}let p=oo(d);if(this.cpuData&&p!==this.cpuData.length&&!((f==="uint4"||f==="int4")&&Math.ceil(p/2)===this.cpuData.length))throw new Error(`Tensor's size(${p}) does not match data length(${this.cpuData.length}).`);this.type=f,this.dims=d,this.size=p}static async fromImage(i,s){return Xi(i,s)}static fromTexture(i,s){return Zi(i,s)}static fromGpuBuffer(i,s){return Qi(i,s)}static fromMLTensor(i,s){return Ki(i,s)}static fromPinnedBuffer(i,s,n){return eo(i,s,n)}toDataURL(i){return Yi(this,i)}toImageData(i){return qi(this,i)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(i){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let s=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=s,i&&this.disposer&&(this.disposer(),this.disposer=void 0),s}finally{this.isDownloading=!1}}default:throw new Error(`cannot get data from location: ${this.dataLocation}`)}}dispose(){if(this.isDownloading)throw new Error("The current tensor is being downloaded.");this.disposer&&(this.disposer(),this.disposer=void 0),this.cpuData=void 0,this.gpuTextureData=void 0,this.gpuBufferData=void 0,this.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(i){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return ao(this,i)}}});var Oe,Xr=F(()=>{"use strict";zt();Oe=le});var uo,fo,nt,it,Ye,qe,Zr=F(()=>{"use strict";qr();uo=(a,i)=>{(typeof se.trace>"u"?!se.wasm.trace:!se.trace)||console.timeStamp(`${a}::ORT::${i}`)},fo=(a,i)=>{let s=new Error().stack?.split(/\r\n|\r|\n/g)||[],n=!1;for(let f=0;f<s.length;f++){if(n&&!s[f].includes("TRACE_FUNC")){let d=`FUNC_${a}::${s[f].trim().split(" ")[1]}`;i&&(d+=`::${i}`),uo("CPU",d);return}s[f].includes("TRACE_FUNC")&&(n=!0)}},nt=a=>{(typeof se.trace>"u"?!se.wasm.trace:!se.trace)||fo("BEGIN",a)},it=a=>{(typeof se.trace>"u"?!se.wasm.trace:!se.trace)||fo("END",a)},Ye=a=>{(typeof se.trace>"u"?!se.wasm.trace:!se.trace)||console.time(`ORT::${a}`)},qe=a=>{(typeof se.trace>"u"?!se.wasm.trace:!se.trace)||console.timeEnd(`ORT::${a}`)}});var Vt,lo=F(()=>{"use strict";Yr();Xr();Zr();Vt=class a{constructor(i){this.handler=i}async run(i,s,n){nt(),Ye("InferenceSession.run");let f={},d={};if(typeof i!="object"||i===null||i instanceof Oe||Array.isArray(i))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let p=!0;if(typeof s=="object"){if(s===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(s instanceof Oe)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(s)){if(s.length===0)throw new TypeError("'fetches' cannot be an empty array.");p=!1;for(let g of s){if(typeof g!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(g)===-1)throw new RangeError(`'fetches' contains invalid output name: ${g}.`);f[g]=null}if(typeof n=="object"&&n!==null)d=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else{let g=!1,v=Object.getOwnPropertyNames(s);for(let C of this.outputNames)if(v.indexOf(C)!==-1){let T=s[C];(T===null||T instanceof Oe)&&(g=!0,p=!1,f[C]=T)}if(g){if(typeof n=="object"&&n!==null)d=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else d=s}}else if(typeof s<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let g of this.inputNames)if(typeof i[g]>"u")throw new Error(`input '${g}' is missing in 'feeds'.`);if(p)for(let g of this.outputNames)f[g]=null;let c=await this.handler.run(i,f,d),h={};for(let g in c)if(Object.hasOwnProperty.call(c,g)){let v=c[g];v instanceof Oe?h[g]=v:h[g]=new Oe(v.type,v.data,v.dims)}return qe("InferenceSession.run"),it(),h}async release(){return this.handler.dispose()}static async create(i,s,n,f){nt(),Ye("InferenceSession.create");let d,p={};if(typeof i=="string"){if(d=i,typeof s=="object"&&s!==null)p=s;else if(typeof s<"u")throw new TypeError("'options' must be an object.")}else if(i instanceof Uint8Array){if(d=i,typeof s=="object"&&s!==null)p=s;else if(typeof s<"u")throw new TypeError("'options' must be an object.")}else if(i instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&i instanceof SharedArrayBuffer){let v=i,C=0,T=i.byteLength;if(typeof s=="object"&&s!==null)p=s;else if(typeof s=="number"){if(C=s,!Number.isSafeInteger(C))throw new RangeError("'byteOffset' must be an integer.");if(C<0||C>=v.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${v.byteLength}).`);if(T=i.byteLength-C,typeof n=="number"){if(T=n,!Number.isSafeInteger(T))throw new RangeError("'byteLength' must be an integer.");if(T<=0||C+T>v.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${v.byteLength-C}].`);if(typeof f=="object"&&f!==null)p=f;else if(typeof f<"u")throw new TypeError("'options' must be an object.")}else if(typeof n<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof s<"u")throw new TypeError("'options' must be an object.");d=new Uint8Array(v,C,T)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[c,h]=await ji(p),g=await c.createInferenceSessionHandler(d,h);return qe("InferenceSession.create"),it(),new a(g)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}});var xu,co=F(()=>{"use strict";lo();xu=Vt});var po=F(()=>{"use strict"});var mo=F(()=>{"use strict"});var yo=F(()=>{"use strict"});var ho=F(()=>{"use strict"});var Qr={};_t(Qr,{InferenceSession:()=>xu,TRACE:()=>uo,TRACE_EVENT_BEGIN:()=>Ye,TRACE_EVENT_END:()=>qe,TRACE_FUNC_BEGIN:()=>nt,TRACE_FUNC_END:()=>it,Tensor:()=>Oe,env:()=>X,registerBackend:()=>tt});var Je=F(()=>{"use strict";Gi();Hi();co();Xr();po();mo();Zr();yo();ho()});var Ht=F(()=>{"use strict"});var vo={};_t(vo,{default:()=>Iu});var go,wo,Iu,To=F(()=>{"use strict";Kr();Xe();Yt();go="ort-wasm-proxy-worker",wo=globalThis.self?.name===go;wo&&(self.onmessage=a=>{let{type:i,in:s}=a.data;try{switch(i){case"init-wasm":qt(s.wasm).then(()=>{Jt(s).then(()=>{postMessage({type:i})},n=>{postMessage({type:i,err:n})})},n=>{postMessage({type:i,err:n})});break;case"init-ep":{let{epName:n,env:f}=s;Xt(f,n).then(()=>{postMessage({type:i})},d=>{postMessage({type:i,err:d})});break}case"copy-from":{let{buffer:n}=s,f=At(n);postMessage({type:i,out:f});break}case"create":{let{model:n,options:f}=s;Zt(n,f).then(d=>{postMessage({type:i,out:d})},d=>{postMessage({type:i,err:d})});break}case"release":Qt(s),postMessage({type:i});break;case"run":{let{sessionId:n,inputIndices:f,inputs:d,outputIndices:p,options:c}=s;Kt(n,f,d,p,new Array(p.length).fill(null),c).then(h=>{h.some(g=>g[3]!=="cpu")?postMessage({type:i,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:i,out:h},tr([...d,...h]))},h=>{postMessage({type:i,err:h})});break}case"end-profiling":er(s),postMessage({type:i});break;default:}}catch(n){postMessage({type:i,err:n})}});Iu=wo?null:a=>new Worker(a??be,{type:"module",name:go})});var Eo={};_t(Eo,{default:()=>Ou});var Co,Ou,Lu,_o=F(()=>{"use strict";Co=async function(a={}){var i,s,n=a,f=new Promise((e,t)=>{i=e,s=t}),d=typeof window=="object",p=typeof WorkerGlobalScope<"u",c=p&&self.name?.startsWith("em-pthread");n.mountExternalData=(e,t)=>{e.startsWith("./")&&(e=e.substring(2)),(n.fc||(n.fc=new Map)).set(e,t)},n.unmountExternalData=()=>{delete n.fc};var h=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,ld:!0}).buffer.constructor;let g=()=>{let e=(t,r,o)=>(...u)=>{let l=Me,m=r?.();u=t(...u);let y=r?.();return m!==y&&(t=y,o(m),r=o=null),Me!=l?new Promise((w,E)=>{Ir={resolve:w,reject:E}}):u};(()=>{for(let t of["_OrtAppendExecutionProvider","_OrtCreateSession","_OrtRun","_OrtRunWithBinding","_OrtBindInput"])n[t]=e(n[t],()=>n[t],r=>n[t]=r)})(),typeof jsepRunAsync<"u"&&(n._OrtRun=jsepRunAsync(n._OrtRun),n._OrtRunWithBinding=jsepRunAsync(n._OrtRunWithBinding)),g=void 0};n.asyncInit=()=>{g?.()};var v,C,T=(e,t)=>{throw t},S=import.meta.url,U="";if(d||p){try{U=new URL(".",S).href}catch{}p&&(C=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),v=async e=>{if(Z(e))return new Promise((r,o)=>{var u=new XMLHttpRequest;u.open("GET",e,!0),u.responseType="arraybuffer",u.onload=()=>{u.status==200||u.status==0&&u.response?r(u.response):o(u.status)},u.onerror=o,u.send(null)});var t=await fetch(e,{credentials:"same-origin"});if(t.ok)return t.arrayBuffer();throw Error(t.status+" : "+t.url)}}var D,R,M,L,j,P,z,ne,fe,te,oe,ie,Q,ge,wt,W=console.log.bind(console),we=console.error.bind(console),lt=W,N=we,ue=!1,Z=e=>e.startsWith("file://");function re(){return R.buffer!=j.buffer&&V(),j}function ae(){return R.buffer!=j.buffer&&V(),P}function Le(){return R.buffer!=j.buffer&&V(),z}function $e(){return R.buffer!=j.buffer&&V(),ne}function I(){return R.buffer!=j.buffer&&V(),fe}function _(){return R.buffer!=j.buffer&&V(),te}function ve(){return R.buffer!=j.buffer&&V(),oe}function de(){return R.buffer!=j.buffer&&V(),ge}if(c){let e=function(t){try{var r=t.data,o=r.dc;if(o==="load"){let u=[];self.onmessage=l=>u.push(l),self.startWorker=()=>{postMessage({dc:"loaded"});for(let l of u)e(l);self.onmessage=e};for(let l of r.Uc)n[l]&&!n[l].proxy||(n[l]=(...m)=>{postMessage({dc:"callHandler",Tc:l,args:m})},l=="print"&&(lt=n[l]),l=="printErr"&&(N=n[l]));R=r.bd,V(),wt(r.cd)}else if(o==="run"){la(r.ac),jr(r.ac,0,0,1,0,0),Cn(),Ar(r.ac),De||(hi(),De=!0);try{ca(r.Zc,r.jc)}catch(u){if(u!="unwind")throw u}}else r.target!=="setimmediate"&&(o==="checkMailbox"?De&&Bt():o&&(N(`worker: received unknown command ${o}`),N(r)))}catch(u){throw Li(),u}};var ef=e,De=!1;self.onunhandledrejection=t=>{throw t.reason||t},self.onmessage=e}function V(){var e=R.buffer;n.HEAP8=j=new Int8Array(e),z=new Int16Array(e),n.HEAPU8=P=new Uint8Array(e),ne=new Uint16Array(e),n.HEAP32=fe=new Int32Array(e),n.HEAPU32=te=new Uint32Array(e),oe=new Float32Array(e),ge=new Float64Array(e),ie=new BigInt64Array(e),Q=new BigUint64Array(e)}function q(){c?startWorker(n):b.nb()}var Te,Ae=0,Pe=null;function yr(){if(--Ae==0&&Pe){var e=Pe;Pe=null,e()}}function Re(e){throw N(e="Aborted("+e+")"),ue=!0,e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info."),s(e),e}function hn(){return{a:{R:vu,b:pa,ba:An,I:On,ra:Ln,jb:Bn,lb:Mn,sa:Un,pa:Dn,ia:Pn,oa:Rn,P:Wn,kb:kn,hb:Nn,qa:Fn,ib:jn,xa:ma,Z:ha,cb:ba,ab:wa,Y:Ta,w:Ca,t:Ea,bb:_a,L:Ba,db:Ma,la:Ua,fb:Da,ca:Pa,_a:Ra,$:Wa,ka:Ar,ua:ka,s:Na,Na:Fa,A:$a,o:za,m:Ha,c:Er,Ma:Ya,n:qa,i:Za,v:Qa,p:Ka,f:es,u:ts,k:rs,e:ns,j:is,h:os,g:as,d:ss,fa:us,ga:fs,ha:ls,da:ei,ea:ti,$a:ri,za:ds,wa:ys,E:hs,La:bs,M:gs,va:ps,C:ws,ta:vs,gb:Ts,r:cs,Ia:Cs,F:Es,Q:_s,eb:Ss,Ba:As,Aa:xs,Ha:Ds,q:Ps,U:Rs,T:Ws,Ka:ks,D:Ns,l:Fs,Ga:js,Fa:Gs,Ja:$s,Ea:zs,Da:Vs,Ca:Hs,ma:ui,na:fi,aa:wr,J:li,O:ci,ja:di,N:pi,a:R,ya:gr,Xa:qs,K:Js,x:Xs,S:Zs,Ya:Qs,y:Ks,Ta:eu,Va:tu,V:ru,z:nu,_:iu,W:ou,G:au,Ra:su,mb:uu,B:fu,Ua:lu,Wa:cu,Oa:du,Pa:pu,Qa:mu,H:yu,X:hu,Sa:bu,Za:gu}}}class hr{name="ExitStatus";constructor(t){this.message=`Program terminated with exit(${t})`,this.status=t}}var bn=e=>{e.terminate(),e.onmessage=()=>{}},br=[],gn=e=>{ze.length==0&&(_n(),En(ze[0]));var t=ze.pop();if(!t)return 6;vt.push(t),Qe[e.ac]=t,t.ac=e.ac;var r={dc:"run",Zc:e.Yc,jc:e.jc,ac:e.ac};return t.postMessage(r,e.Oc),0},K=0,J=(e,t,...r)=>{for(var o=2*r.length,u=_e(),l=jt(8*o),m=l>>>3,y=0;y<r.length;y++){var w=r[y];typeof w=="bigint"?(ie[m+2*y]=1n,ie[m+2*y+1]=w):(ie[m+2*y]=0n,de()[m+2*y+1>>>0]=w)}return e=Bi(e,0,o,l,t),Ee(u),e};function gr(e){if(c)return J(0,1,e);if(L=e,!(0<K)){for(var t of vt)bn(t);for(t of ze)bn(t);ze=[],vt=[],Qe={},ue=!0}T(0,new hr(e))}function wn(e){if(c)return J(1,0,e);wr(e)}var wr=e=>{if(L=e,c)throw wn(e),"unwind";gr(e)},ze=[],vt=[],vn=[],Qe={},Tn=e=>{var t=e.ac;delete Qe[t],ze.push(e),vt.splice(vt.indexOf(e),1),e.ac=0,Mi(t)};function Cn(){vn.forEach(e=>e())}var En=e=>new Promise(t=>{e.onmessage=u=>{var l=(u=u.data).dc;if(u.hc&&u.hc!=Rr()){var m=Qe[u.hc];m?m.postMessage(u,u.Oc):N(`Internal error! Worker sent a message "${l}" to target pthread ${u.hc}, but that thread no longer exists!`)}else l==="checkMailbox"?Bt():l==="spawnThread"?gn(u):l==="cleanupThread"?Tn(Qe[u.$c]):l==="loaded"?(e.loaded=!0,t(e)):u.target==="setimmediate"?e.postMessage(u):l==="callHandler"?n[u.Tc](...u.args):l&&N(`worker sent an unknown command ${l}`)},e.onerror=u=>{throw N(`worker sent an error! ${u.filename}:${u.lineno}: ${u.message}`),u};var r,o=[];for(r of[])n.propertyIsEnumerable(r)&&o.push(r);e.postMessage({dc:"load",Uc:o,bd:R,cd:M})});function _n(){var e=new Worker((()=>{let t=URL;return import.meta.url>"file:"&&import.meta.url<"file;"?new t("ort.webgpu.bundle.min.mjs",import.meta.url):new URL(import.meta.url)})(),{type:"module",workerData:"em-pthread",name:"em-pthread"});ze.push(e)}var la=e=>{V();var t=_()[e+52>>>2>>>0];e=_()[e+56>>>2>>>0],Pi(t,t-e),Ee(t)},ca=(e,t)=>{K=0,e=Ri(e,t),0<K?L=e:Gr(e)};class da{constructor(t){this.ic=t-24}}var he=e=>-9007199254740992>e||9007199254740992<e?NaN:Number(e);function pa(e,t,r){var o=new da(e>>>=0);throw t>>>=0,r>>>=0,_()[o.ic+16>>>2>>>0]=0,_()[o.ic+4>>>2>>>0]=t,_()[o.ic+8>>>2>>>0]=r,e}function Sn(e,t,r,o){return c?J(2,1,e,t,r,o):An(e,t,r,o)}function An(e,t,r,o){if(e>>>=0,r>>>=0,o>>>=0,h===void 0)return 6;var u=[];return c&&u.length===0?Sn(e,t>>>=0,r,o):(e={Yc:r,ac:e,jc:o,Oc:u},c?(e.dc="spawnThread",postMessage(e,u),0):gn(e))}var xn=typeof TextDecoder<"u"?new TextDecoder:void 0,In=(e,t=0,r=NaN)=>{var o=(t>>>=0)+r;for(r=t;e[r]&&!(r>=o);)++r;if(16<r-t&&e.buffer&&xn)return xn.decode(e.buffer instanceof ArrayBuffer?e.subarray(t,r):e.slice(t,r));for(o="";t<r;){var u=e[t++];if(128&u){var l=63&e[t++];if((224&u)==192)o+=String.fromCharCode((31&u)<<6|l);else{var m=63&e[t++];65536>(u=(240&u)==224?(15&u)<<12|l<<6|m:(7&u)<<18|l<<12|m<<6|63&e[t++])?o+=String.fromCharCode(u):(u-=65536,o+=String.fromCharCode(55296|u>>10,56320|1023&u))}}else o+=String.fromCharCode(u)}return o},ct=(e,t)=>(e>>>=0)?In(ae(),e,t):"";function On(e,t,r){return c?J(3,1,e,t,r):0}function Ln(e,t){if(c)return J(4,1,e,t)}function Bn(e,t){if(c)return J(5,1,e,t)}function Mn(e,t,r){if(c)return J(6,1,e,t,r)}function Un(e,t,r){return c?J(7,1,e,t,r):0}function Dn(e,t){if(c)return J(8,1,e,t)}function Pn(e,t,r){if(c)return J(9,1,e,t,r)}function Rn(e,t,r,o){if(c)return J(10,1,e,t,r,o)}function Wn(e,t,r,o){if(c)return J(11,1,e,t,r,o)}function kn(e,t,r,o){if(c)return J(12,1,e,t,r,o)}function Nn(e){if(c)return J(13,1,e)}function Fn(e,t){if(c)return J(14,1,e,t)}function jn(e,t,r){if(c)return J(15,1,e,t,r)}var Gn,ma=()=>Re(""),Be=e=>{for(var t="";ae()[e>>>0];)t+=Gn[ae()[e++>>>0]];return t},vr={},Tr={},ya={},dt=n.BindingError=class extends Error{constructor(e){super(e),this.name="BindingError"}};function We(e,t,r={}){return function(o,u,l={}){var m=u.name;if(!o)throw new dt(`type "${m}" must have a positive integer typeid pointer`);if(Tr.hasOwnProperty(o)){if(l.Vc)return;throw new dt(`Cannot register type '${m}' twice`)}Tr[o]=u,delete ya[o],vr.hasOwnProperty(o)&&(u=vr[o],delete vr[o],u.forEach(y=>y()))}(e,t,r)}var $n=(e,t,r)=>{switch(t){case 1:return r?o=>re()[o>>>0]:o=>ae()[o>>>0];case 2:return r?o=>Le()[o>>>1>>>0]:o=>$e()[o>>>1>>>0];case 4:return r?o=>I()[o>>>2>>>0]:o=>_()[o>>>2>>>0];case 8:return r?o=>ie[o>>>3]:o=>Q[o>>>3];default:throw new TypeError(`invalid integer width (${t}): ${e}`)}};function ha(e,t,r){r>>>=0,We(e>>>=0,{name:t=Be(t>>>0),fromWireType:o=>o,toWireType:function(o,u){if(typeof u!="bigint"&&typeof u!="number")throw u=u===null?"null":(o=typeof u)=="object"||o==="array"||o==="function"?u.toString():""+u,new TypeError(`Cannot convert "${u}" to ${this.name}`);return typeof u=="number"&&(u=BigInt(u)),u},cc:Ve,readValueFromPointer:$n(t,r,t.indexOf("u")==-1),ec:null})}var Ve=8;function ba(e,t,r,o){We(e>>>=0,{name:t=Be(t>>>0),fromWireType:function(u){return!!u},toWireType:function(u,l){return l?r:o},cc:Ve,readValueFromPointer:function(u){return this.fromWireType(ae()[u>>>0])},ec:null})}var Cr=[],ke=[];function Er(e){9<(e>>>=0)&&--ke[e+1]==0&&(ke[e]=void 0,Cr.push(e))}var pe=e=>{if(!e)throw new dt(`Cannot use deleted val. handle = ${e}`);return ke[e]},Ce=e=>{switch(e){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:let t=Cr.pop()||ke.length;return ke[t]=e,ke[t+1]=1,t}};function _r(e){return this.fromWireType(_()[e>>>2>>>0])}var ga={name:"emscripten::val",fromWireType:e=>{var t=pe(e);return Er(e),t},toWireType:(e,t)=>Ce(t),cc:Ve,readValueFromPointer:_r,ec:null};function wa(e){return We(e>>>0,ga)}var va=(e,t)=>{switch(t){case 4:return function(r){return this.fromWireType(ve()[r>>>2>>>0])};case 8:return function(r){return this.fromWireType(de()[r>>>3>>>0])};default:throw new TypeError(`invalid float width (${t}): ${e}`)}};function Ta(e,t,r){r>>>=0,We(e>>>=0,{name:t=Be(t>>>0),fromWireType:o=>o,toWireType:(o,u)=>u,cc:Ve,readValueFromPointer:va(t,r),ec:null})}function Ca(e,t,r,o,u){if(e>>>=0,r>>>=0,t=Be(t>>>0),u===-1&&(u=4294967295),u=y=>y,o===0){var l=32-8*r;u=y=>y<<l>>>l}var m=t.includes("unsigned")?function(y,w){return w>>>0}:function(y,w){return w};We(e,{name:t,fromWireType:u,toWireType:m,cc:Ve,readValueFromPointer:$n(t,r,o!==0),ec:null})}function Ea(e,t,r){function o(l){var m=_()[l>>>2>>>0];return l=_()[l+4>>>2>>>0],new u(re().buffer,l,m)}var u=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][t];We(e>>>=0,{name:r=Be(r>>>0),fromWireType:o,cc:Ve,readValueFromPointer:o},{Vc:!0})}var Ne=(e,t,r)=>{var o=ae();if(t>>>=0,0<r){var u=t;r=t+r-1;for(var l=0;l<e.length;++l){var m=e.charCodeAt(l);if(55296<=m&&57343>=m&&(m=65536+((1023&m)<<10)|1023&e.charCodeAt(++l)),127>=m){if(t>=r)break;o[t++>>>0]=m}else{if(2047>=m){if(t+1>=r)break;o[t++>>>0]=192|m>>6}else{if(65535>=m){if(t+2>=r)break;o[t++>>>0]=224|m>>12}else{if(t+3>=r)break;o[t++>>>0]=240|m>>18,o[t++>>>0]=128|m>>12&63}o[t++>>>0]=128|m>>6&63}o[t++>>>0]=128|63&m}}o[t>>>0]=0,e=t-u}else e=0;return e},Fe=e=>{for(var t=0,r=0;r<e.length;++r){var o=e.charCodeAt(r);127>=o?t++:2047>=o?t+=2:55296<=o&&57343>=o?(t+=4,++r):t+=3}return t};function _a(e,t){We(e>>>=0,{name:t=Be(t>>>0),fromWireType:function(r){for(var o,u=_()[r>>>2>>>0],l=r+4,m=l,y=0;y<=u;++y){var w=l+y;y!=u&&ae()[w>>>0]!=0||(m=ct(m,w-m),o===void 0?o=m:(o+="\0",o+=m),m=w+1)}return xe(r),o},toWireType:function(r,o){o instanceof ArrayBuffer&&(o=new Uint8Array(o));var u=typeof o=="string";if(!(u||ArrayBuffer.isView(o)&&o.BYTES_PER_ELEMENT==1))throw new dt("Cannot pass non-string to std::string");var l=u?Fe(o):o.length,m=yt(4+l+1),y=m+4;return _()[m>>>2>>>0]=l,u?Ne(o,y,l+1):ae().set(o,y>>>0),r!==null&&r.push(xe,m),m},cc:Ve,readValueFromPointer:_r,ec(r){xe(r)}})}var zn=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0,Sa=(e,t)=>{for(var r=e>>1,o=r+t/2;!(r>=o)&&$e()[r>>>0];)++r;if(32<(r<<=1)-e&&zn)return zn.decode(ae().slice(e,r));for(r="",o=0;!(o>=t/2);++o){var u=Le()[e+2*o>>>1>>>0];if(u==0)break;r+=String.fromCharCode(u)}return r},Aa=(e,t,r)=>{if(r??=2147483647,2>r)return 0;var o=t;r=(r-=2)<2*e.length?r/2:e.length;for(var u=0;u<r;++u){var l=e.charCodeAt(u);Le()[t>>>1>>>0]=l,t+=2}return Le()[t>>>1>>>0]=0,t-o},xa=e=>2*e.length,Ia=(e,t)=>{for(var r=0,o="";!(r>=t/4);){var u=I()[e+4*r>>>2>>>0];if(u==0)break;++r,65536<=u?(u-=65536,o+=String.fromCharCode(55296|u>>10,56320|1023&u)):o+=String.fromCharCode(u)}return o},Oa=(e,t,r)=>{if(t>>>=0,r??=2147483647,4>r)return 0;var o=t;r=o+r-4;for(var u=0;u<e.length;++u){var l=e.charCodeAt(u);if(55296<=l&&57343>=l&&(l=65536+((1023&l)<<10)|1023&e.charCodeAt(++u)),I()[t>>>2>>>0]=l,(t+=4)+4>r)break}return I()[t>>>2>>>0]=0,t-o},La=e=>{for(var t=0,r=0;r<e.length;++r){var o=e.charCodeAt(r);55296<=o&&57343>=o&&++r,t+=4}return t};function Ba(e,t,r){if(e>>>=0,t>>>=0,r=Be(r>>>=0),t===2)var o=Sa,u=Aa,l=xa,m=y=>$e()[y>>>1>>>0];else t===4&&(o=Ia,u=Oa,l=La,m=y=>_()[y>>>2>>>0]);We(e,{name:r,fromWireType:y=>{for(var w,E=_()[y>>>2>>>0],A=y+4,O=0;O<=E;++O){var k=y+4+O*t;O!=E&&m(k)!=0||(A=o(A,k-A),w===void 0?w=A:(w+="\0",w+=A),A=k+t)}return xe(y),w},toWireType:(y,w)=>{if(typeof w!="string")throw new dt(`Cannot pass non-string to C++ string type ${r}`);var E=l(w),A=yt(4+E+t);return _()[A>>>2>>>0]=E/t,u(w,A+4,E+t),y!==null&&y.push(xe,A),A},cc:Ve,readValueFromPointer:_r,ec(y){xe(y)}})}function Ma(e,t){We(e>>>=0,{Wc:!0,name:t=Be(t>>>0),cc:0,fromWireType:()=>{},toWireType:()=>{}})}function Ua(e){jr(e>>>0,!p,1,!d,131072,!1),Cn()}var Sr=e=>{if(!ue)try{if(e(),!(0<K))try{c?Gr(L):wr(L)}catch(t){t instanceof hr||t=="unwind"||T(0,t)}}catch(t){t instanceof hr||t=="unwind"||T(0,t)}};function Ar(e){e>>>=0,typeof Atomics.ad=="function"&&(Atomics.ad(I(),e>>>2,e).value.then(Bt),e+=128,Atomics.store(I(),e>>>2,1))}var Bt=()=>{var e=Rr();e&&(Ar(e),Sr(Di))};function Da(e,t){(e>>>=0)==t>>>0?setTimeout(Bt):c?postMessage({hc:e,dc:"checkMailbox"}):(e=Qe[e])&&e.postMessage({dc:"checkMailbox"})}var xr=[];function Pa(e,t,r,o,u){for(t>>>=0,o/=2,xr.length=o,r=u>>>0>>>3,u=0;u<o;u++)xr[u]=ie[r+2*u]?ie[r+2*u+1]:de()[r+2*u+1>>>0];return(t?Dr[t]:wu[e])(...xr)}var Ra=()=>{K=0};function Wa(e){e>>>=0,c?postMessage({dc:"cleanupThread",$c:e}):Tn(Qe[e])}function ka(e){}var Mt=(e,t)=>{var r=Tr[e];if(r===void 0)throw e=yi(e),r=Be(e),xe(e),new dt(`${t} has unknown type ${r}`);return r},Vn=(e,t,r)=>{var o=[];return e=e.toWireType(o,r),o.length&&(_()[t>>>2>>>0]=Ce(o)),e};function Na(e,t,r){return t>>>=0,r>>>=0,e=pe(e>>>0),t=Mt(t,"emval::as"),Vn(t,r,e)}function Fa(e,t){return t>>>=0,e=pe(e>>>0),(t=Mt(t,"emval::as")).toWireType(null,e)}var Ut=e=>{try{e()}catch(t){Re(t)}},He=0,Me=null,Hn=0,Dt=[],Yn={},qn={},ja=0,Ir=null,Ga=[];function Jn(e){return function(t){if(!ue){if(He===0){var r=!1,o=!1;t((u=0)=>{if(!ue&&(Hn=u,r=!0,o)){He=2,Ut(()=>Ni(Me)),typeof MainLoop<"u"&&MainLoop.Sc&&MainLoop.resume(),u=!1;try{var l=function(){var w=I()[Me+8>>>2>>>0];return w=b[qn[w]],--K,w()}()}catch(w){l=w,u=!0}var m=!1;if(!Me){var y=Ir;y&&(Ir=null,(u?y.reject:y.resolve)(l),m=!0)}if(u&&!m)throw l}}),o=!0,r||(He=1,Me=function(){var u=yt(65548),l=u+12;_()[u>>>2>>>0]=l,_()[u+4>>>2>>>0]=l+65536,l=Dt[0];var m=Yn[l];return m===void 0&&(m=ja++,Yn[l]=m,qn[m]=l),l=m,I()[u+8>>>2>>>0]=l,u}(),typeof MainLoop<"u"&&MainLoop.Sc&&MainLoop.pause(),Ut(()=>Wi(Me)))}else He===2?(He=0,Ut(Fi),xe(Me),Me=null,Ga.forEach(Sr)):Re(`invalid state: ${He}`);return Hn}}(t=>{e().then(t)})}function $a(e){return e>>>=0,Jn(async()=>{var t=await pe(e);return Ce(t)})}var Pt=[];function za(e,t,r,o){return r>>>=0,o>>>=0,(e=Pt[e>>>0])(null,t=pe(t>>>0),r,o)}var Va={},Rt=e=>{var t=Va[e];return t===void 0?Be(e):t};function Ha(e,t,r,o,u){return r>>>=0,o>>>=0,u>>>=0,(e=Pt[e>>>0])(t=pe(t>>>0),t[r=Rt(r)],o,u)}function Ya(e,t){return t>>>=0,(e=pe(e>>>0))==pe(t)}var Xn=()=>typeof globalThis=="object"?globalThis:Function("return this")();function qa(e){return(e>>>=0)==0?Ce(Xn()):(e=Rt(e),Ce(Xn()[e]))}var Ja=e=>{var t=Pt.length;return Pt.push(e),t},Xa=(e,t)=>{for(var r=Array(e),o=0;o<e;++o)r[o]=Mt(_()[t+4*o>>>2>>>0],`parameter ${o}`);return r};function Za(e,t,r){var o=(t=Xa(e,t>>>0)).shift();e--;var u=`return function (obj, func, destructorsRef, args) { `,l=0,m=[];r===0&&m.push("obj");for(var y=["retType"],w=[o],E=0;E<e;++E)m.push(`arg${E}`),y.push(`argType${E}`),w.push(t[E]),u+=` var arg${E} = argType${E}.readValueFromPointer(args${l?"+"+l:""}); `,l+=t[E].cc;return u+=` var rv = ${r===1?"new func":"func.call"}(${m.join(", ")}); `,o.Wc||(y.push("emval_returnValue"),w.push(Vn),u+=` return emval_returnValue(retType, destructorsRef, rv); `),e=new Function(...y,u+`}; `)(...w),r=`methodCaller<(${t.map(A=>A.name).join(", ")}) => ${o.name}>`,Ja(Object.defineProperty(e,"name",{value:r}))}function Qa(e){return e=Rt(e>>>0),Ce(n[e])}function Ka(e,t){return t>>>=0,e=pe(e>>>0),t=pe(t),Ce(e[t])}function es(e){9<(e>>>=0)&&(ke[e+1]+=1)}function ts(){return Ce([])}function rs(e){e=pe(e>>>0);for(var t=Array(e.length),r=0;r<e.length;r++)t[r]=e[r];return Ce(t)}function ns(e){return Ce(Rt(e>>>0))}function is(){return Ce({})}function os(e){for(var t=pe(e>>>=0);t.length;){var r=t.pop();t.pop()(r)}Er(e)}function as(e,t,r){t>>>=0,r>>>=0,e=pe(e>>>0),t=pe(t),r=pe(r),e[t]=r}function ss(e,t){return t>>>=0,e=(e=Mt(e>>>0,"_emval_take_value")).readValueFromPointer(t),Ce(e)}function us(e,t){e=he(e),t>>>=0,e=new Date(1e3*e),I()[t>>>2>>>0]=e.getUTCSeconds(),I()[t+4>>>2>>>0]=e.getUTCMinutes(),I()[t+8>>>2>>>0]=e.getUTCHours(),I()[t+12>>>2>>>0]=e.getUTCDate(),I()[t+16>>>2>>>0]=e.getUTCMonth(),I()[t+20>>>2>>>0]=e.getUTCFullYear()-1900,I()[t+24>>>2>>>0]=e.getUTCDay(),e=(e.getTime()-Date.UTC(e.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,I()[t+28>>>2>>>0]=e}var Zn=e=>e%4==0&&(e%100!=0||e%400==0),Qn=[0,31,60,91,121,152,182,213,244,274,305,335],Kn=[0,31,59,90,120,151,181,212,243,273,304,334];function fs(e,t){e=he(e),t>>>=0,e=new Date(1e3*e),I()[t>>>2>>>0]=e.getSeconds(),I()[t+4>>>2>>>0]=e.getMinutes(),I()[t+8>>>2>>>0]=e.getHours(),I()[t+12>>>2>>>0]=e.getDate(),I()[t+16>>>2>>>0]=e.getMonth(),I()[t+20>>>2>>>0]=e.getFullYear()-1900,I()[t+24>>>2>>>0]=e.getDay();var r=(Zn(e.getFullYear())?Qn:Kn)[e.getMonth()]+e.getDate()-1|0;I()[t+28>>>2>>>0]=r,I()[t+36>>>2>>>0]=-60*e.getTimezoneOffset(),r=new Date(e.getFullYear(),6,1).getTimezoneOffset();var o=new Date(e.getFullYear(),0,1).getTimezoneOffset();e=0|(r!=o&&e.getTimezoneOffset()==Math.min(o,r)),I()[t+32>>>2>>>0]=e}function ls(e){e>>>=0;var t=new Date(I()[e+20>>>2>>>0]+1900,I()[e+16>>>2>>>0],I()[e+12>>>2>>>0],I()[e+8>>>2>>>0],I()[e+4>>>2>>>0],I()[e>>>2>>>0],0),r=I()[e+32>>>2>>>0],o=t.getTimezoneOffset(),u=new Date(t.getFullYear(),6,1).getTimezoneOffset(),l=new Date(t.getFullYear(),0,1).getTimezoneOffset(),m=Math.min(l,u);return 0>r?I()[e+32>>>2>>>0]=+(u!=l&&m==o):0<r!=(m==o)&&(u=Math.max(l,u),t.setTime(t.getTime()+6e4*((0<r?m:u)-o))),I()[e+24>>>2>>>0]=t.getDay(),r=(Zn(t.getFullYear())?Qn:Kn)[t.getMonth()]+t.getDate()-1|0,I()[e+28>>>2>>>0]=r,I()[e>>>2>>>0]=t.getSeconds(),I()[e+4>>>2>>>0]=t.getMinutes(),I()[e+8>>>2>>>0]=t.getHours(),I()[e+12>>>2>>>0]=t.getDate(),I()[e+16>>>2>>>0]=t.getMonth(),I()[e+20>>>2>>>0]=t.getYear(),e=t.getTime(),BigInt(isNaN(e)?-1:e/1e3)}function ei(e,t,r,o,u,l,m){return c?J(16,1,e,t,r,o,u,l,m):-52}function ti(e,t,r,o,u,l){if(c)return J(17,1,e,t,r,o,u,l)}var Tt={},cs=()=>performance.timeOrigin+performance.now();function ri(e,t){if(c)return J(18,1,e,t);if(Tt[e]&&(clearTimeout(Tt[e].id),delete Tt[e]),!t)return 0;var r=setTimeout(()=>{delete Tt[e],Sr(()=>Ui(e,performance.timeOrigin+performance.now()))},t);return Tt[e]={id:r,nd:t},0}function ds(e,t,r,o){e>>>=0,t>>>=0,r>>>=0,o>>>=0;var u=new Date().getFullYear(),l=new Date(u,0,1).getTimezoneOffset();u=new Date(u,6,1).getTimezoneOffset();var m=Math.max(l,u);_()[e>>>2>>>0]=60*m,I()[t>>>2>>>0]=+(l!=u),e=(t=y=>{var w=Math.abs(y);return`UTC${0<=y?"-":"+"}${String(Math.floor(w/60)).padStart(2,"0")}${String(w%60).padStart(2,"0")}`})(l),t=t(u),u<l?(Ne(e,r,17),Ne(t,o,17)):(Ne(e,o,17),Ne(t,r,17))}var ps=()=>Date.now(),ms=1;function ys(e,t,r){if(!(0<=e&&3>=e))return 28;if(e===0)e=Date.now();else{if(!ms)return 52;e=performance.timeOrigin+performance.now()}return ie[r>>>0>>>3]=BigInt(Math.round(1e6*e)),0}var Or=[],ni=(e,t)=>{Or.length=0;for(var r;r=ae()[e++>>>0];){var o=r!=105;t+=(o&=r!=112)&&t%8?4:0,Or.push(r==112?_()[t>>>2>>>0]:r==106?ie[t>>>3]:r==105?I()[t>>>2>>>0]:de()[t>>>3>>>0]),t+=o?8:4}return Or};function hs(e,t,r){return e>>>=0,t=ni(t>>>0,r>>>0),Dr[e](...t)}function bs(e,t,r){return e>>>=0,t=ni(t>>>0,r>>>0),Dr[e](...t)}var gs=()=>{};function ws(e,t){return N(ct(e>>>0,t>>>0))}var vs=()=>{throw K+=1,"unwind"};function Ts(){return 4294901760}var Cs=()=>1,Es=()=>navigator.hardwareConcurrency;function _s(){return Re("Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER"),0}function Ss(e){e>>>=0;var t=ae().length;if(e<=t||4294901760<e)return!1;for(var r=1;4>=r;r*=2){var o=t*(1+.2/r);o=Math.min(o,e+100663296);e:{o=(Math.min(4294901760,65536*Math.ceil(Math.max(e,o)/65536))-R.buffer.byteLength+65535)/65536|0;try{R.grow(o),V();var u=1;break e}catch{}u=void 0}if(u)return!0}return!1}var Wt=()=>(Re("Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER"),0),pt={},ii=e=>{e.forEach(t=>{var r=Wt();r&&(pt[r]=t)})};function As(){var e=Error().stack.toString().split(` `);return e[0]=="Error"&&e.shift(),ii(e),pt.oc=Wt(),pt.Xc=e,pt.oc}function xs(e,t,r){if(e>>>=0,t>>>=0,pt.oc==e)var o=pt.Xc;else(o=Error().stack.toString().split(` `))[0]=="Error"&&o.shift(),ii(o);for(var u=3;o[u]&&Wt()!=e;)++u;for(e=0;e<r&&o[e+u];++e)I()[t+4*e>>>2>>>0]=Wt();return e}var je=e=>{var t=Fe(e)+1,r=jt(t);return Ne(e,r,t),r},Lr=[],me=(e,t)=>{Lr[e>>>=0]=t},Ue=[],kt=[],Ct=(e,t)=>{kt[e]=new Promise(r=>t.finally(()=>r(e)))},B=e=>{if(e)return Lr[e>>>0]},Nt=(e,t,r)=>{_()[e>>>2>>>0]=t,_()[e+4>>>2>>>0]=r},oi=e=>{var t=_()[e>>>2>>>0];return e=_()[e+4>>>2>>>0],ct(t,e)},Ge=e=>{var t=_()[e>>>2>>>0];return e=_()[e+4>>>2>>>0],t?ct(t,e):e===0?"":void 0},ai=(e,t)=>{function r(u,l){u=e[u],I()[t+l>>>2>>>0]=u}function o(u,l){ie[t+l>>>3]=BigInt(e[u])}r("maxTextureDimension1D",4),r("maxTextureDimension2D",8),r("maxTextureDimension3D",12),r("maxTextureArrayLayers",16),r("maxBindGroups",20),r("maxBindGroupsPlusVertexBuffers",24),r("maxBindingsPerBindGroup",28),r("maxDynamicUniformBuffersPerPipelineLayout",32),r("maxDynamicStorageBuffersPerPipelineLayout",36),r("maxSampledTexturesPerShaderStage",40),r("maxSamplersPerShaderStage",44),r("maxStorageBuffersPerShaderStage",48),r("maxStorageTexturesPerShaderStage",52),r("maxUniformBuffersPerShaderStage",56),r("minUniformBufferOffsetAlignment",80),r("minStorageBufferOffsetAlignment",84),o("maxUniformBufferBindingSize",64),o("maxStorageBufferBindingSize",72),r("maxVertexBuffers",88),o("maxBufferSize",96),r("maxVertexAttributes",104),r("maxVertexBufferArrayStride",108),r("maxInterStageShaderVariables",112),r("maxColorAttachments",116),r("maxColorAttachmentBytesPerSample",120),r("maxComputeWorkgroupStorageSize",124),r("maxComputeInvocationsPerWorkgroup",128),r("maxComputeWorkgroupSizeX",132),r("maxComputeWorkgroupSizeY",136),r("maxComputeWorkgroupSizeZ",140),r("maxComputeWorkgroupsPerDimension",144),e.kd!==void 0&&r("maxImmediateSize",148)},Is={undefined:1,pd:1,gd:2},Os={1:"validation",2:"out-of-memory",3:"internal"},Ls=[,"compatibility","core"],Br={1:"depth-clip-control",2:"depth32float-stencil8",3:"timestamp-query",4:"texture-compression-bc",5:"texture-compression-bc-sliced-3d",6:"texture-compression-etc2",7:"texture-compression-astc",8:"texture-compression-astc-sliced-3d",9:"indirect-first-instance",10:"shader-f16",11:"rg11b10ufloat-renderable",12:"bgra8unorm-storage",13:"float32-filterable",14:"float32-blendable",15:"clip-distances",16:"dual-source-blending",17:"subgroups",18:"core-features-and-limits",327692:"chromium-experimental-unorm16-texture-formats",327693:"chromium-experimental-snorm16-texture-formats",327732:"chromium-experimental-multi-draw-indirect"},Bs=[,"low-power","high-performance"],Ms={1:"occlusion",2:"timestamp"},Us={"depth-clip-control":"1","depth32float-stencil8":"2","timestamp-query":"3","texture-compression-bc":"4","texture-compression-bc-sliced-3d":"5","texture-compression-etc2":"6","texture-compression-astc":"7","texture-compression-astc-sliced-3d":"8","indirect-first-instance":"9","shader-f16":"10","rg11b10ufloat-renderable":"11","bgra8unorm-storage":"12","float32-filterable":"13","float32-blendable":"14","clip-distances":"15","dual-source-blending":"16",md:"17","core-features-and-limits":"18","chromium-experimental-unorm16-texture-formats":"327692","chromium-experimental-snorm16-texture-formats":"327693","chromium-experimental-multi-draw-indirect":"327732"};function Ds(e,t,r,o,u,l){t=he(t),r=he(r),o>>>=0,u>>>=0,l>>>=0,e=B(e>>>0);var m={};if(l){var y=_()[l+12>>>2>>>0];if(y){var w=_()[l+16>>>2>>>0];m.requiredFeatures=Array.from(_().subarray(w>>>2>>>0,w+4*y>>>2>>>0),x=>Br[x])}var E=_()[l+20>>>2>>>0];if(E){let x=function(ee,Y,Ie=!1){Y=E+Y,(Y=_()[Y>>>2>>>0])==4294967295||Ie&&Y==0||(A[ee]=Y)},H=function(ee,Y){Y=E+Y;var Ie=_()[Y>>>2>>>0],Ke=_()[Y+4>>>2>>>0];Ie==4294967295&&Ke==4294967295||(A[ee]=4294967296*_()[Y+4>>>2>>>0]+_()[Y>>>2>>>0])};var O=x,k=H,A={};x("maxTextureDimension1D",4),x("maxTextureDimension2D",8),x("maxTextureDimension3D",12),x("maxTextureArrayLayers",16),x("maxBindGroups",20),x("maxBindGroupsPlusVertexBuffers",24),x("maxDynamicUniformBuffersPerPipelineLayout",32),x("maxDynamicStorageBuffersPerPipelineLayout",36),x("maxSampledTexturesPerShaderStage",40),x("maxSamplersPerShaderStage",44),x("maxStorageBuffersPerShaderStage",48),x("maxStorageTexturesPerShaderStage",52),x("maxUniformBuffersPerShaderStage",56),x("minUniformBufferOffsetAlignment",80),x("minStorageBufferOffsetAlignment",84),H("maxUniformBufferBindingSize",64),H("maxStorageBufferBindingSize",72),x("maxVertexBuffers",88),H("maxBufferSize",96),x("maxVertexAttributes",104),x("maxVertexBufferArrayStride",108),x("maxInterStageShaderVariables",112),x("maxColorAttachments",116),x("maxColorAttachmentBytesPerSample",120),x("maxComputeWorkgroupStorageSize",124),x("maxComputeInvocationsPerWorkgroup",128),x("maxComputeWorkgroupSizeX",132),x("maxComputeWorkgroupSizeY",136),x("maxComputeWorkgroupSizeZ",140),x("maxComputeWorkgroupsPerDimension",144),x("maxImmediateSize",148,!0),m.requiredLimits=A}(y=_()[l+24>>>2>>>0])&&(y={label:Ge(y+4)},m.defaultQueue=y),m.label=Ge(l+4)}K+=1,Ct(t,e.requestDevice(m).then(x=>{--K,me(u,x.queue),me(o,x),r&&(K+=1,Ct(r,x.lost.then(H=>{--K,x.onuncapturederror=()=>{};var ee=_e(),Y=je(H.message);Wr(r,Is[H.reason],Y),Ee(ee)}))),x.onuncapturederror=H=>{var ee=5;H.error instanceof GPUValidationError?ee=2:H.error instanceof GPUOutOfMemoryError?ee=3:H.error instanceof GPUInternalError&&(ee=4);var Y=_e();H=je(H.error.message),Oi(o,ee,H),Ee(Y)},Fr(t,1,o,0)},x=>{--K;var H=_e();x=je(x.message),Fr(t,3,o,x),r&&Wr(r,4,x),Ee(H)}))}function Ps(e){var t=B(e>>>=0),r=Ue[e];if(r){for(var o=0;o<r.length;++o)r[o]();delete Ue[e]}t.destroy()}var mt=()=>{var e="getMappedRange size=0 no longer means WGPU_WHOLE_MAP_SIZE";mt.kc||(mt.kc={}),mt.kc[e]||(mt.kc[e]=1,N(e))};function Rs(e,t,r){t>>>=0,r>>>=0;var o=B(e>>>=0);r===0&&mt(),r==4294967295&&(r=void 0);try{var u=o.getMappedRange(t,r)}catch{return 0}var l=$r(16,u.byteLength);return ae().set(new Uint8Array(u),l>>>0),Ue[e].push(()=>xe(l)),l}function Ws(e,t,r){t>>>=0,r>>>=0;var o=B(e>>>=0);r===0&&mt(),r==4294967295&&(r=void 0);try{var u=o.getMappedRange(t,r)}catch{return 0}var l=$r(16,u.byteLength);return ae().fill(0,l,u.byteLength),Ue[e].push(()=>{new Uint8Array(u).set(ae().subarray(l>>>0,l+u.byteLength>>>0)),xe(l)}),l}function ks(e,t,r,o,u){e>>>=0,t=he(t),r=he(r),u>>>=0;var l=B(e);Ue[e]=[],u==4294967295&&(u=void 0),K+=1,Ct(t,l.mapAsync(r,o>>>0,u).then(()=>{--K,kr(t,1,0)},m=>{--K,_e();var y=je(m.message);kr(t,m.name==="AbortError"?4:m.name==="OperationError"?3:0,y),delete Ue[e]}))}function Ns(e){var t=B(e>>>=0),r=Ue[e];if(r){for(var o=0;o<r.length;++o)r[o]();delete Ue[e],t.unmap()}}function Fs(e){delete Lr[e>>>0]}function js(e,t,r){e>>>=0,t>>>=0,r>>>=0;var o=!!_()[t+32>>>2>>>0];t={label:Ge(t+4),usa