UNPKG

onnxruntime-web

Version:

A Javascript library for running ONNX models on browsers

6 lines 467 kB
/*! * ONNX Runtime Web v1.20.0-dev.20240924-cfa45df6b5 * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var zd=Object.create;var nn=Object.defineProperty;var Wd=Object.getOwnPropertyDescriptor;var Hd=Object.getOwnPropertyNames;var qd=Object.getPrototypeOf,jd=Object.prototype.hasOwnProperty;var ko=(i=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(i,{get:(e,o)=>(typeof require<"u"?require:e)[o]}):i)(function(i){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+i+'" is not supported')});var O=(i,e)=>()=>(i&&(e=i(i=0)),e);var mt=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),Or=(i,e)=>{for(var o in e)nn(i,o,{get:e[o],enumerable:!0})},Za=(i,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Hd(e))!jd.call(i,r)&&r!==o&&nn(i,r,{get:()=>e[r],enumerable:!(t=Wd(e,r))||t.enumerable});return i};var rr=(i,e,o)=>(o=i!=null?zd(qd(i)):{},Za(e||!i||!i.__esModule?nn(o,"default",{value:i,enumerable:!0}):o,i)),on=i=>Za(nn({},"__esModule",{value:!0}),i);var an,$e,nr,Xd,sn,un=O(()=>{"use strict";an=new Map,$e=[],nr=(i,e,o)=>{if(e&&typeof e.init=="function"&&typeof e.createInferenceSessionHandler=="function"){let t=an.get(i);if(t===void 0)an.set(i,{backend:e,priority:o});else{if(t.priority>o)return;if(t.priority===o&&t.backend!==e)throw new Error(`cannot register backend "${i}" using priority ${o}`)}if(o>=0){let r=$e.indexOf(i);r!==-1&&$e.splice(r,1);for(let n=0;n<$e.length;n++)if(an.get($e[n]).priority<=o){$e.splice(n,0,i);return}$e.push(i)}return}throw new TypeError("not a valid backend")},Xd=async i=>{let e=an.get(i);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(i)),await e.initPromise,e.initialized=!0,e.backend}catch(t){return o||(e.error=`${t}`,e.aborted=!0),e.error}finally{delete e.initPromise}}},sn=async i=>{let e=i.executionProviders||[],o=e.map(u=>typeof u=="string"?u:u.name),t=o.length===0?$e:o,r,n=[],s=new Set;for(let u of t){let l=await Xd(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 a=e.filter(u=>s.has(typeof u=="string"?u:u.name));return[r,new Proxy(i,{get:(u,l)=>l==="executionProviders"?a:Reflect.get(u,l)})]}});var Qa=O(()=>{"use strict";un()});var ts,es=O(()=>{"use strict";ts="1.20.0-dev.20240912-ae39c40e5b"});var rs,Rt,Bo=O(()=>{"use strict";es();rs="warning",Rt={wasm:{},webgl:{},webgpu:{},versions:{common:ts},set logLevel(i){if(i!==void 0){if(typeof i!="string"||["verbose","info","warning","error","fatal"].indexOf(i)===-1)throw new Error(`Unsupported logging level: ${i}`);rs=i}},get logLevel(){return rs}};Object.defineProperty(Rt,"logLevel",{enumerable:!0})});var z,ns=O(()=>{"use strict";Bo();z=Rt});var os,is,as=O(()=>{"use strict";os=(i,e)=>{let o=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(1,1);o.width=i.dims[3],o.height=i.dims[2];let t=o.getContext("2d");if(t!=null){let r,n;e?.tensorLayout!==void 0&&e.tensorLayout==="NHWC"?(r=i.dims[2],n=i.dims[3]):(r=i.dims[3],n=i.dims[2]);let s=e?.format!==void 0?e.format:"RGB",a=e?.norm,u,l;a===void 0||a.mean===void 0?u=[255,255,255,255]:typeof a.mean=="number"?u=[a.mean,a.mean,a.mean,a.mean]:(u=[a.mean[0],a.mean[1],a.mean[2],0],a.mean[3]!==void 0&&(u[3]=a.mean[3])),a===void 0||a.bias===void 0?l=[0,0,0,0]:typeof a.bias=="number"?l=[a.bias,a.bias,a.bias,a.bias]:(l=[a.bias[0],a.bias[1],a.bias[2],0],a.bias[3]!==void 0&&(l[3]=a.bias[3]));let f=n*r,p=0,d=f,y=f*2,w=-1;s==="RGBA"?(p=0,d=f,y=f*2,w=f*3):s==="RGB"?(p=0,d=f,y=f*2):s==="RBG"&&(p=0,y=f,d=f*2);for(let v=0;v<n;v++)for(let S=0;S<r;S++){let L=(i.data[p++]-l[0])*u[0],P=(i.data[d++]-l[1])*u[1],A=(i.data[y++]-l[2])*u[2],M=w===-1?255:(i.data[w++]-l[3])*u[3];t.fillStyle="rgba("+L+","+P+","+A+","+M+")",t.fillRect(S,v,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")},is=(i,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=i.dims[2],n=i.dims[1],s=i.dims[3]):(r=i.dims[3],n=i.dims[2],s=i.dims[1]);let a=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,y=0,w=1,v=2,S=3,L=0,P=p,A=p*2,M=-1;a==="RGBA"?(L=0,P=p,A=p*2,M=p*3):a==="RGB"?(L=0,P=p,A=p*2):a==="RBG"&&(L=0,A=p,P=p*2),t=o.createImageData(r,n);for(let V=0;V<n*r;y+=d,w+=d,v+=d,S+=d,V++)t.data[y]=(i.data[L++]-f[0])*l[0],t.data[w]=(i.data[P++]-f[1])*l[1],t.data[v]=(i.data[A++]-f[2])*l[2],t.data[S]=M===-1?255:(i.data[M++]-f[3])*l[3]}else throw new Error("Can not access image data");return t}});var Fo,ss,us,ls,fs,cs=O(()=>{"use strict";ln();Fo=(i,e)=>{if(i===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 a=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,y=1,w=2,v=3,S=0,L=l,P=l*2,A=-1;a==="RGB"&&(p=3,d=0,y=1,w=2,v=-1),u==="RGBA"?A=l*3:u==="RBG"?(S=0,P=l,L=l*2):u==="BGR"&&(P=0,L=l,S=l*2);for(let V=0;V<l;V++,d+=p,w+=p,y+=p,v+=p)f[S++]=(i[d]+s[0])/n[0],f[L++]=(i[y]+s[1])/n[1],f[P++]=(i[w]+s[2])/n[2],A!==-1&&v!==-1&&(f[A++]=(i[v]+s[3])/n[3]);return u==="RGBA"?new Lt("float32",f,[1,4,o,t]):new Lt("float32",f,[1,3,o,t])},ss=async(i,e)=>{let o=typeof HTMLImageElement<"u"&&i instanceof HTMLImageElement,t=typeof ImageData<"u"&&i instanceof ImageData,r=typeof ImageBitmap<"u"&&i instanceof ImageBitmap,n=typeof i=="string",s,a=e??{},u=()=>{if(typeof document<"u")return document.createElement("canvas");if(typeof OffscreenCanvas<"u")return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},l=f=>f instanceof HTMLCanvasElement||f instanceof OffscreenCanvas?f.getContext("2d"):null;if(o){let f=u();f.width=i.width,f.height=i.height;let p=l(f);if(p!=null){let d=i.height,y=i.width;if(e!==void 0&&e.resizedHeight!==void 0&&e.resizedWidth!==void 0&&(d=e.resizedHeight,y=e.resizedWidth),e!==void 0){if(a=e,e.tensorFormat!==void 0)throw new Error("Image input config format must be RGBA for HTMLImageElement");a.tensorFormat="RGBA",a.height=d,a.width=y}else a.tensorFormat="RGBA",a.height=d,a.width=y;p.drawImage(i,0,0),s=p.getImageData(0,0,y,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=i.height,p=i.width),e!==void 0&&(a=e),a.format="RGBA",a.height=f,a.width=p,e!==void 0){let d=u();d.width=p,d.height=f;let y=l(d);if(y!=null)y.putImageData(i,0,0),s=y.getImageData(0,0,p,f).data;else throw new Error("Can not access image data")}else s=i.data}else if(r){if(e===void 0)throw new Error("Please provide image config with format for Imagebitmap");let f=u();f.width=i.width,f.height=i.height;let p=l(f);if(p!=null){let d=i.height,y=i.width;return p.drawImage(i,0,0,y,d),s=p.getImageData(0,0,y,d).data,a.height=d,a.width=y,Fo(s,a)}else throw new Error("Can not access image data")}else{if(n)return new Promise((f,p)=>{let d=u(),y=l(d);if(!i||!y)return p();let w=new Image;w.crossOrigin="Anonymous",w.src=i,w.onload=()=>{d.width=w.width,d.height=w.height,y.drawImage(w,0,0,d.width,d.height);let v=y.getImageData(0,0,d.width,d.height);a.height=d.height,a.width=d.width,f(Fo(v.data,a))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(s!==void 0)return Fo(s,a);throw new Error("Input data provided is not supported - aborted tensor creation")},us=(i,e)=>{let{width:o,height:t,download:r,dispose:n}=e,s=[1,t,o,4];return new Lt({location:"texture",type:"float32",texture:i,dims:s,download:r,dispose:n})},ls=(i,e)=>{let{dataType:o,dims:t,download:r,dispose:n}=e;return new Lt({location:"gpu-buffer",type:o??"float32",gpuBuffer:i,dims:t,download:r,dispose:n})},fs=(i,e,o)=>new Lt({location:"cpu-pinned",type:i,data:e,dims:o??[e.length]})});var ke,Sr,ps,ds,hs=O(()=>{"use strict";ke=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array],["int4",Uint8Array],["uint4",Uint8Array]]),Sr=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),ps=!1,ds=()=>{if(!ps){ps=!0;let i=typeof BigInt64Array<"u"&&BigInt64Array.from,e=typeof BigUint64Array<"u"&&BigUint64Array.from,o=typeof Float16Array<"u"&&Float16Array.from;i&&(ke.set("int64",BigInt64Array),Sr.set(BigInt64Array,"int64")),e&&(ke.set("uint64",BigUint64Array),Sr.set(BigUint64Array,"uint64")),o?(ke.set("float16",Float16Array),Sr.set(Float16Array,"float16")):ke.set("float16",Uint16Array)}}});var ms,bs,gs=O(()=>{"use strict";ln();ms=i=>{let e=1;for(let o=0;o<i.length;o++){let t=i[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},bs=(i,e)=>{switch(i.location){case"cpu":return new Lt(i.type,i.data,e);case"cpu-pinned":return new Lt({location:"cpu-pinned",data:i.data,type:i.type,dims:e});case"texture":return new Lt({location:"texture",texture:i.texture,type:i.type,dims:e});case"gpu-buffer":return new Lt({location:"gpu-buffer",gpuBuffer:i.gpuBuffer,type:i.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${i.location} is not supported`)}}});var Lt,ln=O(()=>{"use strict";as();cs();hs();gs();Lt=class{constructor(e,o,t){ds();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 a=ke.get(r);if(!a)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(e.data instanceof a))throw new TypeError(`buffer should be of type ${a.name}`);this.cpuData=e.data;break}case"texture":{if(r!=="float32")throw new TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=e.texture,this.downloader=e.download,this.disposer=e.dispose;break}case"gpu-buffer":{if(r!=="float32"&&r!=="float16"&&r!=="int32"&&r!=="int64"&&r!=="uint32"&&r!=="uint8"&&r!=="bool"&&r!=="uint4"&&r!=="int4")throw new TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=e.gpuBuffer,this.downloader=e.download,this.disposer=e.dispose;break}default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let a,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.");a=o}else{let l=ke.get(e);if(l===void 0)throw new TypeError(`Unsupported tensor type: ${e}.`);if(Array.isArray(o)){if(e==="float16"&&l===Uint16Array||e==="uint4"||e==="int4")throw new TypeError(`Creating a ${e} tensor from number array is not supported. Please use ${l.name} as data.`);e==="uint64"||e==="int64"?a=l.from(o,BigInt):a=l.from(o)}else if(o instanceof l)a=o;else if(o instanceof Uint8ClampedArray)if(e==="uint8")a=Uint8Array.from(o);else throw new TypeError("A Uint8ClampedArray tensor's data must be type of uint8");else throw new TypeError(`A ${r} tensor's data must be type of ${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",a=e;else if(l==="boolean")r="bool",a=Uint8Array.from(e);else throw new TypeError(`Invalid element type of data array: ${l}.`)}else if(e instanceof Uint8ClampedArray)r="uint8",a=Uint8Array.from(e);else{let l=Sr.get(e.constructor);if(l===void 0)throw new TypeError(`Unsupported type for tensor data: ${e.constructor}.`);r=l,a=e}if(u===void 0)u=[a.length];else if(!Array.isArray(u))throw new TypeError("A tensor's dims must be a number array");n=u,this.cpuData=a,this.dataLocation="cpu"}let s=ms(n);if(this.cpuData&&s!==this.cpuData.length&&!((r==="uint4"||r==="int4")&&Math.ceil(s/2)===this.cpuData.length))throw new Error(`Tensor's size(${s}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=n,this.size=s}static async fromImage(e,o){return ss(e,o)}static fromTexture(e,o){return us(e,o)}static fromGpuBuffer(e,o){return ls(e,o)}static fromPinnedBuffer(e,o,t){return fs(e,o,t)}toDataURL(e){return os(this,e)}toImageData(e){return is(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 bs(this,e)}}});var Tt,fn=O(()=>{"use strict";ln();Tt=Lt});var ys,xs,Be,Fe,Co=O(()=>{"use strict";Bo();ys=(i,e)=>{(typeof Rt.trace>"u"?!Rt.wasm.trace:!Rt.trace)||console.timeStamp(`${i}::ORT::${e}`)},xs=(i,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_${i}::${o[r].trim().split(" ")[1]}`;e&&(n+=`::${e}`),ys("CPU",n);return}o[r].includes("TRACE_FUNC")&&(t=!0)}},Be=i=>{(typeof Rt.trace>"u"?!Rt.wasm.trace:!Rt.trace)||xs("BEGIN",i)},Fe=i=>{(typeof Rt.trace>"u"?!Rt.wasm.trace:!Rt.trace)||xs("END",i)}});var cn,Ts=O(()=>{"use strict";un();fn();Co();cn=class i{constructor(e){this.handler=e}async run(e,o,t){Be();let r={},n={};if(typeof e!="object"||e===null||e instanceof Tt||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 Tt)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 Tt)&&(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 a=await this.handler.run(e,r,n),u={};for(let l in a)if(Object.hasOwnProperty.call(a,l)){let f=a[l];f instanceof Tt?u[l]=f:u[l]=new Tt(f.type,f.data,f.dims)}return Fe(),u}async release(){return this.handler.dispose()}static async create(e,o,t,r){Be();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[a,u]=await sn(s),l=await a.createInferenceSessionHandler(n,u);return Fe(),new i(l)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}});var Kd,ws=O(()=>{"use strict";Ts();Kd=cn});var vs=O(()=>{"use strict"});var Is=O(()=>{"use strict"});var _s=O(()=>{"use strict"});var Os=O(()=>{"use strict"});var Jd,pn,Ss=O(()=>{"use strict";un();fn();Jd="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",pn=class i{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,a]=await sn(n);if(s.createTrainingSessionHandler){let u=await s.createTrainingSessionHandler(e.checkpointState,e.trainModel,t,r,a);return new i(u,!!e.optimizerModel,!!e.evalModel)}else throw new Error(Jd)}typeNarrowingForRunStep(e,o,t,r,n){let s={},a={};if(typeof t!="object"||t===null||t instanceof Tt||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 Tt)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)a=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 Tt)&&(l=!0,u=!1,s[p]=d)}if(l){if(typeof n=="object"&&n!==null)a=n;else if(typeof n<"u")throw new TypeError("'options' must be an object.")}else a=r}}else if(typeof r<"u")throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(let 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,a]}convertHandlerReturnTypeToMapOfTensors(e){let o={};for(let t in e)if(Object.hasOwnProperty.call(e,t)){let r=e[t];r instanceof Tt?o[t]=r:o[t]=new Tt(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 Yd,As=O(()=>{"use strict";Ss();Yd=pn});var No={};Or(No,{InferenceSession:()=>Kd,TRACE:()=>ys,TRACE_FUNC_BEGIN:()=>Be,TRACE_FUNC_END:()=>Fe,Tensor:()=>Tt,TrainingSession:()=>Yd,env:()=>z,registerBackend:()=>nr});var Kt=O(()=>{"use strict";Qa();ns();ws();fn();vs();Is();Co();_s();Os();As()});function Ie(i,e,o,t){if(e===void 0)return Qd(i);if(o===void 0)dn(i,e,1);else if(typeof o=="number"&&t===void 0)dn(i,e,o);else if(typeof o=="string"&&t===void 0)dn(i,o,1,e);else if(typeof o=="string"&&typeof t=="number")dn(i,o,t,e);else throw new TypeError("input is valid")}function Qd(i){return{verbose:Ie.verbose.bind(null,i),info:Ie.info.bind(null,i),warning:Ie.warning.bind(null,i),error:Ie.error.bind(null,i),fatal:Ie.fatal.bind(null,i)}}function dn(i,e,o,t){let r=Ar[t||""]||Ar[""];Es[i]<Es[r.minimalSeverity]||(r.logDateTime&&(e=`${new Date().toISOString()}|${e}`),r.logSourceLocation,Zd[r.provider].log(i,e,t))}var Ro,Go,Es,Zd,Ds,Ar,tt,mn,bn,gn,hn,Mt=O(()=>{"use strict";Ro=class{log(e,o,t){}},Go=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}`)}}},Es={verbose:1e3,info:2e3,warning:4e3,error:5e3,fatal:6e3},Zd={none:new Ro,console:new Go},Ds={provider:"console",minimalSeverity:"warning",logDateTime:!0,logSourceLocation:!1},Ar={"":Ds};(u=>{function i(l,f){u("verbose",l,f)}u.verbose=i;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){Ar={},s("",l||{})}u.reset=n;function s(l,f){if(l==="*")n(f);else{let p=Ar[l]||Ds;Ar[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 a(l){let f={};l.logLevel&&(f.minimalSeverity=l.logLevel),s("",f)}u.setWithEnv=a})(Ie||={});tt=Ie,mn=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)}},bn=class{constructor(e,o,t,r){this.category=e;this.name=o;this.startTime=t;this.endTime=r}},gn=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=hn(),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,a=t();if(a&&typeof a.then=="function")return s=!0,new Promise((u,l)=>{a.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(a)},p=>{f(p)})})}return a}begin(e,o,t){if(!this._started)throw new Error("profiler is not started yet");if(t===void 0){let r=hn();return this.flush(r),new mn(e,o,r,n=>this.endSync(n))}else{let r=t.beginTimer();return new mn(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 bn(e.category,e.name,e.startTime,o)),this.flush(o))}endSync(e){let o=hn();this._timingEvents.length<this._maxNumberEvents&&(this._timingEvents.push(new bn(e.category,e.name,e.startTime,o)),this.flush(o))}logOneEvent(e){tt.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=hn()}}get started(){return this._started}},hn=typeof performance<"u"&&performance.now?()=>performance.now():Date.now});function Ls(i,e,o){for(let t of o){let r=t[0],n=t[1],s=t[2],a=t[3],u=t[4];if(i.opType===r){for(let l of e)if((l.domain===n||l.domain==="ai.onnx"&&n==="")&&th(l.version,s))return{opImpl:a,opInit:u}}}throw new TypeError(`cannot resolve operator '${i.opType}' with opsets: ${e.map(t=>`${t.domain||"ai.onnx"} v${t.version}`).join(", ")}`)}function th(i,e){if(e.endsWith("+")){let o=Number.parseInt(e.substring(0,e.length-1),10);return!isNaN(o)&&o<=i}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<=i&&i<=r}else return Number.parseInt(e,10)===i}var $s=O(()=>{"use strict"});var ks=mt(Mo=>{"use strict";Mo.__esModule=!0;var eh=function(){function i(e){if(!e)throw new TypeError("Invalid argument; `value` has no value.");this.value=i.EMPTY,e&&i.isGuid(e)&&(this.value=e)}return i.isGuid=function(e){var o=e.toString();return e&&(e instanceof i||i.validator.test(o))},i.create=function(){return new i([i.gen(2),i.gen(1),i.gen(1),i.gen(1),i.gen(3)].join("-"))},i.createEmpty=function(){return new i("emptyguid")},i.parse=function(e){return new i(e)},i.raw=function(){return[i.gen(2),i.gen(1),i.gen(1),i.gen(1),i.gen(3)].join("-")},i.gen=function(e){for(var o="",t=0;t<e;t++)o+=((1+Math.random())*65536|0).toString(16).substring(1);return o},i.prototype.equals=function(e){return i.isGuid(e)&&this.value===e.toString()},i.prototype.isEmpty=function(){return this.value===i.EMPTY},i.prototype.toString=function(){return this.value},i.prototype.toJSON=function(){return{value:this.value}},i.validator=new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$","i"),i.EMPTY="00000000-0000-0000-0000-000000000000",i}();Mo.Guid=eh});function rt(i,e,o){this.low=i|0,this.high=e|0,this.unsigned=!!o}function Pt(i){return(i&&i.__isLong__)===!0}function Bs(i){var e=Math.clz32(i&-i);return i?31-e:e}function Ce(i,e){var o,t,r;return e?(i>>>=0,(r=0<=i&&i<256)&&(t=Cs[i],t)?t:(o=J(i,0,!0),r&&(Cs[i]=o),o)):(i|=0,(r=-128<=i&&i<128)&&(t=Fs[i],t)?t:(o=J(i,i<0?-1:0,!1),r&&(Fs[i]=o),o))}function Vt(i,e){if(isNaN(i))return e?he:Jt;if(e){if(i<0)return he;if(i>=Ms)return zs}else{if(i<=-Rs)return Ft;if(i+1>=Rs)return Vs}return i<0?Vt(-i,e).neg():J(i%ir|0,i/ir|0,e)}function J(i,e,o){return new rt(i,e,o)}function Vo(i,e,o){if(i.length===0)throw Error("empty string");if(typeof e=="number"?(o=e,e=!1):e=!!e,i==="NaN"||i==="Infinity"||i==="+Infinity"||i==="-Infinity")return e?he:Jt;if(o=o||10,o<2||36<o)throw RangeError("radix");var t;if((t=i.indexOf("-"))>0)throw Error("interior hyphen");if(t===0)return Vo(i.substring(1),e,o).neg();for(var r=Vt(yn(o,8)),n=Jt,s=0;s<i.length;s+=8){var a=Math.min(8,i.length-s),u=parseInt(i.substring(s,s+a),o);if(a<8){var l=Vt(yn(o,a));n=n.mul(l).add(Vt(u))}else n=n.mul(r),n=n.add(Vt(u))}return n.unsigned=e,n}function Yt(i,e){return typeof i=="number"?Vt(i,e):typeof i=="string"?Vo(i,e):J(i.low,i.high,typeof e=="boolean"?e:i.unsigned)}var Ut,Fs,Cs,yn,Ns,rh,ir,Ms,Rs,Gs,Jt,he,or,Us,Uo,Vs,zs,Ft,D,me,zo=O(()=>{Ut=null;try{Ut=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{}rt.prototype.__isLong__;Object.defineProperty(rt.prototype,"__isLong__",{value:!0});rt.isLong=Pt;Fs={},Cs={};rt.fromInt=Ce;rt.fromNumber=Vt;rt.fromBits=J;yn=Math.pow;rt.fromString=Vo;rt.fromValue=Yt;Ns=65536,rh=1<<24,ir=Ns*Ns,Ms=ir*ir,Rs=Ms/2,Gs=Ce(rh),Jt=Ce(0);rt.ZERO=Jt;he=Ce(0,!0);rt.UZERO=he;or=Ce(1);rt.ONE=or;Us=Ce(1,!0);rt.UONE=Us;Uo=Ce(-1);rt.NEG_ONE=Uo;Vs=J(-1,2147483647,!1);rt.MAX_VALUE=Vs;zs=J(-1,-1,!0);rt.MAX_UNSIGNED_VALUE=zs;Ft=J(0,-2147483648,!1);rt.MIN_VALUE=Ft;D=rt.prototype;D.toInt=function(){return this.unsigned?this.low>>>0:this.low};D.toNumber=function(){return this.unsigned?(this.high>>>0)*ir+(this.low>>>0):this.high*ir+(this.low>>>0)};D.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(Ft)){var o=Vt(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=Vt(yn(e,6),this.unsigned),s=this,a="";;){var u=s.div(n),l=s.sub(u.mul(n)).toInt()>>>0,f=l.toString(e);if(s=u,s.isZero())return f+a;for(;f.length<6;)f="0"+f;a=""+f+a}};D.getHighBits=function(){return this.high};D.getHighBitsUnsigned=function(){return this.high>>>0};D.getLowBits=function(){return this.low};D.getLowBitsUnsigned=function(){return this.low>>>0};D.getNumBitsAbs=function(){if(this.isNegative())return this.eq(Ft)?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};D.isZero=function(){return this.high===0&&this.low===0};D.eqz=D.isZero;D.isNegative=function(){return!this.unsigned&&this.high<0};D.isPositive=function(){return this.unsigned||this.high>=0};D.isOdd=function(){return(this.low&1)===1};D.isEven=function(){return(this.low&1)===0};D.equals=function(e){return Pt(e)||(e=Yt(e)),this.unsigned!==e.unsigned&&this.high>>>31===1&&e.high>>>31===1?!1:this.high===e.high&&this.low===e.low};D.eq=D.equals;D.notEquals=function(e){return!this.eq(e)};D.neq=D.notEquals;D.ne=D.notEquals;D.lessThan=function(e){return this.comp(e)<0};D.lt=D.lessThan;D.lessThanOrEqual=function(e){return this.comp(e)<=0};D.lte=D.lessThanOrEqual;D.le=D.lessThanOrEqual;D.greaterThan=function(e){return this.comp(e)>0};D.gt=D.greaterThan;D.greaterThanOrEqual=function(e){return this.comp(e)>=0};D.gte=D.greaterThanOrEqual;D.ge=D.greaterThanOrEqual;D.compare=function(e){if(Pt(e)||(e=Yt(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};D.comp=D.compare;D.negate=function(){return!this.unsigned&&this.eq(Ft)?Ft:this.not().add(or)};D.neg=D.negate;D.add=function(e){Pt(e)||(e=Yt(e));var o=this.high>>>16,t=this.high&65535,r=this.low>>>16,n=this.low&65535,s=e.high>>>16,a=e.high&65535,u=e.low>>>16,l=e.low&65535,f=0,p=0,d=0,y=0;return y+=n+l,d+=y>>>16,y&=65535,d+=r+u,p+=d>>>16,d&=65535,p+=t+a,f+=p>>>16,p&=65535,f+=o+s,f&=65535,J(d<<16|y,f<<16|p,this.unsigned)};D.subtract=function(e){return Pt(e)||(e=Yt(e)),this.add(e.neg())};D.sub=D.subtract;D.multiply=function(e){if(this.isZero())return this;if(Pt(e)||(e=Yt(e)),Ut){var o=Ut.mul(this.low,this.high,e.low,e.high);return J(o,Ut.get_high(),this.unsigned)}if(e.isZero())return this.unsigned?he:Jt;if(this.eq(Ft))return e.isOdd()?Ft:Jt;if(e.eq(Ft))return this.isOdd()?Ft:Jt;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(Gs)&&e.lt(Gs))return Vt(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,r=this.high&65535,n=this.low>>>16,s=this.low&65535,a=e.high>>>16,u=e.high&65535,l=e.low>>>16,f=e.low&65535,p=0,d=0,y=0,w=0;return w+=s*f,y+=w>>>16,w&=65535,y+=n*f,d+=y>>>16,y&=65535,y+=s*l,d+=y>>>16,y&=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*a,p&=65535,J(y<<16|w,p<<16|d,this.unsigned)};D.mul=D.multiply;D.divide=function(e){if(Pt(e)||(e=Yt(e)),e.isZero())throw Error("division by zero");if(Ut){if(!this.unsigned&&this.high===-2147483648&&e.low===-1&&e.high===-1)return this;var o=(this.unsigned?Ut.div_u:Ut.div_s)(this.low,this.high,e.low,e.high);return J(o,Ut.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?he:Jt;var t,r,n;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return he;if(e.gt(this.shru(1)))return Us;n=he}else{if(this.eq(Ft)){if(e.eq(or)||e.eq(Uo))return Ft;if(e.eq(Ft))return or;var s=this.shr(1);return t=s.div(e).shl(1),t.eq(Jt)?e.isNegative()?or:Uo:(r=this.sub(e.mul(t)),n=t.add(r.div(e)),n)}else if(e.eq(Ft))return this.unsigned?he:Jt;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=Jt}for(r=this;r.gte(e);){t=Math.max(1,Math.floor(r.toNumber()/e.toNumber()));for(var a=Math.ceil(Math.log(t)/Math.LN2),u=a<=48?1:yn(2,a-48),l=Vt(t),f=l.mul(e);f.isNegative()||f.gt(r);)t-=u,l=Vt(t,this.unsigned),f=l.mul(e);l.isZero()&&(l=or),n=n.add(l),r=r.sub(f)}return n};D.div=D.divide;D.modulo=function(e){if(Pt(e)||(e=Yt(e)),Ut){var o=(this.unsigned?Ut.rem_u:Ut.rem_s)(this.low,this.high,e.low,e.high);return J(o,Ut.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))};D.mod=D.modulo;D.rem=D.modulo;D.not=function(){return J(~this.low,~this.high,this.unsigned)};D.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32};D.clz=D.countLeadingZeros;D.countTrailingZeros=function(){return this.low?Bs(this.low):Bs(this.high)+32};D.ctz=D.countTrailingZeros;D.and=function(e){return Pt(e)||(e=Yt(e)),J(this.low&e.low,this.high&e.high,this.unsigned)};D.or=function(e){return Pt(e)||(e=Yt(e)),J(this.low|e.low,this.high|e.high,this.unsigned)};D.xor=function(e){return Pt(e)||(e=Yt(e)),J(this.low^e.low,this.high^e.high,this.unsigned)};D.shiftLeft=function(e){return Pt(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?J(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):J(0,this.low<<e-32,this.unsigned)};D.shl=D.shiftLeft;D.shiftRight=function(e){return Pt(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?J(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):J(this.high>>e-32,this.high>=0?0:-1,this.unsigned)};D.shr=D.shiftRight;D.shiftRightUnsigned=function(e){return Pt(e)&&(e=e.toInt()),(e&=63)===0?this:e<32?J(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):e===32?J(this.high,0,this.unsigned):J(this.high>>>e-32,0,this.unsigned)};D.shru=D.shiftRightUnsigned;D.shr_u=D.shiftRightUnsigned;D.rotateLeft=function(e){var o;return Pt(e)&&(e=e.toInt()),(e&=63)===0?this:e===32?J(this.high,this.low,this.unsigned):e<32?(o=32-e,J(this.low<<e|this.high>>>o,this.high<<e|this.low>>>o,this.unsigned)):(e-=32,o=32-e,J(this.high<<e|this.low>>>o,this.low<<e|this.high>>>o,this.unsigned))};D.rotl=D.rotateLeft;D.rotateRight=function(e){var o;return Pt(e)&&(e=e.toInt()),(e&=63)===0?this:e===32?J(this.high,this.low,this.unsigned):e<32?(o=32-e,J(this.high<<o|this.low>>>e,this.low<<o|this.high>>>e,this.unsigned)):(e-=32,o=32-e,J(this.low<<o|this.high>>>e,this.high<<o|this.low>>>e,this.unsigned))};D.rotr=D.rotateRight;D.toSigned=function(){return this.unsigned?J(this.low,this.high,!1):this};D.toUnsigned=function(){return this.unsigned?this:J(this.low,this.high,!0)};D.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()};D.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]};D.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]};rt.fromBytes=function(e,o,t){return t?rt.fromBytesLE(e,o):rt.fromBytesBE(e,o)};rt.fromBytesLE=function(e,o){return new rt(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,o)};rt.fromBytesBE=function(e,o){return new rt(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],o)};me=rt});var T,xn=O(()=>{T={};T.Offset;T.Table;T.SIZEOF_SHORT=2;T.SIZEOF_INT=4;T.FILE_IDENTIFIER_LENGTH=4;T.SIZE_PREFIX_LENGTH=4;T.Encoding={UTF8_BYTES:1,UTF16_STRING:2};T.int32=new Int32Array(2);T.float32=new Float32Array(T.int32.buffer);T.float64=new Float64Array(T.int32.buffer);T.isLittleEndian=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;T.Long=function(i,e){this.low=i|0,this.high=e|0};T.Long.create=function(i,e){return i==0&&e==0?T.Long.ZERO:new T.Long(i,e)};T.Long.prototype.toFloat64=function(){return(this.low>>>0)+this.high*4294967296};T.Long.prototype.equals=function(i){return this.low==i.low&&this.high==i.high};T.Long.ZERO=new T.Long(0,0);T.Builder=function(i){if(i)var e=i;else var e=1024;this.bb=T.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};T.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};T.Builder.prototype.forceDefaults=function(i){this.force_defaults=i};T.Builder.prototype.dataBuffer=function(){return this.bb};T.Builder.prototype.asUint8Array=function(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())};T.Builder.prototype.prep=function(i,e){i>this.minalign&&(this.minalign=i);for(var o=~(this.bb.capacity()-this.space+e)+1&i-1;this.space<o+i+e;){var t=this.bb.capacity();this.bb=T.Builder.growByteBuffer(this.bb),this.space+=this.bb.capacity()-t}this.pad(o)};T.Builder.prototype.pad=function(i){for(var e=0;e<i;e++)this.bb.writeInt8(--this.space,0)};T.Builder.prototype.writeInt8=function(i){this.bb.writeInt8(this.space-=1,i)};T.Builder.prototype.writeInt16=function(i){this.bb.writeInt16(this.space-=2,i)};T.Builder.prototype.writeInt32=function(i){this.bb.writeInt32(this.space-=4,i)};T.Builder.prototype.writeInt64=function(i){this.bb.writeInt64(this.space-=8,i)};T.Builder.prototype.writeFloat32=function(i){this.bb.writeFloat32(this.space-=4,i)};T.Builder.prototype.writeFloat64=function(i){this.bb.writeFloat64(this.space-=8,i)};T.Builder.prototype.addInt8=function(i){this.prep(1,0),this.writeInt8(i)};T.Builder.prototype.addInt16=function(i){this.prep(2,0),this.writeInt16(i)};T.Builder.prototype.addInt32=function(i){this.prep(4,0),this.writeInt32(i)};T.Builder.prototype.addInt64=function(i){this.prep(8,0),this.writeInt64(i)};T.Builder.prototype.addFloat32=function(i){this.prep(4,0),this.writeFloat32(i)};T.Builder.prototype.addFloat64=function(i){this.prep(8,0),this.writeFloat64(i)};T.Builder.prototype.addFieldInt8=function(i,e,o){(this.force_defaults||e!=o)&&(this.addInt8(e),this.slot(i))};T.Builder.prototype.addFieldInt16=function(i,e,o){(this.force_defaults||e!=o)&&(this.addInt16(e),this.slot(i))};T.Builder.prototype.addFieldInt32=function(i,e,o){(this.force_defaults||e!=o)&&(this.addInt32(e),this.slot(i))};T.Builder.prototype.addFieldInt64=function(i,e,o){(this.force_defaults||!e.equals(o))&&(this.addInt64(e),this.slot(i))};T.Builder.prototype.addFieldFloat32=function(i,e,o){(this.force_defaults||e!=o)&&(this.addFloat32(e),this.slot(i))};T.Builder.prototype.addFieldFloat64=function(i,e,o){(this.force_defaults||e!=o)&&(this.addFloat64(e),this.slot(i))};T.Builder.prototype.addFieldOffset=function(i,e,o){(this.force_defaults||e!=o)&&(this.addOffset(e),this.slot(i))};T.Builder.prototype.addFieldStruct=function(i,e,o){e!=o&&(this.nested(e),this.slot(i))};T.Builder.prototype.nested=function(i){if(i!=this.offset())throw new Error("FlatBuffers: struct must be serialized inline.")};T.Builder.prototype.notNested=function(){if(this.isNested)throw new Error("FlatBuffers: object serialization must not be nested.")};T.Builder.prototype.slot=function(i){this.vtable[i]=this.offset()};T.Builder.prototype.offset=function(){return this.bb.capacity()-this.space};T.Builder.growByteBuffer=function(i){var e=i.capacity();if(e&3221225472)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");var o=e<<1,t=T.ByteBuffer.allocate(o);return t.setPosition(o-e),t.bytes().set(i.bytes(),o-e),t};T.Builder.prototype.addOffset=function(i){this.prep(T.SIZEOF_INT,0),this.writeInt32(this.offset()-i+T.SIZEOF_INT)};T.Builder.prototype.startObject=function(i){this.notNested(),this.vtable==null&&(this.vtable=[]),this.vtable_in_use=i;for(var e=0;e<i;e++)this.vtable[e]=0;this.isNested=!0,this.object_start=this.offset()};T.Builder.prototype.endObject=function(){if(this.vtable==null||!this.isNested)throw new Error("FlatBuffers: endObject called without startObject");this.addInt32(0);for(var i=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?i-this.vtable[e]:0);var t=2;this.addInt16(i-this.object_start);var r=(o+t)*T.SIZEOF_SHORT;this.addInt16(r);var n=0,s=this.space;t:for(e=0;e<this.vtables.length;e++){var a=this.bb.capacity()-this.vtables[e];if(r==this.bb.readInt16(a)){for(var u=T.SIZEOF_SHORT;u<r;u+=T.SIZEOF_SHORT)if(this.bb.readInt16(s+u)!=this.bb.readInt16(a+u))continue t;n=this.vtables[e];break}}return n?(this.space=this.bb.capacity()-i,this.bb.writeInt32(this.space,n-i)):(this.vtables.push(this.offset()),this.bb.writeInt32(this.bb.capacity()-i,this.offset()-i)),this.isNested=!1,i};T.Builder.prototype.finish=function(i,e,o){var t=o?T.SIZE_PREFIX_LENGTH:0;if(e){var r=e;if(this.prep(this.minalign,T.SIZEOF_INT+T.FILE_IDENTIFIER_LENGTH+t),r.length!=T.FILE_IDENTIFIER_LENGTH)throw new Error("FlatBuffers: file identifier must be length "+T.FILE_IDENTIFIER_LENGTH);for(var n=T.FILE_IDENTIFIER_LENGTH-1;n>=0;n--)this.writeInt8(r.charCodeAt(n))}this.prep(this.minalign,T.SIZEOF_INT+t),this.addOffset(i),t&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)};T.Builder.prototype.finishSizePrefixed=function(i,e){this.finish(i,e,!0)};T.Builder.prototype.requiredField=function(i,e){var o=this.bb.capacity()-i,t=o-this.bb.readInt32(o),r=this.bb.readInt16(t+e)!=0;if(!r)throw new Error("FlatBuffers: field "+e+" must be set")};T.Builder.prototype.startVector=function(i,e,o){this.notNested(),this.vector_num_elems=e,this.prep(T.SIZEOF_INT,i*e),this.prep(o,i*e)};T.Builder.prototype.endVector=function(){return this.writeInt32(this.vector_num_elems),this.offset()};T.Builder.prototype.createString=function(i){if(i instanceof Uint8Array)var e=i;else for(var e=[],o=0;o<i.length;){var t,r=i.charCodeAt(o++);if(r<55296||r>=56320)t=r;else{var n=i.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,a=this.bb.bytes();o<e.length;o++)a[s++]=e[o];return this.endVector()};T.Builder.prototype.createLong=function(i,e){return T.Long.create(i,e)};T.ByteBuffer=function(i){this.bytes_=i,this.position_=0};T.ByteBuffer.allocate=function(i){return new T.ByteBuffer(new Uint8Array(i))};T.ByteBuffer.prototype.clear=function(){this.position_=0};T.ByteBuffer.prototype.bytes=function(){return this.bytes_};T.ByteBuffer.prototype.position=function(){return this.position_};T.ByteBuffer.prototype.setPosition=function(i){this.position_=i};T.ByteBuffer.prototype.capacity=function(){return this.bytes_.length};T.ByteBuffer.prototype.readInt8=function(i){return this.readUint8(i)<<24>>24};T.ByteBuffer.prototype.readUint8=function(i){return this.bytes_[i]};T.ByteBuffer.prototype.readInt16=function(i){return this.readUint16(i)<<16>>16};T.ByteBuffer.prototype.readUint16=function(i){return this.bytes_[i]|this.bytes_[i+1]<<8};T.ByteBuffer.prototype.readInt32=function(i){return this.bytes_[i]|this.bytes_[i+1]<<8|this.bytes_[i+2]<<16|this.bytes_[i+3]<<24};T.ByteBuffer.prototype.readUint32=function(i){return this.readInt32(i)>>>0};T.ByteBuffer.prototype.readInt64=function(i){return new T.Long(this.readInt32(i),this.readInt32(i+4))};T.ByteBuffer.prototype.readUint64=function(i){return new T.Long(this.readUint32(i),this.readUint32(i+4))};T.ByteBuffer.prototype.readFloat32=function(i){return T.int32[0]=this.readInt32(i),T.float32[0]};T.ByteBuffer.prototype.readFloat64=function(i){return T.int32[T.isLittleEndian?0:1]=this.readInt32(i),T.int32[T.isLittleEndian?1:0]=this.readInt32(i+4),T.float64[0]};T.ByteBuffer.prototype.writeInt8=function(i,e){this.bytes_[i]=e};T.ByteBuffer.prototype.writeUint8=function(i,e){this.bytes_[i]=e};T.ByteBuffer.prototype.writeInt16=function(i,e){this.bytes_[i]=e,this.bytes_[i+1]=e>>8};T.ByteBuffer.prototype.writeUint16=function(i,e){this.bytes_[i]=e,this.bytes_[i+1]=e>>8};T.ByteBuffer.prototype.writeInt32=function(i,e){this.bytes_[i]=e,this.bytes_[i+1]=e>>8,this.bytes_[i+2]=e>>16,this.bytes_[i+3]=e>>24};T.ByteBuffer.prototype.writeUint32=function(i,e){this.bytes_[i]=e,this.bytes_[i+1]=e>>8,this.bytes_[i+2]=e>>16,this.bytes_[i+3]=e>>24};T.ByteBuffer.prototype.writeInt64=function(i,e){this.writeInt32(i,e.low),this.writeInt32(i+4,e.high)};T.ByteBuffer.prototype.writeUint64=function(i,e){this.writeUint32(i,e.low),this.writeUint32(i+4,e.high)};T.ByteBuffer.prototype.writeFloat32=function(i,e){T.float32[0]=e,this.writeInt32(i,T.int32[0])};T.ByteBuffer.prototype.writeFloat64=function(i,e){T.float64[0]=e,this.writeInt32(i,T.int32[T.isLittleEndian?0:1]),this.writeInt32(i+4,T.int32[T.isLittleEndian?1:0])};T.ByteBuffer.prototype.getBufferIdentifier=function(){if(this.bytes_.length<this.position_+T.SIZEOF_INT+T.FILE_IDENTIFIER_LENGTH)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");for(var i="",e=0;e<T.FILE_IDENTIFIER_LENGTH;e++)i+=String.fromCharCode(this.readInt8(this.position_+T.SIZEOF_INT+e));return i};T.ByteBuffer.prototype.__offset=function(i,e){var o=i-this.readInt32(i);return e<this.readInt16(o)?this.readInt16(o+e):0};T.ByteBuffer.prototype.__union=function(i,e){return i.bb_pos=e+this.readInt32(e),i.bb=this,i};T.ByteBuffer.prototype.__string=function(i,e){i+=this.readInt32(i);var o=this.readInt32(i),t="",r=0;if(i+