kokoro-js
Version:
High-quality text-to-speech for the web
1 lines • 2.14 MB
JavaScript
const e=new Map,A=[],t=async A=>{const t=e.get(A);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{const e=!!t.initPromise;try{return e||(t.initPromise=t.backend.init(A)),await t.initPromise,t.initialized=!0,t.backend}catch(A){return e||(t.error=`${A}`,t.aborted=!0),t.error}finally{delete t.initPromise}}};let r="warning";const n={wasm:{},webgl:{},webgpu:{},versions:{common:"1.21.0"},set logLevel(e){if(void 0!==e){if("string"!=typeof e||-1===["verbose","info","warning","error","fatal"].indexOf(e))throw new Error(`Unsupported logging level: ${e}`);r=e}},get logLevel(){return r}};Object.defineProperty(n,"logLevel",{enumerable:!0});const a=n,s=(e,A)=>{if(void 0===e)throw new Error("Image buffer must be defined");if(void 0===A.height||void 0===A.width)throw new Error("Image height and width must be defined");if("NHWC"===A.tensorLayout)throw new Error("NHWC Tensor layout is not supported yet");const{height:t,width:r}=A,n=A.norm??{mean:255,bias:0};let a,s;a="number"==typeof n.mean?[n.mean,n.mean,n.mean,n.mean]:[n.mean[0],n.mean[1],n.mean[2],n.mean[3]??255],s="number"==typeof n.bias?[n.bias,n.bias,n.bias,n.bias]:[n.bias[0],n.bias[1],n.bias[2],n.bias[3]??0];const i=void 0!==A.format?A.format:"RGBA",o=void 0!==A.tensorFormat&&void 0!==A.tensorFormat?A.tensorFormat:"RGB",l=t*r,g="RGBA"===o?new Float32Array(4*l):new Float32Array(3*l);let u=4,d=0,f=1,p=2,h=3,m=0,C=l,b=2*l,I=-1;"RGB"===i&&(u=3,d=0,f=1,p=2,h=-1),"RGBA"===o?I=3*l:"RBG"===o?(m=0,b=l,C=2*l):"BGR"===o&&(b=0,C=l,m=2*l);for(let A=0;A<l;A++,d+=u,p+=u,f+=u,h+=u)g[m++]=(e[d]+s[0])/a[0],g[C++]=(e[f]+s[1])/a[1],g[b++]=(e[p]+s[2])/a[2],-1!==I&&-1!==h&&(g[I++]=(e[h]+s[3])/a[3]);return new c("float32",g,"RGBA"===o?[1,4,t,r]:[1,3,t,r])},i=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),o=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]);let l=!1;let c=class{constructor(e,A,t){let r,n;if((()=>{if(!l){l=!0;const e="undefined"!=typeof BigInt64Array&&BigInt64Array.from,A="undefined"!=typeof BigUint64Array&&BigUint64Array.from,t=globalThis.Float16Array,r=void 0!==t&&t.from;e&&(i.set("int64",BigInt64Array),o.set(BigInt64Array,"int64")),A&&(i.set("uint64",BigUint64Array),o.set(BigUint64Array,"uint64")),r?(i.set("float16",t),o.set(t,"float16")):i.set("float16",Uint16Array)}})(),"object"==typeof e&&"location"in e)switch(this.dataLocation=e.location,r=e.type,n=e.dims,e.location){case"cpu-pinned":{const A=i.get(r);if(!A)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof A))throw new TypeError(`buffer should be of type ${A.name}`);this.cpuData=e.data;break}case"texture":if("float32"!==r)throw new TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break;case"gpu-buffer":if("float32"!==r&&"float16"!==r&&"int32"!==r&&"int64"!==r&&"uint32"!==r&&"uint8"!==r&&"bool"!==r&&"uint4"!==r&&"int4"!==r)throw new TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break;case"ml-tensor":if("float32"!==r&&"float16"!==r&&"int32"!==r&&"int64"!==r&&"uint32"!==r&&"uint64"!==r&&"int8"!==r&&"uint8"!==r&&"bool"!==r&&"uint4"!==r&&"int4"!==r)throw new TypeError(`unsupported type "${r}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break;default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let a,s;if("string"==typeof e)if(r=e,s=t,"string"===e){if(!Array.isArray(A))throw new TypeError("A string tensor's data must be a string array.");a=A}else{const t=i.get(e);if(void 0===t)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(A)){if("float16"===e&&t===Uint16Array||"uint4"===e||"int4"===e)throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${t.name} as data.`);a="uint64"===e||"int64"===e?t.from(A,BigInt):t.from(A)}else if(A instanceof t)a=A;else if(A instanceof Uint8ClampedArray){if("uint8"!==e)throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");a=Uint8Array.from(A)}else{if(!("float16"===e&&A instanceof Uint16Array&&t!==Uint16Array))throw new TypeError(`A ${r} tensor's data must be type of ${t}`);a=new globalThis.Float16Array(A.buffer,A.byteOffset,A.length)}}else if(s=A,Array.isArray(e)){if(0===e.length)throw new TypeError("Tensor type cannot be inferred from an empty array.");const A=typeof e[0];if("string"===A)r="string",a=e;else{if("boolean"!==A)throw new TypeError(`Invalid element type of data array: ${A}.`);r="bool",a=Uint8Array.from(e)}}else if(e instanceof Uint8ClampedArray)r="uint8",a=Uint8Array.from(e);else{const A=o.get(e.constructor);if(void 0===A)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=A,a=e}if(void 0===s)s=[a.length];else if(!Array.isArray(s))throw new TypeError("A tensor's dims must be a number array");n=s,this.cpuData=a,this.dataLocation="cpu"}const a=(e=>{let A=1;for(let t=0;t<e.length;t++){const r=e[t];if("number"!=typeof r||!Number.isSafeInteger(r))throw new TypeError(`dims[${t}] must be an integer, got: ${r}`);if(r<0)throw new RangeError(`dims[${t}] must be a non-negative integer, got: ${r}`);A*=r}return A})(n);if(this.cpuData&&a!==this.cpuData.length&&("uint4"!==r&&"int4"!==r||Math.ceil(a/2)!==this.cpuData.length))throw new Error(`Tensor's size(${a}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=n,this.size=a}static async fromImage(e,A){return(async(e,A)=>{const t="undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement,r="undefined"!=typeof ImageData&&e instanceof ImageData,n="undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap,a="string"==typeof e;let i,o=A??{};const l=()=>{if("undefined"!=typeof document)return document.createElement("canvas");if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},c=e=>"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext("2d"):null;if(t){const t=l();t.width=e.width,t.height=e.height;const r=c(t);if(null==r)throw new Error("Can not access image data");{let t=e.height,n=e.width;if(void 0!==A&&void 0!==A.resizedHeight&&void 0!==A.resizedWidth&&(t=A.resizedHeight,n=A.resizedWidth),void 0!==A){if(o=A,void 0!==A.tensorFormat)throw new Error("Image input config format must be RGBA for HTMLImageElement");o.tensorFormat="RGBA",o.height=t,o.width=n}else o.tensorFormat="RGBA",o.height=t,o.width=n;r.drawImage(e,0,0),i=r.getImageData(0,0,n,t).data}}else{if(!r){if(n){if(void 0===A)throw new Error("Please provide image config with format for Imagebitmap");const t=l();t.width=e.width,t.height=e.height;const r=c(t);if(null!=r){const A=e.height,t=e.width;return r.drawImage(e,0,0,t,A),i=r.getImageData(0,0,t,A).data,o.height=A,o.width=t,s(i,o)}throw new Error("Can not access image data")}if(a)return new Promise(((A,t)=>{const r=l(),n=c(r);if(!e||!n)return t();const a=new Image;a.crossOrigin="Anonymous",a.src=e,a.onload=()=>{r.width=a.width,r.height=a.height,n.drawImage(a,0,0,r.width,r.height);const e=n.getImageData(0,0,r.width,r.height);o.height=r.height,o.width=r.width,A(s(e.data,o))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{let t,r;if(void 0!==A&&void 0!==A.resizedWidth&&void 0!==A.resizedHeight?(t=A.resizedHeight,r=A.resizedWidth):(t=e.height,r=e.width),void 0!==A&&(o=A),o.format="RGBA",o.height=t,o.width=r,void 0!==A){const A=l();A.width=r,A.height=t;const n=c(A);if(null==n)throw new Error("Can not access image data");n.putImageData(e,0,0),i=n.getImageData(0,0,r,t).data}else i=e.data}}if(void 0!==i)return s(i,o);throw new Error("Input data provided is not supported - aborted tensor creation")})(e,A)}static fromTexture(e,A){return((e,A)=>{const{width:t,height:r,download:n,dispose:a}=A;return new c({location:"texture",type:"float32",texture:e,dims:[1,r,t,4],download:n,dispose:a})})(e,A)}static fromGpuBuffer(e,A){return((e,A)=>{const{dataType:t,dims:r,download:n,dispose:a}=A;return new c({location:"gpu-buffer",type:t??"float32",gpuBuffer:e,dims:r,download:n,dispose:a})})(e,A)}static fromMLTensor(e,A){return((e,A)=>{const{dataType:t,dims:r,download:n,dispose:a}=A;return new c({location:"ml-tensor",type:t??"float32",mlTensor:e,dims:r,download:n,dispose:a})})(e,A)}static fromPinnedBuffer(e,A,t){return((e,A,t)=>new c({location:"cpu-pinned",type:e,data:A,dims:t??[A.length]}))(e,A,t)}toDataURL(e){return((e,A)=>{const t="undefined"!=typeof document?document.createElement("canvas"):new OffscreenCanvas(1,1);t.width=e.dims[3],t.height=e.dims[2];const r=t.getContext("2d");if(null!=r){let n,a;void 0!==A?.tensorLayout&&"NHWC"===A.tensorLayout?(n=e.dims[2],a=e.dims[3]):(n=e.dims[3],a=e.dims[2]);const s=void 0!==A?.format?A.format:"RGB",i=A?.norm;let o,l;void 0===i||void 0===i.mean?o=[255,255,255,255]:"number"==typeof i.mean?o=[i.mean,i.mean,i.mean,i.mean]:(o=[i.mean[0],i.mean[1],i.mean[2],0],void 0!==i.mean[3]&&(o[3]=i.mean[3])),void 0===i||void 0===i.bias?l=[0,0,0,0]:"number"==typeof i.bias?l=[i.bias,i.bias,i.bias,i.bias]:(l=[i.bias[0],i.bias[1],i.bias[2],0],void 0!==i.bias[3]&&(l[3]=i.bias[3]));const c=a*n;let g=0,u=c,d=2*c,f=-1;"RGBA"===s?(g=0,u=c,d=2*c,f=3*c):"RGB"===s?(g=0,u=c,d=2*c):"RBG"===s&&(g=0,d=c,u=2*c);for(let A=0;A<a;A++)for(let t=0;t<n;t++){const n=(e.data[g++]-l[0])*o[0],a=(e.data[u++]-l[1])*o[1],s=(e.data[d++]-l[2])*o[2],i=-1===f?255:(e.data[f++]-l[3])*o[3];r.fillStyle="rgba("+n+","+a+","+s+","+i+")",r.fillRect(t,A,1,1)}if("toDataURL"in t)return t.toDataURL();throw new Error("toDataURL is not supported")}throw new Error("Can not access image data")})(this,e)}toImageData(e){return((e,A)=>{const t="undefined"!=typeof document?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d");let r;if(null==t)throw new Error("Can not access image data");{let n,a,s;void 0!==A?.tensorLayout&&"NHWC"===A.tensorLayout?(n=e.dims[2],a=e.dims[1],s=e.dims[3]):(n=e.dims[3],a=e.dims[2],s=e.dims[1]);const i=void 0!==A&&void 0!==A.format?A.format:"RGB",o=A?.norm;let l,c;void 0===o||void 0===o.mean?l=[255,255,255,255]:"number"==typeof o.mean?l=[o.mean,o.mean,o.mean,o.mean]:(l=[o.mean[0],o.mean[1],o.mean[2],255],void 0!==o.mean[3]&&(l[3]=o.mean[3])),void 0===o||void 0===o.bias?c=[0,0,0,0]:"number"==typeof o.bias?c=[o.bias,o.bias,o.bias,o.bias]:(c=[o.bias[0],o.bias[1],o.bias[2],0],void 0!==o.bias[3]&&(c[3]=o.bias[3]));const g=a*n;if(void 0!==A&&(void 0!==A.format&&4===s&&"RGBA"!==A.format||3===s&&"RGB"!==A.format&&"BGR"!==A.format))throw new Error("Tensor format doesn't match input tensor dims");const u=4;let d=0,f=1,p=2,h=3,m=0,C=g,b=2*g,I=-1;"RGBA"===i?(m=0,C=g,b=2*g,I=3*g):"RGB"===i?(m=0,C=g,b=2*g):"RBG"===i&&(m=0,b=g,C=2*g),r=t.createImageData(n,a);for(let A=0;A<a*n;d+=u,f+=u,p+=u,h+=u,A++)r.data[d]=(e.data[m++]-c[0])*l[0],r.data[f]=(e.data[C++]-c[1])*l[1],r.data[p]=(e.data[b++]-c[2])*l[2],r.data[h]=-1===I?255:(e.data[I++]-c[3])*l[3]}return r})(this,e)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;const A=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=A,e&&this.disposer&&(this.disposer(),this.disposer=void 0),A}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("none"===this.dataLocation)throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return((e,A)=>{switch(e.location){case"cpu":return new c(e.type,e.data,A);case"cpu-pinned":return new c({location:"cpu-pinned",data:e.data,type:e.type,dims:A});case"texture":return new c({location:"texture",texture:e.texture,type:e.type,dims:A});case"gpu-buffer":return new c({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:A});case"ml-tensor":return new c({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:A});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}})(this,e)}};const g=c,u=(e,A)=>{(void 0===n.trace?n.wasm.trace:n.trace)&&console.timeStamp(`${e}::ORT::${A}`)},d=(e,A)=>{const t=(new Error).stack?.split(/\r\n|\r|\n/g)||[];let r=!1;for(let n=0;n<t.length;n++){if(r&&!t[n].includes("TRACE_FUNC")){let r=`FUNC_${e}::${t[n].trim().split(" ")[1]}`;return A&&(r+=`::${A}`),void u("CPU",r)}t[n].includes("TRACE_FUNC")&&(r=!0)}},f=e=>{(void 0===n.trace?n.wasm.trace:n.trace)&&d("BEGIN",e)},p=e=>{(void 0===n.trace?n.wasm.trace:n.trace)&&d("END",e)};const h=class e{constructor(e){this.handler=e}async run(e,A,t){f();const r={};let n={};if("object"!=typeof e||null===e||e instanceof g||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if("object"==typeof A){if(null===A)throw new TypeError("Unexpected argument[1]: cannot be null.");if(A instanceof g)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(A)){if(0===A.length)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(const e of A){if("string"!=typeof e)throw new TypeError("'fetches' must be a string array or an object.");if(-1===this.outputNames.indexOf(e))throw new RangeError(`'fetches' contains invalid output name: ${e}.`);r[e]=null}if("object"==typeof t&&null!==t)n=t;else if(void 0!==t)throw new TypeError("'options' must be an object.")}else{let e=!1;const s=Object.getOwnPropertyNames(A);for(const t of this.outputNames)if(-1!==s.indexOf(t)){const n=A[t];(null===n||n instanceof g)&&(e=!0,a=!1,r[t]=n)}if(e){if("object"==typeof t&&null!==t)n=t;else if(void 0!==t)throw new TypeError("'options' must be an object.")}else n=A}}else if(void 0!==A)throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const A of this.inputNames)if(void 0===e[A])throw new Error(`input '${A}' is missing in 'feeds'.`);if(a)for(const e of this.outputNames)r[e]=null;const s=await this.handler.run(e,r,n),i={};for(const e in s)if(Object.hasOwnProperty.call(s,e)){const A=s[e];i[e]=A instanceof g?A:new g(A.type,A.data,A.dims)}return p(),i}async release(){return this.handler.dispose()}static async create(r,n,a,s){let i;f();let o={};if("string"==typeof r){if(i=r,"object"==typeof n&&null!==n)o=n;else if(void 0!==n)throw new TypeError("'options' must be an object.")}else if(r instanceof Uint8Array){if(i=r,"object"==typeof n&&null!==n)o=n;else if(void 0!==n)throw new TypeError("'options' must be an object.")}else{if(!(r instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&r instanceof SharedArrayBuffer))throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");{const e=r;let A=0,t=r.byteLength;if("object"==typeof n&&null!==n)o=n;else if("number"==typeof n){if(A=n,!Number.isSafeInteger(A))throw new RangeError("'byteOffset' must be an integer.");if(A<0||A>=e.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${e.byteLength}).`);if(t=r.byteLength-A,"number"==typeof a){if(t=a,!Number.isSafeInteger(t))throw new RangeError("'byteLength' must be an integer.");if(t<=0||A+t>e.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${e.byteLength-A}].`);if("object"==typeof s&&null!==s)o=s;else if(void 0!==s)throw new TypeError("'options' must be an object.")}else if(void 0!==a)throw new TypeError("'byteLength' must be a number.")}else if(void 0!==n)throw new TypeError("'options' must be an object.");i=new Uint8Array(e,A,t)}}const[l,c]=await(async e=>{const r=e.executionProviders||[],n=r.map((e=>"string"==typeof e?e:e.name)),a=0===n.length?A:n;let s;const i=[],o=new Set;for(const e of a){const A=await t(e);"string"==typeof A?i.push({name:e,err:A}):(s||(s=A),s===A&&o.add(e))}if(!s)throw new Error(`no available backend found. ERR: ${i.map((e=>`[${e.name}] ${e.err}`)).join(", ")}`);for(const{name:e,err:A}of i)n.includes(e)&&console.warn(`removing requested execution provider "${e}" from session options because it is not available: ${A}`);const l=r.filter((e=>o.has("string"==typeof e?e:e.name)));return[s,new Proxy(e,{get:(e,A)=>"executionProviders"===A?l:Reflect.get(e,A)})]})(o),g=await l.createInferenceSessionHandler(i,c);return p(),new e(g)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}};var m,C,b,I,w,k,x,v,B,y,E,M,G,D,Q,T,P,z,F,S,N,O,L,Y,H,R,j,V,W,U,K,Z=Object.freeze({__proto__:null,InferenceSession:h,TRACE:u,TRACE_FUNC_BEGIN:f,TRACE_FUNC_END:p,Tensor:g,env:a,registerBackend:(t,r,n)=>{if(!r||"function"!=typeof r.init||"function"!=typeof r.createInferenceSessionHandler)throw new TypeError("not a valid backend");{const a=e.get(t);if(void 0===a)e.set(t,{backend:r,priority:n});else{if(a.priority>n)return;if(a.priority===n&&a.backend!==r)throw new Error(`cannot register backend "${t}" using priority ${n}`)}if(n>=0){const r=A.indexOf(t);-1!==r&&A.splice(r,1);for(let r=0;r<A.length;r++)if(e.get(A[r]).priority<=n)return void A.splice(r,0,t);A.push(t)}}}}),X=Object.defineProperty,q=Object.getOwnPropertyDescriptor,J=Object.getOwnPropertyNames,_=Object.prototype.hasOwnProperty,$=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(e,A)=>(typeof require<"u"?require:e)[A]}):e)((function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')})),ee=(e,A)=>()=>(e&&(A=e(e=0)),A),Ae=(e,A)=>{for(var t in A)X(e,t,{get:A[t],enumerable:!0})},te=e=>((e,A,t,r)=>{if(A&&"object"==typeof A||"function"==typeof A)for(let n of J(A))!_.call(e,n)&&n!==t&&X(e,n,{get:()=>A[n],enumerable:!(r=q(A,n))||r.enumerable});return e})(X({},"__esModule",{value:!0}),e),re=ee((()=>{m=new Map,C=[],b=(e,A,t)=>{if(!A||"function"!=typeof A.init||"function"!=typeof A.createInferenceSessionHandler)throw new TypeError("not a valid backend");{let r=m.get(e);if(void 0===r)m.set(e,{backend:A,priority:t});else{if(r.priority>t)return;if(r.priority===t&&r.backend!==A)throw new Error(`cannot register backend "${e}" using priority ${t}`)}if(t>=0){let A=C.indexOf(e);-1!==A&&C.splice(A,1);for(let A=0;A<C.length;A++)if(m.get(C[A]).priority<=t)return void C.splice(A,0,e);C.push(e)}}},I=async e=>{let A=m.get(e);if(!A)return"backend not found.";if(A.initialized)return A.backend;if(A.aborted)return A.error;{let t=!!A.initPromise;try{return t||(A.initPromise=A.backend.init(e)),await A.initPromise,A.initialized=!0,A.backend}catch(e){return t||(A.error=`${e}`,A.aborted=!0),A.error}finally{delete A.initPromise}}},w=async e=>{let A,t=e.executionProviders||[],r=t.map((e=>"string"==typeof e?e:e.name)),n=0===r.length?C:r,a=[],s=new Set;for(let e of n){let t=await I(e);"string"==typeof t?a.push({name:e,err:t}):(A||(A=t),A===t&&s.add(e))}if(!A)throw new Error(`no available backend found. ERR: ${a.map((e=>`[${e.name}] ${e.err}`)).join(", ")}`);for(let{name:e,err:A}of a)r.includes(e)&&console.warn(`removing requested execution provider "${e}" from session options because it is not available: ${A}`);let i=t.filter((e=>s.has("string"==typeof e?e:e.name)));return[A,new Proxy(e,{get:(e,A)=>"executionProviders"===A?i:Reflect.get(e,A)})]}})),ne=ee((()=>{re()})),ae=ee((()=>{k="1.22.0-dev.20250409-89f8206ba4"})),se=ee((()=>{ae(),x="warning",v={wasm:{},webgl:{},webgpu:{},versions:{common:k},set logLevel(e){if(void 0!==e){if("string"!=typeof e||-1===["verbose","info","warning","error","fatal"].indexOf(e))throw new Error(`Unsupported logging level: ${e}`);x=e}},get logLevel(){return x}},Object.defineProperty(v,"logLevel",{enumerable:!0})})),ie=ee((()=>{se(),B=v})),oe=ee((()=>{y=(e,A)=>{let t=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);t.width=e.dims[3],t.height=e.dims[2];let r=t.getContext("2d");if(null!=r){let n,a;void 0!==A?.tensorLayout&&"NHWC"===A.tensorLayout?(n=e.dims[2],a=e.dims[3]):(n=e.dims[3],a=e.dims[2]);let s,i,o=void 0!==A?.format?A.format:"RGB",l=A?.norm;void 0===l||void 0===l.mean?s=[255,255,255,255]:"number"==typeof l.mean?s=[l.mean,l.mean,l.mean,l.mean]:(s=[l.mean[0],l.mean[1],l.mean[2],0],void 0!==l.mean[3]&&(s[3]=l.mean[3])),void 0===l||void 0===l.bias?i=[0,0,0,0]:"number"==typeof l.bias?i=[l.bias,l.bias,l.bias,l.bias]:(i=[l.bias[0],l.bias[1],l.bias[2],0],void 0!==l.bias[3]&&(i[3]=l.bias[3]));let c=a*n,g=0,u=c,d=2*c,f=-1;"RGBA"===o?(g=0,u=c,d=2*c,f=3*c):"RGB"===o?(g=0,u=c,d=2*c):"RBG"===o&&(g=0,d=c,u=2*c);for(let A=0;A<a;A++)for(let t=0;t<n;t++){let n=(e.data[g++]-i[0])*s[0],a=(e.data[u++]-i[1])*s[1],o=(e.data[d++]-i[2])*s[2],l=-1===f?255:(e.data[f++]-i[3])*s[3];r.fillStyle="rgba("+n+","+a+","+o+","+l+")",r.fillRect(t,A,1,1)}if("toDataURL"in t)return t.toDataURL();throw new Error("toDataURL is not supported")}throw new Error("Can not access image data")},E=(e,A)=>{let t,r=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d");if(null==r)throw new Error("Can not access image data");{let n,a,s;void 0!==A?.tensorLayout&&"NHWC"===A.tensorLayout?(n=e.dims[2],a=e.dims[1],s=e.dims[3]):(n=e.dims[3],a=e.dims[2],s=e.dims[1]);let i,o,l=void 0!==A&&void 0!==A.format?A.format:"RGB",c=A?.norm;void 0===c||void 0===c.mean?i=[255,255,255,255]:"number"==typeof c.mean?i=[c.mean,c.mean,c.mean,c.mean]:(i=[c.mean[0],c.mean[1],c.mean[2],255],void 0!==c.mean[3]&&(i[3]=c.mean[3])),void 0===c||void 0===c.bias?o=[0,0,0,0]:"number"==typeof c.bias?o=[c.bias,c.bias,c.bias,c.bias]:(o=[c.bias[0],c.bias[1],c.bias[2],0],void 0!==c.bias[3]&&(o[3]=c.bias[3]));let g=a*n;if(void 0!==A&&(void 0!==A.format&&4===s&&"RGBA"!==A.format||3===s&&"RGB"!==A.format&&"BGR"!==A.format))throw new Error("Tensor format doesn't match input tensor dims");let u=4,d=0,f=1,p=2,h=3,m=0,C=g,b=2*g,I=-1;"RGBA"===l?(m=0,C=g,b=2*g,I=3*g):"RGB"===l?(m=0,C=g,b=2*g):"RBG"===l&&(m=0,b=g,C=2*g),t=r.createImageData(n,a);for(let A=0;A<a*n;d+=u,f+=u,p+=u,h+=u,A++)t.data[d]=(e.data[m++]-o[0])*i[0],t.data[f]=(e.data[C++]-o[1])*i[1],t.data[p]=(e.data[b++]-o[2])*i[2],t.data[h]=-1===I?255:(e.data[I++]-o[3])*i[3]}return t}})),le=ee((()=>{ue(),M=(e,A)=>{if(void 0===e)throw new Error("Image buffer must be defined");if(void 0===A.height||void 0===A.width)throw new Error("Image height and width must be defined");if("NHWC"===A.tensorLayout)throw new Error("NHWC Tensor layout is not supported yet");let t,r,{height:n,width:a}=A,s=A.norm??{mean:255,bias:0};t="number"==typeof s.mean?[s.mean,s.mean,s.mean,s.mean]:[s.mean[0],s.mean[1],s.mean[2],s.mean[3]??255],r="number"==typeof s.bias?[s.bias,s.bias,s.bias,s.bias]:[s.bias[0],s.bias[1],s.bias[2],s.bias[3]??0];let i=void 0!==A.format?A.format:"RGBA",o=void 0!==A.tensorFormat&&void 0!==A.tensorFormat?A.tensorFormat:"RGB",l=n*a,c="RGBA"===o?new Float32Array(4*l):new Float32Array(3*l),g=4,u=0,d=1,f=2,p=3,h=0,m=l,C=2*l,b=-1;"RGB"===i&&(g=3,u=0,d=1,f=2,p=-1),"RGBA"===o?b=3*l:"RBG"===o?(h=0,C=l,m=2*l):"BGR"===o&&(C=0,m=l,h=2*l);for(let A=0;A<l;A++,u+=g,f+=g,d+=g,p+=g)c[h++]=(e[u]+r[0])/t[0],c[m++]=(e[d]+r[1])/t[1],c[C++]=(e[f]+r[2])/t[2],-1!==b&&-1!==p&&(c[b++]=(e[p]+r[3])/t[3]);return new Y("float32",c,"RGBA"===o?[1,4,n,a]:[1,3,n,a])},G=async(e,A)=>{let t,r=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,n=typeof ImageData<"u"&&e instanceof ImageData,a=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,s="string"==typeof e,i=A??{},o=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},l=e=>typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext("2d"):null;if(r){let r=o();r.width=e.width,r.height=e.height;let n=l(r);if(null==n)throw new Error("Can not access image data");{let r=e.height,a=e.width;if(void 0!==A&&void 0!==A.resizedHeight&&void 0!==A.resizedWidth&&(r=A.resizedHeight,a=A.resizedWidth),void 0!==A){if(i=A,void 0!==A.tensorFormat)throw new Error("Image input config format must be RGBA for HTMLImageElement");i.tensorFormat="RGBA",i.height=r,i.width=a}else i.tensorFormat="RGBA",i.height=r,i.width=a;n.drawImage(e,0,0),t=n.getImageData(0,0,a,r).data}}else{if(!n){if(a){if(void 0===A)throw new Error("Please provide image config with format for Imagebitmap");let r=o();r.width=e.width,r.height=e.height;let n=l(r);if(null!=n){let A=e.height,r=e.width;return n.drawImage(e,0,0,r,A),t=n.getImageData(0,0,r,A).data,i.height=A,i.width=r,M(t,i)}throw new Error("Can not access image data")}if(s)return new Promise(((A,t)=>{let r=o(),n=l(r);if(!e||!n)return t();let a=new Image;a.crossOrigin="Anonymous",a.src=e,a.onload=()=>{r.width=a.width,r.height=a.height,n.drawImage(a,0,0,r.width,r.height);let e=n.getImageData(0,0,r.width,r.height);i.height=r.height,i.width=r.width,A(M(e.data,i))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{let r,n;if(void 0!==A&&void 0!==A.resizedWidth&&void 0!==A.resizedHeight?(r=A.resizedHeight,n=A.resizedWidth):(r=e.height,n=e.width),void 0!==A&&(i=A),i.format="RGBA",i.height=r,i.width=n,void 0!==A){let A=o();A.width=n,A.height=r;let a=l(A);if(null==a)throw new Error("Can not access image data");a.putImageData(e,0,0),t=a.getImageData(0,0,n,r).data}else t=e.data}}if(void 0!==t)return M(t,i);throw new Error("Input data provided is not supported - aborted tensor creation")},D=(e,A)=>{let{width:t,height:r,download:n,dispose:a}=A;return new Y({location:"texture",type:"float32",texture:e,dims:[1,r,t,4],download:n,dispose:a})},Q=(e,A)=>{let{dataType:t,dims:r,download:n,dispose:a}=A;return new Y({location:"gpu-buffer",type:t??"float32",gpuBuffer:e,dims:r,download:n,dispose:a})},T=(e,A)=>{let{dataType:t,dims:r,download:n,dispose:a}=A;return new Y({location:"ml-tensor",type:t??"float32",mlTensor:e,dims:r,download:n,dispose:a})},P=(e,A,t)=>new Y({location:"cpu-pinned",type:e,data:A,dims:t??[A.length]})})),ce=ee((()=>{z=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),F=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),S=!1,N=()=>{if(!S){S=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,A=typeof BigUint64Array<"u"&&BigUint64Array.from,t=globalThis.Float16Array,r=typeof t<"u"&&t.from;e&&(z.set("int64",BigInt64Array),F.set(BigInt64Array,"int64")),A&&(z.set("uint64",BigUint64Array),F.set(BigUint64Array,"uint64")),r?(z.set("float16",t),F.set(t,"float16")):z.set("float16",Uint16Array)}}})),ge=ee((()=>{ue(),O=e=>{let A=1;for(let t=0;t<e.length;t++){let r=e[t];if("number"!=typeof r||!Number.isSafeInteger(r))throw new TypeError(`dims[${t}] must be an integer, got: ${r}`);if(r<0)throw new RangeError(`dims[${t}] must be a non-negative integer, got: ${r}`);A*=r}return A},L=(e,A)=>{switch(e.location){case"cpu":return new Y(e.type,e.data,A);case"cpu-pinned":return new Y({location:"cpu-pinned",data:e.data,type:e.type,dims:A});case"texture":return new Y({location:"texture",texture:e.texture,type:e.type,dims:A});case"gpu-buffer":return new Y({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:A});case"ml-tensor":return new Y({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:A});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}}})),ue=ee((()=>{oe(),le(),ce(),ge(),Y=class{constructor(e,A,t){let r,n;if(N(),"object"==typeof e&&"location"in e)switch(this.dataLocation=e.location,r=e.type,n=e.dims,e.location){case"cpu-pinned":{let A=z.get(r);if(!A)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof A))throw new TypeError(`buffer should be of type ${A.name}`);this.cpuData=e.data;break}case"texture":if("float32"!==r)throw new TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break;case"gpu-buffer":if("float32"!==r&&"float16"!==r&&"int32"!==r&&"int64"!==r&&"uint32"!==r&&"uint8"!==r&&"bool"!==r&&"uint4"!==r&&"int4"!==r)throw new TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break;case"ml-tensor":if("float32"!==r&&"float16"!==r&&"int32"!==r&&"int64"!==r&&"uint32"!==r&&"uint64"!==r&&"int8"!==r&&"uint8"!==r&&"bool"!==r&&"uint4"!==r&&"int4"!==r)throw new TypeError(`unsupported type "${r}" to create tensor from MLTensor`);this.mlTensorData=e.mlTensor,this.downloader=e.download,this.disposer=e.dispose;break;default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let a,s;if("string"==typeof e)if(r=e,s=t,"string"===e){if(!Array.isArray(A))throw new TypeError("A string tensor's data must be a string array.");a=A}else{let t=z.get(e);if(void 0===t)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(A)){if("float16"===e&&t===Uint16Array||"uint4"===e||"int4"===e)throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${t.name} as data.`);a="uint64"===e||"int64"===e?t.from(A,BigInt):t.from(A)}else if(A instanceof t)a=A;else if(A instanceof Uint8ClampedArray){if("uint8"!==e)throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");a=Uint8Array.from(A)}else{if(!("float16"===e&&A instanceof Uint16Array&&t!==Uint16Array))throw new TypeError(`A ${r} tensor's data must be type of ${t}`);a=new globalThis.Float16Array(A.buffer,A.byteOffset,A.length)}}else if(s=A,Array.isArray(e)){if(0===e.length)throw new TypeError("Tensor type cannot be inferred from an empty array.");let A=typeof e[0];if("string"===A)r="string",a=e;else{if("boolean"!==A)throw new TypeError(`Invalid element type of data array: ${A}.`);r="bool",a=Uint8Array.from(e)}}else if(e instanceof Uint8ClampedArray)r="uint8",a=Uint8Array.from(e);else{let A=F.get(e.constructor);if(void 0===A)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=A,a=e}if(void 0===s)s=[a.length];else if(!Array.isArray(s))throw new TypeError("A tensor's dims must be a number array");n=s,this.cpuData=a,this.dataLocation="cpu"}let a=O(n);if(this.cpuData&&a!==this.cpuData.length&&("uint4"!==r&&"int4"!==r||Math.ceil(a/2)!==this.cpuData.length))throw new Error(`Tensor's size(${a}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=n,this.size=a}static async fromImage(e,A){return G(e,A)}static fromTexture(e,A){return D(e,A)}static fromGpuBuffer(e,A){return Q(e,A)}static fromMLTensor(e,A){return T(e,A)}static fromPinnedBuffer(e,A,t){return P(e,A,t)}toDataURL(e){return y(this,e)}toImageData(e){return E(this,e)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}get mlTensor(){if(this.ensureValid(),!this.mlTensorData)throw new Error("The data is not stored as a WebNN MLTensor.");return this.mlTensorData}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":case"ml-tensor":if(!this.downloader)throw new Error("The current tensor is not created with a specified data downloader.");if(this.isDownloading)throw new Error("The current tensor is being downloaded.");try{this.isDownloading=!0;let A=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=A,e&&this.disposer&&(this.disposer(),this.disposer=void 0),A}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("none"===this.dataLocation)throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return L(this,e)}}})),de=ee((()=>{ue(),H=Y})),fe=ee((()=>{se(),R=(e,A)=>{(typeof v.trace>"u"?!v.wasm.trace:!v.trace)||console.timeStamp(`${e}::ORT::${A}`)},j=(e,A)=>{let t=(new Error).stack?.split(/\r\n|\r|\n/g)||[],r=!1;for(let n=0;n<t.length;n++){if(r&&!t[n].includes("TRACE_FUNC")){let r=`FUNC_${e}::${t[n].trim().split(" ")[1]}`;return A&&(r+=`::${A}`),void R("CPU",r)}t[n].includes("TRACE_FUNC")&&(r=!0)}},V=e=>{(typeof v.trace>"u"?!v.wasm.trace:!v.trace)||j("BEGIN",e)},W=e=>{(typeof v.trace>"u"?!v.wasm.trace:!v.trace)||j("END",e)}})),pe=ee((()=>{re(),de(),fe(),U=class e{constructor(e){this.handler=e}async run(e,A,t){V();let r={},n={};if("object"!=typeof e||null===e||e instanceof H||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if("object"==typeof A){if(null===A)throw new TypeError("Unexpected argument[1]: cannot be null.");if(A instanceof H)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(A)){if(0===A.length)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(let e of A){if("string"!=typeof e)throw new TypeError("'fetches' must be a string array or an object.");if(-1===this.outputNames.indexOf(e))throw new RangeError(`'fetches' contains invalid output name: ${e}.`);r[e]=null}if("object"==typeof t&&null!==t)n=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else{let e=!1,s=Object.getOwnPropertyNames(A);for(let t of this.outputNames)if(-1!==s.indexOf(t)){let n=A[t];(null===n||n instanceof H)&&(e=!0,a=!1,r[t]=n)}if(e){if("object"==typeof t&&null!==t)n=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else n=A}}else if(typeof A<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let A of this.inputNames)if(typeof e[A]>"u")throw new Error(`input '${A}' is missing in 'feeds'.`);if(a)for(let e of this.outputNames)r[e]=null;let s=await this.handler.run(e,r,n),i={};for(let e in s)if(Object.hasOwnProperty.call(s,e)){let A=s[e];i[e]=A instanceof H?A:new H(A.type,A.data,A.dims)}return W(),i}async release(){return this.handler.dispose()}static async create(A,t,r,n){V();let a,s={};if("string"==typeof A){if(a=A,"object"==typeof t&&null!==t)s=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(A instanceof Uint8Array){if(a=A,"object"==typeof t&&null!==t)s=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else{if(!(A instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&A instanceof SharedArrayBuffer))throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");{let e=A,i=0,o=A.byteLength;if("object"==typeof t&&null!==t)s=t;else if("number"==typeof t){if(i=t,!Number.isSafeInteger(i))throw new RangeError("'byteOffset' must be an integer.");if(i<0||i>=e.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${e.byteLength}).`);if(o=A.byteLength-i,"number"==typeof r){if(o=r,!Number.isSafeInteger(o))throw new RangeError("'byteLength' must be an integer.");if(o<=0||i+o>e.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${e.byteLength-i}].`);if("object"==typeof n&&null!==n)s=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(typeof r<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof t<"u")throw new TypeError("'options' must be an object.");a=new Uint8Array(e,i,o)}}let[i,o]=await w(s),l=await i.createInferenceSessionHandler(a,o);return W(),new e(l)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}get inputMetadata(){return this.handler.inputMetadata}get outputMetadata(){return this.handler.outputMetadata}}})),he=ee((()=>{pe(),K=U})),me=ee((()=>{})),Ce=ee((()=>{})),be=ee((()=>{})),Ie=ee((()=>{})),we={};Ae(we,{InferenceSession:()=>K,TRACE:()=>R,TRACE_FUNC_BEGIN:()=>V,TRACE_FUNC_END:()=>W,Tensor:()=>H,env:()=>B,registerBackend:()=>b});var ke=ee((()=>{ne(),ie(),he(),de(),me(),Ce(),fe(),be(),Ie()})),xe=ee((()=>{})),ve={};Ae(ve,{default:()=>Ee});var Be,ye,Ee,Me=ee((()=>{Bg(),bl(),Cl(),Be="ort-wasm-proxy-worker",(ye=globalThis.self?.name===Be)&&(self.onmessage=e=>{let{type:A,in:t}=e.data;try{switch(A){case"init-wasm":AA(t.wasm).then((()=>{Wc(t).then((()=>{postMessage({type:A})}),(e=>{postMessage({type:A,err:e})}))}),(e=>{postMessage({type:A,err:e})}));break;case"init-ep":{let{epName:e,env:r}=t;Uc(r,e).then((()=>{postMessage({type:A})}),(e=>{postMessage({type:A,err:e})}));break}case"copy-from":{let{buffer:e}=t,r=qc(e);postMessage({type:A,out:r});break}case"create":{let{model:e,options:r}=t;Jc(e,r).then((e=>{postMessage({type:A,out:e})}),(e=>{postMessage({type:A,err:e})}));break}case"release":_c(t),postMessage({type:A});break;case"run":{let{sessionId:e,inputIndices:r,inputs:n,outputIndices:a,options:s}=t;eg(e,r,n,a,new Array(a.length).fill(null),s).then((e=>{e.some((e=>"cpu"!==e[3]))?postMessage({type:A,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:A,out:e},tg([...n,...e]))}),(e=>{postMessage({type:A,err:e})}));break}case"end-profiling":Ag(t),postMessage({type:A})}}catch(e){postMessage({type:A,err:e})}}),Ee=ye?null:e=>new Worker(e??Ne,{type:"module",name:Be})})),Ge={};Ae(Ge,{default:()=>Te});var De,Qe,Te,Pe,ze,Fe,Se,Ne,Oe,Le,Ye,He,Re,je,Ve,We,Ue,Ke,Ze,Xe,qe,Je,_e,$e,eA,AA,tA,rA,nA,aA,sA,iA,oA,lA,cA,gA,uA,dA,fA,pA,hA,mA,CA,bA,IA,wA,kA,xA,vA,BA,yA,EA,MA,GA,DA,QA,TA,PA,zA,FA,SA,NA,OA,LA,YA,HA,RA,jA,VA,WA,UA,KA,ZA,XA,qA,JA,_A,$A,et,At,tt,rt,nt,at,st,it,ot,lt,ct,gt,ut,dt,ft,pt,ht,mt,Ct,bt,It,wt,kt,xt,vt,Bt,yt,Et,Mt,Gt,Dt,Qt,Tt,Pt,zt,Ft,St,Nt,Ot,Lt,Yt,Ht,Rt,jt,Vt,Wt,Ut,Kt,Zt,Xt,qt,Jt,_t,$t,er,Ar,tr,rr,nr,ar,sr,ir,or,lr,cr,gr,ur,dr,fr,pr,hr,mr,Cr,br,Ir,wr,kr,xr,vr,Br,yr,Er,Mr,Gr,Dr,Qr,Tr,Pr,zr,Fr,Sr,Nr,Or,Lr,Yr,Hr,Rr,jr,Vr,Wr,Ur,Kr,Zr,Xr,qr,Jr,_r,$r,en,An,tn,rn,nn,an,sn,on,ln,cn,gn,un,dn,fn,pn,hn,mn,Cn,bn,In,wn,kn,xn,vn,Bn,yn,En,Mn,Gn,Dn,Qn,Tn,Pn,zn,Fn,Sn,Nn,On,Ln,Yn,Hn,Rn,jn,Vn,Wn,Un,Kn,Zn,Xn,qn,Jn,_n,$n,ea,Aa,ta,ra,na,aa,sa,ia,oa,la,ca,ga,ua,da,fa,pa,ha,ma,Ca,ba,Ia,wa,ka,xa,va,Ba,ya,Ea,Ma,Ga,Da,Qa,Ta,Pa,za,Fa,Sa,Na,Oa,La,Ya,Ha,Ra,ja,Va,Wa,Ua,Ka,Za,Xa,qa,Ja,_a,$a,es,As,ts,rs,ns,as,ss,is,os,ls,cs,gs,us,ds,fs,ps,hs,ms,Cs,bs,Is,ws,ks,xs,vs,Bs,ys,Es,Ms,Gs,Ds,Qs,Ts,Ps,zs,Fs,Ss,Ns,Os,Ls,Ys,Hs,Rs,js,Vs,Ws,Us,Ks,Zs,Xs,qs,Js,_s,$s,ei,Ai,ti,ri,ni,ai,si,ii,oi,li,ci,gi,ui,di,fi,pi,hi,mi,Ci,bi,Ii,wi,ki,xi,vi,Bi,yi,Ei,Mi,Gi,Di,Qi,Ti,Pi,zi,Fi,Si,Ni,Oi,Li,Yi,Hi,Ri,ji,Vi,Wi,Ui,Ki,Zi,Xi,qi,Ji,_i,$i,eo,Ao,to,ro,no,ao,so,io,oo,lo,co,go,uo,fo,po,ho,mo,Co,bo,Io,wo,ko,xo,vo,Bo,yo,Eo,Mo,Go,Do,Qo,To,Po,zo,Fo,So,No,Oo,Lo,Yo,Ho,Ro,jo,Vo,Wo,Uo,Ko,Zo,Xo,qo,Jo,_o,$o,el,Al,tl,rl,nl,al,sl,il,ol,ll,cl,gl,ul,dl,fl,pl,hl,ml=ee((()=>{De=import.meta.url,Qe=async function(e={}){var A,t,r=e,n=new Promise(((e,r)=>{A=e,t=r})),a="object"==typeof window,s=typeof WorkerGlobalScope<"u",i=s&&self.name?.startsWith("em-pthread");r.mountExternalData=(e,A)=>{e.startsWith("./")&&(e=e.substring(2)),(r.Eb||(r.Eb=new Map)).set(e,A)},r.unmountExternalData=()=>{delete r.Eb};var o=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,pc:!0}).buffer.constructor;let l=e=>async(...A)=>{try{if(r.Fb)throw Error("Session already started");let t=r.Fb={dc:A[0],errors:[]},n=await e(...A);if(r.Fb!==t)throw Error("Session mismatch");r.Jb?.flush();let a=t.errors;if(0<a.length){let e=await Promise.all(a);if(e=e.filter((e=>e)),0<e.length)throw Error(e.join("\n"))}return n}finally{r.Fb=null}};r.jsepInit=(e,A)=>{if("webgpu"===e){[r.Jb,r.Ub,r.Yb,r.Kb,r.Xb,r.jb,r.Zb,r.ac,r.Vb,r.Wb,r.$b]=A;let e=r.Jb;r.jsepRegisterBuffer=(A,t,r,n)=>e.registerBuffer(A,t,r,n),r.jsepGetBuffer=A=>e.getBuffer(A),r.jsepCreateDownloader=(A,t,r)=>e.createDownloader(A,t,r),r.jsepOnCreateSession=A=>{e.onCreateSession(A)},r.jsepOnReleaseSession=A=>{e.onReleaseSession(A)},r.jsepOnRunStart=A=>e.onRunStart(A),r.bc=(A,t)=>{e.upload(A,t)}}else if("webnn"===e){let e=A[0];[r.nc,r.Nb,r.webnnEnsureTensor,r.Ob,r.webnnDownloadTensor]=A.slice(1),r.webnnReleaseTensorId=r.Nb,r.webnnUploadTensor=r.Ob,r.webnnOnRunStart=A=>e.onRunStart(A),r.webnnOnRunEnd=e.onRunEnd.bind(e),r.webnnRegisterMLContext=(A,t)=>{e.registerMLContext(A,t)},r.webnnOnReleaseSession=A=>{e.onReleaseSession(A)},r.webnnCreateMLTensorDownloader=(A,t)=>e.createMLTensorDownloader(A,t),r.webnnRegisterMLTensor=(A,t,r,n)=>e.registerMLTensor(A,t,r,n),r.webnnCreateMLContext=A=>e.createMLContext(A),r.webnnRegisterMLConstant=(A,t,n,a,s,i)=>e.registerMLConstant(A,t,n,a,s,r.Eb,i),r.webnnRegisterGraphInput=e.registerGraphInput.bind(e),r.webnnIsGraphInput=e.isGraphInput.bind(e),r.webnnCreateTemporaryTensor=e.createTemporaryTensor.bind(e),r.webnnIsInt64Supported=e.isInt64Supported.bind(e)}};let c=()=>{let e=(e,A,t)=>(...r)=>{let n=YA,a=A?.();r=e(...r);let s=A?.();return a!==s&&(e=s,t(a),A=t=null),YA!=n?new Promise(((e,A)=>{UA={resolve:e,reject:A}})):r};(()=>{for(let A of["_OrtAppendExecutionProvider","_OrtCreateSession","_OrtRun","_OrtRunWithBinding","_OrtBindInput"])r[A]=e(r[A],(()=>r[A]),(e=>r[A]=e))})(),void 0!==l&&(r._OrtRun=l(r._OrtRun),r._OrtRunWithBinding=l(r._OrtRunWithBinding)),c=void 0};r.asyncInit=()=>{c?.()};var g,u,d=Object.assign({},r),f=(e,A)=>{throw A},p="";(a||s)&&(s?p=self.location.href:typeof document<"u"&&document.currentScript&&(p=document.currentScript.src),De&&(p=De),p=p.startsWith("blob:")?"":p.slice(0,p.replace(/[?#].*/,"").lastIndexOf("/")+1),s&&(u=e=>{var A=new XMLHttpRequest;return A.open("GET",e,!1),A.responseType="arraybuffer",A.send(null),new Uint8Array(A.response)}),g=async e=>{if(F(e))return new Promise(((A,t)=>{var r=new XMLHttpRequest;r.open("GET",e,!0),r.responseType="arraybuffer",r.onload=()=>{200==r.status||0==r.status&&r.response?A(r.response):t(r.status)},r.onerror=t,r.send(null)}));var A=await fetch(e,{credentials:"same-origin"});if(A.ok)return A.arrayBuffer();throw Error(A.status+" : "+A.url)});var h=console.log.bind(console),m=console.error.bind(console),C=h,b=m;Object.assign(r,d),d=null;var I,w,k,x,v,B,y,E,M,G,D,Q,T,P=r.wasmBinary,z=!1,F=e=>e.startsWith("file://");function S(){return I.buffer!=x.buffer&&U(),x}function N(){return I.buffer!=x.buffer&&U(),v}function O(){return I.buffer!=x.buffer&&U(),B}function L(){return I.buffer!=x.buffer&&U(),y}function Y(){return I.buffer!=x.buffer&&U(),E}function H(){return I.buffer!=x.buffer&&U(),M}function R(){return I.buffer!=x.buffer&&U(),G}function j(){return I.buffer!=x.buffer&&U(),T}if(i){let e=function(A){try{var t=A.data,n=t.Bb;if("load"===n){let A=[];self.onmessage=e=>A.push(e),self.startWorker=()=>{postMessage({Bb:"loaded"});for(let t of A)e(t);self.onmessage=e};for(let e of t.Rb)r[e]&&!r[e].proxy||(r[e]=(...A)=>{postMessage({Bb:"callHandler",Qb:e,args:A})},"print"==e&&(C=r[e]),"printErr"==e&&(b=r[e]));I=t.kc,U(),V(t.lc)}else if("run"===n){Ie(t.Ab),ur(t.Ab,0,0,1,0,0),me(),yA(t.Ab),W||(or(),W=!0);try{we(t.fc,t.Hb)}catch(e){if("unwind"!=e)throw e}}else"setimmediate"!==t.target&&("checkMailbox"===n?W&&EA():n&&(b(`worker: received unknown command ${n}`),b(t)))}catch(e){throw dr(),e}};var V,W=!1;b=function(...e){e=e.join(" "),console.error(e)},self.alert=function(...e){postMessage({Bb:"alert",text:e.join(" "),ic:lr()})},self.onunhandledrejection=e=>{throw e.reason||e},self.onmessage=e}function U(){var e=I.buffer;r.HEAP8=x=new Int8Array(e),r.HEAP16=B=new Int16Array(e),r.HEAPU8=v=new Uint8Array(e),r.HEAPU16=y=new Uint16Array(e),r.HEAP32=E=new Int32Array(e),r.HEAPU32=M=new Uint32Array(e),r.HEAPF32=G=new Float32Array(e),r.HEAPF64=T=new Float64Array(e),r.HEAP64=D=new BigInt64Array(e),r.HEAPU64=Q=new BigUint64Array(e)}function K(){i?startWorker(r):ar.Ca()}i||(I=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),U());var Z,X=0,q=null;function J(){if(0==--X&&q){var e=q;q=null,e()}}function _(e){throw b(e="Aborted("+e+")"),z=!0,e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info."),t(e),e}function $(){return{a:{L:te,Aa:Ae,b:xe,$:Be,A:Ge,pa:Qe,X:ze,Z:Fe,qa:Se,na:Ne,ga:Oe,ma:Le,J:Ye,Y:He,V:Re,oa:je,W:Ve,va:Ke,E:$e,Q:AA,O:lA,D:gA,u:uA,r:dA,P:fA,z:kA,R:xA,ja:vA,T:MA,aa:DA,M:QA,F:TA,ia:yA,sa:PA,t:SA,Ba:NA,w:XA,o:JA,l:et,c:nA,n:tt,j:st,v:it,p:ot,f:lt,s:ct,m:gt,e:ut,k:dt,i:ft,g:pt,d:ht,da:mt,ea:wt,fa:kt,ba:xt,ca:vt,N:Et,xa:Mt,ua:Dt,h:Pt,C:zt,G:Ft,ta:Gt,x:St,ra:Nt,U:Ot,q:yt,y:Lt,K:Yt,S:Ht,za:Wt,ya:Ut,ka:qt,la:Jt,_:ge,B:_t,I:$t,ha:er,H:tr,a:I,wa:le}}}var ee={829644:(e,A,t,n,a)=>{if(void 0===r||!r.Eb)return 1;if((e=Me(Number(e>>>0))).startsWith("./")&&(e=e.substring(2)),!(e=r.Eb.get(e)))return 2;if(A=Number(A>>>0),t=Number(t>>>0),n=Number(n>>>0),A+t>e.byteLength)return 3;try{let s=e.subarray(A,A+t);switch(a){case 0:N().set(s,n>>>0);break;case 1:r.mc?r.mc(n,s):r.bc(n,s);break;default:return 4}return 0}catch{return 4}},830468:(e,A,t)=>{r.Ob(e,N().subarray(A>>>0,A+t>>>0))},830532:()=>r.nc(),830574:e=>{r.Nb(e)},830611:()=>{r.Vb()},830642:()=>{r.Wb()},830671:()=>{r.$b()},830696:e=>r.Ub(e),830729:e=>r.Yb(e),830761:(e,A,t)=>{r.Kb(Number(e),Number(A),Number(t),!0)},830824:(e,A,t)=>{r.Kb(Number(e),Number(A),Number(t))},830881:()=>typeof wasmOffsetConverter<"u",830938:e=>{r.jb("Abs",e,void 0)},830989:e=>{r.jb("Neg",e,void 0)},831040:e=>{r.jb("Floor",e,void 0)},831093:e=>{r.jb("Ceil",e,void 0)},831145:e=>{r.jb("Reciprocal",e,void 0)},831203:e=>{r.jb("Sqrt",e,void 0)},831255:e=>{r.jb("Exp",e,void 0)},831306:e=>{r.jb("Erf",e,void 0)},831357:e=>{r.jb("Sigmoid",e,void 0)},831412:(e,A,t)=>{r.jb("HardSigmoid",e,{alpha:A,beta:t})},831491:e=>{r.jb("Log",e,void 0)},831542:e=>{r.jb("Sin",e,void 0)},831593:e=>{r.jb("Cos",e,void 0)},831644:e=>{r.jb("Tan",e,void 0)},831695:e=>{r.jb("Asin",e,void 0)},831747:e=>{r.jb("Acos",e,void 0)},831799:e=>{r.jb("Atan",e,void 0)},831851:e=>{r.jb("Sinh",e,void 0)},831903:e=>{r.jb("Cosh",e,void 0)},831955:e=>{r.jb("Asinh",e,void 0)},832008:e=>{r.jb("Acosh",e,void 0)},832061:e=>{r.jb("Atanh",e,void 0)},832114:e=>{r.jb("Tanh",e,void 0)},832166:e=>{r.jb("Not",e,void 0)},832217:(e,A,t)=>{r.jb("Clip",e,{min:A,max:t})},832286:e=>{r.jb("Clip",e,void 0)},832338:(e,A)=>{r.jb("Elu",e,{alpha:A})},832396:e=>{r.jb("Gelu",e,void 0)},832448:e=>{r.jb("Relu",e,void 0)},832500:(e,A)=>{r.jb("LeakyRelu",e,{alpha:A})},832564:(e,A)=>{r.jb("ThresholdedRelu",e,{alpha:A})},832634:(e,A)=>{r.jb("Cast",e,{to:A})},832692:e=>{r.jb("Add",e,void 0)},832743:e=>{r.jb("Sub",e,void 0)},832794:e=>{r.jb("Mul",e,void 0)},832845:e=>{r.jb("Div",e,void 0)},832896:e=>{r.jb("Pow",e,void 0)},832947:e=>{r.jb("Equal",e,void 0)},833e3:e=>{r.jb("Greater",e,void 0)},833055:e=>{r.jb("GreaterOrEqual",e,void 0)},833117:e=>{r.jb("Less",e,void 0)},833169:e=>{r.jb("LessOrEqual",e,void 0)},833228:(e,A,t,n,a)=>{r.jb("ReduceMean",e,{keepDims:!!A,noopWithEmptyAxes:!!t,axes:n?Array.from(Y().subarray(Number(n)>>>0,Number(a)>>>0)):[]})},833403:(e,A,t,n,a)=>{r.jb("ReduceMax",e,{keepDims:!!A,noopWithEmptyAxes:!!t,axes:n?Array.from(Y().subarray(Number(n)>>>0,Number(a)>>>0)):[]})},833577:(e,A,t,n,a)=>{r.jb("ReduceMin",e,{keepDims:!!A,noopWithEmptyAxes:!!t,axes:n?Array.from(Y().subarray(Number(n)>>>0,Number(a)>>>0)):[]})},833751:(e,A,t,n,a)=>{r.jb("ReduceProd",e,{keepDims:!!A,noopWithEmptyAxes:!!t,axes:n?Array.from(Y().subarray(Number(n)>>>0,Number(a)>>>0)):[]})},833926:(e,A,t,n,a)=>{r.jb("ReduceSum",e,{keepDims:!!A,noopWithEmptyAxes:!!t,axes:n?Array.from(Y().subarray(Number(n)>>>0,Number(a)>>>0)):[]})},834100:(e,A,t,n,a)=>{r.jb("ReduceL1",e,{k