UNPKG

@juanpin/aicomponents

Version:

Components for AI, that I constantly use

2 lines 806 kB
/*! For license information please see worker.bundle.js.LICENSE.txt */ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(self,(()=>(()=>{"use strict";var e={6:(e,t,n)=>{e.exports=n.p+"acd5e88b482f6b97fb20.mjs"},651:(e,t,n)=>{e.exports=n.p+"666d0398a1e13e9c0c1d.wasm"}},t={};function n(r){var s=t[r];if(void 0!==s)return s.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.m=e,n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;n.g.importScripts&&(e=n.g.location+"");var t=n.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var s=r.length-1;s>-1&&(!e||!/^http(s?):/.test(e));)e=r[s--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),n.b=self.location+"";var r={};n.r(r),n.d(r,{InferenceSession:()=>M,TRACE:()=>w,TRACE_FUNC_BEGIN:()=>y,TRACE_FUNC_END:()=>x,Tensor:()=>g,env:()=>c,registerBackend:()=>o});var s={};n.r(s),n.d(s,{InferenceSession:()=>te,TRACE:()=>X,TRACE_FUNC_BEGIN:()=>Y,TRACE_FUNC_END:()=>Z,Tensor:()=>Q,default:()=>Vc,env:()=>z,registerBackend:()=>S});const i=new Map,a=[],o=(e,t,n)=>{if(!t||"function"!=typeof t.init||"function"!=typeof t.createInferenceSessionHandler)throw new TypeError("not a valid backend");{const r=i.get(e);if(void 0===r)i.set(e,{backend:t,priority:n});else{if(r.priority>n)return;if(r.priority===n&&r.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${n}`)}if(n>=0){const t=a.indexOf(e);-1!==t&&a.splice(t,1);for(let t=0;t<a.length;t++)if(i.get(a[t]).priority<=n)return void a.splice(t,0,e);a.push(e)}}},l=async e=>{const t=i.get(e);if(!t)return"backend not found.";if(t.initialized)return t.backend;if(t.aborted)return t.error;{const n=!!t.initPromise;try{return n||(t.initPromise=t.backend.init(e)),await t.initPromise,t.initialized=!0,t.backend}catch(e){return n||(t.error=`${e}`,t.aborted=!0),t.error}finally{delete t.initPromise}}};let u="warning";const d={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}`);u=e}},get logLevel(){return u}};Object.defineProperty(d,"logLevel",{enumerable:!0});const c=d,p=(e,t)=>{if(void 0===e)throw new Error("Image buffer must be defined");if(void 0===t.height||void 0===t.width)throw new Error("Image height and width must be defined");if("NHWC"===t.tensorLayout)throw new Error("NHWC Tensor layout is not supported yet");const{height:n,width:r}=t,s=t.norm??{mean:255,bias:0};let i,a;i="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],a="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];const o=void 0!==t.format?t.format:"RGBA",l=void 0!==t.tensorFormat&&void 0!==t.tensorFormat?t.tensorFormat:"RGB",u=n*r,d="RGBA"===l?new Float32Array(4*u):new Float32Array(3*u);let c=4,p=0,h=1,m=2,f=3,g=0,w=u,b=2*u,y=-1;"RGB"===o&&(c=3,p=0,h=1,m=2,f=-1),"RGBA"===l?y=3*u:"RBG"===l?(g=0,b=u,w=2*u):"BGR"===l&&(b=0,w=u,g=2*u);for(let t=0;t<u;t++,p+=c,m+=c,h+=c,f+=c)d[g++]=(e[p]+a[0])/i[0],d[w++]=(e[h]+a[1])/i[1],d[b++]=(e[m]+a[2])/i[2],-1!==y&&-1!==f&&(d[y++]=(e[f]+a[3])/i[3]);return new _("float32",d,"RGBA"===l?[1,4,n,r]:[1,3,n,r])},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]]),m=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]);let f=!1;class _{constructor(e,t,n){let r,s;if((()=>{if(!f){f=!0;const e="undefined"!=typeof BigInt64Array&&BigInt64Array.from,t="undefined"!=typeof BigUint64Array&&BigUint64Array.from,n=globalThis.Float16Array,r=void 0!==n&&n.from;e&&(h.set("int64",BigInt64Array),m.set(BigInt64Array,"int64")),t&&(h.set("uint64",BigUint64Array),m.set(BigUint64Array,"uint64")),r?(h.set("float16",n),m.set(n,"float16")):h.set("float16",Uint16Array)}})(),"object"==typeof e&&"location"in e)switch(this.dataLocation=e.location,r=e.type,s=e.dims,e.location){case"cpu-pinned":{const t=h.get(r);if(!t)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof t))throw new TypeError(`buffer should be of type ${t.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 i,a;if("string"==typeof e)if(r=e,a=n,"string"===e){if(!Array.isArray(t))throw new TypeError("A string tensor's data must be a string array.");i=t}else{const n=h.get(e);if(void 0===n)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(t)){if("float16"===e&&n===Uint16Array||"uint4"===e||"int4"===e)throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${n.name} as data.`);i="uint64"===e||"int64"===e?n.from(t,BigInt):n.from(t)}else if(t instanceof n)i=t;else if(t instanceof Uint8ClampedArray){if("uint8"!==e)throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");i=Uint8Array.from(t)}else{if(!("float16"===e&&t instanceof Uint16Array&&n!==Uint16Array))throw new TypeError(`A ${r} tensor's data must be type of ${n}`);i=new globalThis.Float16Array(t.buffer,t.byteOffset,t.length)}}else if(a=t,Array.isArray(e)){if(0===e.length)throw new TypeError("Tensor type cannot be inferred from an empty array.");const t=typeof e[0];if("string"===t)r="string",i=e;else{if("boolean"!==t)throw new TypeError(`Invalid element type of data array: ${t}.`);r="bool",i=Uint8Array.from(e)}}else if(e instanceof Uint8ClampedArray)r="uint8",i=Uint8Array.from(e);else{const t=m.get(e.constructor);if(void 0===t)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=t,i=e}if(void 0===a)a=[i.length];else if(!Array.isArray(a))throw new TypeError("A tensor's dims must be a number array");s=a,this.cpuData=i,this.dataLocation="cpu"}const i=(e=>{let t=1;for(let n=0;n<e.length;n++){const r=e[n];if("number"!=typeof r||!Number.isSafeInteger(r))throw new TypeError(`dims[${n}] must be an integer, got: ${r}`);if(r<0)throw new RangeError(`dims[${n}] must be a non-negative integer, got: ${r}`);t*=r}return t})(s);if(this.cpuData&&i!==this.cpuData.length&&("uint4"!==r&&"int4"!==r||Math.ceil(i/2)!==this.cpuData.length))throw new Error(`Tensor's size(${i}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=s,this.size=i}static async fromImage(e,t){return(async(e,t)=>{const n="undefined"!=typeof HTMLImageElement&&e instanceof HTMLImageElement,r="undefined"!=typeof ImageData&&e instanceof ImageData,s="undefined"!=typeof ImageBitmap&&e instanceof ImageBitmap,i="string"==typeof e;let a,o=t??{};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")},u=e=>"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext("2d"):null;if(n){const n=l();n.width=e.width,n.height=e.height;const r=u(n);if(null==r)throw new Error("Can not access image data");{let n=e.height,s=e.width;if(void 0!==t&&void 0!==t.resizedHeight&&void 0!==t.resizedWidth&&(n=t.resizedHeight,s=t.resizedWidth),void 0!==t){if(o=t,void 0!==t.tensorFormat)throw new Error("Image input config format must be RGBA for HTMLImageElement");o.tensorFormat="RGBA",o.height=n,o.width=s}else o.tensorFormat="RGBA",o.height=n,o.width=s;r.drawImage(e,0,0),a=r.getImageData(0,0,s,n).data}}else{if(!r){if(s){if(void 0===t)throw new Error("Please provide image config with format for Imagebitmap");const n=l();n.width=e.width,n.height=e.height;const r=u(n);if(null!=r){const t=e.height,n=e.width;return r.drawImage(e,0,0,n,t),a=r.getImageData(0,0,n,t).data,o.height=t,o.width=n,p(a,o)}throw new Error("Can not access image data")}if(i)return new Promise(((t,n)=>{const r=l(),s=u(r);if(!e||!s)return n();const i=new Image;i.crossOrigin="Anonymous",i.src=e,i.onload=()=>{r.width=i.width,r.height=i.height,s.drawImage(i,0,0,r.width,r.height);const e=s.getImageData(0,0,r.width,r.height);o.height=r.height,o.width=r.width,t(p(e.data,o))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{let n,r;if(void 0!==t&&void 0!==t.resizedWidth&&void 0!==t.resizedHeight?(n=t.resizedHeight,r=t.resizedWidth):(n=e.height,r=e.width),void 0!==t&&(o=t),o.format="RGBA",o.height=n,o.width=r,void 0!==t){const t=l();t.width=r,t.height=n;const s=u(t);if(null==s)throw new Error("Can not access image data");s.putImageData(e,0,0),a=s.getImageData(0,0,r,n).data}else a=e.data}}if(void 0!==a)return p(a,o);throw new Error("Input data provided is not supported - aborted tensor creation")})(e,t)}static fromTexture(e,t){return((e,t)=>{const{width:n,height:r,download:s,dispose:i}=t;return new _({location:"texture",type:"float32",texture:e,dims:[1,r,n,4],download:s,dispose:i})})(e,t)}static fromGpuBuffer(e,t){return((e,t)=>{const{dataType:n,dims:r,download:s,dispose:i}=t;return new _({location:"gpu-buffer",type:n??"float32",gpuBuffer:e,dims:r,download:s,dispose:i})})(e,t)}static fromMLTensor(e,t){return((e,t)=>{const{dataType:n,dims:r,download:s,dispose:i}=t;return new _({location:"ml-tensor",type:n??"float32",mlTensor:e,dims:r,download:s,dispose:i})})(e,t)}static fromPinnedBuffer(e,t,n){return((e,t,n)=>new _({location:"cpu-pinned",type:e,data:t,dims:n??[t.length]}))(e,t,n)}toDataURL(e){return((e,t)=>{const n="undefined"!=typeof document?document.createElement("canvas"):new OffscreenCanvas(1,1);n.width=e.dims[3],n.height=e.dims[2];const r=n.getContext("2d");if(null!=r){let s,i;void 0!==t?.tensorLayout&&"NHWC"===t.tensorLayout?(s=e.dims[2],i=e.dims[3]):(s=e.dims[3],i=e.dims[2]);const a=void 0!==t?.format?t.format:"RGB",o=t?.norm;let l,u;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],0],void 0!==o.mean[3]&&(l[3]=o.mean[3])),void 0===o||void 0===o.bias?u=[0,0,0,0]:"number"==typeof o.bias?u=[o.bias,o.bias,o.bias,o.bias]:(u=[o.bias[0],o.bias[1],o.bias[2],0],void 0!==o.bias[3]&&(u[3]=o.bias[3]));const d=i*s;let c=0,p=d,h=2*d,m=-1;"RGBA"===a?(c=0,p=d,h=2*d,m=3*d):"RGB"===a?(c=0,p=d,h=2*d):"RBG"===a&&(c=0,h=d,p=2*d);for(let t=0;t<i;t++)for(let n=0;n<s;n++){const s=(e.data[c++]-u[0])*l[0],i=(e.data[p++]-u[1])*l[1],a=(e.data[h++]-u[2])*l[2],o=-1===m?255:(e.data[m++]-u[3])*l[3];r.fillStyle="rgba("+s+","+i+","+a+","+o+")",r.fillRect(n,t,1,1)}if("toDataURL"in n)return n.toDataURL();throw new Error("toDataURL is not supported")}throw new Error("Can not access image data")})(this,e)}toImageData(e){return((e,t)=>{const n="undefined"!=typeof document?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d");let r;if(null==n)throw new Error("Can not access image data");{let s,i,a;void 0!==t?.tensorLayout&&"NHWC"===t.tensorLayout?(s=e.dims[2],i=e.dims[1],a=e.dims[3]):(s=e.dims[3],i=e.dims[2],a=e.dims[1]);const o=void 0!==t&&void 0!==t.format?t.format:"RGB",l=t?.norm;let u,d;void 0===l||void 0===l.mean?u=[255,255,255,255]:"number"==typeof l.mean?u=[l.mean,l.mean,l.mean,l.mean]:(u=[l.mean[0],l.mean[1],l.mean[2],255],void 0!==l.mean[3]&&(u[3]=l.mean[3])),void 0===l||void 0===l.bias?d=[0,0,0,0]:"number"==typeof l.bias?d=[l.bias,l.bias,l.bias,l.bias]:(d=[l.bias[0],l.bias[1],l.bias[2],0],void 0!==l.bias[3]&&(d[3]=l.bias[3]));const c=i*s;if(void 0!==t&&(void 0!==t.format&&4===a&&"RGBA"!==t.format||3===a&&"RGB"!==t.format&&"BGR"!==t.format))throw new Error("Tensor format doesn't match input tensor dims");const p=4;let h=0,m=1,f=2,_=3,g=0,w=c,b=2*c,y=-1;"RGBA"===o?(g=0,w=c,b=2*c,y=3*c):"RGB"===o?(g=0,w=c,b=2*c):"RBG"===o&&(g=0,b=c,w=2*c),r=n.createImageData(s,i);for(let t=0;t<i*s;h+=p,m+=p,f+=p,_+=p,t++)r.data[h]=(e.data[g++]-d[0])*u[0],r.data[m]=(e.data[w++]-d[1])*u[1],r.data[f]=(e.data[b++]-d[2])*u[2],r.data[_]=-1===y?255:(e.data[y++]-d[3])*u[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 t=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=t,e&&this.disposer&&(this.disposer(),this.disposer=void 0),t}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,t)=>{switch(e.location){case"cpu":return new _(e.type,e.data,t);case"cpu-pinned":return new _({location:"cpu-pinned",data:e.data,type:e.type,dims:t});case"texture":return new _({location:"texture",texture:e.texture,type:e.type,dims:t});case"gpu-buffer":return new _({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case"ml-tensor":return new _({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:t});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}})(this,e)}}const g=_,w=(e,t)=>{(void 0===d.trace?d.wasm.trace:d.trace)&&console.timeStamp(`${e}::ORT::${t}`)},b=(e,t)=>{const n=(new Error).stack?.split(/\r\n|\r|\n/g)||[];let r=!1;for(let s=0;s<n.length;s++){if(r&&!n[s].includes("TRACE_FUNC")){let r=`FUNC_${e}::${n[s].trim().split(" ")[1]}`;return t&&(r+=`::${t}`),void w("CPU",r)}n[s].includes("TRACE_FUNC")&&(r=!0)}},y=e=>{(void 0===d.trace?d.wasm.trace:d.trace)&&b("BEGIN",e)},x=e=>{(void 0===d.trace?d.wasm.trace:d.trace)&&b("END",e)};class v{constructor(e){this.handler=e}async run(e,t,n){y();const r={};let s={};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 i=!0;if("object"==typeof t){if(null===t)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof g)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(0===t.length)throw new TypeError("'fetches' cannot be an empty array.");i=!1;for(const e of t){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 n&&null!==n)s=n;else if(void 0!==n)throw new TypeError("'options' must be an object.")}else{let e=!1;const a=Object.getOwnPropertyNames(t);for(const n of this.outputNames)if(-1!==a.indexOf(n)){const s=t[n];(null===s||s instanceof g)&&(e=!0,i=!1,r[n]=s)}if(e){if("object"==typeof n&&null!==n)s=n;else if(void 0!==n)throw new TypeError("'options' must be an object.")}else s=t}}else if(void 0!==t)throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const t of this.inputNames)if(void 0===e[t])throw new Error(`input '${t}' is missing in 'feeds'.`);if(i)for(const e of this.outputNames)r[e]=null;const a=await this.handler.run(e,r,s),o={};for(const e in a)if(Object.hasOwnProperty.call(a,e)){const t=a[e];o[e]=t instanceof g?t:new g(t.type,t.data,t.dims)}return x(),o}async release(){return this.handler.dispose()}static async create(e,t,n,r){let s;y();let i={};if("string"==typeof e){if(s=e,"object"==typeof t&&null!==t)i=t;else if(void 0!==t)throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(s=e,"object"==typeof t&&null!==t)i=t;else if(void 0!==t)throw new TypeError("'options' must be an object.")}else{if(!(e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer))throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");{const a=e;let o=0,l=e.byteLength;if("object"==typeof t&&null!==t)i=t;else if("number"==typeof t){if(o=t,!Number.isSafeInteger(o))throw new RangeError("'byteOffset' must be an integer.");if(o<0||o>=a.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${a.byteLength}).`);if(l=e.byteLength-o,"number"==typeof n){if(l=n,!Number.isSafeInteger(l))throw new RangeError("'byteLength' must be an integer.");if(l<=0||o+l>a.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${a.byteLength-o}].`);if("object"==typeof r&&null!==r)i=r;else if(void 0!==r)throw new TypeError("'options' must be an object.")}else if(void 0!==n)throw new TypeError("'byteLength' must be a number.")}else if(void 0!==t)throw new TypeError("'options' must be an object.");s=new Uint8Array(a,o,l)}}const[o,u]=await(async e=>{const t=e.executionProviders||[],n=t.map((e=>"string"==typeof e?e:e.name)),r=0===n.length?a:n;let s;const i=[],o=new Set;for(const e of r){const t=await l(e);"string"==typeof t?i.push({name:e,err:t}):(s||(s=t),s===t&&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:t}of i)n.includes(e)&&console.warn(`removing requested execution provider "${e}" from session options because it is not available: ${t}`);const u=t.filter((e=>o.has("string"==typeof e?e:e.name)));return[s,new Proxy(e,{get:(e,t)=>"executionProviders"===t?u:Reflect.get(e,t)})]})(i),d=await o.createInferenceSessionHandler(s,u);return x(),new v(d)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}const M=v;var k,$,T,S,C,E,P,I,A,z,F,O,L,B,D,N,j,R,V,U,G,q,W,H,K,Q,X,J,Y,Z,ee,te,ne=Object.defineProperty,re=Object.getOwnPropertyDescriptor,se=Object.getOwnPropertyNames,ie=Object.prototype.hasOwnProperty,ae=(k=function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')},typeof require<"u"?require:typeof Proxy<"u"?new Proxy(k,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):k),oe=(e,t)=>()=>(e&&(t=e(e=0)),t),le=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})},ue=e=>((e,t,n,r)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of se(t))!ie.call(e,n)&&undefined!==n&&ne(e,n,{get:()=>t[n],enumerable:!(r=re(t,n))||r.enumerable});return e})(ne({},"__esModule",{value:!0}),e),de=oe((()=>{$=new Map,T=[],S=(e,t,n)=>{if(!t||"function"!=typeof t.init||"function"!=typeof t.createInferenceSessionHandler)throw new TypeError("not a valid backend");{let r=$.get(e);if(void 0===r)$.set(e,{backend:t,priority:n});else{if(r.priority>n)return;if(r.priority===n&&r.backend!==t)throw new Error(`cannot register backend "${e}" using priority ${n}`)}if(n>=0){let t=T.indexOf(e);-1!==t&&T.splice(t,1);for(let t=0;t<T.length;t++)if($.get(T[t]).priority<=n)return void T.splice(t,0,e);T.push(e)}}},C=async e=>{let t=$.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(e){return n||(t.error=`${e}`,t.aborted=!0),t.error}finally{delete t.initPromise}}},E=async e=>{let t,n=e.executionProviders||[],r=n.map((e=>"string"==typeof e?e:e.name)),s=0===r.length?T:r,i=[],a=new Set;for(let e of s){let n=await C(e);"string"==typeof n?i.push({name:e,err:n}):(t||(t=n),t===n&&a.add(e))}if(!t)throw new Error(`no available backend found. ERR: ${i.map((e=>`[${e.name}] ${e.err}`)).join(", ")}`);for(let{name:e,err:t}of i)r.includes(e)&&console.warn(`removing requested execution provider "${e}" from session options because it is not available: ${t}`);let o=n.filter((e=>a.has("string"==typeof e?e:e.name)));return[t,new Proxy(e,{get:(e,t)=>"executionProviders"===t?o:Reflect.get(e,t)})]}})),ce=oe((()=>{de()})),pe=oe((()=>{P="1.22.0-dev.20250409-89f8206ba4"})),he=oe((()=>{pe(),I="warning",A={wasm:{},webgl:{},webgpu:{},versions:{common:P},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}`);I=e}},get logLevel(){return I}},Object.defineProperty(A,"logLevel",{enumerable:!0})})),me=oe((()=>{he(),z=A})),fe=oe((()=>{F=(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 r=n.getContext("2d");if(null!=r){let s,i;void 0!==t?.tensorLayout&&"NHWC"===t.tensorLayout?(s=e.dims[2],i=e.dims[3]):(s=e.dims[3],i=e.dims[2]);let a,o,l=void 0!==t?.format?t.format:"RGB",u=t?.norm;void 0===u||void 0===u.mean?a=[255,255,255,255]:"number"==typeof u.mean?a=[u.mean,u.mean,u.mean,u.mean]:(a=[u.mean[0],u.mean[1],u.mean[2],0],void 0!==u.mean[3]&&(a[3]=u.mean[3])),void 0===u||void 0===u.bias?o=[0,0,0,0]:"number"==typeof u.bias?o=[u.bias,u.bias,u.bias,u.bias]:(o=[u.bias[0],u.bias[1],u.bias[2],0],void 0!==u.bias[3]&&(o[3]=u.bias[3]));let d=i*s,c=0,p=d,h=2*d,m=-1;"RGBA"===l?(c=0,p=d,h=2*d,m=3*d):"RGB"===l?(c=0,p=d,h=2*d):"RBG"===l&&(c=0,h=d,p=2*d);for(let t=0;t<i;t++)for(let n=0;n<s;n++){let s=(e.data[c++]-o[0])*a[0],i=(e.data[p++]-o[1])*a[1],l=(e.data[h++]-o[2])*a[2],u=-1===m?255:(e.data[m++]-o[3])*a[3];r.fillStyle="rgba("+s+","+i+","+l+","+u+")",r.fillRect(n,t,1,1)}if("toDataURL"in n)return n.toDataURL();throw new Error("toDataURL is not supported")}throw new Error("Can not access image data")},O=(e,t)=>{let n,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 s,i,a;void 0!==t?.tensorLayout&&"NHWC"===t.tensorLayout?(s=e.dims[2],i=e.dims[1],a=e.dims[3]):(s=e.dims[3],i=e.dims[2],a=e.dims[1]);let o,l,u=void 0!==t&&void 0!==t.format?t.format:"RGB",d=t?.norm;void 0===d||void 0===d.mean?o=[255,255,255,255]:"number"==typeof d.mean?o=[d.mean,d.mean,d.mean,d.mean]:(o=[d.mean[0],d.mean[1],d.mean[2],255],void 0!==d.mean[3]&&(o[3]=d.mean[3])),void 0===d||void 0===d.bias?l=[0,0,0,0]:"number"==typeof d.bias?l=[d.bias,d.bias,d.bias,d.bias]:(l=[d.bias[0],d.bias[1],d.bias[2],0],void 0!==d.bias[3]&&(l[3]=d.bias[3]));let c=i*s;if(void 0!==t&&(void 0!==t.format&&4===a&&"RGBA"!==t.format||3===a&&"RGB"!==t.format&&"BGR"!==t.format))throw new Error("Tensor format doesn't match input tensor dims");let p=4,h=0,m=1,f=2,_=3,g=0,w=c,b=2*c,y=-1;"RGBA"===u?(g=0,w=c,b=2*c,y=3*c):"RGB"===u?(g=0,w=c,b=2*c):"RBG"===u&&(g=0,b=c,w=2*c),n=r.createImageData(s,i);for(let t=0;t<i*s;h+=p,m+=p,f+=p,_+=p,t++)n.data[h]=(e.data[g++]-l[0])*o[0],n.data[m]=(e.data[w++]-l[1])*o[1],n.data[f]=(e.data[b++]-l[2])*o[2],n.data[_]=-1===y?255:(e.data[y++]-l[3])*o[3]}return n}})),_e=oe((()=>{be(),L=(e,t)=>{if(void 0===e)throw new Error("Image buffer must be defined");if(void 0===t.height||void 0===t.width)throw new Error("Image height and width must be defined");if("NHWC"===t.tensorLayout)throw new Error("NHWC Tensor layout is not supported yet");let n,r,{height:s,width:i}=t,a=t.norm??{mean:255,bias:0};n="number"==typeof a.mean?[a.mean,a.mean,a.mean,a.mean]:[a.mean[0],a.mean[1],a.mean[2],a.mean[3]??255],r="number"==typeof a.bias?[a.bias,a.bias,a.bias,a.bias]:[a.bias[0],a.bias[1],a.bias[2],a.bias[3]??0];let o=void 0!==t.format?t.format:"RGBA",l=void 0!==t.tensorFormat&&void 0!==t.tensorFormat?t.tensorFormat:"RGB",u=s*i,d="RGBA"===l?new Float32Array(4*u):new Float32Array(3*u),c=4,p=0,h=1,m=2,f=3,_=0,g=u,w=2*u,b=-1;"RGB"===o&&(c=3,p=0,h=1,m=2,f=-1),"RGBA"===l?b=3*u:"RBG"===l?(_=0,w=u,g=2*u):"BGR"===l&&(w=0,g=u,_=2*u);for(let t=0;t<u;t++,p+=c,m+=c,h+=c,f+=c)d[_++]=(e[p]+r[0])/n[0],d[g++]=(e[h]+r[1])/n[1],d[w++]=(e[m]+r[2])/n[2],-1!==b&&-1!==f&&(d[b++]=(e[f]+r[3])/n[3]);return new K("float32",d,"RGBA"===l?[1,4,s,i]:[1,3,s,i])},B=async(e,t)=>{let n,r=typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement,s=typeof ImageData<"u"&&e instanceof ImageData,i=typeof ImageBitmap<"u"&&e instanceof ImageBitmap,a="string"==typeof e,o=t??{},l=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},u=e=>typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||e instanceof OffscreenCanvas?e.getContext("2d"):null;if(r){let r=l();r.width=e.width,r.height=e.height;let s=u(r);if(null==s)throw new Error("Can not access image data");{let r=e.height,i=e.width;if(void 0!==t&&void 0!==t.resizedHeight&&void 0!==t.resizedWidth&&(r=t.resizedHeight,i=t.resizedWidth),void 0!==t){if(o=t,void 0!==t.tensorFormat)throw new Error("Image input config format must be RGBA for HTMLImageElement");o.tensorFormat="RGBA",o.height=r,o.width=i}else o.tensorFormat="RGBA",o.height=r,o.width=i;s.drawImage(e,0,0),n=s.getImageData(0,0,i,r).data}}else{if(!s){if(i){if(void 0===t)throw new Error("Please provide image config with format for Imagebitmap");let r=l();r.width=e.width,r.height=e.height;let s=u(r);if(null!=s){let t=e.height,r=e.width;return s.drawImage(e,0,0,r,t),n=s.getImageData(0,0,r,t).data,o.height=t,o.width=r,L(n,o)}throw new Error("Can not access image data")}if(a)return new Promise(((t,n)=>{let r=l(),s=u(r);if(!e||!s)return n();let i=new Image;i.crossOrigin="Anonymous",i.src=e,i.onload=()=>{r.width=i.width,r.height=i.height,s.drawImage(i,0,0,r.width,r.height);let e=s.getImageData(0,0,r.width,r.height);o.height=r.height,o.width=r.width,t(L(e.data,o))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{let r,s;if(void 0!==t&&void 0!==t.resizedWidth&&void 0!==t.resizedHeight?(r=t.resizedHeight,s=t.resizedWidth):(r=e.height,s=e.width),void 0!==t&&(o=t),o.format="RGBA",o.height=r,o.width=s,void 0!==t){let t=l();t.width=s,t.height=r;let i=u(t);if(null==i)throw new Error("Can not access image data");i.putImageData(e,0,0),n=i.getImageData(0,0,s,r).data}else n=e.data}}if(void 0!==n)return L(n,o);throw new Error("Input data provided is not supported - aborted tensor creation")},D=(e,t)=>{let{width:n,height:r,download:s,dispose:i}=t;return new K({location:"texture",type:"float32",texture:e,dims:[1,r,n,4],download:s,dispose:i})},N=(e,t)=>{let{dataType:n,dims:r,download:s,dispose:i}=t;return new K({location:"gpu-buffer",type:n??"float32",gpuBuffer:e,dims:r,download:s,dispose:i})},j=(e,t)=>{let{dataType:n,dims:r,download:s,dispose:i}=t;return new K({location:"ml-tensor",type:n??"float32",mlTensor:e,dims:r,download:s,dispose:i})},R=(e,t,n)=>new K({location:"cpu-pinned",type:e,data:t,dims:n??[t.length]})})),ge=oe((()=>{V=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),U=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),G=!1,q=()=>{if(!G){G=!0;let e=typeof BigInt64Array<"u"&&BigInt64Array.from,t=typeof BigUint64Array<"u"&&BigUint64Array.from,n=globalThis.Float16Array,r=typeof n<"u"&&n.from;e&&(V.set("int64",BigInt64Array),U.set(BigInt64Array,"int64")),t&&(V.set("uint64",BigUint64Array),U.set(BigUint64Array,"uint64")),r?(V.set("float16",n),U.set(n,"float16")):V.set("float16",Uint16Array)}}})),we=oe((()=>{be(),W=e=>{let t=1;for(let n=0;n<e.length;n++){let r=e[n];if("number"!=typeof r||!Number.isSafeInteger(r))throw new TypeError(`dims[${n}] must be an integer, got: ${r}`);if(r<0)throw new RangeError(`dims[${n}] must be a non-negative integer, got: ${r}`);t*=r}return t},H=(e,t)=>{switch(e.location){case"cpu":return new K(e.type,e.data,t);case"cpu-pinned":return new K({location:"cpu-pinned",data:e.data,type:e.type,dims:t});case"texture":return new K({location:"texture",texture:e.texture,type:e.type,dims:t});case"gpu-buffer":return new K({location:"gpu-buffer",gpuBuffer:e.gpuBuffer,type:e.type,dims:t});case"ml-tensor":return new K({location:"ml-tensor",mlTensor:e.mlTensor,type:e.type,dims:t});default:throw new Error(`tensorReshape: tensor location ${e.location} is not supported`)}}})),be=oe((()=>{fe(),_e(),ge(),we(),K=class{constructor(e,t,n){let r,s;if(q(),"object"==typeof e&&"location"in e)switch(this.dataLocation=e.location,r=e.type,s=e.dims,e.location){case"cpu-pinned":{let t=V.get(r);if(!t)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof t))throw new TypeError(`buffer should be of type ${t.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 i,a;if("string"==typeof e)if(r=e,a=n,"string"===e){if(!Array.isArray(t))throw new TypeError("A string tensor's data must be a string array.");i=t}else{let n=V.get(e);if(void 0===n)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(t)){if("float16"===e&&n===Uint16Array||"uint4"===e||"int4"===e)throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${n.name} as data.`);i="uint64"===e||"int64"===e?n.from(t,BigInt):n.from(t)}else if(t instanceof n)i=t;else if(t instanceof Uint8ClampedArray){if("uint8"!==e)throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");i=Uint8Array.from(t)}else{if(!("float16"===e&&t instanceof Uint16Array&&n!==Uint16Array))throw new TypeError(`A ${r} tensor's data must be type of ${n}`);i=new globalThis.Float16Array(t.buffer,t.byteOffset,t.length)}}else if(a=t,Array.isArray(e)){if(0===e.length)throw new TypeError("Tensor type cannot be inferred from an empty array.");let t=typeof e[0];if("string"===t)r="string",i=e;else{if("boolean"!==t)throw new TypeError(`Invalid element type of data array: ${t}.`);r="bool",i=Uint8Array.from(e)}}else if(e instanceof Uint8ClampedArray)r="uint8",i=Uint8Array.from(e);else{let t=U.get(e.constructor);if(void 0===t)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=t,i=e}if(void 0===a)a=[i.length];else if(!Array.isArray(a))throw new TypeError("A tensor's dims must be a number array");s=a,this.cpuData=i,this.dataLocation="cpu"}let i=W(s);if(this.cpuData&&i!==this.cpuData.length&&("uint4"!==r&&"int4"!==r||Math.ceil(i/2)!==this.cpuData.length))throw new Error(`Tensor's size(${i}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=s,this.size=i}static async fromImage(e,t){return B(e,t)}static fromTexture(e,t){return D(e,t)}static fromGpuBuffer(e,t){return N(e,t)}static fromMLTensor(e,t){return j(e,t)}static fromPinnedBuffer(e,t,n){return R(e,t,n)}toDataURL(e){return F(this,e)}toImageData(e){return O(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 t=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=t,e&&this.disposer&&(this.disposer(),this.disposer=void 0),t}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 H(this,e)}}})),ye=oe((()=>{be(),Q=K})),xe=oe((()=>{he(),X=(e,t)=>{(typeof A.trace>"u"?!A.wasm.trace:!A.trace)||console.timeStamp(`${e}::ORT::${t}`)},J=(e,t)=>{let n=(new Error).stack?.split(/\r\n|\r|\n/g)||[],r=!1;for(let s=0;s<n.length;s++){if(r&&!n[s].includes("TRACE_FUNC")){let r=`FUNC_${e}::${n[s].trim().split(" ")[1]}`;return t&&(r+=`::${t}`),void X("CPU",r)}n[s].includes("TRACE_FUNC")&&(r=!0)}},Y=e=>{(typeof A.trace>"u"?!A.wasm.trace:!A.trace)||J("BEGIN",e)},Z=e=>{(typeof A.trace>"u"?!A.wasm.trace:!A.trace)||J("END",e)}})),ve=oe((()=>{de(),ye(),xe(),ee=class e{constructor(e){this.handler=e}async run(e,t,n){Y();let r={},s={};if("object"!=typeof e||null===e||e instanceof Q||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let i=!0;if("object"==typeof t){if(null===t)throw new TypeError("Unexpected argument[1]: cannot be null.");if(t instanceof Q)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(t)){if(0===t.length)throw new TypeError("'fetches' cannot be an empty array.");i=!1;for(let e of t){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 n&&null!==n)s=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else{let e=!1,a=Object.getOwnPropertyNames(t);for(let n of this.outputNames)if(-1!==a.indexOf(n)){let s=t[n];(null===s||s instanceof Q)&&(e=!0,i=!1,r[n]=s)}if(e){if("object"==typeof n&&null!==n)s=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else s=t}}else if(typeof t<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let t of this.inputNames)if(typeof e[t]>"u")throw new Error(`input '${t}' is missing in 'feeds'.`);if(i)for(let e of this.outputNames)r[e]=null;let a=await this.handler.run(e,r,s),o={};for(let e in a)if(Object.hasOwnProperty.call(a,e)){let t=a[e];o[e]=t instanceof Q?t:new Q(t.type,t.data,t.dims)}return Z(),o}async release(){return this.handler.dispose()}static async create(t,n,r,s){Y();let i,a={};if("string"==typeof t){if(i=t,"object"==typeof n&&null!==n)a=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else if(t instanceof Uint8Array){if(i=t,"object"==typeof n&&null!==n)a=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))throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");{let e=t,o=0,l=t.byteLength;if("object"==typeof n&&null!==n)a=n;else if("number"==typeof n){if(o=n,!Number.isSafeInteger(o))throw new RangeError("'byteOffset' must be an integer.");if(o<0||o>=e.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${e.byteLength}).`);if(l=t.byteLength-o,"number"==typeof r){if(l=r,!Number.isSafeInteger(l))throw new RangeError("'byteLength' must be an integer.");if(l<=0||o+l>e.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${e.byteLength-o}].`);if("object"==typeof s&&null!==s)a=s;else if(typeof s<"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 n<"u")throw new TypeError("'options' must be an object.");i=new Uint8Array(e,o,l)}}let[o,l]=await E(a),u=await o.createInferenceSessionHandler(i,l);return Z(),new e(u)}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}}})),Me=oe((()=>{ve(),te=ee})),ke=oe((()=>{})),$e=oe((()=>{})),Te=oe((()=>{})),Se=oe((()=>{})),Ce={};le(Ce,{InferenceSession:()=>te,TRACE:()=>X,TRACE_FUNC_BEGIN:()=>Y,TRACE_FUNC_END:()=>Z,Tensor:()=>Q,env:()=>z,registerBackend:()=>S});var Ee=oe((()=>{ce(),me(),Me(),ye(),ke(),$e(),xe(),Te(),Se()})),Pe=oe((()=>{})),Ie={};le(Ie,{default:()=>Fe});var Ae,ze,Fe,Oe=oe((()=>{Ac(),Tu(),$u(),Ae="ort-wasm-proxy-worker",(ze=globalThis.self?.name===Ae)&&(self.onmessage=e=>{let{type:t,in:n}=e.data;try{switch(t){case"init-wasm":lt(n.wasm).then((()=>{Yd(n).then((()=>{postMessage({type:t})}),(e=>{postMessage({type:t,err:e})}))}),(e=>{postMessage({type:t,err:e})}));break;case"init-ep":{let{epName:e,env:r}=n;Zd(r,e).then((()=>{postMessage({type:t})}),(e=>{postMessage({type:t,err:e})}));break}case"copy-from":{let{buffer:e}=n,r=rc(e);postMessage({type:t,out:r});break}case"create":{let{model:e,options:r}=n;sc(e,r).then((e=>{postMessage({type:t,out:e})}),(e=>{postMessage({type:t,err:e})}));break}case"release":ic(n),postMessage({type:t});break;case"run":{let{sessionId:e,inputIndices:r,inputs:s,outputIndices:i,options:a}=n;oc(e,r,s,i,new Array(i.length).fill(null),a).then((e=>{e.some((e=>"cpu"!==e[3]))?postMessage({type:t,err:"Proxy does not support non-cpu tensor location."}):postMessage({type:t,out:e},uc([...s,...e]))}),(e=>{postMessage({type:t,err:e})}));break}case"end-profiling":lc(n),postMessage({type:t})}}catch(e){postMessage({type:t,err:e})}}),Fe=ze?null:e=>new Worker(e??Ge,{type:"module",name:Ae})})),Le={};le(Le,{default:()=>Ne});var Be,De,Ne,je,Re,Ve,Ue,Ge,qe,We,He,Ke,Qe,Xe,Je,Ye,Ze,et,tt,nt,rt,st,it,at,ot,lt,ut,dt,ct,pt,ht,mt,ft,_t,gt,wt,bt,yt,xt,vt,Mt,kt,$t,Tt,St,Ct,Et,Pt,It,At,zt,Ft,Ot,Lt,Bt,Dt,Nt,jt,Rt,Vt,Ut,Gt,qt,Wt,Ht,Kt,Qt,Xt,Jt,Yt,Zt,en,tn,nn,rn,sn,an,on,ln,un,dn,cn,pn,hn,mn,fn,_n,gn,wn,bn,yn,xn,vn,Mn,kn,$n,Tn,Sn,Cn,En,Pn,In,An,zn,Fn,On,Ln,Bn,Dn,Nn,jn,Rn,Vn,Un,Gn,qn,Wn,Hn,Kn,Qn,Xn,Jn,Yn,Zn,er,tr,nr,rr,sr,ir,ar,or,lr,ur,dr,cr,pr,hr,mr,fr,_r,gr,wr,br,yr,xr,vr,Mr,kr,$r,Tr,Sr,Cr,Er,Pr,Ir,Ar,zr,Fr,Or,Lr,Br,Dr,Nr,jr,Rr,Vr,Ur,Gr,qr,Wr,Hr,Kr,Qr,Xr,Jr,Yr,Zr,es,ts,ns,rs,ss,is,as,os,ls,us,ds,cs,ps,hs,ms,fs,_s,gs,ws,bs,ys,xs,vs,Ms,ks,$s,Ts,Ss,Cs,Es,Ps,Is,As,zs,Fs,Os,Ls,Bs,Ds,Ns,js,Rs,Vs,Us,Gs,qs,Ws,Hs,Ks,Qs,Xs,Js,Ys,Zs,ei,ti,ni,ri,si,ii,ai,oi,li,ui,di,ci,pi,hi,mi,fi,_i,gi,wi,bi,yi,xi,vi,Mi,ki,$i,Ti,Si,Ci,Ei,Pi,Ii,Ai,zi,Fi,Oi,Li,Bi,Di,Ni,ji,Ri,Vi,Ui,Gi,qi,Wi,Hi,Ki,Qi,Xi,Ji,Yi,Zi,ea,ta,na,ra,sa,ia,aa,oa,la,ua,da,ca,pa,ha,ma,fa,_a,ga,wa,ba,ya,xa,va,Ma,ka,$a,Ta,Sa,Ca,Ea,Pa,Ia,Aa,za,Fa,Oa,La,Ba,Da,Na,ja,Ra,Va,Ua,Ga,qa,Wa,Ha,Ka,Qa,Xa,Ja,Ya,Za,eo,to,no,ro,so,io,ao,oo,lo,uo,co,po,ho,mo,fo,_o,go,wo,bo,yo,xo,vo,Mo,ko,$o,To,So,Co,Eo,Po,Io,Ao,zo,Fo,Oo,Lo,Bo,Do,No,jo,Ro,Vo,Uo,Go,qo,Wo,Ho,Ko,Qo,Xo,Jo,Yo,Zo,el,tl,nl,rl,sl,il,al,ol,ll,ul,dl,cl,pl,hl,ml,fl,_l,gl,wl,bl,yl,xl,vl,Ml,kl,$l,Tl,Sl,Cl,El,Pl,Il,Al,zl,Fl,Ol,Ll,Bl,Dl,Nl,jl,Rl,Vl,Ul,Gl,ql,Wl,Hl,Kl,Ql,Xl,Jl,Yl,Zl,eu,tu,nu,ru,su,iu,au,ou,lu,uu,du,cu,pu,hu,mu,fu,_u,gu,wu,bu,yu,xu,vu,Mu,ku=oe((()=>{Be="file:///Users/juanpin/code/browserbrains/node_modules/.pnpm/onnxruntime-web@1.22.0-dev.20250409-89f8206ba4/node_modules/onnxruntime-web/dist/ort.bundle.min.mjs",De=async function(e={}){var t,r,s=e,i=new Promise(((e,n)=>{t=e,r=n})),a="object"==typeof window,o=typeof WorkerGlobalScope<"u",l=o&&self.name?.startsWith("em-pthread");s.mountExternalData=(e,t)=>{e.startsWith("./")&&(e=e.substring(2)),(s.Eb||(s.Eb=new Map)).set(e,t)},s.unmountExternalData=()=>{delete s.Eb};var u=globalThis.SharedArrayBuffer??new WebAssembly.Memory({initial:0,maximum:0,pc:!0}).buffer.constructor;let d=e=>async(...t)=>{try{if(s.Fb)throw Error("Session already started");let n=s.Fb={dc:t[0],errors:[]},r=await e(...t);if(s.Fb!==n)throw Error("Session mismatch");s.Jb?.flush();let i=n.errors;if(0<i.length){let e=await Promise.all(i);if(e=e.filter((e=>e)),0<e.length)throw Error(e.join("\n"))}return r}finally{s.Fb=null}};s.jsepInit=(e,t)=>{if("webgpu"===e){[s.Jb,s.Ub,s.Yb,s.Kb,s.Xb,s.jb,s.Zb,s.ac,s.Vb,s.Wb,s.$b]=t;let e=s.Jb;s.jsepRegisterBuffer=(t,n,r,s)=>e.registerBuffer(t,n,r,s),s.jsepGetBuffer=t=>e.getBuffer(t),s.jsepCreateDownloader=(t,n,r)=>e.createDownloader(t,n,r),s.jsepOnCreateSession=t=>{e.onCreateSession(t)},s.jsepOnReleaseSession=t=>{e.onReleaseSession(t)},s.jsepOnRunStart=t=>e.onRunStart(t),s.bc=(t,n)=>{e.upload(t,n)}}else if("webnn"===e){let e=t[0];[s.nc,s.Nb,s.webnnEnsureTensor,s.Ob,s.webnnDownloadTensor]=t.slice(1),s.webnnReleaseTensorId=s.Nb,s.webnnUploadTensor=s.Ob,s.webnnOnRunStart=t=>e.onRunStart(t),s.webnnOnRunEnd=e.onRunEnd.bind(e),s.webnnRegisterMLContext=(t,n)=>{e.registerMLContext(t,n)},s.webnnOnReleaseSession=t=>{e.onReleaseSession(t)},s.webnnCreateMLTensorDownloader=(t,n)=>e.createMLTensorDownloader(t,n),s.webnnRegisterMLTensor=(t,n,r,s)=>e.registerMLTensor(t,n,r,s),s.webnnCreateMLContext=t=>e.createMLContext(t),s.webnnRegisterMLConstant=(t,n,r,i,a,o)=>e.registerMLConstant(t,n,r,i,a,s.Eb,o),s.webnnRegisterGraphInput=e.registerGraphInput.bind(e),s.webnnIsGraphInput=e.isGraphInput.bind(e),s.webnnCreateTemporaryTensor=e.createTemporaryTensor.bind(e),s.webnnIsInt64Supported=e.isInt64Supported.bind(e)}};let c=()=>{let e=(e,t,n)=>(...r)=>{let s=Vt,i=t?.();r=e(...r);let a=t?.();return i!==a&&(e=a,n(i),t=n=null),Vt!=s?new Promise(((e,t)=>{Kt={resolve:e,reject:t}})):r};(()=>{for(let t of["_OrtAppendExecutionProvider","_OrtCreateSession","_OrtRun","_OrtRunWithBinding","_OrtBindInput"])s[t]=e(s[t],(()=>s[t]),(e=>s[t]=e))})(),void 0!==d&&(s._OrtRun=d(s._OrtRun),s._OrtRunWithBinding=d(s._OrtRunWithBinding)),c=void 0};s.asyncInit=()=>{c?.()};var p,h,m=Object.assign({},s),f=(e,t)=>{throw t},_="";(a||o)&&(o?_=self.location.href:typeof document<"u"&&document.currentScript&&(_=document.currentScript.src),Be&&(_=Be),_=_.startsWith("blob:")?"":_.slice(0,_.replace(/[?#].*/,"").lastIndexOf("/")+1),o&&(h=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}),p=async e=>{if(L(e))return new Promise(((t,n)=>{var r=new XMLHttpRequest;r.open("GET",e,!0),r.responseType="arraybuffer",r.onload=()=>{200==r.status||0==r.status&&r.response?t(r.response):n(r.status)},r.onerror=n,r.send(null)}));var t=await fetch(e,{credentials:"same-origin"});if(t.ok)return t.arrayBuffer();throw Error(t.status+" : "+t.url)});var g=console.log.bind(console),w=console.error.bind(console),b=g,y=w;Object.assign(s,m),m=null;var x,v,M,k,$,T,S,C,E,P,I,A,z,F=s.wasmBinary,O=!1,L=e=>e.startsWith("file://");function B(){return x.buffer!=k.buffer&&H(),k}function D(){return x.buffer!=k.buffer&&H(),$}function N(){return x.buffer!=k.buffer&&H(),T}function j(){return x.buffer!=k.buffer&&H(),S}function R(){return x.buffer!=k.buffer&&H(),C}function V(){return x.buffer!=k.buffer&&H(),E}function U(){return x.buffer!=k.buffer&&H(),P}function G(){return x.buffer!=k.buffer&&H(),z}if(l){let e=function(t){try{var n=t.data,r=n.Bb;if("load"===r){let t=[];self.onmessage=e=>t.push(e),self.startWorker=()=>{postMessage({Bb:"loaded"});for(let n of t)e(n);self.onmessage=e};for(let e of n.Rb)s[e]&&!s[e].proxy||(s[e]=(...t)=>{postMessage({Bb:"callHandler",Qb:e,args:t})},"print"==e&&(b=s[e]),"printErr"==e&&(y=s[e]));x=n.kc,H(),q(n.lc)}else if("run"===r){xe(n.Ab),_r(n.Ab,0,0,1,0,0),we(),Ct(n.Ab),W||(pr(),W=!0);try{ve(n.fc,n.Hb)}catch(e){if("unwind"!=e)throw e}}else"setimmediate"!==n.target&&("checkMailbox"===r?W&&Et():r&&(y(`worker: received unknown command ${r}`),y(n)))}catch(e){throw gr(),e}};var q,W=!1;y=function(...e){e=e.join(" "),console.error(e)},self.alert=function(...e){postMessage({Bb:"alert",text:e.join(" "),ic:hr()})},self.onunhandledrejection=e=>{throw e.reason||e},self.onmessage=e}function H(){var e=x.buffer;s.HEAP8=k=new Int8Array(e),s.HEAP16=T=new Int16Array(e),s.HEAPU8=$=new Uint8Array(e),s.HEAPU16=S=new Uint16Array(e),s.HEAP32=C=new Int32Array(e),s.HEAPU32=E=new Uint32Array(e),s.HEAPF32=P=new Float32Array(e),s.HEAPF64=z=new Float64Array(e),s.HEAP64=I=new BigInt64Array(e),s.HEAPU64=A=new BigUint64Array(e)}function K(){l?startWorker(s):ur.Ca()}l||(x=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),H());var Q,X=0,J=null;function Y(){if(0==--X&&J){var e=J;J=null,e()}}function Z(e){throw y(e="Aborted("+e+")"),O=!0,e=new WebAssembly.RuntimeError(e+". Build with -sASSERTIONS for more info."),r(e),e}function ee(){return{a:{L:re,Aa:ne,b:ke,$:Te,A:Pe,pa:Ie,X:Fe,Z:Oe,qa:Le,na:De,ga:Ne,ma:je,J:Re,Y:Ve,V:Ue,oa:Ge,W:qe,va:Ke,E:tt,Q:rt,O:ct,D:ht,u:mt,r:ft,P:_t,z:kt,R:$t,ja:Tt,T:Pt,aa:At,M:zt,F:Ft,ia:Ct,sa:Ot,t:Dt,Ba:Nt,w:Jt,o:Zt,l:nn,c:at,n:sn,j:un,v:dn,p:cn,f:pn,s:hn,m:mn,e:fn,k:_n,i:gn,g:wn,d:bn,da:yn,ea:kn,fa:$n,ba:Tn,ca:Sn,N:Pn,xa:In,ua:Fn,h:Bn,C:Dn,G:Nn,ta:An,x:jn,ra:Rn,U:Vn,q:En,y:Un,K:Gn,S:qn,za:Qn,ya:Xn,ka:er,la:tr,_:pe,B:nr,I:rr,ha:sr,H:ar,a:x,wa:de}}}var te={829644:(e,t,n,r,i)=>{if(void 0===s||!s.Eb)return 1;if((e=Ee(Number(e>>>0))).startsWith("./")&&(e=e.substring(2)),!(e=s.Eb.get(e)))return 2;if(t=Number(t>>>0),n=Number(n>>>0),r=Number(r>>>0),t+n>e.byteLength)return 3;try{let a=e.subarray(t,t+n);switch(i){case 0:D().set(a,r>>>0);break;case 1:s.mc?s.mc(r,a):s.bc(r,a);break;default:return 4}return 0}catch{return 4}},830468:(e,t,n)=>{s.Ob(e,D().subarray(t>>>0,t+n>>>0))},830532:()=>s.nc(),830574:e=>{s.Nb(e)},830611:()=>{s.Vb()},830642:()=>{s.Wb()},830671:()=>{s.$b()},830696:e=>s.Ub(e),830729:e=>s.Yb(e),830761:(e,t,n)=>{s.Kb(Number(e),Number(t),Number(n),!0)},830824:(e,t,n)=>{s.Kb(Number(e),Number(t),Number(n))},830881:()=>typeof wasmOffsetConverter<"u",830938:e=>{s.jb("Abs",e,void 0)},830989:e=>{s.jb("Neg",e,void 0)},831040:e=>{s.jb("Floor",e,void 0)},831093:e=>{s.jb("Ceil",e,void 0)},831145:e=>{s.jb("Reciprocal",e,void 0)},831203:e=>{s.jb("Sqrt",e,void 0)},831255:e=>{s.jb("Exp",e,void 0)},831306:e=>{s.jb("Erf",e,void 0)},831357:e=>{s.jb("Sigmoid",e,void 0)},831412:(e,t,n)=>{s.jb("HardSigmoid",e,{alpha:t,beta:n})},831491