dicomweb-proxy
Version:
A proxy to translate between dicomweb and dimse
2 lines • 907 kB
JavaScript
/*! For license information please see ort.js.LICENSE.txt */
"use strict";var ort=(()=>{var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__esm=(t,e)=>function(){return t&&(e=(0,t[__getOwnPropNames(t)[0]])(t=0)),e},__commonJS=(t,e)=>function(){return e||(0,t[__getOwnPropNames(t)[0]])((e={exports:{}}).exports,e),e.exports},__export=(t,e)=>{for(var n in e)__defProp(t,n,{get:e[n],enumerable:!0})},__copyProps=(t,e,n,r)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let s of __getOwnPropNames(e))__hasOwnProp.call(t,s)||s===n||__defProp(t,s,{get:()=>e[s],enumerable:!(r=__getOwnPropDesc(e,s))||r.enumerable});return t},__toESM=(t,e,n)=>(n=null!=t?__create(__getProtoOf(t)):{},__copyProps(!e&&t&&t.__esModule?n:__defProp(n,"default",{value:t,enumerable:!0}),t)),__toCommonJS=t=>__copyProps(__defProp({},"__esModule",{value:!0}),t),backends,backendsSortedByPriority,registerBackend,resolveBackend,init_backend_impl=__esm({"common/dist/esm/backend-impl.js"(){backends=new Map,backendsSortedByPriority=[],registerBackend=(t,e,n)=>{if(!e||"function"!=typeof e.init||"function"!=typeof e.createInferenceSessionHandler)throw new TypeError("not a valid backend");{const r=backends.get(t);if(void 0===r)backends.set(t,{backend:e,priority:n});else{if(r.priority>n)return;if(r.priority===n&&r.backend!==e)throw new Error(`cannot register backend "${t}" using priority ${n}`)}if(n>=0){const e=backendsSortedByPriority.indexOf(t);-1!==e&&backendsSortedByPriority.splice(e,1);for(let e=0;e<backendsSortedByPriority.length;e++)if(backends.get(backendsSortedByPriority[e]).priority<=n)return void backendsSortedByPriority.splice(e,0,t);backendsSortedByPriority.push(t)}}},resolveBackend=async t=>{const e=0===t.length?backendsSortedByPriority:t,n=[];for(const t of e){const e=backends.get(t);if(e){if(e.initialized)return e.backend;if(e.aborted)continue;const r=!!e.initPromise;try{return r||(e.initPromise=e.backend.init(t)),await e.initPromise,e.initialized=!0,e.backend}catch(s){r||n.push({name:t,err:s}),e.aborted=!0}finally{delete e.initPromise}}}throw new Error(`no available backend found. ERR: ${n.map((t=>`[${t.name}] ${t.err}`)).join(", ")}`)}}}),init_backend=__esm({"common/dist/esm/backend.js"(){init_backend_impl()}}),version,init_version=__esm({"common/dist/esm/version.js"(){version="1.17.1"}}),logLevelValue,env,init_env_impl=__esm({"common/dist/esm/env-impl.js"(){init_version(),logLevelValue="warning",env={wasm:{},webgl:{},webgpu:{},versions:{common:version},set logLevel(t){if(void 0!==t){if("string"!=typeof t||-1===["verbose","info","warning","error","fatal"].indexOf(t))throw new Error(`Unsupported logging level: ${t}`);logLevelValue=t}},get logLevel(){return logLevelValue}},Object.defineProperty(env,"logLevel",{enumerable:!0})}}),env2,init_env=__esm({"common/dist/esm/env.js"(){init_env_impl(),env2=env}}),tensorToDataURL,tensorToImageData,init_tensor_conversion_impl=__esm({"common/dist/esm/tensor-conversion-impl.js"(){tensorToDataURL=(t,e)=>{const n="undefined"!=typeof document?document.createElement("canvas"):new OffscreenCanvas(1,1);n.width=t.dims[3],n.height=t.dims[2];const r=n.getContext("2d");if(null!=r){let s,i;void 0!==e?.tensorLayout&&"NHWC"===e.tensorLayout?(s=t.dims[2],i=t.dims[3]):(s=t.dims[3],i=t.dims[2]);const o=void 0!==e?.format?e.format:"RGB",a=e?.norm;let l,F;void 0===a||void 0===a.mean?l=[255,255,255,255]:"number"==typeof a.mean?l=[a.mean,a.mean,a.mean,a.mean]:(l=[a.mean[0],a.mean[1],a.mean[2],0],void 0!==a.mean[3]&&(l[3]=a.mean[3])),void 0===a||void 0===a.bias?F=[0,0,0,0]:"number"==typeof a.bias?F=[a.bias,a.bias,a.bias,a.bias]:(F=[a.bias[0],a.bias[1],a.bias[2],0],void 0!==a.bias[3]&&(F[3]=a.bias[3]));const U=i*s;let c=0,u=U,Q=2*U,d=-1;"RGBA"===o?(c=0,u=U,Q=2*U,d=3*U):"RGB"===o?(c=0,u=U,Q=2*U):"RBG"===o&&(c=0,Q=U,u=2*U);for(let e=0;e<i;e++)for(let n=0;n<s;n++){const s=(t.data[c++]-F[0])*l[0],i=(t.data[u++]-F[1])*l[1],o=(t.data[Q++]-F[2])*l[2],a=-1===d?255:(t.data[d++]-F[3])*l[3];r.fillStyle="rgba("+s+","+i+","+o+","+a+")",r.fillRect(n,e,1,1)}if("toDataURL"in n)return n.toDataURL();throw new Error("toDataURL is not supported")}throw new Error("Can not access image data")},tensorToImageData=(t,e)=>{const n="undefined"!=typeof document?document.createElement("canvas").getContext("2d"):new OffscreenCanvas(1,1).getContext("2d");let r;if(null==n)throw new Error("Can not access image data");{let s,i,o;void 0!==e?.tensorLayout&&"NHWC"===e.tensorLayout?(s=t.dims[2],i=t.dims[1],o=t.dims[3]):(s=t.dims[3],i=t.dims[2],o=t.dims[1]);const a=void 0!==e&&void 0!==e.format?e.format:"RGB",l=e?.norm;let F,U;void 0===l||void 0===l.mean?F=[255,255,255,255]:"number"==typeof l.mean?F=[l.mean,l.mean,l.mean,l.mean]:(F=[l.mean[0],l.mean[1],l.mean[2],255],void 0!==l.mean[3]&&(F[3]=l.mean[3])),void 0===l||void 0===l.bias?U=[0,0,0,0]:"number"==typeof l.bias?U=[l.bias,l.bias,l.bias,l.bias]:(U=[l.bias[0],l.bias[1],l.bias[2],0],void 0!==l.bias[3]&&(U[3]=l.bias[3]));const c=i*s;if(void 0!==e&&(void 0!==e.format&&4===o&&"RGBA"!==e.format||3===o&&"RGB"!==e.format&&"BGR"!==e.format))throw new Error("Tensor format doesn't match input tensor dims");const u=4;let Q=0,d=1,B=2,p=3,g=0,h=c,b=2*c,f=-1;"RGBA"===a?(g=0,h=c,b=2*c,f=3*c):"RGB"===a?(g=0,h=c,b=2*c):"RBG"===a&&(g=0,b=c,h=2*c),r=n.createImageData(s,i);for(let e=0;e<i*s;Q+=u,d+=u,B+=u,p+=u,e++)r.data[Q]=(t.data[g++]-U[0])*F[0],r.data[d]=(t.data[h++]-U[1])*F[1],r.data[B]=(t.data[b++]-U[2])*F[2],r.data[p]=-1===f?255:(t.data[f++]-U[3])*F[3]}return r}}}),bufferToTensor,tensorFromImage,tensorFromTexture,tensorFromGpuBuffer,tensorFromPinnedBuffer,init_tensor_factory_impl=__esm({"common/dist/esm/tensor-factory-impl.js"(){init_tensor_impl(),bufferToTensor=(t,e)=>{if(void 0===t)throw new Error("Image buffer must be defined");if(void 0===e.height||void 0===e.width)throw new Error("Image height and width must be defined");if("NHWC"===e.tensorLayout)throw new Error("NHWC Tensor layout is not supported yet");const{height:n,width:r}=e,s=e.norm??{mean:255,bias:0};let i,o;i="number"==typeof s.mean?[s.mean,s.mean,s.mean,s.mean]:[s.mean[0],s.mean[1],s.mean[2],s.mean[3]??255],o="number"==typeof s.bias?[s.bias,s.bias,s.bias,s.bias]:[s.bias[0],s.bias[1],s.bias[2],s.bias[3]??0];const a=void 0!==e.format?e.format:"RGBA",l=void 0!==e.tensorFormat&&void 0!==e.tensorFormat?e.tensorFormat:"RGB",F=n*r,U="RGBA"===l?new Float32Array(4*F):new Float32Array(3*F);let c=4,u=0,Q=1,d=2,B=3,p=0,g=F,h=2*F,b=-1;"RGB"===a&&(c=3,u=0,Q=1,d=2,B=-1),"RGBA"===l?b=3*F:"RBG"===l?(p=0,h=F,g=2*F):"BGR"===l&&(h=0,g=F,p=2*F);for(let e=0;e<F;e++,u+=c,d+=c,Q+=c,B+=c)U[p++]=(t[u]+o[0])/i[0],U[g++]=(t[Q]+o[1])/i[1],U[h++]=(t[d]+o[2])/i[2],-1!==b&&-1!==B&&(U[b++]=(t[B]+o[3])/i[3]);return new Tensor("float32",U,"RGBA"===l?[1,4,n,r]:[1,3,n,r])},tensorFromImage=async(t,e)=>{const n="undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement,r="undefined"!=typeof ImageData&&t instanceof ImageData,s="undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap,i="string"==typeof t;let o,a=e??{};const l=()=>{if("undefined"!=typeof document)return document.createElement("canvas");if("undefined"!=typeof OffscreenCanvas)return new OffscreenCanvas(1,1);throw new Error("Canvas is not supported")},F=t=>t instanceof HTMLCanvasElement||t instanceof OffscreenCanvas?t.getContext("2d"):null;if(n){const n=l();n.width=t.width,n.height=t.height;const r=F(n);if(null==r)throw new Error("Can not access image data");{let n=t.height,s=t.width;if(void 0!==e&&void 0!==e.resizedHeight&&void 0!==e.resizedWidth&&(n=e.resizedHeight,s=e.resizedWidth),void 0!==e){if(a=e,void 0!==e.tensorFormat)throw new Error("Image input config format must be RGBA for HTMLImageElement");a.tensorFormat="RGBA",a.height=n,a.width=s}else a.tensorFormat="RGBA",a.height=n,a.width=s;r.drawImage(t,0,0),o=r.getImageData(0,0,s,n).data}}else{if(!r){if(s){if(void 0===e)throw new Error("Please provide image config with format for Imagebitmap");const n=l();n.width=t.width,n.height=t.height;const r=F(n);if(null!=r){const e=t.height,n=t.width;return r.drawImage(t,0,0,n,e),o=r.getImageData(0,0,n,e).data,a.height=e,a.width=n,bufferToTensor(o,a)}throw new Error("Can not access image data")}if(i)return new Promise(((e,n)=>{const r=l(),s=F(r);if(!t||!s)return n();const i=new Image;i.crossOrigin="Anonymous",i.src=t,i.onload=()=>{r.width=i.width,r.height=i.height,s.drawImage(i,0,0,r.width,r.height);const t=s.getImageData(0,0,r.width,r.height);a.height=r.height,a.width=r.width,e(bufferToTensor(t.data,a))}}));throw new Error("Input data provided is not supported - aborted tensor creation")}{let n,r;if(void 0!==e&&void 0!==e.resizedWidth&&void 0!==e.resizedHeight?(n=e.resizedHeight,r=e.resizedWidth):(n=t.height,r=t.width),void 0!==e&&(a=e),a.format="RGBA",a.height=n,a.width=r,void 0!==e){const e=l();e.width=r,e.height=n;const s=F(e);if(null==s)throw new Error("Can not access image data");s.putImageData(t,0,0),o=s.getImageData(0,0,r,n).data}else o=t.data}}if(void 0!==o)return bufferToTensor(o,a);throw new Error("Input data provided is not supported - aborted tensor creation")},tensorFromTexture=(t,e)=>{const{width:n,height:r,download:s,dispose:i}=e;return new Tensor({location:"texture",type:"float32",texture:t,dims:[1,r,n,4],download:s,dispose:i})},tensorFromGpuBuffer=(t,e)=>{const{dataType:n,dims:r,download:s,dispose:i}=e;return new Tensor({location:"gpu-buffer",type:n??"float32",gpuBuffer:t,dims:r,download:s,dispose:i})},tensorFromPinnedBuffer=(t,e,n)=>new Tensor({location:"cpu-pinned",type:t,data:e,dims:n??[e.length]})}}),NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP,NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP,isBigIntChecked,checkBigInt,init_tensor_impl_type_mapping=__esm({"common/dist/esm/tensor-impl-type-mapping.js"(){NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",Uint16Array],["float16",Uint16Array],["int16",Int16Array],["int32",Int32Array],["bool",Uint8Array],["float64",Float64Array],["uint32",Uint32Array]]),NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP=new Map([[Float32Array,"float32"],[Uint8Array,"uint8"],[Int8Array,"int8"],[Uint16Array,"uint16"],[Int16Array,"int16"],[Int32Array,"int32"],[Float64Array,"float64"],[Uint32Array,"uint32"]]),isBigIntChecked=!1,checkBigInt=()=>{if(!isBigIntChecked){isBigIntChecked=!0;const t="undefined"!=typeof BigInt64Array&&"function"==typeof BigInt64Array.from,e="undefined"!=typeof BigUint64Array&&"function"==typeof BigUint64Array.from;t&&(NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("int64",BigInt64Array),NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array,"int64")),e&&(NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("uint64",BigUint64Array),NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array,"uint64"))}}}}),calculateSize,tensorReshape,init_tensor_utils_impl=__esm({"common/dist/esm/tensor-utils-impl.js"(){init_tensor_impl(),calculateSize=t=>{let e=1;for(let n=0;n<t.length;n++){const r=t[n];if("number"!=typeof r||!Number.isSafeInteger(r))throw new TypeError(`dims[${n}] must be an integer, got: ${r}`);if(r<0)throw new RangeError(`dims[${n}] must be a non-negative integer, got: ${r}`);e*=r}return e},tensorReshape=(t,e)=>{switch(t.location){case"cpu":return new Tensor(t.type,t.data,e);case"cpu-pinned":return new Tensor({location:"cpu-pinned",data:t.data,type:t.type,dims:e});case"texture":return new Tensor({location:"texture",texture:t.texture,type:t.type,dims:e});case"gpu-buffer":return new Tensor({location:"gpu-buffer",gpuBuffer:t.gpuBuffer,type:t.type,dims:e});default:throw new Error(`tensorReshape: tensor location ${t.location} is not supported`)}}}}),Tensor,init_tensor_impl=__esm({"common/dist/esm/tensor-impl.js"(){init_tensor_conversion_impl(),init_tensor_factory_impl(),init_tensor_impl_type_mapping(),init_tensor_utils_impl(),Tensor=class{constructor(t,e,n){let r,s;if(checkBigInt(),"object"==typeof t&&"location"in t)switch(this.dataLocation=t.location,r=t.type,s=t.dims,t.location){case"cpu-pinned":{const e=NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(r);if(!e)throw new TypeError(`unsupported type "${r}" to create tensor from pinned buffer`);if(!(t.data instanceof e))throw new TypeError(`buffer should be of type ${e.name}`);this.cpuData=t.data;break}case"texture":if("float32"!==r)throw new TypeError(`unsupported type "${r}" to create tensor from texture`);this.gpuTextureData=t.texture,this.downloader=t.download,this.disposer=t.dispose;break;case"gpu-buffer":if("float32"!==r&&"float16"!==r&&"int32"!==r&&"int64"!==r&&"uint32"!==r&&"bool"!==r)throw new TypeError(`unsupported type "${r}" to create tensor from gpu buffer`);this.gpuBufferData=t.gpuBuffer,this.downloader=t.download,this.disposer=t.dispose;break;default:throw new Error(`Tensor constructor: unsupported location '${this.dataLocation}'`)}else{let i,o;if("string"==typeof t)if(r=t,o=n,"string"===t){if(!Array.isArray(e))throw new TypeError("A string tensor's data must be a string array.");i=e}else{const n=NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(t);if(void 0===n)throw new TypeError(`Unsupported tensor type: ${t}.`);if(Array.isArray(e)){if("float16"===t)throw new TypeError("Creating a float16 tensor from number array is not supported. Please use Uint16Array as data.");i="uint64"===t||"int64"===t?n.from(e,BigInt):n.from(e)}else{if(!(e instanceof n))throw new TypeError(`A ${r} tensor's data must be type of ${n}`);i=e}}else if(o=e,Array.isArray(t)){if(0===t.length)throw new TypeError("Tensor type cannot be inferred from an empty array.");const e=typeof t[0];if("string"===e)r="string",i=t;else{if("boolean"!==e)throw new TypeError(`Invalid element type of data array: ${e}.`);r="bool",i=Uint8Array.from(t)}}else{const e=NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.get(t.constructor);if(void 0===e)throw new TypeError(`Unsupported type for tensor data: ${t.constructor}.`);r=e,i=t}if(void 0===o)o=[i.length];else if(!Array.isArray(o))throw new TypeError("A tensor's dims must be a number array");s=o,this.cpuData=i,this.dataLocation="cpu"}const i=calculateSize(s);if(this.cpuData&&i!==this.cpuData.length)throw new Error(`Tensor's size(${i}) does not match data length(${this.cpuData.length}).`);this.type=r,this.dims=s,this.size=i}static async fromImage(t,e){return tensorFromImage(t,e)}static fromTexture(t,e){return tensorFromTexture(t,e)}static fromGpuBuffer(t,e){return tensorFromGpuBuffer(t,e)}static fromPinnedBuffer(t,e,n){return tensorFromPinnedBuffer(t,e,n)}toDataURL(t){return tensorToDataURL(this,t)}toImageData(t){return tensorToImageData(this,t)}get data(){if(this.ensureValid(),!this.cpuData)throw new Error("The data is not on CPU. Use `getData()` to download GPU data to CPU, or use `texture` or `gpuBuffer` property to access the GPU data directly.");return this.cpuData}get location(){return this.dataLocation}get texture(){if(this.ensureValid(),!this.gpuTextureData)throw new Error("The data is not stored as a WebGL texture.");return this.gpuTextureData}get gpuBuffer(){if(this.ensureValid(),!this.gpuBufferData)throw new Error("The data is not stored as a WebGPU buffer.");return this.gpuBufferData}async getData(t){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;const e=await this.downloader();return this.downloader=void 0,this.dataLocation="cpu",this.cpuData=e,t&&this.disposer&&(this.disposer(),this.disposer=void 0),e}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("none"===this.dataLocation)throw new Error("The tensor is disposed.")}reshape(t){if(this.ensureValid(),this.downloader||this.disposer)throw new Error("Cannot reshape a tensor that owns GPU resource.");return tensorReshape(this,t)}}}}),Tensor2,init_tensor=__esm({"common/dist/esm/tensor.js"(){init_tensor_impl(),Tensor2=Tensor}}),TRACE,TRACE_FUNC,TRACE_FUNC_BEGIN,TRACE_FUNC_END,init_trace=__esm({"common/dist/esm/trace.js"(){init_env_impl(),TRACE=(t,e)=>{env.wasm.trace&&console.timeStamp(`${t}::ORT::${e}`)},TRACE_FUNC=(t,e)=>{const n=(new Error).stack?.split(/\r\n|\r|\n/g)||[];let r=!1;for(let s=0;s<n.length;s++){if(r&&!n[s].includes("TRACE_FUNC")){let r=`FUNC_${t}::${n[s].trim().split(" ")[1]}`;return e&&(r+=`::${e}`),void TRACE("CPU",r)}n[s].includes("TRACE_FUNC")&&(r=!0)}},TRACE_FUNC_BEGIN=t=>{env.wasm.trace&&TRACE_FUNC("BEGIN",t)},TRACE_FUNC_END=t=>{env.wasm.trace&&TRACE_FUNC("END",t)}}}),InferenceSession,init_inference_session_impl=__esm({"common/dist/esm/inference-session-impl.js"(){init_backend_impl(),init_tensor(),init_trace(),InferenceSession=class t{constructor(t){this.handler=t}async run(t,e,n){TRACE_FUNC_BEGIN();const r={};let s={};if("object"!=typeof t||null===t||t instanceof Tensor2||Array.isArray(t))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let i=!0;if("object"==typeof e){if(null===e)throw new TypeError("Unexpected argument[1]: cannot be null.");if(e instanceof Tensor2)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(e)){if(0===e.length)throw new TypeError("'fetches' cannot be an empty array.");i=!1;for(const t of e){if("string"!=typeof t)throw new TypeError("'fetches' must be a string array or an object.");if(-1===this.outputNames.indexOf(t))throw new RangeError(`'fetches' contains invalid output name: ${t}.`);r[t]=null}if("object"==typeof n&&null!==n)s=n;else if(void 0!==n)throw new TypeError("'options' must be an object.")}else{let t=!1;const o=Object.getOwnPropertyNames(e);for(const n of this.outputNames)if(-1!==o.indexOf(n)){const s=e[n];(null===s||s instanceof Tensor2)&&(t=!0,i=!1,r[n]=s)}if(t){if("object"==typeof n&&null!==n)s=n;else if(void 0!==n)throw new TypeError("'options' must be an object.")}else s=e}}else if(void 0!==e)throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const e of this.inputNames)if(void 0===t[e])throw new Error(`input '${e}' is missing in 'feeds'.`);if(i)for(const t of this.outputNames)r[t]=null;const o=await this.handler.run(t,r,s),a={};for(const t in o)if(Object.hasOwnProperty.call(o,t)){const e=o[t];a[t]=e instanceof Tensor2?e:new Tensor2(e.type,e.data,e.dims)}return TRACE_FUNC_END(),a}async release(){return this.handler.dispose()}static async create(e,n,r,s){let i;TRACE_FUNC_BEGIN();let o={};if("string"==typeof e){if(i=e,"object"==typeof n&&null!==n)o=n;else if(void 0!==n)throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(i=e,"object"==typeof n&&null!==n)o=n;else if(void 0!==n)throw new TypeError("'options' must be an object.")}else{if(!(e instanceof ArrayBuffer||"undefined"!=typeof SharedArrayBuffer&&e instanceof SharedArrayBuffer))throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");{const t=e;let a=0,l=e.byteLength;if("object"==typeof n&&null!==n)o=n;else if("number"==typeof n){if(a=n,!Number.isSafeInteger(a))throw new RangeError("'byteOffset' must be an integer.");if(a<0||a>=t.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${t.byteLength}).`);if(l=e.byteLength-a,"number"==typeof r){if(l=r,!Number.isSafeInteger(l))throw new RangeError("'byteLength' must be an integer.");if(l<=0||a+l>t.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${t.byteLength-a}].`);if("object"==typeof s&&null!==s)o=s;else if(void 0!==s)throw new TypeError("'options' must be an object.")}else if(void 0!==r)throw new TypeError("'byteLength' must be a number.")}else if(void 0!==n)throw new TypeError("'options' must be an object.");i=new Uint8Array(t,a,l)}}const a=(o.executionProviders||[]).map((t=>"string"==typeof t?t:t.name)),l=await resolveBackend(a),F=await l.createInferenceSessionHandler(i,o);return TRACE_FUNC_END(),new t(F)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}}}}),InferenceSession2,init_inference_session=__esm({"common/dist/esm/inference-session.js"(){init_inference_session_impl(),InferenceSession2=InferenceSession}}),init_onnx_value=__esm({"common/dist/esm/onnx-value.js"(){}}),noBackendErrMsg,TrainingSession,init_training_session_impl=__esm({"common/dist/esm/training-session-impl.js"(){init_backend_impl(),init_tensor(),noBackendErrMsg="Training backend could not be resolved. Make sure you're using the correct configuration & WebAssembly files.",TrainingSession=class t{constructor(t,e,n){this.handler=t,this.hasOptimizerModel=e,this.hasEvalModel=n}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,n){const r=e.evalModel||"",s=e.optimizerModel||"",i=n||{},o=(i.executionProviders||[]).map((t=>"string"==typeof t?t:t.name)),a=await resolveBackend(o);if(a.createTrainingSessionHandler){const n=await a.createTrainingSessionHandler(e.checkpointState,e.trainModel,r,s,i);return new t(n,!!e.optimizerModel,!!e.evalModel)}throw new Error(noBackendErrMsg)}typeNarrowingForRunStep(t,e,n,r,s){const i={};let o={};if("object"!=typeof n||null===n||n instanceof Tensor2||Array.isArray(n))throw new TypeError("'feeds' must be an object that use input names as keys and OnnxValue as corresponding values.");let a=!0;if("object"==typeof r){if(null===r)throw new TypeError("Unexpected argument[1]: cannot be null.");if(r instanceof Tensor2)throw new TypeError("'fetches' cannot be a Tensor");if(Array.isArray(r)){if(0===r.length)throw new TypeError("'fetches' cannot be an empty array.");a=!1;for(const t of r){if("string"!=typeof t)throw new TypeError("'fetches' must be a string array or an object.");if(-1===e.indexOf(t))throw new RangeError(`'fetches' contains invalid output name: ${t}.`);i[t]=null}if("object"==typeof s&&null!==s)o=s;else if(void 0!==s)throw new TypeError("'options' must be an object.")}else{let t=!1;const n=Object.getOwnPropertyNames(r);for(const s of e)if(-1!==n.indexOf(s)){const e=r[s];(null===e||e instanceof Tensor2)&&(t=!0,a=!1,i[s]=e)}if(t){if("object"==typeof s&&null!==s)o=s;else if(void 0!==s)throw new TypeError("'options' must be an object.")}else o=r}}else if(void 0!==r)throw new TypeError("Unexpected argument[1]: must be 'fetches' or 'options'.");for(const e of t)if(void 0===n[e])throw new Error(`input '${e}' is missing in 'feeds'.`);if(a)for(const t of e)i[t]=null;return[i,o]}convertHandlerReturnTypeToMapOfTensors(t){const e={};for(const n in t)if(Object.hasOwnProperty.call(t,n)){const r=t[n];e[n]=r instanceof Tensor2?r:new Tensor2(r.type,r.data,r.dims)}return e}async lazyResetGrad(){await this.handler.lazyResetGrad()}async runTrainStep(t,e,n){const[r,s]=this.typeNarrowingForRunStep(this.trainingInputNames,this.trainingOutputNames,t,e,n),i=await this.handler.runTrainStep(t,r,s);return this.convertHandlerReturnTypeToMapOfTensors(i)}async runOptimizerStep(t){if(!this.hasOptimizerModel)throw new Error("This TrainingSession has no OptimizerModel loaded.");await this.handler.runOptimizerStep(t||{})}async runEvalStep(t,e,n){if(this.hasEvalModel){const[r,s]=this.typeNarrowingForRunStep(this.evalInputNames,this.evalOutputNames,t,e,n),i=await this.handler.runEvalStep(t,r,s);return this.convertHandlerReturnTypeToMapOfTensors(i)}throw new Error("This TrainingSession has no EvalModel loaded.")}async getParametersSize(t=!0){return this.handler.getParametersSize(t)}async loadParametersBuffer(t,e=!0){const n=await this.getParametersSize(e);if(t.length!==4*n)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(t,e)}async getContiguousParameters(t=!0){return this.handler.getContiguousParameters(t)}async release(){return this.handler.dispose()}}}}),TrainingSession2,init_training_session=__esm({"common/dist/esm/training-session.js"(){init_training_session_impl(),TrainingSession2=TrainingSession}}),esm_exports={};__export(esm_exports,{InferenceSession:()=>InferenceSession2,TRACE:()=>TRACE,TRACE_FUNC_BEGIN:()=>TRACE_FUNC_BEGIN,TRACE_FUNC_END:()=>TRACE_FUNC_END,Tensor:()=>Tensor2,TrainingSession:()=>TrainingSession2,env:()=>env2,registerBackend:()=>registerBackend});var init_esm=__esm({"common/dist/esm/index.js"(){init_backend(),init_env(),init_inference_session(),init_tensor(),init_trace(),init_onnx_value(),init_training_session()}}),readFile,init_promises=__esm({"nodejs-ignore:node:fs/promises"(){readFile=void 0}}),NoOpLoggerProvider,ConsoleLoggerProvider,SEVERITY_VALUE,LOGGER_PROVIDER_MAP,LOGGER_DEFAULT_CONFIG,LOGGER_CONFIG_MAP,Logger,Event,EventRecord,Profiler,now;function log(t,e,n,r){if(void 0===e)return createCategorizedLogger(t);if(void 0===n)logInternal(t,e,1);else if("number"==typeof n&&void 0===r)logInternal(t,e,n);else if("string"==typeof n&&void 0===r)logInternal(t,n,1,e);else{if("string"!=typeof n||"number"!=typeof r)throw new TypeError("input is valid");logInternal(t,n,r,e)}}function createCategorizedLogger(t){return{verbose:log.verbose.bind(null,t),info:log.info.bind(null,t),warning:log.warning.bind(null,t),error:log.error.bind(null,t),fatal:log.fatal.bind(null,t)}}function logInternal(t,e,n,r){const s=LOGGER_CONFIG_MAP[r||""]||LOGGER_CONFIG_MAP[""];SEVERITY_VALUE[t]<SEVERITY_VALUE[s.minimalSeverity]||(s.logDateTime&&(e=`${(new Date).toISOString()}|${e}`),s.logSourceLocation,LOGGER_PROVIDER_MAP[s.provider].log(t,e,r))}var init_instrument=__esm({"web/lib/onnxjs/instrument.ts"(){NoOpLoggerProvider=class{log(t,e,n){}},ConsoleLoggerProvider=class{log(t,e,n){console.log(`${this.color(t)} ${n?"[35m"+n+"[0m ":""}${e}`)}color(t){switch(t){case"verbose":return"[34;40mv[0m";case"info":return"[32mi[0m";case"warning":return"[30;43mw[0m";case"error":return"[31;40me[0m";case"fatal":return"[101mf[0m";default:throw new Error(`unsupported severity: ${t}`)}}},SEVERITY_VALUE={verbose:1e3,info:2e3,warning:4e3,error:5e3,fatal:6e3},LOGGER_PROVIDER_MAP={none:new NoOpLoggerProvider,console:new ConsoleLoggerProvider},LOGGER_CONFIG_MAP={"":LOGGER_DEFAULT_CONFIG={provider:"console",minimalSeverity:"warning",logDateTime:!0,logSourceLocation:!1}},(t=>{function e(t){LOGGER_CONFIG_MAP={},n("",t||{})}function n(t,n){if("*"===t)e(n);else{const e=LOGGER_CONFIG_MAP[t]||LOGGER_DEFAULT_CONFIG;LOGGER_CONFIG_MAP[t]={provider:n.provider||e.provider,minimalSeverity:n.minimalSeverity||e.minimalSeverity,logDateTime:void 0===n.logDateTime?e.logDateTime:n.logDateTime,logSourceLocation:void 0===n.logSourceLocation?e.logSourceLocation:n.logSourceLocation}}}t.verbose=function(e,n){t("verbose",e,n)},t.info=function(e,n){t("info",e,n)},t.warning=function(e,n){t("warning",e,n)},t.error=function(e,n){t("error",e,n)},t.fatal=function(e,n){t("fatal",e,n)},t.reset=e,t.set=n,t.setWithEnv=function(t){const e={};t.logLevel&&(e.minimalSeverity=t.logLevel),n("",e)}})(log||(log={})),Logger=log,Event=class{constructor(t,e,n,r,s,i){this.category=t,this.name=e,this.startTime=n,this.endCallback=r,this.timer=s,this.ctx=i}async end(){return this.endCallback(this)}async checkTimer(){if(void 0===this.ctx||void 0===this.timer)throw new Error("No webgl timer found");return this.ctx.endTimer(),this.ctx.waitForQueryAndGetTime(this.timer)}},EventRecord=class{constructor(t,e,n,r){this.category=t,this.name=e,this.startTime=n,this.endTime=r}},Profiler=class{constructor(t,e,n){this._started=!1,this._flushPointer=0,this._started=!1,this._maxNumberEvents=void 0===t?1e4:t,this._flushBatchSize=void 0===e?10:e,this._flushIntervalInMilliseconds=void 0===n?5e3:n}static create(t){return void 0===t?new this:new this(t.maxNumberEvents,t.flushBatchSize,t.flushIntervalInMilliseconds)}start(){this._started=!0,this._timingEvents=[],this._flushTime=now(),this._flushPointer=0}stop(){for(this._started=!1;this._flushPointer<this._timingEvents.length;this._flushPointer++)this.logOneEvent(this._timingEvents[this._flushPointer])}event(t,e,n,r){const s=this._started?this.begin(t,e,r):void 0;let i=!1;const o=n();if(o&&"function"==typeof o.then)return i=!0,new Promise(((t,e)=>{o.then((async e=>{s&&await s.end(),t(e)}),(async t=>{s&&await s.end(),e(t)}))}));if(!i&&s){const t=s.end();if(t&&"function"==typeof t.then)return new Promise(((e,n)=>{t.then((()=>{e(o)}),(t=>{n(t)}))}))}return o}begin(t,e,n){if(!this._started)throw new Error("profiler is not started yet");if(void 0===n){const n=now();return this.flush(n),new Event(t,e,n,(t=>this.endSync(t)))}{const r=n.beginTimer();return new Event(t,e,0,(async t=>this.end(t)),r,n)}}async end(t){const e=await t.checkTimer();this._timingEvents.length<this._maxNumberEvents&&(this._timingEvents.push(new EventRecord(t.category,t.name,t.startTime,e)),this.flush(e))}endSync(t){const e=now();this._timingEvents.length<this._maxNumberEvents&&(this._timingEvents.push(new EventRecord(t.category,t.name,t.startTime,e)),this.flush(e))}logOneEvent(t){Logger.verbose(`Profiler.${t.category}`,`${(t.endTime-t.startTime).toFixed(2)}ms on event '${t.name}' at ${t.endTime.toFixed(2)}`)}flush(t){if(this._timingEvents.length-this._flushPointer>=this._flushBatchSize||t-this._flushTime>=this._flushIntervalInMilliseconds){for(const t=this._flushPointer;this._flushPointer<t+this._flushBatchSize&&this._flushPointer<this._timingEvents.length;this._flushPointer++)this.logOneEvent(this._timingEvents[this._flushPointer]);this._flushTime=now()}}get started(){return this._started}},now="undefined"!=typeof performance&&performance.now?()=>performance.now():Date.now}});function resolveOperator(t,e,n){for(const r of n){const n=r[0],s=r[1],i=r[2],o=r[3],a=r[4];if(t.opType===n)for(const t of e)if((t.domain===s||"ai.onnx"===t.domain&&""===s)&&matchSelector(t.version,i))return{opImpl:o,opInit:a}}throw new TypeError(`cannot resolve operator '${t.opType}' with opsets: ${e.map((t=>`${t.domain||"ai.onnx"} v${t.version}`)).join(", ")}`)}function matchSelector(t,e){if(e.endsWith("+")){const n=Number.parseInt(e.substring(0,e.length-1),10);return!isNaN(n)&&n<=t}if(2===e.split("-").length){const n=e.split("-"),r=Number.parseInt(n[0],10),s=Number.parseInt(n[1],10);return!isNaN(r)&&!isNaN(s)&&r<=t&&t<=s}return Number.parseInt(e,10)===t}var init_opset=__esm({"web/lib/onnxjs/opset.ts"(){}}),require_guid=__commonJS({"web/node_modules/guid-typescript/dist/guid.js"(t){t.__esModule=!0;var e=function(){function t(e){if(!e)throw new TypeError("Invalid argument; `value` has no value.");this.value=t.EMPTY,e&&t.isGuid(e)&&(this.value=e)}return t.isGuid=function(e){var n=e.toString();return e&&(e instanceof t||t.validator.test(n))},t.create=function(){return new t([t.gen(2),t.gen(1),t.gen(1),t.gen(1),t.gen(3)].join("-"))},t.createEmpty=function(){return new t("emptyguid")},t.parse=function(e){return new t(e)},t.raw=function(){return[t.gen(2),t.gen(1),t.gen(1),t.gen(1),t.gen(3)].join("-")},t.gen=function(t){for(var e="",n=0;n<t;n++)e+=(65536*(1+Math.random())|0).toString(16).substring(1);return e},t.prototype.equals=function(e){return t.isGuid(e)&&this.value===e.toString()},t.prototype.isEmpty=function(){return this.value===t.EMPTY},t.prototype.toString=function(){return this.value},t.prototype.toJSON=function(){return{value:this.value}},t.validator=new RegExp("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$","i"),t.EMPTY="00000000-0000-0000-0000-000000000000",t}();t.Guid=e}}),wasm,INT_CACHE,UINT_CACHE,pow_dbl,TWO_PWR_16_DBL,TWO_PWR_24_DBL,TWO_PWR_32_DBL,TWO_PWR_64_DBL,TWO_PWR_63_DBL,TWO_PWR_24,ZERO,UZERO,ONE,UONE,NEG_ONE,MAX_VALUE,MAX_UNSIGNED_VALUE,MIN_VALUE,LongPrototype,long_default;function Long(t,e,n){this.low=0|t,this.high=0|e,this.unsigned=!!n}function isLong(t){return!0===(t&&t.__isLong__)}function ctz32(t){var e=Math.clz32(t&-t);return t?31-e:e}function fromInt(t,e){var n,r,s;return e?(s=0<=(t>>>=0)&&t<256)&&(r=UINT_CACHE[t])?r:(n=fromBits(t,0,!0),s&&(UINT_CACHE[t]=n),n):(s=-128<=(t|=0)&&t<128)&&(r=INT_CACHE[t])?r:(n=fromBits(t,t<0?-1:0,!1),s&&(INT_CACHE[t]=n),n)}function fromNumber(t,e){if(isNaN(t))return e?UZERO:ZERO;if(e){if(t<0)return UZERO;if(t>=TWO_PWR_64_DBL)return MAX_UNSIGNED_VALUE}else{if(t<=-TWO_PWR_63_DBL)return MIN_VALUE;if(t+1>=TWO_PWR_63_DBL)return MAX_VALUE}return t<0?fromNumber(-t,e).neg():fromBits(t%TWO_PWR_32_DBL|0,t/TWO_PWR_32_DBL|0,e)}function fromBits(t,e,n){return new Long(t,e,n)}function fromString(t,e,n){if(0===t.length)throw Error("empty string");if("number"==typeof e?(n=e,e=!1):e=!!e,"NaN"===t||"Infinity"===t||"+Infinity"===t||"-Infinity"===t)return e?UZERO:ZERO;if((n=n||10)<2||36<n)throw RangeError("radix");var r;if((r=t.indexOf("-"))>0)throw Error("interior hyphen");if(0===r)return fromString(t.substring(1),e,n).neg();for(var s=fromNumber(pow_dbl(n,8)),i=ZERO,o=0;o<t.length;o+=8){var a=Math.min(8,t.length-o),l=parseInt(t.substring(o,o+a),n);if(a<8){var F=fromNumber(pow_dbl(n,a));i=i.mul(F).add(fromNumber(l))}else i=(i=i.mul(s)).add(fromNumber(l))}return i.unsigned=e,i}function fromValue(t,e){return"number"==typeof t?fromNumber(t,e):"string"==typeof t?fromString(t,e):fromBits(t.low,t.high,"boolean"==typeof e?e:t.unsigned)}var init_long=__esm({"web/node_modules/long/index.js"(){wasm=null;try{wasm=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(t){}Long.prototype.__isLong__,Object.defineProperty(Long.prototype,"__isLong__",{value:!0}),Long.isLong=isLong,INT_CACHE={},UINT_CACHE={},Long.fromInt=fromInt,Long.fromNumber=fromNumber,Long.fromBits=fromBits,pow_dbl=Math.pow,Long.fromString=fromString,Long.fromValue=fromValue,TWO_PWR_63_DBL=(TWO_PWR_64_DBL=(TWO_PWR_32_DBL=(TWO_PWR_16_DBL=65536)*TWO_PWR_16_DBL)*TWO_PWR_32_DBL)/2,TWO_PWR_24=fromInt(TWO_PWR_24_DBL=1<<24),ZERO=fromInt(0),Long.ZERO=ZERO,UZERO=fromInt(0,!0),Long.UZERO=UZERO,ONE=fromInt(1),Long.ONE=ONE,UONE=fromInt(1,!0),Long.UONE=UONE,NEG_ONE=fromInt(-1),Long.NEG_ONE=NEG_ONE,MAX_VALUE=fromBits(-1,2147483647,!1),Long.MAX_VALUE=MAX_VALUE,MAX_UNSIGNED_VALUE=fromBits(-1,-1,!0),Long.MAX_UNSIGNED_VALUE=MAX_UNSIGNED_VALUE,MIN_VALUE=fromBits(0,-2147483648,!1),Long.MIN_VALUE=MIN_VALUE,(LongPrototype=Long.prototype).toInt=function(){return this.unsigned?this.low>>>0:this.low},LongPrototype.toNumber=function(){return this.unsigned?(this.high>>>0)*TWO_PWR_32_DBL+(this.low>>>0):this.high*TWO_PWR_32_DBL+(this.low>>>0)},LongPrototype.toString=function(t){if((t=t||10)<2||36<t)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(MIN_VALUE)){var e=fromNumber(t),n=this.div(e),r=n.mul(e).sub(this);return n.toString(t)+r.toInt().toString(t)}return"-"+this.neg().toString(t)}for(var s=fromNumber(pow_dbl(t,6),this.unsigned),i=this,o="";;){var a=i.div(s),l=(i.sub(a.mul(s)).toInt()>>>0).toString(t);if((i=a).isZero())return l+o;for(;l.length<6;)l="0"+l;o=""+l+o}},LongPrototype.getHighBits=function(){return this.high},LongPrototype.getHighBitsUnsigned=function(){return this.high>>>0},LongPrototype.getLowBits=function(){return this.low},LongPrototype.getLowBitsUnsigned=function(){return this.low>>>0},LongPrototype.getNumBitsAbs=function(){if(this.isNegative())return this.eq(MIN_VALUE)?64:this.neg().getNumBitsAbs();for(var t=0!=this.high?this.high:this.low,e=31;e>0&&!(t&1<<e);e--);return 0!=this.high?e+33:e+1},LongPrototype.isZero=function(){return 0===this.high&&0===this.low},LongPrototype.eqz=LongPrototype.isZero,LongPrototype.isNegative=function(){return!this.unsigned&&this.high<0},LongPrototype.isPositive=function(){return this.unsigned||this.high>=0},LongPrototype.isOdd=function(){return!(1&~this.low)},LongPrototype.isEven=function(){return!(1&this.low)},LongPrototype.equals=function(t){return isLong(t)||(t=fromValue(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=1)&&(this.high===t.high&&this.low===t.low)},LongPrototype.eq=LongPrototype.equals,LongPrototype.notEquals=function(t){return!this.eq(t)},LongPrototype.neq=LongPrototype.notEquals,LongPrototype.ne=LongPrototype.notEquals,LongPrototype.lessThan=function(t){return this.comp(t)<0},LongPrototype.lt=LongPrototype.lessThan,LongPrototype.lessThanOrEqual=function(t){return this.comp(t)<=0},LongPrototype.lte=LongPrototype.lessThanOrEqual,LongPrototype.le=LongPrototype.lessThanOrEqual,LongPrototype.greaterThan=function(t){return this.comp(t)>0},LongPrototype.gt=LongPrototype.greaterThan,LongPrototype.greaterThanOrEqual=function(t){return this.comp(t)>=0},LongPrototype.gte=LongPrototype.greaterThanOrEqual,LongPrototype.ge=LongPrototype.greaterThanOrEqual,LongPrototype.compare=function(t){if(isLong(t)||(t=fromValue(t)),this.eq(t))return 0;var e=this.isNegative(),n=t.isNegative();return e&&!n?-1:!e&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1},LongPrototype.comp=LongPrototype.compare,LongPrototype.negate=function(){return!this.unsigned&&this.eq(MIN_VALUE)?MIN_VALUE:this.not().add(ONE)},LongPrototype.neg=LongPrototype.negate,LongPrototype.add=function(t){isLong(t)||(t=fromValue(t));var e=this.high>>>16,n=65535&this.high,r=this.low>>>16,s=65535&this.low,i=t.high>>>16,o=65535&t.high,a=t.low>>>16,l=0,F=0,U=0,c=0;return U+=(c+=s+(65535&t.low))>>>16,F+=(U+=r+a)>>>16,l+=(F+=n+o)>>>16,l+=e+i,fromBits((U&=65535)<<16|(c&=65535),(l&=65535)<<16|(F&=65535),this.unsigned)},LongPrototype.subtract=function(t){return isLong(t)||(t=fromValue(t)),this.add(t.neg())},LongPrototype.sub=LongPrototype.subtract,LongPrototype.multiply=function(t){if(this.isZero())return this;if(isLong(t)||(t=fromValue(t)),wasm)return fromBits(wasm.mul(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned);if(t.isZero())return this.unsigned?UZERO:ZERO;if(this.eq(MIN_VALUE))return t.isOdd()?MIN_VALUE:ZERO;if(t.eq(MIN_VALUE))return this.isOdd()?MIN_VALUE:ZERO;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(TWO_PWR_24)&&t.lt(TWO_PWR_24))return fromNumber(this.toNumber()*t.toNumber(),this.unsigned);var e=this.high>>>16,n=65535&this.high,r=this.low>>>16,s=65535&this.low,i=t.high>>>16,o=65535&t.high,a=t.low>>>16,l=65535&t.low,F=0,U=0,c=0,u=0;return c+=(u+=s*l)>>>16,U+=(c+=r*l)>>>16,c&=65535,U+=(c+=s*a)>>>16,F+=(U+=n*l)>>>16,U&=65535,F+=(U+=r*a)>>>16,U&=65535,F+=(U+=s*o)>>>16,F+=e*l+n*a+r*o+s*i,fromBits((c&=65535)<<16|(u&=65535),(F&=65535)<<16|(U&=65535),this.unsigned)},LongPrototype.mul=LongPrototype.multiply,LongPrototype.divide=function(t){if(isLong(t)||(t=fromValue(t)),t.isZero())throw Error("division by zero");var e,n,r;if(wasm)return this.unsigned||-2147483648!==this.high||-1!==t.low||-1!==t.high?fromBits((this.unsigned?wasm.div_u:wasm.div_s)(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?UZERO:ZERO;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return UZERO;if(t.gt(this.shru(1)))return UONE;r=UZERO}else{if(this.eq(MIN_VALUE))return t.eq(ONE)||t.eq(NEG_ONE)?MIN_VALUE:t.eq(MIN_VALUE)?ONE:(e=this.shr(1).div(t).shl(1)).eq(ZERO)?t.isNegative()?ONE:NEG_ONE:(n=this.sub(t.mul(e)),r=e.add(n.div(t)));if(t.eq(MIN_VALUE))return this.unsigned?UZERO:ZERO;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();r=ZERO}for(n=this;n.gte(t);){e=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));for(var s=Math.ceil(Math.log(e)/Math.LN2),i=s<=48?1:pow_dbl(2,s-48),o=fromNumber(e),a=o.mul(t);a.isNegative()||a.gt(n);)a=(o=fromNumber(e-=i,this.unsigned)).mul(t);o.isZero()&&(o=ONE),r=r.add(o),n=n.sub(a)}return r},LongPrototype.div=LongPrototype.divide,LongPrototype.modulo=function(t){return isLong(t)||(t=fromValue(t)),wasm?fromBits((this.unsigned?wasm.rem_u:wasm.rem_s)(this.low,this.high,t.low,t.high),wasm.get_high(),this.unsigned):this.sub(this.div(t).mul(t))},LongPrototype.mod=LongPrototype.modulo,LongPrototype.rem=LongPrototype.modulo,LongPrototype.not=function(){return fromBits(~this.low,~this.high,this.unsigned)},LongPrototype.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},LongPrototype.clz=LongPrototype.countLeadingZeros,LongPrototype.countTrailingZeros=function(){return this.low?ctz32(this.low):ctz32(this.high)+32},LongPrototype.ctz=LongPrototype.countTrailingZeros,LongPrototype.and=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low&t.low,this.high&t.high,this.unsigned)},LongPrototype.or=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low|t.low,this.high|t.high,this.unsigned)},LongPrototype.xor=function(t){return isLong(t)||(t=fromValue(t)),fromBits(this.low^t.low,this.high^t.high,this.unsigned)},LongPrototype.shiftLeft=function(t){return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):fromBits(0,this.low<<t-32,this.unsigned)},LongPrototype.shl=LongPrototype.shiftLeft,LongPrototype.shiftRight=function(t){return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)},LongPrototype.shr=LongPrototype.shiftRight,LongPrototype.shiftRightUnsigned=function(t){return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?fromBits(this.low>>>t|this.high<<32-t,this.high>>>t,this.unsigned):fromBits(32===t?this.high:this.high>>>t-32,0,this.unsigned)},LongPrototype.shru=LongPrototype.shiftRightUnsigned,LongPrototype.shr_u=LongPrototype.shiftRightUnsigned,LongPrototype.rotateLeft=function(t){var e;return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:32===t?fromBits(this.high,this.low,this.unsigned):t<32?(e=32-t,fromBits(this.low<<t|this.high>>>e,this.high<<t|this.low>>>e,this.unsigned)):(e=32-(t-=32),fromBits(this.high<<t|this.low>>>e,this.low<<t|this.high>>>e,this.unsigned))},LongPrototype.rotl=LongPrototype.rotateLeft,LongPrototype.rotateRight=function(t){var e;return isLong(t)&&(t=t.toInt()),0==(t&=63)?this:32===t?fromBits(this.high,this.low,this.unsigned):t<32?(e=32-t,fromBits(this.high<<e|this.low>>>t,this.low<<e|this.high>>>t,this.unsigned)):(e=32-(t-=32),fromBits(this.low<<e|this.high>>>t,this.high<<e|this.low>>>t,this.unsigned))},LongPrototype.rotr=LongPrototype.rotateRight,LongPrototype.toSigned=function(){return this.unsigned?fromBits(this.low,this.high,!1):this},LongPrototype.toUnsigned=function(){return this.unsigned?this:fromBits(this.low,this.high,!0)},LongPrototype.toBytes=function(t){return t?this.toBytesLE():this.toBytesBE()},LongPrototype.toBytesLE=function(){var t=this.high,e=this.low;return[255&e,e>>>8&255,e>>>16&255,e>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]},LongPrototype.toBytesBE=function(){var t=this.high,e=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,e>>>24,e>>>16&255,e>>>8&255,255&e]},Long.fromBytes=function(t,e,n){return n?Long.fromBytesLE(t,e):Long.fromBytesBE(t,e)},Long.fromBytesLE=function(t,e){return new Long(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,e)},Long.fromBytesBE=function(t,e){return new Long(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],e)},long_default=Long}}),flatbuffers,init_flatbuffers=__esm({"web/node_modules/flatbuffers/js/flatbuffers.mjs"(){flatbuffers={},flatbuffers.Table,flatbuffers.SIZEOF_SHORT=2,flatbuffers.SIZEOF_INT=4,flatbuffers.FILE_IDENTIFIER_LENGTH=4,flatbuffers.SIZE_PREFIX_LENGTH=4,flatbuffers.Encoding={UTF8_BYTES:1,UTF16_STRING:2},flatbuffers.int32=new Int32Array(2),flatbuffers.float32=new Float32Array(flatbuffers.int32.buffer),flatbuffers.float64=new Float64Array(flatbuffers.int32.buffer),flatbuffers.isLittleEndian=1===new Uint16Array(new Uint8Array([1,0]).buffer)[0],flatbuffers.Long=function(t,e){this.low=0|t,this.high=0|e},flatbuffers.Long.create=function(t,e){return 0==t&&0==e?flatbuffers.Long.ZERO:new flatbuffers.Long(t,e)},flatbuffers.Long.prototype.toFloat64=function(){return(this.low>>>0)+4294967296*this.high},flatbuffers.Long.prototype.equals=function(t){return this.low==t.low&&this.high==t.high},flatbuffers.Long.ZERO=new flatbuffers.Long(0,0),flatbuffers.Builder=function(t){if(t)e=t;else var e=1024;this.bb=flatbuffers.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},flatbuffers.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},flatbuffers.Builder.prototype.forceDefaults=function(t){this.force_defaults=t},flatbuffers.Builder.prototype.dataBuffer=function(){return this.bb},flatbuffers.Builder.prototype.asUint8Array=function(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())},flatbuffers.Builder.prototype.prep=function(t,e){t>this.minalign&&(this.minalign=t);for(var n=1+~(this.bb.capacity()-this.space+e)&t-1;this.space<n+t+e;){var r=this.bb.capacity();this.bb=flatbuffers.Builder.growByteBuffer(this.bb),this.space+=this.bb.capacity()-r}this.pad(n)},flatbuffers.Builder.prototype.pad=function(t){for(var e=0;e<t;e++)this.bb.writeInt8(--this.space,0)},flatbuffers.Builder.prototype.writeInt8=function(t){this.bb.writeInt8(this.space-=1,t)},flatbuffers.Builder.prototype.writeInt16=function(t){this.bb.writeInt16(this.space-=2,t)},flatbuffers.Builder.prototype.writeInt32=function(t){this.bb.writeInt32(this.space-=4,t)},flatbuffers.Builder.prototype.writeInt64=function(t){this.bb.writeInt64(this.space-=8,t)},flatbuffers.Builder.prototype.writeFloat32=function(t){this.bb.writeFloat32(this.space-=4,t)},flatbuffers.Builder.prototype.writeFloat64=function(t){this.bb.writeFloat64(this.space-=8,t)},flatbuffers.Builder.prototype.addInt8=function(t){this.prep(1,0),this.writeInt8(t)},flatbuffers.Builder.prototype.addInt16=function(t){this.prep(2,0),this.writeInt16(t)},flatbuffers.Builder.prototype.addInt32=function(t){this.prep(4,0),this.writeInt32(t)},flatbuffers.Builder.prototype.addInt64=function(t){this.prep(8,0),this.writeInt64(t)},flatbuffers.Builder.prototype.addFloat32=function(t){this.prep(4,0),this.writeFloat32(t)},flatbuffers.Builder.prototype.addFloat64=function(t){this.prep(8,0),this.writeFloat64(t)},flatbuffers.Builder.prototype.addFieldInt8=function(t,e,n){(this.force_defaults||e!=n)&&(this.addInt8(e),this.slot(t))},flatbuffers.Builder.prototype.addFieldInt16=function(t,e,n){(this.force_defaults||e!=n)&&(this.addInt16(e),this.slot(t))},flatbuffers.Builder.prototype.addFieldInt32=function(t,e,n){(this.force_defaults||e!=n)&&(this.addInt32(e),this.slot(t))},flatbuffers.Builder.prototype.addFieldInt64=function(t,e,n){!this.force_defaults&&e.equals(n)||(this.addInt64(e),this.slot(t))},flatbuffers.Builder.prototype.addFieldFloat32=function(t,e,n){(this.force_defaults||e!=n)&&(this.addFloat32(e),this.slot(t))},flatbuffers.Builder.prototype.addFieldFloat64=function(t,e,n){(this.force_defaults||e!=n)&&(this.addFloat64(e),this.slot(t))},flatbuffers.Builder.prototype.addFieldOffset=function(t,e,n){(this.force_defaults||e!=n)&&(this.addOffset(e),this.slot(t))},flatbuffers.Builder.prototype.addFieldStruct=function(t,e,n){e!=n&&(this.nested(e),this.slot(t))},flatbuffers.Builder.prototype.nested=function(t){if(t!=this.offset())throw new Error("FlatBuffers: struct must be serialized inline.")},flatbuffers.Builder.prototype.notNested=function(){if(this.isNested)throw new Error("FlatBuffers: object serialization must not be nested.")},flatbuffers.Builder.prototype.slot=function(t){this.vtable[t]=this.offset()},flatbuffers.Builder.prototype.offset=function(){return this.bb.capacity()-this.space},flatbuffers.Builder.growByteBuffer=function(t){var e=t.capacity();if(3221225472&e)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");var n=e<<1,r=flatbuffers.ByteBuffer.allocate(n);return r.setPosition(n-e),r.bytes().set(t.bytes(),n-e),r},flatbuffers.Builder.prototype.addOffset=function(t){this.prep(flatbuffers.SIZEOF_INT,0),this.writeInt32(this.offset()-t+flatbuffers.SIZEOF_INT)},flatbuffers.Builder.prototype.startObject=function(t){this.notNested(),null==this.vtable&&(this.vtable=[]),this.vtable_in_use=t;for(var e=0;e<t;e++)this.vtable[e]=0;this.isNested=!0,this.object_start=this.offset()},flatbuffers.Builder.prototype.endObject=function(){if(null==thi