UNPKG

onnxruntime-web

Version:

A Javascript library for running ONNX models on browsers

8 lines 110 kB
/*! * ONNX Runtime Web v1.26.0 * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var Pr=Object.defineProperty;var Vi=Object.getOwnPropertyDescriptor;var Hi=Object.getOwnPropertyNames;var qi=Object.prototype.hasOwnProperty;var Ur=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(t,a)=>(typeof require<"u"?require:t)[a]}):o)(function(o){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+o+'" is not supported')});var R=(o,t)=>()=>(o&&(t=o(o=0)),t);var bt=(o,t)=>{for(var a in t)Pr(o,a,{get:t[a],enumerable:!0})},Yi=(o,t,a,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Hi(t))!qi.call(o,i)&&i!==a&&Pr(o,i,{get:()=>t[i],enumerable:!(u=Vi(t,i))||u.enumerable});return o};var Ut=o=>Yi(Pr({},"__esModule",{value:!0}),o);var Rt,He,qe,Ji,bo,Rr=R(()=>{"use strict";Rt=new Map,He=[],qe=(o,t,a)=>{if(t&&typeof t.init=="function"&&typeof t.createInferenceSessionHandler=="function"){let u=Rt.get(o);if(u===void 0)Rt.set(o,{backend:t,priority:a});else{if(u.priority>a)return;if(u.priority===a&&u.backend!==t)throw new Error(`cannot register backend "${o}" using priority ${a}`)}if(a>=0){let i=He.indexOf(o);i!==-1&&He.splice(i,1);for(let c=0;c<He.length;c++)if(Rt.get(He[c]).priority<=a){He.splice(c,0,o);return}He.push(o)}return}throw new TypeError("not a valid backend")},Ji=async o=>{let t=Rt.get(o);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{let a=!!t.initPromise;try{return a||(t.initPromise=t.backend.init(o)),await t.initPromise,t.initialized=!0,t.backend}catch(u){return a||(t.error=`${u}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},bo=async o=>{let t=o.executionProviders||[],a=t.map(h=>typeof h=="string"?h:h.name),u=a.length===0?He:a,i,c=[],l=new Set;for(let h of u){let g=await Ji(h);typeof g=="string"?c.push({name:h,err:g}):(i||(i=g),i===g&&l.add(h))}if(!i)throw new Error(`no available backend found. ERR: ${c.map(h=>`[${h.name}] ${h.err}`).join(", ")}`);for(let{name:h,err:g}of c)a.includes(h)&&console.warn(`removing requested execution provider "${h}" from session options because it is not available: ${g}`);let d=t.filter(h=>l.has(typeof h=="string"?h:h.name));return[i,new Proxy(o,{get:(h,g)=>g==="executionProviders"?d:Reflect.get(h,g)})]}});var To=R(()=>{"use strict";Rr()});var vo,Eo=R(()=>{"use strict";vo="1.26.0"});var _o,ee,kr=R(()=>{"use strict";Eo();_o="warning",ee={wasm:{},webgl:{},webgpu:{},versions:{common:vo},set logLevel(o){if(o!==void 0){if(typeof o!="string"||["verbose","info","warning","error","fatal"].indexOf(o)===-1)throw new Error(`Unsupported logging level: ${o}`);_o=o}},get logLevel(){return _o}};Object.defineProperty(ee,"logLevel",{enumerable:!0})});var X,So=R(()=>{"use strict";kr();X=ee});var Ao,Io,xo=R(()=>{"use strict";Ao=(o,t)=>{let a=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);a.width=o.dims[3],a.height=o.dims[2];let u=a.getContext("2d");if(u!=null){let i,c;t?.tensorLayout!==void 0&&t.tensorLayout==="NHWC"?(i=o.dims[2],c=o.dims[3]):(i=o.dims[3],c=o.dims[2]);let l=t?.format!==void 0?t.format:"RGB",d=t?.norm,h,g;d===void 0||d.mean===void 0?h=[255,255,255,255]:typeof d.mean=="number"?h=[d.mean,d.mean,d.mean,d.mean]:(h=[d.mean[0],d.mean[1],d.mean[2],0],d.mean[3]!==void 0&&(h[3]=d.mean[3])),d===void 0||d.bias===void 0?g=[0,0,0,0]:typeof d.bias=="number"?g=[d.bias,d.bias,d.bias,d.bias]:(g=[d.bias[0],d.bias[1],d.bias[2],0],d.bias[3]!==void 0&&(g[3]=d.bias[3]));let w=c*i,b=0,v=w,E=w*2,O=-1;l==="RGBA"?(b=0,v=w,E=w*2,O=w*3):l==="RGB"?(b=0,v=w,E=w*2):l==="RBG"&&(b=0,E=w,v=w*2);for(let P=0;P<c;P++)for(let j=0;j<i;j++){let L=(o.data[b++]-g[0])*h[0],x=(o.data[v++]-g[1])*h[1],U=(o.data[E++]-g[2])*h[2],M=O===-1?255:(o.data[O++]-g[3])*h[3];u.fillStyle="rgba("+L+","+x+","+U+","+M+")",u.fillRect(j,P,1,1)}if("toDataURL"in a)return a.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},Io=(o,t)=>{let a=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),u;if(a!=null){let i,c,l;t?.tensorLayout!==void 0&&t.tensorLayout==="NHWC"?(i=o.dims[2],c=o.dims[1],l=o.dims[3]):(i=o.dims[3],c=o.dims[2],l=o.dims[1]);let d=t!==void 0&&t.format!==void 0?t.format:"RGB",h=t?.norm,g,w;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?w=[0,0,0,0]:typeof h.bias=="number"?w=[h.bias,h.bias,h.bias,h.bias]:(w=[h.bias[0],h.bias[1],h.bias[2],0],h.bias[3]!==void 0&&(w[3]=h.bias[3]));let b=c*i;if(t!==void 0&&(t.format!==void 0&&l===4&&t.format!=="RGBA"||l===3&&t.format!=="RGB"&&t.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let v=4,E=0,O=1,P=2,j=3,L=0,x=b,U=b*2,M=-1;d==="RGBA"?(L=0,x=b,U=b*2,M=b*3):d==="RGB"?(L=0,x=b,U=b*2):d==="RBG"&&(L=0,U=b,x=b*2),u=a.createImageData(i,c);for(let F=0;F<c*i;E+=v,O+=v,P+=v,j+=v,F++)u.data[E]=(o.data[L++]-w[0])*g[0],u.data[O]=(o.data[x++]-w[1])*g[1],u.data[P]=(o.data[U++]-w[2])*g[2],u.data[j]=M===-1?255:(o.data[M++]-w[3])*g[3]}else throw new Error("Can not access image data");return u}});var Nr,Oo,Lo,Bo,Co,Mo,Do=R(()=>{"use strict";kt();Nr=(o,t)=>{if(o===void 0)throw new Error("Image buffer must be defined");if(t.height===void 0||t.width===void 0)throw new Error("Image height and width must be defined");if(t.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:a,width:u}=t,i=t.norm??{mean:255,bias:0},c,l;typeof i.mean=="number"?c=[i.mean,i.mean,i.mean,i.mean]:c=[i.mean[0],i.mean[1],i.mean[2],i.mean[3]??255],typeof i.bias=="number"?l=[i.bias,i.bias,i.bias,i.bias]:l=[i.bias[0],i.bias[1],i.bias[2],i.bias[3]??0];let d=t.format!==void 0?t.format:"RGBA",h=t.tensorFormat!==void 0&&t.tensorFormat!==void 0?t.tensorFormat:"RGB",g=a*u,w=h==="RGBA"?new Float32Array(g*4):new Float32Array(g*3),b=4,v=0,E=1,O=2,P=3,j=0,L=g,x=g*2,U=-1;d==="RGB"&&(b=3,v=0,E=1,O=2,P=-1),h==="RGBA"?U=g*3:h==="RBG"?(j=0,x=g,L=g*2):h==="BGR"&&(x=0,L=g,j=g*2);for(let F=0;F<g;F++,v+=b,O+=b,E+=b,P+=b)w[j++]=(o[v]+l[0])/c[0],w[L++]=(o[E]+l[1])/c[1],w[x++]=(o[O]+l[2])/c[2],U!==-1&&P!==-1&&(w[U++]=(o[P]+l[3])/c[3]);return h==="RGBA"?new oe("float32",w,[1,4,a,u]):new oe("float32",w,[1,3,a,u])},Oo=async(o,t)=>{let a=typeof HTMLImageElement<"u"&&o instanceof HTMLImageElement,u=typeof ImageData<"u"&&o instanceof ImageData,i=typeof ImageBitmap<"u"&&o instanceof ImageBitmap,c=typeof o=="string",l,d=t??{},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=w=>typeof HTMLCanvasElement<"u"&&w instanceof HTMLCanvasElement||w instanceof OffscreenCanvas?w.getContext("2d"):null;if(a){let w=h();w.width=o.width,w.height=o.height;let b=g(w);if(b!=null){let v=o.height,E=o.width;if(t!==void 0&&t.resizedHeight!==void 0&&t.resizedWidth!==void 0&&(v=t.resizedHeight,E=t.resizedWidth),t!==void 0){if(d=t,t.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");d.tensorFormat="RGBA",d.height=v,d.width=E}else d.tensorFormat="RGBA",d.height=v,d.width=E;b.drawImage(o,0,0),l=b.getImageData(0,0,E,v).data}else throw new Error("Can not access image data")}else if(u){let w,b;if(t!==void 0&&t.resizedWidth!==void 0&&t.resizedHeight!==void 0?(w=t.resizedHeight,b=t.resizedWidth):(w=o.height,b=o.width),t!==void 0&&(d=t),d.format="RGBA",d.height=w,d.width=b,t!==void 0){let v=h();v.width=b,v.height=w;let E=g(v);if(E!=null)E.putImageData(o,0,0),l=E.getImageData(0,0,b,w).data;else throw new Error("Can not access image data")}else l=o.data}else if(i){if(t===void 0)throw new Error("Please provide image config with format for Imagebitmap");let w=h();w.width=o.width,w.height=o.height;let b=g(w);if(b!=null){let v=o.height,E=o.width;return b.drawImage(o,0,0,E,v),l=b.getImageData(0,0,E,v).data,d.height=v,d.width=E,Nr(l,d)}else throw new Error("Can not access image data")}else{if(c)return new Promise((w,b)=>{let v=h(),E=g(v);if(!o||!E)return b();let O=new Image;O.crossOrigin="Anonymous",O.src=o,O.onload=()=>{v.width=O.width,v.height=O.height,E.drawImage(O,0,0,v.width,v.height);let P=E.getImageData(0,0,v.width,v.height);d.height=v.height,d.width=v.width,w(Nr(P.data,d))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(l!==void 0)return Nr(l,d);throw new Error("Input data provided is not supported - aborted tensor creation")},Lo=(o,t)=>{let{width:a,height:u,download:i,dispose:c}=t,l=[1,u,a,4];return new oe({location:"texture",type:"float32",texture:o,dims:l,download:i,dispose:c})},Bo=(o,t)=>{let{dataType:a,dims:u,download:i,dispose:c}=t;return new oe({location:"gpu-buffer",type:a??"float32",gpuBuffer:o,dims:u,download:i,dispose:c})},Co=(o,t)=>{let{dataType:a,dims:u,download:i,dispose:c}=t;return new oe({location:"ml-tensor",type:a??"float32",mlTensor:o,dims:u,download:i,dispose:c})},Mo=(o,t,a)=>new oe({location:"cpu-pinned",type:o,data:t,dims:a??[t.length]})});var Ye,Tt,Po,Uo,Ro=R(()=>{"use strict";Ye=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),Tt=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Po=!1,Uo=()=>{if(!Po){Po=!0;let o=typeof BigInt64Array<"u"&&BigInt64Array.from,t=typeof BigUint64Array<"u"&&BigUint64Array.from,a=globalThis.Float16Array,u=typeof a<"u"&&a.from;o&&(Ye.set("int64",BigInt64Array),Tt.set(BigInt64Array,"int64")),t&&(Ye.set("uint64",BigUint64Array),Tt.set(BigUint64Array,"uint64")),u?(Ye.set("float16",a),Tt.set(a,"float16")):Ye.set("float16",Uint16Array)}}});var ko,No,Wo=R(()=>{"use strict";kt();ko=o=>{let t=1;for(let a=0;a<o.length;a++){let u=o[a];if(typeof u!="number"||!Number.isSafeInteger(u))throw new TypeError(`dims[${a}] must be an integer, got: ${u}`);if(u<0)throw new RangeError(`dims[${a}] must be a non-negative integer, got: ${u}`);t*=u}return t},No=(o,t)=>{switch(o.location){case"cpu":return new oe(o.type,o.data,t);case"cpu-pinned":return new oe({location:"cpu-pinned",data:o.data,type:o.type,dims:t});case"texture":return new oe({location:"texture",texture:o.texture,type:o.type,dims:t});case"gpu-buffer":return new oe({location:"gpu-buffer",gpuBuffer:o.gpuBuffer,type:o.type,dims:t});case"ml-tensor":return new oe({location:"ml-tensor",mlTensor:o.mlTensor,type:o.type,dims:t});default:throw new Error(`tensorReshape: tensor location ${o.location} is not supported`)}}});var oe,kt=R(()=>{"use strict";xo();Do();Ro();Wo();oe=class{constructor(t,a,u){Uo();let i,c;if(typeof t=="object"&&"location"in t)switch(this.dataLocation=t.location,i=t.type,c=t.dims,t.location){case"cpu-pinned":{let d=Ye.get(i);if(!d)throw new TypeError(`unsupported type "${i}" to create tensor from pinned buffer`);if(!(t.data instanceof d))throw new TypeError(`buffer should be of type ${d.name}`);this.cpuData=t.data;break}case"texture":{if(i!=="float32")throw new TypeError(`unsupported type "${i}" to create tensor from texture`);this.gpuTextureData=t.texture,this.downloader=t.download,this.disposer=t.dispose;break}case"gpu-buffer":{if(i!=="float32"&&i!=="float16"&&i!=="int32"&&i!=="int64"&&i!=="uint32"&&i!=="uint8"&&i!=="bool"&&i!=="uint4"&&i!=="int4")throw new TypeError(`unsupported type "${i}" to create tensor from gpu buffer`);this.gpuBufferData=t.gpuBuffer,this.downloader=t.download,this.disposer=t.dispose;break}case"ml-tensor":{if(i!=="float32"&&i!=="float16"&&i!=="int32"&&i!=="int64"&&i!=="uint32"&&i!=="uint64"&&i!=="int8"&&i!=="uint8"&&i!=="bool"&&i!=="uint4"&&i!=="int4")throw new TypeError(`unsupported type "${i}" to create tensor from MLTensor`);this.mlTensorData=t.mlTensor,this.downloader=t.download,this.disposer=t.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let d,h;if(typeof t=="string")if(i=t,h=u,t==="string"){if(!Array.isArray(a))throw new TypeError("A string tensor's data must be a string array.");d=a}else{let g=Ye.get(t);if(g===void 0)throw new TypeError(`Unsupported tensor type: ${t}.`);if(Array.isArray(a)){if(t==="float16"&&g===Uint16Array||t==="uint4"||t==="int4")throw new TypeError(`Creating a ${t} tensor from number array is not supported. Please use ${g.name} as data.`);t==="uint64"||t==="int64"?d=g.from(a,BigInt):d=g.from(a)}else if(a instanceof g)d=a;else if(a instanceof Uint8ClampedArray)if(t==="uint8")d=Uint8Array.from(a);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else if(t==="float16"&&a instanceof Uint16Array&&g!==Uint16Array)d=new globalThis.Float16Array(a.buffer,a.byteOffset,a.length);else throw new TypeError(`A ${i} tensor's data must be type of ${g}`)}else if(h=a,Array.isArray(t)){if(t.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let g=typeof t[0];if(g==="string")i="string",d=t;else if(g==="boolean")i="bool",d=Uint8Array.from(t);else throw new TypeError(`Invalid element type of data array: ${g}.`)}else if(t instanceof Uint8ClampedArray)i="uint8",d=Uint8Array.from(t);else{let g=Tt.get(t.constructor);if(g===void 0)throw new TypeError(`Unsupported type for tensor data: ${t.constructor}.`);i=g,d=t}if(h===void 0)h=[d.length];else if(!Array.isArray(h))throw new TypeError("A tensor's dims must be a number array");c=h,this.cpuData=d,this.dataLocation="cpu"}let l=ko(c);if(this.cpuData&&l!==this.cpuData.length&&!((i==="uint4"||i==="int4")&&Math.ceil(l/2)===this.cpuData.length))throw new Error(`Tensor's size(${l}) does not match data length(${this.cpuData.length}).`);this.type=i,this.dims=c,this.size=l}static async fromImage(t,a){return Oo(t,a)}static fromTexture(t,a){return Lo(t,a)}static fromGpuBuffer(t,a){return Bo(t,a)}static fromMLTensor(t,a){return Co(t,a)}static fromPinnedBuffer(t,a,u){return Mo(t,a,u)}toDataURL(t){return Ao(this,t)}toImageData(t){return Io(this,t)}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(t){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 a=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=a,t&&this.disposer&&(this.disposer(),this.disposer=void 0),a}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(t){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return No(this,t)}}});var ve,Wr=R(()=>{"use strict";kt();ve=oe});var Fo,Go,Je,Xe,Re,ke,Fr=R(()=>{"use strict";kr();Fo=(o,t)=>{(typeof ee.trace>"u"?!ee.wasm.trace:!ee.trace)||console.timeStamp(`${o}::ORT::${t}`)},Go=(o,t)=>{let a=new Error().stack?.split(/\r\n|\r|\n/g)||[],u=!1;for(let i=0;i<a.length;i++){if(u&&!a[i].includes("TRACE_FUNC")){let c=`FUNC_${o}::${a[i].trim().split(" ")[1]}`;t&&(c+=`::${t}`),Fo("CPU",c);return}a[i].includes("TRACE_FUNC")&&(u=!0)}},Je=o=>{(typeof ee.trace>"u"?!ee.wasm.trace:!ee.trace)||Go("BEGIN",o)},Xe=o=>{(typeof ee.trace>"u"?!ee.wasm.trace:!ee.trace)||Go("END",o)},Re=o=>{(typeof ee.trace>"u"?!ee.wasm.trace:!ee.trace)||console.time(`ORT::${o}`)},ke=o=>{(typeof ee.trace>"u"?!ee.wasm.trace:!ee.trace)||console.timeEnd(`ORT::${o}`)}});var Nt,$o=R(()=>{"use strict";Rr();Wr();Fr();Nt=class o{constructor(t){this.handler=t}async run(t,a,u){Je(),Re("InferenceSession.run");let i={},c={};if(typeof t!="object"||t===null||t instanceof ve||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let l=!0;if(typeof a=="object"){if(a===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(a instanceof ve)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(a)){if(a.length===0)throw new TypeError("'fetches' cannot be an empty array.");l=!1;for(let g of a){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}.`);i[g]=null}if(typeof u=="object"&&u!==null)c=u;else if(typeof u<"u")throw new TypeError("'options' must be an object.")}else{let g=!1,w=Object.getOwnPropertyNames(a);for(let b of this.outputNames)if(w.indexOf(b)!==-1){let v=a[b];(v===null||v instanceof ve)&&(g=!0,l=!1,i[b]=v)}if(g){if(typeof u=="object"&&u!==null)c=u;else if(typeof u<"u")throw new TypeError("'options' must be an object.")}else c=a}}else if(typeof a<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let g of this.inputNames)if(typeof t[g]>"u")throw new Error(`input '${g}' is missing in 'feeds'.`);if(l)for(let g of this.outputNames)i[g]=null;let d=await this.handler.run(t,i,c),h={};for(let g in d)if(Object.hasOwnProperty.call(d,g)){let w=d[g];w instanceof ve?h[g]=w:h[g]=new ve(w.type,w.data,w.dims)}return ke("InferenceSession.run"),Xe(),h}async release(){return this.handler.dispose()}static async create(t,a,u,i){Je(),Re("InferenceSession.create");let c,l={};if(typeof t=="string"){if(c=t,typeof a=="object"&&a!==null)l=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof Uint8Array){if(c=t,typeof a=="object"&&a!==null)l=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer){let w=t,b=0,v=t.byteLength;if(typeof a=="object"&&a!==null)l=a;else if(typeof a=="number"){if(b=a,!Number.isSafeInteger(b))throw new RangeError("'byteOffset' must be an integer.");if(b<0||b>=w.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${w.byteLength}).`);if(v=t.byteLength-b,typeof u=="number"){if(v=u,!Number.isSafeInteger(v))throw new RangeError("'byteLength' must be an integer.");if(v<=0||b+v>w.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${w.byteLength-b}].`);if(typeof i=="object"&&i!==null)l=i;else if(typeof i<"u")throw new TypeError("'options' must be an object.")}else if(typeof u<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof a<"u")throw new TypeError("'options' must be an object.");c=new Uint8Array(w,b,v)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[d,h]=await bo(l),g=await d.createInferenceSessionHandler(c,h);return ke("InferenceSession.create"),Xe(),new o(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 Xi,zo=R(()=>{"use strict";$o();Xi=Nt});var jo=R(()=>{"use strict"});var Vo=R(()=>{"use strict"});var Ho=R(()=>{"use strict"});var qo=R(()=>{"use strict"});var Gr={};bt(Gr,{InferenceSession:()=>Xi,TRACE:()=>Fo,TRACE_EVENT_BEGIN:()=>Re,TRACE_EVENT_END:()=>ke,TRACE_FUNC_BEGIN:()=>Je,TRACE_FUNC_END:()=>Xe,Tensor:()=>ve,env:()=>X,registerBackend:()=>qe});var Ne=R(()=>{"use strict";To();So();zo();Wr();jo();Vo();Fr();Ho();qo()});var Wt=R(()=>{"use strict"});var Zo={};bt(Zo,{default:()=>Zi});var Jo,Xo,Zi,Qo=R(()=>{"use strict";$r();We();Ft();Jo="ort-wasm-proxy-worker",Xo=globalThis.self?.name===Jo;Xo&&(self.onmessage=o=>{let{type:t,in:a}=o.data;try{switch(t){case"init-wasm":Gt(a.wasm).then(()=>{$t(a).then(()=>{postMessage({type:t})},u=>{postMessage({type:t,err:u})})},u=>{postMessage({type:t,err:u})});break;case"init-ep":{let{epName:u,env:i}=a;zt(i,u).then(()=>{postMessage({type:t})},c=>{postMessage({type:t,err:c})});break}case"copy-from":{let{buffer:u}=a,i=vt(u);postMessage({type:t,out:i});break}case"create":{let{model:u,options:i}=a;jt(u,i).then(c=>{postMessage({type:t,out:c})},c=>{postMessage({type:t,err:c})});break}case"release":Vt(a),postMessage({type:t});break;case"run":{let{sessionId:u,inputIndices:i,inputs:c,outputIndices:l,options:d}=a;Ht(u,i,c,l,new Array(l.length).fill(null),d).then(h=>{h.some(g=>g[3]!=="cpu")?postMessage({type:t,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:t,out:h},Yt([...c,...h]))},h=>{postMessage({type:t,err:h})});break}case"end-profiling":qt(a),postMessage({type:t});break;default:}}catch(u){postMessage({type:t,err:u})}});Zi=Xo?null:o=>new Worker(o??ge,{type:"module",name:Jo})});var ea={};bt(ea,{default:()=>Qi});async function Ko(o={}){var t=o,a=!!globalThis.window,u=!!globalThis.WorkerGlobalScope,i=u&&self.name?.startsWith("em-pthread");t.mountExternalData=(e,r)=>{e.startsWith("./")&&(e=e.substring(2)),(t.o||(t.o=new Map)).set(e,r)},t.unmountExternalData=()=>{delete t.o},globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,shared:!0}).buffer.constructor;var c,l,d=(e,r)=>{throw r},h=import.meta.url,g="";if(a||u){try{g=new URL(".",h).href}catch{}u&&(l=e=>{var r=new XMLHttpRequest;return r.open("GET",e,!1),r.responseType="arraybuffer",r.send(null),new Uint8Array(r.response)}),c=async e=>{if(F(e))return new Promise((n,s)=>{var f=new XMLHttpRequest;f.open("GET",e,!0),f.responseType="arraybuffer",f.onload=()=>{f.status==200||f.status==0&&f.response?n(f.response):s(f.status)},f.onerror=s,f.send(null)});var r=await fetch(e,{credentials:"same-origin"});if(r.ok)return r.arrayBuffer();throw Error(r.status+" : "+r.url)}}var w,b,v,E,O,P,j=console.log.bind(console),L=console.error.bind(console),x=j,U=L,M=!1,F=e=>e.startsWith("file://");function p(){Ue.buffer!=H.buffer&&q()}if(i){var te=!1;async function e(r){try{var n=r.data,s=n.i;if(s==="load"){let f=[];self.onmessage=m=>f.push(m),P=()=>{postMessage({i:"loaded"});for(let m of f)e(m);self.onmessage=e};for(let m of n.H)t[m]&&!t[m].proxy||(t[m]=(...T)=>{postMessage({i:"callHandler",G:m,args:T})},m=="print"&&(x=t[m]),m=="printErr"&&(U=t[m]));Ue=n.N,q(),b=n.O,$e(),Pt()}else if(s==="run"){(function(f){var m=(p(),_)[f+52>>>2>>>0];f=(p(),_)[f+56>>>2>>>0],yo(m,m-f),de(m)})(n.h),Lr(n.h,0,0,1,0,0),on(),hr(n.h),te||(Zn(),te=!0);try{await Ga(n.L,n.u)}catch(f){if(f!="unwind")throw f}}else n.target!=="setimmediate"&&(s==="checkMailbox"?te&&Ot():s&&(U(`worker: received unknown command ${s}`),U(n)))}catch(f){throw co(),f}}self.onunhandledrejection=r=>{throw r.reason||r},self.onmessage=e}var H,G,se,De,S,_,Ge,B,Z,nt,V,le=!1;function q(){var e=Ue.buffer;t.HEAP8=H=new Int8Array(e),se=new Int16Array(e),t.HEAPU8=G=new Uint8Array(e),De=new Uint16Array(e),t.HEAP32=S=new Int32Array(e),t.HEAPU32=_=new Uint32Array(e),Ge=new Float32Array(e),B=new Float64Array(e),Z=new BigInt64Array(e),nt=new BigUint64Array(e)}function K(){le=!0,i?P():Me.__wasm_call_ctors()}function ot(e){throw U(e="Aborted("+e+")"),M=!0,e+=". Build with -sASSERTIONS for more info.",le&&go(),e=new WebAssembly.RuntimeError(e),O?.(e),e}function at(){if(!(wt={__pthread_create_js:fn,__syscall_fcntl64:dn,__syscall_fstat64:mn,__syscall_getcwd:hn,__syscall_getdents64:gn,__syscall_ioctl:yn,__syscall_lstat64:wn,__syscall_mkdirat:bn,__syscall_newfstatat:Tn,__syscall_openat:vn,__syscall_readlinkat:En,__syscall_rmdir:_n,__syscall_stat64:Sn,__syscall_unlinkat:An,_abort_js:$a,_embind_register_bigint:ja,_embind_register_bool:Va,_embind_register_emval:qa,_embind_register_float:Ja,_embind_register_integer:Xa,_embind_register_memory_view:Za,_embind_register_std_string:Qa,_embind_register_std_wstring:as,_embind_register_void:ss,_emscripten_init_main_thread_js:is,_emscripten_notify_mailbox_postmessage:fs,_emscripten_receive_on_main_thread_js:cs,_emscripten_runtime_keepalive_clear:ls,_emscripten_thread_cleanup:ps,_emscripten_thread_mailbox_await:hr,_emscripten_thread_set_strongref:ds,_emval_await:Bn,_emval_create_invoker:bs,_emval_decref:dr,_emval_equals:Ts,_emval_get_global:vs,_emval_get_module_property:Es,_emval_get_property:_s,_emval_incref:Ss,_emval_invoke:Cn,_emval_invoke_i64:As,_emval_new_array:Is,_emval_new_array_from_memory_view:xs,_emval_new_cstring:Os,_emval_new_object:Ls,_emval_run_destructors:Bs,_emval_set_property:Cs,_gmtime_js:Ms,_localtime_js:Ds,_mktime_js:Ps,_mmap_js:Un,_munmap_js:Rn,_setitimer_js:kn,_tzset_js:Rs,clock_time_get:Ws,emscripten_asm_const_int:Fs,emscripten_asm_const_ptr:Gs,emscripten_check_blocking_allowed:$s,emscripten_date_now:ks,emscripten_errn:zs,emscripten_exit_with_live_runtime:js,emscripten_get_heap_max:Vs,emscripten_get_now:Us,emscripten_has_asyncify:Hs,emscripten_num_logical_cores:qs,emscripten_resize_heap:Ys,emwgpuAdapterRequestDevice:ni,emwgpuBufferDestroy:oi,emwgpuBufferGetConstMappedRange:ai,emwgpuBufferGetMappedRange:si,emwgpuBufferMapAsync:ii,emwgpuBufferUnmap:ui,emwgpuDelete:fi,emwgpuDeviceCreateBuffer:ci,emwgpuDeviceCreateComputePipelineAsync:li,emwgpuDeviceCreateShaderModule:pi,emwgpuDeviceDestroy:di,emwgpuDevicePopErrorScope:mi,emwgpuInstanceRequestAdapter:hi,emwgpuWaitAny:$n,environ_get:jn,environ_sizes_get:Vn,exit:fr,fd_close:Hn,fd_read:qn,fd_seek:Yn,fd_write:Jn,memory:Ue,proc_exit:ze,wgpuAdapterGetLimits:yi,wgpuAdapterHasFeature:wi,wgpuBufferGetSize:bi,wgpuBufferGetUsage:Ti,wgpuCommandEncoderBeginComputePass:vi,wgpuCommandEncoderClearBuffer:Ei,wgpuCommandEncoderCopyBufferToBuffer:_i,wgpuCommandEncoderFinish:Si,wgpuCommandEncoderResolveQuerySet:Ai,wgpuComputePassEncoderDispatchWorkgroups:Ii,wgpuComputePassEncoderDispatchWorkgroupsIndirect:xi,wgpuComputePassEncoderEnd:Oi,wgpuComputePassEncoderSetBindGroup:Li,wgpuComputePassEncoderSetPipeline:Bi,wgpuComputePassEncoderWriteTimestamp:Ci,wgpuComputePipelineGetBindGroupLayout:Mi,wgpuDeviceCreateBindGroup:Di,wgpuDeviceCreateCommandEncoder:Pi,wgpuDeviceCreateQuerySet:Ui,wgpuDeviceGetAdapterInfo:Ri,wgpuDeviceGetFeatures:Ni,wgpuDeviceGetLimits:Wi,wgpuDevicePushErrorScope:Fi,wgpuQueueSubmit:Gi,wgpuQueueWriteBuffer:$i}).F){wt.F=!0;var e=wt,r=/^(invoke_.*|__asyncjs__.*)$/;for(let[n,s]of Object.entries(e))typeof s=="function"&&(s.v||r.test(n))&&(e[n]=s=new WebAssembly.Suspending(s))}return{env:wt,wasi_snapshot_preview1:wt}}async function $e(){function e(s,f){s=Me=s.exports;var m=/^(OrtAppendExecutionProvider|OrtCreateSession|OrtRun|OrtRunWithBinding|OrtBindInput|main|__main_argc_argv)$/;yr=new Set;var T={};for(let[y,A]of Object.entries(s))typeof A=="function"?(m.test(y)&&(yr.add(A),A=WebAssembly.promising(A)),T[y]=ms(A)):T[y]=A;return Me=T,Me=function(){var y=Me,A=z=>J=>z(J)>>>0,C=z=>()=>z()>>>0;return(y=Object.assign({},y)).__getTypeName=A(y.__getTypeName),y.pthread_self=C(y.pthread_self),y.malloc=A(y.malloc),y.memalign=(z=>(J,ie)=>z(J,ie)>>>0)(y.memalign),y._emscripten_stack_alloc=A(y._emscripten_stack_alloc),y.emscripten_stack_get_current=C(y.emscripten_stack_get_current),y}(),rn.push(Me._emscripten_tls_init),Xn=(s=Me).__getTypeName,Zn=s._embind_initialize_bindings,t._OrtInit=s.OrtInit,t._OrtGetLastError=s.OrtGetLastError,t._OrtCreateSessionOptions=s.OrtCreateSessionOptions,t._OrtAppendExecutionProvider=s.OrtAppendExecutionProvider,t._OrtAddFreeDimensionOverride=s.OrtAddFreeDimensionOverride,t._OrtAddSessionConfigEntry=s.OrtAddSessionConfigEntry,t._OrtReleaseSessionOptions=s.OrtReleaseSessionOptions,t._OrtCreateSession=s.OrtCreateSession,t._OrtReleaseSession=s.OrtReleaseSession,t._OrtGetInputOutputCount=s.OrtGetInputOutputCount,t._OrtGetInputOutputMetadata=s.OrtGetInputOutputMetadata,t._OrtFree=s.OrtFree,t._OrtCreateTensor=s.OrtCreateTensor,t._OrtGetTensorData=s.OrtGetTensorData,t._OrtReleaseTensor=s.OrtReleaseTensor,t._OrtCreateRunOptions=s.OrtCreateRunOptions,t._OrtAddRunConfigEntry=s.OrtAddRunConfigEntry,t._OrtReleaseRunOptions=s.OrtReleaseRunOptions,t._OrtCreateBinding=s.OrtCreateBinding,t._OrtBindInput=s.OrtBindInput,t._OrtBindOutput=s.OrtBindOutput,t._OrtClearBoundOutputs=s.OrtClearBoundOutputs,t._OrtReleaseBinding=s.OrtReleaseBinding,t._OrtRunWithBinding=s.OrtRunWithBinding,t._OrtRun=s.OrtRun,t._OrtEndProfiling=s.OrtEndProfiling,_r=t._OrtGetWebGpuDevice=s.OrtGetWebGpuDevice,Mt=s.pthread_self,Ie=t._free=s.free,gt=t._malloc=s.malloc,Qn=t._wgpuBufferRelease=s.wgpuBufferRelease,Kn=t._wgpuCreateInstance=s.wgpuCreateInstance,eo=s.emwgpuCreateBindGroup,to=s.emwgpuCreateBindGroupLayout,ro=s.emwgpuCreateCommandBuffer,no=s.emwgpuCreateCommandEncoder,oo=s.emwgpuCreateComputePassEncoder,ao=s.emwgpuCreateQuerySet,so=s.emwgpuCreateBuffer,io=s.emwgpuCreateDevice,uo=s.emwgpuCreateQueue,Sr=s.emwgpuOnCreateComputePipelineCompleted,Ar=s.emwgpuOnDeviceLostCompleted,Ir=s.emwgpuOnMapAsyncCompleted,xr=s.emwgpuOnPopErrorScopeCompleted,yt=s.emwgpuOnRequestAdapterCompleted,Or=s.emwgpuOnRequestDeviceCompleted,fo=s.emwgpuOnUncapturedError,Lr=s._emscripten_thread_init,co=s._emscripten_thread_crashed,lo=s._emscripten_run_js_on_main_thread,po=s._emscripten_thread_free_data,Br=s._emscripten_thread_exit,mo=s._emscripten_timeout,ho=s._emscripten_check_mailbox,Cr=s.memalign,go=s.__trap,yo=s.emscripten_stack_set_limits,de=s._emscripten_stack_restore,Dt=s._emscripten_stack_alloc,me=s.emscripten_stack_get_current,wo=s.__indirect_function_table,b=f,Me}var r,n=at();return t.instantiateWasm?new Promise(s=>{t.instantiateWasm(n,(f,m)=>{s(e(f,m))})}):i?e(new WebAssembly.Instance(b,at()),b):(V??=t.locateFile?t.locateFile?t.locateFile("ort-wasm-simd-threaded.jspi.wasm",g):g+"ort-wasm-simd-threaded.jspi.wasm":new URL("ort-wasm-simd-threaded.jspi.wasm",import.meta.url).href,r=await async function(s){var f=V;if(!w&&!F(f))try{var m=fetch(f,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(m,s)}catch(T){U(`wasm streaming compile failed: ${T}`),U("falling back to ArrayBuffer instantiation")}return async function(T,y){try{var A=await async function(C){if(!w)try{var z=await c(C);return new Uint8Array(z)}catch{}if(C==V&&w)C=new Uint8Array(w);else{if(!l)throw"both async and sync fetching of the wasm failed";C=l(C)}return C}(T);return await WebAssembly.instantiate(A,y)}catch(C){U(`failed to asynchronously prepare wasm: ${C}`),ot(C)}}(f,s)}(n),e(r.instance,r.module))}class st{name="ExitStatus";constructor(r){this.message=`Program terminated with exit(${r})`,this.status=r}}var xt=e=>{e.terminate(),e.onmessage=()=>{}},Ee=()=>{for(var e=be;0<e.length;)e.shift()(t)},be=[],_e=0,Q=null,Y=e=>{Pe.length==0&&(sn(),an(Pe[0]));var r=Pe.pop();if(!r)return 6;dt.push(r),je[e.h]=r,r.h=e.h;var n={i:"run",L:e.K,u:e.u,h:e.h};return r.postMessage(n,e.A),0},k=0,$=(e,r,...n)=>{var s,f=16*n.length,m=me(),T=Dt(f),y=T>>>3;for(s of n)typeof s=="bigint"?((p(),Z)[y++>>>0]=1n,(p(),Z)[y++>>>0]=s):((p(),Z)[y++>>>0]=0n,(p(),B)[y++>>>0]=s);return e=lo(e,0,f,T,r),de(m),e};function ze(e){if(i)return $(0,1,e);if(v=e,!(0<k)){for(var r of dt)xt(r);for(r of Pe)xt(r);Pe=[],dt=[],je={},M=!0}d(0,new st(e))}function ur(e){if(i)return $(1,0,e);fr(e)}var fr=e=>{if(v=e,i)throw ur(e),"unwind";ze(e)},Pe=[],dt=[],rn=[],je={},nn=e=>{var r=e.h;delete je[r],Pe.push(e),dt.splice(dt.indexOf(e),1),e.h=0,po(r)};function on(){rn.forEach(e=>e())}var an=e=>new Promise(r=>{e.onmessage=f=>{var m=f.data;if(f=m.i,m.s&&m.s!=Mt()){var T=je[m.s];T?T.postMessage(m,m.A):U(`Internal error! Worker sent a message "${f}" to target pthread ${m.s}, but that thread no longer exists!`)}else f==="checkMailbox"?Ot():f==="spawnThread"?Y(m):f==="cleanupThread"?pe(()=>{nn(je[m.M])}):f==="loaded"?(e.loaded=!0,r(e)):m.target==="setimmediate"?e.postMessage(m):f==="uncaughtException"?e.onerror(m.error):f==="callHandler"?t[m.G](...m.args):f&&U(`worker sent an unknown command ${f}`)},e.onerror=f=>{throw U(`worker sent an error! ${f.filename}:${f.lineno}: ${f.message}`),f};var n,s=[];for(n of[])t.propertyIsEnumerable(n)&&s.push(n);e.postMessage({i:"load",H:s,N:Ue,O:b})});function sn(){var e=new Worker((()=>{let r=URL;return import.meta.url>"file:"&&import.meta.url<"file;"?new r("ort.jspi.bundle.min.mjs",import.meta.url):new URL(import.meta.url)})(),{type:"module",workerData:"em-pthread",name:"em-pthread"});Pe.push(e)}var Ue,cr=[],Ga=async(e,r)=>{k=0;var n=WebAssembly,s=n.promising,f=cr[e];f||(cr[e]=f=wo.get(e),yr?.has(f)&&(cr[e]=f=WebAssembly.promising(f))),e=s.call(n,f)(r),e=await e,0<k?v=e:Br(e)};function un(e,r,n,s){return i?$(2,1,e,r,n,s):fn(e,r,n,s)}var re=e=>-9007199254740992>e||9007199254740992<e?NaN:Number(e);function fn(e,r,n,s){if(e>>>=0,r>>>=0,n>>>=0,s>>>=0,!globalThis.SharedArrayBuffer)return 6;var f=[];return i&&f.length===0?un(e,r,n,s):(e={K:n,h:e,u:s,A:f},i?(e.i="spawnThread",postMessage(e,f),0):Y(e))}var cn=globalThis.TextDecoder&&new TextDecoder,ln=(e,r,n,s)=>{if(n=r+n,s)return n;for(;e[r]&&!(r>=n);)++r;return r},pn=(e,r=0,n,s)=>{if(16<(n=ln(e,r>>>=0,n,s))-r&&e.buffer&&cn)return cn.decode(e.buffer instanceof ArrayBuffer?e.subarray(r,n):e.slice(r,n));for(s="";r<n;){var f=e[r++];if(128&f){var m=63&e[r++];if((224&f)==192)s+=String.fromCharCode((31&f)<<6|m);else{var T=63&e[r++];65536>(f=(240&f)==224?(15&f)<<12|m<<6|T:(7&f)<<18|m<<12|T<<6|63&e[r++])?s+=String.fromCharCode(f):(f-=65536,s+=String.fromCharCode(55296|f>>10,56320|1023&f))}}else s+=String.fromCharCode(f)}return s},it=(e,r,n)=>(e>>>=0)?pn((p(),G),e,r,n):"";function dn(e,r,n){return i?$(3,1,e,r,n):0}function mn(e,r){if(i)return $(4,1,e,r)}function hn(e,r){if(i)return $(5,1,e,r)}function gn(e,r,n){if(i)return $(6,1,e,r,n)}function yn(e,r,n){return i?$(7,1,e,r,n):0}function wn(e,r){if(i)return $(8,1,e,r)}function bn(e,r,n){if(i)return $(9,1,e,r,n)}function Tn(e,r,n,s){if(i)return $(10,1,e,r,n,s)}function vn(e,r,n,s){if(i)return $(11,1,e,r,n,s)}function En(e,r,n,s){if(i)return $(12,1,e,r,n,s)}function _n(e){if(i)return $(13,1,e)}function Sn(e,r){if(i)return $(14,1,e,r)}function An(e,r,n){if(i)return $(15,1,e,r,n)}var $a=()=>ot(""),Se=e=>{e>>>=0;for(var r="";;){var n=(p(),G)[e++>>>0];if(!n)return r;r+=String.fromCharCode(n)}},lr={},pr={},za={},ut=class extends Error{constructor(e){super(e),this.name="BindingError"}};function xe(e,r,n={}){return function(s,f,m={}){var T=f.name;if(!s)throw new ut(`type "${T}" must have a positive integer typeid pointer`);if(pr.hasOwnProperty(s)){if(m.I)return;throw new ut(`Cannot register type '${T}' twice`)}pr[s]=f,delete za[s],lr.hasOwnProperty(s)&&(f=lr[s],delete lr[s],f.forEach(y=>y()))}(e,r,n)}var In=(e,r,n)=>{switch(r){case 1:return n?s=>(p(),H)[s>>>0]:s=>(p(),G)[s>>>0];case 2:return n?s=>(p(),se)[s>>>1>>>0]:s=>(p(),De)[s>>>1>>>0];case 4:return n?s=>(p(),S)[s>>>2>>>0]:s=>(p(),_)[s>>>2>>>0];case 8:return n?s=>(p(),Z)[s>>>3>>>0]:s=>(p(),nt)[s>>>3>>>0];default:throw new TypeError(`invalid integer width (${r}): ${e}`)}};function ja(e,r,n,s,f){e>>>=0,n>>>=0,r=Se(r>>>0);let m=T=>T;if(s=s===0n){let T=8*n;m=y=>BigInt.asUintN(T,y),f=m(f)}xe(e,{name:r,g:m,l:(T,y)=>(typeof y=="number"&&(y=BigInt(y)),y),j:In(r,n,!s),m:null})}function Va(e,r,n,s){xe(e>>>=0,{name:r=Se(r>>>0),g:function(f){return!!f},l:function(f,m){return m?n:s},j:function(f){return this.g((p(),G)[f>>>0])},m:null})}var xn=[],Ve=[0,1,,1,null,1,!0,1,!1,1];function dr(e){9<(e>>>=0)&&--Ve[e+1]==0&&(Ve[e]=void 0,xn.push(e))}var ye=e=>{if(!e)throw new ut(`Cannot use deleted val. handle = ${e}`);return Ve[e]},Te=e=>{switch(e){case void 0:return 2;case null:return 4;case!0:return 6;case!1:return 8;default:let r=xn.pop()||Ve.length;return Ve[r]=e,Ve[r+1]=1,r}};function mr(e){return this.g((p(),_)[e>>>2>>>0])}var Ha={name:"emscripten::val",g:e=>{var r=ye(e);return dr(e),r},l:(e,r)=>Te(r),j:mr,m:null};function qa(e){return xe(e>>>0,Ha)}var Ya=(e,r)=>{switch(r){case 4:return function(n){return this.g((p(),Ge)[n>>>2>>>0])};case 8:return function(n){return this.g((p(),B)[n>>>3>>>0])};default:throw new TypeError(`invalid float width (${r}): ${e}`)}};function Ja(e,r,n){n>>>=0,xe(e>>>=0,{name:r=Se(r>>>0),g:s=>s,l:(s,f)=>f,j:Ya(r,n),m:null})}function Xa(e,r,n,s,f){e>>>=0,n>>>=0,r=Se(r>>>0);let m=y=>y;if(s===0){var T=32-8*n;m=y=>y<<T>>>T,f=m(f)}xe(e,{name:r,g:m,l:(y,A)=>A,j:In(r,n,s!==0),m:null})}function Za(e,r,n){function s(m){var T=(p(),_)[m>>>2>>>0];return m=(p(),_)[m+4>>>2>>>0],new f((p(),H).buffer,m,T)}var f=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array][r];xe(e>>>=0,{name:n=Se(n>>>0),g:s,j:s},{I:!0})}var Oe=(e,r,n)=>{var s=(p(),G);if(r>>>=0,0<n){var f=r;n=r+n-1;for(var m=0;m<e.length;++m){var T=e.codePointAt(m);if(127>=T){if(r>=n)break;s[r++>>>0]=T}else if(2047>=T){if(r+1>=n)break;s[r++>>>0]=192|T>>6,s[r++>>>0]=128|63&T}else if(65535>=T){if(r+2>=n)break;s[r++>>>0]=224|T>>12,s[r++>>>0]=128|T>>6&63,s[r++>>>0]=128|63&T}else{if(r+3>=n)break;s[r++>>>0]=240|T>>18,s[r++>>>0]=128|T>>12&63,s[r++>>>0]=128|T>>6&63,s[r++>>>0]=128|63&T,m++}}s[r>>>0]=0,e=r-f}else e=0;return e},Le=e=>{for(var r=0,n=0;n<e.length;++n){var s=e.charCodeAt(n);127>=s?r++:2047>=s?r+=2:55296<=s&&57343>=s?(r+=4,++n):r+=3}return r};function Qa(e,r){xe(e>>>=0,{name:r=Se(r>>>0),g(n){var s=(p(),_)[n>>>2>>>0];return s=it(n+4,s,!0),Ie(n),s},l(n,s){s instanceof ArrayBuffer&&(s=new Uint8Array(s));var f=typeof s=="string";if(!(f||ArrayBuffer.isView(s)&&s.BYTES_PER_ELEMENT==1))throw new ut("Cannot pass non-string to std::string");var m=f?Le(s):s.length,T=gt(4+m+1),y=T+4;return(p(),_)[T>>>2>>>0]=m,f?Oe(s,y,m+1):(p(),G).set(s,y>>>0),n!==null&&n.push(Ie,T),T},j:mr,m(n){Ie(n)}})}var On=globalThis.TextDecoder?new TextDecoder("utf-16le"):void 0,Ka=(e,r,n)=>{if(e>>>=1,16<(r=ln((p(),De),e,r/2,n))-e&&On)return On.decode((p(),De).slice(e,r));for(n="";e<r;++e){var s=(p(),De)[e>>>0];n+=String.fromCharCode(s)}return n},es=(e,r,n)=>{if(n??=2147483647,2>n)return 0;var s=r;n=(n-=2)<2*e.length?n/2:e.length;for(var f=0;f<n;++f){var m=e.charCodeAt(f);(p(),se)[r>>>1>>>0]=m,r+=2}return(p(),se)[r>>>1>>>0]=0,r-s},ts=e=>2*e.length,rs=(e,r,n)=>{var s="";e>>>=2;for(var f=0;!(f>=r/4);f++){var m=(p(),_)[e+f>>>0];if(!m&&!n)break;s+=String.fromCodePoint(m)}return s},ns=(e,r,n)=>{if(r>>>=0,n??=2147483647,4>n)return 0;var s=r;n=s+n-4;for(var f=0;f<e.length;++f){var m=e.codePointAt(f);if(65535<m&&f++,(p(),S)[r>>>2>>>0]=m,(r+=4)+4>n)break}return(p(),S)[r>>>2>>>0]=0,r-s},os=e=>{for(var r=0,n=0;n<e.length;++n)65535<e.codePointAt(n)&&n++,r+=4;return r};function as(e,r,n){if(e>>>=0,r>>>=0,n=Se(n>>>=0),r===2)var s=Ka,f=es,m=ts;else s=rs,f=ns,m=os;xe(e,{name:n,g:T=>{var y=(p(),_)[T>>>2>>>0];return y=s(T+4,y*r,!0),Ie(T),y},l:(T,y)=>{if(typeof y!="string")throw new ut(`Cannot pass non-string to C++ string type ${n}`);var A=m(y),C=gt(4+A+r);return(p(),_)[C>>>2>>>0]=A/r,f(y,C+4,A+r),T!==null&&T.push(Ie,C),C},j:mr,m(T){Ie(T)}})}function ss(e,r){xe(e>>>=0,{J:!0,name:r=Se(r>>>0),g:()=>{},l:()=>{}})}function is(e){Lr(e>>>0,!u,1,!a,131072,!1),on()}var pe=e=>{if(!M)try{if(e(),!(0<k))try{i?Mt()&&Br(v):fr(v)}catch(r){r instanceof st||r=="unwind"||d(0,r)}}catch(r){r instanceof st||r=="unwind"||d(0,r)}},us=!Atomics.waitAsync||globalThis.navigator?.userAgent&&91>Number((navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)||[])[2]);function hr(e){e>>>=0,us||(Atomics.waitAsync((p(),S),e>>>2,e).value.then(Ot),e+=128,Atomics.store((p(),S),e>>>2,1))}var Ot=()=>pe(()=>{var e=Mt();e&&(hr(e),ho())});function fs(e,r){(e>>>=0)==r>>>0?setTimeout(Ot):i?postMessage({s:e,i:"checkMailbox"}):(e=je[e])&&e.postMessage({i:"checkMailbox"})}var gr=[];function cs(e,r,n,s,f){for(r>>>=0,f>>>=0,gr.length=0,n=f>>>3,s=f+s>>>3;n<s;){var m;m=(p(),Z)[n++>>>0]?(p(),Z)[n++>>>0]:(p(),B)[n++>>>0],gr.push(m)}return(r?Mr[r]:zi[e])(...gr)}var ls=()=>{k=0};function ps(e){e>>>=0,i?postMessage({i:"cleanupThread",M:e}):nn(je[e])}function ds(e){}function ms(e){return(...r)=>e(...r)}var yr=null,Ln=async e=>{k+=1;try{return await e()}finally{--k}};function Bn(e){return e>>>=0,Ln(async()=>{var r=await ye(e);return Te(r)})}Bn.v=!0;var wr=[],hs=e=>{var r=wr.length;return wr.push(e),r},gs=(e,r)=>{for(var n=Array(e),s=0;s<e;++s){var f=s,m=(p(),_)[r+4*s>>>2>>>0],T=pr[m];if(T===void 0)throw e=`parameter ${s}`,m=Xn(m),r=Se(m),Ie(m),new ut(`${e} has unknown type ${r}`);n[f]=T}return n},ys=(e,r,n)=>{var s=[];return e=e(s,n),s.length&&((p(),_)[r>>>2>>>0]=Te(s)),e},ws={},Lt=e=>{var r=ws[e];return r===void 0?Se(e):r};function bs(e,r,n){var[s,...f]=gs(e,r>>>0);r=s.l.bind(s);var m=f.map(A=>A.j.bind(A));e--;var T={toValue:ye};switch(e=m.map((A,C)=>{var z=`argFromPtr${C}`;return T[z]=A,`${z}(args${C?"+"+8*C:""})`}),n){case 0:var y="toValue(handle)";break;case 2:y="new (toValue(handle))";break;case 3:y="";break;case 1:T.getStringOrSymbol=Lt,y="toValue(handle)[getStringOrSymbol(methodName)]"}return y+=`(${e})`,s.J||(T.toReturnWire=r,T.emval_returnValue=ys,y=`return emval_returnValue(toReturnWire, destructorsRef, ${y})`),y=`return function (handle, methodName, destructorsRef, args) { ${y} }`,n=new Function(Object.keys(T),y)(...Object.values(T)),y=`methodCaller<(${f.map(A=>A.name)}) => ${s.name}>`,hs(Object.defineProperty(n,"name",{value:y}))}function Ts(e,r){return r>>>=0,(e=ye(e>>>0))==ye(r)}function vs(e){return(e>>>=0)?(e=Lt(e),Te(globalThis[e])):Te(globalThis)}function Es(e){return e=Lt(e>>>0),Te(t[e])}function _s(e,r){return r>>>=0,e=ye(e>>>0),r=ye(r),Te(e[r])}function Ss(e){9<(e>>>=0)&&(Ve[e+1]+=1)}function Cn(e,r,n,s,f){return wr[e>>>0](r>>>0,n>>>0,s>>>0,f>>>0)}function As(e,r,n,s,f){return Cn(e>>>0,r>>>0,n>>>0,s>>>0,f>>>0)}function Is(){return Te([])}function xs(e){e=ye(e>>>0);for(var r=Array(e.length),n=0;n<e.length;n++)r[n]=e[n];return Te(r)}function Os(e){return Te(Lt(e>>>0))}function Ls(){return Te({})}function Bs(e){for(var r=ye(e>>>=0);r.length;){var n=r.pop();r.pop()(n)}dr(e)}function Cs(e,r,n){r>>>=0,n>>>=0,e=ye(e>>>0),r=ye(r),n=ye(n),e[r]=n}function Ms(e,r){e=re(e),r>>>=0,e=new Date(1e3*e),(p(),S)[r>>>2>>>0]=e.getUTCSeconds(),(p(),S)[r+4>>>2>>>0]=e.getUTCMinutes(),(p(),S)[r+8>>>2>>>0]=e.getUTCHours(),(p(),S)[r+12>>>2>>>0]=e.getUTCDate(),(p(),S)[r+16>>>2>>>0]=e.getUTCMonth(),(p(),S)[r+20>>>2>>>0]=e.getUTCFullYear()-1900,(p(),S)[r+24>>>2>>>0]=e.getUTCDay(),e=(e.getTime()-Date.UTC(e.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,(p(),S)[r+28>>>2>>>0]=e}var Mn=e=>e%4==0&&(e%100!=0||e%400==0),Dn=[0,31,60,91,121,152,182,213,244,274,305,335],Pn=[0,31,59,90,120,151,181,212,243,273,304,334];function Ds(e,r){e=re(e),r>>>=0,e=new Date(1e3*e),(p(),S)[r>>>2>>>0]=e.getSeconds(),(p(),S)[r+4>>>2>>>0]=e.getMinutes(),(p(),S)[r+8>>>2>>>0]=e.getHours(),(p(),S)[r+12>>>2>>>0]=e.getDate(),(p(),S)[r+16>>>2>>>0]=e.getMonth(),(p(),S)[r+20>>>2>>>0]=e.getFullYear()-1900,(p(),S)[r+24>>>2>>>0]=e.getDay();var n=(Mn(e.getFullYear())?Dn:Pn)[e.getMonth()]+e.getDate()-1|0;(p(),S)[r+28>>>2>>>0]=n,(p(),S)[r+36>>>2>>>0]=-60*e.getTimezoneOffset(),n=new Date(e.getFullYear(),6,1).getTimezoneOffset();var s=new Date(e.getFullYear(),0,1).getTimezoneOffset();e=0|(n!=s&&e.getTimezoneOffset()==Math.min(s,n)),(p(),S)[r+32>>>2>>>0]=e}function Ps(e){e>>>=0;var r=new Date((p(),S)[e+20>>>2>>>0]+1900,(p(),S)[e+16>>>2>>>0],(p(),S)[e+12>>>2>>>0],(p(),S)[e+8>>>2>>>0],(p(),S)[e+4>>>2>>>0],(p(),S)[e>>>2>>>0],0),n=(p(),S)[e+32>>>2>>>0],s=r.getTimezoneOffset(),f=new Date(r.getFullYear(),6,1).getTimezoneOffset(),m=new Date(r.getFullYear(),0,1).getTimezoneOffset(),T=Math.min(m,f);return 0>n?(p(),S)[e+32>>>2>>>0]=+(f!=m&&T==s):0<n!=(T==s)&&(f=Math.max(m,f),r.setTime(r.getTime()+6e4*((0<n?T:f)-s))),(p(),S)[e+24>>>2>>>0]=r.getDay(),n=(Mn(r.getFullYear())?Dn:Pn)[r.getMonth()]+r.getDate()-1|0,(p(),S)[e+28>>>2>>>0]=n,(p(),S)[e>>>2>>>0]=r.getSeconds(),(p(),S)[e+4>>>2>>>0]=r.getMinutes(),(p(),S)[e+8>>>2>>>0]=r.getHours(),(p(),S)[e+12>>>2>>>0]=r.getDate(),(p(),S)[e+16>>>2>>>0]=r.getMonth(),(p(),S)[e+20>>>2>>>0]=r.getYear(),e=r.getTime(),BigInt(isNaN(e)?-1:e/1e3)}function Un(e,r,n,s,f,m,T){return i?$(16,1,e,r,n,s,f,m,T):-52}function Rn(e,r,n,s,f,m){if(i)return $(17,1,e,r,n,s,f,m)}var mt={},Us=()=>performance.timeOrigin+performance.now();function kn(e,r){if(i)return $(18,1,e,r);if(mt[e]&&(clearTimeout(mt[e].id),delete mt[e]),!r)return 0;var n=setTimeout(()=>{delete mt[e],pe(()=>mo(e,performance.timeOrigin+performance.now()))},r);return mt[e]={id:n,V:r},0}function Rs(e,r,n,s){e>>>=0,r>>>=0,n>>>=0,s>>>=0;var f=new Date().getFullYear(),m=new Date(f,0,1).getTimezoneOffset();f=new Date(f,6,1).getTimezoneOffset();var T=Math.max(m,f);(p(),_)[e>>>2>>>0]=60*T,(p(),S)[r>>>2>>>0]=+(m!=f),e=(r=y=>{var A=Math.abs(y);return`UTC${0<=y?"-":"+"}${String(Math.floor(A/60)).padStart(2,"0")}${String(A%60).padStart(2,"0")}`})(m),r=r(f),f<m?(Oe(e,n,17),Oe(r,s,17)):(Oe(e,s,17),Oe(r,n,17))}var ks=()=>Date.now(),Ns=1;function Ws(e,r,n){if(n>>>=0,!(0<=e&&3>=e))return 28;if(e===0)e=Date.now();else{if(!Ns)return 52;e=performance.timeOrigin+performance.now()}return e=Math.round(1e6*e),(p(),Z)[n>>>3>>>0]=BigInt(e),0}var br=[],Nn=(e,r)=>{br.length=0;for(var n;n=(p(),G)[e++>>>0];){var s=n!=105;r+=(s&=n!=112)&&r%8?4:0,br.push(n==112?(p(),_)[r>>>2>>>0]:n==106?(p(),Z)[r>>>3>>>0]:n==105?(p(),S)[r>>>2>>>0]:(p(),B)[r>>>3>>>0]),r+=s?8:4}return br};function Fs(e,r,n){return e>>>=0,r=Nn(r>>>0,n>>>0),Mr[e](...r)}function Gs(e,r,n){return e>>>=0,r=Nn(r>>>0,n>>>0),Mr[e](...r)}var $s=()=>{};function zs(e,r){return U(it(e>>>0,r>>>0))}var js=()=>{throw k+=1,"unwind"};function Vs(){return 4294901760}var Hs=()=>2,qs=()=>navigator.hardwareConcurrency;function Ys(e){e>>>=0;var r=(p(),G).length;if(e<=r||4294901760<e)return!1;for(var n=1;4>=n;n*=2){var s=r*(1+.2/n);s=Math.min(s,e+100663296);e:{s=(Math.min(4294901760,65536*Math.ceil(Math.max(e,s)/65536))-Ue.buffer.byteLength+65535)/65536|0;try{Ue.grow(s),q();var f=1;break e}catch{}f=void 0}if(f)return!0}return!1}var Ae=e=>{var r=Le(e)+1,n=Dt(r);return Oe(e,n,r),n},Tr=(e,r)=>{(p(),_)[e>>>2>>>0]=r;var n=(p(),_)[e>>>2>>>0];(p(),_)[e+4>>>2>>>0]=(r-n)/4294967296},ht=e=>(p(),_)[e>>>2>>>0]+4294967296*(p(),S)[e+4>>>2>>>0],ne=[],Js=(e,r)=>{ne[e>>>0]=r},Be=[],Bt=[],ft=(e,r)=>{Bt[e]=new Promise(n=>r.finally(()=>n(e)))},I=e=>{if(e)return ne[e>>>0]},Xs=(e,r)=>{for(e=(p(),_)[e>>>2>>>0];e;e=(p(),_)[e>>>2>>>0])r[(p(),S)[e+4>>>2>>>0]](e)},Ct=(e,r,n)=>{(p(),_)[e>>>2>>>0]=r,(p(),_)[e+4>>>2>>>0]=n},Wn=e=>{var r=(p(),_)[e>>>2>>>0];return e=(p(),_)[e+4>>>2>>>0],it(r,e)},Ce=e=>{var r=(p(),_)[e>>>2>>>0];return e=(p(),_)[e+4>>>2>>>0],r?it(r,e):e===0?"":void 0},Zs=e=>{var r=Ce(e+4),n=(n=(p(),_)[e+12>>>2>>>0])?I(n):"auto";if(e+=16){var s=I((p(),_)[e+4>>>2>>>0]),f=(p(),_)[e+16>>>2>>>0],m=(p(),_)[e+20>>>2>>>0];if(f){for(var T={},y=0;y<f;++y){var A=m+24*y;T[Wn(A+4)]=(p(),B)[A+16>>>3>>>0]}f=T}else f=void 0;e={module:s,constants:f,entryPoint:Ce(e+8)}}else e=void 0;return{label:r,layout:n,compute:e}},Fn=(e,r)=>{function n(s,f){s=e[s],(p(),_)[r+f>>>2>>>0]=s}n("maxTextureDimension1D",4),n("maxTextureDimension2D",8),n("maxTextureDimension3D",12),n("maxTextureArrayLayers",16),n("maxBindGroups",20),n("maxBindGroupsPlusVertexBuffers",24),n("maxBindingsPerBindGroup",28),n("maxDynamicUniformBuffersPerPipelineLayout",32),n("maxDynamicStorageBuffersPerPipelineLayout",36),n("maxSampledTexturesPerShaderStage",40),n("maxSamplersPerShaderStage",44),n("maxStorageBuffersPerShaderStage",48),n("maxStorageTexturesPerShaderStage",52),n("maxUniformBuffersPerShaderStage",56),n("minUniformBufferOffsetAlignment",80),n("minStorageBufferOffsetAlignment",84),Tr(r+64,e.maxUniformBufferBindingSize),Tr(r+72,e.maxStorageBufferBindingSize),n("maxVertexBuffers",88),Tr(r+96,e.maxBufferSize),n("maxVertexAttributes",104),n("maxVertexBufferArrayStride",108),n("maxInterStageShaderVariables",112),n("maxColorAttachments",116),n("maxColorAttachmentBytesPerSample",120),n("maxComputeWorkgroupStorageSize",124),n("maxComputeInvocationsPerWorkgroup",128),n("maxComputeWorkgroupSizeX",132),n("maxComputeWorkgroupSizeY",136),n("maxComputeWorkgroupSizeZ",140),n("maxComputeWorkgroupsPerDimension",144),e.U!==void 0&&n("maxImmediateSize",148)},Qs=[,"validation","out-of-memory","internal"],Ks=[,"compatibility","core"],Gn={1:"core-features-and-limits",2:"depth-clip-control",3:"depth32float-stencil8",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:"timestamp-query",10:"indirect-first-instance",11:"shader-f16",12:"rg11b10ufloat-renderable",13:"bgra8unorm-storage",14:"float32-filterable",15:"float32-blendable",16:"clip-distances",17:"dual-source-blending",18:"subgroups",19:"texture-formats-tier1",20:"texture-formats-tier2",21:"primitive-index",22:"texture-component-swizzle",327692:"chromium-experimental-unorm16-texture-formats",327729:"chromium-experimental-multi-draw-indirect"},ei=[,"low-power","high-performance"],ti=[,"occlusion","timestamp"],ri={undefined:1,unknown:1,destroyed:2};function ni(e,r,n,s,f,m){r=re(r),n=re(n),s>>>=0,f>>>=0,m>>>=0;var T=I(e>>>0);if(e={},m){var y=(p(),_)[m+12>>>2>>>0];if(y){var A=(p(),_)[m+16>>>2>>>0];e.requiredFeatures=Array.from((p(),_).subarray(A>>>2>>>0,A+4*y>>