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

onnxruntime-web

Package Overview
Dependencies
Maintainers
3
Versions
263
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

onnxruntime-web - npm Package Compare versions

Comparing version 1.21.0-dev.20241106-742a0d30be to 1.21.0-dev.20241107-6a295eb75b

2

__commit.txt

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

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

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

ComputeContext,
DeviceInfo,
GpuArchitecture,

@@ -138,2 +139,22 @@ GpuData,

class DeviceInfoImpl implements DeviceInfo {
readonly subgroupsSupported: boolean;
readonly subgroupsF16Supported: boolean;
readonly subgroupSizeRange?: readonly [number, number];
constructor(device: GPUDevice) {
this.subgroupsSupported = device.features.has('subgroups' as GPUFeatureName);
this.subgroupsF16Supported = device.features.has('subgroups' as GPUFeatureName);
// Currently subgroups feature is still experimental and size attributes are not in the WebGPU IDL, so we have to
// workaround the IDL type checks.
// TODO: clean this after subgroups feature is settled in IDL.
const deviceSubgroupsLimits = device.limits as { minSubgroupSize?: number; maxSubgroupSize?: number };
if (!this.subgroupsSupported || !deviceSubgroupsLimits.minSubgroupSize || !deviceSubgroupsLimits.maxSubgroupSize) {
this.subgroupSizeRange = undefined;
} else {
this.subgroupSizeRange = [deviceSubgroupsLimits.minSubgroupSize, deviceSubgroupsLimits.maxSubgroupSize];
}
}
}
/**

@@ -146,2 +167,3 @@ * this class is designed to store status and being used as a singleton for JSEP. It will be passed to jsepInit() as

device: GPUDevice;
deviceInfo: DeviceInfoImpl;
/**

@@ -249,12 +271,18 @@ * an instance of GpuDataManager to manage a GpuDataId -> GpuBuffer mapping

if (adapter.features.has('chromium-experimental-timestamp-query-inside-passes')) {
requiredFeatures.push('chromium-experimental-timestamp-query-inside-passes' as GPUFeatureName);
} else if (adapter.features.has('timestamp-query')) {
requiredFeatures.push('timestamp-query');
// Try requiring WebGPU features
const requireFeatureIfAvailable = (feature: GPUFeatureName) =>
adapter.features.has(feature) && requiredFeatures.push(feature) && true;
// Try chromium-experimental-timestamp-query-inside-passes and fallback to timestamp-query
if (!requireFeatureIfAvailable('chromium-experimental-timestamp-query-inside-passes' as GPUFeatureName)) {
requireFeatureIfAvailable('timestamp-query');
}
if (adapter.features.has('shader-f16')) {
requiredFeatures.push('shader-f16');
requireFeatureIfAvailable('shader-f16');
// Try subgroups
if (requireFeatureIfAvailable('subgroups' as GPUFeatureName)) {
// If subgroups feature is available, also try subgroups-f16
requireFeatureIfAvailable('subgroups-f16' as GPUFeatureName);
}
this.device = await adapter.requestDevice(deviceDescriptor);
this.deviceInfo = new DeviceInfoImpl(this.device);
this.adapterInfo = new AdapterInfoImpl(adapter.info || (await adapter.requestAdapterInfo()));

@@ -261,0 +289,0 @@ this.gpuDataManager = createGpuDataManager(this);

@@ -14,3 +14,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved.

import { ShapeUtil } from './util';
import { AdapterInfo, ComputeContext, ComputeContextInputsOutputsMapping, ProgramInfo } from './webgpu/types';
import {
AdapterInfo,
ComputeContext,
ComputeContextInputsOutputsMapping,
DeviceInfo,
ProgramInfo,
} from './webgpu/types';
import { WebNNBackend } from './backend-webnn';

@@ -74,2 +80,3 @@

readonly adapterInfo: AdapterInfo;
readonly deviceInfo: DeviceInfo;
readonly opKernelContext: number;

@@ -92,2 +99,3 @@ readonly inputs: readonly TensorView[];

this.adapterInfo = backend.adapterInfo;
this.deviceInfo = backend.deviceInfo;

@@ -118,14 +126,2 @@ // extract context data

getMaxComputeWorkgroupSizes(): [number, number, number] {
return [
this.backend.device.limits.maxComputeWorkgroupSizeX,
this.backend.device.limits.maxComputeWorkgroupSizeY,
this.backend.device.limits.maxComputeWorkgroupSizeZ,
];
}
getMaxComputeWorkgroupStoragesize(): number {
return this.backend.device.limits.maxComputeWorkgroupStorageSize;
}
compute(program: ProgramInfo, inputsOutputsMapping?: ComputeContextInputsOutputsMapping): TensorView[] {

@@ -132,0 +128,0 @@ // prepare inputs. inputs should always be valid data.

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

// pending buffers for uploading ( data is unmapped )
private buffersForUploadingPending: GPUBuffer[];
// pending buffers for computing

@@ -216,3 +214,2 @@ private buffersPending: GPUBuffer[];

this.freeUniformBuffers = new Map();
this.buffersForUploadingPending = [];
this.buffersPending = [];

@@ -257,9 +254,8 @@ this.capturedPendingBuffers = new Map();

// GPU copy
const commandEncoder = this.backend.getCommandEncoder();
this.backend.endComputePass();
const commandEncoder = this.backend.device.createCommandEncoder();
commandEncoder.copyBufferToBuffer(gpuBufferForUploading, 0, gpuDataCache.gpuData.buffer, 0, size);
this.backend.device.queue.submit([commandEncoder.finish()]);
gpuBufferForUploading.destroy();
LOG_DEBUG('verbose', () => `[WebGPU] GpuDataManager.upload(id=${id})`);
this.buffersForUploadingPending.push(gpuBufferForUploading);
}

@@ -401,8 +397,2 @@

refreshPendingBuffers(): void {
for (const buffer of this.buffersForUploadingPending) {
// upload buffer is only useful in the session creation time. So we don't need to reuse them in session running.
buffer.destroy();
}
this.buffersForUploadingPending = [];
if (this.buffersPending.length === 0) {

@@ -409,0 +399,0 @@ return;

@@ -96,9 +96,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved.

const device = this.backend.device;
const extensions: string[] = [];
if (device.features.has('shader-f16')) {
extensions.push('enable f16;');
}
const enableDirectives: string[] = [];
// Enable WGSL extensions based on available WebGPU features
const extensionsInfo: Array<{ feature: GPUFeatureName; extension: string }> = [
{ feature: 'shader-f16', extension: 'f16' },
{ feature: 'subgroups' as GPUFeatureName, extension: 'subgroups' },
{ feature: 'subgroups-f16' as GPUFeatureName, extension: 'subgroups_f16' },
];
extensionsInfo.forEach((info) => {
if (device.features.has(info.feature)) {
enableDirectives.push(`enable ${info.extension};`);
}
});
const shaderHelper = createShaderHelper(normalizedDispatchGroupSize, this.backend.device.limits);
const userCode = programInfo.getShaderSource(shaderHelper);
const code = `${extensions.join('\n')}\n${shaderHelper.additionalImplementations}\n${userCode}`;
const code = `${enableDirectives.join('\n')}\n${shaderHelper.additionalImplementations}\n${userCode}`;
const shaderModule = device.createShaderModule({ code, label: programInfo.name });

@@ -105,0 +115,0 @@ LOG_DEBUG('verbose', () => `[WebGPU] ${programInfo.name} shader code: ${code}`);

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

}
export interface DeviceInfo {
readonly subgroupsSupported: boolean;
readonly subgroupsF16Supported: boolean;
readonly subgroupSizeRange?: readonly [number, number];
}

@@ -165,2 +170,7 @@ export interface GpuData {

/**
* gpu device info
*/
readonly deviceInfo: DeviceInfo;
/**
* stores the pointer to OpKernelContext

@@ -192,6 +202,4 @@ */

