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