MCPcopy Create free account
hub / github.com/JunJD/alading / createInferenceSessionHandler

Method createInferenceSessionHandler

public/onnxruntime/ort.bundle.min.mjs:1802–1802  ·  view source on GitHub ↗
(e,o)

Source from the content-addressed store, hash-verified

1800Shader source:
1801${e}`);return r}deleteShader(e){this.gl.deleteShader(e)}bindTextureToUniform(e,o,t){let r=this.gl;r.activeTexture(r.TEXTURE0+o),this.checkError(),r.bindTexture(r.TEXTURE_2D,e),this.checkError(),r.uniform1i(t,o),this.checkError()}draw(){this.gl.drawArrays(this.gl.TRIANGLE_STRIP,0,4),this.checkError()}checkError(){if(z.debug){let e=this.gl,o=e.getError(),t="";switch(o){case e.NO_ERROR:return;case e.INVALID_ENUM:t="INVALID_ENUM";break;case e.INVALID_VALUE:t="INVALID_VALUE";break;case e.INVALID_OPERATION:t="INVALID_OPERATION";break;case e.INVALID_FRAMEBUFFER_OPERATION:t="INVALID_FRAMEBUFFER_OPERATION";break;case e.OUT_OF_MEMORY:t="OUT_OF_MEMORY";break;case e.CONTEXT_LOST_WEBGL:t="CONTEXT_LOST_WEBGL";break;default:t=`Unknown WebGL Error: ${o.toString(16)}`}throw new Error(t)}}deleteTexture(e){this.gl.deleteTexture(e)}deleteProgram(e){this.gl.deleteProgram(e)}getEncoder(e,o,t=0){if(this.version===2)return new Pn(this.gl,o);switch(e){case"float":return t===1||this.isRenderFloat32Supported?new Br(this.gl,o):new Br(this.gl,o,this.textureHalfFloatExtension.HALF_FLOAT_OES);case"int":throw new Error("not implemented");case"byte":return new En(this.gl,o);default:throw new Error(`Invalid dataType: ${e}`)}}clearActiveTextures(){let e=this.gl;for(let o=0;o<this.maxTextureImageUnits;++o)e.activeTexture(e.TEXTURE0+o),e.bindTexture(e.TEXTURE_2D,null)}dispose(){if(this.disposed)return;let e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteFramebuffer(this.framebuffer),e.bindBuffer(e.ARRAY_BUFFER,null),e.deleteBuffer(this.vertexbuffer),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),e.finish(),this.disposed=!0}createDefaultGeometry(){return new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,-1,0,1,0])}createVertexbuffer(){let e=this.gl,o=e.createBuffer();if(!o)throw new Error("createBuffer() returned null");let t=this.createDefaultGeometry();return e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,t,e.STATIC_DRAW),this.checkError(),o}createFramebuffer(){let e=this.gl.createFramebuffer();if(!e)throw new Error("createFramebuffer returned null");return e}queryVitalParameters(){let e=this.gl;if(this.isFloatTextureAttachableToFrameBuffer=this.checkFloatTextureAttachableToFrameBuffer(),this.isRenderFloat32Supported=this.checkRenderFloat32(),this.isFloat32DownloadSupported=this.checkFloat32Download(),this.version===1&&!this.textureHalfFloatExtension&&!this.isRenderFloat32Supported)throw new Error("both float32 and float16 TextureType are not supported");this.isBlendSupported=!this.isRenderFloat32Supported||this.checkFloat32Blend(),this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.maxTextureImageUnits=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.version}getExtensions(){this.version===2?(this.colorBufferFloatExtension=this.gl.getExtension("EXT_color_buffer_float"),this.disjointTimerQueryWebgl2Extension=this.gl.getExtension("EXT_disjoint_timer_query_webgl2")):(this.textureFloatExtension=this.gl.getExtension("OES_texture_float"),this.textureHalfFloatExtension=this.gl.getExtension("OES_texture_half_float"))}checkFloatTextureAttachableToFrameBuffer(){let e=this.gl,o=e.createTexture();e.bindTexture(e.TEXTURE_2D,o);let t=this.version===2?e.RGBA32F:e.RGBA;e.texImage2D(e.TEXTURE_2D,0,t,1,1,0,e.RGBA,e.FLOAT,null);let r=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0);let n=e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE;return e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteTexture(o),e.deleteFramebuffer(r),n}checkRenderFloat32(){if(this.version===2){if(!this.colorBufferFloatExtension)return!1}else if(!this.textureFloatExtension)return!1;return this.isFloatTextureAttachableToFrameBuffer}checkFloat32Download(){if(this.version===2){if(!this.colorBufferFloatExtension)return!1}else if(!this.textureFloatExtension||!this.gl.getExtension("WEBGL_color_buffer_float"))return!1;return this.isFloatTextureAttachableToFrameBuffer}checkFloat32Blend(){let e=this.gl,o,t,r,n,s;try{o=e.createTexture(),t=e.createFramebuffer(),e.bindTexture(e.TEXTURE_2D,o);let a=this.version===2?e.RGBA32F:e.RGBA;return e.texImage2D(e.TEXTURE_2D,0,a,1,1,0,e.RGBA,e.FLOAT,null),e.bindFramebuffer(e.FRAMEBUFFER,t),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,o,0),e.enable(e.BLEND),r=e.createShader(e.VERTEX_SHADER),!r||(e.shaderSource(r,"void main(){}"),e.compileShader(r),n=e.createShader(e.FRAGMENT_SHADER),!n)||(e.shaderSource(n,"precision highp float;void main(){gl_FragColor=vec4(0.5);}"),e.compileShader(n),s=e.createProgram(),!s)?!1:(e.attachShader(s,r),e.attachShader(s,n),e.linkProgram(s),e.useProgram(s),e.drawArrays(e.POINTS,0,1),e.getError()===e.NO_ERROR)}finally{e.disable(e.BLEND),s&&e.deleteProgram(s),r&&e.deleteShader(r),n&&e.deleteShader(n),t&&(e.bindFramebuffer(e.FRAMEBUFFER,null),e.deleteFramebuffer(t)),o&&(e.bindTexture(e.TEXTURE_2D,null),e.deleteTexture(o))}}beginTimer(){if(this.version===2&&this.disjointTimerQueryWebgl2Extension){let e=this.gl,o=this.disjointTimerQueryWebgl2Extension,t=e.createQuery();return e.beginQuery(o.TIME_ELAPSED_EXT,t),t}else throw new Error("WebGL1 profiling currently not supported.")}endTimer(){if(this.version===2&&this.disjointTimerQueryWebgl2Extension){let e=this.gl,o=this.disjointTimerQueryWebgl2Extension;e.endQuery(o.TIME_ELAPSED_EXT);return}else throw new Error("WebGL1 profiling currently not supported")}isTimerResultAvailable(e){let o=!1,t=!1;if(this.version===2&&this.disjointTimerQueryWebgl2Extension){let r=this.gl,n=this.disjointTimerQueryWebgl2Extension;o=r.getQueryParameter(e,r.QUERY_RESULT_AVAILABLE),t=r.getParameter(n.GPU_DISJOINT_EXT)}else throw new Error("WebGL1 profiling currently not supported");return o&&!t}getTimerResult(e){let o=0;if(this.version===2){let t=this.gl;o=t.getQueryParameter(e,t.QUERY_RESULT),t.deleteQuery(e)}else throw new Error("WebGL1 profiling currently not supported");return o/1e6}async waitForQueryAndGetTime(e){return await li(()=>this.isTimerResultAvailable(e)),this.getTimerResult(e)}async createAndWaitForFence(){let e=this.createFence(this.gl);return this.pollFence(e)}createFence(e){let o,t=e,r=t.fenceSync(t.SYNC_GPU_COMMANDS_COMPLETE,0);return e.flush(),r===null?o=()=>!0:o=()=>{let n=t.clientWaitSync(r,0,0);return n===t.ALREADY_SIGNALED||n===t.CONDITION_SATISFIED},{query:r,isFencePassed:o}}async pollFence(e){return new Promise(o=>{this.addItemToPoll(()=>e.isFencePassed(),()=>o())})}pollItems(){let e=bg(this.itemsToPoll.map(o=>o.isDoneFn));for(let o=0;o<=e;++o){let{resolveFn:t}=this.itemsToPoll[o];t()}this.itemsToPoll=this.itemsToPoll.slice(e+1)}async addItemToPoll(e,o){this.itemsToPoll.push({isDoneFn:e,resolveFn:o}),!(this.itemsToPoll.length>1)&&await li(()=>(this.pollItems(),this.itemsToPoll.length===0))}}});function Gi(i){let e;if((!i||i==="webgl2")&&"webgl2"in mr?e=mr.webgl2:(!i||i==="webgl")&&"webgl"in mr&&(e=mr.webgl),!e)try{let t=yg();e=vp(t,i)}catch{let r=gg();e=vp(r,i)}i=i||e.version===1?"webgl":"webgl2";let o=e.gl;return mr[i]=e,o.isContextLost()?(delete mr[i],Gi(i)):(o.disable(o.DEPTH_TEST),o.disable(o.STENCIL_TEST),o.disable(o.BLEND),o.disable(o.DITHER),o.disable(o.POLYGON_OFFSET_FILL),o.disable(o.SAMPLE_COVERAGE),o.enable(o.SCISSOR_TEST),o.enable(o.CULL_FACE),o.cullFace(o.BACK),e)}function vp(i,e){let o={alpha:!1,depth:!1,antialias:!1,stencil:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1,failIfMajorPerformanceCaveat:!1},t,r=o;if((!e||e==="webgl2")&&(t=i.getContext("webgl2",r),t))try{return new Mr(t,2)}catch(n){tt.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl2'. Error: ${n}`)}if((!e||e==="webgl")&&(t=i.getContext("webgl",r)||i.getContext("experimental-webgl",r),t))try{return new Mr(t,1)}catch(n){tt.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl' or 'experimental-webgl'. Error: ${n}`)}throw new Error("WebGL is not supported")}function gg(){if(typeof document>"u")throw new TypeError("failed to create canvas: document is not supported");let i=document.createElement("canvas");return i.width=1,i.height=1,i}function yg(){if(typeof OffscreenCanvas>"u")throw new TypeError("failed to create offscreen canvas: OffscreenCanvas is not supported");return new OffscreenCanvas(1,1)}var mr,Ip=O(()=>{"use strict";Ut();wp();mr={}});var Yn,_p=O(()=>{"use strict";Yt();Ut();Tp();Ip();Yn=class{get contextId(){return z.webgl.contextId}set contextId(e){z.webgl.contextId=e}get matmulMaxBatchSize(){return z.webgl.matmulMaxBatchSize}set matmulMaxBatchSize(e){z.webgl.matmulMaxBatchSize=e}get textureCacheMode(){return z.webgl.textureCacheMode}set textureCacheMode(e){z.webgl.textureCacheMode=e}get pack(){return z.webgl.pack}set pack(e){z.webgl.pack=e}get async(){return z.webgl.async}set async(e){z.webgl.async=e}initialize(){try{return this.glContext=Gi(this.contextId),typeof this.matmulMaxBatchSize!="number"&&(this.matmulMaxBatchSize=16),typeof this.textureCacheMode!="string"&&(this.textureCacheMode="full"),typeof this.pack!="boolean"&&(this.pack=!1),typeof this.async!="boolean"&&(this.async=!1),tt.setWithEnv(z),z.webgl.context||Object.defineProperty(z.webgl,"context",{value:this.glContext.gl}),tt.verbose("WebGLBackend",`Created WebGLContext: ${typeof this.glContext} with matmulMaxBatchSize: ${this.matmulMaxBatchSize}; textureCacheMode: ${this.textureCacheMode}; pack: ${this.pack}; async: ${this.async}.`),!0}catch(e){return tt.warning("WebGLBackend",`Unable to initialize WebGLBackend. ${e}`),!1}}createSessionHandler(e){return new Jn(this,e)}dispose(){this.glContext.dispose()}}});async function Mi(i){if(i){let e=typeof i=="string"?[i]:i;for(let o of e){let t=Op.get(o);if(t)return t;let r=await Tg(o);if(r)return r}}else return Mi(["webgl"]);throw new Error("no available backend to use")}async function Tg(i){let e=xg;if(typeof e[i]<"u"&&wg(e[i])){let o=e[i],t=o.initialize();if(typeof t=="object"&&"then"in t&&(t=await t),t)return Op.set(i,o),o}}function wg(i){let e=i;return"initialize"in e&&typeof e.initialize=="function"&&"createSessionHandler"in e&&typeof e.createSessionHandler=="function"&&"dispose"in e&&typeof e.dispose=="function"}var Op,xg,Sp=O(()=>{"use strict";_p();Op=new Map,xg={webgl:new Yn}});var Ui,Zn,Ap=O(()=>{"use strict";Ut();Ui=class{constructor(e,o){this.op=e;this.node=o}},Zn=class{constructor(e,o,t){this.graph=e;this.profiler=t;this.initialize(o)}initialize(e){this.profiler.event("session","ExecutionPlan.initialize",()=>{let o=this.graph.getNodes();if(o.length!==e.length)throw new Error("The size of nodes and OPs do not match.");this._ops=e.map((t,r)=>new Ui(t,o[r])),this.reset(),this._starter=[],this._ops.forEach((t,r)=>{let n=!0;for(let s of t.node.inputs)if(!this._values[s]&&this.graph.getInputIndices().indexOf(s)===-1){n=!1;break}n&&this._starter.push(r)})})}reset(){this._values=this.graph.getValues().map(e=>e.tensor)}async execute(e,o){return this.profiler.event("session","ExecutionPlan.execute",async()=>{this.reset();let t=e.createInferenceHandler(),r=this.graph.getInputIndices();if(o.length!==r.length)throw new Error(`number of input tensors don't match the number of inputs to the model: actual: ${o.length} expected: ${r.length}`);o.forEach((f,p)=>{let d=r[p];this._values[d]=f});let n=this._starter.slice(0),s=this.graph.getValues(),a=this.graph.getNodes(),u=0;for(;u<n.length;){let f=n[u++],p=this._ops[f],d=p.node.inputs.map(S=>this._values[S]);if(d.indexOf(void 0)!==-1)throw new Error(`unresolved input detected: op: ${p.node}`);let y=d;tt.verbose("ExecPlan",`Running op:${p.node.name} (${y.map((S,L)=>`'${p.node.inputs[L]}': ${S.type}[${S.dims.join(",")}]`).join(", ")})`);let T=await this.profiler.event("node",p.node.name,async()=>p.op.impl(t,y,p.op.context));if(T.length!==p.node.outputs.length)throw new Error("the size of output does not match model definition.");T.forEach((S,L)=>{let P=p.node.outputs[L];if(this._values[P])throw new Error(`output [${P}] already has value: op:${p.node.name}`);this._values[P]=S});let v=new Set;T.forEach((S,L)=>{let P=p.node.outputs[L];for(let A of s[P].to){let M=a[A],V=!0;for(let lt of M.inputs)if(!this._values[lt]){V=!1;break}V&&v.add(A)}}),n.push(...v)}let l=[];for(let f=0;f<this.graph.getOutputIndices().length;f++){let p=this.graph.getOutputIndices()[f],d=this._values[p];if(d===void 0)throw new Error(`required output [${p}] does not have value`);p===0?await d.getData():d.data,l.push(d)}return tt.verbose("ExecPlan","disposing of inferenceHandler"),t.dispose(),l})}}});var q,Xt,Ur,Pp=O(()=>{"use strict";Pr();q=rr(sr());We();Y();Xt=F.experimental.fbs,Ur=class i{constructor(e){if(this._attributes=new Map,e!=null){for(let o of e)o instanceof q.onnx.AttributeProto?this._attributes.set(o.name,[i.getValue(o),i.getType(o)]):o instanceof Xt.Attribute&&this._attributes.set(o.name(),[i.getValue(o),i.getType(o)]);if(this._attributes.size<e.length)throw new Error("duplicated attribute names")}}set(e,o,t){this._attributes.set(e,[t,o])}delete(e){this._attributes.delete(e)}getFloat(e,o){return this.get(e,"float",o)}getInt(e,o){return this.get(e,"int",o)}getString(e,o){return this.get(e,"string",o)}getTensor(e,o){return this.get(e,"tensor",o)}getFloats(e,o){return this.get(e,"floats",o)}getInts(e,o){return this.get(e,"ints",o)}getStrings(e,o){return this.get(e,"strings",o)}getTensors(e,o){return this.get(e,"tensors",o)}get(e,o,t){let r=this._attributes.get(e);if(r===void 0){if(t!==void 0)return t;throw new Error(`required attribute not found: ${e}`)}if(r[1]!==o)throw new Error(`type mismatch: expected ${o} but got ${r[1]}`);return r[0]}static getType(e){let o=e instanceof q.onnx.AttributeProto?e.type:e.type();switch(o){case q.onnx.AttributeProto.AttributeType.FLOAT:return"float";case q.onnx.AttributeProto.AttributeType.INT:return"int";case q.onnx.AttributeProto.AttributeType.STRING:return"string";case q.onnx.AttributeProto.AttributeType.TENSOR:return"tensor";case q.onnx.AttributeProto.AttributeType.FLOATS:return"floats";case q.onnx.AttributeProto.AttributeType.INTS:return"ints";case q.onnx.AttributeProto.AttributeType.STRINGS:return"strings";case q.onnx.AttributeProto.AttributeType.TENSORS:return"tensors";default:throw new Error(`attribute type is not supported yet: ${q.onnx.AttributeProto.AttributeType[o]}`)}}static getValue(e){let o=e instanceof q.onnx.AttributeProto?e.type:e.type();if(o===q.onnx.AttributeProto.AttributeType.GRAPH||o===q.onnx.AttributeProto.AttributeType.GRAPHS)throw new Error("graph attribute is not supported yet");let t=this.getValueNoCheck(e);if(o===q.onnx.AttributeProto.AttributeType.INT&&Rt.isLong(t))return Rt.longToNumber(t);if(o===q.onnx.AttributeProto.AttributeType.INTS){let r=t,n=new Array(r.length);for(let s=0;s<r.length;s++){let a=r[s];n[s]=Rt.longToNumber(a)}return n}if(o===q.onnx.AttributeProto.AttributeType.TENSOR)return e instanceof q.onnx.AttributeProto?bt.fromProto(t):bt.fromOrtTensor(t);if(o===q.onnx.AttributeProto.AttributeType.TENSORS){if(e instanceof q.onnx.AttributeProto)return t.map(n=>bt.fromProto(n));if(e instanceof Xt.Attribute)return t.map(n=>bt.fromOrtTensor(n))}return o===q.onnx.AttributeProto.AttributeType.STRING&&e instanceof q.onnx.AttributeProto?kr(t):o===q.onnx.AttributeProto.AttributeType.STRINGS&&e instanceof q.onnx.AttributeProto?t.map(kr):t}static getValueNoCheck(e){return e instanceof q.onnx.AttributeProto?this.getValueNoCheckFromOnnxFormat(e):this.getValueNoCheckFromOrtFormat(e)}static getValueNoCheckFromOnnxFormat(e){switch(e.type){case q.onnx.AttributeProto.AttributeType.FLOAT:return e.f;case q.onnx.AttributeProto.AttributeType.INT:return e.i;case q.onnx.AttributeProto.AttributeType.STRING:return e.s;case q.onnx.AttributeProto.AttributeType.TENSOR:return e.t;case q.onnx.AttributeProto.AttributeType.GRAPH:return e.g;case q.onnx.AttributeProto.AttributeType.FLOATS:return e.floats;case q.onnx.AttributeProto.AttributeType.INTS:return e.ints;case q.onnx.AttributeProto.AttributeType.STRINGS:return e.strings;case q.onnx.AttributeProto.AttributeType.TENSORS:return e.tensors;case q.onnx.AttributeProto.AttributeType.GRAPHS:return e.graphs;default:throw new Error(`unsupported attribute type: ${q.onnx.AttributeProto.AttributeType[e.type]}`)}}static getValueNoCheckFromOrtFormat(e){switch(e.type()){case Xt.AttributeType.FLOAT:return e.f();case Xt.AttributeType.INT:return e.i();case Xt.AttributeType.STRING:return e.s();case Xt.AttributeType.TENSOR:return e.t();case Xt.AttributeType.GRAPH:return e.g();case Xt.AttributeType.FLOATS:return e.floatsArray();case Xt.AttributeType.INTS:{let o=[];for(let t=0;t<e.intsLength();t++)o.push(e.ints(t));return o}case Xt.AttributeType.STRINGS:{let o=[];for(let t=0;t<e.stringsLength();t++)o.push(e.strings(t));return o}case Xt.AttributeType.TENSORS:{let o=[];for(let t=0;t<e.tensorsLength();t++)o.push(e.tensors(t));return o}default:throw new Error(`unsupported attribute type: ${Xt.AttributeType[e.type()]}`)}}}});var zi,Qn,Wi,me,to,Vi,Ep=O(()=>{"use strict";Pp();Pr();zi=rr(sr());We();Y();Qn=F.experimental.fbs,Wi={from:(i,e)=>new Vi(i,e)},me=class{constructor(e){this._from=void 0,this._to=[],this.tensor=void 0,this.type=void 0,e&&(this.type=At.tensorValueTypeFromProto(e.type.tensorType))}get from(){return this._from}get to(){return this._to}},to=class{constructor(e,o){e instanceof zi.onnx.NodeProto?(this.name=e.name,this.opType=e.opType,this.attributes=new Ur(e.attribute)):e instanceof Qn.Node&&(this.name=o??e.name(),this.opType=e.opType(),this.attributes=new Ur(At.tensorAttributesFromORTFormat(e))),this.inputs=[],this.outputs=[],this.executeNode=!0}},Vi=class{constructor(e,o){if(!e)throw new TypeError("graph is empty");this.buildGraph(e),this.transformGraph(o),this.checkIsAcyclic()}getInputIndices(){return this._allInputIndices}getInputNames(){return this._allInputNames}getOutputIndices(){return this._allOutputIndices}getOutputNames(){return this._allOutputNames}getValues(){return this._allData}getNodes(){return this._nodes}buildGraph(e){if(e instanceof zi.onnx.GraphProto)this.buildGraphFromOnnxFormat(e);else if(e instanceof Qn.Graph)this.buildGraphFromOrtFormat(e);else throw new TypeError("Graph type is not supported.")}buildGraphFromOnnxFormat(e){let o=new Map;this._allData=[],this._allInputIndices=[],this._allInputNames=[],this._allOutputIndices=[],this._allOutputNames=[],this._nodes=[];let t=new Map;if(!e.input)throw new Error("missing information in graph: input");let r=[];for(let n of e.input){if(o.has(n.name))throw new Error(`duplicated input name: ${n.name}`);let s=this._allData.push(new me(n))-1;o.set(n.name,s),r.push(n.name)}if(!e.initializer)throw new Error("missing information in graph: initializer");for(let n of e.initializer){let s=o.get(n.name);if(s===void 0){let a=new me;a.type={shape:{dims:At.tensorDimsFromProto(n.dims)},tensorType:At.tensorDataTypeFromProto(n.dataType)},s=this._allData.push(a)-1,o.set(n.name,s)}this._allData[s]._from=-1,this._allData[s].tensor=bt.fromProto(n)}for(let n=0;n<this._allData.length;n++)this._allData[n].tensor||(this._allInputIndices.push(n),this._allInputNames.push(r[n]));if(!e.output)throw new Error("missing information in graph: output");for(let n of e.output){if(o.has(n.name))throw new Error(`duplicated output name: ${n.name}`);let s=this._allData.push(new me(n))-1;o.set(n.name,s),this._allOutputIndices.push(s),this._allOutputNames.push(n.name)}if(!e.node)throw new Error("missing information in graph: node");for(let n of e.node){if(!n.name)for(let a=0;;a++){let u=`unnamed_${n.opType}_${a}`;if(!t.has(u)){n.name=u;break}}if(t.has(n.name))throw new Error(`duplicated node name: ${n.name}`);let s=this._nodes.push(new to(n))-1;t.set(n.name,s)}for(let n=0;n<this._nodes.length;n++){let s=this._nodes[n],a=e.node[n];if(!a.output)throw new Error(`missing output for node: ${a.name}`);for(let u of a.output){let l=o.get(u);if(typeof l>"u"&&(l=this._allData.push(new me)-1,o.set(u,l)),s.outputs.push(l),this._allData[l]._from!==void 0)throw new Error(`multiple nodes output to one data value: ${l}`);if(this._allData[l]._from=n,a.opType==="Constant"){if(!a.attribute||a.attribute.length!==1||!a.attribute[0].t)throw new Error("missing attributes or missing tensor value in attributes for this Constant operator");if(!a.output||a.output.length!==1)throw new Error("missing output or incorrect number of outputs for this Constant operator");s.outputs.pop(),s.executeNode=!1,this._allData[l]._from=-1,this._allData[l].tensor=bt.fromProto(a.attribute[0].t)}}}for(let n=0;n<this._nodes.length;n++){let s=this._nodes[n],a=e.node[n];if(!a.input)throw new Error(`missing input for node: ${a.name}`);for(let u of a.input){let l=o.get(u);if(typeof l>"u"){if(u===""&&(a.input.length===3||a.input.length===4)&&a.opType==="Resize")continue;throw new Error(`unrecognized input '${u}' for node: ${a.name}`)}s.inputs.push(l),this._allData[l]._to.push(n)}}return!0}buildGraphFromOrtFormat(e){let o=new Map;this._allData=[],this._allInputIndices=[],this._allInputNames=[],this._allOutputIndices=[],this._allOutputNames=[],this._nodes=[];let t=new Map,r=[];for(let n=0;n<e.inputsLength();n++){let s=e.inputs(n);if(o.has(s))throw new Error(`duplicated input name: ${s}`);for(let a=0;a<e.nodeArgsLength();a++)if(e.nodeArgs(a)?.name()===s){let u=new me;if(e.nodeArgs(a)?.type()?.valueType()!==Qn.TypeInfoValue.tensor_type)throw new Error("Unexpected value type for the nodeArg.");let f=e.nodeArgs(a).type().value(new Qn.TensorTypeAndShape),p=At.tensorDataTypeFromProto(f.elemType()),d=f.shape(),y=[];for(let v=0;v<d.dimLength();v++)y.push(Rt.longToNumber(d.dim(v).value().dimValue()));u.type={shape:{dims:y},tensorType:p};let T=this._allData.push(u)-1;o.set(s,T),r.push(s)}}for(let n=0;n<e.initializersLength();n++){let s=e.initializers(n),a=o.get(s.name());if(a===void 0){let u=new me,l=At.tensorDimsFromORTFormat(s),f=At.tensorDataTypeFromProto(s.dataType());u.type={shape:{dims:l},tensorType:f},a=this._allData.push(u)-1,o.set(s.name(),a)}this._allData[a]._from=-1,this._allData[a].tensor=bt.fromOrtTensor(s)}for(let n=0;n<this._allData.length;n++)this._allData[n].tensor||(this._allInputIndices.push(n),this._allInputNames.push(r[n]));for(let n=0;n<e.outputsLength();n++){let s=e.outputs(n);if(o.has(s))throw new Error(`duplicated output name: ${s}`);let a=this._allData.push(new me)-1;o.set(s,a),this._allOutputIndices.push(a),this._allOutputNames.push(s)}if(!e.nodes)throw new Error("missing information in graph: node");for(let n=0;n<e.nodesLength();n++){let s=e.nodes(n),a=s.name();if(!a)for(let l=0;a=`unnamed_${s.opType()}_${l}`,!!t.has(a);l++);if(t.has(a))throw new Error(`duplicated node name: ${a}`);let u=this._nodes.push(new to(s,a))-1;t.set(a,u)}for(let n=0;n<this._nodes.length;n++){let s=this._nodes[n],a=e.nodes(n);if(a==null)throw new Error(`No node exists at index ${n}`);if(a?.outputsLength()===0)throw new Error(`missing output for node: ${a.name}`);for(let u=0;u<a?.outputsLength();u++){let l=a?.outputs(u),f=o.get(l);if(typeof f>"u"&&(f=this._allData.push(new me)-1,o.set(l,f)),s.outputs.push(f),this._allData[f]._from!==void 0)throw new Error(`multiple nodes output to one data value: ${f}`);if(this._allData[f]._from=n,a.opType()==="Constant"){if(a.attributesLength()!==1||!a.attributes(0).t())throw new Error("missing attributes or missing tensor value in attributes for this Constant operator");if(a.outputsLength()!==1)throw new Error("missing output or incorrect number of outputs for this Constant operator");s.outputs.pop(),s.executeNode=!1,this._allData[f]._from=-1,this._allData[f].tensor=bt.fromOrtTensor(a.attributes(0).t())}}}for(let n=0;n<this._nodes.length;n++){let s=this._nodes[n],a=e.nodes(n);if(a.inputsLength()===0)throw new Error(`missing input for node: ${a.name}`);for(let u=0;u<a.inputsLength();u++){let l=a.inputs(u),f=o.get(l);if(typeof f>"u")throw new Error(`unrecognized input '${l}' for node: ${a.name()}`);s.inputs.push(f),this._allData[f]._to.push(n)}}}checkIsAcyclic(){let e=new Set;this._allInputIndices.forEach(r=>{this._allData[r]._to.forEach(s=>{e.add(s)})});let o=Array.from(e),t=new Array(this._nodes.length).fill("white");for(;o.length>0;){let r=o.pop();t[r]==="gray"?t[r]="black":(o.push(r),t[r]="gray",this._nodes[r].outputs.forEach(n=>{let s=this._allData[n];if(typeof s.tensor<"u")throw new Error("node outputs should not be initialized");if(s._from!==r)throw new Error("from property of the Value object doesn't match index of Node being processed");s._to.forEach(a=>{if(t[a]==="gray")throw new Error("model graph is cyclic");t[a]==="white"&&o.push(a)})}))}}transformGraph(e){this.removeAllIdentityNodes(),this.removeAllDropoutNodes(),this.fuseConvActivationNodes(),e&&e.transformGraph(this),this.finalizeGraph()}finalizeGraph(){let e=0,o=new Array(this._nodes.length,0),t=0;for(let r=0;r<this._nodes.length;r++)o[r]=t,this._nodes[r].executeNode?(t!==r&&(this._nodes[t]=this._nodes[r]),t++):this._nodes[r].outputs.forEach(n=>{this._allData[n]._from=-2});this._nodes.splice(t,this._nodes.length-t);for(let r=0;r<this._allData.length;r++){let n=this._allData[r];n._from!==void 0&&n._from!==-1&&n._from!==-2&&(n._from=o[n._from]);for(let s=0;s<n._to.length;s++)if(n._to[s]>=0)n._to[s]=o[n._to[s]];else throw new Error("Trying to update a removed node")}e=0;for(let r=0;r<this._allData.length;r++){if(this._allData[r].from===-2&&this._allOutputIndices.indexOf(r+e)===-1){e++,this._allData.splice(r,1),r--;continue}if(e>0){let n=-1;this._allData[r].from!==void 0&&this._allData[r].from!==-1?(n=this._nodes[this._allData[r].from].outputs.indexOf(r+e),n!==-1&&(this._nodes[this._allData[r].from].outputs[n]=r)):(n=this._allInputIndices.indexOf(r+e),n!==-1&&(this._allInputIndices[n]=r)),this._allData[r].to.forEach(s=>{n=this._nodes[s].inputs.indexOf(r+e),n!==-1&&(this._nodes[s].inputs[n]=r)}),this._allData[r].to.length===0&&(n=this._allOutputIndices.indexOf(r+e),n!==-1&&(this._allOutputIndices[n]=r))}}}deleteNode(e){let o=this._nodes[e];if(o.outputs.length>1){for(let a=1;a<o.outputs.length;a++)if(this._allData[o.outputs[a]].to.length>0)throw new Error("Node deletion with more than one output connected to other nodes is not supported. ")}o.executeNode=!1;let t=o.inputs[0],r=o.outputs[0],n=this._allData[r].to;for(let a=0;a<o.inputs.length;a++){let u=this._allData[o.inputs[a]].to.indexOf(e);if(u===-1)throw new Error("The Value object doesn't have the current Node in it's 'to' property ");this._allData[o.inputs[a]].to.splice(u,1)}this._allData[r]._to=[];let s=this._allOutputIndices.indexOf(r);if(s!==-1&&(this._allOutputIndices[s]=t),n&&n.length>0)for(let a of n){let u=this._nodes[a].inputs.indexOf(r);if(u===-1)throw new Error("The Node object doesn't have the output Value in it's 'inputs' property ");this._nodes[a].inputs[u]=t,this._allData[t].to.push(a)}}removeAllDropoutNodes(){let e=0;for(let o of this._nodes){if(o.opType==="Dropout"){if(o.inputs.length!==1)throw new Error("Dropout nodes should only contain one input. ");if(o.outputs.length!==1&&o.outputs.length!==2)throw new Error("Dropout nodes should contain either 1 or 2 output(s)");if(o.outputs.length===2&&this._allData[o.outputs[1]]._to.length!==0)throw new Error("Dropout nodes's second output should not be referenced by other nodes");this.deleteNode(e)}e++}}removeAllIdentityNodes(){let e=0;for(let o of this._nodes)o.opType==="Identity"&&this.deleteNode(e),e++}isActivation(e){switch(e.opType){case"Relu":case"Sigmoid":case"Clip":return!0;default:return!1}}fuseConvActivationNodes(){for(let e of this._nodes)if(e.opType==="Conv"){let o=this._allData[e.outputs[0]]._to;if(o.length===1&&this.isActivation(this._nodes[o[0]])){let t=this._nodes[o[0]];if(t.opType==="Clip")if(t.inputs.length===1)try{e.attributes.set("activation_params","floats",[t.attributes.getFloat("min"),t.attributes.getFloat("max")])}catch{e.attributes.set("activation_params","floats",[Ve,ze])}else if(t.inputs.length>=3&&this._allData[t.inputs[1]].tensor!==void 0&&this._allData[t.inputs[2]].tensor!==void 0)e.attributes.set("activation_params","floats",[this._allData[t.inputs[1]].tensor.floatData[0],this._allData[t.inputs[2]].tensor.floatData[0]]);else continue;e.attributes.set("activation","string",t.opType),this.deleteNode(o[0])}}}}});var Dp,vg,eo,Lp=O(()=>{"use strict";wn();Ep();Pr();Dp=rr(sr());Y();vg=F.experimental.fbs,eo=class{constructor(){}load(e,o,t){let r;if(!t)try{this.loadFromOnnxFormat(e,o);return}catch(n){if(t!==void 0)throw n;r=n}try{this.loadFromOrtFormat(e,o)}catch(n){throw t!==void 0?n:new Error(`Failed to load model as ONNX format: ${r}
1802as ORT format: ${n}`)}}loadFromOnnxFormat(e,o){let t=Dp.onnx.ModelProto.decode(e);if(Rt.longToNumber(t.irVersion)<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=t.opsetImport.map(n=>({domain:n.domain,version:Rt.longToNumber(n.version)})),this._graph=Wi.from(t.graph,o)}loadFromOrtFormat(e,o){let t=new w.ByteBuffer(e),r=vg.InferenceSession.getRootAsInferenceSession(t).model();if(Rt.longToNumber(r.irVersion())<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=[];for(let s=0;s<r.opsetImportLength();s++){let a=r.opsetImport(s);this._opsets.push({domain:a?.domain(),version:Rt.longToNumber(a.version())})}this._graph=Wi.from(r.graph(),o)}get graph(){return this._graph}get opsets(){return this._opsets}}});var ro,$p=O(()=>{"use strict";Sp();Ap();Ut();Lp();ro=class{constructor(e={}){this._initialized=!1,this.backendHint=e.backendHint,this.profiler=xn.create(e.profiler),this.context={profiler:this.profiler,graphInputTypes:[],graphInputDims:[]}}get inputNames(){return this._model.graph.getInputNames()}get outputNames(){return this._model.graph.getOutputNames()}startProfiling(){this.profiler.start()}endProfiling(){this.profiler.stop()}async loadModel(e,o,t){await this.profiler.event("session","Session.loadModel",async()=>{let r=await Mi(this.backendHint);if(this.sessionHandler=r.createSessionHandler(this.context),this._model=new eo,typeof e=="string"){let n=e.endsWith(".ort");{let a=await(await fetch(e)).arrayBuffer();this.initialize(new Uint8Array(a),n)}}else if(ArrayBuffer.isView(e))this.initialize(e);else{let n=new Uint8Array(e,o||0,t||e.byteLength);this.initialize(n)}})}initialize(e,o){if(this._initialized)throw new Error("already initialized");this.profiler.event("session","Session.initialize",()=>{let t=this.sessionHandler.transformGraph?this.sessionHandler:void 0;this._model.load(e,t,o),this.sessionHandler.onGraphInitialized&&this.sessionHandler.onGraphInitialized(this._model.graph),this.initializeOps(this._model.graph),this._executionPlan=new Zn(this._model.graph,this._ops,this.profiler)}),this._initialized=!0}async run(e){if(!this._initialized)throw new Error("session not initialized yet");return this.profiler.event("session","Session.run",async()=>{let o=this.normalizeAndValidateInputs(e),t=await this._executionPlan.execute(this.sessionHandler,o);return this.createOutput(t)})}normalizeAndValidateInputs(e){let o=this._model.graph.getInputNames();if(Array.isArray(e)){if(e.length!==o.length)throw new Error(`incorrect input array length: expected ${o.length} but got ${e.length}`)}else{if(e.size!==o.length)throw new Error(`incorrect input map size: expected ${o.length} but got ${e.size}`);let t=new Array(e.size),r=0;for(let n=0;n<o.length;++n){let s=e.get(o[n]);if(!s)throw new Error(`missing input tensor for: '${name}'`);t[r++]=s}e=t}if(!this.context.graphInputTypes||this.context.graphInputTypes.length===0||!this.context.graphInputDims||this.context.graphInputDims.length===0){let t=this._model.graph.getInputIndices(),r=this._model.graph.getValues(),n=new Array(t.length);for(let s=0;s<t.length;++s){let a=r[t[s]];n[s]=a.type.shape.dims,this.context.graphInputTypes.push(a.type.tensorType),this.context.graphInputDims.push(e[s].dims)}this.validateInputTensorDims(n,e,!0)}else this.validateInputTensorDims(this.context.graphInputDims,e,!1);return this.validateInputTensorTypes(this.context.graphInputTypes,e),e}validateInputTensorTypes(e,o){for(let t=0;t<o.length;t++){let r=e[t],n=o[t].type;if(r!==n)throw new Error(`input tensor[${t}] check failed: expected type '${r}' but got ${n}`)}}validateInputTensorDims(e,o,t){for(let r=0;r<o.length;r++){let n=e[r],s=o[r].dims;if(!this.compareTensorDims(n,s,t))throw new Error(`input tensor[${r}] check failed: expected shape '[${n.join(",")}]' but got [${s.join(",")}]`)}}compareTensorDims(e,o,t){if(e.length!==o.length)return!1;for(let r=0;r<e.length;++r)if(e[r]!==o[r]&&(!t||e[r]!==0))return!1;return!0}createOutput(e){let o=this._model.graph.getOutputNames();if(e.length!==o.length)throw new Error("expected number of outputs do not match number of generated outputs");let t=new Map;for(let r=0;r<o.length;++r)t.set(o[r],e[r]);return t}initializeOps(e){let o=e.getNodes();this._ops=new Array(o.length);for(let t=0;t<o.length;t++)this._ops[t]=this.sessionHandler.resolve(o[t],this._model.opsets,e)}}});var no,kp=O(()=>{"use strict";Yt();We();no=class{constructor(e){this.session=e;this.inputNames=this.session.inputNames,this.outputNames=this.session.outputNames}async dispose(){}async run(e,o,t){let r=new Map;for(let a in e)if(Object.hasOwnProperty.call(e,a)){let u=e[a];r.set(a,new bt(u.dims,u.type,void 0,void 0,u.data))}let n=await this.session.run(r),s={};return n.forEach((a,u)=>{s[u]=new yt(a.type,a.data,a.dims)}),s}startProfiling(){this.session.startProfiling()}endProfiling(){this.session.endProfiling()}}});var Bp={};Or(Bp,{onnxjsBackend:()=>Ig});var Hi,Ig,Fp=O(()=>{"use strict";$p();kp();Hi=class{async init(){}async createInferenceSessionHandler(e,o){let t=new ro(o);return typeof e=="string"?await t.loadModel(e):await t.loadModel(e),new no(t)}},Ig=new Hi});var oo=O(()=>{"use strict"});var Rp={};Or(Rp,{default:()=>_g});var Cp,Np,_g,Gp=O(()=>{"use strict";qi();Ke();Vr();Cp="ort-wasm-proxy-worker",Np=globalThis.self?.name===Cp;Np&&(self.onmessage=i=>{let{type:e,in:o}=i.data;try{switch(e){case"init-wasm":io(o.wasm).then(()=>{ao(o).then(()=>{postMessage({type:e})},t=>{postMessage({type:e,err:t})})},t=>{postMessage({type:e,err:t})});break;case"init-ep":{let{epName:t,env:r}=o;so(r,t).then(()=>{postMessage({type:e})},n=>{postMessage({type:e,err:n})});break}case"copy-from":{let{buffer:t}=o,r=zr(t);postMessage({type:e,out:r});break}case"create":{let{model:t,options:r}=o;uo(t,r).then(n=>{postMessage({type:e,out:n})},n=>{postMessage({type:e,err:n})});break}case"release":lo(o),postMessage({type:e});break;case"run":{let{sessionId:t,inputIndices:r,inputs:n,outputIndices:s,options:a}=o;fo(t,r,n,s,new Array(s.length).fill(null),a).then(u=>{u.some(l=>l[3]!=="cpu")?postMessage({type:e,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:e,out:u},po([...n,...u]))},u=>{postMessage({type:e,err:u})});break}case"end-profiling":co(o),postMessage({type:e});break;default:}}catch(t){postMessage({type:e,err:t})}});_g=Np?null:i=>new Worker(i??br,{type:"module",name:Cp})});var Up={};Or(Up,{default:()=>Og});var ji,Mp,Og,Vp=O(()=>{"use strict";Mp=(ji=import.meta.url,async function(i={}){function e(){return C.buffer!=oe.buffer&&it(),oe}function o(){return C.buffer!=oe.buffer&&it(),be}function t(){return C.buffer!=oe.buffer&&it(),Z}function r(){return C.buffer!=oe.buffer&&it(),ge}function n(){return C.buffer!=oe.buffer&&it(),ae}var s,a,u=Object.assign({},i),l=new Promise((c,m)=>{s=c,a=m}),f=typeof window=="object",p=typeof importScripts=="function",d=p&&self.name=="em-pthread";u.mountExternalData=(c,m)=>{c.startsWith("./")&&(c=c.substring(2)),(u.Ua||(u.Ua=new Map)).set(c,m)},u.unmountExternalData=()=>{delete u.Ua};var y,T,v=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,shared:!0}).buffer.constructor,S=Object.assign({},u),L="./this.program",P=(c,m)=>{throw m},A="";(f||p)&&(p?A=self.location.href:typeof document<"u"&&document.currentScript&&(A=document.currentScript.src),ji&&(A=ji),A=A.startsWith("blob:")?"":A.substr(0,A.replace(/[?#].*/,"").lastIndexOf("/")+1),p&&(T=c=>{var m=new XMLHttpRequest;return m.open("GET",c,!1),m.responseType="arraybuffer",m.send(null),new Uint8Array(m.response)}),y=(c,m,g)=>{var x=new XMLHttpRequest;x.open("GET",c,!0),x.responseType="arraybuffer",x.onload=()=>{x.status==200||x.status==0&&x.response?m(x.response):g()},x.onerror=g,x.send(null)});var M,V=console.log.bind(console),lt=console.error.bind(console),wt=V,et=lt;if(Object.assign(u,S),S=null,d){let c=function(m){try{var g=m.data,x=g.cmd;if(x==="load"){let I=[];self.onmessage=E=>I.push(E),self.startWorker=()=>{postMessage({cmd:"loaded"});for(let E of I)c(E);self.onmessage=c};for(let E of g.handlers)u[E]&&!u[E].proxy||(u[E]=(...R)=>{postMessage({Za:"callHandler",kb:E,args:R})},E=="print"&&(wt=u[E]),E=="printErr"&&(et=u[E]));C=g.wasmMemory,it(),Dt(g.wasmModule)}else if(x==="run"){$o(g.pthread_ptr,0,0,1,0,0),Ao(g.pthread_ptr),md(),aa(),_t||=!0;try{bd(g.start_routine,g.arg)}catch(I){if(I!="unwind")throw I}}else x==="cancel"?er()&&nn(-1):g.target!=="setimmediate"&&(x==="checkMailbox"?_t&&tn():x&&(et(`worker: received unknown command ${x}`),et(g)))}catch(I){throw Ha(),I}};var Vg=c,Dt,_t=!1;et=function(...m){m=m.join(" "),console.error(m)},self.alert=function(...m){postMessage({Za:"alert",text:m.join(" "),nb:er()})},u.instantiateWasm=(m,g)=>new Promise(x=>{Dt=I=>{I=new WebAssembly.Instance(I,Yr()),g(I),x()}}),self.onunhandledrejection=m=>{throw m.reason||m},self.onmessage=c}u.wasmBinary&&(M=u.wasmBinary);var C,Kr,we,oe,be,Z,ge,ie,ae,se=!1;function it(){var c=C.buffer;u.HEAP8=oe=new Int8Array(c),u.HEAP16=new Int16Array(c),u.HEAPU8=be=new Uint8Array(c),u.HEAPU16=new Uint16Array(c),u.HEAP32=Z=new Int32Array(c),u.HEAPU32=ge=new Uint32Array(c),u.HEAPF32=new Float32Array(c),u.HEAPF64=ae=new Float64Array(c),u.HEAP64=ie=new BigInt64Array(c),u.HEAPU64=new BigUint64Array(c)}if(!d){if(!((C=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0})).buffer instanceof v))throw et("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),Error("bad memory");it()}var Lt=[],Jr=[],Ye=[],ue=0,Ze=null,De=null;function le(){if(--ue==0&&(Ze!==null&&(clearInterval(Ze),Ze=null),De)){var c=De;De=null,c()}}function Mt(c){throw et(c="Aborted("+c+")"),se=!0,we=1,c=new WebAssembly.RuntimeError(c+". Build with -sASSERTIONS for more info."),a(c),c}var ve,gt=c=>c.startsWith("data:application/octet-stream;base64,"),Ot=c=>c.startsWith("file://");function Jt(c){if(c==ve&&M)return new Uint8Array(M);if(T)return T(c);throw"both async and sync fetching of the wasm failed"}function wr(c,m,g){return function(x){if(!M&&(f||p)){if(typeof fetch=="function"&&!Ot(x))return fetch(x,{credentials:"same-origin"}).then(I=>{if(!I.ok)throw`failed to load wasm binary file at '${x}'`;return I.arrayBuffer()}).catch(()=>Jt(x));if(y)return new Promise((I,E)=>{y(x,R=>I(new Uint8Array(R)),E)})}return Promise.resolve().then(()=>Jt(x))}(c).then(x=>WebAssembly.instantiate(x,m)).then(g,x=>{et(`failed to asynchronously prepare wasm: ${x}`),Mt(x)})}function Yr(){return{a:{j:hd,b:yd,E:ca,g:ha,V:ma,A:ya,C:xa,W:Ta,T:wa,L:va,S:Ia,o:_a,B:Oa,y:Sa,U:Aa,z:Pa,_:xd,Z:Td,P:wd,w:vd,F:Id,k:_d,O:Ao,Y:Od,I:Sd,J:Ad,K:Pd,G:La,H:$a,v:Ed,q:Dd,l:Ld,p:$d,e:kd,X:Bd,x:Fd,d:ka,f:Cd,i:Nd,u:Rd,t:Gd,s:Md,Q:Ca,R:Na,D:So,h:Ra,n:Ga,M:Ma,m:Ua,a:C,r:Oo,N:Wa,c:zd}}}var ea={836900:(c,m,g,x,I)=>{if(u===void 0||!u.Ua)return 1;if((c=Ir(c>>>0)).startsWith("./")&&(c=c.substring(2)),!(c=u.Ua.get(c)))return 2;if(x>>>=0,(m>>>=0)+(g>>>=0)>c.byteLength)return 3;try{let E=c.subarray(m,m+g);switch(I){case 0:o().set(E,x>>>0);break;case 1:u.mb(x,E);break;default:return 4}return 0}catch{return 4}},837583:()=>typeof wasmOffsetConverter<"u"};function hd(){return typeof wasmOffsetConverter<"u"}function Io(c){this.name="ExitStatus",this.message=`Program terminated with exit(${c})`,this.status=c}var _o=c=>{c.terminate(),c.onmessage=()=>{}},ra=c=>{Ie.length==0&&(ua(),sa(Ie[0]));var m=Ie.pop();if(!m)return 6;Le.push(m),fe[c.Ra]=m,m.Ra=c.Ra;var g={cmd:"run",start_routine:c.cb,arg:c.ab,pthread_ptr:c.Ra};return m.postMessage(g,c.ib),0},vr=0,st=(c,m,...g)=>{for(var x=2*g.length,I=Fo(),E=Bo(8*x),R=E>>>3,at=0;at<g.length;at++){var Pt=g[at];typeof Pt=="bigint"?(ie[R+2*at]=1n,ie[R+2*at+1]=Pt):(ie[R+2*at]=0n,n()[R+2*at+1>>>0]=Pt)}return c=qa(c,0,x,E,m),on(I),c};function Oo(c){if(d)return st(0,1,c);if(we=c,!(0<vr)){for(var m of Le)_o(m);for(m of Ie)_o(m);Ie=[],Le=[],fe=[],se=!0}P(c,new Io(c))}function na(c){if(d)return st(1,0,c);So(c)}var So=c=>{if(we=c,d)throw na(c),"unwind";Oo(c)},Ie=[],Le=[],oa=[],fe={},ia=c=>{var m=c.Ra;delete fe[m],Ie.push(c),Le.splice(Le.indexOf(c),1),c.Ra=0,ko(m)};function aa(){oa.forEach(c=>c())}var sa=c=>new Promise(m=>{c.onmessage=I=>{var E=(I=I.data).cmd;if(I.targetThread&&I.targetThread!=er()){var R=fe[I.targetThread];R?R.postMessage(I,I.transferList):et(`Internal error! Worker sent a message "${E}" to target pthread ${I.targetThread}, but that thread no longer exists!`)}else E==="checkMailbox"?tn():E==="spawnThread"?ra(I):E==="cleanupThread"?ia(fe[I.thread]):E==="killThread"?(I=I.thread,E=fe[I],delete fe[I],_o(E),ko(I),Le.splice(Le.indexOf(E),1),E.Ra=0):E==="cancelThread"?fe[I.thread].postMessage({cmd:"cancel"}):E==="loaded"?(c.loaded=!0,m(c)):E==="alert"?alert(`Thread ${I.threadId}: ${I.text}`):I.target==="setimmediate"?c.postMessage(I):E==="callHandler"?u[I.handler](...I.args):E&&et(`worker sent an unknown command ${E}`)},c.onerror=I=>{throw et(`worker sent an error! ${I.filename}:${I.lineno}: ${I.message}`),I};var g,x=[];for(g of[])u.hasOwnProperty(g)&&x.push(g);c.postMessage({cmd:"load",handlers:x,wasmMemory:C,wasmModule:Kr})});function ua(){var c=new Worker(new URL(import.meta.url),{type:"module",workerData:"em-pthread",name:"em-pthread"});Ie.push(c)}var la,Zr=c=>{for(;0<c.length;)c.shift()(u)},md=()=>{var c=er(),m=r()[c+52>>>2>>>0];c=r()[c+56>>>2>>>0],Xa(m,m-c),on(m)},Qr=[],bd=(c,m)=>{vr=0;var g=Qr[c];g||(c>=Qr.length&&(Qr.length=c+1),Qr[c]=g=la.get(c)),c=g(m),0<vr?we=c:nn(c)};class gd{constructor(m){this.Xa=m-24}}function yd(c,m,g){var x=new gd(c>>>=0);throw m>>>=0,g>>>=0,r()[x.Xa+16>>>2>>>0]=0,r()[x.Xa+4>>>2>>>0]=m,r()[x.Xa+8>>>2>>>0]=g,c}function fa(c,m,g,x){return d?st(2,1,c,m,g,x):ca(c,m,g,x)}function ca(c,m,g,x){if(c>>>=0,m>>>=0,g>>>=0,x>>>=0,v===void 0)return et("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var I=[];return d&&I.length===0?fa(c,m,g,x):(c={cb:g,Ra:c,ab:x,ib:I},d?(c.Za="spawnThread",postMessage(c,I),0):ra(c))}var pa=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,da=(c,m,g)=>{var x=(m>>>=0)+g;for(g=m;c[g]&&!(g>=x);)++g;if(16<g-m&&c.buffer&&pa)return pa.decode(c.buffer instanceof v?c.slice(m,g):c.subarray(m,g));for(x="";m<g;){var I=c[m++];if(128&I){var E=63&c[m++];if((224&I)==192)x+=String.fromCharCode((31&I)<<6|E);else{var R=63&c[m++];65536>(I=(240&I)==224?(15&I)<<12|E<<6|R:(7&I)<<18|E<<12|R<<6|63&c[m++])?x+=String.fromCharCode(I):(I-=65536,x+=String.fromCharCode(55296|I>>10,56320|1023&I))}}else x+=String.fromCharCode(I)}return x},Ir=(c,m)=>(c>>>=0)?da(o(),c,m):"";function ha(c,m,g){return d?st(3,1,c,m,g):0}function ma(c,m){if(d)return st(4,1,c,m)}var ba=c=>{for(var m=0,g=0;g<c.length;++g){var x=c.charCodeAt(g);127>=x?m++:2047>=x?m+=2:55296<=x&&57343>=x?(m+=4,++g):m+=3}return m},ga=(c,m,g,x)=>{if(!(0<x))return 0;var I=g>>>=0;x=g+x-1;for(var E=0;E<c.length;++E){var R=c.charCodeAt(E);if(55296<=R&&57343>=R&&(R=65536+((1023&R)<<10)|1023&c.charCodeAt(++E)),127>=R){if(g>=x)break;m[g++>>>0]=R}else{if(2047>=R){if(g+1>=x)break;m[g++>>>0]=192|R>>6}else{if(65535>=R){if(g+2>=x)break;m[g++>>>0]=224|R>>12}else{if(g+3>=x)break;m[g++>>>0]=240|R>>18,m[g++>>>0]=128|R>>12&63}m[g++>>>0]=128|R>>6&63}m[g++>>>0]=128|63&R}}return m[g>>>0]=0,g-I},_r=(c,m,g)=>ga(c,o(),m,g);function ya(c,m){if(d)return st(5,1,c,m)}function xa(c,m,g){if(d)return st(6,1,c,m,g)}function Ta(c,m,g){return d?st(7,1,c,m,g):0}function wa(c,m){if(d)return st(8,1,c,m)}function va(c,m,g){if(d)return st(9,1,c,m,g)}function Ia(c,m,g,x){if(d)return st(10,1,c,m,g,x)}function _a(c,m,g,x){if(d)return st(11,1,c,m,g,x)}function Oa(c,m,g,x){if(d)return st(12,1,c,m,g,x)}function Sa(c){if(d)return st(13,1,c)}function Aa(c,m){if(d)return st(14,1,c,m)}function Pa(c,m,g){if(d)return st(15,1,c,m,g)}var xd=()=>{Mt("")},Td=()=>1;function wd(c){$o(c>>>0,!p,1,!f,131072,!1),aa()}function Ao(c){c>>>=0,typeof Atomics.jb=="function"&&(Atomics.jb(t(),c>>>2,c).value.then(tn),c+=128,Atomics.store(t(),c>>>2,1))}var tn=()=>{var c=er();if(c&&(Ao(c),c=ja,!se))try{if(c(),!(0<vr))try{d?nn(we):So(we)}catch(m){m instanceof Io||m=="unwind"||P(1,m)}}catch(m){m instanceof Io||m=="unwind"||P(1,m)}};function vd(c,m){(c>>>=0)==m>>>0?setTimeout(tn):d?postMessage({targetThread:c,cmd:"checkMailbox"}):(c=fe[c])&&c.postMessage({cmd:"checkMailbox"})}var Po=[];function Id(c,m,g,x,I){for(m>>>=0,x/=2,Po.length=x,g=I>>>0>>>3,I=0;I<x;I++)Po[I]=ie[g+2*I]?ie[g+2*I+1]:n()[g+2*I+1>>>0];return(m?ea[m]:Wd[c])(...Po)}function _d(c){c>>>=0,d?postMessage({cmd:"cleanupThread",thread:c}):ia(fe[c])}function Od(c){}function Sd(c,m){c=-9007199254740992>c||9007199254740992<c?NaN:Number(c),m>>>=0,c=new Date(1e3*c),t()[m>>>2>>>0]=c.getUTCSeconds(),t()[m+4>>>2>>>0]=c.getUTCMinutes(),t()[m+8>>>2>>>0]=c.getUTCHours(),t()[m+12>>>2>>>0]=c.getUTCDate(),t()[m+16>>>2>>>0]=c.getUTCMonth(),t()[m+20>>>2>>>0]=c.getUTCFullYear()-1900,t()[m+24>>>2>>>0]=c.getUTCDay(),c=(c.getTime()-Date.UTC(c.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,t()[m+28>>>2>>>0]=c}var Qe=c=>c%4==0&&(c%100!=0||c%400==0),Ea=[0,31,60,91,121,152,182,213,244,274,305,335],Da=[0,31,59,90,120,151,181,212,243,273,304,334];function Ad(c,m){c=-9007199254740992>c||9007199254740992<c?NaN:Number(c),m>>>=0,c=new Date(1e3*c),t()[m>>>2>>>0]=c.getSeconds(),t()[m+4>>>2>>>0]=c.getMinutes(),t()[m+8>>>2>>>0]=c.getHours(),t()[m+12>>>2>>>0]=c.getDate(),t()[m+16>>>2>>>0]=c.getMonth(),t()[m+20>>>2>>>0]=c.getFullYear()-1900,t()[m+24>>>2>>>0]=c.getDay();var g=(Qe(c.getFullYear())?Ea:Da)[c.getMonth()]+c.getDate()-1|0;t()[m+28>>>2>>>0]=g,t()[m+36>>>2>>>0]=-60*c.getTimezoneOffset(),g=new Date(c.getFullYear(),6,1).getTimezoneOffset();var x=new Date(c.getFullYear(),0,1).getTimezoneOffset();c=0|(g!=x&&c.getTimezoneOffset()==Math.min(x,g)),t()[m+32>>>2>>>0]=c}function Pd(c){c>>>=0;var m=new Date(t()[c+20>>>2>>>0]+1900,t()[c+16>>>2>>>0],t()[c+12>>>2>>>0],t()[c+8>>>2>>>0],t()[c+4>>>2>>>0],t()[c>>>2>>>0],0),g=t()[c+32>>>2>>>0],x=m.getTimezoneOffset(),I=new Date(m.getFullYear(),6,1).getTimezoneOffset(),E=new Date(m.getFullYear(),0,1).getTimezoneOffset(),R=Math.min(E,I);return 0>g?t()[c+32>>>2>>>0]=+(I!=E&&R==x):0<g!=(R==x)&&(I=Math.max(E,I),m.setTime(m.getTime()+6e4*((0<g?R:I)-x))),t()[c+24>>>2>>>0]=m.getDay(),g=(Qe(m.getFullYear())?Ea:Da)[m.getMonth()]+m.getDate()-1|0,t()[c+28>>>2>>>0]=g,t()[c>>>2>>>0]=m.getSeconds(),t()[c+4>>>2>>>0]=m.getMinutes(),t()[c+8>>>2>>>0]=m.getHours(),t()[c+12>>>2>>>0]=m.getDate(),t()[c+16>>>2>>>0]=m.getMonth(),t()[c+20>>>2>>>0]=m.getYear(),c=m.getTime(),BigInt(isNaN(c)?-1:c/1e3)}function La(c,m,g,x,I,E,R){return d?st(16,1,c,m,g,x,I,E,R):-52}function $a(c,m,g,x,I,E){if(d)return st(17,1,c,m,g,x,I,E)}function Ed(c,m,g,x){c>>>=0,m>>>=0,g>>>=0,x>>>=0;var I=new Date().getFullYear(),E=new Date(I,0,1),R=new Date(I,6,1);I=E.getTimezoneOffset();var at=R.getTimezoneOffset(),Pt=Math.max(I,at);r()[c>>>2>>>0]=60*Pt,t()[m>>>2>>>0]=+(I!=at),E=(c=$t=>$t.toLocaleTimeString(void 0,{hour12:!1,timeZoneName:"short"}).split(" ")[1])(E),R=c(R),at<I?(_r(E,g,17),_r(R,x,17)):(_r(E,x,17),_r(R,g,17))}var Eo=[];function Dd(c,m,g){c>>>=0,m>>>=0,g>>>=0,Eo.length=0;for(var x;x=o()[m++>>>0];){var I=x!=105;g+=(I&=x!=112)&&g%8?4:0,Eo.push(x==112?r()[g>>>2>>>0]:x==106?ie[g>>>3]:x==105?t()[g>>>2>>>0]:n()[g>>>3>>>0]),g+=I?8:4}return ea[c](...Eo)}var Ld=()=>{},$d=()=>Date.now();function kd(c,m){return et(Ir(c>>>0,m>>>0))}var ka,Bd=()=>{throw vr+=1,"unwind"};function Fd(){return 4294901760}ka=()=>performance.timeOrigin+performance.now();var Cd=()=>navigator.hardwareConcurrency;function Nd(){return Mt("Cannot use emscripten_pc_get_function without -sUSE_OFFSET_CONVERTER"),0}function Rd(c){c>>>=0;var m=o().length;if(c<=m||4294901760<c)return!1;for(var g=1;4>=g;g*=2){var x=m*(1+.2/g);x=Math.min(x,c+100663296);var I=Math;x=Math.max(c,x);t:{I=(I.min.call(I,4294901760,x+(65536-x%65536)%65536)-C.buffer.byteLength+65535)/65536;try{C.grow(I),it();var E=1;break t}catch{}E=void 0}if(E)return!0}return!1}var en=()=>(Mt("Cannot use convertFrameToPC (needed by __builtin_return_address) without -sUSE_OFFSET_CONVERTER"),0),tr={},Ba=c=>{c.forEach(m=>{var g=en();g&&(tr[g]=m)})};function Gd(){var c=Error().stack.toString().split(`
1803`);return c[0]=="Error"&&c.shift(),Ba(c),tr.$a=en(),tr.bb=c,tr.$a}function Md(c,m,g){if(c>>>=0,m>>>=0,tr.$a==c)var x=tr.bb;else(x=Error().stack.toString().split(`
1804`))[0]=="Error"&&x.shift(),Ba(x);for(var I=3;x[I]&&en()!=c;)++I;for(c=0;c<g&&x[c+I];++c)t()[m+4*c>>>2>>>0]=en();return c}var Do,Lo={},Fa=()=>{if(!Do){var c,m={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:L||"./this.program"};for(c in Lo)Lo[c]===void 0?delete m[c]:m[c]=Lo[c];var g=[];for(c in m)g.push(`${c}=${m[c]}`);Do=g}return Do};function Ca(c,m){if(d)return st(18,1,c,m);c>>>=0,m>>>=0;var g=0;return Fa().forEach((x,I)=>{var E=m+g;for(I=r()[c+4*I>>>2>>>0]=E,E=0;E<x.length;++E)e()[I++>>>0]=x.charCodeAt(E);e()[I>>>0]=0,g+=x.length+1}),0}function Na(c,m){if(d)return st(19,1,c,m);c>>>=0,m>>>=0;var g=Fa();r()[c>>>2>>>0]=g.length;var x=0;return g.forEach(I=>x+=I.length+1),r()[m>>>2>>>0]=x,0}function Ra(c){return d?st(20,1,c):52}function Ga(c,m,g,x){return d?st(21,1,c,m,g,x):52}function Ma(c,m,g,x){return d?st(22,1,c,m,g,x):70}var Ud=[null,[],[]];function Ua(c,m,g,x){if(d)return st(23,1,c,m,g,x);m>>>=0,g>>>=0,x>>>=0;for(var I=0,E=0;E<g;E++){var R=r()[m>>>2>>>0],at=r()[m+4>>>2>>>0];m+=8;for(var Pt=0;Pt<at;Pt++){var $t=o()[R+Pt>>>0],Ft=Ud[c];$t===0||$t===10?((c===1?wt:et)(da(Ft,0)),Ft.length=0):Ft.push($t)}I+=at}return r()[x>>>2>>>0]=I,0}var Va=[31,29,31,30,31,30,31,31,30,31,30,31],za=[31,28,31,30,31,30,31,31,30,31,30,31],Vd=(c,m)=>{e().set(c,m>>>0)};function Wa(c,m,g,x){function I(_,Q,ft){for(_=typeof _=="number"?_.toString():_||"";_.length<Q;)_=ft[0]+_;return _}function E(_,Q){return I(_,Q,"0")}function R(_,Q){function ft(Za){return 0>Za?-1:0<Za?1:0}var $e;return($e=ft(_.getFullYear()-Q.getFullYear()))===0&&($e=ft(_.getMonth()-Q.getMonth()))===0&&($e=ft(_.getDate()-Q.getDate())),$e}function at(_){switch(_.getDay()){case 0:return new Date(_.getFullYear()-1,11,29);case 1:return _;case 2:return new Date(_.getFullYear(),0,3);case 3:return new Date(_.getFullYear(),0,2);case 4:return new Date(_.getFullYear(),0,1);case 5:return new Date(_.getFullYear()-1,11,31);case 6:return new Date(_.getFullYear()-1,11,30)}}function Pt(_){var Q=_.Sa;for(_=new Date(new Date(_.Ta+1900,0,1).getTime());0<Q;){var ft=_.getMonth(),$e=(Qe(_.getFullYear())?Va:za)[ft];if(!(Q>$e-_.getDate())){_.setDate(_.getDate()+Q);break}Q-=$e-_.getDate()+1,_.setDate(1),11>ft?_.setMonth(ft+1):(_.setMonth(0),_.setFullYear(_.getFullYear()+1))}return ft=new Date(_.getFullYear()+1,0,4),Q=at(new Date(_.getFullYear(),0,4)),ft=at(ft),0>=R(Q,_)?0>=R(ft,_)?_.getFullYear()+1:_.getFullYear():_.getFullYear()-1}c>>>=0,m>>>=0,g>>>=0,x>>>=0;var $t=r()[x+40>>>2>>>0];for(var Ft in x={gb:t()[x>>>2>>>0],fb:t()[x+4>>>2>>>0],Va:t()[x+8>>>2>>>0],Ya:t()[x+12>>>2>>>0],Wa:t()[x+16>>>2>>>0],Ta:t()[x+20>>>2>>>0],Qa:t()[x+24>>>2>>>0],Sa:t()[x+28>>>2>>>0],ob:t()[x+32>>>2>>>0],eb:t()[x+36>>>2>>>0],hb:$t?Ir($t):""},g=Ir(g),$t={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})g=g.replace(new RegExp(Ft,"g"),$t[Ft]);var Ja="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),Ya="January February March April May June July August September October November December".split(" ");for(Ft in $t={"%a":_=>Ja[_.Qa].substring(0,3),"%A":_=>Ja[_.Qa],"%b":_=>Ya[_.Wa].substring(0,3),"%B":_=>Ya[_.Wa],"%C":_=>E((_.Ta+1900)/100|0,2),"%d":_=>E(_.Ya,2),"%e":_=>I(_.Ya,2," "),"%g":_=>Pt(_).toString().substring(2),"%G":Pt,"%H":_=>E(_.Va,2),"%I":_=>((_=_.Va)==0?_=12:12<_&&(_-=12),E(_,2)),"%j":_=>{for(var Q=0,ft=0;ft<=_.Wa-1;Q+=(Qe(_.Ta+1900)?Va:za)[ft++]);return E(_.Ya+Q,3)},"%m":_=>E(_.Wa+1,2),"%M":_=>E(_.fb,2),"%n":()=>`
1805`,"%p":_=>0<=_.Va&&12>_.Va?"AM":"PM","%S":_=>E(_.gb,2),"%t":()=>" ","%u":_=>_.Qa||7,"%U":_=>E(Math.floor((_.Sa+7-_.Qa)/7),2),"%V":_=>{var Q=Math.floor((_.Sa+7-(_.Qa+6)%7)/7);if(2>=(_.Qa+371-_.Sa-2)%7&&Q++,Q)Q==53&&((ft=(_.Qa+371-_.Sa)%7)==4||ft==3&&Qe(_.Ta)||(Q=1));else{Q=52;var ft=(_.Qa+7-_.Sa-1)%7;(ft==4||ft==5&&Qe(_.Ta%400-1))&&Q++}return E(Q,2)},"%w":_=>_.Qa,"%W":_=>E(Math.floor((_.Sa+7-(_.Qa+6)%7)/7),2),"%y":_=>(_.Ta+1900).toString().substring(2),"%Y":_=>_.Ta+1900,"%z":_=>{var Q=0<=(_=_.eb);return _=Math.abs(_)/60,(Q?"+":"-")+("0000"+(_/60*100+_%60)).slice(-4)},"%Z":_=>_.hb,"%%":()=>"%"},g=g.replace(/%%/g,"\0\0"),$t)g.includes(Ft)&&(g=g.replace(new RegExp(Ft,"g"),$t[Ft](x)));return Ft=function(_){var Q=Array(ba(_)+1);return ga(_,Q,0,Q.length),Q}(g=g.replace(/\0\0/g,"%")),Ft.length>m?0:(Vd(Ft,c),Ft.length-1)}function zd(c,m,g,x){return Wa(c>>>0,m>>>0,g>>>0,x>>>0)}d||function(){for(var c=u.numThreads-1;c--;)ua();Lt.unshift(()=>{ue++,function(m){d?m():Promise.all(Ie.map(sa)).then(m)}(()=>le())})}();var Wd=[Oo,na,fa,ha,ma,ya,xa,Ta,wa,va,Ia,_a,Oa,Sa,Aa,Pa,La,$a,Ca,Na,Ra,Ga,Ma,Ua],U=function(){function c(g,x){return U=g.exports,U=function(){var I=U,E=at=>()=>at()>>>0,R=at=>Pt=>at(Pt)>>>0;return(I=Object.assign({},I)).Ba=E(I.Ba),I.Ca=R(I.Ca),I.emscripten_main_runtime_thread_id=E(I.emscripten_main_runtime_thread_id),I.Oa=R(I.Oa),I.Pa=E(I.Pa),I}(),oa.push(U.Ea),la=U.Fa,Jr.unshift(U.$),Kr=x,le(),U}var m=Yr();if(ue++,u.instantiateWasm)try{return u.instantiateWasm(m,c)}catch(g){et(`Module.instantiateWasm callback failed with error: ${g}`),a(g)}return ve||=u.locateFile?gt("ort-wasm-simd-threaded.wasm")?"ort-wasm-simd-threaded.wasm":u.locateFile?u.locateFile("ort-wasm-simd-threaded.wasm",A):A+"ort-wasm-simd-threaded.wasm":new URL("ort-wasm-simd-threaded.wasm",import.meta.url).href,function(g,x){var I=ve;return M||typeof WebAssembly.instantiateStreaming!="function"||gt(I)||Ot(I)||typeof fetch!="function"?wr(I,g,x):fetch(I,{credentials:"same-origin"}).then(E=>WebAssembly.instantiateStreaming(E,g).then(x,function(R){return et(`wasm streaming compile failed: ${R}`),et("falling back to ArrayBuffer instantiation"),wr(I,g,x)}))}(m,function(g){c(g.instance,g.module)}).catch(a),{}}();u._OrtInit=(c,m)=>(u._OrtInit=U.aa)(c,m),u._OrtGetLastError=(c,m)=>(u._OrtGetLastError=U.ba)(c,m),u._OrtCreateSessionOptions=(c,m,g,x,I,E,R,at,Pt,$t)=>(u._OrtCreateSessionOptions=U.ca)(c,m,g,x,I,E,R,at,Pt,$t),u._OrtAppendExecutionProvider=(c,m)=>(u._OrtAppendExecutionProvider=U.da)(c,m),u._OrtAddFreeDimensionOverride=(c,m,g)=>(u._OrtAddFreeDimensionOverride=U.ea)(c,m,g),u._OrtAddSessionConfigEntry=(c,m,g)=>(u._OrtAddSessionConfigEntry=U.fa)(c,m,g),u._OrtReleaseSessionOptions=c=>(u._OrtReleaseSessionOptions=U.ga)(c),u._OrtCreateSession=(c,m,g)=>(u._OrtCreateSession=U.ha)(c,m,g),u._OrtReleaseSession=c=>(u._OrtReleaseSession=U.ia)(c),u._OrtGetInputOutputCount=(c,m,g)=>(u._OrtGetInputOutputCount=U.ja)(c,m,g),u._OrtGetInputName=(c,m)=>(u._OrtGetInputName=U.ka)(c,m),u._OrtGetOutputName=(c,m)=>(u._OrtGetOutputName=U.la)(c,m),u._OrtFree=c=>(u._OrtFree=U.ma)(c),u._OrtCreateTensor=(c,m,g,x,I,E)=>(u._OrtCreateTensor=U.na)(c,m,g,x,I,E),u._OrtGetTensorData=(c,m,g,x,I)=>(u._OrtGetTensorData=U.oa)(c,m,g,x,I),u._OrtReleaseTensor=c=>(u._OrtReleaseTensor=U.pa)(c),u._OrtCreateRunOptions=(c,m,g,x)=>(u._OrtCreateRunOptions=U.qa)(c,m,g,x),u._OrtAddRunConfigEntry=(c,m,g)=>(u._OrtAddRunConfigEntry=U.ra)(c,m,g),u._OrtReleaseRunOptions=c=>(u._OrtReleaseRunOptions=U.sa)(c),u._OrtCreateBinding=c=>(u._OrtCreateBinding=U.ta)(c),u._OrtBindInput=(c,m,g)=>(u._OrtBindInput=U.ua)(c,m,g),u._OrtBindOutput=(c,m,g,x)=>(u._OrtBindOutput=U.va)(c,m,g,x),u._OrtClearBoundOutputs=c=>(u._OrtClearBoundOutputs=U.wa)(c),u._OrtReleaseBinding=c=>(u._OrtReleaseBinding=U.xa)(c),u._OrtRunWithBinding=(c,m,g,x,I)=>(u._OrtRunWithBinding=U.ya)(c,m,g,x,I),u._OrtRun=(c,m,g,x,I,E,R,at)=>(u._OrtRun=U.za)(c,m,g,x,I,E,R,at),u._OrtEndProfiling=c=>(u._OrtEndProfiling=U.Aa)(c);var er=()=>(er=U.Ba)();u._malloc=c=>(u._malloc=U.Ca)(c),u._free=c=>(u._free=U.Da)(c);var rn,$o=(c,m,g,x,I,E)=>($o=U.Ga)(c,m,g,x,I,E),Ha=()=>(Ha=U.Ha)(),qa=(c,m,g,x,I)=>(qa=U.Ia)(c,m,g,x,I),ko=c=>(ko=U.Ja)(c),nn=c=>(nn=U.Ka)(c),ja=()=>(ja=U.La)(),Xa=(c,m)=>(Xa=U.Ma)(c,m),on=c=>(on=U.Na)(c),Bo=c=>(Bo=U.Oa)(c),Fo=()=>(Fo=U.Pa)();function Ka(){0<ue||(d?(s(u),d||Zr(Jr),startWorker(u)):(Zr(Lt),0<ue||rn||(rn=!0,u.calledRun=!0,se||(d||Zr(Jr),s(u),d||Zr(Ye)))))}return u.___start_em_js=837640,u.___stop_em_js=837701,u.stackSave=()=>Fo(),u.stackRestore=c=>on(c),u.stackAlloc=c=>Bo(c),u.UTF8ToString=Ir,u.stringToUTF8=_r,u.lengthBytesUTF8=ba,De=function c(){rn||Ka(),rn||(De=c)},Ka(),l}),Og=Mp;globalThis.self?.name==="em-pthread"&&Mp()});var br,Sg,Ag,Pg,zp,Wp,Eg,Hp,Vr=O(()=>{"use strict";oo();br=!1?void 0:import.meta.url??(typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0),Sg=!1||typeof location>"u"?void 0:location.origin,Ag=(i,e)=>{try{let o=e??br;return(o?new URL(i,o):new URL(i)).origin===Sg}catch{return!1}},Pg=async i=>{let o=await(await fetch(i,{credentials:"same-origin"})).blob();return URL.createObjectURL(o)},zp=(Gp(),sn(Rp)).default,Wp=async()=>{if(!br)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(Ag(br))return[void 0,zp()];let i=await Pg(br);return[i,zp(i)]},Eg=(Vp(),sn(Up)).default,Hp=async(i,e,o)=>[void 0,Eg]});var Xi,Ki,ho,qp,Dg,Lg,io,xt,Ke=O(()=>{"use strict";Vr();Ki=!1,ho=!1,qp=!1,Dg=()=>{if(typeof SharedArrayBuffer>"u")return!1;try{return typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11]))}catch{return!1}},Lg=()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}},io=async i=>{if(Ki)return Promise.resolve();if(ho)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(qp)throw new Error("previous call to 'initializeWebAssembly()' failed.");ho=!0;let e=i.initTimeout,o=i.numThreads;if(!Lg())throw new Error("WebAssembly SIMD is not supported in the current environment.");let t=Dg();o>1&&!t&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+o+", but this will not work unless you enable crossOriginIsolated mode. See https://web.dev/cross-origin-isolation-guide/ for more info."),console.warn("WebAssembly multi-threading is not supported in the current environment. Falling back to single-threading."),i.numThreads=o=1);let r=i.wasmPaths,n=typeof r=="string"?r:void 0,s=r?.mjs,a=s?.href??s,u=r?.wasm,l=u?.href??u,f=i.wasmBinary,[p,d]=await Hp(a,n,o>1),y=!1,T=[];if(e>0&&T.push(new Promise(v=>{setTimeout(()=>{y=!0,v()},e)})),T.push(new Promise((v,S)=>{let L={numThreads:o};f?L.wasmBinary=f:(l||n)&&(L.locateFile=(P,A)=>l??(n??A)+P),d(L).then(P=>{ho=!1,Ki=!0,Xi=P,v(),p&&URL.revokeObjectURL(p)},P=>{ho=!1,qp=!0,S(P)})})),await Promise.race(T),y)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},xt=()=>{if(Ki&&Xi)return Xi;throw new Error("WebAssembly is not initialized yet.")}});var Tt,Wr,ht,mo=O(()=>{"use strict";Ke();Tt=(i,e)=>{let o=xt(),t=o.lengthBytesUTF8(i)+1,r=o._malloc(t);return o.stringToUTF8(i,r,t),e.push(r),r},Wr=(i,e,o,t)=>{if(typeof i=="object"&&i!==null){if(o.has(i))throw new Error("Circular reference in options");o.add(i)}Object.entries(i).forEach(([r,n])=>{let s=e?e+r:r;if(typeof n=="object")Wr(n,s+".",o,t);else if(typeof n=="string"||typeof n=="number")t(s,n.toString());else if(typeof n=="boolean")t(s,n?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof n}`)})},ht=i=>{let e=xt(),o=e.stackSave();try{let t=e.stackAlloc(8);e._OrtGetLastError(t,t+4);let r=e.HEAP32[t/4],n=e.HEAPU32[t/4+1],s=n?e.UTF8ToString(n):"";throw new Error(`${i} ERROR_CODE: ${r}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(o)}}});var jp,Xp=O(()=>{"use strict";Ke();mo();jp=i=>{let e=xt(),o=0,t=[],r=i||{};try{if(i?.logSeverityLevel===void 0)r.logSeverityLevel=2;else if(typeof i.logSeverityLevel!="number"||!Number.isInteger(i.logSeverityLevel)||i.logSeverityLevel<0||i.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${i.logSeverityLevel}`);if(i?.logVerbosityLevel===void 0)r.logVerbosityLevel=0;else if(typeof i.logVerbosityLevel!="number"||!Number.isInteger(i.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${i.logVerbosityLevel}`);i?.terminate===void 0&&(r.terminate=!1);let n=0;return i?.tag!==void 0&&(n=Tt(i.tag,t)),o=e._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,n),o===0&&ht("Can't create run options."),i?.extra!==void 0&&Wr(i.extra,"",new WeakSet,(s,a)=>{let u=Tt(s,t),l=Tt(a,t);e._OrtAddRunConfigEntry(o,u,l)!==0&&ht(`Can't set a run config entry: ${s} - ${a}.`)}),[o,t]}catch(n){throw o!==0&&e._OrtReleaseRunOptions(o),t.forEach(s=>e._free(s)),n}}});var $g,kg,Bg,Fg,Kp,Jp=O(()=>{"use strict";Ke();mo();$g=i=>{switch(i){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${i}`)}},kg=i=>{switch(i){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${i}`)}},Bg=i=>{i.extra||(i.extra={}),i.extra.session||(i.extra.session={});let e=i.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),i.executionProviders&&i.executionProviders.some(o=>(typeof o=="string"?o:o.name)==="webgpu")&&(i.enableMemPattern=!1)},Fg=(i,e,o)=>{for(let t of e){let r=typeof t=="string"?t:t.name;switch(r){case"webnn":if(r="WEBNN",typeof t!="string"){let a=t?.deviceType;if(a){let u=Tt("deviceType",o),l=Tt(a,o);xt()._OrtAddSessionConfigEntry(i,u,l)!==0&&ht(`Can't set a session config entry: 'deviceType' - ${a}.`)}}break;case"webgpu":if(r="JS",typeof t!="string"){let s=t;if(s?.preferredLayout){if(s.preferredLayout!=="NCHW"&&s.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${s.preferredLayout}`);let a=Tt("preferredLayout",o),u=Tt(s.preferredLayout,o);xt()._OrtAddSessionConfigEntry(i,a,u)!==0&&ht(`Can't set a session config entry: 'preferredLayout' - ${s.preferredLayout}.`)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${r}`)}let n=Tt(r,o);xt()._OrtAppendExecutionProvider(i,n)!==0&&ht(`Can't append execution provider: ${r}.`)}},Kp=i=>{let e=xt(),o=0,t=[],r=i||{};Bg(r);try{let n=$g(r.graphOptimizationLevel??"all"),s=kg(r.executionMode??"sequential"),a=typeof r.logId=="string"?Tt(r.logId,t):0,u=r.logSeverityLevel??2;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log serverity level is not valid: ${u}`);let l=r.logVerbosityLevel??0;if(!Number.isInteger(l)||l<0||l>4)throw new Error(`log verbosity level is not valid: ${l}`);let f=typeof r.optimizedModelFilePath=="string"?Tt(r.optimizedModelFilePath,t):0;if(o=e._OrtCreateSessionOptions(n,!!r.enableCpuMemArena,!!r.enableMemPattern,s,!!r.enableProfiling,0,a,u,l,f),o===0&&ht("Can't create session options."),r.executionProviders&&Fg(o,r.executionProviders,t),r.enableGraphCapture!==void 0){if(typeof r.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);let p=Tt("enableGraphCapture",t),d=Tt(r.enableGraphCapture.toString(),t);e._OrtAddSessionConfigEntry(o,p,d)!==0&&ht(`Can't set a session config entry: 'enableGraphCapture' - ${r.enableGraphCapture}.`)}if(r.freeDimensionOverrides)for(let[p,d]of Object.entries(r.freeDimensionOverrides)){if(typeof p!="string")throw new Error(`free dimension override name must be a string: ${p}`);if(typeof d!="number"||!Number.isInteger(d)||d<0)throw new Error(`free dimension override value must be a non-negative integer: ${d}`);let y=Tt(p,t);e._OrtAddFreeDimensionOverride(o,y,d)!==0&&ht(`Can't set a free dimension override: ${p} - ${d}.`)}return r.extra!==void 0&&Wr(r.extra,"",new WeakSet,(p,d)=>{let y=Tt(p,t),T=Tt(d,t);e._OrtAddSessionConfigEntry(o,y,T)!==0&&ht(`Can't set a session config entry: ${p} - ${d}.`)}),[o,t]}catch(n){throw o!==0&&e._OrtReleaseSessionOptions(o),t.forEach(s=>e._free(s)),n}}});var Hr,Yp,qr,Zp,Qp,bo,go,td,Ji=O(()=>{"use strict";Hr=i=>{switch(i){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float16":return 10;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;case"int4":return 22;case"uint4":return 21;default:throw new Error(`unsupported data type: ${i}`)}},Yp=i=>{switch(i){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 10:return"float16";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";case 22:return"int4";case 21:return"uint4";default:throw new Error(`unsupported data type: ${i}`)}},qr=(i,e)=>{let o=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][i],t=typeof e=="number"?e:e.reduce((r,n)=>r*n,1);return o>0?Math.ceil(t*o):void 0},Zp=i=>{switch(i){case"float16":return typeof Float16Array<"u"&&Float16Array.from?Float16Array:Uint16Array;case"float32":return Float32Array;case"uint8":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"bool":return Uint8Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${i}`)}},Qp=i=>{switch(i){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${i}`)}},bo=i=>i==="float32"||i==="float16"||i==="int32"||i==="int64"||i==="uint32"||i==="uint8"||i==="bool"||i==="uint4"||i==="int4",go=i=>i==="float32"||i==="float16"||i==="int32"||i==="int64"||i==="uint32"||i==="uint64"||i==="int8"||i==="uint8"||i==="bool",td=i=>{switch(i){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${i}`)}}});var jr,Yi=O(()=>{"use strict";oo();jr=async i=>{if(typeof i=="string")if(!1)try{let{readFile:e}=Co("node:fs/promises");return new Uint8Array(await e(i))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:o}=Co("node:fs"),t=o(i),r=[];for await(let n of t)r.push(n);return new Uint8Array(Buffer.concat(r))}throw e}else{let e=await fetch(i);if(!e.ok)throw new Error(`failed to load external data file: ${i}`);let o=e.headers.get("Content-Length"),t=o?parseInt(o,10):0;if(t<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${i}, no response body.`);let r=e.body.getReader(),n;try{n=new ArrayBuffer(t)}catch(a){if(a instanceof RangeError){let u=Math.ceil(t/65536);n=new WebAssembly.Memory({initial:u,maximum:u}).buffer}else throw a}let s=0;for(;;){let{done:a,value:u}=await r.read();if(a)break;let l=u.byteLength;new Uint8Array(n,s,l).set(u),s+=l}return new Uint8Array(n,0,t)}}else return i instanceof Blob?new Uint8Array(await i.arrayBuffer()):i instanceof Uint8Array?i:new Uint8Array(i)}});var Cg,ao,so,yr,Ng,zr,uo,lo,ed,fo,co,po,qi=O(()=>{"use strict";Xp();Jp();Ji();Ke();mo();Yi();Cg=(i,e)=>{xt()._OrtInit(i,e)!==0&&ht("Can't initialize onnxruntime.")},ao=async i=>{Cg(i.wasm.numThreads,Qp(i.logLevel))},so=async(i,e)=>{},yr=new Map,Ng=i=>{let e=xt(),o=e.stackSave();try{let t=e.stackAlloc(8);return e._OrtGetInputOutputCount(i,t,t+4)!==0&&ht("Can't get session input/output count."),[e.HEAP32[t/4],e.HEAP32[t/4+1]]}finally{e.stackRestore(o)}},zr=i=>{let e=xt(),o=e._malloc(i.byteLength);if(o===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${i.byteLength}.`);return e.HEAPU8.set(i,o),[o,i.byteLength]},uo=async(i,e)=>{let o,t,r=xt();Array.isArray(i)?[o,t]=i:i.buffer===r.HEAPU8.buffer?[o,t]=[i.byteOffset,i.byteLength]:[o,t]=zr(i);let n=0,s=0,a=0,u=[],l=[],f=[];try{if([s,u]=Kp(e),e?.externalData&&r.mountExternalData){let P=[];for(let A of e.externalData){let M=typeof A=="string"?A:A.path;P.push(jr(typeof A=="string"?A:A.data).then(V=>{r.mountExternalData(M,V)}))}await Promise.all(P)}for(let P of e?.executionProviders??[])if((typeof P=="string"?P:P.name)==="webnn"){if(r.shouldTransferToMLTensor=!1,r.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof P!="string"){let M=P,V=M?.context,lt=M?.gpuDevice,wt=M?.deviceType,et=M?.numThreads,Dt=M?.powerPreference;V?r.currentContext=V:lt?r.currentContext=await navigator.ml.createContext(lt):r.currentContext=await navigator.ml.createContext({deviceType:wt,numThreads:et,powerPreference:Dt})}else r.currentContext=await navigator.ml.createContext();break}n=await r._OrtCreateSession(o,t,s),n===0&&ht("Can't create a session."),r.currentContext&&(r.jsepRegisterMLContext(n,r.currentContext),r.currentContext=void 0,r.shouldTransferToMLTensor=!0);let[p,d]=Ng(n),y=!!e?.enableGraphCapture,T=[],v=[],S=[];for(let P=0;P<p;P++){let A=r._OrtGetInputName(n,P);A===0&&ht("Can't get an input name."),l.push(A),T.push(r.UTF8ToString(A))}for(let P=0;P<d;P++){let A=r._OrtGetOutputName(n,P);A===0&&ht("Can't get an output name."),f.push(A);let M=r.UTF8ToString(A);v.push(M)}let L=null;return yr.set(n,[n,l,f,L,y,!1]),[n,T,v]}catch(p){throw l.forEach(d=>r._OrtFree(d)),f.forEach(d=>r._OrtFree(d)),a!==0&&r._OrtReleaseBinding(a),n!==0&&r._OrtReleaseSession(n),p}finally{r._free(o),s!==0&&r._OrtReleaseSessionOptions(s),u.forEach(p=>r._free(p)),r.unmountExternalData?.()}},lo=i=>{let e=xt(),o=yr.get(i);if(!o)throw new Error(`cannot release session. invalid session id: ${i}`);let[t,r,n,s,a]=o;s&&(a&&e._OrtClearBoundOutputs(s.handle),e._OrtReleaseBinding(s.handle)),e.jsepOnReleaseSession?.(i),r.forEach(u=>e._OrtFree(u)),n.forEach(u=>e._OrtFree(u)),e._OrtReleaseSession(t),yr.delete(i)},ed=(i,e,o,t,r,n=!1)=>{if(!i){e.push(0);return}let s=xt(),a=i[0],u=i[1],l=i[3],f,p;if(a==="string"&&(l==="gpu-buffer"||l==="ml-tensor"))throw new Error("String tensor is not supported on GPU.");if(n&&l!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${r} when enableGraphCapture is true.`);if(l==="gpu-buffer"){let T=i[2].gpuBuffer;p=qr(Hr(a),u);let v=s.jsepRegisterBuffer;if(!v)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');f=v(t,r,T,p)}else if(l==="ml-tensor"){let T=i[2].mlTensor;p=qr(Hr(a),u);let v=s.jsepRegisterMLTensor;if(!v)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');f=v(T,Hr(a),u)}else{let T=i[2];if(Array.isArray(T)){p=4*T.length,f=s._malloc(p),o.push(f);let v=f/4;for(let S=0;S<T.length;S++){if(typeof T[S]!="string")throw new TypeError(`tensor data at index ${S} is not a string`);s.HEAPU32[v++]=Tt(T[S],o)}}else p=T.byteLength,f=s._malloc(p),o.push(f),s.HEAPU8.set(new Uint8Array(T.buffer,T.byteOffset,p),f)}let d=s.stackSave(),y=s.stackAlloc(4*u.length);try{let T=y/4;u.forEach(S=>s.HEAP32[T++]=S);let v=s._OrtCreateTensor(Hr(a),f,p,y,u.length,td(l));v===0&&ht(`Can't create tensor for input/output. session=${t}, index=${r}.`),e.push(v)}finally{s.stackRestore(d)}},fo=async(i,e,o,t,r,n)=>{let s=xt(),a=yr.get(i);if(!a)throw new Error(`cannot run inference. invalid session id: ${i}`);let u=a[0],l=a[1],f=a[2],p=a[3],d=a[4],y=a[5],T=e.length,v=t.length,S=0,L=[],P=[],A=[],M=[],V=s.stackSave(),lt=s.stackAlloc(T*4),wt=s.stackAlloc(T*4),et=s.stackAlloc(v*4),Dt=s.stackAlloc(v*4);try{s.jsepOnRunStart?.(u),[S,L]=jp(n);for(let Z=0;Z<T;Z++)ed(o[Z],P,M,i,e[Z],d);for(let Z=0;Z<v;Z++)ed(r[Z],A,M,i,T+t[Z],d);let _t=lt/4,C=wt/4,Kr=et/4,we=Dt/4;for(let Z=0;Z<T;Z++)s.HEAPU32[_t++]=P[Z],s.HEAPU32[C++]=l[e[Z]];for(let Z=0;Z<v;Z++)s.HEAPU32[Kr++]=A[Z],s.HEAPU32[we++]=f[t[Z]];let oe;oe=await s._OrtRun(u,wt,lt,T,Dt,v,et,S),oe!==0&&ht("failed to call OrtRun().");let be=[];for(let Z=0;Z<v;Z++){let ge=s.HEAPU32[et/4+Z];if(ge===A[Z]){be.push(r[Z]);continue}let ie=s.stackSave(),ae=s.stackAlloc(4*4),se=!1,it,Lt=0;try{s._OrtGetTensorData(ge,ae,ae+4,ae+8,ae+12)!==0&&ht(`Can't access output tensor data on index ${Z}.`);let Ye=ae/4,ue=s.HEAPU32[Ye++];Lt=s.HEAPU32[Ye++];let Ze=s.HEAPU32[Ye++],De=s.HEAPU32[Ye++],le=[];for(let gt=0;gt<De;gt++)le.push(s.HEAPU32[Ze/4+gt]);s._OrtFree(Ze);let Mt=le.reduce((gt,Ot)=>gt*Ot,1);it=Yp(ue);let ve=p?.outputPreferredLocations[t[Z]];if(it==="string"){if(ve==="gpu-buffer"||ve==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let gt=[],Ot=Lt/4;for(let Jt=0;Jt<Mt;Jt++){let wr=s.HEAPU32[Ot++],Yr=Jt===Mt-1?void 0:s.HEAPU32[Ot]-wr;gt.push(s.UTF8ToString(wr,Yr))}be.push([it,le,gt,"cpu"])}else if(ve==="gpu-buffer"&&Mt>0){let gt=s.jsepGetBuffer;if(!gt)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let Ot=gt(Lt),Jt=qr(ue,Mt);if(Jt===void 0||!bo(it))throw new Error(`Unsupported data type: ${it}`);se=!0,be.push([it,le,{gpuBuffer:Ot,download:s.jsepCreateDownloader(Ot,Jt,it),dispose:()=>{s._OrtReleaseTensor(ge)}},"gpu-buffer"])}else if(ve==="ml-tensor"&&Mt>0){let gt=s.jsepEnsureTensor;if(!gt)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(qr(ue,Mt)===void 0||!go(it))throw new Error(`Unsupported data type: ${it}`);let Jt=await gt(Lt,ue,le,!1);se=!0,be.push([it,le,{mlTensor:Jt,download:s.jsepCreateMLTensorDownloader(Lt,it),dispose:()=>{s.jsepReleaseTensorId(Lt),s._OrtReleaseTensor(ge)}},"ml-tensor"])}else{let gt=Zp(it),Ot=new gt(Mt);new Uint8Array(Ot.buffer,Ot.byteOffset,Ot.byteLength).set(s.HEAPU8.subarray(Lt,Lt+Ot.byteLength)),be.push([it,le,Ot,"cpu"])}}finally{s.stackRestore(ie),it==="string"&&Lt&&s._free(Lt),se||s._OrtReleaseTensor(ge)}}return p&&!d&&(s._OrtClearBoundOutputs(p.handle),yr.set(i,[u,l,f,p,d,!1])),be}finally{s.stackRestore(V),P.forEach(_t=>s._OrtReleaseTensor(_t)),A.forEach(_t=>s._OrtReleaseTensor(_t)),M.forEach(_t=>s._free(_t)),S!==0&&s._OrtReleaseRunOptions(S),L.forEach(_t=>s._free(_t))}},co=i=>{let e=xt(),o=yr.get(i);if(!o)throw new Error("invalid session id");let t=o[0],r=e._OrtEndProfiling(t);r===0&&ht("Can't get an profile file name."),e._OrtFree(r)},po=i=>{let e=[];for(let o of i){let t=o[2];!Array.isArray(t)&&"buffer"in t&&e.push(t.buffer)}return e}});var Je,Kt,Xr,xo,To,yo,Zi,Qi,xr,Tr,Gg,rd,nd,od,id,ad,sd,ud,ta=O(()=>{"use strict";Yt();qi();Ke();Vr();Je=()=>!!z.wasm.proxy&&typeof document<"u",Xr=!1,xo=!1,To=!1,Qi=new Map,xr=(i,e)=>{let o=Qi.get(i);o?o.push(e):Qi.set(i,[e])},Tr=()=>{if(Xr||!xo||To||!Kt)throw new Error("worker not ready")},Gg=i=>{switch(i.data.type){case"init-wasm":Xr=!1,i.data.err?(To=!0,Zi[1](i.data.err)):(xo=!0,Zi[0]()),yo&&(URL.revokeObjectURL(yo),yo=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=Qi.get(i.data.type);i.data.err?e.shift()[1](i.data.err):e.shift()[0](i.data.out);break}default:}},rd=async()=>{if(!xo){if(Xr)throw new Error("multiple calls to 'initWasm()' detected.");if(To)throw new Error("previous call to 'initWasm()' failed.");if(Xr=!0,Je())return new Promise((i,e)=>{Kt?.terminate(),Wp().then(([o,t])=>{try{Kt=t,Kt.onerror=n=>e(n),Kt.onmessage=Gg,Zi=[i,e];let r={type:"init-wasm",in:z};Kt.postMessage(r),yo=o}catch(r){e(r)}},e)});try{await io(z.wasm),await ao(z),xo=!0}catch(i){throw To=!0,i}finally{Xr=!1}}},nd=async i=>{if(Je())return Tr(),new Promise((e,o)=>{xr("init-ep",[e,o]);let t={type:"init-ep",in:{epName:i,env:z}};Kt.postMessage(t)});await so(z,i)},od=async i=>Je()?(Tr(),new Promise((e,o)=>{xr("copy-from",[e,o]);let t={type:"copy-from",in:{buffer:i}};Kt.postMessage(t,[i.buffer])})):zr(i),id=async(i,e)=>{if(Je()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return Tr(),new Promise((o,t)=>{xr("create",[o,t]);let r={type:"create",in:{model:i,options:{...e}}},n=[];i instanceof Uint8Array&&n.push(i.buffer),Kt.postMessage(r,n)})}else return uo(i,e)},ad=async i=>{if(Je())return Tr(),new Promise((e,o)=>{xr("release",[e,o]);let t={type:"release",in:i};Kt.postMessage(t)});lo(i)},sd=async(i,e,o,t,r,n)=>{if(Je()){if(o.some(s=>s[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(r.some(s=>s))throw new Error("pre-allocated output tensor is not supported for proxy.");return Tr(),new Promise((s,a)=>{xr("run",[s,a]);let u=o,l={type:"run",in:{sessionId:i,inputIndices:e,inputs:u,outputIndices:t,options:n}};Kt.postMessage(l,po(u))})}else return fo(i,e,o,t,r,n)},ud=async i=>{if(Je())return Tr(),new Promise((e,o)=>{xr("end-profiling",[e,o]);let t={type:"end-profiling",in:i};Kt.postMessage(t)});co(i)}});var ld,Mg,wo,fd=O(()=>{"use strict";Yt();ta();Ji();oo();Yi();ld=(i,e)=>{switch(i.location){case"cpu":return[i.type,i.dims,i.data,"cpu"];case"gpu-buffer":return[i.type,i.dims,{gpuBuffer:i.gpuBuffer},"gpu-buffer"];case"ml-tensor":return[i.type,i.dims,{mlTensor:i.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${i.location} for ${e()}`)}},Mg=i=>{switch(i[3]){case"cpu":return new yt(i[0],i[2],i[1]);case"gpu-buffer":{let e=i[0];if(!bo(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:o,download:t,dispose:r}=i[2];return yt.fromGpuBuffer(o,{dataType:e,dims:i[1],download:t,dispose:r})}case"ml-tensor":{let e=i[0];if(!go(e))throw new Error(`not supported data type: ${e} for deserializing MLTensor tensor`);let{mlTensor:o,download:t,dispose:r}=i[2];return yt.fromMLTensor(o,{dataType:e,dims:i[1],download:t,dispose:r})}default:throw new Error(`invalid data location: ${i[3]}`)}},wo=class{async fetchModelAndCopyToWasmMemory(e){return od(await jr(e))}async loadModel(e,o){Fe();let t;typeof e=="string"?!1?t=await jr(e):t=await this.fetchModelAndCopyToWasmMemory(e):t=e,[this.sessionId,this.inputNames,this.outputNames]=await id(t,o),Ce()}async dispose(){return ad(this.sessionId)}async run(e,o,t){Fe();let r=[],n=[];Object.entries(e).forEach(d=>{let y=d[0],T=d[1],v=this.inputNames.indexOf(y);if(v===-1)throw new Error(`invalid input '${y}'`);r.push(T),n.push(v)});let s=[],a=[];Object.entries(o).forEach(d=>{let y=d[0],T=d[1],v=this.outputNames.indexOf(y);if(v===-1)throw new Error(`invalid output '${y}'`);s.push(T),a.push(v)});let u=r.map((d,y)=>ld(d,()=>`input "${this.inputNames[n[y]]}"`)),l=s.map((d,y)=>d?ld(d,()=>`output "${this.outputNames[a[y]]}"`):null),f=await sd(this.sessionId,n,u,a,l,t),p={};for(let d=0;d<f.length;d++)p[this.outputNames[a[d]]]=s[d]??Mg(f[d]);return Ce(),p}startProfiling(){}endProfiling(){ud(this.sessionId)}}});var pd={};Or(pd,{OnnxruntimeWebAssemblyBackend:()=>vo,initializeFlags:()=>cd,wasmBackend:()=>Ug});var cd,vo,Ug,dd=O(()=>{"use strict";Yt();ta();fd();Vr();cd=()=>{if((typeof z.wasm.initTimeout!="number"||z.wasm.initTimeout<0)&&(z.wasm.initTimeout=0),z.wasm.simd===!1&&console.warn('Deprecated property "env.wasm.simd" is set to false. non-SIMD build is no longer provided, and this setting will be ignored.'),typeof z.wasm.proxy!="boolean"&&(z.wasm.proxy=!1),typeof z.wasm.trace!="boolean"&&(z.wasm.trace=!1),typeof z.wasm.numThreads!="number"||!Number.isInteger(z.wasm.numThreads)||z.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)z.wasm.numThreads=1;else{let i=typeof navigator>"u"?Co("node:os").cpus().length:navigator.hardwareConcurrency;z.wasm.numThreads=Math.min(4,Math.ceil((i||1)/2))}},vo=class{async init(e){cd(),await rd(),await nd(e)}async createInferenceSessionHandler(e,o){let t=new wo;return await t.loadModel(e,o),Promise.resolve(t)}},Ug=new vo});Yt();Yt();Yt();var Ds="1.20.0";var mO=Mo;{let i=(Fp(),sn(Bp)).onnxjsBackend;nr("webgl",i,-10)}{let i=(dd(),sn(pd)).wasmBackend;nr("cpu",i,10),nr("wasm",i,10)}Object.defineProperty(z.versions,"web",{value:Ds,enumerable:!0});export{Yd as InferenceSession,Ts as TRACE,Fe as TRACE_FUNC_BEGIN,Ce as TRACE_FUNC_END,yt as Tensor,Qd as TrainingSession,mO as default,z as env,nr as registerBackend};

Callers 1

createMethod · 0.80

Calls 2

loadModelMethod · 0.80
resolveMethod · 0.80

Tested by

no test coverage detected