onnxruntime-web
Version:
A Javascript library for running ONNX models on browsers
6 lines • 420 kB
JavaScript
/*!
* ONNX Runtime Web v1.17.3
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
"use strict";var ort=(()=>{var Dl=Object.create;var Ne=Object.defineProperty;var Ll=Object.getOwnPropertyDescriptor;var $l=Object.getOwnPropertyNames;var kl=Object.getPrototypeOf,Bl=Object.prototype.hasOwnProperty;var x=(a,e)=>()=>(a&&(e=a(a=0)),e);var Z=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),Br=(a,e)=>{for(var o in e)Ne(a,o,{get:e[o],enumerable:!0})},qn=(a,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of $l(e))!Bl.call(a,r)&&r!==o&&Ne(a,r,{get:()=>e[r],enumerable:!(t=Ll(e,r))||t.enumerable});return a};var ne=(a,e,o)=>(o=a!=null?Dl(kl(a)):{},qn(e||!a||!a.__esModule?Ne(o,"default",{value:a,enumerable:!0}):o,a)),jn=a=>qn(Ne({},"__esModule",{value:!0}),a);var Ce,Ut,be,Fl,Ge,Re=x(()=>{"use strict";Ce=new Map,Ut=[],be=(a,e,o)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let t=Ce.get(a);if(t===void 0)Ce.set(a,{backend:e,priority:o});else{if(t.priority>o)return;if(t.priority===o&&t.backend!==e)throw new Error(`cannot register backend "${a}" using priority ${o}`)}if(o>=0){let r=Ut.indexOf(a);r!==-1&&Ut.splice(r,1);for(let n=0;n<Ut.length;n++)if(Ce.get(Ut[n]).priority<=o){Ut.splice(n,0,a);return}Ut.push(a)}return}throw new TypeError("not a valid backend")},Fl=async a=>{let e=Ce.get(a);if(!e)return"backend not found.";if(e.initialized)return e.backend;if(e.aborted)return e.error;{let o=!!e.initPromise;try{return o||(e.initPromise=e.backend.init(a)),await e.initPromise,e.initialized=!0,e.backend}catch(t){return o||(e.error=`${t}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},Ge=async a=>{let e=a.executionProviders||[],o=e.map(u=>typeof u=="string"?u:u.name),t=o.length===0?Ut:o,r,n=[],s=new Set;for(let u of t){let l=await Fl(u);typeof l=="string"?n.push({name:u,err:l}):(r||(r=l),r===l&&s.add(u))}if(!r)throw new Error(`no available backend found. ERR: ${n.map(u=>`[${u.name}] ${u.err}`).join(", ")}`);for(let{name:u,err:l}of n)o.includes(u)&&console.warn(`removing requested execution provider "${u}" from session options because it is not available: ${l}`);let i=e.filter(u=>s.has(typeof u=="string"?u:u.name));return[r,new Proxy(a,{get:(u,l)=>l==="executionProviders"?i:Reflect.get(u,l)})]}});var Kn=x(()=>{"use strict";Re()});var Xn,Jn=x(()=>{"use strict";Xn="1.17.3"});var Zn,ct,Fr=x(()=>{"use strict";Jn();Zn="warning",ct={wasm:{},webgl:{},webgpu:{},versions:{common:Xn},set logLevel(a){if(a!==void 0){if(typeof a!="string"||["verbose","info","warning","error","fatal"].indexOf(a)===-1)throw new Error(`Unsupported logging level: ${a}`);Zn=a}},get logLevel(){return Zn}};Object.defineProperty(ct,"logLevel",{enumerable:!0})});var j,Yn=x(()=>{"use strict";Fr();j=ct});var Qn,to,eo=x(()=>{"use strict";Qn=(a,e)=>{let o=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);o.width=a.dims[3],o.height=a.dims[2];let t=o.getContext("2d");if(t!=null){let r,n;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=a.dims[2],n=a.dims[3]):(r=a.dims[3],n=a.dims[2]);let s=e?.format!==void 0?e.format:"RGB",i=e?.norm,u,l;i===void 0||i.mean===void 0?u=[255,255,255,255]:typeof i.mean=="number"?u=[i.mean,i.mean,i.mean,i.mean]:(u=[i.mean[0],i.mean[1],i.mean[2],0],i.mean[3]!==void 0&&(u[3]=i.mean[3])),i===void 0||i.bias===void 0?l=[0,0,0,0]:typeof i.bias=="number"?l=[i.bias,i.bias,i.bias,i.bias]:(l=[i.bias[0],i.bias[1],i.bias[2],0],i.bias[3]!==void 0&&(l[3]=i.bias[3]));let f=n*r,p=0,d=f,b=f*2,g=-1;s==="RGBA"?(p=0,d=f,b=f*2,g=f*3):s==="RGB"?(p=0,d=f,b=f*2):s==="RBG"&&(p=0,b=f,d=f*2);for(let y=0;y<n;y++)for(let v=0;v<r;v++){let _=(a.data[p++]-l[0])*u[0],A=(a.data[d++]-l[1])*u[1],S=(a.data[b++]-l[2])*u[2],C=g===-1?255:(a.data[g++]-l[3])*u[3];t.fillStyle="rgba("+_+","+A+","+S+","+C+")",t.fillRect(v,y,1,1)}if("toDataURL"in o)return o.toDataURL();throw new Error("toDataURL is not supported")}else throw new Error("Can not access image data")},to=(a,e)=>{let o=typeof document<"u"?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d"),t;if(o!=null){let r,n,s;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=a.dims[2],n=a.dims[1],s=a.dims[3]):(r=a.dims[3],n=a.dims[2],s=a.dims[1]);let i=e!==void 0&&e.format!==void 0?e.format:"RGB",u=e?.norm,l,f;u===void 0||u.mean===void 0?l=[255,255,255,255]:typeof u.mean=="number"?l=[u.mean,u.mean,u.mean,u.mean]:(l=[u.mean[0],u.mean[1],u.mean[2],255],u.mean[3]!==void 0&&(l[3]=u.mean[3])),u===void 0||u.bias===void 0?f=[0,0,0,0]:typeof u.bias=="number"?f=[u.bias,u.bias,u.bias,u.bias]:(f=[u.bias[0],u.bias[1],u.bias[2],0],u.bias[3]!==void 0&&(f[3]=u.bias[3]));let p=n*r;if(e!==void 0&&(e.format!==void 0&&s===4&&e.format!=="RGBA"||s===3&&e.format!=="RGB"&&e.format!=="BGR"))throw new Error("Tensor format doesn't match input tensor dims");let d=4,b=0,g=1,y=2,v=3,_=0,A=p,S=p*2,C=-1;i==="RGBA"?(_=0,A=p,S=p*2,C=p*3):i==="RGB"?(_=0,A=p,S=p*2):i==="RBG"&&(_=0,S=p,A=p*2),t=o.createImageData(r,n);for(let F=0;F<n*r;b+=d,g+=d,y+=d,v+=d,F++)t.data[b]=(a.data[_++]-f[0])*l[0],t.data[g]=(a.data[A++]-f[1])*l[1],t.data[y]=(a.data[S++]-f[2])*l[2],t.data[v]=C===-1?255:(a.data[C++]-f[3])*l[3]}else throw new Error("Can not access image data");return t}});var Nr,ro,no,oo,io,ao=x(()=>{"use strict";Ve();Nr=(a,e)=>{if(a===void 0)throw new Error("Image buffer must be defined");if(e.height===void 0||e.width===void 0)throw new Error("Image height and width must be defined");if(e.tensorLayout==="NHWC")throw new Error("NHWC Tensor layout is not supported yet");let{height:o,width:t}=e,r=e.norm??{mean:255,bias:0},n,s;typeof r.mean=="number"?n=[r.mean,r.mean,r.mean,r.mean]:n=[r.mean[0],r.mean[1],r.mean[2],r.mean[3]??255],typeof r.bias=="number"?s=[r.bias,r.bias,r.bias,r.bias]:s=[r.bias[0],r.bias[1],r.bias[2],r.bias[3]??0];let i=e.format!==void 0?e.format:"RGBA",u=e.tensorFormat!==void 0&&e.tensorFormat!==void 0?e.tensorFormat:"RGB",l=o*t,f=u==="RGBA"?new Float32Array(l*4):new Float32Array(l*3),p=4,d=0,b=1,g=2,y=3,v=0,_=l,A=l*2,S=-1;i==="RGB"&&(p=3,d=0,b=1,g=2,y=-1),u==="RGBA"?S=l*3:u==="RBG"?(v=0,A=l,_=l*2):u==="BGR"&&(A=0,_=l,v=l*2);for(let F=0;F<l;F++,d+=p,g+=p,b+=p,y+=p)f[v++]=(a[d]+s[0])/n[0],f[_++]=(a[b]+s[1])/n[1],f[A++]=(a[g]+s[2])/n[2],S!==-1&&y!==-1&&(f[S++]=(a[y]+s[3])/n[3]);return u==="RGBA"?new ot("float32",f,[1,4,o,t]):new ot("float32",f,[1,3,o,t])},ro=async(a,e)=>{let o=typeof HTMLImageElement<"u"&&a instanceof HTMLImageElement,t=typeof ImageData<"u"&&a instanceof ImageData,r=typeof ImageBitmap<"u"&&a instanceof ImageBitmap,n=typeof a=="string",s,i=e??{},u=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},l=f=>f instanceof HTMLCanvasElement||f instanceof OffscreenCanvas?f.getContext("2d"):null;if(o){let f=u();f.width=a.width,f.height=a.height;let p=l(f);if(p!=null){let d=a.height,b=a.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(d=e.resizedHeight,b=e.resizedWidth),e!==void 0){if(i=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");i.tensorFormat="RGBA",i.height=d,i.width=b}else i.tensorFormat="RGBA",i.height=d,i.width=b;p.drawImage(a,0,0),s=p.getImageData(0,0,b,d).data}else throw new Error("Can not access image data")}else if(t){let f,p;if(e!==void 0&&e.resizedWidth!==void 0&&e.resizedHeight!==void 0?(f=e.resizedHeight,p=e.resizedWidth):(f=a.height,p=a.width),e!==void 0&&(i=e),i.format="RGBA",i.height=f,i.width=p,e!==void 0){let d=u();d.width=p,d.height=f;let b=l(d);if(b!=null)b.putImageData(a,0,0),s=b.getImageData(0,0,p,f).data;else throw new Error("Can not access image data")}else s=a.data}else if(r){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let f=u();f.width=a.width,f.height=a.height;let p=l(f);if(p!=null){let d=a.height,b=a.width;return p.drawImage(a,0,0,b,d),s=p.getImageData(0,0,b,d).data,i.height=d,i.width=b,Nr(s,i)}else throw new Error("Can not access image data")}else{if(n)return new Promise((f,p)=>{let d=u(),b=l(d);if(!a||!b)return p();let g=new Image;g.crossOrigin="Anonymous",g.src=a,g.onload=()=>{d.width=g.width,d.height=g.height,b.drawImage(g,0,0,d.width,d.height);let y=b.getImageData(0,0,d.width,d.height);i.height=d.height,i.width=d.width,f(Nr(y.data,i))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return Nr(s,i);throw new Error("Input data provided is not supported - aborted tensor creation")},no=(a,e)=>{let{width:o,height:t,download:r,dispose:n}=e,s=[1,t,o,4];return new ot({location:"texture",type:"float32",texture:a,dims:s,download:r,dispose:n})},oo=(a,e)=>{let{dataType:o,dims:t,download:r,dispose:n}=e;return new ot({location:"gpu-buffer",type:o??"float32",gpuBuffer:a,dims:t,download:r,dispose:n})},io=(a,e,o)=>new ot({location:"cpu-pinned",type:a,data:e,dims:o??[e.length]})});var Wt,ye,so,uo,lo=x(()=>{"use strict";Wt=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array]]),ye=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),so=!1,uo=()=>{if(!so){so=!0;let a=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,o=typeof Float16Array<"u"&&Float16Array.from;a&&(Wt.set("int64",BigInt64Array),ye.set(BigInt64Array,"int64")),e&&(Wt.set("uint64",BigUint64Array),ye.set(BigUint64Array,"uint64")),o?(Wt.set("float16",Float16Array),ye.set(Float16Array,"float16")):Wt.set("float16",Uint16Array)}}});var fo,co,po=x(()=>{"use strict";Ve();fo=a=>{let e=1;for(let o=0;o<a.length;o++){let t=a[o];if(typeof t!="number"||!Number.isSafeInteger(t))throw new TypeError(`dims[${o}] must be an integer, got: ${t}`);if(t<0)throw new RangeError(`dims[${o}] must be a non-negative integer, got: ${t}`);e*=t}return e},co=(a,e)=>{switch(a.location){case"cpu":return new ot(a.type,a.data,e);case"cpu-pinned":return new ot({location:"cpu-pinned",data:a.data,type:a.type,dims:e});case"texture":return new ot({location:"texture",texture:a.texture,type:a.type,dims:e});case"gpu-buffer":return new ot({location:"gpu-buffer",gpuBuffer:a.gpuBuffer,type:a.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${a.location} is not supported`)}}});var ot,Ve=x(()=>{"use strict";eo();ao();lo();po();ot=class{constructor(e,o,t){uo();let r,n;if(typeof e=="object"&&"location"in e)switch(this.dataLocation=e.location,r=e.type,n=e.dims,e.location){case"cpu-pinned":{let i=Wt.get(r);if(!i)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof i))throw new TypeError(`buffer should be of type ${i.name}`);this.cpuData=e.data;break}case"texture":{if(r!=="float32")throw new TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint8"&&r!=="bool")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}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let i,u;if(typeof e=="string")if(r=e,u=t,e==="string"){if(!Array.isArray(o))throw new TypeError("A string tensor's data must be a string array.");i=o}else{let l=Wt.get(e);if(l===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(o)){if(e==="float16"&&l===Uint16Array)throw new TypeError("Creating a float16 tensor from number array is not supported. Please use Uint16Array as data.");e==="uint64"||e==="int64"?i=l.from(o,BigInt):i=l.from(o)}else if(o instanceof l)i=o;else throw new TypeError(`A ${r} tensor's data must be type of ${l}`)}else if(u=o,Array.isArray(e)){if(e.length===0)throw new TypeError("Tensor type cannot be inferred from an empty array.");let l=typeof e[0];if(l==="string")r="string",i=e;else if(l==="boolean")r="bool",i=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${l}.`)}else{let l=ye.get(e.constructor);if(l===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=l,i=e}if(u===void 0)u=[i.length];else if(!Array.isArray(u))throw new TypeError("A tensor's dims must be a number array");n=u,this.cpuData=i,this.dataLocation="cpu"}let s=fo(n);if(this.cpuData&&s!==this.cpuData.length)throw new Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=n,this.size=s}static async fromImage(e,o){return ro(e,o)}static fromTexture(e,o){return no(e,o)}static fromGpuBuffer(e,o){return oo(e,o)}static fromPinnedBuffer(e,o,t){return io(e,o,t)}toDataURL(e){return Qn(this,e)}toImageData(e){return to(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}async getData(e){switch(this.ensureValid(),this.dataLocation){case"cpu":case"cpu-pinned":return this.data;case"texture":case"gpu-buffer":{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 o=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=o,e&&this.disposer&&(this.disposer(),this.disposer=void 0),o}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.downloader=void 0,this.isDownloading=void 0,this.dataLocation="none"}ensureValid(){if(this.dataLocation==="none")throw new Error("The tensor is disposed.")}reshape(e){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return co(this,e)}}});var rt,ze=x(()=>{"use strict";Ve();rt=ot});var Cr,ho,ge,xe,Gr=x(()=>{"use strict";Fr();Cr=(a,e)=>{(typeof ct.trace>"u"?!ct.wasm.trace:!ct.trace)||console.timeStamp(`${a}::ORT::${e}`)},ho=(a,e)=>{let o=new Error().stack?.split(/\r\n|\r|\n/g)||[],t=!1;for(let r=0;r<o.length;r++){if(t&&!o[r].includes("TRACE_FUNC")){let n=`FUNC_${a}::${o[r].trim().split(" ")[1]}`;e&&(n+=`::${e}`),Cr("CPU",n);return}o[r].includes("TRACE_FUNC")&&(t=!0)}},ge=a=>{(typeof ct.trace>"u"?!ct.wasm.trace:!ct.trace)||ho("BEGIN",a)},xe=a=>{(typeof ct.trace>"u"?!ct.wasm.trace:!ct.trace)||ho("END",a)}});var Me,mo=x(()=>{"use strict";Re();ze();Gr();Me=class a{constructor(e){this.handler=e}async run(e,o,t){ge();let r={},n={};if(typeof e!="object"||e===null||e instanceof rt||Array.isArray(e))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let s=!0;if(typeof o=="object"){if(o===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(o instanceof rt)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(o)){if(o.length===0)throw new TypeError("'fetches' cannot be an empty array.");s=!1;for(let l of o){if(typeof l!="string")throw new TypeError("'fetches' must be a string array or an object.");if(this.outputNames.indexOf(l)===-1)throw new RangeError(`'fetches' contains invalid output name: ${l}.`);r[l]=null}if(typeof t=="object"&&t!==null)n=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else{let l=!1,f=Object.getOwnPropertyNames(o);for(let p of this.outputNames)if(f.indexOf(p)!==-1){let d=o[p];(d===null||d instanceof rt)&&(l=!0,s=!1,r[p]=d)}if(l){if(typeof t=="object"&&t!==null)n=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else n=o}}else if(typeof o<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let l of this.inputNames)if(typeof e[l]>"u")throw new Error(`input '${l}' is missing in 'feeds'.`);if(s)for(let l of this.outputNames)r[l]=null;let i=await this.handler.run(e,r,n),u={};for(let l in i)if(Object.hasOwnProperty.call(i,l)){let f=i[l];f instanceof rt?u[l]=f:u[l]=new rt(f.type,f.data,f.dims)}return xe(),u}async release(){return this.handler.dispose()}static async create(e,o,t,r){ge();let n,s={};if(typeof e=="string"){if(n=e,typeof o=="object"&&o!==null)s=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(n=e,typeof o=="object"&&o!==null)s=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){let f=e,p=0,d=e.byteLength;if(typeof o=="object"&&o!==null)s=o;else if(typeof o=="number"){if(p=o,!Number.isSafeInteger(p))throw new RangeError("'byteOffset' must be an integer.");if(p<0||p>=f.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${f.byteLength}).`);if(d=e.byteLength-p,typeof t=="number"){if(d=t,!Number.isSafeInteger(d))throw new RangeError("'byteLength' must be an integer.");if(d<=0||p+d>f.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${f.byteLength-p}].`);if(typeof r=="object"&&r!==null)s=r;else if(typeof r<"u")throw new TypeError("'options' must be an object.")}else if(typeof t<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof o<"u")throw new TypeError("'options' must be an object.");n=new Uint8Array(f,p,d)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");let[i,u]=await Ge(s),l=await i.createInferenceSessionHandler(n,u);return xe(),new a(l)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var bo,yo=x(()=>{"use strict";mo();bo=Me});var go=x(()=>{"use strict"});var xo=x(()=>{"use strict"});var To=x(()=>{"use strict"});var vo=x(()=>{"use strict"});var Nl,Ue,wo=x(()=>{"use strict";Re();ze();Nl="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",Ue=class a{constructor(e,o,t){this.handler=e,this.hasOptimizerModel=o,this.hasEvalModel=t}get trainingInputNames(){return this.handler.inputNames}get trainingOutputNames(){return this.handler.outputNames}get evalInputNames(){if(this.hasEvalModel)return this.handler.evalInputNames;throw new Error("This training session has no evalModel loaded.")}get evalOutputNames(){if(this.hasEvalModel)return this.handler.evalOutputNames;throw new Error("This training session has no evalModel loaded.")}static async create(e,o){let t=e.evalModel||"",r=e.optimizerModel||"",n=o||{},[s,i]=await Ge(n);if(s.createTrainingSessionHandler){let u=await s.createTrainingSessionHandler(e.checkpointState,e.trainModel,t,r,i);return new a(u,!!e.optimizerModel,!!e.evalModel)}else throw new Error(Nl)}typeNarrowingForRunStep(e,o,t,r,n){let s={},i={};if(typeof t!="object"||t===null||t instanceof rt||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let u=!0;if(typeof r=="object"){if(r===null)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof rt)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(r.length===0)throw new TypeError("'fetches' cannot be an empty array.");u=!1;for(let l of r){if(typeof l!="string")throw new TypeError("'fetches' must be a string array or an object.");if(o.indexOf(l)===-1)throw new RangeError(`'fetches' contains invalid output name: ${l}.`);s[l]=null}if(typeof n=="object"&&n!==null)i=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else{let l=!1,f=Object.getOwnPropertyNames(r);for(let p of o)if(f.indexOf(p)!==-1){let d=r[p];(d===null||d instanceof rt)&&(l=!0,u=!1,s[p]=d)}if(l){if(typeof n=="object"&&n!==null)i=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else i=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let l of e)if(typeof t[l]>"u")throw new Error(`input '${l}' is missing in 'feeds'.`);if(u)for(let l of o)s[l]=null;return[s,i]}convertHandlerReturnTypeToMapOfTensors(e){let o={};for(let t in e)if(Object.hasOwnProperty.call(e,t)){let r=e[t];r instanceof rt?o[t]=r:o[t]=new rt(r.type,r.data,r.dims)}return o}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(e,o,t){let[r,n]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,e,o,t),s=await this.handler.runTrainStep(e,r,n);return this.convertHandlerReturnTypeToMapOfTensors(s)}async runOptimizerStep(e){if(this.hasOptimizerModel)await this.handler.runOptimizerStep(e||{});else throw new Error("This TrainingSession has no OptimizerModel loaded.")}async runEvalStep(e,o,t){if(this.hasEvalModel){let[r,n]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,e,o,t),s=await this.handler.runEvalStep(e,r,n);return this.convertHandlerReturnTypeToMapOfTensors(s)}else throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(e=!0){return this.handler.getParametersSize(e)}async loadParametersBuffer(e,o=!0){let t=await this.getParametersSize(o);if(e.length!==4*t)throw new Error("Size of the buffer passed into loadParametersBuffer must match the number of parameters in the model. Please use getParametersSize method to check.");return this.handler.loadParametersBuffer(e,o)}async getContiguousParameters(e=!0){return this.handler.getContiguousParameters(e)}async release(){return this.handler.dispose()}}});var Io,_o=x(()=>{"use strict";wo();Io=Ue});var Rr={};Br(Rr,{InferenceSession:()=>bo,TRACE:()=>Cr,TRACE_FUNC_BEGIN:()=>ge,TRACE_FUNC_END:()=>xe,Tensor:()=>rt,TrainingSession:()=>Io,env:()=>j,registerBackend:()=>be});var Ft=x(()=>{"use strict";Kn();Yn();yo();ze();go();xo();Gr();To();vo();_o()});function Nt(a,e,o,t){if(e===void 0)return Gl(a);if(o===void 0)We(a,e,1);else if(typeof o=="number"&&t===void 0)We(a,e,o);else if(typeof o=="string"&&t===void 0)We(a,o,1,e);else if(typeof o=="string"&&typeof t=="number")We(a,o,t,e);else throw new TypeError("input is valid")}function Gl(a){return{verbose:Nt.verbose.bind(null,a),info:Nt.info.bind(null,a),warning:Nt.warning.bind(null,a),error:Nt.error.bind(null,a),fatal:Nt.fatal.bind(null,a)}}function We(a,e,o,t){let r=Te[t||""]||Te[""];Ao[a]<Ao[r.minimalSeverity]||(r.logDateTime&&(e=`${new Date().toISOString()}|${e}`),r.logSourceLocation,Cl[r.provider].log(a,e,t))}var Vr,zr,Ao,Cl,Oo,Te,M,qe,je,Ke,He,pt=x(()=>{"use strict";Vr=class{log(e,o,t){}},zr=class{log(e,o,t){console.log(`${this.color(e)} ${t?"\x1B[35m"+t+"\x1B[0m ":""}${o}`)}color(e){switch(e){case"verbose":return"\x1B[34;40mv\x1B[0m";case"info":return"\x1B[32mi\x1B[0m";case"warning":return"\x1B[30;43mw\x1B[0m";case"error":return"\x1B[31;40me\x1B[0m";case"fatal":return"\x1B[101mf\x1B[0m";default:throw new Error(`unsupported severity: ${e}`)}}},Ao={verbose:1e3,info:2e3,warning:4e3,error:5e3,fatal:6e3},Cl={none:new Vr,console:new zr},Oo={provider:"console",minimalSeverity:"warning",logDateTime:!0,logSourceLocation:!1},Te={"":Oo};(u=>{function a(l,f){u("verbose",l,f)}u.verbose=a;function e(l,f){u("info",l,f)}u.info=e;function o(l,f){u("warning",l,f)}u.warning=o;function t(l,f){u("error",l,f)}u.error=t;function r(l,f){u("fatal",l,f)}u.fatal=r;function n(l){Te={},s("",l||{})}u.reset=n;function s(l,f){if(l==="*")n(f);else{let p=Te[l]||Oo;Te[l]={provider:f.provider||p.provider,minimalSeverity:f.minimalSeverity||p.minimalSeverity,logDateTime:f.logDateTime===void 0?p.logDateTime:f.logDateTime,logSourceLocation:f.logSourceLocation===void 0?p.logSourceLocation:f.logSourceLocation}}}u.set=s;function i(l){let f={};l.logLevel&&(f.minimalSeverity=l.logLevel),s("",f)}u.setWithEnv=i})(Nt||={});M=Nt,qe=class{constructor(e,o,t,r,n,s){this.category=e;this.name=o;this.startTime=t;this.endCallback=r;this.timer=n;this.ctx=s}async end(){return this.endCallback(this)}async checkTimer(){if(this.ctx===void 0||this.timer===void 0)throw new Error("No webgl timer found");return this.ctx.endTimer(),this.ctx.waitForQueryAndGetTime(this.timer)}},je=class{constructor(e,o,t,r){this.category=e;this.name=o;this.startTime=t;this.endTime=r}},Ke=class{constructor(e,o,t){this._started=!1;this._flushPointer=0;this._started=!1,this._maxNumberEvents=e===void 0?1e4:e,this._flushBatchSize=o===void 0?10:o,this._flushIntervalInMilliseconds=t===void 0?5e3:t}static create(e){return e===void 0?new this:new this(e.maxNumberEvents,e.flushBatchSize,e.flushIntervalInMilliseconds)}start(){this._started=!0,this._timingEvents=[],this._flushTime=He(),this._flushPointer=0}stop(){for(this._started=!1;this._flushPointer<this._timingEvents.length;this._flushPointer++)this.logOneEvent(this._timingEvents[this._flushPointer])}event(e,o,t,r){let n=this._started?this.begin(e,o,r):void 0,s=!1,i=t();if(i&&typeof i.then=="function")return s=!0,new Promise((u,l)=>{i.then(async f=>{n&&await n.end(),u(f)},async f=>{n&&await n.end(),l(f)})});if(!s&&n){let u=n.end();if(u&&typeof u.then=="function")return new Promise((l,f)=>{u.then(()=>{l(i)},p=>{f(p)})})}return i}begin(e,o,t){if(!this._started)throw new Error("profiler is not started yet");if(t===void 0){let r=He();return this.flush(r),new qe(e,o,r,n=>this.endSync(n))}else{let r=t.beginTimer();return new qe(e,o,0,async n=>this.end(n),r,t)}}async end(e){let o=await e.checkTimer();this._timingEvents.length<this._maxNumberEvents&&(this._timingEvents.push(new je(e.category,e.name,e.startTime,o)),this.flush(o))}endSync(e){let o=He();this._timingEvents.length<this._maxNumberEvents&&(this._timingEvents.push(new je(e.category,e.name,e.startTime,o)),this.flush(o))}logOneEvent(e){M.verbose(`Profiler.${e.category}`,`${(e.endTime-e.startTime).toFixed(2)}ms on event '${e.name}' at ${e.endTime.toFixed(2)}`)}flush(e){if(this._timingEvents.length-this._flushPointer>=this._flushBatchSize||e-this._flushTime>=this._flushIntervalInMilliseconds){for(let o=this._flushPointer;this._flushPointer<o+this._flushBatchSize&&this._flushPointer<this._timingEvents.length;this._flushPointer++)this.logOneEvent(this._timingEvents[this._flushPointer]);this._flushTime=He()}}get started(){return this._started}},He=typeof performance<"u"&&performance.now?()=>performance.now():Date.now});function Po(a,e,o){for(let t of o){let r=t[0],n=t[1],s=t[2],i=t[3],u=t[4];if(a.opType===r){for(let l of e)if((l.domain===n||l.domain==="ai.onnx"&&n==="")&&Rl(l.version,s))return{opImpl:i,opInit:u}}}throw new TypeError(`cannot resolve operator '${a.opType}' with opsets: ${e.map(t=>`${t.domain||"ai.onnx"} v${t.version}`).join(", ")}`)}function Rl(a,e){if(e.endsWith("+")){let o=Number.parseInt(e.substring(0,e.length-1),10);return!isNaN(o)&&o<=a}else if(e.split("-").length===2){let o=e.split("-"),t=Number.parseInt(o[0],10),r=Number.parseInt(o[1],10);return!isNaN(t)&&!isNaN(r)&&t<=a&&a<=r}else return Number.parseInt(e,10)===a}var Eo=x(()=>{"use strict"});var Do=Z(Mr=>{"use strict";Mr.__esModule=!0;var Vl=function(){function a(e){if(!e)throw new TypeError("Invalid argument; `value` has no value.");this.value=a.EMPTY,e&&a.isGuid(e)&&(this.value=e)}return a.isGuid=function(e){var o=e.toString();return e&&(e instanceof a||a.validator.test(o))},a.create=function(){return new a([a.gen(2),a.gen(1),a.gen(1),a.gen(1),a.gen(3)].join("-"))},a.createEmpty=function(){return new a("emptyguid")},a.parse=function(e){return new a(e)},a.raw=function(){return[a.gen(2),a.gen(1),a.gen(1),a.gen(1),a.gen(3)].join("-")},a.gen=function(e){for(var o="",t=0;t<e;t++)o+=((1+Math.random())*65536|0).toString(16).substring(1);return o},a.prototype.equals=function(e){return a.isGuid(e)&&this.value===e.toString()},a.prototype.isEmpty=function(){return this.value===a.EMPTY},a.prototype.toString=function(){return this.value},a.prototype.toJSON=function(){return{value:this.value}},a.validator=new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$","i"),a.EMPTY="00000000-0000-0000-0000-000000000000",a}();Mr.Guid=Vl});function U(a,e,o){this.low=a|0,this.high=e|0,this.unsigned=!!o}function nt(a){return(a&&a.__isLong__)===!0}function Lo(a){var e=Math.clz32(a&-a);return a?31-e:e}function Ht(a,e){var o,t,r;return e?(a>>>=0,(r=0<=a&&a<256)&&(t=ko[a],t)?t:(o=V(a,0,!0),r&&(ko[a]=o),o)):(a|=0,(r=-128<=a&&a<128)&&(t=$o[a],t)?t:(o=V(a,a<0?-1:0,!1),r&&($o[a]=o),o))}function ht(a,e){if(isNaN(a))return e?$t:Tt;if(e){if(a<0)return $t;if(a>=Co)return Vo}else{if(a<=-Fo)return ut;if(a+1>=Fo)return Ro}return a<0?ht(-a,e).neg():V(a%ie|0,a/ie|0,e)}function V(a,e,o){return new U(a,e,o)}function Wr(a,e,o){if(a.length===0)throw Error("empty string");if(typeof e=="number"?(o=e,e=!1):e=!!e,a==="NaN"||a==="Infinity"||a==="+Infinity"||a==="-Infinity")return e?$t:Tt;if(o=o||10,o<2||36<o)throw RangeError("radix");var t;if((t=a.indexOf("-"))>0)throw Error("interior hyphen");if(t===0)return Wr(a.substring(1),e,o).neg();for(var r=ht(Xe(o,8)),n=Tt,s=0;s<a.length;s+=8){var i=Math.min(8,a.length-s),u=parseInt(a.substring(s,s+i),o);if(i<8){var l=ht(Xe(o,i));n=n.mul(l).add(ht(u))}else n=n.mul(r),n=n.add(ht(u))}return n.unsigned=e,n}function vt(a,e){return typeof a=="number"?ht(a,e):typeof a=="string"?Wr(a,e):V(a.low,a.high,typeof e=="boolean"?e:a.unsigned)}var dt,$o,ko,Xe,Bo,zl,ie,Co,Fo,No,Tt,$t,oe,Go,Ur,Ro,Vo,ut,T,kt,Hr=x(()=>{dt=null;try{dt=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}U.prototype.__isLong__;Object.defineProperty(U.prototype,"__isLong__",{value:!0});U.isLong=nt;$o={},ko={};U.fromInt=Ht;U.fromNumber=ht;U.fromBits=V;Xe=Math.pow;U.fromString=Wr;U.fromValue=vt;Bo=65536,zl=1<<24,ie=Bo*Bo,Co=ie*ie,Fo=Co/2,No=Ht(zl),Tt=Ht(0);U.ZERO=Tt;$t=Ht(0,!0);U.UZERO=$t;oe=Ht(1);U.ONE=oe;Go=Ht(1,!0);U.UONE=Go;Ur=Ht(-1);U.NEG_ONE=Ur;Ro=V(-1,2147483647,!1);U.MAX_VALUE=Ro;Vo=V(-1,-1,!0);U.MAX_UNSIGNED_VALUE=Vo;ut=V(0,-2147483648,!1);U.MIN_VALUE=ut;T=U.prototype;T.toInt=function(){return this.unsigned?this.low>>>0:this.low};T.toNumber=function(){return this.unsigned?(this.high>>>0)*ie+(this.low>>>0):this.high*ie+(this.low>>>0)};T.toString=function(e){if(e=e||10,e<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative())if(this.eq(ut)){var o=ht(e),t=this.div(o),r=t.mul(o).sub(this);return t.toString(e)+r.toInt().toString(e)}else return"-"+this.neg().toString(e);for(var n=ht(Xe(e,6),this.unsigned),s=this,i="";;){var u=s.div(n),l=s.sub(u.mul(n)).toInt()>>>0,f=l.toString(e);if(s=u,s.isZero())return f+i;for(;f.length<6;)f="0"+f;i=""+f+i}};T.getHighBits=function(){return this.high};T.getHighBitsUnsigned=function(){return this.high>>>0};T.getLowBits=function(){return this.low};T.getLowBitsUnsigned=function(){return this.low>>>0};T.getNumBitsAbs=function(){if(this.isNegative())return this.eq(ut)?64:this.neg().getNumBitsAbs();for(var e=this.high!=0?this.high:this.low,o=31;o>0&&!(e&1<<o);o--);return this.high!=0?o+33:o+1};T.isZero=function(){return this.high===0&&this.low===0};T.eqz=T.isZero;T.isNegative=function(){return!this.unsigned&&this.high<0};T.isPositive=function(){return this.unsigned||this.high>=0};T.isOdd=function(){return(this.low&1)===1};T.isEven=function(){return(this.low&1)===0};T.equals=function(e){return nt(e)||(e=vt(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low};T.eq=T.equals;T.notEquals=function(e){return!this.eq(e)};T.neq=T.notEquals;T.ne=T.notEquals;T.lessThan=function(e){return this.comp(e)<0};T.lt=T.lessThan;T.lessThanOrEqual=function(e){return this.comp(e)<=0};T.lte=T.lessThanOrEqual;T.le=T.lessThanOrEqual;T.greaterThan=function(e){return this.comp(e)>0};T.gt=T.greaterThan;T.greaterThanOrEqual=function(e){return this.comp(e)>=0};T.gte=T.greaterThanOrEqual;T.ge=T.greaterThanOrEqual;T.compare=function(e){if(nt(e)||(e=vt(e)),this.eq(e))return 0;var o=this.isNegative(),t=e.isNegative();return o&&!t?-1:!o&&t?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1};T.comp=T.compare;T.negate=function(){return!this.unsigned&&this.eq(ut)?ut:this.not().add(oe)};T.neg=T.negate;T.add=function(e){nt(e)||(e=vt(e));var o=this.high>>>16,t=this.high&65535,r=this.low>>>16,n=this.low&65535,s=e.high>>>16,i=e.high&65535,u=e.low>>>16,l=e.low&65535,f=0,p=0,d=0,b=0;return b+=n+l,d+=b>>>16,b&=65535,d+=r+u,p+=d>>>16,d&=65535,p+=t+i,f+=p>>>16,p&=65535,f+=o+s,f&=65535,V(d<<16|b,f<<16|p,this.unsigned)};T.subtract=function(e){return nt(e)||(e=vt(e)),this.add(e.neg())};T.sub=T.subtract;T.multiply=function(e){if(this.isZero())return this;if(nt(e)||(e=vt(e)),dt){var o=dt.mul(this.low,this.high,e.low,e.high);return V(o,dt.get_high(),this.unsigned)}if(e.isZero())return this.unsigned?$t:Tt;if(this.eq(ut))return e.isOdd()?ut:Tt;if(e.eq(ut))return this.isOdd()?ut:Tt;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(No)&&e.lt(No))return ht(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,r=this.high&65535,n=this.low>>>16,s=this.low&65535,i=e.high>>>16,u=e.high&65535,l=e.low>>>16,f=e.low&65535,p=0,d=0,b=0,g=0;return g+=s*f,b+=g>>>16,g&=65535,b+=n*f,d+=b>>>16,b&=65535,b+=s*l,d+=b>>>16,b&=65535,d+=r*f,p+=d>>>16,d&=65535,d+=n*l,p+=d>>>16,d&=65535,d+=s*u,p+=d>>>16,d&=65535,p+=t*f+r*l+n*u+s*i,p&=65535,V(b<<16|g,p<<16|d,this.unsigned)};T.mul=T.multiply;T.divide=function(e){if(nt(e)||(e=vt(e)),e.isZero())throw Error("division by zero");if(dt){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var o=(this.unsigned?dt.div_u:dt.div_s)(this.low,this.high,e.low,e.high);return V(o,dt.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?$t:Tt;var t,r,n;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return $t;if(e.gt(this.shru(1)))return Go;n=$t}else{if(this.eq(ut)){if(e.eq(oe)||e.eq(Ur))return ut;if(e.eq(ut))return oe;var s=this.shr(1);return t=s.div(e).shl(1),t.eq(Tt)?e.isNegative()?oe:Ur:(r=this.sub(e.mul(t)),n=t.add(r.div(e)),n)}else if(e.eq(ut))return this.unsigned?$t:Tt;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();n=Tt}for(r=this;r.gte(e);){t=Math.max(1,Math.floor(r.toNumber()/e.toNumber()));for(var i=Math.ceil(Math.log(t)/Math.LN2),u=i<=48?1:Xe(2,i-48),l=ht(t),f=l.mul(e);f.isNegative()||f.gt(r);)t-=u,l=ht(t,this.unsigned),f=l.mul(e);l.isZero()&&(l=oe),n=n.add(l),r=r.sub(f)}return n};T.div=T.divide;T.modulo=function(e){if(nt(e)||(e=vt(e)),dt){var o=(this.unsigned?dt.rem_u:dt.rem_s)(this.low,this.high,e.low,e.high);return V(o,dt.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))};T.mod=T.modulo;T.rem=T.modulo;T.not=function(){return V(~this.low,~this.high,this.unsigned)};T.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32};T.clz=T.countLeadingZeros;T.countTrailingZeros=function(){return this.low?Lo(this.low):Lo(this.high)+32};T.ctz=T.countTrailingZeros;T.and=function(e){return nt(e)||(e=vt(e)),V(this.low&e.low,this.high&e.high,this.unsigned)};T.or=function(e){return nt(e)||(e=vt(e)),V(this.low|e.low,this.high|e.high,this.unsigned)};T.xor=function(e){return nt(e)||(e=vt(e)),V(this.low^e.low,this.high^e.high,this.unsigned)};T.shiftLeft=function(e){return nt(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?V(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):V(0,this.low<<e-32,this.unsigned)};T.shl=T.shiftLeft;T.shiftRight=function(e){return nt(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?V(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):V(this.high>>e-32,this.high>=0?0:-1,this.unsigned)};T.shr=T.shiftRight;T.shiftRightUnsigned=function(e){return nt(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?V(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):e===32?V(this.high,0,this.unsigned):V(this.high>>>e-32,0,this.unsigned)};T.shru=T.shiftRightUnsigned;T.shr_u=T.shiftRightUnsigned;T.rotateLeft=function(e){var o;return nt(e)&&(e=e.toInt()),(e&=63)===0?this:e===32?V(this.high,this.low,this.unsigned):e<32?(o=32-e,V(this.low<<e|this.high>>>o,this.high<<e|this.low>>>o,this.unsigned)):(e-=32,o=32-e,V(this.high<<e|this.low>>>o,this.low<<e|this.high>>>o,this.unsigned))};T.rotl=T.rotateLeft;T.rotateRight=function(e){var o;return nt(e)&&(e=e.toInt()),(e&=63)===0?this:e===32?V(this.high,this.low,this.unsigned):e<32?(o=32-e,V(this.high<<o|this.low>>>e,this.low<<o|this.high>>>e,this.unsigned)):(e-=32,o=32-e,V(this.low<<o|this.high>>>e,this.high<<o|this.low>>>e,this.unsigned))};T.rotr=T.rotateRight;T.toSigned=function(){return this.unsigned?V(this.low,this.high,!1):this};T.toUnsigned=function(){return this.unsigned?this:V(this.low,this.high,!0)};T.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()};T.toBytesLE=function(){var e=this.high,o=this.low;return[o&255,o>>>8&255,o>>>16&255,o>>>24,e&255,e>>>8&255,e>>>16&255,e>>>24]};T.toBytesBE=function(){var e=this.high,o=this.low;return[e>>>24,e>>>16&255,e>>>8&255,e&255,o>>>24,o>>>16&255,o>>>8&255,o&255]};U.fromBytes=function(e,o,t){return t?U.fromBytesLE(e,o):U.fromBytesBE(e,o)};U.fromBytesLE=function(e,o){return new U(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,o)};U.fromBytesBE=function(e,o){return new U(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],o)};kt=U});var m,Je=x(()=>{m={};m.Offset;m.Table;m.SIZEOF_SHORT=2;m.SIZEOF_INT=4;m.FILE_IDENTIFIER_LENGTH=4;m.SIZE_PREFIX_LENGTH=4;m.Encoding={UTF8_BYTES:1,UTF16_STRING:2};m.int32=new Int32Array(2);m.float32=new Float32Array(m.int32.buffer);m.float64=new Float64Array(m.int32.buffer);m.isLittleEndian=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;m.Long=function(a,e){this.low=a|0,this.high=e|0};m.Long.create=function(a,e){return a==0&&e==0?m.Long.ZERO:new m.Long(a,e)};m.Long.prototype.toFloat64=function(){return(this.low>>>0)+this.high*4294967296};m.Long.prototype.equals=function(a){return this.low==a.low&&this.high==a.high};m.Long.ZERO=new m.Long(0,0);m.Builder=function(a){if(a)var e=a;else var e=1024;this.bb=m.ByteBuffer.allocate(e),this.space=e,this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1};m.Builder.prototype.clear=function(){this.bb.clear(),this.space=this.bb.capacity(),this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1};m.Builder.prototype.forceDefaults=function(a){this.force_defaults=a};m.Builder.prototype.dataBuffer=function(){return this.bb};m.Builder.prototype.asUint8Array=function(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())};m.Builder.prototype.prep=function(a,e){a>this.minalign&&(this.minalign=a);for(var o=~(this.bb.capacity()-this.space+e)+1&a-1;this.space<o+a+e;){var t=this.bb.capacity();this.bb=m.Builder.growByteBuffer(this.bb),this.space+=this.bb.capacity()-t}this.pad(o)};m.Builder.prototype.pad=function(a){for(var e=0;e<a;e++)this.bb.writeInt8(--this.space,0)};m.Builder.prototype.writeInt8=function(a){this.bb.writeInt8(this.space-=1,a)};m.Builder.prototype.writeInt16=function(a){this.bb.writeInt16(this.space-=2,a)};m.Builder.prototype.writeInt32=function(a){this.bb.writeInt32(this.space-=4,a)};m.Builder.prototype.writeInt64=function(a){this.bb.writeInt64(this.space-=8,a)};m.Builder.prototype.writeFloat32=function(a){this.bb.writeFloat32(this.space-=4,a)};m.Builder.prototype.writeFloat64=function(a){this.bb.writeFloat64(this.space-=8,a)};m.Builder.prototype.addInt8=function(a){this.prep(1,0),this.writeInt8(a)};m.Builder.prototype.addInt16=function(a){this.prep(2,0),this.writeInt16(a)};m.Builder.prototype.addInt32=function(a){this.prep(4,0),this.writeInt32(a)};m.Builder.prototype.addInt64=function(a){this.prep(8,0),this.writeInt64(a)};m.Builder.prototype.addFloat32=function(a){this.prep(4,0),this.writeFloat32(a)};m.Builder.prototype.addFloat64=function(a){this.prep(8,0),this.writeFloat64(a)};m.Builder.prototype.addFieldInt8=function(a,e,o){(this.force_defaults||e!=o)&&(this.addInt8(e),this.slot(a))};m.Builder.prototype.addFieldInt16=function(a,e,o){(this.force_defaults||e!=o)&&(this.addInt16(e),this.slot(a))};m.Builder.prototype.addFieldInt32=function(a,e,o){(this.force_defaults||e!=o)&&(this.addInt32(e),this.slot(a))};m.Builder.prototype.addFieldInt64=function(a,e,o){(this.force_defaults||!e.equals(o))&&(this.addInt64(e),this.slot(a))};m.Builder.prototype.addFieldFloat32=function(a,e,o){(this.force_defaults||e!=o)&&(this.addFloat32(e),this.slot(a))};m.Builder.prototype.addFieldFloat64=function(a,e,o){(this.force_defaults||e!=o)&&(this.addFloat64(e),this.slot(a))};m.Builder.prototype.addFieldOffset=function(a,e,o){(this.force_defaults||e!=o)&&(this.addOffset(e),this.slot(a))};m.Builder.prototype.addFieldStruct=function(a,e,o){e!=o&&(this.nested(e),this.slot(a))};m.Builder.prototype.nested=function(a){if(a!=this.offset())throw new Error("FlatBuffers: struct must be serialized inline.")};m.Builder.prototype.notNested=function(){if(this.isNested)throw new Error("FlatBuffers: object serialization must not be nested.")};m.Builder.prototype.slot=function(a){this.vtable[a]=this.offset()};m.Builder.prototype.offset=function(){return this.bb.capacity()-this.space};m.Builder.growByteBuffer=function(a){var e=a.capacity();if(e&3221225472)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");var o=e<<1,t=m.ByteBuffer.allocate(o);return t.setPosition(o-e),t.bytes().set(a.bytes(),o-e),t};m.Builder.prototype.addOffset=function(a){this.prep(m.SIZEOF_INT,0),this.writeInt32(this.offset()-a+m.SIZEOF_INT)};m.Builder.prototype.startObject=function(a){this.notNested(),this.vtable==null&&(this.vtable=[]),this.vtable_in_use=a;for(var e=0;e<a;e++)this.vtable[e]=0;this.isNested=!0,this.object_start=this.offset()};m.Builder.prototype.endObject=function(){if(this.vtable==null||!this.isNested)throw new Error("FlatBuffers: endObject called without startObject");this.addInt32(0);for(var a=this.offset(),e=this.vtable_in_use-1;e>=0&&this.vtable[e]==0;e--);for(var o=e+1;e>=0;e--)this.addInt16(this.vtable[e]!=0?a-this.vtable[e]:0);var t=2;this.addInt16(a-this.object_start);var r=(o+t)*m.SIZEOF_SHORT;this.addInt16(r);var n=0,s=this.space;t:for(e=0;e<this.vtables.length;e++){var i=this.bb.capacity()-this.vtables[e];if(r==this.bb.readInt16(i)){for(var u=m.SIZEOF_SHORT;u<r;u+=m.SIZEOF_SHORT)if(this.bb.readInt16(s+u)!=this.bb.readInt16(i+u))continue t;n=this.vtables[e];break}}return n?(this.space=this.bb.capacity()-a,this.bb.writeInt32(this.space,n-a)):(this.vtables.push(this.offset()),this.bb.writeInt32(this.bb.capacity()-a,this.offset()-a)),this.isNested=!1,a};m.Builder.prototype.finish=function(a,e,o){var t=o?m.SIZE_PREFIX_LENGTH:0;if(e){var r=e;if(this.prep(this.minalign,m.SIZEOF_INT+m.FILE_IDENTIFIER_LENGTH+t),r.length!=m.FILE_IDENTIFIER_LENGTH)throw new Error("FlatBuffers: file identifier must be length "+m.FILE_IDENTIFIER_LENGTH);for(var n=m.FILE_IDENTIFIER_LENGTH-1;n>=0;n--)this.writeInt8(r.charCodeAt(n))}this.prep(this.minalign,m.SIZEOF_INT+t),this.addOffset(a),t&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)};m.Builder.prototype.finishSizePrefixed=function(a,e){this.finish(a,e,!0)};m.Builder.prototype.requiredField=function(a,e){var o=this.bb.capacity()-a,t=o-this.bb.readInt32(o),r=this.bb.readInt16(t+e)!=0;if(!r)throw new Error("FlatBuffers: field "+e+" must be set")};m.Builder.prototype.startVector=function(a,e,o){this.notNested(),this.vector_num_elems=e,this.prep(m.SIZEOF_INT,a*e),this.prep(o,a*e)};m.Builder.prototype.endVector=function(){return this.writeInt32(this.vector_num_elems),this.offset()};m.Builder.prototype.createString=function(a){if(a instanceof Uint8Array)var e=a;else for(var e=[],o=0;o<a.length;){var t,r=a.charCodeAt(o++);if(r<55296||r>=56320)t=r;else{var n=a.charCodeAt(o++);t=(r<<10)+n+(65536-56623104-56320)}t<128?e.push(t):(t<2048?e.push(t>>6&31|192):(t<65536?e.push(t>>12&15|224):e.push(t>>18&7|240,t>>12&63|128),e.push(t>>6&63|128)),e.push(t&63|128))}this.addInt8(0),this.startVector(1,e.length,1),this.bb.setPosition(this.space-=e.length);for(var o=0,s=this.space,i=this.bb.bytes();o<e.length;o++)i[s++]=e[o];return this.endVector()};m.Builder.prototype.createLong=function(a,e){return m.Long.create(a,e)};m.ByteBuffer=function(a){this.bytes_=a,this.position_=0};m.ByteBuffer.allocate=function(a){return new m.ByteBuffer(new Uint8Array(a))};m.ByteBuffer.prototype.clear=function(){this.position_=0};m.ByteBuffer.prototype.bytes=function(){return this.bytes_};m.ByteBuffer.prototype.position=function(){return this.position_};m.ByteBuffer.prototype.setPosition=function(a){this.position_=a};m.ByteBuffer.prototype.capacity=function(){return this.bytes_.length};m.ByteBuffer.prototype.readInt8=function(a){return this.readUint8(a)<<24>>24};m.ByteBuffer.prototype.readUint8=function(a){return this.bytes_[a]};m.ByteBuffer.prototype.readInt16=function(a){return this.readUint16(a)<<16>>16};m.ByteBuffer.prototype.readUint16=function(a){return this.bytes_[a]|this.bytes_[a+1]<<8};m.ByteBuffer.prototype.readInt32=function(a){return this.bytes_[a]|this.bytes_[a+1]<<8|this.bytes_[a+2]<<16|this.bytes_[a+3]<<24};m.ByteBuffer.prototype.readUint32=function(a){return this.readInt32(a)>>>0};m.ByteBuffer.prototype.readInt64=function(a){return new m.Long(this.readInt32(a),this.readInt32(a+4))};m.ByteBuffer.prototype.readUint64=function(a){return new m.Long(this.readUint32(a),this.readUint32(a+4))};m.ByteBuffer.prototype.readFloat32=function(a){return m.int32[0]=this.readInt32(a),m.float32[0]};m.ByteBuffer.prototype.readFloat64=function(a){return m.int32[m.isLittleEndian?0:1]=this.readInt32(a),m.int32[m.isLittleEndian?1:0]=this.readInt32(a+4),m.float64[0]};m.ByteBuffer.prototype.writeInt8=function(a,e){this.bytes_[a]=e};m.ByteBuffer.prototype.writeUint8=function(a,e){this.bytes_[a]=e};m.ByteBuffer.prototype.writeInt16=function(a,e){this.bytes_[a]=e,this.bytes_[a+1]=e>>8};m.ByteBuffer.prototype.writeUint16=function(a,e){this.bytes_[a]=e,this.bytes_[a+1]=e>>8};m.ByteBuffer.prototype.writeInt32=function(a,e){this.bytes_[a]=e,this.bytes_[a+1]=e>>8,this.bytes_[a+2]=e>>16,this.bytes_[a+3]=e>>24};m.ByteBuffer.prototype.writeUint32=function(a,e){this.bytes_[a]=e,this.bytes_[a+1]=e>>8,this.bytes_[a+2]=e>>16,this.bytes_[a+3]=e>>24};m.ByteBuffer.prototype.writeInt64=function(a,e){this.writeInt32(a,e.low),this.writeInt32(a+4,e.high)};m.ByteBuffer.prototype.writeUint64=function(a,e){this.writeUint32(a,e.low),this.writeUint32(a+4,e.high)};m.ByteBuffer.prototype.writeFloat32=function(a,e){m.float32[0]=e,this.writeInt32(a,m.int32[0])};m.ByteBuffer.prototype.writeFloat64=function(a,e){m.float64[0]=e,this.writeInt32(a,m.int32[m.isLittleEndian?0:1]),this.writeInt32(a+4,m.int32[m.isLittleEndian?1:0])};m.ByteBuffer.prototype.getBufferIdentifier=function(){if(this.bytes_.length<this.position_+m.SIZEOF_INT+m.FILE_IDENTIFIER_LENGTH)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");for(var a="",e=0;e<m.FILE_IDENTIFIER_LENGTH;e++)a+=String.fromCharCode(this.readInt8(this.position_+m.SIZEOF_INT+e));return a};m.ByteBuffer.prototype.__offset=function(a,e){var o=a-this.readInt32(a);return e<this.readInt16(o)?this.readInt16(o+e):0};m.ByteBuffer.prototype.__union=function(a,e){return a.bb_pos=e+this.readInt32(e),a.bb=this,a};m.ByteBuffer.prototype.__string=function(a,e){a+=this.readInt32(a);var o=this.readInt32(a),t="",r=0;if(a+=m.SIZEOF_INT,e===m.Encoding.UTF8_BYTES)return this.bytes_.subarray(a,a+o);for(;r<o;){var n,s=this.readUint8(a+r++);if(s<192)n=s;else{var i=this.readUint8(a+r++);if(s<224)n=(s&31)<<6|i&63;else{var u=this.readUint8(a+r++);if(s<240)n=(s&15)<<12|(i&63)<<6|u&63;else{var l=this.readUint8(a+r++);n=(s&7)<<18|(i&63)<<12|(u&63)<<6|l&63}}}n<65536?t+=String.fromCharCode(n):(n-=65536,t+=String.fromCharCode((n>>10)+55296,(n&1024-1)+56320))}return t};m.ByteBuffer.prototype.__indirect=function(a){return a+this.readInt32(a)};m.ByteBuffer.prototype.__vector=function(a){return a+this.readInt32(a)+m.SIZEOF_INT};m.ByteBuffer.prototype.__vector_len=function(a){return this.readInt32(a+this.readInt32