Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

onnxruntime-web

Package Overview
Dependencies
Maintainers
3
Versions
247
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onnxruntime-web - npm Package Compare versions

Comparing version 1.20.0-dev.20240913-904b850b44 to 1.20.0-dev.20240914-c63dd0234b

2

__commit.txt

@@ -1,1 +0,1 @@

904b850b445ccfb3dc935e39b96cfb3dbfb52673
c63dd0234b4e0236b24fabdca005bbeb75ff4eb9
/*!
* ONNX Runtime Web v1.20.0-dev.20240913-904b850b44
* ONNX Runtime Web v1.20.0-dev.20240914-c63dd0234b
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
"use strict";var pt=Object.create;var re=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var gt=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var P=(e,t)=>()=>(e&&(t=e(e=0)),t);var xe=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},te=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of gt(t))!bt.call(e,r)&&r!==n&&re(e,r,{get:()=>t[r],enumerable:!(o=mt(t,r))||o.enumerable});return e},k=(e,t,n)=>(te(e,t,"default"),n&&te(n,t,"default")),wt=(e,t,n)=>(n=e!=null?pt(yt(e)):{},te(t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n,e)),Pe=e=>te(re({},"__esModule",{value:!0}),e);var D,ne=P(()=>{"use strict";D=!!(typeof process<"u"&&process.versions&&process.versions.node)});var F,ht,St,Et,Ot,vt,At,Te,oe=P(()=>{"use strict";ne();F=D?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,ht=D||typeof location>"u"?void 0:location.origin,St=(e,t)=>{try{let n=t??F;return(n?new URL(e,n):new URL(e)).origin===ht}catch{return!1}},Et=(e,t)=>{let n=t??F;try{return(n?new URL(e,n):new URL(e)).href}catch{return}},Ot=(e,t)=>`${t??"./"}${e}`,vt=async e=>{let n=await(await fetch(e,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},At=async e=>(await import(/*webpackIgnore:true*/e)).default,Te=async(e,t,n)=>{{let o="ort-wasm-simd-threaded.mjs",r=e??Et(o,t),a=!D&&n&&r&&!St(r,t),s=a?await vt(r):r??Ot(o,t);return[a?s:void 0,await At(s)]}}});var fe,de,se,Ce,It,xt,Be,S,R=P(()=>{"use strict";oe();de=!1,se=!1,Ce=!1,It=()=>{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}},xt=()=>{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}},Be=async e=>{if(de)return Promise.resolve();if(se)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Ce)throw new Error("previous call to 'initializeWebAssembly()' failed.");se=!0;let t=e.initTimeout,n=e.numThreads;if(!xt())throw new Error("WebAssembly SIMD is not supported in the current environment.");let o=It();n>1&&!o&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+n+", 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."),e.numThreads=n=1);let r=e.wasmPaths,a=typeof r=="string"?r:void 0,s=r?.mjs,u=s?.href??s,c=r?.wasm,d=c?.href??c,y=e.wasmBinary,[l,i]=await Te(u,a,n>1),b=!1,f=[];if(t>0&&f.push(new Promise(g=>{setTimeout(()=>{b=!0,g()},t)})),f.push(new Promise((g,v)=>{let _={numThreads:n};y?_.wasmBinary=y:(d||a)&&(_.locateFile=(p,w)=>d??(a??w)+p),i(_).then(p=>{se=!1,de=!0,fe=p,g(),l&&URL.revokeObjectURL(l)},p=>{se=!1,Ce=!0,v(p)})})),await Promise.race(f),b)throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`)},S=()=>{if(de&&fe)return fe;throw new Error("WebAssembly is not initialized yet.")}});var E,J,h,ae=P(()=>{"use strict";R();E=(e,t)=>{let n=S(),o=n.lengthBytesUTF8(e)+1,r=n._malloc(o);return n.stringToUTF8(e,r,o),t.push(r),r},J=(e,t,n,o)=>{if(typeof e=="object"&&e!==null){if(n.has(e))throw new Error("Circular reference in options");n.add(e)}Object.entries(e).forEach(([r,a])=>{let s=t?t+r:r;if(typeof a=="object")J(a,s+".",n,o);else if(typeof a=="string"||typeof a=="number")o(s,a.toString());else if(typeof a=="boolean")o(s,a?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof a}`)})},h=e=>{let t=S(),n=t.stackSave();try{let o=t.stackAlloc(8);t._OrtGetLastError(o,o+4);let r=t.HEAP32[o/4],a=t.HEAPU32[o/4+1],s=a?t.UTF8ToString(a):"";throw new Error(`${e} ERROR_CODE: ${r}, ERROR_MESSAGE: ${s}`)}finally{t.stackRestore(n)}}});var ke,Ue=P(()=>{"use strict";R();ae();ke=e=>{let t=S(),n=0,o=[],r=e||{};try{if(e?.logSeverityLevel===void 0)r.logSeverityLevel=2;else if(typeof e.logSeverityLevel!="number"||!Number.isInteger(e.logSeverityLevel)||e.logSeverityLevel<0||e.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${e.logSeverityLevel}`);if(e?.logVerbosityLevel===void 0)r.logVerbosityLevel=0;else if(typeof e.logVerbosityLevel!="number"||!Number.isInteger(e.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);e?.terminate===void 0&&(r.terminate=!1);let a=0;return e?.tag!==void 0&&(a=E(e.tag,o)),n=t._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,a),n===0&&h("Can't create run options."),e?.extra!==void 0&&J(e.extra,"",new WeakSet,(s,u)=>{let c=E(s,o),d=E(u,o);t._OrtAddRunConfigEntry(n,c,d)!==0&&h(`Can't set a run config entry: ${s} - ${u}.`)}),[n,o]}catch(a){throw n!==0&&t._OrtReleaseRunOptions(n),o.forEach(s=>t._free(s)),a}}});var Pt,Lt,Tt,Ct,_e,De=P(()=>{"use strict";R();ae();Pt=e=>{switch(e){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${e}`)}},Lt=e=>{switch(e){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${e}`)}},Tt=e=>{e.extra||(e.extra={}),e.extra.session||(e.extra.session={});let t=e.extra.session;t.use_ort_model_bytes_directly||(t.use_ort_model_bytes_directly="1"),e.executionProviders&&e.executionProviders.some(n=>(typeof n=="string"?n:n.name)==="webgpu")&&(e.enableMemPattern=!1)},Ct=(e,t,n)=>{for(let o of t){let r=typeof o=="string"?o:o.name;switch(r){case"webnn":if(r="WEBNN",typeof o!="string"){let u=o?.deviceType;if(u){let c=E("deviceType",n),d=E(u,n);S()._OrtAddSessionConfigEntry(e,c,d)!==0&&h(`Can't set a session config entry: 'deviceType' - ${u}.`)}}break;case"webgpu":if(r="JS",typeof o!="string"){let s=o;if(s?.preferredLayout){if(s.preferredLayout!=="NCHW"&&s.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${s.preferredLayout}`);let u=E("preferredLayout",n),c=E(s.preferredLayout,n);S()._OrtAddSessionConfigEntry(e,u,c)!==0&&h(`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 a=E(r,n);S()._OrtAppendExecutionProvider(e,a)!==0&&h(`Can't append execution provider: ${r}.`)}},_e=e=>{let t=S(),n=0,o=[],r=e||{};Tt(r);try{let a=Pt(r.graphOptimizationLevel??"all"),s=Lt(r.executionMode??"sequential"),u=typeof r.logId=="string"?E(r.logId,o):0,c=r.logSeverityLevel??2;if(!Number.isInteger(c)||c<0||c>4)throw new Error(`log serverity level is not valid: ${c}`);let d=r.logVerbosityLevel??0;if(!Number.isInteger(d)||d<0||d>4)throw new Error(`log verbosity level is not valid: ${d}`);let y=typeof r.optimizedModelFilePath=="string"?E(r.optimizedModelFilePath,o):0;if(n=t._OrtCreateSessionOptions(a,!!r.enableCpuMemArena,!!r.enableMemPattern,s,!!r.enableProfiling,0,u,c,d,y),n===0&&h("Can't create session options."),r.executionProviders&&Ct(n,r.executionProviders,o),r.enableGraphCapture!==void 0){if(typeof r.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);let l=E("enableGraphCapture",o),i=E(r.enableGraphCapture.toString(),o);t._OrtAddSessionConfigEntry(n,l,i)!==0&&h(`Can't set a session config entry: 'enableGraphCapture' - ${r.enableGraphCapture}.`)}if(r.freeDimensionOverrides)for(let[l,i]of Object.entries(r.freeDimensionOverrides)){if(typeof l!="string")throw new Error(`free dimension override name must be a string: ${l}`);if(typeof i!="number"||!Number.isInteger(i)||i<0)throw new Error(`free dimension override value must be a non-negative integer: ${i}`);let b=E(l,o);t._OrtAddFreeDimensionOverride(n,b,i)!==0&&h(`Can't set a free dimension override: ${l} - ${i}.`)}return r.extra!==void 0&&J(r.extra,"",new WeakSet,(l,i)=>{let b=E(l,o),f=E(i,o);t._OrtAddSessionConfigEntry(n,b,f)!==0&&h(`Can't set a session config entry: ${l} - ${i}.`)}),[n,o]}catch(a){throw n!==0&&t._OrtReleaseSessionOptions(n),o.forEach(s=>t._free(s)),a}}});var pe,Me,me,We,Fe,ie,Ne,ge=P(()=>{"use strict";pe=e=>{switch(e){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: ${e}`)}},Me=e=>{switch(e){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: ${e}`)}},me=(e,t)=>{let n=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][e],o=typeof t=="number"?t:t.reduce((r,a)=>r*a,1);return n>0?Math.ceil(o*n):void 0},We=e=>{switch(e){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: ${e}`)}},Fe=e=>{switch(e){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: ${e}`)}},ie=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",Ne=e=>{switch(e){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;default:throw new Error(`unsupported data location: ${e}`)}}});var Y,ye=P(()=>{"use strict";ne();Y=async e=>{if(typeof e=="string")if(D)try{let{readFile:t}=require("node:fs/promises");return new Uint8Array(await t(e))}catch(t){if(t.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:n}=require("node:fs"),o=n(e),r=[];for await(let a of o)r.push(a);return new Uint8Array(Buffer.concat(r))}throw t}else{let t=await fetch(e);if(!t.ok)throw new Error(`failed to load external data file: ${e}`);let n=t.headers.get("Content-Length"),o=n?parseInt(n,10):0;if(o<1073741824)return new Uint8Array(await t.arrayBuffer());{if(!t.body)throw new Error(`failed to load external data file: ${e}, no response body.`);let r=t.body.getReader(),a;try{a=new ArrayBuffer(o)}catch(u){if(u instanceof RangeError){let c=Math.ceil(o/65536);a=new WebAssembly.Memory({initial:c,maximum:c}).buffer}else throw u}let s=0;for(;;){let{done:u,value:c}=await r.read();if(u)break;let d=c.byteLength;new Uint8Array(a,s,d).set(c),s+=d}return new Uint8Array(a,0,o)}}else return e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e instanceof Uint8Array?e:new Uint8Array(e)}});var Bt,$e,He,$,kt,be,je,ze,Re,Ge,qe,Ve=P(()=>{"use strict";Ue();De();ge();R();ae();ye();Bt=(e,t)=>{S()._OrtInit(e,t)!==0&&h("Can't initialize onnxruntime.")},$e=async e=>{Bt(e.wasm.numThreads,Fe(e.logLevel))},He=async(e,t)=>{},$=new Map,kt=e=>{let t=S(),n=t.stackSave();try{let o=t.stackAlloc(8);return t._OrtGetInputOutputCount(e,o,o+4)!==0&&h("Can't get session input/output count."),[t.HEAP32[o/4],t.HEAP32[o/4+1]]}finally{t.stackRestore(n)}},be=e=>{let t=S(),n=t._malloc(e.byteLength);if(n===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);return t.HEAPU8.set(e,n),[n,e.byteLength]},je=async(e,t)=>{let n,o,r=S();Array.isArray(e)?[n,o]=e:e.buffer===r.HEAPU8.buffer?[n,o]=[e.byteOffset,e.byteLength]:[n,o]=be(e);let a=0,s=0,u=0,c=[],d=[],y=[];try{if([s,c]=_e(t),t?.externalData&&r.mountExternalData){let p=[];for(let w of t.externalData){let A=typeof w=="string"?w:w.path;p.push(Y(typeof w=="string"?w:w.data).then(M=>{r.mountExternalData(A,M)}))}await Promise.all(p)}for(let p of t?.executionProviders??[])if((typeof p=="string"?p:p.name)==="webnn"){if(r.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof p!="string"){let A=p,M=A?.context,H=A?.gpuDevice,K=A?.deviceType,j=A?.numThreads,Q=A?.powerPreference;M?r.currentContext=M:H?r.currentContext=await navigator.ml.createContext(H):r.currentContext=await navigator.ml.createContext({deviceType:K,numThreads:j,powerPreference:Q})}else r.currentContext=await navigator.ml.createContext();break}a=await r._OrtCreateSession(n,o,s),a===0&&h("Can't create a session."),r.currentContext&&(r.currentContext=void 0);let[l,i]=kt(a),b=!!t?.enableGraphCapture,f=[],g=[],v=[];for(let p=0;p<l;p++){let w=r._OrtGetInputName(a,p);w===0&&h("Can't get an input name."),d.push(w),f.push(r.UTF8ToString(w))}for(let p=0;p<i;p++){let w=r._OrtGetOutputName(a,p);w===0&&h("Can't get an output name."),y.push(w);let A=r.UTF8ToString(w);g.push(A)}let _=null;return $.set(a,[a,d,y,_,b,!1]),[a,f,g]}catch(l){throw d.forEach(i=>r._OrtFree(i)),y.forEach(i=>r._OrtFree(i)),u!==0&&r._OrtReleaseBinding(u),a!==0&&r._OrtReleaseSession(a),l}finally{r._free(n),s!==0&&r._OrtReleaseSessionOptions(s),c.forEach(l=>r._free(l)),r.unmountExternalData?.()}},ze=e=>{let t=S(),n=$.get(e);if(!n)throw new Error(`cannot release session. invalid session id: ${e}`);let[o,r,a,s,u]=n;s&&(u&&t._OrtClearBoundOutputs(s.handle),t._OrtReleaseBinding(s.handle)),t.jsepOnReleaseSession?.(e),r.forEach(c=>t._OrtFree(c)),a.forEach(c=>t._OrtFree(c)),t._OrtReleaseSession(o),$.delete(e)},Re=(e,t,n,o,r,a=!1)=>{if(!e){t.push(0);return}let s=S(),u=e[0],c=e[1],d=e[3],y,l;if(u==="string"&&d==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");if(a&&d!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${r} when enableGraphCapture is true.`);if(d==="gpu-buffer"){let f=e[2].gpuBuffer;l=me(pe(u),c);let g=s.jsepRegisterBuffer;if(!g)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');y=g(o,r,f,l)}else{let f=e[2];if(Array.isArray(f)){l=4*f.length,y=s._malloc(l),n.push(y);let g=y/4;for(let v=0;v<f.length;v++){if(typeof f[v]!="string")throw new TypeError(`tensor data at index ${v} is not a string`);s.HEAPU32[g++]=E(f[v],n)}}else l=f.byteLength,y=s._malloc(l),n.push(y),s.HEAPU8.set(new Uint8Array(f.buffer,f.byteOffset,l),y)}let i=s.stackSave(),b=s.stackAlloc(4*c.length);try{let f=b/4;c.forEach(v=>s.HEAP32[f++]=v);let g=s._OrtCreateTensor(pe(u),y,l,b,c.length,Ne(d));g===0&&h(`Can't create tensor for input/output. session=${o}, index=${r}.`),t.push(g)}finally{s.stackRestore(i)}},Ge=async(e,t,n,o,r,a)=>{let s=S(),u=$.get(e);if(!u)throw new Error(`cannot run inference. invalid session id: ${e}`);let c=u[0],d=u[1],y=u[2],l=u[3],i=u[4],b=u[5],f=t.length,g=o.length,v=0,_=[],p=[],w=[],A=[],M=s.stackSave(),H=s.stackAlloc(f*4),K=s.stackAlloc(f*4),j=s.stackAlloc(g*4),Q=s.stackAlloc(g*4);try{[v,_]=ke(a);for(let m=0;m<f;m++)Re(n[m],p,A,e,t[m],i);for(let m=0;m<g;m++)Re(r[m],w,A,e,f+o[m],i);let C=H/4,ut=K/4,ct=j/4,lt=Q/4;for(let m=0;m<f;m++)s.HEAPU32[C++]=p[m],s.HEAPU32[ut++]=d[t[m]];for(let m=0;m<g;m++)s.HEAPU32[ct++]=w[m],s.HEAPU32[lt++]=y[o[m]];s.jsepOnRunStart?.(c);let Se;Se=await s._OrtRun(c,K,H,f,Q,g,j,v),Se!==0&&h("failed to call OrtRun().");let z=[];for(let m=0;m<g;m++){let G=s.HEAPU32[j/4+m];if(G===w[m]){z.push(r[m]);continue}let Ee=s.stackSave(),W=s.stackAlloc(4*4),Z=!1,L,B=0;try{s._OrtGetTensorData(G,W,W+4,W+8,W+12)!==0&&h(`Can't access output tensor data on index ${m}.`);let ee=W/4,Oe=s.HEAPU32[ee++];B=s.HEAPU32[ee++];let ve=s.HEAPU32[ee++],ft=s.HEAPU32[ee++],q=[];for(let I=0;I<ft;I++)q.push(s.HEAPU32[ve/4+I]);s._OrtFree(ve);let V=q.reduce((I,x)=>I*x,1);L=Me(Oe);let Ae=l?.outputPreferredLocations[o[m]];if(L==="string"){if(Ae==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");let I=[],x=B/4;for(let N=0;N<V;N++){let Ie=s.HEAPU32[x++],dt=N===V-1?void 0:s.HEAPU32[x]-Ie;I.push(s.UTF8ToString(Ie,dt))}z.push([L,q,I,"cpu"])}else if(Ae==="gpu-buffer"&&V>0){let I=s.jsepGetBuffer;if(!I)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let x=I(B),N=me(Oe,V);if(N===void 0||!ie(L))throw new Error(`Unsupported data type: ${L}`);Z=!0,z.push([L,q,{gpuBuffer:x,download:s.jsepCreateDownloader(x,N,L),dispose:()=>{s._OrtReleaseTensor(G)}},"gpu-buffer"])}else{let I=We(L),x=new I(V);new Uint8Array(x.buffer,x.byteOffset,x.byteLength).set(s.HEAPU8.subarray(B,B+x.byteLength)),z.push([L,q,x,"cpu"])}}finally{s.stackRestore(Ee),L==="string"&&B&&s._free(B),Z||s._OrtReleaseTensor(G)}}return l&&!i&&(s._OrtClearBoundOutputs(l.handle),$.set(e,[c,d,y,l,i,!1])),z}finally{s.stackRestore(M),p.forEach(C=>s._OrtReleaseTensor(C)),w.forEach(C=>s._OrtReleaseTensor(C)),A.forEach(C=>s._free(C)),v!==0&&s._OrtReleaseRunOptions(v),_.forEach(C=>s._free(C))}},qe=e=>{let t=S(),n=$.get(e);if(!n)throw new Error("invalid session id");let o=n[0],r=t._OrtEndProfiling(o);r===0&&h("Can't get an profile file name."),t._OrtFree(r)}});var ue,we,Je,Ye,Xe,Ke,Qe,Ze,et,tt,rt,he=P(()=>{"use strict";ue=require("onnxruntime-common");Ve();R();oe();we=!1,Je=!1,Ye=!1,Xe=async()=>{if(!Je){if(we)throw new Error("multiple calls to 'initWasm()' detected.");if(Ye)throw new Error("previous call to 'initWasm()' failed.");we=!0;try{await Be(ue.env.wasm),await $e(ue.env),Je=!0}catch(e){throw Ye=!0,e}finally{we=!1}}},Ke=async e=>{await He(ue.env,e)},Qe=async e=>be(e),Ze=async(e,t)=>je(e,t),et=async e=>{ze(e)},tt=async(e,t,n,o,r,a)=>Ge(e,t,n,o,r,a),rt=async e=>{qe(e)}});var U,nt,_t,ce,ot=P(()=>{"use strict";U=require("onnxruntime-common");he();ge();ne();ye();nt=(e,t)=>{switch(e.location){case"cpu":return[e.type,e.dims,e.data,"cpu"];case"gpu-buffer":return[e.type,e.dims,{gpuBuffer:e.gpuBuffer},"gpu-buffer"];default:throw new Error(`invalid data location: ${e.location} for ${t()}`)}},_t=e=>{switch(e[3]){case"cpu":return new U.Tensor(e[0],e[2],e[1]);case"gpu-buffer":{let t=e[0];if(!ie(t))throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:o,dispose:r}=e[2];return U.Tensor.fromGpuBuffer(n,{dataType:t,dims:e[1],download:o,dispose:r})}default:throw new Error(`invalid data location: ${e[3]}`)}},ce=class{async fetchModelAndCopyToWasmMemory(t){return Qe(await Y(t))}async loadModel(t,n){(0,U.TRACE_FUNC_BEGIN)();let o;typeof t=="string"?D?o=await Y(t):o=await this.fetchModelAndCopyToWasmMemory(t):o=t,[this.sessionId,this.inputNames,this.outputNames]=await Ze(o,n),(0,U.TRACE_FUNC_END)()}async dispose(){return et(this.sessionId)}async run(t,n,o){(0,U.TRACE_FUNC_BEGIN)();let r=[],a=[];Object.entries(t).forEach(i=>{let b=i[0],f=i[1],g=this.inputNames.indexOf(b);if(g===-1)throw new Error(`invalid input '${b}'`);r.push(f),a.push(g)});let s=[],u=[];Object.entries(n).forEach(i=>{let b=i[0],f=i[1],g=this.outputNames.indexOf(b);if(g===-1)throw new Error(`invalid output '${b}'`);s.push(f),u.push(g)});let c=r.map((i,b)=>nt(i,()=>`input "${this.inputNames[a[b]]}"`)),d=s.map((i,b)=>i?nt(i,()=>`output "${this.outputNames[u[b]]}"`):null),y=await tt(this.sessionId,a,c,u,d,o),l={};for(let i=0;i<y.length;i++)l[this.outputNames[u[i]]]=s[i]??_t(y[i]);return(0,U.TRACE_FUNC_END)(),l}startProfiling(){}endProfiling(){rt(this.sessionId)}}});var O,Dt,le,st=P(()=>{"use strict";O=require("onnxruntime-common");he();ot();oe();Dt=()=>{if((typeof O.env.wasm.initTimeout!="number"||O.env.wasm.initTimeout<0)&&(O.env.wasm.initTimeout=0),O.env.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 O.env.wasm.proxy!="boolean"&&(O.env.wasm.proxy=!1),typeof O.env.wasm.trace!="boolean"&&(O.env.wasm.trace=!1),typeof O.env.wasm.numThreads!="number"||!Number.isInteger(O.env.wasm.numThreads)||O.env.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)O.env.wasm.numThreads=1;else{let e=typeof navigator>"u"?require("node:os").cpus().length:navigator.hardwareConcurrency;O.env.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}O.env.wasm.wasmPaths===void 0&&F&&F.indexOf("blob:")!==0&&(O.env.wasm.wasmPaths=F.substring(0,F.lastIndexOf("/")+1))},le=class{async init(t){Dt(),await Xe(),await Ke(t)}async createInferenceSessionHandler(t,n){let o=new ce;return await o.loadModel(t,n),Promise.resolve(o)}}});var at={};xe(at,{wasmBackend:()=>Mt});var Mt,it=P(()=>{"use strict";st();Mt=new le});var T={};xe(T,{default:()=>Ft});module.exports=Pe(T);k(T,require("onnxruntime-common"),module.exports);var Wt=wt(require("onnxruntime-common")),X=require("onnxruntime-common");var Le="1.20.0-dev.20240913-904b850b44";var Ft=Wt;{let e=(it(),Pe(at)).wasmBackend;(0,X.registerBackend)("cpu",e,10),(0,X.registerBackend)("wasm",e,10)}Object.defineProperty(X.env.versions,"web",{value:Le,enumerable:!0});0&&(module.exports={...require("onnxruntime-common")});
"use strict";var pt=Object.create;var re=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var gt=Object.getOwnPropertyNames;var yt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var P=(e,t)=>()=>(e&&(t=e(e=0)),t);var xe=(e,t)=>{for(var n in t)re(e,n,{get:t[n],enumerable:!0})},te=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of gt(t))!bt.call(e,r)&&r!==n&&re(e,r,{get:()=>t[r],enumerable:!(o=mt(t,r))||o.enumerable});return e},k=(e,t,n)=>(te(e,t,"default"),n&&te(n,t,"default")),wt=(e,t,n)=>(n=e!=null?pt(yt(e)):{},te(t||!e||!e.__esModule?re(n,"default",{value:e,enumerable:!0}):n,e)),Pe=e=>te(re({},"__esModule",{value:!0}),e);var D,ne=P(()=>{"use strict";D=!!(typeof process<"u"&&process.versions&&process.versions.node)});var F,ht,St,Et,Ot,vt,At,Te,oe=P(()=>{"use strict";ne();F=D?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,ht=D||typeof location>"u"?void 0:location.origin,St=(e,t)=>{try{let n=t??F;return(n?new URL(e,n):new URL(e)).origin===ht}catch{return!1}},Et=(e,t)=>{let n=t??F;try{return(n?new URL(e,n):new URL(e)).href}catch{return}},Ot=(e,t)=>`${t??"./"}${e}`,vt=async e=>{let n=await(await fetch(e,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},At=async e=>(await import(/*webpackIgnore:true*/e)).default,Te=async(e,t,n)=>{{let o="ort-wasm-simd-threaded.mjs",r=e??Et(o,t),a=!D&&n&&r&&!St(r,t),s=a?await vt(r):r??Ot(o,t);return[a?s:void 0,await At(s)]}}});var fe,de,se,Ce,It,xt,Be,S,R=P(()=>{"use strict";oe();de=!1,se=!1,Ce=!1,It=()=>{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}},xt=()=>{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}},Be=async e=>{if(de)return Promise.resolve();if(se)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Ce)throw new Error("previous call to 'initializeWebAssembly()' failed.");se=!0;let t=e.initTimeout,n=e.numThreads;if(!xt())throw new Error("WebAssembly SIMD is not supported in the current environment.");let o=It();n>1&&!o&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+n+", 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."),e.numThreads=n=1);let r=e.wasmPaths,a=typeof r=="string"?r:void 0,s=r?.mjs,u=s?.href??s,c=r?.wasm,d=c?.href??c,y=e.wasmBinary,[l,i]=await Te(u,a,n>1),b=!1,f=[];if(t>0&&f.push(new Promise(g=>{setTimeout(()=>{b=!0,g()},t)})),f.push(new Promise((g,v)=>{let _={numThreads:n};y?_.wasmBinary=y:(d||a)&&(_.locateFile=(p,w)=>d??(a??w)+p),i(_).then(p=>{se=!1,de=!0,fe=p,g(),l&&URL.revokeObjectURL(l)},p=>{se=!1,Ce=!0,v(p)})})),await Promise.race(f),b)throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`)},S=()=>{if(de&&fe)return fe;throw new Error("WebAssembly is not initialized yet.")}});var E,J,h,ae=P(()=>{"use strict";R();E=(e,t)=>{let n=S(),o=n.lengthBytesUTF8(e)+1,r=n._malloc(o);return n.stringToUTF8(e,r,o),t.push(r),r},J=(e,t,n,o)=>{if(typeof e=="object"&&e!==null){if(n.has(e))throw new Error("Circular reference in options");n.add(e)}Object.entries(e).forEach(([r,a])=>{let s=t?t+r:r;if(typeof a=="object")J(a,s+".",n,o);else if(typeof a=="string"||typeof a=="number")o(s,a.toString());else if(typeof a=="boolean")o(s,a?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof a}`)})},h=e=>{let t=S(),n=t.stackSave();try{let o=t.stackAlloc(8);t._OrtGetLastError(o,o+4);let r=t.HEAP32[o/4],a=t.HEAPU32[o/4+1],s=a?t.UTF8ToString(a):"";throw new Error(`${e} ERROR_CODE: ${r}, ERROR_MESSAGE: ${s}`)}finally{t.stackRestore(n)}}});var ke,Ue=P(()=>{"use strict";R();ae();ke=e=>{let t=S(),n=0,o=[],r=e||{};try{if(e?.logSeverityLevel===void 0)r.logSeverityLevel=2;else if(typeof e.logSeverityLevel!="number"||!Number.isInteger(e.logSeverityLevel)||e.logSeverityLevel<0||e.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${e.logSeverityLevel}`);if(e?.logVerbosityLevel===void 0)r.logVerbosityLevel=0;else if(typeof e.logVerbosityLevel!="number"||!Number.isInteger(e.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${e.logVerbosityLevel}`);e?.terminate===void 0&&(r.terminate=!1);let a=0;return e?.tag!==void 0&&(a=E(e.tag,o)),n=t._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,a),n===0&&h("Can't create run options."),e?.extra!==void 0&&J(e.extra,"",new WeakSet,(s,u)=>{let c=E(s,o),d=E(u,o);t._OrtAddRunConfigEntry(n,c,d)!==0&&h(`Can't set a run config entry: ${s} - ${u}.`)}),[n,o]}catch(a){throw n!==0&&t._OrtReleaseRunOptions(n),o.forEach(s=>t._free(s)),a}}});var Pt,Lt,Tt,Ct,_e,De=P(()=>{"use strict";R();ae();Pt=e=>{switch(e){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${e}`)}},Lt=e=>{switch(e){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${e}`)}},Tt=e=>{e.extra||(e.extra={}),e.extra.session||(e.extra.session={});let t=e.extra.session;t.use_ort_model_bytes_directly||(t.use_ort_model_bytes_directly="1"),e.executionProviders&&e.executionProviders.some(n=>(typeof n=="string"?n:n.name)==="webgpu")&&(e.enableMemPattern=!1)},Ct=(e,t,n)=>{for(let o of t){let r=typeof o=="string"?o:o.name;switch(r){case"webnn":if(r="WEBNN",typeof o!="string"){let u=o?.deviceType;if(u){let c=E("deviceType",n),d=E(u,n);S()._OrtAddSessionConfigEntry(e,c,d)!==0&&h(`Can't set a session config entry: 'deviceType' - ${u}.`)}}break;case"webgpu":if(r="JS",typeof o!="string"){let s=o;if(s?.preferredLayout){if(s.preferredLayout!=="NCHW"&&s.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${s.preferredLayout}`);let u=E("preferredLayout",n),c=E(s.preferredLayout,n);S()._OrtAddSessionConfigEntry(e,u,c)!==0&&h(`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 a=E(r,n);S()._OrtAppendExecutionProvider(e,a)!==0&&h(`Can't append execution provider: ${r}.`)}},_e=e=>{let t=S(),n=0,o=[],r=e||{};Tt(r);try{let a=Pt(r.graphOptimizationLevel??"all"),s=Lt(r.executionMode??"sequential"),u=typeof r.logId=="string"?E(r.logId,o):0,c=r.logSeverityLevel??2;if(!Number.isInteger(c)||c<0||c>4)throw new Error(`log serverity level is not valid: ${c}`);let d=r.logVerbosityLevel??0;if(!Number.isInteger(d)||d<0||d>4)throw new Error(`log verbosity level is not valid: ${d}`);let y=typeof r.optimizedModelFilePath=="string"?E(r.optimizedModelFilePath,o):0;if(n=t._OrtCreateSessionOptions(a,!!r.enableCpuMemArena,!!r.enableMemPattern,s,!!r.enableProfiling,0,u,c,d,y),n===0&&h("Can't create session options."),r.executionProviders&&Ct(n,r.executionProviders,o),r.enableGraphCapture!==void 0){if(typeof r.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);let l=E("enableGraphCapture",o),i=E(r.enableGraphCapture.toString(),o);t._OrtAddSessionConfigEntry(n,l,i)!==0&&h(`Can't set a session config entry: 'enableGraphCapture' - ${r.enableGraphCapture}.`)}if(r.freeDimensionOverrides)for(let[l,i]of Object.entries(r.freeDimensionOverrides)){if(typeof l!="string")throw new Error(`free dimension override name must be a string: ${l}`);if(typeof i!="number"||!Number.isInteger(i)||i<0)throw new Error(`free dimension override value must be a non-negative integer: ${i}`);let b=E(l,o);t._OrtAddFreeDimensionOverride(n,b,i)!==0&&h(`Can't set a free dimension override: ${l} - ${i}.`)}return r.extra!==void 0&&J(r.extra,"",new WeakSet,(l,i)=>{let b=E(l,o),f=E(i,o);t._OrtAddSessionConfigEntry(n,b,f)!==0&&h(`Can't set a session config entry: ${l} - ${i}.`)}),[n,o]}catch(a){throw n!==0&&t._OrtReleaseSessionOptions(n),o.forEach(s=>t._free(s)),a}}});var pe,Me,me,We,Fe,ie,Ne,ge=P(()=>{"use strict";pe=e=>{switch(e){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: ${e}`)}},Me=e=>{switch(e){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: ${e}`)}},me=(e,t)=>{let n=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][e],o=typeof t=="number"?t:t.reduce((r,a)=>r*a,1);return n>0?Math.ceil(o*n):void 0},We=e=>{switch(e){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: ${e}`)}},Fe=e=>{switch(e){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: ${e}`)}},ie=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",Ne=e=>{switch(e){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;default:throw new Error(`unsupported data location: ${e}`)}}});var Y,ye=P(()=>{"use strict";ne();Y=async e=>{if(typeof e=="string")if(D)try{let{readFile:t}=require("node:fs/promises");return new Uint8Array(await t(e))}catch(t){if(t.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:n}=require("node:fs"),o=n(e),r=[];for await(let a of o)r.push(a);return new Uint8Array(Buffer.concat(r))}throw t}else{let t=await fetch(e);if(!t.ok)throw new Error(`failed to load external data file: ${e}`);let n=t.headers.get("Content-Length"),o=n?parseInt(n,10):0;if(o<1073741824)return new Uint8Array(await t.arrayBuffer());{if(!t.body)throw new Error(`failed to load external data file: ${e}, no response body.`);let r=t.body.getReader(),a;try{a=new ArrayBuffer(o)}catch(u){if(u instanceof RangeError){let c=Math.ceil(o/65536);a=new WebAssembly.Memory({initial:c,maximum:c}).buffer}else throw u}let s=0;for(;;){let{done:u,value:c}=await r.read();if(u)break;let d=c.byteLength;new Uint8Array(a,s,d).set(c),s+=d}return new Uint8Array(a,0,o)}}else return e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e instanceof Uint8Array?e:new Uint8Array(e)}});var Bt,$e,He,$,kt,be,je,ze,Re,Ge,qe,Ve=P(()=>{"use strict";Ue();De();ge();R();ae();ye();Bt=(e,t)=>{S()._OrtInit(e,t)!==0&&h("Can't initialize onnxruntime.")},$e=async e=>{Bt(e.wasm.numThreads,Fe(e.logLevel))},He=async(e,t)=>{},$=new Map,kt=e=>{let t=S(),n=t.stackSave();try{let o=t.stackAlloc(8);return t._OrtGetInputOutputCount(e,o,o+4)!==0&&h("Can't get session input/output count."),[t.HEAP32[o/4],t.HEAP32[o/4+1]]}finally{t.stackRestore(n)}},be=e=>{let t=S(),n=t._malloc(e.byteLength);if(n===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${e.byteLength}.`);return t.HEAPU8.set(e,n),[n,e.byteLength]},je=async(e,t)=>{let n,o,r=S();Array.isArray(e)?[n,o]=e:e.buffer===r.HEAPU8.buffer?[n,o]=[e.byteOffset,e.byteLength]:[n,o]=be(e);let a=0,s=0,u=0,c=[],d=[],y=[];try{if([s,c]=_e(t),t?.externalData&&r.mountExternalData){let p=[];for(let w of t.externalData){let A=typeof w=="string"?w:w.path;p.push(Y(typeof w=="string"?w:w.data).then(M=>{r.mountExternalData(A,M)}))}await Promise.all(p)}for(let p of t?.executionProviders??[])if((typeof p=="string"?p:p.name)==="webnn"){if(r.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof p!="string"){let A=p,M=A?.context,H=A?.gpuDevice,K=A?.deviceType,j=A?.numThreads,Q=A?.powerPreference;M?r.currentContext=M:H?r.currentContext=await navigator.ml.createContext(H):r.currentContext=await navigator.ml.createContext({deviceType:K,numThreads:j,powerPreference:Q})}else r.currentContext=await navigator.ml.createContext();break}a=await r._OrtCreateSession(n,o,s),a===0&&h("Can't create a session."),r.currentContext&&(r.currentContext=void 0);let[l,i]=kt(a),b=!!t?.enableGraphCapture,f=[],g=[],v=[];for(let p=0;p<l;p++){let w=r._OrtGetInputName(a,p);w===0&&h("Can't get an input name."),d.push(w),f.push(r.UTF8ToString(w))}for(let p=0;p<i;p++){let w=r._OrtGetOutputName(a,p);w===0&&h("Can't get an output name."),y.push(w);let A=r.UTF8ToString(w);g.push(A)}let _=null;return $.set(a,[a,d,y,_,b,!1]),[a,f,g]}catch(l){throw d.forEach(i=>r._OrtFree(i)),y.forEach(i=>r._OrtFree(i)),u!==0&&r._OrtReleaseBinding(u),a!==0&&r._OrtReleaseSession(a),l}finally{r._free(n),s!==0&&r._OrtReleaseSessionOptions(s),c.forEach(l=>r._free(l)),r.unmountExternalData?.()}},ze=e=>{let t=S(),n=$.get(e);if(!n)throw new Error(`cannot release session. invalid session id: ${e}`);let[o,r,a,s,u]=n;s&&(u&&t._OrtClearBoundOutputs(s.handle),t._OrtReleaseBinding(s.handle)),t.jsepOnReleaseSession?.(e),r.forEach(c=>t._OrtFree(c)),a.forEach(c=>t._OrtFree(c)),t._OrtReleaseSession(o),$.delete(e)},Re=(e,t,n,o,r,a=!1)=>{if(!e){t.push(0);return}let s=S(),u=e[0],c=e[1],d=e[3],y,l;if(u==="string"&&d==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");if(a&&d!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${r} when enableGraphCapture is true.`);if(d==="gpu-buffer"){let f=e[2].gpuBuffer;l=me(pe(u),c);let g=s.jsepRegisterBuffer;if(!g)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');y=g(o,r,f,l)}else{let f=e[2];if(Array.isArray(f)){l=4*f.length,y=s._malloc(l),n.push(y);let g=y/4;for(let v=0;v<f.length;v++){if(typeof f[v]!="string")throw new TypeError(`tensor data at index ${v} is not a string`);s.HEAPU32[g++]=E(f[v],n)}}else l=f.byteLength,y=s._malloc(l),n.push(y),s.HEAPU8.set(new Uint8Array(f.buffer,f.byteOffset,l),y)}let i=s.stackSave(),b=s.stackAlloc(4*c.length);try{let f=b/4;c.forEach(v=>s.HEAP32[f++]=v);let g=s._OrtCreateTensor(pe(u),y,l,b,c.length,Ne(d));g===0&&h(`Can't create tensor for input/output. session=${o}, index=${r}.`),t.push(g)}finally{s.stackRestore(i)}},Ge=async(e,t,n,o,r,a)=>{let s=S(),u=$.get(e);if(!u)throw new Error(`cannot run inference. invalid session id: ${e}`);let c=u[0],d=u[1],y=u[2],l=u[3],i=u[4],b=u[5],f=t.length,g=o.length,v=0,_=[],p=[],w=[],A=[],M=s.stackSave(),H=s.stackAlloc(f*4),K=s.stackAlloc(f*4),j=s.stackAlloc(g*4),Q=s.stackAlloc(g*4);try{[v,_]=ke(a);for(let m=0;m<f;m++)Re(n[m],p,A,e,t[m],i);for(let m=0;m<g;m++)Re(r[m],w,A,e,f+o[m],i);let C=H/4,ut=K/4,ct=j/4,lt=Q/4;for(let m=0;m<f;m++)s.HEAPU32[C++]=p[m],s.HEAPU32[ut++]=d[t[m]];for(let m=0;m<g;m++)s.HEAPU32[ct++]=w[m],s.HEAPU32[lt++]=y[o[m]];s.jsepOnRunStart?.(c);let Se;Se=await s._OrtRun(c,K,H,f,Q,g,j,v),Se!==0&&h("failed to call OrtRun().");let z=[];for(let m=0;m<g;m++){let G=s.HEAPU32[j/4+m];if(G===w[m]){z.push(r[m]);continue}let Ee=s.stackSave(),W=s.stackAlloc(4*4),Z=!1,L,B=0;try{s._OrtGetTensorData(G,W,W+4,W+8,W+12)!==0&&h(`Can't access output tensor data on index ${m}.`);let ee=W/4,Oe=s.HEAPU32[ee++];B=s.HEAPU32[ee++];let ve=s.HEAPU32[ee++],ft=s.HEAPU32[ee++],q=[];for(let I=0;I<ft;I++)q.push(s.HEAPU32[ve/4+I]);s._OrtFree(ve);let V=q.reduce((I,x)=>I*x,1);L=Me(Oe);let Ae=l?.outputPreferredLocations[o[m]];if(L==="string"){if(Ae==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");let I=[],x=B/4;for(let N=0;N<V;N++){let Ie=s.HEAPU32[x++],dt=N===V-1?void 0:s.HEAPU32[x]-Ie;I.push(s.UTF8ToString(Ie,dt))}z.push([L,q,I,"cpu"])}else if(Ae==="gpu-buffer"&&V>0){let I=s.jsepGetBuffer;if(!I)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let x=I(B),N=me(Oe,V);if(N===void 0||!ie(L))throw new Error(`Unsupported data type: ${L}`);Z=!0,z.push([L,q,{gpuBuffer:x,download:s.jsepCreateDownloader(x,N,L),dispose:()=>{s._OrtReleaseTensor(G)}},"gpu-buffer"])}else{let I=We(L),x=new I(V);new Uint8Array(x.buffer,x.byteOffset,x.byteLength).set(s.HEAPU8.subarray(B,B+x.byteLength)),z.push([L,q,x,"cpu"])}}finally{s.stackRestore(Ee),L==="string"&&B&&s._free(B),Z||s._OrtReleaseTensor(G)}}return l&&!i&&(s._OrtClearBoundOutputs(l.handle),$.set(e,[c,d,y,l,i,!1])),z}finally{s.stackRestore(M),p.forEach(C=>s._OrtReleaseTensor(C)),w.forEach(C=>s._OrtReleaseTensor(C)),A.forEach(C=>s._free(C)),v!==0&&s._OrtReleaseRunOptions(v),_.forEach(C=>s._free(C))}},qe=e=>{let t=S(),n=$.get(e);if(!n)throw new Error("invalid session id");let o=n[0],r=t._OrtEndProfiling(o);r===0&&h("Can't get an profile file name."),t._OrtFree(r)}});var ue,we,Je,Ye,Xe,Ke,Qe,Ze,et,tt,rt,he=P(()=>{"use strict";ue=require("onnxruntime-common");Ve();R();oe();we=!1,Je=!1,Ye=!1,Xe=async()=>{if(!Je){if(we)throw new Error("multiple calls to 'initWasm()' detected.");if(Ye)throw new Error("previous call to 'initWasm()' failed.");we=!0;try{await Be(ue.env.wasm),await $e(ue.env),Je=!0}catch(e){throw Ye=!0,e}finally{we=!1}}},Ke=async e=>{await He(ue.env,e)},Qe=async e=>be(e),Ze=async(e,t)=>je(e,t),et=async e=>{ze(e)},tt=async(e,t,n,o,r,a)=>Ge(e,t,n,o,r,a),rt=async e=>{qe(e)}});var U,nt,_t,ce,ot=P(()=>{"use strict";U=require("onnxruntime-common");he();ge();ne();ye();nt=(e,t)=>{switch(e.location){case"cpu":return[e.type,e.dims,e.data,"cpu"];case"gpu-buffer":return[e.type,e.dims,{gpuBuffer:e.gpuBuffer},"gpu-buffer"];default:throw new Error(`invalid data location: ${e.location} for ${t()}`)}},_t=e=>{switch(e[3]){case"cpu":return new U.Tensor(e[0],e[2],e[1]);case"gpu-buffer":{let t=e[0];if(!ie(t))throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:o,dispose:r}=e[2];return U.Tensor.fromGpuBuffer(n,{dataType:t,dims:e[1],download:o,dispose:r})}default:throw new Error(`invalid data location: ${e[3]}`)}},ce=class{async fetchModelAndCopyToWasmMemory(t){return Qe(await Y(t))}async loadModel(t,n){(0,U.TRACE_FUNC_BEGIN)();let o;typeof t=="string"?D?o=await Y(t):o=await this.fetchModelAndCopyToWasmMemory(t):o=t,[this.sessionId,this.inputNames,this.outputNames]=await Ze(o,n),(0,U.TRACE_FUNC_END)()}async dispose(){return et(this.sessionId)}async run(t,n,o){(0,U.TRACE_FUNC_BEGIN)();let r=[],a=[];Object.entries(t).forEach(i=>{let b=i[0],f=i[1],g=this.inputNames.indexOf(b);if(g===-1)throw new Error(`invalid input '${b}'`);r.push(f),a.push(g)});let s=[],u=[];Object.entries(n).forEach(i=>{let b=i[0],f=i[1],g=this.outputNames.indexOf(b);if(g===-1)throw new Error(`invalid output '${b}'`);s.push(f),u.push(g)});let c=r.map((i,b)=>nt(i,()=>`input "${this.inputNames[a[b]]}"`)),d=s.map((i,b)=>i?nt(i,()=>`output "${this.outputNames[u[b]]}"`):null),y=await tt(this.sessionId,a,c,u,d,o),l={};for(let i=0;i<y.length;i++)l[this.outputNames[u[i]]]=s[i]??_t(y[i]);return(0,U.TRACE_FUNC_END)(),l}startProfiling(){}endProfiling(){rt(this.sessionId)}}});var O,Dt,le,st=P(()=>{"use strict";O=require("onnxruntime-common");he();ot();oe();Dt=()=>{if((typeof O.env.wasm.initTimeout!="number"||O.env.wasm.initTimeout<0)&&(O.env.wasm.initTimeout=0),O.env.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 O.env.wasm.proxy!="boolean"&&(O.env.wasm.proxy=!1),typeof O.env.wasm.trace!="boolean"&&(O.env.wasm.trace=!1),typeof O.env.wasm.numThreads!="number"||!Number.isInteger(O.env.wasm.numThreads)||O.env.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)O.env.wasm.numThreads=1;else{let e=typeof navigator>"u"?require("node:os").cpus().length:navigator.hardwareConcurrency;O.env.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}O.env.wasm.wasmPaths===void 0&&F&&F.indexOf("blob:")!==0&&(O.env.wasm.wasmPaths=F.substring(0,F.lastIndexOf("/")+1))},le=class{async init(t){Dt(),await Xe(),await Ke(t)}async createInferenceSessionHandler(t,n){let o=new ce;return await o.loadModel(t,n),Promise.resolve(o)}}});var at={};xe(at,{wasmBackend:()=>Mt});var Mt,it=P(()=>{"use strict";st();Mt=new le});var T={};xe(T,{default:()=>Ft});module.exports=Pe(T);k(T,require("onnxruntime-common"),module.exports);var Wt=wt(require("onnxruntime-common")),X=require("onnxruntime-common");var Le="1.20.0-dev.20240914-c63dd0234b";var Ft=Wt;{let e=(it(),Pe(at)).wasmBackend;(0,X.registerBackend)("cpu",e,10),(0,X.registerBackend)("wasm",e,10)}Object.defineProperty(X.env.versions,"web",{value:Le,enumerable:!0});0&&(module.exports={...require("onnxruntime-common")});
//# sourceMappingURL=ort.node.min.js.map
/*!
* ONNX Runtime Web v1.20.0-dev.20240913-904b850b44
* ONNX Runtime Web v1.20.0-dev.20240914-c63dd0234b
* Copyright (c) Microsoft Corporation. All rights reserved.

@@ -7,4 +7,4 @@ * Licensed under the MIT License.

"use strict";var ort=(()=>{var et=Object.defineProperty;var Gn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var Vn=Object.prototype.hasOwnProperty;var tt=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,n)=>(typeof require<"u"?require:e)[n]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var g=(t,e)=>()=>(t&&(e=t(t=0)),e);var Ae=(t,e)=>{for(var n in e)et(t,n,{get:e[n],enumerable:!0})},Yn=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of jn(e))!Vn.call(t,r)&&r!==n&&et(t,r,{get:()=>e[r],enumerable:!(o=Gn(e,r))||o.enumerable});return t};var nt=t=>Yn(et({},"__esModule",{value:!0}),t);var Oe,j,ee,qn,Ie,ve=g(()=>{"use strict";Oe=new Map,j=[],ee=(t,e,n)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let o=Oe.get(t);if(o===void 0)Oe.set(t,{backend:e,priority:n});else{if(o.priority>n)return;if(o.priority===n&&o.backend!==e)throw new Error(`cannot register backend "${t}" using priority ${n}`)}if(n>=0){let r=j.indexOf(t);r!==-1&&j.splice(r,1);for(let a=0;a<j.length;a++)if(Oe.get(j[a]).priority<=n){j.splice(a,0,t);return}j.push(t)}return}throw new TypeError("not a valid backend")},qn=async t=>{let e=Oe.get(t);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let n=!!e.initPromise;try{return n||(e.initPromise=e.backend.init(t)),await e.initPromise,e.initialized=!0,e.backend}catch(o){return n||(e.error=`${o}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},Ie=async t=>{let e=t.executionProviders||[],n=e.map(c=>typeof c=="string"?c:c.name),o=n.length===0?j:n,r,a=[],s=new Set;for(let c of o){let u=await qn(c);typeof u=="string"?a.push({name:c,err:u}):(r||(r=u),r===u&&s.add(c))}if(!r)throw new Error(`no available backend found. ERR: ${a.map(c=>`[${c.name}] ${c.err}`).join(", ")}`);for(let{name:c,err:u}of a)n.includes(c)&&console.warn(`removing requested execution provider "${c}" from session options because it is not available: ${u}`);let i=e.filter(c=>s.has(typeof c=="string"?c:c.name));return[r,new Proxy(t,{get:(c,u)=>u==="executionProviders"?i:Reflect.get(c,u)})]}});var Pt=g(()=>{"use strict";ve()});var xt,Ct=g(()=>{"use strict";xt="1.20.0-dev.20240912-ae39c40e5b"});var Bt,U,rt=g(()=>{"use strict";Ct();Bt="warning",U={wasm:{},webgl:{},webgpu:{},versions:{common:xt},set logLevel(t){if(t!==void 0){if(typeof t!="string"||["verbose","info","warning","error","fatal"].indexOf(t)===-1)throw new Error(`Unsupported logging level: ${t}`);Bt=t}},get logLevel(){return Bt}};Object.defineProperty(U,"logLevel",{enumerable:!0})});var O,_t=g(()=>{"use strict";rt();O=U});var Rt,Ut,Mt=g(()=>{"use strict";Rt=(t,e)=>{let n=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);n.width=t.dims[3],n.height=t.dims[2];let o=n.getContext("2d");if(o!=null){let r,a;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=t.dims[2],a=t.dims[3]):(r=t.dims[3],a=t.dims[2]);let s=e?.format!==void 0?e.format:"RGB",i=e?.norm,c,u;i===void 0||i.mean===void 0?c=[255,255,255,255]:typeof i.mean=="number"?c=[i.mean,i.mean,i.mean,i.mean]:(c=[i.mean[0],i.mean[1],i.mean[2],0],i.mean[3]!==void 0&&(c[3]=i.mean[3])),i===void 0||i.bias===void 0?u=[0,0,0,0]:typeof i.bias=="number"?u=[i.bias,i.bias,i.bias,i.bias]:(u=[i.bias[0],i.bias[1],i.bias[2],0],i.bias[3]!==void 0&&(u[3]=i.bias[3]));let f=a*r,l=0,d=f,m=f*2,h=-1;s==="RGBA"?(l=0,d=f,m=f*2,h=f*3):s==="RGB"?(l=0,d=f,m=f*2):s==="RBG"&&(l=0,m=f,d=f*2);for(let p=0;p<a;p++)for(let b=0;b<r;b++){let S=(t.data[l++]-u[0])*c[0],w=(t.data[d++]-u[1])*c[1],y=(t.data[m++]-u[2])*c[2],T=h===-1?255:(t.data[h++]-u[3])*c[3];o.fillStyle="rgba("+S+","+w+","+y+","+T+")",o.fillRect(b,p,1,1)}if("toDataURL"in n)return n.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},Ut=(t,e)=>{let n=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),o;if(n!=null){let r,a,s;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=t.dims[2],a=t.dims[1],s=t.dims[3]):(r=t.dims[3],a=t.dims[2],s=t.dims[1]);let i=e!==void 0&&e.format!==void 0?e.format:"RGB",c=e?.norm,u,f;c===void 0||c.mean===void 0?u=[255,255,255,255]:typeof c.mean=="number"?u=[c.mean,c.mean,c.mean,c.mean]:(u=[c.mean[0],c.mean[1],c.mean[2],255],c.mean[3]!==void 0&&(u[3]=c.mean[3])),c===void 0||c.bias===void 0?f=[0,0,0,0]:typeof c.bias=="number"?f=[c.bias,c.bias,c.bias,c.bias]:(f=[c.bias[0],c.bias[1],c.bias[2],0],c.bias[3]!==void 0&&(f[3]=c.bias[3]));let l=a*r;if(e!==void 0&&(e.format!==void 0&&s===4&&e.format!=="RGBA"||s===3&&e.format!=="RGB"&&e.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let d=4,m=0,h=1,p=2,b=3,S=0,w=l,y=l*2,T=-1;i==="RGBA"?(S=0,w=l,y=l*2,T=l*3):i==="RGB"?(S=0,w=l,y=l*2):i==="RBG"&&(S=0,y=l,w=l*2),o=n.createImageData(r,a);for(let P=0;P<a*r;m+=d,h+=d,p+=d,b+=d,P++)o.data[m]=(t.data[S++]-f[0])*u[0],o.data[h]=(t.data[w++]-f[1])*u[1],o.data[p]=(t.data[y++]-f[2])*u[2],o.data[b]=T===-1?255:(t.data[T++]-f[3])*u[3]}else throw new Error("Can not access image data");return o}});var ot,Lt,kt,Dt,Nt,Ft=g(()=>{"use strict";Pe();ot=(t,e)=>{if(t===void 0)throw new Error("Image buffer must be defined");if(e.height===void 0||e.width===void 0)throw new Error("Image height and width must be defined");if(e.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:n,width:o}=e,r=e.norm??{mean:255,bias:0},a,s;typeof r.mean=="number"?a=[r.mean,r.mean,r.mean,r.mean]:a=[r.mean[0],r.mean[1],r.mean[2],r.mean[3]??255],typeof r.bias=="number"?s=[r.bias,r.bias,r.bias,r.bias]:s=[r.bias[0],r.bias[1],r.bias[2],r.bias[3]??0];let i=e.format!==void 0?e.format:"RGBA",c=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",u=n*o,f=c==="RGBA"?new Float32Array(u*4):new Float32Array(u*3),l=4,d=0,m=1,h=2,p=3,b=0,S=u,w=u*2,y=-1;i==="RGB"&&(l=3,d=0,m=1,h=2,p=-1),c==="RGBA"?y=u*3:c==="RBG"?(b=0,w=u,S=u*2):c==="BGR"&&(w=0,S=u,b=u*2);for(let P=0;P<u;P++,d+=l,h+=l,m+=l,p+=l)f[b++]=(t[d]+s[0])/a[0],f[S++]=(t[m]+s[1])/a[1],f[w++]=(t[h]+s[2])/a[2],y!==-1&&p!==-1&&(f[y++]=(t[p]+s[3])/a[3]);return c==="RGBA"?new C("float32",f,[1,4,n,o]):new C("float32",f,[1,3,n,o])},Lt=async(t,e)=>{let n=typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement,o=typeof ImageData<"u"&&t instanceof ImageData,r=typeof ImageBitmap<"u"&&t instanceof ImageBitmap,a=typeof t=="string",s,i=e??{},c=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},u=f=>f instanceof HTMLCanvasElement||f instanceof OffscreenCanvas?f.getContext("2d"):null;if(n){let f=c();f.width=t.width,f.height=t.height;let l=u(f);if(l!=null){let d=t.height,m=t.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(d=e.resizedHeight,m=e.resizedWidth),e!==void 0){if(i=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");i.tensorFormat="RGBA",i.height=d,i.width=m}else i.tensorFormat="RGBA",i.height=d,i.width=m;l.drawImage(t,0,0),s=l.getImageData(0,0,m,d).data}else throw new Error("Can not access image data")}else if(o){let f,l;if(e!==void 0&&e.resizedWidth!==void 0&&e.resizedHeight!==void 0?(f=e.resizedHeight,l=e.resizedWidth):(f=t.height,l=t.width),e!==void 0&&(i=e),i.format="RGBA",i.height=f,i.width=l,e!==void 0){let d=c();d.width=l,d.height=f;let m=u(d);if(m!=null)m.putImageData(t,0,0),s=m.getImageData(0,0,l,f).data;else throw new Error("Can not access image data")}else s=t.data}else if(r){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let f=c();f.width=t.width,f.height=t.height;let l=u(f);if(l!=null){let d=t.height,m=t.width;return l.drawImage(t,0,0,m,d),s=l.getImageData(0,0,m,d).data,i.height=d,i.width=m,ot(s,i)}else throw new Error("Can not access image data")}else{if(a)return new Promise((f,l)=>{let d=c(),m=u(d);if(!t||!m)return l();let h=new Image;h.crossOrigin="Anonymous",h.src=t,h.onload=()=>{d.width=h.width,d.height=h.height,m.drawImage(h,0,0,d.width,d.height);let p=m.getImageData(0,0,d.width,d.height);i.height=d.height,i.width=d.width,f(ot(p.data,i))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return ot(s,i);throw new Error("Input data provided is not supported - aborted tensor creation")},kt=(t,e)=>{let{width:n,height:o,download:r,dispose:a}=e,s=[1,o,n,4];return new C({location:"texture",type:"float32",texture:t,dims:s,download:r,dispose:a})},Dt=(t,e)=>{let{dataType:n,dims:o,download:r,dispose:a}=e;return new C({location:"gpu-buffer",type:n??"float32",gpuBuffer:t,dims:o,download:r,dispose:a})},Nt=(t,e,n)=>new C({location:"cpu-pinned",type:t,data:e,dims:n??[e.length]})});var V,le,Ht,Wt,zt=g(()=>{"use strict";V=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),le=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Ht=!1,Wt=()=>{if(!Ht){Ht=!0;let t=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,n=typeof Float16Array<"u"&&Float16Array.from;t&&(V.set("int64",BigInt64Array),le.set(BigInt64Array,"int64")),e&&(V.set("uint64",BigUint64Array),le.set(BigUint64Array,"uint64")),n?(V.set("float16",Float16Array),le.set(Float16Array,"float16")):V.set("float16",Uint16Array)}}});var $t,Gt,jt=g(()=>{"use strict";Pe();$t=t=>{let e=1;for(let n=0;n<t.length;n++){let o=t[n];if(typeof o!="number"||!Number.isSafeInteger(o))throw new TypeError(`dims[${n}] must be an integer, got: ${o}`);if(o<0)throw new RangeError(`dims[${n}] must be a non-negative integer, got: ${o}`);e*=o}return e},Gt=(t,e)=>{switch(t.location){case"cpu":return new C(t.type,t.data,e);case"cpu-pinned":return new C({location:"cpu-pinned",data:t.data,type:t.type,dims:e});case"texture":return new C({location:"texture",texture:t.texture,type:t.type,dims:e});case"gpu-buffer":return new C({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${t.location} is not supported`)}}});var C,Pe=g(()=>{"use strict";Mt();Ft();zt();jt();C=class{constructor(e,n,o){Wt();let r,a;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,r=e.type,a=e.dims,e.location){case"cpu-pinned":{let i=V.get(r);if(!i)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof i))throw new TypeError(`buffer should be of type ${i.name}`);this.cpuData=e.data;break}case"texture":{if(r!=="float32")throw new TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint8"&&r!=="bool"&&r!=="uint4"&&r!=="int4")throw new TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let i,c;if(typeof e=="string")if(r=e,c=o,e==="string"){if(!Array.isArray(n))throw new TypeError("A string tensor's data must be a string array.");i=n}else{let u=V.get(e);if(u===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(n)){if(e==="float16"&&u===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${u.name} as data.`);e==="uint64"||e==="int64"?i=u.from(n,BigInt):i=u.from(n)}else if(n instanceof u)i=n;else if(n instanceof Uint8ClampedArray)if(e==="uint8")i=Uint8Array.from(n);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else throw new TypeError(`A ${r} tensor's data must be type of ${u}`)}else if(c=n,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let u=typeof e[0];if(u==="string")r="string",i=e;else if(u==="boolean")r="bool",i=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${u}.`)}else if(e instanceof Uint8ClampedArray)r="uint8",i=Uint8Array.from(e);else{let u=le.get(e.constructor);if(u===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=u,i=e}if(c===void 0)c=[i.length];else if(!Array.isArray(c))throw new TypeError("A tensor's dims must be a number array");a=c,this.cpuData=i,this.dataLocation="cpu"}let s=$t(a);if(this.cpuData&&s!==this.cpuData.length&&!((r==="uint4"||r==="int4")&&Math.ceil(s/2)===this.cpuData.length))throw new Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=a,this.size=s}static async fromImage(e,n){return Lt(e,n)}static fromTexture(e,n){return kt(e,n)}static fromGpuBuffer(e,n){return Dt(e,n)}static fromPinnedBuffer(e,n,o){return Nt(e,n,o)}toDataURL(e){return Rt(this,e)}toImageData(e){return Ut(this,e)}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}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":{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 n=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=n,e&&this.disposer&&(this.disposer(),this.disposer=void 0),n}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.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return Gt(this,e)}}});var x,xe=g(()=>{"use strict";Pe();x=C});var st,Vt,W,z,at=g(()=>{"use strict";rt();st=(t,e)=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||console.timeStamp(`${t}::ORT::${e}`)},Vt=(t,e)=>{let n=new Error().stack?.split(/\r\n|\r|\n/g)||[],o=!1;for(let r=0;r<n.length;r++){if(o&&!n[r].includes("TRACE_FUNC")){let a=`FUNC_${t}::${n[r].trim().split(" ")[1]}`;e&&(a+=`::${e}`),st("CPU",a);return}n[r].includes("TRACE_FUNC")&&(o=!0)}},W=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Vt("BEGIN",t)},z=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Vt("END",t)}});var Ce,Yt=g(()=>{"use strict";ve();xe();at();Ce=class t{constructor(e){this.handler=e}async run(e,n,o){W();let r={},a={};if(typeof e!="object"||e===null||e instanceof x||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if(typeof n=="object"){if(n===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(n instanceof x)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(n)){if(n.length===0)throw new TypeError("'fetches' cannot be an empty array.");s=!1;for(let u of n){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);r[u]=null}if(typeof o=="object"&&o!==null)a=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,f=Object.getOwnPropertyNames(n);for(let l of this.outputNames)if(f.indexOf(l)!==-1){let d=n[l];(d===null||d instanceof x)&&(u=!0,s=!1,r[l]=d)}if(u){if(typeof o=="object"&&o!==null)a=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else a=n}}else if(typeof n<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of this.inputNames)if(typeof e[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(s)for(let u of this.outputNames)r[u]=null;let i=await this.handler.run(e,r,a),c={};for(let u in i)if(Object.hasOwnProperty.call(i,u)){let f=i[u];f instanceof x?c[u]=f:c[u]=new x(f.type,f.data,f.dims)}return z(),c}async release(){return this.handler.dispose()}static async create(e,n,o,r){W();let a,s={};if(typeof e=="string"){if(a=e,typeof n=="object"&&n!==null)s=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(a=e,typeof n=="object"&&n!==null)s=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){let f=e,l=0,d=e.byteLength;if(typeof n=="object"&&n!==null)s=n;else if(typeof n=="number"){if(l=n,!Number.isSafeInteger(l))throw new RangeError("'byteOffset' must be an integer.");if(l<0||l>=f.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${f.byteLength}).`);if(d=e.byteLength-l,typeof o=="number"){if(d=o,!Number.isSafeInteger(d))throw new RangeError("'byteLength' must be an integer.");if(d<=0||l+d>f.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${f.byteLength-l}].`);if(typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(typeof o<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof n<"u")throw new TypeError("'options' must be an object.");a=new Uint8Array(f,l,d)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[i,c]=await Ie(s),u=await i.createInferenceSessionHandler(a,c);return z(),new t(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var qt,Jt=g(()=>{"use strict";Yt();qt=Ce});var Xt=g(()=>{"use strict"});var Kt=g(()=>{"use strict"});var Qt=g(()=>{"use strict"});var Zt=g(()=>{"use strict"});var Jn,Be,en=g(()=>{"use strict";ve();xe();Jn="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",Be=class t{constructor(e,n,o){this.handler=e,this.hasOptimizerModel=n,this.hasEvalModel=o}get trainingInputNames(){return this.handler.inputNames}get trainingOutputNames(){return this.handler.outputNames}get evalInputNames(){if(this.hasEvalModel)return this.handler.evalInputNames;throw new Error("This training session has no evalModel loaded.")}get evalOutputNames(){if(this.hasEvalModel)return this.handler.evalOutputNames;throw new Error("This training session has no evalModel loaded.")}static async create(e,n){let o=e.evalModel||"",r=e.optimizerModel||"",a=n||{},[s,i]=await Ie(a);if(s.createTrainingSessionHandler){let c=await s.createTrainingSessionHandler(e.checkpointState,e.trainModel,o,r,i);return new t(c,!!e.optimizerModel,!!e.evalModel)}else throw new Error(Jn)}typeNarrowingForRunStep(e,n,o,r,a){let s={},i={};if(typeof o!="object"||o===null||o instanceof x||Array.isArray(o))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let c=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof x)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(r.length===0)throw new TypeError("'fetches' cannot be an empty array.");c=!1;for(let u of r){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(n.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);s[u]=null}if(typeof a=="object"&&a!==null)i=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,f=Object.getOwnPropertyNames(r);for(let l of n)if(f.indexOf(l)!==-1){let d=r[l];(d===null||d instanceof x)&&(u=!0,c=!1,s[l]=d)}if(u){if(typeof a=="object"&&a!==null)i=a;else if(typeof a<"u")throw new TypeError("'options' must be an object.")}else i=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of e)if(typeof o[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(c)for(let u of n)s[u]=null;return[s,i]}convertHandlerReturnTypeToMapOfTensors(e){let n={};for(let o in e)if(Object.hasOwnProperty.call(e,o)){let r=e[o];r instanceof x?n[o]=r:n[o]=new x(r.type,r.data,r.dims)}return n}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(e,n,o){let[r,a]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,e,n,o),s=await this.handler.runTrainStep(e,r,a);return this.convertHandlerReturnTypeToMapOfTensors(s)}async runOptimizerStep(e){if(this.hasOptimizerModel)await this.handler.runOptimizerStep(e||{});else throw new Error("This TrainingSession has no OptimizerModel loaded.")}async runEvalStep(e,n,o){if(this.hasEvalModel){let[r,a]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,e,n,o),s=await this.handler.runEvalStep(e,r,a);return this.convertHandlerReturnTypeToMapOfTensors(s)}else throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(e=!0){return this.handler.getParametersSize(e)}async loadParametersBuffer(e,n=!0){let o=await this.getParametersSize(n);if(e.length!==4*o)throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");return this.handler.loadParametersBuffer(e,n)}async getContiguousParameters(e=!0){return this.handler.getContiguousParameters(e)}async release(){return this.handler.dispose()}}});var tn,nn=g(()=>{"use strict";en();tn=Be});var it={};Ae(it,{InferenceSession:()=>qt,TRACE:()=>st,TRACE_FUNC_BEGIN:()=>W,TRACE_FUNC_END:()=>z,Tensor:()=>x,TrainingSession:()=>tn,env:()=>O,registerBackend:()=>ee});var Y=g(()=>{"use strict";Pt();_t();Jt();xe();Xt();Kt();at();Qt();Zt();nn()});var _e=g(()=>{"use strict"});var an={};Ae(an,{default:()=>Xn});var on,sn,Xn,un=g(()=>{"use strict";pe();$();de();on="ort-wasm-proxy-worker",sn=globalThis.self?.name===on;sn&&(self.onmessage=t=>{let{type:e,in:n}=t.data;try{switch(e){case"init-wasm":Re(n.wasm).then(()=>{Ue(n).then(()=>{postMessage({type:e})},o=>{postMessage({type:e,err:o})})},o=>{postMessage({type:e,err:o})});break;case"init-ep":{let{epName:o,env:r}=n;Me(r,o).then(()=>{postMessage({type:e})},a=>{postMessage({type:e,err:a})});break}case"copy-from":{let{buffer:o}=n,r=q(o);postMessage({type:e,out:r});break}case"create":{let{model:o,options:r}=n;Le(o,r).then(a=>{postMessage({type:e,out:a})},a=>{postMessage({type:e,err:a})});break}case"release":ke(n),postMessage({type:e});break;case"run":{let{sessionId:o,inputIndices:r,inputs:a,outputIndices:s,options:i}=n;De(o,r,a,s,new Array(s.length).fill(null),i).then(c=>{c.some(u=>u[3]!=="cpu")?postMessage({type:e,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:e,out:c},Fe([...a,...c]))},c=>{postMessage({type:e,err:c})});break}case"end-profiling":Ne(n),postMessage({type:e});break;default:}}catch(o){postMessage({type:e,err:o})}});Xn=sn?null:t=>new Worker(t??L,{type:"classic",name:on})});var L,Kn,fn,Qn,Zn,ln,er,cn,dn,pn,de=g(()=>{"use strict";_e();L=!1?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,Kn=!1||typeof location>"u"?void 0:location.origin,fn=(t,e)=>{try{let n=e??L;return(n?new URL(t,n):new URL(t)).origin===Kn}catch{return!1}},Qn=(t,e)=>{let n=e??L;try{return(n?new URL(t,n):new URL(t)).href}catch{return}},Zn=(t,e)=>`${e??"./"}${t}`,ln=async t=>{let n=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},er=async t=>(await import(/*webpackIgnore:true*/t)).default,cn=(un(),nt(an)).default,dn=async()=>{if(!L)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(fn(L))return[void 0,cn()];let t=await ln(L);return[t,cn(t)]},pn=async(t,e,n)=>{{let o="ort-training-wasm-simd-threaded.mjs",r=t??Qn(o,e),a=!!1&&n&&r&&!fn(r,e),s=a?await ln(r):r??Zn(o,e);return[a?s:void 0,await er(s)]}}});var ut,ct,He,mn,tr,nr,Re,E,$=g(()=>{"use strict";de();ct=!1,He=!1,mn=!1,tr=()=>{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}},nr=()=>{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}},Re=async t=>{if(ct)return Promise.resolve();if(He)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(mn)throw new Error("previous call to 'initializeWebAssembly()' failed.");He=!0;let e=t.initTimeout,n=t.numThreads;if(!nr())throw new Error("WebAssembly SIMD is not supported in the current environment.");let o=tr();n>1&&!o&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+n+", 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."),t.numThreads=n=1);let r=t.wasmPaths,a=typeof r=="string"?r:void 0,s=r?.mjs,i=s?.href??s,c=r?.wasm,u=c?.href??c,f=t.wasmBinary,[l,d]=await pn(i,a,n>1),m=!1,h=[];if(e>0&&h.push(new Promise(p=>{setTimeout(()=>{m=!0,p()},e)})),h.push(new Promise((p,b)=>{let S={numThreads:n};f?S.wasmBinary=f:(u||a)&&(S.locateFile=(w,y)=>u??(a??y)+w),d(S).then(w=>{He=!1,ct=!0,ut=w,p(),l&&URL.revokeObjectURL(l)},w=>{He=!1,mn=!0,b(w)})})),await Promise.race(h),m)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},E=()=>{if(ct&&ut)return ut;throw new Error("WebAssembly is not initialized yet.")}});var v,me,I,he=g(()=>{"use strict";$();v=(t,e)=>{let n=E(),o=n.lengthBytesUTF8(t)+1,r=n._malloc(o);return n.stringToUTF8(t,r,o),e.push(r),r},me=(t,e,n,o)=>{if(typeof t=="object"&&t!==null){if(n.has(t))throw new Error("Circular reference in options");n.add(t)}Object.entries(t).forEach(([r,a])=>{let s=e?e+r:r;if(typeof a=="object")me(a,s+".",n,o);else if(typeof a=="string"||typeof a=="number")o(s,a.toString());else if(typeof a=="boolean")o(s,a?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof a}`)})},I=t=>{let e=E(),n=e.stackSave();try{let o=e.stackAlloc(8);e._OrtGetLastError(o,o+4);let r=e.HEAP32[o/4],a=e.HEAPU32[o/4+1],s=a?e.UTF8ToString(a):"";throw new Error(`${t} ERROR_CODE: ${r}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(n)}}});var te,ft=g(()=>{"use strict";$();he();te=t=>{let e=E(),n=0,o=[],r=t||{};try{if(t?.logSeverityLevel===void 0)r.logSeverityLevel=2;else if(typeof t.logSeverityLevel!="number"||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(t?.logVerbosityLevel===void 0)r.logVerbosityLevel=0;else if(typeof t.logVerbosityLevel!="number"||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);t?.terminate===void 0&&(r.terminate=!1);let a=0;return t?.tag!==void 0&&(a=v(t.tag,o)),n=e._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,a),n===0&&I("Can't create run options."),t?.extra!==void 0&&me(t.extra,"",new WeakSet,(s,i)=>{let c=v(s,o),u=v(i,o);e._OrtAddRunConfigEntry(n,c,u)!==0&&I(`Can't set a run config entry: ${s} - ${i}.`)}),[n,o]}catch(a){throw n!==0&&e._OrtReleaseRunOptions(n),o.forEach(s=>e._free(s)),a}}});var rr,or,sr,ar,We,lt=g(()=>{"use strict";$();he();rr=t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${t}`)}},or=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},sr=t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});let e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),t.executionProviders&&t.executionProviders.some(n=>(typeof n=="string"?n:n.name)==="webgpu")&&(t.enableMemPattern=!1)},ar=(t,e,n)=>{for(let o of e){let r=typeof o=="string"?o:o.name;switch(r){case"webnn":if(r="WEBNN",typeof o!="string"){let i=o?.deviceType;if(i){let c=v("deviceType",n),u=v(i,n);E()._OrtAddSessionConfigEntry(t,c,u)!==0&&I(`Can't set a session config entry: 'deviceType' - ${i}.`)}}break;case"webgpu":if(r="JS",typeof o!="string"){let s=o;if(s?.preferredLayout){if(s.preferredLayout!=="NCHW"&&s.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${s.preferredLayout}`);let i=v("preferredLayout",n),c=v(s.preferredLayout,n);E()._OrtAddSessionConfigEntry(t,i,c)!==0&&I(`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 a=v(r,n);E()._OrtAppendExecutionProvider(t,a)!==0&&I(`Can't append execution provider: ${r}.`)}},We=t=>{let e=E(),n=0,o=[],r=t||{};sr(r);try{let a=rr(r.graphOptimizationLevel??"all"),s=or(r.executionMode??"sequential"),i=typeof r.logId=="string"?v(r.logId,o):0,c=r.logSeverityLevel??2;if(!Number.isInteger(c)||c<0||c>4)throw new Error(`log serverity level is not valid: ${c}`);let u=r.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let f=typeof r.optimizedModelFilePath=="string"?v(r.optimizedModelFilePath,o):0;if(n=e._OrtCreateSessionOptions(a,!!r.enableCpuMemArena,!!r.enableMemPattern,s,!!r.enableProfiling,0,i,c,u,f),n===0&&I("Can't create session options."),r.executionProviders&&ar(n,r.executionProviders,o),r.enableGraphCapture!==void 0){if(typeof r.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);let l=v("enableGraphCapture",o),d=v(r.enableGraphCapture.toString(),o);e._OrtAddSessionConfigEntry(n,l,d)!==0&&I(`Can't set a session config entry: 'enableGraphCapture' - ${r.enableGraphCapture}.`)}if(r.freeDimensionOverrides)for(let[l,d]of Object.entries(r.freeDimensionOverrides)){if(typeof l!="string")throw new Error(`free dimension override name must be a string: ${l}`);if(typeof d!="number"||!Number.isInteger(d)||d<0)throw new Error(`free dimension override value must be a non-negative integer: ${d}`);let m=v(l,o);e._OrtAddFreeDimensionOverride(n,m,d)!==0&&I(`Can't set a free dimension override: ${l} - ${d}.`)}return r.extra!==void 0&&me(r.extra,"",new WeakSet,(l,d)=>{let m=v(l,o),h=v(d,o);e._OrtAddSessionConfigEntry(n,m,h)!==0&&I(`Can't set a session config entry: ${l} - ${d}.`)}),[n,o]}catch(a){throw n!==0&&e._OrtReleaseSessionOptions(n),o.forEach(s=>e._free(s)),a}}});var ne,ze,dt,ye,hn,$e,we,Ge=g(()=>{"use strict";ne=t=>{switch(t){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: ${t}`)}},ze=t=>{switch(t){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: ${t}`)}},dt=(t,e)=>{let n=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][t],o=typeof e=="number"?e:e.reduce((r,a)=>r*a,1);return n>0?Math.ceil(o*n):void 0},ye=t=>{switch(t){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: ${t}`)}},hn=t=>{switch(t){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: ${t}`)}},$e=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",we=t=>{switch(t){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;default:throw new Error(`unsupported data location: ${t}`)}}});var ge,pt=g(()=>{"use strict";_e();ge=async t=>{if(typeof t=="string")if(!1)try{let{readFile:e}=tt("node:fs/promises");return new Uint8Array(await e(t))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:n}=tt("node:fs"),o=n(t),r=[];for await(let a of o)r.push(a);return new Uint8Array(Buffer.concat(r))}throw e}else{let e=await fetch(t);if(!e.ok)throw new Error(`failed to load external data file: ${t}`);let n=e.headers.get("Content-Length"),o=n?parseInt(n,10):0;if(o<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${t}, no response body.`);let r=e.body.getReader(),a;try{a=new ArrayBuffer(o)}catch(i){if(i instanceof RangeError){let c=Math.ceil(o/65536);a=new WebAssembly.Memory({initial:c,maximum:c}).buffer}else throw i}let s=0;for(;;){let{done:i,value:c}=await r.read();if(i)break;let u=c.byteLength;new Uint8Array(a,s,u).set(c),s+=u}return new Uint8Array(a,0,o)}}else return t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t instanceof Uint8Array?t:new Uint8Array(t)}});var ir,Ue,Me,re,ur,q,Le,ke,je,De,Ne,Fe,pe=g(()=>{"use strict";ft();lt();Ge();$();he();pt();ir=(t,e)=>{E()._OrtInit(t,e)!==0&&I("Can't initialize onnxruntime.")},Ue=async t=>{ir(t.wasm.numThreads,hn(t.logLevel))},Me=async(t,e)=>{},re=new Map,ur=t=>{let e=E(),n=e.stackSave();try{let o=e.stackAlloc(8);return e._OrtGetInputOutputCount(t,o,o+4)!==0&&I("Can't get session input/output count."),[e.HEAP32[o/4],e.HEAP32[o/4+1]]}finally{e.stackRestore(n)}},q=t=>{let e=E(),n=e._malloc(t.byteLength);if(n===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${t.byteLength}.`);return e.HEAPU8.set(t,n),[n,t.byteLength]},Le=async(t,e)=>{let n,o,r=E();Array.isArray(t)?[n,o]=t:t.buffer===r.HEAPU8.buffer?[n,o]=[t.byteOffset,t.byteLength]:[n,o]=q(t);let a=0,s=0,i=0,c=[],u=[],f=[];try{if([s,c]=We(e),e?.externalData&&r.mountExternalData){let w=[];for(let y of e.externalData){let T=typeof y=="string"?y:y.path;w.push(ge(typeof y=="string"?y:y.data).then(P=>{r.mountExternalData(T,P)}))}await Promise.all(w)}for(let w of e?.executionProviders??[])if((typeof w=="string"?w:w.name)==="webnn"){if(r.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof w!="string"){let T=w,P=T?.context,H=T?.gpuDevice,Q=T?.deviceType,ae=T?.numThreads,Ee=T?.powerPreference;P?r.currentContext=P:H?r.currentContext=await navigator.ml.createContext(H):r.currentContext=await navigator.ml.createContext({deviceType:Q,numThreads:ae,powerPreference:Ee})}else r.currentContext=await navigator.ml.createContext();break}a=await r._OrtCreateSession(n,o,s),a===0&&I("Can't create a session."),r.currentContext&&(r.currentContext=void 0);let[l,d]=ur(a),m=!!e?.enableGraphCapture,h=[],p=[],b=[];for(let w=0;w<l;w++){let y=r._OrtGetInputName(a,w);y===0&&I("Can't get an input name."),u.push(y),h.push(r.UTF8ToString(y))}for(let w=0;w<d;w++){let y=r._OrtGetOutputName(a,w);y===0&&I("Can't get an output name."),f.push(y);let T=r.UTF8ToString(y);p.push(T)}let S=null;return re.set(a,[a,u,f,S,m,!1]),[a,h,p]}catch(l){throw u.forEach(d=>r._OrtFree(d)),f.forEach(d=>r._OrtFree(d)),i!==0&&r._OrtReleaseBinding(i),a!==0&&r._OrtReleaseSession(a),l}finally{r._free(n),s!==0&&r._OrtReleaseSessionOptions(s),c.forEach(l=>r._free(l)),r.unmountExternalData?.()}},ke=t=>{let e=E(),n=re.get(t);if(!n)throw new Error(`cannot release session. invalid session id: ${t}`);let[o,r,a,s,i]=n;s&&(i&&e._OrtClearBoundOutputs(s.handle),e._OrtReleaseBinding(s.handle)),e.jsepOnReleaseSession?.(t),r.forEach(c=>e._OrtFree(c)),a.forEach(c=>e._OrtFree(c)),e._OrtReleaseSession(o),re.delete(t)},je=(t,e,n,o,r,a=!1)=>{if(!t){e.push(0);return}let s=E(),i=t[0],c=t[1],u=t[3],f,l;if(i==="string"&&u==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");if(a&&u!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${r} when enableGraphCapture is true.`);if(u==="gpu-buffer"){let h=t[2].gpuBuffer;l=dt(ne(i),c);let p=s.jsepRegisterBuffer;if(!p)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');f=p(o,r,h,l)}else{let h=t[2];if(Array.isArray(h)){l=4*h.length,f=s._malloc(l),n.push(f);let p=f/4;for(let b=0;b<h.length;b++){if(typeof h[b]!="string")throw new TypeError(`tensor data at index ${b} is not a string`);s.HEAPU32[p++]=v(h[b],n)}}else l=h.byteLength,f=s._malloc(l),n.push(f),s.HEAPU8.set(new Uint8Array(h.buffer,h.byteOffset,l),f)}let d=s.stackSave(),m=s.stackAlloc(4*c.length);try{let h=m/4;c.forEach(b=>s.HEAP32[h++]=b);let p=s._OrtCreateTensor(ne(i),f,l,m,c.length,we(u));p===0&&I(`Can't create tensor for input/output. session=${o}, index=${r}.`),e.push(p)}finally{s.stackRestore(d)}},De=async(t,e,n,o,r,a)=>{let s=E(),i=re.get(t);if(!i)throw new Error(`cannot run inference. invalid session id: ${t}`);let c=i[0],u=i[1],f=i[2],l=i[3],d=i[4],m=i[5],h=e.length,p=o.length,b=0,S=[],w=[],y=[],T=[],P=s.stackSave(),H=s.stackAlloc(h*4),Q=s.stackAlloc(h*4),ae=s.stackAlloc(p*4),Ee=s.stackAlloc(p*4);try{[b,S]=te(a);for(let A=0;A<h;A++)je(n[A],w,T,t,e[A],d);for(let A=0;A<p;A++)je(r[A],y,T,t,h+o[A],d);let N=H/4,Fn=Q/4,Hn=ae/4,Wn=Ee/4;for(let A=0;A<h;A++)s.HEAPU32[N++]=w[A],s.HEAPU32[Fn++]=u[e[A]];for(let A=0;A<p;A++)s.HEAPU32[Hn++]=y[A],s.HEAPU32[Wn++]=f[o[A]];s.jsepOnRunStart?.(c);let Tt;Tt=await s._OrtRun(c,Q,H,h,Ee,p,ae,b),Tt!==0&&I("failed to call OrtRun().");let ie=[];for(let A=0;A<p;A++){let ue=s.HEAPU32[ae/4+A];if(ue===y[A]){ie.push(r[A]);continue}let St=s.stackSave(),G=s.stackAlloc(4*4),Te=!1,M,F=0;try{s._OrtGetTensorData(ue,G,G+4,G+8,G+12)!==0&&I(`Can't access output tensor data on index ${A}.`);let Se=G/4,At=s.HEAPU32[Se++];F=s.HEAPU32[Se++];let Ot=s.HEAPU32[Se++],zn=s.HEAPU32[Se++],ce=[];for(let _=0;_<zn;_++)ce.push(s.HEAPU32[Ot/4+_]);s._OrtFree(Ot);let fe=ce.reduce((_,R)=>_*R,1);M=ze(At);let It=l?.outputPreferredLocations[o[A]];if(M==="string"){if(It==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");let _=[],R=F/4;for(let Z=0;Z<fe;Z++){let vt=s.HEAPU32[R++],$n=Z===fe-1?void 0:s.HEAPU32[R]-vt;_.push(s.UTF8ToString(vt,$n))}ie.push([M,ce,_,"cpu"])}else if(It==="gpu-buffer"&&fe>0){let _=s.jsepGetBuffer;if(!_)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let R=_(F),Z=dt(At,fe);if(Z===void 0||!$e(M))throw new Error(`Unsupported data type: ${M}`);Te=!0,ie.push([M,ce,{gpuBuffer:R,download:s.jsepCreateDownloader(R,Z,M),dispose:()=>{s._OrtReleaseTensor(ue)}},"gpu-buffer"])}else{let _=ye(M),R=new _(fe);new Uint8Array(R.buffer,R.byteOffset,R.byteLength).set(s.HEAPU8.subarray(F,F+R.byteLength)),ie.push([M,ce,R,"cpu"])}}finally{s.stackRestore(St),M==="string"&&F&&s._free(F),Te||s._OrtReleaseTensor(ue)}}return l&&!d&&(s._OrtClearBoundOutputs(l.handle),re.set(t,[c,u,f,l,d,!1])),ie}finally{s.stackRestore(P),w.forEach(N=>s._OrtReleaseTensor(N)),y.forEach(N=>s._OrtReleaseTensor(N)),T.forEach(N=>s._free(N)),b!==0&&s._OrtReleaseRunOptions(b),S.forEach(N=>s._free(N))}},Ne=t=>{let e=E(),n=re.get(t);if(!n)throw new Error("invalid session id");let o=n[0],r=e._OrtEndProfiling(o);r===0&&I("Can't get an profile file name."),e._OrtFree(r)},Fe=t=>{let e=[];for(let n of t){let o=n[2];!Array.isArray(o)&&"buffer"in o&&e.push(o.buffer)}return e}});var X,k,be,Ye,qe,Ve,mt,ht,oe,se,fr,yn,wn,gn,bn,En,Tn,Sn,yt=g(()=>{"use strict";Y();pe();$();de();X=()=>!!O.wasm.proxy&&typeof document<"u",be=!1,Ye=!1,qe=!1,ht=new Map,oe=(t,e)=>{let n=ht.get(t);n?n.push(e):ht.set(t,[e])},se=()=>{if(be||!Ye||qe||!k)throw new Error("worker not ready")},fr=t=>{switch(t.data.type){case"init-wasm":be=!1,t.data.err?(qe=!0,mt[1](t.data.err)):(Ye=!0,mt[0]()),Ve&&(URL.revokeObjectURL(Ve),Ve=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=ht.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}default:}},yn=async()=>{if(!Ye){if(be)throw new Error("multiple calls to 'initWasm()' detected.");if(qe)throw new Error("previous call to 'initWasm()' failed.");if(be=!0,X())return new Promise((t,e)=>{k?.terminate(),dn().then(([n,o])=>{try{k=o,k.onerror=a=>e(a),k.onmessage=fr,mt=[t,e];let r={type:"init-wasm",in:O};k.postMessage(r),Ve=n}catch(r){e(r)}},e)});try{await Re(O.wasm),await Ue(O),Ye=!0}catch(t){throw qe=!0,t}finally{be=!1}}},wn=async t=>{if(X())return se(),new Promise((e,n)=>{oe("init-ep",[e,n]);let o={type:"init-ep",in:{epName:t,env:O}};k.postMessage(o)});await Me(O,t)},gn=async t=>X()?(se(),new Promise((e,n)=>{oe("copy-from",[e,n]);let o={type:"copy-from",in:{buffer:t}};k.postMessage(o,[t.buffer])})):q(t),bn=async(t,e)=>{if(X()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return se(),new Promise((n,o)=>{oe("create",[n,o]);let r={type:"create",in:{model:t,options:{...e}}},a=[];t instanceof Uint8Array&&a.push(t.buffer),k.postMessage(r,a)})}else return Le(t,e)},En=async t=>{if(X())return se(),new Promise((e,n)=>{oe("release",[e,n]);let o={type:"release",in:t};k.postMessage(o)});ke(t)},Tn=async(t,e,n,o,r,a)=>{if(X()){if(n.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 se(),new Promise((s,i)=>{oe("run",[s,i]);let c=n,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:c,outputIndices:o,options:a}};k.postMessage(u,Fe(c))})}else return De(t,e,n,o,r,a)},Sn=async t=>{if(X())return se(),new Promise((e,n)=>{oe("end-profiling",[e,n]);let o={type:"end-profiling",in:t};k.postMessage(o)});Ne(t)}});var K,Xe,Je,wt=g(()=>{"use strict";Y();yt();Ge();_e();pt();K=(t,e)=>{switch(t.location){case"cpu":return[t.type,t.dims,t.data,"cpu"];case"gpu-buffer":return[t.type,t.dims,{gpuBuffer:t.gpuBuffer},"gpu-buffer"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},Xe=t=>{switch(t[3]){case"cpu":return new x(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!$e(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:n,download:o,dispose:r}=t[2];return x.fromGpuBuffer(n,{dataType:e,dims:t[1],download:o,dispose:r})}default:throw new Error(`invalid data location: ${t[3]}`)}},Je=class{async fetchModelAndCopyToWasmMemory(e){return gn(await ge(e))}async loadModel(e,n){W();let o;typeof e=="string"?!1?o=await ge(e):o=await this.fetchModelAndCopyToWasmMemory(e):o=e,[this.sessionId,this.inputNames,this.outputNames]=await bn(o,n),z()}async dispose(){return En(this.sessionId)}async run(e,n,o){W();let r=[],a=[];Object.entries(e).forEach(d=>{let m=d[0],h=d[1],p=this.inputNames.indexOf(m);if(p===-1)throw new Error(`invalid input '${m}'`);r.push(h),a.push(p)});let s=[],i=[];Object.entries(n).forEach(d=>{let m=d[0],h=d[1],p=this.outputNames.indexOf(m);if(p===-1)throw new Error(`invalid output '${m}'`);s.push(h),i.push(p)});let c=r.map((d,m)=>K(d,()=>`input "${this.inputNames[a[m]]}"`)),u=s.map((d,m)=>d?K(d,()=>`output "${this.outputNames[i[m]]}"`):null),f=await Tn(this.sessionId,a,c,i,u,o),l={};for(let d=0;d<f.length;d++)l[this.outputNames[i[d]]]=s[d]??Xe(f[d]);return z(),l}startProfiling(){}endProfiling(){Sn(this.sessionId)}}});var lr,Ke,An=g(()=>{"use strict";Y();yt();wt();de();lr=()=>{if((typeof O.wasm.initTimeout!="number"||O.wasm.initTimeout<0)&&(O.wasm.initTimeout=0),O.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 O.wasm.proxy!="boolean"&&(O.wasm.proxy=!1),typeof O.wasm.trace!="boolean"&&(O.wasm.trace=!1),typeof O.wasm.numThreads!="number"||!Number.isInteger(O.wasm.numThreads)||O.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)O.wasm.numThreads=1;else{let t=typeof navigator>"u"?tt("node:os").cpus().length:navigator.hardwareConcurrency;O.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}O.wasm.wasmPaths===void 0&&L&&L.indexOf("blob:")!==0&&(O.wasm.wasmPaths=L.substring(0,L.lastIndexOf("/")+1))},Ke=class{async init(e){lr(),await yn(),await wn(e)}async createInferenceSessionHandler(e,n){let o=new Je;return await o.loadModel(e,n),Promise.resolve(o)}}});var D,B,In,dr,On,gt,vn,Qe,Pn,xn,Cn,Bn,_n,bt,Rn,Un,Mn,Ln=g(()=>{"use strict";ft();lt();Ge();pe();$();he();D="Built without training API's enabled. Use the onnxruntime-web/training import for training functionality, and make sure that all the correct artifacts are built & moved to the correct folder if using a custom build. Check https://onnxruntime.ai/docs/build/web.html for more information.",B=(t,e,n=!0)=>{n&&t!==0?I(e):!n&&t===0&&I(e)},In=t=>{let e=E(),[n,o]=t,r=0;try{if(e._OrtTrainingLoadCheckpoint)r=e._OrtTrainingLoadCheckpoint(n,o);else throw new Error(D);return B(r,"Error occurred when trying to create a CheckpointState",!1),r}catch(a){throw e._OrtTrainingReleaseCheckpoint&&r!==0&&e._OrtTrainingReleaseCheckpoint(r),a}finally{e._OrtFree(t[0])}},dr=(t,e)=>{let n=E(),o=n.stackSave();try{let r=n.stackAlloc(8);if(n._OrtTrainingGetModelInputOutputCount){let a=n._OrtTrainingGetModelInputOutputCount(t,r,r+4,e);return B(a,"Can't get session input/output count."),[n.HEAP32[r/4],n.HEAP32[r/4+1]]}else throw new Error(D)}finally{n.stackRestore(o)}},On=(t,e,n,o)=>{let r=[],a=E();for(let s=0;s<e;s++)if(a._OrtTrainingGetModelInputOutputName){let i=a._OrtTrainingGetModelInputOutputName(t,s,n,o);B(i,`Can't get input or output name -- is input: ${n}, index ${s}`,!1),r.push(a.UTF8ToString(i)),a._free(i)}else throw new Error(D);return r},gt=(t,e)=>{let n=[],o=[],[r,a]=dr(t,e);return n=On(t,r,!0,e),o=On(t,a,!1,e),[n,o]},vn=(t,e,n,o,r)=>{let a=E(),s=0,i=0,c=[];try{if([i,c]=We(r),a._OrtTrainingCreateSession)s=a._OrtTrainingCreateSession(i,t,e[0],e[1],n[0],n[1],o[0],o[1]);else throw new Error(D);return B(s,"Error occurred when trying to create a TrainingSession",!1),s}catch(u){throw a._OrtTrainingReleaseSession&&s!==0&&a._OrtTrainingReleaseSession(s),u}finally{a._free(e[0]),a._free(n[0]),a._free(o[0]),i!==0&&a._OrtReleaseSessionOptions(i),c.forEach(u=>a._free(u))}},Qe=(t,e,n,o,r,a)=>{let s=e.length;for(let f=0;f<s;f++)je(n[f],o,r,t,a+e[f]);let i=E(),c=i.stackAlloc(s*4),u=c/4;for(let f=0;f<s;f++)i.HEAPU32[u++]=o[f];return c},Pn=(t,e,n,o)=>{let r=E(),a=[];for(let s=0;s<e;s++){let i=r.HEAPU32[t/4+s];if(i===n[s]){a.push(o[s]);continue}let c=r.stackSave(),u=r.stackAlloc(4*4),f,l=0;try{let d=r._OrtGetTensorData(i,u,u+4,u+8,u+12);B(d,`Can't access output tensor data on index ${s}.`);let m=u/4,h=r.HEAPU32[m++];l=r.HEAPU32[m++];let p=r.HEAPU32[m++],b=r.HEAPU32[m++],S=[];for(let y=0;y<b;y++)S.push(r.HEAPU32[p/4+y]);r._OrtFree(p);let w=S.reduce((y,T)=>y*T,1);if(f=ze(h),f==="string"){let y=[],T=l/4;for(let P=0;P<w;P++){let H=r.HEAPU32[T++],Q=P===w-1?void 0:r.HEAPU32[T]-H;y.push(r.UTF8ToString(H,Q))}a.push([f,S,y,"cpu"])}else{let y=ye(f),T=new y(w);new Uint8Array(T.buffer,T.byteOffset,T.byteLength).set(r.HEAPU8.subarray(l,l+T.byteLength)),a.push([f,S,T,"cpu"])}}finally{r.stackRestore(c),f==="string"&&l&&r._free(l),r._OrtReleaseTensor(i)}}return a},xn=async t=>{let e=E();if(e._OrtTrainingLazyResetGrad){let n=e._OrtTrainingLazyResetGrad(t);B(n,"Can't call lazyResetGrad.")}else throw new Error(D)},Cn=async(t,e,n,o,r,a)=>{let s=E(),i=e.length,c=o.length,u=0,f=[],l=[],d=[],m=[],h=s.stackSave();try{[u,f]=te(a);let p=Qe(t,e,n,l,m,0),b=Qe(t,o,r,d,m,i);if(s._OrtTrainingRunTrainStep){let S=s._OrtTrainingRunTrainStep(t,p,i,b,c,u);B(S,"failed to call OrtTrainingRunTrainStep in the WebAssembly layer")}else throw new Error(D);return Pn(b,c,d,r)}finally{s.stackRestore(h),l.forEach(p=>s._OrtReleaseTensor(p)),d.forEach(p=>s._OrtReleaseTensor(p)),m.forEach(p=>s._free(p)),u!==0&&s._OrtReleaseRunOptions(u),f.forEach(p=>s._free(p))}},Bn=async(t,e)=>{let n=E(),o=0,r=[];try{if([o,r]=te(e),n._OrtTrainingOptimizerStep){let a=n._OrtTrainingOptimizerStep(t,o);B(a,"Failed to call OrtTrainingOptimizerStep in the WebAssembly layer")}else throw new Error(D)}finally{o!==0&&n._OrtReleaseRunOptions(o),r.forEach(a=>n._free(a))}},_n=async(t,e,n,o,r,a)=>{let s=E(),i=e.length,c=o.length,u=0,f=[],l=[],d=[],m=[],h=s.stackSave();try{[u,f]=te(a);let p=Qe(t,e,n,l,m,0),b=Qe(t,o,r,d,m,i);if(s._OrtTrainingEvalStep){let S=s._OrtTrainingEvalStep(t,p,i,b,c,u);B(S,"failed to call OrtTrainingEvalStep in the WebAssembly layer")}else throw new Error(D);return Pn(b,c,d,r)}finally{s.stackRestore(h),l.forEach(p=>s._OrtReleaseTensor(p)),d.forEach(p=>s._OrtReleaseTensor(p)),m.forEach(p=>s._free(p)),u!==0&&s._OrtReleaseRunOptions(u),f.forEach(p=>s._free(p))}},bt=(t,e)=>{let n=E(),o=n.stackSave();try{let r=n.stackAlloc(4);if(n._OrtTrainingGetParametersSize){let a=n._OrtTrainingGetParametersSize(t,r,e);return B(a,"Can't get parameters size"),n.HEAP32[r/4]}else throw new Error(D)}finally{n.stackRestore(o)}},Rn=async(t,e)=>{let n=E(),o=n.stackSave(),r="float32",a="cpu",s=bt(t,e),i=0,c=4*s,u=n._malloc(c),f=[s],l=n.stackAlloc(4),d=l/4;n.HEAP32[d]=s;try{if(i=n._OrtCreateTensor(ne(r),u,c,l,f.length,we(a)),B(i,`Can't create tensor for getContiguousParameters. session=${t}.`,!1),n._OrtTrainingCopyParametersToBuffer){let b=n._OrtTrainingCopyParametersToBuffer(t,i,s,e);B(b,"Can't get contiguous parameters.")}else throw new Error(D);let m=ye(r),h=new m(s),p=[];if(new Uint8Array(h.buffer,h.byteOffset,h.byteLength).set(n.HEAPU8.subarray(u,u+c)),p.push([r,f,h,a]),p.length!==1)throw new Error(`something unexpected happened in the getContiguousParameters function. Expected output length of
one, got ${p.length}`);return p[0]}finally{i!==0&&n._OrtReleaseTensor(i),n._free(u),n._free(l),n.stackRestore(o)}},Un=async(t,e,n)=>{let o=E(),r=o.stackSave(),a="float32",s="cpu",i=e.length,c=i/4,u=o._malloc(i);o.HEAPU8.set(e,u);let f=o.stackAlloc(4);o.HEAP32[f/4]=c;let l=1,d=0;try{if(d=o._OrtCreateTensor(ne(a),u,i,f,l,we(s)),B(d,`Can't create tensor for input/output. session=${t}`,!1),o._OrtTrainingCopyParametersFromBuffer){let m=o._OrtTrainingCopyParametersFromBuffer(t,d,c,n);B(m,"Can't copy buffer to parameters.")}else throw new Error(D)}finally{d!==0&&o._OrtReleaseTensor(d),o.stackRestore(r),o._free(u),o._free(f)}},Mn=(t,e)=>{let n=E();n._OrtTrainingReleaseSession&&n._OrtTrainingReleaseSession(e),n._OrtTrainingReleaseCheckpoint&&n._OrtTrainingReleaseCheckpoint(t)}});var Ze,kn=g(()=>{"use strict";wt();pe();Ln();Ze=class{constructor(){this.evalInputNames=[];this.evalOutputNames=[]}async uriOrBufferToHeap(e){let n;if(typeof e=="string"){let r=await(await fetch(e)).arrayBuffer();n=new Uint8Array(r)}else n=e;return q(n)}async createTrainingSession(e,n,o,r,a){let s=await this.uriOrBufferToHeap(e),i=await this.uriOrBufferToHeap(n),c=[0,0],u=[0,0];o!==""&&(c=await this.uriOrBufferToHeap(o)),r!==""&&(u=await this.uriOrBufferToHeap(r)),this.checkpointId=In(s),this.sessionId=vn(this.checkpointId,i,c,u,a),[this.inputNames,this.outputNames]=gt(this.sessionId,!1),o!==""&&([this.evalInputNames,this.evalOutputNames]=gt(this.sessionId,!0))}convertMapIntoValuesArrayAndIndicesArray(e,n,o){let r=[],a=[];Object.entries(e).forEach(i=>{let c=i[0],u=i[1],f=n.indexOf(c);if(f===-1)throw new Error(`invalid input '${c}`);r.push(u),a.push(f)});let s=r.map(o);return[r,a,s]}convertTensorMetadataToReturnType(e,n,o){let r={};for(let a=0;a<e.length;a++)r[this.outputNames[o[a]]]=n[a]??Xe(e[a]);return r}async lazyResetGrad(){await xn(this.sessionId)}async runTrainStep(e,n,o){let[,r,a]=this.convertMapIntoValuesArrayAndIndicesArray(e,this.inputNames,(f,l)=>K(f,()=>`input "${this.inputNames[r[l]]}"`)),[s,i,c]=this.convertMapIntoValuesArrayAndIndicesArray(n,this.outputNames,(f,l)=>f?K(f,()=>`output "${this.outputNames[i[l]]}"`):null),u=await Cn(this.sessionId,r,a,i,c,o);return this.convertTensorMetadataToReturnType(u,s,i)}async runOptimizerStep(e){await Bn(this.sessionId,e)}async runEvalStep(e,n,o){let[,r,a]=this.convertMapIntoValuesArrayAndIndicesArray(e,this.evalInputNames,(f,l)=>K(f,()=>`input "${this.evalInputNames[r[l]]}"`)),[s,i,c]=this.convertMapIntoValuesArrayAndIndicesArray(n,this.evalOutputNames,(f,l)=>f?K(f,()=>`output "${this.evalOutputNames[i[l]]}"`):null),u=await _n(this.sessionId,r,a,i,c,o);return this.convertTensorMetadataToReturnType(u,s,i)}async getParametersSize(e){return bt(this.sessionId,e)}async loadParametersBuffer(e,n){await Un(this.sessionId,e,n)}async getContiguousParameters(e){let n=await Rn(this.sessionId,e);return Xe(n)}async dispose(){return Mn(this.checkpointId,this.sessionId)}}});var Dn={};Ae(Dn,{wasmBackend:()=>pr});var Et,pr,Nn=g(()=>{"use strict";An();kn();Et=class extends Ke{async createTrainingSessionHandler(e,n,o,r,a){let s=new Ze;return await s.createTrainingSession(e,n,o,r,a),Promise.resolve(s)}},pr=new Et});var hr={};Ae(hr,{InferenceSession:()=>qt,TRACE:()=>st,TRACE_FUNC_BEGIN:()=>W,TRACE_FUNC_END:()=>z,Tensor:()=>x,TrainingSession:()=>tn,default:()=>mr,env:()=>O,registerBackend:()=>ee});Y();Y();Y();var rn="1.20.0-dev.20240913-904b850b44";var mr=it;{let t=(Nn(),nt(Dn)).wasmBackend;ee("cpu",t,10),ee("wasm",t,10)}Object.defineProperty(O.versions,"web",{value:rn,enumerable:!0});return nt(hr);})();
one, got ${p.length}`);return p[0]}finally{i!==0&&n._OrtReleaseTensor(i),n._free(u),n._free(l),n.stackRestore(o)}},Un=async(t,e,n)=>{let o=E(),r=o.stackSave(),a="float32",s="cpu",i=e.length,c=i/4,u=o._malloc(i);o.HEAPU8.set(e,u);let f=o.stackAlloc(4);o.HEAP32[f/4]=c;let l=1,d=0;try{if(d=o._OrtCreateTensor(ne(a),u,i,f,l,we(s)),B(d,`Can't create tensor for input/output. session=${t}`,!1),o._OrtTrainingCopyParametersFromBuffer){let m=o._OrtTrainingCopyParametersFromBuffer(t,d,c,n);B(m,"Can't copy buffer to parameters.")}else throw new Error(D)}finally{d!==0&&o._OrtReleaseTensor(d),o.stackRestore(r),o._free(u),o._free(f)}},Mn=(t,e)=>{let n=E();n._OrtTrainingReleaseSession&&n._OrtTrainingReleaseSession(e),n._OrtTrainingReleaseCheckpoint&&n._OrtTrainingReleaseCheckpoint(t)}});var Ze,kn=g(()=>{"use strict";wt();pe();Ln();Ze=class{constructor(){this.evalInputNames=[];this.evalOutputNames=[]}async uriOrBufferToHeap(e){let n;if(typeof e=="string"){let r=await(await fetch(e)).arrayBuffer();n=new Uint8Array(r)}else n=e;return q(n)}async createTrainingSession(e,n,o,r,a){let s=await this.uriOrBufferToHeap(e),i=await this.uriOrBufferToHeap(n),c=[0,0],u=[0,0];o!==""&&(c=await this.uriOrBufferToHeap(o)),r!==""&&(u=await this.uriOrBufferToHeap(r)),this.checkpointId=In(s),this.sessionId=vn(this.checkpointId,i,c,u,a),[this.inputNames,this.outputNames]=gt(this.sessionId,!1),o!==""&&([this.evalInputNames,this.evalOutputNames]=gt(this.sessionId,!0))}convertMapIntoValuesArrayAndIndicesArray(e,n,o){let r=[],a=[];Object.entries(e).forEach(i=>{let c=i[0],u=i[1],f=n.indexOf(c);if(f===-1)throw new Error(`invalid input '${c}`);r.push(u),a.push(f)});let s=r.map(o);return[r,a,s]}convertTensorMetadataToReturnType(e,n,o){let r={};for(let a=0;a<e.length;a++)r[this.outputNames[o[a]]]=n[a]??Xe(e[a]);return r}async lazyResetGrad(){await xn(this.sessionId)}async runTrainStep(e,n,o){let[,r,a]=this.convertMapIntoValuesArrayAndIndicesArray(e,this.inputNames,(f,l)=>K(f,()=>`input "${this.inputNames[r[l]]}"`)),[s,i,c]=this.convertMapIntoValuesArrayAndIndicesArray(n,this.outputNames,(f,l)=>f?K(f,()=>`output "${this.outputNames[i[l]]}"`):null),u=await Cn(this.sessionId,r,a,i,c,o);return this.convertTensorMetadataToReturnType(u,s,i)}async runOptimizerStep(e){await Bn(this.sessionId,e)}async runEvalStep(e,n,o){let[,r,a]=this.convertMapIntoValuesArrayAndIndicesArray(e,this.evalInputNames,(f,l)=>K(f,()=>`input "${this.evalInputNames[r[l]]}"`)),[s,i,c]=this.convertMapIntoValuesArrayAndIndicesArray(n,this.evalOutputNames,(f,l)=>f?K(f,()=>`output "${this.evalOutputNames[i[l]]}"`):null),u=await _n(this.sessionId,r,a,i,c,o);return this.convertTensorMetadataToReturnType(u,s,i)}async getParametersSize(e){return bt(this.sessionId,e)}async loadParametersBuffer(e,n){await Un(this.sessionId,e,n)}async getContiguousParameters(e){let n=await Rn(this.sessionId,e);return Xe(n)}async dispose(){return Mn(this.checkpointId,this.sessionId)}}});var Dn={};Ae(Dn,{wasmBackend:()=>pr});var Et,pr,Nn=g(()=>{"use strict";An();kn();Et=class extends Ke{async createTrainingSessionHandler(e,n,o,r,a){let s=new Ze;return await s.createTrainingSession(e,n,o,r,a),Promise.resolve(s)}},pr=new Et});var hr={};Ae(hr,{InferenceSession:()=>qt,TRACE:()=>st,TRACE_FUNC_BEGIN:()=>W,TRACE_FUNC_END:()=>z,Tensor:()=>x,TrainingSession:()=>tn,default:()=>mr,env:()=>O,registerBackend:()=>ee});Y();Y();Y();var rn="1.20.0-dev.20240914-c63dd0234b";var mr=it;{let t=(Nn(),nt(Dn)).wasmBackend;ee("cpu",t,10),ee("wasm",t,10)}Object.defineProperty(O.versions,"web",{value:rn,enumerable:!0});return nt(hr);})();
typeof exports=="object"&&typeof module=="object"&&(module.exports=ort);
//# sourceMappingURL=ort.training.wasm.min.js.map
/*!
* ONNX Runtime Web v1.20.0-dev.20240913-904b850b44
* ONNX Runtime Web v1.20.0-dev.20240914-c63dd0234b
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
"use strict";var ort=(()=>{var Ne=Object.defineProperty;var Tr=Object.getOwnPropertyDescriptor;var Ar=Object.getOwnPropertyNames;var Or=Object.prototype.hasOwnProperty;var We=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var w=(t,e)=>()=>(t&&(e=t(t=0)),e);var me=(t,e)=>{for(var r in e)Ne(t,r,{get:e[r],enumerable:!0})},vr=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ar(e))!Or.call(t,n)&&n!==r&&Ne(t,n,{get:()=>e[n],enumerable:!(o=Tr(e,n))||o.enumerable});return t};var $e=t=>vr(Ne({},"__esModule",{value:!0}),t);var he,$,q,xr,ye,we=w(()=>{"use strict";he=new Map,$=[],q=(t,e,r)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let o=he.get(t);if(o===void 0)he.set(t,{backend:e,priority:r});else{if(o.priority>r)return;if(o.priority===r&&o.backend!==e)throw new Error(`cannot register backend "${t}" using priority ${r}`)}if(r>=0){let n=$.indexOf(t);n!==-1&&$.splice(n,1);for(let i=0;i<$.length;i++)if(he.get($[i]).priority<=r){$.splice(i,0,t);return}$.push(t)}return}throw new TypeError("not a valid backend")},xr=async t=>{let e=he.get(t);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let r=!!e.initPromise;try{return r||(e.initPromise=e.backend.init(t)),await e.initPromise,e.initialized=!0,e.backend}catch(o){return r||(e.error=`${o}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},ye=async t=>{let e=t.executionProviders||[],r=e.map(a=>typeof a=="string"?a:a.name),o=r.length===0?$:r,n,i=[],s=new Set;for(let a of o){let u=await xr(a);typeof u=="string"?i.push({name:a,err:u}):(n||(n=u),n===u&&s.add(a))}if(!n)throw new Error(`no available backend found. ERR: ${i.map(a=>`[${a.name}] ${a.err}`).join(", ")}`);for(let{name:a,err:u}of i)r.includes(a)&&console.warn(`removing requested execution provider "${a}" from session options because it is not available: ${u}`);let f=e.filter(a=>s.has(typeof a=="string"?a:a.name));return[n,new Proxy(t,{get:(a,u)=>u==="executionProviders"?f:Reflect.get(a,u)})]}});var ft=w(()=>{"use strict";we()});var ct,dt=w(()=>{"use strict";ct="1.20.0-dev.20240912-ae39c40e5b"});var lt,U,Ge=w(()=>{"use strict";dt();lt="warning",U={wasm:{},webgl:{},webgpu:{},versions:{common:ct},set logLevel(t){if(t!==void 0){if(typeof t!="string"||["verbose","info","warning","error","fatal"].indexOf(t)===-1)throw new Error(`Unsupported logging level: ${t}`);lt=t}},get logLevel(){return lt}};Object.defineProperty(U,"logLevel",{enumerable:!0})});var E,pt=w(()=>{"use strict";Ge();E=U});var mt,ht,yt=w(()=>{"use strict";mt=(t,e)=>{let r=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);r.width=t.dims[3],r.height=t.dims[2];let o=r.getContext("2d");if(o!=null){let n,i;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(n=t.dims[2],i=t.dims[3]):(n=t.dims[3],i=t.dims[2]);let s=e?.format!==void 0?e.format:"RGB",f=e?.norm,a,u;f===void 0||f.mean===void 0?a=[255,255,255,255]:typeof f.mean=="number"?a=[f.mean,f.mean,f.mean,f.mean]:(a=[f.mean[0],f.mean[1],f.mean[2],0],f.mean[3]!==void 0&&(a[3]=f.mean[3])),f===void 0||f.bias===void 0?u=[0,0,0,0]:typeof f.bias=="number"?u=[f.bias,f.bias,f.bias,f.bias]:(u=[f.bias[0],f.bias[1],f.bias[2],0],f.bias[3]!==void 0&&(u[3]=f.bias[3]));let l=i*n,d=0,c=l,p=l*2,m=-1;s==="RGBA"?(d=0,c=l,p=l*2,m=l*3):s==="RGB"?(d=0,c=l,p=l*2):s==="RBG"&&(d=0,p=l,c=l*2);for(let h=0;h<i;h++)for(let S=0;S<n;S++){let O=(t.data[d++]-u[0])*a[0],y=(t.data[c++]-u[1])*a[1],b=(t.data[p++]-u[2])*a[2],A=m===-1?255:(t.data[m++]-u[3])*a[3];o.fillStyle="rgba("+O+","+y+","+b+","+A+")",o.fillRect(S,h,1,1)}if("toDataURL"in r)return r.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},ht=(t,e)=>{let r=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),o;if(r!=null){let n,i,s;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(n=t.dims[2],i=t.dims[1],s=t.dims[3]):(n=t.dims[3],i=t.dims[2],s=t.dims[1]);let f=e!==void 0&&e.format!==void 0?e.format:"RGB",a=e?.norm,u,l;a===void 0||a.mean===void 0?u=[255,255,255,255]:typeof a.mean=="number"?u=[a.mean,a.mean,a.mean,a.mean]:(u=[a.mean[0],a.mean[1],a.mean[2],255],a.mean[3]!==void 0&&(u[3]=a.mean[3])),a===void 0||a.bias===void 0?l=[0,0,0,0]:typeof a.bias=="number"?l=[a.bias,a.bias,a.bias,a.bias]:(l=[a.bias[0],a.bias[1],a.bias[2],0],a.bias[3]!==void 0&&(l[3]=a.bias[3]));let d=i*n;if(e!==void 0&&(e.format!==void 0&&s===4&&e.format!=="RGBA"||s===3&&e.format!=="RGB"&&e.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let c=4,p=0,m=1,h=2,S=3,O=0,y=d,b=d*2,A=-1;f==="RGBA"?(O=0,y=d,b=d*2,A=d*3):f==="RGB"?(O=0,y=d,b=d*2):f==="RBG"&&(O=0,b=d,y=d*2),o=r.createImageData(n,i);for(let B=0;B<i*n;p+=c,m+=c,h+=c,S+=c,B++)o.data[p]=(t.data[O++]-l[0])*u[0],o.data[m]=(t.data[y++]-l[1])*u[1],o.data[h]=(t.data[b++]-l[2])*u[2],o.data[S]=A===-1?255:(t.data[A++]-l[3])*u[3]}else throw new Error("Can not access image data");return o}});var ze,wt,bt,gt,Et,St=w(()=>{"use strict";be();ze=(t,e)=>{if(t===void 0)throw new Error("Image buffer must be defined");if(e.height===void 0||e.width===void 0)throw new Error("Image height and width must be defined");if(e.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:r,width:o}=e,n=e.norm??{mean:255,bias:0},i,s;typeof n.mean=="number"?i=[n.mean,n.mean,n.mean,n.mean]:i=[n.mean[0],n.mean[1],n.mean[2],n.mean[3]??255],typeof n.bias=="number"?s=[n.bias,n.bias,n.bias,n.bias]:s=[n.bias[0],n.bias[1],n.bias[2],n.bias[3]??0];let f=e.format!==void 0?e.format:"RGBA",a=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",u=r*o,l=a==="RGBA"?new Float32Array(u*4):new Float32Array(u*3),d=4,c=0,p=1,m=2,h=3,S=0,O=u,y=u*2,b=-1;f==="RGB"&&(d=3,c=0,p=1,m=2,h=-1),a==="RGBA"?b=u*3:a==="RBG"?(S=0,y=u,O=u*2):a==="BGR"&&(y=0,O=u,S=u*2);for(let B=0;B<u;B++,c+=d,m+=d,p+=d,h+=d)l[S++]=(t[c]+s[0])/i[0],l[O++]=(t[p]+s[1])/i[1],l[y++]=(t[m]+s[2])/i[2],b!==-1&&h!==-1&&(l[b++]=(t[h]+s[3])/i[3]);return a==="RGBA"?new P("float32",l,[1,4,r,o]):new P("float32",l,[1,3,r,o])},wt=async(t,e)=>{let r=typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement,o=typeof ImageData<"u"&&t instanceof ImageData,n=typeof ImageBitmap<"u"&&t instanceof ImageBitmap,i=typeof t=="string",s,f=e??{},a=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},u=l=>l instanceof HTMLCanvasElement||l instanceof OffscreenCanvas?l.getContext("2d"):null;if(r){let l=a();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,p=t.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(c=e.resizedHeight,p=e.resizedWidth),e!==void 0){if(f=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");f.tensorFormat="RGBA",f.height=c,f.width=p}else f.tensorFormat="RGBA",f.height=c,f.width=p;d.drawImage(t,0,0),s=d.getImageData(0,0,p,c).data}else throw new Error("Can not access image data")}else if(o){let l,d;if(e!==void 0&&e.resizedWidth!==void 0&&e.resizedHeight!==void 0?(l=e.resizedHeight,d=e.resizedWidth):(l=t.height,d=t.width),e!==void 0&&(f=e),f.format="RGBA",f.height=l,f.width=d,e!==void 0){let c=a();c.width=d,c.height=l;let p=u(c);if(p!=null)p.putImageData(t,0,0),s=p.getImageData(0,0,d,l).data;else throw new Error("Can not access image data")}else s=t.data}else if(n){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let l=a();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,p=t.width;return d.drawImage(t,0,0,p,c),s=d.getImageData(0,0,p,c).data,f.height=c,f.width=p,ze(s,f)}else throw new Error("Can not access image data")}else{if(i)return new Promise((l,d)=>{let c=a(),p=u(c);if(!t||!p)return d();let m=new Image;m.crossOrigin="Anonymous",m.src=t,m.onload=()=>{c.width=m.width,c.height=m.height,p.drawImage(m,0,0,c.width,c.height);let h=p.getImageData(0,0,c.width,c.height);f.height=c.height,f.width=c.width,l(ze(h.data,f))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return ze(s,f);throw new Error("Input data provided is not supported - aborted tensor creation")},bt=(t,e)=>{let{width:r,height:o,download:n,dispose:i}=e,s=[1,o,r,4];return new P({location:"texture",type:"float32",texture:t,dims:s,download:n,dispose:i})},gt=(t,e)=>{let{dataType:r,dims:o,download:n,dispose:i}=e;return new P({location:"gpu-buffer",type:r??"float32",gpuBuffer:t,dims:o,download:n,dispose:i})},Et=(t,e,r)=>new P({location:"cpu-pinned",type:t,data:e,dims:r??[e.length]})});var G,oe,Tt,At,Ot=w(()=>{"use strict";G=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),oe=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Tt=!1,At=()=>{if(!Tt){Tt=!0;let t=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,r=typeof Float16Array<"u"&&Float16Array.from;t&&(G.set("int64",BigInt64Array),oe.set(BigInt64Array,"int64")),e&&(G.set("uint64",BigUint64Array),oe.set(BigUint64Array,"uint64")),r?(G.set("float16",Float16Array),oe.set(Float16Array,"float16")):G.set("float16",Uint16Array)}}});var vt,xt,It=w(()=>{"use strict";be();vt=t=>{let e=1;for(let r=0;r<t.length;r++){let o=t[r];if(typeof o!="number"||!Number.isSafeInteger(o))throw new TypeError(`dims[${r}] must be an integer, got: ${o}`);if(o<0)throw new RangeError(`dims[${r}] must be a non-negative integer, got: ${o}`);e*=o}return e},xt=(t,e)=>{switch(t.location){case"cpu":return new P(t.type,t.data,e);case"cpu-pinned":return new P({location:"cpu-pinned",data:t.data,type:t.type,dims:e});case"texture":return new P({location:"texture",texture:t.texture,type:t.type,dims:e});case"gpu-buffer":return new P({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${t.location} is not supported`)}}});var P,be=w(()=>{"use strict";yt();St();Ot();It();P=class{constructor(e,r,o){At();let n,i;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,n=e.type,i=e.dims,e.location){case"cpu-pinned":{let f=G.get(n);if(!f)throw new TypeError(`unsupported type "${n}" to create tensor from pinned buffer`);if(!(e.data instanceof f))throw new TypeError(`buffer should be of type ${f.name}`);this.cpuData=e.data;break}case"texture":{if(n!=="float32")throw new TypeError(`unsupported type "${n}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(n!=="float32"&&n!=="float16"&&n!=="int32"&&n!=="int64"&&n!=="uint32"&&n!=="uint8"&&n!=="bool"&&n!=="uint4"&&n!=="int4")throw new TypeError(`unsupported type "${n}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let f,a;if(typeof e=="string")if(n=e,a=o,e==="string"){if(!Array.isArray(r))throw new TypeError("A string tensor's data must be a string array.");f=r}else{let u=G.get(e);if(u===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(r)){if(e==="float16"&&u===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${u.name} as data.`);e==="uint64"||e==="int64"?f=u.from(r,BigInt):f=u.from(r)}else if(r instanceof u)f=r;else if(r instanceof Uint8ClampedArray)if(e==="uint8")f=Uint8Array.from(r);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else throw new TypeError(`A ${n} tensor's data must be type of ${u}`)}else if(a=r,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let u=typeof e[0];if(u==="string")n="string",f=e;else if(u==="boolean")n="bool",f=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${u}.`)}else if(e instanceof Uint8ClampedArray)n="uint8",f=Uint8Array.from(e);else{let u=oe.get(e.constructor);if(u===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);n=u,f=e}if(a===void 0)a=[f.length];else if(!Array.isArray(a))throw new TypeError("A tensor's dims must be a number array");i=a,this.cpuData=f,this.dataLocation="cpu"}let s=vt(i);if(this.cpuData&&s!==this.cpuData.length&&!((n==="uint4"||n==="int4")&&Math.ceil(s/2)===this.cpuData.length))throw new Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=n,this.dims=i,this.size=s}static async fromImage(e,r){return wt(e,r)}static fromTexture(e,r){return bt(e,r)}static fromGpuBuffer(e,r){return gt(e,r)}static fromPinnedBuffer(e,r,o){return Et(e,r,o)}toDataURL(e){return mt(this,e)}toImageData(e){return ht(this,e)}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}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":{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 r=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=r,e&&this.disposer&&(this.disposer(),this.disposer=void 0),r}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.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return xt(this,e)}}});var I,ge=w(()=>{"use strict";be();I=P});var He,Pt,F,N,je=w(()=>{"use strict";Ge();He=(t,e)=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||console.timeStamp(`${t}::ORT::${e}`)},Pt=(t,e)=>{let r=new Error().stack?.split(/\r\n|\r|\n/g)||[],o=!1;for(let n=0;n<r.length;n++){if(o&&!r[n].includes("TRACE_FUNC")){let i=`FUNC_${t}::${r[n].trim().split(" ")[1]}`;e&&(i+=`::${e}`),He("CPU",i);return}r[n].includes("TRACE_FUNC")&&(o=!0)}},F=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Pt("BEGIN",t)},N=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Pt("END",t)}});var Ee,Bt=w(()=>{"use strict";we();ge();je();Ee=class t{constructor(e){this.handler=e}async run(e,r,o){F();let n={},i={};if(typeof e!="object"||e===null||e instanceof I||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof I)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(r.length===0)throw new TypeError("'fetches' cannot be an empty array.");s=!1;for(let u of r){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);n[u]=null}if(typeof o=="object"&&o!==null)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,l=Object.getOwnPropertyNames(r);for(let d of this.outputNames)if(l.indexOf(d)!==-1){let c=r[d];(c===null||c instanceof I)&&(u=!0,s=!1,n[d]=c)}if(u){if(typeof o=="object"&&o!==null)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else i=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of this.inputNames)if(typeof e[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(s)for(let u of this.outputNames)n[u]=null;let f=await this.handler.run(e,n,i),a={};for(let u in f)if(Object.hasOwnProperty.call(f,u)){let l=f[u];l instanceof I?a[u]=l:a[u]=new I(l.type,l.data,l.dims)}return N(),a}async release(){return this.handler.dispose()}static async create(e,r,o,n){F();let i,s={};if(typeof e=="string"){if(i=e,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(i=e,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){let l=e,d=0,c=e.byteLength;if(typeof r=="object"&&r!==null)s=r;else if(typeof r=="number"){if(d=r,!Number.isSafeInteger(d))throw new RangeError("'byteOffset' must be an integer.");if(d<0||d>=l.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${l.byteLength}).`);if(c=e.byteLength-d,typeof o=="number"){if(c=o,!Number.isSafeInteger(c))throw new RangeError("'byteLength' must be an integer.");if(c<=0||d+c>l.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${l.byteLength-d}].`);if(typeof n=="object"&&n!==null)s=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(typeof o<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof r<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(l,d,c)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[f,a]=await ye(s),u=await f.createInferenceSessionHandler(i,a);return N(),new t(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var Ct,Lt=w(()=>{"use strict";Bt();Ct=Ee});var Ut=w(()=>{"use strict"});var Mt=w(()=>{"use strict"});var Dt=w(()=>{"use strict"});var Rt=w(()=>{"use strict"});var Ir,Se,_t=w(()=>{"use strict";we();ge();Ir="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",Se=class t{constructor(e,r,o){this.handler=e,this.hasOptimizerModel=r,this.hasEvalModel=o}get trainingInputNames(){return this.handler.inputNames}get trainingOutputNames(){return this.handler.outputNames}get evalInputNames(){if(this.hasEvalModel)return this.handler.evalInputNames;throw new Error("This training session has no evalModel loaded.")}get evalOutputNames(){if(this.hasEvalModel)return this.handler.evalOutputNames;throw new Error("This training session has no evalModel loaded.")}static async create(e,r){let o=e.evalModel||"",n=e.optimizerModel||"",i=r||{},[s,f]=await ye(i);if(s.createTrainingSessionHandler){let a=await s.createTrainingSessionHandler(e.checkpointState,e.trainModel,o,n,f);return new t(a,!!e.optimizerModel,!!e.evalModel)}else throw new Error(Ir)}typeNarrowingForRunStep(e,r,o,n,i){let s={},f={};if(typeof o!="object"||o===null||o instanceof I||Array.isArray(o))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if(typeof n=="object"){if(n===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(n instanceof I)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(n)){if(n.length===0)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(let u of n){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(r.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);s[u]=null}if(typeof i=="object"&&i!==null)f=i;else if(typeof i<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,l=Object.getOwnPropertyNames(n);for(let d of r)if(l.indexOf(d)!==-1){let c=n[d];(c===null||c instanceof I)&&(u=!0,a=!1,s[d]=c)}if(u){if(typeof i=="object"&&i!==null)f=i;else if(typeof i<"u")throw new TypeError("'options' must be an object.")}else f=n}}else if(typeof n<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of e)if(typeof o[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(a)for(let u of r)s[u]=null;return[s,f]}convertHandlerReturnTypeToMapOfTensors(e){let r={};for(let o in e)if(Object.hasOwnProperty.call(e,o)){let n=e[o];n instanceof I?r[o]=n:r[o]=new I(n.type,n.data,n.dims)}return r}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(e,r,o){let[n,i]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,e,r,o),s=await this.handler.runTrainStep(e,n,i);return this.convertHandlerReturnTypeToMapOfTensors(s)}async runOptimizerStep(e){if(this.hasOptimizerModel)await this.handler.runOptimizerStep(e||{});else throw new Error("This TrainingSession has no OptimizerModel loaded.")}async runEvalStep(e,r,o){if(this.hasEvalModel){let[n,i]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,e,r,o),s=await this.handler.runEvalStep(e,n,i);return this.convertHandlerReturnTypeToMapOfTensors(s)}else throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(e=!0){return this.handler.getParametersSize(e)}async loadParametersBuffer(e,r=!0){let o=await this.getParametersSize(r);if(e.length!==4*o)throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");return this.handler.loadParametersBuffer(e,r)}async getContiguousParameters(e=!0){return this.handler.getContiguousParameters(e)}async release(){return this.handler.dispose()}}});var kt,Ft=w(()=>{"use strict";_t();kt=Se});var Ve={};me(Ve,{InferenceSession:()=>Ct,TRACE:()=>He,TRACE_FUNC_BEGIN:()=>F,TRACE_FUNC_END:()=>N,Tensor:()=>I,TrainingSession:()=>kt,env:()=>E,registerBackend:()=>q});var z=w(()=>{"use strict";ft();pt();Lt();ge();Ut();Mt();je();Dt();Rt();Ft()});var Te=w(()=>{"use strict"});var Gt={};me(Gt,{default:()=>Pr});var Wt,$t,Pr,zt=w(()=>{"use strict";Ye();H();se();Wt="ort-wasm-proxy-worker",$t=globalThis.self?.name===Wt;$t&&(self.onmessage=t=>{let{type:e,in:r}=t.data;try{switch(e){case"init-wasm":Ae(r.wasm).then(()=>{Oe(r).then(()=>{postMessage({type:e})},o=>{postMessage({type:e,err:o})})},o=>{postMessage({type:e,err:o})});break;case"init-ep":{let{epName:o,env:n}=r;ve(n,o).then(()=>{postMessage({type:e})},i=>{postMessage({type:e,err:i})});break}case"copy-from":{let{buffer:o}=r,n=ie(o);postMessage({type:e,out:n});break}case"create":{let{model:o,options:n}=r;xe(o,n).then(i=>{postMessage({type:e,out:i})},i=>{postMessage({type:e,err:i})});break}case"release":Ie(r),postMessage({type:e});break;case"run":{let{sessionId:o,inputIndices:n,inputs:i,outputIndices:s,options:f}=r;Pe(o,n,i,s,new Array(s.length).fill(null),f).then(a=>{a.some(u=>u[3]!=="cpu")?postMessage({type:e,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:e,out:a},Ce([...i,...a]))},a=>{postMessage({type:e,err:a})});break}case"end-profiling":Be(r),postMessage({type:e});break;default:}}catch(o){postMessage({type:e,err:o})}});Pr=$t?null:t=>new Worker(t??D,{type:"classic",name:Wt})});var D,Br,jt,Cr,Lr,Vt,Ur,Ht,Yt,qt,se=w(()=>{"use strict";Te();D=!1?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,Br=!1||typeof location>"u"?void 0:location.origin,jt=(t,e)=>{try{let r=e??D;return(r?new URL(t,r):new URL(t)).origin===Br}catch{return!1}},Cr=(t,e)=>{let r=e??D;try{return(r?new URL(t,r):new URL(t)).href}catch{return}},Lr=(t,e)=>`${e??"./"}${t}`,Vt=async t=>{let r=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(r)},Ur=async t=>(await import(/*webpackIgnore:true*/t)).default,Ht=(zt(),$e(Gt)).default,Yt=async()=>{if(!D)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(jt(D))return[void 0,Ht()];let t=await Vt(D);return[t,Ht(t)]},qt=async(t,e,r)=>{{let o="ort-wasm-simd-threaded.mjs",n=t??Cr(o,e),i=!!1&&r&&n&&!jt(n,e),s=i?await Vt(n):n??Lr(o,e);return[i?s:void 0,await Ur(s)]}}});var qe,Je,Le,Jt,Mr,Dr,Ae,v,H=w(()=>{"use strict";se();Je=!1,Le=!1,Jt=!1,Mr=()=>{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}},Dr=()=>{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}},Ae=async t=>{if(Je)return Promise.resolve();if(Le)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Jt)throw new Error("previous call to 'initializeWebAssembly()' failed.");Le=!0;let e=t.initTimeout,r=t.numThreads;if(!Dr())throw new Error("WebAssembly SIMD is not supported in the current environment.");let o=Mr();r>1&&!o&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+r+", 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."),t.numThreads=r=1);let n=t.wasmPaths,i=typeof n=="string"?n:void 0,s=n?.mjs,f=s?.href??s,a=n?.wasm,u=a?.href??a,l=t.wasmBinary,[d,c]=await qt(f,i,r>1),p=!1,m=[];if(e>0&&m.push(new Promise(h=>{setTimeout(()=>{p=!0,h()},e)})),m.push(new Promise((h,S)=>{let O={numThreads:r};l?O.wasmBinary=l:(u||i)&&(O.locateFile=(y,b)=>u??(i??b)+y),c(O).then(y=>{Le=!1,Je=!0,qe=y,h(),d&&URL.revokeObjectURL(d)},y=>{Le=!1,Jt=!0,S(y)})})),await Promise.race(m),p)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},v=()=>{if(Je&&qe)return qe;throw new Error("WebAssembly is not initialized yet.")}});var x,ae,T,Ue=w(()=>{"use strict";H();x=(t,e)=>{let r=v(),o=r.lengthBytesUTF8(t)+1,n=r._malloc(o);return r.stringToUTF8(t,n,o),e.push(n),n},ae=(t,e,r,o)=>{if(typeof t=="object"&&t!==null){if(r.has(t))throw new Error("Circular reference in options");r.add(t)}Object.entries(t).forEach(([n,i])=>{let s=e?e+n:n;if(typeof i=="object")ae(i,s+".",r,o);else if(typeof i=="string"||typeof i=="number")o(s,i.toString());else if(typeof i=="boolean")o(s,i?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof i}`)})},T=t=>{let e=v(),r=e.stackSave();try{let o=e.stackAlloc(8);e._OrtGetLastError(o,o+4);let n=e.HEAP32[o/4],i=e.HEAPU32[o/4+1],s=i?e.UTF8ToString(i):"";throw new Error(`${t} ERROR_CODE: ${n}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(r)}}});var Xt,Kt=w(()=>{"use strict";H();Ue();Xt=t=>{let e=v(),r=0,o=[],n=t||{};try{if(t?.logSeverityLevel===void 0)n.logSeverityLevel=2;else if(typeof t.logSeverityLevel!="number"||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(t?.logVerbosityLevel===void 0)n.logVerbosityLevel=0;else if(typeof t.logVerbosityLevel!="number"||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);t?.terminate===void 0&&(n.terminate=!1);let i=0;return t?.tag!==void 0&&(i=x(t.tag,o)),r=e._OrtCreateRunOptions(n.logSeverityLevel,n.logVerbosityLevel,!!n.terminate,i),r===0&&T("Can't create run options."),t?.extra!==void 0&&ae(t.extra,"",new WeakSet,(s,f)=>{let a=x(s,o),u=x(f,o);e._OrtAddRunConfigEntry(r,a,u)!==0&&T(`Can't set a run config entry: ${s} - ${f}.`)}),[r,o]}catch(i){throw r!==0&&e._OrtReleaseRunOptions(r),o.forEach(s=>e._free(s)),i}}});var Rr,_r,kr,Fr,Qt,Zt=w(()=>{"use strict";H();Ue();Rr=t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${t}`)}},_r=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},kr=t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});let e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),t.executionProviders&&t.executionProviders.some(r=>(typeof r=="string"?r:r.name)==="webgpu")&&(t.enableMemPattern=!1)},Fr=(t,e,r)=>{for(let o of e){let n=typeof o=="string"?o:o.name;switch(n){case"webnn":if(n="WEBNN",typeof o!="string"){let f=o?.deviceType;if(f){let a=x("deviceType",r),u=x(f,r);v()._OrtAddSessionConfigEntry(t,a,u)!==0&&T(`Can't set a session config entry: 'deviceType' - ${f}.`)}}break;case"webgpu":if(n="JS",typeof o!="string"){let s=o;if(s?.preferredLayout){if(s.preferredLayout!=="NCHW"&&s.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${s.preferredLayout}`);let f=x("preferredLayout",r),a=x(s.preferredLayout,r);v()._OrtAddSessionConfigEntry(t,f,a)!==0&&T(`Can't set a session config entry: 'preferredLayout' - ${s.preferredLayout}.`)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${n}`)}let i=x(n,r);v()._OrtAppendExecutionProvider(t,i)!==0&&T(`Can't append execution provider: ${n}.`)}},Qt=t=>{let e=v(),r=0,o=[],n=t||{};kr(n);try{let i=Rr(n.graphOptimizationLevel??"all"),s=_r(n.executionMode??"sequential"),f=typeof n.logId=="string"?x(n.logId,o):0,a=n.logSeverityLevel??2;if(!Number.isInteger(a)||a<0||a>4)throw new Error(`log serverity level is not valid: ${a}`);let u=n.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let l=typeof n.optimizedModelFilePath=="string"?x(n.optimizedModelFilePath,o):0;if(r=e._OrtCreateSessionOptions(i,!!n.enableCpuMemArena,!!n.enableMemPattern,s,!!n.enableProfiling,0,f,a,u,l),r===0&&T("Can't create session options."),n.executionProviders&&Fr(r,n.executionProviders,o),n.enableGraphCapture!==void 0){if(typeof n.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${n.enableGraphCapture}`);let d=x("enableGraphCapture",o),c=x(n.enableGraphCapture.toString(),o);e._OrtAddSessionConfigEntry(r,d,c)!==0&&T(`Can't set a session config entry: 'enableGraphCapture' - ${n.enableGraphCapture}.`)}if(n.freeDimensionOverrides)for(let[d,c]of Object.entries(n.freeDimensionOverrides)){if(typeof d!="string")throw new Error(`free dimension override name must be a string: ${d}`);if(typeof c!="number"||!Number.isInteger(c)||c<0)throw new Error(`free dimension override value must be a non-negative integer: ${c}`);let p=x(d,o);e._OrtAddFreeDimensionOverride(r,p,c)!==0&&T(`Can't set a free dimension override: ${d} - ${c}.`)}return n.extra!==void 0&&ae(n.extra,"",new WeakSet,(d,c)=>{let p=x(d,o),m=x(c,o);e._OrtAddSessionConfigEntry(r,p,m)!==0&&T(`Can't set a session config entry: ${d} - ${c}.`)}),[r,o]}catch(i){throw r!==0&&e._OrtReleaseSessionOptions(r),o.forEach(s=>e._free(s)),i}}});var Xe,er,Ke,tr,rr,Me,nr,Qe=w(()=>{"use strict";Xe=t=>{switch(t){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: ${t}`)}},er=t=>{switch(t){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: ${t}`)}},Ke=(t,e)=>{let r=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][t],o=typeof e=="number"?e:e.reduce((n,i)=>n*i,1);return r>0?Math.ceil(o*r):void 0},tr=t=>{switch(t){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: ${t}`)}},rr=t=>{switch(t){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: ${t}`)}},Me=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",nr=t=>{switch(t){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;default:throw new Error(`unsupported data location: ${t}`)}}});var ue,Ze=w(()=>{"use strict";Te();ue=async t=>{if(typeof t=="string")if(!1)try{let{readFile:e}=We("node:fs/promises");return new Uint8Array(await e(t))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:r}=We("node:fs"),o=r(t),n=[];for await(let i of o)n.push(i);return new Uint8Array(Buffer.concat(n))}throw e}else{let e=await fetch(t);if(!e.ok)throw new Error(`failed to load external data file: ${t}`);let r=e.headers.get("Content-Length"),o=r?parseInt(r,10):0;if(o<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${t}, no response body.`);let n=e.body.getReader(),i;try{i=new ArrayBuffer(o)}catch(f){if(f instanceof RangeError){let a=Math.ceil(o/65536);i=new WebAssembly.Memory({initial:a,maximum:a}).buffer}else throw f}let s=0;for(;;){let{done:f,value:a}=await n.read();if(f)break;let u=a.byteLength;new Uint8Array(i,s,u).set(a),s+=u}return new Uint8Array(i,0,o)}}else return t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t instanceof Uint8Array?t:new Uint8Array(t)}});var Nr,Oe,ve,J,Wr,ie,xe,Ie,or,Pe,Be,Ce,Ye=w(()=>{"use strict";Kt();Zt();Qe();H();Ue();Ze();Nr=(t,e)=>{v()._OrtInit(t,e)!==0&&T("Can't initialize onnxruntime.")},Oe=async t=>{Nr(t.wasm.numThreads,rr(t.logLevel))},ve=async(t,e)=>{},J=new Map,Wr=t=>{let e=v(),r=e.stackSave();try{let o=e.stackAlloc(8);return e._OrtGetInputOutputCount(t,o,o+4)!==0&&T("Can't get session input/output count."),[e.HEAP32[o/4],e.HEAP32[o/4+1]]}finally{e.stackRestore(r)}},ie=t=>{let e=v(),r=e._malloc(t.byteLength);if(r===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${t.byteLength}.`);return e.HEAPU8.set(t,r),[r,t.byteLength]},xe=async(t,e)=>{let r,o,n=v();Array.isArray(t)?[r,o]=t:t.buffer===n.HEAPU8.buffer?[r,o]=[t.byteOffset,t.byteLength]:[r,o]=ie(t);let i=0,s=0,f=0,a=[],u=[],l=[];try{if([s,a]=Qt(e),e?.externalData&&n.mountExternalData){let y=[];for(let b of e.externalData){let A=typeof b=="string"?b:b.path;y.push(ue(typeof b=="string"?b:b.data).then(B=>{n.mountExternalData(A,B)}))}await Promise.all(y)}for(let y of e?.executionProviders??[])if((typeof y=="string"?y:y.name)==="webnn"){if(n.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof y!="string"){let A=y,B=A?.context,Q=A?.gpuDevice,ce=A?.deviceType,Z=A?.numThreads,de=A?.powerPreference;B?n.currentContext=B:Q?n.currentContext=await navigator.ml.createContext(Q):n.currentContext=await navigator.ml.createContext({deviceType:ce,numThreads:Z,powerPreference:de})}else n.currentContext=await navigator.ml.createContext();break}i=await n._OrtCreateSession(r,o,s),i===0&&T("Can't create a session."),n.currentContext&&(n.currentContext=void 0);let[d,c]=Wr(i),p=!!e?.enableGraphCapture,m=[],h=[],S=[];for(let y=0;y<d;y++){let b=n._OrtGetInputName(i,y);b===0&&T("Can't get an input name."),u.push(b),m.push(n.UTF8ToString(b))}for(let y=0;y<c;y++){let b=n._OrtGetOutputName(i,y);b===0&&T("Can't get an output name."),l.push(b);let A=n.UTF8ToString(b);h.push(A)}let O=null;return J.set(i,[i,u,l,O,p,!1]),[i,m,h]}catch(d){throw u.forEach(c=>n._OrtFree(c)),l.forEach(c=>n._OrtFree(c)),f!==0&&n._OrtReleaseBinding(f),i!==0&&n._OrtReleaseSession(i),d}finally{n._free(r),s!==0&&n._OrtReleaseSessionOptions(s),a.forEach(d=>n._free(d)),n.unmountExternalData?.()}},Ie=t=>{let e=v(),r=J.get(t);if(!r)throw new Error(`cannot release session. invalid session id: ${t}`);let[o,n,i,s,f]=r;s&&(f&&e._OrtClearBoundOutputs(s.handle),e._OrtReleaseBinding(s.handle)),e.jsepOnReleaseSession?.(t),n.forEach(a=>e._OrtFree(a)),i.forEach(a=>e._OrtFree(a)),e._OrtReleaseSession(o),J.delete(t)},or=(t,e,r,o,n,i=!1)=>{if(!t){e.push(0);return}let s=v(),f=t[0],a=t[1],u=t[3],l,d;if(f==="string"&&u==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");if(i&&u!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${n} when enableGraphCapture is true.`);if(u==="gpu-buffer"){let m=t[2].gpuBuffer;d=Ke(Xe(f),a);let h=s.jsepRegisterBuffer;if(!h)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');l=h(o,n,m,d)}else{let m=t[2];if(Array.isArray(m)){d=4*m.length,l=s._malloc(d),r.push(l);let h=l/4;for(let S=0;S<m.length;S++){if(typeof m[S]!="string")throw new TypeError(`tensor data at index ${S} is not a string`);s.HEAPU32[h++]=x(m[S],r)}}else d=m.byteLength,l=s._malloc(d),r.push(l),s.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,d),l)}let c=s.stackSave(),p=s.stackAlloc(4*a.length);try{let m=p/4;a.forEach(S=>s.HEAP32[m++]=S);let h=s._OrtCreateTensor(Xe(f),l,d,p,a.length,nr(u));h===0&&T(`Can't create tensor for input/output. session=${o}, index=${n}.`),e.push(h)}finally{s.stackRestore(c)}},Pe=async(t,e,r,o,n,i)=>{let s=v(),f=J.get(t);if(!f)throw new Error(`cannot run inference. invalid session id: ${t}`);let a=f[0],u=f[1],l=f[2],d=f[3],c=f[4],p=f[5],m=e.length,h=o.length,S=0,O=[],y=[],b=[],A=[],B=s.stackSave(),Q=s.stackAlloc(m*4),ce=s.stackAlloc(m*4),Z=s.stackAlloc(h*4),de=s.stackAlloc(h*4);try{[S,O]=Xt(i);for(let g=0;g<m;g++)or(r[g],y,A,t,e[g],c);for(let g=0;g<h;g++)or(n[g],b,A,t,m+o[g],c);let _=Q/4,wr=ce/4,br=Z/4,gr=de/4;for(let g=0;g<m;g++)s.HEAPU32[_++]=y[g],s.HEAPU32[wr++]=u[e[g]];for(let g=0;g<h;g++)s.HEAPU32[br++]=b[g],s.HEAPU32[gr++]=l[o[g]];s.jsepOnRunStart?.(a);let nt;nt=await s._OrtRun(a,ce,Q,m,de,h,Z,S),nt!==0&&T("failed to call OrtRun().");let ee=[];for(let g=0;g<h;g++){let te=s.HEAPU32[Z/4+g];if(te===b[g]){ee.push(n[g]);continue}let ot=s.stackSave(),W=s.stackAlloc(4*4),le=!1,M,k=0;try{s._OrtGetTensorData(te,W,W+4,W+8,W+12)!==0&&T(`Can't access output tensor data on index ${g}.`);let pe=W/4,st=s.HEAPU32[pe++];k=s.HEAPU32[pe++];let it=s.HEAPU32[pe++],Er=s.HEAPU32[pe++],re=[];for(let C=0;C<Er;C++)re.push(s.HEAPU32[it/4+C]);s._OrtFree(it);let ne=re.reduce((C,L)=>C*L,1);M=er(st);let at=d?.outputPreferredLocations[o[g]];if(M==="string"){if(at==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");let C=[],L=k/4;for(let Y=0;Y<ne;Y++){let ut=s.HEAPU32[L++],Sr=Y===ne-1?void 0:s.HEAPU32[L]-ut;C.push(s.UTF8ToString(ut,Sr))}ee.push([M,re,C,"cpu"])}else if(at==="gpu-buffer"&&ne>0){let C=s.jsepGetBuffer;if(!C)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let L=C(k),Y=Ke(st,ne);if(Y===void 0||!Me(M))throw new Error(`Unsupported data type: ${M}`);le=!0,ee.push([M,re,{gpuBuffer:L,download:s.jsepCreateDownloader(L,Y,M),dispose:()=>{s._OrtReleaseTensor(te)}},"gpu-buffer"])}else{let C=tr(M),L=new C(ne);new Uint8Array(L.buffer,L.byteOffset,L.byteLength).set(s.HEAPU8.subarray(k,k+L.byteLength)),ee.push([M,re,L,"cpu"])}}finally{s.stackRestore(ot),M==="string"&&k&&s._free(k),le||s._OrtReleaseTensor(te)}}return d&&!c&&(s._OrtClearBoundOutputs(d.handle),J.set(t,[a,u,l,d,c,!1])),ee}finally{s.stackRestore(B),y.forEach(_=>s._OrtReleaseTensor(_)),b.forEach(_=>s._OrtReleaseTensor(_)),A.forEach(_=>s._free(_)),S!==0&&s._OrtReleaseRunOptions(S),O.forEach(_=>s._free(_))}},Be=t=>{let e=v(),r=J.get(t);if(!r)throw new Error("invalid session id");let o=r[0],n=e._OrtEndProfiling(o);n===0&&T("Can't get an profile file name."),e._OrtFree(n)},Ce=t=>{let e=[];for(let r of t){let o=r[2];!Array.isArray(o)&&"buffer"in o&&e.push(o.buffer)}return e}});var V,R,fe,Re,_e,De,et,tt,X,K,Gr,sr,ir,ar,ur,fr,cr,dr,rt=w(()=>{"use strict";z();Ye();H();se();V=()=>!!E.wasm.proxy&&typeof document<"u",fe=!1,Re=!1,_e=!1,tt=new Map,X=(t,e)=>{let r=tt.get(t);r?r.push(e):tt.set(t,[e])},K=()=>{if(fe||!Re||_e||!R)throw new Error("worker not ready")},Gr=t=>{switch(t.data.type){case"init-wasm":fe=!1,t.data.err?(_e=!0,et[1](t.data.err)):(Re=!0,et[0]()),De&&(URL.revokeObjectURL(De),De=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=tt.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}default:}},sr=async()=>{if(!Re){if(fe)throw new Error("multiple calls to 'initWasm()' detected.");if(_e)throw new Error("previous call to 'initWasm()' failed.");if(fe=!0,V())return new Promise((t,e)=>{R?.terminate(),Yt().then(([r,o])=>{try{R=o,R.onerror=i=>e(i),R.onmessage=Gr,et=[t,e];let n={type:"init-wasm",in:E};R.postMessage(n),De=r}catch(n){e(n)}},e)});try{await Ae(E.wasm),await Oe(E),Re=!0}catch(t){throw _e=!0,t}finally{fe=!1}}},ir=async t=>{if(V())return K(),new Promise((e,r)=>{X("init-ep",[e,r]);let o={type:"init-ep",in:{epName:t,env:E}};R.postMessage(o)});await ve(E,t)},ar=async t=>V()?(K(),new Promise((e,r)=>{X("copy-from",[e,r]);let o={type:"copy-from",in:{buffer:t}};R.postMessage(o,[t.buffer])})):ie(t),ur=async(t,e)=>{if(V()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return K(),new Promise((r,o)=>{X("create",[r,o]);let n={type:"create",in:{model:t,options:{...e}}},i=[];t instanceof Uint8Array&&i.push(t.buffer),R.postMessage(n,i)})}else return xe(t,e)},fr=async t=>{if(V())return K(),new Promise((e,r)=>{X("release",[e,r]);let o={type:"release",in:t};R.postMessage(o)});Ie(t)},cr=async(t,e,r,o,n,i)=>{if(V()){if(r.some(s=>s[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(n.some(s=>s))throw new Error("pre-allocated output tensor is not supported for proxy.");return K(),new Promise((s,f)=>{X("run",[s,f]);let a=r,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:a,outputIndices:o,options:i}};R.postMessage(u,Ce(a))})}else return Pe(t,e,r,o,n,i)},dr=async t=>{if(V())return K(),new Promise((e,r)=>{X("end-profiling",[e,r]);let o={type:"end-profiling",in:t};R.postMessage(o)});Be(t)}});var lr,zr,ke,pr=w(()=>{"use strict";z();rt();Qe();Te();Ze();lr=(t,e)=>{switch(t.location){case"cpu":return[t.type,t.dims,t.data,"cpu"];case"gpu-buffer":return[t.type,t.dims,{gpuBuffer:t.gpuBuffer},"gpu-buffer"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},zr=t=>{switch(t[3]){case"cpu":return new I(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!Me(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:r,download:o,dispose:n}=t[2];return I.fromGpuBuffer(r,{dataType:e,dims:t[1],download:o,dispose:n})}default:throw new Error(`invalid data location: ${t[3]}`)}},ke=class{async fetchModelAndCopyToWasmMemory(e){return ar(await ue(e))}async loadModel(e,r){F();let o;typeof e=="string"?!1?o=await ue(e):o=await this.fetchModelAndCopyToWasmMemory(e):o=e,[this.sessionId,this.inputNames,this.outputNames]=await ur(o,r),N()}async dispose(){return fr(this.sessionId)}async run(e,r,o){F();let n=[],i=[];Object.entries(e).forEach(c=>{let p=c[0],m=c[1],h=this.inputNames.indexOf(p);if(h===-1)throw new Error(`invalid input '${p}'`);n.push(m),i.push(h)});let s=[],f=[];Object.entries(r).forEach(c=>{let p=c[0],m=c[1],h=this.outputNames.indexOf(p);if(h===-1)throw new Error(`invalid output '${p}'`);s.push(m),f.push(h)});let a=n.map((c,p)=>lr(c,()=>`input "${this.inputNames[i[p]]}"`)),u=s.map((c,p)=>c?lr(c,()=>`output "${this.outputNames[f[p]]}"`):null),l=await cr(this.sessionId,i,a,f,u,o),d={};for(let c=0;c<l.length;c++)d[this.outputNames[f[c]]]=s[c]??zr(l[c]);return N(),d}startProfiling(){}endProfiling(){dr(this.sessionId)}}});var Hr,Fe,mr=w(()=>{"use strict";z();rt();pr();se();Hr=()=>{if((typeof E.wasm.initTimeout!="number"||E.wasm.initTimeout<0)&&(E.wasm.initTimeout=0),E.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 E.wasm.proxy!="boolean"&&(E.wasm.proxy=!1),typeof E.wasm.trace!="boolean"&&(E.wasm.trace=!1),typeof E.wasm.numThreads!="number"||!Number.isInteger(E.wasm.numThreads)||E.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)E.wasm.numThreads=1;else{let t=typeof navigator>"u"?We("node:os").cpus().length:navigator.hardwareConcurrency;E.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}E.wasm.wasmPaths===void 0&&D&&D.indexOf("blob:")!==0&&(E.wasm.wasmPaths=D.substring(0,D.lastIndexOf("/")+1))},Fe=class{async init(e){Hr(),await sr(),await ir(e)}async createInferenceSessionHandler(e,r){let o=new ke;return await o.loadModel(e,r),Promise.resolve(o)}}});var hr={};me(hr,{wasmBackend:()=>jr});var jr,yr=w(()=>{"use strict";mr();jr=new Fe});var Yr={};me(Yr,{InferenceSession:()=>Ct,TRACE:()=>He,TRACE_FUNC_BEGIN:()=>F,TRACE_FUNC_END:()=>N,Tensor:()=>I,TrainingSession:()=>kt,default:()=>Vr,env:()=>E,registerBackend:()=>q});z();z();z();var Nt="1.20.0-dev.20240913-904b850b44";var Vr=Ve;{let t=(yr(),$e(hr)).wasmBackend;q("cpu",t,10),q("wasm",t,10)}Object.defineProperty(E.versions,"web",{value:Nt,enumerable:!0});return $e(Yr);})();
"use strict";var ort=(()=>{var Ne=Object.defineProperty;var Tr=Object.getOwnPropertyDescriptor;var Ar=Object.getOwnPropertyNames;var Or=Object.prototype.hasOwnProperty;var We=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var w=(t,e)=>()=>(t&&(e=t(t=0)),e);var me=(t,e)=>{for(var r in e)Ne(t,r,{get:e[r],enumerable:!0})},vr=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ar(e))!Or.call(t,n)&&n!==r&&Ne(t,n,{get:()=>e[n],enumerable:!(o=Tr(e,n))||o.enumerable});return t};var $e=t=>vr(Ne({},"__esModule",{value:!0}),t);var he,$,q,xr,ye,we=w(()=>{"use strict";he=new Map,$=[],q=(t,e,r)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let o=he.get(t);if(o===void 0)he.set(t,{backend:e,priority:r});else{if(o.priority>r)return;if(o.priority===r&&o.backend!==e)throw new Error(`cannot register backend "${t}" using priority ${r}`)}if(r>=0){let n=$.indexOf(t);n!==-1&&$.splice(n,1);for(let i=0;i<$.length;i++)if(he.get($[i]).priority<=r){$.splice(i,0,t);return}$.push(t)}return}throw new TypeError("not a valid backend")},xr=async t=>{let e=he.get(t);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let r=!!e.initPromise;try{return r||(e.initPromise=e.backend.init(t)),await e.initPromise,e.initialized=!0,e.backend}catch(o){return r||(e.error=`${o}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},ye=async t=>{let e=t.executionProviders||[],r=e.map(a=>typeof a=="string"?a:a.name),o=r.length===0?$:r,n,i=[],s=new Set;for(let a of o){let u=await xr(a);typeof u=="string"?i.push({name:a,err:u}):(n||(n=u),n===u&&s.add(a))}if(!n)throw new Error(`no available backend found. ERR: ${i.map(a=>`[${a.name}] ${a.err}`).join(", ")}`);for(let{name:a,err:u}of i)r.includes(a)&&console.warn(`removing requested execution provider "${a}" from session options because it is not available: ${u}`);let f=e.filter(a=>s.has(typeof a=="string"?a:a.name));return[n,new Proxy(t,{get:(a,u)=>u==="executionProviders"?f:Reflect.get(a,u)})]}});var ft=w(()=>{"use strict";we()});var ct,dt=w(()=>{"use strict";ct="1.20.0-dev.20240912-ae39c40e5b"});var lt,U,Ge=w(()=>{"use strict";dt();lt="warning",U={wasm:{},webgl:{},webgpu:{},versions:{common:ct},set logLevel(t){if(t!==void 0){if(typeof t!="string"||["verbose","info","warning","error","fatal"].indexOf(t)===-1)throw new Error(`Unsupported logging level: ${t}`);lt=t}},get logLevel(){return lt}};Object.defineProperty(U,"logLevel",{enumerable:!0})});var E,pt=w(()=>{"use strict";Ge();E=U});var mt,ht,yt=w(()=>{"use strict";mt=(t,e)=>{let r=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);r.width=t.dims[3],r.height=t.dims[2];let o=r.getContext("2d");if(o!=null){let n,i;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(n=t.dims[2],i=t.dims[3]):(n=t.dims[3],i=t.dims[2]);let s=e?.format!==void 0?e.format:"RGB",f=e?.norm,a,u;f===void 0||f.mean===void 0?a=[255,255,255,255]:typeof f.mean=="number"?a=[f.mean,f.mean,f.mean,f.mean]:(a=[f.mean[0],f.mean[1],f.mean[2],0],f.mean[3]!==void 0&&(a[3]=f.mean[3])),f===void 0||f.bias===void 0?u=[0,0,0,0]:typeof f.bias=="number"?u=[f.bias,f.bias,f.bias,f.bias]:(u=[f.bias[0],f.bias[1],f.bias[2],0],f.bias[3]!==void 0&&(u[3]=f.bias[3]));let l=i*n,d=0,c=l,p=l*2,m=-1;s==="RGBA"?(d=0,c=l,p=l*2,m=l*3):s==="RGB"?(d=0,c=l,p=l*2):s==="RBG"&&(d=0,p=l,c=l*2);for(let h=0;h<i;h++)for(let S=0;S<n;S++){let O=(t.data[d++]-u[0])*a[0],y=(t.data[c++]-u[1])*a[1],b=(t.data[p++]-u[2])*a[2],A=m===-1?255:(t.data[m++]-u[3])*a[3];o.fillStyle="rgba("+O+","+y+","+b+","+A+")",o.fillRect(S,h,1,1)}if("toDataURL"in r)return r.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},ht=(t,e)=>{let r=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),o;if(r!=null){let n,i,s;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(n=t.dims[2],i=t.dims[1],s=t.dims[3]):(n=t.dims[3],i=t.dims[2],s=t.dims[1]);let f=e!==void 0&&e.format!==void 0?e.format:"RGB",a=e?.norm,u,l;a===void 0||a.mean===void 0?u=[255,255,255,255]:typeof a.mean=="number"?u=[a.mean,a.mean,a.mean,a.mean]:(u=[a.mean[0],a.mean[1],a.mean[2],255],a.mean[3]!==void 0&&(u[3]=a.mean[3])),a===void 0||a.bias===void 0?l=[0,0,0,0]:typeof a.bias=="number"?l=[a.bias,a.bias,a.bias,a.bias]:(l=[a.bias[0],a.bias[1],a.bias[2],0],a.bias[3]!==void 0&&(l[3]=a.bias[3]));let d=i*n;if(e!==void 0&&(e.format!==void 0&&s===4&&e.format!=="RGBA"||s===3&&e.format!=="RGB"&&e.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let c=4,p=0,m=1,h=2,S=3,O=0,y=d,b=d*2,A=-1;f==="RGBA"?(O=0,y=d,b=d*2,A=d*3):f==="RGB"?(O=0,y=d,b=d*2):f==="RBG"&&(O=0,b=d,y=d*2),o=r.createImageData(n,i);for(let B=0;B<i*n;p+=c,m+=c,h+=c,S+=c,B++)o.data[p]=(t.data[O++]-l[0])*u[0],o.data[m]=(t.data[y++]-l[1])*u[1],o.data[h]=(t.data[b++]-l[2])*u[2],o.data[S]=A===-1?255:(t.data[A++]-l[3])*u[3]}else throw new Error("Can not access image data");return o}});var ze,wt,bt,gt,Et,St=w(()=>{"use strict";be();ze=(t,e)=>{if(t===void 0)throw new Error("Image buffer must be defined");if(e.height===void 0||e.width===void 0)throw new Error("Image height and width must be defined");if(e.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:r,width:o}=e,n=e.norm??{mean:255,bias:0},i,s;typeof n.mean=="number"?i=[n.mean,n.mean,n.mean,n.mean]:i=[n.mean[0],n.mean[1],n.mean[2],n.mean[3]??255],typeof n.bias=="number"?s=[n.bias,n.bias,n.bias,n.bias]:s=[n.bias[0],n.bias[1],n.bias[2],n.bias[3]??0];let f=e.format!==void 0?e.format:"RGBA",a=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",u=r*o,l=a==="RGBA"?new Float32Array(u*4):new Float32Array(u*3),d=4,c=0,p=1,m=2,h=3,S=0,O=u,y=u*2,b=-1;f==="RGB"&&(d=3,c=0,p=1,m=2,h=-1),a==="RGBA"?b=u*3:a==="RBG"?(S=0,y=u,O=u*2):a==="BGR"&&(y=0,O=u,S=u*2);for(let B=0;B<u;B++,c+=d,m+=d,p+=d,h+=d)l[S++]=(t[c]+s[0])/i[0],l[O++]=(t[p]+s[1])/i[1],l[y++]=(t[m]+s[2])/i[2],b!==-1&&h!==-1&&(l[b++]=(t[h]+s[3])/i[3]);return a==="RGBA"?new P("float32",l,[1,4,r,o]):new P("float32",l,[1,3,r,o])},wt=async(t,e)=>{let r=typeof HTMLImageElement<"u"&&t instanceof HTMLImageElement,o=typeof ImageData<"u"&&t instanceof ImageData,n=typeof ImageBitmap<"u"&&t instanceof ImageBitmap,i=typeof t=="string",s,f=e??{},a=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},u=l=>l instanceof HTMLCanvasElement||l instanceof OffscreenCanvas?l.getContext("2d"):null;if(r){let l=a();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,p=t.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(c=e.resizedHeight,p=e.resizedWidth),e!==void 0){if(f=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");f.tensorFormat="RGBA",f.height=c,f.width=p}else f.tensorFormat="RGBA",f.height=c,f.width=p;d.drawImage(t,0,0),s=d.getImageData(0,0,p,c).data}else throw new Error("Can not access image data")}else if(o){let l,d;if(e!==void 0&&e.resizedWidth!==void 0&&e.resizedHeight!==void 0?(l=e.resizedHeight,d=e.resizedWidth):(l=t.height,d=t.width),e!==void 0&&(f=e),f.format="RGBA",f.height=l,f.width=d,e!==void 0){let c=a();c.width=d,c.height=l;let p=u(c);if(p!=null)p.putImageData(t,0,0),s=p.getImageData(0,0,d,l).data;else throw new Error("Can not access image data")}else s=t.data}else if(n){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let l=a();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,p=t.width;return d.drawImage(t,0,0,p,c),s=d.getImageData(0,0,p,c).data,f.height=c,f.width=p,ze(s,f)}else throw new Error("Can not access image data")}else{if(i)return new Promise((l,d)=>{let c=a(),p=u(c);if(!t||!p)return d();let m=new Image;m.crossOrigin="Anonymous",m.src=t,m.onload=()=>{c.width=m.width,c.height=m.height,p.drawImage(m,0,0,c.width,c.height);let h=p.getImageData(0,0,c.width,c.height);f.height=c.height,f.width=c.width,l(ze(h.data,f))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return ze(s,f);throw new Error("Input data provided is not supported - aborted tensor creation")},bt=(t,e)=>{let{width:r,height:o,download:n,dispose:i}=e,s=[1,o,r,4];return new P({location:"texture",type:"float32",texture:t,dims:s,download:n,dispose:i})},gt=(t,e)=>{let{dataType:r,dims:o,download:n,dispose:i}=e;return new P({location:"gpu-buffer",type:r??"float32",gpuBuffer:t,dims:o,download:n,dispose:i})},Et=(t,e,r)=>new P({location:"cpu-pinned",type:t,data:e,dims:r??[e.length]})});var G,oe,Tt,At,Ot=w(()=>{"use strict";G=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),oe=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Tt=!1,At=()=>{if(!Tt){Tt=!0;let t=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,r=typeof Float16Array<"u"&&Float16Array.from;t&&(G.set("int64",BigInt64Array),oe.set(BigInt64Array,"int64")),e&&(G.set("uint64",BigUint64Array),oe.set(BigUint64Array,"uint64")),r?(G.set("float16",Float16Array),oe.set(Float16Array,"float16")):G.set("float16",Uint16Array)}}});var vt,xt,It=w(()=>{"use strict";be();vt=t=>{let e=1;for(let r=0;r<t.length;r++){let o=t[r];if(typeof o!="number"||!Number.isSafeInteger(o))throw new TypeError(`dims[${r}] must be an integer, got: ${o}`);if(o<0)throw new RangeError(`dims[${r}] must be a non-negative integer, got: ${o}`);e*=o}return e},xt=(t,e)=>{switch(t.location){case"cpu":return new P(t.type,t.data,e);case"cpu-pinned":return new P({location:"cpu-pinned",data:t.data,type:t.type,dims:e});case"texture":return new P({location:"texture",texture:t.texture,type:t.type,dims:e});case"gpu-buffer":return new P({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${t.location} is not supported`)}}});var P,be=w(()=>{"use strict";yt();St();Ot();It();P=class{constructor(e,r,o){At();let n,i;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,n=e.type,i=e.dims,e.location){case"cpu-pinned":{let f=G.get(n);if(!f)throw new TypeError(`unsupported type "${n}" to create tensor from pinned buffer`);if(!(e.data instanceof f))throw new TypeError(`buffer should be of type ${f.name}`);this.cpuData=e.data;break}case"texture":{if(n!=="float32")throw new TypeError(`unsupported type "${n}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(n!=="float32"&&n!=="float16"&&n!=="int32"&&n!=="int64"&&n!=="uint32"&&n!=="uint8"&&n!=="bool"&&n!=="uint4"&&n!=="int4")throw new TypeError(`unsupported type "${n}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let f,a;if(typeof e=="string")if(n=e,a=o,e==="string"){if(!Array.isArray(r))throw new TypeError("A string tensor's data must be a string array.");f=r}else{let u=G.get(e);if(u===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(r)){if(e==="float16"&&u===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${u.name} as data.`);e==="uint64"||e==="int64"?f=u.from(r,BigInt):f=u.from(r)}else if(r instanceof u)f=r;else if(r instanceof Uint8ClampedArray)if(e==="uint8")f=Uint8Array.from(r);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else throw new TypeError(`A ${n} tensor's data must be type of ${u}`)}else if(a=r,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let u=typeof e[0];if(u==="string")n="string",f=e;else if(u==="boolean")n="bool",f=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${u}.`)}else if(e instanceof Uint8ClampedArray)n="uint8",f=Uint8Array.from(e);else{let u=oe.get(e.constructor);if(u===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);n=u,f=e}if(a===void 0)a=[f.length];else if(!Array.isArray(a))throw new TypeError("A tensor's dims must be a number array");i=a,this.cpuData=f,this.dataLocation="cpu"}let s=vt(i);if(this.cpuData&&s!==this.cpuData.length&&!((n==="uint4"||n==="int4")&&Math.ceil(s/2)===this.cpuData.length))throw new Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=n,this.dims=i,this.size=s}static async fromImage(e,r){return wt(e,r)}static fromTexture(e,r){return bt(e,r)}static fromGpuBuffer(e,r){return gt(e,r)}static fromPinnedBuffer(e,r,o){return Et(e,r,o)}toDataURL(e){return mt(this,e)}toImageData(e){return ht(this,e)}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}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":{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 r=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=r,e&&this.disposer&&(this.disposer(),this.disposer=void 0),r}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.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return xt(this,e)}}});var I,ge=w(()=>{"use strict";be();I=P});var He,Pt,F,N,je=w(()=>{"use strict";Ge();He=(t,e)=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||console.timeStamp(`${t}::ORT::${e}`)},Pt=(t,e)=>{let r=new Error().stack?.split(/\r\n|\r|\n/g)||[],o=!1;for(let n=0;n<r.length;n++){if(o&&!r[n].includes("TRACE_FUNC")){let i=`FUNC_${t}::${r[n].trim().split(" ")[1]}`;e&&(i+=`::${e}`),He("CPU",i);return}r[n].includes("TRACE_FUNC")&&(o=!0)}},F=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Pt("BEGIN",t)},N=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Pt("END",t)}});var Ee,Bt=w(()=>{"use strict";we();ge();je();Ee=class t{constructor(e){this.handler=e}async run(e,r,o){F();let n={},i={};if(typeof e!="object"||e===null||e instanceof I||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof I)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(r.length===0)throw new TypeError("'fetches' cannot be an empty array.");s=!1;for(let u of r){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);n[u]=null}if(typeof o=="object"&&o!==null)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,l=Object.getOwnPropertyNames(r);for(let d of this.outputNames)if(l.indexOf(d)!==-1){let c=r[d];(c===null||c instanceof I)&&(u=!0,s=!1,n[d]=c)}if(u){if(typeof o=="object"&&o!==null)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else i=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of this.inputNames)if(typeof e[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(s)for(let u of this.outputNames)n[u]=null;let f=await this.handler.run(e,n,i),a={};for(let u in f)if(Object.hasOwnProperty.call(f,u)){let l=f[u];l instanceof I?a[u]=l:a[u]=new I(l.type,l.data,l.dims)}return N(),a}async release(){return this.handler.dispose()}static async create(e,r,o,n){F();let i,s={};if(typeof e=="string"){if(i=e,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(i=e,typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){let l=e,d=0,c=e.byteLength;if(typeof r=="object"&&r!==null)s=r;else if(typeof r=="number"){if(d=r,!Number.isSafeInteger(d))throw new RangeError("'byteOffset' must be an integer.");if(d<0||d>=l.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${l.byteLength}).`);if(c=e.byteLength-d,typeof o=="number"){if(c=o,!Number.isSafeInteger(c))throw new RangeError("'byteLength' must be an integer.");if(c<=0||d+c>l.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${l.byteLength-d}].`);if(typeof n=="object"&&n!==null)s=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(typeof o<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof r<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(l,d,c)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[f,a]=await ye(s),u=await f.createInferenceSessionHandler(i,a);return N(),new t(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var Ct,Lt=w(()=>{"use strict";Bt();Ct=Ee});var Ut=w(()=>{"use strict"});var Mt=w(()=>{"use strict"});var Dt=w(()=>{"use strict"});var Rt=w(()=>{"use strict"});var Ir,Se,_t=w(()=>{"use strict";we();ge();Ir="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",Se=class t{constructor(e,r,o){this.handler=e,this.hasOptimizerModel=r,this.hasEvalModel=o}get trainingInputNames(){return this.handler.inputNames}get trainingOutputNames(){return this.handler.outputNames}get evalInputNames(){if(this.hasEvalModel)return this.handler.evalInputNames;throw new Error("This training session has no evalModel loaded.")}get evalOutputNames(){if(this.hasEvalModel)return this.handler.evalOutputNames;throw new Error("This training session has no evalModel loaded.")}static async create(e,r){let o=e.evalModel||"",n=e.optimizerModel||"",i=r||{},[s,f]=await ye(i);if(s.createTrainingSessionHandler){let a=await s.createTrainingSessionHandler(e.checkpointState,e.trainModel,o,n,f);return new t(a,!!e.optimizerModel,!!e.evalModel)}else throw new Error(Ir)}typeNarrowingForRunStep(e,r,o,n,i){let s={},f={};if(typeof o!="object"||o===null||o instanceof I||Array.isArray(o))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if(typeof n=="object"){if(n===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(n instanceof I)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(n)){if(n.length===0)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(let u of n){if(typeof u!="string")throw new TypeError("'fetches' must be a string array or an object.");if(r.indexOf(u)===-1)throw new RangeError(`'fetches' contains invalid output name: ${u}.`);s[u]=null}if(typeof i=="object"&&i!==null)f=i;else if(typeof i<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,l=Object.getOwnPropertyNames(n);for(let d of r)if(l.indexOf(d)!==-1){let c=n[d];(c===null||c instanceof I)&&(u=!0,a=!1,s[d]=c)}if(u){if(typeof i=="object"&&i!==null)f=i;else if(typeof i<"u")throw new TypeError("'options' must be an object.")}else f=n}}else if(typeof n<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let u of e)if(typeof o[u]>"u")throw new Error(`input '${u}' is missing in 'feeds'.`);if(a)for(let u of r)s[u]=null;return[s,f]}convertHandlerReturnTypeToMapOfTensors(e){let r={};for(let o in e)if(Object.hasOwnProperty.call(e,o)){let n=e[o];n instanceof I?r[o]=n:r[o]=new I(n.type,n.data,n.dims)}return r}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(e,r,o){let[n,i]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,e,r,o),s=await this.handler.runTrainStep(e,n,i);return this.convertHandlerReturnTypeToMapOfTensors(s)}async runOptimizerStep(e){if(this.hasOptimizerModel)await this.handler.runOptimizerStep(e||{});else throw new Error("This TrainingSession has no OptimizerModel loaded.")}async runEvalStep(e,r,o){if(this.hasEvalModel){let[n,i]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,e,r,o),s=await this.handler.runEvalStep(e,n,i);return this.convertHandlerReturnTypeToMapOfTensors(s)}else throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(e=!0){return this.handler.getParametersSize(e)}async loadParametersBuffer(e,r=!0){let o=await this.getParametersSize(r);if(e.length!==4*o)throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");return this.handler.loadParametersBuffer(e,r)}async getContiguousParameters(e=!0){return this.handler.getContiguousParameters(e)}async release(){return this.handler.dispose()}}});var kt,Ft=w(()=>{"use strict";_t();kt=Se});var Ve={};me(Ve,{InferenceSession:()=>Ct,TRACE:()=>He,TRACE_FUNC_BEGIN:()=>F,TRACE_FUNC_END:()=>N,Tensor:()=>I,TrainingSession:()=>kt,env:()=>E,registerBackend:()=>q});var z=w(()=>{"use strict";ft();pt();Lt();ge();Ut();Mt();je();Dt();Rt();Ft()});var Te=w(()=>{"use strict"});var Gt={};me(Gt,{default:()=>Pr});var Wt,$t,Pr,zt=w(()=>{"use strict";Ye();H();se();Wt="ort-wasm-proxy-worker",$t=globalThis.self?.name===Wt;$t&&(self.onmessage=t=>{let{type:e,in:r}=t.data;try{switch(e){case"init-wasm":Ae(r.wasm).then(()=>{Oe(r).then(()=>{postMessage({type:e})},o=>{postMessage({type:e,err:o})})},o=>{postMessage({type:e,err:o})});break;case"init-ep":{let{epName:o,env:n}=r;ve(n,o).then(()=>{postMessage({type:e})},i=>{postMessage({type:e,err:i})});break}case"copy-from":{let{buffer:o}=r,n=ie(o);postMessage({type:e,out:n});break}case"create":{let{model:o,options:n}=r;xe(o,n).then(i=>{postMessage({type:e,out:i})},i=>{postMessage({type:e,err:i})});break}case"release":Ie(r),postMessage({type:e});break;case"run":{let{sessionId:o,inputIndices:n,inputs:i,outputIndices:s,options:f}=r;Pe(o,n,i,s,new Array(s.length).fill(null),f).then(a=>{a.some(u=>u[3]!=="cpu")?postMessage({type:e,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:e,out:a},Ce([...i,...a]))},a=>{postMessage({type:e,err:a})});break}case"end-profiling":Be(r),postMessage({type:e});break;default:}}catch(o){postMessage({type:e,err:o})}});Pr=$t?null:t=>new Worker(t??D,{type:"classic",name:Wt})});var D,Br,jt,Cr,Lr,Vt,Ur,Ht,Yt,qt,se=w(()=>{"use strict";Te();D=!1?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,Br=!1||typeof location>"u"?void 0:location.origin,jt=(t,e)=>{try{let r=e??D;return(r?new URL(t,r):new URL(t)).origin===Br}catch{return!1}},Cr=(t,e)=>{let r=e??D;try{return(r?new URL(t,r):new URL(t)).href}catch{return}},Lr=(t,e)=>`${e??"./"}${t}`,Vt=async t=>{let r=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(r)},Ur=async t=>(await import(/*webpackIgnore:true*/t)).default,Ht=(zt(),$e(Gt)).default,Yt=async()=>{if(!D)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(jt(D))return[void 0,Ht()];let t=await Vt(D);return[t,Ht(t)]},qt=async(t,e,r)=>{{let o="ort-wasm-simd-threaded.mjs",n=t??Cr(o,e),i=!!1&&r&&n&&!jt(n,e),s=i?await Vt(n):n??Lr(o,e);return[i?s:void 0,await Ur(s)]}}});var qe,Je,Le,Jt,Mr,Dr,Ae,v,H=w(()=>{"use strict";se();Je=!1,Le=!1,Jt=!1,Mr=()=>{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}},Dr=()=>{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}},Ae=async t=>{if(Je)return Promise.resolve();if(Le)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Jt)throw new Error("previous call to 'initializeWebAssembly()' failed.");Le=!0;let e=t.initTimeout,r=t.numThreads;if(!Dr())throw new Error("WebAssembly SIMD is not supported in the current environment.");let o=Mr();r>1&&!o&&(typeof self<"u"&&!self.crossOriginIsolated&&console.warn("env.wasm.numThreads is set to "+r+", 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."),t.numThreads=r=1);let n=t.wasmPaths,i=typeof n=="string"?n:void 0,s=n?.mjs,f=s?.href??s,a=n?.wasm,u=a?.href??a,l=t.wasmBinary,[d,c]=await qt(f,i,r>1),p=!1,m=[];if(e>0&&m.push(new Promise(h=>{setTimeout(()=>{p=!0,h()},e)})),m.push(new Promise((h,S)=>{let O={numThreads:r};l?O.wasmBinary=l:(u||i)&&(O.locateFile=(y,b)=>u??(i??b)+y),c(O).then(y=>{Le=!1,Je=!0,qe=y,h(),d&&URL.revokeObjectURL(d)},y=>{Le=!1,Jt=!0,S(y)})})),await Promise.race(m),p)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},v=()=>{if(Je&&qe)return qe;throw new Error("WebAssembly is not initialized yet.")}});var x,ae,T,Ue=w(()=>{"use strict";H();x=(t,e)=>{let r=v(),o=r.lengthBytesUTF8(t)+1,n=r._malloc(o);return r.stringToUTF8(t,n,o),e.push(n),n},ae=(t,e,r,o)=>{if(typeof t=="object"&&t!==null){if(r.has(t))throw new Error("Circular reference in options");r.add(t)}Object.entries(t).forEach(([n,i])=>{let s=e?e+n:n;if(typeof i=="object")ae(i,s+".",r,o);else if(typeof i=="string"||typeof i=="number")o(s,i.toString());else if(typeof i=="boolean")o(s,i?"1":"0");else throw new Error(`Can't handle extra config type: ${typeof i}`)})},T=t=>{let e=v(),r=e.stackSave();try{let o=e.stackAlloc(8);e._OrtGetLastError(o,o+4);let n=e.HEAP32[o/4],i=e.HEAPU32[o/4+1],s=i?e.UTF8ToString(i):"";throw new Error(`${t} ERROR_CODE: ${n}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(r)}}});var Xt,Kt=w(()=>{"use strict";H();Ue();Xt=t=>{let e=v(),r=0,o=[],n=t||{};try{if(t?.logSeverityLevel===void 0)n.logSeverityLevel=2;else if(typeof t.logSeverityLevel!="number"||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(t?.logVerbosityLevel===void 0)n.logVerbosityLevel=0;else if(typeof t.logVerbosityLevel!="number"||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);t?.terminate===void 0&&(n.terminate=!1);let i=0;return t?.tag!==void 0&&(i=x(t.tag,o)),r=e._OrtCreateRunOptions(n.logSeverityLevel,n.logVerbosityLevel,!!n.terminate,i),r===0&&T("Can't create run options."),t?.extra!==void 0&&ae(t.extra,"",new WeakSet,(s,f)=>{let a=x(s,o),u=x(f,o);e._OrtAddRunConfigEntry(r,a,u)!==0&&T(`Can't set a run config entry: ${s} - ${f}.`)}),[r,o]}catch(i){throw r!==0&&e._OrtReleaseRunOptions(r),o.forEach(s=>e._free(s)),i}}});var Rr,_r,kr,Fr,Qt,Zt=w(()=>{"use strict";H();Ue();Rr=t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${t}`)}},_r=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},kr=t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});let e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1"),t.executionProviders&&t.executionProviders.some(r=>(typeof r=="string"?r:r.name)==="webgpu")&&(t.enableMemPattern=!1)},Fr=(t,e,r)=>{for(let o of e){let n=typeof o=="string"?o:o.name;switch(n){case"webnn":if(n="WEBNN",typeof o!="string"){let f=o?.deviceType;if(f){let a=x("deviceType",r),u=x(f,r);v()._OrtAddSessionConfigEntry(t,a,u)!==0&&T(`Can't set a session config entry: 'deviceType' - ${f}.`)}}break;case"webgpu":if(n="JS",typeof o!="string"){let s=o;if(s?.preferredLayout){if(s.preferredLayout!=="NCHW"&&s.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${s.preferredLayout}`);let f=x("preferredLayout",r),a=x(s.preferredLayout,r);v()._OrtAddSessionConfigEntry(t,f,a)!==0&&T(`Can't set a session config entry: 'preferredLayout' - ${s.preferredLayout}.`)}}break;case"wasm":case"cpu":continue;default:throw new Error(`not supported execution provider: ${n}`)}let i=x(n,r);v()._OrtAppendExecutionProvider(t,i)!==0&&T(`Can't append execution provider: ${n}.`)}},Qt=t=>{let e=v(),r=0,o=[],n=t||{};kr(n);try{let i=Rr(n.graphOptimizationLevel??"all"),s=_r(n.executionMode??"sequential"),f=typeof n.logId=="string"?x(n.logId,o):0,a=n.logSeverityLevel??2;if(!Number.isInteger(a)||a<0||a>4)throw new Error(`log serverity level is not valid: ${a}`);let u=n.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let l=typeof n.optimizedModelFilePath=="string"?x(n.optimizedModelFilePath,o):0;if(r=e._OrtCreateSessionOptions(i,!!n.enableCpuMemArena,!!n.enableMemPattern,s,!!n.enableProfiling,0,f,a,u,l),r===0&&T("Can't create session options."),n.executionProviders&&Fr(r,n.executionProviders,o),n.enableGraphCapture!==void 0){if(typeof n.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${n.enableGraphCapture}`);let d=x("enableGraphCapture",o),c=x(n.enableGraphCapture.toString(),o);e._OrtAddSessionConfigEntry(r,d,c)!==0&&T(`Can't set a session config entry: 'enableGraphCapture' - ${n.enableGraphCapture}.`)}if(n.freeDimensionOverrides)for(let[d,c]of Object.entries(n.freeDimensionOverrides)){if(typeof d!="string")throw new Error(`free dimension override name must be a string: ${d}`);if(typeof c!="number"||!Number.isInteger(c)||c<0)throw new Error(`free dimension override value must be a non-negative integer: ${c}`);let p=x(d,o);e._OrtAddFreeDimensionOverride(r,p,c)!==0&&T(`Can't set a free dimension override: ${d} - ${c}.`)}return n.extra!==void 0&&ae(n.extra,"",new WeakSet,(d,c)=>{let p=x(d,o),m=x(c,o);e._OrtAddSessionConfigEntry(r,p,m)!==0&&T(`Can't set a session config entry: ${d} - ${c}.`)}),[r,o]}catch(i){throw r!==0&&e._OrtReleaseSessionOptions(r),o.forEach(s=>e._free(s)),i}}});var Xe,er,Ke,tr,rr,Me,nr,Qe=w(()=>{"use strict";Xe=t=>{switch(t){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: ${t}`)}},er=t=>{switch(t){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: ${t}`)}},Ke=(t,e)=>{let r=[-1,4,1,1,2,2,4,8,-1,1,2,8,4,8,-1,-1,-1,-1,-1,-1,-1,.5,.5][t],o=typeof e=="number"?e:e.reduce((n,i)=>n*i,1);return r>0?Math.ceil(o*r):void 0},tr=t=>{switch(t){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: ${t}`)}},rr=t=>{switch(t){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: ${t}`)}},Me=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",nr=t=>{switch(t){case"none":return 0;case"cpu":return 1;case"cpu-pinned":return 2;case"texture":return 3;case"gpu-buffer":return 4;default:throw new Error(`unsupported data location: ${t}`)}}});var ue,Ze=w(()=>{"use strict";Te();ue=async t=>{if(typeof t=="string")if(!1)try{let{readFile:e}=We("node:fs/promises");return new Uint8Array(await e(t))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:r}=We("node:fs"),o=r(t),n=[];for await(let i of o)n.push(i);return new Uint8Array(Buffer.concat(n))}throw e}else{let e=await fetch(t);if(!e.ok)throw new Error(`failed to load external data file: ${t}`);let r=e.headers.get("Content-Length"),o=r?parseInt(r,10):0;if(o<1073741824)return new Uint8Array(await e.arrayBuffer());{if(!e.body)throw new Error(`failed to load external data file: ${t}, no response body.`);let n=e.body.getReader(),i;try{i=new ArrayBuffer(o)}catch(f){if(f instanceof RangeError){let a=Math.ceil(o/65536);i=new WebAssembly.Memory({initial:a,maximum:a}).buffer}else throw f}let s=0;for(;;){let{done:f,value:a}=await n.read();if(f)break;let u=a.byteLength;new Uint8Array(i,s,u).set(a),s+=u}return new Uint8Array(i,0,o)}}else return t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t instanceof Uint8Array?t:new Uint8Array(t)}});var Nr,Oe,ve,J,Wr,ie,xe,Ie,or,Pe,Be,Ce,Ye=w(()=>{"use strict";Kt();Zt();Qe();H();Ue();Ze();Nr=(t,e)=>{v()._OrtInit(t,e)!==0&&T("Can't initialize onnxruntime.")},Oe=async t=>{Nr(t.wasm.numThreads,rr(t.logLevel))},ve=async(t,e)=>{},J=new Map,Wr=t=>{let e=v(),r=e.stackSave();try{let o=e.stackAlloc(8);return e._OrtGetInputOutputCount(t,o,o+4)!==0&&T("Can't get session input/output count."),[e.HEAP32[o/4],e.HEAP32[o/4+1]]}finally{e.stackRestore(r)}},ie=t=>{let e=v(),r=e._malloc(t.byteLength);if(r===0)throw new Error(`Can't create a session. failed to allocate a buffer of size ${t.byteLength}.`);return e.HEAPU8.set(t,r),[r,t.byteLength]},xe=async(t,e)=>{let r,o,n=v();Array.isArray(t)?[r,o]=t:t.buffer===n.HEAPU8.buffer?[r,o]=[t.byteOffset,t.byteLength]:[r,o]=ie(t);let i=0,s=0,f=0,a=[],u=[],l=[];try{if([s,a]=Qt(e),e?.externalData&&n.mountExternalData){let y=[];for(let b of e.externalData){let A=typeof b=="string"?b:b.path;y.push(ue(typeof b=="string"?b:b.data).then(B=>{n.mountExternalData(A,B)}))}await Promise.all(y)}for(let y of e?.executionProviders??[])if((typeof y=="string"?y:y.name)==="webnn"){if(n.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof y!="string"){let A=y,B=A?.context,Q=A?.gpuDevice,ce=A?.deviceType,Z=A?.numThreads,de=A?.powerPreference;B?n.currentContext=B:Q?n.currentContext=await navigator.ml.createContext(Q):n.currentContext=await navigator.ml.createContext({deviceType:ce,numThreads:Z,powerPreference:de})}else n.currentContext=await navigator.ml.createContext();break}i=await n._OrtCreateSession(r,o,s),i===0&&T("Can't create a session."),n.currentContext&&(n.currentContext=void 0);let[d,c]=Wr(i),p=!!e?.enableGraphCapture,m=[],h=[],S=[];for(let y=0;y<d;y++){let b=n._OrtGetInputName(i,y);b===0&&T("Can't get an input name."),u.push(b),m.push(n.UTF8ToString(b))}for(let y=0;y<c;y++){let b=n._OrtGetOutputName(i,y);b===0&&T("Can't get an output name."),l.push(b);let A=n.UTF8ToString(b);h.push(A)}let O=null;return J.set(i,[i,u,l,O,p,!1]),[i,m,h]}catch(d){throw u.forEach(c=>n._OrtFree(c)),l.forEach(c=>n._OrtFree(c)),f!==0&&n._OrtReleaseBinding(f),i!==0&&n._OrtReleaseSession(i),d}finally{n._free(r),s!==0&&n._OrtReleaseSessionOptions(s),a.forEach(d=>n._free(d)),n.unmountExternalData?.()}},Ie=t=>{let e=v(),r=J.get(t);if(!r)throw new Error(`cannot release session. invalid session id: ${t}`);let[o,n,i,s,f]=r;s&&(f&&e._OrtClearBoundOutputs(s.handle),e._OrtReleaseBinding(s.handle)),e.jsepOnReleaseSession?.(t),n.forEach(a=>e._OrtFree(a)),i.forEach(a=>e._OrtFree(a)),e._OrtReleaseSession(o),J.delete(t)},or=(t,e,r,o,n,i=!1)=>{if(!t){e.push(0);return}let s=v(),f=t[0],a=t[1],u=t[3],l,d;if(f==="string"&&u==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");if(i&&u!=="gpu-buffer")throw new Error(`External buffer must be provided for input/output index ${n} when enableGraphCapture is true.`);if(u==="gpu-buffer"){let m=t[2].gpuBuffer;d=Ke(Xe(f),a);let h=s.jsepRegisterBuffer;if(!h)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');l=h(o,n,m,d)}else{let m=t[2];if(Array.isArray(m)){d=4*m.length,l=s._malloc(d),r.push(l);let h=l/4;for(let S=0;S<m.length;S++){if(typeof m[S]!="string")throw new TypeError(`tensor data at index ${S} is not a string`);s.HEAPU32[h++]=x(m[S],r)}}else d=m.byteLength,l=s._malloc(d),r.push(l),s.HEAPU8.set(new Uint8Array(m.buffer,m.byteOffset,d),l)}let c=s.stackSave(),p=s.stackAlloc(4*a.length);try{let m=p/4;a.forEach(S=>s.HEAP32[m++]=S);let h=s._OrtCreateTensor(Xe(f),l,d,p,a.length,nr(u));h===0&&T(`Can't create tensor for input/output. session=${o}, index=${n}.`),e.push(h)}finally{s.stackRestore(c)}},Pe=async(t,e,r,o,n,i)=>{let s=v(),f=J.get(t);if(!f)throw new Error(`cannot run inference. invalid session id: ${t}`);let a=f[0],u=f[1],l=f[2],d=f[3],c=f[4],p=f[5],m=e.length,h=o.length,S=0,O=[],y=[],b=[],A=[],B=s.stackSave(),Q=s.stackAlloc(m*4),ce=s.stackAlloc(m*4),Z=s.stackAlloc(h*4),de=s.stackAlloc(h*4);try{[S,O]=Xt(i);for(let g=0;g<m;g++)or(r[g],y,A,t,e[g],c);for(let g=0;g<h;g++)or(n[g],b,A,t,m+o[g],c);let _=Q/4,wr=ce/4,br=Z/4,gr=de/4;for(let g=0;g<m;g++)s.HEAPU32[_++]=y[g],s.HEAPU32[wr++]=u[e[g]];for(let g=0;g<h;g++)s.HEAPU32[br++]=b[g],s.HEAPU32[gr++]=l[o[g]];s.jsepOnRunStart?.(a);let nt;nt=await s._OrtRun(a,ce,Q,m,de,h,Z,S),nt!==0&&T("failed to call OrtRun().");let ee=[];for(let g=0;g<h;g++){let te=s.HEAPU32[Z/4+g];if(te===b[g]){ee.push(n[g]);continue}let ot=s.stackSave(),W=s.stackAlloc(4*4),le=!1,M,k=0;try{s._OrtGetTensorData(te,W,W+4,W+8,W+12)!==0&&T(`Can't access output tensor data on index ${g}.`);let pe=W/4,st=s.HEAPU32[pe++];k=s.HEAPU32[pe++];let it=s.HEAPU32[pe++],Er=s.HEAPU32[pe++],re=[];for(let C=0;C<Er;C++)re.push(s.HEAPU32[it/4+C]);s._OrtFree(it);let ne=re.reduce((C,L)=>C*L,1);M=er(st);let at=d?.outputPreferredLocations[o[g]];if(M==="string"){if(at==="gpu-buffer")throw new Error("String tensor is not supported on GPU.");let C=[],L=k/4;for(let Y=0;Y<ne;Y++){let ut=s.HEAPU32[L++],Sr=Y===ne-1?void 0:s.HEAPU32[L]-ut;C.push(s.UTF8ToString(ut,Sr))}ee.push([M,re,C,"cpu"])}else if(at==="gpu-buffer"&&ne>0){let C=s.jsepGetBuffer;if(!C)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let L=C(k),Y=Ke(st,ne);if(Y===void 0||!Me(M))throw new Error(`Unsupported data type: ${M}`);le=!0,ee.push([M,re,{gpuBuffer:L,download:s.jsepCreateDownloader(L,Y,M),dispose:()=>{s._OrtReleaseTensor(te)}},"gpu-buffer"])}else{let C=tr(M),L=new C(ne);new Uint8Array(L.buffer,L.byteOffset,L.byteLength).set(s.HEAPU8.subarray(k,k+L.byteLength)),ee.push([M,re,L,"cpu"])}}finally{s.stackRestore(ot),M==="string"&&k&&s._free(k),le||s._OrtReleaseTensor(te)}}return d&&!c&&(s._OrtClearBoundOutputs(d.handle),J.set(t,[a,u,l,d,c,!1])),ee}finally{s.stackRestore(B),y.forEach(_=>s._OrtReleaseTensor(_)),b.forEach(_=>s._OrtReleaseTensor(_)),A.forEach(_=>s._free(_)),S!==0&&s._OrtReleaseRunOptions(S),O.forEach(_=>s._free(_))}},Be=t=>{let e=v(),r=J.get(t);if(!r)throw new Error("invalid session id");let o=r[0],n=e._OrtEndProfiling(o);n===0&&T("Can't get an profile file name."),e._OrtFree(n)},Ce=t=>{let e=[];for(let r of t){let o=r[2];!Array.isArray(o)&&"buffer"in o&&e.push(o.buffer)}return e}});var V,R,fe,Re,_e,De,et,tt,X,K,Gr,sr,ir,ar,ur,fr,cr,dr,rt=w(()=>{"use strict";z();Ye();H();se();V=()=>!!E.wasm.proxy&&typeof document<"u",fe=!1,Re=!1,_e=!1,tt=new Map,X=(t,e)=>{let r=tt.get(t);r?r.push(e):tt.set(t,[e])},K=()=>{if(fe||!Re||_e||!R)throw new Error("worker not ready")},Gr=t=>{switch(t.data.type){case"init-wasm":fe=!1,t.data.err?(_e=!0,et[1](t.data.err)):(Re=!0,et[0]()),De&&(URL.revokeObjectURL(De),De=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=tt.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}default:}},sr=async()=>{if(!Re){if(fe)throw new Error("multiple calls to 'initWasm()' detected.");if(_e)throw new Error("previous call to 'initWasm()' failed.");if(fe=!0,V())return new Promise((t,e)=>{R?.terminate(),Yt().then(([r,o])=>{try{R=o,R.onerror=i=>e(i),R.onmessage=Gr,et=[t,e];let n={type:"init-wasm",in:E};R.postMessage(n),De=r}catch(n){e(n)}},e)});try{await Ae(E.wasm),await Oe(E),Re=!0}catch(t){throw _e=!0,t}finally{fe=!1}}},ir=async t=>{if(V())return K(),new Promise((e,r)=>{X("init-ep",[e,r]);let o={type:"init-ep",in:{epName:t,env:E}};R.postMessage(o)});await ve(E,t)},ar=async t=>V()?(K(),new Promise((e,r)=>{X("copy-from",[e,r]);let o={type:"copy-from",in:{buffer:t}};R.postMessage(o,[t.buffer])})):ie(t),ur=async(t,e)=>{if(V()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return K(),new Promise((r,o)=>{X("create",[r,o]);let n={type:"create",in:{model:t,options:{...e}}},i=[];t instanceof Uint8Array&&i.push(t.buffer),R.postMessage(n,i)})}else return xe(t,e)},fr=async t=>{if(V())return K(),new Promise((e,r)=>{X("release",[e,r]);let o={type:"release",in:t};R.postMessage(o)});Ie(t)},cr=async(t,e,r,o,n,i)=>{if(V()){if(r.some(s=>s[3]!=="cpu"))throw new Error("input tensor on GPU is not supported for proxy.");if(n.some(s=>s))throw new Error("pre-allocated output tensor is not supported for proxy.");return K(),new Promise((s,f)=>{X("run",[s,f]);let a=r,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:a,outputIndices:o,options:i}};R.postMessage(u,Ce(a))})}else return Pe(t,e,r,o,n,i)},dr=async t=>{if(V())return K(),new Promise((e,r)=>{X("end-profiling",[e,r]);let o={type:"end-profiling",in:t};R.postMessage(o)});Be(t)}});var lr,zr,ke,pr=w(()=>{"use strict";z();rt();Qe();Te();Ze();lr=(t,e)=>{switch(t.location){case"cpu":return[t.type,t.dims,t.data,"cpu"];case"gpu-buffer":return[t.type,t.dims,{gpuBuffer:t.gpuBuffer},"gpu-buffer"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},zr=t=>{switch(t[3]){case"cpu":return new I(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!Me(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:r,download:o,dispose:n}=t[2];return I.fromGpuBuffer(r,{dataType:e,dims:t[1],download:o,dispose:n})}default:throw new Error(`invalid data location: ${t[3]}`)}},ke=class{async fetchModelAndCopyToWasmMemory(e){return ar(await ue(e))}async loadModel(e,r){F();let o;typeof e=="string"?!1?o=await ue(e):o=await this.fetchModelAndCopyToWasmMemory(e):o=e,[this.sessionId,this.inputNames,this.outputNames]=await ur(o,r),N()}async dispose(){return fr(this.sessionId)}async run(e,r,o){F();let n=[],i=[];Object.entries(e).forEach(c=>{let p=c[0],m=c[1],h=this.inputNames.indexOf(p);if(h===-1)throw new Error(`invalid input '${p}'`);n.push(m),i.push(h)});let s=[],f=[];Object.entries(r).forEach(c=>{let p=c[0],m=c[1],h=this.outputNames.indexOf(p);if(h===-1)throw new Error(`invalid output '${p}'`);s.push(m),f.push(h)});let a=n.map((c,p)=>lr(c,()=>`input "${this.inputNames[i[p]]}"`)),u=s.map((c,p)=>c?lr(c,()=>`output "${this.outputNames[f[p]]}"`):null),l=await cr(this.sessionId,i,a,f,u,o),d={};for(let c=0;c<l.length;c++)d[this.outputNames[f[c]]]=s[c]??zr(l[c]);return N(),d}startProfiling(){}endProfiling(){dr(this.sessionId)}}});var Hr,Fe,mr=w(()=>{"use strict";z();rt();pr();se();Hr=()=>{if((typeof E.wasm.initTimeout!="number"||E.wasm.initTimeout<0)&&(E.wasm.initTimeout=0),E.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 E.wasm.proxy!="boolean"&&(E.wasm.proxy=!1),typeof E.wasm.trace!="boolean"&&(E.wasm.trace=!1),typeof E.wasm.numThreads!="number"||!Number.isInteger(E.wasm.numThreads)||E.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)E.wasm.numThreads=1;else{let t=typeof navigator>"u"?We("node:os").cpus().length:navigator.hardwareConcurrency;E.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}E.wasm.wasmPaths===void 0&&D&&D.indexOf("blob:")!==0&&(E.wasm.wasmPaths=D.substring(0,D.lastIndexOf("/")+1))},Fe=class{async init(e){Hr(),await sr(),await ir(e)}async createInferenceSessionHandler(e,r){let o=new ke;return await o.loadModel(e,r),Promise.resolve(o)}}});var hr={};me(hr,{wasmBackend:()=>jr});var jr,yr=w(()=>{"use strict";mr();jr=new Fe});var Yr={};me(Yr,{InferenceSession:()=>Ct,TRACE:()=>He,TRACE_FUNC_BEGIN:()=>F,TRACE_FUNC_END:()=>N,Tensor:()=>I,TrainingSession:()=>kt,default:()=>Vr,env:()=>E,registerBackend:()=>q});z();z();z();var Nt="1.20.0-dev.20240914-c63dd0234b";var Vr=Ve;{let t=(yr(),$e(hr)).wasmBackend;q("cpu",t,10),q("wasm",t,10)}Object.defineProperty(E.versions,"web",{value:Nt,enumerable:!0});return $e(Yr);})();
typeof exports=="object"&&typeof module=="object"&&(module.exports=ort);
//# sourceMappingURL=ort.wasm.min.js.map

@@ -7,2 +7,2 @@ // Copyright (c) Microsoft Corporation. All rights reserved.

export const version = '1.20.0-dev.20240913-904b850b44';
export const version = '1.20.0-dev.20240914-c63dd0234b';

@@ -10,3 +10,3 @@ {

"author": "fs-eire",
"version": "1.20.0-dev.20240913-904b850b44",
"version": "1.20.0-dev.20240914-c63dd0234b",
"jsdelivr": "dist/ort.min.js",

@@ -13,0 +13,0 @@ "dependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc