onnxruntime-web
Advanced tools
Comparing version 1.20.0-dev.20241009-9ee963110e to 1.20.0-dev.20241010-1bc546af61
@@ -1,1 +0,1 @@ | ||
9ee963110ec97b79fe9b5487abe28d1924e23048 | ||
1bc546af61d4c85660a56d70d5312196ba7032d3 |
/*! | ||
* ONNX Runtime Web v1.20.0-dev.20241009-9ee963110e | ||
* ONNX Runtime Web v1.20.0-dev.20241010-1bc546af61 | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
"use strict";var mt=Object.create;var ae=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var bt=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var L=(e,t)=>()=>(e&&(t=e(e=0)),t);var Pe=(e,t)=>{for(var n in t)ae(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of yt(t))!wt.call(e,r)&&r!==n&&ae(e,r,{get:()=>t[r],enumerable:!(s=gt(t,r))||s.enumerable});return e},U=(e,t,n)=>(se(e,t,"default"),n&&se(n,t,"default")),ht=(e,t,n)=>(n=e!=null?mt(bt(e)):{},se(t||!e||!e.__esModule?ae(n,"default",{value:e,enumerable:!0}):n,e)),Ie=e=>se(ae({},"__esModule",{value:!0}),e);var W,ie=L(()=>{"use strict";W=!!(typeof process<"u"&&process.versions&&process.versions.node)});var $,St,Et,Ot,vt,Tt,xt,Ce,ue=L(()=>{"use strict";ie();$=W?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,St=W||typeof location>"u"?void 0:location.origin,Et=(e,t)=>{try{let n=t??$;return(n?new URL(e,n):new URL(e)).origin===St}catch{return!1}},Ot=(e,t)=>{let n=t??$;try{return(n?new URL(e,n):new URL(e)).href}catch{return}},vt=(e,t)=>`${t??"./"}${e}`,Tt=async e=>{let n=await(await fetch(e,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},xt=async e=>(await import(/*webpackIgnore:true*/e)).default,Ce=async(e,t,n)=>{{let s="ort-wasm-simd-threaded.mjs",r=e??Ot(s,t),a=!W&&n&&r&&!Et(r,t),o=a?await Tt(r):r??vt(s,t);return[a?o:void 0,await xt(o)]}}});var ye,be,ce,ke,At,Pt,Be,S,z=L(()=>{"use strict";ue();be=!1,ce=!1,ke=!1,At=()=>{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}},Pt=()=>{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(be)return Promise.resolve();if(ce)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(ke)throw new Error("previous call to 'initializeWebAssembly()' failed.");ce=!0;let t=e.initTimeout,n=e.numThreads;if(!Pt())throw new Error("WebAssembly SIMD is not supported in the current environment.");let s=At();n>1&&!s&&(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,o=r?.mjs,u=o?.href??o,c=r?.wasm,d=c?.href??c,y=e.wasmBinary,[l,i]=await Ce(u,a,n>1),b=!1,f=[];if(t>0&&f.push(new Promise(p=>{setTimeout(()=>{b=!0,p()},t)})),f.push(new Promise((p,x)=>{let _={numThreads:n};y?_.wasmBinary=y:(d||a)&&(_.locateFile=(m,w)=>d??(a??w)+m),i(_).then(m=>{ce=!1,be=!0,ye=m,p(),l&&URL.revokeObjectURL(l)},m=>{ce=!1,ke=!0,x(m)})})),await Promise.race(f),b)throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`)},S=()=>{if(be&&ye)return ye;throw new Error("WebAssembly is not initialized yet.")}});var E,Y,h,le=L(()=>{"use strict";z();E=(e,t)=>{let n=S(),s=n.lengthBytesUTF8(e)+1,r=n._malloc(s);return n.stringToUTF8(e,r,s),t.push(r),r},Y=(e,t,n,s)=>{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 o=t?t+r:r;if(typeof a=="object")Y(a,o+".",n,s);else if(typeof a=="string"||typeof a=="number")s(o,a.toString());else if(typeof a=="boolean")s(o,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 s=t.stackAlloc(8);t._OrtGetLastError(s,s+4);let r=t.HEAP32[s/4],a=t.HEAPU32[s/4+1],o=a?t.UTF8ToString(a):"";throw new Error(`${e} ERROR_CODE: ${r}, ERROR_MESSAGE: ${o}`)}finally{t.stackRestore(n)}}});var Ue,_e=L(()=>{"use strict";z();le();Ue=e=>{let t=S(),n=0,s=[],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,s)),n=t._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,a),n===0&&h("Can't create run options."),e?.extra!==void 0&&Y(e.extra,"",new WeakSet,(o,u)=>{let c=E(o,s),d=E(u,s);t._OrtAddRunConfigEntry(n,c,d)!==0&&h(`Can't set a run config entry: ${o} - ${u}.`)}),[n,s]}catch(a){throw n!==0&&t._OrtReleaseRunOptions(n),s.forEach(o=>t._free(o)),a}}});var It,Lt,Ct,kt,Me,We=L(()=>{"use strict";z();le();It=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}`)}},Ct=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)},kt=(e,t,n)=>{for(let s of t){let r=typeof s=="string"?s:s.name;switch(r){case"webnn":if(r="WEBNN",typeof s!="string"){let u=s?.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 s!="string"){let o=s;if(o?.preferredLayout){if(o.preferredLayout!=="NCHW"&&o.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${o.preferredLayout}`);let u=E("preferredLayout",n),c=E(o.preferredLayout,n);S()._OrtAddSessionConfigEntry(e,u,c)!==0&&h(`Can't set a session config entry: 'preferredLayout' - ${o.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}.`)}},Me=e=>{let t=S(),n=0,s=[],r=e||{};Ct(r);try{let a=It(r.graphOptimizationLevel??"all"),o=Lt(r.executionMode??"sequential"),u=typeof r.logId=="string"?E(r.logId,s):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,s):0;if(n=t._OrtCreateSessionOptions(a,!!r.enableCpuMemArena,!!r.enableMemPattern,o,!!r.enableProfiling,0,u,c,d,y),n===0&&h("Can't create session options."),r.executionProviders&&kt(n,r.executionProviders,s),r.enableGraphCapture!==void 0){if(typeof r.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);let l=E("enableGraphCapture",s),i=E(r.enableGraphCapture.toString(),s);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,s);t._OrtAddFreeDimensionOverride(n,b,i)!==0&&h(`Can't set a free dimension override: ${l} - ${i}.`)}return r.extra!==void 0&&Y(r.extra,"",new WeakSet,(l,i)=>{let b=E(l,s),f=E(i,s);t._OrtAddSessionConfigEntry(n,b,f)!==0&&h(`Can't set a session config entry: ${l} - ${i}.`)}),[n,s]}catch(a){throw n!==0&&t._OrtReleaseSessionOptions(n),s.forEach(o=>t._free(o)),a}}});var X,De,K,Fe,Re,fe,de,Ne,we=L(()=>{"use strict";X=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}`)}},De=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}`)}},K=(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],s=typeof t=="number"?t:t.reduce((r,a)=>r*a,1);return n>0?Math.ceil(s*n):void 0},Fe=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}`)}},Re=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}`)}},fe=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",de=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint64"||e==="int8"||e==="uint8"||e==="bool",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;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${e}`)}}});var Q,he=L(()=>{"use strict";ie();Q=async e=>{if(typeof e=="string")if(W)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"),s=n(e),r=[];for await(let a of s)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"),s=n?parseInt(n,10):0;if(s<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(s)}catch(u){if(u instanceof RangeError){let c=Math.ceil(s/65536);a=new WebAssembly.Memory({initial:c,maximum:c}).buffer}else throw u}let o=0;for(;;){let{done:u,value:c}=await r.read();if(u)break;let d=c.byteLength;new Uint8Array(a,o,d).set(c),o+=d}return new Uint8Array(a,0,s)}}else return e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e instanceof Uint8Array?e:new Uint8Array(e)}});var Bt,He,je,G,Ut,Se,ze,Ge,$e,qe,Ve,Je=L(()=>{"use strict";_e();We();we();z();le();he();Bt=(e,t)=>{S()._OrtInit(e,t)!==0&&h("Can't initialize onnxruntime.")},He=async e=>{Bt(e.wasm.numThreads,Re(e.logLevel))},je=async(e,t)=>{},G=new Map,Ut=e=>{let t=S(),n=t.stackSave();try{let s=t.stackAlloc(8);return t._OrtGetInputOutputCount(e,s,s+4)!==0&&h("Can't get session input/output count."),[t.HEAP32[s/4],t.HEAP32[s/4+1]]}finally{t.stackRestore(n)}},Se=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]},ze=async(e,t)=>{let n,s,r=S();Array.isArray(e)?[n,s]=e:e.buffer===r.HEAPU8.buffer?[n,s]=[e.byteOffset,e.byteLength]:[n,s]=Se(e);let a=0,o=0,u=0,c=[],d=[],y=[];try{if([o,c]=Me(t),t?.externalData&&r.mountExternalData){let m=[];for(let w of t.externalData){let P=typeof w=="string"?w:w.path;m.push(Q(typeof w=="string"?w:w.data).then(D=>{r.mountExternalData(P,D)}))}await Promise.all(m)}for(let m of t?.executionProviders??[])if((typeof m=="string"?m:m.name)==="webnn"){if(r.shouldTransferToMLTensor=!1,r.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof m!="string"){let P=m,D=P?.context,q=P?.gpuDevice,ee=P?.deviceType,V=P?.numThreads,te=P?.powerPreference;D?r.currentContext=D:q?r.currentContext=await navigator.ml.createContext(q):r.currentContext=await navigator.ml.createContext({deviceType:ee,numThreads:V,powerPreference:te})}else r.currentContext=await navigator.ml.createContext();break}a=await r._OrtCreateSession(n,s,o),a===0&&h("Can't create a session."),r.currentContext&&(r.jsepRegisterMLContext(a,r.currentContext),r.currentContext=void 0,r.shouldTransferToMLTensor=!0);let[l,i]=Ut(a),b=!!t?.enableGraphCapture,f=[],p=[],x=[];for(let m=0;m<l;m++){let w=r._OrtGetInputName(a,m);w===0&&h("Can't get an input name."),d.push(w),f.push(r.UTF8ToString(w))}for(let m=0;m<i;m++){let w=r._OrtGetOutputName(a,m);w===0&&h("Can't get an output name."),y.push(w);let P=r.UTF8ToString(w);p.push(P)}let _=null;return G.set(a,[a,d,y,_,b,!1]),[a,f,p]}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),o!==0&&r._OrtReleaseSessionOptions(o),c.forEach(l=>r._free(l)),r.unmountExternalData?.()}},Ge=e=>{let t=S(),n=G.get(e);if(!n)throw new Error(`cannot release session. invalid session id: ${e}`);let[s,r,a,o,u]=n;o&&(u&&t._OrtClearBoundOutputs(o.handle),t._OrtReleaseBinding(o.handle)),t.jsepOnReleaseSession?.(e),r.forEach(c=>t._OrtFree(c)),a.forEach(c=>t._OrtFree(c)),t._OrtReleaseSession(s),G.delete(e)},$e=(e,t,n,s,r,a=!1)=>{if(!e){t.push(0);return}let o=S(),u=e[0],c=e[1],d=e[3],y,l;if(u==="string"&&(d==="gpu-buffer"||d==="ml-tensor"))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=K(X(u),c);let p=o.jsepRegisterBuffer;if(!p)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');y=p(s,r,f,l)}else if(d==="ml-tensor"){let f=e[2].mlTensor;l=K(X(u),c);let p=o.jsepRegisterMLTensor;if(!p)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');y=p(f,X(u),c)}else{let f=e[2];if(Array.isArray(f)){l=4*f.length,y=o._malloc(l),n.push(y);let p=y/4;for(let x=0;x<f.length;x++){if(typeof f[x]!="string")throw new TypeError(`tensor data at index ${x} is not a string`);o.HEAPU32[p++]=E(f[x],n)}}else l=f.byteLength,y=o._malloc(l),n.push(y),o.HEAPU8.set(new Uint8Array(f.buffer,f.byteOffset,l),y)}let i=o.stackSave(),b=o.stackAlloc(4*c.length);try{let f=b/4;c.forEach(x=>o.HEAP32[f++]=x);let p=o._OrtCreateTensor(X(u),y,l,b,c.length,Ne(d));p===0&&h(`Can't create tensor for input/output. session=${s}, index=${r}.`),t.push(p)}finally{o.stackRestore(i)}},qe=async(e,t,n,s,r,a)=>{let o=S(),u=G.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,p=s.length,x=0,_=[],m=[],w=[],P=[],D=o.stackSave(),q=o.stackAlloc(f*4),ee=o.stackAlloc(f*4),V=o.stackAlloc(p*4),te=o.stackAlloc(p*4);try{o.jsepOnRunStart?.(c),[x,_]=Ue(a);for(let g=0;g<f;g++)$e(n[g],m,P,e,t[g],i);for(let g=0;g<p;g++)$e(r[g],w,P,e,f+s[g],i);let B=q/4,ct=ee/4,lt=V/4,ft=te/4;for(let g=0;g<f;g++)o.HEAPU32[B++]=m[g],o.HEAPU32[ct++]=d[t[g]];for(let g=0;g<p;g++)o.HEAPU32[lt++]=w[g],o.HEAPU32[ft++]=y[s[g]];let ve;ve=await o._OrtRun(c,ee,q,f,te,p,V,x),ve!==0&&h("failed to call OrtRun().");let H=[];for(let g=0;g<p;g++){let j=o.HEAPU32[V/4+g];if(j===w[g]){H.push(r[g]);continue}let Te=o.stackSave(),F=o.stackAlloc(4*4),J=!1,O,I=0;try{o._OrtGetTensorData(j,F,F+4,F+8,F+12)!==0&&h(`Can't access output tensor data on index ${g}.`);let re=F/4,ne=o.HEAPU32[re++];I=o.HEAPU32[re++];let xe=o.HEAPU32[re++],dt=o.HEAPU32[re++],R=[];for(let v=0;v<dt;v++)R.push(o.HEAPU32[xe/4+v]);o._OrtFree(xe);let N=R.reduce((v,A)=>v*A,1);O=De(ne);let oe=l?.outputPreferredLocations[s[g]];if(O==="string"){if(oe==="gpu-buffer"||oe==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let v=[],A=I/4;for(let M=0;M<N;M++){let Ae=o.HEAPU32[A++],pt=M===N-1?void 0:o.HEAPU32[A]-Ae;v.push(o.UTF8ToString(Ae,pt))}H.push([O,R,v,"cpu"])}else if(oe==="gpu-buffer"&&N>0){let v=o.jsepGetBuffer;if(!v)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let A=v(I),M=K(ne,N);if(M===void 0||!fe(O))throw new Error(`Unsupported data type: ${O}`);J=!0,H.push([O,R,{gpuBuffer:A,download:o.jsepCreateDownloader(A,M,O),dispose:()=>{o._OrtReleaseTensor(j)}},"gpu-buffer"])}else if(oe==="ml-tensor"&&N>0){let v=o.jsepEnsureTensor;if(!v)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(K(ne,N)===void 0||!de(O))throw new Error(`Unsupported data type: ${O}`);let M=await v(I,ne,R,!1);J=!0,H.push([O,R,{mlTensor:M,download:o.jsepCreateMLTensorDownloader(I,O),dispose:()=>{o.jsepReleaseTensorId(I),o._OrtReleaseTensor(j)}},"ml-tensor"])}else{let v=Fe(O),A=new v(N);new Uint8Array(A.buffer,A.byteOffset,A.byteLength).set(o.HEAPU8.subarray(I,I+A.byteLength)),H.push([O,R,A,"cpu"])}}finally{o.stackRestore(Te),O==="string"&&I&&o._free(I),J||o._OrtReleaseTensor(j)}}return l&&!i&&(o._OrtClearBoundOutputs(l.handle),G.set(e,[c,d,y,l,i,!1])),H}finally{o.stackRestore(D),m.forEach(B=>o._OrtReleaseTensor(B)),w.forEach(B=>o._OrtReleaseTensor(B)),P.forEach(B=>o._free(B)),x!==0&&o._OrtReleaseRunOptions(x),_.forEach(B=>o._free(B))}},Ve=e=>{let t=S(),n=G.get(e);if(!n)throw new Error("invalid session id");let s=n[0],r=t._OrtEndProfiling(s);r===0&&h("Can't get an profile file name."),t._OrtFree(r)}});var pe,Ee,Ye,Xe,Ke,Qe,Ze,et,tt,rt,nt,Oe=L(()=>{"use strict";pe=require("onnxruntime-common");Je();z();ue();Ee=!1,Ye=!1,Xe=!1,Ke=async()=>{if(!Ye){if(Ee)throw new Error("multiple calls to 'initWasm()' detected.");if(Xe)throw new Error("previous call to 'initWasm()' failed.");Ee=!0;try{await Be(pe.env.wasm),await He(pe.env),Ye=!0}catch(e){throw Xe=!0,e}finally{Ee=!1}}},Qe=async e=>{await je(pe.env,e)},Ze=async e=>Se(e),et=async(e,t)=>ze(e,t),tt=async e=>{Ge(e)},rt=async(e,t,n,s,r,a)=>qe(e,t,n,s,r,a),nt=async e=>{Ve(e)}});var C,ot,Mt,me,st=L(()=>{"use strict";C=require("onnxruntime-common");Oe();we();ie();he();ot=(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"];case"ml-tensor":return[e.type,e.dims,{mlTensor:e.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${e.location} for ${t()}`)}},Mt=e=>{switch(e[3]){case"cpu":return new C.Tensor(e[0],e[2],e[1]);case"gpu-buffer":{let t=e[0];if(!fe(t))throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:s,dispose:r}=e[2];return C.Tensor.fromGpuBuffer(n,{dataType:t,dims:e[1],download:s,dispose:r})}case"ml-tensor":{let t=e[0];if(!de(t))throw new Error(`not supported data type: ${t} for deserializing MLTensor tensor`);let{mlTensor:n,download:s,dispose:r}=e[2];return C.Tensor.fromMLTensor(n,{dataType:t,dims:e[1],download:s,dispose:r})}default:throw new Error(`invalid data location: ${e[3]}`)}},me=class{async fetchModelAndCopyToWasmMemory(t){return Ze(await Q(t))}async loadModel(t,n){(0,C.TRACE_FUNC_BEGIN)();let s;typeof t=="string"?W?s=await Q(t):s=await this.fetchModelAndCopyToWasmMemory(t):s=t,[this.sessionId,this.inputNames,this.outputNames]=await et(s,n),(0,C.TRACE_FUNC_END)()}async dispose(){return tt(this.sessionId)}async run(t,n,s){(0,C.TRACE_FUNC_BEGIN)();let r=[],a=[];Object.entries(t).forEach(i=>{let b=i[0],f=i[1],p=this.inputNames.indexOf(b);if(p===-1)throw new Error(`invalid input '${b}'`);r.push(f),a.push(p)});let o=[],u=[];Object.entries(n).forEach(i=>{let b=i[0],f=i[1],p=this.outputNames.indexOf(b);if(p===-1)throw new Error(`invalid output '${b}'`);o.push(f),u.push(p)});let c=r.map((i,b)=>ot(i,()=>`input "${this.inputNames[a[b]]}"`)),d=o.map((i,b)=>i?ot(i,()=>`output "${this.outputNames[u[b]]}"`):null),y=await rt(this.sessionId,a,c,u,d,s),l={};for(let i=0;i<y.length;i++)l[this.outputNames[u[i]]]=o[i]??Mt(y[i]);return(0,C.TRACE_FUNC_END)(),l}startProfiling(){}endProfiling(){nt(this.sessionId)}}});var it={};Pe(it,{OnnxruntimeWebAssemblyBackend:()=>ge,initializeFlags:()=>at,wasmBackend:()=>Wt});var T,at,ge,Wt,ut=L(()=>{"use strict";T=require("onnxruntime-common");Oe();st();ue();at=()=>{if((typeof T.env.wasm.initTimeout!="number"||T.env.wasm.initTimeout<0)&&(T.env.wasm.initTimeout=0),T.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 T.env.wasm.proxy!="boolean"&&(T.env.wasm.proxy=!1),typeof T.env.wasm.trace!="boolean"&&(T.env.wasm.trace=!1),typeof T.env.wasm.numThreads!="number"||!Number.isInteger(T.env.wasm.numThreads)||T.env.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)T.env.wasm.numThreads=1;else{let e=typeof navigator>"u"?require("node:os").cpus().length:navigator.hardwareConcurrency;T.env.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}T.env.wasm.wasmPaths===void 0&&$&&$.indexOf("blob:")!==0&&(T.env.wasm.wasmPaths=$.substring(0,$.lastIndexOf("/")+1))},ge=class{async init(t){at(),await Ke(),await Qe(t)}async createInferenceSessionHandler(t,n){let s=new me;return await s.loadModel(t,n),Promise.resolve(s)}},Wt=new ge});var k={};Pe(k,{default:()=>Ft});module.exports=Ie(k);U(k,require("onnxruntime-common"),module.exports);var Dt=ht(require("onnxruntime-common")),Z=require("onnxruntime-common");var Le="1.20.0-dev.20241009-9ee963110e";var Ft=Dt;{let e=(ut(),Ie(it)).wasmBackend;(0,Z.registerBackend)("cpu",e,10),(0,Z.registerBackend)("wasm",e,10)}Object.defineProperty(Z.env.versions,"web",{value:Le,enumerable:!0});0&&(module.exports={...require("onnxruntime-common")}); | ||
"use strict";var mt=Object.create;var ae=Object.defineProperty;var gt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var bt=Object.getPrototypeOf,wt=Object.prototype.hasOwnProperty;var L=(e,t)=>()=>(e&&(t=e(e=0)),t);var Pe=(e,t)=>{for(var n in t)ae(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of yt(t))!wt.call(e,r)&&r!==n&&ae(e,r,{get:()=>t[r],enumerable:!(s=gt(t,r))||s.enumerable});return e},U=(e,t,n)=>(se(e,t,"default"),n&&se(n,t,"default")),ht=(e,t,n)=>(n=e!=null?mt(bt(e)):{},se(t||!e||!e.__esModule?ae(n,"default",{value:e,enumerable:!0}):n,e)),Ie=e=>se(ae({},"__esModule",{value:!0}),e);var W,ie=L(()=>{"use strict";W=!!(typeof process<"u"&&process.versions&&process.versions.node)});var $,St,Et,Ot,vt,Tt,xt,Ce,ue=L(()=>{"use strict";ie();$=W?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,St=W||typeof location>"u"?void 0:location.origin,Et=(e,t)=>{try{let n=t??$;return(n?new URL(e,n):new URL(e)).origin===St}catch{return!1}},Ot=(e,t)=>{let n=t??$;try{return(n?new URL(e,n):new URL(e)).href}catch{return}},vt=(e,t)=>`${t??"./"}${e}`,Tt=async e=>{let n=await(await fetch(e,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},xt=async e=>(await import(/*webpackIgnore:true*/e)).default,Ce=async(e,t,n)=>{{let s="ort-wasm-simd-threaded.mjs",r=e??Ot(s,t),a=!W&&n&&r&&!Et(r,t),o=a?await Tt(r):r??vt(s,t);return[a?o:void 0,await xt(o)]}}});var ye,be,ce,ke,At,Pt,Be,S,z=L(()=>{"use strict";ue();be=!1,ce=!1,ke=!1,At=()=>{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}},Pt=()=>{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(be)return Promise.resolve();if(ce)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(ke)throw new Error("previous call to 'initializeWebAssembly()' failed.");ce=!0;let t=e.initTimeout,n=e.numThreads;if(!Pt())throw new Error("WebAssembly SIMD is not supported in the current environment.");let s=At();n>1&&!s&&(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,o=r?.mjs,u=o?.href??o,c=r?.wasm,d=c?.href??c,y=e.wasmBinary,[l,i]=await Ce(u,a,n>1),b=!1,f=[];if(t>0&&f.push(new Promise(p=>{setTimeout(()=>{b=!0,p()},t)})),f.push(new Promise((p,x)=>{let _={numThreads:n};y?_.wasmBinary=y:(d||a)&&(_.locateFile=(m,w)=>d??(a??w)+m),i(_).then(m=>{ce=!1,be=!0,ye=m,p(),l&&URL.revokeObjectURL(l)},m=>{ce=!1,ke=!0,x(m)})})),await Promise.race(f),b)throw new Error(`WebAssembly backend initializing failed due to timeout: ${t}ms`)},S=()=>{if(be&&ye)return ye;throw new Error("WebAssembly is not initialized yet.")}});var E,Y,h,le=L(()=>{"use strict";z();E=(e,t)=>{let n=S(),s=n.lengthBytesUTF8(e)+1,r=n._malloc(s);return n.stringToUTF8(e,r,s),t.push(r),r},Y=(e,t,n,s)=>{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 o=t?t+r:r;if(typeof a=="object")Y(a,o+".",n,s);else if(typeof a=="string"||typeof a=="number")s(o,a.toString());else if(typeof a=="boolean")s(o,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 s=t.stackAlloc(8);t._OrtGetLastError(s,s+4);let r=t.HEAP32[s/4],a=t.HEAPU32[s/4+1],o=a?t.UTF8ToString(a):"";throw new Error(`${e} ERROR_CODE: ${r}, ERROR_MESSAGE: ${o}`)}finally{t.stackRestore(n)}}});var Ue,_e=L(()=>{"use strict";z();le();Ue=e=>{let t=S(),n=0,s=[],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,s)),n=t._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,a),n===0&&h("Can't create run options."),e?.extra!==void 0&&Y(e.extra,"",new WeakSet,(o,u)=>{let c=E(o,s),d=E(u,s);t._OrtAddRunConfigEntry(n,c,d)!==0&&h(`Can't set a run config entry: ${o} - ${u}.`)}),[n,s]}catch(a){throw n!==0&&t._OrtReleaseRunOptions(n),s.forEach(o=>t._free(o)),a}}});var It,Lt,Ct,kt,Me,We=L(()=>{"use strict";z();le();It=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}`)}},Ct=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)},kt=(e,t,n)=>{for(let s of t){let r=typeof s=="string"?s:s.name;switch(r){case"webnn":if(r="WEBNN",typeof s!="string"){let u=s?.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 s!="string"){let o=s;if(o?.preferredLayout){if(o.preferredLayout!=="NCHW"&&o.preferredLayout!=="NHWC")throw new Error(`preferredLayout must be either 'NCHW' or 'NHWC': ${o.preferredLayout}`);let u=E("preferredLayout",n),c=E(o.preferredLayout,n);S()._OrtAddSessionConfigEntry(e,u,c)!==0&&h(`Can't set a session config entry: 'preferredLayout' - ${o.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}.`)}},Me=e=>{let t=S(),n=0,s=[],r=e||{};Ct(r);try{let a=It(r.graphOptimizationLevel??"all"),o=Lt(r.executionMode??"sequential"),u=typeof r.logId=="string"?E(r.logId,s):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,s):0;if(n=t._OrtCreateSessionOptions(a,!!r.enableCpuMemArena,!!r.enableMemPattern,o,!!r.enableProfiling,0,u,c,d,y),n===0&&h("Can't create session options."),r.executionProviders&&kt(n,r.executionProviders,s),r.enableGraphCapture!==void 0){if(typeof r.enableGraphCapture!="boolean")throw new Error(`enableGraphCapture must be a boolean value: ${r.enableGraphCapture}`);let l=E("enableGraphCapture",s),i=E(r.enableGraphCapture.toString(),s);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,s);t._OrtAddFreeDimensionOverride(n,b,i)!==0&&h(`Can't set a free dimension override: ${l} - ${i}.`)}return r.extra!==void 0&&Y(r.extra,"",new WeakSet,(l,i)=>{let b=E(l,s),f=E(i,s);t._OrtAddSessionConfigEntry(n,b,f)!==0&&h(`Can't set a session config entry: ${l} - ${i}.`)}),[n,s]}catch(a){throw n!==0&&t._OrtReleaseSessionOptions(n),s.forEach(o=>t._free(o)),a}}});var X,De,K,Fe,Re,fe,de,Ne,we=L(()=>{"use strict";X=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}`)}},De=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}`)}},K=(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],s=typeof t=="number"?t:t.reduce((r,a)=>r*a,1);return n>0?Math.ceil(s*n):void 0},Fe=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}`)}},Re=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}`)}},fe=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint8"||e==="bool"||e==="uint4"||e==="int4",de=e=>e==="float32"||e==="float16"||e==="int32"||e==="int64"||e==="uint32"||e==="uint64"||e==="int8"||e==="uint8"||e==="bool",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;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${e}`)}}});var Q,he=L(()=>{"use strict";ie();Q=async e=>{if(typeof e=="string")if(W)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"),s=n(e),r=[];for await(let a of s)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"),s=n?parseInt(n,10):0;if(s<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(s)}catch(u){if(u instanceof RangeError){let c=Math.ceil(s/65536);a=new WebAssembly.Memory({initial:c,maximum:c}).buffer}else throw u}let o=0;for(;;){let{done:u,value:c}=await r.read();if(u)break;let d=c.byteLength;new Uint8Array(a,o,d).set(c),o+=d}return new Uint8Array(a,0,s)}}else return e instanceof Blob?new Uint8Array(await e.arrayBuffer()):e instanceof Uint8Array?e:new Uint8Array(e)}});var Bt,He,je,G,Ut,Se,ze,Ge,$e,qe,Ve,Je=L(()=>{"use strict";_e();We();we();z();le();he();Bt=(e,t)=>{S()._OrtInit(e,t)!==0&&h("Can't initialize onnxruntime.")},He=async e=>{Bt(e.wasm.numThreads,Re(e.logLevel))},je=async(e,t)=>{},G=new Map,Ut=e=>{let t=S(),n=t.stackSave();try{let s=t.stackAlloc(8);return t._OrtGetInputOutputCount(e,s,s+4)!==0&&h("Can't get session input/output count."),[t.HEAP32[s/4],t.HEAP32[s/4+1]]}finally{t.stackRestore(n)}},Se=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]},ze=async(e,t)=>{let n,s,r=S();Array.isArray(e)?[n,s]=e:e.buffer===r.HEAPU8.buffer?[n,s]=[e.byteOffset,e.byteLength]:[n,s]=Se(e);let a=0,o=0,u=0,c=[],d=[],y=[];try{if([o,c]=Me(t),t?.externalData&&r.mountExternalData){let m=[];for(let w of t.externalData){let P=typeof w=="string"?w:w.path;m.push(Q(typeof w=="string"?w:w.data).then(D=>{r.mountExternalData(P,D)}))}await Promise.all(m)}for(let m of t?.executionProviders??[])if((typeof m=="string"?m:m.name)==="webnn"){if(r.shouldTransferToMLTensor=!1,r.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof m!="string"){let P=m,D=P?.context,q=P?.gpuDevice,ee=P?.deviceType,V=P?.numThreads,te=P?.powerPreference;D?r.currentContext=D:q?r.currentContext=await navigator.ml.createContext(q):r.currentContext=await navigator.ml.createContext({deviceType:ee,numThreads:V,powerPreference:te})}else r.currentContext=await navigator.ml.createContext();break}a=await r._OrtCreateSession(n,s,o),a===0&&h("Can't create a session."),r.currentContext&&(r.jsepRegisterMLContext(a,r.currentContext),r.currentContext=void 0,r.shouldTransferToMLTensor=!0);let[l,i]=Ut(a),b=!!t?.enableGraphCapture,f=[],p=[],x=[];for(let m=0;m<l;m++){let w=r._OrtGetInputName(a,m);w===0&&h("Can't get an input name."),d.push(w),f.push(r.UTF8ToString(w))}for(let m=0;m<i;m++){let w=r._OrtGetOutputName(a,m);w===0&&h("Can't get an output name."),y.push(w);let P=r.UTF8ToString(w);p.push(P)}let _=null;return G.set(a,[a,d,y,_,b,!1]),[a,f,p]}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),o!==0&&r._OrtReleaseSessionOptions(o),c.forEach(l=>r._free(l)),r.unmountExternalData?.()}},Ge=e=>{let t=S(),n=G.get(e);if(!n)throw new Error(`cannot release session. invalid session id: ${e}`);let[s,r,a,o,u]=n;o&&(u&&t._OrtClearBoundOutputs(o.handle),t._OrtReleaseBinding(o.handle)),t.jsepOnReleaseSession?.(e),r.forEach(c=>t._OrtFree(c)),a.forEach(c=>t._OrtFree(c)),t._OrtReleaseSession(s),G.delete(e)},$e=(e,t,n,s,r,a=!1)=>{if(!e){t.push(0);return}let o=S(),u=e[0],c=e[1],d=e[3],y,l;if(u==="string"&&(d==="gpu-buffer"||d==="ml-tensor"))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=K(X(u),c);let p=o.jsepRegisterBuffer;if(!p)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');y=p(s,r,f,l)}else if(d==="ml-tensor"){let f=e[2].mlTensor;l=K(X(u),c);let p=o.jsepRegisterMLTensor;if(!p)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');y=p(f,X(u),c)}else{let f=e[2];if(Array.isArray(f)){l=4*f.length,y=o._malloc(l),n.push(y);let p=y/4;for(let x=0;x<f.length;x++){if(typeof f[x]!="string")throw new TypeError(`tensor data at index ${x} is not a string`);o.HEAPU32[p++]=E(f[x],n)}}else l=f.byteLength,y=o._malloc(l),n.push(y),o.HEAPU8.set(new Uint8Array(f.buffer,f.byteOffset,l),y)}let i=o.stackSave(),b=o.stackAlloc(4*c.length);try{let f=b/4;c.forEach(x=>o.HEAP32[f++]=x);let p=o._OrtCreateTensor(X(u),y,l,b,c.length,Ne(d));p===0&&h(`Can't create tensor for input/output. session=${s}, index=${r}.`),t.push(p)}finally{o.stackRestore(i)}},qe=async(e,t,n,s,r,a)=>{let o=S(),u=G.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,p=s.length,x=0,_=[],m=[],w=[],P=[],D=o.stackSave(),q=o.stackAlloc(f*4),ee=o.stackAlloc(f*4),V=o.stackAlloc(p*4),te=o.stackAlloc(p*4);try{o.jsepOnRunStart?.(c),[x,_]=Ue(a);for(let g=0;g<f;g++)$e(n[g],m,P,e,t[g],i);for(let g=0;g<p;g++)$e(r[g],w,P,e,f+s[g],i);let B=q/4,ct=ee/4,lt=V/4,ft=te/4;for(let g=0;g<f;g++)o.HEAPU32[B++]=m[g],o.HEAPU32[ct++]=d[t[g]];for(let g=0;g<p;g++)o.HEAPU32[lt++]=w[g],o.HEAPU32[ft++]=y[s[g]];let ve;ve=await o._OrtRun(c,ee,q,f,te,p,V,x),ve!==0&&h("failed to call OrtRun().");let H=[];for(let g=0;g<p;g++){let j=o.HEAPU32[V/4+g];if(j===w[g]){H.push(r[g]);continue}let Te=o.stackSave(),F=o.stackAlloc(4*4),J=!1,O,I=0;try{o._OrtGetTensorData(j,F,F+4,F+8,F+12)!==0&&h(`Can't access output tensor data on index ${g}.`);let re=F/4,ne=o.HEAPU32[re++];I=o.HEAPU32[re++];let xe=o.HEAPU32[re++],dt=o.HEAPU32[re++],R=[];for(let v=0;v<dt;v++)R.push(o.HEAPU32[xe/4+v]);o._OrtFree(xe);let N=R.reduce((v,A)=>v*A,1);O=De(ne);let oe=l?.outputPreferredLocations[s[g]];if(O==="string"){if(oe==="gpu-buffer"||oe==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let v=[],A=I/4;for(let M=0;M<N;M++){let Ae=o.HEAPU32[A++],pt=M===N-1?void 0:o.HEAPU32[A]-Ae;v.push(o.UTF8ToString(Ae,pt))}H.push([O,R,v,"cpu"])}else if(oe==="gpu-buffer"&&N>0){let v=o.jsepGetBuffer;if(!v)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let A=v(I),M=K(ne,N);if(M===void 0||!fe(O))throw new Error(`Unsupported data type: ${O}`);J=!0,H.push([O,R,{gpuBuffer:A,download:o.jsepCreateDownloader(A,M,O),dispose:()=>{o._OrtReleaseTensor(j)}},"gpu-buffer"])}else if(oe==="ml-tensor"&&N>0){let v=o.jsepEnsureTensor;if(!v)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(K(ne,N)===void 0||!de(O))throw new Error(`Unsupported data type: ${O}`);let M=await v(I,ne,R,!1);J=!0,H.push([O,R,{mlTensor:M,download:o.jsepCreateMLTensorDownloader(I,O),dispose:()=>{o.jsepReleaseTensorId(I),o._OrtReleaseTensor(j)}},"ml-tensor"])}else{let v=Fe(O),A=new v(N);new Uint8Array(A.buffer,A.byteOffset,A.byteLength).set(o.HEAPU8.subarray(I,I+A.byteLength)),H.push([O,R,A,"cpu"])}}finally{o.stackRestore(Te),O==="string"&&I&&o._free(I),J||o._OrtReleaseTensor(j)}}return l&&!i&&(o._OrtClearBoundOutputs(l.handle),G.set(e,[c,d,y,l,i,!1])),H}finally{o.stackRestore(D),m.forEach(B=>o._OrtReleaseTensor(B)),w.forEach(B=>o._OrtReleaseTensor(B)),P.forEach(B=>o._free(B)),x!==0&&o._OrtReleaseRunOptions(x),_.forEach(B=>o._free(B))}},Ve=e=>{let t=S(),n=G.get(e);if(!n)throw new Error("invalid session id");let s=n[0],r=t._OrtEndProfiling(s);r===0&&h("Can't get an profile file name."),t._OrtFree(r)}});var pe,Ee,Ye,Xe,Ke,Qe,Ze,et,tt,rt,nt,Oe=L(()=>{"use strict";pe=require("onnxruntime-common");Je();z();ue();Ee=!1,Ye=!1,Xe=!1,Ke=async()=>{if(!Ye){if(Ee)throw new Error("multiple calls to 'initWasm()' detected.");if(Xe)throw new Error("previous call to 'initWasm()' failed.");Ee=!0;try{await Be(pe.env.wasm),await He(pe.env),Ye=!0}catch(e){throw Xe=!0,e}finally{Ee=!1}}},Qe=async e=>{await je(pe.env,e)},Ze=async e=>Se(e),et=async(e,t)=>ze(e,t),tt=async e=>{Ge(e)},rt=async(e,t,n,s,r,a)=>qe(e,t,n,s,r,a),nt=async e=>{Ve(e)}});var C,ot,Mt,me,st=L(()=>{"use strict";C=require("onnxruntime-common");Oe();we();ie();he();ot=(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"];case"ml-tensor":return[e.type,e.dims,{mlTensor:e.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${e.location} for ${t()}`)}},Mt=e=>{switch(e[3]){case"cpu":return new C.Tensor(e[0],e[2],e[1]);case"gpu-buffer":{let t=e[0];if(!fe(t))throw new Error(`not supported data type: ${t} for deserializing GPU tensor`);let{gpuBuffer:n,download:s,dispose:r}=e[2];return C.Tensor.fromGpuBuffer(n,{dataType:t,dims:e[1],download:s,dispose:r})}case"ml-tensor":{let t=e[0];if(!de(t))throw new Error(`not supported data type: ${t} for deserializing MLTensor tensor`);let{mlTensor:n,download:s,dispose:r}=e[2];return C.Tensor.fromMLTensor(n,{dataType:t,dims:e[1],download:s,dispose:r})}default:throw new Error(`invalid data location: ${e[3]}`)}},me=class{async fetchModelAndCopyToWasmMemory(t){return Ze(await Q(t))}async loadModel(t,n){(0,C.TRACE_FUNC_BEGIN)();let s;typeof t=="string"?W?s=await Q(t):s=await this.fetchModelAndCopyToWasmMemory(t):s=t,[this.sessionId,this.inputNames,this.outputNames]=await et(s,n),(0,C.TRACE_FUNC_END)()}async dispose(){return tt(this.sessionId)}async run(t,n,s){(0,C.TRACE_FUNC_BEGIN)();let r=[],a=[];Object.entries(t).forEach(i=>{let b=i[0],f=i[1],p=this.inputNames.indexOf(b);if(p===-1)throw new Error(`invalid input '${b}'`);r.push(f),a.push(p)});let o=[],u=[];Object.entries(n).forEach(i=>{let b=i[0],f=i[1],p=this.outputNames.indexOf(b);if(p===-1)throw new Error(`invalid output '${b}'`);o.push(f),u.push(p)});let c=r.map((i,b)=>ot(i,()=>`input "${this.inputNames[a[b]]}"`)),d=o.map((i,b)=>i?ot(i,()=>`output "${this.outputNames[u[b]]}"`):null),y=await rt(this.sessionId,a,c,u,d,s),l={};for(let i=0;i<y.length;i++)l[this.outputNames[u[i]]]=o[i]??Mt(y[i]);return(0,C.TRACE_FUNC_END)(),l}startProfiling(){}endProfiling(){nt(this.sessionId)}}});var it={};Pe(it,{OnnxruntimeWebAssemblyBackend:()=>ge,initializeFlags:()=>at,wasmBackend:()=>Wt});var T,at,ge,Wt,ut=L(()=>{"use strict";T=require("onnxruntime-common");Oe();st();ue();at=()=>{if((typeof T.env.wasm.initTimeout!="number"||T.env.wasm.initTimeout<0)&&(T.env.wasm.initTimeout=0),T.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 T.env.wasm.proxy!="boolean"&&(T.env.wasm.proxy=!1),typeof T.env.wasm.trace!="boolean"&&(T.env.wasm.trace=!1),typeof T.env.wasm.numThreads!="number"||!Number.isInteger(T.env.wasm.numThreads)||T.env.wasm.numThreads<=0)if(typeof self<"u"&&!self.crossOriginIsolated)T.env.wasm.numThreads=1;else{let e=typeof navigator>"u"?require("node:os").cpus().length:navigator.hardwareConcurrency;T.env.wasm.numThreads=Math.min(4,Math.ceil((e||1)/2))}T.env.wasm.wasmPaths===void 0&&$&&$.indexOf("blob:")!==0&&(T.env.wasm.wasmPaths=$.substring(0,$.lastIndexOf("/")+1))},ge=class{async init(t){at(),await Ke(),await Qe(t)}async createInferenceSessionHandler(t,n){let s=new me;return await s.loadModel(t,n),Promise.resolve(s)}},Wt=new ge});var k={};Pe(k,{default:()=>Ft});module.exports=Ie(k);U(k,require("onnxruntime-common"),module.exports);var Dt=ht(require("onnxruntime-common")),Z=require("onnxruntime-common");var Le="1.20.0-dev.20241010-1bc546af61";var Ft=Dt;{let e=(ut(),Ie(it)).wasmBackend;(0,Z.registerBackend)("cpu",e,10),(0,Z.registerBackend)("wasm",e,10)}Object.defineProperty(Z.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.20241009-9ee963110e | ||
* ONNX Runtime Web v1.20.0-dev.20241010-1bc546af61 | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
"use strict";var ort=(()=>{var He=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var xr=Object.prototype.hasOwnProperty;var je=(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 w=(t,e)=>()=>(t&&(e=t(t=0)),e);var be=(t,e)=>{for(var n in e)He(t,n,{get:e[n],enumerable:!0})},Pr=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of vr(e))!xr.call(t,r)&&r!==n&&He(t,r,{get:()=>e[r],enumerable:!(o=Or(e,r))||o.enumerable});return t};var Ve=t=>Pr(He({},"__esModule",{value:!0}),t);var ge,H,Q,Ir,Ee,Te=w(()=>{"use strict";ge=new Map,H=[],Q=(t,e,n)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let o=ge.get(t);if(o===void 0)ge.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=H.indexOf(t);r!==-1&&H.splice(r,1);for(let i=0;i<H.length;i++)if(ge.get(H[i]).priority<=n){H.splice(i,0,t);return}H.push(t)}return}throw new TypeError("not a valid backend")},Ir=async t=>{let e=ge.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}}},Ee=async t=>{let e=t.executionProviders||[],n=e.map(a=>typeof a=="string"?a:a.name),o=n.length===0?H:n,r,i=[],s=new Set;for(let a of o){let u=await Ir(a);typeof u=="string"?i.push({name:a,err:u}):(r||(r=u),r===u&&s.add(a))}if(!r)throw new Error(`no available backend found. ERR: ${i.map(a=>`[${a.name}] ${a.err}`).join(", ")}`);for(let{name:a,err:u}of i)n.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[r,new Proxy(t,{get:(a,u)=>u==="executionProviders"?f:Reflect.get(a,u)})]}});var ct=w(()=>{"use strict";Te()});var dt,lt=w(()=>{"use strict";dt="1.20.0-dev.20240928-1bda91fc57"});var pt,U,Ye=w(()=>{"use strict";lt();pt="warning",U={wasm:{},webgl:{},webgpu:{},versions:{common:dt},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}`);pt=t}},get logLevel(){return pt}};Object.defineProperty(U,"logLevel",{enumerable:!0})});var E,mt=w(()=>{"use strict";Ye();E=U});var ht,yt,wt=w(()=>{"use strict";ht=(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,i;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=t.dims[2],i=t.dims[3]):(r=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*r,d=0,c=l,m=l*2,p=-1;s==="RGBA"?(d=0,c=l,m=l*2,p=l*3):s==="RGB"?(d=0,c=l,m=l*2):s==="RBG"&&(d=0,m=l,c=l*2);for(let h=0;h<i;h++)for(let T=0;T<r;T++){let O=(t.data[d++]-u[0])*a[0],y=(t.data[c++]-u[1])*a[1],b=(t.data[m++]-u[2])*a[2],A=p===-1?255:(t.data[p++]-u[3])*a[3];o.fillStyle="rgba("+O+","+y+","+b+","+A+")",o.fillRect(T,h,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")},yt=(t,e)=>{let n=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),o;if(n!=null){let r,i,s;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=t.dims[2],i=t.dims[1],s=t.dims[3]):(r=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*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 c=4,m=0,p=1,h=2,T=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=n.createImageData(r,i);for(let M=0;M<i*r;m+=c,p+=c,h+=c,T+=c,M++)o.data[m]=(t.data[O++]-l[0])*u[0],o.data[p]=(t.data[y++]-l[1])*u[1],o.data[h]=(t.data[b++]-l[2])*u[2],o.data[T]=A===-1?255:(t.data[A++]-l[3])*u[3]}else throw new Error("Can not access image data");return o}});var qe,bt,gt,Et,Tt,St,At=w(()=>{"use strict";Se();qe=(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},i,s;typeof r.mean=="number"?i=[r.mean,r.mean,r.mean,r.mean]:i=[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 f=e.format!==void 0?e.format:"RGBA",a=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",u=n*o,l=a==="RGBA"?new Float32Array(u*4):new Float32Array(u*3),d=4,c=0,m=1,p=2,h=3,T=0,O=u,y=u*2,b=-1;f==="RGB"&&(d=3,c=0,m=1,p=2,h=-1),a==="RGBA"?b=u*3:a==="RBG"?(T=0,y=u,O=u*2):a==="BGR"&&(y=0,O=u,T=u*2);for(let M=0;M<u;M++,c+=d,p+=d,m+=d,h+=d)l[T++]=(t[c]+s[0])/i[0],l[O++]=(t[m]+s[1])/i[1],l[y++]=(t[p]+s[2])/i[2],b!==-1&&h!==-1&&(l[b++]=(t[h]+s[3])/i[3]);return a==="RGBA"?new I("float32",l,[1,4,n,o]):new I("float32",l,[1,3,n,o])},bt=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,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=>typeof HTMLCanvasElement<"u"&&l instanceof HTMLCanvasElement||l instanceof OffscreenCanvas?l.getContext("2d"):null;if(n){let l=a();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,m=t.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(c=e.resizedHeight,m=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=m}else f.tensorFormat="RGBA",f.height=c,f.width=m;d.drawImage(t,0,0),s=d.getImageData(0,0,m,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 m=u(c);if(m!=null)m.putImageData(t,0,0),s=m.getImageData(0,0,d,l).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 l=a();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,m=t.width;return d.drawImage(t,0,0,m,c),s=d.getImageData(0,0,m,c).data,f.height=c,f.width=m,qe(s,f)}else throw new Error("Can not access image data")}else{if(i)return new Promise((l,d)=>{let c=a(),m=u(c);if(!t||!m)return d();let p=new Image;p.crossOrigin="Anonymous",p.src=t,p.onload=()=>{c.width=p.width,c.height=p.height,m.drawImage(p,0,0,c.width,c.height);let h=m.getImageData(0,0,c.width,c.height);f.height=c.height,f.width=c.width,l(qe(h.data,f))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return qe(s,f);throw new Error("Input data provided is not supported - aborted tensor creation")},gt=(t,e)=>{let{width:n,height:o,download:r,dispose:i}=e,s=[1,o,n,4];return new I({location:"texture",type:"float32",texture:t,dims:s,download:r,dispose:i})},Et=(t,e)=>{let{dataType:n,dims:o,download:r,dispose:i}=e;return new I({location:"gpu-buffer",type:n??"float32",gpuBuffer:t,dims:o,download:r,dispose:i})},Tt=(t,e)=>{let{dataType:n,dims:o,download:r,dispose:i}=e;return new I({location:"ml-tensor",type:n??"float32",mlTensor:t,dims:o,download:r,dispose:i})},St=(t,e,n)=>new I({location:"cpu-pinned",type:t,data:e,dims:n??[e.length]})});var j,se,Ot,vt,xt=w(()=>{"use strict";j=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),se=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Ot=!1,vt=()=>{if(!Ot){Ot=!0;let t=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,n=typeof Float16Array<"u"&&Float16Array.from;t&&(j.set("int64",BigInt64Array),se.set(BigInt64Array,"int64")),e&&(j.set("uint64",BigUint64Array),se.set(BigUint64Array,"uint64")),n?(j.set("float16",Float16Array),se.set(Float16Array,"float16")):j.set("float16",Uint16Array)}}});var Pt,It,Lt=w(()=>{"use strict";Se();Pt=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},It=(t,e)=>{switch(t.location){case"cpu":return new I(t.type,t.data,e);case"cpu-pinned":return new I({location:"cpu-pinned",data:t.data,type:t.type,dims:e});case"texture":return new I({location:"texture",texture:t.texture,type:t.type,dims:e});case"gpu-buffer":return new I({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:e});case"ml-tensor":return new I({location:"ml-tensor",mlTensor:t.mlTensor,type:t.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${t.location} is not supported`)}}});var I,Se=w(()=>{"use strict";wt();At();xt();Lt();I=class{constructor(e,n,o){vt();let r,i;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,r=e.type,i=e.dims,e.location){case"cpu-pinned":{let f=j.get(r);if(!f)throw new TypeError(`unsupported type "${r}" 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(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}case"ml-tensor":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint64"&&r!=="int8"&&r!=="uint8"&&r!=="bool")throw new TypeError(`unsupported type "${r}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,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(r=e,a=o,e==="string"){if(!Array.isArray(n))throw new TypeError("A string tensor's data must be a string array.");f=n}else{let u=j.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"?f=u.from(n,BigInt):f=u.from(n)}else if(n instanceof u)f=n;else if(n instanceof Uint8ClampedArray)if(e==="uint8")f=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(a=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",f=e;else if(u==="boolean")r="bool",f=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${u}.`)}else if(e instanceof Uint8ClampedArray)r="uint8",f=Uint8Array.from(e);else{let u=se.get(e.constructor);if(u===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=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=Pt(i);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=i,this.size=s}static async fromImage(e,n){return bt(e,n)}static fromTexture(e,n){return gt(e,n)}static fromGpuBuffer(e,n){return Et(e,n)}static fromMLTensor(e,n){return Tt(e,n)}static fromPinnedBuffer(e,n,o){return St(e,n,o)}toDataURL(e){return ht(this,e)}toImageData(e){return yt(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}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let 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.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return It(this,e)}}});var P,Ae=w(()=>{"use strict";Se();P=I});var Je,Bt,N,W,Xe=w(()=>{"use strict";Ye();Je=(t,e)=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||console.timeStamp(`${t}::ORT::${e}`)},Bt=(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 i=`FUNC_${t}::${n[r].trim().split(" ")[1]}`;e&&(i+=`::${e}`),Je("CPU",i);return}n[r].includes("TRACE_FUNC")&&(o=!0)}},N=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Bt("BEGIN",t)},W=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Bt("END",t)}});var Oe,Ct=w(()=>{"use strict";Te();Ae();Xe();Oe=class t{constructor(e){this.handler=e}async run(e,n,o){N();let r={},i={};if(typeof e!="object"||e===null||e instanceof P||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 P)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)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,l=Object.getOwnPropertyNames(n);for(let d of this.outputNames)if(l.indexOf(d)!==-1){let c=n[d];(c===null||c instanceof P)&&(u=!0,s=!1,r[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=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 f=await this.handler.run(e,r,i),a={};for(let u in f)if(Object.hasOwnProperty.call(f,u)){let l=f[u];l instanceof P?a[u]=l:a[u]=new P(l.type,l.data,l.dims)}return W(),a}async release(){return this.handler.dispose()}static async create(e,n,o,r){N();let i,s={};if(typeof e=="string"){if(i=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(i=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 l=e,d=0,c=e.byteLength;if(typeof n=="object"&&n!==null)s=n;else if(typeof n=="number"){if(d=n,!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 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.");i=new Uint8Array(l,d,c)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[f,a]=await Ee(s),u=await f.createInferenceSessionHandler(i,a);return W(),new t(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var Mt,Ut=w(()=>{"use strict";Ct();Mt=Oe});var Dt=w(()=>{"use strict"});var Rt=w(()=>{"use strict"});var _t=w(()=>{"use strict"});var kt=w(()=>{"use strict"});var Lr,ve,Ft=w(()=>{"use strict";Te();Ae();Lr="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",ve=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||"",i=n||{},[s,f]=await Ee(i);if(s.createTrainingSessionHandler){let a=await s.createTrainingSessionHandler(e.checkpointState,e.trainModel,o,r,f);return new t(a,!!e.optimizerModel,!!e.evalModel)}else throw new Error(Lr)}typeNarrowingForRunStep(e,n,o,r,i){let s={},f={};if(typeof o!="object"||o===null||o instanceof P||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 r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof P)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.");a=!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 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(r);for(let d of n)if(l.indexOf(d)!==-1){let c=r[d];(c===null||c instanceof P)&&(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=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(a)for(let u of n)s[u]=null;return[s,f]}convertHandlerReturnTypeToMapOfTensors(e){let n={};for(let o in e)if(Object.hasOwnProperty.call(e,o)){let r=e[o];r instanceof P?n[o]=r:n[o]=new P(r.type,r.data,r.dims)}return n}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(e,n,o){let[r,i]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,e,n,o),s=await this.handler.runTrainStep(e,r,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,n,o){if(this.hasEvalModel){let[r,i]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,e,n,o),s=await this.handler.runEvalStep(e,r,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,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 Nt,Wt=w(()=>{"use strict";Ft();Nt=ve});var Ke={};be(Ke,{InferenceSession:()=>Mt,TRACE:()=>Je,TRACE_FUNC_BEGIN:()=>N,TRACE_FUNC_END:()=>W,Tensor:()=>P,TrainingSession:()=>Nt,env:()=>E,registerBackend:()=>Q});var V=w(()=>{"use strict";ct();mt();Ut();Ae();Dt();Rt();Xe();_t();kt();Wt()});var xe=w(()=>{"use strict"});var Ht={};be(Ht,{default:()=>Br});var zt,Gt,Br,jt=w(()=>{"use strict";Qe();Y();ie();zt="ort-wasm-proxy-worker",Gt=globalThis.self?.name===zt;Gt&&(self.onmessage=t=>{let{type:e,in:n}=t.data;try{switch(e){case"init-wasm":Pe(n.wasm).then(()=>{Ie(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;Le(r,o).then(()=>{postMessage({type:e})},i=>{postMessage({type:e,err:i})});break}case"copy-from":{let{buffer:o}=n,r=ae(o);postMessage({type:e,out:r});break}case"create":{let{model:o,options:r}=n;Be(o,r).then(i=>{postMessage({type:e,out:i})},i=>{postMessage({type:e,err:i})});break}case"release":Ce(n),postMessage({type:e});break;case"run":{let{sessionId:o,inputIndices:r,inputs:i,outputIndices:s,options:f}=n;Me(o,r,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},De([...i,...a]))},a=>{postMessage({type:e,err:a})});break}case"end-profiling":Ue(n),postMessage({type:e});break;default:}}catch(o){postMessage({type:e,err:o})}});Br=Gt?null:t=>new Worker(t??R,{type:"classic",name:zt})});var R,Cr,Yt,Mr,Ur,qt,Dr,Vt,Jt,Xt,ie=w(()=>{"use strict";xe();R=!1?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,Cr=!1||typeof location>"u"?void 0:location.origin,Yt=(t,e)=>{try{let n=e??R;return(n?new URL(t,n):new URL(t)).origin===Cr}catch{return!1}},Mr=(t,e)=>{let n=e??R;try{return(n?new URL(t,n):new URL(t)).href}catch{return}},Ur=(t,e)=>`${e??"./"}${t}`,qt=async t=>{let n=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},Dr=async t=>(await import(/*webpackIgnore:true*/t)).default,Vt=(jt(),Ve(Ht)).default,Jt=async()=>{if(!R)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(Yt(R))return[void 0,Vt()];let t=await qt(R);return[t,Vt(t)]},Xt=async(t,e,n)=>{{let o="ort-wasm-simd-threaded.mjs",r=t??Mr(o,e),i=!!1&&n&&r&&!Yt(r,e),s=i?await qt(r):r??Ur(o,e);return[i?s:void 0,await Dr(s)]}}});var Ze,et,Re,Kt,Rr,_r,Pe,v,Y=w(()=>{"use strict";ie();et=!1,Re=!1,Kt=!1,Rr=()=>{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}},_r=()=>{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}},Pe=async t=>{if(et)return Promise.resolve();if(Re)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Kt)throw new Error("previous call to 'initializeWebAssembly()' failed.");Re=!0;let e=t.initTimeout,n=t.numThreads;if(!_r())throw new Error("WebAssembly SIMD is not supported in the current environment.");let o=Rr();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,i=typeof r=="string"?r:void 0,s=r?.mjs,f=s?.href??s,a=r?.wasm,u=a?.href??a,l=t.wasmBinary,[d,c]=await Xt(f,i,n>1),m=!1,p=[];if(e>0&&p.push(new Promise(h=>{setTimeout(()=>{m=!0,h()},e)})),p.push(new Promise((h,T)=>{let O={numThreads:n};l?O.wasmBinary=l:(u||i)&&(O.locateFile=(y,b)=>u??(i??b)+y),c(O).then(y=>{Re=!1,et=!0,Ze=y,h(),d&&URL.revokeObjectURL(d)},y=>{Re=!1,Kt=!0,T(y)})})),await Promise.race(p),m)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},v=()=>{if(et&&Ze)return Ze;throw new Error("WebAssembly is not initialized yet.")}});var x,ue,S,_e=w(()=>{"use strict";Y();x=(t,e)=>{let n=v(),o=n.lengthBytesUTF8(t)+1,r=n._malloc(o);return n.stringToUTF8(t,r,o),e.push(r),r},ue=(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,i])=>{let s=e?e+r:r;if(typeof i=="object")ue(i,s+".",n,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}`)})},S=t=>{let e=v(),n=e.stackSave();try{let o=e.stackAlloc(8);e._OrtGetLastError(o,o+4);let r=e.HEAP32[o/4],i=e.HEAPU32[o/4+1],s=i?e.UTF8ToString(i):"";throw new Error(`${t} ERROR_CODE: ${r}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(n)}}});var Qt,Zt=w(()=>{"use strict";Y();_e();Qt=t=>{let e=v(),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 i=0;return t?.tag!==void 0&&(i=x(t.tag,o)),n=e._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,i),n===0&&S("Can't create run options."),t?.extra!==void 0&&ue(t.extra,"",new WeakSet,(s,f)=>{let a=x(s,o),u=x(f,o);e._OrtAddRunConfigEntry(n,a,u)!==0&&S(`Can't set a run config entry: ${s} - ${f}.`)}),[n,o]}catch(i){throw n!==0&&e._OrtReleaseRunOptions(n),o.forEach(s=>e._free(s)),i}}});var kr,Fr,Nr,Wr,er,tr=w(()=>{"use strict";Y();_e();kr=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}`)}},Fr=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},Nr=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)},Wr=(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 f=o?.deviceType;if(f){let a=x("deviceType",n),u=x(f,n);v()._OrtAddSessionConfigEntry(t,a,u)!==0&&S(`Can't set a session config entry: 'deviceType' - ${f}.`)}}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 f=x("preferredLayout",n),a=x(s.preferredLayout,n);v()._OrtAddSessionConfigEntry(t,f,a)!==0&&S(`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 i=x(r,n);v()._OrtAppendExecutionProvider(t,i)!==0&&S(`Can't append execution provider: ${r}.`)}},er=t=>{let e=v(),n=0,o=[],r=t||{};Nr(r);try{let i=kr(r.graphOptimizationLevel??"all"),s=Fr(r.executionMode??"sequential"),f=typeof r.logId=="string"?x(r.logId,o):0,a=r.logSeverityLevel??2;if(!Number.isInteger(a)||a<0||a>4)throw new Error(`log serverity level is not valid: ${a}`);let u=r.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let l=typeof r.optimizedModelFilePath=="string"?x(r.optimizedModelFilePath,o):0;if(n=e._OrtCreateSessionOptions(i,!!r.enableCpuMemArena,!!r.enableMemPattern,s,!!r.enableProfiling,0,f,a,u,l),n===0&&S("Can't create session options."),r.executionProviders&&Wr(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 d=x("enableGraphCapture",o),c=x(r.enableGraphCapture.toString(),o);e._OrtAddSessionConfigEntry(n,d,c)!==0&&S(`Can't set a session config entry: 'enableGraphCapture' - ${r.enableGraphCapture}.`)}if(r.freeDimensionOverrides)for(let[d,c]of Object.entries(r.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 m=x(d,o);e._OrtAddFreeDimensionOverride(n,m,c)!==0&&S(`Can't set a free dimension override: ${d} - ${c}.`)}return r.extra!==void 0&&ue(r.extra,"",new WeakSet,(d,c)=>{let m=x(d,o),p=x(c,o);e._OrtAddSessionConfigEntry(n,m,p)!==0&&S(`Can't set a session config entry: ${d} - ${c}.`)}),[n,o]}catch(i){throw n!==0&&e._OrtReleaseSessionOptions(n),o.forEach(s=>e._free(s)),i}}});var fe,rr,ce,nr,or,ke,Fe,sr,tt=w(()=>{"use strict";fe=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}`)}},rr=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}`)}},ce=(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,i)=>r*i,1);return n>0?Math.ceil(o*n):void 0},nr=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}`)}},or=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}`)}},ke=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",Fe=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint64"||t==="int8"||t==="uint8"||t==="bool",sr=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;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${t}`)}}});var de,rt=w(()=>{"use strict";xe();de=async t=>{if(typeof t=="string")if(!1)try{let{readFile:e}=je("node:fs/promises");return new Uint8Array(await e(t))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:n}=je("node:fs"),o=n(t),r=[];for await(let i of o)r.push(i);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(),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 r.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 $r,Ie,Le,Z,zr,ae,Be,Ce,ir,Me,Ue,De,Qe=w(()=>{"use strict";Zt();tr();tt();Y();_e();rt();$r=(t,e)=>{v()._OrtInit(t,e)!==0&&S("Can't initialize onnxruntime.")},Ie=async t=>{$r(t.wasm.numThreads,or(t.logLevel))},Le=async(t,e)=>{},Z=new Map,zr=t=>{let e=v(),n=e.stackSave();try{let o=e.stackAlloc(8);return e._OrtGetInputOutputCount(t,o,o+4)!==0&&S("Can't get session input/output count."),[e.HEAP32[o/4],e.HEAP32[o/4+1]]}finally{e.stackRestore(n)}},ae=t=>{let e=v(),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]},Be=async(t,e)=>{let n,o,r=v();Array.isArray(t)?[n,o]=t:t.buffer===r.HEAPU8.buffer?[n,o]=[t.byteOffset,t.byteLength]:[n,o]=ae(t);let i=0,s=0,f=0,a=[],u=[],l=[];try{if([s,a]=er(e),e?.externalData&&r.mountExternalData){let y=[];for(let b of e.externalData){let A=typeof b=="string"?b:b.path;y.push(de(typeof b=="string"?b:b.data).then(M=>{r.mountExternalData(A,M)}))}await Promise.all(y)}for(let y of e?.executionProviders??[])if((typeof y=="string"?y:y.name)==="webnn"){if(r.shouldTransferToMLTensor=!1,r.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof y!="string"){let A=y,M=A?.context,re=A?.gpuDevice,pe=A?.deviceType,ne=A?.numThreads,me=A?.powerPreference;M?r.currentContext=M:re?r.currentContext=await navigator.ml.createContext(re):r.currentContext=await navigator.ml.createContext({deviceType:pe,numThreads:ne,powerPreference:me})}else r.currentContext=await navigator.ml.createContext();break}i=await r._OrtCreateSession(n,o,s),i===0&&S("Can't create a session."),r.currentContext&&(r.jsepRegisterMLContext(i,r.currentContext),r.currentContext=void 0,r.shouldTransferToMLTensor=!0);let[d,c]=zr(i),m=!!e?.enableGraphCapture,p=[],h=[],T=[];for(let y=0;y<d;y++){let b=r._OrtGetInputName(i,y);b===0&&S("Can't get an input name."),u.push(b),p.push(r.UTF8ToString(b))}for(let y=0;y<c;y++){let b=r._OrtGetOutputName(i,y);b===0&&S("Can't get an output name."),l.push(b);let A=r.UTF8ToString(b);h.push(A)}let O=null;return Z.set(i,[i,u,l,O,m,!1]),[i,p,h]}catch(d){throw u.forEach(c=>r._OrtFree(c)),l.forEach(c=>r._OrtFree(c)),f!==0&&r._OrtReleaseBinding(f),i!==0&&r._OrtReleaseSession(i),d}finally{r._free(n),s!==0&&r._OrtReleaseSessionOptions(s),a.forEach(d=>r._free(d)),r.unmountExternalData?.()}},Ce=t=>{let e=v(),n=Z.get(t);if(!n)throw new Error(`cannot release session. invalid session id: ${t}`);let[o,r,i,s,f]=n;s&&(f&&e._OrtClearBoundOutputs(s.handle),e._OrtReleaseBinding(s.handle)),e.jsepOnReleaseSession?.(t),r.forEach(a=>e._OrtFree(a)),i.forEach(a=>e._OrtFree(a)),e._OrtReleaseSession(o),Z.delete(t)},ir=(t,e,n,o,r,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"||u==="ml-tensor"))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 ${r} when enableGraphCapture is true.`);if(u==="gpu-buffer"){let p=t[2].gpuBuffer;d=ce(fe(f),a);let h=s.jsepRegisterBuffer;if(!h)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');l=h(o,r,p,d)}else if(u==="ml-tensor"){let p=t[2].mlTensor;d=ce(fe(f),a);let h=s.jsepRegisterMLTensor;if(!h)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');l=h(p,fe(f),a)}else{let p=t[2];if(Array.isArray(p)){d=4*p.length,l=s._malloc(d),n.push(l);let h=l/4;for(let T=0;T<p.length;T++){if(typeof p[T]!="string")throw new TypeError(`tensor data at index ${T} is not a string`);s.HEAPU32[h++]=x(p[T],n)}}else d=p.byteLength,l=s._malloc(d),n.push(l),s.HEAPU8.set(new Uint8Array(p.buffer,p.byteOffset,d),l)}let c=s.stackSave(),m=s.stackAlloc(4*a.length);try{let p=m/4;a.forEach(T=>s.HEAP32[p++]=T);let h=s._OrtCreateTensor(fe(f),l,d,m,a.length,sr(u));h===0&&S(`Can't create tensor for input/output. session=${o}, index=${r}.`),e.push(h)}finally{s.stackRestore(c)}},Me=async(t,e,n,o,r,i)=>{let s=v(),f=Z.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],m=f[5],p=e.length,h=o.length,T=0,O=[],y=[],b=[],A=[],M=s.stackSave(),re=s.stackAlloc(p*4),pe=s.stackAlloc(p*4),ne=s.stackAlloc(h*4),me=s.stackAlloc(h*4);try{s.jsepOnRunStart?.(a),[T,O]=Qt(i);for(let g=0;g<p;g++)ir(n[g],y,A,t,e[g],c);for(let g=0;g<h;g++)ir(r[g],b,A,t,p+o[g],c);let k=re/4,gr=pe/4,Er=ne/4,Tr=me/4;for(let g=0;g<p;g++)s.HEAPU32[k++]=y[g],s.HEAPU32[gr++]=u[e[g]];for(let g=0;g<h;g++)s.HEAPU32[Er++]=b[g],s.HEAPU32[Tr++]=l[o[g]];let it;it=await s._OrtRun(a,pe,re,p,me,h,ne,T),it!==0&&S("failed to call OrtRun().");let X=[];for(let g=0;g<h;g++){let K=s.HEAPU32[ne/4+g];if(K===b[g]){X.push(r[g]);continue}let at=s.stackSave(),$=s.stackAlloc(4*4),oe=!1,L,D=0;try{s._OrtGetTensorData(K,$,$+4,$+8,$+12)!==0&&S(`Can't access output tensor data on index ${g}.`);let he=$/4,ye=s.HEAPU32[he++];D=s.HEAPU32[he++];let ut=s.HEAPU32[he++],Sr=s.HEAPU32[he++],z=[];for(let B=0;B<Sr;B++)z.push(s.HEAPU32[ut/4+B]);s._OrtFree(ut);let G=z.reduce((B,C)=>B*C,1);L=rr(ye);let we=d?.outputPreferredLocations[o[g]];if(L==="string"){if(we==="gpu-buffer"||we==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let B=[],C=D/4;for(let F=0;F<G;F++){let ft=s.HEAPU32[C++],Ar=F===G-1?void 0:s.HEAPU32[C]-ft;B.push(s.UTF8ToString(ft,Ar))}X.push([L,z,B,"cpu"])}else if(we==="gpu-buffer"&&G>0){let B=s.jsepGetBuffer;if(!B)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let C=B(D),F=ce(ye,G);if(F===void 0||!ke(L))throw new Error(`Unsupported data type: ${L}`);oe=!0,X.push([L,z,{gpuBuffer:C,download:s.jsepCreateDownloader(C,F,L),dispose:()=>{s._OrtReleaseTensor(K)}},"gpu-buffer"])}else if(we==="ml-tensor"&&G>0){let B=s.jsepEnsureTensor;if(!B)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(ce(ye,G)===void 0||!Fe(L))throw new Error(`Unsupported data type: ${L}`);let F=await B(D,ye,z,!1);oe=!0,X.push([L,z,{mlTensor:F,download:s.jsepCreateMLTensorDownloader(D,L),dispose:()=>{s.jsepReleaseTensorId(D),s._OrtReleaseTensor(K)}},"ml-tensor"])}else{let B=nr(L),C=new B(G);new Uint8Array(C.buffer,C.byteOffset,C.byteLength).set(s.HEAPU8.subarray(D,D+C.byteLength)),X.push([L,z,C,"cpu"])}}finally{s.stackRestore(at),L==="string"&&D&&s._free(D),oe||s._OrtReleaseTensor(K)}}return d&&!c&&(s._OrtClearBoundOutputs(d.handle),Z.set(t,[a,u,l,d,c,!1])),X}finally{s.stackRestore(M),y.forEach(k=>s._OrtReleaseTensor(k)),b.forEach(k=>s._OrtReleaseTensor(k)),A.forEach(k=>s._free(k)),T!==0&&s._OrtReleaseRunOptions(T),O.forEach(k=>s._free(k))}},Ue=t=>{let e=v(),n=Z.get(t);if(!n)throw new Error("invalid session id");let o=n[0],r=e._OrtEndProfiling(o);r===0&&S("Can't get an profile file name."),e._OrtFree(r)},De=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 J,_,le,We,$e,Ne,nt,ot,ee,te,Hr,ar,ur,fr,cr,dr,lr,pr,st=w(()=>{"use strict";V();Qe();Y();ie();J=()=>!!E.wasm.proxy&&typeof document<"u",le=!1,We=!1,$e=!1,ot=new Map,ee=(t,e)=>{let n=ot.get(t);n?n.push(e):ot.set(t,[e])},te=()=>{if(le||!We||$e||!_)throw new Error("worker not ready")},Hr=t=>{switch(t.data.type){case"init-wasm":le=!1,t.data.err?($e=!0,nt[1](t.data.err)):(We=!0,nt[0]()),Ne&&(URL.revokeObjectURL(Ne),Ne=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=ot.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}default:}},ar=async()=>{if(!We){if(le)throw new Error("multiple calls to 'initWasm()' detected.");if($e)throw new Error("previous call to 'initWasm()' failed.");if(le=!0,J())return new Promise((t,e)=>{_?.terminate(),Jt().then(([n,o])=>{try{_=o,_.onerror=i=>e(i),_.onmessage=Hr,nt=[t,e];let r={type:"init-wasm",in:E};_.postMessage(r),Ne=n}catch(r){e(r)}},e)});try{await Pe(E.wasm),await Ie(E),We=!0}catch(t){throw $e=!0,t}finally{le=!1}}},ur=async t=>{if(J())return te(),new Promise((e,n)=>{ee("init-ep",[e,n]);let o={type:"init-ep",in:{epName:t,env:E}};_.postMessage(o)});await Le(E,t)},fr=async t=>J()?(te(),new Promise((e,n)=>{ee("copy-from",[e,n]);let o={type:"copy-from",in:{buffer:t}};_.postMessage(o,[t.buffer])})):ae(t),cr=async(t,e)=>{if(J()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return te(),new Promise((n,o)=>{ee("create",[n,o]);let r={type:"create",in:{model:t,options:{...e}}},i=[];t instanceof Uint8Array&&i.push(t.buffer),_.postMessage(r,i)})}else return Be(t,e)},dr=async t=>{if(J())return te(),new Promise((e,n)=>{ee("release",[e,n]);let o={type:"release",in:t};_.postMessage(o)});Ce(t)},lr=async(t,e,n,o,r,i)=>{if(J()){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 te(),new Promise((s,f)=>{ee("run",[s,f]);let a=n,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:a,outputIndices:o,options:i}};_.postMessage(u,De(a))})}else return Me(t,e,n,o,r,i)},pr=async t=>{if(J())return te(),new Promise((e,n)=>{ee("end-profiling",[e,n]);let o={type:"end-profiling",in:t};_.postMessage(o)});Ue(t)}});var mr,jr,ze,hr=w(()=>{"use strict";V();st();tt();xe();rt();mr=(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"];case"ml-tensor":return[t.type,t.dims,{mlTensor:t.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},jr=t=>{switch(t[3]){case"cpu":return new P(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!ke(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:n,download:o,dispose:r}=t[2];return P.fromGpuBuffer(n,{dataType:e,dims:t[1],download:o,dispose:r})}case"ml-tensor":{let e=t[0];if(!Fe(e))throw new Error(`not supported data type: ${e} for deserializing MLTensor tensor`);let{mlTensor:n,download:o,dispose:r}=t[2];return P.fromMLTensor(n,{dataType:e,dims:t[1],download:o,dispose:r})}default:throw new Error(`invalid data location: ${t[3]}`)}},ze=class{async fetchModelAndCopyToWasmMemory(e){return fr(await de(e))}async loadModel(e,n){N();let o;typeof e=="string"?!1?o=await de(e):o=await this.fetchModelAndCopyToWasmMemory(e):o=e,[this.sessionId,this.inputNames,this.outputNames]=await cr(o,n),W()}async dispose(){return dr(this.sessionId)}async run(e,n,o){N();let r=[],i=[];Object.entries(e).forEach(c=>{let m=c[0],p=c[1],h=this.inputNames.indexOf(m);if(h===-1)throw new Error(`invalid input '${m}'`);r.push(p),i.push(h)});let s=[],f=[];Object.entries(n).forEach(c=>{let m=c[0],p=c[1],h=this.outputNames.indexOf(m);if(h===-1)throw new Error(`invalid output '${m}'`);s.push(p),f.push(h)});let a=r.map((c,m)=>mr(c,()=>`input "${this.inputNames[i[m]]}"`)),u=s.map((c,m)=>c?mr(c,()=>`output "${this.outputNames[f[m]]}"`):null),l=await lr(this.sessionId,i,a,f,u,o),d={};for(let c=0;c<l.length;c++)d[this.outputNames[f[c]]]=s[c]??jr(l[c]);return W(),d}startProfiling(){}endProfiling(){pr(this.sessionId)}}});var wr={};be(wr,{OnnxruntimeWebAssemblyBackend:()=>Ge,initializeFlags:()=>yr,wasmBackend:()=>Vr});var yr,Ge,Vr,br=w(()=>{"use strict";V();st();hr();ie();yr=()=>{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"?je("node:os").cpus().length:navigator.hardwareConcurrency;E.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}E.wasm.wasmPaths===void 0&&R&&R.indexOf("blob:")!==0&&(E.wasm.wasmPaths=R.substring(0,R.lastIndexOf("/")+1))},Ge=class{async init(e){yr(),await ar(),await ur(e)}async createInferenceSessionHandler(e,n){let o=new ze;return await o.loadModel(e,n),Promise.resolve(o)}},Vr=new Ge});var qr={};be(qr,{InferenceSession:()=>Mt,TRACE:()=>Je,TRACE_FUNC_BEGIN:()=>N,TRACE_FUNC_END:()=>W,Tensor:()=>P,TrainingSession:()=>Nt,default:()=>Yr,env:()=>E,registerBackend:()=>Q});V();V();V();var $t="1.20.0-dev.20241009-9ee963110e";var Yr=Ke;{let t=(br(),Ve(wr)).wasmBackend;Q("cpu",t,10),Q("wasm",t,10)}Object.defineProperty(E.versions,"web",{value:$t,enumerable:!0});return Ve(qr);})(); | ||
"use strict";var ort=(()=>{var He=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames;var xr=Object.prototype.hasOwnProperty;var je=(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 w=(t,e)=>()=>(t&&(e=t(t=0)),e);var be=(t,e)=>{for(var n in e)He(t,n,{get:e[n],enumerable:!0})},Pr=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of vr(e))!xr.call(t,r)&&r!==n&&He(t,r,{get:()=>e[r],enumerable:!(o=Or(e,r))||o.enumerable});return t};var Ve=t=>Pr(He({},"__esModule",{value:!0}),t);var ge,H,Q,Ir,Ee,Te=w(()=>{"use strict";ge=new Map,H=[],Q=(t,e,n)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let o=ge.get(t);if(o===void 0)ge.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=H.indexOf(t);r!==-1&&H.splice(r,1);for(let i=0;i<H.length;i++)if(ge.get(H[i]).priority<=n){H.splice(i,0,t);return}H.push(t)}return}throw new TypeError("not a valid backend")},Ir=async t=>{let e=ge.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}}},Ee=async t=>{let e=t.executionProviders||[],n=e.map(a=>typeof a=="string"?a:a.name),o=n.length===0?H:n,r,i=[],s=new Set;for(let a of o){let u=await Ir(a);typeof u=="string"?i.push({name:a,err:u}):(r||(r=u),r===u&&s.add(a))}if(!r)throw new Error(`no available backend found. ERR: ${i.map(a=>`[${a.name}] ${a.err}`).join(", ")}`);for(let{name:a,err:u}of i)n.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[r,new Proxy(t,{get:(a,u)=>u==="executionProviders"?f:Reflect.get(a,u)})]}});var ct=w(()=>{"use strict";Te()});var dt,lt=w(()=>{"use strict";dt="1.20.0-dev.20240928-1bda91fc57"});var pt,U,Ye=w(()=>{"use strict";lt();pt="warning",U={wasm:{},webgl:{},webgpu:{},versions:{common:dt},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}`);pt=t}},get logLevel(){return pt}};Object.defineProperty(U,"logLevel",{enumerable:!0})});var E,mt=w(()=>{"use strict";Ye();E=U});var ht,yt,wt=w(()=>{"use strict";ht=(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,i;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=t.dims[2],i=t.dims[3]):(r=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*r,d=0,c=l,m=l*2,p=-1;s==="RGBA"?(d=0,c=l,m=l*2,p=l*3):s==="RGB"?(d=0,c=l,m=l*2):s==="RBG"&&(d=0,m=l,c=l*2);for(let h=0;h<i;h++)for(let T=0;T<r;T++){let O=(t.data[d++]-u[0])*a[0],y=(t.data[c++]-u[1])*a[1],b=(t.data[m++]-u[2])*a[2],A=p===-1?255:(t.data[p++]-u[3])*a[3];o.fillStyle="rgba("+O+","+y+","+b+","+A+")",o.fillRect(T,h,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")},yt=(t,e)=>{let n=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),o;if(n!=null){let r,i,s;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=t.dims[2],i=t.dims[1],s=t.dims[3]):(r=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*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 c=4,m=0,p=1,h=2,T=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=n.createImageData(r,i);for(let M=0;M<i*r;m+=c,p+=c,h+=c,T+=c,M++)o.data[m]=(t.data[O++]-l[0])*u[0],o.data[p]=(t.data[y++]-l[1])*u[1],o.data[h]=(t.data[b++]-l[2])*u[2],o.data[T]=A===-1?255:(t.data[A++]-l[3])*u[3]}else throw new Error("Can not access image data");return o}});var qe,bt,gt,Et,Tt,St,At=w(()=>{"use strict";Se();qe=(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},i,s;typeof r.mean=="number"?i=[r.mean,r.mean,r.mean,r.mean]:i=[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 f=e.format!==void 0?e.format:"RGBA",a=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",u=n*o,l=a==="RGBA"?new Float32Array(u*4):new Float32Array(u*3),d=4,c=0,m=1,p=2,h=3,T=0,O=u,y=u*2,b=-1;f==="RGB"&&(d=3,c=0,m=1,p=2,h=-1),a==="RGBA"?b=u*3:a==="RBG"?(T=0,y=u,O=u*2):a==="BGR"&&(y=0,O=u,T=u*2);for(let M=0;M<u;M++,c+=d,p+=d,m+=d,h+=d)l[T++]=(t[c]+s[0])/i[0],l[O++]=(t[m]+s[1])/i[1],l[y++]=(t[p]+s[2])/i[2],b!==-1&&h!==-1&&(l[b++]=(t[h]+s[3])/i[3]);return a==="RGBA"?new I("float32",l,[1,4,n,o]):new I("float32",l,[1,3,n,o])},bt=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,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=>typeof HTMLCanvasElement<"u"&&l instanceof HTMLCanvasElement||l instanceof OffscreenCanvas?l.getContext("2d"):null;if(n){let l=a();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,m=t.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(c=e.resizedHeight,m=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=m}else f.tensorFormat="RGBA",f.height=c,f.width=m;d.drawImage(t,0,0),s=d.getImageData(0,0,m,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 m=u(c);if(m!=null)m.putImageData(t,0,0),s=m.getImageData(0,0,d,l).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 l=a();l.width=t.width,l.height=t.height;let d=u(l);if(d!=null){let c=t.height,m=t.width;return d.drawImage(t,0,0,m,c),s=d.getImageData(0,0,m,c).data,f.height=c,f.width=m,qe(s,f)}else throw new Error("Can not access image data")}else{if(i)return new Promise((l,d)=>{let c=a(),m=u(c);if(!t||!m)return d();let p=new Image;p.crossOrigin="Anonymous",p.src=t,p.onload=()=>{c.width=p.width,c.height=p.height,m.drawImage(p,0,0,c.width,c.height);let h=m.getImageData(0,0,c.width,c.height);f.height=c.height,f.width=c.width,l(qe(h.data,f))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return qe(s,f);throw new Error("Input data provided is not supported - aborted tensor creation")},gt=(t,e)=>{let{width:n,height:o,download:r,dispose:i}=e,s=[1,o,n,4];return new I({location:"texture",type:"float32",texture:t,dims:s,download:r,dispose:i})},Et=(t,e)=>{let{dataType:n,dims:o,download:r,dispose:i}=e;return new I({location:"gpu-buffer",type:n??"float32",gpuBuffer:t,dims:o,download:r,dispose:i})},Tt=(t,e)=>{let{dataType:n,dims:o,download:r,dispose:i}=e;return new I({location:"ml-tensor",type:n??"float32",mlTensor:t,dims:o,download:r,dispose:i})},St=(t,e,n)=>new I({location:"cpu-pinned",type:t,data:e,dims:n??[e.length]})});var j,se,Ot,vt,xt=w(()=>{"use strict";j=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),se=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),Ot=!1,vt=()=>{if(!Ot){Ot=!0;let t=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,n=typeof Float16Array<"u"&&Float16Array.from;t&&(j.set("int64",BigInt64Array),se.set(BigInt64Array,"int64")),e&&(j.set("uint64",BigUint64Array),se.set(BigUint64Array,"uint64")),n?(j.set("float16",Float16Array),se.set(Float16Array,"float16")):j.set("float16",Uint16Array)}}});var Pt,It,Lt=w(()=>{"use strict";Se();Pt=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},It=(t,e)=>{switch(t.location){case"cpu":return new I(t.type,t.data,e);case"cpu-pinned":return new I({location:"cpu-pinned",data:t.data,type:t.type,dims:e});case"texture":return new I({location:"texture",texture:t.texture,type:t.type,dims:e});case"gpu-buffer":return new I({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:e});case"ml-tensor":return new I({location:"ml-tensor",mlTensor:t.mlTensor,type:t.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${t.location} is not supported`)}}});var I,Se=w(()=>{"use strict";wt();At();xt();Lt();I=class{constructor(e,n,o){vt();let r,i;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,r=e.type,i=e.dims,e.location){case"cpu-pinned":{let f=j.get(r);if(!f)throw new TypeError(`unsupported type "${r}" 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(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}case"ml-tensor":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint64"&&r!=="int8"&&r!=="uint8"&&r!=="bool")throw new TypeError(`unsupported type "${r}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,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(r=e,a=o,e==="string"){if(!Array.isArray(n))throw new TypeError("A string tensor's data must be a string array.");f=n}else{let u=j.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"?f=u.from(n,BigInt):f=u.from(n)}else if(n instanceof u)f=n;else if(n instanceof Uint8ClampedArray)if(e==="uint8")f=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(a=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",f=e;else if(u==="boolean")r="bool",f=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${u}.`)}else if(e instanceof Uint8ClampedArray)r="uint8",f=Uint8Array.from(e);else{let u=se.get(e.constructor);if(u===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=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=Pt(i);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=i,this.size=s}static async fromImage(e,n){return bt(e,n)}static fromTexture(e,n){return gt(e,n)}static fromGpuBuffer(e,n){return Et(e,n)}static fromMLTensor(e,n){return Tt(e,n)}static fromPinnedBuffer(e,n,o){return St(e,n,o)}toDataURL(e){return ht(this,e)}toImageData(e){return yt(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}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":{if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let 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.mlTensorData=void 0,this.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return It(this,e)}}});var P,Ae=w(()=>{"use strict";Se();P=I});var Je,Bt,N,W,Xe=w(()=>{"use strict";Ye();Je=(t,e)=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||console.timeStamp(`${t}::ORT::${e}`)},Bt=(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 i=`FUNC_${t}::${n[r].trim().split(" ")[1]}`;e&&(i+=`::${e}`),Je("CPU",i);return}n[r].includes("TRACE_FUNC")&&(o=!0)}},N=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Bt("BEGIN",t)},W=t=>{(typeof U.trace>"u"?!U.wasm.trace:!U.trace)||Bt("END",t)}});var Oe,Ct=w(()=>{"use strict";Te();Ae();Xe();Oe=class t{constructor(e){this.handler=e}async run(e,n,o){N();let r={},i={};if(typeof e!="object"||e===null||e instanceof P||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 P)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)i=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else{let u=!1,l=Object.getOwnPropertyNames(n);for(let d of this.outputNames)if(l.indexOf(d)!==-1){let c=n[d];(c===null||c instanceof P)&&(u=!0,s=!1,r[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=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 f=await this.handler.run(e,r,i),a={};for(let u in f)if(Object.hasOwnProperty.call(f,u)){let l=f[u];l instanceof P?a[u]=l:a[u]=new P(l.type,l.data,l.dims)}return W(),a}async release(){return this.handler.dispose()}static async create(e,n,o,r){N();let i,s={};if(typeof e=="string"){if(i=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(i=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 l=e,d=0,c=e.byteLength;if(typeof n=="object"&&n!==null)s=n;else if(typeof n=="number"){if(d=n,!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 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.");i=new Uint8Array(l,d,c)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[f,a]=await Ee(s),u=await f.createInferenceSessionHandler(i,a);return W(),new t(u)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var Mt,Ut=w(()=>{"use strict";Ct();Mt=Oe});var Dt=w(()=>{"use strict"});var Rt=w(()=>{"use strict"});var _t=w(()=>{"use strict"});var kt=w(()=>{"use strict"});var Lr,ve,Ft=w(()=>{"use strict";Te();Ae();Lr="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",ve=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||"",i=n||{},[s,f]=await Ee(i);if(s.createTrainingSessionHandler){let a=await s.createTrainingSessionHandler(e.checkpointState,e.trainModel,o,r,f);return new t(a,!!e.optimizerModel,!!e.evalModel)}else throw new Error(Lr)}typeNarrowingForRunStep(e,n,o,r,i){let s={},f={};if(typeof o!="object"||o===null||o instanceof P||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 r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof P)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.");a=!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 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(r);for(let d of n)if(l.indexOf(d)!==-1){let c=r[d];(c===null||c instanceof P)&&(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=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(a)for(let u of n)s[u]=null;return[s,f]}convertHandlerReturnTypeToMapOfTensors(e){let n={};for(let o in e)if(Object.hasOwnProperty.call(e,o)){let r=e[o];r instanceof P?n[o]=r:n[o]=new P(r.type,r.data,r.dims)}return n}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(e,n,o){let[r,i]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,e,n,o),s=await this.handler.runTrainStep(e,r,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,n,o){if(this.hasEvalModel){let[r,i]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,e,n,o),s=await this.handler.runEvalStep(e,r,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,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 Nt,Wt=w(()=>{"use strict";Ft();Nt=ve});var Ke={};be(Ke,{InferenceSession:()=>Mt,TRACE:()=>Je,TRACE_FUNC_BEGIN:()=>N,TRACE_FUNC_END:()=>W,Tensor:()=>P,TrainingSession:()=>Nt,env:()=>E,registerBackend:()=>Q});var V=w(()=>{"use strict";ct();mt();Ut();Ae();Dt();Rt();Xe();_t();kt();Wt()});var xe=w(()=>{"use strict"});var Ht={};be(Ht,{default:()=>Br});var zt,Gt,Br,jt=w(()=>{"use strict";Qe();Y();ie();zt="ort-wasm-proxy-worker",Gt=globalThis.self?.name===zt;Gt&&(self.onmessage=t=>{let{type:e,in:n}=t.data;try{switch(e){case"init-wasm":Pe(n.wasm).then(()=>{Ie(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;Le(r,o).then(()=>{postMessage({type:e})},i=>{postMessage({type:e,err:i})});break}case"copy-from":{let{buffer:o}=n,r=ae(o);postMessage({type:e,out:r});break}case"create":{let{model:o,options:r}=n;Be(o,r).then(i=>{postMessage({type:e,out:i})},i=>{postMessage({type:e,err:i})});break}case"release":Ce(n),postMessage({type:e});break;case"run":{let{sessionId:o,inputIndices:r,inputs:i,outputIndices:s,options:f}=n;Me(o,r,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},De([...i,...a]))},a=>{postMessage({type:e,err:a})});break}case"end-profiling":Ue(n),postMessage({type:e});break;default:}}catch(o){postMessage({type:e,err:o})}});Br=Gt?null:t=>new Worker(t??R,{type:"classic",name:zt})});var R,Cr,Yt,Mr,Ur,qt,Dr,Vt,Jt,Xt,ie=w(()=>{"use strict";xe();R=!1?void 0:typeof document<"u"?document.currentScript?.src:typeof self<"u"?self.location?.href:void 0,Cr=!1||typeof location>"u"?void 0:location.origin,Yt=(t,e)=>{try{let n=e??R;return(n?new URL(t,n):new URL(t)).origin===Cr}catch{return!1}},Mr=(t,e)=>{let n=e??R;try{return(n?new URL(t,n):new URL(t)).href}catch{return}},Ur=(t,e)=>`${e??"./"}${t}`,qt=async t=>{let n=await(await fetch(t,{credentials:"same-origin"})).blob();return URL.createObjectURL(n)},Dr=async t=>(await import(/*webpackIgnore:true*/t)).default,Vt=(jt(),Ve(Ht)).default,Jt=async()=>{if(!R)throw new Error("Failed to load proxy worker: cannot determine the script source URL.");if(Yt(R))return[void 0,Vt()];let t=await qt(R);return[t,Vt(t)]},Xt=async(t,e,n)=>{{let o="ort-wasm-simd-threaded.mjs",r=t??Mr(o,e),i=!!1&&n&&r&&!Yt(r,e),s=i?await qt(r):r??Ur(o,e);return[i?s:void 0,await Dr(s)]}}});var Ze,et,Re,Kt,Rr,_r,Pe,v,Y=w(()=>{"use strict";ie();et=!1,Re=!1,Kt=!1,Rr=()=>{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}},_r=()=>{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}},Pe=async t=>{if(et)return Promise.resolve();if(Re)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(Kt)throw new Error("previous call to 'initializeWebAssembly()' failed.");Re=!0;let e=t.initTimeout,n=t.numThreads;if(!_r())throw new Error("WebAssembly SIMD is not supported in the current environment.");let o=Rr();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,i=typeof r=="string"?r:void 0,s=r?.mjs,f=s?.href??s,a=r?.wasm,u=a?.href??a,l=t.wasmBinary,[d,c]=await Xt(f,i,n>1),m=!1,p=[];if(e>0&&p.push(new Promise(h=>{setTimeout(()=>{m=!0,h()},e)})),p.push(new Promise((h,T)=>{let O={numThreads:n};l?O.wasmBinary=l:(u||i)&&(O.locateFile=(y,b)=>u??(i??b)+y),c(O).then(y=>{Re=!1,et=!0,Ze=y,h(),d&&URL.revokeObjectURL(d)},y=>{Re=!1,Kt=!0,T(y)})})),await Promise.race(p),m)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},v=()=>{if(et&&Ze)return Ze;throw new Error("WebAssembly is not initialized yet.")}});var x,ue,S,_e=w(()=>{"use strict";Y();x=(t,e)=>{let n=v(),o=n.lengthBytesUTF8(t)+1,r=n._malloc(o);return n.stringToUTF8(t,r,o),e.push(r),r},ue=(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,i])=>{let s=e?e+r:r;if(typeof i=="object")ue(i,s+".",n,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}`)})},S=t=>{let e=v(),n=e.stackSave();try{let o=e.stackAlloc(8);e._OrtGetLastError(o,o+4);let r=e.HEAP32[o/4],i=e.HEAPU32[o/4+1],s=i?e.UTF8ToString(i):"";throw new Error(`${t} ERROR_CODE: ${r}, ERROR_MESSAGE: ${s}`)}finally{e.stackRestore(n)}}});var Qt,Zt=w(()=>{"use strict";Y();_e();Qt=t=>{let e=v(),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 i=0;return t?.tag!==void 0&&(i=x(t.tag,o)),n=e._OrtCreateRunOptions(r.logSeverityLevel,r.logVerbosityLevel,!!r.terminate,i),n===0&&S("Can't create run options."),t?.extra!==void 0&&ue(t.extra,"",new WeakSet,(s,f)=>{let a=x(s,o),u=x(f,o);e._OrtAddRunConfigEntry(n,a,u)!==0&&S(`Can't set a run config entry: ${s} - ${f}.`)}),[n,o]}catch(i){throw n!==0&&e._OrtReleaseRunOptions(n),o.forEach(s=>e._free(s)),i}}});var kr,Fr,Nr,Wr,er,tr=w(()=>{"use strict";Y();_e();kr=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}`)}},Fr=t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}},Nr=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)},Wr=(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 f=o?.deviceType;if(f){let a=x("deviceType",n),u=x(f,n);v()._OrtAddSessionConfigEntry(t,a,u)!==0&&S(`Can't set a session config entry: 'deviceType' - ${f}.`)}}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 f=x("preferredLayout",n),a=x(s.preferredLayout,n);v()._OrtAddSessionConfigEntry(t,f,a)!==0&&S(`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 i=x(r,n);v()._OrtAppendExecutionProvider(t,i)!==0&&S(`Can't append execution provider: ${r}.`)}},er=t=>{let e=v(),n=0,o=[],r=t||{};Nr(r);try{let i=kr(r.graphOptimizationLevel??"all"),s=Fr(r.executionMode??"sequential"),f=typeof r.logId=="string"?x(r.logId,o):0,a=r.logSeverityLevel??2;if(!Number.isInteger(a)||a<0||a>4)throw new Error(`log serverity level is not valid: ${a}`);let u=r.logVerbosityLevel??0;if(!Number.isInteger(u)||u<0||u>4)throw new Error(`log verbosity level is not valid: ${u}`);let l=typeof r.optimizedModelFilePath=="string"?x(r.optimizedModelFilePath,o):0;if(n=e._OrtCreateSessionOptions(i,!!r.enableCpuMemArena,!!r.enableMemPattern,s,!!r.enableProfiling,0,f,a,u,l),n===0&&S("Can't create session options."),r.executionProviders&&Wr(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 d=x("enableGraphCapture",o),c=x(r.enableGraphCapture.toString(),o);e._OrtAddSessionConfigEntry(n,d,c)!==0&&S(`Can't set a session config entry: 'enableGraphCapture' - ${r.enableGraphCapture}.`)}if(r.freeDimensionOverrides)for(let[d,c]of Object.entries(r.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 m=x(d,o);e._OrtAddFreeDimensionOverride(n,m,c)!==0&&S(`Can't set a free dimension override: ${d} - ${c}.`)}return r.extra!==void 0&&ue(r.extra,"",new WeakSet,(d,c)=>{let m=x(d,o),p=x(c,o);e._OrtAddSessionConfigEntry(n,m,p)!==0&&S(`Can't set a session config entry: ${d} - ${c}.`)}),[n,o]}catch(i){throw n!==0&&e._OrtReleaseSessionOptions(n),o.forEach(s=>e._free(s)),i}}});var fe,rr,ce,nr,or,ke,Fe,sr,tt=w(()=>{"use strict";fe=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}`)}},rr=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}`)}},ce=(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,i)=>r*i,1);return n>0?Math.ceil(o*n):void 0},nr=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}`)}},or=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}`)}},ke=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint8"||t==="bool"||t==="uint4"||t==="int4",Fe=t=>t==="float32"||t==="float16"||t==="int32"||t==="int64"||t==="uint32"||t==="uint64"||t==="int8"||t==="uint8"||t==="bool",sr=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;case"ml-tensor":return 5;default:throw new Error(`unsupported data location: ${t}`)}}});var de,rt=w(()=>{"use strict";xe();de=async t=>{if(typeof t=="string")if(!1)try{let{readFile:e}=je("node:fs/promises");return new Uint8Array(await e(t))}catch(e){if(e.code==="ERR_FS_FILE_TOO_LARGE"){let{createReadStream:n}=je("node:fs"),o=n(t),r=[];for await(let i of o)r.push(i);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(),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 r.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 $r,Ie,Le,Z,zr,ae,Be,Ce,ir,Me,Ue,De,Qe=w(()=>{"use strict";Zt();tr();tt();Y();_e();rt();$r=(t,e)=>{v()._OrtInit(t,e)!==0&&S("Can't initialize onnxruntime.")},Ie=async t=>{$r(t.wasm.numThreads,or(t.logLevel))},Le=async(t,e)=>{},Z=new Map,zr=t=>{let e=v(),n=e.stackSave();try{let o=e.stackAlloc(8);return e._OrtGetInputOutputCount(t,o,o+4)!==0&&S("Can't get session input/output count."),[e.HEAP32[o/4],e.HEAP32[o/4+1]]}finally{e.stackRestore(n)}},ae=t=>{let e=v(),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]},Be=async(t,e)=>{let n,o,r=v();Array.isArray(t)?[n,o]=t:t.buffer===r.HEAPU8.buffer?[n,o]=[t.byteOffset,t.byteLength]:[n,o]=ae(t);let i=0,s=0,f=0,a=[],u=[],l=[];try{if([s,a]=er(e),e?.externalData&&r.mountExternalData){let y=[];for(let b of e.externalData){let A=typeof b=="string"?b:b.path;y.push(de(typeof b=="string"?b:b.data).then(M=>{r.mountExternalData(A,M)}))}await Promise.all(y)}for(let y of e?.executionProviders??[])if((typeof y=="string"?y:y.name)==="webnn"){if(r.shouldTransferToMLTensor=!1,r.currentContext)throw new Error("WebNN execution provider is already set.");if(typeof y!="string"){let A=y,M=A?.context,re=A?.gpuDevice,pe=A?.deviceType,ne=A?.numThreads,me=A?.powerPreference;M?r.currentContext=M:re?r.currentContext=await navigator.ml.createContext(re):r.currentContext=await navigator.ml.createContext({deviceType:pe,numThreads:ne,powerPreference:me})}else r.currentContext=await navigator.ml.createContext();break}i=await r._OrtCreateSession(n,o,s),i===0&&S("Can't create a session."),r.currentContext&&(r.jsepRegisterMLContext(i,r.currentContext),r.currentContext=void 0,r.shouldTransferToMLTensor=!0);let[d,c]=zr(i),m=!!e?.enableGraphCapture,p=[],h=[],T=[];for(let y=0;y<d;y++){let b=r._OrtGetInputName(i,y);b===0&&S("Can't get an input name."),u.push(b),p.push(r.UTF8ToString(b))}for(let y=0;y<c;y++){let b=r._OrtGetOutputName(i,y);b===0&&S("Can't get an output name."),l.push(b);let A=r.UTF8ToString(b);h.push(A)}let O=null;return Z.set(i,[i,u,l,O,m,!1]),[i,p,h]}catch(d){throw u.forEach(c=>r._OrtFree(c)),l.forEach(c=>r._OrtFree(c)),f!==0&&r._OrtReleaseBinding(f),i!==0&&r._OrtReleaseSession(i),d}finally{r._free(n),s!==0&&r._OrtReleaseSessionOptions(s),a.forEach(d=>r._free(d)),r.unmountExternalData?.()}},Ce=t=>{let e=v(),n=Z.get(t);if(!n)throw new Error(`cannot release session. invalid session id: ${t}`);let[o,r,i,s,f]=n;s&&(f&&e._OrtClearBoundOutputs(s.handle),e._OrtReleaseBinding(s.handle)),e.jsepOnReleaseSession?.(t),r.forEach(a=>e._OrtFree(a)),i.forEach(a=>e._OrtFree(a)),e._OrtReleaseSession(o),Z.delete(t)},ir=(t,e,n,o,r,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"||u==="ml-tensor"))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 ${r} when enableGraphCapture is true.`);if(u==="gpu-buffer"){let p=t[2].gpuBuffer;d=ce(fe(f),a);let h=s.jsepRegisterBuffer;if(!h)throw new Error('Tensor location "gpu-buffer" is not supported without using WebGPU.');l=h(o,r,p,d)}else if(u==="ml-tensor"){let p=t[2].mlTensor;d=ce(fe(f),a);let h=s.jsepRegisterMLTensor;if(!h)throw new Error('Tensor location "ml-tensor" is not supported without using WebNN.');l=h(p,fe(f),a)}else{let p=t[2];if(Array.isArray(p)){d=4*p.length,l=s._malloc(d),n.push(l);let h=l/4;for(let T=0;T<p.length;T++){if(typeof p[T]!="string")throw new TypeError(`tensor data at index ${T} is not a string`);s.HEAPU32[h++]=x(p[T],n)}}else d=p.byteLength,l=s._malloc(d),n.push(l),s.HEAPU8.set(new Uint8Array(p.buffer,p.byteOffset,d),l)}let c=s.stackSave(),m=s.stackAlloc(4*a.length);try{let p=m/4;a.forEach(T=>s.HEAP32[p++]=T);let h=s._OrtCreateTensor(fe(f),l,d,m,a.length,sr(u));h===0&&S(`Can't create tensor for input/output. session=${o}, index=${r}.`),e.push(h)}finally{s.stackRestore(c)}},Me=async(t,e,n,o,r,i)=>{let s=v(),f=Z.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],m=f[5],p=e.length,h=o.length,T=0,O=[],y=[],b=[],A=[],M=s.stackSave(),re=s.stackAlloc(p*4),pe=s.stackAlloc(p*4),ne=s.stackAlloc(h*4),me=s.stackAlloc(h*4);try{s.jsepOnRunStart?.(a),[T,O]=Qt(i);for(let g=0;g<p;g++)ir(n[g],y,A,t,e[g],c);for(let g=0;g<h;g++)ir(r[g],b,A,t,p+o[g],c);let k=re/4,gr=pe/4,Er=ne/4,Tr=me/4;for(let g=0;g<p;g++)s.HEAPU32[k++]=y[g],s.HEAPU32[gr++]=u[e[g]];for(let g=0;g<h;g++)s.HEAPU32[Er++]=b[g],s.HEAPU32[Tr++]=l[o[g]];let it;it=await s._OrtRun(a,pe,re,p,me,h,ne,T),it!==0&&S("failed to call OrtRun().");let X=[];for(let g=0;g<h;g++){let K=s.HEAPU32[ne/4+g];if(K===b[g]){X.push(r[g]);continue}let at=s.stackSave(),$=s.stackAlloc(4*4),oe=!1,L,D=0;try{s._OrtGetTensorData(K,$,$+4,$+8,$+12)!==0&&S(`Can't access output tensor data on index ${g}.`);let he=$/4,ye=s.HEAPU32[he++];D=s.HEAPU32[he++];let ut=s.HEAPU32[he++],Sr=s.HEAPU32[he++],z=[];for(let B=0;B<Sr;B++)z.push(s.HEAPU32[ut/4+B]);s._OrtFree(ut);let G=z.reduce((B,C)=>B*C,1);L=rr(ye);let we=d?.outputPreferredLocations[o[g]];if(L==="string"){if(we==="gpu-buffer"||we==="ml-tensor")throw new Error("String tensor is not supported on GPU.");let B=[],C=D/4;for(let F=0;F<G;F++){let ft=s.HEAPU32[C++],Ar=F===G-1?void 0:s.HEAPU32[C]-ft;B.push(s.UTF8ToString(ft,Ar))}X.push([L,z,B,"cpu"])}else if(we==="gpu-buffer"&&G>0){let B=s.jsepGetBuffer;if(!B)throw new Error('preferredLocation "gpu-buffer" is not supported without using WebGPU.');let C=B(D),F=ce(ye,G);if(F===void 0||!ke(L))throw new Error(`Unsupported data type: ${L}`);oe=!0,X.push([L,z,{gpuBuffer:C,download:s.jsepCreateDownloader(C,F,L),dispose:()=>{s._OrtReleaseTensor(K)}},"gpu-buffer"])}else if(we==="ml-tensor"&&G>0){let B=s.jsepEnsureTensor;if(!B)throw new Error('preferredLocation "ml-tensor" is not supported without using WebNN.');if(ce(ye,G)===void 0||!Fe(L))throw new Error(`Unsupported data type: ${L}`);let F=await B(D,ye,z,!1);oe=!0,X.push([L,z,{mlTensor:F,download:s.jsepCreateMLTensorDownloader(D,L),dispose:()=>{s.jsepReleaseTensorId(D),s._OrtReleaseTensor(K)}},"ml-tensor"])}else{let B=nr(L),C=new B(G);new Uint8Array(C.buffer,C.byteOffset,C.byteLength).set(s.HEAPU8.subarray(D,D+C.byteLength)),X.push([L,z,C,"cpu"])}}finally{s.stackRestore(at),L==="string"&&D&&s._free(D),oe||s._OrtReleaseTensor(K)}}return d&&!c&&(s._OrtClearBoundOutputs(d.handle),Z.set(t,[a,u,l,d,c,!1])),X}finally{s.stackRestore(M),y.forEach(k=>s._OrtReleaseTensor(k)),b.forEach(k=>s._OrtReleaseTensor(k)),A.forEach(k=>s._free(k)),T!==0&&s._OrtReleaseRunOptions(T),O.forEach(k=>s._free(k))}},Ue=t=>{let e=v(),n=Z.get(t);if(!n)throw new Error("invalid session id");let o=n[0],r=e._OrtEndProfiling(o);r===0&&S("Can't get an profile file name."),e._OrtFree(r)},De=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 J,_,le,We,$e,Ne,nt,ot,ee,te,Hr,ar,ur,fr,cr,dr,lr,pr,st=w(()=>{"use strict";V();Qe();Y();ie();J=()=>!!E.wasm.proxy&&typeof document<"u",le=!1,We=!1,$e=!1,ot=new Map,ee=(t,e)=>{let n=ot.get(t);n?n.push(e):ot.set(t,[e])},te=()=>{if(le||!We||$e||!_)throw new Error("worker not ready")},Hr=t=>{switch(t.data.type){case"init-wasm":le=!1,t.data.err?($e=!0,nt[1](t.data.err)):(We=!0,nt[0]()),Ne&&(URL.revokeObjectURL(Ne),Ne=void 0);break;case"init-ep":case"copy-from":case"create":case"release":case"run":case"end-profiling":{let e=ot.get(t.data.type);t.data.err?e.shift()[1](t.data.err):e.shift()[0](t.data.out);break}default:}},ar=async()=>{if(!We){if(le)throw new Error("multiple calls to 'initWasm()' detected.");if($e)throw new Error("previous call to 'initWasm()' failed.");if(le=!0,J())return new Promise((t,e)=>{_?.terminate(),Jt().then(([n,o])=>{try{_=o,_.onerror=i=>e(i),_.onmessage=Hr,nt=[t,e];let r={type:"init-wasm",in:E};_.postMessage(r),Ne=n}catch(r){e(r)}},e)});try{await Pe(E.wasm),await Ie(E),We=!0}catch(t){throw $e=!0,t}finally{le=!1}}},ur=async t=>{if(J())return te(),new Promise((e,n)=>{ee("init-ep",[e,n]);let o={type:"init-ep",in:{epName:t,env:E}};_.postMessage(o)});await Le(E,t)},fr=async t=>J()?(te(),new Promise((e,n)=>{ee("copy-from",[e,n]);let o={type:"copy-from",in:{buffer:t}};_.postMessage(o,[t.buffer])})):ae(t),cr=async(t,e)=>{if(J()){if(e?.preferredOutputLocation)throw new Error('session option "preferredOutputLocation" is not supported for proxy.');return te(),new Promise((n,o)=>{ee("create",[n,o]);let r={type:"create",in:{model:t,options:{...e}}},i=[];t instanceof Uint8Array&&i.push(t.buffer),_.postMessage(r,i)})}else return Be(t,e)},dr=async t=>{if(J())return te(),new Promise((e,n)=>{ee("release",[e,n]);let o={type:"release",in:t};_.postMessage(o)});Ce(t)},lr=async(t,e,n,o,r,i)=>{if(J()){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 te(),new Promise((s,f)=>{ee("run",[s,f]);let a=n,u={type:"run",in:{sessionId:t,inputIndices:e,inputs:a,outputIndices:o,options:i}};_.postMessage(u,De(a))})}else return Me(t,e,n,o,r,i)},pr=async t=>{if(J())return te(),new Promise((e,n)=>{ee("end-profiling",[e,n]);let o={type:"end-profiling",in:t};_.postMessage(o)});Ue(t)}});var mr,jr,ze,hr=w(()=>{"use strict";V();st();tt();xe();rt();mr=(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"];case"ml-tensor":return[t.type,t.dims,{mlTensor:t.mlTensor},"ml-tensor"];default:throw new Error(`invalid data location: ${t.location} for ${e()}`)}},jr=t=>{switch(t[3]){case"cpu":return new P(t[0],t[2],t[1]);case"gpu-buffer":{let e=t[0];if(!ke(e))throw new Error(`not supported data type: ${e} for deserializing GPU tensor`);let{gpuBuffer:n,download:o,dispose:r}=t[2];return P.fromGpuBuffer(n,{dataType:e,dims:t[1],download:o,dispose:r})}case"ml-tensor":{let e=t[0];if(!Fe(e))throw new Error(`not supported data type: ${e} for deserializing MLTensor tensor`);let{mlTensor:n,download:o,dispose:r}=t[2];return P.fromMLTensor(n,{dataType:e,dims:t[1],download:o,dispose:r})}default:throw new Error(`invalid data location: ${t[3]}`)}},ze=class{async fetchModelAndCopyToWasmMemory(e){return fr(await de(e))}async loadModel(e,n){N();let o;typeof e=="string"?!1?o=await de(e):o=await this.fetchModelAndCopyToWasmMemory(e):o=e,[this.sessionId,this.inputNames,this.outputNames]=await cr(o,n),W()}async dispose(){return dr(this.sessionId)}async run(e,n,o){N();let r=[],i=[];Object.entries(e).forEach(c=>{let m=c[0],p=c[1],h=this.inputNames.indexOf(m);if(h===-1)throw new Error(`invalid input '${m}'`);r.push(p),i.push(h)});let s=[],f=[];Object.entries(n).forEach(c=>{let m=c[0],p=c[1],h=this.outputNames.indexOf(m);if(h===-1)throw new Error(`invalid output '${m}'`);s.push(p),f.push(h)});let a=r.map((c,m)=>mr(c,()=>`input "${this.inputNames[i[m]]}"`)),u=s.map((c,m)=>c?mr(c,()=>`output "${this.outputNames[f[m]]}"`):null),l=await lr(this.sessionId,i,a,f,u,o),d={};for(let c=0;c<l.length;c++)d[this.outputNames[f[c]]]=s[c]??jr(l[c]);return W(),d}startProfiling(){}endProfiling(){pr(this.sessionId)}}});var wr={};be(wr,{OnnxruntimeWebAssemblyBackend:()=>Ge,initializeFlags:()=>yr,wasmBackend:()=>Vr});var yr,Ge,Vr,br=w(()=>{"use strict";V();st();hr();ie();yr=()=>{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"?je("node:os").cpus().length:navigator.hardwareConcurrency;E.wasm.numThreads=Math.min(4,Math.ceil((t||1)/2))}E.wasm.wasmPaths===void 0&&R&&R.indexOf("blob:")!==0&&(E.wasm.wasmPaths=R.substring(0,R.lastIndexOf("/")+1))},Ge=class{async init(e){yr(),await ar(),await ur(e)}async createInferenceSessionHandler(e,n){let o=new ze;return await o.loadModel(e,n),Promise.resolve(o)}},Vr=new Ge});var qr={};be(qr,{InferenceSession:()=>Mt,TRACE:()=>Je,TRACE_FUNC_BEGIN:()=>N,TRACE_FUNC_END:()=>W,Tensor:()=>P,TrainingSession:()=>Nt,default:()=>Yr,env:()=>E,registerBackend:()=>Q});V();V();V();var $t="1.20.0-dev.20241010-1bc546af61";var Yr=Ke;{let t=(br(),Ve(wr)).wasmBackend;Q("cpu",t,10),Q("wasm",t,10)}Object.defineProperty(E.versions,"web",{value:$t,enumerable:!0});return Ve(qr);})(); | ||
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.20241009-9ee963110e'; | ||
export const version = '1.20.0-dev.20241010-1bc546af61'; |
@@ -10,3 +10,3 @@ { | ||
"author": "fs-eire", | ||
"version": "1.20.0-dev.20241009-9ee963110e", | ||
"version": "1.20.0-dev.20241010-1bc546af61", | ||
"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 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95655186