output(index: number, dims: readonly number[]): number;
getMaxComputeWorkgroupSizes(): [number, number, number];
getMaxComputeWorkgroupStoragesize(): number;
}
export type TimestampQuery = 'none' | 'inside-passes' | 'at-passes';

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

/**
* Map from MLOperandDataType to size in bits. Using bits instead of bytes to avoid possible precision loss on int4 and uint4.
*/
const webnnDataTypeToSize = new Map<MLOperandDataType, number>([
['float32', 32],
['float16', 16],
['int32', 32],
['uint32', 32],
['int64', 64],
['uint64', 64],
['int8', 8],
['uint8', 8],
['int4', 4],
['uint4', 4],
]);
/**
* Calculate the byte length of a tensor with the given data type and shape.
*/
const calculateByteLength = (dataType: MLOperandDataType, shape: readonly number[]): number => {
const size = webnnDataTypeToSize.get(dataType);
if (!size) {
throw new Error('Unsupported data type.');
}
return Math.ceil((shape.reduce((a, b) => a * b) * size) / 8);
};
/**
* TensorWrapper wraps an MLTensor and provides a way to track the last session that used it.

@@ -96,2 +123,6 @@ */

public get byteLength(): number {
return calculateByteLength(this.dataType, this.tensorShape);
}
public destroy(): void {

@@ -116,3 +147,7 @@ LOG_DEBUG('verbose', () => '[WebNN] TensorWrapper.destroy');

public sameTypeAndShape(dataType: MLOperandDataType, shape: readonly number[]): boolean {
return this.dataType === dataType && this.tensorShape.every((v, i) => v === shape[i]);
return (
this.dataType === dataType &&
this.tensorShape.length === shape.length &&
this.tensorShape.every((v, i) => v === shape[i])
);
}

@@ -142,2 +177,3 @@ }

this.tensorManager.releaseTensor(this.tensorWrapper);
this.wrapper = undefined;
}

@@ -156,2 +192,5 @@ }

if (copyOld) {
if (this.wrapper.byteLength !== calculateByteLength(dataType, shape)) {
throw new Error('Unable to copy data to tensor with different size.');
}
this.activeUpload = new Uint8Array(await this.wrapper.read());

@@ -177,4 +216,9 @@ }

if (this.wrapper) {
this.wrapper.write(data);
return;
if (data.byteLength === this.wrapper.byteLength) {
this.wrapper.write(data);
return;
} else {
LOG_DEBUG('verbose', () => 'Data size does not match tensor size. Releasing tensor.');
this.releaseTensor();
}
}

@@ -321,2 +365,3 @@

if (tensor.sameTypeAndShape(dataType, shape)) {
LOG_DEBUG('verbose', () => `[WebNN] Reusing tensor {dataType: ${dataType}, shape: ${shape}}`);
const wrapper = this.freeTensors.splice(index, 1)[0];

@@ -323,0 +368,0 @@ wrapper.sessionId = sessionId;

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

"author": "fs-eire",
"version": "1.21.0-dev.20241106-742a0d30be",
"version": "1.21.0-dev.20241107-6a295eb75b",
"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 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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc