function _mergeNamespaces(s,e){for(var t=0;tr[o]})}}}return Object.freeze(Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const c of o)if(c.type==="childList")for(const l of c.addedNodes)l.tagName==="LINK"&&l.rel==="modulepreload"&&r(l)}).observe(document,{childList:!0,subtree:!0});function t(o){const c={};return o.integrity&&(c.integrity=o.integrity),o.referrerPolicy&&(c.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?c.credentials="include":o.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function r(o){if(o.ep)return;o.ep=!0;const c=t(o);fetch(o.href,c)}})();/** * @license * Copyright 2010-2023 Three.js Authors * SPDX-License-Identifier: MIT */const REVISION="160",MOUSE={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},TOUCH={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},CullFaceNone=0,CullFaceBack=1,CullFaceFront=2,PCFShadowMap=1,PCFSoftShadowMap=2,VSMShadowMap=3,FrontSide=0,BackSide=1,DoubleSide=2,NoBlending=0,NormalBlending=1,AdditiveBlending=2,SubtractiveBlending=3,MultiplyBlending=4,CustomBlending=5,AddEquation=100,SubtractEquation=101,ReverseSubtractEquation=102,MinEquation=103,MaxEquation=104,ZeroFactor=200,OneFactor=201,SrcColorFactor=202,OneMinusSrcColorFactor=203,SrcAlphaFactor=204,OneMinusSrcAlphaFactor=205,DstAlphaFactor=206,OneMinusDstAlphaFactor=207,DstColorFactor=208,OneMinusDstColorFactor=209,SrcAlphaSaturateFactor=210,ConstantColorFactor=211,OneMinusConstantColorFactor=212,ConstantAlphaFactor=213,OneMinusConstantAlphaFactor=214,NeverDepth=0,AlwaysDepth=1,LessDepth=2,LessEqualDepth=3,EqualDepth=4,GreaterEqualDepth=5,GreaterDepth=6,NotEqualDepth=7,MultiplyOperation=0,MixOperation=1,AddOperation=2,NoToneMapping=0,LinearToneMapping=1,ReinhardToneMapping=2,CineonToneMapping=3,ACESFilmicToneMapping=4,CustomToneMapping=5,AgXToneMapping=6,UVMapping=300,CubeReflectionMapping=301,CubeRefractionMapping=302,EquirectangularReflectionMapping=303,EquirectangularRefractionMapping=304,CubeUVReflectionMapping=306,RepeatWrapping=1e3,ClampToEdgeWrapping=1001,MirroredRepeatWrapping=1002,NearestFilter=1003,NearestMipmapNearestFilter=1004,NearestMipmapLinearFilter=1005,LinearFilter=1006,LinearMipmapNearestFilter=1007,LinearMipmapLinearFilter=1008,UnsignedByteType=1009,ByteType=1010,ShortType=1011,UnsignedShortType=1012,IntType=1013,UnsignedIntType=1014,FloatType=1015,HalfFloatType=1016,UnsignedShort4444Type=1017,UnsignedShort5551Type=1018,UnsignedInt248Type=1020,AlphaFormat=1021,RGBAFormat=1023,LuminanceFormat=1024,LuminanceAlphaFormat=1025,DepthFormat=1026,DepthStencilFormat=1027,RedFormat=1028,RedIntegerFormat=1029,RGFormat=1030,RGIntegerFormat=1031,RGBAIntegerFormat=1033,RGB_S3TC_DXT1_Format=33776,RGBA_S3TC_DXT1_Format=33777,RGBA_S3TC_DXT3_Format=33778,RGBA_S3TC_DXT5_Format=33779,RGB_PVRTC_4BPPV1_Format=35840,RGB_PVRTC_2BPPV1_Format=35841,RGBA_PVRTC_4BPPV1_Format=35842,RGBA_PVRTC_2BPPV1_Format=35843,RGB_ETC1_Format=36196,RGB_ETC2_Format=37492,RGBA_ETC2_EAC_Format=37496,RGBA_ASTC_4x4_Format=37808,RGBA_ASTC_5x4_Format=37809,RGBA_ASTC_5x5_Format=37810,RGBA_ASTC_6x5_Format=37811,RGBA_ASTC_6x6_Format=37812,RGBA_ASTC_8x5_Format=37813,RGBA_ASTC_8x6_Format=37814,RGBA_ASTC_8x8_Format=37815,RGBA_ASTC_10x5_Format=37816,RGBA_ASTC_10x6_Format=37817,RGBA_ASTC_10x8_Format=37818,RGBA_ASTC_10x10_Format=37819,RGBA_ASTC_12x10_Format=37820,RGBA_ASTC_12x12_Format=37821,RGBA_BPTC_Format=36492,RGB_BPTC_SIGNED_Format=36494,RGB_BPTC_UNSIGNED_Format=36495,RED_RGTC1_Format=36283,SIGNED_RED_RGTC1_Format=36284,RED_GREEN_RGTC2_Format=36285,SIGNED_RED_GREEN_RGTC2_Format=36286,LinearEncoding=3e3,sRGBEncoding=3001,BasicDepthPacking=3200,RGBADepthPacking=3201,TangentSpaceNormalMap=0,ObjectSpaceNormalMap=1,NoColorSpace="",SRGBColorSpace="srgb",LinearSRGBColorSpace="srgb-linear",DisplayP3ColorSpace="display-p3",LinearDisplayP3ColorSpace="display-p3-linear",LinearTransfer="linear",SRGBTransfer="srgb",Rec709Primaries="rec709",P3Primaries="p3",KeepStencilOp=7680,AlwaysStencilFunc=519,NeverCompare=512,LessCompare=513,EqualCompare=514,LessEqualCompare=515,GreaterCompare=516,NotEqualCompare=517,GreaterEqualCompare=518,AlwaysCompare=519,StaticDrawUsage=35044,GLSL3="300 es",_SRGBAFormat=1035,WebGLCoordinateSystem=2e3,WebGPUCoordinateSystem=2001;class EventDispatcher{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const r=this._listeners;r[e]===void 0&&(r[e]=[]),r[e].indexOf(t)===-1&&r[e].push(t)}hasEventListener(e,t){if(this._listeners===void 0)return!1;const r=this._listeners;return r[e]!==void 0&&r[e].indexOf(t)!==-1}removeEventListener(e,t){if(this._listeners===void 0)return;const o=this._listeners[e];if(o!==void 0){const c=o.indexOf(t);c!==-1&&o.splice(c,1)}}dispatchEvent(e){if(this._listeners===void 0)return;const r=this._listeners[e.type];if(r!==void 0){e.target=this;const o=r.slice(0);for(let c=0,l=o.length;c>8&255]+_lut[s>>16&255]+_lut[s>>24&255]+"-"+_lut[e&255]+_lut[e>>8&255]+"-"+_lut[e>>16&15|64]+_lut[e>>24&255]+"-"+_lut[t&63|128]+_lut[t>>8&255]+"-"+_lut[t>>16&255]+_lut[t>>24&255]+_lut[r&255]+_lut[r>>8&255]+_lut[r>>16&255]+_lut[r>>24&255]).toLowerCase()}function clamp(s,e,t){return Math.max(e,Math.min(t,s))}function euclideanModulo(s,e){return(s%e+e)%e}function mapLinear(s,e,t,r,o){return r+(s-e)*(o-r)/(t-e)}function inverseLerp(s,e,t){return s!==e?(t-s)/(e-s):0}function lerp(s,e,t){return(1-t)*s+t*e}function damp(s,e,t,r){return lerp(s,e,1-Math.exp(-t*r))}function pingpong(s,e=1){return e-Math.abs(euclideanModulo(s,e*2)-e)}function smoothstep(s,e,t){return s<=e?0:s>=t?1:(s=(s-e)/(t-e),s*s*(3-2*s))}function smootherstep(s,e,t){return s<=e?0:s>=t?1:(s=(s-e)/(t-e),s*s*s*(s*(s*6-15)+10))}function randInt(s,e){return s+Math.floor(Math.random()*(e-s+1))}function randFloat(s,e){return s+Math.random()*(e-s)}function randFloatSpread(s){return s*(.5-Math.random())}function seededRandom(s){s!==void 0&&(_seed=s);let e=_seed+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function degToRad(s){return s*DEG2RAD}function radToDeg(s){return s*RAD2DEG}function isPowerOfTwo$1(s){return(s&s-1)===0&&s!==0}function ceilPowerOfTwo(s){return Math.pow(2,Math.ceil(Math.log(s)/Math.LN2))}function floorPowerOfTwo(s){return Math.pow(2,Math.floor(Math.log(s)/Math.LN2))}function setQuaternionFromProperEuler(s,e,t,r,o){const c=Math.cos,l=Math.sin,h=c(t/2),p=l(t/2),f=c((e+r)/2),d=l((e+r)/2),i=c((e-r)/2),n=l((e-r)/2),a=c((r-e)/2),u=l((r-e)/2);switch(o){case"XYX":s.set(h*d,p*i,p*n,h*f);break;case"YZY":s.set(p*n,h*d,p*i,h*f);break;case"ZXZ":s.set(p*i,p*n,h*d,h*f);break;case"XZX":s.set(h*d,p*u,p*a,h*f);break;case"YXY":s.set(p*a,h*d,p*u,h*f);break;case"ZYZ":s.set(p*u,p*a,h*d,h*f);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+o)}}function denormalize(s,e){switch(e.constructor){case Float32Array:return s;case Uint32Array:return s/4294967295;case Uint16Array:return s/65535;case Uint8Array:return s/255;case Int32Array:return Math.max(s/2147483647,-1);case Int16Array:return Math.max(s/32767,-1);case Int8Array:return Math.max(s/127,-1);default:throw new Error("Invalid component type.")}}function normalize(s,e){switch(e.constructor){case Float32Array:return s;case Uint32Array:return Math.round(s*4294967295);case Uint16Array:return Math.round(s*65535);case Uint8Array:return Math.round(s*255);case Int32Array:return Math.round(s*2147483647);case Int16Array:return Math.round(s*32767);case Int8Array:return Math.round(s*127);default:throw new Error("Invalid component type.")}}const MathUtils={DEG2RAD,RAD2DEG,generateUUID,clamp,euclideanModulo,mapLinear,inverseLerp,lerp,damp,pingpong,smoothstep,smootherstep,randInt,randFloat,randFloatSpread,seededRandom,degToRad,radToDeg,isPowerOfTwo:isPowerOfTwo$1,ceilPowerOfTwo,floorPowerOfTwo,setQuaternionFromProperEuler,normalize,denormalize};class Vector2{constructor(e=0,t=0){Vector2.prototype.isVector2=!0,this.x=e,this.y=t}get width(){return this.x}set width(e){this.x=e}get height(){return this.y}set height(e){this.y=e}set(e,t){return this.x=e,this.y=t,this}setScalar(e){return this.x=e,this.y=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,r=this.y,o=e.elements;return this.x=o[0]*t+o[3]*r+o[6],this.y=o[1]*t+o[4]*r+o[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const r=this.dot(e)/t;return Math.acos(clamp(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,r=this.y-e.y;return t*t+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this}rotateAround(e,t){const r=Math.cos(t),o=Math.sin(t),c=this.x-e.x,l=this.y-e.y;return this.x=c*r-l*o+e.x,this.y=c*o+l*r+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class Matrix3{constructor(e,t,r,o,c,l,h,p,f){Matrix3.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,r,o,c,l,h,p,f)}set(e,t,r,o,c,l,h,p,f){const d=this.elements;return d[0]=e,d[1]=o,d[2]=h,d[3]=t,d[4]=c,d[5]=p,d[6]=r,d[7]=l,d[8]=f,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,r=e.elements;return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],this}extractBasis(e,t,r){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),r.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const r=e.elements,o=t.elements,c=this.elements,l=r[0],h=r[3],p=r[6],f=r[1],d=r[4],i=r[7],n=r[2],a=r[5],u=r[8],m=o[0],g=o[3],_=o[6],b=o[1],y=o[4],v=o[7],x=o[2],w=o[5],S=o[8];return c[0]=l*m+h*b+p*x,c[3]=l*g+h*y+p*w,c[6]=l*_+h*v+p*S,c[1]=f*m+d*b+i*x,c[4]=f*g+d*y+i*w,c[7]=f*_+d*v+i*S,c[2]=n*m+a*b+u*x,c[5]=n*g+a*y+u*w,c[8]=n*_+a*v+u*S,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],r=e[1],o=e[2],c=e[3],l=e[4],h=e[5],p=e[6],f=e[7],d=e[8];return t*l*d-t*h*f-r*c*d+r*h*p+o*c*f-o*l*p}invert(){const e=this.elements,t=e[0],r=e[1],o=e[2],c=e[3],l=e[4],h=e[5],p=e[6],f=e[7],d=e[8],i=d*l-h*f,n=h*p-d*c,a=f*c-l*p,u=t*i+r*n+o*a;if(u===0)return this.set(0,0,0,0,0,0,0,0,0);const m=1/u;return e[0]=i*m,e[1]=(o*f-d*r)*m,e[2]=(h*r-o*l)*m,e[3]=n*m,e[4]=(d*t-o*p)*m,e[5]=(o*c-h*t)*m,e[6]=a*m,e[7]=(r*p-f*t)*m,e[8]=(l*t-r*c)*m,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,r,o,c,l,h){const p=Math.cos(c),f=Math.sin(c);return this.set(r*p,r*f,-r*(p*l+f*h)+l+e,-o*f,o*p,-o*(-f*l+p*h)+h+t,0,0,1),this}scale(e,t){return this.premultiply(_m3.makeScale(e,t)),this}rotate(e){return this.premultiply(_m3.makeRotation(-e)),this}translate(e,t){return this.premultiply(_m3.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,-r,0,r,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,r=e.elements;for(let o=0;o<9;o++)if(t[o]!==r[o])return!1;return!0}fromArray(e,t=0){for(let r=0;r<9;r++)this.elements[r]=e[r+t];return this}toArray(e=[],t=0){const r=this.elements;return e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3],e[t+4]=r[4],e[t+5]=r[5],e[t+6]=r[6],e[t+7]=r[7],e[t+8]=r[8],e}clone(){return new this.constructor().fromArray(this.elements)}}const _m3=new Matrix3;function arrayNeedsUint32(s){for(let e=s.length-1;e>=0;--e)if(s[e]>=65535)return!0;return!1}function createElementNS(s){return document.createElementNS("http://www.w3.org/1999/xhtml",s)}function createCanvasElement(){const s=createElementNS("canvas");return s.style.display="block",s}const _cache={};function warnOnce(s){s in _cache||(_cache[s]=!0,console.warn(s))}const LINEAR_SRGB_TO_LINEAR_DISPLAY_P3=new Matrix3().set(.8224621,.177538,0,.0331941,.9668058,0,.0170827,.0723974,.9105199),LINEAR_DISPLAY_P3_TO_LINEAR_SRGB=new Matrix3().set(1.2249401,-.2249404,0,-.0420569,1.0420571,0,-.0196376,-.0786361,1.0982735),COLOR_SPACES={[LinearSRGBColorSpace]:{transfer:LinearTransfer,primaries:Rec709Primaries,toReference:s=>s,fromReference:s=>s},[SRGBColorSpace]:{transfer:SRGBTransfer,primaries:Rec709Primaries,toReference:s=>s.convertSRGBToLinear(),fromReference:s=>s.convertLinearToSRGB()},[LinearDisplayP3ColorSpace]:{transfer:LinearTransfer,primaries:P3Primaries,toReference:s=>s.applyMatrix3(LINEAR_DISPLAY_P3_TO_LINEAR_SRGB),fromReference:s=>s.applyMatrix3(LINEAR_SRGB_TO_LINEAR_DISPLAY_P3)},[DisplayP3ColorSpace]:{transfer:SRGBTransfer,primaries:P3Primaries,toReference:s=>s.convertSRGBToLinear().applyMatrix3(LINEAR_DISPLAY_P3_TO_LINEAR_SRGB),fromReference:s=>s.applyMatrix3(LINEAR_SRGB_TO_LINEAR_DISPLAY_P3).convertLinearToSRGB()}},SUPPORTED_WORKING_COLOR_SPACES=new Set([LinearSRGBColorSpace,LinearDisplayP3ColorSpace]),ColorManagement={enabled:!0,_workingColorSpace:LinearSRGBColorSpace,get workingColorSpace(){return this._workingColorSpace},set workingColorSpace(s){if(!SUPPORTED_WORKING_COLOR_SPACES.has(s))throw new Error(`Unsupported working color space, "${s}".`);this._workingColorSpace=s},convert:function(s,e,t){if(this.enabled===!1||e===t||!e||!t)return s;const r=COLOR_SPACES[e].toReference,o=COLOR_SPACES[t].fromReference;return o(r(s))},fromWorkingColorSpace:function(s,e){return this.convert(s,this._workingColorSpace,e)},toWorkingColorSpace:function(s,e){return this.convert(s,e,this._workingColorSpace)},getPrimaries:function(s){return COLOR_SPACES[s].primaries},getTransfer:function(s){return s===NoColorSpace?LinearTransfer:COLOR_SPACES[s].transfer}};function SRGBToLinear(s){return s<.04045?s*.0773993808:Math.pow(s*.9478672986+.0521327014,2.4)}function LinearToSRGB(s){return s<.0031308?s*12.92:1.055*Math.pow(s,.41666)-.055}let _canvas;class ImageUtils{static getDataURL(e){if(/^data:/i.test(e.src)||typeof HTMLCanvasElement>"u")return e.src;let t;if(e instanceof HTMLCanvasElement)t=e;else{_canvas===void 0&&(_canvas=createElementNS("canvas")),_canvas.width=e.width,_canvas.height=e.height;const r=_canvas.getContext("2d");e instanceof ImageData?r.putImageData(e,0,0):r.drawImage(e,0,0,e.width,e.height),t=_canvas}return t.width>2048||t.height>2048?(console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons",e),t.toDataURL("image/jpeg",.6)):t.toDataURL("image/png")}static sRGBToLinear(e){if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap){const t=createElementNS("canvas");t.width=e.width,t.height=e.height;const r=t.getContext("2d");r.drawImage(e,0,0,e.width,e.height);const o=r.getImageData(0,0,e.width,e.height),c=o.data;for(let l=0;l0&&(r.userData=this.userData),t||(e.textures[this.uuid]=r),r}dispose(){this.dispatchEvent({type:"dispose"})}transformUv(e){if(this.mapping!==UVMapping)return e;if(e.applyMatrix3(this.matrix),e.x<0||e.x>1)switch(this.wrapS){case RepeatWrapping:e.x=e.x-Math.floor(e.x);break;case ClampToEdgeWrapping:e.x=e.x<0?0:1;break;case MirroredRepeatWrapping:Math.abs(Math.floor(e.x)%2)===1?e.x=Math.ceil(e.x)-e.x:e.x=e.x-Math.floor(e.x);break}if(e.y<0||e.y>1)switch(this.wrapT){case RepeatWrapping:e.y=e.y-Math.floor(e.y);break;case ClampToEdgeWrapping:e.y=e.y<0?0:1;break;case MirroredRepeatWrapping:Math.abs(Math.floor(e.y)%2)===1?e.y=Math.ceil(e.y)-e.y:e.y=e.y-Math.floor(e.y);break}return this.flipY&&(e.y=1-e.y),e}set needsUpdate(e){e===!0&&(this.version++,this.source.needsUpdate=!0)}get encoding(){return warnOnce("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace===SRGBColorSpace?sRGBEncoding:LinearEncoding}set encoding(e){warnOnce("THREE.Texture: Property .encoding has been replaced by .colorSpace."),this.colorSpace=e===sRGBEncoding?SRGBColorSpace:NoColorSpace}}Texture.DEFAULT_IMAGE=null;Texture.DEFAULT_MAPPING=UVMapping;Texture.DEFAULT_ANISOTROPY=1;class Vector4{constructor(e=0,t=0,r=0,o=1){Vector4.prototype.isVector4=!0,this.x=e,this.y=t,this.z=r,this.w=o}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,r,o){return this.x=e,this.y=t,this.z=r,this.w=o,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w!==void 0?e.w:1,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,r=this.y,o=this.z,c=this.w,l=e.elements;return this.x=l[0]*t+l[4]*r+l[8]*o+l[12]*c,this.y=l[1]*t+l[5]*r+l[9]*o+l[13]*c,this.z=l[2]*t+l[6]*r+l[10]*o+l[14]*c,this.w=l[3]*t+l[7]*r+l[11]*o+l[15]*c,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,r,o,c;const p=e.elements,f=p[0],d=p[4],i=p[8],n=p[1],a=p[5],u=p[9],m=p[2],g=p[6],_=p[10];if(Math.abs(d-n)<.01&&Math.abs(i-m)<.01&&Math.abs(u-g)<.01){if(Math.abs(d+n)<.1&&Math.abs(i+m)<.1&&Math.abs(u+g)<.1&&Math.abs(f+a+_-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const y=(f+1)/2,v=(a+1)/2,x=(_+1)/2,w=(d+n)/4,S=(i+m)/4,M=(u+g)/4;return y>v&&y>x?y<.01?(r=0,o=.707106781,c=.707106781):(r=Math.sqrt(y),o=w/r,c=S/r):v>x?v<.01?(r=.707106781,o=0,c=.707106781):(o=Math.sqrt(v),r=w/o,c=M/o):x<.01?(r=.707106781,o=.707106781,c=0):(c=Math.sqrt(x),r=S/c,o=M/c),this.set(r,o,c,t),this}let b=Math.sqrt((g-u)*(g-u)+(i-m)*(i-m)+(n-d)*(n-d));return Math.abs(b)<.001&&(b=1),this.x=(g-u)/b,this.y=(i-m)/b,this.z=(n-d)/b,this.w=Math.acos((f+a+_-1)/2),this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this.w=e.w+(t.w-e.w)*r,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this.w=e.getW(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class RenderTarget extends EventDispatcher{constructor(e=1,t=1,r={}){super(),this.isRenderTarget=!0,this.width=e,this.height=t,this.depth=1,this.scissor=new Vector4(0,0,e,t),this.scissorTest=!1,this.viewport=new Vector4(0,0,e,t);const o={width:e,height:t,depth:1};r.encoding!==void 0&&(warnOnce("THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace."),r.colorSpace=r.encoding===sRGBEncoding?SRGBColorSpace:NoColorSpace),r=Object.assign({generateMipmaps:!1,internalFormat:null,minFilter:LinearFilter,depthBuffer:!0,stencilBuffer:!1,depthTexture:null,samples:0},r),this.texture=new Texture(o,r.mapping,r.wrapS,r.wrapT,r.magFilter,r.minFilter,r.format,r.type,r.anisotropy,r.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.flipY=!1,this.texture.generateMipmaps=r.generateMipmaps,this.texture.internalFormat=r.internalFormat,this.depthBuffer=r.depthBuffer,this.stencilBuffer=r.stencilBuffer,this.depthTexture=r.depthTexture,this.samples=r.samples}setSize(e,t,r=1){(this.width!==e||this.height!==t||this.depth!==r)&&(this.width=e,this.height=t,this.depth=r,this.texture.image.width=e,this.texture.image.height=t,this.texture.image.depth=r,this.dispose()),this.viewport.set(0,0,e,t),this.scissor.set(0,0,e,t)}clone(){return new this.constructor().copy(this)}copy(e){this.width=e.width,this.height=e.height,this.depth=e.depth,this.scissor.copy(e.scissor),this.scissorTest=e.scissorTest,this.viewport.copy(e.viewport),this.texture=e.texture.clone(),this.texture.isRenderTargetTexture=!0;const t=Object.assign({},e.texture.image);return this.texture.source=new Source(t),this.depthBuffer=e.depthBuffer,this.stencilBuffer=e.stencilBuffer,e.depthTexture!==null&&(this.depthTexture=e.depthTexture.clone()),this.samples=e.samples,this}dispose(){this.dispatchEvent({type:"dispose"})}}class WebGLRenderTarget extends RenderTarget{constructor(e=1,t=1,r={}){super(e,t,r),this.isWebGLRenderTarget=!0}}class DataArrayTexture extends Texture{constructor(e=null,t=1,r=1,o=1){super(null),this.isDataArrayTexture=!0,this.image={data:e,width:t,height:r,depth:o},this.magFilter=NearestFilter,this.minFilter=NearestFilter,this.wrapR=ClampToEdgeWrapping,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Data3DTexture extends Texture{constructor(e=null,t=1,r=1,o=1){super(null),this.isData3DTexture=!0,this.image={data:e,width:t,height:r,depth:o},this.magFilter=NearestFilter,this.minFilter=NearestFilter,this.wrapR=ClampToEdgeWrapping,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1}}class Quaternion{constructor(e=0,t=0,r=0,o=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=r,this._w=o}static slerpFlat(e,t,r,o,c,l,h){let p=r[o+0],f=r[o+1],d=r[o+2],i=r[o+3];const n=c[l+0],a=c[l+1],u=c[l+2],m=c[l+3];if(h===0){e[t+0]=p,e[t+1]=f,e[t+2]=d,e[t+3]=i;return}if(h===1){e[t+0]=n,e[t+1]=a,e[t+2]=u,e[t+3]=m;return}if(i!==m||p!==n||f!==a||d!==u){let g=1-h;const _=p*n+f*a+d*u+i*m,b=_>=0?1:-1,y=1-_*_;if(y>Number.EPSILON){const x=Math.sqrt(y),w=Math.atan2(x,_*b);g=Math.sin(g*w)/x,h=Math.sin(h*w)/x}const v=h*b;if(p=p*g+n*v,f=f*g+a*v,d=d*g+u*v,i=i*g+m*v,g===1-h){const x=1/Math.sqrt(p*p+f*f+d*d+i*i);p*=x,f*=x,d*=x,i*=x}}e[t]=p,e[t+1]=f,e[t+2]=d,e[t+3]=i}static multiplyQuaternionsFlat(e,t,r,o,c,l){const h=r[o],p=r[o+1],f=r[o+2],d=r[o+3],i=c[l],n=c[l+1],a=c[l+2],u=c[l+3];return e[t]=h*u+d*i+p*a-f*n,e[t+1]=p*u+d*n+f*i-h*a,e[t+2]=f*u+d*a+h*n-p*i,e[t+3]=d*u-h*i-p*n-f*a,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,r,o){return this._x=e,this._y=t,this._z=r,this._w=o,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const r=e._x,o=e._y,c=e._z,l=e._order,h=Math.cos,p=Math.sin,f=h(r/2),d=h(o/2),i=h(c/2),n=p(r/2),a=p(o/2),u=p(c/2);switch(l){case"XYZ":this._x=n*d*i+f*a*u,this._y=f*a*i-n*d*u,this._z=f*d*u+n*a*i,this._w=f*d*i-n*a*u;break;case"YXZ":this._x=n*d*i+f*a*u,this._y=f*a*i-n*d*u,this._z=f*d*u-n*a*i,this._w=f*d*i+n*a*u;break;case"ZXY":this._x=n*d*i-f*a*u,this._y=f*a*i+n*d*u,this._z=f*d*u+n*a*i,this._w=f*d*i-n*a*u;break;case"ZYX":this._x=n*d*i-f*a*u,this._y=f*a*i+n*d*u,this._z=f*d*u-n*a*i,this._w=f*d*i+n*a*u;break;case"YZX":this._x=n*d*i+f*a*u,this._y=f*a*i+n*d*u,this._z=f*d*u-n*a*i,this._w=f*d*i-n*a*u;break;case"XZY":this._x=n*d*i-f*a*u,this._y=f*a*i-n*d*u,this._z=f*d*u+n*a*i,this._w=f*d*i+n*a*u;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+l)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const r=t/2,o=Math.sin(r);return this._x=e.x*o,this._y=e.y*o,this._z=e.z*o,this._w=Math.cos(r),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,r=t[0],o=t[4],c=t[8],l=t[1],h=t[5],p=t[9],f=t[2],d=t[6],i=t[10],n=r+h+i;if(n>0){const a=.5/Math.sqrt(n+1);this._w=.25/a,this._x=(d-p)*a,this._y=(c-f)*a,this._z=(l-o)*a}else if(r>h&&r>i){const a=2*Math.sqrt(1+r-h-i);this._w=(d-p)/a,this._x=.25*a,this._y=(o+l)/a,this._z=(c+f)/a}else if(h>i){const a=2*Math.sqrt(1+h-r-i);this._w=(c-f)/a,this._x=(o+l)/a,this._y=.25*a,this._z=(p+d)/a}else{const a=2*Math.sqrt(1+i-r-h);this._w=(l-o)/a,this._x=(c+f)/a,this._y=(p+d)/a,this._z=.25*a}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let r=e.dot(t)+1;return rMath.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=r):(this._x=0,this._y=-e.z,this._z=e.y,this._w=r)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=r),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(clamp(this.dot(e),-1,1)))}rotateTowards(e,t){const r=this.angleTo(e);if(r===0)return this;const o=Math.min(1,t/r);return this.slerp(e,o),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const r=e._x,o=e._y,c=e._z,l=e._w,h=t._x,p=t._y,f=t._z,d=t._w;return this._x=r*d+l*h+o*f-c*p,this._y=o*d+l*p+c*h-r*f,this._z=c*d+l*f+r*p-o*h,this._w=l*d-r*h-o*p-c*f,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const r=this._x,o=this._y,c=this._z,l=this._w;let h=l*e._w+r*e._x+o*e._y+c*e._z;if(h<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,h=-h):this.copy(e),h>=1)return this._w=l,this._x=r,this._y=o,this._z=c,this;const p=1-h*h;if(p<=Number.EPSILON){const a=1-t;return this._w=a*l+t*this._w,this._x=a*r+t*this._x,this._y=a*o+t*this._y,this._z=a*c+t*this._z,this.normalize(),this}const f=Math.sqrt(p),d=Math.atan2(f,h),i=Math.sin((1-t)*d)/f,n=Math.sin(t*d)/f;return this._w=l*i+this._w*n,this._x=r*i+this._x*n,this._y=o*i+this._y*n,this._z=c*i+this._z*n,this._onChangeCallback(),this}slerpQuaternions(e,t,r){return this.copy(e).slerp(t,r)}random(){const e=Math.random(),t=Math.sqrt(1-e),r=Math.sqrt(e),o=2*Math.PI*Math.random(),c=2*Math.PI*Math.random();return this.set(t*Math.cos(o),r*Math.sin(c),r*Math.cos(c),t*Math.sin(o))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}fromBufferAttribute(e,t){return this._x=e.getX(t),this._y=e.getY(t),this._z=e.getZ(t),this._w=e.getW(t),this._onChangeCallback(),this}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class Vector3{constructor(e=0,t=0,r=0){Vector3.prototype.isVector3=!0,this.x=e,this.y=t,this.z=r}set(e,t,r){return r===void 0&&(r=this.z),this.x=e,this.y=t,this.z=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(_quaternion$4.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(_quaternion$4.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,r=this.y,o=this.z,c=e.elements;return this.x=c[0]*t+c[3]*r+c[6]*o,this.y=c[1]*t+c[4]*r+c[7]*o,this.z=c[2]*t+c[5]*r+c[8]*o,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,r=this.y,o=this.z,c=e.elements,l=1/(c[3]*t+c[7]*r+c[11]*o+c[15]);return this.x=(c[0]*t+c[4]*r+c[8]*o+c[12])*l,this.y=(c[1]*t+c[5]*r+c[9]*o+c[13])*l,this.z=(c[2]*t+c[6]*r+c[10]*o+c[14])*l,this}applyQuaternion(e){const t=this.x,r=this.y,o=this.z,c=e.x,l=e.y,h=e.z,p=e.w,f=2*(l*o-h*r),d=2*(h*t-c*o),i=2*(c*r-l*t);return this.x=t+p*f+l*i-h*d,this.y=r+p*d+h*f-c*i,this.z=o+p*i+c*d-l*f,this}project(e){return this.applyMatrix4(e.matrixWorldInverse).applyMatrix4(e.projectionMatrix)}unproject(e){return this.applyMatrix4(e.projectionMatrixInverse).applyMatrix4(e.matrixWorld)}transformDirection(e){const t=this.x,r=this.y,o=this.z,c=e.elements;return this.x=c[0]*t+c[4]*r+c[8]*o,this.y=c[1]*t+c[5]*r+c[9]*o,this.z=c[2]*t+c[6]*r+c[10]*o,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const r=e.x,o=e.y,c=e.z,l=t.x,h=t.y,p=t.z;return this.x=o*p-c*h,this.y=c*l-r*p,this.z=r*h-o*l,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const r=e.dot(this)/t;return this.copy(e).multiplyScalar(r)}projectOnPlane(e){return _vector$c.copy(this).projectOnVector(e),this.sub(_vector$c)}reflect(e){return this.sub(_vector$c.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const r=this.dot(e)/t;return Math.acos(clamp(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,r=this.y-e.y,o=this.z-e.z;return t*t+r*r+o*o}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSpherical(e){return this.setFromSphericalCoords(e.radius,e.phi,e.theta)}setFromSphericalCoords(e,t,r){const o=Math.sin(t)*e;return this.x=o*Math.sin(r),this.y=Math.cos(t)*e,this.z=o*Math.cos(r),this}setFromCylindrical(e){return this.setFromCylindricalCoords(e.radius,e.theta,e.y)}setFromCylindricalCoords(e,t,r){return this.x=e*Math.sin(t),this.y=r,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),r=this.setFromMatrixColumn(e,1).length(),o=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=r,this.z=o,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}setFromColor(e){return this.x=e.r,this.y=e.g,this.z=e.b,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}fromBufferAttribute(e,t){return this.x=e.getX(t),this.y=e.getY(t),this.z=e.getZ(t),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=(Math.random()-.5)*2,t=Math.random()*Math.PI*2,r=Math.sqrt(1-e**2);return this.x=r*Math.cos(t),this.y=r*Math.sin(t),this.z=e,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const _vector$c=new Vector3,_quaternion$4=new Quaternion;class Box3{constructor(e=new Vector3(1/0,1/0,1/0),t=new Vector3(-1/0,-1/0,-1/0)){this.isBox3=!0,this.min=e,this.max=t}set(e,t){return this.min.copy(e),this.max.copy(t),this}setFromArray(e){this.makeEmpty();for(let t=0,r=e.length;tthis.max.x||e.ythis.max.y||e.zthis.max.z)}containsBox(e){return this.min.x<=e.min.x&&e.max.x<=this.max.x&&this.min.y<=e.min.y&&e.max.y<=this.max.y&&this.min.z<=e.min.z&&e.max.z<=this.max.z}getParameter(e,t){return t.set((e.x-this.min.x)/(this.max.x-this.min.x),(e.y-this.min.y)/(this.max.y-this.min.y),(e.z-this.min.z)/(this.max.z-this.min.z))}intersectsBox(e){return!(e.max.xthis.max.x||e.max.ythis.max.y||e.max.zthis.max.z)}intersectsSphere(e){return this.clampPoint(e.center,_vector$b),_vector$b.distanceToSquared(e.center)<=e.radius*e.radius}intersectsPlane(e){let t,r;return e.normal.x>0?(t=e.normal.x*this.min.x,r=e.normal.x*this.max.x):(t=e.normal.x*this.max.x,r=e.normal.x*this.min.x),e.normal.y>0?(t+=e.normal.y*this.min.y,r+=e.normal.y*this.max.y):(t+=e.normal.y*this.max.y,r+=e.normal.y*this.min.y),e.normal.z>0?(t+=e.normal.z*this.min.z,r+=e.normal.z*this.max.z):(t+=e.normal.z*this.max.z,r+=e.normal.z*this.min.z),t<=-e.constant&&r>=-e.constant}intersectsTriangle(e){if(this.isEmpty())return!1;this.getCenter(_center),_extents.subVectors(this.max,_center),_v0$2.subVectors(e.a,_center),_v1$7.subVectors(e.b,_center),_v2$4.subVectors(e.c,_center),_f0.subVectors(_v1$7,_v0$2),_f1.subVectors(_v2$4,_v1$7),_f2.subVectors(_v0$2,_v2$4);let t=[0,-_f0.z,_f0.y,0,-_f1.z,_f1.y,0,-_f2.z,_f2.y,_f0.z,0,-_f0.x,_f1.z,0,-_f1.x,_f2.z,0,-_f2.x,-_f0.y,_f0.x,0,-_f1.y,_f1.x,0,-_f2.y,_f2.x,0];return!satForAxes(t,_v0$2,_v1$7,_v2$4,_extents)||(t=[1,0,0,0,1,0,0,0,1],!satForAxes(t,_v0$2,_v1$7,_v2$4,_extents))?!1:(_triangleNormal.crossVectors(_f0,_f1),t=[_triangleNormal.x,_triangleNormal.y,_triangleNormal.z],satForAxes(t,_v0$2,_v1$7,_v2$4,_extents))}clampPoint(e,t){return t.copy(e).clamp(this.min,this.max)}distanceToPoint(e){return this.clampPoint(e,_vector$b).distanceTo(e)}getBoundingSphere(e){return this.isEmpty()?e.makeEmpty():(this.getCenter(e.center),e.radius=this.getSize(_vector$b).length()*.5),e}intersect(e){return this.min.max(e.min),this.max.min(e.max),this.isEmpty()&&this.makeEmpty(),this}union(e){return this.min.min(e.min),this.max.max(e.max),this}applyMatrix4(e){return this.isEmpty()?this:(_points[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(e),_points[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(e),_points[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(e),_points[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(e),_points[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(e),_points[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(e),_points[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(e),_points[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(e),this.setFromPoints(_points),this)}translate(e){return this.min.add(e),this.max.add(e),this}equals(e){return e.min.equals(this.min)&&e.max.equals(this.max)}}const _points=[new Vector3,new Vector3,new Vector3,new Vector3,new Vector3,new Vector3,new Vector3,new Vector3],_vector$b=new Vector3,_box$4=new Box3,_v0$2=new Vector3,_v1$7=new Vector3,_v2$4=new Vector3,_f0=new Vector3,_f1=new Vector3,_f2=new Vector3,_center=new Vector3,_extents=new Vector3,_triangleNormal=new Vector3,_testAxis=new Vector3;function satForAxes(s,e,t,r,o){for(let c=0,l=s.length-3;c<=l;c+=3){_testAxis.fromArray(s,c);const h=o.x*Math.abs(_testAxis.x)+o.y*Math.abs(_testAxis.y)+o.z*Math.abs(_testAxis.z),p=e.dot(_testAxis),f=t.dot(_testAxis),d=r.dot(_testAxis);if(Math.max(-Math.max(p,f,d),Math.min(p,f,d))>h)return!1}return!0}const _box$3=new Box3,_v1$6=new Vector3,_v2$3=new Vector3;class Sphere{constructor(e=new Vector3,t=-1){this.isSphere=!0,this.center=e,this.radius=t}set(e,t){return this.center.copy(e),this.radius=t,this}setFromPoints(e,t){const r=this.center;t!==void 0?r.copy(t):_box$3.setFromPoints(e).getCenter(r);let o=0;for(let c=0,l=e.length;cthis.radius*this.radius&&(t.sub(this.center).normalize(),t.multiplyScalar(this.radius).add(this.center)),t}getBoundingBox(e){return this.isEmpty()?(e.makeEmpty(),e):(e.set(this.center,this.center),e.expandByScalar(this.radius),e)}applyMatrix4(e){return this.center.applyMatrix4(e),this.radius=this.radius*e.getMaxScaleOnAxis(),this}translate(e){return this.center.add(e),this}expandByPoint(e){if(this.isEmpty())return this.center.copy(e),this.radius=0,this;_v1$6.subVectors(e,this.center);const t=_v1$6.lengthSq();if(t>this.radius*this.radius){const r=Math.sqrt(t),o=(r-this.radius)*.5;this.center.addScaledVector(_v1$6,o/r),this.radius+=o}return this}union(e){return e.isEmpty()?this:this.isEmpty()?(this.copy(e),this):(this.center.equals(e.center)===!0?this.radius=Math.max(this.radius,e.radius):(_v2$3.subVectors(e.center,this.center).setLength(e.radius),this.expandByPoint(_v1$6.copy(e.center).add(_v2$3)),this.expandByPoint(_v1$6.copy(e.center).sub(_v2$3))),this)}equals(e){return e.center.equals(this.center)&&e.radius===this.radius}clone(){return new this.constructor().copy(this)}}const _vector$a=new Vector3,_segCenter=new Vector3,_segDir=new Vector3,_diff=new Vector3,_edge1=new Vector3,_edge2=new Vector3,_normal$1=new Vector3;class Ray{constructor(e=new Vector3,t=new Vector3(0,0,-1)){this.origin=e,this.direction=t}set(e,t){return this.origin.copy(e),this.direction.copy(t),this}copy(e){return this.origin.copy(e.origin),this.direction.copy(e.direction),this}at(e,t){return t.copy(this.origin).addScaledVector(this.direction,e)}lookAt(e){return this.direction.copy(e).sub(this.origin).normalize(),this}recast(e){return this.origin.copy(this.at(e,_vector$a)),this}closestPointToPoint(e,t){t.subVectors(e,this.origin);const r=t.dot(this.direction);return r<0?t.copy(this.origin):t.copy(this.origin).addScaledVector(this.direction,r)}distanceToPoint(e){return Math.sqrt(this.distanceSqToPoint(e))}distanceSqToPoint(e){const t=_vector$a.subVectors(e,this.origin).dot(this.direction);return t<0?this.origin.distanceToSquared(e):(_vector$a.copy(this.origin).addScaledVector(this.direction,t),_vector$a.distanceToSquared(e))}distanceSqToSegment(e,t,r,o){_segCenter.copy(e).add(t).multiplyScalar(.5),_segDir.copy(t).sub(e).normalize(),_diff.copy(this.origin).sub(_segCenter);const c=e.distanceTo(t)*.5,l=-this.direction.dot(_segDir),h=_diff.dot(this.direction),p=-_diff.dot(_segDir),f=_diff.lengthSq(),d=Math.abs(1-l*l);let i,n,a,u;if(d>0)if(i=l*p-h,n=l*h-p,u=c*d,i>=0)if(n>=-u)if(n<=u){const m=1/d;i*=m,n*=m,a=i*(i+l*n+2*h)+n*(l*i+n+2*p)+f}else n=c,i=Math.max(0,-(l*n+h)),a=-i*i+n*(n+2*p)+f;else n=-c,i=Math.max(0,-(l*n+h)),a=-i*i+n*(n+2*p)+f;else n<=-u?(i=Math.max(0,-(-l*c+h)),n=i>0?-c:Math.min(Math.max(-c,-p),c),a=-i*i+n*(n+2*p)+f):n<=u?(i=0,n=Math.min(Math.max(-c,-p),c),a=n*(n+2*p)+f):(i=Math.max(0,-(l*c+h)),n=i>0?c:Math.min(Math.max(-c,-p),c),a=-i*i+n*(n+2*p)+f);else n=l>0?-c:c,i=Math.max(0,-(l*n+h)),a=-i*i+n*(n+2*p)+f;return r&&r.copy(this.origin).addScaledVector(this.direction,i),o&&o.copy(_segCenter).addScaledVector(_segDir,n),a}intersectSphere(e,t){_vector$a.subVectors(e.center,this.origin);const r=_vector$a.dot(this.direction),o=_vector$a.dot(_vector$a)-r*r,c=e.radius*e.radius;if(o>c)return null;const l=Math.sqrt(c-o),h=r-l,p=r+l;return p<0?null:h<0?this.at(p,t):this.at(h,t)}intersectsSphere(e){return this.distanceSqToPoint(e.center)<=e.radius*e.radius}distanceToPlane(e){const t=e.normal.dot(this.direction);if(t===0)return e.distanceToPoint(this.origin)===0?0:null;const r=-(this.origin.dot(e.normal)+e.constant)/t;return r>=0?r:null}intersectPlane(e,t){const r=this.distanceToPlane(e);return r===null?null:this.at(r,t)}intersectsPlane(e){const t=e.distanceToPoint(this.origin);return t===0||e.normal.dot(this.direction)*t<0}intersectBox(e,t){let r,o,c,l,h,p;const f=1/this.direction.x,d=1/this.direction.y,i=1/this.direction.z,n=this.origin;return f>=0?(r=(e.min.x-n.x)*f,o=(e.max.x-n.x)*f):(r=(e.max.x-n.x)*f,o=(e.min.x-n.x)*f),d>=0?(c=(e.min.y-n.y)*d,l=(e.max.y-n.y)*d):(c=(e.max.y-n.y)*d,l=(e.min.y-n.y)*d),r>l||c>o||((c>r||isNaN(r))&&(r=c),(l=0?(h=(e.min.z-n.z)*i,p=(e.max.z-n.z)*i):(h=(e.max.z-n.z)*i,p=(e.min.z-n.z)*i),r>p||h>o)||((h>r||r!==r)&&(r=h),(p=0?r:o,t)}intersectsBox(e){return this.intersectBox(e,_vector$a)!==null}intersectTriangle(e,t,r,o,c){_edge1.subVectors(t,e),_edge2.subVectors(r,e),_normal$1.crossVectors(_edge1,_edge2);let l=this.direction.dot(_normal$1),h;if(l>0){if(o)return null;h=1}else if(l<0)h=-1,l=-l;else return null;_diff.subVectors(this.origin,e);const p=h*this.direction.dot(_edge2.crossVectors(_diff,_edge2));if(p<0)return null;const f=h*this.direction.dot(_edge1.cross(_diff));if(f<0||p+f>l)return null;const d=-h*_diff.dot(_normal$1);return d<0?null:this.at(d/l,c)}applyMatrix4(e){return this.origin.applyMatrix4(e),this.direction.transformDirection(e),this}equals(e){return e.origin.equals(this.origin)&&e.direction.equals(this.direction)}clone(){return new this.constructor().copy(this)}}class Matrix4{constructor(e,t,r,o,c,l,h,p,f,d,i,n,a,u,m,g){Matrix4.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,r,o,c,l,h,p,f,d,i,n,a,u,m,g)}set(e,t,r,o,c,l,h,p,f,d,i,n,a,u,m,g){const _=this.elements;return _[0]=e,_[4]=t,_[8]=r,_[12]=o,_[1]=c,_[5]=l,_[9]=h,_[13]=p,_[2]=f,_[6]=d,_[10]=i,_[14]=n,_[3]=a,_[7]=u,_[11]=m,_[15]=g,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new Matrix4().fromArray(this.elements)}copy(e){const t=this.elements,r=e.elements;return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],t[9]=r[9],t[10]=r[10],t[11]=r[11],t[12]=r[12],t[13]=r[13],t[14]=r[14],t[15]=r[15],this}copyPosition(e){const t=this.elements,r=e.elements;return t[12]=r[12],t[13]=r[13],t[14]=r[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,r){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),r.setFromMatrixColumn(this,2),this}makeBasis(e,t,r){return this.set(e.x,t.x,r.x,0,e.y,t.y,r.y,0,e.z,t.z,r.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,r=e.elements,o=1/_v1$5.setFromMatrixColumn(e,0).length(),c=1/_v1$5.setFromMatrixColumn(e,1).length(),l=1/_v1$5.setFromMatrixColumn(e,2).length();return t[0]=r[0]*o,t[1]=r[1]*o,t[2]=r[2]*o,t[3]=0,t[4]=r[4]*c,t[5]=r[5]*c,t[6]=r[6]*c,t[7]=0,t[8]=r[8]*l,t[9]=r[9]*l,t[10]=r[10]*l,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,r=e.x,o=e.y,c=e.z,l=Math.cos(r),h=Math.sin(r),p=Math.cos(o),f=Math.sin(o),d=Math.cos(c),i=Math.sin(c);if(e.order==="XYZ"){const n=l*d,a=l*i,u=h*d,m=h*i;t[0]=p*d,t[4]=-p*i,t[8]=f,t[1]=a+u*f,t[5]=n-m*f,t[9]=-h*p,t[2]=m-n*f,t[6]=u+a*f,t[10]=l*p}else if(e.order==="YXZ"){const n=p*d,a=p*i,u=f*d,m=f*i;t[0]=n+m*h,t[4]=u*h-a,t[8]=l*f,t[1]=l*i,t[5]=l*d,t[9]=-h,t[2]=a*h-u,t[6]=m+n*h,t[10]=l*p}else if(e.order==="ZXY"){const n=p*d,a=p*i,u=f*d,m=f*i;t[0]=n-m*h,t[4]=-l*i,t[8]=u+a*h,t[1]=a+u*h,t[5]=l*d,t[9]=m-n*h,t[2]=-l*f,t[6]=h,t[10]=l*p}else if(e.order==="ZYX"){const n=l*d,a=l*i,u=h*d,m=h*i;t[0]=p*d,t[4]=u*f-a,t[8]=n*f+m,t[1]=p*i,t[5]=m*f+n,t[9]=a*f-u,t[2]=-f,t[6]=h*p,t[10]=l*p}else if(e.order==="YZX"){const n=l*p,a=l*f,u=h*p,m=h*f;t[0]=p*d,t[4]=m-n*i,t[8]=u*i+a,t[1]=i,t[5]=l*d,t[9]=-h*d,t[2]=-f*d,t[6]=a*i+u,t[10]=n-m*i}else if(e.order==="XZY"){const n=l*p,a=l*f,u=h*p,m=h*f;t[0]=p*d,t[4]=-i,t[8]=f*d,t[1]=n*i+m,t[5]=l*d,t[9]=a*i-u,t[2]=u*i-a,t[6]=h*d,t[10]=m*i+n}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(_zero,e,_one)}lookAt(e,t,r){const o=this.elements;return _z.subVectors(e,t),_z.lengthSq()===0&&(_z.z=1),_z.normalize(),_x.crossVectors(r,_z),_x.lengthSq()===0&&(Math.abs(r.z)===1?_z.x+=1e-4:_z.z+=1e-4,_z.normalize(),_x.crossVectors(r,_z)),_x.normalize(),_y.crossVectors(_z,_x),o[0]=_x.x,o[4]=_y.x,o[8]=_z.x,o[1]=_x.y,o[5]=_y.y,o[9]=_z.y,o[2]=_x.z,o[6]=_y.z,o[10]=_z.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const r=e.elements,o=t.elements,c=this.elements,l=r[0],h=r[4],p=r[8],f=r[12],d=r[1],i=r[5],n=r[9],a=r[13],u=r[2],m=r[6],g=r[10],_=r[14],b=r[3],y=r[7],v=r[11],x=r[15],w=o[0],S=o[4],M=o[8],T=o[12],E=o[1],R=o[5],I=o[9],k=o[13],C=o[2],z=o[6],O=o[10],U=o[14],K=o[3],$=o[7],J=o[11],ee=o[15];return c[0]=l*w+h*E+p*C+f*K,c[4]=l*S+h*R+p*z+f*$,c[8]=l*M+h*I+p*O+f*J,c[12]=l*T+h*k+p*U+f*ee,c[1]=d*w+i*E+n*C+a*K,c[5]=d*S+i*R+n*z+a*$,c[9]=d*M+i*I+n*O+a*J,c[13]=d*T+i*k+n*U+a*ee,c[2]=u*w+m*E+g*C+_*K,c[6]=u*S+m*R+g*z+_*$,c[10]=u*M+m*I+g*O+_*J,c[14]=u*T+m*k+g*U+_*ee,c[3]=b*w+y*E+v*C+x*K,c[7]=b*S+y*R+v*z+x*$,c[11]=b*M+y*I+v*O+x*J,c[15]=b*T+y*k+v*U+x*ee,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],r=e[4],o=e[8],c=e[12],l=e[1],h=e[5],p=e[9],f=e[13],d=e[2],i=e[6],n=e[10],a=e[14],u=e[3],m=e[7],g=e[11],_=e[15];return u*(+c*p*i-o*f*i-c*h*n+r*f*n+o*h*a-r*p*a)+m*(+t*p*a-t*f*n+c*l*n-o*l*a+o*f*d-c*p*d)+g*(+t*f*i-t*h*a-c*l*i+r*l*a+c*h*d-r*f*d)+_*(-o*h*d-t*p*i+t*h*n+o*l*i-r*l*n+r*p*d)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,r){const o=this.elements;return e.isVector3?(o[12]=e.x,o[13]=e.y,o[14]=e.z):(o[12]=e,o[13]=t,o[14]=r),this}invert(){const e=this.elements,t=e[0],r=e[1],o=e[2],c=e[3],l=e[4],h=e[5],p=e[6],f=e[7],d=e[8],i=e[9],n=e[10],a=e[11],u=e[12],m=e[13],g=e[14],_=e[15],b=i*g*f-m*n*f+m*p*a-h*g*a-i*p*_+h*n*_,y=u*n*f-d*g*f-u*p*a+l*g*a+d*p*_-l*n*_,v=d*m*f-u*i*f+u*h*a-l*m*a-d*h*_+l*i*_,x=u*i*p-d*m*p-u*h*n+l*m*n+d*h*g-l*i*g,w=t*b+r*y+o*v+c*x;if(w===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const S=1/w;return e[0]=b*S,e[1]=(m*n*c-i*g*c-m*o*a+r*g*a+i*o*_-r*n*_)*S,e[2]=(h*g*c-m*p*c+m*o*f-r*g*f-h*o*_+r*p*_)*S,e[3]=(i*p*c-h*n*c-i*o*f+r*n*f+h*o*a-r*p*a)*S,e[4]=y*S,e[5]=(d*g*c-u*n*c+u*o*a-t*g*a-d*o*_+t*n*_)*S,e[6]=(u*p*c-l*g*c-u*o*f+t*g*f+l*o*_-t*p*_)*S,e[7]=(l*n*c-d*p*c+d*o*f-t*n*f-l*o*a+t*p*a)*S,e[8]=v*S,e[9]=(u*i*c-d*m*c-u*r*a+t*m*a+d*r*_-t*i*_)*S,e[10]=(l*m*c-u*h*c+u*r*f-t*m*f-l*r*_+t*h*_)*S,e[11]=(d*h*c-l*i*c-d*r*f+t*i*f+l*r*a-t*h*a)*S,e[12]=x*S,e[13]=(d*m*o-u*i*o+u*r*n-t*m*n-d*r*g+t*i*g)*S,e[14]=(u*h*o-l*m*o-u*r*p+t*m*p+l*r*g-t*h*g)*S,e[15]=(l*i*o-d*h*o+d*r*p-t*i*p-l*r*n+t*h*n)*S,this}scale(e){const t=this.elements,r=e.x,o=e.y,c=e.z;return t[0]*=r,t[4]*=o,t[8]*=c,t[1]*=r,t[5]*=o,t[9]*=c,t[2]*=r,t[6]*=o,t[10]*=c,t[3]*=r,t[7]*=o,t[11]*=c,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],r=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],o=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,r,o))}makeTranslation(e,t,r){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,r,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),r=Math.sin(e);return this.set(1,0,0,0,0,t,-r,0,0,r,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,0,r,0,0,1,0,0,-r,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,-r,0,0,r,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const r=Math.cos(t),o=Math.sin(t),c=1-r,l=e.x,h=e.y,p=e.z,f=c*l,d=c*h;return this.set(f*l+r,f*h-o*p,f*p+o*h,0,f*h+o*p,d*h+r,d*p-o*l,0,f*p-o*h,d*p+o*l,c*p*p+r,0,0,0,0,1),this}makeScale(e,t,r){return this.set(e,0,0,0,0,t,0,0,0,0,r,0,0,0,0,1),this}makeShear(e,t,r,o,c,l){return this.set(1,r,c,0,e,1,l,0,t,o,1,0,0,0,0,1),this}compose(e,t,r){const o=this.elements,c=t._x,l=t._y,h=t._z,p=t._w,f=c+c,d=l+l,i=h+h,n=c*f,a=c*d,u=c*i,m=l*d,g=l*i,_=h*i,b=p*f,y=p*d,v=p*i,x=r.x,w=r.y,S=r.z;return o[0]=(1-(m+_))*x,o[1]=(a+v)*x,o[2]=(u-y)*x,o[3]=0,o[4]=(a-v)*w,o[5]=(1-(n+_))*w,o[6]=(g+b)*w,o[7]=0,o[8]=(u+y)*S,o[9]=(g-b)*S,o[10]=(1-(n+m))*S,o[11]=0,o[12]=e.x,o[13]=e.y,o[14]=e.z,o[15]=1,this}decompose(e,t,r){const o=this.elements;let c=_v1$5.set(o[0],o[1],o[2]).length();const l=_v1$5.set(o[4],o[5],o[6]).length(),h=_v1$5.set(o[8],o[9],o[10]).length();this.determinant()<0&&(c=-c),e.x=o[12],e.y=o[13],e.z=o[14],_m1$2.copy(this);const f=1/c,d=1/l,i=1/h;return _m1$2.elements[0]*=f,_m1$2.elements[1]*=f,_m1$2.elements[2]*=f,_m1$2.elements[4]*=d,_m1$2.elements[5]*=d,_m1$2.elements[6]*=d,_m1$2.elements[8]*=i,_m1$2.elements[9]*=i,_m1$2.elements[10]*=i,t.setFromRotationMatrix(_m1$2),r.x=c,r.y=l,r.z=h,this}makePerspective(e,t,r,o,c,l,h=WebGLCoordinateSystem){const p=this.elements,f=2*c/(t-e),d=2*c/(r-o),i=(t+e)/(t-e),n=(r+o)/(r-o);let a,u;if(h===WebGLCoordinateSystem)a=-(l+c)/(l-c),u=-2*l*c/(l-c);else if(h===WebGPUCoordinateSystem)a=-l/(l-c),u=-l*c/(l-c);else throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: "+h);return p[0]=f,p[4]=0,p[8]=i,p[12]=0,p[1]=0,p[5]=d,p[9]=n,p[13]=0,p[2]=0,p[6]=0,p[10]=a,p[14]=u,p[3]=0,p[7]=0,p[11]=-1,p[15]=0,this}makeOrthographic(e,t,r,o,c,l,h=WebGLCoordinateSystem){const p=this.elements,f=1/(t-e),d=1/(r-o),i=1/(l-c),n=(t+e)*f,a=(r+o)*d;let u,m;if(h===WebGLCoordinateSystem)u=(l+c)*i,m=-2*i;else if(h===WebGPUCoordinateSystem)u=c*i,m=-1*i;else throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: "+h);return p[0]=2*f,p[4]=0,p[8]=0,p[12]=-n,p[1]=0,p[5]=2*d,p[9]=0,p[13]=-a,p[2]=0,p[6]=0,p[10]=m,p[14]=-u,p[3]=0,p[7]=0,p[11]=0,p[15]=1,this}equals(e){const t=this.elements,r=e.elements;for(let o=0;o<16;o++)if(t[o]!==r[o])return!1;return!0}fromArray(e,t=0){for(let r=0;r<16;r++)this.elements[r]=e[r+t];return this}toArray(e=[],t=0){const r=this.elements;return e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3],e[t+4]=r[4],e[t+5]=r[5],e[t+6]=r[6],e[t+7]=r[7],e[t+8]=r[8],e[t+9]=r[9],e[t+10]=r[10],e[t+11]=r[11],e[t+12]=r[12],e[t+13]=r[13],e[t+14]=r[14],e[t+15]=r[15],e}}const _v1$5=new Vector3,_m1$2=new Matrix4,_zero=new Vector3(0,0,0),_one=new Vector3(1,1,1),_x=new Vector3,_y=new Vector3,_z=new Vector3,_matrix$1=new Matrix4,_quaternion$3=new Quaternion;class Euler{constructor(e=0,t=0,r=0,o=Euler.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=r,this._order=o}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,r,o=this._order){return this._x=e,this._y=t,this._z=r,this._order=o,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,r=!0){const o=e.elements,c=o[0],l=o[4],h=o[8],p=o[1],f=o[5],d=o[9],i=o[2],n=o[6],a=o[10];switch(t){case"XYZ":this._y=Math.asin(clamp(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(-d,a),this._z=Math.atan2(-l,c)):(this._x=Math.atan2(n,f),this._z=0);break;case"YXZ":this._x=Math.asin(-clamp(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(h,a),this._z=Math.atan2(p,f)):(this._y=Math.atan2(-i,c),this._z=0);break;case"ZXY":this._x=Math.asin(clamp(n,-1,1)),Math.abs(n)<.9999999?(this._y=Math.atan2(-i,a),this._z=Math.atan2(-l,f)):(this._y=0,this._z=Math.atan2(p,c));break;case"ZYX":this._y=Math.asin(-clamp(i,-1,1)),Math.abs(i)<.9999999?(this._x=Math.atan2(n,a),this._z=Math.atan2(p,c)):(this._x=0,this._z=Math.atan2(-l,f));break;case"YZX":this._z=Math.asin(clamp(p,-1,1)),Math.abs(p)<.9999999?(this._x=Math.atan2(-d,f),this._y=Math.atan2(-i,c)):(this._x=0,this._y=Math.atan2(h,a));break;case"XZY":this._z=Math.asin(-clamp(l,-1,1)),Math.abs(l)<.9999999?(this._x=Math.atan2(n,f),this._y=Math.atan2(h,c)):(this._x=Math.atan2(-d,a),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,r===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,r){return _matrix$1.makeRotationFromQuaternion(e),this.setFromRotationMatrix(_matrix$1,t,r)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return _quaternion$3.setFromEuler(this),this.setFromQuaternion(_quaternion$3,e)}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._order===this._order}fromArray(e){return this._x=e[0],this._y=e[1],this._z=e[2],e[3]!==void 0&&(this._order=e[3]),this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._order,e}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Euler.DEFAULT_ORDER="XYZ";class Layers{constructor(){this.mask=1}set(e){this.mask=(1<>>0}enable(e){this.mask|=1<1){for(let t=0;t1){for(let r=0;r0&&(o.userData=this.userData),o.layers=this.layers.mask,o.matrix=this.matrix.toArray(),o.up=this.up.toArray(),this.matrixAutoUpdate===!1&&(o.matrixAutoUpdate=!1),this.isInstancedMesh&&(o.type="InstancedMesh",o.count=this.count,o.instanceMatrix=this.instanceMatrix.toJSON(),this.instanceColor!==null&&(o.instanceColor=this.instanceColor.toJSON())),this.isBatchedMesh&&(o.type="BatchedMesh",o.perObjectFrustumCulled=this.perObjectFrustumCulled,o.sortObjects=this.sortObjects,o.drawRanges=this._drawRanges,o.reservedRanges=this._reservedRanges,o.visibility=this._visibility,o.active=this._active,o.bounds=this._bounds.map(h=>({boxInitialized:h.boxInitialized,boxMin:h.box.min.toArray(),boxMax:h.box.max.toArray(),sphereInitialized:h.sphereInitialized,sphereRadius:h.sphere.radius,sphereCenter:h.sphere.center.toArray()})),o.maxGeometryCount=this._maxGeometryCount,o.maxVertexCount=this._maxVertexCount,o.maxIndexCount=this._maxIndexCount,o.geometryInitialized=this._geometryInitialized,o.geometryCount=this._geometryCount,o.matricesTexture=this._matricesTexture.toJSON(e),this.boundingSphere!==null&&(o.boundingSphere={center:o.boundingSphere.center.toArray(),radius:o.boundingSphere.radius}),this.boundingBox!==null&&(o.boundingBox={min:o.boundingBox.min.toArray(),max:o.boundingBox.max.toArray()}));function c(h,p){return h[p.uuid]===void 0&&(h[p.uuid]=p.toJSON(e)),p.uuid}if(this.isScene)this.background&&(this.background.isColor?o.background=this.background.toJSON():this.background.isTexture&&(o.background=this.background.toJSON(e).uuid)),this.environment&&this.environment.isTexture&&this.environment.isRenderTargetTexture!==!0&&(o.environment=this.environment.toJSON(e).uuid);else if(this.isMesh||this.isLine||this.isPoints){o.geometry=c(e.geometries,this.geometry);const h=this.geometry.parameters;if(h!==void 0&&h.shapes!==void 0){const p=h.shapes;if(Array.isArray(p))for(let f=0,d=p.length;f0){o.children=[];for(let h=0;h0){o.animations=[];for(let h=0;h0&&(r.geometries=h),p.length>0&&(r.materials=p),f.length>0&&(r.textures=f),d.length>0&&(r.images=d),i.length>0&&(r.shapes=i),n.length>0&&(r.skeletons=n),a.length>0&&(r.animations=a),u.length>0&&(r.nodes=u)}return r.object=o,r;function l(h){const p=[];for(const f in h){const d=h[f];delete d.metadata,p.push(d)}return p}}clone(e){return new this.constructor().copy(this,e)}copy(e,t=!0){if(this.name=e.name,this.up.copy(e.up),this.position.copy(e.position),this.rotation.order=e.rotation.order,this.quaternion.copy(e.quaternion),this.scale.copy(e.scale),this.matrix.copy(e.matrix),this.matrixWorld.copy(e.matrixWorld),this.matrixAutoUpdate=e.matrixAutoUpdate,this.matrixWorldAutoUpdate=e.matrixWorldAutoUpdate,this.matrixWorldNeedsUpdate=e.matrixWorldNeedsUpdate,this.layers.mask=e.layers.mask,this.visible=e.visible,this.castShadow=e.castShadow,this.receiveShadow=e.receiveShadow,this.frustumCulled=e.frustumCulled,this.renderOrder=e.renderOrder,this.animations=e.animations.slice(),this.userData=JSON.parse(JSON.stringify(e.userData)),t===!0)for(let r=0;r0?o.multiplyScalar(1/Math.sqrt(c)):o.set(0,0,0)}static getBarycoord(e,t,r,o,c){_v0$1.subVectors(o,t),_v1$3.subVectors(r,t),_v2$2.subVectors(e,t);const l=_v0$1.dot(_v0$1),h=_v0$1.dot(_v1$3),p=_v0$1.dot(_v2$2),f=_v1$3.dot(_v1$3),d=_v1$3.dot(_v2$2),i=l*f-h*h;if(i===0)return c.set(0,0,0),null;const n=1/i,a=(f*p-h*d)*n,u=(l*d-h*p)*n;return c.set(1-a-u,u,a)}static containsPoint(e,t,r,o){return this.getBarycoord(e,t,r,o,_v3$1)===null?!1:_v3$1.x>=0&&_v3$1.y>=0&&_v3$1.x+_v3$1.y<=1}static getUV(e,t,r,o,c,l,h,p){return warnedGetUV===!1&&(console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."),warnedGetUV=!0),this.getInterpolation(e,t,r,o,c,l,h,p)}static getInterpolation(e,t,r,o,c,l,h,p){return this.getBarycoord(e,t,r,o,_v3$1)===null?(p.x=0,p.y=0,"z"in p&&(p.z=0),"w"in p&&(p.w=0),null):(p.setScalar(0),p.addScaledVector(c,_v3$1.x),p.addScaledVector(l,_v3$1.y),p.addScaledVector(h,_v3$1.z),p)}static isFrontFacing(e,t,r,o){return _v0$1.subVectors(r,t),_v1$3.subVectors(e,t),_v0$1.cross(_v1$3).dot(o)<0}set(e,t,r){return this.a.copy(e),this.b.copy(t),this.c.copy(r),this}setFromPointsAndIndices(e,t,r,o){return this.a.copy(e[t]),this.b.copy(e[r]),this.c.copy(e[o]),this}setFromAttributeAndIndices(e,t,r,o){return this.a.fromBufferAttribute(e,t),this.b.fromBufferAttribute(e,r),this.c.fromBufferAttribute(e,o),this}clone(){return new this.constructor().copy(this)}copy(e){return this.a.copy(e.a),this.b.copy(e.b),this.c.copy(e.c),this}getArea(){return _v0$1.subVectors(this.c,this.b),_v1$3.subVectors(this.a,this.b),_v0$1.cross(_v1$3).length()*.5}getMidpoint(e){return e.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)}getNormal(e){return Triangle.getNormal(this.a,this.b,this.c,e)}getPlane(e){return e.setFromCoplanarPoints(this.a,this.b,this.c)}getBarycoord(e,t){return Triangle.getBarycoord(e,this.a,this.b,this.c,t)}getUV(e,t,r,o,c){return warnedGetUV===!1&&(console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."),warnedGetUV=!0),Triangle.getInterpolation(e,this.a,this.b,this.c,t,r,o,c)}getInterpolation(e,t,r,o,c){return Triangle.getInterpolation(e,this.a,this.b,this.c,t,r,o,c)}containsPoint(e){return Triangle.containsPoint(e,this.a,this.b,this.c)}isFrontFacing(e){return Triangle.isFrontFacing(this.a,this.b,this.c,e)}intersectsBox(e){return e.intersectsTriangle(this)}closestPointToPoint(e,t){const r=this.a,o=this.b,c=this.c;let l,h;_vab.subVectors(o,r),_vac.subVectors(c,r),_vap.subVectors(e,r);const p=_vab.dot(_vap),f=_vac.dot(_vap);if(p<=0&&f<=0)return t.copy(r);_vbp.subVectors(e,o);const d=_vab.dot(_vbp),i=_vac.dot(_vbp);if(d>=0&&i<=d)return t.copy(o);const n=p*i-d*f;if(n<=0&&p>=0&&d<=0)return l=p/(p-d),t.copy(r).addScaledVector(_vab,l);_vcp.subVectors(e,c);const a=_vab.dot(_vcp),u=_vac.dot(_vcp);if(u>=0&&a<=u)return t.copy(c);const m=a*f-p*u;if(m<=0&&f>=0&&u<=0)return h=f/(f-u),t.copy(r).addScaledVector(_vac,h);const g=d*u-a*i;if(g<=0&&i-d>=0&&a-u>=0)return _vbc.subVectors(c,o),h=(i-d)/(i-d+(a-u)),t.copy(o).addScaledVector(_vbc,h);const _=1/(g+m+n);return l=m*_,h=n*_,t.copy(r).addScaledVector(_vab,l).addScaledVector(_vac,h)}equals(e){return e.a.equals(this.a)&&e.b.equals(this.b)&&e.c.equals(this.c)}}const _colorKeywords={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},_hslA={h:0,s:0,l:0},_hslB={h:0,s:0,l:0};function hue2rgb(s,e,t){return t<0&&(t+=1),t>1&&(t-=1),t<1/6?s+(e-s)*6*t:t<1/2?e:t<2/3?s+(e-s)*6*(2/3-t):s}class Color{constructor(e,t,r){return this.isColor=!0,this.r=1,this.g=1,this.b=1,this.set(e,t,r)}set(e,t,r){if(t===void 0&&r===void 0){const o=e;o&&o.isColor?this.copy(o):typeof o=="number"?this.setHex(o):typeof o=="string"&&this.setStyle(o)}else this.setRGB(e,t,r);return this}setScalar(e){return this.r=e,this.g=e,this.b=e,this}setHex(e,t=SRGBColorSpace){return e=Math.floor(e),this.r=(e>>16&255)/255,this.g=(e>>8&255)/255,this.b=(e&255)/255,ColorManagement.toWorkingColorSpace(this,t),this}setRGB(e,t,r,o=ColorManagement.workingColorSpace){return this.r=e,this.g=t,this.b=r,ColorManagement.toWorkingColorSpace(this,o),this}setHSL(e,t,r,o=ColorManagement.workingColorSpace){if(e=euclideanModulo(e,1),t=clamp(t,0,1),r=clamp(r,0,1),t===0)this.r=this.g=this.b=r;else{const c=r<=.5?r*(1+t):r+t-r*t,l=2*r-c;this.r=hue2rgb(l,c,e+1/3),this.g=hue2rgb(l,c,e),this.b=hue2rgb(l,c,e-1/3)}return ColorManagement.toWorkingColorSpace(this,o),this}setStyle(e,t=SRGBColorSpace){function r(c){c!==void 0&&parseFloat(c)<1&&console.warn("THREE.Color: Alpha component of "+e+" will be ignored.")}let o;if(o=/^(\w+)\(([^\)]*)\)/.exec(e)){let c;const l=o[1],h=o[2];switch(l){case"rgb":case"rgba":if(c=/^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(h))return r(c[4]),this.setRGB(Math.min(255,parseInt(c[1],10))/255,Math.min(255,parseInt(c[2],10))/255,Math.min(255,parseInt(c[3],10))/255,t);if(c=/^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(h))return r(c[4]),this.setRGB(Math.min(100,parseInt(c[1],10))/100,Math.min(100,parseInt(c[2],10))/100,Math.min(100,parseInt(c[3],10))/100,t);break;case"hsl":case"hsla":if(c=/^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(h))return r(c[4]),this.setHSL(parseFloat(c[1])/360,parseFloat(c[2])/100,parseFloat(c[3])/100,t);break;default:console.warn("THREE.Color: Unknown color model "+e)}}else if(o=/^\#([A-Fa-f\d]+)$/.exec(e)){const c=o[1],l=c.length;if(l===3)return this.setRGB(parseInt(c.charAt(0),16)/15,parseInt(c.charAt(1),16)/15,parseInt(c.charAt(2),16)/15,t);if(l===6)return this.setHex(parseInt(c,16),t);console.warn("THREE.Color: Invalid hex color "+e)}else if(e&&e.length>0)return this.setColorName(e,t);return this}setColorName(e,t=SRGBColorSpace){const r=_colorKeywords[e.toLowerCase()];return r!==void 0?this.setHex(r,t):console.warn("THREE.Color: Unknown color "+e),this}clone(){return new this.constructor(this.r,this.g,this.b)}copy(e){return this.r=e.r,this.g=e.g,this.b=e.b,this}copySRGBToLinear(e){return this.r=SRGBToLinear(e.r),this.g=SRGBToLinear(e.g),this.b=SRGBToLinear(e.b),this}copyLinearToSRGB(e){return this.r=LinearToSRGB(e.r),this.g=LinearToSRGB(e.g),this.b=LinearToSRGB(e.b),this}convertSRGBToLinear(){return this.copySRGBToLinear(this),this}convertLinearToSRGB(){return this.copyLinearToSRGB(this),this}getHex(e=SRGBColorSpace){return ColorManagement.fromWorkingColorSpace(_color.copy(this),e),Math.round(clamp(_color.r*255,0,255))*65536+Math.round(clamp(_color.g*255,0,255))*256+Math.round(clamp(_color.b*255,0,255))}getHexString(e=SRGBColorSpace){return("000000"+this.getHex(e).toString(16)).slice(-6)}getHSL(e,t=ColorManagement.workingColorSpace){ColorManagement.fromWorkingColorSpace(_color.copy(this),t);const r=_color.r,o=_color.g,c=_color.b,l=Math.max(r,o,c),h=Math.min(r,o,c);let p,f;const d=(h+l)/2;if(h===l)p=0,f=0;else{const i=l-h;switch(f=d<=.5?i/(l+h):i/(2-l-h),l){case r:p=(o-c)/i+(o0!=e>0&&this.version++,this._alphaTest=e}onBuild(){}onBeforeRender(){}onBeforeCompile(){}customProgramCacheKey(){return this.onBeforeCompile.toString()}setValues(e){if(e!==void 0)for(const t in e){const r=e[t];if(r===void 0){console.warn(`THREE.Material: parameter '${t}' has value of undefined.`);continue}const o=this[t];if(o===void 0){console.warn(`THREE.Material: '${t}' is not a property of THREE.${this.type}.`);continue}o&&o.isColor?o.set(r):o&&o.isVector3&&r&&r.isVector3?o.copy(r):this[t]=r}}toJSON(e){const t=e===void 0||typeof e=="string";t&&(e={textures:{},images:{}});const r={metadata:{version:4.6,type:"Material",generator:"Material.toJSON"}};r.uuid=this.uuid,r.type=this.type,this.name!==""&&(r.name=this.name),this.color&&this.color.isColor&&(r.color=this.color.getHex()),this.roughness!==void 0&&(r.roughness=this.roughness),this.metalness!==void 0&&(r.metalness=this.metalness),this.sheen!==void 0&&(r.sheen=this.sheen),this.sheenColor&&this.sheenColor.isColor&&(r.sheenColor=this.sheenColor.getHex()),this.sheenRoughness!==void 0&&(r.sheenRoughness=this.sheenRoughness),this.emissive&&this.emissive.isColor&&(r.emissive=this.emissive.getHex()),this.emissiveIntensity&&this.emissiveIntensity!==1&&(r.emissiveIntensity=this.emissiveIntensity),this.specular&&this.specular.isColor&&(r.specular=this.specular.getHex()),this.specularIntensity!==void 0&&(r.specularIntensity=this.specularIntensity),this.specularColor&&this.specularColor.isColor&&(r.specularColor=this.specularColor.getHex()),this.shininess!==void 0&&(r.shininess=this.shininess),this.clearcoat!==void 0&&(r.clearcoat=this.clearcoat),this.clearcoatRoughness!==void 0&&(r.clearcoatRoughness=this.clearcoatRoughness),this.clearcoatMap&&this.clearcoatMap.isTexture&&(r.clearcoatMap=this.clearcoatMap.toJSON(e).uuid),this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture&&(r.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(e).uuid),this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture&&(r.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(e).uuid,r.clearcoatNormalScale=this.clearcoatNormalScale.toArray()),this.iridescence!==void 0&&(r.iridescence=this.iridescence),this.iridescenceIOR!==void 0&&(r.iridescenceIOR=this.iridescenceIOR),this.iridescenceThicknessRange!==void 0&&(r.iridescenceThicknessRange=this.iridescenceThicknessRange),this.iridescenceMap&&this.iridescenceMap.isTexture&&(r.iridescenceMap=this.iridescenceMap.toJSON(e).uuid),this.iridescenceThicknessMap&&this.iridescenceThicknessMap.isTexture&&(r.iridescenceThicknessMap=this.iridescenceThicknessMap.toJSON(e).uuid),this.anisotropy!==void 0&&(r.anisotropy=this.anisotropy),this.anisotropyRotation!==void 0&&(r.anisotropyRotation=this.anisotropyRotation),this.anisotropyMap&&this.anisotropyMap.isTexture&&(r.anisotropyMap=this.anisotropyMap.toJSON(e).uuid),this.map&&this.map.isTexture&&(r.map=this.map.toJSON(e).uuid),this.matcap&&this.matcap.isTexture&&(r.matcap=this.matcap.toJSON(e).uuid),this.alphaMap&&this.alphaMap.isTexture&&(r.alphaMap=this.alphaMap.toJSON(e).uuid),this.lightMap&&this.lightMap.isTexture&&(r.lightMap=this.lightMap.toJSON(e).uuid,r.lightMapIntensity=this.lightMapIntensity),this.aoMap&&this.aoMap.isTexture&&(r.aoMap=this.aoMap.toJSON(e).uuid,r.aoMapIntensity=this.aoMapIntensity),this.bumpMap&&this.bumpMap.isTexture&&(r.bumpMap=this.bumpMap.toJSON(e).uuid,r.bumpScale=this.bumpScale),this.normalMap&&this.normalMap.isTexture&&(r.normalMap=this.normalMap.toJSON(e).uuid,r.normalMapType=this.normalMapType,r.normalScale=this.normalScale.toArray()),this.displacementMap&&this.displacementMap.isTexture&&(r.displacementMap=this.displacementMap.toJSON(e).uuid,r.displacementScale=this.displacementScale,r.displacementBias=this.displacementBias),this.roughnessMap&&this.roughnessMap.isTexture&&(r.roughnessMap=this.roughnessMap.toJSON(e).uuid),this.metalnessMap&&this.metalnessMap.isTexture&&(r.metalnessMap=this.metalnessMap.toJSON(e).uuid),this.emissiveMap&&this.emissiveMap.isTexture&&(r.emissiveMap=this.emissiveMap.toJSON(e).uuid),this.specularMap&&this.specularMap.isTexture&&(r.specularMap=this.specularMap.toJSON(e).uuid),this.specularIntensityMap&&this.specularIntensityMap.isTexture&&(r.specularIntensityMap=this.specularIntensityMap.toJSON(e).uuid),this.specularColorMap&&this.specularColorMap.isTexture&&(r.specularColorMap=this.specularColorMap.toJSON(e).uuid),this.envMap&&this.envMap.isTexture&&(r.envMap=this.envMap.toJSON(e).uuid,this.combine!==void 0&&(r.combine=this.combine)),this.envMapIntensity!==void 0&&(r.envMapIntensity=this.envMapIntensity),this.reflectivity!==void 0&&(r.reflectivity=this.reflectivity),this.refractionRatio!==void 0&&(r.refractionRatio=this.refractionRatio),this.gradientMap&&this.gradientMap.isTexture&&(r.gradientMap=this.gradientMap.toJSON(e).uuid),this.transmission!==void 0&&(r.transmission=this.transmission),this.transmissionMap&&this.transmissionMap.isTexture&&(r.transmissionMap=this.transmissionMap.toJSON(e).uuid),this.thickness!==void 0&&(r.thickness=this.thickness),this.thicknessMap&&this.thicknessMap.isTexture&&(r.thicknessMap=this.thicknessMap.toJSON(e).uuid),this.attenuationDistance!==void 0&&this.attenuationDistance!==1/0&&(r.attenuationDistance=this.attenuationDistance),this.attenuationColor!==void 0&&(r.attenuationColor=this.attenuationColor.getHex()),this.size!==void 0&&(r.size=this.size),this.shadowSide!==null&&(r.shadowSide=this.shadowSide),this.sizeAttenuation!==void 0&&(r.sizeAttenuation=this.sizeAttenuation),this.blending!==NormalBlending&&(r.blending=this.blending),this.side!==FrontSide&&(r.side=this.side),this.vertexColors===!0&&(r.vertexColors=!0),this.opacity<1&&(r.opacity=this.opacity),this.transparent===!0&&(r.transparent=!0),this.blendSrc!==SrcAlphaFactor&&(r.blendSrc=this.blendSrc),this.blendDst!==OneMinusSrcAlphaFactor&&(r.blendDst=this.blendDst),this.blendEquation!==AddEquation&&(r.blendEquation=this.blendEquation),this.blendSrcAlpha!==null&&(r.blendSrcAlpha=this.blendSrcAlpha),this.blendDstAlpha!==null&&(r.blendDstAlpha=this.blendDstAlpha),this.blendEquationAlpha!==null&&(r.blendEquationAlpha=this.blendEquationAlpha),this.blendColor&&this.blendColor.isColor&&(r.blendColor=this.blendColor.getHex()),this.blendAlpha!==0&&(r.blendAlpha=this.blendAlpha),this.depthFunc!==LessEqualDepth&&(r.depthFunc=this.depthFunc),this.depthTest===!1&&(r.depthTest=this.depthTest),this.depthWrite===!1&&(r.depthWrite=this.depthWrite),this.colorWrite===!1&&(r.colorWrite=this.colorWrite),this.stencilWriteMask!==255&&(r.stencilWriteMask=this.stencilWriteMask),this.stencilFunc!==AlwaysStencilFunc&&(r.stencilFunc=this.stencilFunc),this.stencilRef!==0&&(r.stencilRef=this.stencilRef),this.stencilFuncMask!==255&&(r.stencilFuncMask=this.stencilFuncMask),this.stencilFail!==KeepStencilOp&&(r.stencilFail=this.stencilFail),this.stencilZFail!==KeepStencilOp&&(r.stencilZFail=this.stencilZFail),this.stencilZPass!==KeepStencilOp&&(r.stencilZPass=this.stencilZPass),this.stencilWrite===!0&&(r.stencilWrite=this.stencilWrite),this.rotation!==void 0&&this.rotation!==0&&(r.rotation=this.rotation),this.polygonOffset===!0&&(r.polygonOffset=!0),this.polygonOffsetFactor!==0&&(r.polygonOffsetFactor=this.polygonOffsetFactor),this.polygonOffsetUnits!==0&&(r.polygonOffsetUnits=this.polygonOffsetUnits),this.linewidth!==void 0&&this.linewidth!==1&&(r.linewidth=this.linewidth),this.dashSize!==void 0&&(r.dashSize=this.dashSize),this.gapSize!==void 0&&(r.gapSize=this.gapSize),this.scale!==void 0&&(r.scale=this.scale),this.dithering===!0&&(r.dithering=!0),this.alphaTest>0&&(r.alphaTest=this.alphaTest),this.alphaHash===!0&&(r.alphaHash=!0),this.alphaToCoverage===!0&&(r.alphaToCoverage=!0),this.premultipliedAlpha===!0&&(r.premultipliedAlpha=!0),this.forceSinglePass===!0&&(r.forceSinglePass=!0),this.wireframe===!0&&(r.wireframe=!0),this.wireframeLinewidth>1&&(r.wireframeLinewidth=this.wireframeLinewidth),this.wireframeLinecap!=="round"&&(r.wireframeLinecap=this.wireframeLinecap),this.wireframeLinejoin!=="round"&&(r.wireframeLinejoin=this.wireframeLinejoin),this.flatShading===!0&&(r.flatShading=!0),this.visible===!1&&(r.visible=!1),this.toneMapped===!1&&(r.toneMapped=!1),this.fog===!1&&(r.fog=!1),Object.keys(this.userData).length>0&&(r.userData=this.userData);function o(c){const l=[];for(const h in c){const p=c[h];delete p.metadata,l.push(p)}return l}if(t){const c=o(e.textures),l=o(e.images);c.length>0&&(r.textures=c),l.length>0&&(r.images=l)}return r}clone(){return new this.constructor().copy(this)}copy(e){this.name=e.name,this.blending=e.blending,this.side=e.side,this.vertexColors=e.vertexColors,this.opacity=e.opacity,this.transparent=e.transparent,this.blendSrc=e.blendSrc,this.blendDst=e.blendDst,this.blendEquation=e.blendEquation,this.blendSrcAlpha=e.blendSrcAlpha,this.blendDstAlpha=e.blendDstAlpha,this.blendEquationAlpha=e.blendEquationAlpha,this.blendColor.copy(e.blendColor),this.blendAlpha=e.blendAlpha,this.depthFunc=e.depthFunc,this.depthTest=e.depthTest,this.depthWrite=e.depthWrite,this.stencilWriteMask=e.stencilWriteMask,this.stencilFunc=e.stencilFunc,this.stencilRef=e.stencilRef,this.stencilFuncMask=e.stencilFuncMask,this.stencilFail=e.stencilFail,this.stencilZFail=e.stencilZFail,this.stencilZPass=e.stencilZPass,this.stencilWrite=e.stencilWrite;const t=e.clippingPlanes;let r=null;if(t!==null){const o=t.length;r=new Array(o);for(let c=0;c!==o;++c)r[c]=t[c].clone()}return this.clippingPlanes=r,this.clipIntersection=e.clipIntersection,this.clipShadows=e.clipShadows,this.shadowSide=e.shadowSide,this.colorWrite=e.colorWrite,this.precision=e.precision,this.polygonOffset=e.polygonOffset,this.polygonOffsetFactor=e.polygonOffsetFactor,this.polygonOffsetUnits=e.polygonOffsetUnits,this.dithering=e.dithering,this.alphaTest=e.alphaTest,this.alphaHash=e.alphaHash,this.alphaToCoverage=e.alphaToCoverage,this.premultipliedAlpha=e.premultipliedAlpha,this.forceSinglePass=e.forceSinglePass,this.visible=e.visible,this.toneMapped=e.toneMapped,this.userData=JSON.parse(JSON.stringify(e.userData)),this}dispose(){this.dispatchEvent({type:"dispose"})}set needsUpdate(e){e===!0&&this.version++}}class MeshBasicMaterial extends Material{constructor(e){super(),this.isMeshBasicMaterial=!0,this.type="MeshBasicMaterial",this.color=new Color(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=MultiplyOperation,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.color.copy(e.color),this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.specularMap=e.specularMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.combine=e.combine,this.reflectivity=e.reflectivity,this.refractionRatio=e.refractionRatio,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.fog=e.fog,this}}const _vector$9=new Vector3,_vector2$1=new Vector2;class BufferAttribute{constructor(e,t,r=!1){if(Array.isArray(e))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.isBufferAttribute=!0,this.name="",this.array=e,this.itemSize=t,this.count=e!==void 0?e.length/t:0,this.normalized=r,this.usage=StaticDrawUsage,this._updateRange={offset:0,count:-1},this.updateRanges=[],this.gpuType=FloatType,this.version=0}onUploadCallback(){}set needsUpdate(e){e===!0&&this.version++}get updateRange(){return console.warn("THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead."),this._updateRange}setUsage(e){return this.usage=e,this}addUpdateRange(e,t){this.updateRanges.push({start:e,count:t})}clearUpdateRanges(){this.updateRanges.length=0}copy(e){return this.name=e.name,this.array=new e.array.constructor(e.array),this.itemSize=e.itemSize,this.count=e.count,this.normalized=e.normalized,this.usage=e.usage,this.gpuType=e.gpuType,this}copyAt(e,t,r){e*=this.itemSize,r*=t.itemSize;for(let o=0,c=this.itemSize;o0&&(e.userData=this.userData),this.parameters!==void 0){const p=this.parameters;for(const f in p)p[f]!==void 0&&(e[f]=p[f]);return e}e.data={attributes:{}};const t=this.index;t!==null&&(e.data.index={type:t.array.constructor.name,array:Array.prototype.slice.call(t.array)});const r=this.attributes;for(const p in r){const f=r[p];e.data.attributes[p]=f.toJSON(e.data)}const o={};let c=!1;for(const p in this.morphAttributes){const f=this.morphAttributes[p],d=[];for(let i=0,n=f.length;i0&&(o[p]=d,c=!0)}c&&(e.data.morphAttributes=o,e.data.morphTargetsRelative=this.morphTargetsRelative);const l=this.groups;l.length>0&&(e.data.groups=JSON.parse(JSON.stringify(l)));const h=this.boundingSphere;return h!==null&&(e.data.boundingSphere={center:h.center.toArray(),radius:h.radius}),e}clone(){return new this.constructor().copy(this)}copy(e){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;const t={};this.name=e.name;const r=e.index;r!==null&&this.setIndex(r.clone(t));const o=e.attributes;for(const f in o){const d=o[f];this.setAttribute(f,d.clone(t))}const c=e.morphAttributes;for(const f in c){const d=[],i=c[f];for(let n=0,a=i.length;n0){const o=t[r[0]];if(o!==void 0){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(let c=0,l=o.length;c(e.far-e.near)**2))&&(_inverseMatrix$3.copy(c).invert(),_ray$3.copy(e.ray).applyMatrix4(_inverseMatrix$3),!(r.boundingBox!==null&&_ray$3.intersectsBox(r.boundingBox)===!1)&&this._computeIntersections(e,t,_ray$3)))}_computeIntersections(e,t,r){let o;const c=this.geometry,l=this.material,h=c.index,p=c.attributes.position,f=c.attributes.uv,d=c.attributes.uv1,i=c.attributes.normal,n=c.groups,a=c.drawRange;if(h!==null)if(Array.isArray(l))for(let u=0,m=n.length;ut.far?null:{distance:f,point:_intersectionPointWorld.clone(),object:s}}function checkGeometryIntersection(s,e,t,r,o,c,l,h,p,f){s.getVertexPosition(h,_vA$1),s.getVertexPosition(p,_vB$1),s.getVertexPosition(f,_vC$1);const d=checkIntersection(s,e,t,r,_vA$1,_vB$1,_vC$1,_intersectionPoint);if(d){o&&(_uvA$1.fromBufferAttribute(o,h),_uvB$1.fromBufferAttribute(o,p),_uvC$1.fromBufferAttribute(o,f),d.uv=Triangle.getInterpolation(_intersectionPoint,_vA$1,_vB$1,_vC$1,_uvA$1,_uvB$1,_uvC$1,new Vector2)),c&&(_uvA$1.fromBufferAttribute(c,h),_uvB$1.fromBufferAttribute(c,p),_uvC$1.fromBufferAttribute(c,f),d.uv1=Triangle.getInterpolation(_intersectionPoint,_vA$1,_vB$1,_vC$1,_uvA$1,_uvB$1,_uvC$1,new Vector2),d.uv2=d.uv1),l&&(_normalA.fromBufferAttribute(l,h),_normalB.fromBufferAttribute(l,p),_normalC.fromBufferAttribute(l,f),d.normal=Triangle.getInterpolation(_intersectionPoint,_vA$1,_vB$1,_vC$1,_normalA,_normalB,_normalC,new Vector3),d.normal.dot(r.direction)>0&&d.normal.multiplyScalar(-1));const i={a:h,b:p,c:f,normal:new Vector3,materialIndex:0};Triangle.getNormal(_vA$1,_vB$1,_vC$1,i.normal),d.face=i}return d}class BoxGeometry extends BufferGeometry{constructor(e=1,t=1,r=1,o=1,c=1,l=1){super(),this.type="BoxGeometry",this.parameters={width:e,height:t,depth:r,widthSegments:o,heightSegments:c,depthSegments:l};const h=this;o=Math.floor(o),c=Math.floor(c),l=Math.floor(l);const p=[],f=[],d=[],i=[];let n=0,a=0;u("z","y","x",-1,-1,r,t,e,l,c,0),u("z","y","x",1,-1,r,t,-e,l,c,1),u("x","z","y",1,1,e,r,t,o,l,2),u("x","z","y",1,-1,e,r,-t,o,l,3),u("x","y","z",1,-1,e,t,r,o,c,4),u("x","y","z",-1,-1,e,t,-r,o,c,5),this.setIndex(p),this.setAttribute("position",new Float32BufferAttribute(f,3)),this.setAttribute("normal",new Float32BufferAttribute(d,3)),this.setAttribute("uv",new Float32BufferAttribute(i,2));function u(m,g,_,b,y,v,x,w,S,M,T){const E=v/S,R=x/M,I=v/2,k=x/2,C=w/2,z=S+1,O=M+1;let U=0,K=0;const $=new Vector3;for(let J=0;J0?1:-1,d.push($.x,$.y,$.z),i.push(he/S),i.push(1-J/M),U+=1}}for(let J=0;J0&&(t.defines=this.defines),t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader,t.lights=this.lights,t.clipping=this.clipping;const r={};for(const o in this.extensions)this.extensions[o]===!0&&(r[o]=!0);return Object.keys(r).length>0&&(t.extensions=r),t}}class Camera extends Object3D{constructor(){super(),this.isCamera=!0,this.type="Camera",this.matrixWorldInverse=new Matrix4,this.projectionMatrix=new Matrix4,this.projectionMatrixInverse=new Matrix4,this.coordinateSystem=WebGLCoordinateSystem}copy(e,t){return super.copy(e,t),this.matrixWorldInverse.copy(e.matrixWorldInverse),this.projectionMatrix.copy(e.projectionMatrix),this.projectionMatrixInverse.copy(e.projectionMatrixInverse),this.coordinateSystem=e.coordinateSystem,this}getWorldDirection(e){return super.getWorldDirection(e).negate()}updateMatrixWorld(e){super.updateMatrixWorld(e),this.matrixWorldInverse.copy(this.matrixWorld).invert()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.matrixWorldInverse.copy(this.matrixWorld).invert()}clone(){return new this.constructor().copy(this)}}class PerspectiveCamera extends Camera{constructor(e=50,t=1,r=.1,o=2e3){super(),this.isPerspectiveCamera=!0,this.type="PerspectiveCamera",this.fov=e,this.zoom=1,this.near=r,this.far=o,this.focus=10,this.aspect=t,this.view=null,this.filmGauge=35,this.filmOffset=0,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.fov=e.fov,this.zoom=e.zoom,this.near=e.near,this.far=e.far,this.focus=e.focus,this.aspect=e.aspect,this.view=e.view===null?null:Object.assign({},e.view),this.filmGauge=e.filmGauge,this.filmOffset=e.filmOffset,this}setFocalLength(e){const t=.5*this.getFilmHeight()/e;this.fov=RAD2DEG*2*Math.atan(t),this.updateProjectionMatrix()}getFocalLength(){const e=Math.tan(DEG2RAD*.5*this.fov);return .5*this.getFilmHeight()/e}getEffectiveFOV(){return RAD2DEG*2*Math.atan(Math.tan(DEG2RAD*.5*this.fov)/this.zoom)}getFilmWidth(){return this.filmGauge*Math.min(this.aspect,1)}getFilmHeight(){return this.filmGauge/Math.max(this.aspect,1)}setViewOffset(e,t,r,o,c,l){this.aspect=e/t,this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=r,this.view.offsetY=o,this.view.width=c,this.view.height=l,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=this.near;let t=e*Math.tan(DEG2RAD*.5*this.fov)/this.zoom,r=2*t,o=this.aspect*r,c=-.5*o;const l=this.view;if(this.view!==null&&this.view.enabled){const p=l.fullWidth,f=l.fullHeight;c+=l.offsetX*o/p,t-=l.offsetY*r/f,o*=l.width/p,r*=l.height/f}const h=this.filmOffset;h!==0&&(c+=e*h/this.getFilmWidth()),this.projectionMatrix.makePerspective(c,c+o,t,t-r,e,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.fov=this.fov,t.object.zoom=this.zoom,t.object.near=this.near,t.object.far=this.far,t.object.focus=this.focus,t.object.aspect=this.aspect,this.view!==null&&(t.object.view=Object.assign({},this.view)),t.object.filmGauge=this.filmGauge,t.object.filmOffset=this.filmOffset,t}}const fov=-90,aspect=1;class CubeCamera extends Object3D{constructor(e,t,r){super(),this.type="CubeCamera",this.renderTarget=r,this.coordinateSystem=null,this.activeMipmapLevel=0;const o=new PerspectiveCamera(fov,aspect,e,t);o.layers=this.layers,this.add(o);const c=new PerspectiveCamera(fov,aspect,e,t);c.layers=this.layers,this.add(c);const l=new PerspectiveCamera(fov,aspect,e,t);l.layers=this.layers,this.add(l);const h=new PerspectiveCamera(fov,aspect,e,t);h.layers=this.layers,this.add(h);const p=new PerspectiveCamera(fov,aspect,e,t);p.layers=this.layers,this.add(p);const f=new PerspectiveCamera(fov,aspect,e,t);f.layers=this.layers,this.add(f)}updateCoordinateSystem(){const e=this.coordinateSystem,t=this.children.concat(),[r,o,c,l,h,p]=t;for(const f of t)this.remove(f);if(e===WebGLCoordinateSystem)r.up.set(0,1,0),r.lookAt(1,0,0),o.up.set(0,1,0),o.lookAt(-1,0,0),c.up.set(0,0,-1),c.lookAt(0,1,0),l.up.set(0,0,1),l.lookAt(0,-1,0),h.up.set(0,1,0),h.lookAt(0,0,1),p.up.set(0,1,0),p.lookAt(0,0,-1);else if(e===WebGPUCoordinateSystem)r.up.set(0,-1,0),r.lookAt(-1,0,0),o.up.set(0,-1,0),o.lookAt(1,0,0),c.up.set(0,0,1),c.lookAt(0,1,0),l.up.set(0,0,-1),l.lookAt(0,-1,0),h.up.set(0,-1,0),h.lookAt(0,0,1),p.up.set(0,-1,0),p.lookAt(0,0,-1);else throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: "+e);for(const f of t)this.add(f),f.updateMatrixWorld()}update(e,t){this.parent===null&&this.updateMatrixWorld();const{renderTarget:r,activeMipmapLevel:o}=this;this.coordinateSystem!==e.coordinateSystem&&(this.coordinateSystem=e.coordinateSystem,this.updateCoordinateSystem());const[c,l,h,p,f,d]=this.children,i=e.getRenderTarget(),n=e.getActiveCubeFace(),a=e.getActiveMipmapLevel(),u=e.xr.enabled;e.xr.enabled=!1;const m=r.texture.generateMipmaps;r.texture.generateMipmaps=!1,e.setRenderTarget(r,0,o),e.render(t,c),e.setRenderTarget(r,1,o),e.render(t,l),e.setRenderTarget(r,2,o),e.render(t,h),e.setRenderTarget(r,3,o),e.render(t,p),e.setRenderTarget(r,4,o),e.render(t,f),r.texture.generateMipmaps=m,e.setRenderTarget(r,5,o),e.render(t,d),e.setRenderTarget(i,n,a),e.xr.enabled=u,r.texture.needsPMREMUpdate=!0}}class CubeTexture extends Texture{constructor(e,t,r,o,c,l,h,p,f,d){e=e!==void 0?e:[],t=t!==void 0?t:CubeReflectionMapping,super(e,t,r,o,c,l,h,p,f,d),this.isCubeTexture=!0,this.flipY=!1}get images(){return this.image}set images(e){this.image=e}}class WebGLCubeRenderTarget extends WebGLRenderTarget{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;const r={width:e,height:e,depth:1},o=[r,r,r,r,r,r];t.encoding!==void 0&&(warnOnce("THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace."),t.colorSpace=t.encoding===sRGBEncoding?SRGBColorSpace:NoColorSpace),this.texture=new CubeTexture(o,t.mapping,t.wrapS,t.wrapT,t.magFilter,t.minFilter,t.format,t.type,t.anisotropy,t.colorSpace),this.texture.isRenderTargetTexture=!0,this.texture.generateMipmaps=t.generateMipmaps!==void 0?t.generateMipmaps:!1,this.texture.minFilter=t.minFilter!==void 0?t.minFilter:LinearFilter}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;const r={uniforms:{tEquirect:{value:null}},vertexShader:` varying vec3 vWorldDirection; vec3 transformDirection( in vec3 dir, in mat4 matrix ) { return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); } void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include } `,fragmentShader:` uniform sampler2D tEquirect; varying vec3 vWorldDirection; #include void main() { vec3 direction = normalize( vWorldDirection ); vec2 sampleUV = equirectUv( direction ); gl_FragColor = texture2D( tEquirect, sampleUV ); } `},o=new BoxGeometry(5,5,5),c=new ShaderMaterial({name:"CubemapFromEquirect",uniforms:cloneUniforms(r.uniforms),vertexShader:r.vertexShader,fragmentShader:r.fragmentShader,side:BackSide,blending:NoBlending});c.uniforms.tEquirect.value=t;const l=new Mesh(o,c),h=t.minFilter;return t.minFilter===LinearMipmapLinearFilter&&(t.minFilter=LinearFilter),new CubeCamera(1,10,this).update(e,l),t.minFilter=h,l.geometry.dispose(),l.material.dispose(),this}clear(e,t,r,o){const c=e.getRenderTarget();for(let l=0;l<6;l++)e.setRenderTarget(this,l),e.clear(t,r,o);e.setRenderTarget(c)}}const _vector1=new Vector3,_vector2=new Vector3,_normalMatrix=new Matrix3;class Plane{constructor(e=new Vector3(1,0,0),t=0){this.isPlane=!0,this.normal=e,this.constant=t}set(e,t){return this.normal.copy(e),this.constant=t,this}setComponents(e,t,r,o){return this.normal.set(e,t,r),this.constant=o,this}setFromNormalAndCoplanarPoint(e,t){return this.normal.copy(e),this.constant=-t.dot(this.normal),this}setFromCoplanarPoints(e,t,r){const o=_vector1.subVectors(r,t).cross(_vector2.subVectors(e,t)).normalize();return this.setFromNormalAndCoplanarPoint(o,e),this}copy(e){return this.normal.copy(e.normal),this.constant=e.constant,this}normalize(){const e=1/this.normal.length();return this.normal.multiplyScalar(e),this.constant*=e,this}negate(){return this.constant*=-1,this.normal.negate(),this}distanceToPoint(e){return this.normal.dot(e)+this.constant}distanceToSphere(e){return this.distanceToPoint(e.center)-e.radius}projectPoint(e,t){return t.copy(e).addScaledVector(this.normal,-this.distanceToPoint(e))}intersectLine(e,t){const r=e.delta(_vector1),o=this.normal.dot(r);if(o===0)return this.distanceToPoint(e.start)===0?t.copy(e.start):null;const c=-(e.start.dot(this.normal)+this.constant)/o;return c<0||c>1?null:t.copy(e.start).addScaledVector(r,c)}intersectsLine(e){const t=this.distanceToPoint(e.start),r=this.distanceToPoint(e.end);return t<0&&r>0||r<0&&t>0}intersectsBox(e){return e.intersectsPlane(this)}intersectsSphere(e){return e.intersectsPlane(this)}coplanarPoint(e){return e.copy(this.normal).multiplyScalar(-this.constant)}applyMatrix4(e,t){const r=t||_normalMatrix.getNormalMatrix(e),o=this.coplanarPoint(_vector1).applyMatrix4(e),c=this.normal.applyMatrix3(r).normalize();return this.constant=-o.dot(c),this}translate(e){return this.constant-=e.dot(this.normal),this}equals(e){return e.normal.equals(this.normal)&&e.constant===this.constant}clone(){return new this.constructor().copy(this)}}const _sphere$5=new Sphere,_vector$7=new Vector3;class Frustum{constructor(e=new Plane,t=new Plane,r=new Plane,o=new Plane,c=new Plane,l=new Plane){this.planes=[e,t,r,o,c,l]}set(e,t,r,o,c,l){const h=this.planes;return h[0].copy(e),h[1].copy(t),h[2].copy(r),h[3].copy(o),h[4].copy(c),h[5].copy(l),this}copy(e){const t=this.planes;for(let r=0;r<6;r++)t[r].copy(e.planes[r]);return this}setFromProjectionMatrix(e,t=WebGLCoordinateSystem){const r=this.planes,o=e.elements,c=o[0],l=o[1],h=o[2],p=o[3],f=o[4],d=o[5],i=o[6],n=o[7],a=o[8],u=o[9],m=o[10],g=o[11],_=o[12],b=o[13],y=o[14],v=o[15];if(r[0].setComponents(p-c,n-f,g-a,v-_).normalize(),r[1].setComponents(p+c,n+f,g+a,v+_).normalize(),r[2].setComponents(p+l,n+d,g+u,v+b).normalize(),r[3].setComponents(p-l,n-d,g-u,v-b).normalize(),r[4].setComponents(p-h,n-i,g-m,v-y).normalize(),t===WebGLCoordinateSystem)r[5].setComponents(p+h,n+i,g+m,v+y).normalize();else if(t===WebGPUCoordinateSystem)r[5].setComponents(h,i,m,y).normalize();else throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: "+t);return this}intersectsObject(e){if(e.boundingSphere!==void 0)e.boundingSphere===null&&e.computeBoundingSphere(),_sphere$5.copy(e.boundingSphere).applyMatrix4(e.matrixWorld);else{const t=e.geometry;t.boundingSphere===null&&t.computeBoundingSphere(),_sphere$5.copy(t.boundingSphere).applyMatrix4(e.matrixWorld)}return this.intersectsSphere(_sphere$5)}intersectsSprite(e){return _sphere$5.center.set(0,0,0),_sphere$5.radius=.7071067811865476,_sphere$5.applyMatrix4(e.matrixWorld),this.intersectsSphere(_sphere$5)}intersectsSphere(e){const t=this.planes,r=e.center,o=-e.radius;for(let c=0;c<6;c++)if(t[c].distanceToPoint(r)0?e.max.x:e.min.x,_vector$7.y=o.normal.y>0?e.max.y:e.min.y,_vector$7.z=o.normal.z>0?e.max.z:e.min.z,o.distanceToPoint(_vector$7)<0)return!1}return!0}containsPoint(e){const t=this.planes;for(let r=0;r<6;r++)if(t[r].distanceToPoint(e)<0)return!1;return!0}clone(){return new this.constructor().copy(this)}}function WebGLAnimation(){let s=null,e=!1,t=null,r=null;function o(c,l){t(c,l),r=s.requestAnimationFrame(o)}return{start:function(){e!==!0&&t!==null&&(r=s.requestAnimationFrame(o),e=!0)},stop:function(){s.cancelAnimationFrame(r),e=!1},setAnimationLoop:function(c){t=c},setContext:function(c){s=c}}}function WebGLAttributes(s,e){const t=e.isWebGL2,r=new WeakMap;function o(f,d){const i=f.array,n=f.usage,a=i.byteLength,u=s.createBuffer();s.bindBuffer(d,u),s.bufferData(d,i,n),f.onUploadCallback();let m;if(i instanceof Float32Array)m=s.FLOAT;else if(i instanceof Uint16Array)if(f.isFloat16BufferAttribute)if(t)m=s.HALF_FLOAT;else throw new Error("THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.");else m=s.UNSIGNED_SHORT;else if(i instanceof Int16Array)m=s.SHORT;else if(i instanceof Uint32Array)m=s.UNSIGNED_INT;else if(i instanceof Int32Array)m=s.INT;else if(i instanceof Int8Array)m=s.BYTE;else if(i instanceof Uint8Array)m=s.UNSIGNED_BYTE;else if(i instanceof Uint8ClampedArray)m=s.UNSIGNED_BYTE;else throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: "+i);return{buffer:u,type:m,bytesPerElement:i.BYTES_PER_ELEMENT,version:f.version,size:a}}function c(f,d,i){const n=d.array,a=d._updateRange,u=d.updateRanges;if(s.bindBuffer(i,f),a.count===-1&&u.length===0&&s.bufferSubData(i,0,n),u.length!==0){for(let m=0,g=u.length;m 0 vec4 plane; #pragma unroll_loop_start for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) { plane = clippingPlanes[ i ]; if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard; } #pragma unroll_loop_end #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES bool clipped = true; #pragma unroll_loop_start for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) { plane = clippingPlanes[ i ]; clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped; } #pragma unroll_loop_end if ( clipped ) discard; #endif #endif`,clipping_planes_pars_fragment=`#if NUM_CLIPPING_PLANES > 0 varying vec3 vClipPosition; uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ]; #endif`,clipping_planes_pars_vertex=`#if NUM_CLIPPING_PLANES > 0 varying vec3 vClipPosition; #endif`,clipping_planes_vertex=`#if NUM_CLIPPING_PLANES > 0 vClipPosition = - mvPosition.xyz; #endif`,color_fragment=`#if defined( USE_COLOR_ALPHA ) diffuseColor *= vColor; #elif defined( USE_COLOR ) diffuseColor.rgb *= vColor; #endif`,color_pars_fragment=`#if defined( USE_COLOR_ALPHA ) varying vec4 vColor; #elif defined( USE_COLOR ) varying vec3 vColor; #endif`,color_pars_vertex=`#if defined( USE_COLOR_ALPHA ) varying vec4 vColor; #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) varying vec3 vColor; #endif`,color_vertex=`#if defined( USE_COLOR_ALPHA ) vColor = vec4( 1.0 ); #elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) vColor = vec3( 1.0 ); #endif #ifdef USE_COLOR vColor *= color; #endif #ifdef USE_INSTANCING_COLOR vColor.xyz *= instanceColor.xyz; #endif`,common=`#define PI 3.141592653589793 #define PI2 6.283185307179586 #define PI_HALF 1.5707963267948966 #define RECIPROCAL_PI 0.3183098861837907 #define RECIPROCAL_PI2 0.15915494309189535 #define EPSILON 1e-6 #ifndef saturate #define saturate( a ) clamp( a, 0.0, 1.0 ) #endif #define whiteComplement( a ) ( 1.0 - saturate( a ) ) float pow2( const in float x ) { return x*x; } vec3 pow2( const in vec3 x ) { return x*x; } float pow3( const in float x ) { return x*x*x; } float pow4( const in float x ) { float x2 = x*x; return x2*x2; } float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); } float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); } highp float rand( const in vec2 uv ) { const highp float a = 12.9898, b = 78.233, c = 43758.5453; highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI ); return fract( sin( sn ) * c ); } #ifdef HIGH_PRECISION float precisionSafeLength( vec3 v ) { return length( v ); } #else float precisionSafeLength( vec3 v ) { float maxComponent = max3( abs( v ) ); return length( v / maxComponent ) * maxComponent; } #endif struct IncidentLight { vec3 color; vec3 direction; bool visible; }; struct ReflectedLight { vec3 directDiffuse; vec3 directSpecular; vec3 indirectDiffuse; vec3 indirectSpecular; }; #ifdef USE_ALPHAHASH varying vec3 vPosition; #endif vec3 transformDirection( in vec3 dir, in mat4 matrix ) { return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); } vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) { return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz ); } mat3 transposeMat3( const in mat3 m ) { mat3 tmp; tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x ); tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y ); tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z ); return tmp; } float luminance( const in vec3 rgb ) { const vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 ); return dot( weights, rgb ); } bool isPerspectiveMatrix( mat4 m ) { return m[ 2 ][ 3 ] == - 1.0; } vec2 equirectUv( in vec3 dir ) { float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5; float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5; return vec2( u, v ); } vec3 BRDF_Lambert( const in vec3 diffuseColor ) { return RECIPROCAL_PI * diffuseColor; } vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) { float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); } float F_Schlick( const in float f0, const in float f90, const in float dotVH ) { float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH ); return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel ); } // validated`,cube_uv_reflection_fragment=`#ifdef ENVMAP_TYPE_CUBE_UV #define cubeUV_minMipLevel 4.0 #define cubeUV_minTileSize 16.0 float getFace( vec3 direction ) { vec3 absDirection = abs( direction ); float face = - 1.0; if ( absDirection.x > absDirection.z ) { if ( absDirection.x > absDirection.y ) face = direction.x > 0.0 ? 0.0 : 3.0; else face = direction.y > 0.0 ? 1.0 : 4.0; } else { if ( absDirection.z > absDirection.y ) face = direction.z > 0.0 ? 2.0 : 5.0; else face = direction.y > 0.0 ? 1.0 : 4.0; } return face; } vec2 getUV( vec3 direction, float face ) { vec2 uv; if ( face == 0.0 ) { uv = vec2( direction.z, direction.y ) / abs( direction.x ); } else if ( face == 1.0 ) { uv = vec2( - direction.x, - direction.z ) / abs( direction.y ); } else if ( face == 2.0 ) { uv = vec2( - direction.x, direction.y ) / abs( direction.z ); } else if ( face == 3.0 ) { uv = vec2( - direction.z, direction.y ) / abs( direction.x ); } else if ( face == 4.0 ) { uv = vec2( - direction.x, direction.z ) / abs( direction.y ); } else { uv = vec2( direction.x, direction.y ) / abs( direction.z ); } return 0.5 * ( uv + 1.0 ); } vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) { float face = getFace( direction ); float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 ); mipInt = max( mipInt, cubeUV_minMipLevel ); float faceSize = exp2( mipInt ); highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0; if ( face > 2.0 ) { uv.y += faceSize; face -= 3.0; } uv.x += face * faceSize; uv.x += filterInt * 3.0 * cubeUV_minTileSize; uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize ); uv.x *= CUBEUV_TEXEL_WIDTH; uv.y *= CUBEUV_TEXEL_HEIGHT; #ifdef texture2DGradEXT return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb; #else return texture2D( envMap, uv ).rgb; #endif } #define cubeUV_r0 1.0 #define cubeUV_m0 - 2.0 #define cubeUV_r1 0.8 #define cubeUV_m1 - 1.0 #define cubeUV_r4 0.4 #define cubeUV_m4 2.0 #define cubeUV_r5 0.305 #define cubeUV_m5 3.0 #define cubeUV_r6 0.21 #define cubeUV_m6 4.0 float roughnessToMip( float roughness ) { float mip = 0.0; if ( roughness >= cubeUV_r1 ) { mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0; } else if ( roughness >= cubeUV_r4 ) { mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1; } else if ( roughness >= cubeUV_r5 ) { mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4; } else if ( roughness >= cubeUV_r6 ) { mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5; } else { mip = - 2.0 * log2( 1.16 * roughness ); } return mip; } vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) { float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP ); float mipF = fract( mip ); float mipInt = floor( mip ); vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt ); if ( mipF == 0.0 ) { return vec4( color0, 1.0 ); } else { vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 ); return vec4( mix( color0, color1, mipF ), 1.0 ); } } #endif`,defaultnormal_vertex=`vec3 transformedNormal = objectNormal; #ifdef USE_TANGENT vec3 transformedTangent = objectTangent; #endif #ifdef USE_BATCHING mat3 bm = mat3( batchingMatrix ); transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) ); transformedNormal = bm * transformedNormal; #ifdef USE_TANGENT transformedTangent = bm * transformedTangent; #endif #endif #ifdef USE_INSTANCING mat3 im = mat3( instanceMatrix ); transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) ); transformedNormal = im * transformedNormal; #ifdef USE_TANGENT transformedTangent = im * transformedTangent; #endif #endif transformedNormal = normalMatrix * transformedNormal; #ifdef FLIP_SIDED transformedNormal = - transformedNormal; #endif #ifdef USE_TANGENT transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz; #ifdef FLIP_SIDED transformedTangent = - transformedTangent; #endif #endif`,displacementmap_pars_vertex=`#ifdef USE_DISPLACEMENTMAP uniform sampler2D displacementMap; uniform float displacementScale; uniform float displacementBias; #endif`,displacementmap_vertex=`#ifdef USE_DISPLACEMENTMAP transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias ); #endif`,emissivemap_fragment=`#ifdef USE_EMISSIVEMAP vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv ); totalEmissiveRadiance *= emissiveColor.rgb; #endif`,emissivemap_pars_fragment=`#ifdef USE_EMISSIVEMAP uniform sampler2D emissiveMap; #endif`,colorspace_fragment="gl_FragColor = linearToOutputTexel( gl_FragColor );",colorspace_pars_fragment=` const mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3( vec3( 0.8224621, 0.177538, 0.0 ), vec3( 0.0331941, 0.9668058, 0.0 ), vec3( 0.0170827, 0.0723974, 0.9105199 ) ); const mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3( vec3( 1.2249401, - 0.2249404, 0.0 ), vec3( - 0.0420569, 1.0420571, 0.0 ), vec3( - 0.0196376, - 0.0786361, 1.0982735 ) ); vec4 LinearSRGBToLinearDisplayP3( in vec4 value ) { return vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a ); } vec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) { return vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a ); } vec4 LinearTransferOETF( in vec4 value ) { return value; } vec4 sRGBTransferOETF( in vec4 value ) { return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a ); } vec4 LinearToLinear( in vec4 value ) { return value; } vec4 LinearTosRGB( in vec4 value ) { return sRGBTransferOETF( value ); }`,envmap_fragment=`#ifdef USE_ENVMAP #ifdef ENV_WORLDPOS vec3 cameraToFrag; if ( isOrthographic ) { cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); } else { cameraToFrag = normalize( vWorldPosition - cameraPosition ); } vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); #ifdef ENVMAP_MODE_REFLECTION vec3 reflectVec = reflect( cameraToFrag, worldNormal ); #else vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio ); #endif #else vec3 reflectVec = vReflect; #endif #ifdef ENVMAP_TYPE_CUBE vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) ); #else vec4 envColor = vec4( 0.0 ); #endif #ifdef ENVMAP_BLENDING_MULTIPLY outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity ); #elif defined( ENVMAP_BLENDING_MIX ) outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity ); #elif defined( ENVMAP_BLENDING_ADD ) outgoingLight += envColor.xyz * specularStrength * reflectivity; #endif #endif`,envmap_common_pars_fragment=`#ifdef USE_ENVMAP uniform float envMapIntensity; uniform float flipEnvMap; #ifdef ENVMAP_TYPE_CUBE uniform samplerCube envMap; #else uniform sampler2D envMap; #endif #endif`,envmap_pars_fragment=`#ifdef USE_ENVMAP uniform float reflectivity; #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) #define ENV_WORLDPOS #endif #ifdef ENV_WORLDPOS varying vec3 vWorldPosition; uniform float refractionRatio; #else varying vec3 vReflect; #endif #endif`,envmap_pars_vertex=`#ifdef USE_ENVMAP #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT ) #define ENV_WORLDPOS #endif #ifdef ENV_WORLDPOS varying vec3 vWorldPosition; #else varying vec3 vReflect; uniform float refractionRatio; #endif #endif`,envmap_vertex=`#ifdef USE_ENVMAP #ifdef ENV_WORLDPOS vWorldPosition = worldPosition.xyz; #else vec3 cameraToVertex; if ( isOrthographic ) { cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) ); } else { cameraToVertex = normalize( worldPosition.xyz - cameraPosition ); } vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); #ifdef ENVMAP_MODE_REFLECTION vReflect = reflect( cameraToVertex, worldNormal ); #else vReflect = refract( cameraToVertex, worldNormal, refractionRatio ); #endif #endif #endif`,fog_vertex=`#ifdef USE_FOG vFogDepth = - mvPosition.z; #endif`,fog_pars_vertex=`#ifdef USE_FOG varying float vFogDepth; #endif`,fog_fragment=`#ifdef USE_FOG #ifdef FOG_EXP2 float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth ); #else float fogFactor = smoothstep( fogNear, fogFar, vFogDepth ); #endif gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor ); #endif`,fog_pars_fragment=`#ifdef USE_FOG uniform vec3 fogColor; varying float vFogDepth; #ifdef FOG_EXP2 uniform float fogDensity; #else uniform float fogNear; uniform float fogFar; #endif #endif`,gradientmap_pars_fragment=`#ifdef USE_GRADIENTMAP uniform sampler2D gradientMap; #endif vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) { float dotNL = dot( normal, lightDirection ); vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 ); #ifdef USE_GRADIENTMAP return vec3( texture2D( gradientMap, coord ).r ); #else vec2 fw = fwidth( coord ) * 0.5; return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) ); #endif }`,lightmap_fragment=`#ifdef USE_LIGHTMAP vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; reflectedLight.indirectDiffuse += lightMapIrradiance; #endif`,lightmap_pars_fragment=`#ifdef USE_LIGHTMAP uniform sampler2D lightMap; uniform float lightMapIntensity; #endif`,lights_lambert_fragment=`LambertMaterial material; material.diffuseColor = diffuseColor.rgb; material.specularStrength = specularStrength;`,lights_lambert_pars_fragment=`varying vec3 vViewPosition; struct LambertMaterial { vec3 diffuseColor; float specularStrength; }; void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); vec3 irradiance = dotNL * directLight.color; reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) { reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } #define RE_Direct RE_Direct_Lambert #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,lights_pars_begin=`uniform bool receiveShadow; uniform vec3 ambientLightColor; #if defined( USE_LIGHT_PROBES ) uniform vec3 lightProbe[ 9 ]; #endif vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) { float x = normal.x, y = normal.y, z = normal.z; vec3 result = shCoefficients[ 0 ] * 0.886227; result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y; result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z; result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x; result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y; result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z; result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 ); result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z; result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y ); return result; } vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) { vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe ); return irradiance; } vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) { vec3 irradiance = ambientLightColor; return irradiance; } float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) { #if defined ( LEGACY_LIGHTS ) if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) { return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent ); } return 1.0; #else float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 ); if ( cutoffDistance > 0.0 ) { distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); } return distanceFalloff; #endif } float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) { return smoothstep( coneCosine, penumbraCosine, angleCosine ); } #if NUM_DIR_LIGHTS > 0 struct DirectionalLight { vec3 direction; vec3 color; }; uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ]; void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) { light.color = directionalLight.color; light.direction = directionalLight.direction; light.visible = true; } #endif #if NUM_POINT_LIGHTS > 0 struct PointLight { vec3 position; vec3 color; float distance; float decay; }; uniform PointLight pointLights[ NUM_POINT_LIGHTS ]; void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) { vec3 lVector = pointLight.position - geometryPosition; light.direction = normalize( lVector ); float lightDistance = length( lVector ); light.color = pointLight.color; light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay ); light.visible = ( light.color != vec3( 0.0 ) ); } #endif #if NUM_SPOT_LIGHTS > 0 struct SpotLight { vec3 position; vec3 direction; vec3 color; float distance; float decay; float coneCos; float penumbraCos; }; uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ]; void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) { vec3 lVector = spotLight.position - geometryPosition; light.direction = normalize( lVector ); float angleCos = dot( light.direction, spotLight.direction ); float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos ); if ( spotAttenuation > 0.0 ) { float lightDistance = length( lVector ); light.color = spotLight.color * spotAttenuation; light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay ); light.visible = ( light.color != vec3( 0.0 ) ); } else { light.color = vec3( 0.0 ); light.visible = false; } } #endif #if NUM_RECT_AREA_LIGHTS > 0 struct RectAreaLight { vec3 color; vec3 position; vec3 halfWidth; vec3 halfHeight; }; uniform sampler2D ltc_1; uniform sampler2D ltc_2; uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ]; #endif #if NUM_HEMI_LIGHTS > 0 struct HemisphereLight { vec3 direction; vec3 skyColor; vec3 groundColor; }; uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ]; vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) { float dotNL = dot( normal, hemiLight.direction ); float hemiDiffuseWeight = 0.5 * dotNL + 0.5; vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight ); return irradiance; } #endif`,envmap_physical_pars_fragment=`#ifdef USE_ENVMAP vec3 getIBLIrradiance( const in vec3 normal ) { #ifdef ENVMAP_TYPE_CUBE_UV vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 ); return PI * envMapColor.rgb * envMapIntensity; #else return vec3( 0.0 ); #endif } vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { #ifdef ENVMAP_TYPE_CUBE_UV vec3 reflectVec = reflect( - viewDir, normal ); reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) ); reflectVec = inverseTransformDirection( reflectVec, viewMatrix ); vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness ); return envMapColor.rgb * envMapIntensity; #else return vec3( 0.0 ); #endif } #ifdef USE_ANISOTROPY vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) { #ifdef ENVMAP_TYPE_CUBE_UV vec3 bentNormal = cross( bitangent, viewDir ); bentNormal = normalize( cross( bentNormal, bitangent ) ); bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) ); return getIBLRadiance( viewDir, bentNormal, roughness ); #else return vec3( 0.0 ); #endif } #endif #endif`,lights_toon_fragment=`ToonMaterial material; material.diffuseColor = diffuseColor.rgb;`,lights_toon_pars_fragment=`varying vec3 vViewPosition; struct ToonMaterial { vec3 diffuseColor; }; void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color; reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) { reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } #define RE_Direct RE_Direct_Toon #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,lights_phong_fragment=`BlinnPhongMaterial material; material.diffuseColor = diffuseColor.rgb; material.specularColor = specular; material.specularShininess = shininess; material.specularStrength = specularStrength;`,lights_phong_pars_fragment=`varying vec3 vViewPosition; struct BlinnPhongMaterial { vec3 diffuseColor; vec3 specularColor; float specularShininess; float specularStrength; }; void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); vec3 irradiance = dotNL * directLight.color; reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength; } void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) { reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } #define RE_Direct RE_Direct_BlinnPhong #define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,lights_physical_fragment=`PhysicalMaterial material; material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor ); vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) ); float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z ); material.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness; material.roughness = min( material.roughness, 1.0 ); #ifdef IOR material.ior = ior; #ifdef USE_SPECULAR float specularIntensityFactor = specularIntensity; vec3 specularColorFactor = specularColor; #ifdef USE_SPECULAR_COLORMAP specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb; #endif #ifdef USE_SPECULAR_INTENSITYMAP specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a; #endif material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor ); #else float specularIntensityFactor = 1.0; vec3 specularColorFactor = vec3( 1.0 ); material.specularF90 = 1.0; #endif material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor ); #else material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor ); material.specularF90 = 1.0; #endif #ifdef USE_CLEARCOAT material.clearcoat = clearcoat; material.clearcoatRoughness = clearcoatRoughness; material.clearcoatF0 = vec3( 0.04 ); material.clearcoatF90 = 1.0; #ifdef USE_CLEARCOATMAP material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y; #endif material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 ); material.clearcoatRoughness += geometryRoughness; material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 ); #endif #ifdef USE_IRIDESCENCE material.iridescence = iridescence; material.iridescenceIOR = iridescenceIOR; #ifdef USE_IRIDESCENCEMAP material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum; #else material.iridescenceThickness = iridescenceThicknessMaximum; #endif #endif #ifdef USE_SHEEN material.sheenColor = sheenColor; #ifdef USE_SHEEN_COLORMAP material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb; #endif material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 ); #ifdef USE_SHEEN_ROUGHNESSMAP material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a; #endif #endif #ifdef USE_ANISOTROPY #ifdef USE_ANISOTROPYMAP mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x ); vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb; vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b; #else vec2 anisotropyV = anisotropyVector; #endif material.anisotropy = length( anisotropyV ); if( material.anisotropy == 0.0 ) { anisotropyV = vec2( 1.0, 0.0 ); } else { anisotropyV /= material.anisotropy; material.anisotropy = saturate( material.anisotropy ); } material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) ); material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y; material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y; #endif`,lights_physical_pars_fragment=`struct PhysicalMaterial { vec3 diffuseColor; float roughness; vec3 specularColor; float specularF90; #ifdef USE_CLEARCOAT float clearcoat; float clearcoatRoughness; vec3 clearcoatF0; float clearcoatF90; #endif #ifdef USE_IRIDESCENCE float iridescence; float iridescenceIOR; float iridescenceThickness; vec3 iridescenceFresnel; vec3 iridescenceF0; #endif #ifdef USE_SHEEN vec3 sheenColor; float sheenRoughness; #endif #ifdef IOR float ior; #endif #ifdef USE_TRANSMISSION float transmission; float transmissionAlpha; float thickness; float attenuationDistance; vec3 attenuationColor; #endif #ifdef USE_ANISOTROPY float anisotropy; float alphaT; vec3 anisotropyT; vec3 anisotropyB; #endif }; vec3 clearcoatSpecularDirect = vec3( 0.0 ); vec3 clearcoatSpecularIndirect = vec3( 0.0 ); vec3 sheenSpecularDirect = vec3( 0.0 ); vec3 sheenSpecularIndirect = vec3(0.0 ); vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) { float x = clamp( 1.0 - dotVH, 0.0, 1.0 ); float x2 = x * x; float x5 = clamp( x * x2 * x2, 0.0, 0.9999 ); return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 ); } float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) { float a2 = pow2( alpha ); float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) ); float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) ); return 0.5 / max( gv + gl, EPSILON ); } float D_GGX( const in float alpha, const in float dotNH ) { float a2 = pow2( alpha ); float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0; return RECIPROCAL_PI * a2 / pow2( denom ); } #ifdef USE_ANISOTROPY float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) { float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) ); float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) ); float v = 0.5 / ( gv + gl ); return saturate(v); } float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) { float a2 = alphaT * alphaB; highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH ); highp float v2 = dot( v, v ); float w2 = a2 / v2; return RECIPROCAL_PI * a2 * pow2 ( w2 ); } #endif #ifdef USE_CLEARCOAT vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) { vec3 f0 = material.clearcoatF0; float f90 = material.clearcoatF90; float roughness = material.clearcoatRoughness; float alpha = pow2( roughness ); vec3 halfDir = normalize( lightDir + viewDir ); float dotNL = saturate( dot( normal, lightDir ) ); float dotNV = saturate( dot( normal, viewDir ) ); float dotNH = saturate( dot( normal, halfDir ) ); float dotVH = saturate( dot( viewDir, halfDir ) ); vec3 F = F_Schlick( f0, f90, dotVH ); float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); float D = D_GGX( alpha, dotNH ); return F * ( V * D ); } #endif vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) { vec3 f0 = material.specularColor; float f90 = material.specularF90; float roughness = material.roughness; float alpha = pow2( roughness ); vec3 halfDir = normalize( lightDir + viewDir ); float dotNL = saturate( dot( normal, lightDir ) ); float dotNV = saturate( dot( normal, viewDir ) ); float dotNH = saturate( dot( normal, halfDir ) ); float dotVH = saturate( dot( viewDir, halfDir ) ); vec3 F = F_Schlick( f0, f90, dotVH ); #ifdef USE_IRIDESCENCE F = mix( F, material.iridescenceFresnel, material.iridescence ); #endif #ifdef USE_ANISOTROPY float dotTL = dot( material.anisotropyT, lightDir ); float dotTV = dot( material.anisotropyT, viewDir ); float dotTH = dot( material.anisotropyT, halfDir ); float dotBL = dot( material.anisotropyB, lightDir ); float dotBV = dot( material.anisotropyB, viewDir ); float dotBH = dot( material.anisotropyB, halfDir ); float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL ); float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH ); #else float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV ); float D = D_GGX( alpha, dotNH ); #endif return F * ( V * D ); } vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) { const float LUT_SIZE = 64.0; const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; const float LUT_BIAS = 0.5 / LUT_SIZE; float dotNV = saturate( dot( N, V ) ); vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) ); uv = uv * LUT_SCALE + LUT_BIAS; return uv; } float LTC_ClippedSphereFormFactor( const in vec3 f ) { float l = length( f ); return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 ); } vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) { float x = dot( v1, v2 ); float y = abs( x ); float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y; float b = 3.4175940 + ( 4.1616724 + y ) * y; float v = a / b; float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v; return cross( v1, v2 ) * theta_sintheta; } vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) { vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ]; vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ]; vec3 lightNormal = cross( v1, v2 ); if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 ); vec3 T1, T2; T1 = normalize( V - N * dot( V, N ) ); T2 = - cross( N, T1 ); mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) ); vec3 coords[ 4 ]; coords[ 0 ] = mat * ( rectCoords[ 0 ] - P ); coords[ 1 ] = mat * ( rectCoords[ 1 ] - P ); coords[ 2 ] = mat * ( rectCoords[ 2 ] - P ); coords[ 3 ] = mat * ( rectCoords[ 3 ] - P ); coords[ 0 ] = normalize( coords[ 0 ] ); coords[ 1 ] = normalize( coords[ 1 ] ); coords[ 2 ] = normalize( coords[ 2 ] ); coords[ 3 ] = normalize( coords[ 3 ] ); vec3 vectorFormFactor = vec3( 0.0 ); vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] ); vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] ); vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] ); vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] ); float result = LTC_ClippedSphereFormFactor( vectorFormFactor ); return vec3( result ); } #if defined( USE_SHEEN ) float D_Charlie( float roughness, float dotNH ) { float alpha = pow2( roughness ); float invAlpha = 1.0 / alpha; float cos2h = dotNH * dotNH; float sin2h = max( 1.0 - cos2h, 0.0078125 ); return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI ); } float V_Neubelt( float dotNV, float dotNL ) { return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) ); } vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) { vec3 halfDir = normalize( lightDir + viewDir ); float dotNL = saturate( dot( normal, lightDir ) ); float dotNV = saturate( dot( normal, viewDir ) ); float dotNH = saturate( dot( normal, halfDir ) ); float D = D_Charlie( sheenRoughness, dotNH ); float V = V_Neubelt( dotNV, dotNL ); return sheenColor * ( D * V ); } #endif float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { float dotNV = saturate( dot( normal, viewDir ) ); float r2 = roughness * roughness; float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95; float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72; float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) ); return saturate( DG * RECIPROCAL_PI ); } vec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) { float dotNV = saturate( dot( normal, viewDir ) ); const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 ); const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); vec4 r = roughness * c0 + c1; float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y; vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw; return fab; } vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) { vec2 fab = DFGApprox( normal, viewDir, roughness ); return specularColor * fab.x + specularF90 * fab.y; } #ifdef USE_IRIDESCENCE void computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { #else void computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) { #endif vec2 fab = DFGApprox( normal, viewDir, roughness ); #ifdef USE_IRIDESCENCE vec3 Fr = mix( specularColor, iridescenceF0, iridescence ); #else vec3 Fr = specularColor; #endif vec3 FssEss = Fr * fab.x + specularF90 * fab.y; float Ess = fab.x + fab.y; float Ems = 1.0 - Ess; vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg ); singleScatter += FssEss; multiScatter += Fms * Ems; } #if NUM_RECT_AREA_LIGHTS > 0 void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { vec3 normal = geometryNormal; vec3 viewDir = geometryViewDir; vec3 position = geometryPosition; vec3 lightPos = rectAreaLight.position; vec3 halfWidth = rectAreaLight.halfWidth; vec3 halfHeight = rectAreaLight.halfHeight; vec3 lightColor = rectAreaLight.color; float roughness = material.roughness; vec3 rectCoords[ 4 ]; rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight; rectCoords[ 2 ] = lightPos - halfWidth + halfHeight; rectCoords[ 3 ] = lightPos + halfWidth + halfHeight; vec2 uv = LTC_Uv( normal, viewDir, roughness ); vec4 t1 = texture2D( ltc_1, uv ); vec4 t2 = texture2D( ltc_2, uv ); mat3 mInv = mat3( vec3( t1.x, 0, t1.y ), vec3( 0, 1, 0 ), vec3( t1.z, 0, t1.w ) ); vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y ); reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords ); reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords ); } #endif void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { float dotNL = saturate( dot( geometryNormal, directLight.direction ) ); vec3 irradiance = dotNL * directLight.color; #ifdef USE_CLEARCOAT float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) ); vec3 ccIrradiance = dotNLcc * directLight.color; clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material ); #endif #ifdef USE_SHEEN sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness ); #endif reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material ); reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) { reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor ); } void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { #ifdef USE_CLEARCOAT clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness ); #endif #ifdef USE_SHEEN sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ); #endif vec3 singleScattering = vec3( 0.0 ); vec3 multiScattering = vec3( 0.0 ); vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI; #ifdef USE_IRIDESCENCE computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering ); #else computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering ); #endif vec3 totalScattering = singleScattering + multiScattering; vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) ); reflectedLight.indirectSpecular += radiance * singleScattering; reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance; reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance; } #define RE_Direct RE_Direct_Physical #define RE_Direct_RectArea RE_Direct_RectArea_Physical #define RE_IndirectDiffuse RE_IndirectDiffuse_Physical #define RE_IndirectSpecular RE_IndirectSpecular_Physical float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) { return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion ); }`,lights_fragment_begin=` vec3 geometryPosition = - vViewPosition; vec3 geometryNormal = normal; vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition ); vec3 geometryClearcoatNormal = vec3( 0.0 ); #ifdef USE_CLEARCOAT geometryClearcoatNormal = clearcoatNormal; #endif #ifdef USE_IRIDESCENCE float dotNVi = saturate( dot( normal, geometryViewDir ) ); if ( material.iridescenceThickness == 0.0 ) { material.iridescence = 0.0; } else { material.iridescence = saturate( material.iridescence ); } if ( material.iridescence > 0.0 ) { material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor ); material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi ); } #endif IncidentLight directLight; #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct ) PointLight pointLight; #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0 PointLightShadow pointLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) { pointLight = pointLights[ i ]; getPointLightInfo( pointLight, geometryPosition, directLight ); #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) pointLightShadow = pointLightShadows[ i ]; directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0; #endif RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); } #pragma unroll_loop_end #endif #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct ) SpotLight spotLight; vec4 spotColor; vec3 spotLightCoord; bool inSpotLightMap; #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0 SpotLightShadow spotLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) { spotLight = spotLights[ i ]; getSpotLightInfo( spotLight, geometryPosition, directLight ); #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS #else #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS ) #endif #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS ) spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w; inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) ); spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy ); directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color; #endif #undef SPOT_LIGHT_MAP_INDEX #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) spotLightShadow = spotLightShadows[ i ]; directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; #endif RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); } #pragma unroll_loop_end #endif #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct ) DirectionalLight directionalLight; #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0 DirectionalLightShadow directionalLightShadow; #endif #pragma unroll_loop_start for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) { directionalLight = directionalLights[ i ]; getDirectionalLightInfo( directionalLight, directLight ); #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) directionalLightShadow = directionalLightShadows[ i ]; directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; #endif RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); } #pragma unroll_loop_end #endif #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea ) RectAreaLight rectAreaLight; #pragma unroll_loop_start for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) { rectAreaLight = rectAreaLights[ i ]; RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); } #pragma unroll_loop_end #endif #if defined( RE_IndirectDiffuse ) vec3 iblIrradiance = vec3( 0.0 ); vec3 irradiance = getAmbientLightIrradiance( ambientLightColor ); #if defined( USE_LIGHT_PROBES ) irradiance += getLightProbeIrradiance( lightProbe, geometryNormal ); #endif #if ( NUM_HEMI_LIGHTS > 0 ) #pragma unroll_loop_start for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal ); } #pragma unroll_loop_end #endif #endif #if defined( RE_IndirectSpecular ) vec3 radiance = vec3( 0.0 ); vec3 clearcoatRadiance = vec3( 0.0 ); #endif`,lights_fragment_maps=`#if defined( RE_IndirectDiffuse ) #ifdef USE_LIGHTMAP vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity; irradiance += lightMapIrradiance; #endif #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV ) iblIrradiance += getIBLIrradiance( geometryNormal ); #endif #endif #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular ) #ifdef USE_ANISOTROPY radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy ); #else radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness ); #endif #ifdef USE_CLEARCOAT clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness ); #endif #endif`,lights_fragment_end=`#if defined( RE_IndirectDiffuse ) RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); #endif #if defined( RE_IndirectSpecular ) RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight ); #endif`,logdepthbuf_fragment=`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT ) gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5; #endif`,logdepthbuf_pars_fragment=`#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT ) uniform float logDepthBufFC; varying float vFragDepth; varying float vIsPerspective; #endif`,logdepthbuf_pars_vertex=`#ifdef USE_LOGDEPTHBUF #ifdef USE_LOGDEPTHBUF_EXT varying float vFragDepth; varying float vIsPerspective; #else uniform float logDepthBufFC; #endif #endif`,logdepthbuf_vertex=`#ifdef USE_LOGDEPTHBUF #ifdef USE_LOGDEPTHBUF_EXT vFragDepth = 1.0 + gl_Position.w; vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) ); #else if ( isPerspectiveMatrix( projectionMatrix ) ) { gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0; gl_Position.z *= gl_Position.w; } #endif #endif`,map_fragment=`#ifdef USE_MAP vec4 sampledDiffuseColor = texture2D( map, vMapUv ); #ifdef DECODE_VIDEO_TEXTURE sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w ); #endif diffuseColor *= sampledDiffuseColor; #endif`,map_pars_fragment=`#ifdef USE_MAP uniform sampler2D map; #endif`,map_particle_fragment=`#if defined( USE_MAP ) || defined( USE_ALPHAMAP ) #if defined( USE_POINTS_UV ) vec2 uv = vUv; #else vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy; #endif #endif #ifdef USE_MAP diffuseColor *= texture2D( map, uv ); #endif #ifdef USE_ALPHAMAP diffuseColor.a *= texture2D( alphaMap, uv ).g; #endif`,map_particle_pars_fragment=`#if defined( USE_POINTS_UV ) varying vec2 vUv; #else #if defined( USE_MAP ) || defined( USE_ALPHAMAP ) uniform mat3 uvTransform; #endif #endif #ifdef USE_MAP uniform sampler2D map; #endif #ifdef USE_ALPHAMAP uniform sampler2D alphaMap; #endif`,metalnessmap_fragment=`float metalnessFactor = metalness; #ifdef USE_METALNESSMAP vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv ); metalnessFactor *= texelMetalness.b; #endif`,metalnessmap_pars_fragment=`#ifdef USE_METALNESSMAP uniform sampler2D metalnessMap; #endif`,morphcolor_vertex=`#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE ) vColor *= morphTargetBaseInfluence; for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { #if defined( USE_COLOR_ALPHA ) if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ]; #elif defined( USE_COLOR ) if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ]; #endif } #endif`,morphnormal_vertex=`#ifdef USE_MORPHNORMALS objectNormal *= morphTargetBaseInfluence; #ifdef MORPHTARGETS_TEXTURE for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ]; } #else objectNormal += morphNormal0 * morphTargetInfluences[ 0 ]; objectNormal += morphNormal1 * morphTargetInfluences[ 1 ]; objectNormal += morphNormal2 * morphTargetInfluences[ 2 ]; objectNormal += morphNormal3 * morphTargetInfluences[ 3 ]; #endif #endif`,morphtarget_pars_vertex=`#ifdef USE_MORPHTARGETS uniform float morphTargetBaseInfluence; #ifdef MORPHTARGETS_TEXTURE uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ]; uniform sampler2DArray morphTargetsTexture; uniform ivec2 morphTargetsTextureSize; vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) { int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset; int y = texelIndex / morphTargetsTextureSize.x; int x = texelIndex - y * morphTargetsTextureSize.x; ivec3 morphUV = ivec3( x, y, morphTargetIndex ); return texelFetch( morphTargetsTexture, morphUV, 0 ); } #else #ifndef USE_MORPHNORMALS uniform float morphTargetInfluences[ 8 ]; #else uniform float morphTargetInfluences[ 4 ]; #endif #endif #endif`,morphtarget_vertex=`#ifdef USE_MORPHTARGETS transformed *= morphTargetBaseInfluence; #ifdef MORPHTARGETS_TEXTURE for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) { if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ]; } #else transformed += morphTarget0 * morphTargetInfluences[ 0 ]; transformed += morphTarget1 * morphTargetInfluences[ 1 ]; transformed += morphTarget2 * morphTargetInfluences[ 2 ]; transformed += morphTarget3 * morphTargetInfluences[ 3 ]; #ifndef USE_MORPHNORMALS transformed += morphTarget4 * morphTargetInfluences[ 4 ]; transformed += morphTarget5 * morphTargetInfluences[ 5 ]; transformed += morphTarget6 * morphTargetInfluences[ 6 ]; transformed += morphTarget7 * morphTargetInfluences[ 7 ]; #endif #endif #endif`,normal_fragment_begin=`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0; #ifdef FLAT_SHADED vec3 fdx = dFdx( vViewPosition ); vec3 fdy = dFdy( vViewPosition ); vec3 normal = normalize( cross( fdx, fdy ) ); #else vec3 normal = normalize( vNormal ); #ifdef DOUBLE_SIDED normal *= faceDirection; #endif #endif #if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) #ifdef USE_TANGENT mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); #else mat3 tbn = getTangentFrame( - vViewPosition, normal, #if defined( USE_NORMALMAP ) vNormalMapUv #elif defined( USE_CLEARCOAT_NORMALMAP ) vClearcoatNormalMapUv #else vUv #endif ); #endif #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) tbn[0] *= faceDirection; tbn[1] *= faceDirection; #endif #endif #ifdef USE_CLEARCOAT_NORMALMAP #ifdef USE_TANGENT mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal ); #else mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv ); #endif #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED ) tbn2[0] *= faceDirection; tbn2[1] *= faceDirection; #endif #endif vec3 nonPerturbedNormal = normal;`,normal_fragment_maps=`#ifdef USE_NORMALMAP_OBJECTSPACE normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; #ifdef FLIP_SIDED normal = - normal; #endif #ifdef DOUBLE_SIDED normal = normal * faceDirection; #endif normal = normalize( normalMatrix * normal ); #elif defined( USE_NORMALMAP_TANGENTSPACE ) vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0; mapN.xy *= normalScale; normal = normalize( tbn * mapN ); #elif defined( USE_BUMPMAP ) normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection ); #endif`,normal_pars_fragment=`#ifndef FLAT_SHADED varying vec3 vNormal; #ifdef USE_TANGENT varying vec3 vTangent; varying vec3 vBitangent; #endif #endif`,normal_pars_vertex=`#ifndef FLAT_SHADED varying vec3 vNormal; #ifdef USE_TANGENT varying vec3 vTangent; varying vec3 vBitangent; #endif #endif`,normal_vertex=`#ifndef FLAT_SHADED vNormal = normalize( transformedNormal ); #ifdef USE_TANGENT vTangent = normalize( transformedTangent ); vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w ); #endif #endif`,normalmap_pars_fragment=`#ifdef USE_NORMALMAP uniform sampler2D normalMap; uniform vec2 normalScale; #endif #ifdef USE_NORMALMAP_OBJECTSPACE uniform mat3 normalMatrix; #endif #if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) ) mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) { vec3 q0 = dFdx( eye_pos.xyz ); vec3 q1 = dFdy( eye_pos.xyz ); vec2 st0 = dFdx( uv.st ); vec2 st1 = dFdy( uv.st ); vec3 N = surf_norm; vec3 q1perp = cross( q1, N ); vec3 q0perp = cross( N, q0 ); vec3 T = q1perp * st0.x + q0perp * st1.x; vec3 B = q1perp * st0.y + q0perp * st1.y; float det = max( dot( T, T ), dot( B, B ) ); float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det ); return mat3( T * scale, B * scale, N ); } #endif`,clearcoat_normal_fragment_begin=`#ifdef USE_CLEARCOAT vec3 clearcoatNormal = nonPerturbedNormal; #endif`,clearcoat_normal_fragment_maps=`#ifdef USE_CLEARCOAT_NORMALMAP vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0; clearcoatMapN.xy *= clearcoatNormalScale; clearcoatNormal = normalize( tbn2 * clearcoatMapN ); #endif`,clearcoat_pars_fragment=`#ifdef USE_CLEARCOATMAP uniform sampler2D clearcoatMap; #endif #ifdef USE_CLEARCOAT_NORMALMAP uniform sampler2D clearcoatNormalMap; uniform vec2 clearcoatNormalScale; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP uniform sampler2D clearcoatRoughnessMap; #endif`,iridescence_pars_fragment=`#ifdef USE_IRIDESCENCEMAP uniform sampler2D iridescenceMap; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP uniform sampler2D iridescenceThicknessMap; #endif`,opaque_fragment=`#ifdef OPAQUE diffuseColor.a = 1.0; #endif #ifdef USE_TRANSMISSION diffuseColor.a *= material.transmissionAlpha; #endif gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,packing=`vec3 packNormalToRGB( const in vec3 normal ) { return normalize( normal ) * 0.5 + 0.5; } vec3 unpackRGBToNormal( const in vec3 rgb ) { return 2.0 * rgb.xyz - 1.0; } const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.; const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. ); const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. ); const float ShiftRight8 = 1. / 256.; vec4 packDepthToRGBA( const in float v ) { vec4 r = vec4( fract( v * PackFactors ), v ); r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale; } float unpackRGBAToDepth( const in vec4 v ) { return dot( v, UnpackFactors ); } vec2 packDepthToRG( in highp float v ) { return packDepthToRGBA( v ).yx; } float unpackRGToDepth( const in highp vec2 v ) { return unpackRGBAToDepth( vec4( v.xy, 0.0, 0.0 ) ); } vec4 pack2HalfToRGBA( vec2 v ) { vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) ); return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w ); } vec2 unpackRGBATo2Half( vec4 v ) { return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) ); } float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) { return ( viewZ + near ) / ( near - far ); } float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) { return depth * ( near - far ) - near; } float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) { return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ ); } float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) { return ( near * far ) / ( ( far - near ) * depth - far ); }`,premultiplied_alpha_fragment=`#ifdef PREMULTIPLIED_ALPHA gl_FragColor.rgb *= gl_FragColor.a; #endif`,project_vertex=`vec4 mvPosition = vec4( transformed, 1.0 ); #ifdef USE_BATCHING mvPosition = batchingMatrix * mvPosition; #endif #ifdef USE_INSTANCING mvPosition = instanceMatrix * mvPosition; #endif mvPosition = modelViewMatrix * mvPosition; gl_Position = projectionMatrix * mvPosition;`,dithering_fragment=`#ifdef DITHERING gl_FragColor.rgb = dithering( gl_FragColor.rgb ); #endif`,dithering_pars_fragment=`#ifdef DITHERING vec3 dithering( vec3 color ) { float grid_position = rand( gl_FragCoord.xy ); vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 ); dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position ); return color + dither_shift_RGB; } #endif`,roughnessmap_fragment=`float roughnessFactor = roughness; #ifdef USE_ROUGHNESSMAP vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv ); roughnessFactor *= texelRoughness.g; #endif`,roughnessmap_pars_fragment=`#ifdef USE_ROUGHNESSMAP uniform sampler2D roughnessMap; #endif`,shadowmap_pars_fragment=`#if NUM_SPOT_LIGHT_COORDS > 0 varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; #endif #if NUM_SPOT_LIGHT_MAPS > 0 uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ]; #endif #ifdef USE_SHADOWMAP #if NUM_DIR_LIGHT_SHADOWS > 0 uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ]; varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; struct DirectionalLightShadow { float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; }; uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; #endif #if NUM_SPOT_LIGHT_SHADOWS > 0 uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ]; struct SpotLightShadow { float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; }; uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; #endif #if NUM_POINT_LIGHT_SHADOWS > 0 uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ]; varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; struct PointLightShadow { float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; float shadowCameraNear; float shadowCameraFar; }; uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; #endif float texture2DCompare( sampler2D depths, vec2 uv, float compare ) { return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) ); } vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) { return unpackRGBATo2Half( texture2D( shadow, uv ) ); } float VSMShadow (sampler2D shadow, vec2 uv, float compare ){ float occlusion = 1.0; vec2 distribution = texture2DDistribution( shadow, uv ); float hard_shadow = step( compare , distribution.x ); if (hard_shadow != 1.0 ) { float distance = compare - distribution.x ; float variance = max( 0.00000, distribution.y * distribution.y ); float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 ); } return occlusion; } float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) { float shadow = 1.0; shadowCoord.xyz /= shadowCoord.w; shadowCoord.z += shadowBias; bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0; bool frustumTest = inFrustum && shadowCoord.z <= 1.0; if ( frustumTest ) { #if defined( SHADOWMAP_TYPE_PCF ) vec2 texelSize = vec2( 1.0 ) / shadowMapSize; float dx0 = - texelSize.x * shadowRadius; float dy0 = - texelSize.y * shadowRadius; float dx1 = + texelSize.x * shadowRadius; float dy1 = + texelSize.y * shadowRadius; float dx2 = dx0 / 2.0; float dy2 = dy0 / 2.0; float dx3 = dx1 / 2.0; float dy3 = dy1 / 2.0; shadow = ( texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) + texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z ) ) * ( 1.0 / 17.0 ); #elif defined( SHADOWMAP_TYPE_PCF_SOFT ) vec2 texelSize = vec2( 1.0 ) / shadowMapSize; float dx = texelSize.x; float dy = texelSize.y; vec2 uv = shadowCoord.xy; vec2 f = fract( uv * shadowMapSize + 0.5 ); uv -= f * texelSize; shadow = ( texture2DCompare( shadowMap, uv, shadowCoord.z ) + texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) + texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) + texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) + mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ), f.x ) + mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ), f.x ) + mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ), f.y ) + mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ), f.y ) + mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ), f.x ), mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ), f.x ), f.y ) ) * ( 1.0 / 9.0 ); #elif defined( SHADOWMAP_TYPE_VSM ) shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z ); #else shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ); #endif } return shadow; } vec2 cubeToUV( vec3 v, float texelSizeY ) { vec3 absV = abs( v ); float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) ); absV *= scaleToCube; v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY ); vec2 planar = v.xy; float almostATexel = 1.5 * texelSizeY; float almostOne = 1.0 - almostATexel; if ( absV.z >= almostOne ) { if ( v.z > 0.0 ) planar.x = 4.0 - v.x; } else if ( absV.x >= almostOne ) { float signX = sign( v.x ); planar.x = v.z * signX + 2.0 * signX; } else if ( absV.y >= almostOne ) { float signY = sign( v.y ); planar.x = v.x + 2.0 * signY + 2.0; planar.y = v.z * signY - 2.0; } return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 ); } float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) { vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) ); vec3 lightToPosition = shadowCoord.xyz; float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias; vec3 bd3D = normalize( lightToPosition ); #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM ) vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y; return ( texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) + texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) + texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp ) ) * ( 1.0 / 9.0 ); #else return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ); #endif } #endif`,shadowmap_pars_vertex=`#if NUM_SPOT_LIGHT_COORDS > 0 uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ]; varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ]; #endif #ifdef USE_SHADOWMAP #if NUM_DIR_LIGHT_SHADOWS > 0 uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ]; varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ]; struct DirectionalLightShadow { float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; }; uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ]; #endif #if NUM_SPOT_LIGHT_SHADOWS > 0 struct SpotLightShadow { float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; }; uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ]; #endif #if NUM_POINT_LIGHT_SHADOWS > 0 uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ]; varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ]; struct PointLightShadow { float shadowBias; float shadowNormalBias; float shadowRadius; vec2 shadowMapSize; float shadowCameraNear; float shadowCameraFar; }; uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ]; #endif #endif`,shadowmap_vertex=`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 ) vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); vec4 shadowWorldPosition; #endif #if defined( USE_SHADOWMAP ) #if NUM_DIR_LIGHT_SHADOWS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 ); vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition; } #pragma unroll_loop_end #endif #if NUM_POINT_LIGHT_SHADOWS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 ); vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition; } #pragma unroll_loop_end #endif #endif #if NUM_SPOT_LIGHT_COORDS > 0 #pragma unroll_loop_start for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) { shadowWorldPosition = worldPosition; #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS ) shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias; #endif vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition; } #pragma unroll_loop_end #endif`,shadowmask_pars_fragment=`float getShadowMask() { float shadow = 1.0; #ifdef USE_SHADOWMAP #if NUM_DIR_LIGHT_SHADOWS > 0 DirectionalLightShadow directionalLight; #pragma unroll_loop_start for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) { directionalLight = directionalLightShadows[ i ]; shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0; } #pragma unroll_loop_end #endif #if NUM_SPOT_LIGHT_SHADOWS > 0 SpotLightShadow spotLight; #pragma unroll_loop_start for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) { spotLight = spotLightShadows[ i ]; shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0; } #pragma unroll_loop_end #endif #if NUM_POINT_LIGHT_SHADOWS > 0 PointLightShadow pointLight; #pragma unroll_loop_start for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) { pointLight = pointLightShadows[ i ]; shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0; } #pragma unroll_loop_end #endif #endif return shadow; }`,skinbase_vertex=`#ifdef USE_SKINNING mat4 boneMatX = getBoneMatrix( skinIndex.x ); mat4 boneMatY = getBoneMatrix( skinIndex.y ); mat4 boneMatZ = getBoneMatrix( skinIndex.z ); mat4 boneMatW = getBoneMatrix( skinIndex.w ); #endif`,skinning_pars_vertex=`#ifdef USE_SKINNING uniform mat4 bindMatrix; uniform mat4 bindMatrixInverse; uniform highp sampler2D boneTexture; mat4 getBoneMatrix( const in float i ) { int size = textureSize( boneTexture, 0 ).x; int j = int( i ) * 4; int x = j % size; int y = j / size; vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 ); vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 ); vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 ); vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 ); return mat4( v1, v2, v3, v4 ); } #endif`,skinning_vertex=`#ifdef USE_SKINNING vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 ); vec4 skinned = vec4( 0.0 ); skinned += boneMatX * skinVertex * skinWeight.x; skinned += boneMatY * skinVertex * skinWeight.y; skinned += boneMatZ * skinVertex * skinWeight.z; skinned += boneMatW * skinVertex * skinWeight.w; transformed = ( bindMatrixInverse * skinned ).xyz; #endif`,skinnormal_vertex=`#ifdef USE_SKINNING mat4 skinMatrix = mat4( 0.0 ); skinMatrix += skinWeight.x * boneMatX; skinMatrix += skinWeight.y * boneMatY; skinMatrix += skinWeight.z * boneMatZ; skinMatrix += skinWeight.w * boneMatW; skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix; objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz; #ifdef USE_TANGENT objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz; #endif #endif`,specularmap_fragment=`float specularStrength; #ifdef USE_SPECULARMAP vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv ); specularStrength = texelSpecular.r; #else specularStrength = 1.0; #endif`,specularmap_pars_fragment=`#ifdef USE_SPECULARMAP uniform sampler2D specularMap; #endif`,tonemapping_fragment=`#if defined( TONE_MAPPING ) gl_FragColor.rgb = toneMapping( gl_FragColor.rgb ); #endif`,tonemapping_pars_fragment=`#ifndef saturate #define saturate( a ) clamp( a, 0.0, 1.0 ) #endif uniform float toneMappingExposure; vec3 LinearToneMapping( vec3 color ) { return saturate( toneMappingExposure * color ); } vec3 ReinhardToneMapping( vec3 color ) { color *= toneMappingExposure; return saturate( color / ( vec3( 1.0 ) + color ) ); } vec3 OptimizedCineonToneMapping( vec3 color ) { color *= toneMappingExposure; color = max( vec3( 0.0 ), color - 0.004 ); return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) ); } vec3 RRTAndODTFit( vec3 v ) { vec3 a = v * ( v + 0.0245786 ) - 0.000090537; vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081; return a / b; } vec3 ACESFilmicToneMapping( vec3 color ) { const mat3 ACESInputMat = mat3( vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ), vec3( 0.04823, 0.01566, 0.83777 ) ); const mat3 ACESOutputMat = mat3( vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ), vec3( -0.07367, -0.00605, 1.07602 ) ); color *= toneMappingExposure / 0.6; color = ACESInputMat * color; color = RRTAndODTFit( color ); color = ACESOutputMat * color; return saturate( color ); } const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3( vec3( 1.6605, - 0.1246, - 0.0182 ), vec3( - 0.5876, 1.1329, - 0.1006 ), vec3( - 0.0728, - 0.0083, 1.1187 ) ); const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3( vec3( 0.6274, 0.0691, 0.0164 ), vec3( 0.3293, 0.9195, 0.0880 ), vec3( 0.0433, 0.0113, 0.8956 ) ); vec3 agxDefaultContrastApprox( vec3 x ) { vec3 x2 = x * x; vec3 x4 = x2 * x2; return + 15.5 * x4 * x2 - 40.14 * x4 * x + 31.96 * x4 - 6.868 * x2 * x + 0.4298 * x2 + 0.1191 * x - 0.00232; } vec3 AgXToneMapping( vec3 color ) { const mat3 AgXInsetMatrix = mat3( vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ), vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ), vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 ) ); const mat3 AgXOutsetMatrix = mat3( vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ), vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ), vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 ) ); const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069; color = LINEAR_SRGB_TO_LINEAR_REC2020 * color; color *= toneMappingExposure; color = AgXInsetMatrix * color; color = max( color, 1e-10 ); color = log2( color ); color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv ); color = clamp( color, 0.0, 1.0 ); color = agxDefaultContrastApprox( color ); color = AgXOutsetMatrix * color; color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) ); color = LINEAR_REC2020_TO_LINEAR_SRGB * color; return color; } vec3 CustomToneMapping( vec3 color ) { return color; }`,transmission_fragment=`#ifdef USE_TRANSMISSION material.transmission = transmission; material.transmissionAlpha = 1.0; material.thickness = thickness; material.attenuationDistance = attenuationDistance; material.attenuationColor = attenuationColor; #ifdef USE_TRANSMISSIONMAP material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r; #endif #ifdef USE_THICKNESSMAP material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g; #endif vec3 pos = vWorldPosition; vec3 v = normalize( cameraPosition - pos ); vec3 n = inverseTransformDirection( normal, viewMatrix ); vec4 transmitted = getIBLVolumeRefraction( n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90, pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness, material.attenuationColor, material.attenuationDistance ); material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission ); totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission ); #endif`,transmission_pars_fragment=`#ifdef USE_TRANSMISSION uniform float transmission; uniform float thickness; uniform float attenuationDistance; uniform vec3 attenuationColor; #ifdef USE_TRANSMISSIONMAP uniform sampler2D transmissionMap; #endif #ifdef USE_THICKNESSMAP uniform sampler2D thicknessMap; #endif uniform vec2 transmissionSamplerSize; uniform sampler2D transmissionSamplerMap; uniform mat4 modelMatrix; uniform mat4 projectionMatrix; varying vec3 vWorldPosition; float w0( float a ) { return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 ); } float w1( float a ) { return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 ); } float w2( float a ){ return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 ); } float w3( float a ) { return ( 1.0 / 6.0 ) * ( a * a * a ); } float g0( float a ) { return w0( a ) + w1( a ); } float g1( float a ) { return w2( a ) + w3( a ); } float h0( float a ) { return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) ); } float h1( float a ) { return 1.0 + w3( a ) / ( w2( a ) + w3( a ) ); } vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) { uv = uv * texelSize.zw + 0.5; vec2 iuv = floor( uv ); vec2 fuv = fract( uv ); float g0x = g0( fuv.x ); float g1x = g1( fuv.x ); float h0x = h0( fuv.x ); float h1x = h1( fuv.x ); float h0y = h0( fuv.y ); float h1y = h1( fuv.y ); vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy; vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy; return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) + g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) ); } vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) { vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) ); vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) ); vec2 fLodSizeInv = 1.0 / fLodSize; vec2 cLodSizeInv = 1.0 / cLodSize; vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) ); vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) ); return mix( fSample, cSample, fract( lod ) ); } vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) { vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior ); vec3 modelScale; modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) ); modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) ); modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) ); return normalize( refractionVector ) * thickness * modelScale; } float applyIorToRoughness( const in float roughness, const in float ior ) { return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 ); } vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) { float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior ); return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod ); } vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) { if ( isinf( attenuationDistance ) ) { return vec3( 1.0 ); } else { vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance; vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance; } } vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor, const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix, const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness, const in vec3 attenuationColor, const in float attenuationDistance ) { vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix ); vec3 refractedRayExit = position + transmissionRay; vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 ); vec2 refractionCoords = ndcPos.xy / ndcPos.w; refractionCoords += 1.0; refractionCoords /= 2.0; vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior ); vec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance ); vec3 attenuatedColor = transmittance * transmittedLight.rgb; vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness ); float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0; return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor ); } #endif`,uv_pars_fragment=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) varying vec2 vUv; #endif #ifdef USE_MAP varying vec2 vMapUv; #endif #ifdef USE_ALPHAMAP varying vec2 vAlphaMapUv; #endif #ifdef USE_LIGHTMAP varying vec2 vLightMapUv; #endif #ifdef USE_AOMAP varying vec2 vAoMapUv; #endif #ifdef USE_BUMPMAP varying vec2 vBumpMapUv; #endif #ifdef USE_NORMALMAP varying vec2 vNormalMapUv; #endif #ifdef USE_EMISSIVEMAP varying vec2 vEmissiveMapUv; #endif #ifdef USE_METALNESSMAP varying vec2 vMetalnessMapUv; #endif #ifdef USE_ROUGHNESSMAP varying vec2 vRoughnessMapUv; #endif #ifdef USE_ANISOTROPYMAP varying vec2 vAnisotropyMapUv; #endif #ifdef USE_CLEARCOATMAP varying vec2 vClearcoatMapUv; #endif #ifdef USE_CLEARCOAT_NORMALMAP varying vec2 vClearcoatNormalMapUv; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP varying vec2 vClearcoatRoughnessMapUv; #endif #ifdef USE_IRIDESCENCEMAP varying vec2 vIridescenceMapUv; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP varying vec2 vIridescenceThicknessMapUv; #endif #ifdef USE_SHEEN_COLORMAP varying vec2 vSheenColorMapUv; #endif #ifdef USE_SHEEN_ROUGHNESSMAP varying vec2 vSheenRoughnessMapUv; #endif #ifdef USE_SPECULARMAP varying vec2 vSpecularMapUv; #endif #ifdef USE_SPECULAR_COLORMAP varying vec2 vSpecularColorMapUv; #endif #ifdef USE_SPECULAR_INTENSITYMAP varying vec2 vSpecularIntensityMapUv; #endif #ifdef USE_TRANSMISSIONMAP uniform mat3 transmissionMapTransform; varying vec2 vTransmissionMapUv; #endif #ifdef USE_THICKNESSMAP uniform mat3 thicknessMapTransform; varying vec2 vThicknessMapUv; #endif`,uv_pars_vertex=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) varying vec2 vUv; #endif #ifdef USE_MAP uniform mat3 mapTransform; varying vec2 vMapUv; #endif #ifdef USE_ALPHAMAP uniform mat3 alphaMapTransform; varying vec2 vAlphaMapUv; #endif #ifdef USE_LIGHTMAP uniform mat3 lightMapTransform; varying vec2 vLightMapUv; #endif #ifdef USE_AOMAP uniform mat3 aoMapTransform; varying vec2 vAoMapUv; #endif #ifdef USE_BUMPMAP uniform mat3 bumpMapTransform; varying vec2 vBumpMapUv; #endif #ifdef USE_NORMALMAP uniform mat3 normalMapTransform; varying vec2 vNormalMapUv; #endif #ifdef USE_DISPLACEMENTMAP uniform mat3 displacementMapTransform; varying vec2 vDisplacementMapUv; #endif #ifdef USE_EMISSIVEMAP uniform mat3 emissiveMapTransform; varying vec2 vEmissiveMapUv; #endif #ifdef USE_METALNESSMAP uniform mat3 metalnessMapTransform; varying vec2 vMetalnessMapUv; #endif #ifdef USE_ROUGHNESSMAP uniform mat3 roughnessMapTransform; varying vec2 vRoughnessMapUv; #endif #ifdef USE_ANISOTROPYMAP uniform mat3 anisotropyMapTransform; varying vec2 vAnisotropyMapUv; #endif #ifdef USE_CLEARCOATMAP uniform mat3 clearcoatMapTransform; varying vec2 vClearcoatMapUv; #endif #ifdef USE_CLEARCOAT_NORMALMAP uniform mat3 clearcoatNormalMapTransform; varying vec2 vClearcoatNormalMapUv; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP uniform mat3 clearcoatRoughnessMapTransform; varying vec2 vClearcoatRoughnessMapUv; #endif #ifdef USE_SHEEN_COLORMAP uniform mat3 sheenColorMapTransform; varying vec2 vSheenColorMapUv; #endif #ifdef USE_SHEEN_ROUGHNESSMAP uniform mat3 sheenRoughnessMapTransform; varying vec2 vSheenRoughnessMapUv; #endif #ifdef USE_IRIDESCENCEMAP uniform mat3 iridescenceMapTransform; varying vec2 vIridescenceMapUv; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP uniform mat3 iridescenceThicknessMapTransform; varying vec2 vIridescenceThicknessMapUv; #endif #ifdef USE_SPECULARMAP uniform mat3 specularMapTransform; varying vec2 vSpecularMapUv; #endif #ifdef USE_SPECULAR_COLORMAP uniform mat3 specularColorMapTransform; varying vec2 vSpecularColorMapUv; #endif #ifdef USE_SPECULAR_INTENSITYMAP uniform mat3 specularIntensityMapTransform; varying vec2 vSpecularIntensityMapUv; #endif #ifdef USE_TRANSMISSIONMAP uniform mat3 transmissionMapTransform; varying vec2 vTransmissionMapUv; #endif #ifdef USE_THICKNESSMAP uniform mat3 thicknessMapTransform; varying vec2 vThicknessMapUv; #endif`,uv_vertex=`#if defined( USE_UV ) || defined( USE_ANISOTROPY ) vUv = vec3( uv, 1 ).xy; #endif #ifdef USE_MAP vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy; #endif #ifdef USE_ALPHAMAP vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy; #endif #ifdef USE_LIGHTMAP vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy; #endif #ifdef USE_AOMAP vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy; #endif #ifdef USE_BUMPMAP vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy; #endif #ifdef USE_NORMALMAP vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy; #endif #ifdef USE_DISPLACEMENTMAP vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy; #endif #ifdef USE_EMISSIVEMAP vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy; #endif #ifdef USE_METALNESSMAP vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_ROUGHNESSMAP vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_ANISOTROPYMAP vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy; #endif #ifdef USE_CLEARCOATMAP vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy; #endif #ifdef USE_CLEARCOAT_NORMALMAP vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy; #endif #ifdef USE_CLEARCOAT_ROUGHNESSMAP vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_IRIDESCENCEMAP vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy; #endif #ifdef USE_IRIDESCENCE_THICKNESSMAP vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_SHEEN_COLORMAP vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy; #endif #ifdef USE_SHEEN_ROUGHNESSMAP vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy; #endif #ifdef USE_SPECULARMAP vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy; #endif #ifdef USE_SPECULAR_COLORMAP vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy; #endif #ifdef USE_SPECULAR_INTENSITYMAP vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy; #endif #ifdef USE_TRANSMISSIONMAP vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy; #endif #ifdef USE_THICKNESSMAP vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy; #endif`,worldpos_vertex=`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0 vec4 worldPosition = vec4( transformed, 1.0 ); #ifdef USE_BATCHING worldPosition = batchingMatrix * worldPosition; #endif #ifdef USE_INSTANCING worldPosition = instanceMatrix * worldPosition; #endif worldPosition = modelMatrix * worldPosition; #endif`;const vertex$h=`varying vec2 vUv; uniform mat3 uvTransform; void main() { vUv = ( uvTransform * vec3( uv, 1 ) ).xy; gl_Position = vec4( position.xy, 1.0, 1.0 ); }`,fragment$h=`uniform sampler2D t2D; uniform float backgroundIntensity; varying vec2 vUv; void main() { vec4 texColor = texture2D( t2D, vUv ); #ifdef DECODE_VIDEO_TEXTURE texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w ); #endif texColor.rgb *= backgroundIntensity; gl_FragColor = texColor; #include #include }`,vertex$g=`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include gl_Position.z = gl_Position.w; }`,fragment$g=`#ifdef ENVMAP_TYPE_CUBE uniform samplerCube envMap; #elif defined( ENVMAP_TYPE_CUBE_UV ) uniform sampler2D envMap; #endif uniform float flipEnvMap; uniform float backgroundBlurriness; uniform float backgroundIntensity; varying vec3 vWorldDirection; #include void main() { #ifdef ENVMAP_TYPE_CUBE vec4 texColor = textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ); #elif defined( ENVMAP_TYPE_CUBE_UV ) vec4 texColor = textureCubeUV( envMap, vWorldDirection, backgroundBlurriness ); #else vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 ); #endif texColor.rgb *= backgroundIntensity; gl_FragColor = texColor; #include #include }`,vertex$f=`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include gl_Position.z = gl_Position.w; }`,fragment$f=`uniform samplerCube tCube; uniform float tFlip; uniform float opacity; varying vec3 vWorldDirection; void main() { vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) ); gl_FragColor = texColor; gl_FragColor.a *= opacity; #include #include }`,vertex$e=`#include #include #include #include #include #include #include #include varying vec2 vHighPrecisionZW; void main() { #include #include #include #ifdef USE_DISPLACEMENTMAP #include #include #include #endif #include #include #include #include #include #include #include vHighPrecisionZW = gl_Position.zw; }`,fragment$e=`#if DEPTH_PACKING == 3200 uniform float opacity; #endif #include #include #include #include #include #include #include #include #include varying vec2 vHighPrecisionZW; void main() { #include vec4 diffuseColor = vec4( 1.0 ); #if DEPTH_PACKING == 3200 diffuseColor.a = opacity; #endif #include #include #include #include #include float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5; #if DEPTH_PACKING == 3200 gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity ); #elif DEPTH_PACKING == 3201 gl_FragColor = packDepthToRGBA( fragCoordZ ); #endif }`,vertex$d=`#define DISTANCE varying vec3 vWorldPosition; #include #include #include #include #include #include #include void main() { #include #include #include #ifdef USE_DISPLACEMENTMAP #include #include #include #endif #include #include #include #include #include #include #include vWorldPosition = worldPosition.xyz; }`,fragment$d=`#define DISTANCE uniform vec3 referencePosition; uniform float nearDistance; uniform float farDistance; varying vec3 vWorldPosition; #include #include #include #include #include #include #include #include void main () { #include vec4 diffuseColor = vec4( 1.0 ); #include #include #include #include float dist = length( vWorldPosition - referencePosition ); dist = ( dist - nearDistance ) / ( farDistance - nearDistance ); dist = saturate( dist ); gl_FragColor = packDepthToRGBA( dist ); }`,vertex$c=`varying vec3 vWorldDirection; #include void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include }`,fragment$c=`uniform sampler2D tEquirect; varying vec3 vWorldDirection; #include void main() { vec3 direction = normalize( vWorldDirection ); vec2 sampleUV = equirectUv( direction ); gl_FragColor = texture2D( tEquirect, sampleUV ); #include #include }`,vertex$b=`uniform float scale; attribute float lineDistance; varying float vLineDistance; #include #include #include #include #include #include #include void main() { vLineDistance = scale * lineDistance; #include #include #include #include #include #include #include #include #include }`,fragment$b=`uniform vec3 diffuse; uniform float opacity; uniform float dashSize; uniform float totalSize; varying float vLineDistance; #include #include #include #include #include #include #include void main() { #include if ( mod( vLineDistance, totalSize ) > dashSize ) { discard; } vec3 outgoingLight = vec3( 0.0 ); vec4 diffuseColor = vec4( diffuse, opacity ); #include #include #include outgoingLight = diffuseColor.rgb; #include #include #include #include #include }`,vertex$a=`#include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING ) #include #include #include #include #include #endif #include #include #include #include #include #include #include #include #include }`,fragment$a=`uniform vec3 diffuse; uniform float opacity; #ifndef FLAT_SHADED varying vec3 vNormal; #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include vec4 diffuseColor = vec4( diffuse, opacity ); #include #include #include #include #include #include #include ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); #ifdef USE_LIGHTMAP vec4 lightMapTexel = texture2D( lightMap, vLightMapUv ); reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI; #else reflectedLight.indirectDiffuse += vec3( 1.0 ); #endif #include reflectedLight.indirectDiffuse *= diffuseColor.rgb; vec3 outgoingLight = reflectedLight.indirectDiffuse; #include #include #include #include #include #include #include }`,vertex$9=`#define LAMBERT varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; #include #include #include #include }`,fragment$9=`#define LAMBERT uniform vec3 diffuse; uniform vec3 emissive; uniform float opacity; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include vec4 diffuseColor = vec4( diffuse, opacity ); ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; #include #include #include #include #include #include #include }`,vertex$8=`#define MATCAP varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; }`,fragment$8=`#define MATCAP uniform vec3 diffuse; uniform float opacity; uniform sampler2D matcap; varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include vec4 diffuseColor = vec4( diffuse, opacity ); #include #include #include #include #include #include #include #include vec3 viewDir = normalize( vViewPosition ); vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) ); vec3 y = cross( viewDir, x ); vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5; #ifdef USE_MATCAP vec4 matcapColor = texture2D( matcap, uv ); #else vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 ); #endif vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb; #include #include #include #include #include #include }`,vertex$7=`#define NORMAL #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) varying vec3 vViewPosition; #endif #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) vViewPosition = - mvPosition.xyz; #endif }`,fragment$7=`#define NORMAL uniform float opacity; #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE ) varying vec3 vViewPosition; #endif #include #include #include #include #include #include #include void main() { #include #include #include #include gl_FragColor = vec4( packNormalToRGB( normal ), opacity ); #ifdef OPAQUE gl_FragColor.a = 1.0; #endif }`,vertex$6=`#define PHONG varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; #include #include #include #include }`,fragment$6=`#define PHONG uniform vec3 diffuse; uniform vec3 emissive; uniform vec3 specular; uniform float shininess; uniform float opacity; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include vec4 diffuseColor = vec4( diffuse, opacity ); ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance; #include #include #include #include #include #include #include }`,vertex$5=`#define STANDARD varying vec3 vViewPosition; #ifdef USE_TRANSMISSION varying vec3 vWorldPosition; #endif #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; #include #include #include #ifdef USE_TRANSMISSION vWorldPosition = worldPosition.xyz; #endif }`,fragment$5=`#define STANDARD #ifdef PHYSICAL #define IOR #define USE_SPECULAR #endif uniform vec3 diffuse; uniform vec3 emissive; uniform float roughness; uniform float metalness; uniform float opacity; #ifdef IOR uniform float ior; #endif #ifdef USE_SPECULAR uniform float specularIntensity; uniform vec3 specularColor; #ifdef USE_SPECULAR_COLORMAP uniform sampler2D specularColorMap; #endif #ifdef USE_SPECULAR_INTENSITYMAP uniform sampler2D specularIntensityMap; #endif #endif #ifdef USE_CLEARCOAT uniform float clearcoat; uniform float clearcoatRoughness; #endif #ifdef USE_IRIDESCENCE uniform float iridescence; uniform float iridescenceIOR; uniform float iridescenceThicknessMinimum; uniform float iridescenceThicknessMaximum; #endif #ifdef USE_SHEEN uniform vec3 sheenColor; uniform float sheenRoughness; #ifdef USE_SHEEN_COLORMAP uniform sampler2D sheenColorMap; #endif #ifdef USE_SHEEN_ROUGHNESSMAP uniform sampler2D sheenRoughnessMap; #endif #endif #ifdef USE_ANISOTROPY uniform vec2 anisotropyVector; #ifdef USE_ANISOTROPYMAP uniform sampler2D anisotropyMap; #endif #endif varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include vec4 diffuseColor = vec4( diffuse, opacity ); ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse; vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular; #include vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance; #ifdef USE_SHEEN float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor ); outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect; #endif #ifdef USE_CLEARCOAT float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) ); vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc ); outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat; #endif #include #include #include #include #include #include }`,vertex$4=`#define TOON varying vec3 vViewPosition; #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include vViewPosition = - mvPosition.xyz; #include #include #include }`,fragment$4=`#define TOON uniform vec3 diffuse; uniform vec3 emissive; uniform float opacity; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void main() { #include vec4 diffuseColor = vec4( diffuse, opacity ); ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); vec3 totalEmissiveRadiance = emissive; #include #include #include #include #include #include #include #include #include #include #include #include #include #include vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; #include #include #include #include #include #include }`,vertex$3=`uniform float size; uniform float scale; #include #include #include #include #include #include #ifdef USE_POINTS_UV varying vec2 vUv; uniform mat3 uvTransform; #endif void main() { #ifdef USE_POINTS_UV vUv = ( uvTransform * vec3( uv, 1 ) ).xy; #endif #include #include #include #include #include gl_PointSize = size; #ifdef USE_SIZEATTENUATION bool isPerspective = isPerspectiveMatrix( projectionMatrix ); if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z ); #endif #include #include #include #include }`,fragment$3=`uniform vec3 diffuse; uniform float opacity; #include #include #include #include #include #include #include #include void main() { #include vec3 outgoingLight = vec3( 0.0 ); vec4 diffuseColor = vec4( diffuse, opacity ); #include #include #include #include #include outgoingLight = diffuseColor.rgb; #include #include #include #include #include }`,vertex$2=`#include #include #include #include #include #include #include void main() { #include #include #include #include #include #include #include #include #include #include #include #include #include #include }`,fragment$2=`uniform vec3 color; uniform float opacity; #include #include #include #include #include #include #include #include void main() { #include gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) ); #include #include #include }`,vertex$1=`uniform float rotation; uniform vec2 center; #include #include #include #include #include void main() { #include vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 ); vec2 scale; scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) ); scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) ); #ifndef USE_SIZEATTENUATION bool isPerspective = isPerspectiveMatrix( projectionMatrix ); if ( isPerspective ) scale *= - mvPosition.z; #endif vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale; vec2 rotatedPosition; rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y; rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y; mvPosition.xy += rotatedPosition; gl_Position = projectionMatrix * mvPosition; #include #include #include }`,fragment$1=`uniform vec3 diffuse; uniform float opacity; #include #include #include #include #include #include #include #include #include void main() { #include vec3 outgoingLight = vec3( 0.0 ); vec4 diffuseColor = vec4( diffuse, opacity ); #include #include #include #include #include outgoingLight = diffuseColor.rgb; #include #include #include #include }`,ShaderChunk={alphahash_fragment,alphahash_pars_fragment,alphamap_fragment,alphamap_pars_fragment,alphatest_fragment,alphatest_pars_fragment,aomap_fragment,aomap_pars_fragment,batching_pars_vertex,batching_vertex,begin_vertex,beginnormal_vertex,bsdfs,iridescence_fragment,bumpmap_pars_fragment,clipping_planes_fragment,clipping_planes_pars_fragment,clipping_planes_pars_vertex,clipping_planes_vertex,color_fragment,color_pars_fragment,color_pars_vertex,color_vertex,common,cube_uv_reflection_fragment,defaultnormal_vertex,displacementmap_pars_vertex,displacementmap_vertex,emissivemap_fragment,emissivemap_pars_fragment,colorspace_fragment,colorspace_pars_fragment,envmap_fragment,envmap_common_pars_fragment,envmap_pars_fragment,envmap_pars_vertex,envmap_physical_pars_fragment,envmap_vertex,fog_vertex,fog_pars_vertex,fog_fragment,fog_pars_fragment,gradientmap_pars_fragment,lightmap_fragment,lightmap_pars_fragment,lights_lambert_fragment,lights_lambert_pars_fragment,lights_pars_begin,lights_toon_fragment,lights_toon_pars_fragment,lights_phong_fragment,lights_phong_pars_fragment,lights_physical_fragment,lights_physical_pars_fragment,lights_fragment_begin,lights_fragment_maps,lights_fragment_end,logdepthbuf_fragment,logdepthbuf_pars_fragment,logdepthbuf_pars_vertex,logdepthbuf_vertex,map_fragment,map_pars_fragment,map_particle_fragment,map_particle_pars_fragment,metalnessmap_fragment,metalnessmap_pars_fragment,morphcolor_vertex,morphnormal_vertex,morphtarget_pars_vertex,morphtarget_vertex,normal_fragment_begin,normal_fragment_maps,normal_pars_fragment,normal_pars_vertex,normal_vertex,normalmap_pars_fragment,clearcoat_normal_fragment_begin,clearcoat_normal_fragment_maps,clearcoat_pars_fragment,iridescence_pars_fragment,opaque_fragment,packing,premultiplied_alpha_fragment,project_vertex,dithering_fragment,dithering_pars_fragment,roughnessmap_fragment,roughnessmap_pars_fragment,shadowmap_pars_fragment,shadowmap_pars_vertex,shadowmap_vertex,shadowmask_pars_fragment,skinbase_vertex,skinning_pars_vertex,skinning_vertex,skinnormal_vertex,specularmap_fragment,specularmap_pars_fragment,tonemapping_fragment,tonemapping_pars_fragment,transmission_fragment,transmission_pars_fragment,uv_pars_fragment,uv_pars_vertex,uv_vertex,worldpos_vertex,background_vert:vertex$h,background_frag:fragment$h,backgroundCube_vert:vertex$g,backgroundCube_frag:fragment$g,cube_vert:vertex$f,cube_frag:fragment$f,depth_vert:vertex$e,depth_frag:fragment$e,distanceRGBA_vert:vertex$d,distanceRGBA_frag:fragment$d,equirect_vert:vertex$c,equirect_frag:fragment$c,linedashed_vert:vertex$b,linedashed_frag:fragment$b,meshbasic_vert:vertex$a,meshbasic_frag:fragment$a,meshlambert_vert:vertex$9,meshlambert_frag:fragment$9,meshmatcap_vert:vertex$8,meshmatcap_frag:fragment$8,meshnormal_vert:vertex$7,meshnormal_frag:fragment$7,meshphong_vert:vertex$6,meshphong_frag:fragment$6,meshphysical_vert:vertex$5,meshphysical_frag:fragment$5,meshtoon_vert:vertex$4,meshtoon_frag:fragment$4,points_vert:vertex$3,points_frag:fragment$3,shadow_vert:vertex$2,shadow_frag:fragment$2,sprite_vert:vertex$1,sprite_frag:fragment$1},UniformsLib={common:{diffuse:{value:new Color(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new Matrix3},alphaMap:{value:null},alphaMapTransform:{value:new Matrix3},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new Matrix3}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new Matrix3}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new Matrix3}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new Matrix3},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new Matrix3},normalScale:{value:new Vector2(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new Matrix3},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new Matrix3}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new Matrix3}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new Matrix3}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new Color(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotShadowMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null}},points:{diffuse:{value:new Color(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new Matrix3},alphaTest:{value:0},uvTransform:{value:new Matrix3}},sprite:{diffuse:{value:new Color(16777215)},opacity:{value:1},center:{value:new Vector2(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new Matrix3},alphaMap:{value:null},alphaMapTransform:{value:new Matrix3},alphaTest:{value:0}}},ShaderLib={basic:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.fog]),vertexShader:ShaderChunk.meshbasic_vert,fragmentShader:ShaderChunk.meshbasic_frag},lambert:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0)}}]),vertexShader:ShaderChunk.meshlambert_vert,fragmentShader:ShaderChunk.meshlambert_frag},phong:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0)},specular:{value:new Color(1118481)},shininess:{value:30}}]),vertexShader:ShaderChunk.meshphong_vert,fragmentShader:ShaderChunk.meshphong_frag},standard:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.roughnessmap,UniformsLib.metalnessmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:ShaderChunk.meshphysical_vert,fragmentShader:ShaderChunk.meshphysical_frag},toon:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.gradientmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0)}}]),vertexShader:ShaderChunk.meshtoon_vert,fragmentShader:ShaderChunk.meshtoon_frag},matcap:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.fog,{matcap:{value:null}}]),vertexShader:ShaderChunk.meshmatcap_vert,fragmentShader:ShaderChunk.meshmatcap_frag},points:{uniforms:mergeUniforms([UniformsLib.points,UniformsLib.fog]),vertexShader:ShaderChunk.points_vert,fragmentShader:ShaderChunk.points_frag},dashed:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:ShaderChunk.linedashed_vert,fragmentShader:ShaderChunk.linedashed_frag},depth:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.displacementmap]),vertexShader:ShaderChunk.depth_vert,fragmentShader:ShaderChunk.depth_frag},normal:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,{opacity:{value:1}}]),vertexShader:ShaderChunk.meshnormal_vert,fragmentShader:ShaderChunk.meshnormal_frag},sprite:{uniforms:mergeUniforms([UniformsLib.sprite,UniformsLib.fog]),vertexShader:ShaderChunk.sprite_vert,fragmentShader:ShaderChunk.sprite_frag},background:{uniforms:{uvTransform:{value:new Matrix3},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:ShaderChunk.background_vert,fragmentShader:ShaderChunk.background_frag},backgroundCube:{uniforms:{envMap:{value:null},flipEnvMap:{value:-1},backgroundBlurriness:{value:0},backgroundIntensity:{value:1}},vertexShader:ShaderChunk.backgroundCube_vert,fragmentShader:ShaderChunk.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:ShaderChunk.cube_vert,fragmentShader:ShaderChunk.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:ShaderChunk.equirect_vert,fragmentShader:ShaderChunk.equirect_frag},distanceRGBA:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.displacementmap,{referencePosition:{value:new Vector3},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:ShaderChunk.distanceRGBA_vert,fragmentShader:ShaderChunk.distanceRGBA_frag},shadow:{uniforms:mergeUniforms([UniformsLib.lights,UniformsLib.fog,{color:{value:new Color(0)},opacity:{value:1}}]),vertexShader:ShaderChunk.shadow_vert,fragmentShader:ShaderChunk.shadow_frag}};ShaderLib.physical={uniforms:mergeUniforms([ShaderLib.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new Matrix3},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new Matrix3},clearcoatNormalScale:{value:new Vector2(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new Matrix3},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new Matrix3},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new Matrix3},sheen:{value:0},sheenColor:{value:new Color(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new Matrix3},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new Matrix3},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new Matrix3},transmissionSamplerSize:{value:new Vector2},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new Matrix3},attenuationDistance:{value:0},attenuationColor:{value:new Color(0)},specularColor:{value:new Color(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new Matrix3},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new Matrix3},anisotropyVector:{value:new Vector2},anisotropyMap:{value:null},anisotropyMapTransform:{value:new Matrix3}}]),vertexShader:ShaderChunk.meshphysical_vert,fragmentShader:ShaderChunk.meshphysical_frag};const _rgb={r:0,b:0,g:0};function WebGLBackground(s,e,t,r,o,c,l){const h=new Color(0);let p=c===!0?0:1,f,d,i=null,n=0,a=null;function u(g,_){let b=!1,y=_.isScene===!0?_.background:null;y&&y.isTexture&&(y=(_.backgroundBlurriness>0?t:e).get(y)),y===null?m(h,p):y&&y.isColor&&(m(y,1),b=!0);const v=s.xr.getEnvironmentBlendMode();v==="additive"?r.buffers.color.setClear(0,0,0,1,l):v==="alpha-blend"&&r.buffers.color.setClear(0,0,0,0,l),(s.autoClear||b)&&s.clear(s.autoClearColor,s.autoClearDepth,s.autoClearStencil),y&&(y.isCubeTexture||y.mapping===CubeUVReflectionMapping)?(d===void 0&&(d=new Mesh(new BoxGeometry(1,1,1),new ShaderMaterial({name:"BackgroundCubeMaterial",uniforms:cloneUniforms(ShaderLib.backgroundCube.uniforms),vertexShader:ShaderLib.backgroundCube.vertexShader,fragmentShader:ShaderLib.backgroundCube.fragmentShader,side:BackSide,depthTest:!1,depthWrite:!1,fog:!1})),d.geometry.deleteAttribute("normal"),d.geometry.deleteAttribute("uv"),d.onBeforeRender=function(x,w,S){this.matrixWorld.copyPosition(S.matrixWorld)},Object.defineProperty(d.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),o.update(d)),d.material.uniforms.envMap.value=y,d.material.uniforms.flipEnvMap.value=y.isCubeTexture&&y.isRenderTargetTexture===!1?-1:1,d.material.uniforms.backgroundBlurriness.value=_.backgroundBlurriness,d.material.uniforms.backgroundIntensity.value=_.backgroundIntensity,d.material.toneMapped=ColorManagement.getTransfer(y.colorSpace)!==SRGBTransfer,(i!==y||n!==y.version||a!==s.toneMapping)&&(d.material.needsUpdate=!0,i=y,n=y.version,a=s.toneMapping),d.layers.enableAll(),g.unshift(d,d.geometry,d.material,0,0,null)):y&&y.isTexture&&(f===void 0&&(f=new Mesh(new PlaneGeometry(2,2),new ShaderMaterial({name:"BackgroundMaterial",uniforms:cloneUniforms(ShaderLib.background.uniforms),vertexShader:ShaderLib.background.vertexShader,fragmentShader:ShaderLib.background.fragmentShader,side:FrontSide,depthTest:!1,depthWrite:!1,fog:!1})),f.geometry.deleteAttribute("normal"),Object.defineProperty(f.material,"map",{get:function(){return this.uniforms.t2D.value}}),o.update(f)),f.material.uniforms.t2D.value=y,f.material.uniforms.backgroundIntensity.value=_.backgroundIntensity,f.material.toneMapped=ColorManagement.getTransfer(y.colorSpace)!==SRGBTransfer,y.matrixAutoUpdate===!0&&y.updateMatrix(),f.material.uniforms.uvTransform.value.copy(y.matrix),(i!==y||n!==y.version||a!==s.toneMapping)&&(f.material.needsUpdate=!0,i=y,n=y.version,a=s.toneMapping),f.layers.enableAll(),g.unshift(f,f.geometry,f.material,0,0,null))}function m(g,_){g.getRGB(_rgb,getUnlitUniformColorSpace(s)),r.buffers.color.setClear(_rgb.r,_rgb.g,_rgb.b,_,l)}return{getClearColor:function(){return h},setClearColor:function(g,_=1){h.set(g),p=_,m(h,p)},getClearAlpha:function(){return p},setClearAlpha:function(g){p=g,m(h,p)},render:u}}function WebGLBindingStates(s,e,t,r){const o=s.getParameter(s.MAX_VERTEX_ATTRIBS),c=r.isWebGL2?null:e.get("OES_vertex_array_object"),l=r.isWebGL2||c!==null,h={},p=g(null);let f=p,d=!1;function i(C,z,O,U,K){let $=!1;if(l){const J=m(U,O,z);f!==J&&(f=J,a(f.object)),$=_(C,U,O,K),$&&b(C,U,O,K)}else{const J=z.wireframe===!0;(f.geometry!==U.id||f.program!==O.id||f.wireframe!==J)&&(f.geometry=U.id,f.program=O.id,f.wireframe=J,$=!0)}K!==null&&t.update(K,s.ELEMENT_ARRAY_BUFFER),($||d)&&(d=!1,M(C,z,O,U),K!==null&&s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t.get(K).buffer))}function n(){return r.isWebGL2?s.createVertexArray():c.createVertexArrayOES()}function a(C){return r.isWebGL2?s.bindVertexArray(C):c.bindVertexArrayOES(C)}function u(C){return r.isWebGL2?s.deleteVertexArray(C):c.deleteVertexArrayOES(C)}function m(C,z,O){const U=O.wireframe===!0;let K=h[C.id];K===void 0&&(K={},h[C.id]=K);let $=K[z.id];$===void 0&&($={},K[z.id]=$);let J=$[U];return J===void 0&&(J=g(n()),$[U]=J),J}function g(C){const z=[],O=[],U=[];for(let K=0;K=0){const le=K[he];let de=$[he];if(de===void 0&&(he==="instanceMatrix"&&C.instanceMatrix&&(de=C.instanceMatrix),he==="instanceColor"&&C.instanceColor&&(de=C.instanceColor)),le===void 0||le.attribute!==de||de&&le.data!==de.data)return!0;J++}return f.attributesNum!==J||f.index!==U}function b(C,z,O,U){const K={},$=z.attributes;let J=0;const ee=O.getAttributes();for(const he in ee)if(ee[he].location>=0){let le=$[he];le===void 0&&(he==="instanceMatrix"&&C.instanceMatrix&&(le=C.instanceMatrix),he==="instanceColor"&&C.instanceColor&&(le=C.instanceColor));const de={};de.attribute=le,le&&le.data&&(de.data=le.data),K[he]=de,J++}f.attributes=K,f.attributesNum=J,f.index=U}function y(){const C=f.newAttributes;for(let z=0,O=C.length;z=0){let ie=K[ee];if(ie===void 0&&(ee==="instanceMatrix"&&C.instanceMatrix&&(ie=C.instanceMatrix),ee==="instanceColor"&&C.instanceColor&&(ie=C.instanceColor)),ie!==void 0){const le=ie.normalized,de=ie.itemSize,Me=t.get(ie);if(Me===void 0)continue;const Ee=Me.buffer,Fe=Me.type,Be=Me.bytesPerElement,Ce=r.isWebGL2===!0&&(Fe===s.INT||Fe===s.UNSIGNED_INT||ie.gpuType===IntType);if(ie.isInterleavedBufferAttribute){const je=ie.data,ne=je.stride,Qe=ie.offset;if(je.isInstancedInterleavedBuffer){for(let Pe=0;Pe0&&s.getShaderPrecisionFormat(s.FRAGMENT_SHADER,s.HIGH_FLOAT).precision>0)return"highp";S="mediump"}return S==="mediump"&&s.getShaderPrecisionFormat(s.VERTEX_SHADER,s.MEDIUM_FLOAT).precision>0&&s.getShaderPrecisionFormat(s.FRAGMENT_SHADER,s.MEDIUM_FLOAT).precision>0?"mediump":"lowp"}const l=typeof WebGL2RenderingContext<"u"&&s.constructor.name==="WebGL2RenderingContext";let h=t.precision!==void 0?t.precision:"highp";const p=c(h);p!==h&&(console.warn("THREE.WebGLRenderer:",h,"not supported, using",p,"instead."),h=p);const f=l||e.has("WEBGL_draw_buffers"),d=t.logarithmicDepthBuffer===!0,i=s.getParameter(s.MAX_TEXTURE_IMAGE_UNITS),n=s.getParameter(s.MAX_VERTEX_TEXTURE_IMAGE_UNITS),a=s.getParameter(s.MAX_TEXTURE_SIZE),u=s.getParameter(s.MAX_CUBE_MAP_TEXTURE_SIZE),m=s.getParameter(s.MAX_VERTEX_ATTRIBS),g=s.getParameter(s.MAX_VERTEX_UNIFORM_VECTORS),_=s.getParameter(s.MAX_VARYING_VECTORS),b=s.getParameter(s.MAX_FRAGMENT_UNIFORM_VECTORS),y=n>0,v=l||e.has("OES_texture_float"),x=y&&v,w=l?s.getParameter(s.MAX_SAMPLES):0;return{isWebGL2:l,drawBuffers:f,getMaxAnisotropy:o,getMaxPrecision:c,precision:h,logarithmicDepthBuffer:d,maxTextures:i,maxVertexTextures:n,maxTextureSize:a,maxCubemapSize:u,maxAttributes:m,maxVertexUniforms:g,maxVaryings:_,maxFragmentUniforms:b,vertexTextures:y,floatFragmentTextures:v,floatVertexTextures:x,maxSamples:w}}function WebGLClipping(s){const e=this;let t=null,r=0,o=!1,c=!1;const l=new Plane,h=new Matrix3,p={value:null,needsUpdate:!1};this.uniform=p,this.numPlanes=0,this.numIntersection=0,this.init=function(i,n){const a=i.length!==0||n||r!==0||o;return o=n,r=i.length,a},this.beginShadows=function(){c=!0,d(null)},this.endShadows=function(){c=!1},this.setGlobalState=function(i,n){t=d(i,n,0)},this.setState=function(i,n,a){const u=i.clippingPlanes,m=i.clipIntersection,g=i.clipShadows,_=s.get(i);if(!o||u===null||u.length===0||c&&!g)c?d(null):f();else{const b=c?0:r,y=b*4;let v=_.clippingState||null;p.value=v,v=d(u,n,y,a);for(let x=0;x!==y;++x)v[x]=t[x];_.clippingState=v,this.numIntersection=m?this.numPlanes:0,this.numPlanes+=b}};function f(){p.value!==t&&(p.value=t,p.needsUpdate=r>0),e.numPlanes=r,e.numIntersection=0}function d(i,n,a,u){const m=i!==null?i.length:0;let g=null;if(m!==0){if(g=p.value,u!==!0||g===null){const _=a+m*4,b=n.matrixWorldInverse;h.getNormalMatrix(b),(g===null||g.length<_)&&(g=new Float32Array(_));for(let y=0,v=a;y!==m;++y,v+=4)l.copy(i[y]).applyMatrix4(b,h),l.normal.toArray(g,v),g[v+3]=l.constant}p.value=g,p.needsUpdate=!0}return e.numPlanes=m,e.numIntersection=0,g}}function WebGLCubeMaps(s){let e=new WeakMap;function t(l,h){return h===EquirectangularReflectionMapping?l.mapping=CubeReflectionMapping:h===EquirectangularRefractionMapping&&(l.mapping=CubeRefractionMapping),l}function r(l){if(l&&l.isTexture){const h=l.mapping;if(h===EquirectangularReflectionMapping||h===EquirectangularRefractionMapping)if(e.has(l)){const p=e.get(l).texture;return t(p,l.mapping)}else{const p=l.image;if(p&&p.height>0){const f=new WebGLCubeRenderTarget(p.height/2);return f.fromEquirectangularTexture(s,l),e.set(l,f),l.addEventListener("dispose",o),t(f.texture,l.mapping)}else return null}}return l}function o(l){const h=l.target;h.removeEventListener("dispose",o);const p=e.get(h);p!==void 0&&(e.delete(h),p.dispose())}function c(){e=new WeakMap}return{get:r,dispose:c}}class OrthographicCamera extends Camera{constructor(e=-1,t=1,r=1,o=-1,c=.1,l=2e3){super(),this.isOrthographicCamera=!0,this.type="OrthographicCamera",this.zoom=1,this.view=null,this.left=e,this.right=t,this.top=r,this.bottom=o,this.near=c,this.far=l,this.updateProjectionMatrix()}copy(e,t){return super.copy(e,t),this.left=e.left,this.right=e.right,this.top=e.top,this.bottom=e.bottom,this.near=e.near,this.far=e.far,this.zoom=e.zoom,this.view=e.view===null?null:Object.assign({},e.view),this}setViewOffset(e,t,r,o,c,l){this.view===null&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=e,this.view.fullHeight=t,this.view.offsetX=r,this.view.offsetY=o,this.view.width=c,this.view.height=l,this.updateProjectionMatrix()}clearViewOffset(){this.view!==null&&(this.view.enabled=!1),this.updateProjectionMatrix()}updateProjectionMatrix(){const e=(this.right-this.left)/(2*this.zoom),t=(this.top-this.bottom)/(2*this.zoom),r=(this.right+this.left)/2,o=(this.top+this.bottom)/2;let c=r-e,l=r+e,h=o+t,p=o-t;if(this.view!==null&&this.view.enabled){const f=(this.right-this.left)/this.view.fullWidth/this.zoom,d=(this.top-this.bottom)/this.view.fullHeight/this.zoom;c+=f*this.view.offsetX,l=c+f*this.view.width,h-=d*this.view.offsetY,p=h-d*this.view.height}this.projectionMatrix.makeOrthographic(c,l,h,p,this.near,this.far,this.coordinateSystem),this.projectionMatrixInverse.copy(this.projectionMatrix).invert()}toJSON(e){const t=super.toJSON(e);return t.object.zoom=this.zoom,t.object.left=this.left,t.object.right=this.right,t.object.top=this.top,t.object.bottom=this.bottom,t.object.near=this.near,t.object.far=this.far,this.view!==null&&(t.object.view=Object.assign({},this.view)),t}}const LOD_MIN=4,EXTRA_LOD_SIGMA=[.125,.215,.35,.446,.526,.582],MAX_SAMPLES=20,_flatCamera=new OrthographicCamera,_clearColor=new Color;let _oldTarget=null,_oldActiveCubeFace=0,_oldActiveMipmapLevel=0;const PHI=(1+Math.sqrt(5))/2,INV_PHI=1/PHI,_axisDirections=[new Vector3(1,1,1),new Vector3(-1,1,1),new Vector3(1,1,-1),new Vector3(-1,1,-1),new Vector3(0,PHI,INV_PHI),new Vector3(0,PHI,-INV_PHI),new Vector3(INV_PHI,0,PHI),new Vector3(-INV_PHI,0,PHI),new Vector3(PHI,INV_PHI,0),new Vector3(-PHI,INV_PHI,0)];class PMREMGenerator{constructor(e){this._renderer=e,this._pingPongRenderTarget=null,this._lodMax=0,this._cubeSize=0,this._lodPlanes=[],this._sizeLods=[],this._sigmas=[],this._blurMaterial=null,this._cubemapMaterial=null,this._equirectMaterial=null,this._compileMaterial(this._blurMaterial)}fromScene(e,t=0,r=.1,o=100){_oldTarget=this._renderer.getRenderTarget(),_oldActiveCubeFace=this._renderer.getActiveCubeFace(),_oldActiveMipmapLevel=this._renderer.getActiveMipmapLevel(),this._setSize(256);const c=this._allocateTargets();return c.depthBuffer=!0,this._sceneToCubeUV(e,r,o,c),t>0&&this._blur(c,0,0,t),this._applyPMREM(c),this._cleanup(c),c}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=_getCubemapMaterial(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=_getEquirectMaterial(),this._compileMaterial(this._equirectMaterial))}dispose(){this._dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose()}_setSize(e){this._lodMax=Math.floor(Math.log2(e)),this._cubeSize=Math.pow(2,this._lodMax)}_dispose(){this._blurMaterial!==null&&this._blurMaterial.dispose(),this._pingPongRenderTarget!==null&&this._pingPongRenderTarget.dispose();for(let e=0;e2?y:0,y,y),d.setRenderTarget(o),m&&d.render(u,h),d.render(e,h)}u.geometry.dispose(),u.material.dispose(),d.toneMapping=n,d.autoClear=i,e.background=g}_textureToCubeUV(e,t){const r=this._renderer,o=e.mapping===CubeReflectionMapping||e.mapping===CubeRefractionMapping;o?(this._cubemapMaterial===null&&(this._cubemapMaterial=_getCubemapMaterial()),this._cubemapMaterial.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):this._equirectMaterial===null&&(this._equirectMaterial=_getEquirectMaterial());const c=o?this._cubemapMaterial:this._equirectMaterial,l=new Mesh(this._lodPlanes[0],c),h=c.uniforms;h.envMap.value=e;const p=this._cubeSize;_setViewport(t,0,0,3*p,2*p),r.setRenderTarget(t),r.render(l,_flatCamera)}_applyPMREM(e){const t=this._renderer,r=t.autoClear;t.autoClear=!1;for(let o=1;oMAX_SAMPLES&&console.warn(`sigmaRadians, ${c}, is too large and will clip, as it requested ${g} samples when the maximum is set to ${MAX_SAMPLES}`);const _=[];let b=0;for(let S=0;Sy-LOD_MIN?o-y+LOD_MIN:0),w=4*(this._cubeSize-v);_setViewport(t,x,w,3*v,2*v),p.setRenderTarget(t),p.render(i,_flatCamera)}}function _createPlanes(s){const e=[],t=[],r=[];let o=s;const c=s-LOD_MIN+1+EXTRA_LOD_SIGMA.length;for(let l=0;ls-LOD_MIN?p=EXTRA_LOD_SIGMA[l-s+LOD_MIN-1]:l===0&&(p=0),r.push(p);const f=1/(h-2),d=-f,i=1+f,n=[d,d,i,d,i,i,d,d,i,i,d,i],a=6,u=6,m=3,g=2,_=1,b=new Float32Array(m*u*a),y=new Float32Array(g*u*a),v=new Float32Array(_*u*a);for(let w=0;w2?0:-1,T=[S,M,0,S+2/3,M,0,S+2/3,M+1,0,S,M,0,S+2/3,M+1,0,S,M+1,0];b.set(T,m*u*w),y.set(n,g*u*w);const E=[w,w,w,w,w,w];v.set(E,_*u*w)}const x=new BufferGeometry;x.setAttribute("position",new BufferAttribute(b,m)),x.setAttribute("uv",new BufferAttribute(y,g)),x.setAttribute("faceIndex",new BufferAttribute(v,_)),e.push(x),o>LOD_MIN&&o--}return{lodPlanes:e,sizeLods:t,sigmas:r}}function _createRenderTarget(s,e,t){const r=new WebGLRenderTarget(s,e,t);return r.texture.mapping=CubeUVReflectionMapping,r.texture.name="PMREM.cubeUv",r.scissorTest=!0,r}function _setViewport(s,e,t,r,o){s.viewport.set(e,t,r,o),s.scissor.set(e,t,r,o)}function _getBlurShader(s,e,t){const r=new Float32Array(MAX_SAMPLES),o=new Vector3(0,1,0);return new ShaderMaterial({name:"SphericalGaussianBlur",defines:{n:MAX_SAMPLES,CUBEUV_TEXEL_WIDTH:1/e,CUBEUV_TEXEL_HEIGHT:1/t,CUBEUV_MAX_MIP:`${s}.0`},uniforms:{envMap:{value:null},samples:{value:1},weights:{value:r},latitudinal:{value:!1},dTheta:{value:0},mipInt:{value:0},poleAxis:{value:o}},vertexShader:_getCommonVertexShader(),fragmentShader:` precision mediump float; precision mediump int; varying vec3 vOutputDirection; uniform sampler2D envMap; uniform int samples; uniform float weights[ n ]; uniform bool latitudinal; uniform float dTheta; uniform float mipInt; uniform vec3 poleAxis; #define ENVMAP_TYPE_CUBE_UV #include vec3 getSample( float theta, vec3 axis ) { float cosTheta = cos( theta ); // Rodrigues' axis-angle rotation vec3 sampleDirection = vOutputDirection * cosTheta + cross( axis, vOutputDirection ) * sin( theta ) + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); return bilinearCubeUV( envMap, sampleDirection, mipInt ); } void main() { vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); if ( all( equal( axis, vec3( 0.0 ) ) ) ) { axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); } axis = normalize( axis ); gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); for ( int i = 1; i < n; i++ ) { if ( i >= samples ) { break; } float theta = dTheta * float( i ); gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); } } `,blending:NoBlending,depthTest:!1,depthWrite:!1})}function _getEquirectMaterial(){return new ShaderMaterial({name:"EquirectangularToCubeUV",uniforms:{envMap:{value:null}},vertexShader:_getCommonVertexShader(),fragmentShader:` precision mediump float; precision mediump int; varying vec3 vOutputDirection; uniform sampler2D envMap; #include void main() { vec3 outputDirection = normalize( vOutputDirection ); vec2 uv = equirectUv( outputDirection ); gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); } `,blending:NoBlending,depthTest:!1,depthWrite:!1})}function _getCubemapMaterial(){return new ShaderMaterial({name:"CubemapToCubeUV",uniforms:{envMap:{value:null},flipEnvMap:{value:-1}},vertexShader:_getCommonVertexShader(),fragmentShader:` precision mediump float; precision mediump int; uniform float flipEnvMap; varying vec3 vOutputDirection; uniform samplerCube envMap; void main() { gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); } `,blending:NoBlending,depthTest:!1,depthWrite:!1})}function _getCommonVertexShader(){return` precision mediump float; precision mediump int; attribute float faceIndex; varying vec3 vOutputDirection; // RH coordinate system; PMREM face-indexing convention vec3 getDirection( vec2 uv, float face ) { uv = 2.0 * uv - 1.0; vec3 direction = vec3( uv, 1.0 ); if ( face == 0.0 ) { direction = direction.zyx; // ( 1, v, u ) pos x } else if ( face == 1.0 ) { direction = direction.xzy; direction.xz *= -1.0; // ( -u, 1, -v ) pos y } else if ( face == 2.0 ) { direction.x *= -1.0; // ( -u, v, 1 ) pos z } else if ( face == 3.0 ) { direction = direction.zyx; direction.xz *= -1.0; // ( -1, v, -u ) neg x } else if ( face == 4.0 ) { direction = direction.xzy; direction.xy *= -1.0; // ( -u, -1, v ) neg y } else if ( face == 5.0 ) { direction.z *= -1.0; // ( u, v, -1 ) neg z } return direction; } void main() { vOutputDirection = getDirection( uv, faceIndex ); gl_Position = vec4( position, 1.0 ); } `}function WebGLCubeUVMaps(s){let e=new WeakMap,t=null;function r(h){if(h&&h.isTexture){const p=h.mapping,f=p===EquirectangularReflectionMapping||p===EquirectangularRefractionMapping,d=p===CubeReflectionMapping||p===CubeRefractionMapping;if(f||d)if(h.isRenderTargetTexture&&h.needsPMREMUpdate===!0){h.needsPMREMUpdate=!1;let i=e.get(h);return t===null&&(t=new PMREMGenerator(s)),i=f?t.fromEquirectangular(h,i):t.fromCubemap(h,i),e.set(h,i),i.texture}else{if(e.has(h))return e.get(h).texture;{const i=h.image;if(f&&i&&i.height>0||d&&i&&o(i)){t===null&&(t=new PMREMGenerator(s));const n=f?t.fromEquirectangular(h):t.fromCubemap(h);return e.set(h,n),h.addEventListener("dispose",c),n.texture}else return null}}}return h}function o(h){let p=0;const f=6;for(let d=0;de.maxTextureSize&&(E=Math.ceil(T/e.maxTextureSize),T=e.maxTextureSize);const R=new Float32Array(T*E*4*u),I=new DataArrayTexture(R,T,E,u);I.type=FloatType,I.needsUpdate=!0;const k=M*4;for(let z=0;z0)return s;const o=e*t;let c=arrayCacheF32[o];if(c===void 0&&(c=new Float32Array(o),arrayCacheF32[o]=c),e!==0){r.toArray(c,0);for(let l=1,h=0;l!==e;++l)h+=t,s[l].toArray(c,h)}return c}function arraysEqual(s,e){if(s.length!==e.length)return!1;for(let t=0,r=s.length;t":" "} ${h}: ${t[l]}`)}return r.join(` `)}function getEncodingComponents(s){const e=ColorManagement.getPrimaries(ColorManagement.workingColorSpace),t=ColorManagement.getPrimaries(s);let r;switch(e===t?r="":e===P3Primaries&&t===Rec709Primaries?r="LinearDisplayP3ToLinearSRGB":e===Rec709Primaries&&t===P3Primaries&&(r="LinearSRGBToLinearDisplayP3"),s){case LinearSRGBColorSpace:case LinearDisplayP3ColorSpace:return[r,"LinearTransferOETF"];case SRGBColorSpace:case DisplayP3ColorSpace:return[r,"sRGBTransferOETF"];default:return console.warn("THREE.WebGLProgram: Unsupported color space:",s),[r,"LinearTransferOETF"]}}function getShaderErrors(s,e,t){const r=s.getShaderParameter(e,s.COMPILE_STATUS),o=s.getShaderInfoLog(e).trim();if(r&&o==="")return"";const c=/ERROR: 0:(\d+)/.exec(o);if(c){const l=parseInt(c[1]);return t.toUpperCase()+` `+o+` `+handleSource(s.getShaderSource(e),l)}else return o}function getTexelEncodingFunction(s,e){const t=getEncodingComponents(e);return`vec4 ${s}( vec4 value ) { return ${t[0]}( ${t[1]}( value ) ); }`}function getToneMappingFunction(s,e){let t;switch(e){case LinearToneMapping:t="Linear";break;case ReinhardToneMapping:t="Reinhard";break;case CineonToneMapping:t="OptimizedCineon";break;case ACESFilmicToneMapping:t="ACESFilmic";break;case AgXToneMapping:t="AgX";break;case CustomToneMapping:t="Custom";break;default:console.warn("THREE.WebGLProgram: Unsupported toneMapping:",e),t="Linear"}return"vec3 "+s+"( vec3 color ) { return "+t+"ToneMapping( color ); }"}function generateExtensions(s){return[s.extensionDerivatives||s.envMapCubeUVHeight||s.bumpMap||s.normalMapTangentSpace||s.clearcoatNormalMap||s.flatShading||s.shaderID==="physical"?"#extension GL_OES_standard_derivatives : enable":"",(s.extensionFragDepth||s.logarithmicDepthBuffer)&&s.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",s.extensionDrawBuffers&&s.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(s.extensionShaderTextureLOD||s.envMap||s.transmission)&&s.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter(filterEmptyLine).join(` `)}function generateVertexExtensions(s){return[s.extensionClipCullDistance?"#extension GL_ANGLE_clip_cull_distance : require":""].filter(filterEmptyLine).join(` `)}function generateDefines(s){const e=[];for(const t in s){const r=s[t];r!==!1&&e.push("#define "+t+" "+r)}return e.join(` `)}function fetchAttributeLocations(s,e){const t={},r=s.getProgramParameter(e,s.ACTIVE_ATTRIBUTES);for(let o=0;o/gm;function resolveIncludes(s){return s.replace(includePattern,includeReplacer)}const shaderChunkMap=new Map([["encodings_fragment","colorspace_fragment"],["encodings_pars_fragment","colorspace_pars_fragment"],["output_fragment","opaque_fragment"]]);function includeReplacer(s,e){let t=ShaderChunk[e];if(t===void 0){const r=shaderChunkMap.get(e);if(r!==void 0)t=ShaderChunk[r],console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.',e,r);else throw new Error("Can not resolve #include <"+e+">")}return resolveIncludes(t)}const unrollLoopPattern=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function unrollLoops(s){return s.replace(unrollLoopPattern,loopReplacer)}function loopReplacer(s,e,t,r){let o="";for(let c=parseInt(e);c0&&(_+=` `),b=[a,"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,m].filter(filterEmptyLine).join(` `),b.length>0&&(b+=` `)):(_=[generatePrecision(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,m,t.extensionClipCullDistance?"#define USE_CLIP_DISTANCE":"",t.batching?"#define USE_BATCHING":"",t.instancing?"#define USE_INSTANCING":"",t.instancingColor?"#define USE_INSTANCING_COLOR":"",t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+d:"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.displacementMap?"#define USE_DISPLACEMENTMAP":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.mapUv?"#define MAP_UV "+t.mapUv:"",t.alphaMapUv?"#define ALPHAMAP_UV "+t.alphaMapUv:"",t.lightMapUv?"#define LIGHTMAP_UV "+t.lightMapUv:"",t.aoMapUv?"#define AOMAP_UV "+t.aoMapUv:"",t.emissiveMapUv?"#define EMISSIVEMAP_UV "+t.emissiveMapUv:"",t.bumpMapUv?"#define BUMPMAP_UV "+t.bumpMapUv:"",t.normalMapUv?"#define NORMALMAP_UV "+t.normalMapUv:"",t.displacementMapUv?"#define DISPLACEMENTMAP_UV "+t.displacementMapUv:"",t.metalnessMapUv?"#define METALNESSMAP_UV "+t.metalnessMapUv:"",t.roughnessMapUv?"#define ROUGHNESSMAP_UV "+t.roughnessMapUv:"",t.anisotropyMapUv?"#define ANISOTROPYMAP_UV "+t.anisotropyMapUv:"",t.clearcoatMapUv?"#define CLEARCOATMAP_UV "+t.clearcoatMapUv:"",t.clearcoatNormalMapUv?"#define CLEARCOAT_NORMALMAP_UV "+t.clearcoatNormalMapUv:"",t.clearcoatRoughnessMapUv?"#define CLEARCOAT_ROUGHNESSMAP_UV "+t.clearcoatRoughnessMapUv:"",t.iridescenceMapUv?"#define IRIDESCENCEMAP_UV "+t.iridescenceMapUv:"",t.iridescenceThicknessMapUv?"#define IRIDESCENCE_THICKNESSMAP_UV "+t.iridescenceThicknessMapUv:"",t.sheenColorMapUv?"#define SHEEN_COLORMAP_UV "+t.sheenColorMapUv:"",t.sheenRoughnessMapUv?"#define SHEEN_ROUGHNESSMAP_UV "+t.sheenRoughnessMapUv:"",t.specularMapUv?"#define SPECULARMAP_UV "+t.specularMapUv:"",t.specularColorMapUv?"#define SPECULAR_COLORMAP_UV "+t.specularColorMapUv:"",t.specularIntensityMapUv?"#define SPECULAR_INTENSITYMAP_UV "+t.specularIntensityMapUv:"",t.transmissionMapUv?"#define TRANSMISSIONMAP_UV "+t.transmissionMapUv:"",t.thicknessMapUv?"#define THICKNESSMAP_UV "+t.thicknessMapUv:"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.flatShading?"#define FLAT_SHADED":"",t.skinning?"#define USE_SKINNING":"",t.morphTargets?"#define USE_MORPHTARGETS":"",t.morphNormals&&t.flatShading===!1?"#define USE_MORPHNORMALS":"",t.morphColors&&t.isWebGL2?"#define USE_MORPHCOLORS":"",t.morphTargetsCount>0&&t.isWebGL2?"#define MORPHTARGETS_TEXTURE":"",t.morphTargetsCount>0&&t.isWebGL2?"#define MORPHTARGETS_TEXTURE_STRIDE "+t.morphTextureStride:"",t.morphTargetsCount>0&&t.isWebGL2?"#define MORPHTARGETS_COUNT "+t.morphTargetsCount:"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+p:"",t.sizeAttenuation?"#define USE_SIZEATTENUATION":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.useLegacyLights?"#define LEGACY_LIGHTS":"",t.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",t.logarithmicDepthBuffer&&t.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;","#ifdef USE_INSTANCING"," attribute mat4 instanceMatrix;","#endif","#ifdef USE_INSTANCING_COLOR"," attribute vec3 instanceColor;","#endif","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_UV1"," attribute vec2 uv1;","#endif","#ifdef USE_UV2"," attribute vec2 uv2;","#endif","#ifdef USE_UV3"," attribute vec2 uv3;","#endif","#ifdef USE_TANGENT"," attribute vec4 tangent;","#endif","#if defined( USE_COLOR_ALPHA )"," attribute vec4 color;","#elif defined( USE_COLOR )"," attribute vec3 color;","#endif","#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )"," attribute vec3 morphTarget0;"," attribute vec3 morphTarget1;"," attribute vec3 morphTarget2;"," attribute vec3 morphTarget3;"," #ifdef USE_MORPHNORMALS"," attribute vec3 morphNormal0;"," attribute vec3 morphNormal1;"," attribute vec3 morphNormal2;"," attribute vec3 morphNormal3;"," #else"," attribute vec3 morphTarget4;"," attribute vec3 morphTarget5;"," attribute vec3 morphTarget6;"," attribute vec3 morphTarget7;"," #endif","#endif","#ifdef USE_SKINNING"," attribute vec4 skinIndex;"," attribute vec4 skinWeight;","#endif",` `].filter(filterEmptyLine).join(` `),b=[a,generatePrecision(t),"#define SHADER_TYPE "+t.shaderType,"#define SHADER_NAME "+t.shaderName,m,t.useFog&&t.fog?"#define USE_FOG":"",t.useFog&&t.fogExp2?"#define FOG_EXP2":"",t.map?"#define USE_MAP":"",t.matcap?"#define USE_MATCAP":"",t.envMap?"#define USE_ENVMAP":"",t.envMap?"#define "+f:"",t.envMap?"#define "+d:"",t.envMap?"#define "+i:"",n?"#define CUBEUV_TEXEL_WIDTH "+n.texelWidth:"",n?"#define CUBEUV_TEXEL_HEIGHT "+n.texelHeight:"",n?"#define CUBEUV_MAX_MIP "+n.maxMip+".0":"",t.lightMap?"#define USE_LIGHTMAP":"",t.aoMap?"#define USE_AOMAP":"",t.bumpMap?"#define USE_BUMPMAP":"",t.normalMap?"#define USE_NORMALMAP":"",t.normalMapObjectSpace?"#define USE_NORMALMAP_OBJECTSPACE":"",t.normalMapTangentSpace?"#define USE_NORMALMAP_TANGENTSPACE":"",t.emissiveMap?"#define USE_EMISSIVEMAP":"",t.anisotropy?"#define USE_ANISOTROPY":"",t.anisotropyMap?"#define USE_ANISOTROPYMAP":"",t.clearcoat?"#define USE_CLEARCOAT":"",t.clearcoatMap?"#define USE_CLEARCOATMAP":"",t.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",t.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",t.iridescence?"#define USE_IRIDESCENCE":"",t.iridescenceMap?"#define USE_IRIDESCENCEMAP":"",t.iridescenceThicknessMap?"#define USE_IRIDESCENCE_THICKNESSMAP":"",t.specularMap?"#define USE_SPECULARMAP":"",t.specularColorMap?"#define USE_SPECULAR_COLORMAP":"",t.specularIntensityMap?"#define USE_SPECULAR_INTENSITYMAP":"",t.roughnessMap?"#define USE_ROUGHNESSMAP":"",t.metalnessMap?"#define USE_METALNESSMAP":"",t.alphaMap?"#define USE_ALPHAMAP":"",t.alphaTest?"#define USE_ALPHATEST":"",t.alphaHash?"#define USE_ALPHAHASH":"",t.sheen?"#define USE_SHEEN":"",t.sheenColorMap?"#define USE_SHEEN_COLORMAP":"",t.sheenRoughnessMap?"#define USE_SHEEN_ROUGHNESSMAP":"",t.transmission?"#define USE_TRANSMISSION":"",t.transmissionMap?"#define USE_TRANSMISSIONMAP":"",t.thicknessMap?"#define USE_THICKNESSMAP":"",t.vertexTangents&&t.flatShading===!1?"#define USE_TANGENT":"",t.vertexColors||t.instancingColor?"#define USE_COLOR":"",t.vertexAlphas?"#define USE_COLOR_ALPHA":"",t.vertexUv1s?"#define USE_UV1":"",t.vertexUv2s?"#define USE_UV2":"",t.vertexUv3s?"#define USE_UV3":"",t.pointsUvs?"#define USE_POINTS_UV":"",t.gradientMap?"#define USE_GRADIENTMAP":"",t.flatShading?"#define FLAT_SHADED":"",t.doubleSided?"#define DOUBLE_SIDED":"",t.flipSided?"#define FLIP_SIDED":"",t.shadowMapEnabled?"#define USE_SHADOWMAP":"",t.shadowMapEnabled?"#define "+p:"",t.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",t.numLightProbes>0?"#define USE_LIGHT_PROBES":"",t.useLegacyLights?"#define LEGACY_LIGHTS":"",t.decodeVideoTexture?"#define DECODE_VIDEO_TEXTURE":"",t.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",t.logarithmicDepthBuffer&&t.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",t.toneMapping!==NoToneMapping?"#define TONE_MAPPING":"",t.toneMapping!==NoToneMapping?ShaderChunk.tonemapping_pars_fragment:"",t.toneMapping!==NoToneMapping?getToneMappingFunction("toneMapping",t.toneMapping):"",t.dithering?"#define DITHERING":"",t.opaque?"#define OPAQUE":"",ShaderChunk.colorspace_pars_fragment,getTexelEncodingFunction("linearToOutputTexel",t.outputColorSpace),t.useDepthPacking?"#define DEPTH_PACKING "+t.depthPacking:"",` `].filter(filterEmptyLine).join(` `)),l=resolveIncludes(l),l=replaceLightNums(l,t),l=replaceClippingPlaneNums(l,t),h=resolveIncludes(h),h=replaceLightNums(h,t),h=replaceClippingPlaneNums(h,t),l=unrollLoops(l),h=unrollLoops(h),t.isWebGL2&&t.isRawShaderMaterial!==!0&&(y=`#version 300 es `,_=[u,"precision mediump sampler2DArray;","#define attribute in","#define varying out","#define texture2D texture"].join(` `)+` `+_,b=["precision mediump sampler2DArray;","#define varying in",t.glslVersion===GLSL3?"":"layout(location = 0) out highp vec4 pc_fragColor;",t.glslVersion===GLSL3?"":"#define gl_FragColor pc_fragColor","#define gl_FragDepthEXT gl_FragDepth","#define texture2D texture","#define textureCube texture","#define texture2DProj textureProj","#define texture2DLodEXT textureLod","#define texture2DProjLodEXT textureProjLod","#define textureCubeLodEXT textureLod","#define texture2DGradEXT textureGrad","#define texture2DProjGradEXT textureProjGrad","#define textureCubeGradEXT textureGrad"].join(` `)+` `+b);const v=y+_+l,x=y+b+h,w=WebGLShader(o,o.VERTEX_SHADER,v),S=WebGLShader(o,o.FRAGMENT_SHADER,x);o.attachShader(g,w),o.attachShader(g,S),t.index0AttributeName!==void 0?o.bindAttribLocation(g,0,t.index0AttributeName):t.morphTargets===!0&&o.bindAttribLocation(g,0,"position"),o.linkProgram(g);function M(I){if(s.debug.checkShaderErrors){const k=o.getProgramInfoLog(g).trim(),C=o.getShaderInfoLog(w).trim(),z=o.getShaderInfoLog(S).trim();let O=!0,U=!0;if(o.getProgramParameter(g,o.LINK_STATUS)===!1)if(O=!1,typeof s.debug.onShaderError=="function")s.debug.onShaderError(o,g,w,S);else{const K=getShaderErrors(o,w,"vertex"),$=getShaderErrors(o,S,"fragment");console.error("THREE.WebGLProgram: Shader Error "+o.getError()+" - VALIDATE_STATUS "+o.getProgramParameter(g,o.VALIDATE_STATUS)+` Program Info Log: `+k+` `+K+` `+$)}else k!==""?console.warn("THREE.WebGLProgram: Program Info Log:",k):(C===""||z==="")&&(U=!1);U&&(I.diagnostics={runnable:O,programLog:k,vertexShader:{log:C,prefix:_},fragmentShader:{log:z,prefix:b}})}o.deleteShader(w),o.deleteShader(S),T=new WebGLUniforms(o,g),E=fetchAttributeLocations(o,g)}let T;this.getUniforms=function(){return T===void 0&&M(this),T};let E;this.getAttributes=function(){return E===void 0&&M(this),E};let R=t.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return R===!1&&(R=o.getProgramParameter(g,COMPLETION_STATUS_KHR)),R},this.destroy=function(){r.releaseStatesOfProgram(this),o.deleteProgram(g),this.program=void 0},this.type=t.shaderType,this.name=t.shaderName,this.id=programIdCount++,this.cacheKey=e,this.usedTimes=1,this.program=g,this.vertexShader=w,this.fragmentShader=S,this}let _id$1=0;class WebGLShaderCache{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e){const t=e.vertexShader,r=e.fragmentShader,o=this._getShaderStage(t),c=this._getShaderStage(r),l=this._getShaderCacheForMaterial(e);return l.has(o)===!1&&(l.add(o),o.usedTimes++),l.has(c)===!1&&(l.add(c),c.usedTimes++),this}remove(e){const t=this.materialCache.get(e);for(const r of t)r.usedTimes--,r.usedTimes===0&&this.shaderCache.delete(r.code);return this.materialCache.delete(e),this}getVertexShaderID(e){return this._getShaderStage(e.vertexShader).id}getFragmentShaderID(e){return this._getShaderStage(e.fragmentShader).id}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){const t=this.materialCache;let r=t.get(e);return r===void 0&&(r=new Set,t.set(e,r)),r}_getShaderStage(e){const t=this.shaderCache;let r=t.get(e);return r===void 0&&(r=new WebGLShaderStage(e),t.set(e,r)),r}}class WebGLShaderStage{constructor(e){this.id=_id$1++,this.code=e,this.usedTimes=0}}function WebGLPrograms(s,e,t,r,o,c,l){const h=new Layers,p=new WebGLShaderCache,f=[],d=o.isWebGL2,i=o.logarithmicDepthBuffer,n=o.vertexTextures;let a=o.precision;const u={MeshDepthMaterial:"depth",MeshDistanceMaterial:"distanceRGBA",MeshNormalMaterial:"normal",MeshBasicMaterial:"basic",MeshLambertMaterial:"lambert",MeshPhongMaterial:"phong",MeshToonMaterial:"toon",MeshStandardMaterial:"physical",MeshPhysicalMaterial:"physical",MeshMatcapMaterial:"matcap",LineBasicMaterial:"basic",LineDashedMaterial:"dashed",PointsMaterial:"points",ShadowMaterial:"shadow",SpriteMaterial:"sprite"};function m(T){return T===0?"uv":`uv${T}`}function g(T,E,R,I,k){const C=I.fog,z=k.geometry,O=T.isMeshStandardMaterial?I.environment:null,U=(T.isMeshStandardMaterial?t:e).get(T.envMap||O),K=U&&U.mapping===CubeUVReflectionMapping?U.image.height:null,$=u[T.type];T.precision!==null&&(a=o.getMaxPrecision(T.precision),a!==T.precision&&console.warn("THREE.WebGLProgram.getParameters:",T.precision,"not supported, using",a,"instead."));const J=z.morphAttributes.position||z.morphAttributes.normal||z.morphAttributes.color,ee=J!==void 0?J.length:0;let he=0;z.morphAttributes.position!==void 0&&(he=1),z.morphAttributes.normal!==void 0&&(he=2),z.morphAttributes.color!==void 0&&(he=3);let ie,le,de,Me;if($){const dt=ShaderLib[$];ie=dt.vertexShader,le=dt.fragmentShader}else ie=T.vertexShader,le=T.fragmentShader,p.update(T),de=p.getVertexShaderID(T),Me=p.getFragmentShaderID(T);const Ee=s.getRenderTarget(),Fe=k.isInstancedMesh===!0,Be=k.isBatchedMesh===!0,Ce=!!T.map,je=!!T.matcap,ne=!!U,Qe=!!T.aoMap,Pe=!!T.lightMap,ze=!!T.bumpMap,De=!!T.normalMap,nt=!!T.displacementMap,qe=!!T.emissiveMap,B=!!T.metalnessMap,D=!!T.roughnessMap,re=T.anisotropy>0,ce=T.clearcoat>0,fe=T.iridescence>0,pe=T.sheen>0,Te=T.transmission>0,Oe=re&&!!T.anisotropyMap,Ne=ce&&!!T.clearcoatMap,He=ce&&!!T.clearcoatNormalMap,Xe=ce&&!!T.clearcoatRoughnessMap,me=fe&&!!T.iridescenceMap,rt=fe&&!!T.iridescenceThicknessMap,Ge=pe&&!!T.sheenColorMap,We=pe&&!!T.sheenRoughnessMap,_e=!!T.specularMap,Le=!!T.specularColorMap,H=!!T.specularIntensityMap,Se=Te&&!!T.transmissionMap,ke=Te&&!!T.thicknessMap,be=!!T.gradientMap,ge=!!T.alphaMap,X=T.alphaTest>0,we=!!T.alphaHash,ue=!!T.extensions,ve=!!z.attributes.uv1,ye=!!z.attributes.uv2,Ze=!!z.attributes.uv3;let Ke=NoToneMapping;return T.toneMapped&&(Ee===null||Ee.isXRRenderTarget===!0)&&(Ke=s.toneMapping),{isWebGL2:d,shaderID:$,shaderType:T.type,shaderName:T.name,vertexShader:ie,fragmentShader:le,defines:T.defines,customVertexShaderID:de,customFragmentShaderID:Me,isRawShaderMaterial:T.isRawShaderMaterial===!0,glslVersion:T.glslVersion,precision:a,batching:Be,instancing:Fe,instancingColor:Fe&&k.instanceColor!==null,supportsVertexTextures:n,outputColorSpace:Ee===null?s.outputColorSpace:Ee.isXRRenderTarget===!0?Ee.texture.colorSpace:LinearSRGBColorSpace,map:Ce,matcap:je,envMap:ne,envMapMode:ne&&U.mapping,envMapCubeUVHeight:K,aoMap:Qe,lightMap:Pe,bumpMap:ze,normalMap:De,displacementMap:n&&nt,emissiveMap:qe,normalMapObjectSpace:De&&T.normalMapType===ObjectSpaceNormalMap,normalMapTangentSpace:De&&T.normalMapType===TangentSpaceNormalMap,metalnessMap:B,roughnessMap:D,anisotropy:re,anisotropyMap:Oe,clearcoat:ce,clearcoatMap:Ne,clearcoatNormalMap:He,clearcoatRoughnessMap:Xe,iridescence:fe,iridescenceMap:me,iridescenceThicknessMap:rt,sheen:pe,sheenColorMap:Ge,sheenRoughnessMap:We,specularMap:_e,specularColorMap:Le,specularIntensityMap:H,transmission:Te,transmissionMap:Se,thicknessMap:ke,gradientMap:be,opaque:T.transparent===!1&&T.blending===NormalBlending,alphaMap:ge,alphaTest:X,alphaHash:we,combine:T.combine,mapUv:Ce&&m(T.map.channel),aoMapUv:Qe&&m(T.aoMap.channel),lightMapUv:Pe&&m(T.lightMap.channel),bumpMapUv:ze&&m(T.bumpMap.channel),normalMapUv:De&&m(T.normalMap.channel),displacementMapUv:nt&&m(T.displacementMap.channel),emissiveMapUv:qe&&m(T.emissiveMap.channel),metalnessMapUv:B&&m(T.metalnessMap.channel),roughnessMapUv:D&&m(T.roughnessMap.channel),anisotropyMapUv:Oe&&m(T.anisotropyMap.channel),clearcoatMapUv:Ne&&m(T.clearcoatMap.channel),clearcoatNormalMapUv:He&&m(T.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:Xe&&m(T.clearcoatRoughnessMap.channel),iridescenceMapUv:me&&m(T.iridescenceMap.channel),iridescenceThicknessMapUv:rt&&m(T.iridescenceThicknessMap.channel),sheenColorMapUv:Ge&&m(T.sheenColorMap.channel),sheenRoughnessMapUv:We&&m(T.sheenRoughnessMap.channel),specularMapUv:_e&&m(T.specularMap.channel),specularColorMapUv:Le&&m(T.specularColorMap.channel),specularIntensityMapUv:H&&m(T.specularIntensityMap.channel),transmissionMapUv:Se&&m(T.transmissionMap.channel),thicknessMapUv:ke&&m(T.thicknessMap.channel),alphaMapUv:ge&&m(T.alphaMap.channel),vertexTangents:!!z.attributes.tangent&&(De||re),vertexColors:T.vertexColors,vertexAlphas:T.vertexColors===!0&&!!z.attributes.color&&z.attributes.color.itemSize===4,vertexUv1s:ve,vertexUv2s:ye,vertexUv3s:Ze,pointsUvs:k.isPoints===!0&&!!z.attributes.uv&&(Ce||ge),fog:!!C,useFog:T.fog===!0,fogExp2:C&&C.isFogExp2,flatShading:T.flatShading===!0,sizeAttenuation:T.sizeAttenuation===!0,logarithmicDepthBuffer:i,skinning:k.isSkinnedMesh===!0,morphTargets:z.morphAttributes.position!==void 0,morphNormals:z.morphAttributes.normal!==void 0,morphColors:z.morphAttributes.color!==void 0,morphTargetsCount:ee,morphTextureStride:he,numDirLights:E.directional.length,numPointLights:E.point.length,numSpotLights:E.spot.length,numSpotLightMaps:E.spotLightMap.length,numRectAreaLights:E.rectArea.length,numHemiLights:E.hemi.length,numDirLightShadows:E.directionalShadowMap.length,numPointLightShadows:E.pointShadowMap.length,numSpotLightShadows:E.spotShadowMap.length,numSpotLightShadowsWithMaps:E.numSpotLightShadowsWithMaps,numLightProbes:E.numLightProbes,numClippingPlanes:l.numPlanes,numClipIntersection:l.numIntersection,dithering:T.dithering,shadowMapEnabled:s.shadowMap.enabled&&R.length>0,shadowMapType:s.shadowMap.type,toneMapping:Ke,useLegacyLights:s._useLegacyLights,decodeVideoTexture:Ce&&T.map.isVideoTexture===!0&&ColorManagement.getTransfer(T.map.colorSpace)===SRGBTransfer,premultipliedAlpha:T.premultipliedAlpha,doubleSided:T.side===DoubleSide,flipSided:T.side===BackSide,useDepthPacking:T.depthPacking>=0,depthPacking:T.depthPacking||0,index0AttributeName:T.index0AttributeName,extensionDerivatives:ue&&T.extensions.derivatives===!0,extensionFragDepth:ue&&T.extensions.fragDepth===!0,extensionDrawBuffers:ue&&T.extensions.drawBuffers===!0,extensionShaderTextureLOD:ue&&T.extensions.shaderTextureLOD===!0,extensionClipCullDistance:ue&&T.extensions.clipCullDistance&&r.has("WEBGL_clip_cull_distance"),rendererExtensionFragDepth:d||r.has("EXT_frag_depth"),rendererExtensionDrawBuffers:d||r.has("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:d||r.has("EXT_shader_texture_lod"),rendererExtensionParallelShaderCompile:r.has("KHR_parallel_shader_compile"),customProgramCacheKey:T.customProgramCacheKey()}}function _(T){const E=[];if(T.shaderID?E.push(T.shaderID):(E.push(T.customVertexShaderID),E.push(T.customFragmentShaderID)),T.defines!==void 0)for(const R in T.defines)E.push(R),E.push(T.defines[R]);return T.isRawShaderMaterial===!1&&(b(E,T),y(E,T),E.push(s.outputColorSpace)),E.push(T.customProgramCacheKey),E.join()}function b(T,E){T.push(E.precision),T.push(E.outputColorSpace),T.push(E.envMapMode),T.push(E.envMapCubeUVHeight),T.push(E.mapUv),T.push(E.alphaMapUv),T.push(E.lightMapUv),T.push(E.aoMapUv),T.push(E.bumpMapUv),T.push(E.normalMapUv),T.push(E.displacementMapUv),T.push(E.emissiveMapUv),T.push(E.metalnessMapUv),T.push(E.roughnessMapUv),T.push(E.anisotropyMapUv),T.push(E.clearcoatMapUv),T.push(E.clearcoatNormalMapUv),T.push(E.clearcoatRoughnessMapUv),T.push(E.iridescenceMapUv),T.push(E.iridescenceThicknessMapUv),T.push(E.sheenColorMapUv),T.push(E.sheenRoughnessMapUv),T.push(E.specularMapUv),T.push(E.specularColorMapUv),T.push(E.specularIntensityMapUv),T.push(E.transmissionMapUv),T.push(E.thicknessMapUv),T.push(E.combine),T.push(E.fogExp2),T.push(E.sizeAttenuation),T.push(E.morphTargetsCount),T.push(E.morphAttributeCount),T.push(E.numDirLights),T.push(E.numPointLights),T.push(E.numSpotLights),T.push(E.numSpotLightMaps),T.push(E.numHemiLights),T.push(E.numRectAreaLights),T.push(E.numDirLightShadows),T.push(E.numPointLightShadows),T.push(E.numSpotLightShadows),T.push(E.numSpotLightShadowsWithMaps),T.push(E.numLightProbes),T.push(E.shadowMapType),T.push(E.toneMapping),T.push(E.numClippingPlanes),T.push(E.numClipIntersection),T.push(E.depthPacking)}function y(T,E){h.disableAll(),E.isWebGL2&&h.enable(0),E.supportsVertexTextures&&h.enable(1),E.instancing&&h.enable(2),E.instancingColor&&h.enable(3),E.matcap&&h.enable(4),E.envMap&&h.enable(5),E.normalMapObjectSpace&&h.enable(6),E.normalMapTangentSpace&&h.enable(7),E.clearcoat&&h.enable(8),E.iridescence&&h.enable(9),E.alphaTest&&h.enable(10),E.vertexColors&&h.enable(11),E.vertexAlphas&&h.enable(12),E.vertexUv1s&&h.enable(13),E.vertexUv2s&&h.enable(14),E.vertexUv3s&&h.enable(15),E.vertexTangents&&h.enable(16),E.anisotropy&&h.enable(17),E.alphaHash&&h.enable(18),E.batching&&h.enable(19),T.push(h.mask),h.disableAll(),E.fog&&h.enable(0),E.useFog&&h.enable(1),E.flatShading&&h.enable(2),E.logarithmicDepthBuffer&&h.enable(3),E.skinning&&h.enable(4),E.morphTargets&&h.enable(5),E.morphNormals&&h.enable(6),E.morphColors&&h.enable(7),E.premultipliedAlpha&&h.enable(8),E.shadowMapEnabled&&h.enable(9),E.useLegacyLights&&h.enable(10),E.doubleSided&&h.enable(11),E.flipSided&&h.enable(12),E.useDepthPacking&&h.enable(13),E.dithering&&h.enable(14),E.transmission&&h.enable(15),E.sheen&&h.enable(16),E.opaque&&h.enable(17),E.pointsUvs&&h.enable(18),E.decodeVideoTexture&&h.enable(19),T.push(h.mask)}function v(T){const E=u[T.type];let R;if(E){const I=ShaderLib[E];R=UniformsUtils.clone(I.uniforms)}else R=T.uniforms;return R}function x(T,E){let R;for(let I=0,k=f.length;I0?r.push(_):a.transparent===!0?o.push(_):t.push(_)}function p(i,n,a,u,m,g){const _=l(i,n,a,u,m,g);a.transmission>0?r.unshift(_):a.transparent===!0?o.unshift(_):t.unshift(_)}function f(i,n){t.length>1&&t.sort(i||painterSortStable),r.length>1&&r.sort(n||reversePainterSortStable),o.length>1&&o.sort(n||reversePainterSortStable)}function d(){for(let i=e,n=s.length;i=c.length?(l=new WebGLRenderList,c.push(l)):l=c[o],l}function t(){s=new WeakMap}return{get:e,dispose:t}}function UniformsCache(){const s={};return{get:function(e){if(s[e.id]!==void 0)return s[e.id];let t;switch(e.type){case"DirectionalLight":t={direction:new Vector3,color:new Color};break;case"SpotLight":t={position:new Vector3,direction:new Vector3,color:new Color,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":t={position:new Vector3,color:new Color,distance:0,decay:0};break;case"HemisphereLight":t={direction:new Vector3,skyColor:new Color,groundColor:new Color};break;case"RectAreaLight":t={color:new Color,position:new Vector3,halfWidth:new Vector3,halfHeight:new Vector3};break}return s[e.id]=t,t}}}function ShadowUniformsCache(){const s={};return{get:function(e){if(s[e.id]!==void 0)return s[e.id];let t;switch(e.type){case"DirectionalLight":t={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Vector2};break;case"SpotLight":t={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Vector2};break;case"PointLight":t={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new Vector2,shadowCameraNear:1,shadowCameraFar:1e3};break}return s[e.id]=t,t}}}let nextVersion=0;function shadowCastingAndTexturingLightsFirst(s,e){return(e.castShadow?2:0)-(s.castShadow?2:0)+(e.map?1:0)-(s.map?1:0)}function WebGLLights(s,e){const t=new UniformsCache,r=ShadowUniformsCache(),o={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let d=0;d<9;d++)o.probe.push(new Vector3);const c=new Vector3,l=new Matrix4,h=new Matrix4;function p(d,i){let n=0,a=0,u=0;for(let I=0;I<9;I++)o.probe[I].set(0,0,0);let m=0,g=0,_=0,b=0,y=0,v=0,x=0,w=0,S=0,M=0,T=0;d.sort(shadowCastingAndTexturingLightsFirst);const E=i===!0?Math.PI:1;for(let I=0,k=d.length;I0&&(e.isWebGL2?s.has("OES_texture_float_linear")===!0?(o.rectAreaLTC1=UniformsLib.LTC_FLOAT_1,o.rectAreaLTC2=UniformsLib.LTC_FLOAT_2):(o.rectAreaLTC1=UniformsLib.LTC_HALF_1,o.rectAreaLTC2=UniformsLib.LTC_HALF_2):s.has("OES_texture_float_linear")===!0?(o.rectAreaLTC1=UniformsLib.LTC_FLOAT_1,o.rectAreaLTC2=UniformsLib.LTC_FLOAT_2):s.has("OES_texture_half_float_linear")===!0?(o.rectAreaLTC1=UniformsLib.LTC_HALF_1,o.rectAreaLTC2=UniformsLib.LTC_HALF_2):console.error("THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.")),o.ambient[0]=n,o.ambient[1]=a,o.ambient[2]=u;const R=o.hash;(R.directionalLength!==m||R.pointLength!==g||R.spotLength!==_||R.rectAreaLength!==b||R.hemiLength!==y||R.numDirectionalShadows!==v||R.numPointShadows!==x||R.numSpotShadows!==w||R.numSpotMaps!==S||R.numLightProbes!==T)&&(o.directional.length=m,o.spot.length=_,o.rectArea.length=b,o.point.length=g,o.hemi.length=y,o.directionalShadow.length=v,o.directionalShadowMap.length=v,o.pointShadow.length=x,o.pointShadowMap.length=x,o.spotShadow.length=w,o.spotShadowMap.length=w,o.directionalShadowMatrix.length=v,o.pointShadowMatrix.length=x,o.spotLightMatrix.length=w+S-M,o.spotLightMap.length=S,o.numSpotLightShadowsWithMaps=M,o.numLightProbes=T,R.directionalLength=m,R.pointLength=g,R.spotLength=_,R.rectAreaLength=b,R.hemiLength=y,R.numDirectionalShadows=v,R.numPointShadows=x,R.numSpotShadows=w,R.numSpotMaps=S,R.numLightProbes=T,o.version=nextVersion++)}function f(d,i){let n=0,a=0,u=0,m=0,g=0;const _=i.matrixWorldInverse;for(let b=0,y=d.length;b=h.length?(p=new WebGLRenderState(s,e),h.push(p)):p=h[l],p}function o(){t=new WeakMap}return{get:r,dispose:o}}class MeshDepthMaterial extends Material{constructor(e){super(),this.isMeshDepthMaterial=!0,this.type="MeshDepthMaterial",this.depthPacking=BasicDepthPacking,this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(e)}copy(e){return super.copy(e),this.depthPacking=e.depthPacking,this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this}}class MeshDistanceMaterial extends Material{constructor(e){super(),this.isMeshDistanceMaterial=!0,this.type="MeshDistanceMaterial",this.map=null,this.alphaMap=null,this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.setValues(e)}copy(e){return super.copy(e),this.map=e.map,this.alphaMap=e.alphaMap,this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this}}const vertex=`void main() { gl_Position = vec4( position, 1.0 ); }`,fragment=`uniform sampler2D shadow_pass; uniform vec2 resolution; uniform float radius; #include void main() { const float samples = float( VSM_SAMPLES ); float mean = 0.0; float squared_mean = 0.0; float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 ); float uvStart = samples <= 1.0 ? 0.0 : - 1.0; for ( float i = 0.0; i < samples; i ++ ) { float uvOffset = uvStart + i * uvStride; #ifdef HORIZONTAL_PASS vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) ); mean += distribution.x; squared_mean += distribution.y * distribution.y + distribution.x * distribution.x; #else float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) ); mean += depth; squared_mean += depth * depth; #endif } mean = mean / samples; squared_mean = squared_mean / samples; float std_dev = sqrt( squared_mean - mean * mean ); gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) ); }`;function WebGLShadowMap(s,e,t){let r=new Frustum;const o=new Vector2,c=new Vector2,l=new Vector4,h=new MeshDepthMaterial({depthPacking:RGBADepthPacking}),p=new MeshDistanceMaterial,f={},d=t.maxTextureSize,i={[FrontSide]:BackSide,[BackSide]:FrontSide,[DoubleSide]:DoubleSide},n=new ShaderMaterial({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new Vector2},radius:{value:4}},vertexShader:vertex,fragmentShader:fragment}),a=n.clone();a.defines.HORIZONTAL_PASS=1;const u=new BufferGeometry;u.setAttribute("position",new BufferAttribute(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));const m=new Mesh(u,n),g=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=PCFShadowMap;let _=this.type;this.render=function(w,S,M){if(g.enabled===!1||g.autoUpdate===!1&&g.needsUpdate===!1||w.length===0)return;const T=s.getRenderTarget(),E=s.getActiveCubeFace(),R=s.getActiveMipmapLevel(),I=s.state;I.setBlending(NoBlending),I.buffers.color.setClear(1,1,1,1),I.buffers.depth.setTest(!0),I.setScissorTest(!1);const k=_!==VSMShadowMap&&this.type===VSMShadowMap,C=_===VSMShadowMap&&this.type!==VSMShadowMap;for(let z=0,O=w.length;zd||o.y>d)&&(o.x>d&&(c.x=Math.floor(d/$.x),o.x=c.x*$.x,K.mapSize.x=c.x),o.y>d&&(c.y=Math.floor(d/$.y),o.y=c.y*$.y,K.mapSize.y=c.y)),K.map===null||k===!0||C===!0){const ee=this.type!==VSMShadowMap?{minFilter:NearestFilter,magFilter:NearestFilter}:{};K.map!==null&&K.map.dispose(),K.map=new WebGLRenderTarget(o.x,o.y,ee),K.map.texture.name=U.name+".shadowMap",K.camera.updateProjectionMatrix()}s.setRenderTarget(K.map),s.clear();const J=K.getViewportCount();for(let ee=0;ee0||S.map&&S.alphaTest>0){const I=E.uuid,k=S.uuid;let C=f[I];C===void 0&&(C={},f[I]=C);let z=C[k];z===void 0&&(z=E.clone(),C[k]=z,S.addEventListener("dispose",x)),E=z}if(E.visible=S.visible,E.wireframe=S.wireframe,T===VSMShadowMap?E.side=S.shadowSide!==null?S.shadowSide:S.side:E.side=S.shadowSide!==null?S.shadowSide:i[S.side],E.alphaMap=S.alphaMap,E.alphaTest=S.alphaTest,E.map=S.map,E.clipShadows=S.clipShadows,E.clippingPlanes=S.clippingPlanes,E.clipIntersection=S.clipIntersection,E.displacementMap=S.displacementMap,E.displacementScale=S.displacementScale,E.displacementBias=S.displacementBias,E.wireframeLinewidth=S.wireframeLinewidth,E.linewidth=S.linewidth,M.isPointLight===!0&&E.isMeshDistanceMaterial===!0){const I=s.properties.get(E);I.light=M}return E}function v(w,S,M,T,E){if(w.visible===!1)return;if(w.layers.test(S.layers)&&(w.isMesh||w.isLine||w.isPoints)&&(w.castShadow||w.receiveShadow&&E===VSMShadowMap)&&(!w.frustumCulled||r.intersectsObject(w))){w.modelViewMatrix.multiplyMatrices(M.matrixWorldInverse,w.matrixWorld);const k=e.update(w),C=w.material;if(Array.isArray(C)){const z=k.groups;for(let O=0,U=z.length;O=1):J.indexOf("OpenGL ES")!==-1&&($=parseFloat(/^OpenGL ES (\d)/.exec(J)[1]),K=$>=2);let ee=null,he={};const ie=s.getParameter(s.SCISSOR_BOX),le=s.getParameter(s.VIEWPORT),de=new Vector4().fromArray(ie),Me=new Vector4().fromArray(le);function Ee(X,we,ue,ve){const ye=new Uint8Array(4),Ze=s.createTexture();s.bindTexture(X,Ze),s.texParameteri(X,s.TEXTURE_MIN_FILTER,s.NEAREST),s.texParameteri(X,s.TEXTURE_MAG_FILTER,s.NEAREST);for(let Ke=0;Ke"u"?!1:/OculusBrowser/g.test(navigator.userAgent),d=new WeakMap;let i;const n=new WeakMap;let a=!1;try{a=typeof OffscreenCanvas<"u"&&new OffscreenCanvas(1,1).getContext("2d")!==null}catch{}function u(B,D){return a?new OffscreenCanvas(B,D):createElementNS("canvas")}function m(B,D,re,ce){let fe=1;if((B.width>ce||B.height>ce)&&(fe=ce/Math.max(B.width,B.height)),fe<1||D===!0)if(typeof HTMLImageElement<"u"&&B instanceof HTMLImageElement||typeof HTMLCanvasElement<"u"&&B instanceof HTMLCanvasElement||typeof ImageBitmap<"u"&&B instanceof ImageBitmap){const pe=D?floorPowerOfTwo:Math.floor,Te=pe(fe*B.width),Oe=pe(fe*B.height);i===void 0&&(i=u(Te,Oe));const Ne=re?u(Te,Oe):i;return Ne.width=Te,Ne.height=Oe,Ne.getContext("2d").drawImage(B,0,0,Te,Oe),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+B.width+"x"+B.height+") to ("+Te+"x"+Oe+")."),Ne}else return"data"in B&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+B.width+"x"+B.height+")."),B;return B}function g(B){return isPowerOfTwo$1(B.width)&&isPowerOfTwo$1(B.height)}function _(B){return h?!1:B.wrapS!==ClampToEdgeWrapping||B.wrapT!==ClampToEdgeWrapping||B.minFilter!==NearestFilter&&B.minFilter!==LinearFilter}function b(B,D){return B.generateMipmaps&&D&&B.minFilter!==NearestFilter&&B.minFilter!==LinearFilter}function y(B){s.generateMipmap(B)}function v(B,D,re,ce,fe=!1){if(h===!1)return D;if(B!==null){if(s[B]!==void 0)return s[B];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+B+"'")}let pe=D;if(D===s.RED&&(re===s.FLOAT&&(pe=s.R32F),re===s.HALF_FLOAT&&(pe=s.R16F),re===s.UNSIGNED_BYTE&&(pe=s.R8)),D===s.RED_INTEGER&&(re===s.UNSIGNED_BYTE&&(pe=s.R8UI),re===s.UNSIGNED_SHORT&&(pe=s.R16UI),re===s.UNSIGNED_INT&&(pe=s.R32UI),re===s.BYTE&&(pe=s.R8I),re===s.SHORT&&(pe=s.R16I),re===s.INT&&(pe=s.R32I)),D===s.RG&&(re===s.FLOAT&&(pe=s.RG32F),re===s.HALF_FLOAT&&(pe=s.RG16F),re===s.UNSIGNED_BYTE&&(pe=s.RG8)),D===s.RGBA){const Te=fe?LinearTransfer:ColorManagement.getTransfer(ce);re===s.FLOAT&&(pe=s.RGBA32F),re===s.HALF_FLOAT&&(pe=s.RGBA16F),re===s.UNSIGNED_BYTE&&(pe=Te===SRGBTransfer?s.SRGB8_ALPHA8:s.RGBA8),re===s.UNSIGNED_SHORT_4_4_4_4&&(pe=s.RGBA4),re===s.UNSIGNED_SHORT_5_5_5_1&&(pe=s.RGB5_A1)}return(pe===s.R16F||pe===s.R32F||pe===s.RG16F||pe===s.RG32F||pe===s.RGBA16F||pe===s.RGBA32F)&&e.get("EXT_color_buffer_float"),pe}function x(B,D,re){return b(B,re)===!0||B.isFramebufferTexture&&B.minFilter!==NearestFilter&&B.minFilter!==LinearFilter?Math.log2(Math.max(D.width,D.height))+1:B.mipmaps!==void 0&&B.mipmaps.length>0?B.mipmaps.length:B.isCompressedTexture&&Array.isArray(B.image)?D.mipmaps.length:1}function w(B){return B===NearestFilter||B===NearestMipmapNearestFilter||B===NearestMipmapLinearFilter?s.NEAREST:s.LINEAR}function S(B){const D=B.target;D.removeEventListener("dispose",S),T(D),D.isVideoTexture&&d.delete(D)}function M(B){const D=B.target;D.removeEventListener("dispose",M),R(D)}function T(B){const D=r.get(B);if(D.__webglInit===void 0)return;const re=B.source,ce=n.get(re);if(ce){const fe=ce[D.__cacheKey];fe.usedTimes--,fe.usedTimes===0&&E(B),Object.keys(ce).length===0&&n.delete(re)}r.remove(B)}function E(B){const D=r.get(B);s.deleteTexture(D.__webglTexture);const re=B.source,ce=n.get(re);delete ce[D.__cacheKey],l.memory.textures--}function R(B){const D=B.texture,re=r.get(B),ce=r.get(D);if(ce.__webglTexture!==void 0&&(s.deleteTexture(ce.__webglTexture),l.memory.textures--),B.depthTexture&&B.depthTexture.dispose(),B.isWebGLCubeRenderTarget)for(let fe=0;fe<6;fe++){if(Array.isArray(re.__webglFramebuffer[fe]))for(let pe=0;pe=o.maxTextures&&console.warn("THREE.WebGLTextures: Trying to use "+B+" texture units while this GPU supports only "+o.maxTextures),I+=1,B}function z(B){const D=[];return D.push(B.wrapS),D.push(B.wrapT),D.push(B.wrapR||0),D.push(B.magFilter),D.push(B.minFilter),D.push(B.anisotropy),D.push(B.internalFormat),D.push(B.format),D.push(B.type),D.push(B.generateMipmaps),D.push(B.premultiplyAlpha),D.push(B.flipY),D.push(B.unpackAlignment),D.push(B.colorSpace),D.join()}function O(B,D){const re=r.get(B);if(B.isVideoTexture&&nt(B),B.isRenderTargetTexture===!1&&B.version>0&&re.__version!==B.version){const ce=B.image;if(ce===null)console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found.");else if(ce.complete===!1)console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete");else{de(re,B,D);return}}t.bindTexture(s.TEXTURE_2D,re.__webglTexture,s.TEXTURE0+D)}function U(B,D){const re=r.get(B);if(B.version>0&&re.__version!==B.version){de(re,B,D);return}t.bindTexture(s.TEXTURE_2D_ARRAY,re.__webglTexture,s.TEXTURE0+D)}function K(B,D){const re=r.get(B);if(B.version>0&&re.__version!==B.version){de(re,B,D);return}t.bindTexture(s.TEXTURE_3D,re.__webglTexture,s.TEXTURE0+D)}function $(B,D){const re=r.get(B);if(B.version>0&&re.__version!==B.version){Me(re,B,D);return}t.bindTexture(s.TEXTURE_CUBE_MAP,re.__webglTexture,s.TEXTURE0+D)}const J={[RepeatWrapping]:s.REPEAT,[ClampToEdgeWrapping]:s.CLAMP_TO_EDGE,[MirroredRepeatWrapping]:s.MIRRORED_REPEAT},ee={[NearestFilter]:s.NEAREST,[NearestMipmapNearestFilter]:s.NEAREST_MIPMAP_NEAREST,[NearestMipmapLinearFilter]:s.NEAREST_MIPMAP_LINEAR,[LinearFilter]:s.LINEAR,[LinearMipmapNearestFilter]:s.LINEAR_MIPMAP_NEAREST,[LinearMipmapLinearFilter]:s.LINEAR_MIPMAP_LINEAR},he={[NeverCompare]:s.NEVER,[AlwaysCompare]:s.ALWAYS,[LessCompare]:s.LESS,[LessEqualCompare]:s.LEQUAL,[EqualCompare]:s.EQUAL,[GreaterEqualCompare]:s.GEQUAL,[GreaterCompare]:s.GREATER,[NotEqualCompare]:s.NOTEQUAL};function ie(B,D,re){if(re?(s.texParameteri(B,s.TEXTURE_WRAP_S,J[D.wrapS]),s.texParameteri(B,s.TEXTURE_WRAP_T,J[D.wrapT]),(B===s.TEXTURE_3D||B===s.TEXTURE_2D_ARRAY)&&s.texParameteri(B,s.TEXTURE_WRAP_R,J[D.wrapR]),s.texParameteri(B,s.TEXTURE_MAG_FILTER,ee[D.magFilter]),s.texParameteri(B,s.TEXTURE_MIN_FILTER,ee[D.minFilter])):(s.texParameteri(B,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(B,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE),(B===s.TEXTURE_3D||B===s.TEXTURE_2D_ARRAY)&&s.texParameteri(B,s.TEXTURE_WRAP_R,s.CLAMP_TO_EDGE),(D.wrapS!==ClampToEdgeWrapping||D.wrapT!==ClampToEdgeWrapping)&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping."),s.texParameteri(B,s.TEXTURE_MAG_FILTER,w(D.magFilter)),s.texParameteri(B,s.TEXTURE_MIN_FILTER,w(D.minFilter)),D.minFilter!==NearestFilter&&D.minFilter!==LinearFilter&&console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.")),D.compareFunction&&(s.texParameteri(B,s.TEXTURE_COMPARE_MODE,s.COMPARE_REF_TO_TEXTURE),s.texParameteri(B,s.TEXTURE_COMPARE_FUNC,he[D.compareFunction])),e.has("EXT_texture_filter_anisotropic")===!0){const ce=e.get("EXT_texture_filter_anisotropic");if(D.magFilter===NearestFilter||D.minFilter!==NearestMipmapLinearFilter&&D.minFilter!==LinearMipmapLinearFilter||D.type===FloatType&&e.has("OES_texture_float_linear")===!1||h===!1&&D.type===HalfFloatType&&e.has("OES_texture_half_float_linear")===!1)return;(D.anisotropy>1||r.get(D).__currentAnisotropy)&&(s.texParameterf(B,ce.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(D.anisotropy,o.getMaxAnisotropy())),r.get(D).__currentAnisotropy=D.anisotropy)}}function le(B,D){let re=!1;B.__webglInit===void 0&&(B.__webglInit=!0,D.addEventListener("dispose",S));const ce=D.source;let fe=n.get(ce);fe===void 0&&(fe={},n.set(ce,fe));const pe=z(D);if(pe!==B.__cacheKey){fe[pe]===void 0&&(fe[pe]={texture:s.createTexture(),usedTimes:0},l.memory.textures++,re=!0),fe[pe].usedTimes++;const Te=fe[B.__cacheKey];Te!==void 0&&(fe[B.__cacheKey].usedTimes--,Te.usedTimes===0&&E(D)),B.__cacheKey=pe,B.__webglTexture=fe[pe].texture}return re}function de(B,D,re){let ce=s.TEXTURE_2D;(D.isDataArrayTexture||D.isCompressedArrayTexture)&&(ce=s.TEXTURE_2D_ARRAY),D.isData3DTexture&&(ce=s.TEXTURE_3D);const fe=le(B,D),pe=D.source;t.bindTexture(ce,B.__webglTexture,s.TEXTURE0+re);const Te=r.get(pe);if(pe.version!==Te.__version||fe===!0){t.activeTexture(s.TEXTURE0+re);const Oe=ColorManagement.getPrimaries(ColorManagement.workingColorSpace),Ne=D.colorSpace===NoColorSpace?null:ColorManagement.getPrimaries(D.colorSpace),He=D.colorSpace===NoColorSpace||Oe===Ne?s.NONE:s.BROWSER_DEFAULT_WEBGL;s.pixelStorei(s.UNPACK_FLIP_Y_WEBGL,D.flipY),s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL,D.premultiplyAlpha),s.pixelStorei(s.UNPACK_ALIGNMENT,D.unpackAlignment),s.pixelStorei(s.UNPACK_COLORSPACE_CONVERSION_WEBGL,He);const Xe=_(D)&&g(D.image)===!1;let me=m(D.image,Xe,!1,o.maxTextureSize);me=qe(D,me);const rt=g(me)||h,Ge=c.convert(D.format,D.colorSpace);let We=c.convert(D.type),_e=v(D.internalFormat,Ge,We,D.colorSpace,D.isVideoTexture);ie(ce,D,rt);let Le;const H=D.mipmaps,Se=h&&D.isVideoTexture!==!0&&_e!==RGB_ETC1_Format,ke=Te.__version===void 0||fe===!0,be=x(D,me,rt);if(D.isDepthTexture)_e=s.DEPTH_COMPONENT,h?D.type===FloatType?_e=s.DEPTH_COMPONENT32F:D.type===UnsignedIntType?_e=s.DEPTH_COMPONENT24:D.type===UnsignedInt248Type?_e=s.DEPTH24_STENCIL8:_e=s.DEPTH_COMPONENT16:D.type===FloatType&&console.error("WebGLRenderer: Floating point depth texture requires WebGL2."),D.format===DepthFormat&&_e===s.DEPTH_COMPONENT&&D.type!==UnsignedShortType&&D.type!==UnsignedIntType&&(console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."),D.type=UnsignedIntType,We=c.convert(D.type)),D.format===DepthStencilFormat&&_e===s.DEPTH_COMPONENT&&(_e=s.DEPTH_STENCIL,D.type!==UnsignedInt248Type&&(console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."),D.type=UnsignedInt248Type,We=c.convert(D.type))),ke&&(Se?t.texStorage2D(s.TEXTURE_2D,1,_e,me.width,me.height):t.texImage2D(s.TEXTURE_2D,0,_e,me.width,me.height,0,Ge,We,null));else if(D.isDataTexture)if(H.length>0&&rt){Se&&ke&&t.texStorage2D(s.TEXTURE_2D,be,_e,H[0].width,H[0].height);for(let ge=0,X=H.length;ge>=1,X>>=1}}else if(H.length>0&&rt){Se&&ke&&t.texStorage2D(s.TEXTURE_2D,be,_e,H[0].width,H[0].height);for(let ge=0,X=H.length;ge0&&ke++,t.texStorage2D(s.TEXTURE_CUBE_MAP,ke,Le,me[0].width,me[0].height));for(let ge=0;ge<6;ge++)if(Xe){H?t.texSubImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+ge,0,0,0,me[ge].width,me[ge].height,We,_e,me[ge].data):t.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+ge,0,Le,me[ge].width,me[ge].height,0,We,_e,me[ge].data);for(let X=0;X>pe),me=Math.max(1,D.height>>pe);fe===s.TEXTURE_3D||fe===s.TEXTURE_2D_ARRAY?t.texImage3D(fe,pe,Ne,Xe,me,D.depth,0,Te,Oe,null):t.texImage2D(fe,pe,Ne,Xe,me,0,Te,Oe,null)}t.bindFramebuffer(s.FRAMEBUFFER,B),De(D)?p.framebufferTexture2DMultisampleEXT(s.FRAMEBUFFER,ce,fe,r.get(re).__webglTexture,0,ze(D)):(fe===s.TEXTURE_2D||fe>=s.TEXTURE_CUBE_MAP_POSITIVE_X&&fe<=s.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&s.framebufferTexture2D(s.FRAMEBUFFER,ce,fe,r.get(re).__webglTexture,pe),t.bindFramebuffer(s.FRAMEBUFFER,null)}function Fe(B,D,re){if(s.bindRenderbuffer(s.RENDERBUFFER,B),D.depthBuffer&&!D.stencilBuffer){let ce=h===!0?s.DEPTH_COMPONENT24:s.DEPTH_COMPONENT16;if(re||De(D)){const fe=D.depthTexture;fe&&fe.isDepthTexture&&(fe.type===FloatType?ce=s.DEPTH_COMPONENT32F:fe.type===UnsignedIntType&&(ce=s.DEPTH_COMPONENT24));const pe=ze(D);De(D)?p.renderbufferStorageMultisampleEXT(s.RENDERBUFFER,pe,ce,D.width,D.height):s.renderbufferStorageMultisample(s.RENDERBUFFER,pe,ce,D.width,D.height)}else s.renderbufferStorage(s.RENDERBUFFER,ce,D.width,D.height);s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_ATTACHMENT,s.RENDERBUFFER,B)}else if(D.depthBuffer&&D.stencilBuffer){const ce=ze(D);re&&De(D)===!1?s.renderbufferStorageMultisample(s.RENDERBUFFER,ce,s.DEPTH24_STENCIL8,D.width,D.height):De(D)?p.renderbufferStorageMultisampleEXT(s.RENDERBUFFER,ce,s.DEPTH24_STENCIL8,D.width,D.height):s.renderbufferStorage(s.RENDERBUFFER,s.DEPTH_STENCIL,D.width,D.height),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.DEPTH_STENCIL_ATTACHMENT,s.RENDERBUFFER,B)}else{const ce=D.isWebGLMultipleRenderTargets===!0?D.texture:[D.texture];for(let fe=0;fe0){re.__webglFramebuffer[Oe]=[];for(let Ne=0;Ne0){re.__webglFramebuffer=[];for(let Oe=0;Oe0&&De(B)===!1){const Oe=pe?D:[D];re.__webglMultisampledFramebuffer=s.createFramebuffer(),re.__webglColorRenderbuffer=[],t.bindFramebuffer(s.FRAMEBUFFER,re.__webglMultisampledFramebuffer);for(let Ne=0;Ne0)for(let Ne=0;Ne0)for(let Ne=0;Ne0&&De(B)===!1){const D=B.isWebGLMultipleRenderTargets?B.texture:[B.texture],re=B.width,ce=B.height;let fe=s.COLOR_BUFFER_BIT;const pe=[],Te=B.stencilBuffer?s.DEPTH_STENCIL_ATTACHMENT:s.DEPTH_ATTACHMENT,Oe=r.get(B),Ne=B.isWebGLMultipleRenderTargets===!0;if(Ne)for(let He=0;He0&&e.has("WEBGL_multisampled_render_to_texture")===!0&&D.__useRenderToTexture!==!1}function nt(B){const D=l.render.frame;d.get(B)!==D&&(d.set(B,D),B.update())}function qe(B,D){const re=B.colorSpace,ce=B.format,fe=B.type;return B.isCompressedTexture===!0||B.isVideoTexture===!0||B.format===_SRGBAFormat||re!==LinearSRGBColorSpace&&re!==NoColorSpace&&(ColorManagement.getTransfer(re)===SRGBTransfer?h===!1?e.has("EXT_sRGB")===!0&&ce===RGBAFormat?(B.format=_SRGBAFormat,B.minFilter=LinearFilter,B.generateMipmaps=!1):D=ImageUtils.sRGBToLinear(D):(ce!==RGBAFormat||fe!==UnsignedByteType)&&console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."):console.error("THREE.WebGLTextures: Unsupported texture color space:",re)),D}this.allocateTextureUnit=C,this.resetTextureUnits=k,this.setTexture2D=O,this.setTexture2DArray=U,this.setTexture3D=K,this.setTextureCube=$,this.rebindTextures=je,this.setupRenderTarget=ne,this.updateRenderTargetMipmap=Qe,this.updateMultisampleRenderTarget=Pe,this.setupDepthRenderbuffer=Ce,this.setupFrameBufferTexture=Ee,this.useMultisampledRTT=De}function WebGLUtils(s,e,t){const r=t.isWebGL2;function o(c,l=NoColorSpace){let h;const p=ColorManagement.getTransfer(l);if(c===UnsignedByteType)return s.UNSIGNED_BYTE;if(c===UnsignedShort4444Type)return s.UNSIGNED_SHORT_4_4_4_4;if(c===UnsignedShort5551Type)return s.UNSIGNED_SHORT_5_5_5_1;if(c===ByteType)return s.BYTE;if(c===ShortType)return s.SHORT;if(c===UnsignedShortType)return s.UNSIGNED_SHORT;if(c===IntType)return s.INT;if(c===UnsignedIntType)return s.UNSIGNED_INT;if(c===FloatType)return s.FLOAT;if(c===HalfFloatType)return r?s.HALF_FLOAT:(h=e.get("OES_texture_half_float"),h!==null?h.HALF_FLOAT_OES:null);if(c===AlphaFormat)return s.ALPHA;if(c===RGBAFormat)return s.RGBA;if(c===LuminanceFormat)return s.LUMINANCE;if(c===LuminanceAlphaFormat)return s.LUMINANCE_ALPHA;if(c===DepthFormat)return s.DEPTH_COMPONENT;if(c===DepthStencilFormat)return s.DEPTH_STENCIL;if(c===_SRGBAFormat)return h=e.get("EXT_sRGB"),h!==null?h.SRGB_ALPHA_EXT:null;if(c===RedFormat)return s.RED;if(c===RedIntegerFormat)return s.RED_INTEGER;if(c===RGFormat)return s.RG;if(c===RGIntegerFormat)return s.RG_INTEGER;if(c===RGBAIntegerFormat)return s.RGBA_INTEGER;if(c===RGB_S3TC_DXT1_Format||c===RGBA_S3TC_DXT1_Format||c===RGBA_S3TC_DXT3_Format||c===RGBA_S3TC_DXT5_Format)if(p===SRGBTransfer)if(h=e.get("WEBGL_compressed_texture_s3tc_srgb"),h!==null){if(c===RGB_S3TC_DXT1_Format)return h.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(c===RGBA_S3TC_DXT1_Format)return h.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(c===RGBA_S3TC_DXT3_Format)return h.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(c===RGBA_S3TC_DXT5_Format)return h.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null;else if(h=e.get("WEBGL_compressed_texture_s3tc"),h!==null){if(c===RGB_S3TC_DXT1_Format)return h.COMPRESSED_RGB_S3TC_DXT1_EXT;if(c===RGBA_S3TC_DXT1_Format)return h.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(c===RGBA_S3TC_DXT3_Format)return h.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(c===RGBA_S3TC_DXT5_Format)return h.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null;if(c===RGB_PVRTC_4BPPV1_Format||c===RGB_PVRTC_2BPPV1_Format||c===RGBA_PVRTC_4BPPV1_Format||c===RGBA_PVRTC_2BPPV1_Format)if(h=e.get("WEBGL_compressed_texture_pvrtc"),h!==null){if(c===RGB_PVRTC_4BPPV1_Format)return h.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(c===RGB_PVRTC_2BPPV1_Format)return h.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(c===RGBA_PVRTC_4BPPV1_Format)return h.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(c===RGBA_PVRTC_2BPPV1_Format)return h.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null;if(c===RGB_ETC1_Format)return h=e.get("WEBGL_compressed_texture_etc1"),h!==null?h.COMPRESSED_RGB_ETC1_WEBGL:null;if(c===RGB_ETC2_Format||c===RGBA_ETC2_EAC_Format)if(h=e.get("WEBGL_compressed_texture_etc"),h!==null){if(c===RGB_ETC2_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ETC2:h.COMPRESSED_RGB8_ETC2;if(c===RGBA_ETC2_EAC_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:h.COMPRESSED_RGBA8_ETC2_EAC}else return null;if(c===RGBA_ASTC_4x4_Format||c===RGBA_ASTC_5x4_Format||c===RGBA_ASTC_5x5_Format||c===RGBA_ASTC_6x5_Format||c===RGBA_ASTC_6x6_Format||c===RGBA_ASTC_8x5_Format||c===RGBA_ASTC_8x6_Format||c===RGBA_ASTC_8x8_Format||c===RGBA_ASTC_10x5_Format||c===RGBA_ASTC_10x6_Format||c===RGBA_ASTC_10x8_Format||c===RGBA_ASTC_10x10_Format||c===RGBA_ASTC_12x10_Format||c===RGBA_ASTC_12x12_Format)if(h=e.get("WEBGL_compressed_texture_astc"),h!==null){if(c===RGBA_ASTC_4x4_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:h.COMPRESSED_RGBA_ASTC_4x4_KHR;if(c===RGBA_ASTC_5x4_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:h.COMPRESSED_RGBA_ASTC_5x4_KHR;if(c===RGBA_ASTC_5x5_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:h.COMPRESSED_RGBA_ASTC_5x5_KHR;if(c===RGBA_ASTC_6x5_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:h.COMPRESSED_RGBA_ASTC_6x5_KHR;if(c===RGBA_ASTC_6x6_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:h.COMPRESSED_RGBA_ASTC_6x6_KHR;if(c===RGBA_ASTC_8x5_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:h.COMPRESSED_RGBA_ASTC_8x5_KHR;if(c===RGBA_ASTC_8x6_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:h.COMPRESSED_RGBA_ASTC_8x6_KHR;if(c===RGBA_ASTC_8x8_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:h.COMPRESSED_RGBA_ASTC_8x8_KHR;if(c===RGBA_ASTC_10x5_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:h.COMPRESSED_RGBA_ASTC_10x5_KHR;if(c===RGBA_ASTC_10x6_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:h.COMPRESSED_RGBA_ASTC_10x6_KHR;if(c===RGBA_ASTC_10x8_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:h.COMPRESSED_RGBA_ASTC_10x8_KHR;if(c===RGBA_ASTC_10x10_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:h.COMPRESSED_RGBA_ASTC_10x10_KHR;if(c===RGBA_ASTC_12x10_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:h.COMPRESSED_RGBA_ASTC_12x10_KHR;if(c===RGBA_ASTC_12x12_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:h.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null;if(c===RGBA_BPTC_Format||c===RGB_BPTC_SIGNED_Format||c===RGB_BPTC_UNSIGNED_Format)if(h=e.get("EXT_texture_compression_bptc"),h!==null){if(c===RGBA_BPTC_Format)return p===SRGBTransfer?h.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:h.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(c===RGB_BPTC_SIGNED_Format)return h.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(c===RGB_BPTC_UNSIGNED_Format)return h.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null;if(c===RED_RGTC1_Format||c===SIGNED_RED_RGTC1_Format||c===RED_GREEN_RGTC2_Format||c===SIGNED_RED_GREEN_RGTC2_Format)if(h=e.get("EXT_texture_compression_rgtc"),h!==null){if(c===RGBA_BPTC_Format)return h.COMPRESSED_RED_RGTC1_EXT;if(c===SIGNED_RED_RGTC1_Format)return h.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(c===RED_GREEN_RGTC2_Format)return h.COMPRESSED_RED_GREEN_RGTC2_EXT;if(c===SIGNED_RED_GREEN_RGTC2_Format)return h.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null;return c===UnsignedInt248Type?r?s.UNSIGNED_INT_24_8:(h=e.get("WEBGL_depth_texture"),h!==null?h.UNSIGNED_INT_24_8_WEBGL:null):s[c]!==void 0?s[c]:null}return{convert:o}}class ArrayCamera extends PerspectiveCamera{constructor(e=[]){super(),this.isArrayCamera=!0,this.cameras=e}}class Group extends Object3D{constructor(){super(),this.isGroup=!0,this.type="Group"}}const _moveEvent={type:"move"};class WebXRController{constructor(){this._targetRay=null,this._grip=null,this._hand=null}getHandSpace(){return this._hand===null&&(this._hand=new Group,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints={},this._hand.inputState={pinching:!1}),this._hand}getTargetRaySpace(){return this._targetRay===null&&(this._targetRay=new Group,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1,this._targetRay.hasLinearVelocity=!1,this._targetRay.linearVelocity=new Vector3,this._targetRay.hasAngularVelocity=!1,this._targetRay.angularVelocity=new Vector3),this._targetRay}getGripSpace(){return this._grip===null&&(this._grip=new Group,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1,this._grip.hasLinearVelocity=!1,this._grip.linearVelocity=new Vector3,this._grip.hasAngularVelocity=!1,this._grip.angularVelocity=new Vector3),this._grip}dispatchEvent(e){return this._targetRay!==null&&this._targetRay.dispatchEvent(e),this._grip!==null&&this._grip.dispatchEvent(e),this._hand!==null&&this._hand.dispatchEvent(e),this}connect(e){if(e&&e.hand){const t=this._hand;if(t)for(const r of e.hand.values())this._getHandJoint(t,r)}return this.dispatchEvent({type:"connected",data:e}),this}disconnect(e){return this.dispatchEvent({type:"disconnected",data:e}),this._targetRay!==null&&(this._targetRay.visible=!1),this._grip!==null&&(this._grip.visible=!1),this._hand!==null&&(this._hand.visible=!1),this}update(e,t,r){let o=null,c=null,l=null;const h=this._targetRay,p=this._grip,f=this._hand;if(e&&t.session.visibilityState!=="visible-blurred"){if(f&&e.hand){l=!0;for(const m of e.hand.values()){const g=t.getJointPose(m,r),_=this._getHandJoint(f,m);g!==null&&(_.matrix.fromArray(g.transform.matrix),_.matrix.decompose(_.position,_.rotation,_.scale),_.matrixWorldNeedsUpdate=!0,_.jointRadius=g.radius),_.visible=g!==null}const d=f.joints["index-finger-tip"],i=f.joints["thumb-tip"],n=d.position.distanceTo(i.position),a=.02,u=.005;f.inputState.pinching&&n>a+u?(f.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:e.handedness,target:this})):!f.inputState.pinching&&n<=a-u&&(f.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:e.handedness,target:this}))}else p!==null&&e.gripSpace&&(c=t.getPose(e.gripSpace,r),c!==null&&(p.matrix.fromArray(c.transform.matrix),p.matrix.decompose(p.position,p.rotation,p.scale),p.matrixWorldNeedsUpdate=!0,c.linearVelocity?(p.hasLinearVelocity=!0,p.linearVelocity.copy(c.linearVelocity)):p.hasLinearVelocity=!1,c.angularVelocity?(p.hasAngularVelocity=!0,p.angularVelocity.copy(c.angularVelocity)):p.hasAngularVelocity=!1));h!==null&&(o=t.getPose(e.targetRaySpace,r),o===null&&c!==null&&(o=c),o!==null&&(h.matrix.fromArray(o.transform.matrix),h.matrix.decompose(h.position,h.rotation,h.scale),h.matrixWorldNeedsUpdate=!0,o.linearVelocity?(h.hasLinearVelocity=!0,h.linearVelocity.copy(o.linearVelocity)):h.hasLinearVelocity=!1,o.angularVelocity?(h.hasAngularVelocity=!0,h.angularVelocity.copy(o.angularVelocity)):h.hasAngularVelocity=!1,this.dispatchEvent(_moveEvent)))}return h!==null&&(h.visible=o!==null),p!==null&&(p.visible=c!==null),f!==null&&(f.visible=l!==null),this}_getHandJoint(e,t){if(e.joints[t.jointName]===void 0){const r=new Group;r.matrixAutoUpdate=!1,r.visible=!1,e.joints[t.jointName]=r,e.add(r)}return e.joints[t.jointName]}}class WebXRManager extends EventDispatcher{constructor(e,t){super();const r=this;let o=null,c=1,l=null,h="local-floor",p=1,f=null,d=null,i=null,n=null,a=null,u=null;const m=t.getContextAttributes();let g=null,_=null;const b=[],y=[],v=new Vector2;let x=null;const w=new PerspectiveCamera;w.layers.enable(1),w.viewport=new Vector4;const S=new PerspectiveCamera;S.layers.enable(2),S.viewport=new Vector4;const M=[w,S],T=new ArrayCamera;T.layers.enable(1),T.layers.enable(2);let E=null,R=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(ie){let le=b[ie];return le===void 0&&(le=new WebXRController,b[ie]=le),le.getTargetRaySpace()},this.getControllerGrip=function(ie){let le=b[ie];return le===void 0&&(le=new WebXRController,b[ie]=le),le.getGripSpace()},this.getHand=function(ie){let le=b[ie];return le===void 0&&(le=new WebXRController,b[ie]=le),le.getHandSpace()};function I(ie){const le=y.indexOf(ie.inputSource);if(le===-1)return;const de=b[le];de!==void 0&&(de.update(ie.inputSource,ie.frame,f||l),de.dispatchEvent({type:ie.type,data:ie.inputSource}))}function k(){o.removeEventListener("select",I),o.removeEventListener("selectstart",I),o.removeEventListener("selectend",I),o.removeEventListener("squeeze",I),o.removeEventListener("squeezestart",I),o.removeEventListener("squeezeend",I),o.removeEventListener("end",k),o.removeEventListener("inputsourceschange",C);for(let ie=0;ie=0&&(y[Me]=null,b[Me].disconnect(de))}for(let le=0;le=y.length){y.push(de),Me=Fe;break}else if(y[Fe]===null){y[Fe]=de,Me=Fe;break}if(Me===-1)break}const Ee=b[Me];Ee&&Ee.connect(de)}}const z=new Vector3,O=new Vector3;function U(ie,le,de){z.setFromMatrixPosition(le.matrixWorld),O.setFromMatrixPosition(de.matrixWorld);const Me=z.distanceTo(O),Ee=le.projectionMatrix.elements,Fe=de.projectionMatrix.elements,Be=Ee[14]/(Ee[10]-1),Ce=Ee[14]/(Ee[10]+1),je=(Ee[9]+1)/Ee[5],ne=(Ee[9]-1)/Ee[5],Qe=(Ee[8]-1)/Ee[0],Pe=(Fe[8]+1)/Fe[0],ze=Be*Qe,De=Be*Pe,nt=Me/(-Qe+Pe),qe=nt*-Qe;le.matrixWorld.decompose(ie.position,ie.quaternion,ie.scale),ie.translateX(qe),ie.translateZ(nt),ie.matrixWorld.compose(ie.position,ie.quaternion,ie.scale),ie.matrixWorldInverse.copy(ie.matrixWorld).invert();const B=Be+nt,D=Ce+nt,re=ze-qe,ce=De+(Me-qe),fe=je*Ce/D*B,pe=ne*Ce/D*B;ie.projectionMatrix.makePerspective(re,ce,fe,pe,B,D),ie.projectionMatrixInverse.copy(ie.projectionMatrix).invert()}function K(ie,le){le===null?ie.matrixWorld.copy(ie.matrix):ie.matrixWorld.multiplyMatrices(le.matrixWorld,ie.matrix),ie.matrixWorldInverse.copy(ie.matrixWorld).invert()}this.updateCamera=function(ie){if(o===null)return;T.near=S.near=w.near=ie.near,T.far=S.far=w.far=ie.far,(E!==T.near||R!==T.far)&&(o.updateRenderState({depthNear:T.near,depthFar:T.far}),E=T.near,R=T.far);const le=ie.parent,de=T.cameras;K(T,le);for(let Me=0;Me0&&(g.alphaTest.value=_.alphaTest);const b=e.get(_).envMap;if(b&&(g.envMap.value=b,g.flipEnvMap.value=b.isCubeTexture&&b.isRenderTargetTexture===!1?-1:1,g.reflectivity.value=_.reflectivity,g.ior.value=_.ior,g.refractionRatio.value=_.refractionRatio),_.lightMap){g.lightMap.value=_.lightMap;const y=s._useLegacyLights===!0?Math.PI:1;g.lightMapIntensity.value=_.lightMapIntensity*y,t(_.lightMap,g.lightMapTransform)}_.aoMap&&(g.aoMap.value=_.aoMap,g.aoMapIntensity.value=_.aoMapIntensity,t(_.aoMap,g.aoMapTransform))}function l(g,_){g.diffuse.value.copy(_.color),g.opacity.value=_.opacity,_.map&&(g.map.value=_.map,t(_.map,g.mapTransform))}function h(g,_){g.dashSize.value=_.dashSize,g.totalSize.value=_.dashSize+_.gapSize,g.scale.value=_.scale}function p(g,_,b,y){g.diffuse.value.copy(_.color),g.opacity.value=_.opacity,g.size.value=_.size*b,g.scale.value=y*.5,_.map&&(g.map.value=_.map,t(_.map,g.uvTransform)),_.alphaMap&&(g.alphaMap.value=_.alphaMap,t(_.alphaMap,g.alphaMapTransform)),_.alphaTest>0&&(g.alphaTest.value=_.alphaTest)}function f(g,_){g.diffuse.value.copy(_.color),g.opacity.value=_.opacity,g.rotation.value=_.rotation,_.map&&(g.map.value=_.map,t(_.map,g.mapTransform)),_.alphaMap&&(g.alphaMap.value=_.alphaMap,t(_.alphaMap,g.alphaMapTransform)),_.alphaTest>0&&(g.alphaTest.value=_.alphaTest)}function d(g,_){g.specular.value.copy(_.specular),g.shininess.value=Math.max(_.shininess,1e-4)}function i(g,_){_.gradientMap&&(g.gradientMap.value=_.gradientMap)}function n(g,_){g.metalness.value=_.metalness,_.metalnessMap&&(g.metalnessMap.value=_.metalnessMap,t(_.metalnessMap,g.metalnessMapTransform)),g.roughness.value=_.roughness,_.roughnessMap&&(g.roughnessMap.value=_.roughnessMap,t(_.roughnessMap,g.roughnessMapTransform)),e.get(_).envMap&&(g.envMapIntensity.value=_.envMapIntensity)}function a(g,_,b){g.ior.value=_.ior,_.sheen>0&&(g.sheenColor.value.copy(_.sheenColor).multiplyScalar(_.sheen),g.sheenRoughness.value=_.sheenRoughness,_.sheenColorMap&&(g.sheenColorMap.value=_.sheenColorMap,t(_.sheenColorMap,g.sheenColorMapTransform)),_.sheenRoughnessMap&&(g.sheenRoughnessMap.value=_.sheenRoughnessMap,t(_.sheenRoughnessMap,g.sheenRoughnessMapTransform))),_.clearcoat>0&&(g.clearcoat.value=_.clearcoat,g.clearcoatRoughness.value=_.clearcoatRoughness,_.clearcoatMap&&(g.clearcoatMap.value=_.clearcoatMap,t(_.clearcoatMap,g.clearcoatMapTransform)),_.clearcoatRoughnessMap&&(g.clearcoatRoughnessMap.value=_.clearcoatRoughnessMap,t(_.clearcoatRoughnessMap,g.clearcoatRoughnessMapTransform)),_.clearcoatNormalMap&&(g.clearcoatNormalMap.value=_.clearcoatNormalMap,t(_.clearcoatNormalMap,g.clearcoatNormalMapTransform),g.clearcoatNormalScale.value.copy(_.clearcoatNormalScale),_.side===BackSide&&g.clearcoatNormalScale.value.negate())),_.iridescence>0&&(g.iridescence.value=_.iridescence,g.iridescenceIOR.value=_.iridescenceIOR,g.iridescenceThicknessMinimum.value=_.iridescenceThicknessRange[0],g.iridescenceThicknessMaximum.value=_.iridescenceThicknessRange[1],_.iridescenceMap&&(g.iridescenceMap.value=_.iridescenceMap,t(_.iridescenceMap,g.iridescenceMapTransform)),_.iridescenceThicknessMap&&(g.iridescenceThicknessMap.value=_.iridescenceThicknessMap,t(_.iridescenceThicknessMap,g.iridescenceThicknessMapTransform))),_.transmission>0&&(g.transmission.value=_.transmission,g.transmissionSamplerMap.value=b.texture,g.transmissionSamplerSize.value.set(b.width,b.height),_.transmissionMap&&(g.transmissionMap.value=_.transmissionMap,t(_.transmissionMap,g.transmissionMapTransform)),g.thickness.value=_.thickness,_.thicknessMap&&(g.thicknessMap.value=_.thicknessMap,t(_.thicknessMap,g.thicknessMapTransform)),g.attenuationDistance.value=_.attenuationDistance,g.attenuationColor.value.copy(_.attenuationColor)),_.anisotropy>0&&(g.anisotropyVector.value.set(_.anisotropy*Math.cos(_.anisotropyRotation),_.anisotropy*Math.sin(_.anisotropyRotation)),_.anisotropyMap&&(g.anisotropyMap.value=_.anisotropyMap,t(_.anisotropyMap,g.anisotropyMapTransform))),g.specularIntensity.value=_.specularIntensity,g.specularColor.value.copy(_.specularColor),_.specularColorMap&&(g.specularColorMap.value=_.specularColorMap,t(_.specularColorMap,g.specularColorMapTransform)),_.specularIntensityMap&&(g.specularIntensityMap.value=_.specularIntensityMap,t(_.specularIntensityMap,g.specularIntensityMapTransform))}function u(g,_){_.matcap&&(g.matcap.value=_.matcap)}function m(g,_){const b=e.get(_).light;g.referencePosition.value.setFromMatrixPosition(b.matrixWorld),g.nearDistance.value=b.shadow.camera.near,g.farDistance.value=b.shadow.camera.far}return{refreshFogUniforms:r,refreshMaterialUniforms:o}}function WebGLUniformsGroups(s,e,t,r){let o={},c={},l=[];const h=t.isWebGL2?s.getParameter(s.MAX_UNIFORM_BUFFER_BINDINGS):0;function p(b,y){const v=y.program;r.uniformBlockBinding(b,v)}function f(b,y){let v=o[b.id];v===void 0&&(u(b),v=d(b),o[b.id]=v,b.addEventListener("dispose",g));const x=y.program;r.updateUBOMapping(b,x);const w=e.render.frame;c[b.id]!==w&&(n(b),c[b.id]=w)}function d(b){const y=i();b.__bindingPointIndex=y;const v=s.createBuffer(),x=b.__size,w=b.usage;return s.bindBuffer(s.UNIFORM_BUFFER,v),s.bufferData(s.UNIFORM_BUFFER,x,w),s.bindBuffer(s.UNIFORM_BUFFER,null),s.bindBufferBase(s.UNIFORM_BUFFER,y,v),v}function i(){for(let b=0;b0&&(v+=x-w),b.__size=v,b.__cache={},this}function m(b){const y={boundary:0,storage:0};return typeof b=="number"||typeof b=="boolean"?(y.boundary=4,y.storage=4):b.isVector2?(y.boundary=8,y.storage=8):b.isVector3||b.isColor?(y.boundary=16,y.storage=12):b.isVector4?(y.boundary=16,y.storage=16):b.isMatrix3?(y.boundary=48,y.storage=48):b.isMatrix4?(y.boundary=64,y.storage=64):b.isTexture?console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."):console.warn("THREE.WebGLRenderer: Unsupported uniform value type.",b),y}function g(b){const y=b.target;y.removeEventListener("dispose",g);const v=l.indexOf(y.__bindingPointIndex);l.splice(v,1),s.deleteBuffer(o[y.id]),delete o[y.id],delete c[y.id]}function _(){for(const b in o)s.deleteBuffer(o[b]);l=[],o={},c={}}return{bind:p,update:f,dispose:_}}class WebGLRenderer{constructor(e={}){const{canvas:t=createCanvasElement(),context:r=null,depth:o=!0,stencil:c=!0,alpha:l=!1,antialias:h=!1,premultipliedAlpha:p=!0,preserveDrawingBuffer:f=!1,powerPreference:d="default",failIfMajorPerformanceCaveat:i=!1}=e;this.isWebGLRenderer=!0;let n;r!==null?n=r.getContextAttributes().alpha:n=l;const a=new Uint32Array(4),u=new Int32Array(4);let m=null,g=null;const _=[],b=[];this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this._outputColorSpace=SRGBColorSpace,this._useLegacyLights=!1,this.toneMapping=NoToneMapping,this.toneMappingExposure=1;const y=this;let v=!1,x=0,w=0,S=null,M=-1,T=null;const E=new Vector4,R=new Vector4;let I=null;const k=new Color(0);let C=0,z=t.width,O=t.height,U=1,K=null,$=null;const J=new Vector4(0,0,z,O),ee=new Vector4(0,0,z,O);let he=!1;const ie=new Frustum;let le=!1,de=!1,Me=null;const Ee=new Matrix4,Fe=new Vector2,Be=new Vector3,Ce={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0};function je(){return S===null?U:1}let ne=r;function Qe(P,F){for(let G=0;G{function oe(){if(W.forEach(function(xe){qe.get(xe).currentProgram.isReady()&&W.delete(xe)}),W.size===0){Y(P);return}setTimeout(oe,10)}Pe.get("KHR_parallel_shader_compile")!==null?oe():setTimeout(oe,10)})};let Ke=null;function ct(P){Ke&&Ke(P)}function dt(){pt.stop()}function it(){pt.start()}const pt=new WebGLAnimation;pt.setAnimationLoop(ct),typeof self<"u"&&pt.setContext(self),this.setAnimationLoop=function(P){Ke=P,be.setAnimationLoop(P),P===null?pt.stop():pt.start()},be.addEventListener("sessionstart",dt),be.addEventListener("sessionend",it),this.render=function(P,F){if(F!==void 0&&F.isCamera!==!0){console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.");return}if(v===!0)return;P.matrixWorldAutoUpdate===!0&&P.updateMatrixWorld(),F.parent===null&&F.matrixWorldAutoUpdate===!0&&F.updateMatrixWorld(),be.enabled===!0&&be.isPresenting===!0&&(be.cameraAutoUpdate===!0&&be.updateCamera(F),F=be.getCamera()),P.isScene===!0&&P.onBeforeRender(y,P,F,S),g=He.get(P,b.length),g.init(),b.push(g),Ee.multiplyMatrices(F.projectionMatrix,F.matrixWorldInverse),ie.setFromProjectionMatrix(Ee),de=this.localClippingEnabled,le=Xe.init(this.clippingPlanes,de),m=Ne.get(P,_.length),m.init(),_.push(m),vt(P,F,0,y.sortObjects),m.finish(),y.sortObjects===!0&&m.sort(K,$),this.info.render.frame++,le===!0&&Xe.beginShadows();const G=g.state.shadowsArray;if(me.render(G,P,F),le===!0&&Xe.endShadows(),this.info.autoReset===!0&&this.info.reset(),rt.render(m,P),g.setupLights(y._useLegacyLights),F.isArrayCamera){const W=F.cameras;for(let Y=0,oe=W.length;Y0?g=b[b.length-1]:g=null,_.pop(),_.length>0?m=_[_.length-1]:m=null};function vt(P,F,G,W){if(P.visible===!1)return;if(P.layers.test(F.layers)){if(P.isGroup)G=P.renderOrder;else if(P.isLOD)P.autoUpdate===!0&&P.update(F);else if(P.isLight)g.pushLight(P),P.castShadow&&g.pushShadow(P);else if(P.isSprite){if(!P.frustumCulled||ie.intersectsSprite(P)){W&&Be.setFromMatrixPosition(P.matrixWorld).applyMatrix4(Ee);const xe=pe.update(P),Ie=P.material;Ie.visible&&m.push(P,xe,Ie,G,Be.z,null)}}else if((P.isMesh||P.isLine||P.isPoints)&&(!P.frustumCulled||ie.intersectsObject(P))){const xe=pe.update(P),Ie=P.material;if(W&&(P.boundingSphere!==void 0?(P.boundingSphere===null&&P.computeBoundingSphere(),Be.copy(P.boundingSphere.center)):(xe.boundingSphere===null&&xe.computeBoundingSphere(),Be.copy(xe.boundingSphere.center)),Be.applyMatrix4(P.matrixWorld).applyMatrix4(Ee)),Array.isArray(Ie)){const Ue=xe.groups;for(let Ve=0,Q=Ue.length;Ve0&&Nt(Y,oe,F,G),W&&De.viewport(E.copy(W)),Y.length>0&&Et(Y,F,G),oe.length>0&&Et(oe,F,G),xe.length>0&&Et(xe,F,G),De.buffers.depth.setTest(!0),De.buffers.depth.setMask(!0),De.buffers.color.setMask(!0),De.setPolygonOffset(!1)}function Nt(P,F,G,W){if((G.isScene===!0?G.overrideMaterial:null)!==null)return;const oe=ze.isWebGL2;Me===null&&(Me=new WebGLRenderTarget(1,1,{generateMipmaps:!0,type:Pe.has("EXT_color_buffer_half_float")?HalfFloatType:UnsignedByteType,minFilter:LinearMipmapLinearFilter,samples:oe?4:0})),y.getDrawingBufferSize(Fe),oe?Me.setSize(Fe.x,Fe.y):Me.setSize(floorPowerOfTwo(Fe.x),floorPowerOfTwo(Fe.y));const xe=y.getRenderTarget();y.setRenderTarget(Me),y.getClearColor(k),C=y.getClearAlpha(),C<1&&y.setClearColor(16777215,.5),y.clear();const Ie=y.toneMapping;y.toneMapping=NoToneMapping,Et(P,G,W),B.updateMultisampleRenderTarget(Me),B.updateRenderTargetMipmap(Me);let Ue=!1;for(let Ve=0,Q=F.length;Ve0),Re=!!G.morphAttributes.position,Ye=!!G.morphAttributes.normal,mt=!!G.morphAttributes.color;let ut=NoToneMapping;W.toneMapped&&(S===null||S.isXRRenderTarget===!0)&&(ut=y.toneMapping);const Tt=G.morphAttributes.position||G.morphAttributes.normal||G.morphAttributes.color,ht=Tt!==void 0?Tt.length:0,Je=qe.get(W),bt=g.state.lights;if(le===!0&&(de===!0||P!==T)){const xt=P===T&&W.id===M;Xe.setState(W,P,xt)}let ft=!1;W.version===Je.__version?(Je.needsLights&&Je.lightsStateVersion!==bt.state.version||Je.outputColorSpace!==Ie||Y.isBatchedMesh&&Je.batching===!1||!Y.isBatchedMesh&&Je.batching===!0||Y.isInstancedMesh&&Je.instancing===!1||!Y.isInstancedMesh&&Je.instancing===!0||Y.isSkinnedMesh&&Je.skinning===!1||!Y.isSkinnedMesh&&Je.skinning===!0||Y.isInstancedMesh&&Je.instancingColor===!0&&Y.instanceColor===null||Y.isInstancedMesh&&Je.instancingColor===!1&&Y.instanceColor!==null||Je.envMap!==Ue||W.fog===!0&&Je.fog!==oe||Je.numClippingPlanes!==void 0&&(Je.numClippingPlanes!==Xe.numPlanes||Je.numIntersection!==Xe.numIntersection)||Je.vertexAlphas!==Ve||Je.vertexTangents!==Q||Je.morphTargets!==Re||Je.morphNormals!==Ye||Je.morphColors!==mt||Je.toneMapping!==ut||ze.isWebGL2===!0&&Je.morphTargetsCount!==ht)&&(ft=!0):(ft=!0,Je.__version=W.version);let At=Je.currentProgram;ft===!0&&(At=Mt(W,F,Y));let zt=!1,Dt=!1,Vt=!1;const yt=At.getUniforms(),wt=Je.uniforms;if(De.useProgram(At.program)&&(zt=!0,Dt=!0,Vt=!0),W.id!==M&&(M=W.id,Dt=!0),zt||T!==P){yt.setValue(ne,"projectionMatrix",P.projectionMatrix),yt.setValue(ne,"viewMatrix",P.matrixWorldInverse);const xt=yt.map.cameraPosition;xt!==void 0&&xt.setValue(ne,Be.setFromMatrixPosition(P.matrixWorld)),ze.logarithmicDepthBuffer&&yt.setValue(ne,"logDepthBufFC",2/(Math.log(P.far+1)/Math.LN2)),(W.isMeshPhongMaterial||W.isMeshToonMaterial||W.isMeshLambertMaterial||W.isMeshBasicMaterial||W.isMeshStandardMaterial||W.isShaderMaterial)&&yt.setValue(ne,"isOrthographic",P.isOrthographicCamera===!0),T!==P&&(T=P,Dt=!0,Vt=!0)}if(Y.isSkinnedMesh){yt.setOptional(ne,Y,"bindMatrix"),yt.setOptional(ne,Y,"bindMatrixInverse");const xt=Y.skeleton;xt&&(ze.floatVertexTextures?(xt.boneTexture===null&&xt.computeBoneTexture(),yt.setValue(ne,"boneTexture",xt.boneTexture,B)):console.warn("THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required."))}Y.isBatchedMesh&&(yt.setOptional(ne,Y,"batchingTexture"),yt.setValue(ne,"batchingTexture",Y._matricesTexture,B));const Ft=G.morphAttributes;if((Ft.position!==void 0||Ft.normal!==void 0||Ft.color!==void 0&&ze.isWebGL2===!0)&&Ge.update(Y,G,At),(Dt||Je.receiveShadow!==Y.receiveShadow)&&(Je.receiveShadow=Y.receiveShadow,yt.setValue(ne,"receiveShadow",Y.receiveShadow)),W.isMeshGouraudMaterial&&W.envMap!==null&&(wt.envMap.value=Ue,wt.flipEnvMap.value=Ue.isCubeTexture&&Ue.isRenderTargetTexture===!1?-1:1),Dt&&(yt.setValue(ne,"toneMappingExposure",y.toneMappingExposure),Je.needsLights&&j(wt,Vt),oe&&W.fog===!0&&Oe.refreshFogUniforms(wt,oe),Oe.refreshMaterialUniforms(wt,W,U,O,Me),WebGLUniforms.upload(ne,Rt(Je),wt,B)),W.isShaderMaterial&&W.uniformsNeedUpdate===!0&&(WebGLUniforms.upload(ne,Rt(Je),wt,B),W.uniformsNeedUpdate=!1),W.isSpriteMaterial&&yt.setValue(ne,"center",Y.center),yt.setValue(ne,"modelViewMatrix",Y.modelViewMatrix),yt.setValue(ne,"normalMatrix",Y.normalMatrix),yt.setValue(ne,"modelMatrix",Y.matrixWorld),W.isShaderMaterial||W.isRawShaderMaterial){const xt=W.uniformsGroups;for(let Ut=0,$t=xt.length;Ut<$t;Ut++)if(ze.isWebGL2){const Gt=xt[Ut];Se.update(Gt,At),Se.bind(Gt,At)}else console.warn("THREE.WebGLRenderer: Uniform Buffer Objects can only be used with WebGL 2.")}return At}function j(P,F){P.ambientLightColor.needsUpdate=F,P.lightProbe.needsUpdate=F,P.directionalLights.needsUpdate=F,P.directionalLightShadows.needsUpdate=F,P.pointLights.needsUpdate=F,P.pointLightShadows.needsUpdate=F,P.spotLights.needsUpdate=F,P.spotLightShadows.needsUpdate=F,P.rectAreaLights.needsUpdate=F,P.hemisphereLights.needsUpdate=F}function Z(P){return P.isMeshLambertMaterial||P.isMeshToonMaterial||P.isMeshPhongMaterial||P.isMeshStandardMaterial||P.isShadowMaterial||P.isShaderMaterial&&P.lights===!0}this.getActiveCubeFace=function(){return x},this.getActiveMipmapLevel=function(){return w},this.getRenderTarget=function(){return S},this.setRenderTargetTextures=function(P,F,G){qe.get(P.texture).__webglTexture=F,qe.get(P.depthTexture).__webglTexture=G;const W=qe.get(P);W.__hasExternalTextures=!0,W.__hasExternalTextures&&(W.__autoAllocateDepthBuffer=G===void 0,W.__autoAllocateDepthBuffer||Pe.has("WEBGL_multisampled_render_to_texture")===!0&&(console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"),W.__useRenderToTexture=!1))},this.setRenderTargetFramebuffer=function(P,F){const G=qe.get(P);G.__webglFramebuffer=F,G.__useDefaultFramebuffer=F===void 0},this.setRenderTarget=function(P,F=0,G=0){S=P,x=F,w=G;let W=!0,Y=null,oe=!1,xe=!1;if(P){const Ue=qe.get(P);Ue.__useDefaultFramebuffer!==void 0?(De.bindFramebuffer(ne.FRAMEBUFFER,null),W=!1):Ue.__webglFramebuffer===void 0?B.setupRenderTarget(P):Ue.__hasExternalTextures&&B.rebindTextures(P,qe.get(P.texture).__webglTexture,qe.get(P.depthTexture).__webglTexture);const Ve=P.texture;(Ve.isData3DTexture||Ve.isDataArrayTexture||Ve.isCompressedArrayTexture)&&(xe=!0);const Q=qe.get(P).__webglFramebuffer;P.isWebGLCubeRenderTarget?(Array.isArray(Q[F])?Y=Q[F][G]:Y=Q[F],oe=!0):ze.isWebGL2&&P.samples>0&&B.useMultisampledRTT(P)===!1?Y=qe.get(P).__webglMultisampledFramebuffer:Array.isArray(Q)?Y=Q[G]:Y=Q,E.copy(P.viewport),R.copy(P.scissor),I=P.scissorTest}else E.copy(J).multiplyScalar(U).floor(),R.copy(ee).multiplyScalar(U).floor(),I=he;if(De.bindFramebuffer(ne.FRAMEBUFFER,Y)&&ze.drawBuffers&&W&&De.drawBuffers(P,Y),De.viewport(E),De.scissor(R),De.setScissorTest(I),oe){const Ue=qe.get(P.texture);ne.framebufferTexture2D(ne.FRAMEBUFFER,ne.COLOR_ATTACHMENT0,ne.TEXTURE_CUBE_MAP_POSITIVE_X+F,Ue.__webglTexture,G)}else if(xe){const Ue=qe.get(P.texture),Ve=F||0;ne.framebufferTextureLayer(ne.FRAMEBUFFER,ne.COLOR_ATTACHMENT0,Ue.__webglTexture,G||0,Ve)}M=-1},this.readRenderTargetPixels=function(P,F,G,W,Y,oe,xe){if(!(P&&P.isWebGLRenderTarget)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.");return}let Ie=qe.get(P).__webglFramebuffer;if(P.isWebGLCubeRenderTarget&&xe!==void 0&&(Ie=Ie[xe]),Ie){De.bindFramebuffer(ne.FRAMEBUFFER,Ie);try{const Ue=P.texture,Ve=Ue.format,Q=Ue.type;if(Ve!==RGBAFormat&&Le.convert(Ve)!==ne.getParameter(ne.IMPLEMENTATION_COLOR_READ_FORMAT)){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");return}const Re=Q===HalfFloatType&&(Pe.has("EXT_color_buffer_half_float")||ze.isWebGL2&&Pe.has("EXT_color_buffer_float"));if(Q!==UnsignedByteType&&Le.convert(Q)!==ne.getParameter(ne.IMPLEMENTATION_COLOR_READ_TYPE)&&!(Q===FloatType&&(ze.isWebGL2||Pe.has("OES_texture_float")||Pe.has("WEBGL_color_buffer_float")))&&!Re){console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");return}F>=0&&F<=P.width-W&&G>=0&&G<=P.height-Y&&ne.readPixels(F,G,W,Y,Le.convert(Ve),Le.convert(Q),oe)}finally{const Ue=S!==null?qe.get(S).__webglFramebuffer:null;De.bindFramebuffer(ne.FRAMEBUFFER,Ue)}}},this.copyFramebufferToTexture=function(P,F,G=0){const W=Math.pow(2,-G),Y=Math.floor(F.image.width*W),oe=Math.floor(F.image.height*W);B.setTexture2D(F,0),ne.copyTexSubImage2D(ne.TEXTURE_2D,G,0,0,P.x,P.y,Y,oe),De.unbindTexture()},this.copyTextureToTexture=function(P,F,G,W=0){const Y=F.image.width,oe=F.image.height,xe=Le.convert(G.format),Ie=Le.convert(G.type);B.setTexture2D(G,0),ne.pixelStorei(ne.UNPACK_FLIP_Y_WEBGL,G.flipY),ne.pixelStorei(ne.UNPACK_PREMULTIPLY_ALPHA_WEBGL,G.premultiplyAlpha),ne.pixelStorei(ne.UNPACK_ALIGNMENT,G.unpackAlignment),F.isDataTexture?ne.texSubImage2D(ne.TEXTURE_2D,W,P.x,P.y,Y,oe,xe,Ie,F.image.data):F.isCompressedTexture?ne.compressedTexSubImage2D(ne.TEXTURE_2D,W,P.x,P.y,F.mipmaps[0].width,F.mipmaps[0].height,xe,F.mipmaps[0].data):ne.texSubImage2D(ne.TEXTURE_2D,W,P.x,P.y,xe,Ie,F.image),W===0&&G.generateMipmaps&&ne.generateMipmap(ne.TEXTURE_2D),De.unbindTexture()},this.copyTextureToTexture3D=function(P,F,G,W,Y=0){if(y.isWebGL1Renderer){console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2.");return}const oe=P.max.x-P.min.x+1,xe=P.max.y-P.min.y+1,Ie=P.max.z-P.min.z+1,Ue=Le.convert(W.format),Ve=Le.convert(W.type);let Q;if(W.isData3DTexture)B.setTexture3D(W,0),Q=ne.TEXTURE_3D;else if(W.isDataArrayTexture||W.isCompressedArrayTexture)B.setTexture2DArray(W,0),Q=ne.TEXTURE_2D_ARRAY;else{console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.");return}ne.pixelStorei(ne.UNPACK_FLIP_Y_WEBGL,W.flipY),ne.pixelStorei(ne.UNPACK_PREMULTIPLY_ALPHA_WEBGL,W.premultiplyAlpha),ne.pixelStorei(ne.UNPACK_ALIGNMENT,W.unpackAlignment);const Re=ne.getParameter(ne.UNPACK_ROW_LENGTH),Ye=ne.getParameter(ne.UNPACK_IMAGE_HEIGHT),mt=ne.getParameter(ne.UNPACK_SKIP_PIXELS),ut=ne.getParameter(ne.UNPACK_SKIP_ROWS),Tt=ne.getParameter(ne.UNPACK_SKIP_IMAGES),ht=G.isCompressedTexture?G.mipmaps[Y]:G.image;ne.pixelStorei(ne.UNPACK_ROW_LENGTH,ht.width),ne.pixelStorei(ne.UNPACK_IMAGE_HEIGHT,ht.height),ne.pixelStorei(ne.UNPACK_SKIP_PIXELS,P.min.x),ne.pixelStorei(ne.UNPACK_SKIP_ROWS,P.min.y),ne.pixelStorei(ne.UNPACK_SKIP_IMAGES,P.min.z),G.isDataTexture||G.isData3DTexture?ne.texSubImage3D(Q,Y,F.x,F.y,F.z,oe,xe,Ie,Ue,Ve,ht.data):G.isCompressedArrayTexture?(console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture."),ne.compressedTexSubImage3D(Q,Y,F.x,F.y,F.z,oe,xe,Ie,Ue,ht.data)):ne.texSubImage3D(Q,Y,F.x,F.y,F.z,oe,xe,Ie,Ue,Ve,ht),ne.pixelStorei(ne.UNPACK_ROW_LENGTH,Re),ne.pixelStorei(ne.UNPACK_IMAGE_HEIGHT,Ye),ne.pixelStorei(ne.UNPACK_SKIP_PIXELS,mt),ne.pixelStorei(ne.UNPACK_SKIP_ROWS,ut),ne.pixelStorei(ne.UNPACK_SKIP_IMAGES,Tt),Y===0&&W.generateMipmaps&&ne.generateMipmap(Q),De.unbindTexture()},this.initTexture=function(P){P.isCubeTexture?B.setTextureCube(P,0):P.isData3DTexture?B.setTexture3D(P,0):P.isDataArrayTexture||P.isCompressedArrayTexture?B.setTexture2DArray(P,0):B.setTexture2D(P,0),De.unbindTexture()},this.resetState=function(){x=0,w=0,S=null,De.reset(),H.reset()},typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}get coordinateSystem(){return WebGLCoordinateSystem}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;const t=this.getContext();t.drawingBufferColorSpace=e===DisplayP3ColorSpace?"display-p3":"srgb",t.unpackColorSpace=ColorManagement.workingColorSpace===LinearDisplayP3ColorSpace?"display-p3":"srgb"}get outputEncoding(){return console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."),this.outputColorSpace===SRGBColorSpace?sRGBEncoding:LinearEncoding}set outputEncoding(e){console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."),this.outputColorSpace=e===sRGBEncoding?SRGBColorSpace:LinearSRGBColorSpace}get useLegacyLights(){return console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."),this._useLegacyLights}set useLegacyLights(e){console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."),this._useLegacyLights=e}}class WebGL1Renderer extends WebGLRenderer{}WebGL1Renderer.prototype.isWebGL1Renderer=!0;class Scene extends Object3D{constructor(){super(),this.isScene=!0,this.type="Scene",this.background=null,this.environment=null,this.fog=null,this.backgroundBlurriness=0,this.backgroundIntensity=1,this.overrideMaterial=null,typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}copy(e,t){return super.copy(e,t),e.background!==null&&(this.background=e.background.clone()),e.environment!==null&&(this.environment=e.environment.clone()),e.fog!==null&&(this.fog=e.fog.clone()),this.backgroundBlurriness=e.backgroundBlurriness,this.backgroundIntensity=e.backgroundIntensity,e.overrideMaterial!==null&&(this.overrideMaterial=e.overrideMaterial.clone()),this.matrixAutoUpdate=e.matrixAutoUpdate,this}toJSON(e){const t=super.toJSON(e);return this.fog!==null&&(t.object.fog=this.fog.toJSON()),this.backgroundBlurriness>0&&(t.object.backgroundBlurriness=this.backgroundBlurriness),this.backgroundIntensity!==1&&(t.object.backgroundIntensity=this.backgroundIntensity),t}}class CanvasTexture extends Texture{constructor(e,t,r,o,c,l,h,p,f){super(e,t,r,o,c,l,h,p,f),this.isCanvasTexture=!0,this.needsUpdate=!0}}class MeshStandardMaterial extends Material{constructor(e){super(),this.isMeshStandardMaterial=!0,this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new Color(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new Color(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=TangentSpaceNormalMap,this.normalScale=new Vector2(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapIntensity=1,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.flatShading=!1,this.fog=!0,this.setValues(e)}copy(e){return super.copy(e),this.defines={STANDARD:""},this.color.copy(e.color),this.roughness=e.roughness,this.metalness=e.metalness,this.map=e.map,this.lightMap=e.lightMap,this.lightMapIntensity=e.lightMapIntensity,this.aoMap=e.aoMap,this.aoMapIntensity=e.aoMapIntensity,this.emissive.copy(e.emissive),this.emissiveMap=e.emissiveMap,this.emissiveIntensity=e.emissiveIntensity,this.bumpMap=e.bumpMap,this.bumpScale=e.bumpScale,this.normalMap=e.normalMap,this.normalMapType=e.normalMapType,this.normalScale.copy(e.normalScale),this.displacementMap=e.displacementMap,this.displacementScale=e.displacementScale,this.displacementBias=e.displacementBias,this.roughnessMap=e.roughnessMap,this.metalnessMap=e.metalnessMap,this.alphaMap=e.alphaMap,this.envMap=e.envMap,this.envMapIntensity=e.envMapIntensity,this.wireframe=e.wireframe,this.wireframeLinewidth=e.wireframeLinewidth,this.wireframeLinecap=e.wireframeLinecap,this.wireframeLinejoin=e.wireframeLinejoin,this.flatShading=e.flatShading,this.fog=e.fog,this}}const Cache={enabled:!1,files:{},add:function(s,e){this.enabled!==!1&&(this.files[s]=e)},get:function(s){if(this.enabled!==!1)return this.files[s]},remove:function(s){delete this.files[s]},clear:function(){this.files={}}};class LoadingManager{constructor(e,t,r){const o=this;let c=!1,l=0,h=0,p;const f=[];this.onStart=void 0,this.onLoad=e,this.onProgress=t,this.onError=r,this.itemStart=function(d){h++,c===!1&&o.onStart!==void 0&&o.onStart(d,l,h),c=!0},this.itemEnd=function(d){l++,o.onProgress!==void 0&&o.onProgress(d,l,h),l===h&&(c=!1,o.onLoad!==void 0&&o.onLoad())},this.itemError=function(d){o.onError!==void 0&&o.onError(d)},this.resolveURL=function(d){return p?p(d):d},this.setURLModifier=function(d){return p=d,this},this.addHandler=function(d,i){return f.push(d,i),this},this.removeHandler=function(d){const i=f.indexOf(d);return i!==-1&&f.splice(i,2),this},this.getHandler=function(d){for(let i=0,n=f.length;iMath.PI&&(Ze-=we),Ke<-Math.PI?Ke+=we:Ke>Math.PI&&(Ke-=we),Ze<=Ke?h.theta=Math.max(Ze,Math.min(Ke,h.theta)):h.theta=h.theta>(Ze+Ke)/2?Math.max(Ze,h.theta):Math.min(Ke,h.theta)),h.phi=Math.max(r.minPolarAngle,Math.min(r.maxPolarAngle,h.phi)),h.makeSafe(),r.enableDamping===!0?r.target.addScaledVector(d,r.dampingFactor):r.target.add(d),r.target.sub(r.cursor),r.target.clampLength(r.minTargetRadius,r.maxTargetRadius),r.target.add(r.cursor),r.zoomToCursor&&w||r.object.isOrthographicCamera?h.radius=J(h.radius):h.radius=J(h.radius*f),H.setFromSpherical(h),H.applyQuaternion(ke),ye.copy(r.target).add(H),r.object.lookAt(r.target),r.enableDamping===!0?(p.theta*=1-r.dampingFactor,p.phi*=1-r.dampingFactor,d.multiplyScalar(1-r.dampingFactor)):(p.set(0,0,0),d.set(0,0,0));let ct=!1;if(r.zoomToCursor&&w){let dt=null;if(r.object.isPerspectiveCamera){const it=H.length();dt=J(it*f);const pt=it-dt;r.object.position.addScaledVector(v,pt),r.object.updateMatrixWorld()}else if(r.object.isOrthographicCamera){const it=new Vector3(x.x,x.y,0);it.unproject(r.object),r.object.zoom=Math.max(r.minZoom,Math.min(r.maxZoom,r.object.zoom/f)),r.object.updateProjectionMatrix(),ct=!0;const pt=new Vector3(x.x,x.y,0);pt.unproject(r.object),r.object.position.sub(pt).add(it),r.object.updateMatrixWorld(),dt=H.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),r.zoomToCursor=!1;dt!==null&&(this.screenSpacePanning?r.target.set(0,0,-1).transformDirection(r.object.matrix).multiplyScalar(dt).add(r.object.position):(_ray.origin.copy(r.object.position),_ray.direction.set(0,0,-1).transformDirection(r.object.matrix),Math.abs(r.object.up.dot(_ray.direction))l||8*(1-ge.dot(r.object.quaternion))>l||X.distanceToSquared(r.target)>0?(r.dispatchEvent(_changeEvent),be.copy(r.object.position),ge.copy(r.object.quaternion),X.copy(r.target),!0):!1}}(),this.dispose=function(){r.domElement.removeEventListener("contextmenu",rt),r.domElement.removeEventListener("pointerdown",B),r.domElement.removeEventListener("pointercancel",re),r.domElement.removeEventListener("wheel",pe),r.domElement.removeEventListener("pointermove",D),r.domElement.removeEventListener("pointerup",re),r._domElementKeyEvents!==null&&(r._domElementKeyEvents.removeEventListener("keydown",He),r._domElementKeyEvents=null)};const r=this,o={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let c=o.NONE;const l=1e-6,h=new Spherical,p=new Spherical;let f=1;const d=new Vector3,i=new Vector2,n=new Vector2,a=new Vector2,u=new Vector2,m=new Vector2,g=new Vector2,_=new Vector2,b=new Vector2,y=new Vector2,v=new Vector3,x=new Vector2;let w=!1;const S=[],M={};let T=!1;function E(H){return H!==null?2*Math.PI/60*r.autoRotateSpeed*H:2*Math.PI/60/60*r.autoRotateSpeed}function R(H){const Se=Math.abs(H*.01);return Math.pow(.95,r.zoomSpeed*Se)}function I(H){p.theta-=H}function k(H){p.phi-=H}const C=function(){const H=new Vector3;return function(ke,be){H.setFromMatrixColumn(be,0),H.multiplyScalar(-ke),d.add(H)}}(),z=function(){const H=new Vector3;return function(ke,be){r.screenSpacePanning===!0?H.setFromMatrixColumn(be,1):(H.setFromMatrixColumn(be,0),H.crossVectors(r.object.up,H)),H.multiplyScalar(ke),d.add(H)}}(),O=function(){const H=new Vector3;return function(ke,be){const ge=r.domElement;if(r.object.isPerspectiveCamera){const X=r.object.position;H.copy(X).sub(r.target);let we=H.length();we*=Math.tan(r.object.fov/2*Math.PI/180),C(2*ke*we/ge.clientHeight,r.object.matrix),z(2*be*we/ge.clientHeight,r.object.matrix)}else r.object.isOrthographicCamera?(C(ke*(r.object.right-r.object.left)/r.object.zoom/ge.clientWidth,r.object.matrix),z(be*(r.object.top-r.object.bottom)/r.object.zoom/ge.clientHeight,r.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),r.enablePan=!1)}}();function U(H){r.object.isPerspectiveCamera||r.object.isOrthographicCamera?f/=H:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),r.enableZoom=!1)}function K(H){r.object.isPerspectiveCamera||r.object.isOrthographicCamera?f*=H:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),r.enableZoom=!1)}function $(H,Se){if(!r.zoomToCursor)return;w=!0;const ke=r.domElement.getBoundingClientRect(),be=H-ke.left,ge=Se-ke.top,X=ke.width,we=ke.height;x.x=be/X*2-1,x.y=-(ge/we)*2+1,v.set(x.x,x.y,1).unproject(r.object).sub(r.object.position).normalize()}function J(H){return Math.max(r.minDistance,Math.min(r.maxDistance,H))}function ee(H){i.set(H.clientX,H.clientY)}function he(H){$(H.clientX,H.clientX),_.set(H.clientX,H.clientY)}function ie(H){u.set(H.clientX,H.clientY)}function le(H){n.set(H.clientX,H.clientY),a.subVectors(n,i).multiplyScalar(r.rotateSpeed);const Se=r.domElement;I(2*Math.PI*a.x/Se.clientHeight),k(2*Math.PI*a.y/Se.clientHeight),i.copy(n),r.update()}function de(H){b.set(H.clientX,H.clientY),y.subVectors(b,_),y.y>0?U(R(y.y)):y.y<0&&K(R(y.y)),_.copy(b),r.update()}function Me(H){m.set(H.clientX,H.clientY),g.subVectors(m,u).multiplyScalar(r.panSpeed),O(g.x,g.y),u.copy(m),r.update()}function Ee(H){$(H.clientX,H.clientY),H.deltaY<0?K(R(H.deltaY)):H.deltaY>0&&U(R(H.deltaY)),r.update()}function Fe(H){let Se=!1;switch(H.code){case r.keys.UP:H.ctrlKey||H.metaKey||H.shiftKey?k(2*Math.PI*r.rotateSpeed/r.domElement.clientHeight):O(0,r.keyPanSpeed),Se=!0;break;case r.keys.BOTTOM:H.ctrlKey||H.metaKey||H.shiftKey?k(-2*Math.PI*r.rotateSpeed/r.domElement.clientHeight):O(0,-r.keyPanSpeed),Se=!0;break;case r.keys.LEFT:H.ctrlKey||H.metaKey||H.shiftKey?I(2*Math.PI*r.rotateSpeed/r.domElement.clientHeight):O(r.keyPanSpeed,0),Se=!0;break;case r.keys.RIGHT:H.ctrlKey||H.metaKey||H.shiftKey?I(-2*Math.PI*r.rotateSpeed/r.domElement.clientHeight):O(-r.keyPanSpeed,0),Se=!0;break}Se&&(H.preventDefault(),r.update())}function Be(H){if(S.length===1)i.set(H.pageX,H.pageY);else{const Se=Le(H),ke=.5*(H.pageX+Se.x),be=.5*(H.pageY+Se.y);i.set(ke,be)}}function Ce(H){if(S.length===1)u.set(H.pageX,H.pageY);else{const Se=Le(H),ke=.5*(H.pageX+Se.x),be=.5*(H.pageY+Se.y);u.set(ke,be)}}function je(H){const Se=Le(H),ke=H.pageX-Se.x,be=H.pageY-Se.y,ge=Math.sqrt(ke*ke+be*be);_.set(0,ge)}function ne(H){r.enableZoom&&je(H),r.enablePan&&Ce(H)}function Qe(H){r.enableZoom&&je(H),r.enableRotate&&Be(H)}function Pe(H){if(S.length==1)n.set(H.pageX,H.pageY);else{const ke=Le(H),be=.5*(H.pageX+ke.x),ge=.5*(H.pageY+ke.y);n.set(be,ge)}a.subVectors(n,i).multiplyScalar(r.rotateSpeed);const Se=r.domElement;I(2*Math.PI*a.x/Se.clientHeight),k(2*Math.PI*a.y/Se.clientHeight),i.copy(n)}function ze(H){if(S.length===1)m.set(H.pageX,H.pageY);else{const Se=Le(H),ke=.5*(H.pageX+Se.x),be=.5*(H.pageY+Se.y);m.set(ke,be)}g.subVectors(m,u).multiplyScalar(r.panSpeed),O(g.x,g.y),u.copy(m)}function De(H){const Se=Le(H),ke=H.pageX-Se.x,be=H.pageY-Se.y,ge=Math.sqrt(ke*ke+be*be);b.set(0,ge),y.set(0,Math.pow(b.y/_.y,r.zoomSpeed)),U(y.y),_.copy(b);const X=(H.pageX+Se.x)*.5,we=(H.pageY+Se.y)*.5;$(X,we)}function nt(H){r.enableZoom&&De(H),r.enablePan&&ze(H)}function qe(H){r.enableZoom&&De(H),r.enableRotate&&Pe(H)}function B(H){r.enabled!==!1&&(S.length===0&&(r.domElement.setPointerCapture(H.pointerId),r.domElement.addEventListener("pointermove",D),r.domElement.addEventListener("pointerup",re)),Ge(H),H.pointerType==="touch"?Xe(H):ce(H))}function D(H){r.enabled!==!1&&(H.pointerType==="touch"?me(H):fe(H))}function re(H){We(H),S.length===0&&(r.domElement.releasePointerCapture(H.pointerId),r.domElement.removeEventListener("pointermove",D),r.domElement.removeEventListener("pointerup",re)),r.dispatchEvent(_endEvent),c=o.NONE}function ce(H){let Se;switch(H.button){case 0:Se=r.mouseButtons.LEFT;break;case 1:Se=r.mouseButtons.MIDDLE;break;case 2:Se=r.mouseButtons.RIGHT;break;default:Se=-1}switch(Se){case MOUSE.DOLLY:if(r.enableZoom===!1)return;he(H),c=o.DOLLY;break;case MOUSE.ROTATE:if(H.ctrlKey||H.metaKey||H.shiftKey){if(r.enablePan===!1)return;ie(H),c=o.PAN}else{if(r.enableRotate===!1)return;ee(H),c=o.ROTATE}break;case MOUSE.PAN:if(H.ctrlKey||H.metaKey||H.shiftKey){if(r.enableRotate===!1)return;ee(H),c=o.ROTATE}else{if(r.enablePan===!1)return;ie(H),c=o.PAN}break;default:c=o.NONE}c!==o.NONE&&r.dispatchEvent(_startEvent)}function fe(H){switch(c){case o.ROTATE:if(r.enableRotate===!1)return;le(H);break;case o.DOLLY:if(r.enableZoom===!1)return;de(H);break;case o.PAN:if(r.enablePan===!1)return;Me(H);break}}function pe(H){r.enabled===!1||r.enableZoom===!1||c!==o.NONE||(H.preventDefault(),r.dispatchEvent(_startEvent),Ee(Te(H)),r.dispatchEvent(_endEvent))}function Te(H){const Se=H.deltaMode,ke={clientX:H.clientX,clientY:H.clientY,deltaY:H.deltaY};switch(Se){case 1:ke.deltaY*=16;break;case 2:ke.deltaY*=100;break}return H.ctrlKey&&!T&&(ke.deltaY*=10),ke}function Oe(H){H.key==="Control"&&(T=!0,document.addEventListener("keyup",Ne,{passive:!0,capture:!0}))}function Ne(H){H.key==="Control"&&(T=!1,document.removeEventListener("keyup",Ne,{passive:!0,capture:!0}))}function He(H){r.enabled===!1||r.enablePan===!1||Fe(H)}function Xe(H){switch(_e(H),S.length){case 1:switch(r.touches.ONE){case TOUCH.ROTATE:if(r.enableRotate===!1)return;Be(H),c=o.TOUCH_ROTATE;break;case TOUCH.PAN:if(r.enablePan===!1)return;Ce(H),c=o.TOUCH_PAN;break;default:c=o.NONE}break;case 2:switch(r.touches.TWO){case TOUCH.DOLLY_PAN:if(r.enableZoom===!1&&r.enablePan===!1)return;ne(H),c=o.TOUCH_DOLLY_PAN;break;case TOUCH.DOLLY_ROTATE:if(r.enableZoom===!1&&r.enableRotate===!1)return;Qe(H),c=o.TOUCH_DOLLY_ROTATE;break;default:c=o.NONE}break;default:c=o.NONE}c!==o.NONE&&r.dispatchEvent(_startEvent)}function me(H){switch(_e(H),c){case o.TOUCH_ROTATE:if(r.enableRotate===!1)return;Pe(H),r.update();break;case o.TOUCH_PAN:if(r.enablePan===!1)return;ze(H),r.update();break;case o.TOUCH_DOLLY_PAN:if(r.enableZoom===!1&&r.enablePan===!1)return;nt(H),r.update();break;case o.TOUCH_DOLLY_ROTATE:if(r.enableZoom===!1&&r.enableRotate===!1)return;qe(H),r.update();break;default:c=o.NONE}}function rt(H){r.enabled!==!1&&H.preventDefault()}function Ge(H){S.push(H.pointerId)}function We(H){delete M[H.pointerId];for(let Se=0;Se[t,e]))}function escapeRegExp(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const Callable=class{constructor(){let s=function(...e){return s._call(...e)};return Object.setPrototypeOf(s,new.target.prototype)}_call(...s){throw Error("Must implement _call method in subclass")}};function isTypedArray(s){return s?.prototype?.__proto__?.constructor?.name==="TypedArray"}function isIntegralNumber(s){return Number.isInteger(s)||typeof s=="bigint"}function exists(s){return s!=null}function calculateDimensions(s){const e=[];let t=s;for(;Array.isArray(t);)e.push(t.length),t=t[0];return e}function pop(s,e,t=void 0){const r=s[e];if(r!==void 0)return delete s[e],r;if(t===void 0)throw Error(`Key ${e} does not exist in object.`);return t}function mergeArrays(...s){return Array.prototype.concat.apply([],s)}function product(...s){return s.reduce((e,t)=>e.flatMap(r=>t.map(o=>[r,o])))}function calculateReflectOffset(s,e){return Math.abs((s+e)%(2*e)-e)}const sharp={},ONNX_NODE=Object.freeze(Object.defineProperty({__proto__:null,default:sharp},Symbol.toStringTag,{value:"Module"}));function getDefaultExportFromCjs(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}function getAugmentedNamespace(s){if(s.__esModule)return s;var e=s.default;if(typeof e=="function"){var t=function r(){return this instanceof r?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(s).forEach(function(r){var o=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return s[r]}})}),t}var ortWeb_min$1={exports:{}};const backends={},backendsSortedByPriority=[],registerBackend=(s,e,t)=>{if(e&&typeof e.init=="function"&&typeof e.createSessionHandler=="function"){const r=backends[s];if(r===void 0)backends[s]={backend:e,priority:t};else{if(r.priority>t)return;if(r.priority===t&&r.backend!==e)throw new Error(`cannot register backend "${s}" using priority ${t}`)}if(t>=0){const o=backendsSortedByPriority.indexOf(s);o!==-1&&backendsSortedByPriority.splice(o,1);for(let c=0;c{const e=s.length===0?backendsSortedByPriority:s,t=[];for(const r of e){const o=backends[r];if(o){if(o.initialized)return o.backend;if(o.aborted)continue;const c=!!o.initPromise;try{return c||(o.initPromise=o.backend.init()),await o.initPromise,o.initialized=!0,o.backend}catch(l){c||t.push({name:r,err:l}),o.aborted=!0}finally{delete o.initPromise}}}throw new Error(`no available backend found. ERR: ${t.map(r=>`[${r.name}] ${r.err}`).join(", ")}`)};class EnvImpl{constructor(){this.wasm={},this.webgl={},this.logLevelInternal="warning"}set logLevel(e){if(e!==void 0){if(typeof e!="string"||["verbose","info","warning","error","fatal"].indexOf(e)===-1)throw new Error(`Unsupported logging level: ${e}`);this.logLevelInternal=e}}get logLevel(){return this.logLevelInternal}}const env$2=new EnvImpl,isBigInt64ArrayAvailable=typeof BigInt64Array<"u"&&typeof BigInt64Array.from=="function",isBigUint64ArrayAvailable=typeof BigUint64Array<"u"&&typeof BigUint64Array.from=="function",NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP=new Map([["float32",Float32Array],["uint8",Uint8Array],["int8",Int8Array],["uint16",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"]]);isBigInt64ArrayAvailable&&(NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("int64",BigInt64Array),NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigInt64Array,"int64"));isBigUint64ArrayAvailable&&(NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.set("uint64",BigUint64Array),NUMERIC_TENSOR_TYPEDARRAY_TO_TYPE_MAP.set(BigUint64Array,"uint64"));const calculateSize=s=>{let e=1;for(let t=0;t{const i=document.createElement("canvas"),n=i.getContext("2d");if(!e||!n)return d();const a=new Image;a.crossOrigin="Anonymous",a.src=e,a.onload=()=>{i.width=a.width,i.height=a.height,n.drawImage(a,0,0,i.width,i.height);const u=n.getImageData(0,0,i.width,i.height);if(t!==void 0){if(t.height!==void 0&&t.height!==i.height)throw new Error("Image input config height doesn't match ImageBitmap height");if(p.height=i.height,t.width!==void 0&&t.width!==i.width)throw new Error("Image input config width doesn't match ImageBitmap width");p.width=i.width}else p.height=i.height,p.width=i.width;f(kt.bufferToTensor(u.data,p))}});throw new Error("Input data provided is not supported - aborted tensor creation")}if(h!==void 0)return kt.bufferToTensor(h,p);throw new Error("Input data provided is not supported - aborted tensor creation")}toImageData(e){var t,r;const o=document.createElement("canvas").getContext("2d");let c;if(o!=null){const l=this.dims[3],h=this.dims[2],p=this.dims[1],f=e!==void 0&&e.format!==void 0?e.format:"RGB",d=e!==void 0&&((t=e.norm)===null||t===void 0?void 0:t.mean)!==void 0?e.norm.mean:255,i=e!==void 0&&((r=e.norm)===null||r===void 0?void 0:r.bias)!==void 0?e.norm.bias:0,n=h*l;if(e!==void 0){if(e.height!==void 0&&e.height!==h)throw new Error("Image output config height doesn't match tensor height");if(e.width!==void 0&&e.width!==l)throw new Error("Image output config width doesn't match tensor width");if(e.format!==void 0&&p===4&&e.format!=="RGBA"||p===3&&e.format!=="RGB"&&e.format!=="BGR")throw new Error("Tensor format doesn't match input tensor dims")}const a=4;let u=0,m=1,g=2,_=3,b=0,y=n,v=n*2,x=-1;f==="RGBA"?(b=0,y=n,v=n*2,x=n*3):f==="RGB"?(b=0,y=n,v=n*2):f==="RBG"&&(b=0,v=n,y=n*2),c=o.createImageData(l,h);for(let w=0;w"u")throw new Error(`input '${f}' is missing in 'feeds'.`);if(l)for(const f of this.outputNames)o[f]=null;const h=await this.handler.run(e,o,c),p={};for(const f in h)Object.hasOwnProperty.call(h,f)&&(p[f]=new Tensor$1(h[f].type,h[f].data,h[f].dims));return p}static async create(e,t,r,o){let c,l={};if(typeof e=="string"){if(c=e,typeof t=="object"&&t!==null)l=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof Uint8Array){if(c=e,typeof t=="object"&&t!==null)l=t;else if(typeof t<"u")throw new TypeError("'options' must be an object.")}else if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer){const i=e;let n=0,a=e.byteLength;if(typeof t=="object"&&t!==null)l=t;else if(typeof t=="number"){if(n=t,!Number.isSafeInteger(n))throw new RangeError("'byteOffset' must be an integer.");if(n<0||n>=i.byteLength)throw new RangeError(`'byteOffset' is out of range [0, ${i.byteLength}).`);if(a=e.byteLength-n,typeof r=="number"){if(a=r,!Number.isSafeInteger(a))throw new RangeError("'byteLength' must be an integer.");if(a<=0||n+a>i.byteLength)throw new RangeError(`'byteLength' is out of range (0, ${i.byteLength-n}].`);if(typeof o=="object"&&o!==null)l=o;else if(typeof o<"u")throw new TypeError("'options' must be an object.")}else if(typeof r<"u")throw new TypeError("'byteLength' must be a number.")}else if(typeof t<"u")throw new TypeError("'options' must be an object.");c=new Uint8Array(i,n,a)}else throw new TypeError("Unexpected argument[0]: must be 'path' or 'buffer'.");const p=(l.executionProviders||[]).map(i=>typeof i=="string"?i:i.name),d=await(await resolveBackend(p)).createSessionHandler(c,l);return new dn(d)}startProfiling(){this.handler.startProfiling()}endProfiling(){this.handler.endProfiling()}get inputNames(){return this.handler.inputNames}get outputNames(){return this.handler.outputNames}};const InferenceSession$1=InferenceSession$2,lib=Object.freeze(Object.defineProperty({__proto__:null,InferenceSession:InferenceSession$1,Tensor:Tensor$1,env:env$2,registerBackend},Symbol.toStringTag,{value:"Module"})),require$$0=getAugmentedNamespace(lib);/*! * ONNX Runtime Web v1.14.0 * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */(function(module,exports){(function(s,e){module.exports=e(require$$0)})(self,__WEBPACK_EXTERNAL_MODULE__1670__=>(()=>{var __webpack_modules__={3474:(s,e,t)=>{var r,o=(r=(r=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(c){function l(){return $.buffer!=ee&&Qe($.buffer),he}function h(){return $.buffer!=ee&&Qe($.buffer),ie}function p(){return $.buffer!=ee&&Qe($.buffer),le}function f(){return $.buffer!=ee&&Qe($.buffer),de}function d(){return $.buffer!=ee&&Qe($.buffer),Me}var i,n,a;c=c||{},i||(i=c!==void 0?c:{}),i.ready=new Promise(function(A,L){n=A,a=L});var u,m,g,_,b,y,v=Object.assign({},i),x="./this.program",w=(A,L)=>{throw L},S=typeof window=="object",M=typeof importScripts=="function",T=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",E=i.ENVIRONMENT_IS_PTHREAD||!1,R="";function I(A){return i.locateFile?i.locateFile(A,R):R+A}if(T){let A;R=M?t(908).dirname(R)+"/":"//",y=()=>{b||(_=t(1384),b=t(908))},u=function(L,V){return y(),L=b.normalize(L),_.readFileSync(L,V?void 0:"utf8")},g=L=>((L=u(L,!0)).buffer||(L=new Uint8Array(L)),L),m=(L,V,q)=>{y(),L=b.normalize(L),_.readFile(L,function(te,se){te?q(te):V(se.buffer)})},1{if(D())throw process.exitCode=L,V;V instanceof Xe||U("exiting due to exception: "+V),process.exit(L)},i.inspect=function(){return"[Emscripten Module object]"};try{A=t(9925)}catch(L){throw console.error('The "worker_threads" module is not supported in this node.js build - perhaps a newer version is needed?'),L}t.g.Worker=A.Worker}else(S||M)&&(M?R=self.location.href:typeof document<"u"&&document.currentScript&&(R=document.currentScript.src),r&&(R=r),R=R.indexOf("blob:")!==0?R.substr(0,R.replace(/[?#].*/,"").lastIndexOf("/")+1):"",T||(u=A=>{var L=new XMLHttpRequest;return L.open("GET",A,!1),L.send(null),L.responseText},M&&(g=A=>{var L=new XMLHttpRequest;return L.open("GET",A,!1),L.responseType="arraybuffer",L.send(null),new Uint8Array(L.response)}),m=(A,L,V)=>{var q=new XMLHttpRequest;q.open("GET",A,!0),q.responseType="arraybuffer",q.onload=()=>{q.status==200||q.status==0&&q.response?L(q.response):V()},q.onerror=V,q.send(null)}));T&&typeof performance>"u"&&(t.g.performance=t(6953).performance);var k=console.log.bind(console),C=console.warn.bind(console);T&&(y(),k=A=>_.writeSync(1,A+` `),C=A=>_.writeSync(2,A+` `));var z,O=i.print||k,U=i.printErr||C;Object.assign(i,v),v=null,i.thisProgram&&(x=i.thisProgram),i.quit&&(w=i.quit),i.wasmBinary&&(z=i.wasmBinary);var K=i.noExitRuntime||!1;typeof WebAssembly!="object"&&Te("no native wasm support detected");var $,J,ee,he,ie,le,de,Me,Ee=!1,Fe=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function Be(A,L,V){var q=(L>>>=0)+V;for(V=L;A[V]&&!(V>=q);)++V;if(16(te=(240&te)==224?(15&te)<<12|se<<6|Ae:(7&te)<<18|se<<12|Ae<<6|63&A[L++])?q+=String.fromCharCode(te):(te-=65536,q+=String.fromCharCode(55296|te>>10,56320|1023&te))}}else q+=String.fromCharCode(te)}return q}function Ce(A,L){return(A>>>=0)?Be(h(),A,L):""}function je(A,L,V,q){if(!(0>>=0;q=V+q-1;for(var se=0;se=Ae&&(Ae=65536+((1023&Ae)<<10)|1023&A.charCodeAt(++se)),127>=Ae){if(V>=q)break;L[V++>>>0]=Ae}else{if(2047>=Ae){if(V+1>=q)break;L[V++>>>0]=192|Ae>>6}else{if(65535>=Ae){if(V+2>=q)break;L[V++>>>0]=224|Ae>>12}else{if(V+3>=q)break;L[V++>>>0]=240|Ae>>18,L[V++>>>0]=128|Ae>>12&63}L[V++>>>0]=128|Ae>>6&63}L[V++>>>0]=128|63&Ae}}return L[V>>>0]=0,V-te}function ne(A){for(var L=0,V=0;V=q?L++:2047>=q?L+=2:55296<=q&&57343>=q?(L+=4,++V):L+=3}return L}function Qe(A){ee=A,i.HEAP8=he=new Int8Array(A),i.HEAP16=new Int16Array(A),i.HEAP32=le=new Int32Array(A),i.HEAPU8=ie=new Uint8Array(A),i.HEAPU16=new Uint16Array(A),i.HEAPU32=de=new Uint32Array(A),i.HEAPF32=new Float32Array(A),i.HEAPF64=Me=new Float64Array(A)}E&&(ee=i.buffer);var Pe=i.INITIAL_MEMORY||16777216;if(E)$=i.wasmMemory,ee=i.buffer;else if(i.wasmMemory)$=i.wasmMemory;else if(!(($=new WebAssembly.Memory({initial:Pe/65536,maximum:65536,shared:!0})).buffer instanceof SharedArrayBuffer))throw U("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),T&&console.log("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)"),Error("bad memory");$&&(ee=$.buffer),Pe=ee.byteLength,Qe(ee);var ze,De=[],nt=[],qe=[],B=[];function D(){return K||!1}function re(){var A=i.preRun.shift();De.unshift(A)}var ce,fe=0,pe=null;function Te(A){throw E?postMessage({cmd:"onAbort",arg:A}):i.onAbort&&i.onAbort(A),U(A="Aborted("+A+")"),Ee=!0,A=new WebAssembly.RuntimeError(A+". Build with -sASSERTIONS for more info."),a(A),A}function Oe(){return ce.startsWith("data:application/octet-stream;base64,")}function Ne(){var A=ce;try{if(A==ce&&z)return new Uint8Array(z);if(g)return g(A);throw"both async and sync fetching of the wasm failed"}catch(L){Te(L)}}ce="ort-wasm-threaded.wasm",Oe()||(ce=I(ce));var He={};function Xe(A){this.name="ExitStatus",this.message="Program terminated with exit("+A+")",this.status=A}function me(A){(A=_e.Vb[A])||Te(),_e.mc(A)}function rt(A){var L=_e.Cc();if(!L)return 6;_e.ac.push(L),_e.Vb[A.Ub]=L,L.Ub=A.Ub;var V={cmd:"run",start_routine:A.Ic,arg:A.zc,pthread_ptr:A.Ub};return L.$b=()=>{V.time=performance.now(),L.postMessage(V,A.Nc)},L.loaded&&(L.$b(),delete L.$b),0}function Ge(A){if(E)return oe(1,1,A);D()||(_e.oc(),i.onExit&&i.onExit(A),Ee=!0),w(A,new Xe(A))}function We(A,L){if(!L&&E)throw Se(A),"unwind";D()||E||($t(),Le(qe),Ut(0),Tt[1].length&&ht(1,10),Tt[2].length&&ht(2,10),_e.oc()),Ge(A)}var _e={Yb:[],ac:[],qc:[],Vb:{},fc:function(){E&&_e.Ec()},Pc:function(){},Ec:function(){_e.receiveObjectTransfer=_e.Gc,_e.threadInitTLS=_e.pc,_e.setExitStatus=_e.nc,K=!1},nc:function(){},oc:function(){for(var A of Object.values(_e.Vb))_e.mc(A);for(A of _e.Yb)A.terminate();_e.Yb=[]},mc:function(A){var L=A.Ub;delete _e.Vb[L],_e.Yb.push(A),_e.ac.splice(_e.ac.indexOf(A),1),A.Ub=0,Wt(L)},Gc:function(){},pc:function(){_e.qc.forEach(A=>A())},Fc:function(A,L){A.onmessage=V=>{var q=(V=V.data).cmd;if(A.Ub&&(_e.Bc=A.Ub),V.targetThread&&V.targetThread!=wt()){var te=_e.Vb[V.Qc];te?te.postMessage(V,V.transferList):U('Internal error! Worker sent a message "'+q+'" to target pthread '+V.targetThread+", but that thread no longer exists!")}else q==="processProxyingQueue"?Z(V.queue):q==="spawnThread"?rt(V):q==="cleanupThread"?me(V.thread):q==="killThread"?(V=V.thread,q=_e.Vb[V],delete _e.Vb[V],q.terminate(),Wt(V),_e.ac.splice(_e.ac.indexOf(q),1),q.Ub=0):q==="cancelThread"?_e.Vb[V.thread].postMessage({cmd:"cancel"}):q==="loaded"?(A.loaded=!0,L&&L(A),A.$b&&(A.$b(),delete A.$b)):q==="print"?O("Thread "+V.threadId+": "+V.text):q==="printErr"?U("Thread "+V.threadId+": "+V.text):q==="alert"?alert("Thread "+V.threadId+": "+V.text):V.target==="setimmediate"?A.postMessage(V):q==="onAbort"?i.onAbort&&i.onAbort(V.arg):q&&U("worker sent an unknown command "+q);_e.Bc=void 0},A.onerror=V=>{throw U("worker sent an error! "+V.filename+":"+V.lineno+": "+V.message),V},T&&(A.on("message",function(V){A.onmessage({data:V})}),A.on("error",function(V){A.onerror(V)}),A.on("detachedExit",function(){})),A.postMessage({cmd:"load",urlOrBlob:i.mainScriptUrlOrBlob||r,wasmMemory:$,wasmModule:J})},yc:function(){var A=I("ort-wasm-threaded.worker.js");_e.Yb.push(new Worker(A))},Cc:function(){return _e.Yb.length==0&&(_e.yc(),_e.Fc(_e.Yb[0])),_e.Yb.pop()}};function Le(A){for(;0>2>>>0];A=p()[A+48>>2>>>0],Zt(L,L-A),et(L)};var ke=[];function be(A){var L=ke[A];return L||(A>=ke.length&&(ke.length=A+1),ke[A]=L=ze.get(A)),L}i.invokeEntryPoint=function(A,L){A=be(A)(L),D()?_e.nc(A):Kt(A)};var ge,X,we=[],ue=0,ve=0;function ye(A){this.Zb=A,this.Sb=A-24,this.xc=function(L){f()[this.Sb+4>>2>>>0]=L},this.bc=function(){return f()[this.Sb+4>>2>>>0]},this.wc=function(L){f()[this.Sb+8>>2>>>0]=L},this.Dc=function(){return f()[this.Sb+8>>2>>>0]},this.rc=function(){p()[this.Sb>>2>>>0]=0},this.hc=function(L){L=L?1:0,l()[this.Sb+12>>0>>>0]=L},this.uc=function(){return l()[this.Sb+12>>0>>>0]!=0},this.ic=function(L){L=L?1:0,l()[this.Sb+13>>0>>>0]=L},this.kc=function(){return l()[this.Sb+13>>0>>>0]!=0},this.fc=function(L,V){this.cc(0),this.xc(L),this.wc(V),this.rc(),this.hc(!1),this.ic(!1)},this.sc=function(){Atomics.add(p(),this.Sb>>2,1)},this.Hc=function(){return Atomics.sub(p(),this.Sb>>2,1)===1},this.cc=function(L){f()[this.Sb+16>>2>>>0]=L},this.tc=function(){return f()[this.Sb+16>>2>>>0]},this.vc=function(){if(Qt(this.bc()))return f()[this.Zb>>2>>>0];var L=this.tc();return L!==0?L:this.Zb}}function Ze(A){return xt(new ye(A).Sb)}function Ke(A,L,V,q){return E?oe(3,1,A,L,V,q):ct(A,L,V,q)}function ct(A,L,V,q){if(typeof SharedArrayBuffer>"u")return U("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var te=[];return E&&te.length===0?Ke(A,L,V,q):(A={Ic:V,Ub:A,zc:q,Nc:te},E?(A.Oc="spawnThread",postMessage(A,te),0):rt(A))}function dt(A,L,V){return E?oe(4,1,A,L,V):0}function it(A,L){if(E)return oe(5,1,A,L)}function pt(A,L){if(E)return oe(6,1,A,L)}function vt(A,L,V){if(E)return oe(7,1,A,L,V)}function Ot(A,L,V){return E?oe(8,1,A,L,V):0}function Nt(A,L){if(E)return oe(9,1,A,L)}function Et(A,L,V){if(E)return oe(10,1,A,L,V)}function It(A,L,V,q){if(E)return oe(11,1,A,L,V,q)}function Mt(A,L,V,q){if(E)return oe(12,1,A,L,V,q)}function Rt(A,L,V,q){if(E)return oe(13,1,A,L,V,q)}function Lt(A){if(E)return oe(14,1,A)}function N(A,L){if(E)return oe(15,1,A,L)}function j(A,L,V){if(E)return oe(16,1,A,L,V)}function Z(A){Atomics.store(p(),A>>2,1),wt()&&Yt(A),Atomics.compareExchange(p(),A>>2,1,0)}function P(A){return f()[A>>>2]+4294967296*p()[A+4>>>2]}function F(A,L,V,q,te,se){return E?oe(17,1,A,L,V,q,te,se):-52}function G(A,L,V,q,te,se){if(E)return oe(18,1,A,L,V,q,te,se)}function W(A){var L=ne(A)+1,V=Ft(L);return V&&je(A,l(),V,L),V}function Y(A,L,V){function q(at){return(at=at.toTimeString().match(/\(([A-Za-z ]+)\)$/))?at[1]:"GMT"}if(E)return oe(19,1,A,L,V);var te=new Date().getFullYear(),se=new Date(te,0,1),Ae=new Date(te,6,1);te=se.getTimezoneOffset();var $e=Ae.getTimezoneOffset(),st=Math.max(te,$e);p()[A>>2>>>0]=60*st,p()[L>>2>>>0]=+(te!=$e),A=q(se),L=q(Ae),A=W(A),L=W(L),$e>2>>>0]=A,f()[V+4>>2>>>0]=L):(f()[V>>2>>>0]=L,f()[V+4>>2>>>0]=A)}function oe(A,L){var V=arguments.length-2,q=arguments;return H(()=>{for(var te=qt(8*V),se=te>>3,Ae=0;Ae>>0]=$e}return Xt(A,V,te,L)})}i.executeNotifiedProxyingQueue=Z,X=T?()=>{var A=process.hrtime();return 1e3*A[0]+A[1]/1e6}:E?()=>performance.now()-i.__performance_now_clock_drift:()=>performance.now();var xe,Ie=[],Ue={};function Ve(){if(!xe){var A,L={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:x||"./this.program"};for(A in Ue)Ue[A]===void 0?delete L[A]:L[A]=Ue[A];var V=[];for(A in L)V.push(A+"="+L[A]);xe=V}return xe}function Q(A,L){if(E)return oe(20,1,A,L);var V=0;return Ve().forEach(function(q,te){var se=L+V;for(te=f()[A+4*te>>2>>>0]=se,se=0;se>0>>>0]=q.charCodeAt(se);l()[te>>0>>>0]=0,V+=q.length+1}),0}function Re(A,L){if(E)return oe(21,1,A,L);var V=Ve();f()[A>>2>>>0]=V.length;var q=0;return V.forEach(function(te){q+=te.length+1}),f()[L>>2>>>0]=q,0}function Ye(A){return E?oe(22,1,A):52}function mt(A,L,V,q){return E?oe(23,1,A,L,V,q):52}function ut(A,L,V,q,te){return E?oe(24,1,A,L,V,q,te):70}var Tt=[null,[],[]];function ht(A,L){var V=Tt[A];L===0||L===10?((A===1?O:U)(Be(V,0)),V.length=0):V.push(L)}function Je(A,L,V,q){if(E)return oe(25,1,A,L,V,q);for(var te=0,se=0;se>2>>>0],$e=f()[L+4>>2>>>0];L+=8;for(var st=0;st<$e;st++)ht(A,h()[Ae+st>>>0]);te+=$e}return f()[q>>2>>>0]=te,0}var bt=0;function ft(A){return A%4==0&&(A%100!=0||A%400==0)}var At=[31,29,31,30,31,30,31,31,30,31,30,31],zt=[31,28,31,30,31,30,31,31,30,31,30,31];function Dt(A,L,V,q){function te(ae,lt,gt){for(ae=typeof ae=="number"?ae.toString():ae||"";ae.lengthBt?-1:0Ct-ae.getDate())){ae.setDate(ae.getDate()+lt);break}lt-=Ct-ae.getDate()+1,ae.setDate(1),11>gt?ae.setMonth(gt+1):(ae.setMonth(0),ae.setFullYear(ae.getFullYear()+1))}return gt=new Date(ae.getFullYear()+1,0,4),lt=$e(new Date(ae.getFullYear(),0,4)),gt=$e(gt),0>=Ae(lt,ae)?0>=Ae(gt,ae)?ae.getFullYear()+1:ae.getFullYear():ae.getFullYear()-1}var at=p()[q+40>>2>>>0];for(var _t in q={Lc:p()[q>>2>>>0],Kc:p()[q+4>>2>>>0],dc:p()[q+8>>2>>>0],jc:p()[q+12>>2>>>0],ec:p()[q+16>>2>>>0],Xb:p()[q+20>>2>>>0],Tb:p()[q+24>>2>>>0],Wb:p()[q+28>>2>>>0],Rc:p()[q+32>>2>>>0],Jc:p()[q+36>>2>>>0],Mc:at?Ce(at):""},V=Ce(V),at={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})V=V.replace(new RegExp(_t,"g"),at[_t]);var Pt="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),St="January February March April May June July August September October November December".split(" ");for(_t in at={"%a":function(ae){return Pt[ae.Tb].substring(0,3)},"%A":function(ae){return Pt[ae.Tb]},"%b":function(ae){return St[ae.ec].substring(0,3)},"%B":function(ae){return St[ae.ec]},"%C":function(ae){return se((ae.Xb+1900)/100|0,2)},"%d":function(ae){return se(ae.jc,2)},"%e":function(ae){return te(ae.jc,2," ")},"%g":function(ae){return st(ae).toString().substring(2)},"%G":function(ae){return st(ae)},"%H":function(ae){return se(ae.dc,2)},"%I":function(ae){return(ae=ae.dc)==0?ae=12:12ae.dc?"AM":"PM"},"%S":function(ae){return se(ae.Lc,2)},"%t":function(){return" "},"%u":function(ae){return ae.Tb||7},"%U":function(ae){return se(Math.floor((ae.Wb+7-ae.Tb)/7),2)},"%V":function(ae){var lt=Math.floor((ae.Wb+7-(ae.Tb+6)%7)/7);if(2>=(ae.Tb+371-ae.Wb-2)%7&<++,lt)lt==53&&((gt=(ae.Tb+371-ae.Wb)%7)==4||gt==3&&ft(ae.Xb)||(lt=1));else{lt=52;var gt=(ae.Tb+7-ae.Wb-1)%7;(gt==4||gt==5&&ft(ae.Xb%400-1))&<++}return se(lt,2)},"%w":function(ae){return ae.Tb},"%W":function(ae){return se(Math.floor((ae.Wb+7-(ae.Tb+6)%7)/7),2)},"%y":function(ae){return(ae.Xb+1900).toString().substring(2)},"%Y":function(ae){return ae.Xb+1900},"%z":function(ae){var lt=0<=(ae=ae.Jc);return ae=Math.abs(ae)/60,(lt?"+":"-")+("0000"+(ae/60*100+ae%60)).slice(-4)},"%Z":function(ae){return ae.Mc},"%%":function(){return"%"}},V=V.replace(/%%/g,"\0\0"),at)V.includes(_t)&&(V=V.replace(new RegExp(_t,"g"),at[_t](q)));return _t=function(ae){var lt=Array(ne(ae)+1);return je(ae,lt,0,lt.length),lt}(V=V.replace(/\0\0/g,"%")),_t.length>L?0:(function(ae,lt){l().set(ae,lt>>>0)}(_t,A),_t.length-1)}_e.fc();var Vt=[null,Ge,Se,Ke,dt,it,pt,vt,Ot,Nt,Et,It,Mt,Rt,Lt,N,j,F,G,Y,Q,Re,Ye,mt,ut,Je],yt={b:function(A){return Ft(A+24)+24},n:function(A){return(A=new ye(A)).uc()||(A.hc(!0),ue--),A.ic(!1),we.push(A),A.sc(),A.vc()},ma:function(A){throw U("Unexpected exception thrown, this is not properly supported - aborting"),Ee=!0,A},x:function(){ot(0);var A=we.pop();if(A.Hc()&&!A.kc()){var L=A.Dc();L&&be(L)(A.Zb),Ze(A.Zb)}ve=0},e:function(){var A=ve;if(!A)return bt=0;var L=new ye(A);L.cc(A);var V=L.bc();if(!V)return bt=0,A;for(var q=Array.prototype.slice.call(arguments),te=0;teZ(q));else if(E)postMessage({targetThread:A,cmd:"processProxyingQueue",queue:q});else{if(!(A=_e.Vb[A]))return;A.postMessage({cmd:"processProxyingQueue",queue:q})}return 1},Ea:function(){return-1},Pa:function(A,L){A=new Date(1e3*P(A)),p()[L>>2>>>0]=A.getUTCSeconds(),p()[L+4>>2>>>0]=A.getUTCMinutes(),p()[L+8>>2>>>0]=A.getUTCHours(),p()[L+12>>2>>>0]=A.getUTCDate(),p()[L+16>>2>>>0]=A.getUTCMonth(),p()[L+20>>2>>>0]=A.getUTCFullYear()-1900,p()[L+24>>2>>>0]=A.getUTCDay(),A=(A.getTime()-Date.UTC(A.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,p()[L+28>>2>>>0]=A},Qa:function(A,L){A=new Date(1e3*P(A)),p()[L>>2>>>0]=A.getSeconds(),p()[L+4>>2>>>0]=A.getMinutes(),p()[L+8>>2>>>0]=A.getHours(),p()[L+12>>2>>>0]=A.getDate(),p()[L+16>>2>>>0]=A.getMonth(),p()[L+20>>2>>>0]=A.getFullYear()-1900,p()[L+24>>2>>>0]=A.getDay();var V=new Date(A.getFullYear(),0,1),q=(A.getTime()-V.getTime())/864e5|0;p()[L+28>>2>>>0]=q,p()[L+36>>2>>>0]=-60*A.getTimezoneOffset(),q=new Date(A.getFullYear(),6,1).getTimezoneOffset(),A=0|(q!=(V=V.getTimezoneOffset())&&A.getTimezoneOffset()==Math.min(V,q)),p()[L+32>>2>>>0]=A},Ra:function(A){var L=new Date(p()[A+20>>2>>>0]+1900,p()[A+16>>2>>>0],p()[A+12>>2>>>0],p()[A+8>>2>>>0],p()[A+4>>2>>>0],p()[A>>2>>>0],0),V=p()[A+32>>2>>>0],q=L.getTimezoneOffset(),te=new Date(L.getFullYear(),0,1),se=new Date(L.getFullYear(),6,1).getTimezoneOffset(),Ae=te.getTimezoneOffset(),$e=Math.min(Ae,se);return 0>V?p()[A+32>>2>>>0]=+(se!=Ae&&$e==q):0>2>>>0]=L.getDay(),V=(L.getTime()-te.getTime())/864e5|0,p()[A+28>>2>>>0]=V,p()[A>>2>>>0]=L.getSeconds(),p()[A+4>>2>>>0]=L.getMinutes(),p()[A+8>>2>>>0]=L.getHours(),p()[A+12>>2>>>0]=L.getDate(),p()[A+16>>2>>>0]=L.getMonth(),L.getTime()/1e3|0},Aa:F,Ba:G,Sa:function A(L,V,q){A.Ac||(A.Ac=!0,Y(L,V,q))},y:function(){Te("")},U:function(){if(!T&&!M){var A="Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread";ge||(ge={}),ge[A]||(ge[A]=1,T&&(A="warning: "+A),U(A))}},ra:function(){return 4294901760},B:X,Ia:function(A,L,V){h().copyWithin(A>>>0,L>>>0,L+V>>>0)},F:function(){return T?t(3993).cpus().length:navigator.hardwareConcurrency},Da:function(A,L,V){Ie.length=L,V>>=3;for(var q=0;q>>0];return(0>A?He[-A-1]:Vt[A]).apply(null,Ie)},qa:function(A){var L=h().length;if((A>>>=0)<=L||4294901760=V;V*=2){var q=L*(1+.2/V);q=Math.min(q,A+100663296);var te=Math;q=Math.max(A,q),te=te.min.call(te,4294901760,q+(65536-q%65536)%65536);e:{try{$.grow(te-ee.byteLength+65535>>>16),Qe($.buffer);var se=1;break e}catch{}se=void 0}if(se)return!0}return!1},Na:function(){throw"unwind"},Ga:Q,Ha:Re,J:We,I:Ye,S:mt,ga:ut,R:Je,d:function(){return bt},na:function A(L,V){A.lc||(A.lc=function(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var te=new Uint8Array(1);return()=>(crypto.getRandomValues(te),te[0])}if(T)try{var se=t(Object(function(){var Ae=new Error("Cannot find module 'crypto'");throw Ae.code="MODULE_NOT_FOUND",Ae}()));return()=>se.randomBytes(1)[0]}catch{}return()=>Te("randomDevice")}());for(var q=0;q>0>>>0]=A.lc();return 0},ia:function(A,L,V){var q=tt();try{return be(A)(L,V)}catch(te){if(et(q),te!==te+0)throw te;ot(1,0)}},ja:function(A,L,V){var q=tt();try{return be(A)(L,V)}catch(te){if(et(q),te!==te+0)throw te;ot(1,0)}},K:function(A){var L=tt();try{return be(A)()}catch(V){if(et(L),V!==V+0)throw V;ot(1,0)}},f:function(A,L){var V=tt();try{return be(A)(L)}catch(q){if(et(V),q!==q+0)throw q;ot(1,0)}},P:function(A,L,V){var q=tt();try{return be(A)(L,V)}catch(te){if(et(q),te!==te+0)throw te;ot(1,0)}},Q:function(A,L,V){var q=tt();try{return be(A)(L,V)}catch(te){if(et(q),te!==te+0)throw te;ot(1,0)}},k:function(A,L,V){var q=tt();try{return be(A)(L,V)}catch(te){if(et(q),te!==te+0)throw te;ot(1,0)}},p:function(A,L,V,q){var te=tt();try{return be(A)(L,V,q)}catch(se){if(et(te),se!==se+0)throw se;ot(1,0)}},q:function(A,L,V,q,te){var se=tt();try{return be(A)(L,V,q,te)}catch(Ae){if(et(se),Ae!==Ae+0)throw Ae;ot(1,0)}},N:function(A,L,V,q,te,se){var Ae=tt();try{return be(A)(L,V,q,te,se)}catch($e){if(et(Ae),$e!==$e+0)throw $e;ot(1,0)}},s:function(A,L,V,q,te,se){var Ae=tt();try{return be(A)(L,V,q,te,se)}catch($e){if(et(Ae),$e!==$e+0)throw $e;ot(1,0)}},w:function(A,L,V,q,te,se,Ae){var $e=tt();try{return be(A)(L,V,q,te,se,Ae)}catch(st){if(et($e),st!==st+0)throw st;ot(1,0)}},L:function(A,L,V,q,te,se,Ae,$e){var st=tt();try{return be(A)(L,V,q,te,se,Ae,$e)}catch(at){if(et(st),at!==at+0)throw at;ot(1,0)}},E:function(A,L,V,q,te,se,Ae,$e,st,at,_t,Pt){var St=tt();try{return be(A)(L,V,q,te,se,Ae,$e,st,at,_t,Pt)}catch(ae){if(et(St),ae!==ae+0)throw ae;ot(1,0)}},aa:function(A,L,V,q,te,se,Ae,$e){var st=tt();try{return ln(A,L,V,q,te,se,Ae,$e)}catch(at){if(et(st),at!==at+0)throw at;ot(1,0)}},_:function(A,L,V,q,te,se,Ae){var $e=tt();try{return en(A,L,V,q,te,se,Ae)}catch(st){if(et($e),st!==st+0)throw st;ot(1,0)}},Z:function(A,L,V,q,te){var se=tt();try{return cn(A,L,V,q,te)}catch(Ae){if(et(se),Ae!==Ae+0)throw Ae;ot(1,0)}},ca:function(A,L,V,q){var te=tt();try{return sn(A,L,V,q)}catch(se){if(et(te),se!==se+0)throw se;ot(1,0)}},$:function(A){var L=tt();try{return Jt(A)}catch(V){if(et(L),V!==V+0)throw V;ot(1,0)}},ba:function(A,L){var V=tt();try{return an(A,L)}catch(q){if(et(V),q!==q+0)throw q;ot(1,0)}},Y:function(A,L,V){var q=tt();try{return tn(A,L,V)}catch(te){if(et(q),te!==te+0)throw te;ot(1,0)}},g:function(A){var L=tt();try{be(A)()}catch(V){if(et(L),V!==V+0)throw V;ot(1,0)}},r:function(A,L){var V=tt();try{be(A)(L)}catch(q){if(et(V),q!==q+0)throw q;ot(1,0)}},i:function(A,L,V){var q=tt();try{be(A)(L,V)}catch(te){if(et(q),te!==te+0)throw te;ot(1,0)}},ha:function(A,L,V,q){var te=tt();try{be(A)(L,V,q)}catch(se){if(et(te),se!==se+0)throw se;ot(1,0)}},m:function(A,L,V,q){var te=tt();try{be(A)(L,V,q)}catch(se){if(et(te),se!==se+0)throw se;ot(1,0)}},v:function(A,L,V,q,te){var se=tt();try{be(A)(L,V,q,te)}catch(Ae){if(et(se),Ae!==Ae+0)throw Ae;ot(1,0)}},u:function(A,L,V,q,te,se){var Ae=tt();try{be(A)(L,V,q,te,se)}catch($e){if(et(Ae),$e!==$e+0)throw $e;ot(1,0)}},O:function(A,L,V,q,te,se,Ae){var $e=tt();try{be(A)(L,V,q,te,se,Ae)}catch(st){if(et($e),st!==st+0)throw st;ot(1,0)}},A:function(A,L,V,q,te,se,Ae,$e){var st=tt();try{be(A)(L,V,q,te,se,Ae,$e)}catch(at){if(et(st),at!==at+0)throw at;ot(1,0)}},ka:function(A,L,V,q,te,se,Ae,$e,st){var at=tt();try{be(A)(L,V,q,te,se,Ae,$e,st)}catch(_t){if(et(at),_t!==_t+0)throw _t;ot(1,0)}},C:function(A,L,V,q,te,se,Ae,$e,st,at,_t){var Pt=tt();try{be(A)(L,V,q,te,se,Ae,$e,st,at,_t)}catch(St){if(et(Pt),St!==St+0)throw St;ot(1,0)}},D:function(A,L,V,q,te,se,Ae,$e,st,at,_t,Pt,St,ae,lt,gt){var Ct=tt();try{be(A)(L,V,q,te,se,Ae,$e,st,at,_t,Pt,St,ae,lt,gt)}catch(Bt){if(et(Ct),Bt!==Bt+0)throw Bt;ot(1,0)}},fa:function(A,L,V,q,te,se,Ae,$e){var st=tt();try{nn(A,L,V,q,te,se,Ae,$e)}catch(at){if(et(st),at!==at+0)throw at;ot(1,0)}},da:function(A,L,V,q,te,se,Ae,$e,st,at,_t,Pt){var St=tt();try{on(A,L,V,q,te,se,Ae,$e,st,at,_t,Pt)}catch(ae){if(et(St),ae!==ae+0)throw ae;ot(1,0)}},ea:function(A,L,V,q,te,se){var Ae=tt();try{rn(A,L,V,q,te,se)}catch($e){if(et(Ae),$e!==$e+0)throw $e;ot(1,0)}},o:function(A){return A},a:$||i.wasmMemory,G:function(A){bt=A},la:Dt,z:function(A,L,V,q){return Dt(A,L,V,q)}};(function(){function A(te,se){i.asm=te.exports,_e.qc.push(i.asm.sb),ze=i.asm.ub,nt.unshift(i.asm.Va),J=se,E||(fe--,i.monitorRunDependencies&&i.monitorRunDependencies(fe),fe==0&&pe&&(te=pe,pe=null,te()))}function L(te){A(te.instance,te.module)}function V(te){return function(){if(!z&&(S||M)){if(typeof fetch=="function"&&!ce.startsWith("file://"))return fetch(ce,{credentials:"same-origin"}).then(function(se){if(!se.ok)throw"failed to load wasm binary file at '"+ce+"'";return se.arrayBuffer()}).catch(function(){return Ne()});if(m)return new Promise(function(se,Ae){m(ce,function($e){se(new Uint8Array($e))},Ae)})}return Promise.resolve().then(function(){return Ne()})}().then(function(se){return WebAssembly.instantiate(se,q)}).then(function(se){return se}).then(te,function(se){U("failed to asynchronously prepare wasm: "+se),Te(se)})}var q={a:yt};if(E||(fe++,i.monitorRunDependencies&&i.monitorRunDependencies(fe)),i.instantiateWasm)try{return i.instantiateWasm(q,A)}catch(te){return U("Module.instantiateWasm callback failed with error: "+te),!1}(z||typeof WebAssembly.instantiateStreaming!="function"||Oe()||ce.startsWith("file://")||T||typeof fetch!="function"?V(L):fetch(ce,{credentials:"same-origin"}).then(function(te){return WebAssembly.instantiateStreaming(te,q).then(L,function(se){return U("wasm streaming compile failed: "+se),U("falling back to ArrayBuffer instantiation"),V(L)})})).catch(a)})(),i.___wasm_call_ctors=function(){return(i.___wasm_call_ctors=i.asm.Va).apply(null,arguments)},i._OrtInit=function(){return(i._OrtInit=i.asm.Wa).apply(null,arguments)},i._OrtCreateSessionOptions=function(){return(i._OrtCreateSessionOptions=i.asm.Xa).apply(null,arguments)},i._OrtAppendExecutionProvider=function(){return(i._OrtAppendExecutionProvider=i.asm.Ya).apply(null,arguments)},i._OrtAddSessionConfigEntry=function(){return(i._OrtAddSessionConfigEntry=i.asm.Za).apply(null,arguments)},i._OrtReleaseSessionOptions=function(){return(i._OrtReleaseSessionOptions=i.asm._a).apply(null,arguments)},i._OrtCreateSession=function(){return(i._OrtCreateSession=i.asm.$a).apply(null,arguments)},i._OrtReleaseSession=function(){return(i._OrtReleaseSession=i.asm.ab).apply(null,arguments)},i._OrtGetInputCount=function(){return(i._OrtGetInputCount=i.asm.bb).apply(null,arguments)},i._OrtGetOutputCount=function(){return(i._OrtGetOutputCount=i.asm.cb).apply(null,arguments)},i._OrtGetInputName=function(){return(i._OrtGetInputName=i.asm.db).apply(null,arguments)},i._OrtGetOutputName=function(){return(i._OrtGetOutputName=i.asm.eb).apply(null,arguments)},i._OrtFree=function(){return(i._OrtFree=i.asm.fb).apply(null,arguments)},i._OrtCreateTensor=function(){return(i._OrtCreateTensor=i.asm.gb).apply(null,arguments)},i._OrtGetTensorData=function(){return(i._OrtGetTensorData=i.asm.hb).apply(null,arguments)},i._OrtReleaseTensor=function(){return(i._OrtReleaseTensor=i.asm.ib).apply(null,arguments)},i._OrtCreateRunOptions=function(){return(i._OrtCreateRunOptions=i.asm.jb).apply(null,arguments)},i._OrtAddRunConfigEntry=function(){return(i._OrtAddRunConfigEntry=i.asm.kb).apply(null,arguments)},i._OrtReleaseRunOptions=function(){return(i._OrtReleaseRunOptions=i.asm.lb).apply(null,arguments)},i._OrtRun=function(){return(i._OrtRun=i.asm.mb).apply(null,arguments)},i._OrtEndProfiling=function(){return(i._OrtEndProfiling=i.asm.nb).apply(null,arguments)};var wt=i._pthread_self=function(){return(wt=i._pthread_self=i.asm.ob).apply(null,arguments)},Ft=i._malloc=function(){return(Ft=i._malloc=i.asm.pb).apply(null,arguments)},xt=i._free=function(){return(xt=i._free=i.asm.qb).apply(null,arguments)},Ut=i._fflush=function(){return(Ut=i._fflush=i.asm.rb).apply(null,arguments)};i.__emscripten_tls_init=function(){return(i.__emscripten_tls_init=i.asm.sb).apply(null,arguments)};var $t=i.___funcs_on_exit=function(){return($t=i.___funcs_on_exit=i.asm.tb).apply(null,arguments)},Gt=i.__emscripten_thread_init=function(){return(Gt=i.__emscripten_thread_init=i.asm.vb).apply(null,arguments)};i.__emscripten_thread_crashed=function(){return(i.__emscripten_thread_crashed=i.asm.wb).apply(null,arguments)};var Ht,Xt=i._emscripten_run_in_main_runtime_thread_js=function(){return(Xt=i._emscripten_run_in_main_runtime_thread_js=i.asm.xb).apply(null,arguments)},Yt=i.__emscripten_proxy_execute_task_queue=function(){return(Yt=i.__emscripten_proxy_execute_task_queue=i.asm.yb).apply(null,arguments)},Wt=i.__emscripten_thread_free_data=function(){return(Wt=i.__emscripten_thread_free_data=i.asm.zb).apply(null,arguments)},Kt=i.__emscripten_thread_exit=function(){return(Kt=i.__emscripten_thread_exit=i.asm.Ab).apply(null,arguments)},ot=i._setThrew=function(){return(ot=i._setThrew=i.asm.Bb).apply(null,arguments)},Zt=i._emscripten_stack_set_limits=function(){return(Zt=i._emscripten_stack_set_limits=i.asm.Cb).apply(null,arguments)},tt=i.stackSave=function(){return(tt=i.stackSave=i.asm.Db).apply(null,arguments)},et=i.stackRestore=function(){return(et=i.stackRestore=i.asm.Eb).apply(null,arguments)},qt=i.stackAlloc=function(){return(qt=i.stackAlloc=i.asm.Fb).apply(null,arguments)},jt=i.___cxa_can_catch=function(){return(jt=i.___cxa_can_catch=i.asm.Gb).apply(null,arguments)},Qt=i.___cxa_is_pointer_type=function(){return(Qt=i.___cxa_is_pointer_type=i.asm.Hb).apply(null,arguments)},Jt=i.dynCall_j=function(){return(Jt=i.dynCall_j=i.asm.Ib).apply(null,arguments)},en=i.dynCall_iiiiij=function(){return(en=i.dynCall_iiiiij=i.asm.Jb).apply(null,arguments)},tn=i.dynCall_jii=function(){return(tn=i.dynCall_jii=i.asm.Kb).apply(null,arguments)},nn=i.dynCall_viiiiij=function(){return(nn=i.dynCall_viiiiij=i.asm.Lb).apply(null,arguments)},rn=i.dynCall_vjji=function(){return(rn=i.dynCall_vjji=i.asm.Mb).apply(null,arguments)},on=i.dynCall_viiijjjii=function(){return(on=i.dynCall_viiijjjii=i.asm.Nb).apply(null,arguments)},sn=i.dynCall_iij=function(){return(sn=i.dynCall_iij=i.asm.Ob).apply(null,arguments)},an=i.dynCall_ji=function(){return(an=i.dynCall_ji=i.asm.Pb).apply(null,arguments)},ln=i.dynCall_iiiiiij=function(){return(ln=i.dynCall_iiiiiij=i.asm.Qb).apply(null,arguments)},cn=i.dynCall_iiij=function(){return(cn=i.dynCall_iiij=i.asm.Rb).apply(null,arguments)};function un(){function A(){if(!Ht&&(Ht=!0,i.calledRun=!0,!Ee)&&(E||Le(nt),n(i),i.onRuntimeInitialized&&i.onRuntimeInitialized(),!E)){if(i.postRun)for(typeof i.postRun=="function"&&(i.postRun=[i.postRun]);i.postRun.length;){var L=i.postRun.shift();B.unshift(L)}Le(B)}}if(!(0{var r,o=(r=(r=typeof document<"u"&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(c){var l,h,p;c=c||{},l||(l=c!==void 0?c:{}),l.ready=new Promise(function(N,j){h=N,p=j});var f,d,i,n,a,u,m=Object.assign({},l),g="./this.program",_=(N,j)=>{throw j},b=typeof window=="object",y=typeof importScripts=="function",v=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",x="";v?(x=y?t(908).dirname(x)+"/":"//",u=()=>{a||(n=t(1384),a=t(908))},f=function(N,j){return u(),N=a.normalize(N),n.readFileSync(N,j?void 0:"utf8")},i=N=>((N=f(N,!0)).buffer||(N=new Uint8Array(N)),N),d=(N,j,Z)=>{u(),N=a.normalize(N),n.readFile(N,function(P,F){P?Z(P):j(F.buffer)})},1{if(T||0{var j=new XMLHttpRequest;return j.open("GET",N,!1),j.send(null),j.responseText},y&&(i=N=>{var j=new XMLHttpRequest;return j.open("GET",N,!1),j.responseType="arraybuffer",j.send(null),new Uint8Array(j.response)}),d=(N,j,Z)=>{var P=new XMLHttpRequest;P.open("GET",N,!0),P.responseType="arraybuffer",P.onload=()=>{P.status==200||P.status==0&&P.response?j(P.response):Z()},P.onerror=Z,P.send(null)});var w,S=l.print||console.log.bind(console),M=l.printErr||console.warn.bind(console);Object.assign(l,m),m=null,l.thisProgram&&(g=l.thisProgram),l.quit&&(_=l.quit),l.wasmBinary&&(w=l.wasmBinary);var T=l.noExitRuntime||!1;typeof WebAssembly!="object"&&Qe("no native wasm support detected");var E,R,I,k,C,z,O=!1,U=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function K(N,j,Z){var P=(j>>>=0)+Z;for(Z=j;N[Z]&&!(Z>=P);)++Z;if(16(F=(240&F)==224?(15&F)<<12|G<<6|W:(7&F)<<18|G<<12|W<<6|63&N[j++])?P+=String.fromCharCode(F):(F-=65536,P+=String.fromCharCode(55296|F>>10,56320|1023&F))}}else P+=String.fromCharCode(F)}return P}function $(N,j){return(N>>>=0)?K(k,N,j):""}function J(N,j,Z,P){if(!(0>>=0;P=Z+P-1;for(var G=0;G=W&&(W=65536+((1023&W)<<10)|1023&N.charCodeAt(++G)),127>=W){if(Z>=P)break;j[Z++>>>0]=W}else{if(2047>=W){if(Z+1>=P)break;j[Z++>>>0]=192|W>>6}else{if(65535>=W){if(Z+2>=P)break;j[Z++>>>0]=224|W>>12}else{if(Z+3>=P)break;j[Z++>>>0]=240|W>>18,j[Z++>>>0]=128|W>>12&63}j[Z++>>>0]=128|W>>6&63}j[Z++>>>0]=128|63&W}}return j[Z>>>0]=0,Z-F}function ee(N){for(var j=0,Z=0;Z=P?j++:2047>=P?j+=2:55296<=P&&57343>=P?(j+=4,++Z):j+=3}return j}function he(){var N=E.buffer;R=N,l.HEAP8=I=new Int8Array(N),l.HEAP16=new Int16Array(N),l.HEAP32=C=new Int32Array(N),l.HEAPU8=k=new Uint8Array(N),l.HEAPU16=new Uint16Array(N),l.HEAPU32=z=new Uint32Array(N),l.HEAPF32=new Float32Array(N),l.HEAPF64=new Float64Array(N)}var ie,le=[],de=[],Me=[],Ee=[],Fe=0;function Be(){var N=l.preRun.shift();le.unshift(N)}var Ce,je=0,ne=null;function Qe(N){throw l.onAbort&&l.onAbort(N),M(N="Aborted("+N+")"),O=!0,N=new WebAssembly.RuntimeError(N+". Build with -sASSERTIONS for more info."),p(N),N}function Pe(){return Ce.startsWith("data:application/octet-stream;base64,")}if(Ce="ort-wasm.wasm",!Pe()){var ze=Ce;Ce=l.locateFile?l.locateFile(ze,x):x+ze}function De(){var N=Ce;try{if(N==Ce&&w)return new Uint8Array(w);if(i)return i(N);throw"both async and sync fetching of the wasm failed"}catch(j){Qe(j)}}function nt(N){this.name="ExitStatus",this.message="Program terminated with exit("+N+")",this.status=N}function qe(N){for(;0>2>>>0]=j},this.Eb=function(){return z[this.zb+4>>2>>>0]},this.Sb=function(j){z[this.zb+8>>2>>>0]=j},this.Wb=function(){return z[this.zb+8>>2>>>0]},this.Tb=function(){C[this.zb>>2>>>0]=0},this.Ib=function(j){I[this.zb+12>>0>>>0]=j?1:0},this.Pb=function(){return I[this.zb+12>>0>>>0]!=0},this.Jb=function(j){I[this.zb+13>>0>>>0]=j?1:0},this.Lb=function(){return I[this.zb+13>>0>>>0]!=0},this.Rb=function(j,Z){this.Fb(0),this.Ub(j),this.Sb(Z),this.Tb(),this.Ib(!1),this.Jb(!1)},this.Nb=function(){C[this.zb>>2>>>0]+=1},this.Xb=function(){var j=C[this.zb>>2>>>0];return C[this.zb>>2>>>0]=j-1,j===1},this.Fb=function(j){z[this.zb+16>>2>>>0]=j},this.Ob=function(){return z[this.zb+16>>2>>>0]},this.Qb=function(){if(ct(this.Eb()))return z[this.Db>>2>>>0];var j=this.Ob();return j!==0?j:this.Db}}function fe(N){return ge(new ce(N).zb)}var pe=[];function Te(N){var j=pe[N];return j||(N>=pe.length&&(pe.length=N+1),pe[N]=j=ie.get(N)),j}function Oe(N){var j=ee(N)+1,Z=be(j);return Z&&J(N,I,Z,j),Z}var Ne={};function He(){if(!Xe){var N,j={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:g||"./this.program"};for(N in Ne)Ne[N]===void 0?delete j[N]:j[N]=Ne[N];var Z=[];for(N in j)Z.push(N+"="+j[N]);Xe=Z}return Xe}var Xe,me=[null,[],[]];function rt(N,j){var Z=me[N];j===0||j===10?((N===1?S:M)(K(Z,0)),Z.length=0):Z.push(j)}var Ge=0;function We(N){return N%4==0&&(N%100!=0||N%400==0)}var _e=[31,29,31,30,31,30,31,31,30,31,30,31],Le=[31,28,31,30,31,30,31,31,30,31,30,31];function H(N,j,Z,P){function F(Q,Re,Ye){for(Q=typeof Q=="number"?Q.toString():Q||"";Q.lengthut?-1:0mt-Q.getDate())){Q.setDate(Q.getDate()+Re);break}Re-=mt-Q.getDate()+1,Q.setDate(1),11>Ye?Q.setMonth(Ye+1):(Q.setMonth(0),Q.setFullYear(Q.getFullYear()+1))}return Ye=new Date(Q.getFullYear()+1,0,4),Re=Y(new Date(Q.getFullYear(),0,4)),Ye=Y(Ye),0>=W(Re,Q)?0>=W(Ye,Q)?Q.getFullYear()+1:Q.getFullYear():Q.getFullYear()-1}var xe=C[P+40>>2>>>0];for(var Ie in P={$b:C[P>>2>>>0],Zb:C[P+4>>2>>>0],Gb:C[P+8>>2>>>0],Kb:C[P+12>>2>>>0],Hb:C[P+16>>2>>>0],Cb:C[P+20>>2>>>0],Ab:C[P+24>>2>>>0],Bb:C[P+28>>2>>>0],bc:C[P+32>>2>>>0],Yb:C[P+36>>2>>>0],ac:xe?$(xe):""},Z=$(Z),xe={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})Z=Z.replace(new RegExp(Ie,"g"),xe[Ie]);var Ue="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),Ve="January February March April May June July August September October November December".split(" ");for(Ie in xe={"%a":function(Q){return Ue[Q.Ab].substring(0,3)},"%A":function(Q){return Ue[Q.Ab]},"%b":function(Q){return Ve[Q.Hb].substring(0,3)},"%B":function(Q){return Ve[Q.Hb]},"%C":function(Q){return G((Q.Cb+1900)/100|0,2)},"%d":function(Q){return G(Q.Kb,2)},"%e":function(Q){return F(Q.Kb,2," ")},"%g":function(Q){return oe(Q).toString().substring(2)},"%G":function(Q){return oe(Q)},"%H":function(Q){return G(Q.Gb,2)},"%I":function(Q){return(Q=Q.Gb)==0?Q=12:12Q.Gb?"AM":"PM"},"%S":function(Q){return G(Q.$b,2)},"%t":function(){return" "},"%u":function(Q){return Q.Ab||7},"%U":function(Q){return G(Math.floor((Q.Bb+7-Q.Ab)/7),2)},"%V":function(Q){var Re=Math.floor((Q.Bb+7-(Q.Ab+6)%7)/7);if(2>=(Q.Ab+371-Q.Bb-2)%7&&Re++,Re)Re==53&&((Ye=(Q.Ab+371-Q.Bb)%7)==4||Ye==3&&We(Q.Cb)||(Re=1));else{Re=52;var Ye=(Q.Ab+7-Q.Bb-1)%7;(Ye==4||Ye==5&&We(Q.Cb%400-1))&&Re++}return G(Re,2)},"%w":function(Q){return Q.Ab},"%W":function(Q){return G(Math.floor((Q.Bb+7-(Q.Ab+6)%7)/7),2)},"%y":function(Q){return(Q.Cb+1900).toString().substring(2)},"%Y":function(Q){return Q.Cb+1900},"%z":function(Q){var Re=0<=(Q=Q.Yb);return Q=Math.abs(Q)/60,(Re?"+":"-")+("0000"+(Q/60*100+Q%60)).slice(-4)},"%Z":function(Q){return Q.ac},"%%":function(){return"%"}},Z=Z.replace(/%%/g,"\0\0"),xe)Z.includes(Ie)&&(Z=Z.replace(new RegExp(Ie,"g"),xe[Ie](P)));return Ie=function(Q){var Re=Array(ee(Q)+1);return J(Q,Re,0,Re.length),Re}(Z=Z.replace(/\0\0/g,"%")),Ie.length>j?0:(I.set(Ie,N>>>0),Ie.length-1)}var Se={a:function(N){return be(N+24)+24},m:function(N){return(N=new ce(N)).Pb()||(N.Ib(!0),D--),N.Jb(!1),B.push(N),N.Nb(),N.Qb()},ia:function(N){throw M("Unexpected exception thrown, this is not properly supported - aborting"),O=!0,N},w:function(){ue(0);var N=B.pop();if(N.Xb()&&!N.Lb()){var j=N.Wb();j&&Te(j)(N.Db),fe(N.Db)}re=0},d:function(){var N=re;if(!N)return Ge=0;var j=new ce(N);j.Fb(N);var Z=j.Eb();if(!Z)return Ge=0,N;for(var P=Array.prototype.slice.call(arguments),F=0;F>>2]+4294967296*C[N+4>>>2])),C[j>>2>>>0]=N.getUTCSeconds(),C[j+4>>2>>>0]=N.getUTCMinutes(),C[j+8>>2>>>0]=N.getUTCHours(),C[j+12>>2>>>0]=N.getUTCDate(),C[j+16>>2>>>0]=N.getUTCMonth(),C[j+20>>2>>>0]=N.getUTCFullYear()-1900,C[j+24>>2>>>0]=N.getUTCDay(),C[j+28>>2>>>0]=(N.getTime()-Date.UTC(N.getUTCFullYear(),0,1,0,0,0,0))/864e5|0},Ea:function(N,j){N=new Date(1e3*(z[N>>>2]+4294967296*C[N+4>>>2])),C[j>>2>>>0]=N.getSeconds(),C[j+4>>2>>>0]=N.getMinutes(),C[j+8>>2>>>0]=N.getHours(),C[j+12>>2>>>0]=N.getDate(),C[j+16>>2>>>0]=N.getMonth(),C[j+20>>2>>>0]=N.getFullYear()-1900,C[j+24>>2>>>0]=N.getDay();var Z=new Date(N.getFullYear(),0,1);C[j+28>>2>>>0]=(N.getTime()-Z.getTime())/864e5|0,C[j+36>>2>>>0]=-60*N.getTimezoneOffset();var P=new Date(N.getFullYear(),6,1).getTimezoneOffset();Z=Z.getTimezoneOffset(),C[j+32>>2>>>0]=0|(P!=Z&&N.getTimezoneOffset()==Math.min(Z,P))},Fa:function(N){var j=new Date(C[N+20>>2>>>0]+1900,C[N+16>>2>>>0],C[N+12>>2>>>0],C[N+8>>2>>>0],C[N+4>>2>>>0],C[N>>2>>>0],0),Z=C[N+32>>2>>>0],P=j.getTimezoneOffset(),F=new Date(j.getFullYear(),0,1),G=new Date(j.getFullYear(),6,1).getTimezoneOffset(),W=F.getTimezoneOffset(),Y=Math.min(W,G);return 0>Z?C[N+32>>2>>>0]=+(G!=W&&Y==P):0>2>>>0]=j.getDay(),C[N+28>>2>>>0]=(j.getTime()-F.getTime())/864e5|0,C[N>>2>>>0]=j.getSeconds(),C[N+4>>2>>>0]=j.getMinutes(),C[N+8>>2>>>0]=j.getHours(),C[N+12>>2>>>0]=j.getDate(),C[N+16>>2>>>0]=j.getMonth(),j.getTime()/1e3|0},sa:function(){return-52},ta:function(){},Ga:function N(j,Z,P){N.Vb||(N.Vb=!0,function(F,G,W){function Y(Ve){return(Ve=Ve.toTimeString().match(/\(([A-Za-z ]+)\)$/))?Ve[1]:"GMT"}var oe=new Date().getFullYear(),xe=new Date(oe,0,1),Ie=new Date(oe,6,1);oe=xe.getTimezoneOffset();var Ue=Ie.getTimezoneOffset();C[F>>2>>>0]=60*Math.max(oe,Ue),C[G>>2>>>0]=+(oe!=Ue),F=Y(xe),G=Y(Ie),F=Oe(F),G=Oe(G),Ue>2>>>0]=F,z[W+4>>2>>>0]=G):(z[W>>2>>>0]=G,z[W+4>>2>>>0]=F)}(j,Z,P))},B:function(){Qe("")},ma:function(){return 4294901760},I:v?()=>{var N=process.hrtime();return 1e3*N[0]+N[1]/1e6}:()=>performance.now(),xa:function(N,j,Z){k.copyWithin(N>>>0,j>>>0,j+Z>>>0)},G:function(N){var j=k.length;if(4294901760<(N>>>=0))return!1;for(var Z=1;4>=Z;Z*=2){var P=j*(1+.2/Z);P=Math.min(P,N+100663296);var F=Math;P=Math.max(N,P),F=F.min.call(F,4294901760,P+(65536-P%65536)%65536);e:{try{E.grow(F-R.byteLength+65535>>>16),he();var G=1;break e}catch{}G=void 0}if(G)return!0}return!1},va:function(N,j){var Z=0;return He().forEach(function(P,F){var G=j+Z;for(F=z[N+4*F>>2>>>0]=G,G=0;G>0>>>0]=P.charCodeAt(G);I[F>>0>>>0]=0,Z+=P.length+1}),0},wa:function(N,j){var Z=He();z[N>>2>>>0]=Z.length;var P=0;return Z.forEach(function(F){P+=F.length+1}),z[j>>2>>>0]=P,0},ba:function(N){T||0>2>>>0],Y=z[j+4>>2>>>0];j+=8;for(var oe=0;oe>>0]);F+=Y}return z[P>>2>>>0]=F,0},c:function(){return Ge},ja:function N(j,Z){N.Mb||(N.Mb=function(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var F=new Uint8Array(1);return()=>(crypto.getRandomValues(F),F[0])}if(v)try{var G=t(Object(function(){var W=new Error("Cannot find module 'crypto'");throw W.code="MODULE_NOT_FOUND",W}()));return()=>G.randomBytes(1)[0]}catch{}return()=>Qe("randomDevice")}());for(var P=0;P>0>>>0]=N.Mb();return 0},ea:function(N,j,Z){var P=ve();try{return Te(N)(j,Z)}catch(F){if(ye(P),F!==F+0)throw F;ue(1,0)}},fa:function(N,j,Z){var P=ve();try{return Te(N)(j,Z)}catch(F){if(ye(P),F!==F+0)throw F;ue(1,0)}},J:function(N){var j=ve();try{return Te(N)()}catch(Z){if(ye(j),Z!==Z+0)throw Z;ue(1,0)}},e:function(N,j){var Z=ve();try{return Te(N)(j)}catch(P){if(ye(Z),P!==P+0)throw P;ue(1,0)}},N:function(N,j,Z){var P=ve();try{return Te(N)(j,Z)}catch(F){if(ye(P),F!==F+0)throw F;ue(1,0)}},O:function(N,j,Z){var P=ve();try{return Te(N)(j,Z)}catch(F){if(ye(P),F!==F+0)throw F;ue(1,0)}},j:function(N,j,Z){var P=ve();try{return Te(N)(j,Z)}catch(F){if(ye(P),F!==F+0)throw F;ue(1,0)}},o:function(N,j,Z,P){var F=ve();try{return Te(N)(j,Z,P)}catch(G){if(ye(F),G!==G+0)throw G;ue(1,0)}},p:function(N,j,Z,P,F){var G=ve();try{return Te(N)(j,Z,P,F)}catch(W){if(ye(G),W!==W+0)throw W;ue(1,0)}},M:function(N,j,Z,P,F,G){var W=ve();try{return Te(N)(j,Z,P,F,G)}catch(Y){if(ye(W),Y!==Y+0)throw Y;ue(1,0)}},r:function(N,j,Z,P,F,G){var W=ve();try{return Te(N)(j,Z,P,F,G)}catch(Y){if(ye(W),Y!==Y+0)throw Y;ue(1,0)}},v:function(N,j,Z,P,F,G,W){var Y=ve();try{return Te(N)(j,Z,P,F,G,W)}catch(oe){if(ye(Y),oe!==oe+0)throw oe;ue(1,0)}},K:function(N,j,Z,P,F,G,W,Y){var oe=ve();try{return Te(N)(j,Z,P,F,G,W,Y)}catch(xe){if(ye(oe),xe!==xe+0)throw xe;ue(1,0)}},D:function(N,j,Z,P,F,G,W,Y,oe,xe,Ie,Ue){var Ve=ve();try{return Te(N)(j,Z,P,F,G,W,Y,oe,xe,Ie,Ue)}catch(Q){if(ye(Ve),Q!==Q+0)throw Q;ue(1,0)}},X:function(N,j,Z,P,F,G,W,Y){var oe=ve();try{return Mt(N,j,Z,P,F,G,W,Y)}catch(xe){if(ye(oe),xe!==xe+0)throw xe;ue(1,0)}},V:function(N,j,Z,P,F,G,W){var Y=ve();try{return it(N,j,Z,P,F,G,W)}catch(oe){if(ye(Y),oe!==oe+0)throw oe;ue(1,0)}},U:function(N,j,Z,P,F){var G=ve();try{return Rt(N,j,Z,P,F)}catch(W){if(ye(G),W!==W+0)throw W;ue(1,0)}},Z:function(N,j,Z,P){var F=ve();try{return Et(N,j,Z,P)}catch(G){if(ye(F),G!==G+0)throw G;ue(1,0)}},W:function(N){var j=ve();try{return dt(N)}catch(Z){if(ye(j),Z!==Z+0)throw Z;ue(1,0)}},Y:function(N,j){var Z=ve();try{return It(N,j)}catch(P){if(ye(Z),P!==P+0)throw P;ue(1,0)}},T:function(N,j,Z){var P=ve();try{return pt(N,j,Z)}catch(F){if(ye(P),F!==F+0)throw F;ue(1,0)}},f:function(N){var j=ve();try{Te(N)()}catch(Z){if(ye(j),Z!==Z+0)throw Z;ue(1,0)}},q:function(N,j){var Z=ve();try{Te(N)(j)}catch(P){if(ye(Z),P!==P+0)throw P;ue(1,0)}},h:function(N,j,Z){var P=ve();try{Te(N)(j,Z)}catch(F){if(ye(P),F!==F+0)throw F;ue(1,0)}},da:function(N,j,Z,P){var F=ve();try{Te(N)(j,Z,P)}catch(G){if(ye(F),G!==G+0)throw G;ue(1,0)}},l:function(N,j,Z,P){var F=ve();try{Te(N)(j,Z,P)}catch(G){if(ye(F),G!==G+0)throw G;ue(1,0)}},t:function(N,j,Z,P,F){var G=ve();try{Te(N)(j,Z,P,F)}catch(W){if(ye(G),W!==W+0)throw W;ue(1,0)}},u:function(N,j,Z,P,F,G){var W=ve();try{Te(N)(j,Z,P,F,G)}catch(Y){if(ye(W),Y!==Y+0)throw Y;ue(1,0)}},x:function(N,j,Z,P,F,G,W){var Y=ve();try{Te(N)(j,Z,P,F,G,W)}catch(oe){if(ye(Y),oe!==oe+0)throw oe;ue(1,0)}},z:function(N,j,Z,P,F,G,W,Y){var oe=ve();try{Te(N)(j,Z,P,F,G,W,Y)}catch(xe){if(ye(oe),xe!==xe+0)throw xe;ue(1,0)}},ga:function(N,j,Z,P,F,G,W,Y,oe){var xe=ve();try{Te(N)(j,Z,P,F,G,W,Y,oe)}catch(Ie){if(ye(xe),Ie!==Ie+0)throw Ie;ue(1,0)}},A:function(N,j,Z,P,F,G,W,Y,oe,xe,Ie){var Ue=ve();try{Te(N)(j,Z,P,F,G,W,Y,oe,xe,Ie)}catch(Ve){if(ye(Ue),Ve!==Ve+0)throw Ve;ue(1,0)}},C:function(N,j,Z,P,F,G,W,Y,oe,xe,Ie,Ue,Ve,Q,Re,Ye){var mt=ve();try{Te(N)(j,Z,P,F,G,W,Y,oe,xe,Ie,Ue,Ve,Q,Re,Ye)}catch(ut){if(ye(mt),ut!==ut+0)throw ut;ue(1,0)}},aa:function(N,j,Z,P,F,G,W,Y){var oe=ve();try{vt(N,j,Z,P,F,G,W,Y)}catch(xe){if(ye(oe),xe!==xe+0)throw xe;ue(1,0)}},_:function(N,j,Z,P,F,G,W,Y,oe,xe,Ie,Ue){var Ve=ve();try{Nt(N,j,Z,P,F,G,W,Y,oe,xe,Ie,Ue)}catch(Q){if(ye(Ve),Q!==Q+0)throw Q;ue(1,0)}},$:function(N,j,Z,P,F,G){var W=ve();try{Ot(N,j,Z,P,F,G)}catch(Y){if(ye(W),Y!==Y+0)throw Y;ue(1,0)}},n:function(N){return N},F:function(N){Ge=N},ha:H,y:function(N,j,Z,P){return H(N,j,Z,P)}};(function(){function N(F){l.asm=F.exports,E=l.asm.Ka,he(),ie=l.asm.ib,de.unshift(l.asm.La),je--,l.monitorRunDependencies&&l.monitorRunDependencies(je),je==0&&ne&&(F=ne,ne=null,F())}function j(F){N(F.instance)}function Z(F){return function(){if(!w&&(b||y)){if(typeof fetch=="function"&&!Ce.startsWith("file://"))return fetch(Ce,{credentials:"same-origin"}).then(function(G){if(!G.ok)throw"failed to load wasm binary file at '"+Ce+"'";return G.arrayBuffer()}).catch(function(){return De()});if(d)return new Promise(function(G,W){d(Ce,function(Y){G(new Uint8Array(Y))},W)})}return Promise.resolve().then(function(){return De()})}().then(function(G){return WebAssembly.instantiate(G,P)}).then(function(G){return G}).then(F,function(G){M("failed to asynchronously prepare wasm: "+G),Qe(G)})}var P={a:Se};if(je++,l.monitorRunDependencies&&l.monitorRunDependencies(je),l.instantiateWasm)try{return l.instantiateWasm(P,N)}catch(F){return M("Module.instantiateWasm callback failed with error: "+F),!1}(w||typeof WebAssembly.instantiateStreaming!="function"||Pe()||Ce.startsWith("file://")||v||typeof fetch!="function"?Z(j):fetch(Ce,{credentials:"same-origin"}).then(function(F){return WebAssembly.instantiateStreaming(F,P).then(j,function(G){return M("wasm streaming compile failed: "+G),M("falling back to ArrayBuffer instantiation"),Z(j)})})).catch(p)})(),l.___wasm_call_ctors=function(){return(l.___wasm_call_ctors=l.asm.La).apply(null,arguments)},l._OrtInit=function(){return(l._OrtInit=l.asm.Ma).apply(null,arguments)},l._OrtCreateSessionOptions=function(){return(l._OrtCreateSessionOptions=l.asm.Na).apply(null,arguments)},l._OrtAppendExecutionProvider=function(){return(l._OrtAppendExecutionProvider=l.asm.Oa).apply(null,arguments)},l._OrtAddSessionConfigEntry=function(){return(l._OrtAddSessionConfigEntry=l.asm.Pa).apply(null,arguments)},l._OrtReleaseSessionOptions=function(){return(l._OrtReleaseSessionOptions=l.asm.Qa).apply(null,arguments)},l._OrtCreateSession=function(){return(l._OrtCreateSession=l.asm.Ra).apply(null,arguments)},l._OrtReleaseSession=function(){return(l._OrtReleaseSession=l.asm.Sa).apply(null,arguments)},l._OrtGetInputCount=function(){return(l._OrtGetInputCount=l.asm.Ta).apply(null,arguments)},l._OrtGetOutputCount=function(){return(l._OrtGetOutputCount=l.asm.Ua).apply(null,arguments)},l._OrtGetInputName=function(){return(l._OrtGetInputName=l.asm.Va).apply(null,arguments)},l._OrtGetOutputName=function(){return(l._OrtGetOutputName=l.asm.Wa).apply(null,arguments)},l._OrtFree=function(){return(l._OrtFree=l.asm.Xa).apply(null,arguments)},l._OrtCreateTensor=function(){return(l._OrtCreateTensor=l.asm.Ya).apply(null,arguments)},l._OrtGetTensorData=function(){return(l._OrtGetTensorData=l.asm.Za).apply(null,arguments)},l._OrtReleaseTensor=function(){return(l._OrtReleaseTensor=l.asm._a).apply(null,arguments)},l._OrtCreateRunOptions=function(){return(l._OrtCreateRunOptions=l.asm.$a).apply(null,arguments)},l._OrtAddRunConfigEntry=function(){return(l._OrtAddRunConfigEntry=l.asm.ab).apply(null,arguments)},l._OrtReleaseRunOptions=function(){return(l._OrtReleaseRunOptions=l.asm.bb).apply(null,arguments)},l._OrtRun=function(){return(l._OrtRun=l.asm.cb).apply(null,arguments)},l._OrtEndProfiling=function(){return(l._OrtEndProfiling=l.asm.db).apply(null,arguments)};var ke,be=l._malloc=function(){return(be=l._malloc=l.asm.eb).apply(null,arguments)},ge=l._free=function(){return(ge=l._free=l.asm.fb).apply(null,arguments)},X=l._fflush=function(){return(X=l._fflush=l.asm.gb).apply(null,arguments)},we=l.___funcs_on_exit=function(){return(we=l.___funcs_on_exit=l.asm.hb).apply(null,arguments)},ue=l._setThrew=function(){return(ue=l._setThrew=l.asm.jb).apply(null,arguments)},ve=l.stackSave=function(){return(ve=l.stackSave=l.asm.kb).apply(null,arguments)},ye=l.stackRestore=function(){return(ye=l.stackRestore=l.asm.lb).apply(null,arguments)},Ze=l.stackAlloc=function(){return(Ze=l.stackAlloc=l.asm.mb).apply(null,arguments)},Ke=l.___cxa_can_catch=function(){return(Ke=l.___cxa_can_catch=l.asm.nb).apply(null,arguments)},ct=l.___cxa_is_pointer_type=function(){return(ct=l.___cxa_is_pointer_type=l.asm.ob).apply(null,arguments)},dt=l.dynCall_j=function(){return(dt=l.dynCall_j=l.asm.pb).apply(null,arguments)},it=l.dynCall_iiiiij=function(){return(it=l.dynCall_iiiiij=l.asm.qb).apply(null,arguments)},pt=l.dynCall_jii=function(){return(pt=l.dynCall_jii=l.asm.rb).apply(null,arguments)},vt=l.dynCall_viiiiij=function(){return(vt=l.dynCall_viiiiij=l.asm.sb).apply(null,arguments)},Ot=l.dynCall_vjji=function(){return(Ot=l.dynCall_vjji=l.asm.tb).apply(null,arguments)},Nt=l.dynCall_viiijjjii=function(){return(Nt=l.dynCall_viiijjjii=l.asm.ub).apply(null,arguments)},Et=l.dynCall_iij=function(){return(Et=l.dynCall_iij=l.asm.vb).apply(null,arguments)},It=l.dynCall_ji=function(){return(It=l.dynCall_ji=l.asm.wb).apply(null,arguments)},Mt=l.dynCall_iiiiiij=function(){return(Mt=l.dynCall_iiiiiij=l.asm.xb).apply(null,arguments)},Rt=l.dynCall_iiij=function(){return(Rt=l.dynCall_iiij=l.asm.yb).apply(null,arguments)};function Lt(){function N(){if(!ke&&(ke=!0,l.calledRun=!0,!O)){if(qe(de),h(l),l.onRuntimeInitialized&&l.onRuntimeInitialized(),l.postRun)for(typeof l.postRun=="function"&&(l.postRun=[l.postRun]);l.postRun.length;){var j=l.postRun.shift();Ee.unshift(j)}qe(Ee)}}if(!(0{s.exports=function(e,t){for(var r=new Array(arguments.length-1),o=0,c=2,l=!0;c{var t=e;t.length=function(h){var p=h.length;if(!p)return 0;for(var f=0;--p%4>1&&h.charAt(p)==="=";)++f;return Math.ceil(3*h.length)/4-f};for(var r=new Array(64),o=new Array(123),c=0;c<64;)o[r[c]=c<26?c+65:c<52?c+71:c<62?c-4:c-59|43]=c++;t.encode=function(h,p,f){for(var d,i=null,n=[],a=0,u=0;p>2],d=(3&m)<<4,u=1;break;case 1:n[a++]=r[d|m>>4],d=(15&m)<<2,u=2;break;case 2:n[a++]=r[d|m>>6],n[a++]=r[63&m],u=0}a>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,n)),a=0)}return u&&(n[a++]=r[d],n[a++]=61,u===1&&(n[a++]=61)),i?(a&&i.push(String.fromCharCode.apply(String,n.slice(0,a))),i.join("")):String.fromCharCode.apply(String,n.slice(0,a))};var l="invalid encoding";t.decode=function(h,p,f){for(var d,i=f,n=0,a=0;a1)break;if((u=o[u])===void 0)throw Error(l);switch(n){case 0:d=u,n=1;break;case 1:p[f++]=d<<2|(48&u)>>4,d=u,n=2;break;case 2:p[f++]=(15&d)<<4|(60&u)>>2,d=u,n=3;break;case 3:p[f++]=(3&d)<<6|u,n=0}}if(n===1)throw Error(l);return f-i},t.test=function(h){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(h)}},9211:s=>{function e(){this._listeners={}}s.exports=e,e.prototype.on=function(t,r,o){return(this._listeners[t]||(this._listeners[t]=[])).push({fn:r,ctx:o||this}),this},e.prototype.off=function(t,r){if(t===void 0)this._listeners={};else if(r===void 0)this._listeners[t]=[];else for(var o=this._listeners[t],c=0;c{function e(l){return typeof Float32Array<"u"?function(){var h=new Float32Array([-0]),p=new Uint8Array(h.buffer),f=p[3]===128;function d(u,m,g){h[0]=u,m[g]=p[0],m[g+1]=p[1],m[g+2]=p[2],m[g+3]=p[3]}function i(u,m,g){h[0]=u,m[g]=p[3],m[g+1]=p[2],m[g+2]=p[1],m[g+3]=p[0]}function n(u,m){return p[0]=u[m],p[1]=u[m+1],p[2]=u[m+2],p[3]=u[m+3],h[0]}function a(u,m){return p[3]=u[m],p[2]=u[m+1],p[1]=u[m+2],p[0]=u[m+3],h[0]}l.writeFloatLE=f?d:i,l.writeFloatBE=f?i:d,l.readFloatLE=f?n:a,l.readFloatBE=f?a:n}():function(){function h(f,d,i,n){var a=d<0?1:0;if(a&&(d=-d),d===0)f(1/d>0?0:2147483648,i,n);else if(isNaN(d))f(2143289344,i,n);else if(d>34028234663852886e22)f((a<<31|2139095040)>>>0,i,n);else if(d<11754943508222875e-54)f((a<<31|Math.round(d/1401298464324817e-60))>>>0,i,n);else{var u=Math.floor(Math.log(d)/Math.LN2);f((a<<31|u+127<<23|8388607&Math.round(d*Math.pow(2,-u)*8388608))>>>0,i,n)}}function p(f,d,i){var n=f(d,i),a=2*(n>>31)+1,u=n>>>23&255,m=8388607&n;return u===255?m?NaN:a*(1/0):u===0?1401298464324817e-60*a*m:a*Math.pow(2,u-150)*(m+8388608)}l.writeFloatLE=h.bind(null,t),l.writeFloatBE=h.bind(null,r),l.readFloatLE=p.bind(null,o),l.readFloatBE=p.bind(null,c)}(),typeof Float64Array<"u"?function(){var h=new Float64Array([-0]),p=new Uint8Array(h.buffer),f=p[7]===128;function d(u,m,g){h[0]=u,m[g]=p[0],m[g+1]=p[1],m[g+2]=p[2],m[g+3]=p[3],m[g+4]=p[4],m[g+5]=p[5],m[g+6]=p[6],m[g+7]=p[7]}function i(u,m,g){h[0]=u,m[g]=p[7],m[g+1]=p[6],m[g+2]=p[5],m[g+3]=p[4],m[g+4]=p[3],m[g+5]=p[2],m[g+6]=p[1],m[g+7]=p[0]}function n(u,m){return p[0]=u[m],p[1]=u[m+1],p[2]=u[m+2],p[3]=u[m+3],p[4]=u[m+4],p[5]=u[m+5],p[6]=u[m+6],p[7]=u[m+7],h[0]}function a(u,m){return p[7]=u[m],p[6]=u[m+1],p[5]=u[m+2],p[4]=u[m+3],p[3]=u[m+4],p[2]=u[m+5],p[1]=u[m+6],p[0]=u[m+7],h[0]}l.writeDoubleLE=f?d:i,l.writeDoubleBE=f?i:d,l.readDoubleLE=f?n:a,l.readDoubleBE=f?a:n}():function(){function h(f,d,i,n,a,u){var m=n<0?1:0;if(m&&(n=-n),n===0)f(0,a,u+d),f(1/n>0?0:2147483648,a,u+i);else if(isNaN(n))f(0,a,u+d),f(2146959360,a,u+i);else if(n>17976931348623157e292)f(0,a,u+d),f((m<<31|2146435072)>>>0,a,u+i);else{var g;if(n<22250738585072014e-324)f((g=n/5e-324)>>>0,a,u+d),f((m<<31|g/4294967296)>>>0,a,u+i);else{var _=Math.floor(Math.log(n)/Math.LN2);_===1024&&(_=1023),f(4503599627370496*(g=n*Math.pow(2,-_))>>>0,a,u+d),f((m<<31|_+1023<<20|1048576*g&1048575)>>>0,a,u+i)}}}function p(f,d,i,n,a){var u=f(n,a+d),m=f(n,a+i),g=2*(m>>31)+1,_=m>>>20&2047,b=4294967296*(1048575&m)+u;return _===2047?b?NaN:g*(1/0):_===0?5e-324*g*b:g*Math.pow(2,_-1075)*(b+4503599627370496)}l.writeDoubleLE=h.bind(null,t,0,4),l.writeDoubleBE=h.bind(null,r,4,0),l.readDoubleLE=p.bind(null,o,0,4),l.readDoubleBE=p.bind(null,c,4,0)}(),l}function t(l,h,p){h[p]=255&l,h[p+1]=l>>>8&255,h[p+2]=l>>>16&255,h[p+3]=l>>>24}function r(l,h,p){h[p]=l>>>24,h[p+1]=l>>>16&255,h[p+2]=l>>>8&255,h[p+3]=255&l}function o(l,h){return(l[h]|l[h+1]<<8|l[h+2]<<16|l[h+3]<<24)>>>0}function c(l,h){return(l[h]<<24|l[h+1]<<16|l[h+2]<<8|l[h+3])>>>0}s.exports=e(e)},7199:module=>{function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(s){}return null}module.exports=inquire},6662:s=>{s.exports=function(e,t,r){var o=r||8192,c=o>>>1,l=null,h=o;return function(p){if(p<1||p>c)return e(p);h+p>o&&(l=e(o),h=0);var f=t.call(l,h,h+=p);return 7&h&&(h=1+(7|h)),f}}},4997:(s,e)=>{var t=e;t.length=function(r){for(var o=0,c=0,l=0;l191&&l<224?p[f++]=(31&l)<<6|63&r[o++]:l>239&&l<365?(l=((7&l)<<18|(63&r[o++])<<12|(63&r[o++])<<6|63&r[o++])-65536,p[f++]=55296+(l>>10),p[f++]=56320+(1023&l)):p[f++]=(15&l)<<12|(63&r[o++])<<6|63&r[o++],f>8191&&((h||(h=[])).push(String.fromCharCode.apply(String,p)),f=0);return h?(f&&h.push(String.fromCharCode.apply(String,p.slice(0,f))),h.join("")):String.fromCharCode.apply(String,p.slice(0,f))},t.write=function(r,o,c){for(var l,h,p=c,f=0;f>6|192,o[c++]=63&l|128):(64512&l)==55296&&(64512&(h=r.charCodeAt(f+1)))==56320?(l=65536+((1023&l)<<10)+(1023&h),++f,o[c++]=l>>18|240,o[c++]=l>>12&63|128,o[c++]=l>>6&63|128,o[c++]=63&l|128):(o[c++]=l>>12|224,o[c++]=l>>6&63|128,o[c++]=63&l|128);return c-p}},3442:(s,e)=>{e.__esModule=!0;var t=function(){function r(o){if(!o)throw new TypeError("Invalid argument; `value` has no value.");this.value=r.EMPTY,o&&r.isGuid(o)&&(this.value=o)}return r.isGuid=function(o){var c=o.toString();return o&&(o instanceof r||r.validator.test(c))},r.create=function(){return new r([r.gen(2),r.gen(1),r.gen(1),r.gen(1),r.gen(3)].join("-"))},r.createEmpty=function(){return new r("emptyguid")},r.parse=function(o){return new r(o)},r.raw=function(){return[r.gen(2),r.gen(1),r.gen(1),r.gen(1),r.gen(3)].join("-")},r.gen=function(o){for(var c="",l=0;l{s.exports=t;var e=null;try{e=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{}function t(T,E,R){this.low=0|T,this.high=0|E,this.unsigned=!!R}function r(T){return(T&&T.__isLong__)===!0}t.prototype.__isLong__,Object.defineProperty(t.prototype,"__isLong__",{value:!0}),t.isLong=r;var o={},c={};function l(T,E){var R,I,k;return E?(k=0<=(T>>>=0)&&T<256)&&(I=c[T])?I:(R=p(T,(0|T)<0?-1:0,!0),k&&(c[T]=R),R):(k=-128<=(T|=0)&&T<128)&&(I=o[T])?I:(R=p(T,T<0?-1:0,!1),k&&(o[T]=R),R)}function h(T,E){if(isNaN(T))return E?_:g;if(E){if(T<0)return _;if(T>=a)return w}else{if(T<=-u)return S;if(T+1>=u)return x}return T<0?h(-T,E).neg():p(T%n|0,T/n|0,E)}function p(T,E,R){return new t(T,E,R)}t.fromInt=l,t.fromNumber=h,t.fromBits=p;var f=Math.pow;function d(T,E,R){if(T.length===0)throw Error("empty string");if(T==="NaN"||T==="Infinity"||T==="+Infinity"||T==="-Infinity")return g;if(typeof E=="number"?(R=E,E=!1):E=!!E,(R=R||10)<2||360)throw Error("interior hyphen");if(I===0)return d(T.substring(1),E,R).neg();for(var k=h(f(R,8)),C=g,z=0;z>>0:this.low},M.toNumber=function(){return this.unsigned?(this.high>>>0)*n+(this.low>>>0):this.high*n+(this.low>>>0)},M.toString=function(T){if((T=T||10)<2||36>>0).toString(T);if((C=O).isZero())return U+z;for(;U.length<6;)U="0"+U;z=""+U+z}},M.getHighBits=function(){return this.high},M.getHighBitsUnsigned=function(){return this.high>>>0},M.getLowBits=function(){return this.low},M.getLowBitsUnsigned=function(){return this.low>>>0},M.getNumBitsAbs=function(){if(this.isNegative())return this.eq(S)?64:this.neg().getNumBitsAbs();for(var T=this.high!=0?this.high:this.low,E=31;E>0&&!(T&1<=0},M.isOdd=function(){return(1&this.low)==1},M.isEven=function(){return(1&this.low)==0},M.equals=function(T){return r(T)||(T=i(T)),(this.unsigned===T.unsigned||this.high>>>31!=1||T.high>>>31!=1)&&this.high===T.high&&this.low===T.low},M.eq=M.equals,M.notEquals=function(T){return!this.eq(T)},M.neq=M.notEquals,M.ne=M.notEquals,M.lessThan=function(T){return this.comp(T)<0},M.lt=M.lessThan,M.lessThanOrEqual=function(T){return this.comp(T)<=0},M.lte=M.lessThanOrEqual,M.le=M.lessThanOrEqual,M.greaterThan=function(T){return this.comp(T)>0},M.gt=M.greaterThan,M.greaterThanOrEqual=function(T){return this.comp(T)>=0},M.gte=M.greaterThanOrEqual,M.ge=M.greaterThanOrEqual,M.compare=function(T){if(r(T)||(T=i(T)),this.eq(T))return 0;var E=this.isNegative(),R=T.isNegative();return E&&!R?-1:!E&&R?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},M.comp=M.compare,M.negate=function(){return!this.unsigned&&this.eq(S)?S:this.not().add(b)},M.neg=M.negate,M.add=function(T){r(T)||(T=i(T));var E=this.high>>>16,R=65535&this.high,I=this.low>>>16,k=65535&this.low,C=T.high>>>16,z=65535&T.high,O=T.low>>>16,U=0,K=0,$=0,J=0;return $+=(J+=k+(65535&T.low))>>>16,K+=($+=I+O)>>>16,U+=(K+=R+z)>>>16,U+=E+C,p(($&=65535)<<16|(J&=65535),(U&=65535)<<16|(K&=65535),this.unsigned)},M.subtract=function(T){return r(T)||(T=i(T)),this.add(T.neg())},M.sub=M.subtract,M.multiply=function(T){if(this.isZero())return g;if(r(T)||(T=i(T)),e)return p(e.mul(this.low,this.high,T.low,T.high),e.get_high(),this.unsigned);if(T.isZero())return g;if(this.eq(S))return T.isOdd()?S:g;if(T.eq(S))return this.isOdd()?S:g;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(m)&&T.lt(m))return h(this.toNumber()*T.toNumber(),this.unsigned);var E=this.high>>>16,R=65535&this.high,I=this.low>>>16,k=65535&this.low,C=T.high>>>16,z=65535&T.high,O=T.low>>>16,U=65535&T.low,K=0,$=0,J=0,ee=0;return J+=(ee+=k*U)>>>16,$+=(J+=I*U)>>>16,J&=65535,$+=(J+=k*O)>>>16,K+=($+=R*U)>>>16,$&=65535,K+=($+=I*O)>>>16,$&=65535,K+=($+=k*z)>>>16,K+=E*U+R*O+I*z+k*C,p((J&=65535)<<16|(ee&=65535),(K&=65535)<<16|($&=65535),this.unsigned)},M.mul=M.multiply,M.divide=function(T){if(r(T)||(T=i(T)),T.isZero())throw Error("division by zero");var E,R,I;if(e)return this.unsigned||this.high!==-2147483648||T.low!==-1||T.high!==-1?p((this.unsigned?e.div_u:e.div_s)(this.low,this.high,T.low,T.high),e.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?_:g;if(this.unsigned){if(T.unsigned||(T=T.toUnsigned()),T.gt(this))return _;if(T.gt(this.shru(1)))return y;I=_}else{if(this.eq(S))return T.eq(b)||T.eq(v)?S:T.eq(S)?b:(E=this.shr(1).div(T).shl(1)).eq(g)?T.isNegative()?b:v:(R=this.sub(T.mul(E)),I=E.add(R.div(T)));if(T.eq(S))return this.unsigned?_:g;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();I=g}for(R=this;R.gte(T);){E=Math.max(1,Math.floor(R.toNumber()/T.toNumber()));for(var k=Math.ceil(Math.log(E)/Math.LN2),C=k<=48?1:f(2,k-48),z=h(E),O=z.mul(T);O.isNegative()||O.gt(R);)O=(z=h(E-=C,this.unsigned)).mul(T);z.isZero()&&(z=b),I=I.add(z),R=R.sub(O)}return I},M.div=M.divide,M.modulo=function(T){return r(T)||(T=i(T)),e?p((this.unsigned?e.rem_u:e.rem_s)(this.low,this.high,T.low,T.high),e.get_high(),this.unsigned):this.sub(this.div(T).mul(T))},M.mod=M.modulo,M.rem=M.modulo,M.not=function(){return p(~this.low,~this.high,this.unsigned)},M.and=function(T){return r(T)||(T=i(T)),p(this.low&T.low,this.high&T.high,this.unsigned)},M.or=function(T){return r(T)||(T=i(T)),p(this.low|T.low,this.high|T.high,this.unsigned)},M.xor=function(T){return r(T)||(T=i(T)),p(this.low^T.low,this.high^T.high,this.unsigned)},M.shiftLeft=function(T){return r(T)&&(T=T.toInt()),(T&=63)==0?this:T<32?p(this.low<>>32-T,this.unsigned):p(0,this.low<>>T|this.high<<32-T,this.high>>T,this.unsigned):p(this.high>>T-32,this.high>=0?0:-1,this.unsigned)},M.shr=M.shiftRight,M.shiftRightUnsigned=function(T){if(r(T)&&(T=T.toInt()),(T&=63)==0)return this;var E=this.high;return T<32?p(this.low>>>T|E<<32-T,E>>>T,this.unsigned):p(T===32?E:E>>>T-32,0,this.unsigned)},M.shru=M.shiftRightUnsigned,M.shr_u=M.shiftRightUnsigned,M.toSigned=function(){return this.unsigned?p(this.low,this.high,!1):this},M.toUnsigned=function(){return this.unsigned?this:p(this.low,this.high,!0)},M.toBytes=function(T){return T?this.toBytesLE():this.toBytesBE()},M.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]},M.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]},t.fromBytes=function(T,E,R){return R?t.fromBytesLE(T,E):t.fromBytesBE(T,E)},t.fromBytesLE=function(T,E){return new t(T[0]|T[1]<<8|T[2]<<16|T[3]<<24,T[4]|T[5]<<8|T[6]<<16|T[7]<<24,E)},t.fromBytesBE=function(T,E){return new t(T[4]<<24|T[5]<<16|T[6]<<8|T[7],T[0]<<24|T[1]<<16|T[2]<<8|T[3],E)}},1446:(s,e,t)=>{var r,o,c,l=t(2100),h=l.Reader,p=l.Writer,f=l.util,d=l.roots.default||(l.roots.default={});d.onnx=((c={}).Version=(r={},(o=Object.create(r))[r[0]="_START_VERSION"]=0,o[r[1]="IR_VERSION_2017_10_10"]=1,o[r[2]="IR_VERSION_2017_10_30"]=2,o[r[3]="IR_VERSION_2017_11_3"]=3,o[r[4]="IR_VERSION_2019_1_22"]=4,o[r[5]="IR_VERSION"]=5,o),c.AttributeProto=function(){function i(n){if(this.floats=[],this.ints=[],this.strings=[],this.tensors=[],this.graphs=[],n)for(var a=Object.keys(n),u=0;u>>3){case 1:m.name=n.string();break;case 21:m.refAttrName=n.string();break;case 13:m.docString=n.string();break;case 20:m.type=n.int32();break;case 2:m.f=n.float();break;case 3:m.i=n.int64();break;case 4:m.s=n.bytes();break;case 5:m.t=d.onnx.TensorProto.decode(n,n.uint32());break;case 6:m.g=d.onnx.GraphProto.decode(n,n.uint32());break;case 7:if(m.floats&&m.floats.length||(m.floats=[]),(7&g)==2)for(var _=n.uint32()+n.pos;n.pos<_;)m.floats.push(n.float());else m.floats.push(n.float());break;case 8:if(m.ints&&m.ints.length||(m.ints=[]),(7&g)==2)for(_=n.uint32()+n.pos;n.pos<_;)m.ints.push(n.int64());else m.ints.push(n.int64());break;case 9:m.strings&&m.strings.length||(m.strings=[]),m.strings.push(n.bytes());break;case 10:m.tensors&&m.tensors.length||(m.tensors=[]),m.tensors.push(d.onnx.TensorProto.decode(n,n.uint32()));break;case 11:m.graphs&&m.graphs.length||(m.graphs=[]),m.graphs.push(d.onnx.GraphProto.decode(n,n.uint32()));break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){if(typeof n!="object"||n===null)return"object expected";if(n.name!=null&&n.hasOwnProperty("name")&&!f.isString(n.name))return"name: string expected";if(n.refAttrName!=null&&n.hasOwnProperty("refAttrName")&&!f.isString(n.refAttrName))return"refAttrName: string expected";if(n.docString!=null&&n.hasOwnProperty("docString")&&!f.isString(n.docString))return"docString: string expected";if(n.type!=null&&n.hasOwnProperty("type"))switch(n.type){default:return"type: enum value expected";case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:case 10:}if(n.f!=null&&n.hasOwnProperty("f")&&typeof n.f!="number")return"f: number expected";if(n.i!=null&&n.hasOwnProperty("i")&&!(f.isInteger(n.i)||n.i&&f.isInteger(n.i.low)&&f.isInteger(n.i.high)))return"i: integer|Long expected";if(n.s!=null&&n.hasOwnProperty("s")&&!(n.s&&typeof n.s.length=="number"||f.isString(n.s)))return"s: buffer expected";if(n.t!=null&&n.hasOwnProperty("t")&&(u=d.onnx.TensorProto.verify(n.t)))return"t."+u;if(n.g!=null&&n.hasOwnProperty("g")&&(u=d.onnx.GraphProto.verify(n.g)))return"g."+u;if(n.floats!=null&&n.hasOwnProperty("floats")){if(!Array.isArray(n.floats))return"floats: array expected";for(var a=0;a>>0,n.i.high>>>0).toNumber())),n.s!=null&&(typeof n.s=="string"?f.base64.decode(n.s,a.s=f.newBuffer(f.base64.length(n.s)),0):n.s.length&&(a.s=n.s)),n.t!=null){if(typeof n.t!="object")throw TypeError(".onnx.AttributeProto.t: object expected");a.t=d.onnx.TensorProto.fromObject(n.t)}if(n.g!=null){if(typeof n.g!="object")throw TypeError(".onnx.AttributeProto.g: object expected");a.g=d.onnx.GraphProto.fromObject(n.g)}if(n.floats){if(!Array.isArray(n.floats))throw TypeError(".onnx.AttributeProto.floats: array expected");a.floats=[];for(var u=0;u>>0,n.ints[u].high>>>0).toNumber())}if(n.strings){if(!Array.isArray(n.strings))throw TypeError(".onnx.AttributeProto.strings: array expected");for(a.strings=[],u=0;u>>0,n.i.high>>>0).toNumber():n.i),n.s!=null&&n.hasOwnProperty("s")&&(u.s=a.bytes===String?f.base64.encode(n.s,0,n.s.length):a.bytes===Array?Array.prototype.slice.call(n.s):n.s),n.t!=null&&n.hasOwnProperty("t")&&(u.t=d.onnx.TensorProto.toObject(n.t,a)),n.g!=null&&n.hasOwnProperty("g")&&(u.g=d.onnx.GraphProto.toObject(n.g,a)),n.floats&&n.floats.length){u.floats=[];for(var g=0;g>>0,n.ints[g].high>>>0).toNumber():n.ints[g];if(n.strings&&n.strings.length)for(u.strings=[],g=0;g>>3){case 1:m.name=n.string();break;case 2:m.type=d.onnx.TypeProto.decode(n,n.uint32());break;case 3:m.docString=n.string();break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){if(typeof n!="object"||n===null)return"object expected";if(n.name!=null&&n.hasOwnProperty("name")&&!f.isString(n.name))return"name: string expected";if(n.type!=null&&n.hasOwnProperty("type")){var a=d.onnx.TypeProto.verify(n.type);if(a)return"type."+a}return n.docString!=null&&n.hasOwnProperty("docString")&&!f.isString(n.docString)?"docString: string expected":null},i.fromObject=function(n){if(n instanceof d.onnx.ValueInfoProto)return n;var a=new d.onnx.ValueInfoProto;if(n.name!=null&&(a.name=String(n.name)),n.type!=null){if(typeof n.type!="object")throw TypeError(".onnx.ValueInfoProto.type: object expected");a.type=d.onnx.TypeProto.fromObject(n.type)}return n.docString!=null&&(a.docString=String(n.docString)),a},i.toObject=function(n,a){a||(a={});var u={};return a.defaults&&(u.name="",u.type=null,u.docString=""),n.name!=null&&n.hasOwnProperty("name")&&(u.name=n.name),n.type!=null&&n.hasOwnProperty("type")&&(u.type=d.onnx.TypeProto.toObject(n.type,a)),n.docString!=null&&n.hasOwnProperty("docString")&&(u.docString=n.docString),u},i.prototype.toJSON=function(){return this.constructor.toObject(this,l.util.toJSONOptions)},i}(),c.NodeProto=function(){function i(n){if(this.input=[],this.output=[],this.attribute=[],n)for(var a=Object.keys(n),u=0;u>>3){case 1:m.input&&m.input.length||(m.input=[]),m.input.push(n.string());break;case 2:m.output&&m.output.length||(m.output=[]),m.output.push(n.string());break;case 3:m.name=n.string();break;case 4:m.opType=n.string();break;case 7:m.domain=n.string();break;case 5:m.attribute&&m.attribute.length||(m.attribute=[]),m.attribute.push(d.onnx.AttributeProto.decode(n,n.uint32()));break;case 6:m.docString=n.string();break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){if(typeof n!="object"||n===null)return"object expected";if(n.input!=null&&n.hasOwnProperty("input")){if(!Array.isArray(n.input))return"input: array expected";for(var a=0;a>>3){case 1:m.irVersion=n.int64();break;case 8:m.opsetImport&&m.opsetImport.length||(m.opsetImport=[]),m.opsetImport.push(d.onnx.OperatorSetIdProto.decode(n,n.uint32()));break;case 2:m.producerName=n.string();break;case 3:m.producerVersion=n.string();break;case 4:m.domain=n.string();break;case 5:m.modelVersion=n.int64();break;case 6:m.docString=n.string();break;case 7:m.graph=d.onnx.GraphProto.decode(n,n.uint32());break;case 14:m.metadataProps&&m.metadataProps.length||(m.metadataProps=[]),m.metadataProps.push(d.onnx.StringStringEntryProto.decode(n,n.uint32()));break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){if(typeof n!="object"||n===null)return"object expected";if(n.irVersion!=null&&n.hasOwnProperty("irVersion")&&!(f.isInteger(n.irVersion)||n.irVersion&&f.isInteger(n.irVersion.low)&&f.isInteger(n.irVersion.high)))return"irVersion: integer|Long expected";if(n.opsetImport!=null&&n.hasOwnProperty("opsetImport")){if(!Array.isArray(n.opsetImport))return"opsetImport: array expected";for(var a=0;a>>0,n.irVersion.high>>>0).toNumber())),n.opsetImport){if(!Array.isArray(n.opsetImport))throw TypeError(".onnx.ModelProto.opsetImport: array expected");a.opsetImport=[];for(var u=0;u>>0,n.modelVersion.high>>>0).toNumber())),n.docString!=null&&(a.docString=String(n.docString)),n.graph!=null){if(typeof n.graph!="object")throw TypeError(".onnx.ModelProto.graph: object expected");a.graph=d.onnx.GraphProto.fromObject(n.graph)}if(n.metadataProps){if(!Array.isArray(n.metadataProps))throw TypeError(".onnx.ModelProto.metadataProps: array expected");for(a.metadataProps=[],u=0;u>>0,n.irVersion.high>>>0).toNumber():n.irVersion),n.producerName!=null&&n.hasOwnProperty("producerName")&&(u.producerName=n.producerName),n.producerVersion!=null&&n.hasOwnProperty("producerVersion")&&(u.producerVersion=n.producerVersion),n.domain!=null&&n.hasOwnProperty("domain")&&(u.domain=n.domain),n.modelVersion!=null&&n.hasOwnProperty("modelVersion")&&(typeof n.modelVersion=="number"?u.modelVersion=a.longs===String?String(n.modelVersion):n.modelVersion:u.modelVersion=a.longs===String?f.Long.prototype.toString.call(n.modelVersion):a.longs===Number?new f.LongBits(n.modelVersion.low>>>0,n.modelVersion.high>>>0).toNumber():n.modelVersion),n.docString!=null&&n.hasOwnProperty("docString")&&(u.docString=n.docString),n.graph!=null&&n.hasOwnProperty("graph")&&(u.graph=d.onnx.GraphProto.toObject(n.graph,a)),n.opsetImport&&n.opsetImport.length){u.opsetImport=[];for(var g=0;g>>3){case 1:m.key=n.string();break;case 2:m.value=n.string();break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){return typeof n!="object"||n===null?"object expected":n.key!=null&&n.hasOwnProperty("key")&&!f.isString(n.key)?"key: string expected":n.value!=null&&n.hasOwnProperty("value")&&!f.isString(n.value)?"value: string expected":null},i.fromObject=function(n){if(n instanceof d.onnx.StringStringEntryProto)return n;var a=new d.onnx.StringStringEntryProto;return n.key!=null&&(a.key=String(n.key)),n.value!=null&&(a.value=String(n.value)),a},i.toObject=function(n,a){a||(a={});var u={};return a.defaults&&(u.key="",u.value=""),n.key!=null&&n.hasOwnProperty("key")&&(u.key=n.key),n.value!=null&&n.hasOwnProperty("value")&&(u.value=n.value),u},i.prototype.toJSON=function(){return this.constructor.toObject(this,l.util.toJSONOptions)},i}(),c.TensorAnnotation=function(){function i(n){if(this.quantParameterTensorNames=[],n)for(var a=Object.keys(n),u=0;u>>3){case 1:m.tensorName=n.string();break;case 2:m.quantParameterTensorNames&&m.quantParameterTensorNames.length||(m.quantParameterTensorNames=[]),m.quantParameterTensorNames.push(d.onnx.StringStringEntryProto.decode(n,n.uint32()));break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){if(typeof n!="object"||n===null)return"object expected";if(n.tensorName!=null&&n.hasOwnProperty("tensorName")&&!f.isString(n.tensorName))return"tensorName: string expected";if(n.quantParameterTensorNames!=null&&n.hasOwnProperty("quantParameterTensorNames")){if(!Array.isArray(n.quantParameterTensorNames))return"quantParameterTensorNames: array expected";for(var a=0;a>>3){case 1:m.node&&m.node.length||(m.node=[]),m.node.push(d.onnx.NodeProto.decode(n,n.uint32()));break;case 2:m.name=n.string();break;case 5:m.initializer&&m.initializer.length||(m.initializer=[]),m.initializer.push(d.onnx.TensorProto.decode(n,n.uint32()));break;case 10:m.docString=n.string();break;case 11:m.input&&m.input.length||(m.input=[]),m.input.push(d.onnx.ValueInfoProto.decode(n,n.uint32()));break;case 12:m.output&&m.output.length||(m.output=[]),m.output.push(d.onnx.ValueInfoProto.decode(n,n.uint32()));break;case 13:m.valueInfo&&m.valueInfo.length||(m.valueInfo=[]),m.valueInfo.push(d.onnx.ValueInfoProto.decode(n,n.uint32()));break;case 14:m.quantizationAnnotation&&m.quantizationAnnotation.length||(m.quantizationAnnotation=[]),m.quantizationAnnotation.push(d.onnx.TensorAnnotation.decode(n,n.uint32()));break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){if(typeof n!="object"||n===null)return"object expected";if(n.node!=null&&n.hasOwnProperty("node")){if(!Array.isArray(n.node))return"node: array expected";for(var a=0;a>>3){case 1:if(m.dims&&m.dims.length||(m.dims=[]),(7&g)==2)for(var _=n.uint32()+n.pos;n.pos<_;)m.dims.push(n.int64());else m.dims.push(n.int64());break;case 2:m.dataType=n.int32();break;case 3:m.segment=d.onnx.TensorProto.Segment.decode(n,n.uint32());break;case 4:if(m.floatData&&m.floatData.length||(m.floatData=[]),(7&g)==2)for(_=n.uint32()+n.pos;n.pos<_;)m.floatData.push(n.float());else m.floatData.push(n.float());break;case 5:if(m.int32Data&&m.int32Data.length||(m.int32Data=[]),(7&g)==2)for(_=n.uint32()+n.pos;n.pos<_;)m.int32Data.push(n.int32());else m.int32Data.push(n.int32());break;case 6:m.stringData&&m.stringData.length||(m.stringData=[]),m.stringData.push(n.bytes());break;case 7:if(m.int64Data&&m.int64Data.length||(m.int64Data=[]),(7&g)==2)for(_=n.uint32()+n.pos;n.pos<_;)m.int64Data.push(n.int64());else m.int64Data.push(n.int64());break;case 8:m.name=n.string();break;case 12:m.docString=n.string();break;case 9:m.rawData=n.bytes();break;case 13:m.externalData&&m.externalData.length||(m.externalData=[]),m.externalData.push(d.onnx.StringStringEntryProto.decode(n,n.uint32()));break;case 14:m.dataLocation=n.int32();break;case 10:if(m.doubleData&&m.doubleData.length||(m.doubleData=[]),(7&g)==2)for(_=n.uint32()+n.pos;n.pos<_;)m.doubleData.push(n.double());else m.doubleData.push(n.double());break;case 11:if(m.uint64Data&&m.uint64Data.length||(m.uint64Data=[]),(7&g)==2)for(_=n.uint32()+n.pos;n.pos<_;)m.uint64Data.push(n.uint64());else m.uint64Data.push(n.uint64());break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){if(typeof n!="object"||n===null)return"object expected";if(n.dims!=null&&n.hasOwnProperty("dims")){if(!Array.isArray(n.dims))return"dims: array expected";for(var a=0;a>>0,n.dims[u].high>>>0).toNumber())}if(n.dataType!=null&&(a.dataType=0|n.dataType),n.segment!=null){if(typeof n.segment!="object")throw TypeError(".onnx.TensorProto.segment: object expected");a.segment=d.onnx.TensorProto.Segment.fromObject(n.segment)}if(n.floatData){if(!Array.isArray(n.floatData))throw TypeError(".onnx.TensorProto.floatData: array expected");for(a.floatData=[],u=0;u>>0,n.int64Data[u].high>>>0).toNumber())}if(n.name!=null&&(a.name=String(n.name)),n.docString!=null&&(a.docString=String(n.docString)),n.rawData!=null&&(typeof n.rawData=="string"?f.base64.decode(n.rawData,a.rawData=f.newBuffer(f.base64.length(n.rawData)),0):n.rawData.length&&(a.rawData=n.rawData)),n.externalData){if(!Array.isArray(n.externalData))throw TypeError(".onnx.TensorProto.externalData: array expected");for(a.externalData=[],u=0;u>>0,n.uint64Data[u].high>>>0).toNumber(!0))}return a},i.toObject=function(n,a){a||(a={});var u={};if((a.arrays||a.defaults)&&(u.dims=[],u.floatData=[],u.int32Data=[],u.stringData=[],u.int64Data=[],u.doubleData=[],u.uint64Data=[],u.externalData=[]),a.defaults&&(u.dataType=0,u.segment=null,u.name="",a.bytes===String?u.rawData="":(u.rawData=[],a.bytes!==Array&&(u.rawData=f.newBuffer(u.rawData))),u.docString="",u.dataLocation=a.enums===String?"DEFAULT":0),n.dims&&n.dims.length){u.dims=[];for(var m=0;m>>0,n.dims[m].high>>>0).toNumber():n.dims[m]}if(n.dataType!=null&&n.hasOwnProperty("dataType")&&(u.dataType=n.dataType),n.segment!=null&&n.hasOwnProperty("segment")&&(u.segment=d.onnx.TensorProto.Segment.toObject(n.segment,a)),n.floatData&&n.floatData.length)for(u.floatData=[],m=0;m>>0,n.int64Data[m].high>>>0).toNumber():n.int64Data[m];if(n.name!=null&&n.hasOwnProperty("name")&&(u.name=n.name),n.rawData!=null&&n.hasOwnProperty("rawData")&&(u.rawData=a.bytes===String?f.base64.encode(n.rawData,0,n.rawData.length):a.bytes===Array?Array.prototype.slice.call(n.rawData):n.rawData),n.doubleData&&n.doubleData.length)for(u.doubleData=[],m=0;m>>0,n.uint64Data[m].high>>>0).toNumber(!0):n.uint64Data[m];if(n.docString!=null&&n.hasOwnProperty("docString")&&(u.docString=n.docString),n.externalData&&n.externalData.length)for(u.externalData=[],m=0;m>>3){case 1:g.begin=a.int64();break;case 2:g.end=a.int64();break;default:a.skipType(7&_)}}return g},n.decodeDelimited=function(a){return a instanceof h||(a=new h(a)),this.decode(a,a.uint32())},n.verify=function(a){return typeof a!="object"||a===null?"object expected":a.begin!=null&&a.hasOwnProperty("begin")&&!(f.isInteger(a.begin)||a.begin&&f.isInteger(a.begin.low)&&f.isInteger(a.begin.high))?"begin: integer|Long expected":a.end!=null&&a.hasOwnProperty("end")&&!(f.isInteger(a.end)||a.end&&f.isInteger(a.end.low)&&f.isInteger(a.end.high))?"end: integer|Long expected":null},n.fromObject=function(a){if(a instanceof d.onnx.TensorProto.Segment)return a;var u=new d.onnx.TensorProto.Segment;return a.begin!=null&&(f.Long?(u.begin=f.Long.fromValue(a.begin)).unsigned=!1:typeof a.begin=="string"?u.begin=parseInt(a.begin,10):typeof a.begin=="number"?u.begin=a.begin:typeof a.begin=="object"&&(u.begin=new f.LongBits(a.begin.low>>>0,a.begin.high>>>0).toNumber())),a.end!=null&&(f.Long?(u.end=f.Long.fromValue(a.end)).unsigned=!1:typeof a.end=="string"?u.end=parseInt(a.end,10):typeof a.end=="number"?u.end=a.end:typeof a.end=="object"&&(u.end=new f.LongBits(a.end.low>>>0,a.end.high>>>0).toNumber())),u},n.toObject=function(a,u){u||(u={});var m={};if(u.defaults){if(f.Long){var g=new f.Long(0,0,!1);m.begin=u.longs===String?g.toString():u.longs===Number?g.toNumber():g}else m.begin=u.longs===String?"0":0;f.Long?(g=new f.Long(0,0,!1),m.end=u.longs===String?g.toString():u.longs===Number?g.toNumber():g):m.end=u.longs===String?"0":0}return a.begin!=null&&a.hasOwnProperty("begin")&&(typeof a.begin=="number"?m.begin=u.longs===String?String(a.begin):a.begin:m.begin=u.longs===String?f.Long.prototype.toString.call(a.begin):u.longs===Number?new f.LongBits(a.begin.low>>>0,a.begin.high>>>0).toNumber():a.begin),a.end!=null&&a.hasOwnProperty("end")&&(typeof a.end=="number"?m.end=u.longs===String?String(a.end):a.end:m.end=u.longs===String?f.Long.prototype.toString.call(a.end):u.longs===Number?new f.LongBits(a.end.low>>>0,a.end.high>>>0).toNumber():a.end),m},n.prototype.toJSON=function(){return this.constructor.toObject(this,l.util.toJSONOptions)},n}(),i.DataLocation=function(){var n={},a=Object.create(n);return a[n[0]="DEFAULT"]=0,a[n[1]="EXTERNAL"]=1,a}(),i}(),c.TensorShapeProto=function(){function i(n){if(this.dim=[],n)for(var a=Object.keys(n),u=0;u>>3==1?(m.dim&&m.dim.length||(m.dim=[]),m.dim.push(d.onnx.TensorShapeProto.Dimension.decode(n,n.uint32()))):n.skipType(7&g)}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){if(typeof n!="object"||n===null)return"object expected";if(n.dim!=null&&n.hasOwnProperty("dim")){if(!Array.isArray(n.dim))return"dim: array expected";for(var a=0;a>>3){case 1:_.dimValue=u.int64();break;case 2:_.dimParam=u.string();break;case 3:_.denotation=u.string();break;default:u.skipType(7&b)}}return _},n.decodeDelimited=function(u){return u instanceof h||(u=new h(u)),this.decode(u,u.uint32())},n.verify=function(u){if(typeof u!="object"||u===null)return"object expected";var m={};if(u.dimValue!=null&&u.hasOwnProperty("dimValue")&&(m.value=1,!(f.isInteger(u.dimValue)||u.dimValue&&f.isInteger(u.dimValue.low)&&f.isInteger(u.dimValue.high))))return"dimValue: integer|Long expected";if(u.dimParam!=null&&u.hasOwnProperty("dimParam")){if(m.value===1)return"value: multiple values";if(m.value=1,!f.isString(u.dimParam))return"dimParam: string expected"}return u.denotation!=null&&u.hasOwnProperty("denotation")&&!f.isString(u.denotation)?"denotation: string expected":null},n.fromObject=function(u){if(u instanceof d.onnx.TensorShapeProto.Dimension)return u;var m=new d.onnx.TensorShapeProto.Dimension;return u.dimValue!=null&&(f.Long?(m.dimValue=f.Long.fromValue(u.dimValue)).unsigned=!1:typeof u.dimValue=="string"?m.dimValue=parseInt(u.dimValue,10):typeof u.dimValue=="number"?m.dimValue=u.dimValue:typeof u.dimValue=="object"&&(m.dimValue=new f.LongBits(u.dimValue.low>>>0,u.dimValue.high>>>0).toNumber())),u.dimParam!=null&&(m.dimParam=String(u.dimParam)),u.denotation!=null&&(m.denotation=String(u.denotation)),m},n.toObject=function(u,m){m||(m={});var g={};return m.defaults&&(g.denotation=""),u.dimValue!=null&&u.hasOwnProperty("dimValue")&&(typeof u.dimValue=="number"?g.dimValue=m.longs===String?String(u.dimValue):u.dimValue:g.dimValue=m.longs===String?f.Long.prototype.toString.call(u.dimValue):m.longs===Number?new f.LongBits(u.dimValue.low>>>0,u.dimValue.high>>>0).toNumber():u.dimValue,m.oneofs&&(g.value="dimValue")),u.dimParam!=null&&u.hasOwnProperty("dimParam")&&(g.dimParam=u.dimParam,m.oneofs&&(g.value="dimParam")),u.denotation!=null&&u.hasOwnProperty("denotation")&&(g.denotation=u.denotation),g},n.prototype.toJSON=function(){return this.constructor.toObject(this,l.util.toJSONOptions)},n}(),i}(),c.TypeProto=function(){function i(a){if(a)for(var u=Object.keys(a),m=0;m>>3){case 1:g.tensorType=d.onnx.TypeProto.Tensor.decode(a,a.uint32());break;case 6:g.denotation=a.string();break;default:a.skipType(7&_)}}return g},i.decodeDelimited=function(a){return a instanceof h||(a=new h(a)),this.decode(a,a.uint32())},i.verify=function(a){if(typeof a!="object"||a===null)return"object expected";if(a.tensorType!=null&&a.hasOwnProperty("tensorType")){var u=d.onnx.TypeProto.Tensor.verify(a.tensorType);if(u)return"tensorType."+u}return a.denotation!=null&&a.hasOwnProperty("denotation")&&!f.isString(a.denotation)?"denotation: string expected":null},i.fromObject=function(a){if(a instanceof d.onnx.TypeProto)return a;var u=new d.onnx.TypeProto;if(a.tensorType!=null){if(typeof a.tensorType!="object")throw TypeError(".onnx.TypeProto.tensorType: object expected");u.tensorType=d.onnx.TypeProto.Tensor.fromObject(a.tensorType)}return a.denotation!=null&&(u.denotation=String(a.denotation)),u},i.toObject=function(a,u){u||(u={});var m={};return u.defaults&&(m.denotation=""),a.tensorType!=null&&a.hasOwnProperty("tensorType")&&(m.tensorType=d.onnx.TypeProto.Tensor.toObject(a.tensorType,u),u.oneofs&&(m.value="tensorType")),a.denotation!=null&&a.hasOwnProperty("denotation")&&(m.denotation=a.denotation),m},i.prototype.toJSON=function(){return this.constructor.toObject(this,l.util.toJSONOptions)},i.Tensor=function(){function a(u){if(u)for(var m=Object.keys(u),g=0;g>>3){case 1:_.elemType=u.int32();break;case 2:_.shape=d.onnx.TensorShapeProto.decode(u,u.uint32());break;default:u.skipType(7&b)}}return _},a.decodeDelimited=function(u){return u instanceof h||(u=new h(u)),this.decode(u,u.uint32())},a.verify=function(u){if(typeof u!="object"||u===null)return"object expected";if(u.elemType!=null&&u.hasOwnProperty("elemType")&&!f.isInteger(u.elemType))return"elemType: integer expected";if(u.shape!=null&&u.hasOwnProperty("shape")){var m=d.onnx.TensorShapeProto.verify(u.shape);if(m)return"shape."+m}return null},a.fromObject=function(u){if(u instanceof d.onnx.TypeProto.Tensor)return u;var m=new d.onnx.TypeProto.Tensor;if(u.elemType!=null&&(m.elemType=0|u.elemType),u.shape!=null){if(typeof u.shape!="object")throw TypeError(".onnx.TypeProto.Tensor.shape: object expected");m.shape=d.onnx.TensorShapeProto.fromObject(u.shape)}return m},a.toObject=function(u,m){m||(m={});var g={};return m.defaults&&(g.elemType=0,g.shape=null),u.elemType!=null&&u.hasOwnProperty("elemType")&&(g.elemType=u.elemType),u.shape!=null&&u.hasOwnProperty("shape")&&(g.shape=d.onnx.TensorShapeProto.toObject(u.shape,m)),g},a.prototype.toJSON=function(){return this.constructor.toObject(this,l.util.toJSONOptions)},a}(),i}(),c.OperatorSetIdProto=function(){function i(n){if(n)for(var a=Object.keys(n),u=0;u>>3){case 1:m.domain=n.string();break;case 2:m.version=n.int64();break;default:n.skipType(7&g)}}return m},i.decodeDelimited=function(n){return n instanceof h||(n=new h(n)),this.decode(n,n.uint32())},i.verify=function(n){return typeof n!="object"||n===null?"object expected":n.domain!=null&&n.hasOwnProperty("domain")&&!f.isString(n.domain)?"domain: string expected":n.version!=null&&n.hasOwnProperty("version")&&!(f.isInteger(n.version)||n.version&&f.isInteger(n.version.low)&&f.isInteger(n.version.high))?"version: integer|Long expected":null},i.fromObject=function(n){if(n instanceof d.onnx.OperatorSetIdProto)return n;var a=new d.onnx.OperatorSetIdProto;return n.domain!=null&&(a.domain=String(n.domain)),n.version!=null&&(f.Long?(a.version=f.Long.fromValue(n.version)).unsigned=!1:typeof n.version=="string"?a.version=parseInt(n.version,10):typeof n.version=="number"?a.version=n.version:typeof n.version=="object"&&(a.version=new f.LongBits(n.version.low>>>0,n.version.high>>>0).toNumber())),a},i.toObject=function(n,a){a||(a={});var u={};if(a.defaults)if(u.domain="",f.Long){var m=new f.Long(0,0,!1);u.version=a.longs===String?m.toString():a.longs===Number?m.toNumber():m}else u.version=a.longs===String?"0":0;return n.domain!=null&&n.hasOwnProperty("domain")&&(u.domain=n.domain),n.version!=null&&n.hasOwnProperty("version")&&(typeof n.version=="number"?u.version=a.longs===String?String(n.version):n.version:u.version=a.longs===String?f.Long.prototype.toString.call(n.version):a.longs===Number?new f.LongBits(n.version.low>>>0,n.version.high>>>0).toNumber():n.version),u},i.prototype.toJSON=function(){return this.constructor.toObject(this,l.util.toJSONOptions)},i}(),c),s.exports=d},2100:(s,e,t)=>{s.exports=t(9482)},9482:(s,e,t)=>{var r=e;function o(){r.util._configure(),r.Writer._configure(r.BufferWriter),r.Reader._configure(r.BufferReader)}r.build="minimal",r.Writer=t(1173),r.BufferWriter=t(3155),r.Reader=t(1408),r.BufferReader=t(593),r.util=t(9693),r.rpc=t(5994),r.roots=t(5054),r.configure=o,o()},1408:(s,e,t)=>{s.exports=p;var r,o=t(9693),c=o.LongBits,l=o.utf8;function h(m,g){return RangeError("index out of range: "+m.pos+" + "+(g||1)+" > "+m.len)}function p(m){this.buf=m,this.pos=0,this.len=m.length}var f,d=typeof Uint8Array<"u"?function(m){if(m instanceof Uint8Array||Array.isArray(m))return new p(m);throw Error("illegal buffer")}:function(m){if(Array.isArray(m))return new p(m);throw Error("illegal buffer")},i=function(){return o.Buffer?function(m){return(p.create=function(g){return o.Buffer.isBuffer(g)?new r(g):d(g)})(m)}:d};function n(){var m=new c(0,0),g=0;if(!(this.len-this.pos>4)){for(;g<3;++g){if(this.pos>=this.len)throw h(this);if(m.lo=(m.lo|(127&this.buf[this.pos])<<7*g)>>>0,this.buf[this.pos++]<128)return m}return m.lo=(m.lo|(127&this.buf[this.pos++])<<7*g)>>>0,m}for(;g<4;++g)if(m.lo=(m.lo|(127&this.buf[this.pos])<<7*g)>>>0,this.buf[this.pos++]<128)return m;if(m.lo=(m.lo|(127&this.buf[this.pos])<<28)>>>0,m.hi=(m.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return m;if(g=0,this.len-this.pos>4){for(;g<5;++g)if(m.hi=(m.hi|(127&this.buf[this.pos])<<7*g+3)>>>0,this.buf[this.pos++]<128)return m}else for(;g<5;++g){if(this.pos>=this.len)throw h(this);if(m.hi=(m.hi|(127&this.buf[this.pos])<<7*g+3)>>>0,this.buf[this.pos++]<128)return m}throw Error("invalid varint encoding")}function a(m,g){return(m[g-4]|m[g-3]<<8|m[g-2]<<16|m[g-1]<<24)>>>0}function u(){if(this.pos+8>this.len)throw h(this,8);return new c(a(this.buf,this.pos+=4),a(this.buf,this.pos+=4))}p.create=i(),p.prototype._slice=o.Array.prototype.subarray||o.Array.prototype.slice,p.prototype.uint32=(f=4294967295,function(){if(f=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128||(f=(f|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)||(f=(f|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)||(f=(f|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)||(f=(f|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128))return f;if((this.pos+=5)>this.len)throw this.pos=this.len,h(this,10);return f}),p.prototype.int32=function(){return 0|this.uint32()},p.prototype.sint32=function(){var m=this.uint32();return m>>>1^-(1&m)|0},p.prototype.bool=function(){return this.uint32()!==0},p.prototype.fixed32=function(){if(this.pos+4>this.len)throw h(this,4);return a(this.buf,this.pos+=4)},p.prototype.sfixed32=function(){if(this.pos+4>this.len)throw h(this,4);return 0|a(this.buf,this.pos+=4)},p.prototype.float=function(){if(this.pos+4>this.len)throw h(this,4);var m=o.float.readFloatLE(this.buf,this.pos);return this.pos+=4,m},p.prototype.double=function(){if(this.pos+8>this.len)throw h(this,4);var m=o.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,m},p.prototype.bytes=function(){var m=this.uint32(),g=this.pos,_=this.pos+m;if(_>this.len)throw h(this,m);return this.pos+=m,Array.isArray(this.buf)?this.buf.slice(g,_):g===_?new this.buf.constructor(0):this._slice.call(this.buf,g,_)},p.prototype.string=function(){var m=this.bytes();return l.read(m,0,m.length)},p.prototype.skip=function(m){if(typeof m=="number"){if(this.pos+m>this.len)throw h(this,m);this.pos+=m}else do if(this.pos>=this.len)throw h(this);while(128&this.buf[this.pos++]);return this},p.prototype.skipType=function(m){switch(m){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(m=7&this.uint32())!=4;)this.skipType(m);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+m+" at offset "+this.pos)}return this},p._configure=function(m){r=m,p.create=i(),r._configure();var g=o.Long?"toLong":"toNumber";o.merge(p.prototype,{int64:function(){return n.call(this)[g](!1)},uint64:function(){return n.call(this)[g](!0)},sint64:function(){return n.call(this).zzDecode()[g](!1)},fixed64:function(){return u.call(this)[g](!0)},sfixed64:function(){return u.call(this)[g](!1)}})}},593:(s,e,t)=>{s.exports=c;var r=t(1408);(c.prototype=Object.create(r.prototype)).constructor=c;var o=t(9693);function c(l){r.call(this,l)}c._configure=function(){o.Buffer&&(c.prototype._slice=o.Buffer.prototype.slice)},c.prototype.string=function(){var l=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+l,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+l,this.len))},c._configure()},5054:s=>{s.exports={}},5994:(s,e,t)=>{e.Service=t(7948)},7948:(s,e,t)=>{s.exports=o;var r=t(9693);function o(c,l,h){if(typeof c!="function")throw TypeError("rpcImpl must be a function");r.EventEmitter.call(this),this.rpcImpl=c,this.requestDelimited=!!l,this.responseDelimited=!!h}(o.prototype=Object.create(r.EventEmitter.prototype)).constructor=o,o.prototype.rpcCall=function c(l,h,p,f,d){if(!f)throw TypeError("request must be specified");var i=this;if(!d)return r.asPromise(c,i,l,h,p,f);if(i.rpcImpl)try{return i.rpcImpl(l,h[i.requestDelimited?"encodeDelimited":"encode"](f).finish(),function(n,a){if(n)return i.emit("error",n,l),d(n);if(a!==null){if(!(a instanceof p))try{a=p[i.responseDelimited?"decodeDelimited":"decode"](a)}catch(u){return i.emit("error",u,l),d(u)}return i.emit("data",a,l),d(null,a)}i.end(!0)})}catch(n){return i.emit("error",n,l),void setTimeout(function(){d(n)},0)}else setTimeout(function(){d(Error("already ended"))},0)},o.prototype.end=function(c){return this.rpcImpl&&(c||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},1945:(s,e,t)=>{s.exports=o;var r=t(9693);function o(p,f){this.lo=p>>>0,this.hi=f>>>0}var c=o.zero=new o(0,0);c.toNumber=function(){return 0},c.zzEncode=c.zzDecode=function(){return this},c.length=function(){return 1};var l=o.zeroHash="\0\0\0\0\0\0\0\0";o.fromNumber=function(p){if(p===0)return c;var f=p<0;f&&(p=-p);var d=p>>>0,i=(p-d)/4294967296>>>0;return f&&(i=~i>>>0,d=~d>>>0,++d>4294967295&&(d=0,++i>4294967295&&(i=0))),new o(d,i)},o.from=function(p){if(typeof p=="number")return o.fromNumber(p);if(r.isString(p)){if(!r.Long)return o.fromNumber(parseInt(p,10));p=r.Long.fromString(p)}return p.low||p.high?new o(p.low>>>0,p.high>>>0):c},o.prototype.toNumber=function(p){if(!p&&this.hi>>>31){var f=1+~this.lo>>>0,d=~this.hi>>>0;return f||(d=d+1>>>0),-(f+4294967296*d)}return this.lo+4294967296*this.hi},o.prototype.toLong=function(p){return r.Long?new r.Long(0|this.lo,0|this.hi,!!p):{low:0|this.lo,high:0|this.hi,unsigned:!!p}};var h=String.prototype.charCodeAt;o.fromHash=function(p){return p===l?c:new o((h.call(p,0)|h.call(p,1)<<8|h.call(p,2)<<16|h.call(p,3)<<24)>>>0,(h.call(p,4)|h.call(p,5)<<8|h.call(p,6)<<16|h.call(p,7)<<24)>>>0)},o.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},o.prototype.zzEncode=function(){var p=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^p)>>>0,this.lo=(this.lo<<1^p)>>>0,this},o.prototype.zzDecode=function(){var p=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^p)>>>0,this.hi=(this.hi>>>1^p)>>>0,this},o.prototype.length=function(){var p=this.lo,f=(this.lo>>>28|this.hi<<4)>>>0,d=this.hi>>>24;return d===0?f===0?p<16384?p<128?1:2:p<2097152?3:4:f<16384?f<128?5:6:f<2097152?7:8:d<128?9:10}},9693:function(s,e,t){var r=e;function o(l,h,p){for(var f=Object.keys(h),d=0;d0)},r.Buffer=function(){try{var l=r.inquire("buffer").Buffer;return l.prototype.utf8Write?l:null}catch{return null}}(),r._Buffer_from=null,r._Buffer_allocUnsafe=null,r.newBuffer=function(l){return typeof l=="number"?r.Buffer?r._Buffer_allocUnsafe(l):new r.Array(l):r.Buffer?r._Buffer_from(l):typeof Uint8Array>"u"?l:new Uint8Array(l)},r.Array=typeof Uint8Array<"u"?Uint8Array:Array,r.Long=r.global.dcodeIO&&r.global.dcodeIO.Long||r.global.Long||r.inquire("long"),r.key2Re=/^true|false|0|1$/,r.key32Re=/^-?(?:0|[1-9][0-9]*)$/,r.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,r.longToHash=function(l){return l?r.LongBits.from(l).toHash():r.LongBits.zeroHash},r.longFromHash=function(l,h){var p=r.LongBits.fromHash(l);return r.Long?r.Long.fromBits(p.lo,p.hi,h):p.toNumber(!!h)},r.merge=o,r.lcFirst=function(l){return l.charAt(0).toLowerCase()+l.substring(1)},r.newError=c,r.ProtocolError=c("ProtocolError"),r.oneOfGetter=function(l){for(var h={},p=0;p-1;--d)if(h[f[d]]===1&&this[f[d]]!==void 0&&this[f[d]]!==null)return f[d]}},r.oneOfSetter=function(l){return function(h){for(var p=0;p{s.exports=i;var r,o=t(9693),c=o.LongBits,l=o.base64,h=o.utf8;function p(b,y,v){this.fn=b,this.len=y,this.next=void 0,this.val=v}function f(){}function d(b){this.head=b.head,this.tail=b.tail,this.len=b.len,this.next=b.states}function i(){this.len=0,this.head=new p(f,0,0),this.tail=this.head,this.states=null}var n=function(){return o.Buffer?function(){return(i.create=function(){return new r})()}:function(){return new i}};function a(b,y,v){y[v]=255&b}function u(b,y){this.len=b,this.next=void 0,this.val=y}function m(b,y,v){for(;b.hi;)y[v++]=127&b.lo|128,b.lo=(b.lo>>>7|b.hi<<25)>>>0,b.hi>>>=7;for(;b.lo>127;)y[v++]=127&b.lo|128,b.lo=b.lo>>>7;y[v++]=b.lo}function g(b,y,v){y[v]=255&b,y[v+1]=b>>>8&255,y[v+2]=b>>>16&255,y[v+3]=b>>>24}i.create=n(),i.alloc=function(b){return new o.Array(b)},o.Array!==Array&&(i.alloc=o.pool(i.alloc,o.Array.prototype.subarray)),i.prototype._push=function(b,y,v){return this.tail=this.tail.next=new p(b,y,v),this.len+=y,this},u.prototype=Object.create(p.prototype),u.prototype.fn=function(b,y,v){for(;b>127;)y[v++]=127&b|128,b>>>=7;y[v]=b},i.prototype.uint32=function(b){return this.len+=(this.tail=this.tail.next=new u((b>>>=0)<128?1:b<16384?2:b<2097152?3:b<268435456?4:5,b)).len,this},i.prototype.int32=function(b){return b<0?this._push(m,10,c.fromNumber(b)):this.uint32(b)},i.prototype.sint32=function(b){return this.uint32((b<<1^b>>31)>>>0)},i.prototype.uint64=function(b){var y=c.from(b);return this._push(m,y.length(),y)},i.prototype.int64=i.prototype.uint64,i.prototype.sint64=function(b){var y=c.from(b).zzEncode();return this._push(m,y.length(),y)},i.prototype.bool=function(b){return this._push(a,1,b?1:0)},i.prototype.fixed32=function(b){return this._push(g,4,b>>>0)},i.prototype.sfixed32=i.prototype.fixed32,i.prototype.fixed64=function(b){var y=c.from(b);return this._push(g,4,y.lo)._push(g,4,y.hi)},i.prototype.sfixed64=i.prototype.fixed64,i.prototype.float=function(b){return this._push(o.float.writeFloatLE,4,b)},i.prototype.double=function(b){return this._push(o.float.writeDoubleLE,8,b)};var _=o.Array.prototype.set?function(b,y,v){y.set(b,v)}:function(b,y,v){for(var x=0;x>>0;if(!y)return this._push(a,1,0);if(o.isString(b)){var v=i.alloc(y=l.length(b));l.decode(b,v,0),b=v}return this.uint32(y)._push(_,y,b)},i.prototype.string=function(b){var y=h.length(b);return y?this.uint32(y)._push(h.write,y,b):this._push(a,1,0)},i.prototype.fork=function(){return this.states=new d(this),this.head=this.tail=new p(f,0,0),this.len=0,this},i.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new p(f,0,0),this.len=0),this},i.prototype.ldelim=function(){var b=this.head,y=this.tail,v=this.len;return this.reset().uint32(v),v&&(this.tail.next=b.next,this.tail=y,this.len+=v),this},i.prototype.finish=function(){for(var b=this.head.next,y=this.constructor.alloc(this.len),v=0;b;)b.fn(b.val,y,v),v+=b.len,b=b.next;return y},i._configure=function(b){r=b,i.create=n(),r._configure()}},3155:(s,e,t)=>{s.exports=c;var r=t(1173);(c.prototype=Object.create(r.prototype)).constructor=c;var o=t(9693);function c(){r.call(this)}function l(h,p,f){h.length<40?o.utf8.write(h,p,f):p.utf8Write?p.utf8Write(h,f):p.write(h,f)}c._configure=function(){c.alloc=o._Buffer_allocUnsafe,c.writeBytesBuffer=o.Buffer&&o.Buffer.prototype instanceof Uint8Array&&o.Buffer.prototype.set.name==="set"?function(h,p,f){p.set(h,f)}:function(h,p,f){if(h.copy)h.copy(p,f,0,h.length);else for(var d=0;d>>0;return this.uint32(p),p&&this._push(c.writeBytesBuffer,p,h),this},c.prototype.string=function(h){var p=o.Buffer.byteLength(h);return this.uint32(p),p&&this._push(l,p,h),this},c._configure()},7714:(s,e,t)=>{e.R=void 0;const r=t(6919),o=t(7448);e.R=new class{async init(){}async createSessionHandler(c,l){const h=new r.Session(l);return await h.loadModel(c),new o.OnnxjsSessionHandler(h)}}},4200:(s,e,t)=>{e.c8=e.rX=void 0;const r=t(1670),o=t(5381),c=t(2157),l=t(2306);e.rX=()=>{if((typeof r.env.wasm.initTimeout!="number"||r.env.wasm.initTimeout<0)&&(r.env.wasm.initTimeout=0),typeof r.env.wasm.simd!="boolean"&&(r.env.wasm.simd=!0),typeof r.env.wasm.proxy!="boolean"&&(r.env.wasm.proxy=!1),typeof r.env.wasm.numThreads!="number"||!Number.isInteger(r.env.wasm.numThreads)||r.env.wasm.numThreads<=0){const h=typeof navigator>"u"?(0,o.cpus)().length:navigator.hardwareConcurrency;r.env.wasm.numThreads=Math.min(4,Math.ceil((h||1)/2))}},e.c8=new class{async init(){(0,e.rX)(),await(0,c.initWasm)()}async createSessionHandler(h,p){const f=new l.OnnxruntimeWebAssemblySessionHandler;return await f.loadModel(h,p),Promise.resolve(f)}}},6018:function(s,e,t){var r=this&&this.__createBinding||(Object.create?function(l,h,p,f){f===void 0&&(f=p);var d=Object.getOwnPropertyDescriptor(h,p);d&&!("get"in d?!h.__esModule:d.writable||d.configurable)||(d={enumerable:!0,get:function(){return h[p]}}),Object.defineProperty(l,f,d)}:function(l,h,p,f){f===void 0&&(f=p),l[f]=h[p]}),o=this&&this.__exportStar||function(l,h){for(var p in l)p==="default"||Object.prototype.hasOwnProperty.call(h,p)||r(h,l,p)};Object.defineProperty(e,"__esModule",{value:!0}),o(t(1670),e);const c=t(1670);{const l=t(7714).R;(0,c.registerBackend)("webgl",l,-10)}{const l=t(4200).c8;(0,c.registerBackend)("cpu",l,10),(0,c.registerBackend)("wasm",l,10),(0,c.registerBackend)("xnnpack",l,9)}},246:(s,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createAttributeWithCacheKey=void 0;class t{constructor(o){Object.assign(this,o)}get cacheKey(){return this._cacheKey||(this._cacheKey=Object.getOwnPropertyNames(this).sort().map(o=>`${this[o]}`).join(";")),this._cacheKey}}e.createAttributeWithCacheKey=r=>new t(r)},7778:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Attribute=void 0;const r=t(1446),o=t(9395),c=t(9162),l=t(2517);var h=o.onnxruntime.experimental.fbs;class p{constructor(d){if(this._attributes=new Map,d!=null){for(const i of d)i instanceof r.onnx.AttributeProto?this._attributes.set(i.name,[p.getValue(i),p.getType(i)]):i instanceof h.Attribute&&this._attributes.set(i.name(),[p.getValue(i),p.getType(i)]);if(this._attributes.sizec.Tensor.fromProto(a));if(d instanceof h.Attribute)return n.map(a=>c.Tensor.fromOrtTensor(a))}if(i===r.onnx.AttributeProto.AttributeType.STRING&&d instanceof r.onnx.AttributeProto){const a=n;return(0,l.decodeUtf8String)(a)}return i===r.onnx.AttributeProto.AttributeType.STRINGS&&d instanceof r.onnx.AttributeProto?n.map(l.decodeUtf8String):n}static getValueNoCheck(d){return d instanceof r.onnx.AttributeProto?this.getValueNoCheckFromOnnxFormat(d):this.getValueNoCheckFromOrtFormat(d)}static getValueNoCheckFromOnnxFormat(d){switch(d.type){case r.onnx.AttributeProto.AttributeType.FLOAT:return d.f;case r.onnx.AttributeProto.AttributeType.INT:return d.i;case r.onnx.AttributeProto.AttributeType.STRING:return d.s;case r.onnx.AttributeProto.AttributeType.TENSOR:return d.t;case r.onnx.AttributeProto.AttributeType.GRAPH:return d.g;case r.onnx.AttributeProto.AttributeType.FLOATS:return d.floats;case r.onnx.AttributeProto.AttributeType.INTS:return d.ints;case r.onnx.AttributeProto.AttributeType.STRINGS:return d.strings;case r.onnx.AttributeProto.AttributeType.TENSORS:return d.tensors;case r.onnx.AttributeProto.AttributeType.GRAPHS:return d.graphs;default:throw new Error(`unsupported attribute type: ${r.onnx.AttributeProto.AttributeType[d.type]}`)}}static getValueNoCheckFromOrtFormat(d){switch(d.type()){case h.AttributeType.FLOAT:return d.f();case h.AttributeType.INT:return d.i();case h.AttributeType.STRING:return d.s();case h.AttributeType.TENSOR:return d.t();case h.AttributeType.GRAPH:return d.g();case h.AttributeType.FLOATS:return d.floatsArray();case h.AttributeType.INTS:{const i=[];for(let n=0;n{Object.defineProperty(e,"__esModule",{value:!0}),e.resolveBackend=e.backend=void 0;const r=t(5038),o=new Map;async function c(l){const h=e.backend;if(h[l]!==void 0&&function(p){const f=p;return"initialize"in f&&typeof f.initialize=="function"&&"createSessionHandler"in f&&typeof f.createSessionHandler=="function"&&"dispose"in f&&typeof f.dispose=="function"}(h[l])){const p=h[l];let f=p.initialize();if(typeof f=="object"&&"then"in f&&(f=await f),f)return o.set(l,p),p}}e.backend={webgl:new r.WebGLBackend},e.resolveBackend=async function l(h){if(!h)return l(["webgl"]);{const p=typeof h=="string"?[h]:h;for(const f of p){const d=o.get(f);if(d)return d;const i=await c(f);if(i)return i}}throw new Error("no available backend to use")}},5038:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.WebGLBackend=void 0;const r=t(1670),o=t(6231),c=t(6416),l=t(7305);e.WebGLBackend=class{get contextId(){return r.env.webgl.contextId}set contextId(h){r.env.webgl.contextId=h}get matmulMaxBatchSize(){return r.env.webgl.matmulMaxBatchSize}set matmulMaxBatchSize(h){r.env.webgl.matmulMaxBatchSize=h}get textureCacheMode(){return r.env.webgl.textureCacheMode}set textureCacheMode(h){r.env.webgl.textureCacheMode=h}get pack(){return r.env.webgl.pack}set pack(h){r.env.webgl.pack=h}get async(){return r.env.webgl.async}set async(h){r.env.webgl.async=h}initialize(){try{return this.glContext=(0,l.createWebGLContext)(this.contextId),typeof this.matmulMaxBatchSize!="number"&&(this.matmulMaxBatchSize=16),typeof this.textureCacheMode!="string"&&(this.textureCacheMode="full"),typeof this.pack!="boolean"&&(this.pack=!1),typeof this.async!="boolean"&&(this.async=!1),o.Logger.setWithEnv(r.env),o.Logger.verbose("WebGLBackend",`Created WebGLContext: ${typeof this.glContext} with matmulMaxBatchSize: ${this.matmulMaxBatchSize}; textureCacheMode: ${this.textureCacheMode}; pack: ${this.pack}; async: ${this.async}.`),!0}catch(h){return o.Logger.warning("WebGLBackend",`Unable to initialize WebGLBackend. ${h}`),!1}}createSessionHandler(h){return new c.WebGLSessionHandler(this,h)}dispose(){this.glContext.dispose()}}},5107:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.CoordsGlslLib=void 0;const r=t(2517),o=t(8520),c=t(5060),l=t(7859),h=t(9390);class p extends o.GlslLib{constructor(d){super(d)}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.offsetToCoords()),this.coordsToOffset()),this.toVec()),this.valueFrom()),this.getCommonUtilFuncs()),this.getInputsSamplingSnippets()),this.getOutputSamplingSnippet())}getCustomTypes(){return{}}offsetToCoords(){return{offsetToCoords:new o.GlslLibRoutine(` vec2 offsetToCoords(int offset, int width, int height) { int t = offset / width; int s = offset - t*width; vec2 coords = (vec2(s,t) + vec2(0.5,0.5)) / vec2(width, height); return coords; } `)}}coordsToOffset(){return{coordsToOffset:new o.GlslLibRoutine(` int coordsToOffset(vec2 coords, int width, int height) { float s = coords.s * float(width); float t = coords.t * float(height); int offset = int(t) * width + int(s); return offset; } `)}}getOutputSamplingSnippet(){const d=this.context.outputTextureLayout;return d.isPacked?this.getPackedOutputSamplingSnippet(d):this.getUnpackedOutputSamplingSnippet(d)}getPackedOutputSamplingSnippet(d){const i=d.unpackedShape,n=[d.width,d.height],a={},u="getOutputCoords";switch(i.length){case 0:a[u]=this.getOutputScalarCoords();break;case 1:a[u]=this.getOutputPacked1DCoords(i,n);break;case 2:a[u]=this.getOutputPacked2DCoords(i,n);break;case 3:a[u]=this.getOutputPacked3DCoords(i,n);break;default:a[u]=this.getOutputPackedNDCoords(i,n)}const m=` void setOutput(vec4 val) { ${(0,c.getGlsl)(this.context.glContext.version).output} = val; } `;return a.floatTextureSetRGBA=new o.GlslLibRoutine(m),a}getUnpackedOutputSamplingSnippet(d){const i=d.unpackedShape,n=[d.width,d.height],a={},u="getOutputCoords";switch(i.length){case 0:a[u]=this.getOutputScalarCoords();break;case 1:a[u]=this.getOutputUnpacked1DCoords(i,n);break;case 2:a[u]=this.getOutputUnpacked2DCoords(i,n);break;case 3:a[u]=this.getOutputUnpacked3DCoords(i,n);break;case 4:a[u]=this.getOutputUnpacked4DCoords(i,n);break;case 5:a[u]=this.getOutputUnpacked5DCoords(i,n);break;case 6:a[u]=this.getOutputUnpacked6DCoords(i,n);break;default:throw new Error(`Unsupported output dimensionality: ${i.length}`)}const m=` void setOutput(float val) { ${(0,c.getGlsl)(this.context.glContext.version).output} = vec4(val, 0, 0, 0); } `;return a.floatTextureSetR=new o.GlslLibRoutine(m),a}getOutputScalarCoords(){return new o.GlslLibRoutine(` int getOutputCoords() { return 0; } `)}getOutputPacked1DCoords(d,i){const n=i;let a="";return n[0]===1?(a=` int getOutputCoords() { return 2 * int(TexCoords.y * ${n[1]}.0); } `,new o.GlslLibRoutine(a)):n[1]===1?(a=` int getOutputCoords() { return 2 * int(TexCoords.x * ${n[0]}.0); } `,new o.GlslLibRoutine(a)):(a=` int getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${n[0]}, ${n[1]})); return 2 * (resTexRC.y * ${n[0]} + resTexRC.x); } `,new o.GlslLibRoutine(a))}getOutputPacked2DCoords(d,i){let n="";if(r.ArrayUtil.arraysEqual(d,i))return n=` ivec2 getOutputCoords() { return 2 * ivec2(TexCoords.xy * vec2(${i[0]}, ${i[1]})); } `,new o.GlslLibRoutine(n);const a=i,u=Math.ceil(d[1]/2);return n=` ivec2 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${a[0]}, ${a[1]})); int index = resTexRC.y * ${a[0]} + resTexRC.x; // reverse r and c order for packed texture int r = imod(index, ${u}) * 2; int c = 2 * (index / ${u}); return ivec2(r, c); } `,new o.GlslLibRoutine(n)}getOutputPacked3DCoords(d,i){const n=[i[0],i[1]],a=Math.ceil(d[2]/2),u=a*Math.ceil(d[1]/2),m=` ivec3 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${n[0]}, ${n[1]})); int index = resTexRC.y * ${n[0]} + resTexRC.x; int b = index / ${u}; index -= b * ${u}; // reverse r and c order for packed texture int r = imod(index, ${a}) * 2; int c = 2 * (index / ${a}); return ivec3(b, r, c); } `;return new o.GlslLibRoutine(m)}getOutputPackedNDCoords(d,i){const n=[i[0],i[1]],a=Math.ceil(d[d.length-1]/2),u=a*Math.ceil(d[d.length-2]/2);let m=u,g="",_="b, r, c";for(let y=2;y=0;--_)u[_]=u[_+1]*d[_+1];const m=["r","c","d"],g=u.map((_,b)=>`int ${m[b]} = index / ${_}; ${b===u.length-1?`int ${m[b+1]} = index - ${m[b]} * ${_}`:`index -= ${m[b]} * ${_}`};`).join("");return n=` ivec3 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${i[0]}, ${i[1]})); int index = resTexRC.y * ${i[0]} + resTexRC.x; ${g} return ivec3(r, c, d); } `,new o.GlslLibRoutine(n)}getOutputUnpacked4DCoords(d,i){let n="";const a=d.length;let u=null;a<2&&(u=[]),u=new Array(a-1),u[a-2]=d[a-1];for(let _=a-3;_>=0;--_)u[_]=u[_+1]*d[_+1];const m=["r","c","d","d2"],g=u.map((_,b)=>`int ${m[b]} = index / ${_}; ${b===u.length-1?`int ${m[b+1]} = index - ${m[b]} * ${_}`:`index -= ${m[b]} * ${_}`};`).join("");return n=` ivec4 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${i[0]}, ${i[1]})); int index = resTexRC.y * ${i[0]} + resTexRC.x; ${g} return ivec4(r, c, d, d2); } `,new o.GlslLibRoutine(n)}getOutputUnpacked5DCoords(d,i){let n="";const a=d.length;let u=null;a<2&&(u=[]),u=new Array(a-1),u[a-2]=d[a-1];for(let _=a-3;_>=0;--_)u[_]=u[_+1]*d[_+1];const m=["r","c","d","d2","d3"],g=u.map((_,b)=>`int ${m[b]} = index / ${_}; ${b===u.length-1?`int ${m[b+1]} = index - ${m[b]} * ${_}`:`index -= ${m[b]} * ${_}`};`).join("");return n=` ivec5 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${i[0]}, ${i[1]})); int index = resTexRC.y * ${i[0]} + resTexRC.x; ${g} return ivec5(r, c, d, d2, d3); } `,new o.GlslLibRoutine(n)}getOutputUnpacked6DCoords(d,i){let n="";const a=d.length;let u=null;a<2&&(u=[]),u=new Array(a-1),u[a-2]=d[a-1];for(let _=a-3;_>=0;--_)u[_]=u[_+1]*d[_+1];const m=["r","c","d","d2","d3","d4"],g=u.map((_,b)=>`int ${m[b]} = index / ${_}; ${b===u.length-1?`int ${m[b+1]} = index - ${m[b]} * ${_}`:`index -= ${m[b]} * ${_}`};`).join("");return n=` ivec6 getOutputCoords() { ivec2 resTexRC = ivec2(TexCoords.xy * vec2(${i[0]}, ${i[1]})); int index = resTexRC.y * ${i[0]} + resTexRC.x; ${g} return ivec6(r, c, d, d2, d3, d4); } `,new o.GlslLibRoutine(n)}getCommonUtilFuncs(){const d={};let i="uvFromFlat";d[i]=new o.GlslLibRoutine(` vec2 uvFromFlat(int texNumR, int texNumC, int index) { int texC = index / texNumR; int texR = index - texC * texNumR; // TODO: swap texR, texC order in following function so row is corresponding to u and column is corresponding to // v. return (vec2(texR, texC) + halfCR) / vec2(texNumR, texNumC); } `),i="packedUVfrom1D",d[i]=new o.GlslLibRoutine(` vec2 packedUVfrom1D(int texNumR, int texNumC, int index) { int texelIndex = index / 2; int texR = texelIndex / texNumC; int texC = texelIndex - texR * texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); } `),i="packedUVfrom2D",d[i]=new o.GlslLibRoutine(` vec2 packedUVfrom2D(int texNumR, int texNumC, int texelsInLogicalRow, int row, int col) { int texelIndex = (row / 2) * texelsInLogicalRow + (col / 2); int texR = texelIndex / texNumC; int texC = texelIndex - texR * texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); } `),i="packedUVfrom3D",d[i]=new o.GlslLibRoutine(` vec2 packedUVfrom3D(int texNumR, int texNumC, int texelsInBatch, int texelsInLogicalRow, int b, int row, int col) { int index = b * texelsInBatch + (row / 2) * texelsInLogicalRow + (col / 2); int texR = index / texNumC; int texC = index - texR * texNumC; return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR); } `),i="sampleTexture";const n=(0,c.getGlsl)(this.context.glContext.version);return d[i]=new o.GlslLibRoutine(` float sampleTexture(sampler2D textureSampler, vec2 uv) { return ${n.texture2D}(textureSampler, uv).r; }`),d}getInputsSamplingSnippets(){const d={},i=this.context.outputTextureLayout;return this.context.programInfo.inputNames.forEach((n,a)=>{const u=this.context.inputTextureLayouts[a],m=(0,h.generateShaderFuncNameFromInputSamplerName)(n);u.isPacked?d[m]=this.getPackedSamplerFromInput(m,n,u):d[m]=this.getUnpackedSamplerFromInput(m,n,u);const g=(0,h.generateShaderFuncNameFromInputSamplerNameAtOutCoords)(n);u.unpackedShape.length<=i.unpackedShape.length&&(u.isPacked?d[g]=this.getPackedSamplerAtOutputCoords(g,u,i,n):d[g]=this.getUnpackedSamplerAtOutputCoords(g,u,i,n))}),d}getPackedSamplerAtOutputCoords(d,i,n,a){const u=i.unpackedShape,m=n.unpackedShape,g=a,_=(0,h.generateShaderFuncNameFromInputSamplerName)(g),b=u.length,y=m.length,v=r.BroadcastUtil.getBroadcastDims(u,m),x=(0,h.getCoordsDataType)(y),w=y-b;let S;const M=(0,h.getGlChannels)();S=b===0?"":y<2&&v.length>=1?"coords = 0;":v.map(C=>`coords.${M[C+w]} = 0;`).join(` `);let T="";T=y<2&&b>0?"coords":u.map((C,z)=>`coords.${M[z+w]}`).join(", ");let E="return outputValue;";const R=r.ShapeUtil.size(u)===1,I=r.ShapeUtil.size(m)===1;if(b!==1||R||I){if(R&&!I)E=y===1?` return vec4(outputValue.x, outputValue.x, 0., 0.); `:` return vec4(outputValue.x); `;else if(v.length){const C=b-2,z=b-1;v.indexOf(C)>-1&&v.indexOf(z)>-1?E="return vec4(outputValue.x);":v.indexOf(C)>-1?E="return vec4(outputValue.x, outputValue.y, outputValue.x, outputValue.y);":v.indexOf(z)>-1&&(E="return vec4(outputValue.xx, outputValue.zz);")}}else E=` return vec4(outputValue.xy, outputValue.xy); `;const k=` vec4 ${d}() { ${x} coords = getOutputCoords(); int lastDim = coords.${M[y-1]}; coords.${M[y-1]} = coords.${M[y-2]}; coords.${M[y-2]} = lastDim; ${S} vec4 outputValue = ${_}(${T}); ${E} } `;return new o.GlslLibRoutine(k,["coordinates.getOutputCoords"])}getUnpackedSamplerAtOutputCoords(d,i,n,a){const u=[n.width,n.height],m=[i.width,i.height],g=i.unpackedShape.length,_=n.unpackedShape.length,b=i.unpackedShape,y=n.unpackedShape,v=(0,h.generateShaderFuncNameFromInputSamplerName)(a);if(g===_&&r.ArrayUtil.arraysEqual(m,u)){const I=` float ${d}() { return sampleTexture(${a}, TexCoords); } `;return new o.GlslLibRoutine(I,["coordinates.sampleTexture"])}const x=(0,h.getCoordsDataType)(_),w=r.BroadcastUtil.getBroadcastDims(b,y),S=_-g;let M;const T=(0,h.getGlChannels)();M=g===0?"":_<2&&w.length>=1?"coords = 0;":w.map(I=>`coords.${T[I+S]} = 0;`).join(` `);let E="";E=_<2&&g>0?"coords":i.unpackedShape.map((I,k)=>`coords.${T[k+S]}`).join(", ");const R=` float ${d}() { ${x} coords = getOutputCoords(); ${M} return ${v}(${E}); } `;return new o.GlslLibRoutine(R,["coordinates.getOutputCoords"])}getPackedSamplerFromInput(d,i,n){switch(n.unpackedShape.length){case 0:return this.getPackedSamplerScalar(d,i);case 1:return this.getPackedSampler1D(d,i,n);case 2:return this.getPackedSampler2D(d,i,n);case 3:return this.getPackedSampler3D(d,i,n);default:return this.getPackedSamplerND(d,i,n)}}getUnpackedSamplerFromInput(d,i,n){const a=n.unpackedShape;switch(a.length){case 0:return this.getUnpackedSamplerScalar(d,i,n);case 1:return this.getUnpackedSampler1D(d,i,n);case 2:return this.getUnpackedSampler2D(d,i,n);case 3:return this.getUnpackedSampler3D(d,i,n);case 4:return this.getUnpackedSampler4D(d,i,n);case 5:return this.getUnpackedSampler5D(d,i,n);case 6:return this.getUnpackedSampler6D(d,i,n);default:throw new Error(`Unsupported dimension ${a.length}-D`)}}getPackedSamplerScalar(d,i){const n=` vec4 ${d}() { return ${(0,c.getGlsl)(this.context.glContext.version).texture2D}(${i}, halfCR); } `;return new o.GlslLibRoutine(n)}getPackedSampler1D(d,i,n){const a=[n.width,n.height],u=[a[1],a[0]],m=(0,c.getGlsl)(this.context.glContext.version),g=`vec4 ${d}(int index) { vec2 uv = packedUVfrom1D( ${u[0]}, ${u[1]}, index); return ${m.texture2D}(${i}, uv); }`;return new o.GlslLibRoutine(g,["coordinates.packedUVfrom1D"])}getPackedSampler2D(d,i,n){const a=n.unpackedShape,u=[n.width,n.height],m=(0,c.getGlsl)(this.context.glContext.version),g=u[0],_=u[1];if(u!=null&&r.ArrayUtil.arraysEqual(a,u)){const x=`vec4 ${d}(int row, int col) { vec2 uv = (vec2(col, row) + halfCR) / vec2(${_}.0, ${g}.0); return ${m.texture2D}(${i}, uv); }`;return new o.GlslLibRoutine(x)}const b=u,y=Math.ceil(a[1]/2),v=`vec4 ${d}(int row, int col) { vec2 uv = packedUVfrom2D(${b[1]}, ${b[0]}, ${y}, row, col); return ${m.texture2D}(${i}, uv); }`;return new o.GlslLibRoutine(v,["coordinates.packedUVfrom2D"])}getPackedSampler3D(d,i,n){const a=n.unpackedShape,u=[n.width,n.height],m=[u[0],u[1]],g=(0,c.getGlsl)(this.context.glContext.version);if(a[0]===1){const x=a.slice(1),w=[1,2],S=(0,h.squeezeInputShape)(a,x),M=["b","row","col"],T=JSON.parse(JSON.stringify(n));T.unpackedShape=S;const E=this.getPackedSamplerFromInput(d,i,T),R=`${E.routineBody} vec4 ${d}(int b, int row, int col) { return ${d}(${(0,h.getSqueezedParams)(M,w)}); } `;return new o.GlslLibRoutine(R,E.dependencies)}const _=m[0],b=m[1],y=Math.ceil(a[2]/2),v=`vec4 ${d}(int b, int row, int col) { vec2 uv = packedUVfrom3D( ${b}, ${_}, ${y*Math.ceil(a[1]/2)}, ${y}, b, row, col); return ${g.texture2D}(${i}, uv);}`;return new o.GlslLibRoutine(v,["coordinates.packedUVfrom3D"])}getPackedSamplerND(d,i,n){const a=n.unpackedShape,u=a.length,m=[n.width,n.height],g=(0,c.getGlsl)(this.context.glContext.version),_=[m[0],m[1]],b=_[1],y=_[0],v=Math.ceil(a[u-1]/2);let x=v*Math.ceil(a[u-2]/2),w="int b, int row, int col",S=`b * ${x} + (row / 2) * ${v} + (col / 2)`;for(let T=2;T{const a=this.context.inputTextureLayouts[n],u=(a.unpackedShape.length>0?a.unpackedShape:a.shape).length;let m=`_${i}`;d[m]=new o.GlslLibRoutine(this.getValueFromSingle(i,u,a.width,a.height,!1),[`shapeUtils.indicesToOffset${m}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"]),m+="_T",d[m]=new o.GlslLibRoutine(this.getValueFromSingle(i,u,a.width,a.height,!0),[`shapeUtils.indicesToOffset${m}`,"coordinates.offsetToCoords","fragcolor.getColorAsFloat"])}),d}getValueFromSingle(d,i,n,a,u){let m=`_${d}`;return u&&(m+="_T"),` float ${m}(int m[${i}]) { int offset = indicesToOffset${m}(m); vec2 coords = offsetToCoords(offset, ${n}, ${a}); float value = getColorAsFloat(${(0,c.getGlsl)(this.context.glContext.version).texture2D}(${d}, coords)); return value; } `}getPackedValueFrom(d,i,n,a,u){let m=`_${d}_Pack`;return u&&(m+="_T"),` vec4 ${m}(int m[${i}]) { int offset = indicesToOffset_${d}(m); vec2 coords = offsetToCoords(offset, ${n}, ${a}); return ${(0,c.getGlsl)(this.context.glContext.version).texture2D}(${d}, coords); } `}}e.CoordsGlslLib=p},8520:(s,e)=>{var t;Object.defineProperty(e,"__esModule",{value:!0}),e.TopologicalSortGlslRoutines=e.GlslLibRoutineNode=e.GlslLibRoutine=e.GlslLib=e.GlslContext=e.FunctionType=void 0,(t=e.FunctionType||(e.FunctionType={}))[t.ValueBased=0]="ValueBased",t[t.Positional=1]="Positional",e.GlslContext=class{constructor(r,o,c,l){this.glContext=r,this.programInfo=o,this.inputTextureLayouts=c,this.outputTextureLayout=l}},e.GlslLib=class{constructor(r){this.context=r}},e.GlslLibRoutine=class{constructor(r,o){this.routineBody=r,this.dependencies=o}},e.GlslLibRoutineNode=class{constructor(r,o,c){this.name=r,this.dependencies=c||[],o&&(this.routineBody=o)}addDependency(r){r&&this.dependencies.push(r)}},e.TopologicalSortGlslRoutines=class{static returnOrderedNodes(r){if(!r||r.length===0)return[];if(r.length===1)return r;const o=new Set,c=new Set,l=new Array;return this.createOrderedNodes(r,o,c,l),l}static createOrderedNodes(r,o,c,l){for(let h=0;h0)for(let p=0;p{Object.defineProperty(e,"__esModule",{value:!0}),e.EncodingGlslLib=void 0;const r=t(8520);class o extends r.GlslLib{constructor(l){super(l)}getFunctions(){return Object.assign(Object.assign({},this.encodeFloat32()),this.decodeFloat32())}getCustomTypes(){return{}}encodeFloat32(){return{encode:new r.GlslLibRoutine(`highp vec4 encode(highp float f) { return vec4(f, 0.0, 0.0, 0.0); } `)}}decodeFloat32(){return{decode:new r.GlslLibRoutine(`highp float decode(highp vec4 rgba) { return rgba.r; } `)}}encodeUint8(){const l=o.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{encode:new r.GlslLibRoutine(` highp vec4 encode(highp float f) { highp float F = abs(f); highp float Sign = step(0.0,-f); highp float Exponent = floor(log2(F)); highp float Mantissa = (exp2(- Exponent) * F); Exponent = floor(log2(F) + 127.0) + floor(log2(Mantissa)); highp vec4 rgba; rgba[0] = 128.0 * Sign + floor(Exponent*exp2(-1.0)); rgba[1] = 128.0 * mod(Exponent,2.0) + mod(floor(Mantissa*128.0),128.0); rgba[2] = floor(mod(floor(Mantissa*exp2(23.0 -8.0)),exp2(8.0))); rgba[3] = floor(exp2(23.0)*mod(Mantissa,exp2(-15.0))); ${l} rgba = rgba / 255.0; // values need to be normalized to [0,1] return rgba; } `)}}decodeUint8(){const l=o.isLittleEndian()?"rgba.rgba=rgba.abgr;":"";return{decode:new r.GlslLibRoutine(` highp float decode(highp vec4 rgba) { rgba = rgba * 255.0; // values need to be de-normalized from [0,1] to [0,255] ${l} highp float Sign = 1.0 - step(128.0,rgba[0])*2.0; highp float Exponent = 2.0 * mod(rgba[0],128.0) + step(128.0,rgba[1]) - 127.0; highp float Mantissa = mod(rgba[1],128.0)*65536.0 + rgba[2]*256.0 +rgba[3] + float(0x800000); highp float Result = Sign * exp2(Exponent) * (Mantissa * exp2(-23.0 )); return Result; } `)}}static isLittleEndian(){const l=new ArrayBuffer(4),h=new Uint32Array(l),p=new Uint8Array(l);if(h[0]=3735928559,p[0]===239)return!0;if(p[0]===222)return!1;throw new Error("unknown endianness")}}e.EncodingGlslLib=o},9894:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.FragColorGlslLib=void 0;const r=t(8520),o=t(5060);class c extends r.GlslLib{constructor(h){super(h)}getFunctions(){return Object.assign(Object.assign({},this.setFragColor()),this.getColorAsFloat())}getCustomTypes(){return{}}setFragColor(){const h=(0,o.getGlsl)(this.context.glContext.version);return{setFragColor:new r.GlslLibRoutine(` void setFragColor(float value) { ${h.output} = encode(value); } `,["encoding.encode"])}}getColorAsFloat(){return{getColorAsFloat:new r.GlslLibRoutine(` float getColorAsFloat(vec4 color) { return decode(color); } `,["encoding.decode"])}}}e.FragColorGlslLib=c},2848:(s,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.replaceInlines=void 0;const t=/@inline[\s\n\r]+(\w+)[\s\n\r]+([0-9a-zA-Z_]+)\s*\(([^)]*)\)\s*{(([^}]|[\n\r])*)}/gm;e.replaceInlines=function(r){const o={};let c;for(;(c=t.exec(r))!==null;){const l=c[3].split(",").map(h=>{const p=h.trim().split(" ");return p&&p.length===2?{type:p[0],name:p[1]}:null}).filter(h=>h!==null);o[c[2]]={params:l,body:c[4]}}for(const l in o){const h="(\\w+)?\\s+([_0-9a-zA-Z]+)\\s+=\\s+__FUNC__\\((.*)\\)\\s*;".replace("__FUNC__",l),p=new RegExp(h,"gm");for(;(c=p.exec(r))!==null;){const f=c[1],d=c[2],i=c[3].split(","),n=f?`${f} ${d};`:"";let a=o[l].body,u="";o[l].params.forEach((g,_)=>{g&&(u+=`${g.type} ${g.name} = ${i[_]}; `)}),a=`${u} ${a}`,a=a.replace("return",`${d} = `);const m=` ${n} { ${a} } `;r=r.replace(c[0],m)}}return r.replace(t,"")}},8879:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.GlslPreprocessor=void 0;const r=t(8520),o=t(2848),c=t(5483),l=t(5060);e.GlslPreprocessor=class{constructor(h,p,f,d){this.libs={},this.glslLibRoutineDependencyGraph={},this.context=new r.GlslContext(h,p,f,d),Object.keys(c.glslRegistry).forEach(n=>{const a=new c.glslRegistry[n](this.context);this.libs[n]=a});const i=this.glslLibRoutineDependencyGraph;for(const n in this.libs){const a=this.libs[n].getFunctions();for(const u in a){const m=n+"."+u;let g;i[m]?(g=i[m],g.routineBody=a[u].routineBody):(g=new r.GlslLibRoutineNode(m,a[u].routineBody),i[m]=g);const _=a[u].dependencies;if(_)for(let b=0;b<_.length;++b)if(i[_[b]])g.addDependency(i[_[b]]);else{const y=new r.GlslLibRoutineNode(_[b]);i[_[b]]=y,g.addDependency(y)}}}}preprocess(){const h=this.context.programInfo;let p=h.shaderSource;return this.context.programInfo.hasMain||(p=`${p} ${(0,l.getDefaultFragShaderMain)(this.context.glContext.version,this.context.outputTextureLayout.shape.length)}`),p=(0,o.replaceInlines)(p),`${(0,l.getFragShaderPreamble)(this.context.glContext.version)} ${this.getUniforms(h.inputNames,h.variables)} ${this.getImports(p)} ${p}`}getImports(h){const p=this.selectGlslLibRoutinesToBeIncluded(h);if(p.length===0)return"";let f="";for(let d=0;d{const d=f.split(".")[1];h.indexOf(d)!==-1&&p.push(this.glslLibRoutineDependencyGraph[f])}),r.TopologicalSortGlslRoutines.returnOrderedNodes(p)}getUniforms(h,p){const f=[];if(h)for(const d of h)f.push(`uniform sampler2D ${d};`);if(p)for(const d of p)f.push(`uniform ${d.type} ${d.name}${d.arrayLength?`[${d.arrayLength}]`:""};`);return f.join(` `)}}},5483:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.glslRegistry=void 0;const r=t(5107),o=t(7341),c=t(9894),l=t(2655),h=t(3891);e.glslRegistry={encoding:o.EncodingGlslLib,fragcolor:c.FragColorGlslLib,vec:h.VecGlslLib,shapeUtils:l.ShapeUtilsGlslLib,coordinates:r.CoordsGlslLib}},2655:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ShapeUtilsGlslLib=void 0;const r=t(8520);class o extends r.GlslLib{constructor(l){super(l)}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},this.bcastIndex()),this.bcastMatmulIndex()),this.offsetToIndices()),this.indicesToOffset()),this.incrementIndices())}getCustomTypes(){return{}}bcastIndex(){const l=this.context.outputTextureLayout.shape.length,h={};return this.context.programInfo.inputNames.forEach((p,f)=>{const d=this.context.inputTextureLayouts[f].unpackedShape;if(d.length<=l){const i=d.length,n=l-i,a=`bcastIndices_${p}`;let u="";for(let g=0;g{const d=this.context.inputTextureLayouts[f].shape;if(!(d.length<2||d.length>l)){const i=d.length,n=l-i,a=`bcastMatmulIndices_${p}`;let u="";for(let g=0;g{const f=this.context.inputTextureLayouts[p].shape,d=this.context.inputTextureLayouts[p].strides,i=f.length;let n=`indicesToOffset_${h}`;l[n]=new r.GlslLibRoutine(o.indexToOffsetSingle(n,i,d)),n=`indicesToOffset_${h}_T`,l[n]=new r.GlslLibRoutine(o.indexToOffsetSingle(n,i,d.slice().reverse()))}),l}static indexToOffsetSingle(l,h,p){let f="";for(let d=h-1;d>=0;--d)f+=` offset += indices[${d}] * ${p[d]}; `;return` int ${l}(int indices[${h}]) { int offset = 0; ${f} return offset; } `}offsetToIndices(){const l={};return this.context.programInfo.inputNames.forEach((h,p)=>{const f=this.context.inputTextureLayouts[p].shape,d=this.context.inputTextureLayouts[p].strides,i=f.length;let n=`offsetToIndices_${h}`;l[n]=new r.GlslLibRoutine(o.offsetToIndicesSingle(n,i,d)),n=`offsetToIndices_${h}_T`,l[n]=new r.GlslLibRoutine(o.offsetToIndicesSingle(n,i,d.slice().reverse()))}),l}static offsetToIndicesSingle(l,h,p){const f=[];for(let d=0;d{const f=this.context.inputTextureLayouts[p].shape,d=f.length,i=`incrementIndices_${h}`;let n="";for(let u=0;u= 0; --i) { if(i > axis) continue; indices[i] += 1; if(indices[i] < shape[i]) { break; } indices[i] = 0; } } `;l[i]=new r.GlslLibRoutine(a)}),l}}e.ShapeUtilsGlslLib=o},5060:(s,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getDefaultFragShaderMain=e.getFragShaderPreamble=e.getVertexShaderSource=e.getGlsl=void 0;const t={version:"",attribute:"attribute",varyingVertex:"varying",varyingFrag:"varying",texture2D:"texture2D",output:"gl_FragColor",outputDeclaration:""},r={version:"#version 300 es",attribute:"in",varyingVertex:"out",varyingFrag:"in",texture2D:"texture",output:"outputColor",outputDeclaration:"out vec4 outputColor;"};function o(c){return c===1?t:r}e.getGlsl=o,e.getVertexShaderSource=function(c){const l=o(c);return`${l.version} precision highp float; ${l.attribute} vec3 position; ${l.attribute} vec2 textureCoord; ${l.varyingVertex} vec2 TexCoords; void main() { gl_Position = vec4(position, 1.0); TexCoords = textureCoord; }`},e.getFragShaderPreamble=function(c){const l=o(c);return`${l.version} precision highp float; precision highp int; precision highp sampler2D; ${l.varyingFrag} vec2 TexCoords; ${l.outputDeclaration} const vec2 halfCR = vec2(0.5, 0.5); // Custom vector types to handle higher dimenalities. struct ivec5 { int x; int y; int z; int w; int u; }; struct ivec6 { int x; int y; int z; int w; int u; int v; }; int imod(int x, int y) { return x - y * (x / y); } `},e.getDefaultFragShaderMain=function(c,l){return` void main() { int indices[${l}]; toVec(TexCoords, indices); vec4 result = vec4(process(indices)); ${o(c).output} = result; } `}},3891:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.VecGlslLib=void 0;const r=t(8520);class o extends r.GlslLib{constructor(l){super(l)}getCustomTypes(){return{}}getFunctions(){return Object.assign(Object.assign(Object.assign(Object.assign({},this.binaryVecFunctions()),this.copyVec()),this.setVecItem()),this.getVecItem())}binaryVecFunctions(){const l=this.context.outputTextureLayout.shape.length,h={add:"+=",sub:"-=",mul:"*=",div:"/="},p={};for(const f in h){const d=`${f}Vec`;let i="";for(let a=0;a{Object.defineProperty(e,"__esModule",{value:!0}),e.WebGLInferenceHandler=void 0;const r=t(6231),o=t(9162),c=t(2517),l=t(2403),h=t(7019),p=t(8710),f=t(5611),d=t(4057),i=t(2039);e.WebGLInferenceHandler=class{constructor(n){this.session=n,this.packedTextureDataCache=new Map,this.unpackedTextureDataCache=new Map}calculateTextureWidthAndHeight(n,a){return(0,d.calculateTextureWidthAndHeight)(this.session.layoutStrategy,n,a)}executeProgram(n,a){if(a.length{const w=x.map(M=>`${M.unpackedShape.join(",")};${M.width}x${M.height}`).join("_");let S=v.name;return v.cacheHint&&(S+="["+v.cacheHint+"]"),S+=":"+w,S})(n,u);let g=this.session.programManager.getArtifact(m);const _=g?g.programInfo:typeof n.get=="function"?n.get():n,b=(0,d.createTextureLayoutFromTextureType)(this.session.layoutStrategy,_.output.dims,_.output.textureType),y=this.createTextureData(b,_.output.type);return g||(g=this.session.programManager.build(_,u,y),this.session.programManager.setArtifact(m,g)),this.runProgram(g,u,y),y}run(n,a){return this.executeProgram(n,a).tensor}runProgram(n,a,u){for(let m=0;mthis.readTexture(_),async b=>this.readTextureAsync(_),void 0,g),texture:u});return this.setTextureData(_.tensor.dataId,_,n.isPacked),_}getTextureData(n,a=!1){return this.session.isInitializer(n)?this.session.getTextureData(n,a):a?this.packedTextureDataCache.get(n):this.unpackedTextureDataCache.get(n)}setTextureData(n,a,u=!1){this.session.isInitializer(n)?this.session.setTextureData(n,a,u):(u?this.packedTextureDataCache:this.unpackedTextureDataCache).set(n,a)}isTextureLayoutCached(n,a=!1){return!!this.getTextureData(n.dataId,a)}dispose(){this.session.textureManager.clearActiveTextures(),this.packedTextureDataCache.forEach(n=>this.session.textureManager.releaseTexture(n)),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache.forEach(n=>this.session.textureManager.releaseTexture(n)),this.unpackedTextureDataCache=new Map}readTexture(n){return n.isPacked?this.readTexture(this.unpack(n)):this.session.backend.glContext.isFloat32DownloadSupported?this.session.textureManager.readTexture(n,n.tensor.type,n.channels):this.session.textureManager.readUint8TextureAsFloat((0,p.encodeAsUint8)(this,n))}async readTextureAsync(n){return n.isPacked?this.readTextureAsync(this.unpack(n)):this.session.backend.glContext.isFloat32DownloadSupported?this.session.textureManager.readTextureAsync(n,n.tensor.type,n.channels):this.session.textureManager.readUint8TextureAsFloat((0,p.encodeAsUint8)(this,n))}pack(n){return this.executeProgram((0,l.createPackProgramInfoLoader)(this,n.tensor),[n.tensor])}unpack(n){return this.executeProgram((0,f.createUnpackProgramInfoLoader)(this,n.tensor),[n.tensor])}}},1640:function(s,e,t){var r=this&&this.__createBinding||(Object.create?function($,J,ee,he){he===void 0&&(he=ee);var ie=Object.getOwnPropertyDescriptor(J,ee);ie&&!("get"in ie?!J.__esModule:ie.writable||ie.configurable)||(ie={enumerable:!0,get:function(){return J[ee]}}),Object.defineProperty($,he,ie)}:function($,J,ee,he){he===void 0&&(he=ee),$[he]=J[ee]}),o=this&&this.__setModuleDefault||(Object.create?function($,J){Object.defineProperty($,"default",{enumerable:!0,value:J})}:function($,J){$.default=J}),c=this&&this.__importStar||function($){if($&&$.__esModule)return $;var J={};if($!=null)for(var ee in $)ee!=="default"&&Object.prototype.hasOwnProperty.call($,ee)&&r(J,$,ee);return o(J,$),J};Object.defineProperty(e,"__esModule",{value:!0}),e.WEBGL_OP_RESOLVE_RULES=void 0;const l=t(2898),h=c(t(7839)),p=t(4196),f=t(2069),d=t(8138),i=t(9663),n=t(5193),a=t(7992),u=t(1253),m=t(4776),g=t(6572),_=t(3346),b=t(5623),y=t(2870),v=t(2143),x=t(4939),w=t(718),S=t(2268),M=t(8117),T=t(2278),E=t(5524),R=t(5975),I=t(3933),k=t(6558),C=t(5723),z=t(3738),O=c(t(4909)),U=t(8428),K=t(9793);e.WEBGL_OP_RESOLVE_RULES=[["Abs","","6+",O.abs],["Acos","","7+",O.acos],["Add","","7+",h.add],["And","","7+",h.and],["Asin","","7+",O.asin],["Atan","","7+",O.atan],["AveragePool","","7+",v.averagePool,v.parseAveragePoolAttributes],["BatchNormalization","","7+",l.batchNormalization,l.parseBatchNormalizationAttributes],["Cast","","6+",p.cast,p.parseCastAttributes],["Ceil","","6+",O.ceil],["Clip","","6-10",O.clip,O.parseClipAttributes],["Clip","","11+",O.clipV11],["Concat","","4+",f.concat,f.parseConcatAttributes],["Conv","","1+",d.conv,d.parseConvAttributes],["ConvTranspose","","1+",i.convTranspose,i.parseConvTransposeAttributes],["Cos","","7+",O.cos],["Div","","7+",h.div],["Dropout","","7+",O.identity],["DepthToSpace","","1+",n.depthToSpace,n.parseDepthToSpaceAttributes],["Equal","","7+",h.equal],["Elu","","6+",O.elu,O.parseEluAttributes],["Exp","","6+",O.exp],["Flatten","","1+",a.flatten,a.parseFlattenAttributes],["Floor","","6+",O.floor],["FusedConv","com.microsoft","1+",d.conv,d.parseConvAttributes],["Gather","","1+",u.gather,u.parseGatherAttributes],["Gemm","","7-10",m.gemm,m.parseGemmAttributesV7],["Gemm","","11+",m.gemm,m.parseGemmAttributesV11],["GlobalAveragePool","","1+",v.globalAveragePool,v.parseGlobalAveragePoolAttributes],["GlobalMaxPool","","1+",v.globalMaxPool],["Greater","","7+",h.greater],["Identity","","1+",O.identity],["ImageScaler","","1+",g.imageScaler,g.parseImageScalerAttributes],["InstanceNormalization","","6+",_.instanceNormalization,_.parseInstanceNormalizationAttributes],["LeakyRelu","","6+",O.leakyRelu,O.parseLeakyReluAttributes],["Less","","7+",h.less],["Log","","6+",O.log],["MatMul","","1+",b.matMul,b.parseMatMulAttributes],["MaxPool","","1+",v.maxPool,v.parseMaxPoolAttributes],["Mul","","7+",h.mul],["Neg","","6+",O.neg],["Not","","1+",O.not],["Or","","7+",h.or],["Pad","","2-10",y.padV2,y.parsePadAttributesV2],["Pad","","11+",y.padV11,y.parsePadAttributesV11],["Pow","","7+",h.pow],["PRelu","","7+",h.pRelu],["ReduceLogSum","","1+",x.reduceLogSum,x.parseReduceAttributes],["ReduceMax","","1+",x.reduceMax,x.parseReduceAttributes],["ReduceMean","","1+",x.reduceMean,x.parseReduceAttributes],["ReduceMin","","1+",x.reduceMin,x.parseReduceAttributes],["ReduceProd","","1+",x.reduceProd,x.parseReduceAttributes],["ReduceSum","","1-12",x.reduceSum,x.parseReduceAttributes],["ReduceSumSquare","","1+",x.reduceLogSumSquare,x.parseReduceAttributes],["Relu","","6+",O.relu],["Reshape","","5+",w.reshape],["Resize","","10",S.resize,S.parseResizeAttributesV10],["Resize","","11+",S.resize,S.parseResizeAttributesV11],["Shape","","1+",M.shape],["Sigmoid","","6+",O.sigmoid],["Sin","","7+",O.sin],["Slice","","10+",T.sliceV10],["Slice","","1-9",T.slice,T.parseSliceAttributes],["Softmax","","1-12",E.softmax,E.parseSoftmaxAttributes],["Softmax","","13+",E.softmaxV13,E.parseSoftmaxAttributesV13],["Split","","2-12",R.split,R.parseSplitAttributes],["Sqrt","","6+",O.sqrt],["Squeeze","","1-12",I.squeeze,I.parseSqueezeAttributes],["Squeeze","","13+",I.squeezeV13],["Sub","","7+",h.sub],["Sum","","6+",k.sum],["Tan","","7+",O.tan],["Tanh","","6+",O.tanh],["Tile","","6+",C.tile],["Transpose","","1+",z.transpose,z.parseTransposeAttributes],["Upsample","","7-8",K.upsample,K.parseUpsampleAttributesV7],["Upsample","","9",K.upsample,K.parseUpsampleAttributesV9],["Unsqueeze","","1-12",U.unsqueeze,U.parseUnsqueezeAttributes],["Unsqueeze","","13+",U.unsqueezeV13],["Xor","","7+",h.xor]]},2898:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseBatchNormalizationAttributes=e.batchNormalization=void 0;const r=t(246),o=t(5060),c=t(2039),l={name:"BatchNormalization",inputNames:["A","Scale","B","Mean","Variance"],inputTypes:[c.TextureType.unpacked,c.TextureType.unpacked,c.TextureType.unpacked,c.TextureType.unpacked,c.TextureType.unpacked]};e.batchNormalization=(f,d,i)=>(p(d),[f.run(Object.assign(Object.assign({},l),{cacheHint:i.cacheKey,get:()=>h(f,d,i)}),d)]),e.parseBatchNormalizationAttributes=f=>{const d=f.attributes.getFloat("epsilon",1e-5),i=f.attributes.getFloat("momentum",.9),n=f.attributes.getInt("spatial",1);return(0,r.createAttributeWithCacheKey)({epsilon:d,momentum:i,spatial:n})};const h=(f,d,i)=>{const n=(0,o.getGlsl)(f.session.backend.glContext.version),a=d[0].dims.length,[u,m]=f.calculateTextureWidthAndHeight(d[1].dims,c.TextureType.unpacked),g=` float process(int[${a}] indices) { vec2 position = offsetToCoords(indices[1], ${u}, ${m}); float scale = getColorAsFloat(${n.texture2D}(Scale, position)); float mean = getColorAsFloat(${n.texture2D}(Mean, position)); float variance = getColorAsFloat(${n.texture2D}(Variance, position)); float b = getColorAsFloat(${n.texture2D}(B, position)); return scale * ( (_A(indices) - mean) / sqrt(variance + float(${i.epsilon})) ) + b; }`;return Object.assign(Object.assign({},l),{output:{dims:d[0].dims,type:d[0].type,textureType:c.TextureType.unpacked},shaderSource:g})},p=f=>{if(!f||f.length!==5)throw new Error("BatchNormalization requires 5 inputs.");const d=f[0],i=f[1],n=f[2],a=f[3],u=f[4];if(d.dims.length<3||i.dims.length!==1||n.dims.length!==1||a.dims.length!==1||u.dims.length!==1)throw new Error("invalid input shape.");if(i.dims[0]!==d.dims[1]||n.dims[0]!==d.dims[1]||a.dims[0]!==d.dims[1]||u.dims[0]!==d.dims[1])throw new Error("invalid input shape.");if(d.type!=="float32"&&d.type!=="float64"||i.type!=="float32"&&i.type!=="float64"||n.type!=="float32"&&n.type!=="float64"||a.type!=="float32"&&a.type!=="float64"||u.type!=="float32"&&u.type!=="float64")throw new Error("invalid input tensor types.")}},7839:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.xor=e.sub=e.pRelu=e.pow=e.or=e.mul=e.less=e.greater=e.equal=e.div=e.and=e.add=e.glslPRelu=e.glslPow=e.glslXor=e.glslOr=e.glslAnd=e.glslLess=e.glslGreater=e.glslEqual=e.glslSub=e.glslMul=e.glslDiv=e.glslAdd=void 0;const r=t(2517),o=t(8520),c=t(5060),l=t(2039);function h(){const x="add_";return{body:` float ${x}(float a, float b) { return a + b; } vec4 ${x}(vec4 v1, vec4 v2) { return v1 + v2; } `,name:x,type:o.FunctionType.ValueBased}}function p(){const x="div_";return{body:` float ${x}(float a, float b) { return a / b; } vec4 ${x}(vec4 v1, vec4 v2) { return v1 / v2; } `,name:x,type:o.FunctionType.ValueBased}}function f(){const x="mul_";return{body:` float ${x}(float a, float b) { return a * b; } vec4 ${x}(vec4 v1, vec4 v2) { return v1 * v2; } `,name:x,type:o.FunctionType.ValueBased}}function d(){const x="sub_";return{body:` float ${x}(float a, float b) { return a - b; } vec4 ${x}(vec4 v1, vec4 v2) { return v1 - v2; } `,name:x,type:o.FunctionType.ValueBased}}function i(){const x="equal_";return{body:` float ${x}(float a, float b) { return float(a == b); } vec4 ${x}(vec4 v1, vec4 v2) { return vec4(equal(v1, v2)); } `,name:x,type:o.FunctionType.ValueBased}}function n(){const x="greater_";return{body:` float ${x}(float a, float b) { return float(a > b); } vec4 ${x}(vec4 v1, vec4 v2) { return vec4( v1.r > v2.r , v1.g > v2.g, v1.b > v2.b, v1.a > v2.a ); } `,name:x,type:o.FunctionType.ValueBased}}function a(){const x="less_";return{body:` float ${x}(float a, float b) { return float(a < b); } vec4 ${x}(vec4 v1, vec4 v2) { return vec4( v1.r < v2.r , v1.g < v2.g, v1.b < v2.b, v1.a < v2.a ); } `,name:x,type:o.FunctionType.ValueBased}}function u(){const x="and_";return{body:` float ${x}(float a, float b) { return float( bool(a) && bool(b) ); } vec4 ${x}(vec4 v1, vec4 v2) { bvec4 b1 = bvec4(v1); bvec4 b2 = bvec4(v2); return vec4( b1.r && b2.r , b1.g && b2.g, b1.b && b2.b, b1.a && b2.a ); } `,name:x,type:o.FunctionType.ValueBased}}function m(){const x="or_";return{body:` float ${x}(float a, float b) { return float( bool(a) || bool(b) ); } vec4 ${x}(vec4 v1, vec4 v2) { bvec4 b1 = bvec4(v1); bvec4 b2 = bvec4(v2); return vec4( b1.r || b2.r , b1.g || b2.g, b1.b || b2.b, b1.a || b2.a ); } `,name:x,type:o.FunctionType.ValueBased}}function g(){const x="xor_";return{body:` float ${x}(float a, float b) { return float( bool(a) ^^ bool(b) ); } vec4 ${x}(vec4 v1, vec4 v2) { bvec4 b1 = bvec4(v1); bvec4 b2 = bvec4(v2); return vec4( b1.r ^^ b2.r , b1.g ^^ b2.g, b1.b ^^ b2.b, b1.a ^^ b2.a ); } `,name:x,type:o.FunctionType.ValueBased}}function _(){return function(x){const w=`${x}_`;return{body:` float ${w}(float a, float b) { return ${x}(a, b); } vec4 ${w}(vec4 v1, vec4 v2) { return ${x}(v1, v2); } `,name:w,type:o.FunctionType.ValueBased}}("pow")}function b(){const x="prelu_";return{body:` float ${x}(float a, float b) { return a < 0.0 ? a * b: a; } vec4 ${x}(vec4 v1, vec4 v2) { return vec4( v1.r < 0.0 ? v1.r * v2.r: v1.r, v1.g < 0.0 ? v1.g * v2.g: v1.g, v1.b < 0.0 ? v1.b * v2.b: v1.b, v1.a < 0.0 ? v1.a * v2.a: v1.a ); } `,name:x,type:o.FunctionType.ValueBased}}e.glslAdd=h,e.glslDiv=p,e.glslMul=f,e.glslSub=d,e.glslEqual=i,e.glslGreater=n,e.glslLess=a,e.glslAnd=u,e.glslOr=m,e.glslXor=g,e.glslPow=_,e.glslPRelu=b;const y=(x,w,S,M=w[0].type,T)=>{const E=x.session.pack?l.TextureType.packed:l.TextureType.unpacked;return{name:S.name,inputNames:["A","B"],inputTypes:[E,E],cacheHint:T,get:()=>v(x,w,S,M)}},v=(x,w,S,M=w[0].type)=>{const T=x.session.pack?l.TextureType.packed:l.TextureType.unpacked,E=!r.ShapeUtil.areEqual(w[0].dims,w[1].dims);let R=w[0].dims;const I=x.session.pack;if(E){const z=r.BroadcastUtil.calcShape(w[0].dims,w[1].dims,!1);if(!z)throw new Error("Can't perform binary op on the given tensors");R=z;const O=R.length,U=w[0].dims.length!==0?w[0].dims.length:1,K=w[1].dims.length!==0?w[1].dims.length:1,$=w[0].dims.length!==0?"bcastIndices_A(indices, aindices);":"aindices[0] = 0;",J=w[1].dims.length!==0?"bcastIndices_B(indices, bindices);":"bindices[0] = 0;",ee=(0,c.getGlsl)(x.session.backend.glContext.version),he=I?` ${S.body} void main() { vec4 a = getAAtOutCoords(); vec4 b = getBAtOutCoords(); vec4 result = ${S.name}(a, b); ${ee.output} = result; }`:` ${S.body} float process(int indices[${O}]) { int aindices[${U}]; int bindices[${K}]; ${$} ${J} return ${S.name}(_A(aindices), _B(bindices)); }`;return{name:S.name,inputNames:["A","B"],inputTypes:[T,T],output:{dims:R,type:M,textureType:T},shaderSource:he,hasMain:I}}const k=(0,c.getGlsl)(x.session.backend.glContext.version),C=` ${S.body} void main() { vec4 v1 = ${k.texture2D}(A, TexCoords); vec4 v2 = ${k.texture2D}(B, TexCoords); vec4 result = ${S.name}(v1, v2); ${k.output} = result; } `;return{name:S.name,inputNames:["A","B"],inputTypes:[T,T],output:{dims:w[0].dims,type:M,textureType:T},shaderSource:C,hasMain:!0}};e.add=(x,w)=>[x.run(y(x,w,h()),w)],e.and=(x,w)=>[x.run(y(x,w,u(),"bool"),w)],e.div=(x,w)=>[x.run(y(x,w,p()),w)],e.equal=(x,w)=>[x.run(y(x,w,i(),"bool"),w)],e.greater=(x,w)=>[x.run(y(x,w,n(),"bool"),w)],e.less=(x,w)=>[x.run(y(x,w,a(),"bool"),w)],e.mul=(x,w)=>[x.run(y(x,w,f()),w)],e.or=(x,w)=>[x.run(y(x,w,m(),"bool"),w)],e.pow=(x,w)=>[x.run(y(x,w,_()),w)],e.pRelu=(x,w)=>[x.run(y(x,w,b()),w)],e.sub=(x,w)=>[x.run(y(x,w,d()),w)],e.xor=(x,w)=>[x.run(y(x,w,g(),"bool"),w)]},4196:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseCastAttributes=e.cast=void 0;const r=t(2517);e.cast=(c,l,h)=>(o(l),[c.cast(l[0],h)]),e.parseCastAttributes=c=>r.ProtoUtil.tensorDataTypeFromProto(c.attributes.getInt("to"));const o=c=>{if(!c||c.length!==1)throw new Error("Cast requires 1 input.");if(c[0].type==="string")throw new Error("Invalid input type.")}},1163:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createPackedConcatProgramInfoLoader=void 0;const r=t(5060),o=t(2039),c=t(9390),l=t(2827);e.createPackedConcatProgramInfoLoader=(p,f,d)=>{const i=(n=f.length,a=d.cacheKey,{name:"Concat (packed)",inputNames:Array.from({length:n},(u,m)=>`X${m}`),inputTypes:Array(n).fill(o.TextureType.packed),cacheHint:a});var n,a;return Object.assign(Object.assign({},i),{get:()=>((u,m,g,_)=>{const b=g[0].dims.slice();if(_>=b.length||_<-1*b.length)throw new Error("axis specified for concat doesn't match input dimensionality");_<0&&(_=b.length+_);const y=b.slice(0);for(let $=1;$$.dims),T=(0,c.getGlChannels)(v),E=new Array(M.length-1);E[0]=M[0][_];for(let $=1;$= ${E[$-1]}) { return getChannel( getX${$}(${h(T,R,J)}), vec2(${h(I,R,J)})); }`}const z=E.length,O=E[E.length-1];C+=` return getChannel( getX${z}(${h(T,R,O)}), vec2(${h(I,R,O)}));`;const U=(0,r.getGlsl)(u.session.backend.glContext.version),K=` ${S} float getValue(${T.map($=>"int "+$)}) { ${C} } void main() { ${w} coords = getOutputCoords(); int lastDim = coords.${T[v-1]}; coords.${T[v-1]} = coords.${T[v-2]}; coords.${T[v-2]} = lastDim; vec4 result = vec4(getValue(${x}), 0., 0., 0.); ${x[v-1]} = ${x[v-1]} + 1; if (${x[v-1]} < ${y[v-1]}) { result.g = getValue(${x}); } ${x[v-2]} = ${x[v-2]} + 1; if (${x[v-2]} < ${y[v-2]}) { result.a = getValue(${x}); } ${x[v-1]} = ${x[v-1]} - 1; if (${x[v-2]} < ${y[v-2]} && ${x[v-1]} < ${y[v-1]}) { result.b = getValue(${x}); } ${U.output} = result; } `;return Object.assign(Object.assign({},m),{output:{dims:y,type:g[0].type,textureType:o.TextureType.packed},shaderSource:K,hasMain:!0})})(p,i,f,d.axis)})};const h=(p,f,d)=>{const i=p.indexOf(f);return p.map((n,a)=>a===i?`${n} - ${d}`:n).join()}},2069:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseConcatAttributes=e.concat=void 0;const r=t(246),o=t(2039),c=t(1163);e.concat=(n,a,u)=>(i(a),n.session.pack&&a[0].dims.length>1?[n.run((0,c.createPackedConcatProgramInfoLoader)(n,a,u),a)]:[n.run(l(n,a,u),a)]);const l=(n,a,u)=>{const m=(g=a.length,_=u.cacheKey,{name:"Concat",inputNames:Array.from({length:g},(b,y)=>`X${y}`),inputTypes:Array(g).fill(o.TextureType.unpacked),cacheHint:_});var g,_;return Object.assign(Object.assign({},m),{get:()=>((b,y,v,x)=>{const w=v[0].dims.slice();if(x>=w.length||x<-1*w.length)throw new Error("axis specified for concat doesn't match input dimensionality");x<0&&(x=w.length+x);const S=w.slice(0);for(let k=1;k`int getTextureWhereDataResides(int index) { ${n.map((a,u)=>`if(index<${a}) {return ${u};} `).join("")} }`,p=n=>h(n),f=(n,a)=>{const u=[`float fetchDataFromCorrectTexture(int textureIndex, int indices[${a}]) {`];for(let m=0;m{const a=["int getSizeInConcatAxisValueFromIndex(int index) {"];for(let u=0;u(0,r.createAttributeWithCacheKey)({axis:n.attributes.getInt("axis")});const i=n=>{if(!n||n.length<1)throw new Error("too few inputs");const a=n[0].type,u=n[0].dims.length;if(a==="string")throw new Error("string tensor is not supported yet");for(const m of n){if(m.type!==a)throw new Error("input tensors should be one type");if(m.dims.length!==u)throw new Error("input tensors should have the same shape")}}},4770:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createUnpackedGroupedConvProgramInfoLoader=void 0;const r=t(6231),o=t(5060),c=t(2039),l=t(8138),h=t(2823);e.createUnpackedGroupedConvProgramInfoLoader=(p,f,d)=>{const i=(n=f.length>2,a=d.cacheKey,{name:"GroupedConv",inputNames:n?["X","W","Bias"]:["X","W"],inputTypes:n?[c.TextureType.unpacked,c.TextureType.unpacked,c.TextureType.unpacked]:[c.TextureType.unpacked,c.TextureType.unpacked],cacheHint:a});var n,a;return Object.assign(Object.assign({},i),{get:()=>((u,m,g,_)=>{const b=m.length>2?"value += getBias(output_channel);":"",y=m[0].dims.slice(),v=m[1].dims.slice(),x=v[0]/_.group;r.Logger.verbose("GroupedConv",`autpPad:${_.autoPad}, dilations:${_.dilations}, group:${_.group}, kernelShape:${_.kernelShape}, pads:${_.pads}, strides:${_.strides}`);const w=(0,l.calculateOutputShape)(y,v,_.dilations,_.pads,_.strides),S=(0,o.getGlsl)(u.session.backend.glContext.version),{activationFunction:M,applyActivation:T}=(0,h.getActivationSnippet)(_),E=` const ivec2 strides = ivec2(${_.strides[0]}, ${_.strides[1]}); const ivec2 pads = ivec2(${_.pads[0]}, ${_.pads[1]}); ${M} void main() { ivec4 coords = getOutputCoords(); int batch = coords.x; int output_channel = coords.y; ivec2 xRCCorner = coords.zw * strides - pads; int group_id = output_channel / ${x}; float value = 0.0; for (int wInChannel = 0; wInChannel < ${v[1]}; wInChannel++) { int input_channel = group_id * ${v[1]} + wInChannel; for (int wHeight = 0; wHeight < ${v[2]}; wHeight++) { int xHeight = xRCCorner.x + wHeight * ${_.dilations[0]}; if (xHeight < 0 || xHeight >= ${y[2]}) { continue; } for (int wWidth = 0; wWidth < ${v[3]}; wWidth++) { int xWidth = xRCCorner.y + wWidth * ${_.dilations[1]}; if (xWidth < 0 || xWidth >= ${y[3]}) { continue; } float xVal = getX(batch, input_channel, xWidth, xHeight); float wVal = getW(output_channel, wInChannel, wWidth, wHeight); value += xVal*wVal; } } } ${b} ${T} ${S.output} = vec4(value, .0, .0, .0); } `;return Object.assign(Object.assign({},g),{output:{dims:w,type:m[0].type,textureType:c.TextureType.unpacked},shaderSource:E,hasMain:!0})})(p,f,i,d)})}},1386:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.conv2DPacked=e.conv2DPackedPointwise=void 0;const r=t(8138),o=t(8555),c=t(708);e.conv2DPackedPointwise=(l,h,p)=>{const f=h[0].dims,d=h[1].dims,i=(0,r.calculateOutputShape)(f,d,p.dilations,p.pads,p.strides),n=l.reshapePacked(h[0],[f[1],f[2]*f[3]]),a=l.reshapePacked(h[1],[d[0],d[1]]),u=h.length>2?[a,n,h[2]]:[a,n],m=l.run((0,c.createPackedMatmulProgramInfoLoader)(l,u,p),u);return l.reshapePacked(m,i)},e.conv2DPacked=(l,h,p)=>{const f=h[0].dims,d=h[1].dims,i=(0,r.calculateOutputShape)(f,d,p.dilations,p.pads,p.strides),n=l.run((0,o.createPackedIm2ColProgramInfoLoader)(l,h[0],h[1],i,p),[h[0]]),a=l.reshapePacked(h[1],[d[0],d[1]*d[2]*d[3]]),u=h.length===3?[a,n,h[2]]:[a,n],m=l.run((0,c.createPackedMatmulProgramInfoLoader)(l,u,p),u);return l.reshapePacked(m,i)}},9663:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseConvTransposeAttributes=e.convTranspose=void 0;const r=t(246),o=t(5060),c=t(2039),l=t(2823),h=(a,u,m,g,_,b)=>(a-1)*u+m+(g-1)*_+1-b,p=(a,u,m,g,_)=>{const b=Math.floor(a/2);u==="SAME_UPPER"?(m[g]=b,m[_]=a-b):u==="SAME_LOWER"&&(m[g]=a-b,m[_]=b)};e.convTranspose=(a,u,m)=>(n(u,m),f(a,u,m));const f=(a,u,m)=>{const g=i(m,u);return[d(a,u,g)]},d=(a,u,m)=>a.run(((g,_,b)=>{const y=(v=_.length>2,x=b.cacheKey,{name:"ConvTranspose",inputNames:v?["X","W","B"]:["X","W"],inputTypes:v?[c.TextureType.unpacked,c.TextureType.unpacked,c.TextureType.unpacked]:[c.TextureType.unpacked,c.TextureType.unpacked],cacheHint:x});var v,x;return Object.assign(Object.assign({},y),{get:()=>((w,S,M,T)=>{const E=S.length>2?"getB(output_channel)":"0.0",R=S[0].dims,I=S[1].dims,k=I[1],C=I[0]/T.group,z=[S[0].dims[0],S[1].dims[1]*T.group,...T.outputShape],O=(0,o.getGlsl)(w.session.backend.glContext.version),{activationFunction:U,applyActivation:K}=(0,l.getActivationSnippet)(T),$=` const ivec2 strides = ivec2(${T.strides[0]}, ${T.strides[1]}); const ivec2 pads = ivec2(${T.pads[0]}, ${T.pads[1]}); ${U} void main() { ivec4 coords = getOutputCoords(); int batch = coords.x; int output_channel = coords.y; ivec2 loc = coords.zw + pads; int group_id = output_channel / ${k}; int wOutChannel = output_channel - group_id * ${k}; float value = ${E}; for (int inChannelOffset = 0; inChannelOffset < ${C}; inChannelOffset++) { int input_channel = group_id * ${C} + inChannelOffset; for (int wWOff = 0; wWOff < ${I[2]}; wWOff++) { for (int wHOff = 0; wHOff < ${I[3]}; wHOff++) { ivec2 wOff = ivec2(wWOff * ${T.dilations[0]}, wHOff * ${T.dilations[1]}); ivec2 wLoc = loc - wOff; ivec2 wLocIn = wLoc / strides; if ( wLocIn * strides == wLoc && wLocIn.x >= 0 && wLocIn.x < ${R[2]} && wLocIn.y >= 0 && wLocIn.y < ${R[3]} ) { float xVal = getX(batch, input_channel, wLocIn.y, wLocIn.x); float wVal = getW(input_channel, wOutChannel, wHOff, wWOff); value += xVal * wVal; } } } } ${K} ${O.output} = vec4(value, .0, .0, .0); } `;return Object.assign(Object.assign({},M),{output:{dims:z,type:S[0].type,textureType:c.TextureType.unpacked},shaderSource:$,hasMain:!0})})(g,_,y,b)})})(a,u,m),u),i=(a,u)=>{const m=a.kernelShape.slice();if(a.kernelShape.length===0)for(let y=2;y{const R=y.length-2,I=E.length===0;for(let k=0;k{const u=a.attributes,m=(0,l.parseInternalActivationAttributes)(u),g=u.getString("auto_pad","NOTSET"),_=u.getInts("dilations",[1,1]),b=u.getInt("group",1),y=u.getInts("kernel_shape",[]),v=u.getInts("output_padding",[0,0]),x=u.getInts("output_shape",[]),w=u.getInts("pads",[0,0,0,0]),S=u.getInts("strides",[1,1]);return(0,r.createAttributeWithCacheKey)(Object.assign({autoPad:g,dilations:_,group:b,kernelShape:y,outputPadding:v,outputShape:x,pads:w,strides:S},m))};const n=(a,u)=>{if(!a||a.length!==2&&a.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(a[0].dims.length!==4||a[1].dims.length!==4)throw new Error("currently only support 2-dimensional conv");if(a[0].dims[1]!==a[1].dims[0])throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");const m=a[1].dims[1]*u.group;if(a.length===3&&(a[2].dims.length!==1||a[2].dims[0]!==m))throw new Error("invalid bias");const g=a[0].dims.length-2;if(u.dilations.length!==g)throw new Error(`dilations should be ${g}D`);if(u.strides.length!==g)throw new Error(`strides should be ${g}D`);if(u.pads.length!==2*g)throw new Error(`pads should be ${2*g}D`);if(u.outputPadding.length!==g)throw new Error(`output_padding should be ${g}D`);if(u.kernelShape.length!==0&&u.kernelShape.length!==a[1].dims.length-2)throw new Error("invalid kernel shape");if(u.outputShape.length!==0&&u.outputShape.length!==a[0].dims.length-2)throw new Error("invalid output shape");if(a[0].type!=="float32"||a[1].type!=="float32")throw new Error("ConvTranspose input(X,W) should be float tensor");if(a.length===3&&a[2].type!=="float32")throw new Error("ConvTranspose input(bias) should be float tensor")}},8138:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseConvAttributes=e.conv=e.calculateOutputShape=void 0;const r=t(246),o=t(2517),c=t(4770),l=t(1386),h=t(9828),p=t(2823),f=t(3248),d=t(5623);e.calculateOutputShape=(g,_,b,y,v)=>{const x=g[0],w=g.slice(2),S=w.length,M=_[0],T=_.slice(2).map((R,I)=>R+(R-1)*(b[I]-1)),E=w.map((R,I)=>R+y[I]+y[I+S]).map((R,I)=>Math.floor((R-T[I]+v[I])/v[I]));return[x,M].concat(...E)},e.conv=(g,_,b)=>(m(_,b),i(g,_,b));const i=(g,_,b)=>{const y=u(b,_),v=g.session.pack,x=y.kernelShape[0]===1&&y.kernelShape[1]===1;return y.group>1?[g.run((0,c.createUnpackedGroupedConvProgramInfoLoader)(g,_,y),_)]:x&&v?[n(g,_,y)]:v&&_[0].dims.length===4&&_[0].dims[0]===1&&!x?[(0,l.conv2DPacked)(g,_,y)]:[a(g,_,y)]},n=(g,_,b)=>{const y=_[0].dims,v=_[1].dims,x=(0,e.calculateOutputShape)(y,v,b.dilations,b.pads,b.strides),w=g.reshapeUnpacked(_[0],[y[1],y[2]*y[3]]),S=g.reshapeUnpacked(_[1],[v[0],v[1]]),M=_.length>2?[S,w,_[2]]:[S,w],T=g.run((0,d.createMatmulProgramInfoLoader)(M,b),M);return g.reshapeUnpacked(T,x)},a=(g,_,b)=>{const y=_[0].dims,v=_[1].dims,x=(0,e.calculateOutputShape)(y,v,b.dilations,b.pads,b.strides),w=g.run((0,f.createIm2ColProgramInfoLoader)(g,_[0],_[1],x,b),[_[0]]),S=_.length===3?[w,_[1],_[2]]:[w,_[1]];return g.run((0,h.createDotProductProgramInfoLoader)(g,_,x,b),S)},u=(g,_)=>{const b=g.kernelShape.slice();if(g.kernelShape.length===0)for(let x=2;x<_[1].dims.length;++x)b.push(_[1].dims[x]);const y=g.pads.slice();o.PoolConvUtil.adjustPadsBasedOnAutoPad(_[0].dims,g.strides,g.dilations,b,y,g.autoPad);const v=Object.assign({},g);return Object.assign(v,{kernelShape:b,pads:y,cacheKey:g.cacheKey}),v};e.parseConvAttributes=g=>{const _=g.attributes,b=(0,p.parseInternalActivationAttributes)(_),y=_.getString("auto_pad","NOTSET"),v=_.getInts("dilations",[1,1]),x=_.getInt("group",1),w=_.getInts("kernel_shape",[]),S=_.getInts("pads",[0,0,0,0]),M=_.getInts("strides",[1,1]);return(0,r.createAttributeWithCacheKey)(Object.assign({autoPad:y,dilations:v,group:x,kernelShape:w,pads:S,strides:M},b))};const m=(g,_)=>{if(!g||g.length!==2&&g.length!==3)throw new Error("Conv requires 2 or 3 inputs");if(g[0].dims.length!==4||g[1].dims.length!==4)throw new Error("currently only support 2-dimensional conv");if(g[0].dims[1]!==g[1].dims[1]*_.group)throw new Error("FILTER_IN_CHANNEL should be equal to DATA_CHANNEL");if(g.length===3&&(g[2].dims.length!==1||g[1].dims[0]!==g[2].dims[0]))throw new Error("invalid bias");const b=g[0].dims.length-2;if(_.dilations.length!==b)throw new Error(`dilations should be ${b}D`);if(_.strides.length!==b)throw new Error(`strides should be ${b}D`);if(_.pads.length!==2*b)throw new Error(`pads should be ${2*b}D`);if(_.kernelShape.length!==0&&_.kernelShape.length!==g[1].dims.length-2)throw new Error("invalid kernel shape");if(g[0].type!=="float32"||g[1].type!=="float32")throw new Error("Conv input(X,W) should be float tensor");if(g.length===3&&g[2].type!=="float32")throw new Error("Conv input(bias) should be float tensor")}},5193:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseDepthToSpaceAttributes=e.depthToSpace=void 0;const r=t(3738);e.depthToSpace=(c,l,h)=>{o(l);const p=h.blocksize,f=p*p,d=h.mode==="DCR"?[0,3,4,1,5,2]:[0,1,4,2,5,3],i=h.mode==="DCR"?[l[0].dims[0],p,p,l[0].dims[1]/f,l[0].dims[2],l[0].dims[3]]:[l[0].dims[0],l[0].dims[1]/f,p,p,l[0].dims[2],l[0].dims[3]],n=c.reshapeUnpacked(l[0],i),a={perm:d,cacheKey:`${d}`},[u]=(0,r.transpose)(c,[n],a),m=[l[0].dims[0],l[0].dims[1]/f,l[0].dims[2]*p,l[0].dims[3]*p];return[c.reshapeUnpacked(u,m)]},e.parseDepthToSpaceAttributes=c=>{const l=c.attributes.getInt("blocksize");if(l<1)throw new Error(`blocksize must be >= 1, but got : ${l} for DepthToSpace`);const h=c.attributes.getString("mode","DCR");if(h!=="DCR"&&h!=="CRD")throw new Error(`unrecognized mode: ${h} for DepthToSpace`);return{mode:h,blocksize:l}};const o=c=>{if(c.length!==1)throw new Error(`DepthToSpace expect 1 inputs, but got ${c.length}`);if(c[0].type==="string"||c[0].dims.length!==4)throw new TypeError("DepthToSpace input should be a 4-D numeric tensor")}},9828:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createDotProductProgramInfoLoader=void 0;const r=t(2517),o=t(5060),c=t(2039),l=t(2823),h=t(3248);e.createDotProductProgramInfoLoader=(p,f,d,i)=>{const n=((a,u)=>({name:"ConvDotProduct",inputNames:a?["Im2Col","K","B"]:["Im2Col","K"],inputTypes:a?[c.TextureType.unpacked,c.TextureType.packedLastDimension,c.TextureType.unpacked]:[c.TextureType.unpacked,c.TextureType.packedLastDimension],cacheKey:u.activationCacheKey}))(f.length>2,i);return Object.assign(Object.assign({},n),{get:()=>((a,u,m,g,_)=>{const b=m[0].dims,y=m[1].dims,v=[y[0],Math.ceil(b[1]*y[2]*y[3]/4)],x=(0,h.calculateIm2ColDims)(b,y,g),[w,S]=a.calculateTextureWidthAndHeight(v,c.TextureType.packedLastDimension),M=r.ShapeUtil.computeStrides(x),[T,E]=a.calculateTextureWidthAndHeight(x,c.TextureType.packedLastDimension),R=g.length,I=m.length<3?"0.0":"_B(b)",k=Math.ceil(b[1]*y[2]*y[3]/4),{activationFunction:C,applyActivation:z}=(0,l.getActivationSnippet)(_),O=(0,o.getGlsl)(a.session.backend.glContext.version),U=` ${C} float process(int indices[${R}]) { int b[1]; b[0] = indices[1]; int im2col[4]; im2col[0] = indices[0]; im2col[1] = indices[2]; im2col[2] = indices[3]; int im2colOffset = im2col[0] * ${M[0]} + im2col[1] * ${M[1]} + im2col[2] * ${M[2]}; int kernelOffset = indices[1] * ${v[1]}; float value = ${I}; for (int i = 0; i < ${k}; ++i) { vec2 im2colCoords = offsetToCoords(im2colOffset, ${T}, ${E}); vec2 kernelCoords = offsetToCoords(kernelOffset, ${w}, ${S}); value += dot(${O.texture2D}(Im2Col, im2colCoords), ${O.texture2D}(K, kernelCoords)); ++im2colOffset; ++kernelOffset; } ${z} return value; }`;return Object.assign(Object.assign({},u),{output:{dims:g,type:m[0].type,textureType:c.TextureType.unpacked},shaderSource:U})})(p,n,f,d,i)})}},7992:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseFlattenAttributes=e.flatten=void 0;const r=t(2517);e.flatten=(c,l,h)=>{o(l,h);const p=r.ShapeUtil.flattenShape(l[0].dims,h);return[c.reshapeUnpacked(l[0],p)]},e.parseFlattenAttributes=c=>c.attributes.getInt("axis",1);const o=(c,l)=>{if(!c||c.length!==1)throw new Error("Flatten requires 1 input.");const h=c[0].dims.length;if(h===0)throw new Error("scalar tensor is not supported.");if(l<-h||l>h)throw new Error("Invalid axis");if(c[0].type==="string")throw new Error("string tensor is not supported.")}},2823:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseInternalActivationAttributes=e.getActivationSnippet=void 0;const r=t(2517),o=t(4909);e.getActivationSnippet=function(c){let l;switch(c.activation){case"Relu":l=(0,o.glslRelu)();break;case"Sigmoid":l=(0,o.glslSigmoid)();break;case"Clip":l=(0,o.glslClip)(c.clipMin,c.clipMax);break;default:return{activationFunction:"",applyActivation:""}}const h=l.name;return{activationFunction:l.body,applyActivation:`value = ${h}_(value);`}},e.parseInternalActivationAttributes=c=>{const l=c.getString("activation","");if(l==="Clip"){const[h,p]=c.getFloats("activation_params",[r.MIN_CLIP,r.MAX_CLIP]);return{activation:l,clipMax:p,clipMin:h,activationCacheKey:`${l}:${h},${p}`}}return{activation:l,activationCacheKey:l}}},1253:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseGatherAttributes=e.gather=void 0;const r=t(246),o=t(782),c=t(2517),l=t(2039);e.gather=(d,i,n)=>(f(i,n.axis),[d.run(p(d,i,n),i)]),e.parseGatherAttributes=d=>(0,r.createAttributeWithCacheKey)({axis:d.attributes.getInt("axis",0)});const h={name:"Gather",inputNames:["A","B"],inputTypes:[l.TextureType.unpacked,l.TextureType.unpacked]},p=(d,i,n)=>{const a=Object.assign(Object.assign({},h),{cacheHint:n.cacheKey});return Object.assign(Object.assign({},a),{get:()=>((u,m,g,_)=>{const b=g[0].dims.slice(),y=g[1].dims.slice(),v=new Array(b.length+y.length-1);_=c.ShapeUtil.normalizeAxis(_,b.length);const x=[];for(let S=0;S{if(!d||d.length!==2)throw new Error("Gather requires 2 inputs.");const n=d[0].dims.length;if(n<1)throw new Error("Invalid input shape.");if(i<-n||i>n-1)throw new Error("Invalid axis.");if(o.NUMBER_TYPES.indexOf(d[0].type)===-1)throw new Error("Invaid input type.");if(d[1].type!=="int32"&&d[1].type!=="int16")throw new Error("Invaid input type.")}},4776:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseGemmAttributesV11=e.parseGemmAttributesV7=e.gemm=void 0;const r=t(246),o=t(2517),c=t(2039);e.gemm=(d,i,n)=>(f(i,n),[d.run(h(i,n),i)]);const l=(d,i)=>{const n=d.attributes.getInt("transA",0)!==0,a=d.attributes.getInt("transB",0)!==0,u=d.attributes.getFloat("alpha",1),m=d.attributes.getFloat("beta",1);return(0,r.createAttributeWithCacheKey)({transA:n,transB:a,alpha:u,beta:m,isOptionalC:i})};e.parseGemmAttributesV7=d=>l(d,!1),e.parseGemmAttributesV11=d=>l(d,!0);const h=(d,i)=>{const n={name:"Gemm",inputNames:d.length===3?["A","B","C"]:["A","B"],inputTypes:d.length===3?[c.TextureType.unpacked,c.TextureType.unpacked,c.TextureType.unpacked]:[c.TextureType.unpacked,c.TextureType.unpacked],key:i.cacheKey};return Object.assign(Object.assign({},n),{get:()=>p(n,d,i)})},p=(d,i,n)=>{const a=i[0].dims.slice(),u=i[1].dims.slice(),[m,g]=o.GemmUtil.getShapeOfGemmResult(a,n.transA,u,n.transB,i.length===3?i[2].dims:void 0),_=[m,g];if(!_)throw new Error("Can't use gemm on the given tensors");let b=a[a.length-1],y="";n.transA&&(b=a[0]),n.transA&&n.transB?y="value += _A_T(a) * _B_T(b);":n.transA&&!n.transB?y="value += _A_T(a) * _B(b);":!n.transA&&n.transB?y="value += _A(a) * _B_T(b);":n.transA||n.transB||(y="value += _A(a) * _B(b);");const v=_.length,x=` float process(int indices[${v}]) { int a[${v}]; int b[${v}]; ${i.length===3?`int c[${i[2].dims.length}];`:""} copyVec(indices, a); copyVec(indices, b); ${i.length===3?"bcastIndices_C(indices, c);":""} float value = 0.0; for (int k=0; k<${b}; ++k) { a[${v-1}] = k; b[${v-2}] = k; ${y} } value = value * alpha; ${i.length===3?"value += beta * _C(c);":""} return value; }`;return Object.assign(Object.assign({},d),{output:{dims:_,type:i[0].type,textureType:c.TextureType.unpacked},variables:[{name:"alpha",type:"float",data:n.alpha},{name:"beta",type:"float",data:n.beta}],shaderSource:x})},f=(d,i)=>{if(!d)throw new Error("Input is missing");if(i.isOptionalC&&(d.length<2||d.length>3))throw new Error("Invaid input shape.");if(!i.isOptionalC&&d.length!==3)throw new Error("Gemm requires 3 inputs");if(d.length===3&&d[2].dims.length!==1&&d[2].dims.length!==2)throw new Error("Invalid input shape of C");if(d[0].type!=="float32"&&d[0].type!=="float64"||d[1].type!=="float32"&&d[1].type!=="float64"||d.length===3&&d[2].type!=="float32"&&d[2].type!=="float64")throw new Error("Invalid input type.");if(d[0].type!==d[1].type||d.length===3&&d[0].type!==d[2].type)throw new Error("Input types are mismatched")}},8555:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createPackedIm2ColProgramInfoLoader=void 0;const r=t(5060),o=t(2039),c=t(2827);e.createPackedIm2ColProgramInfoLoader=(l,h,p,f,d)=>{const i=(n=d.cacheKey,{name:"Im2Col (packed)",inputNames:["A"],inputTypes:[o.TextureType.packed],cacheHint:n});var n;return Object.assign(Object.assign({},i),{get:()=>((a,u,m,g,_,b)=>{const y=m.dims,v=g.dims,x=_.length,w=[v[1]*v[2]*v[3],_[2]*_[3]],S=v[2]*v[3],M=(0,c.unpackFromChannel)(),T=(0,r.getGlsl)(a.session.backend.glContext.version);let E="";for(let I=0;I<=1;I++)for(let k=0;k<=1;k++)E+=` blockIndex = rc.x + ${k}; pos = rc.y + ${I}; if(blockIndex < ${w[1]} && pos < ${w[0]}) { offsetY = int(blockIndex / (${_[x-1]})) * ${b.strides[0]} - ${b.pads[0]}; d0 = offsetY + ${b.dilations[0]} * (imod(pos, ${S}) / ${v[2]}); if(d0 < ${y[2]} && d0 >= 0) { offsetX = imod(blockIndex, ${_[x-1]}) * ${b.strides[1]} - ${b.pads[1]}; d1 = offsetX + ${b.dilations[1]} * imod(imod(pos, ${S}), ${v[2]}); if(d1 < ${y[3]} && d1 >= 0) { ch = int(float(pos)/ ${S}.); innerDims = vec2(d0, d1); result[${2*I+k}] = getChannel( getA(0, ch, int(innerDims.x), int(innerDims.y)), innerDims); } } } `;const R=` ${M} void main() { ivec2 rc = getOutputCoords(); vec4 result = vec4(0.0); int blockIndex, pos, offsetY, d0, offsetX, d1, ch; vec2 innerDims; ${E} ${T.output} = result; } `;return Object.assign(Object.assign({},u),{output:{dims:w,type:m.type,textureType:o.TextureType.packed},shaderSource:R,hasMain:!0})})(l,i,h,p,f,d)})}},3248:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.calculateIm2ColDims=e.createIm2ColProgramInfoLoader=void 0;const r=t(2039);e.createIm2ColProgramInfoLoader=(o,c,l,h,p)=>{const f=(d=p.cacheKey,{name:"Im2Col",inputNames:["X"],inputTypes:[r.TextureType.unpacked],cacheHint:d});var d;return Object.assign(Object.assign({},f),{get:()=>((i,n,a,u,m,g)=>{const _=a.dims,b=u.dims,y=m.length,v=(0,e.calculateIm2ColDims)(_,b,m,4),x=` const int XC = ${_[1]}; const int XH = ${_[2]}; const int XW = ${_[3]}; const int KH = ${g.kernelShape[0]}; const int KW = ${g.kernelShape[1]}; const int dilationH = ${g.dilations[0]}; const int dilationW = ${g.dilations[1]}; const int strideH = ${g.strides[0]}; const int strideW = ${g.strides[1]}; const int padH = ${g.pads[0]}; const int padW = ${g.pads[1]}; const int KHKW = KH*KW; const int XCKHKW = XC * KHKW; const int outputChannels = 4; vec4 process(int indices[${y}]) { int b = indices[0]; // batch size int oh = indices[1] * strideH - padH; //output height int ow = indices[2] * strideW - padW; //output width int p = indices[3] * outputChannels; //patch vec4 value = vec4(0.0); for(int i=0; i < outputChannels; ++i) { if(p < XCKHKW) { int patchC = p / KHKW; int patchH = (p - patchC*KHKW) / KW; int patchW = (p - patchC*KHKW) - patchH * KW; int xh2 = oh + patchH * dilationH; int xw2 = ow + patchW * dilationW; int x[${_.length}]; x[0] = b; x[1] = patchC; x[2] = xh2; x[3] = xw2; if(xh2 >= 0 && xh2 < XH && xw2 >= 0 && xw2 < XW) { value[i] = _X(x); } } ++p; } return value; } `;return Object.assign(Object.assign({},n),{output:{dims:v,type:a.type,textureType:r.TextureType.packedLastDimension},shaderSource:x})})(0,f,c,l,h,p)})},e.calculateIm2ColDims=(o,c,l,h=4)=>[l[0],l[2],l[3],Math.ceil(o[1]*c[2]*c[3]/h)]},6572:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseImageScalerAttributes=e.imageScaler=void 0;const r=t(246),o=t(2039);e.imageScaler=(f,d,i)=>(p(d),[f.run(l(f,d,i),d)]),e.parseImageScalerAttributes=f=>{const d=f.attributes.getFloat("scale"),i=f.attributes.getFloats("bias");return(0,r.createAttributeWithCacheKey)({scale:d,bias:i})};const c={name:"ImageScaler",inputNames:["X"],inputTypes:[o.TextureType.unpacked]},l=(f,d,i)=>{const n=Object.assign(Object.assign({},c),{cacheHint:i.cacheKey});return Object.assign(Object.assign({},n),{get:()=>((a,u,m,g)=>{const _=m[0].dims.slice(),b=_.length,y=` ${h(g.bias.length)} float process(int indices[${b}]) { return _X(indices) * scale + getBias(bias, indices[1]); }`;return Object.assign(Object.assign({},u),{output:{dims:_,type:m[0].type,textureType:o.TextureType.unpacked},variables:[{name:"bias",type:"float",arrayLength:g.bias.length,data:g.bias},{name:"scale",type:"float",data:g.scale}],shaderSource:y})})(0,n,d,i)})},h=f=>{const d=[`float getBias(float bias[${f}], int channel) {`];for(let i=0;i{if(!f||f.length!==1)throw new Error("ImageScaler requires 1 input.");if(f[0].dims.length!==4)throw new Error("Invalid input shape.");if(f[0].type!=="float32"&&f[0].type!=="float64")throw new Error("Invalid input type.")}},3346:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseInstanceNormalizationAttributes=e.instanceNormalization=void 0;const r=t(5060),o=t(2039);e.instanceNormalization=(d,i,n)=>{f(i);const a=d.run(l(i[0]),i);return[d.run(p(d,i[0],n,a.dims),[i[0],a,i[1],i[2]])]},e.parseInstanceNormalizationAttributes=d=>d.attributes.getFloat("epsilon",1e-5);const c={name:"InstanceNormalization_MeanAndVariance",inputNames:["X"],inputTypes:[o.TextureType.unpacked]},l=d=>Object.assign(Object.assign({},c),{get:()=>((i,n)=>{const a=n.dims.slice(),u=a[1],m=a[2]*a[3],g=[a[0],u],_=` vec4 process(int[2] indices) { vec4 v = vec4(0.0); int a[4]; a[0] = indices[0]; a[1] = indices[1]; float temp = 0.0; for(int a2=0; a2<${a[2]}; a2++) { a[2] = a2; for(int a3=0; a3<${a[3]}; a3++) { a[3] = a3; float x = _X(a); temp += x; } } float mean = temp / float(${m}); temp = 0.0; for(int a2=0; a2<${a[2]}; a2++) { a[2] = a2; for(int a3=0; a3<${a[3]}; a3++) { a[3] = a3; float x = _X(a); temp += (x - mean) * (x - mean); } } v.r = mean; v.g = temp / float(${m}); return v; }`;return Object.assign(Object.assign({},i),{output:{dims:g,type:n.type,textureType:o.TextureType.packedLastDimension},shaderSource:_})})(c,d)}),h={name:"InstanceNormalization_ComputeOutput",inputNames:["X","MeanAndVariance","Scale","B"],inputTypes:[o.TextureType.unpacked,o.TextureType.packedLastDimension,o.TextureType.unpacked,o.TextureType.unpacked]},p=(d,i,n,a)=>{const u=Object.assign(Object.assign({},h),{cacheHint:`${n}`});return Object.assign(Object.assign({},u),{get:()=>((m,g,_,b,y)=>{const v=(0,r.getGlsl)(m.session.backend.glContext.version),[x,w]=m.calculateTextureWidthAndHeight(y,o.TextureType.packedLastDimension),[S,M]=[x/4,w],T=` vec4 get_MeanAndVariance(int[2] mv) { int offset = indicesToOffset_MeanAndVariance(mv); vec2 coords = offsetToCoords(offset, ${S}, ${M}); return ${v.texture2D}(MeanAndVariance, coords); } float process(int[4] indices) { int mv[2]; mv[0] = indices[0]; mv[1] = indices[1]; vec4 mean_and_variance = get_MeanAndVariance(mv); float mean = mean_and_variance.r; float variance = mean_and_variance.g; int sb[1]; sb[0] = indices[1]; float scale = _Scale(sb); float b = _B(sb); return scale * (_X(indices) - mean) / sqrt(variance + epsilon) + b; }`;return Object.assign(Object.assign({},g),{output:{dims:_.dims,type:_.type,textureType:o.TextureType.unpacked},variables:[{name:"epsilon",type:"float",data:b}],shaderSource:T})})(d,u,i,n,a)})},f=d=>{if(!d||d.length!==3)throw new Error("InstanceNormalization requires 3 inputs.");const i=d[0],n=d[1],a=d[2];if(i.dims.length<3||n.dims.length!==1||a.dims.length!==1)throw new Error("Invalid input shape.");if(n.dims[0]!==i.dims[1]||a.dims[0]!==i.dims[1])throw new Error("Input shapes are mismatched.");if(i.type!=="float32"&&i.type!=="float64"||n.type!=="float32"&&n.type!=="float64"||a.type!=="float32"&&a.type!=="float64")throw new Error("Invalid input type.");if(d[0].dims.length!==4)throw new Error("Only support 4-D input shape.")}},708:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createPackedMatmulProgramInfoLoader=void 0;const r=t(2517),o=t(5060),c=t(2039),l=t(9390),h=t(2823),p=t(5623);e.createPackedMatmulProgramInfoLoader=(f,d,i)=>{const n=(a=d.length>2,u=i.activationCacheKey,{name:"MatMul (packed)",inputNames:a?["A","B","Bias"]:["A","B"],inputTypes:a?[c.TextureType.packed,c.TextureType.packed,c.TextureType.packed]:[c.TextureType.packed,c.TextureType.packed],cacheHint:u});var a,u;return Object.assign(Object.assign({},n),{get:()=>((m,g,_,b)=>{const y=_.length>2,v=y?"value += getBiasForMatmul();":"",x=_[0].dims,w=_[1].dims,S=r.BroadcastUtil.calcShape(x,w,!0),M=!r.ShapeUtil.areEqual(_[0].dims,_[1].dims);if(!S)throw new Error("Can't use matmul on the given tensors");const T=x[x.length-1],E=Math.ceil(T/2),R=x.length,I=w.length,k=(0,o.getGlsl)(m.session.backend.glContext.version),C=(0,l.getCoordsDataType)(S.length),z=S.length,O=(0,l.getGlChannels)(),{activationFunction:U,applyActivation:K}=(0,h.getActivationSnippet)(b),$=y?`${(0,p.getBiasForMatmul)(C,O,_[2].dims,S,!0)}`:"",J=M?`${function(le,de,Me,Ee){let Fe=[],Be=[];const Ce=Me[0].dims,je=Me[1].dims,ne=Ce.length,Qe=je.length,Pe=Ee.length,ze=Pe-ne,De=Pe-Qe;Fe=Ce.map((ce,fe)=>`coords.${de[fe+ze]}`),Fe[ne-1]="i*2",Fe.join(", "),Be=je.map((ce,fe)=>`coords.${de[fe+De]}`),Be[Qe-2]="i*2",Be.join(", ");const nt=r.BroadcastUtil.getBroadcastDims(Ce,Ee),qe=r.BroadcastUtil.getBroadcastDims(je,Ee),B=nt.map(ce=>`coords.${de[ce+ze]} = 0;`).join(` `),D=qe.map(ce=>`coords.${de[ce+De]} = 0;`).join(` `),re=`int lastDim = coords.${de[Pe-1]}; coords.${de[Pe-1]} = coords.${de[Pe-2]}; coords.${de[Pe-2]} = lastDim;`;return` vec4 getAAtOutCoordsMatmul(int i) { ${le} coords = getOutputCoords(); ${re} ${B} vec4 outputValue = getA(${Fe}); return outputValue; } vec4 getBAtOutCoordsMatmul(int i) { ${le} coords = getOutputCoords(); ${re} ${D} vec4 outputValue = getB(${Be}); return outputValue; }`}(C,O,_,S)}`:"",ee=M?"getAAtOutCoordsMatmul(i)":`getA(${function(le,de){let Me="";for(let Ee=0;Ee{Object.defineProperty(e,"__esModule",{value:!0}),e.getBiasForMatmul=e.createMatmulProgramInfoLoader=e.parseMatMulAttributes=e.matMul=void 0;const r=t(2517),o=t(2039),c=t(9390),l=t(2823),h=t(708);function p(i,n){const a=(u=i.length>2,m=n.activationCacheKey,{name:"MatMul",inputNames:u?["A","B","Bias"]:["A","B"],inputTypes:u?[o.TextureType.unpacked,o.TextureType.unpacked,o.TextureType.unpacked]:[o.TextureType.unpacked,o.TextureType.unpacked],cacheHint:m});var u,m;return Object.assign(Object.assign({},a),{get:()=>function(g,_,b){const y=_[0].dims,v=_[1].dims,x=r.BroadcastUtil.calcShape(y,v,!0);if(!x)throw new Error("Can't use matmul on the given tensors");const w=(0,c.getCoordsDataType)(x.length),S=(0,c.getGlChannels)(),{activationFunction:M,applyActivation:T}=(0,l.getActivationSnippet)(b),E=_.length>2,R=E?"value += getBiasForMatmul();":"",I=E?`${d(w,S,_[2].dims,x,!1)}`:"",k=x.length,C=y.length,z=v.length,O=` ${M} ${I} float process(int indices[${k}]) { int a[${C}]; int b[${z}]; bcastMatmulIndices_A(indices, a); bcastMatmulIndices_B(indices, b); float value; for (int k=0; k<${y[y.length-1]}; ++k) { a[${C-1}] = k; b[${z-2}] = k; value += _A(a) * _B(b); } ${R} ${T} return value; }`;return Object.assign(Object.assign({},g),{output:{dims:x,type:_[0].type,textureType:o.TextureType.unpacked},shaderSource:O})}(a,i,n)})}e.matMul=(i,n,a)=>(f(n),i.session.pack?[i.run((0,h.createPackedMatmulProgramInfoLoader)(i,n,a),n)]:[i.run(p(n,a),n)]),e.parseMatMulAttributes=i=>(0,l.parseInternalActivationAttributes)(i.attributes),e.createMatmulProgramInfoLoader=p;const f=i=>{if(!i||i.length!==2)throw new Error("MatMul requires 2 inputs.");if(i[0].dims[i[0].dims.length-1]!==i[1].dims[i[1].dims.length-2])throw new Error("shared dimension does not match.");if(i[0].type!=="float32"&&i[0].type!=="float64"||i[1].type!=="float32"&&i[1].type!=="float64")throw new Error("inputs should be float type");if(i[0].type!==i[1].type)throw new Error("inputs types should match")};function d(i,n,a,u,m){let g="";const _=a.length,b=u.length,y=b-_;g=b<2&&_>0?"coords":a.map((w,S)=>`coords.${n[S+y]}`).join(", ");const v=r.BroadcastUtil.getBroadcastDims(a,u).map(w=>`coords.${n[w+y]} = 0;`).join(` `);let x="vec4(outputValue.xx, outputValue.yy)";return r.ShapeUtil.size(a)===1&&(x="vec4(outputValue.x)"),m?` vec4 getBiasForMatmul() { ${i} coords = getOutputCoords(); ${v} vec4 outputValue = getBias(${g}); return ${x}; }`:` float getBiasForMatmul() { ${i} coords = getOutputCoords(); ${v} return getBias(coords.x); }`}e.getBiasForMatmul=d},2403:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createPackProgramInfoLoader=void 0;const r=t(5060),o=t(2039),c=t(9390),l=t(2827),h={name:"pack",inputNames:["A"],inputTypes:[o.TextureType.unpackedReversed]};e.createPackProgramInfoLoader=(p,f)=>Object.assign(Object.assign({},h),{get:()=>((d,i)=>{const n=(0,r.getGlsl)(d.session.backend.glContext.version),a=i.dims,u=a.length,m=i.dims.length,g=(0,c.getCoordsDataType)(m),_=(0,l.getChannels)("rc",m),b=(y=m,v=_,x=a[a.length-2],w=a[a.length-1],y===0||y===1?"":` int r = ${v[y-2]}; int c = ${v[y-1]}; int rp1 = ${v[y-2]} + 1; int cp1 = ${v[y-1]} + 1; bool rEdge = rp1 >= ${w}; bool cEdge = cp1 >= ${x}; `);var y,v,x,w;let S;S=u===0?[1,1]:u===1?[a[0],1]:[a[m-1],a[m-2]];const M=function(R,I,k){if(R===0)return"false";if(R===1)return`rc > ${I[0]}`;let C="";for(let z=R-2;z= ${I[z-R+2]}`,z= ${R[0]} ? 0. : getA(rc + 1), 0, 0`;let C="";if(k>2)for(let z=0;z{Object.defineProperty(e,"__esModule",{value:!0}),e.unpackFromChannel=e.getChannels=e.getVecChannels=void 0;const r=t(9390);function o(c,l){return(0,r.getGlChannels)(l).map(h=>`${c}.${h}`)}e.getVecChannels=o,e.getChannels=function(c,l){return l===1?[c]:o(c,l)},e.unpackFromChannel=function(){return` float getChannel(vec4 frag, int dim) { int modCoord = imod(dim, 2); return modCoord == 0 ? frag.r : frag.g; } float getChannel(vec4 frag, vec2 innerDims) { vec2 modCoord = mod(innerDims, 2.); return modCoord.x == 0. ? (modCoord.y == 0. ? frag.r : frag.g) : (modCoord.y == 0. ? frag.b : frag.a); } `}},2870:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parsePadAttributesV11=e.padV11=e.parsePadAttributesV2=e.padV2=void 0;const r=t(246),o=t(2517),c=t(5060),l=t(2039),h={name:"Pad",inputNames:["A"],inputTypes:[l.TextureType.unpacked]};e.padV2=(g,_,b)=>(d(_),[g.run(Object.assign(Object.assign({},h),{cacheHint:b.cacheKey,get:()=>f(g,_[0],b)}),_)]),e.parsePadAttributesV2=g=>{const _=g.attributes.getString("mode","constant"),b=g.attributes.getFloat("value",0),y=g.attributes.getInts("pads");return(0,r.createAttributeWithCacheKey)({mode:_,value:b,pads:y})},e.padV11=(g,_,b)=>{i(_);const y=p(g,_,b);return(0,e.padV2)(g,[_[0]],y)},e.parsePadAttributesV11=g=>g.attributes.getString("mode","constant");const p=(g,_,b)=>{if(!g.session.isInitializer(_[1].dataId)||_.length>=3&&!g.session.isInitializer(_[2].dataId))throw new Error("dynamic pad attributes are not allowed");const y=Array.from(_[1].integerData),v=_.length>=3?_[2].floatData[0]:0;return(0,r.createAttributeWithCacheKey)({mode:b,pads:y,value:v})},f=(g,_,b)=>{const y=o.ShapeUtil.padShape(_.dims.slice(),b.pads),v=y.length,x=` ${n(g,_,b)} float process(int[${v}] indices) { return padA(indices); }`;return{name:"Pad",inputNames:["A"],inputTypes:[l.TextureType.unpacked],output:{dims:y,type:_.type,textureType:l.TextureType.unpacked},shaderSource:x}},d=g=>{if(!g||g.length!==1)throw new Error("Pad requires 1 input");if(g[0].type!=="float32"&&g[0].type!=="float64")throw new Error("Invalid input type.")},i=g=>{if(!g||g.length!==2&&g.length!==3)throw new Error("Pad requires 2 or 3 inputs");if(g[1].type!=="int32")throw new Error("Invalid input type.");if(g.length>=3&&g[2].type==="string")throw new Error("Invalid input type.")},n=(g,_,b)=>{const y=(0,c.getGlsl)(g.session.backend.glContext.version),[v,x]=g.calculateTextureWidthAndHeight(_.dims,l.TextureType.unpacked),w=o.ShapeUtil.computeStrides(_.dims);switch(b.mode){case"constant":return a(y,_.dims,w,v,x,b.pads,b.value);case"reflect":return u(y,_.dims,w,v,x,b.pads);case"edge":return m(y,_.dims,w,v,x,b.pads);default:throw new Error("Invalid mode")}},a=(g,_,b,y,v,x,w)=>{const S=_.length;let M="";for(let T=S-1;T>=0;--T)M+=` k = m[${T}] - ${x[T]}; if (k < 0) return constant; if (k >= ${_[T]}) return constant; offset += k * ${b[T]}; `;return` float padA(int m[${S}]) { const float constant = float(${w}); int offset = 0; int k = 0; ${M} vec2 coords = offsetToCoords(offset, ${y}, ${v}); float value = getColorAsFloat(${g.texture2D}(A, coords)); return value; } `},u=(g,_,b,y,v,x)=>{const w=_.length;let S="";for(let M=w-1;M>=0;--M)S+=` k = m[${M}] - ${x[M]}; if (k < 0) { k = -k; } { const int _2n_1 = ${2*(_[M]-1)}; k = int( mod( float(k), float(_2n_1) ) ) ; if(k >= ${_[M]}) { k = _2n_1 - k; } } offset += k * ${b[M]}; `;return` float padA(int m[${w}]) { int offset = 0; int k = 0; ${S} vec2 coords = offsetToCoords(offset, ${y}, ${v}); float value = getColorAsFloat(${g.texture2D}(A, coords)); return value; } `},m=(g,_,b,y,v,x)=>{const w=_.length;let S="";for(let M=w-1;M>=0;--M)S+=` k = m[${M}] - ${x[M]}; if (k < 0) k = 0; if (k >= ${_[M]}) k = ${_[M]-1}; offset += k * ${b[M]}; `;return` float padA(int m[${w}]) { int offset = 0; int k = 0; ${S} vec2 coords = offsetToCoords(offset, ${y}, ${v}); float value = getColorAsFloat(${g.texture2D}(A, coords)); return value; } `}},2143:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.globalMaxPool=e.parseMaxPoolAttributes=e.maxPool=e.parseGlobalAveragePoolAttributes=e.globalAveragePool=e.parseAveragePoolAttributes=e.averagePool=void 0;const r=t(246),o=t(2517),c=t(2039);e.averagePool=(m,g,_)=>{i(g);const b={name:"AveragePool",inputNames:["X"],inputTypes:[c.TextureType.unpacked],cacheHint:_.cacheKey};return[m.run(Object.assign(Object.assign({},b),{get:()=>l(g,b,!1,_)}),g)]},e.parseAveragePoolAttributes=m=>{const g=m.attributes.getString("auto_pad","NOTSET"),_=m.attributes.getInt("ceil_mode",0),b=m.attributes.getInt("count_include_pad",0)!==0,y=m.attributes.getInts("kernel_shape"),v=m.attributes.getInts("strides",[]),x=m.attributes.getInts("pads",[]);if(_!==0)throw new Error("using ceil() in shape computation is not yet supported for AveragePool");return(0,r.createAttributeWithCacheKey)({autoPad:g,ceilMode:_,countIncludePad:b,kernelShape:y,strides:v,pads:x})};const l=(m,g,_,b)=>{const[y,v]=p(m,b,_),x=o.ShapeUtil.size(y.kernelShape);let w="";y.countIncludePad?w+=`value /= float(${x});`:w+=`value /= float(${x} - pad);`;const S=` ${n(m[0].dims,y,"value += _X(x);",w,"0.0")} `;return Object.assign(Object.assign({},g),{output:{dims:v,type:m[0].type,textureType:c.TextureType.unpacked},shaderSource:S})};e.globalAveragePool=(m,g,_)=>{i(g);const b={name:"GlobalAveragePool",inputNames:["X"],inputTypes:[c.TextureType.unpacked],cacheHint:`${_.countIncludePad}`};return[m.run(Object.assign(Object.assign({},b),{get:()=>l(g,b,!0,_)}),g)]},e.parseGlobalAveragePoolAttributes=m=>{const g=m.attributes.getInt("count_include_pad",0)!==0;return(0,r.createAttributeWithCacheKey)({autoPad:"",ceilMode:0,countIncludePad:g,kernelShape:[],strides:[],pads:[]})},e.maxPool=(m,g,_)=>{i(g);const b={name:"MaxPool",inputNames:["X"],inputTypes:[c.TextureType.unpacked],cacheHint:_.cacheKey};return[m.run(Object.assign(Object.assign({},b),{get:()=>h(g,b,!1,_)}),g)]},e.parseMaxPoolAttributes=m=>{const g=m.attributes.getString("auto_pad","NOTSET"),_=m.attributes.getInt("ceil_mode",0),b=m.attributes.getInts("kernel_shape"),y=m.attributes.getInts("strides",[]),v=m.attributes.getInts("pads",[]),x=m.attributes.getInt("storage_order",0),w=m.attributes.getInts("dilations",[]);if(x!==0)throw new Error("column major storage order is not yet supported for MaxPool");if(_!==0)throw new Error("using ceil() in shape computation is not yet supported for MaxPool");return(0,r.createAttributeWithCacheKey)({autoPad:g,ceilMode:_,countIncludePad:!1,kernelShape:b,strides:y,pads:v,storageOrder:x,dilations:w})};const h=(m,g,_,b)=>{const[y,v]=p(m,b,_),x=` ${n(m[0].dims,y,` value = max(_X(x), value); `,"","-1e5")} `;return Object.assign(Object.assign({},g),{output:{dims:v,type:m[0].type,textureType:c.TextureType.unpacked},shaderSource:x})},p=(m,g,_)=>{const b=m[0].dims.slice(),y=Object.hasOwnProperty.call(g,"dilations"),v=g.kernelShape.slice(),x=g.strides.slice(),w=y?g.dilations.slice():[],S=g.pads.slice();o.PoolConvUtil.adjustPoolAttributes(_,b,v,x,w,S);const M=o.PoolConvUtil.computePoolOutputShape(_,b,x,w,v,S,g.autoPad),T=Object.assign({},g);return y?Object.assign(T,{kernelShape:v,strides:x,pads:S,dilations:w,cacheKey:g.cacheKey}):Object.assign(T,{kernelShape:v,strides:x,pads:S,cacheKey:g.cacheKey}),[T,M]},f={autoPad:"",ceilMode:0,countIncludePad:!1,kernelShape:[],strides:[],pads:[],storageOrder:0,dilations:[],cacheKey:""},d={name:"GlobalMaxPool",inputNames:["X"],inputTypes:[c.TextureType.unpacked]};e.globalMaxPool=(m,g)=>(i(g),[m.run(Object.assign(Object.assign({},d),{get:()=>h(g,d,!0,f)}),g)]);const i=m=>{if(!m||m.length!==1)throw new Error("Pool ops requires 1 input.");if(m[0].type!=="float32"&&m[0].type!=="float64")throw new Error("Invalid input type.")},n=(m,g,_,b,y)=>{const v=m.length;if(g.kernelShape.length<=2){const x=g.kernelShape[g.kernelShape.length-1],w=g.strides[g.strides.length-1],S=g.pads[g.pads.length/2-1],M=g.pads[g.pads.length-1],T=m[v-1];let E="",R="",I="";if(E=S+M!==0?` for (int i = 0; i < ${x}; i++) { x[${v} - 1] = indices[${v} - 1] * ${w} - ${S} + i; if (x[${v} - 1] < 0 || x[${v} - 1] >= ${T}) { pad++; continue; } ${_} }`:` for (int i = 0; i < ${x}; i++) { x[${v} - 1] = indices[${v} - 1] * ${w} - ${S} + i; ${_} }`,g.kernelShape.length===2){const k=g.kernelShape[g.kernelShape.length-2],C=g.strides[g.strides.length-2],z=g.pads[g.pads.length/2-2],O=g.pads[g.pads.length-2],U=m[v-2];R=z+O!==0?` for (int j = 0; j < ${k}; j++) { x[${v} - 2] = indices[${v} - 2] * ${C} - ${z} + j; if (x[${v} - 2] < 0 || x[${v} - 2] >= ${U}) { pad+= ${x}; continue; } `:` for (int j = 0; j < ${k}; j++) { x[${v} - 2] = indices[${v} - 2] * ${C} - ${z} + j; `,I=` } `}return` float process(int indices[${v}]) { int x[${v}]; copyVec(indices, x); float value = ${y}; int pad = 0; ${R} ${E} ${I} ${b} return value; } `}{const x=o.ShapeUtil.size(g.kernelShape),w=o.ShapeUtil.computeStrides(g.kernelShape),S=w.length,M=g.pads.length,T=u(S),E=a(m,"inputDims"),R=a(g.pads,"pads"),I=a(w,"kernelStrides"),k=a(g.strides,"strides");let C="";return C=g.pads.reduce((z,O)=>z+O)?` if (x[j] >= inputDims[j] || x[j] < 0) { pad++; isPad = true; break; } } if (!isPad) { ${_} }`:` } ${_} `,` ${T} float process(int indices[${v}]) { int x[${v}]; copyVec(indices, x); int offset[${S}]; int pads[${M}]; int inputDims[${v}]; int kernelStrides[${S}]; int strides[${S}]; ${R} ${E} ${k} ${I} float value = ${y}; int pad = 0; bool isPad = false; for (int i = 0; i < ${x}; i++) { offsetToIndices(i, kernelStrides, offset); isPad = false; for (int j = ${v} - ${S}; j < ${v}; j++) { x[j] = indices[j] * strides[j - ${v} + ${S}] + offset[j - ${v} + ${S}] - pads[j - 2]; ${C} } ${b} return value; } `}},a=(m,g)=>{let _="";for(let b=0;b` void offsetToIndices(int offset, int[${m}] strides, out int[${m}] indices) { if (${m} == 0) { return; } for (int i = 0; i < ${m} - 1; ++i) { indices[i] = offset / strides[i]; offset -= indices[i] * strides[i]; } indices[${m} - 1] = offset; }`},4939:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.reduceLogSumSquare=e.reduceLogSum=e.reduceProd=e.reduceMin=e.reduceMax=e.reduceMean=e.reduceSum=e.parseReduceAttributes=void 0;const r=t(246),o=t(782),c=t(2517),l=t(2039),h=(d,i,n,a,u)=>{f(i);const m={name:a,inputNames:["A"],inputTypes:[l.TextureType.unpacked]};return[d.run(Object.assign(Object.assign({},m),{cacheHint:n.cacheKey,get:()=>p(d,i,n,a,u,m)}),i)]};e.parseReduceAttributes=d=>{const i=d.attributes.getInts("axes",[]),n=d.attributes.getInt("keepdims",1)===1;return(0,r.createAttributeWithCacheKey)({axes:i,keepDims:n})};const p=(d,i,n,a,u,m)=>{const g=[],_=i[0].dims.length||1,b=[],y=c.ShapeUtil.normalizeAxes(n.axes,i[0].dims.length),v=u(i,y);let x=v[1];for(let S=0;S=0||y.length===0?(n.keepDims&&g.push(1),x=` for(int j${S} = 0; j${S} < ${i[0].dims[S]}; j${S}++) { inputIdx[${S}] = j${S}; ${x} }`):(b.push(`inputIdx[${S}] = outputIdx[${g.length}];`),g.push(i[0].dims[S]));const w=` float process(int outputIdx[${g.length||1}]) { float value; // final result int inputIdx[${_}]; // addressing input data ${b.join(` `)} ${v[0]} // init ops for reduce max/min ${x} ${v[2]} // final computation for reduce mean return value; }`;return Object.assign(Object.assign({},m),{output:{dims:g,type:i[0].type,textureType:l.TextureType.unpacked},shaderSource:w})},f=d=>{if(!d||d.length!==1)throw new Error("Reduce op requires 1 input.");if(o.NUMBER_TYPES.indexOf(d[0].type)===-1)throw new Error("Invalid input type.")};e.reduceSum=(d,i,n)=>h(d,i,n,"ReduceSum",()=>["value = 0.0;","value += _A(inputIdx);",""]),e.reduceMean=(d,i,n)=>h(d,i,n,"ReduceMean",(a,u)=>{let m=1;for(let g=0;g=0||u.length===0)&&(m*=a[0].dims[g]);return["value = 0.0;","value += _A(inputIdx);",`value /= ${m}.;`]}),e.reduceMax=(d,i,n)=>h(d,i,n,"ReduceMax",(a,u)=>{const m=[];for(let g=0;g=0||u.length===0)&&m.push(`inputIdx[${g}] = 0;`);return[`${m.join(` `)} value = _A(inputIdx);`,"value = max(value, _A(inputIdx));",""]}),e.reduceMin=(d,i,n)=>h(d,i,n,"ReduceMin",(a,u)=>{const m=[];for(let g=0;g=0||u.length===0)&&m.push(`inputIdx[${g}] = 0;`);return[`${m.join(` `)} value = _A(inputIdx);`,"value = min(value, _A(inputIdx));",""]}),e.reduceProd=(d,i,n)=>h(d,i,n,"ReduceProd",()=>["value = 1.0;","value *= _A(inputIdx);",""]),e.reduceLogSum=(d,i,n)=>h(d,i,n,"ReduceLogSum",()=>["value = 0.0;","value += _A(inputIdx);","value = log(value);"]),e.reduceLogSumSquare=(d,i,n)=>h(d,i,n,"ReduceLogSumSquare",()=>["float t; value = 0.0;","t = _A(inputIdx); value += t * t;",""])},7019:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.isReshapeCheap=e.processDims3D=e.createPackedReshape3DProgramInfoLoader=void 0;const r=t(2517),o=t(5060),c=t(2039),l=t(2827);e.createPackedReshape3DProgramInfoLoader=(h,p,f)=>{const d=(i=>({name:"Reshape (packed)",inputTypes:[c.TextureType.packed],inputNames:["A"],cacheHint:`${i}`}))(f);return Object.assign(Object.assign({},d),{get:()=>((i,n,a,u)=>{const m=n.dims,g=u;let _="";for(let v=0;v<4;v++){let x="";switch(v){case 0:x="outputCoords = rc;";break;case 1:x="outputCoords = ivec3(rc.x, rc.y+1, rc.z);";break;case 2:x="outputCoords = ivec3(rc.x, rc.y, rc.z+1);";break;case 3:x="outputCoords = ivec3(rc.x, rc.y+1, rc.z+1);";break;default:throw new Error}_+=` ${x} ${v>0?"if(outputCoords.y < rows && outputCoords.z < cols){":""} int flattenedIndex = getFlattenedIndex(outputCoords); ivec3 inputRC = inputCoordsFromReshapedOutCoords(flattenedIndex); vec2 innerDims = vec2(float(inputRC.y),float(inputRC.z)); result[${v}] = getChannel(getA(inputRC.x, inputRC.y, inputRC.z), innerDims); ${v>0?"}":""} `}const b=(0,o.getGlsl)(i.session.backend.glContext.version),y=` ${function(v){const x=r.ShapeUtil.computeStrides(v),w=["b","r","c"],S="index";return` ivec3 inputCoordsFromReshapedOutCoords(int index) { ${x.map((M,T)=>`int ${w[T]} = ${S} / ${M}; ${T===x.length-1?`int ${w[T+1]} = ${S} - ${w[T]} * ${M}`:`index -= ${w[T]} * ${M}`};`).join("")} return ivec3(b, r, c); } `}(m)} ${function(v){const x=r.ShapeUtil.computeStrides(v);return` int getFlattenedIndex(ivec3 coords) { // reverse y, z order return coords.x * ${x[0]} + coords.z * ${x[1]} + coords.y; } `}(g)} ${(0,l.unpackFromChannel)()} void main() { ivec3 rc = getOutputCoords(); vec4 result = vec4(0.0); ivec3 outputCoords; int rows = ${g[2]}; int cols = ${g[1]}; ${_} ${b.output} = result; } `;return Object.assign(Object.assign({},a),{output:{dims:g,type:n.type,textureType:c.TextureType.packed},shaderSource:y,hasMain:!0})})(h,p,d,f)})},e.processDims3D=function(h){if(h.length===0)return[1,1,1];let p=1;for(let f=0;f1?h[h.length-2]:1,h[h.length-1]]},e.isReshapeCheap=function(h,p){let f=!1;return f=h.length===0||p.length===0||(h.length<2||p.length<2?h[h.length-1]===p[p.length-1]:h[h.length-1]===p[p.length-1]&&h[h.length-2]===p[p.length-2]),f}},718:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.reshape=void 0;const r=t(2517);e.reshape=(o,c)=>{const l=r.ShapeUtil.calculateReshapedDims(c[0].dims,c[1].integerData);return o.session.pack?[o.reshapePacked(c[0],l)]:[o.reshapeUnpacked(c[0],l)]}},2268:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseResizeAttributesV11=e.parseResizeAttributesV10=e.resize=void 0;const r=t(5060),o=t(2039),c=t(9390),l=t(2827),h=t(9793),p={name:"Resize",inputNames:["A"],inputTypes:[o.TextureType.packed]};e.resize=(a,u,m)=>((0,h.validateInputs)(u,m),[a.run(Object.assign(Object.assign({},p),{cacheHint:m.cacheKey,get:()=>f(a,u,m)}),u)]),e.parseResizeAttributesV10=a=>(0,h.parseUpsampleAttributes)(a,10),e.parseResizeAttributesV11=a=>(0,h.parseUpsampleAttributes)(a,11);const f=(a,u,m)=>{const g=(0,r.getGlsl)(a.session.backend.glContext.version),[_,b]=d(u,m);if(_.every(C=>C===1)&&m.coordinateTransformMode!=="tf_crop_and_resize")return Object.assign(Object.assign({},p),{output:{dims:b,type:u[0].type,textureType:o.TextureType.packed},hasMain:!0,shaderSource:`void main() { vec4 v = ${g.texture2D}(X, TexCoords); ${g.output} = v; }`});const y=b.length;if(y<2)throw new Error(`output dimension should be at least 2, but got ${y}`);const v=b[y-2],x=b[y-1],w=u[0].dims;if(y!==w.length)throw new Error(`output dimension should match input ${w.length}, but got ${y}`);const S=w[y-2],M=w[y-1],T=_[y-2],E=_[y-1];let R="";if(m.mode!=="linear")throw new Error(`resize (packed) does not support mode: '${m.mode}'`);switch(m.coordinateTransformMode){case"asymmetric":R=` vec4 getSourceFracIndex(ivec4 coords) { return vec4(coords) / scaleWHWH; } `;break;case"half_pixel":R=` vec4 getSourceFracIndex(ivec4 coords) { return (vec4(coords) + 0.5) / scaleWHWH - 0.5; } `;break;case"pytorch_half_pixel":R=` vec4 getSourceFracIndex(ivec4 coords) { vec4 fcoords = vec4(coords); return vec4( ${x}.0 > 1.0 ? (fcoords.x + 0.5) / scaleWHWH.x - 0.5 : 0.0, ${v}.0 > 1.0 ? (fcoords.y + 0.5) / scaleWHWH.y - 0.5 : 0.0, ${x}.0 > 1.0 ? (fcoords.z + 0.5) / scaleWHWH.z - 0.5 : 0.0, ${v}.0 > 1.0 ? (fcoords.w + 0.5) / scaleWHWH.w - 0.5 : 0.0 ); } `;break;case"align_corners":R=` vec4 getSourceFracIndex(ivec4 coords) { vec4 resized = vec4(${x}.0 - 1.0, ${v}.0 - 1.0, ${x}.0 - 1.0, ${v}.0 - 1.0); vec4 original = vec4(${M}.0 - 1.0, ${S}.0 - 1.0, ${M}.0 - 1.0, ${S}.0 - 1.0); vec4 new_scale = original / resized; return vec4(coords) * new_scale; } `;break;default:throw new Error(`resize (packed) does not support coordinateTransformMode: '${m.coordinateTransformMode}'`)}const I=(0,c.getCoordsDataType)(y),k=` const vec2 inputWH = vec2(${S}.0, ${M}.0); const vec4 scaleWHWH = vec4(float(${T}), float(${E}), float(${T}), float(${E})); ${(0,l.unpackFromChannel)()} ${R} float getAValue(int x10, int r, int c, int d) { return getChannel(getA(x10, r, c, d), vec2(c, d)); } void main() { ${I} rc = getOutputCoords(); int batch = rc[0]; int depth = rc[1]; // retrieve the 4 coordinates that is used in the 4 packed output values. ivec4 coords = ivec4(rc.wz, rc.w + 1, rc.z + 1); // calculate the source index in fraction vec4 sourceFrac = getSourceFracIndex(coords); // get the lower and upper bound of the 4 values that will be packed into one texel. ivec4 x00 = ivec4(max(sourceFrac.xy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xy))); ivec4 x01 = ivec4(max(sourceFrac.xw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.xw))); ivec4 x10 = ivec4(max(sourceFrac.zy, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zy))); ivec4 x11 = ivec4(max(sourceFrac.zw, vec2(0.0)), min(inputWH - 1.0, ceil(sourceFrac.zw))); bool hasNextRow = rc.w < ${v-1}; bool hasNextCol = rc.z < ${x-1}; // pack x00, x01, x10, x11's top-left corner into one vec4 structure vec4 topLeft = vec4( getAValue(batch, depth, x00.x, x00.y), hasNextCol ? getAValue(batch, depth, x01.x, x01.y) : 0.0, hasNextRow ? getAValue(batch, depth, x10.x, x10.y) : 0.0, (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.y) : 0.0); // pack x00, x01, x10, x11's top-right corner into one vec4 structure vec4 topRight = vec4( getAValue(batch, depth, x00.x, x00.w), hasNextCol ? getAValue(batch, depth, x01.x, x01.w) : 0.0, hasNextRow ? getAValue(batch, depth, x10.x, x10.w) : 0.0, (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.x, x11.w) : 0.0); // pack x00, x01, x10, x11's bottom-left corner into one vec4 structure vec4 bottomLeft = vec4( getAValue(batch, depth, x00.z, x00.y), hasNextCol ? getAValue(batch, depth, x01.z, x01.y) : 0.0, hasNextRow ? getAValue(batch, depth, x10.z, x10.y) : 0.0, (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.y) : 0.0); // pack x00, x01, x10, x11's bottom-right corner into one vec4 structure vec4 bottomRight = vec4( getAValue(batch, depth, x00.z, x00.w), hasNextCol ? getAValue(batch, depth, x01.z, x01.w) : 0.0, hasNextRow ? getAValue(batch, depth, x10.z, x10.w) : 0.0, (hasNextRow && hasNextCol) ? getAValue(batch, depth, x11.z, x11.w) : 0.0); // calculate the interpolation fraction on u and v direction vec4 frac = vec4(sourceFrac) - floor(sourceFrac); vec4 clampFrac = clamp(frac, vec4(0.0), vec4(1.0)); vec4 top = mix(topLeft, topRight, clampFrac.ywyw); vec4 bottom = mix(bottomLeft, bottomRight, clampFrac.ywyw); vec4 newValue = mix(top, bottom, clampFrac.xxzz); ${g.output} = vec4(newValue); } `;return Object.assign(Object.assign({},p),{output:{dims:b,type:u[0].type,textureType:o.TextureType.packed},hasMain:!0,shaderSource:k})},d=(a,u)=>{const m=a[0].dims;let g,_=u.scales;if(_.length===0){const y=a[u.scalesInputIdx];if(y&&y.size!==0){if(a[u.sizesInputIdx])throw new Error("Only one of scales or sizes must be provided as input.");_=i(y,u.mode,u.isResize)}else{const v=a[u.sizesInputIdx];if(!v||v.size===0)throw new Error("Either scales or sizes MUST be provided as input.");g=Array.from(v.integerData),_=n(g,m,u.mode,u.isResize)}}else if(a[u.sizesInputIdx])throw new Error("Only one of scales or sizes must be provided as input.");const b=g||m.map((y,v)=>Math.floor(y*_[v]));return[_,b]},i=(a,u,m)=>{const g=Array.from(a.floatData);return(0,h.scalesValidation)(g,u,m),g},n=(a,u,m,g)=>{const _=u.length,b=new Array(_);for(let y=0,v=_;y{Object.defineProperty(e,"__esModule",{value:!0}),e.shape=void 0;const r=t(9162);e.shape=(c,l)=>(o(l),[new r.Tensor([l[0].dims.length],"int32",void 0,void 0,new Int32Array(l[0].dims))]);const o=c=>{if(!c||c.length!==1)throw new Error("Shape requires 1 input.")}},2278:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.sliceV10=e.parseSliceAttributes=e.slice=void 0;const r=t(246),o=t(782),c=t(2517),l=t(2039),h={name:"Slice",inputNames:["A"],inputTypes:[l.TextureType.unpacked]};e.slice=(n,a,u)=>(f(a),[n.run(Object.assign(Object.assign({},h),{cacheHint:u.cacheKey,get:()=>p(n,a[0],u)}),a)]),e.parseSliceAttributes=n=>{const a=n.attributes.getInts("starts"),u=n.attributes.getInts("ends"),m=n.attributes.getInts("axes",[]);return(0,r.createAttributeWithCacheKey)({starts:a,ends:u,axes:m})};const p=(n,a,u)=>{const m=u.axes.length===0?a.dims.slice(0).map((w,S)=>S):u.axes,g=c.ShapeUtil.normalizeAxes(m,a.dims.length),_=u.starts.map((w,S)=>w>a.dims[g[S]]-1?a.dims[g[S]]:c.ShapeUtil.normalizeAxis(w,a.dims[g[S]])),b=u.ends.map((w,S)=>w>a.dims[g[S]]-1?a.dims[g[S]]:c.ShapeUtil.normalizeAxis(w,a.dims[g[S]])),y=a.dims.slice(),v=[];for(let w=0;w0&&v.push(`outputIdx[${g[w]}] += ${_[w]};`);const x=` float process(int outputIdx[${y.length}]) { ${v.join(` `)} return _A(outputIdx); }`;return Object.assign(Object.assign({},h),{output:{dims:y,type:a.type,textureType:l.TextureType.unpacked},shaderSource:x})},f=n=>{if(!n||n.length!==1)throw new Error("Slice requires 1 input.");if(o.NUMBER_TYPES.indexOf(n[0].type)===-1)throw new Error("Invalid input type.")};e.sliceV10=(n,a)=>{i(a);const u=d(n,a);return[n.run(Object.assign(Object.assign({},h),{cacheHint:u.cacheKey,get:()=>p(n,a[0],u)}),[a[0]])]};const d=(n,a)=>{if(!n.session.isInitializer(a[1].dataId)||!n.session.isInitializer(a[2].dataId)||a.length>=4&&!n.session.isInitializer(a[3].dataId)||a.length>=5&&!n.session.isInitializer(a[4].dataId))throw new Error("dynamic slice attributes are not allowed");if(a.length>=5&&a[4].integerData.some(_=>_!==1))throw new Error("currently non-1 steps is not supported for Slice");const u=Array.from(a[1].integerData),m=Array.from(a[2].integerData),g=a.length>=4?Array.from(a[3].integerData):[];return{starts:u,ends:m,axes:g,cacheKey:`${g};${u};${m}`}},i=n=>{if(!n||n.length<3||n.length>5)throw new Error("Invalid input number.");if(n[1].type!=="int32"||n[1].dims.length!==1)throw new Error("Invalid input type.");if(n[2].type!=="int32"||n[2].dims.length!==1)throw new Error("Invalid input type.");if(n.length>=4&&(n[3].type!=="int32"||n[3].dims.length!==1))throw new Error("Invalid input type.");if(n.length>=5&&(n[4].type!=="int32"||n[4].dims.length!==1))throw new Error("Invalid input type.")}},5524:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.softmaxV13=e.parseSoftmaxAttributesV13=e.parseSoftmaxAttributes=e.softmax=void 0;const r=t(246),o=t(2517),c=t(5060),l=t(2039),h=t(3738),p={name:"SoftmaxComputeMax",inputNames:["A"],inputTypes:[l.TextureType.unpacked]},f={name:"SoftmaxComputeScale",inputNames:["A","Max"],inputTypes:[l.TextureType.unpacked,l.TextureType.unpacked]},d={name:"SoftMax",inputNames:["A","Max","Norm"],inputTypes:[l.TextureType.unpacked,l.TextureType.unpacked,l.TextureType.unpacked]};e.softmax=(g,_,b)=>{m(_);const y=_[0].dims.slice(),v=o.ShapeUtil.normalizeAxis(b.axis,y.length),x=o.ShapeUtil.sizeToDimension(y,v),w=o.ShapeUtil.sizeFromDimension(y,v);return i(g,_,b,x,w)},e.parseSoftmaxAttributes=g=>(0,r.createAttributeWithCacheKey)({axis:g.attributes.getInt("axis",1)}),e.parseSoftmaxAttributesV13=g=>(0,r.createAttributeWithCacheKey)({axis:g.attributes.getInt("axis",-1)}),e.softmaxV13=(g,_,b)=>{m(_);const y=_[0].dims.slice(),v=o.ShapeUtil.normalizeAxis(b.axis,y.length),x=y.length,w=v!==x-1,S=[];let M,T=[],E=[];w&&(T=Array.from({length:x}).map((C,z)=>z),T[v]=x-1,T[x-1]=v,T.map(C=>S.push(y[C])),M=(0,r.createAttributeWithCacheKey)({perm:T}),E=(0,h.transpose)(g,_,M));const R=w?o.ShapeUtil.sizeToDimension(S,x-1):o.ShapeUtil.sizeToDimension(y,x-1),I=w?o.ShapeUtil.sizeFromDimension(S,x-1):o.ShapeUtil.sizeFromDimension(y,x-1),k=i(g,w?E:_,b,R,I);return w?(0,h.transpose)(g,k,M):k};const i=(g,_,b,y,v)=>{const x=n(g,_[0],y,v,[y]),w=g.run(Object.assign(Object.assign({},p),{cacheHint:b.cacheKey,get:()=>x}),_),S=a(g,_[0],y,v,x.output.dims,[y]),M=g.run(Object.assign(Object.assign({},f),{cacheHint:b.cacheKey,get:()=>S}),[_[0],w]),T=u(g,_[0],y,v,x.output.dims,S.output.dims);return[g.run(Object.assign(Object.assign({},d),{cacheHint:b.cacheKey,get:()=>T}),[_[0],w,M])]},n=(g,_,b,y,v)=>{const[x,w]=g.calculateTextureWidthAndHeight(_.dims,l.TextureType.unpacked),S=v.length;if(b<1||y<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(v.length!==1)throw new Error("Dimensionality of the output should be 1");if(v[0]!==b)throw new Error("Shape of the output should be equal to logical row count");const M=(0,c.getGlsl)(g.session.backend.glContext.version),T=` float process(int[${S}] indices) { int logical_row_start_offset = indices[0] * ${y}; float max = getColorAsFloat(${M.texture2D}(A, offsetToCoords(logical_row_start_offset, ${x}, ${w} ))); for(int i=1; i<${y}; ++i) { float current = getColorAsFloat(${M.texture2D}(A, offsetToCoords(logical_row_start_offset + i, ${x}, ${w}))); if(current > max) max = current; } return max; }`;return Object.assign(Object.assign({},p),{output:{dims:v,type:_.type,textureType:l.TextureType.unpacked},shaderSource:T})},a=(g,_,b,y,v,x)=>{const[w,S]=g.calculateTextureWidthAndHeight(_.dims,l.TextureType.unpacked),M=x.length;if(b<1||y<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(x.length!==1)throw new Error("Dimensionality of the output should be 1");if(x[0]!==b)throw new Error("Shape of the output should be equal to logical row count");if(v.length!==1)throw new Error("Dimensionality of the intermediate results should be 1");if(v[0]!==b)throw new Error("Shape of the intermediate results should be equal to logical row count");const T=` float process(int[${M}] indices) { int logical_row_start_offset = indices[0] * ${y}; float norm_factor = 0.0; float max = _Max(indices); for(int i=0; i<${y}; ++i) { norm_factor += exp(getColorAsFloat(${(0,c.getGlsl)(g.session.backend.glContext.version).texture2D}(A, offsetToCoords(logical_row_start_offset + i, ${w}, ${S}))) - max); } return norm_factor; }`;return Object.assign(Object.assign({},f),{output:{dims:x,type:_.type,textureType:l.TextureType.unpacked},shaderSource:T})},u=(g,_,b,y,v,x)=>{const[w,S]=g.calculateTextureWidthAndHeight(_.dims,l.TextureType.unpacked),M=_.dims.length;if(b<1||y<1)throw new Error("Logical row count N and feature count D must be greater than or equal to 1");if(v.length!==1||x.length!==1)throw new Error("Dimensionality of the intermediate results should be 1");if(v[0]!==b||x[0]!==b)throw new Error("Shape of the intermediate results should be equal to logical row count");const T=` float process(int[${M}] indices) { // get offset of current logical tensor index from the 2-D texture coordinates (TexCoords) int offset = coordsToOffset(TexCoords, ${w}, ${S}); //determine the logical row for this index int logical_row_index[1]; logical_row_index[0] = offset / ${y}; float norm_factor = _Norm(logical_row_index); // avoid possible division by 0 // if norm_facor is 0, all elements are zero // if so, return 0 if(norm_factor == 0.0) return 0.0; return exp(_A(indices) - _Max(logical_row_index)) / norm_factor; }`;return Object.assign(Object.assign({},d),{output:{dims:_.dims,type:_.type,textureType:l.TextureType.unpacked},shaderSource:T})},m=g=>{if(!g||g.length!==1)throw new Error("Softmax requires 1 input.");if(g[0].type!=="float32"&&g[0].type!=="float64")throw new Error("Invalid input type")}},5975:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseSplitAttributes=e.split=void 0;const r=t(246),o=t(2517),c=t(2039),l={name:"Split",inputNames:["A"],inputTypes:[c.TextureType.unpacked]};e.split=(d,i,n)=>{f(i);const a=o.ShapeUtil.normalizeAxis(n.axis,i[0].dims.length),u=h(d,i,a,n),m=[];for(let g=0;gp(d,i[0],n,a,g)}),i));return m},e.parseSplitAttributes=d=>{const i=d.attributes.getInt("axis",0),n=d.attributes.getInts("split",[]),a=d.outputs.length;return(0,r.createAttributeWithCacheKey)({axis:i,split:n,numOutputs:a})};const h=(d,i,n,a)=>{const[,u]=o.SplitUtil.splitShape(i[0].dims,n,a.split,a.numOutputs);return u.length},p=(d,i,n,a,u)=>{const[m,g]=o.SplitUtil.splitShape(i.dims,a,n.split,n.numOutputs),_=g[u],b=m[u],y=` float process(int indices[${b.length}]) { indices[${a}] += ${_}; return _A(indices); } `;return Object.assign(Object.assign({},l),{cacheHint:`${n.cacheKey}:${u}`,output:{dims:b,type:i.type,textureType:c.TextureType.unpacked},shaderSource:y})},f=d=>{if(!d||d.length!==1)throw new Error("Split requires one input.");if(d[0].type!=="int8"&&d[0].type!=="uint8"&&d[0].type!=="int16"&&d[0].type!=="uint16"&&d[0].type!=="int32"&&d[0].type!=="uint32"&&d[0].type!=="float32"&&d[0].type!=="float64"&&d[0].type!=="bool")throw new Error("Invalid input type.")}},3933:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseSqueezeAttributes=e.squeezeV13=e.squeeze=void 0;const r=t(2517);e.squeeze=(l,h,p)=>{o(h);const f=r.ShapeUtil.squeezeShape(h[0].dims,p);return[l.reshapeUnpacked(h[0],f)]},e.squeezeV13=(l,h)=>(c(h),(0,e.squeeze)(l,[h[0]],Array.from(h[1].integerData))),e.parseSqueezeAttributes=l=>l.attributes.getInts("axes");const o=l=>{if(!l||l.length!==1)throw new Error("Squeeze requires 1 input.");if(l[0].type==="string")throw new Error("invalid input tensor types.")},c=l=>{if(!l||l.length!==2)throw new Error("Squeeze requires 2 inputs.");if(l[1].type!=="int32")throw new Error("Invalid input type.")}},6558:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.sum=void 0;const r=t(5060),o=t(2039);e.sum=(h,p)=>{l(p);const f={name:"Sum",inputNames:p.map((d,i)=>`X${i}`),inputTypes:new Array(p.length).fill(o.TextureType.unpacked)};return[h.run(Object.assign(Object.assign({},f),{get:()=>c(h,p,f)}),p)]};const c=(h,p,f)=>{const d=(0,r.getGlsl)(h.session.backend.glContext.version),i=p[0].dims.slice(),n=` void main() { vec4 result = ${p.map((a,u)=>`${d.texture2D}(X${u},TexCoords)`).join(" + ")}; ${d.output} = result; } `;return Object.assign(Object.assign({},f),{output:{dims:i,type:p[0].type,textureType:o.TextureType.unpacked},hasMain:!0,shaderSource:n})},l=h=>{if(!h||h.length===0)throw new Error("Sum requires inputs.");const p=h[0].dims.length;for(let f=1;f{Object.defineProperty(e,"__esModule",{value:!0}),e.tile=void 0;const r=t(782),o=t(2039);e.tile=(h,p)=>{l(p);const f={name:"Tile",inputNames:["A"],inputTypes:[o.TextureType.unpacked]};return[h.run(Object.assign(Object.assign({},f),{get:()=>c(h,p,f)}),p)]};const c=(h,p,f)=>{const d=p[0].dims.slice(),i=new Array(d.length),n=[];for(let m=0;m{if(!h||h.length!==2)throw new Error("Tile requires 2 input.");if(h[1].dims.length!==1)throw new Error("The second input shape must 1 dimension.");if(h[1].dims[0]!==h[0].dims.length)throw new Error("Invalid input shape.");if(r.NUMBER_TYPES.indexOf(h[0].type)===-1)throw new Error("Invalid input type.");if(h[1].type!=="int32"&&h[1].type!=="int16")throw new Error("Invalid repeat type.")}},3738:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseTransposeAttributes=e.transpose=void 0;const r=t(246),o=t(2517),c=t(2039),l={name:"Transpose",inputNames:["A"],inputTypes:[c.TextureType.unpacked]};e.transpose=(n,a,u)=>(i(a),[n.run(Object.assign(Object.assign({},l),{cacheHint:u.cacheKey,get:()=>h(n,a[0],u.perm)}),a)]),e.parseTransposeAttributes=n=>(0,r.createAttributeWithCacheKey)({perm:n.attributes.getInts("perm",[])});const h=(n,a,u)=>{const m=a.dims;u=p(m,u);const g=f(m,u),_=m.length,b=` ${d("perm",u,_)} float process(int indices[${_}]) { int a[${_}]; perm(a, indices); return _A(a); }`;return Object.assign(Object.assign({},l),{output:{dims:g,type:a.type,textureType:c.TextureType.unpacked},shaderSource:b})},p=(n,a)=>(a&&a.length!==n.length&&(a=[...n.keys()].reverse()),a),f=(n,a)=>(a=p(n,a),o.ShapeUtil.sortBasedOnPerm(n,a)),d=(n,a,u)=>{const m=[];m.push(`void ${n}(out int a[${u}], int src[${u}]) {`);for(let g=0;g{if(!n||n.length!==1)throw new Error("Transpose requires 1 input.");if(n[0].type!=="float32"&&n[0].type!=="float64")throw new Error("input should be float tensor")}},8710:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.encodeAsUint8=void 0;const r=t(5060),o=t(2039);e.encodeAsUint8=(c,l)=>{const h=l.shape,p=(0,r.getGlsl)(c.session.backend.glContext.version),f=` const float FLOAT_MAX = 1.70141184e38; const float FLOAT_MIN = 1.17549435e-38; bool isNaN(float val) { return (val < 1.0 || 0.0 < val || val == 0.0) ? false : true; } highp vec4 encodeAsUint8(highp float v) { if (isNaN(v)) { return vec4(255, 255, 255, 255); } highp float av = abs(v); if(av < FLOAT_MIN) { return vec4(0.0, 0.0, 0.0, 0.0); } else if(v > FLOAT_MAX) { return vec4(0.0, 0.0, 128.0, 127.0) / 255.0; } else if(v < -FLOAT_MAX) { return vec4(0.0, 0.0, 128.0, 255.0) / 255.0; } highp vec4 c = vec4(0,0,0,0); highp float e = floor(log2(av)); highp float m = exp2(fract(log2(av))) - 1.0; c[2] = floor(128.0 * m); m -= c[2] / 128.0; c[1] = floor(32768.0 * m); m -= c[1] / 32768.0; c[0] = floor(8388608.0 * m); highp float ebias = e + 127.0; c[3] = floor(ebias / 2.0); ebias -= c[3] * 2.0; c[2] += floor(ebias) * 128.0; c[3] += 128.0 * step(0.0, -v); return c / 255.0; } void main() { float value = ${p.texture2D}(X,TexCoords).r; ${p.output} = encodeAsUint8(value); }`,d={name:"Uint8Encode",inputTypes:[o.TextureType.unpacked],inputNames:["X"],output:{dims:h,type:l.tensor.type,textureType:o.TextureType.downloadUint8AsFloat},shaderSource:f,hasMain:!0};return c.executeProgram(d,[l.tensor])}},4909:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.tanh=e.tan=e.sqrt=e.sin=e.sigmoid=e.relu=e.not=e.neg=e.log=e.parseLeakyReluAttributes=e.leakyRelu=e.identity=e.floor=e.exp=e.parseEluAttributes=e.elu=e.cos=e.ceil=e.clipV11=e.parseClipAttributes=e.clip=e.atan=e.asin=e.acos=e.abs=e.glslTanh=e.glslTan=e.glslSqrt=e.glslSigmoid=e.glslRelu=e.glslSin=e.glslNot=e.glslNeg=e.glslLog=e.glslLeakyRelu=e.glslIdentity=e.glslClip=e.glslFloor=e.glslExp=e.glslElu=e.glslCos=e.glslCeil=e.glslAtan=e.glslAsin=e.glslAcos=e.glslAbs=void 0;const r=t(246),o=t(2517),c=t(8520),l=t(5060),h=t(2039);function p(){return k("abs")}function f(){return k("acos")}function d(){return k("asin")}function i(){return k("atan")}function n(){return k("ceil")}function a(){return k("cos")}function u(O){const U="elu";return{body:` const float alpha = float(${O}); float ${U}_(float a) { return a >= 0.0 ? a: (exp(a) - 1.0) * alpha; } vec4 ${U}_(vec4 v) { return vec4(${U}_(v.x), ${U}_(v.y), ${U}_(v.z), ${U}_(v.w)); } `,name:U,type:c.FunctionType.ValueBased}}function m(){return k("exp")}function g(){return k("floor")}function _(O,U){const K="clip";return{body:` const float min = float(${O}); const float max = float(${U}); float ${K}_(float a) { return clamp(a, min, max); } vec4 ${K}_(vec4 v) { return clamp(v, min, max); } `,name:K,type:c.FunctionType.ValueBased}}function b(){const O="indentity";return{body:` float ${O}_(float a) { return a; } vec4 ${O}_(vec4 v) { return v; } `,name:O,type:c.FunctionType.ValueBased}}function y(O){const U="leakyRelu";return{body:` const float alpha = float(${O}); float ${U}_(float a) { return a < 0.0 ? a * alpha : a; } vec4 ${U}_(vec4 v) { return vec4(${U}_(v.x), ${U}_(v.y), ${U}_(v.z), ${U}_(v.w)); } `,name:U,type:c.FunctionType.ValueBased}}function v(){return k("log")}function x(){const O="neg";return{body:` float ${O}_(float a) { return -a; } vec4 ${O}_(vec4 v) { return -v; } `,name:O,type:c.FunctionType.ValueBased}}function w(){const O="not";return{body:` float ${O}_(float a) { return float( ! bool(a) ); } bool ${O}_(bool a) { return !a; } vec4 ${O}_(vec4 v) { return vec4(!bool(v.x), !bool(v.y), !bool(v.z), !bool(v.w)); } bvec4 ${O}_(bvec4 v) { return bvec4(!v.x, !v.y, !v.z, !v.w); } `,name:O,type:c.FunctionType.ValueBased}}function S(){return k("sin")}function M(){const O="relu";return{body:` float ${O}_(float a) { return max( a, 0.0 ); } vec4 ${O}_(vec4 v) { return max( v, 0.0 ); } `,name:O,type:c.FunctionType.ValueBased}}function T(){const O="sigmoid";return{body:` float ${O}_(float a) { return 1.0 / (1.0 + exp(-a)); } vec4 ${O}_(vec4 v) { return 1.0 / (1.0 + exp(-v)); } `,name:O,type:c.FunctionType.ValueBased}}function E(){return k("sqrt")}function R(){return k("tan")}function I(){const O="tanh";return{body:` float ${O}_(float a) { a = clamp(a, -10., 10.); a = exp(2.*a); return (a - 1.) / (a + 1.); } vec4 ${O}_(vec4 v) { v = clamp(v, -10., 10.); v = exp(2.*v); return (v - 1.) / (v + 1.); } `,name:O,type:c.FunctionType.ValueBased}}function k(O){return{body:` float ${O}_(float a) { return ${O}(a); } vec4 ${O}_(vec4 v) { return ${O}(v); } `,name:O,type:c.FunctionType.ValueBased}}e.glslAbs=p,e.glslAcos=f,e.glslAsin=d,e.glslAtan=i,e.glslCeil=n,e.glslCos=a,e.glslElu=u,e.glslExp=m,e.glslFloor=g,e.glslClip=_,e.glslIdentity=b,e.glslLeakyRelu=y,e.glslLog=v,e.glslNeg=x,e.glslNot=w,e.glslSin=S,e.glslRelu=M,e.glslSigmoid=T,e.glslSqrt=E,e.glslTan=R,e.glslTanh=I;const C=(O,U,K,$)=>{const J=O.session.pack?h.TextureType.packed:h.TextureType.unpacked,ee={name:K.name,inputTypes:[J],inputNames:["A"],cacheHint:$};return Object.assign(Object.assign({},ee),{get:()=>((he,ie,le,de)=>{const Me=he.session.pack?h.TextureType.packed:h.TextureType.unpacked,Ee=(0,l.getGlsl)(he.session.backend.glContext.version);return Object.assign(Object.assign({},ie),{output:{dims:le.dims,type:le.type,textureType:Me},shaderSource:` ${de.body} void main() { vec4 v = ${Ee.texture2D}(A, TexCoords); v = ${de.name}_(v); ${Ee.output} = v; } `,hasMain:!0})})(O,ee,U,K)})};e.abs=(O,U)=>[O.run(C(O,U[0],p()),U)],e.acos=(O,U)=>[O.run(C(O,U[0],f()),U)],e.asin=(O,U)=>[O.run(C(O,U[0],d()),U)],e.atan=(O,U)=>[O.run(C(O,U[0],i()),U)],e.clip=(O,U,K)=>[O.run(C(O,U[0],_(K.min,K.max),K.cacheKey),U)],e.parseClipAttributes=O=>(0,r.createAttributeWithCacheKey)({min:O.attributes.getFloat("min",o.MIN_CLIP),max:O.attributes.getFloat("max",o.MAX_CLIP)}),e.clipV11=(O,U)=>{const K=z(O,U);return(0,e.clip)(O,[U[0]],K)};const z=(O,U)=>{if(U.length>=3&&(!O.session.isInitializer(U[1].dataId)||!O.session.isInitializer(U[2].dataId)))throw new Error("dynamic clip attributes are not allowed");const K=U.length>=3?U[1].numberData[0]:o.MIN_CLIP,$=U.length>=3?U[2].numberData[0]:o.MAX_CLIP;return(0,r.createAttributeWithCacheKey)({min:K,max:$})};e.ceil=(O,U)=>[O.run(C(O,U[0],n()),U)],e.cos=(O,U)=>[O.run(C(O,U[0],a()),U)],e.elu=(O,U,K)=>[O.run(C(O,U[0],u(K.alpha),K.cacheKey),U)],e.parseEluAttributes=O=>(0,r.createAttributeWithCacheKey)({alpha:O.attributes.getFloat("alpha",1)}),e.exp=(O,U)=>[O.run(C(O,U[0],m()),U)],e.floor=(O,U)=>[O.run(C(O,U[0],g()),U)],e.identity=(O,U)=>[O.run(C(O,U[0],b()),U)],e.leakyRelu=(O,U,K)=>[O.run(C(O,U[0],y(K.alpha),K.cacheKey),U)],e.parseLeakyReluAttributes=O=>(0,r.createAttributeWithCacheKey)({alpha:O.attributes.getFloat("alpha",.01)}),e.log=(O,U)=>[O.run(C(O,U[0],v()),U)],e.neg=(O,U)=>[O.run(C(O,U[0],x()),U)],e.not=(O,U)=>[O.run(C(O,U[0],w()),U)],e.relu=(O,U)=>[O.run(C(O,U[0],M()),U)],e.sigmoid=(O,U)=>[O.run(C(O,U[0],T()),U)],e.sin=(O,U)=>[O.run(C(O,U[0],S()),U)],e.sqrt=(O,U)=>[O.run(C(O,U[0],E()),U)],e.tan=(O,U)=>[O.run(C(O,U[0],R()),U)],e.tanh=(O,U)=>[O.run(C(O,U[0],I()),U)]},5611:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createUnpackProgramInfoLoader=e.createUnpackProgramInfo=void 0;const r=t(5060),o=t(2039),c=t(9390),l=t(2827),h={name:"unpack",inputNames:["A"],inputTypes:[o.TextureType.packed]};e.createUnpackProgramInfo=(p,f)=>{const d=f.dims.length,i=(0,l.getChannels)("rc",d),n=i.slice(-2),a=(0,c.getCoordsDataType)(d),u=(0,l.unpackFromChannel)(),m=f.dims.length===0?"":function(b,y){if(b===1)return"rc";let v="";for(let x=0;xObject.assign(Object.assign({},h),{get:()=>(0,e.createUnpackProgramInfo)(p,f)})},8428:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.parseUnsqueezeAttributes=e.unsqueezeV13=e.unsqueeze=void 0;const r=t(2517);e.unsqueeze=(l,h,p)=>{o(h);const f=r.ShapeUtil.unsqueezeShape(h[0].dims,p);return[l.reshapeUnpacked(h[0],f)]},e.unsqueezeV13=(l,h)=>(c(h),(0,e.unsqueeze)(l,[h[0]],Array.from(h[1].integerData))),e.parseUnsqueezeAttributes=l=>l.attributes.getInts("axes");const o=l=>{if(!l||l.length!==1)throw new Error("Unsqueeze requires 1 input.");if(l[0].type==="string")throw new Error("invalid input tensor types.")},c=l=>{if(!l||l.length!==2)throw new Error("Unsqueeze requires 2 inputs.");if(l[1].type!=="int32")throw new Error("Invalid input type.")}},9793:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.scalesValidation=e.validateInputs=e.parseUpsampleAttributes=e.parseUpsampleAttributesV9=e.parseUpsampleAttributesV7=e.upsample=void 0;const r=t(246),o=t(5060),c=t(2039),l={name:"Upsample",inputNames:["X"],inputTypes:[c.TextureType.unpacked]};e.upsample=(p,f,d)=>((0,e.validateInputs)(f,d),[p.run(Object.assign(Object.assign({},l),{cacheHint:d.cacheKey,get:()=>h(p,f,d)}),f)]),e.parseUpsampleAttributesV7=p=>(0,e.parseUpsampleAttributes)(p,7),e.parseUpsampleAttributesV9=p=>(0,e.parseUpsampleAttributes)(p,9),e.parseUpsampleAttributes=(p,f)=>{const d=f>=10,i=p.attributes.getString("mode","nearest");if(i!=="nearest"&&i!=="linear"&&(f<11||i!=="cubic"))throw new Error(`unrecognized mode: ${i}`);let n=[];f<9&&(n=p.attributes.getFloats("scales"),(0,e.scalesValidation)(n,i,d));const a=p.attributes.getFloat("extrapolation_value",0),u=f>10?p.attributes.getString("coordinate_transformation_mode","half_pixel"):"asymmetric";if(["asymmetric","pytorch_half_pixel","tf_half_pixel_for_nn","align_corners","tf_crop_and_resize","half_pixel"].indexOf(u)===-1)throw new Error(`coordinate_transform_mode '${u}' is not supported`);const m=u==="tf_crop_and_resize",g=m,_=i==="nearest"&&f>=11?p.attributes.getString("nearest_mode","round_prefer_floor"):"";if(["round_prefer_floor","round_prefer_ceil","floor","ceil",""].indexOf(_)===-1)throw new Error(`nearest_mode '${_}' is not supported`);const b=p.attributes.getFloat("cubic_coeff_a",-.75),y=p.attributes.getInt("exclude_outside",0)!==0;if(y&&i!=="cubic")throw new Error("exclude_outside can be set to 1 only when mode is CUBIC.");const v=f<11||i==="nearest"&&u==="asymmetric"&&_==="floor";let x=0,w=0,S=0;return f>10?p.inputs.length>2?(x=1,w=2,S=3):(w=1,S=2):f===9&&(w=1),(0,r.createAttributeWithCacheKey)({opset:f,isResize:d,mode:i,scales:n,extrapolationValue:a,coordinateTransformMode:u,useExtrapolation:g,needRoiInput:m,nearestMode:_,cubicCoefficientA:b,excludeOutside:y,useNearest2xOptimization:v,roiInputIdx:x,scalesInputIdx:w,sizesInputIdx:S})};const h=(p,f,d)=>{const i=(0,o.getGlsl)(p.session.backend.glContext.version),[n,a]=p.calculateTextureWidthAndHeight(f[0].dims,c.TextureType.unpacked),u=f[0].dims.map((S,M)=>Math.floor(S*d.scales[M])),[m,g]=p.calculateTextureWidthAndHeight(u,c.TextureType.unpacked),_=u.length,b=new Array(_),y=new Array(_);let v=` int output_pitches[${_}]; int input_pitches[${_}]; `;for(let S=_-1;S>=0;S--)b[S]=S===_-1?1:b[S+1]*u[S+1],y[S]=S===_-1?1:y[S+1]*f[0].dims[S+1],v+=` output_pitches[${S}] = ${b[S]}; input_pitches[${S}] = ${y[S]}; `;const x=` float getInputFloat(int index) { vec2 coords = offsetToCoords(index, ${n}, ${a}); float value = getColorAsFloat(${i.texture2D}(X, coords)); return value; } `,w=d.mode==="nearest"?` ${x} float process(int indices[${_}]) { int input_index = 0; int output_index = coordsToOffset(TexCoords, ${m}, ${g}); ${v} int d, m; for (int dim = 0; dim < ${_}; ++dim) { d = output_index / output_pitches[dim]; m = output_index - d * output_pitches[dim]; output_index = m; if (scales[dim] != 1 && d > 0) { int d2 = d / scales[dim]; m = d - d2 * scales[dim]; d = d2; } input_index += input_pitches[dim] * d; } return getInputFloat(input_index); }`:_===4?` ${x} float process(int indices[4]) { int input_index = 0; int output_index = coordsToOffset(TexCoords, ${m}, ${g}); ${v} int m; int index_of_dim0, index_of_dim1, index_of_dim2, index_of_dim3; index_of_dim0 = output_index / output_pitches[0]; m = output_index - index_of_dim0 * output_pitches[0]; index_of_dim1 = m / output_pitches[1]; m = m - index_of_dim1 * output_pitches[1]; index_of_dim2 = m / output_pitches[2]; m = m - index_of_dim2 * output_pitches[2]; index_of_dim3 = m; int index_of_input_dim2, index_of_input_dim3, x_offset, y_offset; index_of_input_dim2 = index_of_dim2 / scales[2]; y_offset = index_of_dim2 - index_of_input_dim2 * scales[2]; index_of_input_dim3 = index_of_dim3 / scales[3]; x_offset = index_of_dim3 - index_of_input_dim3 * scales[3]; input_index = index_of_dim0 * input_pitches[0] + index_of_dim1 * input_pitches[1] + index_of_input_dim2 * input_pitches[2] + index_of_input_dim3; float x00 = getInputFloat(input_index); float x10, x01, x11; bool end_of_dim2 = false; if (index_of_input_dim2 == (${f[0].dims[2]} - 1)) { // It's the end in dimension 2 x01 = x00; end_of_dim2 = true; } else { x01 = getInputFloat(input_index + input_pitches[2]); } if (index_of_input_dim3 == (input_pitches[2] - 1)) { // It's the end in dimension 3 x10 = x00; x11 = x01; } else { x10 = getInputFloat(input_index + 1); x11 = end_of_dim2 ? x10 : getInputFloat(input_index + input_pitches[2] + 1); } float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[2]); float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[2]); return y0 + float(x_offset) * (y1 - y0) / float(scales[3]); }`:` ${x} float process(int indices[2]) { int input_index = 0; int output_index = coordsToOffset(TexCoords, ${m}, ${g}); ${v} int m; int index_of_dim0, index_of_dim1; index_of_dim0 = output_index / output_pitches[0]; m = output_index - index_of_dim0 * output_pitches[0]; index_of_dim1 = m; int index_of_input_dim0, index_of_input_dim1, x_offset, y_offset; index_of_input_dim0 = index_of_dim0 / scales[0]; y_offset = index_of_dim0 - index_of_input_dim0 * scales[0]; index_of_input_dim1 = index_of_dim1 / scales[1]; x_offset = index_of_dim1 - index_of_input_dim1 * scales[1]; input_index = index_of_input_dim0 * input_pitches[0] + index_of_input_dim1; float x00 = getInputFloat(input_index); float x10, x01, x11; bool end_of_dim0 = false; if (index_of_input_dim0 == (${f[0].dims[0]} - 1)) { // It's the end in dimension 0 x01 = x00; end_of_dim0 = true; } else { x01 = getInputFloat(input_index + input_pitches[0]); } if (index_of_input_dim1 == (input_pitches[0] - 1)) { // It's the end in dimension 1 x10 = x00; x11 = x01; } else { x10 = getInputFloat(input_index + 1); x11 = end_of_dim0 ? x10 : getInputFloat(input_index + input_pitches[0] + 1); } float y0 = x00 + float(y_offset) * (x01 - x00) / float(scales[0]); float y1 = x10 + float(y_offset) * (x11 - x10) / float(scales[0]); return y0 + float(x_offset) * (y1 - y0) / float(scales[1]); }`;return Object.assign(Object.assign({},l),{output:{dims:u,type:f[0].type,textureType:c.TextureType.unpacked},shaderSource:w,variables:[{name:"scales",type:"int",arrayLength:d.scales.length,data:d.scales.map(S=>Math.ceil(S))}]})};e.validateInputs=(p,f)=>{if(!p||f.opset<9&&p.length!==1||f.opset>=9&&f.opset<11&&p.length!==2||f.opset>=11&&p.length<2)throw new Error("invalid inputs.");if(f.scales.length>0&&p[0].dims.length!==f.scales.length)throw new Error("Invalid input shape.");if(p[0].type==="string")throw new Error("Invalid input tensor types.")},e.scalesValidation=(p,f,d)=>{if(d){for(const i of p)if(i<=0)throw new Error("Scale value should be greater than 0.")}else for(const i of p)if(i<1)throw new Error("Scale value should be greater than or equal to 1.");if(!(f!=="linear"&&f!=="cubic"||p.length===2||p.length===4&&p[0]===1&&p[1]===1))throw new Error(`'Linear' mode and 'Cubic' mode only support 2-D inputs ('Bilinear', 'Bicubic') or 4-D inputs with the corresponding outermost 2 scale values being 1 in the ${d?"Resize":"Upsample"} opeartor.`)}},1958:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ProgramManager=void 0;const r=t(1670),o=t(6231),c=t(8879),l=t(5060);e.ProgramManager=class{constructor(h,p,f){this.profiler=h,this.glContext=p,this.textureLayoutStrategy=f,this.repo=new Map,this.attributesBound=!1}getArtifact(h){return this.repo.get(h)}setArtifact(h,p){this.repo.set(h,p)}run(h,p,f){var d;this.profiler.event("op",`ProgramManager.run ${(d=h.programInfo.name)!==null&&d!==void 0?d:"unknown kernel"}`,()=>{var i;const n=this.glContext.gl,a=h.program;n.useProgram(a);try{this.bindOutput(f),this.attributesBound||this.bindAttributes(h.attribLocations),this.bindUniforms(h.uniformLocations,(i=h.programInfo.variables)!==null&&i!==void 0?i:[],p)}catch(u){throw o.Logger.error("ProgramManager",h.programInfo.shaderSource),u}this.profiler.event("backend","GlContext.draw()",()=>{this.glContext.draw()})},this.glContext)}dispose(){this.vertexShader&&this.glContext.deleteShader(this.vertexShader),this.repo.forEach(h=>this.glContext.deleteProgram(h.program))}build(h,p,f){return this.profiler.event("backend","ProgramManager.build",()=>{const d=new c.GlslPreprocessor(this.glContext,h,p,f),i=d.preprocess(),n=this.compile(i);return{programInfo:h,program:n,uniformLocations:this.getUniformLocations(n,d.context.programInfo.inputNames,d.context.programInfo.variables),attribLocations:this.getAttribLocations(n)}})}compile(h){if(!this.vertexShader){o.Logger.verbose("ProrgramManager","Compiling and caching Vertex shader for the first time");const d=(0,l.getVertexShaderSource)(this.glContext.version);this.vertexShader=this.glContext.compileShader(d,this.glContext.gl.VERTEX_SHADER)}r.env.debug&&o.Logger.verbose("ProrgramManager",`FragShader: ${h} `);const p=this.glContext.compileShader(h,this.glContext.gl.FRAGMENT_SHADER),f=this.glContext.createProgram(this.vertexShader,p);return this.glContext.deleteShader(p),f}bindOutput(h){const p=h.width,f=h.height;o.Logger.verbose("ProrgramManager",`Binding output texture to Framebuffer: w/h=${p}/${f}, shape=${h.shape}, type=${h.tensor.type}`),this.glContext.attachFramebuffer(h.texture,p,f)}bindAttributes(h){const p=h.position,f=h.textureCoord;this.glContext.setVertexAttributes(p,f),this.attributesBound=!0}bindUniforms(h,p,f){var d;const i=this.glContext.gl;let n=0;for(const{name:a,type:u,location:m,arrayLength:g}of h){const _=(d=p.find(b=>b.name===a))===null||d===void 0?void 0:d.data;if(u!=="sampler2D"&&!_)throw new Error(`variable '${a}' does not have data defined in program info`);switch(u){case"sampler2D":this.bindTexture(f[n],m,n),n++;break;case"float":g?i.uniform1fv(m,_):i.uniform1f(m,_);break;case"int":g?i.uniform1iv(m,_):i.uniform1i(m,_);break;default:throw new Error(`Uniform not implemented: ${u}`)}}}bindTexture(h,p,f){this.glContext.bindTextureToUniform(h.texture,f,p)}getAttribLocations(h){return{position:this.getAttribLocation(h,"position"),textureCoord:this.getAttribLocation(h,"textureCoord")}}getUniformLocations(h,p,f){const d=[];if(p)for(const i of p)d.push({name:i,type:"sampler2D",location:this.getUniformLocation(h,i)});if(f)for(const i of f)d.push(Object.assign(Object.assign({},i),{location:this.getUniformLocation(h,i.name)}));return d}getUniformLocation(h,p){const f=this.glContext.gl.getUniformLocation(h,p);if(f===null)throw new Error(`Uniform ${p} not found.`);return f}getAttribLocation(h,p){return this.glContext.gl.getAttribLocation(h,p)}}},6416:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.WebGLSessionHandler=void 0;const r=t(6231),o=t(1047),c=t(8316),l=t(1640),h=t(1958),p=t(7859),f=t(5702);e.WebGLSessionHandler=class{constructor(d,i){this.backend=d,this.context=i,this.layoutStrategy=new p.PreferLogicalStrategy(d.glContext.maxTextureSize),this.programManager=new h.ProgramManager(this.context.profiler,d.glContext,this.layoutStrategy),this.textureManager=new f.TextureManager(d.glContext,this.layoutStrategy,this.context.profiler,{reuseTextures:d.textureCacheMode==="full"}),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache=new Map,this.pack=d.pack,this.pack2unpackMap=new Map,this.unpack2packMap=new Map}createInferenceHandler(){return new c.WebGLInferenceHandler(this)}onGraphInitialized(d){const i=d.getValues().filter(n=>n.from===-1&&n.tensor).map(n=>n.tensor.dataId);this.initializers=new Set(i)}isInitializer(d){return!!this.initializers&&this.initializers.has(d)}addInitializer(d){this.initializers.add(d)}getTextureData(d,i){return i?this.packedTextureDataCache.get(d):this.unpackedTextureDataCache.get(d)}setTextureData(d,i,n=!1){r.Logger.verbose("WebGLSessionHandler","Storing Texture data in cache"),n?this.packedTextureDataCache.set(d,i):this.unpackedTextureDataCache.set(d,i)}dispose(){this.programManager.dispose(),this.textureManager.clearActiveTextures(),this.packedTextureDataCache.forEach(d=>this.textureManager.releaseTexture(d,!0)),this.packedTextureDataCache=new Map,this.unpackedTextureDataCache.forEach(d=>this.textureManager.releaseTexture(d,!0)),this.unpackedTextureDataCache=new Map}resolve(d,i,n){const a=(0,o.resolveOperator)(d,i,l.WEBGL_OP_RESOLVE_RULES);return{impl:a.opImpl,context:a.opInit?a.opInit(d,n):d}}}},7769:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Uint8DataEncoder=e.RGBAFloatDataEncoder=e.RedFloat32DataEncoder=void 0;const r=t(6231);e.RedFloat32DataEncoder=class{constructor(o,c=1){if(c===1)this.internalFormat=o.R32F,this.format=o.RED,this.textureType=o.FLOAT,this.channelSize=c;else{if(c!==4)throw new Error(`Invalid number of channels: ${c}`);this.internalFormat=o.RGBA32F,this.format=o.RGBA,this.textureType=o.FLOAT,this.channelSize=c}}encode(o,c){let l,h;return o.constructor!==Float32Array&&(r.Logger.warning("Encoder","data was not of type Float32; creating new Float32Array"),h=new Float32Array(o)),c*this.channelSize>o.length?(r.Logger.warning("Encoder","Source data too small. Allocating larger array"),h=o,l=this.allocate(c*this.channelSize),h.forEach((p,f)=>l[f]=p)):(h=o,l=h),l}allocate(o){return new Float32Array(4*o)}decode(o,c){return this.channelSize===1?o.filter((l,h)=>h%4==0).subarray(0,c):o.subarray(0,c)}},e.RGBAFloatDataEncoder=class{constructor(o,c=1,l){if(c!==1&&c!==4)throw new Error(`Invalid number of channels: ${c}`);this.internalFormat=o.RGBA,this.format=o.RGBA,this.channelSize=c,this.textureType=l||o.FLOAT}encode(o,c){let l=o;return this.channelSize===1&&(r.Logger.verbose("Encoder","Exploding into a larger array"),l=this.allocate(c),o.forEach((h,p)=>l[4*p]=h)),l}allocate(o){return new Float32Array(4*o)}decode(o,c){return this.channelSize===1?o.filter((l,h)=>h%4==0).subarray(0,c):o.subarray(0,c)}},e.Uint8DataEncoder=class{constructor(o,c=1){if(this.channelSize=4,c===1)this.internalFormat=o.ALPHA,this.format=o.ALPHA,this.textureType=o.UNSIGNED_BYTE,this.channelSize=c;else{if(c!==4)throw new Error(`Invalid number of channels: ${c}`);this.internalFormat=o.RGBA,this.format=o.RGBA,this.textureType=o.UNSIGNED_BYTE,this.channelSize=c}}encode(o,c){return new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}allocate(o){return new Uint8Array(o*this.channelSize)}decode(o,c){if(o instanceof Uint8Array)return o.subarray(0,c);throw new Error(`Invalid array type: ${o.constructor}`)}}},7859:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getBatchDim=e.sizeToSquarishShape=e.getRowsCols=e.sizeFromShape=e.isInt=e.parseAxisParam=e.squeezeShape=e.PreferLogicalStrategy=e.AlwaysKeepOriginalSizeStrategy=void 0;const r=t(6231),o=t(2517);function c(d,i){const n=[],a=[],u=i!=null&&Array.isArray(i)&&i.length===0,m=i==null||u?null:l(i,d).sort();let g=0;for(let _=0;__)&&d[_]===1&&(n.push(d[_]),a.push(_)),m[g]<=_&&g++}d[_]!==1&&(n.push(d[_]),a.push(_))}return{newShape:n,keptDims:a}}function l(d,i){const n=i.length;return d=d==null?i.map((a,u)=>u):[].concat(d),(0,o.assert)(d.every(a=>a>=-n&&a`All values in axis param must be in range [-${n}, ${n}) but got axis ${d}`),(0,o.assert)(d.every(h),()=>`All values in axis param must be integers but got axis ${d}`),d.map(a=>a<0?n+a:a)}function h(d){return d%1==0}function p(d){if(d.length===0)return 1;let i=d[0];for(let n=1;n=d.length?1:d.slice(i.breakAxis).reduce((_,b)=>_*b),g=i.breakAxis<=0?1:d.slice(0,i.breakAxis).reduce((_,b)=>_*b);if(!(m>n||g>n))return[m,g];r.Logger.verbose("TextureLayout",`Given width/height preferences were unattainable: shape:${d}, breakAxis:${i.breakAxis}`)}const a=d.reduce((m,g)=>m*g);let u=Math.floor(Math.sqrt(a));for(;u=n||a%u!=0)throw new Error(`The given dimensions are outside this GPU's boundaries: ${d}`);return[u,a/u]}},e.PreferLogicalStrategy=class{constructor(d){this.maxTextureSize=d}computeTextureWH(d,i){const n=this.computeTexture(d,i);return i&&i.isPacked&&(n[0]/=2,n[1]/=2),i&&i.reverseWH?[n[1],n[0]]:n}computeTexture(d,i){const n=i&&i.isPacked;if(d.length===0)return n?[2,2]:[1,1];let a=this.maxTextureSize;if(i&&i.breakAxis!==void 0){const g=i.breakAxis>=d.length?1:d.slice(i.breakAxis).reduce((b,y)=>b*y),_=i.breakAxis<=0?1:d.slice(0,i.breakAxis).reduce((b,y)=>b*y);if(!(g>a||_>a))return[g,_];r.Logger.verbose("TextureLayout",`Given width/height preferences were unattainable: shape:${d}, breakAxis:${i.breakAxis}`)}let u=d.slice(0);n&&(a*=2,u=u.map((g,_)=>_>=u.length-2?u[_]%2==0?u[_]:u[_]+1:u[_]),u.length===1&&(u=[2,u[0]])),u.length!==2&&(u=c(u).newShape);const m=p(u);return u.length<=1&&m<=a?[1,m]:u.length===2&&u[0]<=a&&u[1]<=a?u:u.length===3&&u[0]*u[1]<=a&&u[2]<=a?[u[0]*u[1],u[2]]:u.length===3&&u[0]<=a&&u[1]*u[2]<=a?[u[0],u[1]*u[2]]:u.length===4&&u[0]*u[1]*u[2]<=a&&u[3]<=a?[u[0]*u[1]*u[2],u[3]]:u.length===4&&u[0]<=a&&u[1]*u[2]*u[3]<=a?[u[0],u[1]*u[2]*u[3]]:n?f(m/4).map(g=>2*g):f(m)}},e.squeezeShape=c,e.parseAxisParam=l,e.isInt=h,e.sizeFromShape=p,e.getRowsCols=function(d){if(d.length===0)throw Error("Cannot get rows and columns of an empty shape array.");return[d.length>1?d[d.length-2]:1,d[d.length-1]]},e.sizeToSquarishShape=f,e.getBatchDim=function(d,i=2){return p(d.slice(0,d.length-i))}},4057:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createTextureLayoutFromShape=e.calculateTextureWidthAndHeight=e.createTextureLayoutFromTextureType=void 0;const r=t(2517),o=t(2039);e.createTextureLayoutFromTextureType=(c,l,h)=>{const p=h===o.TextureType.unpacked||h===o.TextureType.unpackedReversed?1:4,f=h===o.TextureType.packed,d=h===o.TextureType.unpackedReversed||h===o.TextureType.packed,i=h===o.TextureType.packedLastDimension?l.length-1:void 0,n=h===o.TextureType.packedLastDimension?l.map((a,u)=>u===l.length-1?4*a:a):void 0;return(0,e.createTextureLayoutFromShape)(c,l,p,n,{isPacked:f,reverseWH:d,breakAxis:i})},e.calculateTextureWidthAndHeight=(c,l,h)=>{const p=(0,e.createTextureLayoutFromTextureType)(c,l,h);return[p.width,p.height]},e.createTextureLayoutFromShape=(c,l,h=1,p,f)=>{const d=!(!f||!f.isPacked),[i,n]=c.computeTextureWH(d&&p||l,f),a=l.length;let u=l.slice(0);if(a===0&&(u=[1]),h===1)p=l;else if(d){if(h!==4)throw new Error("a packed texture must be 4-channel");p=l,a>0&&(u[a-1]=Math.ceil(u[a-1]/2)),a>1&&(u[a-2]=Math.ceil(u[a-2]/2))}else if(!p)throw new Error("Unpacked shape is needed when using channels > 1");return{width:i,height:n,channels:h,isPacked:d,shape:u,strides:r.ShapeUtil.computeStrides(u),unpackedShape:p,reversedWH:f&&f.reverseWH}}},5702:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TextureManager=void 0;const r=t(6231);e.TextureManager=class{constructor(o,c,l,h){this.glContext=o,this.layoutStrategy=c,this.profiler=l,this.config=h,this.pendingRead=new Map,h.reuseTextures&&(this.inUseTextures=new Map,this.idleTextures=new Map,this.textureLookup=new Map)}createTextureFromLayout(o,c,l,h){const p=this.toEncoderType(o),f=this.glContext.getEncoder(p,c.channels||1,h);if(c.isPacked&&h===1)throw new Error("not implemented");const d=c.width,i=c.height;let n,a;if(this.config.reuseTextures){n=`${d}x${i}_${f.format}_${f.internalFormat}_${f.textureType}`,a=this.inUseTextures.get(n),a||(a=[],this.inUseTextures.set(n,a));const m=this.idleTextures.get(n);if(m&&m.length>0){const g=m.pop();return a.push(g),h===1&&this.glContext.updateTexture(g,d,i,f,this.toTextureData(o,l)),g}}r.Logger.verbose("TextureManager",`Creating new texture of size ${c.width}x${c.height}`);const u=this.glContext.allocateTexture(d,i,f,this.toTextureData(o,l));return this.config.reuseTextures&&(a.push(u),this.textureLookup.set(u,n)),u}readTexture(o,c,l){return l||(l=1),this.profiler.event("backend","TextureManager.readTexture",()=>{const h=o.shape.reduce((f,d)=>f*d)*l,p=this.glContext.readTexture(o.texture,o.width,o.height,h,this.toEncoderType(c),l);return this.toTensorData(c,p)})}async readTextureAsync(o,c,l){const h=o.tensor.dataId;if(l||(l=1),this.pendingRead.has(h)){const p=this.pendingRead.get(h);return new Promise(f=>p?.push(f))}return this.profiler.event("backend","TextureManager.readTextureAsync",async()=>{this.pendingRead.set(h,[]);const p=o.shape.reduce((n,a)=>n*a)*l;await this.glContext.createAndWaitForFence();const f=this.glContext.readTexture(o.texture,o.width,o.height,p,this.toEncoderType(c),l),d=this.toTensorData(c,f),i=this.pendingRead.get(h);return this.pendingRead.delete(h),i?.forEach(n=>n(d)),d})}readUint8TextureAsFloat(o){return this.profiler.event("backend","TextureManager.readUint8TextureAsFloat",()=>{const c=o.shape.reduce((h,p)=>h*p),l=this.glContext.readTexture(o.texture,o.width,o.height,4*c,"byte",4);return new Float32Array(l.buffer,l.byteOffset,c)})}releaseTexture(o,c){let l;if(this.config.reuseTextures&&(l=this.textureLookup.get(o.texture),l)){c&&this.textureLookup.delete(l);const h=this.inUseTextures.get(l);if(h){const p=h.indexOf(o.texture);if(p!==-1){h.splice(p,1);let f=this.idleTextures.get(l);f||(f=[],this.idleTextures.set(l,f)),f.push(o.texture)}}}l&&!c||(r.Logger.verbose("TextureManager",`Deleting texture of size ${o.width}x${o.height}`),this.glContext.deleteTexture(o.texture))}toTensorData(o,c){switch(o){case"int16":return c instanceof Int16Array?c:Int16Array.from(c);case"int32":return c instanceof Int32Array?c:Int32Array.from(c);case"int8":return c instanceof Int8Array?c:Int8Array.from(c);case"uint16":return c instanceof Uint16Array?c:Uint16Array.from(c);case"uint32":return c instanceof Uint32Array?c:Uint32Array.from(c);case"uint8":case"bool":return c instanceof Uint8Array?c:Uint8Array.from(c);case"float32":return c instanceof Float32Array?c:Float32Array.from(c);case"float64":return c instanceof Float64Array?c:Float64Array.from(c);default:throw new Error(`TensorData type ${o} is not supported`)}}toTextureData(o,c){if(c)return c instanceof Float32Array?c:new Float32Array(c)}toEncoderType(o){return"float"}clearActiveTextures(){this.glContext.clearActiveTextures()}}},2039:(s,e)=>{var t;Object.defineProperty(e,"__esModule",{value:!0}),e.TextureType=void 0,(t=e.TextureType||(e.TextureType={}))[t.unpacked=0]="unpacked",t[t.unpackedReversed=1]="unpackedReversed",t[t.packed=2]="packed",t[t.downloadUint8AsFloat=3]="downloadUint8AsFloat",t[t.packedLastDimension=4]="packedLastDimension"},9390:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getGlChannels=e.getCoordsDataType=e.getSqueezedParams=e.squeezeInputShape=e.generateShaderFuncNameFromInputSamplerNameAtOutCoords=e.generateShaderFuncNameFromInputSamplerName=e.repeatedTry=e.getPackedShape=void 0;const r=t(2517);e.getPackedShape=function(o){const c=o.length;return o.slice(0,c-1).concat(o[c-1]/4)},e.repeatedTry=async function(o,c=h=>0,l){return new Promise((h,p)=>{let f=0;const d=()=>{if(o())return void h();f++;const i=c(f);l!=null&&f>=l?p():setTimeout(d,i)};d()})},e.generateShaderFuncNameFromInputSamplerName=function(o){return(0,r.assert)(o!==void 0&&o.length!==0,()=>"empty string found for sampler name"),"get"+o.charAt(0).toUpperCase()+o.slice(1)},e.generateShaderFuncNameFromInputSamplerNameAtOutCoords=function(o){return(0,r.assert)(o!==void 0&&o.length!==0,()=>"empty string found for sampler name"),"get"+o.charAt(0).toUpperCase()+o.slice(1)+"AtOutCoords"},e.squeezeInputShape=function(o,c){let l=JSON.parse(JSON.stringify(o));return l=c,l},e.getSqueezedParams=function(o,c){return c.map(l=>o[l]).join(", ")},e.getCoordsDataType=function(o){if(o<=1)return"int";if(o===2)return"ivec2";if(o===3)return"ivec3";if(o===4)return"ivec4";if(o===5)return"ivec5";if(o===6)return"ivec6";throw Error(`GPU for rank ${o} is not yet supported`)},e.getGlChannels=function(o=6){return["x","y","z","w","u","v"].slice(0,o)}},7305:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.createNewWebGLContext=e.createWebGLContext=void 0;const r=t(6231),o=t(1713),c={};function l(h){const p=function(){if(typeof document>"u"){if(typeof OffscreenCanvas>"u")throw new TypeError("failed to create canvas: OffscreenCanvas is not supported");return new OffscreenCanvas(1,1)}const i=document.createElement("canvas");return i.width=1,i.height=1,i}();let f;const d={alpha:!1,depth:!1,antialias:!1,stencil:!1,preserveDrawingBuffer:!1,premultipliedAlpha:!1,failIfMajorPerformanceCaveat:!1};if((!h||h==="webgl2")&&(f=p.getContext("webgl2",d),f))try{return new o.WebGLContext(f,2)}catch(i){r.Logger.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl2'. Error: ${i}`)}if((!h||h==="webgl")&&(f=p.getContext("webgl",d)||p.getContext("experimental-webgl",d),f))try{return new o.WebGLContext(f,1)}catch(i){r.Logger.warning("GlContextFactory",`failed to create WebGLContext using contextId 'webgl' or 'experimental-webgl'. Error: ${i}`)}throw new Error("WebGL is not supported")}e.createWebGLContext=function h(p){let f;p&&p!=="webgl2"||!("webgl2"in c)?p&&p!=="webgl"||!("webgl"in c)||(f=c.webgl):f=c.webgl2,f=f||l(p),p=p||f.version===1?"webgl":"webgl2";const d=f.gl;return c[p]=f,d.isContextLost()?(delete c[p],h(p)):(d.disable(d.DEPTH_TEST),d.disable(d.STENCIL_TEST),d.disable(d.BLEND),d.disable(d.DITHER),d.disable(d.POLYGON_OFFSET_FILL),d.disable(d.SAMPLE_COVERAGE),d.enable(d.SCISSOR_TEST),d.enable(d.CULL_FACE),d.cullFace(d.BACK),f)},e.createNewWebGLContext=l},1713:function(s,e,t){var r=this&&this.__createBinding||(Object.create?function(d,i,n,a){a===void 0&&(a=n);var u=Object.getOwnPropertyDescriptor(i,n);u&&!("get"in u?!i.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return i[n]}}),Object.defineProperty(d,a,u)}:function(d,i,n,a){a===void 0&&(a=n),d[a]=i[n]}),o=this&&this.__setModuleDefault||(Object.create?function(d,i){Object.defineProperty(d,"default",{enumerable:!0,value:i})}:function(d,i){d.default=i}),c=this&&this.__importStar||function(d){if(d&&d.__esModule)return d;var i={};if(d!=null)for(var n in d)n!=="default"&&Object.prototype.hasOwnProperty.call(d,n)&&r(i,d,n);return o(i,d),i};Object.defineProperty(e,"__esModule",{value:!0}),e.WebGLContext=e.linearSearchLastTrue=void 0;const l=t(1670),h=c(t(7769)),p=t(9390);function f(d){let i=0;for(;ithis.isTimerResultAvailable(d)),this.getTimerResult(d)}async createAndWaitForFence(){const d=this.createFence(this.gl);return this.pollFence(d)}createFence(d){let i;const n=d,a=n.fenceSync(n.SYNC_GPU_COMMANDS_COMPLETE,0);return d.flush(),i=a===null?()=>!0:()=>{const u=n.clientWaitSync(a,0,0);return u===n.ALREADY_SIGNALED||u===n.CONDITION_SATISFIED},{query:a,isFencePassed:i}}async pollFence(d){return new Promise(i=>{this.addItemToPoll(()=>d.isFencePassed(),()=>i())})}pollItems(){const d=f(this.itemsToPoll.map(i=>i.isDoneFn));for(let i=0;i<=d;++i){const{resolveFn:n}=this.itemsToPoll[i];n()}this.itemsToPoll=this.itemsToPoll.slice(d+1)}async addItemToPoll(d,i){this.itemsToPoll.push({isDoneFn:d,resolveFn:i}),this.itemsToPoll.length>1||await(0,p.repeatedTry)(()=>(this.pollItems(),this.itemsToPoll.length===0))}}},1036:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ExecutionPlan=void 0;const r=t(6231);class o{constructor(l,h){this.op=l,this.node=h}}e.ExecutionPlan=class{constructor(c,l,h){this.graph=c,this.profiler=h,this.initialize(l)}initialize(c){this.profiler.event("session","ExecutionPlan.initialize",()=>{const l=this.graph.getNodes();if(l.length!==c.length)throw new Error("The size of nodes and OPs do not match.");this._ops=c.map((h,p)=>new o(h,l[p])),this.reset(),this._starter=[],this._ops.forEach((h,p)=>{let f=!0;for(const d of h.node.inputs)if(!this._values[d]&&this.graph.getInputIndices().indexOf(d)===-1){f=!1;break}f&&this._starter.push(p)})})}reset(){this._values=this.graph.getValues().map(c=>c.tensor)}async execute(c,l){return this.profiler.event("session","ExecutionPlan.execute",async()=>{this.reset();const h=c.createInferenceHandler(),p=this.graph.getInputIndices();if(l.length!==p.length)throw new Error(`number of input tensors don't match the number of inputs to the model: actual: ${l.length} expected: ${p.length}`);l.forEach((u,m)=>{const g=p[m];this._values[g]=u});const f=this._starter.slice(0),d=this.graph.getValues(),i=this.graph.getNodes();let n=0;for(;nthis._values[v]);if(g.indexOf(void 0)!==-1)throw new Error(`unresolved input detected: op: ${m.node}`);const _=g;r.Logger.verbose("ExecPlan",`Runing op:${m.node.name} (${_.map((v,x)=>`'${m.node.inputs[x]}': ${v.type}[${v.dims.join(",")}]`).join(", ")})`);const b=await this.profiler.event("node",m.node.name,async()=>m.op.impl(h,_,m.op.context));if(b.length!==m.node.outputs.length)throw new Error("the size of output does not match model definition.");b.forEach((v,x)=>{const w=m.node.outputs[x];if(this._values[w])throw new Error(`output [${w}] already has value: op:${m.node.name}`);this._values[w]=v});const y=new Set;b.forEach((v,x)=>{const w=m.node.outputs[x];for(const S of d[w].to){const M=i[S];let T=!0;for(const E of M.inputs)if(!this._values[E]){T=!1;break}T&&y.add(S)}}),f.push(...y)}const a=[];for(let u=0;u{Object.defineProperty(e,"__esModule",{value:!0}),e.Graph=void 0;const r=t(1446),o=t(7778),c=t(9395),l=t(9162),h=t(2517);var p=c.onnxruntime.experimental.fbs;e.Graph={from:(n,a)=>new i(n,a)};class f{constructor(a){this._from=void 0,this._to=[],this.tensor=void 0,this.type=void 0,a&&(this.type=h.ProtoUtil.tensorValueTypeFromProto(a.type.tensorType))}get from(){return this._from}get to(){return this._to}}class d{constructor(a,u){a instanceof r.onnx.NodeProto?(this.name=a.name,this.opType=a.opType,this.attributes=new o.Attribute(a.attribute)):a instanceof p.Node&&(this.name=u??a.name(),this.opType=a.opType(),this.attributes=new o.Attribute(h.ProtoUtil.tensorAttributesFromORTFormat(a))),this.inputs=[],this.outputs=[],this.executeNode=!0}}class i{constructor(a,u){if(!a)throw new TypeError("graph is empty");this.buildGraph(a),this.transformGraph(u),this.checkIsAcyclic()}getInputIndices(){return this._allInputIndices}getInputNames(){return this._allInputNames}getOutputIndices(){return this._allOutputIndices}getOutputNames(){return this._allOutputNames}getValues(){return this._allData}getNodes(){return this._nodes}buildGraph(a){if(a instanceof r.onnx.GraphProto)this.buildGraphFromOnnxFormat(a);else{if(!(a instanceof p.Graph))throw new TypeError("Graph type is not supported.");this.buildGraphFromOrtFormat(a)}}buildGraphFromOnnxFormat(a){const u=new Map;this._allData=[],this._allInputIndices=[],this._allInputNames=[],this._allOutputIndices=[],this._allOutputNames=[],this._nodes=[];const m=new Map;if(!a.input)throw new Error("missing information in graph: input");const g=[];for(const _ of a.input){if(u.has(_.name))throw new Error(`duplicated input name: ${_.name}`);const b=this._allData.push(new f(_))-1;u.set(_.name,b),g.push(_.name)}if(!a.initializer)throw new Error("missing information in graph: initializer");for(const _ of a.initializer){let b=u.get(_.name);if(b===void 0){const y=new f;y.type={shape:{dims:h.ProtoUtil.tensorDimsFromProto(_.dims)},tensorType:h.ProtoUtil.tensorDataTypeFromProto(_.dataType)},b=this._allData.push(y)-1,u.set(_.name,b)}this._allData[b]._from=-1,this._allData[b].tensor=l.Tensor.fromProto(_)}for(let _=0;_{this._allData[g]._to.forEach(_=>{a.add(_)})});const u=Array.from(a),m=new Array(this._nodes.length).fill("white");for(;u.length>0;){const g=u.pop();m[g]==="gray"?m[g]="black":(u.push(g),m[g]="gray",this._nodes[g].outputs.forEach(_=>{const b=this._allData[_];if(b.tensor!==void 0)throw new Error("node outputs should not be initialized");if(b._from!==g)throw new Error("from property of the Value object doesn't match index of Node being processed");b._to.forEach(y=>{if(m[y]==="gray")throw new Error("model graph is cyclic");m[y]==="white"&&u.push(y)})}))}}transformGraph(a){this.removeAllIdentityNodes(),this.removeAllDropoutNodes(),this.fuseConvActivationNodes(),a&&a.transformGraph(this),this.finalizeGraph()}finalizeGraph(){let a=0;for(let u=0;u0&&(this._nodes[u].inputs.forEach(m=>{const g=this._allData[m]._to.indexOf(u+a);g!==-1&&(this._allData[m]._to[g]=u)}),this._nodes[u].outputs.forEach(m=>{this._allData[m]._from&&this._allData[m]._from===u+a&&(this._allData[m]._from=u)})):(a++,this._nodes[u].outputs.forEach(m=>{this._allData[m]._from=-2}),this._nodes.splice(u,1),u--);a=0;for(let u=0;u0){let m=-1;this._allData[u].from!==void 0&&this._allData[u].from!==-1?(m=this._nodes[this._allData[u].from].outputs.indexOf(u+a),m!==-1&&(this._nodes[this._allData[u].from].outputs[m]=u)):(m=this._allInputIndices.indexOf(u+a),m!==-1&&(this._allInputIndices[m]=u)),this._allData[u].to.forEach(g=>{m=this._nodes[g].inputs.indexOf(u+a),m!==-1&&(this._nodes[g].inputs[m]=u)}),this._allData[u].to.length===0&&(m=this._allOutputIndices.indexOf(u+a),m!==-1&&(this._allOutputIndices[m]=u))}}else a++,this._allData.splice(u,1),u--}deleteNode(a){const u=this._nodes[a];if(u.outputs.length>1){for(let v=1;v0)throw new Error("Node deletion with more than one output connected to other nodes is not supported. ")}u.executeNode=!1;const m=u.inputs[0],g=u.outputs[0],_=this._allData[g].to,b=this._allData[m].to.indexOf(a);if(b===-1)throw new Error("The Value object doesn't have the current Node in it's 'to' property ");this._allData[m].to.splice(b,1),this._allData[g]._to=[];const y=this._allOutputIndices.indexOf(g);if(y!==-1&&(this._allOutputIndices[y]=m),_&&_.length>0)for(const v of _){const x=this._nodes[v].inputs.indexOf(g);if(x===-1)throw new Error("The Node object doesn't have the output Value in it's 'inputs' property ");this._nodes[v].inputs[x]=m,this._allData[m].to.push(v)}}removeAllDropoutNodes(){let a=0;for(const u of this._nodes){if(u.opType==="Dropout"){if(u.inputs.length!==1)throw new Error("Dropout nodes should only contain one input. ");if(u.outputs.length!==1&&u.outputs.length!==2)throw new Error("Dropout nodes should contain either 1 or 2 output(s)");if(u.outputs.length===2&&this._allData[u.outputs[1]]._to.length!==0)throw new Error("Dropout nodes's second output should not be referenced by other nodes");this.deleteNode(a)}a++}}removeAllIdentityNodes(){let a=0;for(const u of this._nodes)u.opType==="Identity"&&this.deleteNode(a),a++}isActivation(a){switch(a.opType){case"Relu":case"Sigmoid":case"Clip":return!0;default:return!1}}fuseConvActivationNodes(){for(const a of this._nodes)if(a.opType==="Conv"){const u=this._allData[a.outputs[0]]._to;if(u.length===1&&this.isActivation(this._nodes[u[0]])){const m=this._nodes[u[0]];if(m.opType==="Clip")if(m.inputs.length===1)try{a.attributes.set("activation_params","floats",[m.attributes.getFloat("min"),m.attributes.getFloat("max")])}catch{a.attributes.set("activation_params","floats",[h.MIN_CLIP,h.MAX_CLIP])}else{if(!(m.inputs.length>=3&&this._allData[m.inputs[1]].tensor!==void 0&&this._allData[m.inputs[2]].tensor!==void 0))continue;a.attributes.set("activation_params","floats",[this._allData[m.inputs[1]].tensor.floatData[0],this._allData[m.inputs[2]].tensor.floatData[0]])}a.attributes.set("activation","string",m.opType),this.deleteNode(u[0])}}}}},6231:(s,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.now=e.Profiler=e.Logger=void 0;const t={verbose:1e3,info:2e3,warning:4e3,error:5e3,fatal:6e3},r={none:new class{log(d,i,n){}},console:new class{log(d,i,n){console.log(`${this.color(d)} ${n?"\x1B[35m"+n+"\x1B[0m ":""}${i}`)}color(d){switch(d){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: ${d}`)}}}},o={provider:"console",minimalSeverity:"warning",logDateTime:!0,logSourceLocation:!1};let c={"":o};function l(d,i,n,a){if(i===void 0)return u=d,{verbose:l.verbose.bind(null,u),info:l.info.bind(null,u),warning:l.warning.bind(null,u),error:l.error.bind(null,u),fatal:l.fatal.bind(null,u)};if(n===void 0)h(d,i);else if(typeof n=="number"&&a===void 0)h(d,i);else if(typeof n=="string"&&a===void 0)h(d,n,0,i);else{if(typeof n!="string"||typeof a!="number")throw new TypeError("input is valid");h(d,n,0,i)}var u}function h(d,i,n,a){const u=c[a||""]||c[""];t[d]{g.then(async y=>{u&&await u.end(),_(y)},async y=>{u&&await u.end(),b(y)})});if(!m&&u){const _=u.end();if(_&&typeof _.then=="function")return new Promise((b,y)=>{_.then(()=>{b(g)},v=>{y(v)})})}return g}begin(d,i,n){if(!this._started)throw new Error("profiler is not started yet");if(n===void 0){const a=(0,e.now)();return this.flush(a),new p(d,i,a,u=>this.endSync(u))}{const a=n.beginTimer();return new p(d,i,0,async u=>this.end(u),a,n)}}async end(d){const i=await d.checkTimer();this._timingEvents.length=this._flushBatchSize||d-this._flushTime>=this._flushIntervalInMilliseconds){for(const i=this._flushPointer;this._flushPointerperformance.now():Date.now},2644:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Model=void 0;const r=t(5686),o=t(1446),c=t(7070),l=t(9395),h=t(2517);var p=l.onnxruntime.experimental.fbs;e.Model=class{constructor(){}load(f,d,i){if(!i)try{return void this.loadFromOnnxFormat(f,d)}catch(n){if(i!==void 0)throw n}this.loadFromOrtFormat(f,d)}loadFromOnnxFormat(f,d){const i=o.onnx.ModelProto.decode(f);if(h.LongUtil.longToNumber(i.irVersion)<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=i.opsetImport.map(n=>({domain:n.domain,version:h.LongUtil.longToNumber(n.version)})),this._graph=c.Graph.from(i.graph,d)}loadFromOrtFormat(f,d){const i=new r.flatbuffers.ByteBuffer(f),n=p.InferenceSession.getRootAsInferenceSession(i).model();if(h.LongUtil.longToNumber(n.irVersion())<3)throw new Error("only support ONNX model with IR_VERSION>=3");this._opsets=[];for(let a=0;a{Object.defineProperty(e,"__esModule",{value:!0}),e.FLOAT_TYPES=e.INT_TYPES=e.NUMBER_TYPES=void 0,e.NUMBER_TYPES=["float32","float64","int32","int16","int8","uint16","uint32","uint8"],e.INT_TYPES=["int32","int16","int8","uint16","uint32","uint8"],e.FLOAT_TYPES=["float32","float64"]},1047:(s,e)=>{function t(r,o){if(o.endsWith("+")){const c=Number.parseInt(o.substring(0,o.length-1),10);return!isNaN(c)&&c<=r}if(o.split("-").length===2){const c=o.split("-"),l=Number.parseInt(c[0],10),h=Number.parseInt(c[1],10);return!isNaN(l)&&!isNaN(h)&&l<=r&&r<=h}return Number.parseInt(o,10)===r}Object.defineProperty(e,"__esModule",{value:!0}),e.resolveOperator=void 0,e.resolveOperator=function(r,o,c){for(const l of c){const h=l[0],p=l[1],f=l[2],d=l[3],i=l[4];if(r.opType===h){for(const n of o)if((n.domain===p||n.domain==="ai.onnx"&&p==="")&&t(n.version,f))return{opImpl:d,opInit:i}}}throw new TypeError(`cannot resolve operator '${r.opType}' with opsets: ${o.map(l=>`${l.domain||"ai.onnx"} v${l.version}`).join(", ")}`)}},9395:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.onnxruntime=void 0;const r=t(5686);var o,c;o=e.onnxruntime||(e.onnxruntime={}),function(l){(function(h){h[h.UNDEFINED=0]="UNDEFINED",h[h.FLOAT=1]="FLOAT",h[h.INT=2]="INT",h[h.STRING=3]="STRING",h[h.TENSOR=4]="TENSOR",h[h.GRAPH=5]="GRAPH",h[h.FLOATS=6]="FLOATS",h[h.INTS=7]="INTS",h[h.STRINGS=8]="STRINGS",h[h.TENSORS=9]="TENSORS",h[h.GRAPHS=10]="GRAPHS",h[h.SPARSE_TENSOR=11]="SPARSE_TENSOR",h[h.SPARSE_TENSORS=12]="SPARSE_TENSORS"})(l.AttributeType||(l.AttributeType={}))}((c=o.experimental||(o.experimental={})).fbs||(c.fbs={})),function(l){(function(h){(function(p){(function(f){f[f.UNKNOWN=0]="UNKNOWN",f[f.VALUE=1]="VALUE",f[f.PARAM=2]="PARAM"})(p.DimensionValueType||(p.DimensionValueType={}))})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){(function(f){f[f.UNDEFINED=0]="UNDEFINED",f[f.FLOAT=1]="FLOAT",f[f.UINT8=2]="UINT8",f[f.INT8=3]="INT8",f[f.UINT16=4]="UINT16",f[f.INT16=5]="INT16",f[f.INT32=6]="INT32",f[f.INT64=7]="INT64",f[f.STRING=8]="STRING",f[f.BOOL=9]="BOOL",f[f.FLOAT16=10]="FLOAT16",f[f.DOUBLE=11]="DOUBLE",f[f.UINT32=12]="UINT32",f[f.UINT64=13]="UINT64",f[f.COMPLEX64=14]="COMPLEX64",f[f.COMPLEX128=15]="COMPLEX128",f[f.BFLOAT16=16]="BFLOAT16"})(p.TensorDataType||(p.TensorDataType={}))})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){(function(f){f[f.Primitive=0]="Primitive",f[f.Fused=1]="Fused"})(p.NodeType||(p.NodeType={}))})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){(function(f){f[f.NONE=0]="NONE",f[f.tensor_type=1]="tensor_type",f[f.sequence_type=2]="sequence_type",f[f.map_type=3]="map_type"})(p.TypeInfoValue||(p.TypeInfoValue={}))})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsShape(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsShape(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}dim(i,n){let a=this.bb.__offset(this.bb_pos,4);return a?(n||new l.experimental.fbs.Dimension).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}dimLength(){let i=this.bb.__offset(this.bb_pos,4);return i?this.bb.__vector_len(this.bb_pos+i):0}static startShape(i){i.startObject(1)}static addDim(i,n){i.addFieldOffset(0,n,0)}static createDimVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startDimVector(i,n){i.startVector(4,n,4)}static endShape(i){return i.endObject()}static createShape(i,n){return f.startShape(i),f.addDim(i,n),f.endShape(i)}}p.Shape=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsDimension(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsDimension(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}value(i){let n=this.bb.__offset(this.bb_pos,4);return n?(i||new l.experimental.fbs.DimensionValue).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}denotation(i){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,i):null}static startDimension(i){i.startObject(2)}static addValue(i,n){i.addFieldOffset(0,n,0)}static addDenotation(i,n){i.addFieldOffset(1,n,0)}static endDimension(i){return i.endObject()}static createDimension(i,n,a){return f.startDimension(i),f.addValue(i,n),f.addDenotation(i,a),f.endDimension(i)}}p.Dimension=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsDimensionValue(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsDimensionValue(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}dimType(){let i=this.bb.__offset(this.bb_pos,4);return i?this.bb.readInt8(this.bb_pos+i):l.experimental.fbs.DimensionValueType.UNKNOWN}dimValue(){let i=this.bb.__offset(this.bb_pos,6);return i?this.bb.readInt64(this.bb_pos+i):this.bb.createLong(0,0)}dimParam(i){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.__string(this.bb_pos+n,i):null}static startDimensionValue(i){i.startObject(3)}static addDimType(i,n){i.addFieldInt8(0,n,l.experimental.fbs.DimensionValueType.UNKNOWN)}static addDimValue(i,n){i.addFieldInt64(1,n,i.createLong(0,0))}static addDimParam(i,n){i.addFieldOffset(2,n,0)}static endDimensionValue(i){return i.endObject()}static createDimensionValue(i,n,a,u){return f.startDimensionValue(i),f.addDimType(i,n),f.addDimValue(i,a),f.addDimParam(i,u),f.endDimensionValue(i)}}p.DimensionValue=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsTensorTypeAndShape(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsTensorTypeAndShape(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}elemType(){let i=this.bb.__offset(this.bb_pos,4);return i?this.bb.readInt32(this.bb_pos+i):l.experimental.fbs.TensorDataType.UNDEFINED}shape(i){let n=this.bb.__offset(this.bb_pos,6);return n?(i||new l.experimental.fbs.Shape).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startTensorTypeAndShape(i){i.startObject(2)}static addElemType(i,n){i.addFieldInt32(0,n,l.experimental.fbs.TensorDataType.UNDEFINED)}static addShape(i,n){i.addFieldOffset(1,n,0)}static endTensorTypeAndShape(i){return i.endObject()}static createTensorTypeAndShape(i,n,a){return f.startTensorTypeAndShape(i),f.addElemType(i,n),f.addShape(i,a),f.endTensorTypeAndShape(i)}}p.TensorTypeAndShape=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsMapType(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsMapType(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}keyType(){let i=this.bb.__offset(this.bb_pos,4);return i?this.bb.readInt32(this.bb_pos+i):l.experimental.fbs.TensorDataType.UNDEFINED}valueType(i){let n=this.bb.__offset(this.bb_pos,6);return n?(i||new l.experimental.fbs.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startMapType(i){i.startObject(2)}static addKeyType(i,n){i.addFieldInt32(0,n,l.experimental.fbs.TensorDataType.UNDEFINED)}static addValueType(i,n){i.addFieldOffset(1,n,0)}static endMapType(i){return i.endObject()}static createMapType(i,n,a){return f.startMapType(i),f.addKeyType(i,n),f.addValueType(i,a),f.endMapType(i)}}p.MapType=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsSequenceType(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsSequenceType(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}elemType(i){let n=this.bb.__offset(this.bb_pos,4);return n?(i||new l.experimental.fbs.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startSequenceType(i){i.startObject(1)}static addElemType(i,n){i.addFieldOffset(0,n,0)}static endSequenceType(i){return i.endObject()}static createSequenceType(i,n){return f.startSequenceType(i),f.addElemType(i,n),f.endSequenceType(i)}}p.SequenceType=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(h.fbs||(h.fbs={})).EdgeEnd=class{constructor(){this.bb=null,this.bb_pos=0}__init(p,f){return this.bb_pos=p,this.bb=f,this}nodeIndex(){return this.bb.readUint32(this.bb_pos)}srcArgIndex(){return this.bb.readInt32(this.bb_pos+4)}dstArgIndex(){return this.bb.readInt32(this.bb_pos+8)}static createEdgeEnd(p,f,d,i){return p.prep(4,12),p.writeInt32(i),p.writeInt32(d),p.writeInt32(f),p.offset()}}})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsNodeEdge(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsNodeEdge(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}nodeIndex(){let i=this.bb.__offset(this.bb_pos,4);return i?this.bb.readUint32(this.bb_pos+i):0}inputEdges(i,n){let a=this.bb.__offset(this.bb_pos,6);return a?(n||new l.experimental.fbs.EdgeEnd).__init(this.bb.__vector(this.bb_pos+a)+12*i,this.bb):null}inputEdgesLength(){let i=this.bb.__offset(this.bb_pos,6);return i?this.bb.__vector_len(this.bb_pos+i):0}outputEdges(i,n){let a=this.bb.__offset(this.bb_pos,8);return a?(n||new l.experimental.fbs.EdgeEnd).__init(this.bb.__vector(this.bb_pos+a)+12*i,this.bb):null}outputEdgesLength(){let i=this.bb.__offset(this.bb_pos,8);return i?this.bb.__vector_len(this.bb_pos+i):0}static startNodeEdge(i){i.startObject(3)}static addNodeIndex(i,n){i.addFieldInt32(0,n,0)}static addInputEdges(i,n){i.addFieldOffset(1,n,0)}static startInputEdgesVector(i,n){i.startVector(12,n,4)}static addOutputEdges(i,n){i.addFieldOffset(2,n,0)}static startOutputEdgesVector(i,n){i.startVector(12,n,4)}static endNodeEdge(i){return i.endObject()}static createNodeEdge(i,n,a,u){return f.startNodeEdge(i),f.addNodeIndex(i,n),f.addInputEdges(i,a),f.addOutputEdges(i,u),f.endNodeEdge(i)}}p.NodeEdge=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsNode(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsNode(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}name(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,i):null}docString(i){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,i):null}domain(i){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.__string(this.bb_pos+n,i):null}sinceVersion(){let i=this.bb.__offset(this.bb_pos,10);return i?this.bb.readInt32(this.bb_pos+i):0}index(){let i=this.bb.__offset(this.bb_pos,12);return i?this.bb.readUint32(this.bb_pos+i):0}opType(i){let n=this.bb.__offset(this.bb_pos,14);return n?this.bb.__string(this.bb_pos+n,i):null}type(){let i=this.bb.__offset(this.bb_pos,16);return i?this.bb.readInt32(this.bb_pos+i):l.experimental.fbs.NodeType.Primitive}executionProviderType(i){let n=this.bb.__offset(this.bb_pos,18);return n?this.bb.__string(this.bb_pos+n,i):null}inputs(i,n){let a=this.bb.__offset(this.bb_pos,20);return a?this.bb.__string(this.bb.__vector(this.bb_pos+a)+4*i,n):null}inputsLength(){let i=this.bb.__offset(this.bb_pos,20);return i?this.bb.__vector_len(this.bb_pos+i):0}outputs(i,n){let a=this.bb.__offset(this.bb_pos,22);return a?this.bb.__string(this.bb.__vector(this.bb_pos+a)+4*i,n):null}outputsLength(){let i=this.bb.__offset(this.bb_pos,22);return i?this.bb.__vector_len(this.bb_pos+i):0}attributes(i,n){let a=this.bb.__offset(this.bb_pos,24);return a?(n||new l.experimental.fbs.Attribute).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}attributesLength(){let i=this.bb.__offset(this.bb_pos,24);return i?this.bb.__vector_len(this.bb_pos+i):0}inputArgCounts(i){let n=this.bb.__offset(this.bb_pos,26);return n?this.bb.readInt32(this.bb.__vector(this.bb_pos+n)+4*i):0}inputArgCountsLength(){let i=this.bb.__offset(this.bb_pos,26);return i?this.bb.__vector_len(this.bb_pos+i):0}inputArgCountsArray(){let i=this.bb.__offset(this.bb_pos,26);return i?new Int32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+i),this.bb.__vector_len(this.bb_pos+i)):null}implicitInputs(i,n){let a=this.bb.__offset(this.bb_pos,28);return a?this.bb.__string(this.bb.__vector(this.bb_pos+a)+4*i,n):null}implicitInputsLength(){let i=this.bb.__offset(this.bb_pos,28);return i?this.bb.__vector_len(this.bb_pos+i):0}static startNode(i){i.startObject(13)}static addName(i,n){i.addFieldOffset(0,n,0)}static addDocString(i,n){i.addFieldOffset(1,n,0)}static addDomain(i,n){i.addFieldOffset(2,n,0)}static addSinceVersion(i,n){i.addFieldInt32(3,n,0)}static addIndex(i,n){i.addFieldInt32(4,n,0)}static addOpType(i,n){i.addFieldOffset(5,n,0)}static addType(i,n){i.addFieldInt32(6,n,l.experimental.fbs.NodeType.Primitive)}static addExecutionProviderType(i,n){i.addFieldOffset(7,n,0)}static addInputs(i,n){i.addFieldOffset(8,n,0)}static createInputsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startInputsVector(i,n){i.startVector(4,n,4)}static addOutputs(i,n){i.addFieldOffset(9,n,0)}static createOutputsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startOutputsVector(i,n){i.startVector(4,n,4)}static addAttributes(i,n){i.addFieldOffset(10,n,0)}static createAttributesVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startAttributesVector(i,n){i.startVector(4,n,4)}static addInputArgCounts(i,n){i.addFieldOffset(11,n,0)}static createInputArgCountsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addInt32(n[a]);return i.endVector()}static startInputArgCountsVector(i,n){i.startVector(4,n,4)}static addImplicitInputs(i,n){i.addFieldOffset(12,n,0)}static createImplicitInputsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startImplicitInputsVector(i,n){i.startVector(4,n,4)}static endNode(i){return i.endObject()}static createNode(i,n,a,u,m,g,_,b,y,v,x,w,S,M){return f.startNode(i),f.addName(i,n),f.addDocString(i,a),f.addDomain(i,u),f.addSinceVersion(i,m),f.addIndex(i,g),f.addOpType(i,_),f.addType(i,b),f.addExecutionProviderType(i,y),f.addInputs(i,v),f.addOutputs(i,x),f.addAttributes(i,w),f.addInputArgCounts(i,S),f.addImplicitInputs(i,M),f.endNode(i)}}p.Node=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsValueInfo(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsValueInfo(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}name(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,i):null}docString(i){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,i):null}type(i){let n=this.bb.__offset(this.bb_pos,8);return n?(i||new l.experimental.fbs.TypeInfo).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startValueInfo(i){i.startObject(3)}static addName(i,n){i.addFieldOffset(0,n,0)}static addDocString(i,n){i.addFieldOffset(1,n,0)}static addType(i,n){i.addFieldOffset(2,n,0)}static endValueInfo(i){return i.endObject()}static createValueInfo(i,n,a,u){return f.startValueInfo(i),f.addName(i,n),f.addDocString(i,a),f.addType(i,u),f.endValueInfo(i)}}p.ValueInfo=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsTypeInfo(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsTypeInfo(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}denotation(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,i):null}valueType(){let i=this.bb.__offset(this.bb_pos,6);return i?this.bb.readUint8(this.bb_pos+i):l.experimental.fbs.TypeInfoValue.NONE}value(i){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.__union(i,this.bb_pos+n):null}static startTypeInfo(i){i.startObject(3)}static addDenotation(i,n){i.addFieldOffset(0,n,0)}static addValueType(i,n){i.addFieldInt8(1,n,l.experimental.fbs.TypeInfoValue.NONE)}static addValue(i,n){i.addFieldOffset(2,n,0)}static endTypeInfo(i){return i.endObject()}static createTypeInfo(i,n,a,u){return f.startTypeInfo(i),f.addDenotation(i,n),f.addValueType(i,a),f.addValue(i,u),f.endTypeInfo(i)}}p.TypeInfo=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsOperatorSetId(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsOperatorSetId(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}domain(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,i):null}version(){let i=this.bb.__offset(this.bb_pos,6);return i?this.bb.readInt64(this.bb_pos+i):this.bb.createLong(0,0)}static startOperatorSetId(i){i.startObject(2)}static addDomain(i,n){i.addFieldOffset(0,n,0)}static addVersion(i,n){i.addFieldInt64(1,n,i.createLong(0,0))}static endOperatorSetId(i){return i.endObject()}static createOperatorSetId(i,n,a){return f.startOperatorSetId(i),f.addDomain(i,n),f.addVersion(i,a),f.endOperatorSetId(i)}}p.OperatorSetId=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsTensor(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsTensor(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}name(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,i):null}docString(i){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,i):null}dims(i){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.readInt64(this.bb.__vector(this.bb_pos+n)+8*i):this.bb.createLong(0,0)}dimsLength(){let i=this.bb.__offset(this.bb_pos,8);return i?this.bb.__vector_len(this.bb_pos+i):0}dataType(){let i=this.bb.__offset(this.bb_pos,10);return i?this.bb.readInt32(this.bb_pos+i):l.experimental.fbs.TensorDataType.UNDEFINED}rawData(i){let n=this.bb.__offset(this.bb_pos,12);return n?this.bb.readUint8(this.bb.__vector(this.bb_pos+n)+i):0}rawDataLength(){let i=this.bb.__offset(this.bb_pos,12);return i?this.bb.__vector_len(this.bb_pos+i):0}rawDataArray(){let i=this.bb.__offset(this.bb_pos,12);return i?new Uint8Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+i),this.bb.__vector_len(this.bb_pos+i)):null}stringData(i,n){let a=this.bb.__offset(this.bb_pos,14);return a?this.bb.__string(this.bb.__vector(this.bb_pos+a)+4*i,n):null}stringDataLength(){let i=this.bb.__offset(this.bb_pos,14);return i?this.bb.__vector_len(this.bb_pos+i):0}static startTensor(i){i.startObject(6)}static addName(i,n){i.addFieldOffset(0,n,0)}static addDocString(i,n){i.addFieldOffset(1,n,0)}static addDims(i,n){i.addFieldOffset(2,n,0)}static createDimsVector(i,n){i.startVector(8,n.length,8);for(let a=n.length-1;a>=0;a--)i.addInt64(n[a]);return i.endVector()}static startDimsVector(i,n){i.startVector(8,n,8)}static addDataType(i,n){i.addFieldInt32(3,n,l.experimental.fbs.TensorDataType.UNDEFINED)}static addRawData(i,n){i.addFieldOffset(4,n,0)}static createRawDataVector(i,n){i.startVector(1,n.length,1);for(let a=n.length-1;a>=0;a--)i.addInt8(n[a]);return i.endVector()}static startRawDataVector(i,n){i.startVector(1,n,1)}static addStringData(i,n){i.addFieldOffset(5,n,0)}static createStringDataVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startStringDataVector(i,n){i.startVector(4,n,4)}static endTensor(i){return i.endObject()}static createTensor(i,n,a,u,m,g,_){return f.startTensor(i),f.addName(i,n),f.addDocString(i,a),f.addDims(i,u),f.addDataType(i,m),f.addRawData(i,g),f.addStringData(i,_),f.endTensor(i)}}p.Tensor=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsSparseTensor(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsSparseTensor(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}values(i){let n=this.bb.__offset(this.bb_pos,4);return n?(i||new l.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}indices(i){let n=this.bb.__offset(this.bb_pos,6);return n?(i||new l.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}dims(i){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.readInt64(this.bb.__vector(this.bb_pos+n)+8*i):this.bb.createLong(0,0)}dimsLength(){let i=this.bb.__offset(this.bb_pos,8);return i?this.bb.__vector_len(this.bb_pos+i):0}static startSparseTensor(i){i.startObject(3)}static addValues(i,n){i.addFieldOffset(0,n,0)}static addIndices(i,n){i.addFieldOffset(1,n,0)}static addDims(i,n){i.addFieldOffset(2,n,0)}static createDimsVector(i,n){i.startVector(8,n.length,8);for(let a=n.length-1;a>=0;a--)i.addInt64(n[a]);return i.endVector()}static startDimsVector(i,n){i.startVector(8,n,8)}static endSparseTensor(i){return i.endObject()}static createSparseTensor(i,n,a,u){return f.startSparseTensor(i),f.addValues(i,n),f.addIndices(i,a),f.addDims(i,u),f.endSparseTensor(i)}}p.SparseTensor=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsAttribute(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsAttribute(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}name(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,i):null}docString(i){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.__string(this.bb_pos+n,i):null}type(){let i=this.bb.__offset(this.bb_pos,8);return i?this.bb.readInt32(this.bb_pos+i):l.experimental.fbs.AttributeType.UNDEFINED}f(){let i=this.bb.__offset(this.bb_pos,10);return i?this.bb.readFloat32(this.bb_pos+i):0}i(){let i=this.bb.__offset(this.bb_pos,12);return i?this.bb.readInt64(this.bb_pos+i):this.bb.createLong(0,0)}s(i){let n=this.bb.__offset(this.bb_pos,14);return n?this.bb.__string(this.bb_pos+n,i):null}t(i){let n=this.bb.__offset(this.bb_pos,16);return n?(i||new l.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}g(i){let n=this.bb.__offset(this.bb_pos,18);return n?(i||new l.experimental.fbs.Graph).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}floats(i){let n=this.bb.__offset(this.bb_pos,20);return n?this.bb.readFloat32(this.bb.__vector(this.bb_pos+n)+4*i):0}floatsLength(){let i=this.bb.__offset(this.bb_pos,20);return i?this.bb.__vector_len(this.bb_pos+i):0}floatsArray(){let i=this.bb.__offset(this.bb_pos,20);return i?new Float32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+i),this.bb.__vector_len(this.bb_pos+i)):null}ints(i){let n=this.bb.__offset(this.bb_pos,22);return n?this.bb.readInt64(this.bb.__vector(this.bb_pos+n)+8*i):this.bb.createLong(0,0)}intsLength(){let i=this.bb.__offset(this.bb_pos,22);return i?this.bb.__vector_len(this.bb_pos+i):0}strings(i,n){let a=this.bb.__offset(this.bb_pos,24);return a?this.bb.__string(this.bb.__vector(this.bb_pos+a)+4*i,n):null}stringsLength(){let i=this.bb.__offset(this.bb_pos,24);return i?this.bb.__vector_len(this.bb_pos+i):0}tensors(i,n){let a=this.bb.__offset(this.bb_pos,26);return a?(n||new l.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}tensorsLength(){let i=this.bb.__offset(this.bb_pos,26);return i?this.bb.__vector_len(this.bb_pos+i):0}graphs(i,n){let a=this.bb.__offset(this.bb_pos,28);return a?(n||new l.experimental.fbs.Graph).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}graphsLength(){let i=this.bb.__offset(this.bb_pos,28);return i?this.bb.__vector_len(this.bb_pos+i):0}static startAttribute(i){i.startObject(13)}static addName(i,n){i.addFieldOffset(0,n,0)}static addDocString(i,n){i.addFieldOffset(1,n,0)}static addType(i,n){i.addFieldInt32(2,n,l.experimental.fbs.AttributeType.UNDEFINED)}static addF(i,n){i.addFieldFloat32(3,n,0)}static addI(i,n){i.addFieldInt64(4,n,i.createLong(0,0))}static addS(i,n){i.addFieldOffset(5,n,0)}static addT(i,n){i.addFieldOffset(6,n,0)}static addG(i,n){i.addFieldOffset(7,n,0)}static addFloats(i,n){i.addFieldOffset(8,n,0)}static createFloatsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addFloat32(n[a]);return i.endVector()}static startFloatsVector(i,n){i.startVector(4,n,4)}static addInts(i,n){i.addFieldOffset(9,n,0)}static createIntsVector(i,n){i.startVector(8,n.length,8);for(let a=n.length-1;a>=0;a--)i.addInt64(n[a]);return i.endVector()}static startIntsVector(i,n){i.startVector(8,n,8)}static addStrings(i,n){i.addFieldOffset(10,n,0)}static createStringsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startStringsVector(i,n){i.startVector(4,n,4)}static addTensors(i,n){i.addFieldOffset(11,n,0)}static createTensorsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startTensorsVector(i,n){i.startVector(4,n,4)}static addGraphs(i,n){i.addFieldOffset(12,n,0)}static createGraphsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startGraphsVector(i,n){i.startVector(4,n,4)}static endAttribute(i){return i.endObject()}static createAttribute(i,n,a,u,m,g,_,b,y,v,x,w,S,M){return f.startAttribute(i),f.addName(i,n),f.addDocString(i,a),f.addType(i,u),f.addF(i,m),f.addI(i,g),f.addS(i,_),f.addT(i,b),f.addG(i,y),f.addFloats(i,v),f.addInts(i,x),f.addStrings(i,w),f.addTensors(i,S),f.addGraphs(i,M),f.endAttribute(i)}}p.Attribute=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsGraph(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsGraph(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}initializers(i,n){let a=this.bb.__offset(this.bb_pos,4);return a?(n||new l.experimental.fbs.Tensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}initializersLength(){let i=this.bb.__offset(this.bb_pos,4);return i?this.bb.__vector_len(this.bb_pos+i):0}nodeArgs(i,n){let a=this.bb.__offset(this.bb_pos,6);return a?(n||new l.experimental.fbs.ValueInfo).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}nodeArgsLength(){let i=this.bb.__offset(this.bb_pos,6);return i?this.bb.__vector_len(this.bb_pos+i):0}nodes(i,n){let a=this.bb.__offset(this.bb_pos,8);return a?(n||new l.experimental.fbs.Node).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}nodesLength(){let i=this.bb.__offset(this.bb_pos,8);return i?this.bb.__vector_len(this.bb_pos+i):0}maxNodeIndex(){let i=this.bb.__offset(this.bb_pos,10);return i?this.bb.readUint32(this.bb_pos+i):0}nodeEdges(i,n){let a=this.bb.__offset(this.bb_pos,12);return a?(n||new l.experimental.fbs.NodeEdge).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}nodeEdgesLength(){let i=this.bb.__offset(this.bb_pos,12);return i?this.bb.__vector_len(this.bb_pos+i):0}inputs(i,n){let a=this.bb.__offset(this.bb_pos,14);return a?this.bb.__string(this.bb.__vector(this.bb_pos+a)+4*i,n):null}inputsLength(){let i=this.bb.__offset(this.bb_pos,14);return i?this.bb.__vector_len(this.bb_pos+i):0}outputs(i,n){let a=this.bb.__offset(this.bb_pos,16);return a?this.bb.__string(this.bb.__vector(this.bb_pos+a)+4*i,n):null}outputsLength(){let i=this.bb.__offset(this.bb_pos,16);return i?this.bb.__vector_len(this.bb_pos+i):0}sparseInitializers(i,n){let a=this.bb.__offset(this.bb_pos,18);return a?(n||new l.experimental.fbs.SparseTensor).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}sparseInitializersLength(){let i=this.bb.__offset(this.bb_pos,18);return i?this.bb.__vector_len(this.bb_pos+i):0}static startGraph(i){i.startObject(8)}static addInitializers(i,n){i.addFieldOffset(0,n,0)}static createInitializersVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startInitializersVector(i,n){i.startVector(4,n,4)}static addNodeArgs(i,n){i.addFieldOffset(1,n,0)}static createNodeArgsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startNodeArgsVector(i,n){i.startVector(4,n,4)}static addNodes(i,n){i.addFieldOffset(2,n,0)}static createNodesVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startNodesVector(i,n){i.startVector(4,n,4)}static addMaxNodeIndex(i,n){i.addFieldInt32(3,n,0)}static addNodeEdges(i,n){i.addFieldOffset(4,n,0)}static createNodeEdgesVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startNodeEdgesVector(i,n){i.startVector(4,n,4)}static addInputs(i,n){i.addFieldOffset(5,n,0)}static createInputsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startInputsVector(i,n){i.startVector(4,n,4)}static addOutputs(i,n){i.addFieldOffset(6,n,0)}static createOutputsVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startOutputsVector(i,n){i.startVector(4,n,4)}static addSparseInitializers(i,n){i.addFieldOffset(7,n,0)}static createSparseInitializersVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startSparseInitializersVector(i,n){i.startVector(4,n,4)}static endGraph(i){return i.endObject()}static createGraph(i,n,a,u,m,g,_,b,y){return f.startGraph(i),f.addInitializers(i,n),f.addNodeArgs(i,a),f.addNodes(i,u),f.addMaxNodeIndex(i,m),f.addNodeEdges(i,g),f.addInputs(i,_),f.addOutputs(i,b),f.addSparseInitializers(i,y),f.endGraph(i)}}p.Graph=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsModel(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsModel(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}irVersion(){let i=this.bb.__offset(this.bb_pos,4);return i?this.bb.readInt64(this.bb_pos+i):this.bb.createLong(0,0)}opsetImport(i,n){let a=this.bb.__offset(this.bb_pos,6);return a?(n||new l.experimental.fbs.OperatorSetId).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}opsetImportLength(){let i=this.bb.__offset(this.bb_pos,6);return i?this.bb.__vector_len(this.bb_pos+i):0}producerName(i){let n=this.bb.__offset(this.bb_pos,8);return n?this.bb.__string(this.bb_pos+n,i):null}producerVersion(i){let n=this.bb.__offset(this.bb_pos,10);return n?this.bb.__string(this.bb_pos+n,i):null}domain(i){let n=this.bb.__offset(this.bb_pos,12);return n?this.bb.__string(this.bb_pos+n,i):null}modelVersion(){let i=this.bb.__offset(this.bb_pos,14);return i?this.bb.readInt64(this.bb_pos+i):this.bb.createLong(0,0)}docString(i){let n=this.bb.__offset(this.bb_pos,16);return n?this.bb.__string(this.bb_pos+n,i):null}graph(i){let n=this.bb.__offset(this.bb_pos,18);return n?(i||new l.experimental.fbs.Graph).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}graphDocString(i){let n=this.bb.__offset(this.bb_pos,20);return n?this.bb.__string(this.bb_pos+n,i):null}static startModel(i){i.startObject(9)}static addIrVersion(i,n){i.addFieldInt64(0,n,i.createLong(0,0))}static addOpsetImport(i,n){i.addFieldOffset(1,n,0)}static createOpsetImportVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startOpsetImportVector(i,n){i.startVector(4,n,4)}static addProducerName(i,n){i.addFieldOffset(2,n,0)}static addProducerVersion(i,n){i.addFieldOffset(3,n,0)}static addDomain(i,n){i.addFieldOffset(4,n,0)}static addModelVersion(i,n){i.addFieldInt64(5,n,i.createLong(0,0))}static addDocString(i,n){i.addFieldOffset(6,n,0)}static addGraph(i,n){i.addFieldOffset(7,n,0)}static addGraphDocString(i,n){i.addFieldOffset(8,n,0)}static endModel(i){return i.endObject()}static createModel(i,n,a,u,m,g,_,b,y,v){return f.startModel(i),f.addIrVersion(i,n),f.addOpsetImport(i,a),f.addProducerName(i,u),f.addProducerVersion(i,m),f.addDomain(i,g),f.addModelVersion(i,_),f.addDocString(i,b),f.addGraph(i,y),f.addGraphDocString(i,v),f.endModel(i)}}p.Model=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsKernelCreateInfos(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsKernelCreateInfos(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}nodeIndices(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.readUint32(this.bb.__vector(this.bb_pos+n)+4*i):0}nodeIndicesLength(){let i=this.bb.__offset(this.bb_pos,4);return i?this.bb.__vector_len(this.bb_pos+i):0}nodeIndicesArray(){let i=this.bb.__offset(this.bb_pos,4);return i?new Uint32Array(this.bb.bytes().buffer,this.bb.bytes().byteOffset+this.bb.__vector(this.bb_pos+i),this.bb.__vector_len(this.bb_pos+i)):null}kernelDefHashes(i){let n=this.bb.__offset(this.bb_pos,6);return n?this.bb.readUint64(this.bb.__vector(this.bb_pos+n)+8*i):this.bb.createLong(0,0)}kernelDefHashesLength(){let i=this.bb.__offset(this.bb_pos,6);return i?this.bb.__vector_len(this.bb_pos+i):0}static startKernelCreateInfos(i){i.startObject(2)}static addNodeIndices(i,n){i.addFieldOffset(0,n,0)}static createNodeIndicesVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addInt32(n[a]);return i.endVector()}static startNodeIndicesVector(i,n){i.startVector(4,n,4)}static addKernelDefHashes(i,n){i.addFieldOffset(1,n,0)}static createKernelDefHashesVector(i,n){i.startVector(8,n.length,8);for(let a=n.length-1;a>=0;a--)i.addInt64(n[a]);return i.endVector()}static startKernelDefHashesVector(i,n){i.startVector(8,n,8)}static endKernelCreateInfos(i){return i.endObject()}static createKernelCreateInfos(i,n,a){return f.startKernelCreateInfos(i),f.addNodeIndices(i,n),f.addKernelDefHashes(i,a),f.endKernelCreateInfos(i)}}p.KernelCreateInfos=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsSubGraphSessionState(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsSubGraphSessionState(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}graphId(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,i):null}sessionState(i){let n=this.bb.__offset(this.bb_pos,6);return n?(i||new l.experimental.fbs.SessionState).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startSubGraphSessionState(i){i.startObject(2)}static addGraphId(i,n){i.addFieldOffset(0,n,0)}static addSessionState(i,n){i.addFieldOffset(1,n,0)}static endSubGraphSessionState(i){let n=i.endObject();return i.requiredField(n,4),n}static createSubGraphSessionState(i,n,a){return f.startSubGraphSessionState(i),f.addGraphId(i,n),f.addSessionState(i,a),f.endSubGraphSessionState(i)}}p.SubGraphSessionState=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsSessionState(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsSessionState(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}kernels(i){let n=this.bb.__offset(this.bb_pos,4);return n?(i||new l.experimental.fbs.KernelCreateInfos).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}subGraphSessionStates(i,n){let a=this.bb.__offset(this.bb_pos,6);return a?(n||new l.experimental.fbs.SubGraphSessionState).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos+a)+4*i),this.bb):null}subGraphSessionStatesLength(){let i=this.bb.__offset(this.bb_pos,6);return i?this.bb.__vector_len(this.bb_pos+i):0}static startSessionState(i){i.startObject(2)}static addKernels(i,n){i.addFieldOffset(0,n,0)}static addSubGraphSessionStates(i,n){i.addFieldOffset(1,n,0)}static createSubGraphSessionStatesVector(i,n){i.startVector(4,n.length,4);for(let a=n.length-1;a>=0;a--)i.addOffset(n[a]);return i.endVector()}static startSubGraphSessionStatesVector(i,n){i.startVector(4,n,4)}static endSessionState(i){return i.endObject()}static createSessionState(i,n,a){return f.startSessionState(i),f.addKernels(i,n),f.addSubGraphSessionStates(i,a),f.endSessionState(i)}}p.SessionState=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={})),function(l){(function(h){(function(p){class f{constructor(){this.bb=null,this.bb_pos=0}__init(i,n){return this.bb_pos=i,this.bb=n,this}static getRootAsInferenceSession(i,n){return(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static getSizePrefixedRootAsInferenceSession(i,n){return i.setPosition(i.position()+r.flatbuffers.SIZE_PREFIX_LENGTH),(n||new f).__init(i.readInt32(i.position())+i.position(),i)}static bufferHasIdentifier(i){return i.__has_identifier("ORTM")}ortVersion(i){let n=this.bb.__offset(this.bb_pos,4);return n?this.bb.__string(this.bb_pos+n,i):null}model(i){let n=this.bb.__offset(this.bb_pos,6);return n?(i||new l.experimental.fbs.Model).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}sessionState(i){let n=this.bb.__offset(this.bb_pos,8);return n?(i||new l.experimental.fbs.SessionState).__init(this.bb.__indirect(this.bb_pos+n),this.bb):null}static startInferenceSession(i){i.startObject(3)}static addOrtVersion(i,n){i.addFieldOffset(0,n,0)}static addModel(i,n){i.addFieldOffset(1,n,0)}static addSessionState(i,n){i.addFieldOffset(2,n,0)}static endInferenceSession(i){return i.endObject()}static finishInferenceSessionBuffer(i,n){i.finish(n,"ORTM")}static finishSizePrefixedInferenceSessionBuffer(i,n){i.finish(n,"ORTM",!0)}static createInferenceSession(i,n,a,u){return f.startInferenceSession(i),f.addOrtVersion(i,n),f.addModel(i,a),f.addSessionState(i,u),f.endInferenceSession(i)}}p.InferenceSession=f})(h.fbs||(h.fbs={}))})(l.experimental||(l.experimental={}))}(e.onnxruntime||(e.onnxruntime={}))},7448:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.OnnxjsSessionHandler=void 0;const r=t(1670),o=t(9162);e.OnnxjsSessionHandler=class{constructor(c){this.session=c,this.inputNames=this.session.inputNames,this.outputNames=this.session.outputNames}async dispose(){}async run(c,l,h){const p=new Map;for(const i in c)if(Object.hasOwnProperty.call(c,i)){const n=c[i];p.set(i,new o.Tensor(n.dims,n.type,void 0,void 0,n.data))}const f=await this.session.run(p),d={};return f.forEach((i,n)=>{d[n]=new r.Tensor(i.type,i.data,i.dims)}),d}startProfiling(){this.session.startProfiling()}endProfiling(){this.session.endProfiling()}}},6919:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Session=void 0;const r=t(7067),o=t(1296),c=t(7091),l=t(1036),h=t(6231),p=t(2644);e.Session=class{constructor(f={}){this._initialized=!1,this.backendHint=f.backendHint,this.profiler=h.Profiler.create(f.profiler),this.context={profiler:this.profiler,graphInputTypes:[],graphInputDims:[]}}get inputNames(){return this._model.graph.getInputNames()}get outputNames(){return this._model.graph.getOutputNames()}startProfiling(){this.profiler.start()}endProfiling(){this.profiler.stop()}async loadModel(f,d,i){await this.profiler.event("session","Session.loadModel",async()=>{const n=await(0,c.resolveBackend)(this.backendHint);if(this.sessionHandler=n.createSessionHandler(this.context),this._model=new p.Model,typeof f=="string"){const a=f.endsWith(".ort");if(typeof fetch>"u"){const u=await(0,o.promisify)(r.readFile)(f);this.initialize(u,a)}else{const u=await fetch(f),m=await u.arrayBuffer();this.initialize(new Uint8Array(m),a)}}else if(ArrayBuffer.isView(f))this.initialize(f);else{const a=new Uint8Array(f,d||0,i||f.byteLength);this.initialize(a)}})}initialize(f,d){if(this._initialized)throw new Error("already initialized");this.profiler.event("session","Session.initialize",()=>{const i=this.sessionHandler.transformGraph?this.sessionHandler:void 0;this._model.load(f,i,d),this.sessionHandler.onGraphInitialized&&this.sessionHandler.onGraphInitialized(this._model.graph),this.initializeOps(this._model.graph),this._executionPlan=new l.ExecutionPlan(this._model.graph,this._ops,this.profiler)}),this._initialized=!0}async run(f){if(!this._initialized)throw new Error("session not initialized yet");return this.profiler.event("session","Session.run",async()=>{const d=this.normalizeAndValidateInputs(f),i=await this._executionPlan.execute(this.sessionHandler,d);return this.createOutput(i)})}normalizeAndValidateInputs(f){const d=this._model.graph.getInputNames();if(Array.isArray(f)){if(f.length!==d.length)throw new Error(`incorrect input array length: expected ${d.length} but got ${f.length}`)}else{if(f.size!==d.length)throw new Error(`incorrect input map size: expected ${d.length} but got ${f.size}`);const i=new Array(f.size);let n=0;for(let a=0;atypeof M=="string")))throw new TypeError("cache should be a string array");S&&(this.cache=new Array(w))}else{if(v!==void 0){const M=n(_);if(!(v instanceof M))throw new TypeError(`cache should be type ${M.name}`)}if(S){const M=new ArrayBuffer(w*function(T){switch(T){case"bool":case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;case"float64":return 8;default:throw new Error(`cannot calculate sizeof() on type ${T}`)}}(_));this.cache=function(T,E){return new(n(E))(T)}(M,_)}}}static fromProto(g){if(!g)throw new Error("cannot construct Value from an empty tensor");const _=p.ProtoUtil.tensorDataTypeFromProto(g.dataType),b=p.ProtoUtil.tensorDimsFromProto(g.dims),y=new d(b,_);if(_==="string")g.stringData.forEach((v,x)=>{y.data[x]=(0,p.decodeUtf8String)(v)});else if(g.rawData&&typeof g.rawData.byteLength=="number"&&g.rawData.byteLength>0){const v=y.data,x=new DataView(g.rawData.buffer,g.rawData.byteOffset,g.rawData.byteLength),w=i(g.dataType),S=g.rawData.byteLength/w;if(g.rawData.byteLength%w!=0)throw new Error("invalid buffer length");if(v.length!==S)throw new Error("buffer length mismatch");for(let M=0;M0){const v=y.data,x=new DataView(g.rawDataArray().buffer,g.rawDataArray().byteOffset,g.rawDataLength()),w=i(g.dataType()),S=g.rawDataLength()/w;if(g.rawDataLength()%w!=0)throw new Error("invalid buffer length");if(v.length!==S)throw new Error("buffer length mismatch");for(let M=0;M1&&E>1)return;S[w-M]=Math.max(T,E)}return S}static index(_,b){const y=new Array(b.length);return f.fillIndex(_,b,y),y}static fillIndex(_,b,y){const v=_.length-b.length;for(let x=0;x=0;K--)T[K]=I%w[K],I=Math.floor(I/w[K]);z||(f.fillIndex(T,_.dims,E),k=_.get(E)),O||(f.fillIndex(T,b.dims,R),C=b.get(R)),M.set(T,y(k,C))}}return M}}static isValidBroadcast(_,b){const y=_.length,v=b.length;if(y>v)return!1;for(let x=1;x<=y;x++)if(_[y-x]!==1&&_[y-x]!==b[v-x])return!1;return!0}static getBroadcastDims(_,b){const y=_.length,v=[];for(let x=0;x1&&S===1&&v.unshift(w)}return v}}e.BroadcastUtil=f,e.arrayCopyHelper=function(g,_,b,y,v){if(y<0||y>=_.length)throw new Error("sourceIndex out of bounds");if(b<0||b>=g.length)throw new Error("targetIndex out of bounds");if(y+v>_.length)throw new Error("source indices to be copied are outside bounds");if(b+v>g.length)throw new Error("target array is too small to hold result");for(let x=0;xc.default.isLong(b)?b.toNumber():b)}static tensorValueTypeFromProto(_){return{tensorType:d.tensorDataTypeFromProto(_.elemType),shape:{dims:d.tensorDimsFromProto(_.shape.dim.map(b=>b.dimValue))}}}static tensorDimsFromORTFormat(_){const b=[];for(let y=0;y<_.dimsLength();y++)b.push(i.longToNumber(_.dims(y)));return b}static tensorAttributesFromORTFormat(_){const b=[];for(let y=0;y<_.attributesLength();y++)b.push(_.attributes(y));return b}}e.ProtoUtil=d;class i{static longToNumber(_,b){return c.default.isLong(_)?_.toNumber():_ instanceof o.flatbuffers.Long?c.default.fromValue({low:_.low,high:_.high,unsigned:b!=null&&b}).toNumber():_}static isLong(_){return c.default.isLong(_)||_ instanceof o.flatbuffers.Long}}e.LongUtil=i;class n{static size(_){return n.getSizeFromDimensionRange(_,0,_.length)}static sizeFromDimension(_,b){if(b<0||b>_.length)throw new Error(`invalid dimension of ${b} for sizeFromDimension as Tensor has ${_.length} dimensions.`);return n.getSizeFromDimensionRange(_,b,_.length)}static sizeToDimension(_,b){if(b<0||b>_.length)throw new Error(`invalid dimension of ${b} for sizeToDimension as Tensor has ${_.length} dimensions.`);return n.getSizeFromDimensionRange(_,0,b)}static getSizeFromDimensionRange(_,b,y){let v=1;for(let x=b;x=0;--v)y[v]=y[v+1]*_[v+1];return y}static transpose(_){return _.slice().reverse()}static indicesToOffset(_,b,y){y===void 0&&(y=_.length);let v=0;for(let x=0;x=b)throw new Error("unsupported axis for this operation.");return _<0?_+b:_}static normalizeAxes(_,b){return _.map(y=>this.normalizeAxis(y,b))}static incrementIndex(_,b,y){if(b.length===0||_.length===0)throw new Error("Index incrementing unsupported for scalar Tensor");if(y===void 0)y=b.length;else if(y<=0||y>b.length)throw new Error("Incorrect axis to increment on");for(let v=y-1;v>=0&&(_[v]++,!(_[v]=_.length)throw new Error("the dimension with value zero exceeds the dimension size of the input tensor");v[M]=_[M]}else v[M]=b[M];w*=v[M]}}const S=n.size(_);if(x!==-1){if(S%w!=0)throw new Error(`the input tensor cannot be reshaped to the requested shape. Input shape: [${_}] Output shape: [${b}]`);v[x]=S/w}else if(w!==S)throw new Error("reshapedDims and originalDims don't have matching sizes");return v}static sortBasedOnPerm(_,b){return b?b.map(y=>_[y]):_.slice().reverse()}static padShape(_,b){const y=_.length;return _.map((v,x)=>v+b[x]+b[x+y])}static areEqual(_,b){return _.length===b.length&&_.every((y,v)=>y===b[v])}static validateDimsAndCalcSize(_){if(_.length>6)throw new TypeError("Only rank 0 to 6 is supported for tensor shape.");let b=1;for(const y of _){if(!Number.isInteger(y))throw new TypeError(`Invalid shape: ${y} is not an integer`);if(y<0||y>2147483647)throw new TypeError(`Invalid shape: length ${y} is not allowed`);b*=y}return b}static flattenShape(_,b){b<0&&(b+=_.length);const y=_.reduce((x,w)=>x*w,1),v=_.slice(b).reduce((x,w)=>x*w,1);return[y/v,v]}static squeezeShape(_,b){const y=new Array;b=n.normalizeAxes(b,_.length);for(let v=0;v<_.length;v++){const x=b.indexOf(v)>=0;if(x&&_[v]!==1)throw new Error("squeeze an axis of size different than 1");(b.length===0&&_[v]>1||b.length>0&&!x)&&y.push(_[v])}return y}static unsqueezeShape(_,b){const y=new Array(_.length+b.length);y.fill(0);for(let x=0;x=y.length)throw new Error("'axes' has an out of range axis");if(y[w]!==0)throw new Error("'axes' has a duplicate axis");y[w]=1}let v=0;for(let x=0;x=_.length)throw new Error("sourceIndex out of bounds");if(b<0||b>=g.length)throw new Error("targetIndex out of bounds");if(y+v>_.length)throw new Error("source indices to be copied are outside bounds");if(b+v>g.length)throw new Error("target array is too small to hold result");for(let x=0;x=_.length)throw new Error("sourceIndex out of bounds");if(b<0||b>=g.length)throw new Error("targetIndex out of bounds");if(y+v>_.length)throw new Error("source indices to be copied are outside bounds");if(b+v>g.length)throw new Error("target array is too small to hold result");for(let w=0;w=_.length)throw new Error("sourceIndex out of bounds");if(b<0||b>=g.length)throw new Error("targetIndex out of bounds");if(y+v>_.length)throw new Error("source indices to be copied are outside bounds");if(b+v>g.length)throw new Error("target array is too small to hold result");for(let w=0;w=_.length)throw new Error("sourceIndex out of bounds");if(b<0||b>=g.length)throw new Error("targetIndex out of bounds");if(y+v>_.length)throw new Error("source indices to be copied are outside bounds");if(b+v>g.length)throw new Error("target array is too small to hold result");for(let x=0;xb.push(C));const S=u.calcReduceShape(w,b,!0),M=n.size(S),T=new h.Tensor(S,_.type),E=n.computeStrides(S),R=n.computeStrides(w),I=new Array(w.length);for(let k=0;k=b.length)return w(_[x]);const T=b[v],E=T>=y.length?1:n.size(y.slice(T+1));for(let R=0;Rx!==0)}}e.ReduceUtil=u;class m{static adjustPoolAttributes(_,b,y,v,x,w){if(!_&&y.length!==b.length-2)throw new Error("length of specified kernel shapes should be 2 less than length of input dimensions");if(_)for(let S=0;S=y.length?y.push(b[S+2]):y[S]=b[S+2];for(let S=0;S=y[S]||w[S+y.length]>=y[S])throw new Error("pads should be smaller than kernel")}}static adjustPadsBasedOnAutoPad(_,b,y,v,x,w){if(w){if(x.length!==2*(_.length-2))throw new Error("length of pads should be twice the length of data dimensions");if(b.length!==_.length-2)throw new Error("length of strides should be the length of data dimensions");if(v.length!==_.length-2)throw new Error("length of kernel shapes should be the length of data dimensions");for(let S=0;S<_.length-2;S++)m.adjustPadAndReturnShape(_[S+2],b[S],y[S],v[S],x,S,S+_.length-2,w)}}static computePoolOutputShape(_,b,y,v,x,w,S){if(b.length<=0)throw new Error("input shape must be of size greater than 0");const M=[b[0],b[1]];return m.computeShapeHelper(_,b,M,y,v,x,w,S),M}static computeConvOutputShape(_,b,y,v,x,w,S){if(_.length<=0||b.length<=0)throw new Error("invalid input tensor dims or invalid filter tensor dims");const M=[_[0],b[0]];return m.computeShapeHelper(!1,_,M,y,v,x,w,S),M}static computeShapeHelper(_,b,y,v,x,w,S,M){if(_)for(let T=0;T{Object.defineProperty(e,"__esModule",{value:!0}),e.iterateExtraOptions=void 0,e.iterateExtraOptions=(t,r,o,c)=>{if(typeof t=="object"&&t!==null){if(o.has(t))throw new Error("Circular reference in options");o.add(t)}Object.entries(t).forEach(([l,h])=>{const p=r?r+l:l;if(typeof h=="object")(0,e.iterateExtraOptions)(h,p+".",o,c);else if(typeof h=="string"||typeof h=="number")c(p,h.toString());else{if(typeof h!="boolean")throw new Error("Can't handle extra config type: "+typeof h);c(p,h?"1":"0")}})}},2157:function(s,e,t){var r,o=this&&this.__createBinding||(Object.create?function(E,R,I,k){k===void 0&&(k=I);var C=Object.getOwnPropertyDescriptor(R,I);C&&!("get"in C?!R.__esModule:C.writable||C.configurable)||(C={enumerable:!0,get:function(){return R[I]}}),Object.defineProperty(E,k,C)}:function(E,R,I,k){k===void 0&&(k=I),E[k]=R[I]}),c=this&&this.__setModuleDefault||(Object.create?function(E,R){Object.defineProperty(E,"default",{enumerable:!0,value:R})}:function(E,R){E.default=R}),l=this&&this.__importStar||function(E){if(E&&E.__esModule)return E;var R={};if(E!=null)for(var I in E)I!=="default"&&Object.prototype.hasOwnProperty.call(E,I)&&o(R,E,I);return c(R,E),R};Object.defineProperty(e,"__esModule",{value:!0}),e.endProfiling=e.run=e.releaseSession=e.createSession=e.createSessionFinalize=e.createSessionAllocate=e.initOrt=e.initWasm=void 0;const h=t(1670),p=l(t(349)),f=t(6361),d=()=>!!h.env.wasm.proxy&&typeof document<"u";let i,n,a,u=!1,m=!1,g=!1;const _=[],b=[],y=[],v=[],x=[],w=[],S=()=>{if(u||!m||g||!i)throw new Error("worker not ready")},M=E=>{switch(E.data.type){case"init-wasm":u=!1,E.data.err?(g=!0,n[1](E.data.err)):(m=!0,n[0]());break;case"init-ort":E.data.err?a[1](E.data.err):a[0]();break;case"create_allocate":E.data.err?_.shift()[1](E.data.err):_.shift()[0](E.data.out);break;case"create_finalize":E.data.err?b.shift()[1](E.data.err):b.shift()[0](E.data.out);break;case"create":E.data.err?y.shift()[1](E.data.err):y.shift()[0](E.data.out);break;case"release":E.data.err?v.shift()[1](E.data.err):v.shift()[0]();break;case"run":E.data.err?x.shift()[1](E.data.err):x.shift()[0](E.data.out);break;case"end-profiling":E.data.err?w.shift()[1](E.data.err):w.shift()[0]()}},T=typeof document<"u"?(r=document?.currentScript)===null||r===void 0?void 0:r.src:void 0;e.initWasm=async()=>{if(d()){if(m)return;if(u)throw new Error("multiple calls to 'initWasm()' detected.");if(g)throw new Error("previous call to 'initWasm()' failed.");return u=!0,h.env.wasm.wasmPaths===void 0&&T&&T.indexOf("blob:")!==0&&(h.env.wasm.wasmPaths=T.substr(0,+T.lastIndexOf("/")+1)),new Promise((E,R)=>{i?.terminate(),i=t(9710).Z(),i.onmessage=M,n=[E,R];const I={type:"init-wasm",in:h.env.wasm};i.postMessage(I)})}return(0,f.initializeWebAssembly)(h.env.wasm)},e.initOrt=async(E,R)=>{if(d())return S(),new Promise((I,k)=>{a=[I,k];const C={type:"init-ort",in:{numThreads:E,loggingLevel:R}};i.postMessage(C)});p.initOrt(E,R)},e.createSessionAllocate=async E=>d()?(S(),new Promise((R,I)=>{_.push([R,I]);const k={type:"create_allocate",in:{model:E}};i.postMessage(k,[E.buffer])})):p.createSessionAllocate(E),e.createSessionFinalize=async(E,R)=>d()?(S(),new Promise((I,k)=>{b.push([I,k]);const C={type:"create_finalize",in:{modeldata:E,options:R}};i.postMessage(C)})):p.createSessionFinalize(E,R),e.createSession=async(E,R)=>d()?(S(),new Promise((I,k)=>{y.push([I,k]);const C={type:"create",in:{model:E,options:R}};i.postMessage(C,[E.buffer])})):p.createSession(E,R),e.releaseSession=async E=>{if(d())return S(),new Promise((R,I)=>{v.push([R,I]);const k={type:"release",in:E};i.postMessage(k)});p.releaseSession(E)},e.run=async(E,R,I,k,C)=>d()?(S(),new Promise((z,O)=>{x.push([z,O]);const U={type:"run",in:{sessionId:E,inputIndices:R,inputs:I,outputIndices:k,options:C}};i.postMessage(U,p.extractTransferableBuffers(I))})):p.run(E,R,I,k,C),e.endProfiling=async E=>{if(d())return S(),new Promise((R,I)=>{w.push([R,I]);const k={type:"end-profiling",in:E};i.postMessage(k)});p.endProfiling(E)}},586:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.setRunOptions=void 0;const r=t(7967),o=t(4983),c=t(6361);e.setRunOptions=l=>{const h=(0,c.getInstance)();let p=0;const f=[],d=l||{};try{if(l?.logSeverityLevel===void 0)d.logSeverityLevel=2;else if(typeof l.logSeverityLevel!="number"||!Number.isInteger(l.logSeverityLevel)||l.logSeverityLevel<0||l.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${l.logSeverityLevel}`);if(l?.logVerbosityLevel===void 0)d.logVerbosityLevel=0;else if(typeof l.logVerbosityLevel!="number"||!Number.isInteger(l.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${l.logVerbosityLevel}`);l?.terminate===void 0&&(d.terminate=!1);let i=0;if(l?.tag!==void 0&&(i=(0,o.allocWasmString)(l.tag,f)),p=h._OrtCreateRunOptions(d.logSeverityLevel,d.logVerbosityLevel,!!d.terminate,i),p===0)throw new Error("Can't create run options");return l?.extra!==void 0&&(0,r.iterateExtraOptions)(l.extra,"",new WeakSet,(n,a)=>{const u=(0,o.allocWasmString)(n,f),m=(0,o.allocWasmString)(a,f);if(h._OrtAddRunConfigEntry(p,u,m)!==0)throw new Error(`Can't set a run config entry: ${n} - ${a}`)}),[p,f]}catch(i){throw p!==0&&h._OrtReleaseRunOptions(p),f.forEach(h._free),i}}},2306:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.OnnxruntimeWebAssemblySessionHandler=void 0;const r=t(2806),o=t(1670),c=t(2850),l=t(2157);let h;e.OnnxruntimeWebAssemblySessionHandler=class{async createSessionAllocate(p){const f=await fetch(p),d=await f.arrayBuffer();return(0,l.createSessionAllocate)(new Uint8Array(d))}async loadModel(p,f){if(h||(await(0,l.initOrt)(o.env.wasm.numThreads,(d=>{switch(d){case"verbose":return 0;case"info":return 1;case"warning":return 2;case"error":return 3;case"fatal":return 4;default:throw new Error(`unsupported logging level: ${d}`)}})(o.env.logLevel)),h=!0),typeof p=="string")if(typeof fetch>"u"){const d=await(0,c.promisify)(r.readFile)(p);[this.sessionId,this.inputNames,this.outputNames]=await(0,l.createSession)(d,f)}else{const d=await this.createSessionAllocate(p);[this.sessionId,this.inputNames,this.outputNames]=await(0,l.createSessionFinalize)(d,f)}else[this.sessionId,this.inputNames,this.outputNames]=await(0,l.createSession)(p,f)}async dispose(){return(0,l.releaseSession)(this.sessionId)}async run(p,f,d){const i=[],n=[];Object.entries(p).forEach(g=>{const _=g[0],b=g[1],y=this.inputNames.indexOf(_);if(y===-1)throw new Error(`invalid input '${_}'`);i.push(b),n.push(y)});const a=[];Object.entries(f).forEach(g=>{const _=g[0],b=this.outputNames.indexOf(_);if(b===-1)throw new Error(`invalid output '${_}'`);a.push(b)});const u=await(0,l.run)(this.sessionId,n,i.map(g=>[g.type,g.dims,g.data]),a,d),m={};for(let g=0;g{Object.defineProperty(e,"__esModule",{value:!0}),e.setSessionOptions=void 0;const r=t(7967),o=t(4983),c=t(6361);e.setSessionOptions=l=>{const h=(0,c.getInstance)();let p=0;const f=[],d=l||{};(i=>{i.extra||(i.extra={}),i.extra.session||(i.extra.session={});const n=i.extra.session;n.use_ort_model_bytes_directly||(n.use_ort_model_bytes_directly="1")})(d);try{l?.graphOptimizationLevel===void 0&&(d.graphOptimizationLevel="all");const i=(u=>{switch(u){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${u}`)}})(d.graphOptimizationLevel);l?.enableCpuMemArena===void 0&&(d.enableCpuMemArena=!0),l?.enableMemPattern===void 0&&(d.enableMemPattern=!0),l?.executionMode===void 0&&(d.executionMode="sequential");const n=(u=>{switch(u){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${u}`)}})(d.executionMode);let a=0;if(l?.logId!==void 0&&(a=(0,o.allocWasmString)(l.logId,f)),l?.logSeverityLevel===void 0)d.logSeverityLevel=2;else if(typeof l.logSeverityLevel!="number"||!Number.isInteger(l.logSeverityLevel)||l.logSeverityLevel<0||l.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${l.logSeverityLevel}`);if(l?.logVerbosityLevel===void 0)d.logVerbosityLevel=0;else if(typeof l.logVerbosityLevel!="number"||!Number.isInteger(l.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${l.logVerbosityLevel}`);if(l?.enableProfiling===void 0&&(d.enableProfiling=!1),p=h._OrtCreateSessionOptions(i,!!d.enableCpuMemArena,!!d.enableMemPattern,n,!!d.enableProfiling,0,a,d.logSeverityLevel,d.logVerbosityLevel),p===0)throw new Error("Can't create session options");return l?.executionProviders&&((u,m,g)=>{for(const _ of m){let b=typeof _=="string"?_:_.name;switch(b){case"xnnpack":b="XNNPACK";break;case"wasm":case"cpu":continue;default:throw new Error(`not supported EP: ${b}`)}const y=(0,o.allocWasmString)(b,g);if((0,c.getInstance)()._OrtAppendExecutionProvider(u,y)!==0)throw new Error(`Can't append execution provider: ${b}`)}})(p,l.executionProviders,f),l?.extra!==void 0&&(0,r.iterateExtraOptions)(l.extra,"",new WeakSet,(u,m)=>{const g=(0,o.allocWasmString)(u,f),_=(0,o.allocWasmString)(m,f);if(h._OrtAddSessionConfigEntry(p,g,_)!==0)throw new Error(`Can't set a session config entry: ${u} - ${m}`)}),[p,f]}catch(i){throw p!==0&&h._OrtReleaseSessionOptions(p),f.forEach(h._free),i}}},4983:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.allocWasmString=void 0;const r=t(6361);e.allocWasmString=(o,c)=>{const l=(0,r.getInstance)(),h=l.lengthBytesUTF8(o)+1,p=l._malloc(h);return l.stringToUTF8(o,p,h),c.push(p),p}},349:(s,e,t)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.extractTransferableBuffers=e.endProfiling=e.run=e.releaseSession=e.createSession=e.createSessionFinalize=e.createSessionAllocate=e.initOrt=void 0;const r=t(586),o=t(4919),c=t(4983),l=t(6361);e.initOrt=(i,n)=>{const a=(0,l.getInstance)()._OrtInit(i,n);if(a!==0)throw new Error(`Can't initialize onnxruntime. error code = ${a}`)};const h=new Map;e.createSessionAllocate=i=>{const n=(0,l.getInstance)(),a=n._malloc(i.byteLength);return n.HEAPU8.set(i,a),[a,i.byteLength]},e.createSessionFinalize=(i,n)=>{const a=(0,l.getInstance)();let u=0,m=0,g=[];try{if([m,g]=(0,o.setSessionOptions)(n),u=a._OrtCreateSession(i[0],i[1],m),u===0)throw new Error("Can't create a session")}finally{a._free(i[0]),a._OrtReleaseSessionOptions(m),g.forEach(a._free)}const _=a._OrtGetInputCount(u),b=a._OrtGetOutputCount(u),y=[],v=[],x=[],w=[];for(let S=0;S<_;S++){const M=a._OrtGetInputName(u,S);if(M===0)throw new Error("Can't get an input name");v.push(M),y.push(a.UTF8ToString(M))}for(let S=0;S{const a=(0,e.createSessionAllocate)(i);return(0,e.createSessionFinalize)(a,n)},e.releaseSession=i=>{const n=(0,l.getInstance)(),a=h.get(i);if(!a)throw new Error("invalid session id");const u=a[0],m=a[1],g=a[2];m.forEach(n._OrtFree),g.forEach(n._OrtFree),n._OrtReleaseSession(u),h.delete(i)};const p=i=>{switch(i){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;default:throw new Error(`unsupported data type: ${i}`)}},f=i=>{switch(i){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";default:throw new Error(`unsupported data type: ${i}`)}},d=i=>{switch(i){case"float32":return Float32Array;case"uint8":case"bool":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${i}`)}};e.run=(i,n,a,u,m)=>{const g=(0,l.getInstance)(),_=h.get(i);if(!_)throw new Error("invalid session id");const b=_[0],y=_[1],v=_[2],x=n.length,w=u.length;let S=0,M=[];const T=[],E=[];try{[S,M]=(0,r.setRunOptions)(m);for(let O=0;Og.HEAP32[le++]=Me);const de=g._OrtCreateTensor(p(U),J,ee,ie,K.length);if(de===0)throw new Error("Can't create a tensor");T.push(de)}finally{g.stackRestore(he)}}const R=g.stackSave(),I=g.stackAlloc(4*x),k=g.stackAlloc(4*x),C=g.stackAlloc(4*w),z=g.stackAlloc(4*w);try{let O=I/4,U=k/4,K=C/4,$=z/4;for(let he=0;hePe*ze);if(Me=f(Be),Me==="string"){const Pe=[];let ze=Ee/4;for(let De=0;De{const n=(0,l.getInstance)(),a=h.get(i);if(!a)throw new Error("invalid session id");const u=a[0],m=n._OrtEndProfiling(u);if(m===0)throw new Error("Can't get an profile file name");n._OrtFree(m)},e.extractTransferableBuffers=i=>{const n=[];for(const a of i){const u=a[2];!Array.isArray(u)&&u.buffer&&n.push(u.buffer)}return n}},6361:function(s,e,t){var r=this&&this.__createBinding||(Object.create?function(m,g,_,b){b===void 0&&(b=_);var y=Object.getOwnPropertyDescriptor(g,_);y&&!("get"in y?!g.__esModule:y.writable||y.configurable)||(y={enumerable:!0,get:function(){return g[_]}}),Object.defineProperty(m,b,y)}:function(m,g,_,b){b===void 0&&(b=_),m[b]=g[_]}),o=this&&this.__setModuleDefault||(Object.create?function(m,g){Object.defineProperty(m,"default",{enumerable:!0,value:g})}:function(m,g){m.default=g}),c=this&&this.__importStar||function(m){if(m&&m.__esModule)return m;var g={};if(m!=null)for(var _ in m)_!=="default"&&Object.prototype.hasOwnProperty.call(m,_)&&r(g,m,_);return o(g,m),g},l=this&&this.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(e,"__esModule",{value:!0}),e.dispose=e.getInstance=e.initializeWebAssembly=void 0;const h=c(t(6449)),p=l(t(932)),f=t(3474);let d,i=!1,n=!1,a=!1;const u=(m,g)=>g?m?"ort-wasm-simd-threaded.wasm":"ort-wasm-threaded.wasm":m?"ort-wasm-simd.wasm":"ort-wasm.wasm";e.initializeWebAssembly=async m=>{if(i)return Promise.resolve();if(n)throw new Error("multiple calls to 'initializeWebAssembly()' detected.");if(a)throw new Error("previous call to 'initializeWebAssembly()' failed.");n=!0;const g=m.initTimeout,_=m.numThreads,b=m.simd,y=_>1&&(()=>{try{return typeof SharedArrayBuffer<"u"&&(typeof MessageChannel<"u"&&new MessageChannel().port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11])))}catch{return!1}})(),v=b&&(()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch{return!1}})(),x=typeof m.wasmPaths=="string"?m.wasmPaths:void 0,w=u(!1,y),S=u(v,y),M=typeof m.wasmPaths=="object"?m.wasmPaths[S]:void 0;let T=!1;const E=[];if(g>0&&E.push(new Promise(R=>{setTimeout(()=>{T=!0,R()},g)})),E.push(new Promise((R,I)=>{const k=y?f:p.default,C={locateFile:(z,O)=>y&&z.endsWith(".worker.js")&&typeof Blob<"u"?URL.createObjectURL(new Blob([t(4154)],{type:"text/javascript"})):z===w?M??(x??O)+S:O+z};if(y)if(typeof Blob>"u")C.mainScriptUrlOrBlob=h.join("/","ort-wasm-threaded.js");else{const z=`var ortWasmThreaded=(function(){var _scriptDir;return ${k.toString()}})();`;C.mainScriptUrlOrBlob=new Blob([z],{type:"text/javascript"})}k(C).then(z=>{n=!1,i=!0,d=z,R()},z=>{n=!1,a=!0,I(z)})})),await Promise.race(E),T)throw new Error(`WebAssembly backend initializing failed due to timeout: ${g}ms`)},e.getInstance=()=>{if(i&&d)return d;throw new Error("WebAssembly is not initialized yet.")},e.dispose=()=>{var m;!i||n||a||(n=!0,(m=d.PThread)===null||m===void 0||m.terminateAllThreads(),d=void 0,n=!1,i=!1,a=!0)}},9710:(s,e,t)=>{t.d(e,{Z:()=>c});var r=t(477),o=t.n(r);function c(){return o()('/*!\n* ONNX Runtime Web v1.14.0\n* Copyright (c) Microsoft Corporation. All rights reserved.\n* Licensed under the MIT License.\n*/\n(()=>{var t={474:(t,e,n)=>{var _scriptDir,r=(_scriptDir=(_scriptDir="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(t){function e(){return j.buffer!=D&&N(j.buffer),P}function r(){return j.buffer!=D&&N(j.buffer),U}function a(){return j.buffer!=D&&N(j.buffer),F}function i(){return j.buffer!=D&&N(j.buffer),I}function o(){return j.buffer!=D&&N(j.buffer),W}var u,c,s;t=t||{},u||(u=void 0!==t?t:{}),u.ready=new Promise((function(t,e){c=t,s=e}));var l,f,p,h,d,y,b=Object.assign({},u),m="./this.program",g=(t,e)=>{throw e},v="object"==typeof window,w="function"==typeof importScripts,_="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,O=u.ENVIRONMENT_IS_PTHREAD||!1,A="";function S(t){return u.locateFile?u.locateFile(t,A):A+t}if(_){let e;A=w?n(908).dirname(A)+"/":"//",y=()=>{d||(h=n(384),d=n(908))},l=function(t,e){return y(),t=d.normalize(t),h.readFileSync(t,e?void 0:"utf8")},p=t=>((t=l(t,!0)).buffer||(t=new Uint8Array(t)),t),f=(t,e,n)=>{y(),t=d.normalize(t),h.readFile(t,(function(t,r){t?n(t):e(r.buffer)}))},1{if(Q())throw process.exitCode=t,e;e instanceof ct||x("exiting due to exception: "+e),process.exit(t)},u.inspect=function(){return"[Emscripten Module object]"};try{e=n(925)}catch(t){throw console.error(\'The "worker_threads" module is not supported in this node.js build - perhaps a newer version is needed?\'),t}n.g.Worker=e.Worker}else(v||w)&&(w?A=self.location.href:"undefined"!=typeof document&&document.currentScript&&(A=document.currentScript.src),_scriptDir&&(A=_scriptDir),A=0!==A.indexOf("blob:")?A.substr(0,A.replace(/[?#].*/,"").lastIndexOf("/")+1):"",_||(l=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},w&&(p=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),f=(t,e,n)=>{var r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer",r.onload=()=>{200==r.status||0==r.status&&r.response?e(r.response):n()},r.onerror=n,r.send(null)}));_&&"undefined"==typeof performance&&(n.g.performance=n(953).performance);var T=console.log.bind(console),E=console.warn.bind(console);_&&(y(),T=t=>h.writeSync(1,t+"\\n"),E=t=>h.writeSync(2,t+"\\n"));var M,C=u.print||T,x=u.printErr||E;Object.assign(u,b),b=null,u.thisProgram&&(m=u.thisProgram),u.quit&&(g=u.quit),u.wasmBinary&&(M=u.wasmBinary);var R=u.noExitRuntime||!1;"object"!=typeof WebAssembly&&at("no native wasm support detected");var j,k,D,P,U,F,I,W,H=!1,L="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function z(t,e,n){var r=(e>>>=0)+n;for(n=e;t[n]&&!(n>=r);)++n;if(16(a=224==(240&a)?(15&a)<<12|i<<6|o:(7&a)<<18|i<<12|o<<6|63&t[e++])?r+=String.fromCharCode(a):(a-=65536,r+=String.fromCharCode(55296|a>>10,56320|1023&a))}}else r+=String.fromCharCode(a)}return r}function Y(t,e){return(t>>>=0)?z(r(),t,e):""}function B(t,e,n,r){if(!(0>>=0;r=n+r-1;for(var i=0;i=o&&(o=65536+((1023&o)<<10)|1023&t.charCodeAt(++i)),127>=o){if(n>=r)break;e[n++>>>0]=o}else{if(2047>=o){if(n+1>=r)break;e[n++>>>0]=192|o>>6}else{if(65535>=o){if(n+2>=r)break;e[n++>>>0]=224|o>>12}else{if(n+3>=r)break;e[n++>>>0]=240|o>>18,e[n++>>>0]=128|o>>12&63}e[n++>>>0]=128|o>>6&63}e[n++>>>0]=128|63&o}}return e[n>>>0]=0,n-a}function G(t){for(var e=0,n=0;n=r?e++:2047>=r?e+=2:55296<=r&&57343>=r?(e+=4,++n):e+=3}return e}function N(t){D=t,u.HEAP8=P=new Int8Array(t),u.HEAP16=new Int16Array(t),u.HEAP32=F=new Int32Array(t),u.HEAPU8=U=new Uint8Array(t),u.HEAPU16=new Uint16Array(t),u.HEAPU32=I=new Uint32Array(t),u.HEAPF32=new Float32Array(t),u.HEAPF64=W=new Float64Array(t)}O&&(D=u.buffer);var V=u.INITIAL_MEMORY||16777216;if(O)j=u.wasmMemory,D=u.buffer;else if(u.wasmMemory)j=u.wasmMemory;else if(!((j=new WebAssembly.Memory({initial:V/65536,maximum:65536,shared:!0})).buffer instanceof SharedArrayBuffer))throw x("requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag"),_&&console.log("(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)"),Error("bad memory");j&&(D=j.buffer),V=D.byteLength,N(D);var $,q=[],X=[],J=[],Z=[];function Q(){return R||!1}function K(){var t=u.preRun.shift();q.unshift(t)}var tt,et=0,nt=null,rt=null;function at(t){throw O?postMessage({cmd:"onAbort",arg:t}):u.onAbort&&u.onAbort(t),x(t="Aborted("+t+")"),H=!0,t=new WebAssembly.RuntimeError(t+". Build with -sASSERTIONS for more info."),s(t),t}function it(){return tt.startsWith("data:application/octet-stream;base64,")}function ot(){var t=tt;try{if(t==tt&&M)return new Uint8Array(M);if(p)return p(t);throw"both async and sync fetching of the wasm failed"}catch(t){at(t)}}tt="ort-wasm-threaded.wasm",it()||(tt=S(tt));var ut={};function ct(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function st(t){(t=ht.Vb[t])||at(),ht.mc(t)}function lt(t){var e=ht.Cc();if(!e)return 6;ht.ac.push(e),ht.Vb[t.Ub]=e,e.Ub=t.Ub;var n={cmd:"run",start_routine:t.Ic,arg:t.zc,pthread_ptr:t.Ub};return e.$b=()=>{n.time=performance.now(),e.postMessage(n,t.Nc)},e.loaded&&(e.$b(),delete e.$b),0}function ft(t){if(O)return $t(1,1,t);Q()||(ht.oc(),u.onExit&&u.onExit(t),H=!0),g(t,new ct(t))}function pt(t,e){if(!e&&O)throw bt(t),"unwind";Q()||O||(me(),dt(J),be(0),re[1].length&&ae(1,10),re[2].length&&ae(2,10),ht.oc()),ft(t)}var ht={Yb:[],ac:[],qc:[],Vb:{},fc:function(){O&&ht.Ec()},Pc:function(){},Ec:function(){ht.receiveObjectTransfer=ht.Gc,ht.threadInitTLS=ht.pc,ht.setExitStatus=ht.nc,R=!1},nc:function(){},oc:function(){for(var t of Object.values(ht.Vb))ht.mc(t);for(t of ht.Yb)t.terminate();ht.Yb=[]},mc:function(t){var e=t.Ub;delete ht.Vb[e],ht.Yb.push(t),ht.ac.splice(ht.ac.indexOf(t),1),t.Ub=0,Oe(e)},Gc:function(){},pc:function(){ht.qc.forEach((t=>t()))},Fc:function(t,e){t.onmessage=n=>{var r=(n=n.data).cmd;if(t.Ub&&(ht.Bc=t.Ub),n.targetThread&&n.targetThread!=he()){var a=ht.Vb[n.Qc];a?a.postMessage(n,n.transferList):x(\'Internal error! Worker sent a message "\'+r+\'" to target pthread \'+n.targetThread+", but that thread no longer exists!")}else"processProxyingQueue"===r?zt(n.queue):"spawnThread"===r?lt(n):"cleanupThread"===r?st(n.thread):"killThread"===r?(n=n.thread,r=ht.Vb[n],delete ht.Vb[n],r.terminate(),Oe(n),ht.ac.splice(ht.ac.indexOf(r),1),r.Ub=0):"cancelThread"===r?ht.Vb[n.thread].postMessage({cmd:"cancel"}):"loaded"===r?(t.loaded=!0,e&&e(t),t.$b&&(t.$b(),delete t.$b)):"print"===r?C("Thread "+n.threadId+": "+n.text):"printErr"===r?x("Thread "+n.threadId+": "+n.text):"alert"===r?alert("Thread "+n.threadId+": "+n.text):"setimmediate"===n.target?t.postMessage(n):"onAbort"===r?u.onAbort&&u.onAbort(n.arg):r&&x("worker sent an unknown command "+r);ht.Bc=void 0},t.onerror=t=>{throw x("worker sent an error! "+t.filename+":"+t.lineno+": "+t.message),t},_&&(t.on("message",(function(e){t.onmessage({data:e})})),t.on("error",(function(e){t.onerror(e)})),t.on("detachedExit",(function(){}))),t.postMessage({cmd:"load",urlOrBlob:u.mainScriptUrlOrBlob||_scriptDir,wasmMemory:j,wasmModule:k})},yc:function(){var t=S("ort-wasm-threaded.worker.js");ht.Yb.push(new Worker(t))},Cc:function(){return 0==ht.Yb.length&&(ht.yc(),ht.Fc(ht.Yb[0])),ht.Yb.pop()}};function dt(t){for(;0>2>>>0];t=a()[t+48>>2>>>0],Te(e,e-t),Me(e)};var mt=[];function gt(t){var e=mt[t];return e||(t>=mt.length&&(mt.length=t+1),mt[t]=e=$.get(t)),e}u.invokeEntryPoint=function(t,e){t=gt(t)(e),Q()?ht.nc(t):Ae(t)};var vt,wt,_t=[],Ot=0,At=0;function St(t){this.Zb=t,this.Sb=t-24,this.xc=function(t){i()[this.Sb+4>>2>>>0]=t},this.bc=function(){return i()[this.Sb+4>>2>>>0]},this.wc=function(t){i()[this.Sb+8>>2>>>0]=t},this.Dc=function(){return i()[this.Sb+8>>2>>>0]},this.rc=function(){a()[this.Sb>>2>>>0]=0},this.hc=function(t){t=t?1:0,e()[this.Sb+12>>0>>>0]=t},this.uc=function(){return 0!=e()[this.Sb+12>>0>>>0]},this.ic=function(t){t=t?1:0,e()[this.Sb+13>>0>>>0]=t},this.kc=function(){return 0!=e()[this.Sb+13>>0>>>0]},this.fc=function(t,e){this.cc(0),this.xc(t),this.wc(e),this.rc(),this.hc(!1),this.ic(!1)},this.sc=function(){Atomics.add(a(),this.Sb>>2,1)},this.Hc=function(){return 1===Atomics.sub(a(),this.Sb>>2,1)},this.cc=function(t){i()[this.Sb+16>>2>>>0]=t},this.tc=function(){return i()[this.Sb+16>>2>>>0]},this.vc=function(){if(Re(this.bc()))return i()[this.Zb>>2>>>0];var t=this.tc();return 0!==t?t:this.Zb}}function Tt(t){return ye(new St(t).Sb)}function Et(t,e,n,r){return O?$t(3,1,t,e,n,r):Mt(t,e,n,r)}function Mt(t,e,n,r){if("undefined"==typeof SharedArrayBuffer)return x("Current environment does not support SharedArrayBuffer, pthreads are not available!"),6;var a=[];return O&&0===a.length?Et(t,e,n,r):(t={Ic:n,Ub:t,zc:r,Nc:a},O?(t.Oc="spawnThread",postMessage(t,a),0):lt(t))}function Ct(t,e,n){return O?$t(4,1,t,e,n):0}function xt(t,e){if(O)return $t(5,1,t,e)}function Rt(t,e){if(O)return $t(6,1,t,e)}function jt(t,e,n){if(O)return $t(7,1,t,e,n)}function kt(t,e,n){return O?$t(8,1,t,e,n):0}function Dt(t,e){if(O)return $t(9,1,t,e)}function Pt(t,e,n){if(O)return $t(10,1,t,e,n)}function Ut(t,e,n,r){if(O)return $t(11,1,t,e,n,r)}function Ft(t,e,n,r){if(O)return $t(12,1,t,e,n,r)}function It(t,e,n,r){if(O)return $t(13,1,t,e,n,r)}function Wt(t){if(O)return $t(14,1,t)}function Ht(t,e){if(O)return $t(15,1,t,e)}function Lt(t,e,n){if(O)return $t(16,1,t,e,n)}function zt(t){Atomics.store(a(),t>>2,1),he()&&_e(t),Atomics.compareExchange(a(),t>>2,1,0)}function Yt(t){return i()[t>>>2]+4294967296*a()[t+4>>>2]}function Bt(t,e,n,r,a,i){return O?$t(17,1,t,e,n,r,a,i):-52}function Gt(t,e,n,r,a,i){if(O)return $t(18,1,t,e,n,r,a,i)}function Nt(t){var n=G(t)+1,r=de(n);return r&&B(t,e(),r,n),r}function Vt(t,e,n){function r(t){return(t=t.toTimeString().match(/\\(([A-Za-z ]+)\\)$/))?t[1]:"GMT"}if(O)return $t(19,1,t,e,n);var o=(new Date).getFullYear(),u=new Date(o,0,1),c=new Date(o,6,1);o=u.getTimezoneOffset();var s=c.getTimezoneOffset(),l=Math.max(o,s);a()[t>>2>>>0]=60*l,a()[e>>2>>>0]=Number(o!=s),t=r(u),e=r(c),t=Nt(t),e=Nt(e),s>2>>>0]=t,i()[n+4>>2>>>0]=e):(i()[n>>2>>>0]=e,i()[n+4>>2>>>0]=t)}function $t(t,e){var n=arguments.length-2,r=arguments;return yt((()=>{for(var a=Ce(8*n),i=a>>3,u=0;u>>0]=c}return we(t,n,a,e)}))}u.executeNotifiedProxyingQueue=zt,wt=_?()=>{var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:O?()=>performance.now()-u.__performance_now_clock_drift:()=>performance.now();var qt,Xt=[],Jt={};function Zt(){if(!qt){var t,e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:m||"./this.program"};for(t in Jt)void 0===Jt[t]?delete e[t]:e[t]=Jt[t];var n=[];for(t in e)n.push(t+"="+e[t]);qt=n}return qt}function Qt(t,n){if(O)return $t(20,1,t,n);var r=0;return Zt().forEach((function(a,o){var u=n+r;for(o=i()[t+4*o>>2>>>0]=u,u=0;u>0>>>0]=a.charCodeAt(u);e()[o>>0>>>0]=0,r+=a.length+1})),0}function Kt(t,e){if(O)return $t(21,1,t,e);var n=Zt();i()[t>>2>>>0]=n.length;var r=0;return n.forEach((function(t){r+=t.length+1})),i()[e>>2>>>0]=r,0}function te(t){return O?$t(22,1,t):52}function ee(t,e,n,r){return O?$t(23,1,t,e,n,r):52}function ne(t,e,n,r,a){return O?$t(24,1,t,e,n,r,a):70}var re=[null,[],[]];function ae(t,e){var n=re[t];0===e||10===e?((1===t?C:x)(z(n,0)),n.length=0):n.push(e)}function ie(t,e,n,a){if(O)return $t(25,1,t,e,n,a);for(var o=0,u=0;u>2>>>0],s=i()[e+4>>2>>>0];e+=8;for(var l=0;l>>0]);o+=s}return i()[a>>2>>>0]=o,0}var oe=0;function ue(t){return 0==t%4&&(0!=t%100||0==t%400)}var ce=[31,29,31,30,31,30,31,31,30,31,30,31],se=[31,28,31,30,31,30,31,31,30,31,30,31];function le(t,n,r,i){function o(t,e,n){for(t="number"==typeof t?t.toString():t||"";t.lengtht?-1:0r-t.getDate())){t.setDate(t.getDate()+e);break}e-=r-t.getDate()+1,t.setDate(1),11>n?t.setMonth(n+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1))}return n=new Date(t.getFullYear()+1,0,4),e=s(new Date(t.getFullYear(),0,4)),n=s(n),0>=c(e,t)?0>=c(n,t)?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}var f=a()[i+40>>2>>>0];for(var p in i={Lc:a()[i>>2>>>0],Kc:a()[i+4>>2>>>0],dc:a()[i+8>>2>>>0],jc:a()[i+12>>2>>>0],ec:a()[i+16>>2>>>0],Xb:a()[i+20>>2>>>0],Tb:a()[i+24>>2>>>0],Wb:a()[i+28>>2>>>0],Rc:a()[i+32>>2>>>0],Jc:a()[i+36>>2>>>0],Mc:f?Y(f):""},r=Y(r),f={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})r=r.replace(new RegExp(p,"g"),f[p]);var h="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),d="January February March April May June July August September October November December".split(" ");for(p in f={"%a":function(t){return h[t.Tb].substring(0,3)},"%A":function(t){return h[t.Tb]},"%b":function(t){return d[t.ec].substring(0,3)},"%B":function(t){return d[t.ec]},"%C":function(t){return u((t.Xb+1900)/100|0,2)},"%d":function(t){return u(t.jc,2)},"%e":function(t){return o(t.jc,2," ")},"%g":function(t){return l(t).toString().substring(2)},"%G":function(t){return l(t)},"%H":function(t){return u(t.dc,2)},"%I":function(t){return 0==(t=t.dc)?t=12:12t.dc?"AM":"PM"},"%S":function(t){return u(t.Lc,2)},"%t":function(){return"\\t"},"%u":function(t){return t.Tb||7},"%U":function(t){return u(Math.floor((t.Wb+7-t.Tb)/7),2)},"%V":function(t){var e=Math.floor((t.Wb+7-(t.Tb+6)%7)/7);if(2>=(t.Tb+371-t.Wb-2)%7&&e++,e)53==e&&(4==(n=(t.Tb+371-t.Wb)%7)||3==n&&ue(t.Xb)||(e=1));else{e=52;var n=(t.Tb+7-t.Wb-1)%7;(4==n||5==n&&ue(t.Xb%400-1))&&e++}return u(e,2)},"%w":function(t){return t.Tb},"%W":function(t){return u(Math.floor((t.Wb+7-(t.Tb+6)%7)/7),2)},"%y":function(t){return(t.Xb+1900).toString().substring(2)},"%Y":function(t){return t.Xb+1900},"%z":function(t){var e=0<=(t=t.Jc);return t=Math.abs(t)/60,(e?"+":"-")+String("0000"+(t/60*100+t%60)).slice(-4)},"%Z":function(t){return t.Mc},"%%":function(){return"%"}},r=r.replace(/%%/g,"\\0\\0"),f)r.includes(p)&&(r=r.replace(new RegExp(p,"g"),f[p](i)));return p=function(t){var e=Array(G(t)+1);return B(t,e,0,e.length),e}(r=r.replace(/\\0\\0/g,"%")),p.length>n?0:(function(t,n){e().set(t,n>>>0)}(p,t),p.length-1)}ht.fc();var fe=[null,ft,bt,Et,Ct,xt,Rt,jt,kt,Dt,Pt,Ut,Ft,It,Wt,Ht,Lt,Bt,Gt,Vt,Qt,Kt,te,ee,ne,ie],pe={b:function(t){return de(t+24)+24},n:function(t){return(t=new St(t)).uc()||(t.hc(!0),Ot--),t.ic(!1),_t.push(t),t.sc(),t.vc()},ma:function(t){throw x("Unexpected exception thrown, this is not properly supported - aborting"),H=!0,t},x:function(){Se(0);var t=_t.pop();if(t.Hc()&&!t.kc()){var e=t.Dc();e&>(e)(t.Zb),Tt(t.Zb)}At=0},e:function(){var t=At;if(!t)return oe=0;var e=new St(t);e.cc(t);var n=e.bc();if(!n)return oe=0,t;for(var r=Array.prototype.slice.call(arguments),a=0;azt(r)));else if(O)postMessage({targetThread:t,cmd:"processProxyingQueue",queue:r});else{if(!(t=ht.Vb[t]))return;t.postMessage({cmd:"processProxyingQueue",queue:r})}return 1},Ea:function(){return-1},Pa:function(t,e){t=new Date(1e3*Yt(t)),a()[e>>2>>>0]=t.getUTCSeconds(),a()[e+4>>2>>>0]=t.getUTCMinutes(),a()[e+8>>2>>>0]=t.getUTCHours(),a()[e+12>>2>>>0]=t.getUTCDate(),a()[e+16>>2>>>0]=t.getUTCMonth(),a()[e+20>>2>>>0]=t.getUTCFullYear()-1900,a()[e+24>>2>>>0]=t.getUTCDay(),t=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,1,0,0,0,0))/864e5|0,a()[e+28>>2>>>0]=t},Qa:function(t,e){t=new Date(1e3*Yt(t)),a()[e>>2>>>0]=t.getSeconds(),a()[e+4>>2>>>0]=t.getMinutes(),a()[e+8>>2>>>0]=t.getHours(),a()[e+12>>2>>>0]=t.getDate(),a()[e+16>>2>>>0]=t.getMonth(),a()[e+20>>2>>>0]=t.getFullYear()-1900,a()[e+24>>2>>>0]=t.getDay();var n=new Date(t.getFullYear(),0,1),r=(t.getTime()-n.getTime())/864e5|0;a()[e+28>>2>>>0]=r,a()[e+36>>2>>>0]=-60*t.getTimezoneOffset(),r=new Date(t.getFullYear(),6,1).getTimezoneOffset(),t=0|(r!=(n=n.getTimezoneOffset())&&t.getTimezoneOffset()==Math.min(n,r)),a()[e+32>>2>>>0]=t},Ra:function(t){var e=new Date(a()[t+20>>2>>>0]+1900,a()[t+16>>2>>>0],a()[t+12>>2>>>0],a()[t+8>>2>>>0],a()[t+4>>2>>>0],a()[t>>2>>>0],0),n=a()[t+32>>2>>>0],r=e.getTimezoneOffset(),i=new Date(e.getFullYear(),0,1),o=new Date(e.getFullYear(),6,1).getTimezoneOffset(),u=i.getTimezoneOffset(),c=Math.min(u,o);return 0>n?a()[t+32>>2>>>0]=Number(o!=u&&c==r):0>2>>>0]=e.getDay(),n=(e.getTime()-i.getTime())/864e5|0,a()[t+28>>2>>>0]=n,a()[t>>2>>>0]=e.getSeconds(),a()[t+4>>2>>>0]=e.getMinutes(),a()[t+8>>2>>>0]=e.getHours(),a()[t+12>>2>>>0]=e.getDate(),a()[t+16>>2>>>0]=e.getMonth(),e.getTime()/1e3|0},Aa:Bt,Ba:Gt,Sa:function t(e,n,r){t.Ac||(t.Ac=!0,Vt(e,n,r))},y:function(){at("")},U:function(){if(!_&&!w){var t="Blocking on the main thread is very dangerous, see https://emscripten.org/docs/porting/pthreads.html#blocking-on-the-main-browser-thread";vt||(vt={}),vt[t]||(vt[t]=1,_&&(t="warning: "+t),x(t))}},ra:function(){return 4294901760},B:wt,Ia:function(t,e,n){r().copyWithin(t>>>0,e>>>0,e+n>>>0)},F:function(){return _?n(993).cpus().length:navigator.hardwareConcurrency},Da:function(t,e,n){Xt.length=e,n>>=3;for(var r=0;r>>0];return(0>t?ut[-t-1]:fe[t]).apply(null,Xt)},qa:function(t){var e=r().length;if((t>>>=0)<=e||4294901760=n;n*=2){var a=e*(1+.2/n);a=Math.min(a,t+100663296);var i=Math;a=Math.max(t,a),i=i.min.call(i,4294901760,a+(65536-a%65536)%65536);t:{try{j.grow(i-D.byteLength+65535>>>16),N(j.buffer);var o=1;break t}catch(t){}o=void 0}if(o)return!0}return!1},Na:function(){throw"unwind"},Ga:Qt,Ha:Kt,J:pt,I:te,S:ee,ga:ne,R:ie,d:function(){return oe},na:function t(r,a){t.lc||(t.lc=function(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var t=new Uint8Array(1);return()=>(crypto.getRandomValues(t),t[0])}if(_)try{var e=n(Object(function(){var t=new Error("Cannot find module \'crypto\'");throw t.code="MODULE_NOT_FOUND",t}()));return()=>e.randomBytes(1)[0]}catch(t){}return()=>at("randomDevice")}());for(var i=0;i>0>>>0]=t.lc();return 0},ia:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},ja:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},K:function(t){var e=Ee();try{return gt(t)()}catch(t){if(Me(e),t!==t+0)throw t;Se(1,0)}},f:function(t,e){var n=Ee();try{return gt(t)(e)}catch(t){if(Me(n),t!==t+0)throw t;Se(1,0)}},P:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},Q:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},k:function(t,e,n){var r=Ee();try{return gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},p:function(t,e,n,r){var a=Ee();try{return gt(t)(e,n,r)}catch(t){if(Me(a),t!==t+0)throw t;Se(1,0)}},q:function(t,e,n,r,a){var i=Ee();try{return gt(t)(e,n,r,a)}catch(t){if(Me(i),t!==t+0)throw t;Se(1,0)}},N:function(t,e,n,r,a,i){var o=Ee();try{return gt(t)(e,n,r,a,i)}catch(t){if(Me(o),t!==t+0)throw t;Se(1,0)}},s:function(t,e,n,r,a,i){var o=Ee();try{return gt(t)(e,n,r,a,i)}catch(t){if(Me(o),t!==t+0)throw t;Se(1,0)}},w:function(t,e,n,r,a,i,o){var u=Ee();try{return gt(t)(e,n,r,a,i,o)}catch(t){if(Me(u),t!==t+0)throw t;Se(1,0)}},L:function(t,e,n,r,a,i,o,u){var c=Ee();try{return gt(t)(e,n,r,a,i,o,u)}catch(t){if(Me(c),t!==t+0)throw t;Se(1,0)}},E:function(t,e,n,r,a,i,o,u,c,s,l,f){var p=Ee();try{return gt(t)(e,n,r,a,i,o,u,c,s,l,f)}catch(t){if(Me(p),t!==t+0)throw t;Se(1,0)}},aa:function(t,e,n,r,a,i,o,u){var c=Ee();try{return He(t,e,n,r,a,i,o,u)}catch(t){if(Me(c),t!==t+0)throw t;Se(1,0)}},_:function(t,e,n,r,a,i,o){var u=Ee();try{return ke(t,e,n,r,a,i,o)}catch(t){if(Me(u),t!==t+0)throw t;Se(1,0)}},Z:function(t,e,n,r,a){var i=Ee();try{return Le(t,e,n,r,a)}catch(t){if(Me(i),t!==t+0)throw t;Se(1,0)}},ca:function(t,e,n,r){var a=Ee();try{return Ie(t,e,n,r)}catch(t){if(Me(a),t!==t+0)throw t;Se(1,0)}},$:function(t){var e=Ee();try{return je(t)}catch(t){if(Me(e),t!==t+0)throw t;Se(1,0)}},ba:function(t,e){var n=Ee();try{return We(t,e)}catch(t){if(Me(n),t!==t+0)throw t;Se(1,0)}},Y:function(t,e,n){var r=Ee();try{return De(t,e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},g:function(t){var e=Ee();try{gt(t)()}catch(t){if(Me(e),t!==t+0)throw t;Se(1,0)}},r:function(t,e){var n=Ee();try{gt(t)(e)}catch(t){if(Me(n),t!==t+0)throw t;Se(1,0)}},i:function(t,e,n){var r=Ee();try{gt(t)(e,n)}catch(t){if(Me(r),t!==t+0)throw t;Se(1,0)}},ha:function(t,e,n,r){var a=Ee();try{gt(t)(e,n,r)}catch(t){if(Me(a),t!==t+0)throw t;Se(1,0)}},m:function(t,e,n,r){var a=Ee();try{gt(t)(e,n,r)}catch(t){if(Me(a),t!==t+0)throw t;Se(1,0)}},v:function(t,e,n,r,a){var i=Ee();try{gt(t)(e,n,r,a)}catch(t){if(Me(i),t!==t+0)throw t;Se(1,0)}},u:function(t,e,n,r,a,i){var o=Ee();try{gt(t)(e,n,r,a,i)}catch(t){if(Me(o),t!==t+0)throw t;Se(1,0)}},O:function(t,e,n,r,a,i,o){var u=Ee();try{gt(t)(e,n,r,a,i,o)}catch(t){if(Me(u),t!==t+0)throw t;Se(1,0)}},A:function(t,e,n,r,a,i,o,u){var c=Ee();try{gt(t)(e,n,r,a,i,o,u)}catch(t){if(Me(c),t!==t+0)throw t;Se(1,0)}},ka:function(t,e,n,r,a,i,o,u,c){var s=Ee();try{gt(t)(e,n,r,a,i,o,u,c)}catch(t){if(Me(s),t!==t+0)throw t;Se(1,0)}},C:function(t,e,n,r,a,i,o,u,c,s,l){var f=Ee();try{gt(t)(e,n,r,a,i,o,u,c,s,l)}catch(t){if(Me(f),t!==t+0)throw t;Se(1,0)}},D:function(t,e,n,r,a,i,o,u,c,s,l,f,p,h,d,y){var b=Ee();try{gt(t)(e,n,r,a,i,o,u,c,s,l,f,p,h,d,y)}catch(t){if(Me(b),t!==t+0)throw t;Se(1,0)}},fa:function(t,e,n,r,a,i,o,u){var c=Ee();try{Pe(t,e,n,r,a,i,o,u)}catch(t){if(Me(c),t!==t+0)throw t;Se(1,0)}},da:function(t,e,n,r,a,i,o,u,c,s,l,f){var p=Ee();try{Fe(t,e,n,r,a,i,o,u,c,s,l,f)}catch(t){if(Me(p),t!==t+0)throw t;Se(1,0)}},ea:function(t,e,n,r,a,i){var o=Ee();try{Ue(t,e,n,r,a,i)}catch(t){if(Me(o),t!==t+0)throw t;Se(1,0)}},o:function(t){return t},a:j||u.wasmMemory,G:function(t){oe=t},la:le,z:function(t,e,n,r){return le(t,e,n,r)}};!function(){function t(t,e){u.asm=t.exports,ht.qc.push(u.asm.sb),$=u.asm.ub,X.unshift(u.asm.Va),k=e,O||(et--,u.monitorRunDependencies&&u.monitorRunDependencies(et),0==et&&(null!==nt&&(clearInterval(nt),nt=null),rt&&(t=rt,rt=null,t())))}function e(e){t(e.instance,e.module)}function n(t){return function(){if(!M&&(v||w)){if("function"==typeof fetch&&!tt.startsWith("file://"))return fetch(tt,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw"failed to load wasm binary file at \'"+tt+"\'";return t.arrayBuffer()})).catch((function(){return ot()}));if(f)return new Promise((function(t,e){f(tt,(function(e){t(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return ot()}))}().then((function(t){return WebAssembly.instantiate(t,r)})).then((function(t){return t})).then(t,(function(t){x("failed to asynchronously prepare wasm: "+t),at(t)}))}var r={a:pe};if(O||(et++,u.monitorRunDependencies&&u.monitorRunDependencies(et)),u.instantiateWasm)try{return u.instantiateWasm(r,t)}catch(t){return x("Module.instantiateWasm callback failed with error: "+t),!1}(M||"function"!=typeof WebAssembly.instantiateStreaming||it()||tt.startsWith("file://")||_||"function"!=typeof fetch?n(e):fetch(tt,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,r).then(e,(function(t){return x("wasm streaming compile failed: "+t),x("falling back to ArrayBuffer instantiation"),n(e)}))}))).catch(s)}(),u.___wasm_call_ctors=function(){return(u.___wasm_call_ctors=u.asm.Va).apply(null,arguments)},u._OrtInit=function(){return(u._OrtInit=u.asm.Wa).apply(null,arguments)},u._OrtCreateSessionOptions=function(){return(u._OrtCreateSessionOptions=u.asm.Xa).apply(null,arguments)},u._OrtAppendExecutionProvider=function(){return(u._OrtAppendExecutionProvider=u.asm.Ya).apply(null,arguments)},u._OrtAddSessionConfigEntry=function(){return(u._OrtAddSessionConfigEntry=u.asm.Za).apply(null,arguments)},u._OrtReleaseSessionOptions=function(){return(u._OrtReleaseSessionOptions=u.asm._a).apply(null,arguments)},u._OrtCreateSession=function(){return(u._OrtCreateSession=u.asm.$a).apply(null,arguments)},u._OrtReleaseSession=function(){return(u._OrtReleaseSession=u.asm.ab).apply(null,arguments)},u._OrtGetInputCount=function(){return(u._OrtGetInputCount=u.asm.bb).apply(null,arguments)},u._OrtGetOutputCount=function(){return(u._OrtGetOutputCount=u.asm.cb).apply(null,arguments)},u._OrtGetInputName=function(){return(u._OrtGetInputName=u.asm.db).apply(null,arguments)},u._OrtGetOutputName=function(){return(u._OrtGetOutputName=u.asm.eb).apply(null,arguments)},u._OrtFree=function(){return(u._OrtFree=u.asm.fb).apply(null,arguments)},u._OrtCreateTensor=function(){return(u._OrtCreateTensor=u.asm.gb).apply(null,arguments)},u._OrtGetTensorData=function(){return(u._OrtGetTensorData=u.asm.hb).apply(null,arguments)},u._OrtReleaseTensor=function(){return(u._OrtReleaseTensor=u.asm.ib).apply(null,arguments)},u._OrtCreateRunOptions=function(){return(u._OrtCreateRunOptions=u.asm.jb).apply(null,arguments)},u._OrtAddRunConfigEntry=function(){return(u._OrtAddRunConfigEntry=u.asm.kb).apply(null,arguments)},u._OrtReleaseRunOptions=function(){return(u._OrtReleaseRunOptions=u.asm.lb).apply(null,arguments)},u._OrtRun=function(){return(u._OrtRun=u.asm.mb).apply(null,arguments)},u._OrtEndProfiling=function(){return(u._OrtEndProfiling=u.asm.nb).apply(null,arguments)};var he=u._pthread_self=function(){return(he=u._pthread_self=u.asm.ob).apply(null,arguments)},de=u._malloc=function(){return(de=u._malloc=u.asm.pb).apply(null,arguments)},ye=u._free=function(){return(ye=u._free=u.asm.qb).apply(null,arguments)},be=u._fflush=function(){return(be=u._fflush=u.asm.rb).apply(null,arguments)};u.__emscripten_tls_init=function(){return(u.__emscripten_tls_init=u.asm.sb).apply(null,arguments)};var me=u.___funcs_on_exit=function(){return(me=u.___funcs_on_exit=u.asm.tb).apply(null,arguments)},ge=u.__emscripten_thread_init=function(){return(ge=u.__emscripten_thread_init=u.asm.vb).apply(null,arguments)};u.__emscripten_thread_crashed=function(){return(u.__emscripten_thread_crashed=u.asm.wb).apply(null,arguments)};var ve,we=u._emscripten_run_in_main_runtime_thread_js=function(){return(we=u._emscripten_run_in_main_runtime_thread_js=u.asm.xb).apply(null,arguments)},_e=u.__emscripten_proxy_execute_task_queue=function(){return(_e=u.__emscripten_proxy_execute_task_queue=u.asm.yb).apply(null,arguments)},Oe=u.__emscripten_thread_free_data=function(){return(Oe=u.__emscripten_thread_free_data=u.asm.zb).apply(null,arguments)},Ae=u.__emscripten_thread_exit=function(){return(Ae=u.__emscripten_thread_exit=u.asm.Ab).apply(null,arguments)},Se=u._setThrew=function(){return(Se=u._setThrew=u.asm.Bb).apply(null,arguments)},Te=u._emscripten_stack_set_limits=function(){return(Te=u._emscripten_stack_set_limits=u.asm.Cb).apply(null,arguments)},Ee=u.stackSave=function(){return(Ee=u.stackSave=u.asm.Db).apply(null,arguments)},Me=u.stackRestore=function(){return(Me=u.stackRestore=u.asm.Eb).apply(null,arguments)},Ce=u.stackAlloc=function(){return(Ce=u.stackAlloc=u.asm.Fb).apply(null,arguments)},xe=u.___cxa_can_catch=function(){return(xe=u.___cxa_can_catch=u.asm.Gb).apply(null,arguments)},Re=u.___cxa_is_pointer_type=function(){return(Re=u.___cxa_is_pointer_type=u.asm.Hb).apply(null,arguments)},je=u.dynCall_j=function(){return(je=u.dynCall_j=u.asm.Ib).apply(null,arguments)},ke=u.dynCall_iiiiij=function(){return(ke=u.dynCall_iiiiij=u.asm.Jb).apply(null,arguments)},De=u.dynCall_jii=function(){return(De=u.dynCall_jii=u.asm.Kb).apply(null,arguments)},Pe=u.dynCall_viiiiij=function(){return(Pe=u.dynCall_viiiiij=u.asm.Lb).apply(null,arguments)},Ue=u.dynCall_vjji=function(){return(Ue=u.dynCall_vjji=u.asm.Mb).apply(null,arguments)},Fe=u.dynCall_viiijjjii=function(){return(Fe=u.dynCall_viiijjjii=u.asm.Nb).apply(null,arguments)},Ie=u.dynCall_iij=function(){return(Ie=u.dynCall_iij=u.asm.Ob).apply(null,arguments)},We=u.dynCall_ji=function(){return(We=u.dynCall_ji=u.asm.Pb).apply(null,arguments)},He=u.dynCall_iiiiiij=function(){return(He=u.dynCall_iiiiiij=u.asm.Qb).apply(null,arguments)},Le=u.dynCall_iiij=function(){return(Le=u.dynCall_iiij=u.asm.Rb).apply(null,arguments)};function ze(){function t(){if(!ve&&(ve=!0,u.calledRun=!0,!H)&&(O||dt(X),c(u),u.onRuntimeInitialized&&u.onRuntimeInitialized(),!O)){if(u.postRun)for("function"==typeof u.postRun&&(u.postRun=[u.postRun]);u.postRun.length;){var t=u.postRun.shift();Z.unshift(t)}dt(Z)}}if(!(0{var _scriptDir,r=(_scriptDir=(_scriptDir="undefined"!=typeof document&&document.currentScript?document.currentScript.src:void 0)||"/index.js",function(t){var e,r,a;t=t||{},e||(e=void 0!==t?t:{}),e.ready=new Promise((function(t,e){r=t,a=e}));var i,o,u,c,s,l,f=Object.assign({},e),p="./this.program",h=(t,e)=>{throw e},d="object"==typeof window,y="function"==typeof importScripts,b="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node,m="";b?(m=y?n(908).dirname(m)+"/":"//",l=()=>{s||(c=n(384),s=n(908))},i=function(t,e){return l(),t=s.normalize(t),c.readFileSync(t,e?void 0:"utf8")},u=t=>((t=i(t,!0)).buffer||(t=new Uint8Array(t)),t),o=(t,e,n)=>{l(),t=s.normalize(t),c.readFile(t,(function(t,r){t?n(t):e(r.buffer)}))},1{if(_||0{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.send(null),e.responseText},y&&(u=t=>{var e=new XMLHttpRequest;return e.open("GET",t,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),o=(t,e,n)=>{var r=new XMLHttpRequest;r.open("GET",t,!0),r.responseType="arraybuffer",r.onload=()=>{200==r.status||0==r.status&&r.response?e(r.response):n()},r.onerror=n,r.send(null)});var g,v=e.print||console.log.bind(console),w=e.printErr||console.warn.bind(console);Object.assign(e,f),f=null,e.thisProgram&&(p=e.thisProgram),e.quit&&(h=e.quit),e.wasmBinary&&(g=e.wasmBinary);var _=e.noExitRuntime||!1;"object"!=typeof WebAssembly&&V("no native wasm support detected");var O,A,S,T,E,M,C=!1,x="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function R(t,e,n){var r=(e>>>=0)+n;for(n=e;t[n]&&!(n>=r);)++n;if(16(a=224==(240&a)?(15&a)<<12|i<<6|o:(7&a)<<18|i<<12|o<<6|63&t[e++])?r+=String.fromCharCode(a):(a-=65536,r+=String.fromCharCode(55296|a>>10,56320|1023&a))}}else r+=String.fromCharCode(a)}return r}function j(t,e){return(t>>>=0)?R(T,t,e):""}function k(t,e,n,r){if(!(0>>=0;r=n+r-1;for(var i=0;i=o&&(o=65536+((1023&o)<<10)|1023&t.charCodeAt(++i)),127>=o){if(n>=r)break;e[n++>>>0]=o}else{if(2047>=o){if(n+1>=r)break;e[n++>>>0]=192|o>>6}else{if(65535>=o){if(n+2>=r)break;e[n++>>>0]=224|o>>12}else{if(n+3>=r)break;e[n++>>>0]=240|o>>18,e[n++>>>0]=128|o>>12&63}e[n++>>>0]=128|o>>6&63}e[n++>>>0]=128|63&o}}return e[n>>>0]=0,n-a}function D(t){for(var e=0,n=0;n=r?e++:2047>=r?e+=2:55296<=r&&57343>=r?(e+=4,++n):e+=3}return e}function P(){var t=O.buffer;A=t,e.HEAP8=S=new Int8Array(t),e.HEAP16=new Int16Array(t),e.HEAP32=E=new Int32Array(t),e.HEAPU8=T=new Uint8Array(t),e.HEAPU16=new Uint16Array(t),e.HEAPU32=M=new Uint32Array(t),e.HEAPF32=new Float32Array(t),e.HEAPF64=new Float64Array(t)}var U,F=[],I=[],W=[],H=[],L=0;function z(){var t=e.preRun.shift();F.unshift(t)}var Y,B=0,G=null,N=null;function V(t){throw e.onAbort&&e.onAbort(t),w(t="Aborted("+t+")"),C=!0,t=new WebAssembly.RuntimeError(t+". Build with -sASSERTIONS for more info."),a(t),t}function $(){return Y.startsWith("data:application/octet-stream;base64,")}if(Y="ort-wasm.wasm",!$()){var q=Y;Y=e.locateFile?e.locateFile(q,m):m+q}function X(){var t=Y;try{if(t==Y&&g)return new Uint8Array(g);if(u)return u(t);throw"both async and sync fetching of the wasm failed"}catch(t){V(t)}}function J(t){this.name="ExitStatus",this.message="Program terminated with exit("+t+")",this.status=t}function Z(t){for(;0>2>>>0]=t},this.Eb=function(){return M[this.zb+4>>2>>>0]},this.Sb=function(t){M[this.zb+8>>2>>>0]=t},this.Wb=function(){return M[this.zb+8>>2>>>0]},this.Tb=function(){E[this.zb>>2>>>0]=0},this.Ib=function(t){S[this.zb+12>>0>>>0]=t?1:0},this.Pb=function(){return 0!=S[this.zb+12>>0>>>0]},this.Jb=function(t){S[this.zb+13>>0>>>0]=t?1:0},this.Lb=function(){return 0!=S[this.zb+13>>0>>>0]},this.Rb=function(t,e){this.Fb(0),this.Ub(t),this.Sb(e),this.Tb(),this.Ib(!1),this.Jb(!1)},this.Nb=function(){E[this.zb>>2>>>0]+=1},this.Xb=function(){var t=E[this.zb>>2>>>0];return E[this.zb>>2>>>0]=t-1,1===t},this.Fb=function(t){M[this.zb+16>>2>>>0]=t},this.Ob=function(){return M[this.zb+16>>2>>>0]},this.Qb=function(){if(Mt(this.Eb()))return M[this.Db>>2>>>0];var t=this.Ob();return 0!==t?t:this.Db}}function nt(t){return vt(new et(t).zb)}var rt=[];function at(t){var e=rt[t];return e||(t>=rt.length&&(rt.length=t+1),rt[t]=e=U.get(t)),e}function it(t){var e=D(t)+1,n=gt(e);return n&&k(t,S,n,e),n}var ot={};function ut(){if(!ct){var t,e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:p||"./this.program"};for(t in ot)void 0===ot[t]?delete e[t]:e[t]=ot[t];var n=[];for(t in e)n.push(t+"="+e[t]);ct=n}return ct}var ct,st=[null,[],[]];function lt(t,e){var n=st[t];0===e||10===e?((1===t?v:w)(R(n,0)),n.length=0):n.push(e)}var ft=0;function pt(t){return 0==t%4&&(0!=t%100||0==t%400)}var ht=[31,29,31,30,31,30,31,31,30,31,30,31],dt=[31,28,31,30,31,30,31,31,30,31,30,31];function yt(t,e,n,r){function a(t,e,n){for(t="number"==typeof t?t.toString():t||"";t.lengtht?-1:0r-t.getDate())){t.setDate(t.getDate()+e);break}e-=r-t.getDate()+1,t.setDate(1),11>n?t.setMonth(n+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1))}return n=new Date(t.getFullYear()+1,0,4),e=u(new Date(t.getFullYear(),0,4)),n=u(n),0>=o(e,t)?0>=o(n,t)?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}var s=E[r+40>>2>>>0];for(var l in r={$b:E[r>>2>>>0],Zb:E[r+4>>2>>>0],Gb:E[r+8>>2>>>0],Kb:E[r+12>>2>>>0],Hb:E[r+16>>2>>>0],Cb:E[r+20>>2>>>0],Ab:E[r+24>>2>>>0],Bb:E[r+28>>2>>>0],bc:E[r+32>>2>>>0],Yb:E[r+36>>2>>>0],ac:s?j(s):""},n=j(n),s={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"})n=n.replace(new RegExp(l,"g"),s[l]);var f="Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),p="January February March April May June July August September October November December".split(" ");for(l in s={"%a":function(t){return f[t.Ab].substring(0,3)},"%A":function(t){return f[t.Ab]},"%b":function(t){return p[t.Hb].substring(0,3)},"%B":function(t){return p[t.Hb]},"%C":function(t){return i((t.Cb+1900)/100|0,2)},"%d":function(t){return i(t.Kb,2)},"%e":function(t){return a(t.Kb,2," ")},"%g":function(t){return c(t).toString().substring(2)},"%G":function(t){return c(t)},"%H":function(t){return i(t.Gb,2)},"%I":function(t){return 0==(t=t.Gb)?t=12:12t.Gb?"AM":"PM"},"%S":function(t){return i(t.$b,2)},"%t":function(){return"\\t"},"%u":function(t){return t.Ab||7},"%U":function(t){return i(Math.floor((t.Bb+7-t.Ab)/7),2)},"%V":function(t){var e=Math.floor((t.Bb+7-(t.Ab+6)%7)/7);if(2>=(t.Ab+371-t.Bb-2)%7&&e++,e)53==e&&(4==(n=(t.Ab+371-t.Bb)%7)||3==n&&pt(t.Cb)||(e=1));else{e=52;var n=(t.Ab+7-t.Bb-1)%7;(4==n||5==n&&pt(t.Cb%400-1))&&e++}return i(e,2)},"%w":function(t){return t.Ab},"%W":function(t){return i(Math.floor((t.Bb+7-(t.Ab+6)%7)/7),2)},"%y":function(t){return(t.Cb+1900).toString().substring(2)},"%Y":function(t){return t.Cb+1900},"%z":function(t){var e=0<=(t=t.Yb);return t=Math.abs(t)/60,(e?"+":"-")+String("0000"+(t/60*100+t%60)).slice(-4)},"%Z":function(t){return t.ac},"%%":function(){return"%"}},n=n.replace(/%%/g,"\\0\\0"),s)n.includes(l)&&(n=n.replace(new RegExp(l,"g"),s[l](r)));return l=function(t){var e=Array(D(t)+1);return k(t,e,0,e.length),e}(n=n.replace(/\\0\\0/g,"%")),l.length>e?0:(S.set(l,t>>>0),l.length-1)}var bt={a:function(t){return gt(t+24)+24},m:function(t){return(t=new et(t)).Pb()||(t.Ib(!0),K--),t.Jb(!1),Q.push(t),t.Nb(),t.Qb()},ia:function(t){throw w("Unexpected exception thrown, this is not properly supported - aborting"),C=!0,t},w:function(){Ot(0);var t=Q.pop();if(t.Xb()&&!t.Lb()){var e=t.Wb();e&&at(e)(t.Db),nt(t.Db)}tt=0},d:function(){var t=tt;if(!t)return ft=0;var e=new et(t);e.Fb(t);var n=e.Eb();if(!n)return ft=0,t;for(var r=Array.prototype.slice.call(arguments),a=0;a>>2]+4294967296*E[t+4>>>2])),E[e>>2>>>0]=t.getUTCSeconds(),E[e+4>>2>>>0]=t.getUTCMinutes(),E[e+8>>2>>>0]=t.getUTCHours(),E[e+12>>2>>>0]=t.getUTCDate(),E[e+16>>2>>>0]=t.getUTCMonth(),E[e+20>>2>>>0]=t.getUTCFullYear()-1900,E[e+24>>2>>>0]=t.getUTCDay(),E[e+28>>2>>>0]=(t.getTime()-Date.UTC(t.getUTCFullYear(),0,1,0,0,0,0))/864e5|0},Ea:function(t,e){t=new Date(1e3*(M[t>>>2]+4294967296*E[t+4>>>2])),E[e>>2>>>0]=t.getSeconds(),E[e+4>>2>>>0]=t.getMinutes(),E[e+8>>2>>>0]=t.getHours(),E[e+12>>2>>>0]=t.getDate(),E[e+16>>2>>>0]=t.getMonth(),E[e+20>>2>>>0]=t.getFullYear()-1900,E[e+24>>2>>>0]=t.getDay();var n=new Date(t.getFullYear(),0,1);E[e+28>>2>>>0]=(t.getTime()-n.getTime())/864e5|0,E[e+36>>2>>>0]=-60*t.getTimezoneOffset();var r=new Date(t.getFullYear(),6,1).getTimezoneOffset();n=n.getTimezoneOffset(),E[e+32>>2>>>0]=0|(r!=n&&t.getTimezoneOffset()==Math.min(n,r))},Fa:function(t){var e=new Date(E[t+20>>2>>>0]+1900,E[t+16>>2>>>0],E[t+12>>2>>>0],E[t+8>>2>>>0],E[t+4>>2>>>0],E[t>>2>>>0],0),n=E[t+32>>2>>>0],r=e.getTimezoneOffset(),a=new Date(e.getFullYear(),0,1),i=new Date(e.getFullYear(),6,1).getTimezoneOffset(),o=a.getTimezoneOffset(),u=Math.min(o,i);return 0>n?E[t+32>>2>>>0]=Number(i!=o&&u==r):0>2>>>0]=e.getDay(),E[t+28>>2>>>0]=(e.getTime()-a.getTime())/864e5|0,E[t>>2>>>0]=e.getSeconds(),E[t+4>>2>>>0]=e.getMinutes(),E[t+8>>2>>>0]=e.getHours(),E[t+12>>2>>>0]=e.getDate(),E[t+16>>2>>>0]=e.getMonth(),e.getTime()/1e3|0},sa:function(){return-52},ta:function(){},Ga:function t(e,n,r){t.Vb||(t.Vb=!0,function(t,e,n){function r(t){return(t=t.toTimeString().match(/\\(([A-Za-z ]+)\\)$/))?t[1]:"GMT"}var a=(new Date).getFullYear(),i=new Date(a,0,1),o=new Date(a,6,1);a=i.getTimezoneOffset();var u=o.getTimezoneOffset();E[t>>2>>>0]=60*Math.max(a,u),E[e>>2>>>0]=Number(a!=u),t=r(i),e=r(o),t=it(t),e=it(e),u>2>>>0]=t,M[n+4>>2>>>0]=e):(M[n>>2>>>0]=e,M[n+4>>2>>>0]=t)}(e,n,r))},B:function(){V("")},ma:function(){return 4294901760},I:b?()=>{var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:()=>performance.now(),xa:function(t,e,n){T.copyWithin(t>>>0,e>>>0,e+n>>>0)},G:function(t){var e=T.length;if(4294901760<(t>>>=0))return!1;for(var n=1;4>=n;n*=2){var r=e*(1+.2/n);r=Math.min(r,t+100663296);var a=Math;r=Math.max(t,r),a=a.min.call(a,4294901760,r+(65536-r%65536)%65536);t:{try{O.grow(a-A.byteLength+65535>>>16),P();var i=1;break t}catch(t){}i=void 0}if(i)return!0}return!1},va:function(t,e){var n=0;return ut().forEach((function(r,a){var i=e+n;for(a=M[t+4*a>>2>>>0]=i,i=0;i>0>>>0]=r.charCodeAt(i);S[a>>0>>>0]=0,n+=r.length+1})),0},wa:function(t,e){var n=ut();M[t>>2>>>0]=n.length;var r=0;return n.forEach((function(t){r+=t.length+1})),M[e>>2>>>0]=r,0},ba:function(t){_||0>2>>>0],u=M[e+4>>2>>>0];e+=8;for(var c=0;c>>0]);a+=u}return M[r>>2>>>0]=a,0},c:function(){return ft},ja:function t(e,r){t.Mb||(t.Mb=function(){if("object"==typeof crypto&&"function"==typeof crypto.getRandomValues){var t=new Uint8Array(1);return()=>(crypto.getRandomValues(t),t[0])}if(b)try{var e=n(Object(function(){var t=new Error("Cannot find module \'crypto\'");throw t.code="MODULE_NOT_FOUND",t}()));return()=>e.randomBytes(1)[0]}catch(t){}return()=>V("randomDevice")}());for(var a=0;a>0>>>0]=t.Mb();return 0},ea:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},fa:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},J:function(t){var e=At();try{return at(t)()}catch(t){if(St(e),t!==t+0)throw t;Ot(1,0)}},e:function(t,e){var n=At();try{return at(t)(e)}catch(t){if(St(n),t!==t+0)throw t;Ot(1,0)}},N:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},O:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},j:function(t,e,n){var r=At();try{return at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},o:function(t,e,n,r){var a=At();try{return at(t)(e,n,r)}catch(t){if(St(a),t!==t+0)throw t;Ot(1,0)}},p:function(t,e,n,r,a){var i=At();try{return at(t)(e,n,r,a)}catch(t){if(St(i),t!==t+0)throw t;Ot(1,0)}},M:function(t,e,n,r,a,i){var o=At();try{return at(t)(e,n,r,a,i)}catch(t){if(St(o),t!==t+0)throw t;Ot(1,0)}},r:function(t,e,n,r,a,i){var o=At();try{return at(t)(e,n,r,a,i)}catch(t){if(St(o),t!==t+0)throw t;Ot(1,0)}},v:function(t,e,n,r,a,i,o){var u=At();try{return at(t)(e,n,r,a,i,o)}catch(t){if(St(u),t!==t+0)throw t;Ot(1,0)}},K:function(t,e,n,r,a,i,o,u){var c=At();try{return at(t)(e,n,r,a,i,o,u)}catch(t){if(St(c),t!==t+0)throw t;Ot(1,0)}},D:function(t,e,n,r,a,i,o,u,c,s,l,f){var p=At();try{return at(t)(e,n,r,a,i,o,u,c,s,l,f)}catch(t){if(St(p),t!==t+0)throw t;Ot(1,0)}},X:function(t,e,n,r,a,i,o,u){var c=At();try{return Ft(t,e,n,r,a,i,o,u)}catch(t){if(St(c),t!==t+0)throw t;Ot(1,0)}},V:function(t,e,n,r,a,i,o){var u=At();try{return xt(t,e,n,r,a,i,o)}catch(t){if(St(u),t!==t+0)throw t;Ot(1,0)}},U:function(t,e,n,r,a){var i=At();try{return It(t,e,n,r,a)}catch(t){if(St(i),t!==t+0)throw t;Ot(1,0)}},Z:function(t,e,n,r){var a=At();try{return Pt(t,e,n,r)}catch(t){if(St(a),t!==t+0)throw t;Ot(1,0)}},W:function(t){var e=At();try{return Ct(t)}catch(t){if(St(e),t!==t+0)throw t;Ot(1,0)}},Y:function(t,e){var n=At();try{return Ut(t,e)}catch(t){if(St(n),t!==t+0)throw t;Ot(1,0)}},T:function(t,e,n){var r=At();try{return Rt(t,e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},f:function(t){var e=At();try{at(t)()}catch(t){if(St(e),t!==t+0)throw t;Ot(1,0)}},q:function(t,e){var n=At();try{at(t)(e)}catch(t){if(St(n),t!==t+0)throw t;Ot(1,0)}},h:function(t,e,n){var r=At();try{at(t)(e,n)}catch(t){if(St(r),t!==t+0)throw t;Ot(1,0)}},da:function(t,e,n,r){var a=At();try{at(t)(e,n,r)}catch(t){if(St(a),t!==t+0)throw t;Ot(1,0)}},l:function(t,e,n,r){var a=At();try{at(t)(e,n,r)}catch(t){if(St(a),t!==t+0)throw t;Ot(1,0)}},t:function(t,e,n,r,a){var i=At();try{at(t)(e,n,r,a)}catch(t){if(St(i),t!==t+0)throw t;Ot(1,0)}},u:function(t,e,n,r,a,i){var o=At();try{at(t)(e,n,r,a,i)}catch(t){if(St(o),t!==t+0)throw t;Ot(1,0)}},x:function(t,e,n,r,a,i,o){var u=At();try{at(t)(e,n,r,a,i,o)}catch(t){if(St(u),t!==t+0)throw t;Ot(1,0)}},z:function(t,e,n,r,a,i,o,u){var c=At();try{at(t)(e,n,r,a,i,o,u)}catch(t){if(St(c),t!==t+0)throw t;Ot(1,0)}},ga:function(t,e,n,r,a,i,o,u,c){var s=At();try{at(t)(e,n,r,a,i,o,u,c)}catch(t){if(St(s),t!==t+0)throw t;Ot(1,0)}},A:function(t,e,n,r,a,i,o,u,c,s,l){var f=At();try{at(t)(e,n,r,a,i,o,u,c,s,l)}catch(t){if(St(f),t!==t+0)throw t;Ot(1,0)}},C:function(t,e,n,r,a,i,o,u,c,s,l,f,p,h,d,y){var b=At();try{at(t)(e,n,r,a,i,o,u,c,s,l,f,p,h,d,y)}catch(t){if(St(b),t!==t+0)throw t;Ot(1,0)}},aa:function(t,e,n,r,a,i,o,u){var c=At();try{jt(t,e,n,r,a,i,o,u)}catch(t){if(St(c),t!==t+0)throw t;Ot(1,0)}},_:function(t,e,n,r,a,i,o,u,c,s,l,f){var p=At();try{Dt(t,e,n,r,a,i,o,u,c,s,l,f)}catch(t){if(St(p),t!==t+0)throw t;Ot(1,0)}},$:function(t,e,n,r,a,i){var o=At();try{kt(t,e,n,r,a,i)}catch(t){if(St(o),t!==t+0)throw t;Ot(1,0)}},n:function(t){return t},F:function(t){ft=t},ha:yt,y:function(t,e,n,r){return yt(t,e,n,r)}};!function(){function t(t){e.asm=t.exports,O=e.asm.Ka,P(),U=e.asm.ib,I.unshift(e.asm.La),B--,e.monitorRunDependencies&&e.monitorRunDependencies(B),0==B&&(null!==G&&(clearInterval(G),G=null),N&&(t=N,N=null,t()))}function n(e){t(e.instance)}function r(t){return function(){if(!g&&(d||y)){if("function"==typeof fetch&&!Y.startsWith("file://"))return fetch(Y,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw"failed to load wasm binary file at \'"+Y+"\'";return t.arrayBuffer()})).catch((function(){return X()}));if(o)return new Promise((function(t,e){o(Y,(function(e){t(new Uint8Array(e))}),e)}))}return Promise.resolve().then((function(){return X()}))}().then((function(t){return WebAssembly.instantiate(t,i)})).then((function(t){return t})).then(t,(function(t){w("failed to asynchronously prepare wasm: "+t),V(t)}))}var i={a:bt};if(B++,e.monitorRunDependencies&&e.monitorRunDependencies(B),e.instantiateWasm)try{return e.instantiateWasm(i,t)}catch(t){return w("Module.instantiateWasm callback failed with error: "+t),!1}(g||"function"!=typeof WebAssembly.instantiateStreaming||$()||Y.startsWith("file://")||b||"function"!=typeof fetch?r(n):fetch(Y,{credentials:"same-origin"}).then((function(t){return WebAssembly.instantiateStreaming(t,i).then(n,(function(t){return w("wasm streaming compile failed: "+t),w("falling back to ArrayBuffer instantiation"),r(n)}))}))).catch(a)}(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.La).apply(null,arguments)},e._OrtInit=function(){return(e._OrtInit=e.asm.Ma).apply(null,arguments)},e._OrtCreateSessionOptions=function(){return(e._OrtCreateSessionOptions=e.asm.Na).apply(null,arguments)},e._OrtAppendExecutionProvider=function(){return(e._OrtAppendExecutionProvider=e.asm.Oa).apply(null,arguments)},e._OrtAddSessionConfigEntry=function(){return(e._OrtAddSessionConfigEntry=e.asm.Pa).apply(null,arguments)},e._OrtReleaseSessionOptions=function(){return(e._OrtReleaseSessionOptions=e.asm.Qa).apply(null,arguments)},e._OrtCreateSession=function(){return(e._OrtCreateSession=e.asm.Ra).apply(null,arguments)},e._OrtReleaseSession=function(){return(e._OrtReleaseSession=e.asm.Sa).apply(null,arguments)},e._OrtGetInputCount=function(){return(e._OrtGetInputCount=e.asm.Ta).apply(null,arguments)},e._OrtGetOutputCount=function(){return(e._OrtGetOutputCount=e.asm.Ua).apply(null,arguments)},e._OrtGetInputName=function(){return(e._OrtGetInputName=e.asm.Va).apply(null,arguments)},e._OrtGetOutputName=function(){return(e._OrtGetOutputName=e.asm.Wa).apply(null,arguments)},e._OrtFree=function(){return(e._OrtFree=e.asm.Xa).apply(null,arguments)},e._OrtCreateTensor=function(){return(e._OrtCreateTensor=e.asm.Ya).apply(null,arguments)},e._OrtGetTensorData=function(){return(e._OrtGetTensorData=e.asm.Za).apply(null,arguments)},e._OrtReleaseTensor=function(){return(e._OrtReleaseTensor=e.asm._a).apply(null,arguments)},e._OrtCreateRunOptions=function(){return(e._OrtCreateRunOptions=e.asm.$a).apply(null,arguments)},e._OrtAddRunConfigEntry=function(){return(e._OrtAddRunConfigEntry=e.asm.ab).apply(null,arguments)},e._OrtReleaseRunOptions=function(){return(e._OrtReleaseRunOptions=e.asm.bb).apply(null,arguments)},e._OrtRun=function(){return(e._OrtRun=e.asm.cb).apply(null,arguments)},e._OrtEndProfiling=function(){return(e._OrtEndProfiling=e.asm.db).apply(null,arguments)};var mt,gt=e._malloc=function(){return(gt=e._malloc=e.asm.eb).apply(null,arguments)},vt=e._free=function(){return(vt=e._free=e.asm.fb).apply(null,arguments)},wt=e._fflush=function(){return(wt=e._fflush=e.asm.gb).apply(null,arguments)},_t=e.___funcs_on_exit=function(){return(_t=e.___funcs_on_exit=e.asm.hb).apply(null,arguments)},Ot=e._setThrew=function(){return(Ot=e._setThrew=e.asm.jb).apply(null,arguments)},At=e.stackSave=function(){return(At=e.stackSave=e.asm.kb).apply(null,arguments)},St=e.stackRestore=function(){return(St=e.stackRestore=e.asm.lb).apply(null,arguments)},Tt=e.stackAlloc=function(){return(Tt=e.stackAlloc=e.asm.mb).apply(null,arguments)},Et=e.___cxa_can_catch=function(){return(Et=e.___cxa_can_catch=e.asm.nb).apply(null,arguments)},Mt=e.___cxa_is_pointer_type=function(){return(Mt=e.___cxa_is_pointer_type=e.asm.ob).apply(null,arguments)},Ct=e.dynCall_j=function(){return(Ct=e.dynCall_j=e.asm.pb).apply(null,arguments)},xt=e.dynCall_iiiiij=function(){return(xt=e.dynCall_iiiiij=e.asm.qb).apply(null,arguments)},Rt=e.dynCall_jii=function(){return(Rt=e.dynCall_jii=e.asm.rb).apply(null,arguments)},jt=e.dynCall_viiiiij=function(){return(jt=e.dynCall_viiiiij=e.asm.sb).apply(null,arguments)},kt=e.dynCall_vjji=function(){return(kt=e.dynCall_vjji=e.asm.tb).apply(null,arguments)},Dt=e.dynCall_viiijjjii=function(){return(Dt=e.dynCall_viiijjjii=e.asm.ub).apply(null,arguments)},Pt=e.dynCall_iij=function(){return(Pt=e.dynCall_iij=e.asm.vb).apply(null,arguments)},Ut=e.dynCall_ji=function(){return(Ut=e.dynCall_ji=e.asm.wb).apply(null,arguments)},Ft=e.dynCall_iiiiiij=function(){return(Ft=e.dynCall_iiiiiij=e.asm.xb).apply(null,arguments)},It=e.dynCall_iiij=function(){return(It=e.dynCall_iiij=e.asm.yb).apply(null,arguments)};function Wt(){function t(){if(!mt&&(mt=!0,e.calledRun=!0,!C)){if(Z(I),r(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),e.postRun)for("function"==typeof e.postRun&&(e.postRun=[e.postRun]);e.postRun.length;){var t=e.postRun.shift();H.unshift(t)}Z(H)}}if(!(0{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.iterateExtraOptions=void 0,e.iterateExtraOptions=(t,n,r,a)=>{if("object"==typeof t&&null!==t){if(r.has(t))throw new Error("Circular reference in options");r.add(t)}Object.entries(t).forEach((([t,i])=>{const o=n?n+t:t;if("object"==typeof i)(0,e.iterateExtraOptions)(i,o+".",r,a);else if("string"==typeof i||"number"==typeof i)a(o,i.toString());else{if("boolean"!=typeof i)throw new Error("Can\'t handle extra config type: "+typeof i);a(o,i?"1":"0")}}))}},586:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.setRunOptions=void 0;const r=n(967),a=n(983),i=n(361);e.setRunOptions=t=>{const e=(0,i.getInstance)();let n=0;const o=[],u=t||{};try{if(void 0===(null==t?void 0:t.logSeverityLevel))u.logSeverityLevel=2;else if("number"!=typeof t.logSeverityLevel||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(void 0===(null==t?void 0:t.logVerbosityLevel))u.logVerbosityLevel=0;else if("number"!=typeof t.logVerbosityLevel||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);void 0===(null==t?void 0:t.terminate)&&(u.terminate=!1);let i=0;if(void 0!==(null==t?void 0:t.tag)&&(i=(0,a.allocWasmString)(t.tag,o)),n=e._OrtCreateRunOptions(u.logSeverityLevel,u.logVerbosityLevel,!!u.terminate,i),0===n)throw new Error("Can\'t create run options");return void 0!==(null==t?void 0:t.extra)&&(0,r.iterateExtraOptions)(t.extra,"",new WeakSet,((t,r)=>{const i=(0,a.allocWasmString)(t,o),u=(0,a.allocWasmString)(r,o);if(0!==e._OrtAddRunConfigEntry(n,i,u))throw new Error(`Can\'t set a run config entry: ${t} - ${r}`)})),[n,o]}catch(t){throw 0!==n&&e._OrtReleaseRunOptions(n),o.forEach(e._free),t}}},919:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.setSessionOptions=void 0;const r=n(967),a=n(983),i=n(361);e.setSessionOptions=t=>{const e=(0,i.getInstance)();let n=0;const o=[],u=t||{};(t=>{t.extra||(t.extra={}),t.extra.session||(t.extra.session={});const e=t.extra.session;e.use_ort_model_bytes_directly||(e.use_ort_model_bytes_directly="1")})(u);try{void 0===(null==t?void 0:t.graphOptimizationLevel)&&(u.graphOptimizationLevel="all");const c=(t=>{switch(t){case"disabled":return 0;case"basic":return 1;case"extended":return 2;case"all":return 99;default:throw new Error(`unsupported graph optimization level: ${t}`)}})(u.graphOptimizationLevel);void 0===(null==t?void 0:t.enableCpuMemArena)&&(u.enableCpuMemArena=!0),void 0===(null==t?void 0:t.enableMemPattern)&&(u.enableMemPattern=!0),void 0===(null==t?void 0:t.executionMode)&&(u.executionMode="sequential");const s=(t=>{switch(t){case"sequential":return 0;case"parallel":return 1;default:throw new Error(`unsupported execution mode: ${t}`)}})(u.executionMode);let l=0;if(void 0!==(null==t?void 0:t.logId)&&(l=(0,a.allocWasmString)(t.logId,o)),void 0===(null==t?void 0:t.logSeverityLevel))u.logSeverityLevel=2;else if("number"!=typeof t.logSeverityLevel||!Number.isInteger(t.logSeverityLevel)||t.logSeverityLevel<0||t.logSeverityLevel>4)throw new Error(`log serverity level is not valid: ${t.logSeverityLevel}`);if(void 0===(null==t?void 0:t.logVerbosityLevel))u.logVerbosityLevel=0;else if("number"!=typeof t.logVerbosityLevel||!Number.isInteger(t.logVerbosityLevel))throw new Error(`log verbosity level is not valid: ${t.logVerbosityLevel}`);if(void 0===(null==t?void 0:t.enableProfiling)&&(u.enableProfiling=!1),n=e._OrtCreateSessionOptions(c,!!u.enableCpuMemArena,!!u.enableMemPattern,s,!!u.enableProfiling,0,l,u.logSeverityLevel,u.logVerbosityLevel),0===n)throw new Error("Can\'t create session options");return(null==t?void 0:t.executionProviders)&&((t,e,n)=>{for(const r of e){let e="string"==typeof r?r:r.name;switch(e){case"xnnpack":e="XNNPACK";break;case"wasm":case"cpu":continue;default:throw new Error(`not supported EP: ${e}`)}const o=(0,a.allocWasmString)(e,n);if(0!==(0,i.getInstance)()._OrtAppendExecutionProvider(t,o))throw new Error(`Can\'t append execution provider: ${e}`)}})(n,t.executionProviders,o),void 0!==(null==t?void 0:t.extra)&&(0,r.iterateExtraOptions)(t.extra,"",new WeakSet,((t,r)=>{const i=(0,a.allocWasmString)(t,o),u=(0,a.allocWasmString)(r,o);if(0!==e._OrtAddSessionConfigEntry(n,i,u))throw new Error(`Can\'t set a session config entry: ${t} - ${r}`)})),[n,o]}catch(t){throw 0!==n&&e._OrtReleaseSessionOptions(n),o.forEach(e._free),t}}},983:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.allocWasmString=void 0;const r=n(361);e.allocWasmString=(t,e)=>{const n=(0,r.getInstance)(),a=n.lengthBytesUTF8(t)+1,i=n._malloc(a);return n.stringToUTF8(t,i,a),e.push(i),i}},349:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.extractTransferableBuffers=e.endProfiling=e.run=e.releaseSession=e.createSession=e.createSessionFinalize=e.createSessionAllocate=e.initOrt=void 0;const r=n(586),a=n(919),i=n(983),o=n(361);e.initOrt=(t,e)=>{const n=(0,o.getInstance)()._OrtInit(t,e);if(0!==n)throw new Error(`Can\'t initialize onnxruntime. error code = ${n}`)};const u=new Map;e.createSessionAllocate=t=>{const e=(0,o.getInstance)(),n=e._malloc(t.byteLength);return e.HEAPU8.set(t,n),[n,t.byteLength]},e.createSessionFinalize=(t,e)=>{const n=(0,o.getInstance)();let r=0,i=0,c=[];try{if([i,c]=(0,a.setSessionOptions)(e),r=n._OrtCreateSession(t[0],t[1],i),0===r)throw new Error("Can\'t create a session")}finally{n._free(t[0]),n._OrtReleaseSessionOptions(i),c.forEach(n._free)}const s=n._OrtGetInputCount(r),l=n._OrtGetOutputCount(r),f=[],p=[],h=[],d=[];for(let t=0;t{const r=(0,e.createSessionAllocate)(t);return(0,e.createSessionFinalize)(r,n)},e.releaseSession=t=>{const e=(0,o.getInstance)(),n=u.get(t);if(!n)throw new Error("invalid session id");const r=n[0],a=n[1],i=n[2];a.forEach(e._OrtFree),i.forEach(e._OrtFree),e._OrtReleaseSession(r),u.delete(t)};const c=t=>{switch(t){case"int8":return 3;case"uint8":return 2;case"bool":return 9;case"int16":return 5;case"uint16":return 4;case"int32":return 6;case"uint32":return 12;case"float32":return 1;case"float64":return 11;case"string":return 8;case"int64":return 7;case"uint64":return 13;default:throw new Error(`unsupported data type: ${t}`)}},s=t=>{switch(t){case 3:return"int8";case 2:return"uint8";case 9:return"bool";case 5:return"int16";case 4:return"uint16";case 6:return"int32";case 12:return"uint32";case 1:return"float32";case 11:return"float64";case 8:return"string";case 7:return"int64";case 13:return"uint64";default:throw new Error(`unsupported data type: ${t}`)}},l=t=>{switch(t){case"float32":return Float32Array;case"uint8":case"bool":return Uint8Array;case"int8":return Int8Array;case"uint16":return Uint16Array;case"int16":return Int16Array;case"int32":return Int32Array;case"float64":return Float64Array;case"uint32":return Uint32Array;case"int64":return BigInt64Array;case"uint64":return BigUint64Array;default:throw new Error(`unsupported type: ${t}`)}};e.run=(t,e,n,a,f)=>{const p=(0,o.getInstance)(),h=u.get(t);if(!h)throw new Error("invalid session id");const d=h[0],y=h[1],b=h[2],m=e.length,g=a.length;let v=0,w=[];const _=[],O=[];try{[v,w]=(0,r.setRunOptions)(f);for(let t=0;tp.HEAP32[t++]=e));const n=p._OrtCreateTensor(c(e),o,u,l,r.length);if(0===n)throw new Error("Can\'t create a tensor");_.push(n)}finally{p.stackRestore(s)}}const t=p.stackSave(),o=p.stackAlloc(4*m),u=p.stackAlloc(4*m),h=p.stackAlloc(4*g),A=p.stackAlloc(4*g);try{let n=o/4,r=u/4,i=h/4,c=A/4;for(let t=0;tt*e));if(a=s(o),"string"===a){const t=[];let e=i/4;for(let n=0;n{const e=(0,o.getInstance)(),n=u.get(t);if(!n)throw new Error("invalid session id");const r=n[0],a=e._OrtEndProfiling(r);if(0===a)throw new Error("Can\'t get an profile file name");e._OrtFree(a)},e.extractTransferableBuffers=t=>{const e=[];for(const n of t){const t=n[2];!Array.isArray(t)&&t.buffer&&e.push(t.buffer)}return e}},361:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var a=Object.getOwnPropertyDescriptor(e,n);a&&!("get"in a?!e.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,a)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),a=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),i=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return a(e,t),e},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.dispose=e.getInstance=e.initializeWebAssembly=void 0;const u=i(n(449)),c=o(n(932)),s=n(474);let l,f=!1,p=!1,h=!1;const d=(t,e)=>e?t?"ort-wasm-simd-threaded.wasm":"ort-wasm-threaded.wasm":t?"ort-wasm-simd.wasm":"ort-wasm.wasm";e.initializeWebAssembly=async t=>{if(f)return Promise.resolve();if(p)throw new Error("multiple calls to \'initializeWebAssembly()\' detected.");if(h)throw new Error("previous call to \'initializeWebAssembly()\' failed.");p=!0;const e=t.initTimeout,r=t.numThreads,a=t.simd,i=r>1&&(()=>{try{return"undefined"!=typeof SharedArrayBuffer&&("undefined"!=typeof MessageChannel&&(new MessageChannel).port1.postMessage(new SharedArrayBuffer(1)),WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,5,4,1,3,1,1,10,11,1,9,0,65,0,254,16,2,0,26,11])))}catch(t){return!1}})(),o=a&&(()=>{try{return WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,2,1,0,10,30,1,28,0,65,0,253,15,253,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,253,186,1,26,11]))}catch(t){return!1}})(),y="string"==typeof t.wasmPaths?t.wasmPaths:void 0,b=d(!1,i),m=d(o,i),g="object"==typeof t.wasmPaths?t.wasmPaths[m]:void 0;let v=!1;const w=[];if(e>0&&w.push(new Promise((t=>{setTimeout((()=>{v=!0,t()}),e)}))),w.push(new Promise(((t,e)=>{const r=i?s:c.default,a={locateFile:(t,e)=>i&&t.endsWith(".worker.js")&&"undefined"!=typeof Blob?URL.createObjectURL(new Blob([n(154)],{type:"text/javascript"})):t===b?null!=g?g:(null!=y?y:e)+m:e+t};if(i)if("undefined"==typeof Blob)a.mainScriptUrlOrBlob=u.join("/","ort-wasm-threaded.js");else{const t=`var ortWasmThreaded=(function(){var _scriptDir;return ${r.toString()}})();`;a.mainScriptUrlOrBlob=new Blob([t],{type:"text/javascript"})}r(a).then((e=>{p=!1,f=!0,l=e,t()}),(t=>{p=!1,h=!0,e(t)}))}))),await Promise.race(w),v)throw new Error(`WebAssembly backend initializing failed due to timeout: ${e}ms`)},e.getInstance=()=>{if(f&&l)return l;throw new Error("WebAssembly is not initialized yet.")},e.dispose=()=>{var t;!f||p||h||(p=!0,null===(t=l.PThread)||void 0===t||t.terminateAllThreads(),l=void 0,p=!1,f=!1,h=!0)}},154:t=>{"use strict";t.exports=\'"use strict";var e={},t="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node;if(t){var r=require("worker_threads"),a=r.parentPort;a.on("message",(e=>onmessage({data:e})));var o=require("fs");Object.assign(global,{self:global,require:require,Module:e,location:{href:__filename},Worker:r.Worker,importScripts:function(e){(0,eval)(o.readFileSync(e,"utf8"))},postMessage:function(e){a.postMessage(e)},performance:global.performance||{now:function(){return Date.now()}}})}var s=!1,n=[],i=function(){var e=Array.prototype.slice.call(arguments).join(" ");t?o.writeSync(2,e+"\\\\n"):console.error(e)};self.alert=function(){var t=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:t,threadId:e._pthread_self()})},e.instantiateWasm=(t,r)=>{var a=new WebAssembly.Instance(e.wasmModule,t);return r(a),e.wasmModule=null,a.exports},self.onunhandledrejection=e=>{throw e.reason??e},self.onmessage=t=>{try{if("load"===t.data.cmd){if(e.wasmModule=t.data.wasmModule,e.wasmMemory=t.data.wasmMemory,e.buffer=e.wasmMemory.buffer,e.ENVIRONMENT_IS_PTHREAD=!0,"string"==typeof t.data.urlOrBlob)importScripts(t.data.urlOrBlob);else{var r=URL.createObjectURL(t.data.urlOrBlob);importScripts(r),URL.revokeObjectURL(r)}ortWasmThreaded(e).then((function(t){e=t}))}else if("run"===t.data.cmd){e.__performance_now_clock_drift=performance.now()-t.data.time,e.__emscripten_thread_init(t.data.pthread_ptr,0,0,1),e.establishStackSpace(),e.PThread.receiveObjectTransfer(t.data),e.PThread.threadInitTLS(),s||(n.forEach((t=>{e.executeNotifiedProxyingQueue(t)})),n=[],s=!0);try{e.invokeEntryPoint(t.data.start_routine,t.data.arg)}catch(t){if("unwind"!=t){if(!(t instanceof e.ExitStatus))throw t;e.keepRuntimeAlive()||e.__emscripten_thread_exit(t.status)}}}else"cancel"===t.data.cmd?e._pthread_self()&&e.__emscripten_thread_exit(-1):"setimmediate"===t.data.target||("processProxyingQueue"===t.data.cmd?s?e.executeNotifiedProxyingQueue(t.data.queue):n.push(t.data.queue):(i("worker.js received unknown command "+t.data.cmd),i(t.data)))}catch(t){throw i("worker.js onmessage() captured an uncaught exception: "+t),t&&t.stack&&i(t.stack),e.__emscripten_thread_crashed&&e.__emscripten_thread_crashed(),t}};\\n\'},384:()=>{},993:()=>{},908:()=>{},953:()=>{},925:()=>{},449:()=>{}},e={};function n(r){var a=e[r];if(void 0!==a)return a.exports;var i=e[r]={exports:{}};return t[r].call(i.exports,i,i.exports,n),i.exports}n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),(()=>{"use strict";const t=n(349),e=n(361);self.onmessage=n=>{switch(n.data.type){case"init-wasm":(0,e.initializeWebAssembly)(n.data.in).then((()=>postMessage({type:"init-wasm"})),(t=>postMessage({type:"init-wasm",err:t})));break;case"init-ort":try{const{numThreads:e,loggingLevel:r}=n.data.in;(0,t.initOrt)(e,r),postMessage({type:"init-ort"})}catch(t){postMessage({type:"init-ort",err:t})}break;case"create_allocate":try{const{model:e}=n.data.in,r=(0,t.createSessionAllocate)(e);postMessage({type:"create_allocate",out:r})}catch(t){postMessage({type:"create_allocate",err:t})}break;case"create_finalize":try{const{modeldata:e,options:r}=n.data.in,a=(0,t.createSessionFinalize)(e,r);postMessage({type:"create_finalize",out:a})}catch(t){postMessage({type:"create_finalize",err:t})}break;case"create":try{const{model:e,options:r}=n.data.in,a=(0,t.createSession)(e,r);postMessage({type:"create",out:a})}catch(t){postMessage({type:"create",err:t})}break;case"release":try{const e=n.data.in;(0,t.releaseSession)(e),postMessage({type:"release"})}catch(t){postMessage({type:"release",err:t})}break;case"run":try{const{sessionId:e,inputIndices:r,inputs:a,outputIndices:i,options:o}=n.data.in,u=(0,t.run)(e,r,a,i,o);postMessage({type:"run",out:u},(0,t.extractTransferableBuffers)(u))}catch(t){postMessage({type:"run",err:t})}break;case"end-profiling":try{const e=n.data.in;(0,t.endProfiling)(e),postMessage({type:"end-profiling"})}catch(t){postMessage({type:"end-profiling",err:t})}}}})()})();\n',"Worker",void 0,void 0)}},477:s=>{s.exports=function(e,t,r,o){var c=self||window;try{try{var l;try{l=new c.Blob([e])}catch{(l=new(c.BlobBuilder||c.WebKitBlobBuilder||c.MozBlobBuilder||c.MSBlobBuilder)).append(e),l=l.getBlob()}var h=c.URL||c.webkitURL,p=h.createObjectURL(l),f=new c[t](p,r);return h.revokeObjectURL(p),f}catch{return new c[t]("data:application/javascript,".concat(encodeURIComponent(e)),r)}}catch{if(!o)throw Error("Inline worker is not supported");return new c[t](o,r)}}},4154:s=>{s.exports=`"use strict";var e={},t="object"==typeof process&&"object"==typeof process.versions&&"string"==typeof process.versions.node;if(t){var r=require("worker_threads"),a=r.parentPort;a.on("message",(e=>onmessage({data:e})));var o=require("fs");Object.assign(global,{self:global,require:require,Module:e,location:{href:__filename},Worker:r.Worker,importScripts:function(e){(0,eval)(o.readFileSync(e,"utf8"))},postMessage:function(e){a.postMessage(e)},performance:global.performance||{now:function(){return Date.now()}}})}var s=!1,n=[],i=function(){var e=Array.prototype.slice.call(arguments).join(" ");t?o.writeSync(2,e+"\\n"):console.error(e)};self.alert=function(){var t=Array.prototype.slice.call(arguments).join(" ");postMessage({cmd:"alert",text:t,threadId:e._pthread_self()})},e.instantiateWasm=(t,r)=>{var a=new WebAssembly.Instance(e.wasmModule,t);return r(a),e.wasmModule=null,a.exports},self.onunhandledrejection=e=>{throw e.reason??e},self.onmessage=t=>{try{if("load"===t.data.cmd){if(e.wasmModule=t.data.wasmModule,e.wasmMemory=t.data.wasmMemory,e.buffer=e.wasmMemory.buffer,e.ENVIRONMENT_IS_PTHREAD=!0,"string"==typeof t.data.urlOrBlob)importScripts(t.data.urlOrBlob);else{var r=URL.createObjectURL(t.data.urlOrBlob);importScripts(r),URL.revokeObjectURL(r)}ortWasmThreaded(e).then((function(t){e=t}))}else if("run"===t.data.cmd){e.__performance_now_clock_drift=performance.now()-t.data.time,e.__emscripten_thread_init(t.data.pthread_ptr,0,0,1),e.establishStackSpace(),e.PThread.receiveObjectTransfer(t.data),e.PThread.threadInitTLS(),s||(n.forEach((t=>{e.executeNotifiedProxyingQueue(t)})),n=[],s=!0);try{e.invokeEntryPoint(t.data.start_routine,t.data.arg)}catch(t){if("unwind"!=t){if(!(t instanceof e.ExitStatus))throw t;e.keepRuntimeAlive()||e.__emscripten_thread_exit(t.status)}}}else"cancel"===t.data.cmd?e._pthread_self()&&e.__emscripten_thread_exit(-1):"setimmediate"===t.data.target||("processProxyingQueue"===t.data.cmd?s?e.executeNotifiedProxyingQueue(t.data.queue):n.push(t.data.queue):(i("worker.js received unknown command "+t.data.cmd),i(t.data)))}catch(t){throw i("worker.js onmessage() captured an uncaught exception: "+t),t&&t.stack&&i(t.stack),e.__emscripten_thread_crashed&&e.__emscripten_thread_crashed(),t}}; `},1670:s=>{s.exports=__WEBPACK_EXTERNAL_MODULE__1670__},7067:()=>{},1296:()=>{},1384:()=>{},3993:()=>{},908:()=>{},6953:()=>{},9925:()=>{},2806:()=>{},6449:()=>{},2850:()=>{},5381:()=>{},5686:(s,e,t)=>{t.r(e),t.d(e,{flatbuffers:()=>r});var r={};r.Offset,r.Table,r.SIZEOF_SHORT=2,r.SIZEOF_INT=4,r.FILE_IDENTIFIER_LENGTH=4,r.SIZE_PREFIX_LENGTH=4,r.Encoding={UTF8_BYTES:1,UTF16_STRING:2},r.int32=new Int32Array(2),r.float32=new Float32Array(r.int32.buffer),r.float64=new Float64Array(r.int32.buffer),r.isLittleEndian=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1,r.Long=function(o,c){this.low=0|o,this.high=0|c},r.Long.create=function(o,c){return o==0&&c==0?r.Long.ZERO:new r.Long(o,c)},r.Long.prototype.toFloat64=function(){return(this.low>>>0)+4294967296*this.high},r.Long.prototype.equals=function(o){return this.low==o.low&&this.high==o.high},r.Long.ZERO=new r.Long(0,0),r.Builder=function(o){if(o)c=o;else var c=1024;this.bb=r.ByteBuffer.allocate(c),this.space=c,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},r.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},r.Builder.prototype.forceDefaults=function(o){this.force_defaults=o},r.Builder.prototype.dataBuffer=function(){return this.bb},r.Builder.prototype.asUint8Array=function(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())},r.Builder.prototype.prep=function(o,c){o>this.minalign&&(this.minalign=o);for(var l=1+~(this.bb.capacity()-this.space+c)&o-1;this.space=0&&this.vtable[c]==0;c--);for(var l=c+1;c>=0;c--)this.addInt16(this.vtable[c]!=0?o-this.vtable[c]:0);this.addInt16(o-this.object_start);var h=(l+2)*r.SIZEOF_SHORT;this.addInt16(h);var p=0,f=this.space;e:for(c=0;c=0;f--)this.writeInt8(p.charCodeAt(f))}this.prep(this.minalign,r.SIZEOF_INT+h),this.addOffset(o),h&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)},r.Builder.prototype.finishSizePrefixed=function(o,c){this.finish(o,c,!0)},r.Builder.prototype.requiredField=function(o,c){var l=this.bb.capacity()-o,h=l-this.bb.readInt32(l);if(this.bb.readInt16(h+c)==0)throw new Error("FlatBuffers: field "+c+" must be set")},r.Builder.prototype.startVector=function(o,c,l){this.notNested(),this.vector_num_elems=c,this.prep(r.SIZEOF_INT,o*c),this.prep(l,o*c)},r.Builder.prototype.endVector=function(){return this.writeInt32(this.vector_num_elems),this.offset()},r.Builder.prototype.createString=function(o){if(o instanceof Uint8Array)var c=o;else{c=[];for(var l=0;l=56320?p:(p<<10)+o.charCodeAt(l++)+-56613888)<128?c.push(h):(h<2048?c.push(h>>6&31|192):(h<65536?c.push(h>>12&15|224):c.push(h>>18&7|240,h>>12&63|128),c.push(h>>6&63|128)),c.push(63&h|128))}}this.addInt8(0),this.startVector(1,c.length,1),this.bb.setPosition(this.space-=c.length),l=0;for(var f=this.space,d=this.bb.bytes();l>24},r.ByteBuffer.prototype.readUint8=function(o){return this.bytes_[o]},r.ByteBuffer.prototype.readInt16=function(o){return this.readUint16(o)<<16>>16},r.ByteBuffer.prototype.readUint16=function(o){return this.bytes_[o]|this.bytes_[o+1]<<8},r.ByteBuffer.prototype.readInt32=function(o){return this.bytes_[o]|this.bytes_[o+1]<<8|this.bytes_[o+2]<<16|this.bytes_[o+3]<<24},r.ByteBuffer.prototype.readUint32=function(o){return this.readInt32(o)>>>0},r.ByteBuffer.prototype.readInt64=function(o){return new r.Long(this.readInt32(o),this.readInt32(o+4))},r.ByteBuffer.prototype.readUint64=function(o){return new r.Long(this.readUint32(o),this.readUint32(o+4))},r.ByteBuffer.prototype.readFloat32=function(o){return r.int32[0]=this.readInt32(o),r.float32[0]},r.ByteBuffer.prototype.readFloat64=function(o){return r.int32[r.isLittleEndian?0:1]=this.readInt32(o),r.int32[r.isLittleEndian?1:0]=this.readInt32(o+4),r.float64[0]},r.ByteBuffer.prototype.writeInt8=function(o,c){this.bytes_[o]=c},r.ByteBuffer.prototype.writeUint8=function(o,c){this.bytes_[o]=c},r.ByteBuffer.prototype.writeInt16=function(o,c){this.bytes_[o]=c,this.bytes_[o+1]=c>>8},r.ByteBuffer.prototype.writeUint16=function(o,c){this.bytes_[o]=c,this.bytes_[o+1]=c>>8},r.ByteBuffer.prototype.writeInt32=function(o,c){this.bytes_[o]=c,this.bytes_[o+1]=c>>8,this.bytes_[o+2]=c>>16,this.bytes_[o+3]=c>>24},r.ByteBuffer.prototype.writeUint32=function(o,c){this.bytes_[o]=c,this.bytes_[o+1]=c>>8,this.bytes_[o+2]=c>>16,this.bytes_[o+3]=c>>24},r.ByteBuffer.prototype.writeInt64=function(o,c){this.writeInt32(o,c.low),this.writeInt32(o+4,c.high)},r.ByteBuffer.prototype.writeUint64=function(o,c){this.writeUint32(o,c.low),this.writeUint32(o+4,c.high)},r.ByteBuffer.prototype.writeFloat32=function(o,c){r.float32[0]=c,this.writeInt32(o,r.int32[0])},r.ByteBuffer.prototype.writeFloat64=function(o,c){r.float64[0]=c,this.writeInt32(o,r.int32[r.isLittleEndian?0:1]),this.writeInt32(o+4,r.int32[r.isLittleEndian?1:0])},r.ByteBuffer.prototype.getBufferIdentifier=function(){if(this.bytes_.length>10),56320+(1023&f)))}return h},r.ByteBuffer.prototype.__indirect=function(o){return o+this.readInt32(o)},r.ByteBuffer.prototype.__vector=function(o){return o+this.readInt32(o)+r.SIZEOF_INT},r.ByteBuffer.prototype.__vector_len=function(o){return this.readInt32(o+this.readInt32(o))},r.ByteBuffer.prototype.__has_identifier=function(o){if(o.length!=r.FILE_IDENTIFIER_LENGTH)throw new Error("FlatBuffers: file identifier must be length "+r.FILE_IDENTIFIER_LENGTH);for(var c=0;c{var e=s&&s.__esModule?()=>s.default:()=>s;return __webpack_require__.d(e,{a:e}),e},__webpack_require__.d=(s,e)=>{for(var t in e)__webpack_require__.o(e,t)&&!__webpack_require__.o(s,t)&&Object.defineProperty(s,t,{enumerable:!0,get:e[t]})},__webpack_require__.g=function(){if(typeof globalThis=="object")return globalThis;try{return this||new Function("return this")()}catch{if(typeof window=="object")return window}}(),__webpack_require__.o=(s,e)=>Object.prototype.hasOwnProperty.call(s,e),__webpack_require__.r=s=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(s,"__esModule",{value:!0})};var __webpack_exports__=__webpack_require__(6018);return __webpack_exports__})())})(ortWeb_min$1);var ortWeb_minExports=ortWeb_min$1.exports;const ortWeb_min=getDefaultExportFromCjs(ortWeb_minExports),ONNX_WEB=_mergeNamespaces({__proto__:null,default:ortWeb_min},[ortWeb_minExports]);let ONNX;const executionProviders=["wasm"];typeof process<"u"&&process?.release?.name==="node"?(ONNX=sharp??ONNX_NODE,executionProviders.unshift("cpu")):(ONNX=ortWeb_min??ONNX_WEB,typeof navigator<"u"&&/iP(hone|od|ad).+16_4.+AppleWebKit/.test(navigator.userAgent)&&(ONNX.env.wasm.simd=!1));const{env:onnx_env}=ONNX,VERSION="2.14.1",WEB_CACHE_AVAILABLE=typeof self<"u"&&"caches"in self,FS_AVAILABLE=!isEmpty(sharp),PATH_AVAILABLE=!isEmpty(sharp),RUNNING_LOCALLY=FS_AVAILABLE&&PATH_AVAILABLE,__dirname=RUNNING_LOCALLY?sharp.dirname(sharp.dirname(sharp.fileURLToPath(import.meta.url))):"./",DEFAULT_CACHE_DIR=RUNNING_LOCALLY?sharp.join(__dirname,"/.cache/"):null,DEFAULT_LOCAL_MODEL_PATH="/models/",localModelPath=RUNNING_LOCALLY?sharp.join(__dirname,DEFAULT_LOCAL_MODEL_PATH):DEFAULT_LOCAL_MODEL_PATH;onnx_env.wasm.wasmPaths=RUNNING_LOCALLY?sharp.join(__dirname,"/dist/"):`https://cdn.jsdelivr.net/npm/@xenova/transformers@${VERSION}/dist/`;const env$1={backends:{onnx:onnx_env,tfjs:{}},__dirname,version:VERSION,allowRemoteModels:!0,remoteHost:"https://huggingface.co/",remotePathTemplate:"{model}/resolve/{revision}/",allowLocalModels:!0,localModelPath,useFS:FS_AVAILABLE,useBrowserCache:WEB_CACHE_AVAILABLE,useFSCache:FS_AVAILABLE,cacheDir:DEFAULT_CACHE_DIR,useCustomCache:!1,customCache:null};function isEmpty(s){return Object.keys(s).length===0}var define_process_env_default={};globalThis.ReadableStream||(globalThis.ReadableStream=sharp.ReadableStream);class FileResponse{_CONTENT_TYPE_MAP={txt:"text/plain",html:"text/html",css:"text/css",js:"text/javascript",json:"application/json",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif"};constructor(e){if(this.filePath=e,this.headers=new Headers,this.exists=sharp.existsSync(e),this.exists){this.status=200,this.statusText="OK";let t=sharp.statSync(e);this.headers.set("content-length",t.size.toString()),this.updateContentType();let r=this;this.body=new ReadableStream({start(o){r.arrayBuffer().then(c=>{o.enqueue(new Uint8Array(c)),o.close()})}})}else this.status=404,this.statusText="Not Found",this.body=null}updateContentType(){const e=this.filePath.toString().split(".").pop().toLowerCase();this.headers.set("content-type",this._CONTENT_TYPE_MAP[e]??"application/octet-stream")}clone(){let e=new FileResponse(this.filePath);return e.exists=this.exists,e.status=this.status,e.statusText=this.statusText,e.headers=new Headers(this.headers),e}async arrayBuffer(){return(await sharp.promises.readFile(this.filePath)).buffer}async blob(){const e=await sharp.promises.readFile(this.filePath);return new Blob([e],{type:this.headers.get("content-type")})}async text(){return await sharp.promises.readFile(this.filePath,"utf8")}async json(){return JSON.parse(await this.text())}}function isValidHttpUrl(s,e=null){let t;try{t=new URL(s)}catch{return!1}return e&&!e.includes(t.hostname)?!1:t.protocol==="http:"||t.protocol==="https:"}async function getFile(s){if(env$1.useFS&&!isValidHttpUrl(s))return new FileResponse(s);if(typeof process<"u"&&process?.release?.name==="node"){const e=!!define_process_env_default?.TESTING_REMOTELY,t=env$1.version,r=new Headers;if(r.set("User-Agent",`transformers.js/${t}; is_ci/${e};`),isValidHttpUrl(s,["huggingface.co","hf.co"])){const c=define_process_env_default?.HF_TOKEN??define_process_env_default?.HF_ACCESS_TOKEN;c&&r.set("Authorization",`Bearer ${c}`)}return fetch(s,{headers:r})}else return fetch(s)}const ERROR_MAPPING={400:"Bad request error occurred while trying to load file",401:"Unauthorized access to file",403:"Forbidden access to file",404:"Could not locate file",408:"Request timeout error occurred while trying to load file",500:"Internal server error error occurred while trying to load file",502:"Bad gateway error occurred while trying to load file",503:"Service unavailable error occurred while trying to load file",504:"Gateway timeout error occurred while trying to load file"};function handleError(s,e,t){if(!t)return null;const r=ERROR_MAPPING[s]??`Error (${s}) occurred while trying to load file`;throw Error(`${r}: "${e}".`)}class FileCache{constructor(e){this.path=e}async match(e){let t=sharp.join(this.path,e),r=new FileResponse(t);if(r.exists)return r}async put(e,t){const r=Buffer.from(await t.arrayBuffer());let o=sharp.join(this.path,e);try{await sharp.promises.mkdir(sharp.dirname(o),{recursive:!0}),await sharp.promises.writeFile(o,r)}catch(c){console.warn("An error occurred while writing the file to cache:",c)}}}async function tryCache(s,...e){for(let t of e)try{let r=await s.match(t);if(r)return r}catch{continue}}async function getModelFile(s,e,t=!0,r={}){if(!env$1.allowLocalModels&&r.local_files_only)throw Error("Invalid configuration detected: local models are disabled (`env.allowLocalModels=false`) but you have requested to only use local models (`local_files_only=true`).");dispatchCallback(r.progress_callback,{status:"initiate",name:s,file:e});let o;if(!o&&env$1.useBrowserCache){if(typeof caches>"u")throw Error("Browser cache is not available in this environment.");try{o=await caches.open("transformers-cache")}catch(_){console.warn("An error occurred while opening the browser cache:",_)}}if(!o&&env$1.useFSCache&&(o=new FileCache(r.cache_dir??env$1.cacheDir)),!o&&env$1.useCustomCache)throw Error("`env.useCustomCache=true`, but `env.customCache` is not defined.");const c=r.revision??"main";let l=pathJoin(s,e),h=pathJoin(env$1.localModelPath,l),p=pathJoin(env$1.remoteHost,env$1.remotePathTemplate.replaceAll("{model}",s).replaceAll("{revision}",encodeURIComponent(c)),e),f=c==="main"?l:pathJoin(s,c,e),d,i=o instanceof FileCache?f:p,n=!1,a;o&&(a=await tryCache(o,h,i));const u=a!==void 0;if(a===void 0){if(env$1.allowLocalModels)if(isValidHttpUrl(l)){if(r.local_files_only)throw new Error(`\`local_files_only=true\`, but attempted to load a remote file from: ${l}.`)}else try{a=await getFile(h),d=h}catch(b){console.warn(`Unable to load from local path "${h}": "${b}"`)}if(a===void 0||a.status===404){if(r.local_files_only||!env$1.allowRemoteModels){if(t)throw Error(`\`local_files_only=true\` or \`env.allowRemoteModels=false\` and file was not found locally at "${h}".`);return null}if(a=await getFile(p),a.status!==200)return handleError(a.status,p,t);d=i}n=o&&typeof Response<"u"&&a instanceof Response&&a.status===200}dispatchCallback(r.progress_callback,{status:"download",name:s,file:e});const m={status:"progress",name:s,file:e};let g;return r.progress_callback?u&&typeof navigator<"u"&&/firefox/i.test(navigator.userAgent)?(g=new Uint8Array(await a.arrayBuffer()),dispatchCallback(r.progress_callback,{...m,progress:100,loaded:g.length,total:g.length})):g=await readResponse(a,_=>{dispatchCallback(r.progress_callback,{...m,..._})}):g=new Uint8Array(await a.arrayBuffer()),n&&d&&await o.match(d)===void 0&&await o.put(d,new Response(g,{headers:a.headers})).catch(_=>{console.warn(`Unable to add response to browser cache: ${_}.`)}),dispatchCallback(r.progress_callback,{status:"done",name:s,file:e}),g}async function getModelJSON(s,e,t=!0,r={}){let o=await getModelFile(s,e,t,r);if(o===null)return{};let l=new TextDecoder("utf-8").decode(o);return JSON.parse(l)}async function readResponse(s,e){const t=s.headers.get("Content-Length");t===null&&console.warn("Unable to determine content-length from response headers. Will expand buffer when needed.");let r=parseInt(t??"0"),o=new Uint8Array(r),c=0;const l=s.body.getReader();async function h(){const{done:p,value:f}=await l.read();if(p)return;let d=c+f.length;if(d>r){r=d;let n=new Uint8Array(r);n.set(o),o=n}o.set(f,c),c=d;const i=c/r*100;return e({progress:i,loaded:c,total:r}),h()}return await h(),o}function pathJoin(...s){return s=s.map((e,t)=>(t&&(e=e.replace(new RegExp("^/"),"")),t!==s.length-1&&(e=e.replace(new RegExp("/$"),"")),e)),s.join("/")}function interpolate_data(s,[e,t,r],[o,c],l="bilinear",h=!1){const p=c/r,f=o/t,d=new s.constructor(o*c*e),i=t*r,n=o*c;for(let a=0;a=0;--h)o[h]=p,r[h]=e[t[h]],p*=r[h];const c=t.map((h,p)=>o[t.indexOf(p)]),l=new s.constructor(s.length);for(let h=0;h=0;--f)p+=d%e[f]*c[f],d=Math.floor(d/e[f]);l[p]=s[h]}return[l,r]}function softmax(s){const e=max(s)[0],t=s.map(c=>Math.exp(c-e)),r=t.reduce((c,l)=>c+l,0);return t.map(c=>c/r)}function log_softmax(s){return softmax(s).map(r=>Math.log(r))}function getTopItems(s,e=0){return s=Array.from(s).map((t,r)=>[r,t]).sort((t,r)=>r[1]-t[1]),e!==null&&e>0&&(s=s.slice(0,e)),s}function min(s){if(s.length===0)throw Error("Array must not be empty");let e=s[0],t=0;for(let r=1;re&&(e=s[r],t=r);return[Number(e),t]}function isPowerOfTwo(s){return s>0&&(s&s-1)===0}class P2FFT{constructor(e){if(this.size=e|0,this.size<=1||!isPowerOfTwo(this.size))throw new Error("FFT size must be a power of two larger than 1");this._csize=e<<1,this.table=new Float64Array(this.size*2);for(let r=0;rr;r<<=1)++t;this._width=t%2===0?t-1:t,this._bitrev=new Int32Array(1<>>o&3)<>>1);for(let o=0;o>>1]=e[o];return r}toComplexArray(e,t){const r=t||this.createComplexArray();for(let o=0;o>>1],r[o+1]=0;return r}completeSpectrum(e){const t=this._csize,r=t>>>1;for(let o=2;o>=2;l>=2;l>>=2){h=o/l<<1;const i=h>>>2;for(p=0;p>>1,l>>>1)}else for(p=0,f=0;p>>1,l>>>1,r)}for(l>>=2;l>=2;l>>=2){h=o/l<<1;const i=h>>>2;for(p=0;p>1;++d){const i=(d+1-e)**2/2,n=Math.sqrt(p**2+f**2)**i,a=i*Math.atan2(f,p),u=2*d;c[u]=n*Math.cos(a),c[u+1]=n*Math.sin(a),l[u]=c[u],l[u+1]=-c[u+1]}this._slicedChirpBuffer=c.subarray(t,r),this._f=new P2FFT(o>>1),this._f.transform(this._chirpBuffer,l)}_transform(e,t,r){const o=this._buffer1,c=this._buffer2,l=this._outBuffer1,h=this._outBuffer2,p=this._chirpBuffer,f=this._slicedChirpBuffer,d=this._a;if(r)for(let i=0;i>1,u=t[a];o[i]=u*f[i],o[n]=u*f[n]}else for(let i=0;i=s.length&&(p=2*(s.length-1)-p),r[l++]=s[p]}r.sort(),t[c]=r[o]}return t}function round(s,e){const t=Math.pow(10,e);return Math.round(s*t)/t}const DataTypeMap=Object.freeze({float32:Float32Array,float64:Float64Array,string:Array,int8:Int8Array,uint8:Uint8Array,int16:Int16Array,uint16:Uint16Array,int32:Int32Array,uint32:Uint32Array,int64:BigInt64Array,uint64:BigUint64Array,bool:Uint8Array}),ONNXTensor$1=ONNX.Tensor;class Tensor{dims;type;data;size;constructor(...e){return e[0]instanceof ONNXTensor$1?Object.assign(this,e[0]):Object.assign(this,new ONNXTensor$1(e[0],e[1],e[2])),new Proxy(this,{get:(t,r)=>{if(typeof r=="string"){let o=Number(r);if(Number.isInteger(o))return t._getitem(o)}return t[r]},set:(t,r,o)=>t[r]=o})}*[Symbol.iterator](){const[e,...t]=this.dims;if(t.length>0){const r=t.reduce((o,c)=>o*c);for(let o=0;o0){const o=r.reduce((c,l)=>c*l);return this._subarray(e,o,r)}else return new Tensor(this.type,[this.data[e]],r)}indexOf(e){for(let t=0;tf[1])throw new Error(`Invalid slice: ${f}`);let d=[Math.max(f[0],0),Math.min(f[1],this.dims[p])];r.push(d),t.push(d[1]-d[0])}else throw new Error(`Invalid slice: ${f}`)}let o=r.map(([p,f])=>f-p),c=o.reduce((p,f)=>p*f),l=new this.data.constructor(c);const h=this.stride();for(let p=0;p=0;--d){const n=o[d];f+=(i%n+r[d][0])*h[d],i=Math.floor(i/n)}l[p]=this.data[f]}return new Tensor(this.type,l,t)}transpose(...e){return transpose(this,e)}sum(e=null,t=!1){return this.norm(1,e,t)}norm(e="fro",t=null,r=!1){if(e==="fro")e=2;else if(typeof e=="string")throw Error(`Unsupported norm: ${e}`);if(t===null){let l=this.data.reduce((h,p)=>h+p**e,0)**(1/e);return new Tensor(this.type,[l],[])}t=safeIndex(t,this.dims.length);const o=this.dims.slice();o[t]=1;const c=new this.data.constructor(this.data.length/this.dims[t]);for(let l=0;l=0;--p){const i=this.dims[p];if(p!==t){const n=f%i;h+=n*d,d*=o[p]}f=Math.floor(f/i)}c[h]+=this.data[l]**e}if(e!==1)for(let l=0;l=0;--l){const f=this.dims[l];if(l!==t){const d=h%f;c+=d*p,p*=this.dims[l]}h=Math.floor(h/f)}this.data[o]/=r.data[c]}return this}normalize(e=2,t=1){return this.clone().normalize_(e,t)}stride(){return dimsToStride(this.dims)}squeeze(e=null){return new Tensor(this.type,this.data,calc_squeeze_dims(this.dims,e))}squeeze_(e=null){return this.dims=calc_squeeze_dims(this.dims,e),this}unsqueeze(e=null){return new Tensor(this.type,this.data,calc_unsqueeze_dims(this.dims,e))}unsqueeze_(e=null){return this.dims=calc_unsqueeze_dims(this.dims,e),this}flatten_(e=0,t=-1){t=(t+this.dims.length)%this.dims.length;let r=this.dims.slice(0,e),o=this.dims.slice(e,t+1),c=this.dims.slice(t+1);return this.dims=[...r,o.reduce((l,h)=>l*h,1),...c],this}flatten(e=0,t=-1){return this.clone().flatten_(e,t)}view(...e){let t=-1;for(let r=0;rl!==t?o*c:o,1);e[t]=this.data.length/r}return new Tensor(this.type,this.data,e)}neg_(){for(let e=0;ec*l);if(t!==r)throw Error(`cannot reshape array of size ${t} into shape (${e})`);let o=s;for(let c=e.length-1;c>=0;c--)o=o.reduce((l,h)=>{let p=l[l.length-1];return p.lengtht!==1):typeof e=="number"?s[e]===1&&s.splice(e,1):Array.isArray(e)&&(s=s.filter((t,r)=>t!==1||!e.includes(r))),s}function calc_unsqueeze_dims(s,e){return e=safeIndex(e,s.length+1),s=s.slice(),s.splice(e,0,1),s}function safeIndex(s,e,t=null){if(s<-e||s>=e)throw new Error(`IndexError: index ${s} is out of bounds for dimension${t===null?"":" "+t} with size ${e}`);return s<0&&(s=(s%e+e)%e),s}function cat(s,e=0){e=safeIndex(e,s[0].dims.length);const t=s[0].dims.slice();t[e]=s.reduce((l,h)=>l+h.dims[e],0);const r=t.reduce((l,h)=>l*h,1),o=new s[0].data.constructor(r),c=s[0].type;if(e===0){let l=0;for(let h of s)o.set(h.data,l),l+=h.data.length}else{let l=0;for(let h=0;h=0;--i){const u=p.dims[i];let m=n%u;i===e&&(m+=l),d+=m*a,a*=t[i],n=Math.floor(n/u)}o[d]=p.data[f]}l+=p.dims[e]}}return new Tensor(c,o,t)}function stack(s,e=0){return cat(s.map(t=>t.unsqueeze(e)),e)}function std_mean(s,e=null,t=1,r=!1){if(e===null){const f=s.data.reduce((a,u)=>a+u,0)/s.data.length,d=Math.sqrt(s.data.reduce((a,u)=>a+(u-f)**2,0)/(s.data.length-t)),i=new Tensor(s.type,[f],[]);return[new Tensor(s.type,[d],[]),i]}e=safeIndex(e,s.dims.length);const o=mean(s,e,r),c=s.dims.slice();c[e]=1;const l=new s.data.constructor(s.data.length/s.dims[e]);for(let p=0;p=0;--d){const a=s.dims[d];if(d!==e){const u=i%a;f+=u*n,n*=c[d]}i=Math.floor(i/a)}l[f]+=(s.data[p]-o.data[f])**2}for(let p=0;pl+h,0);return new Tensor(s.type,[c/s.data.length],[])}e=safeIndex(e,s.dims.length);const r=s.dims.slice();r[e]=1;const o=new s.data.constructor(s.data.length/s.dims[e]);for(let c=0;c=0;--h){const d=s.dims[h];if(h!==e){const i=p%d;l+=i*f,f*=r[h]}p=Math.floor(p/d)}o[l]+=s.data[c]}if(s.dims[e]!==1)for(let c=0;c0||h>0;)switch(p.push(l-1),f.push(h-1),c[l][h].item()){case 0:--l,--h;break;case 1:--l;break;case 2:--h;break;default:throw new Error(`Internal error in dynamic time warping. Unexpected trace[${l}, ${h}]. Please file a bug report.`)}return p.reverse(),f.reverse(),[p,f]}function dimsToStride(s){const e=new Array(s.length);for(let t=s.length-1,r=1;t>=0;--t)e[t]=r,r*=s[t];return e}function ones(s){const e=s.reduce((t,r)=>t*r,1);return new Tensor("int64",new BigInt64Array(e).fill(1n),s)}function ones_like(s){return ones(s.dims)}class PriorityQueue{constructor(e=(t,r)=>t>r){this._heap=[],this._comparator=e}get size(){return this._heap.length}isEmpty(){return this.size===0}peek(){return this._heap[0]}push(...e){return this.extend(e)}extend(e){for(const t of e)this._heap.push(t),this._siftUp();return this.size}pop(){const e=this.peek(),t=this.size-1;return t>0&&this._swap(0,t),this._heap.pop(),this._siftDown(),e}replace(e){const t=this.peek();return this._heap[0]=e,this._siftDown(),t}_parent(e){return(e+1>>>1)-1}_left(e){return(e<<1)+1}_right(e){return e+1<<1}_greater(e,t){return this._comparator(this._heap[e],this._heap[t])}_swap(e,t){const r=this._heap[e];this._heap[e]=this._heap[t],this._heap[t]=r}_siftUp(){let e=this.size-1;for(;e>0&&this._greater(e,this._parent(e));)this._swap(e,this._parent(e)),e=this._parent(e)}_siftDown(){let e=0;for(;this._left(e)[]),this.endNodes=Array.from({length:this.len+1},()=>[]);const o=new TokenLatticeNode(this.bosTokenId,0,0,0,0),c=new TokenLatticeNode(this.eosTokenId,1,this.len,0,0);this.nodes.push(o.clone()),this.nodes.push(c.clone()),this.beginNodes[this.len].push(c),this.endNodes[0].push(o)}insert(e,t,r,o){const c=this.nodes.length,l=new TokenLatticeNode(o,c,e,t,r);this.beginNodes[e].push(l),this.endNodes[e+t].push(l),this.nodes.push(l)}viterbi(){const e=this.len;let t=0;for(;t<=e;){if(this.beginNodes[t].length==0)return[];for(let h of this.beginNodes[t]){h.prev=null;let p=0,f=null;for(let d of this.endNodes[t]){const i=d.backtraceScore+h.score;(f===null||i>p)&&(f=d.clone(),p=i)}if(f!==null)h.prev=f,h.backtraceScore=p;else return[]}++t}const r=[],c=this.beginNodes[e][0].prev;if(c===null)return[];let l=c.clone();for(;l.prev!==null;)r.push(l.clone()),l=l.clone().prev.clone();return r.reverse(),r}piece(e){return this.sentence.slice(e.pos,e.pos+e.length)}tokens(){return this.viterbi().map(t=>this.piece(t))}tokenIds(){return this.viterbi().map(t=>t.tokenId)}}class TokenLatticeNode{constructor(e,t,r,o,c){this.tokenId=e,this.nodeId=t,this.pos=r,this.length=o,this.score=c,this.prev=null,this.backtraceScore=0}clone(){const e=new TokenLatticeNode(this.tokenId,this.nodeId,this.pos,this.length,this.score);return e.prev=this.prev,e.backtraceScore=this.backtraceScore,e}}var TOKEN_TYPES=Object.freeze({Text:"Text",NumericLiteral:"NumericLiteral",BooleanLiteral:"BooleanLiteral",StringLiteral:"StringLiteral",Identifier:"Identifier",Equals:"Equals",OpenParen:"OpenParen",CloseParen:"CloseParen",OpenStatement:"OpenStatement",CloseStatement:"CloseStatement",OpenExpression:"OpenExpression",CloseExpression:"CloseExpression",OpenSquareBracket:"OpenSquareBracket",CloseSquareBracket:"CloseSquareBracket",Comma:"Comma",Dot:"Dot",Colon:"Colon",Pipe:"Pipe",CallOperator:"CallOperator",AdditiveBinaryOperator:"AdditiveBinaryOperator",MultiplicativeBinaryOperator:"MultiplicativeBinaryOperator",ComparisonBinaryOperator:"ComparisonBinaryOperator",UnaryOperator:"UnaryOperator",Set:"Set",If:"If",For:"For",In:"In",NotIn:"NotIn",Else:"Else",EndIf:"EndIf",ElseIf:"ElseIf",EndFor:"EndFor",And:"And",Or:"Or",Not:"UnaryOperator"}),KEYWORDS=Object.freeze({set:TOKEN_TYPES.Set,for:TOKEN_TYPES.For,in:TOKEN_TYPES.In,if:TOKEN_TYPES.If,else:TOKEN_TYPES.Else,endif:TOKEN_TYPES.EndIf,elif:TOKEN_TYPES.ElseIf,endfor:TOKEN_TYPES.EndFor,and:TOKEN_TYPES.And,or:TOKEN_TYPES.Or,not:TOKEN_TYPES.Not,"not in":TOKEN_TYPES.NotIn,true:TOKEN_TYPES.BooleanLiteral,false:TOKEN_TYPES.BooleanLiteral}),Token=class{constructor(s,e){this.value=s,this.type=e}};function isWord(s){return/\w/.test(s)}function isInteger(s){return/[0-9]/.test(s)}var ORDERED_MAPPING_TABLE=[["{%",TOKEN_TYPES.OpenStatement],["%}",TOKEN_TYPES.CloseStatement],["{{",TOKEN_TYPES.OpenExpression],["}}",TOKEN_TYPES.CloseExpression],["(",TOKEN_TYPES.OpenParen],[")",TOKEN_TYPES.CloseParen],["[",TOKEN_TYPES.OpenSquareBracket],["]",TOKEN_TYPES.CloseSquareBracket],[",",TOKEN_TYPES.Comma],[".",TOKEN_TYPES.Dot],[":",TOKEN_TYPES.Colon],["|",TOKEN_TYPES.Pipe],["<=",TOKEN_TYPES.ComparisonBinaryOperator],[">=",TOKEN_TYPES.ComparisonBinaryOperator],["==",TOKEN_TYPES.ComparisonBinaryOperator],["!=",TOKEN_TYPES.ComparisonBinaryOperator],["<",TOKEN_TYPES.ComparisonBinaryOperator],[">",TOKEN_TYPES.ComparisonBinaryOperator],["+",TOKEN_TYPES.AdditiveBinaryOperator],["-",TOKEN_TYPES.AdditiveBinaryOperator],["*",TOKEN_TYPES.MultiplicativeBinaryOperator],["/",TOKEN_TYPES.MultiplicativeBinaryOperator],["%",TOKEN_TYPES.MultiplicativeBinaryOperator],["=",TOKEN_TYPES.Equals]],ESCAPE_CHARACTERS=new Map([["n",` `],["t"," "],["r","\r"],["b","\b"],["f","\f"],["v","\v"],["'","'"],['"','"'],["\\","\\"]]);function tokenize(s){const e=[],t=s;let r=0;const o=c=>{let l="";for(;c(t[r]);){if(t[r]==="\\"){if(++r,r>=t.length)throw new SyntaxError("Unexpected end of input");const h=t[r++],p=ESCAPE_CHARACTERS.get(h);if(p===void 0)throw new SyntaxError(`Unexpected escaped character: ${h}`);l+=p;continue}if(l+=t[r++],r>=t.length)throw new SyntaxError("Unexpected end of input")}return l};e:for(;r0){e.push(new Token(h,TOKEN_TYPES.Text));continue}}o(h=>/\s/.test(h));const l=t[r];if(l==="-"||l==="+"){const h=e.at(-1)?.type;if(h===TOKEN_TYPES.Text||h===void 0)throw new SyntaxError(`Unexpected character: ${l}`);switch(h){case TOKEN_TYPES.Identifier:case TOKEN_TYPES.NumericLiteral:case TOKEN_TYPES.BooleanLiteral:case TOKEN_TYPES.StringLiteral:case TOKEN_TYPES.CloseParen:case TOKEN_TYPES.CloseSquareBracket:break;default:{++r;const p=o(isInteger);e.push(new Token(`${l}${p}`,p.length>0?TOKEN_TYPES.NumericLiteral:TOKEN_TYPES.UnaryOperator));continue}}}for(const[h,p]of ORDERED_MAPPING_TABLE)if(t.slice(r,r+h.length)===h){e.push(new Token(h,p)),r+=h.length;continue e}if(l==="'"){++r;const h=o(p=>p!=="'");e.push(new Token(h,TOKEN_TYPES.StringLiteral)),++r;continue}if(isInteger(l)){const h=o(isInteger);e.push(new Token(h,TOKEN_TYPES.NumericLiteral));continue}if(isWord(l)){const h=o(isWord),p=Object.hasOwn(KEYWORDS,h)?KEYWORDS[h]:TOKEN_TYPES.Identifier;p===TOKEN_TYPES.In&&e.at(-1)?.type===TOKEN_TYPES.Not?(e.pop(),e.push(new Token("not in",TOKEN_TYPES.NotIn))):e.push(new Token(h,p));continue}throw new SyntaxError(`Unexpected character: ${l}`)}return e}var Statement=class{type="Statement"},Program=class extends Statement{constructor(s){super(),this.body=s}type="Program"},If=class extends Statement{constructor(s,e,t){super(),this.test=s,this.body=e,this.alternate=t}type="If"},For=class extends Statement{constructor(s,e,t){super(),this.loopvar=s,this.iterable=e,this.body=t}type="For"},SetStatement=class extends Statement{constructor(s,e){super(),this.assignee=s,this.value=e}type="Set"},Expression=class extends Statement{type="Expression"},MemberExpression=class extends Expression{constructor(s,e,t){super(),this.object=s,this.property=e,this.computed=t}type="MemberExpression"},CallExpression=class extends Expression{constructor(s,e){super(),this.callee=s,this.args=e}type="CallExpression"},Identifier=class extends Expression{constructor(s){super(),this.value=s}type="Identifier"},Literal=class extends Expression{constructor(s){super(),this.value=s}type="Literal"},NumericLiteral=class extends Literal{type="NumericLiteral"},StringLiteral=class extends Literal{type="StringLiteral";constructor(s){super(s)}},BooleanLiteral=class extends Literal{type="BooleanLiteral"},BinaryExpression=class extends Expression{constructor(s,e,t){super(),this.operator=s,this.left=e,this.right=t}type="BinaryExpression"},FilterExpression=class extends Expression{constructor(s,e){super(),this.operand=s,this.filter=e}type="FilterExpression"},UnaryExpression=class extends Expression{constructor(s,e){super(),this.operator=s,this.argument=e}type="UnaryExpression"},SliceExpression=class extends Expression{constructor(s=void 0,e=void 0,t=void 0){super(),this.start=s,this.stop=e,this.step=t}type="SliceExpression"};function parse(s){const e=new Program([]);let t=0;function r(I,k){const C=s[t++];if(!C||C.type!==I)throw new Error(`Parser Error: ${k}. ${C.type} !== ${I}.`);return C}function o(){switch(s[t].type){case TOKEN_TYPES.Text:return h();case TOKEN_TYPES.OpenStatement:return p();case TOKEN_TYPES.OpenExpression:return f();default:throw new SyntaxError(`Unexpected token type: ${s[t].type}`)}}function c(...I){return t+I.length<=s.length&&I.some((k,C)=>k!==s[t+C].type)}function l(...I){return t+I.length<=s.length&&I.every((k,C)=>k===s[t+C].type)}function h(){return new StringLiteral(r(TOKEN_TYPES.Text,"Expected text token").value)}function p(){r(TOKEN_TYPES.OpenStatement,"Expected opening statement token");let I;switch(s[t].type){case TOKEN_TYPES.Set:++t,I=d(),r(TOKEN_TYPES.CloseStatement,"Expected closing statement token");break;case TOKEN_TYPES.If:++t,I=i(),r(TOKEN_TYPES.OpenStatement,"Expected {% token"),r(TOKEN_TYPES.EndIf,"Expected endif token"),r(TOKEN_TYPES.CloseStatement,"Expected %} token");break;case TOKEN_TYPES.For:++t,I=n(),r(TOKEN_TYPES.OpenStatement,"Expected {% token"),r(TOKEN_TYPES.EndFor,"Expected endfor token"),r(TOKEN_TYPES.CloseStatement,"Expected %} token");break;default:throw new SyntaxError(`Unknown statement type: ${s[t].type}`)}return I}function f(){r(TOKEN_TYPES.OpenExpression,"Expected opening expression token");const I=a();return r(TOKEN_TYPES.CloseExpression,"Expected closing expression token"),I}function d(){const I=a();if(l(TOKEN_TYPES.Equals)){++t;const k=d();return new SetStatement(I,k)}return I}function i(){const I=a();r(TOKEN_TYPES.CloseStatement,"Expected closing statement token");const k=[],C=[];for(;!(s[t]?.type===TOKEN_TYPES.OpenStatement&&(s[t+1]?.type===TOKEN_TYPES.ElseIf||s[t+1]?.type===TOKEN_TYPES.Else||s[t+1]?.type===TOKEN_TYPES.EndIf));)k.push(o());if(s[t]?.type===TOKEN_TYPES.OpenStatement&&s[t+1]?.type!==TOKEN_TYPES.EndIf)if(++t,l(TOKEN_TYPES.ElseIf))r(TOKEN_TYPES.ElseIf,"Expected elseif token"),C.push(i());else for(r(TOKEN_TYPES.Else,"Expected else token"),r(TOKEN_TYPES.CloseStatement,"Expected closing statement token");!(s[t]?.type===TOKEN_TYPES.OpenStatement&&s[t+1]?.type===TOKEN_TYPES.EndIf);)C.push(o());return new If(I,k,C)}function n(){const I=R();if(!(I instanceof Identifier))throw new SyntaxError("Expected identifier for the loop variable");r(TOKEN_TYPES.In,"Expected `in` keyword following loop variable");const k=a();r(TOKEN_TYPES.CloseStatement,"Expected closing statement token");const C=[];for(;c(TOKEN_TYPES.OpenStatement,TOKEN_TYPES.EndFor);)C.push(o());return new For(I,k,C)}function a(){return u()}function u(){let I=m();for(;l(TOKEN_TYPES.Or);){const k=s[t];++t;const C=m();I=new BinaryExpression(k,I,C)}return I}function m(){let I=g();for(;l(TOKEN_TYPES.And);){const k=s[t];++t;const C=g();I=new BinaryExpression(k,I,C)}return I}function g(){let I;for(;l(TOKEN_TYPES.Not);){const k=s[t];++t;const C=g();I=new UnaryExpression(k,C)}return I??_()}function _(){let I=b();for(;l(TOKEN_TYPES.ComparisonBinaryOperator)||l(TOKEN_TYPES.In)||l(TOKEN_TYPES.NotIn);){const k=s[t];++t;const C=b();I=new BinaryExpression(k,I,C)}return I}function b(){let I=T();for(;l(TOKEN_TYPES.AdditiveBinaryOperator);){const k=s[t];++t;const C=T();I=new BinaryExpression(k,I,C)}return I}function y(){const I=M();return l(TOKEN_TYPES.OpenParen)?v(I):I}function v(I){let k=new CallExpression(I,x());return l(TOKEN_TYPES.OpenParen)&&(k=v(k)),k}function x(){r(TOKEN_TYPES.OpenParen,"Expected opening parenthesis for arguments list");const I=l(TOKEN_TYPES.CloseParen)?[]:w();return r(TOKEN_TYPES.CloseParen,"Expected closing parenthesis for arguments list"),I}function w(){const I=[a()];for(;l(TOKEN_TYPES.Comma);)++t,I.push(a());return I}function S(){const I=[];let k=!1;for(;!l(TOKEN_TYPES.CloseSquareBracket);)l(TOKEN_TYPES.Colon)?(I.push(void 0),++t,k=!0):(I.push(a()),l(TOKEN_TYPES.Colon)&&(++t,k=!0));if(I.length===0)throw new SyntaxError("Expected at least one argument for member/slice expression");if(k){if(I.length>3)throw new SyntaxError("Expected 0-3 arguments for slice expression");return new SliceExpression(...I)}return I[0]}function M(){let I=R();for(;l(TOKEN_TYPES.Dot)||l(TOKEN_TYPES.OpenSquareBracket);){const k=s[t];++t;let C;const z=k.type!==TOKEN_TYPES.Dot;if(z)C=S(),r(TOKEN_TYPES.CloseSquareBracket,"Expected closing square bracket");else if(C=R(),C.type!=="Identifier")throw new SyntaxError("Expected identifier following dot operator");I=new MemberExpression(I,C,z)}return I}function T(){let I=E();for(;l(TOKEN_TYPES.MultiplicativeBinaryOperator);){const k=s[t];++t;const C=E();I=new BinaryExpression(k,I,C)}return I}function E(){let I=y();for(;l(TOKEN_TYPES.Pipe);){++t;const k=R();if(!(k instanceof Identifier))throw new SyntaxError("Expected identifier for the filter");I=new FilterExpression(I,k)}return I}function R(){const I=s[t];switch(I.type){case TOKEN_TYPES.NumericLiteral:return++t,new NumericLiteral(Number(I.value));case TOKEN_TYPES.StringLiteral:return++t,new StringLiteral(I.value);case TOKEN_TYPES.BooleanLiteral:return++t,new BooleanLiteral(I.value==="true");case TOKEN_TYPES.Identifier:return++t,new Identifier(I.value);case TOKEN_TYPES.OpenParen:{++t;const k=a();if(s[t].type!==TOKEN_TYPES.CloseParen)throw new SyntaxError("Expected closing parenthesis");return++t,k}default:throw new SyntaxError(`Unexpected token: ${I.type}`)}}for(;t=0?(e=(e??=0)<0?Math.max(s.length+e,0):Math.min(e,s.length),t=(t??=s.length)<0?Math.max(s.length+t,0):Math.min(t,s.length)):(e=(e??=s.length-1)<0?Math.max(s.length+e,-1):Math.min(e,s.length-1),t=(t??=-1)<-1?Math.max(s.length+t,-1):Math.min(t,s.length-1));const c=[];for(let l=e;o*lnew StringValue(this.value.toUpperCase()))],["lower",new FunctionValue(()=>new StringValue(this.value.toLowerCase()))],["strip",new FunctionValue(()=>new StringValue(this.value.trim()))],["length",new NumericValue(this.value.length)]])},BooleanValue=class extends RuntimeValue{type="BooleanValue"},ObjectValue=class extends RuntimeValue{type="ObjectValue";__bool__(){return new BooleanValue(this.value.size>0)}},ArrayValue=class extends RuntimeValue{type="ArrayValue";builtins=new Map([["length",new NumericValue(this.value.length)]]);__bool__(){return new BooleanValue(this.value.length>0)}},FunctionValue=class extends RuntimeValue{type="FunctionValue"},NullValue=class extends RuntimeValue{type="NullValue"},UndefinedValue=class extends RuntimeValue{type="UndefinedValue"},Environment=class{constructor(s){this.parent=s}variables=new Map;set(s,e){return this.declareVariable(s,convertToRuntimeValues(e))}declareVariable(s,e){if(this.variables.has(s))throw new SyntaxError(`Variable already declared: ${s}`);return this.variables.set(s,e),e}setVariable(s,e){let t;try{t=this.resolve(s)}catch{}return(t??this).variables.set(s,e),e}resolve(s){if(this.variables.has(s))return this;if(this.parent)return this.parent.resolve(s);throw new Error(`Unknown variable: ${s}`)}lookupVariable(s){return this.resolve(s).variables.get(s)??new NullValue}},Interpreter=class{global;constructor(s){this.global=s??new Environment}run(s){return this.evaluate(s,this.global)}evaluateBinaryExpression(s,e){const t=this.evaluate(s.left,e),r=this.evaluate(s.right,e);switch(s.operator.value){case"==":return new BooleanValue(t.value==r.value);case"!=":return new BooleanValue(t.value!=r.value);case"and":return t.__bool__().value?r:t;case"or":return t.__bool__().value?t:r}if(t instanceof UndefinedValue||r instanceof UndefinedValue)throw new Error("Cannot perform operation on undefined values");if(t instanceof NullValue||r instanceof NullValue)throw new Error("Cannot perform operation on null values");if(t instanceof NumericValue&&r instanceof NumericValue)switch(s.operator.value){case"+":return new NumericValue(t.value+r.value);case"-":return new NumericValue(t.value-r.value);case"*":return new NumericValue(t.value*r.value);case"/":return new NumericValue(t.value/r.value);case"%":return new NumericValue(t.value%r.value);case"<":return new BooleanValue(t.value":return new BooleanValue(t.value>r.value);case">=":return new BooleanValue(t.value>=r.value);case"<=":return new BooleanValue(t.value<=r.value)}else if(r instanceof ArrayValue){const o=r.value.find(c=>c.value===t.value)!==void 0;switch(s.operator.value){case"in":return new BooleanValue(o);case"not in":return new BooleanValue(!o)}}if(t instanceof StringValue||r instanceof StringValue)switch(s.operator.value){case"+":return new StringValue(t.value.toString()+r.value.toString())}if(t instanceof StringValue&&r instanceof StringValue)switch(s.operator.value){case"in":return new BooleanValue(r.value.includes(t.value));case"not in":return new BooleanValue(!r.value.includes(t.value))}throw new SyntaxError(`Unknown operator "${s.operator.value}" between ${t.type} and ${r.type}`)}evaluateFilterExpression(s,e){const t=this.evaluate(s.operand,e);if(t instanceof ArrayValue)switch(s.filter.value){case"first":return t.value[0];case"last":return t.value[t.value.length-1];case"length":return new NumericValue(t.value.length);case"reverse":return new ArrayValue(t.value.reverse());case"sort":return new ArrayValue(t.value.sort((r,o)=>{if(r.type!==o.type)throw new Error(`Cannot compare different types: ${r.type} and ${o.type}`);switch(r.type){case"NumericValue":return r.value-o.value;case"StringValue":return r.value.localeCompare(o.value);default:throw new Error(`Cannot compare type: ${r.type}`)}}));default:throw new Error(`Unknown filter: ${s.filter.value}`)}throw new Error(`Cannot apply filter to type: ${t.type}`)}evaluateUnaryExpression(s,e){const t=this.evaluate(s.argument,e);switch(s.operator.value){case"not":return new BooleanValue(!t.value);default:throw new SyntaxError(`Unknown operator: ${s.operator.value}`)}}evalProgram(s,e){return this.evaluateBlock(s.body,e)}evaluateBlock(s,e){let t="";for(const r of s){const o=this.evaluate(r,e);o.type!=="NullValue"&&(t+=o.value)}return t=t.replace(/^\n/,""),new StringValue(t)}evaluateIdentifier(s,e){return e.lookupVariable(s.value)}evaluateCallExpression(s,e){const t=s.args.map(o=>this.evaluate(o,e)),r=this.evaluate(s.callee,e);if(r.type!=="FunctionValue")throw new Error(`Cannot call something that is not a function: got ${r.type}`);return r.value(t,e)}evaluateSliceExpression(s,e,t){if(!(s instanceof ArrayValue||s instanceof StringValue))throw new Error("Slice object must be an array or string");const r=this.evaluate(e.start,t),o=this.evaluate(e.stop,t),c=this.evaluate(e.step,t);if(!(r instanceof NumericValue||r instanceof UndefinedValue))throw new Error("Slice start must be numeric or undefined");if(!(o instanceof NumericValue||o instanceof UndefinedValue))throw new Error("Slice stop must be numeric or undefined");if(!(c instanceof NumericValue||c instanceof UndefinedValue))throw new Error("Slice step must be numeric or undefined");return s instanceof ArrayValue?new ArrayValue(slice(s.value,r.value,o.value,c.value)):new StringValue(slice(Array.from(s.value),r.value,o.value,c.value).join(""))}evaluateMemberExpression(s,e){const t=this.evaluate(s.object,e);let r;if(s.computed){if(s.property.type==="SliceExpression")return this.evaluateSliceExpression(t,s.property,e);r=this.evaluate(s.property,e)}else r=new StringValue(s.property.value);let o;if(t instanceof ObjectValue){if(!(r instanceof StringValue))throw new Error(`Cannot access property with non-string: got ${r.type}`);o=t.value.get(r.value)??t.builtins.get(r.value)}else if(t instanceof ArrayValue||t instanceof StringValue)if(r instanceof NumericValue)o=t.value.at(r.value),t instanceof StringValue&&(o=new StringValue(t.value.at(r.value)));else if(r instanceof StringValue)o=t.builtins.get(r.value);else throw new Error(`Cannot access property with non-string/non-number: got ${r.type}`);else{if(!(r instanceof StringValue))throw new Error(`Cannot access property with non-string: got ${r.type}`);o=t.builtins.get(r.value)}if(!(o instanceof RuntimeValue))throw new Error(`${t.type} has no property '${r.value}'`);return o}evaluateSet(s,e){if(s.assignee.type!=="Identifier")throw new Error(`Invalid LHS inside assignment expression: ${JSON.stringify(s.assignee)}`);const t=s.assignee.value;return e.setVariable(t,this.evaluate(s.value,e)),new NullValue}evaluateIf(s,e){const t=this.evaluate(s.test,e);return this.evaluateBlock(t.__bool__().value?s.body:s.alternate,e)}evaluateFor(s,e){const t=new Environment(e),r=this.evaluate(s.iterable,t);if(!(r instanceof ArrayValue))throw new Error(`Expected iterable type in for loop: got ${r.type}`);let o="";for(let c=0;c[h,p])))),t.setVariable(s.loopvar.value,r.value[c]);const l=this.evaluateBlock(s.body,t);o+=l.value}return new StringValue(o)}evaluate(s,e){if(s===void 0)return new UndefinedValue;switch(s.type){case"Program":return this.evalProgram(s,e);case"Set":return this.evaluateSet(s,e);case"If":return this.evaluateIf(s,e);case"For":return this.evaluateFor(s,e);case"NumericLiteral":return new NumericValue(Number(s.value));case"StringLiteral":return new StringValue(s.value);case"BooleanLiteral":return new BooleanValue(s.value);case"Identifier":return this.evaluateIdentifier(s,e);case"CallExpression":return this.evaluateCallExpression(s,e);case"MemberExpression":return this.evaluateMemberExpression(s,e);case"UnaryExpression":return this.evaluateUnaryExpression(s,e);case"BinaryExpression":return this.evaluateBinaryExpression(s,e);case"FilterExpression":return this.evaluateFilterExpression(s,e);default:throw new SyntaxError(`Unknown node type: ${s.type}`)}}};function convertToRuntimeValues(s){switch(typeof s){case"number":return new NumericValue(s);case"string":return new StringValue(s);case"boolean":return new BooleanValue(s);case"object":return s===null?new NullValue:Array.isArray(s)?new ArrayValue(s.map(convertToRuntimeValues)):new ObjectValue(new Map(Object.entries(s).map(([e,t])=>[e,convertToRuntimeValues(t)])));case"function":return new FunctionValue((e,t)=>{const r=s(...e.map(o=>o.value))??null;return convertToRuntimeValues(r)});default:throw new Error(`Cannot convert to runtime value: ${s}`)}}var Template=class{parsed;constructor(s){s=s.replace(/%}\s+{%/g,"%}{%");const e=tokenize(s);this.parsed=parse(e)}render(s){const e=new Environment;e.set("false",!1),e.set("true",!0),e.set("raise_exception",o=>{throw new Error(o)});for(const[o,c]of Object.entries(s))e.set(o,c);return new Interpreter(e).run(this.parsed).value}};async function loadTokenizer(s,e){const t=await Promise.all([getModelJSON(s,"tokenizer.json",!0,e),getModelJSON(s,"tokenizer_config.json",!0,e)]);return e.legacy!==null&&(t[1].legacy=e.legacy),t}function regexSplit(s,e){const t=[];let r=0;for(const o of s.matchAll(e)){const c=o[0];r0&&t.push(c),r=o.index+c.length}return rthis.tokens_to_ids.get(t)??this.unk_token_id)}convert_ids_to_tokens(e){return e.map(t=>this.vocab[t]??this.unk_token)}}class WordPieceTokenizer extends TokenizerModel{constructor(e){super(e),this.tokens_to_ids=objectToMap(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.max_input_chars_per_word=e.max_input_chars_per_word??100,this.vocab=new Array(this.tokens_to_ids.size);for(const[t,r]of this.tokens_to_ids)this.vocab[r]=t}encode(e){const t=[];for(const r of e){const o=[...r];if(o.length>this.max_input_chars_per_word){t.push(this.unk_token);continue}let c=!1,l=0;const h=[];for(;l0&&(d=this.config.continuing_subword_prefix+d),this.tokens_to_ids.has(d)){f=d;break}--p}if(f===null){c=!0;break}h.push(f),l=p}c?t.push(this.unk_token):t.push(...h)}return t}}class Unigram extends TokenizerModel{constructor(e,t){super(e);const r=e.vocab.length;this.vocab=new Array(r),this.scores=new Array(r);for(let o=0;o[o,c])),this.bosToken=" ",this.bosTokenId=this.tokens_to_ids.get(this.bosToken),this.eosToken=t.eos_token,this.eosTokenId=this.tokens_to_ids.get(this.eosToken),this.unkToken=this.vocab[this.unk_token_id],this.minScore=min(this.scores)[0],this.unkScore=this.minScore-10,this.scores[this.unk_token_id]=this.unkScore,this.trie=new CharTrie,this.trie.extend(this.vocab),this.fuse_unk=!0}populateNodes(e){const t=e.sentence,r=t.length;let o=0;for(;o{const s=[...Array.from({length:94},(o,c)=>c+33),...Array.from({length:12},(o,c)=>c+161),...Array.from({length:82},(o,c)=>c+174)],e=s.slice();let t=0;for(let o=0;o<256;++o)s.includes(o)||(s.push(o),e.push(256+t),t+=1);const r=e.map(o=>String.fromCharCode(o));return Object.fromEntries(s.map((o,c)=>[o,r[c]]))})(),UNICODE_TO_BYTES=reverseDictionary(BYTES_TO_UNICODE);class BPE extends TokenizerModel{constructor(e){super(e),this.BPE_SPLIT_TOKEN=" ",this.tokens_to_ids=objectToMap(e.vocab),this.unk_token_id=this.tokens_to_ids.get(e.unk_token),this.unk_token=e.unk_token,this.vocab=new Array(this.tokens_to_ids.size);for(const[t,r]of this.tokens_to_ids)this.vocab[r]=t;this.bpe_ranks=new Map(e.merges.map((t,r)=>[t,r])),this.merges=e.merges.map(t=>t.split(this.BPE_SPLIT_TOKEN)),this.end_of_word_suffix=e.end_of_word_suffix,this.continuing_subword_suffix=e.continuing_subword_suffix??null,this.byte_fallback=this.config.byte_fallback??!1,this.byte_fallback&&(this.text_encoder=new TextEncoder),this.cache=new Map}bpe(e){if(e.length===0)return[];const t=this.cache.get(e);if(t!==void 0)return t;const r=Array.from(e);this.end_of_word_suffix&&(r[r.length-1]+=this.end_of_word_suffix);let o=[];if(r.length>1){const c=new PriorityQueue((p,f)=>p.score`<0x${l.toString(16).toUpperCase().padStart(2,"0")}>`)):t.push(this.unk_token)}return t}}class LegacyTokenizerModel extends TokenizerModel{constructor(e,t){super(e),this.tokens_to_ids=objectToMap(t.target_lang?e.vocab[t.target_lang]:e.vocab),this.bos_token=t.bos_token,this.bos_token_id=this.tokens_to_ids.get(this.bos_token),this.eos_token=t.eos_token,this.eos_token_id=this.tokens_to_ids.get(this.eos_token),this.pad_token=t.pad_token,this.pad_token_id=this.tokens_to_ids.get(this.pad_token),this.unk_token=t.unk_token,this.unk_token_id=this.tokens_to_ids.get(this.unk_token),this.vocab=new Array(this.tokens_to_ids.size);for(const[r,o]of this.tokens_to_ids)this.vocab[o]=r}encode(e){return e}}class Normalizer extends Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(e===null)return null;switch(e.type){case"BertNormalizer":return new BertNormalizer(e);case"Precompiled":return new Precompiled(e);case"Sequence":return new NormalizerSequence(e);case"Replace":return new Replace(e);case"NFC":return new NFC(e);case"NFKC":return new NFKC(e);case"NFKD":return new NFKD(e);case"Strip":return new StripNormalizer(e);case"StripAccents":return new StripAccents(e);case"Lowercase":return new Lowercase(e);case"Prepend":return new Prepend(e);default:throw new Error(`Unknown Normalizer type: ${e.type}`)}}normalize(e){throw Error("normalize should be implemented in subclass.")}_call(e){return this.normalize(e)}}class Replace extends Normalizer{normalize(e){const t=createPattern(this.config.pattern);return t===null?e:e.replaceAll(t,this.config.content)}}class NFC extends Normalizer{normalize(e){return e=e.normalize("NFC"),e}}class NFKC extends Normalizer{normalize(e){return e=e.normalize("NFKC"),e}}class NFKD extends Normalizer{normalize(e){return e=e.normalize("NFKD"),e}}class StripNormalizer extends Normalizer{normalize(e){return this.config.strip_left&&this.config.strip_right?e=e.trim():(this.config.strip_left&&(e=e.trimStart()),this.config.strip_right&&(e=e.trimEnd())),e}}class StripAccents extends Normalizer{normalize(e){return e=remove_accents(e),e}}class Lowercase extends Normalizer{normalize(e){return e=e.toLowerCase(),e}}class Prepend extends Normalizer{normalize(e){return e=this.config.prepend+e,e}}class NormalizerSequence extends Normalizer{constructor(e){super(e),this.normalizers=e.normalizers.map(t=>Normalizer.fromConfig(t))}normalize(e){return this.normalizers.reduce((t,r)=>r.normalize(t),e)}}class BertNormalizer extends Normalizer{_tokenize_chinese_chars(e){const t=[];for(let r=0;r=19968&&e<=40959||e>=13312&&e<=19903||e>=131072&&e<=173791||e>=173824&&e<=177983||e>=177984&&e<=178207||e>=178208&&e<=183983||e>=63744&&e<=64255||e>=194560&&e<=195103}stripAccents(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"")}_is_control(e){switch(e){case" ":case` `:case"\r":return!1;default:return/^\p{Cc}|\p{Cf}|\p{Co}|\p{Cs}$/u.test(e)}}_clean_text(e){const t=[];for(const r of e){const o=r.charCodeAt(0);o===0||o===65533||this._is_control(r)||(/^\s$/.test(r)?t.push(" "):t.push(r))}return t.join("")}normalize(e){return this.config.clean_text&&(e=this._clean_text(e)),this.config.handle_chinese_chars&&(e=this._tokenize_chinese_chars(e)),this.config.lowercase?(e=e.toLowerCase(),this.config.strip_accents!==!1&&(e=this.stripAccents(e))):this.config.strip_accents&&(e=this.stripAccents(e)),e}}class PreTokenizer extends Callable{static fromConfig(e){if(e===null)return null;switch(e.type){case"BertPreTokenizer":return new BertPreTokenizer(e);case"Sequence":return new PreTokenizerSequence(e);case"WhitespaceSplit":return new WhitespaceSplit(e);case"Metaspace":return new MetaspacePreTokenizer(e);case"ByteLevel":return new ByteLevelPreTokenizer(e);case"Split":return new SplitPreTokenizer(e);case"Punctuation":return new PunctuationPreTokenizer(e);case"Digits":return new DigitsPreTokenizer(e);case"Replace":return new ReplacePreTokenizer(e);default:throw new Error(`Unknown PreTokenizer type: ${e.type}`)}}pre_tokenize_text(e,t){throw Error("pre_tokenize_text should be implemented in subclass.")}pre_tokenize(e,t){return(Array.isArray(e)?e.map(r=>this.pre_tokenize_text(r,t)):this.pre_tokenize_text(e,t)).flat()}_call(e,t){return this.pre_tokenize(e,t)}}class BertPreTokenizer extends PreTokenizer{constructor(e){super(),this.pattern=new RegExp(`[^\\s${PUNCTUATION_REGEX}]+|[${PUNCTUATION_REGEX}]`,"gu")}pre_tokenize_text(e,t){return e.trim().match(this.pattern)||[]}}class ByteLevelPreTokenizer extends PreTokenizer{constructor(e){super(),this.config=e,this.add_prefix_space=this.config.add_prefix_space,this.trim_offsets=this.config.trim_offsets,this.use_regex=this.config.use_regex??!0,this.pattern=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,this.byte_encoder=BYTES_TO_UNICODE,this.text_encoder=new TextEncoder}pre_tokenize_text(e,t){return this.add_prefix_space&&!e.startsWith(" ")&&(e=" "+e),(this.use_regex?e.match(this.pattern)||[]:[e]).map(o=>Array.from(this.text_encoder.encode(o),c=>this.byte_encoder[c]).join(""))}}class SplitPreTokenizer extends PreTokenizer{constructor(e){super(),this.config=e,this.pattern=createPattern(this.config.pattern,this.config.invert)}pre_tokenize_text(e,t){return this.pattern===null?[]:this.config.invert?e.match(this.pattern)||[]:regexSplit(e,this.pattern)}}class PunctuationPreTokenizer extends PreTokenizer{constructor(e){super(),this.config=e,this.pattern=new RegExp(`[^${PUNCTUATION_REGEX}]+|[${PUNCTUATION_REGEX}]+`,"gu")}pre_tokenize_text(e,t){return e.match(this.pattern)||[]}}class DigitsPreTokenizer extends PreTokenizer{constructor(e){super(),this.config=e;const t=`[^\\d]+|\\d${this.config.individual_digits?"":"+"}`;this.pattern=new RegExp(t,"gu")}pre_tokenize_text(e,t){return e.match(this.pattern)||[]}}class PostProcessor extends Callable{constructor(e){super(),this.config=e}static fromConfig(e){if(e===null)return null;switch(e.type){case"TemplateProcessing":return new TemplateProcessing(e);case"ByteLevel":return new ByteLevelPostProcessor(e);case"RobertaProcessing":return new RobertaProcessing(e);case"BertProcessing":return new BertProcessing(e);default:throw new Error(`Unknown PostProcessor type: ${e.type}`)}}post_process(e,...t){throw Error("post_process should be implemented in subclass.")}_call(e,...t){return this.post_process(e,...t)}}class BertProcessing extends PostProcessor{constructor(e){super(e),this.cls=e.cls[0],this.sep=e.sep[0]}post_process(e,t=null,{add_special_tokens:r=!0}={}){r&&(e=mergeArrays([this.cls],e,[this.sep]));let o=new Array(e.length).fill(0);if(t!==null){const c=r&&this instanceof RobertaProcessing?[this.sep]:[],l=r?[this.sep]:[];e=mergeArrays(e,c,t,l),o=mergeArrays(o,new Array(t.length+c.length+l.length).fill(1))}return{tokens:e,token_type_ids:o}}}class RobertaProcessing extends BertProcessing{}class TemplateProcessing extends PostProcessor{constructor(e){super(e),this.single=e.single,this.pair=e.pair}post_process(e,t=null,{add_special_tokens:r=!0}={}){const o=t===null?this.single:this.pair;let c=[],l=[];for(const h of o)"SpecialToken"in h?r&&(c.push(h.SpecialToken.id),l.push(h.SpecialToken.type_id)):"Sequence"in h&&(h.Sequence.id==="A"?(c=mergeArrays(c,e),l=mergeArrays(l,new Array(e.length).fill(h.Sequence.type_id))):h.Sequence.id==="B"&&(c=mergeArrays(c,t),l=mergeArrays(l,new Array(t.length).fill(h.Sequence.type_id))));return{tokens:c,token_type_ids:l}}}class ByteLevelPostProcessor extends PostProcessor{post_process(e,t=null){return t&&(e=mergeArrays(e,t)),{tokens:e}}}class Decoder extends Callable{constructor(e){super(),this.config=e,this.added_tokens=[],this.end_of_word_suffix=null,this.trim_offsets=e.trim_offsets}static fromConfig(e){if(e===null)return null;switch(e.type){case"WordPiece":return new WordPieceDecoder(e);case"Metaspace":return new MetaspaceDecoder(e);case"ByteLevel":return new ByteLevelDecoder(e);case"Replace":return new ReplaceDecoder(e);case"ByteFallback":return new ByteFallback(e);case"Fuse":return new FuseDecoder(e);case"Strip":return new StripDecoder(e);case"Sequence":return new DecoderSequence(e);case"CTC":return new CTCDecoder(e);case"BPEDecoder":return new BPEDecoder(e);default:throw new Error(`Unknown Decoder type: ${e.type}`)}}_call(e){return this.decode(e)}decode(e){return this.decode_chain(e).join("")}decode_chain(e){throw Error("`decode_chain` should be implemented in subclass.")}}class ReplaceDecoder extends Decoder{decode_chain(e){const t=createPattern(this.config.pattern);return t===null?e:e.map(r=>r.replaceAll(t,this.config.content))}}class ByteFallback extends Decoder{constructor(e){super(e),this.text_decoder=new TextDecoder}decode_chain(e){const t=[];let r=[];for(const o of e){let c=null;if(o.length===6&&o.startsWith("<0x")&&o.endsWith(">")){const l=parseInt(o.slice(3,5),16);isNaN(l)||(c=l)}if(c!==null)r.push(c);else{if(r.length>0){const l=this.text_decoder.decode(Uint8Array.from(r));t.push(l),r=[]}t.push(o)}}if(r.length>0){const o=this.text_decoder.decode(Uint8Array.from(r));t.push(o),r=[]}return t}}class FuseDecoder extends Decoder{decode_chain(e){return[e.join("")]}}class StripDecoder extends Decoder{constructor(e){super(e),this.content=this.config.content,this.start=this.config.start,this.stop=this.config.stop}decode_chain(e){return e.map(t=>{let r=0;for(let c=0;c(r!==0&&(t.startsWith(this.config.prefix)?t=t.replace(this.config.prefix,""):t=" "+t),this.cleanup&&(t=clean_up_tokenization(t)),t))}}class ByteLevelDecoder extends Decoder{constructor(e){super(e),this.byte_decoder=UNICODE_TO_BYTES,this.text_decoder=new TextDecoder("utf-8",{fatal:!1,ignoreBOM:!0}),this.end_of_word_suffix=null}convert_tokens_to_string(e){const t=e.join(""),r=new Uint8Array([...t].map(c=>this.byte_decoder[c]));return this.text_decoder.decode(r)}decode_chain(e){const t=[];let r=[];for(const o of e)this.added_tokens.find(c=>c.content===o)!==void 0?(r.length>0&&(t.push(this.convert_tokens_to_string(r)),r=[]),t.push(o)):r.push(o);return r.length>0&&t.push(this.convert_tokens_to_string(r)),t}}class CTCDecoder extends Decoder{constructor(e){super(e),this.pad_token=this.config.pad_token,this.word_delimiter_token=this.config.word_delimiter_token,this.cleanup=this.config.cleanup}convert_tokens_to_string(e){if(e.length===0)return"";const t=[e[0]];for(let c=1;cc!==this.pad_token).join("");return this.cleanup&&(o=clean_up_tokenization(o).replaceAll(this.word_delimiter_token," ").trim()),o}decode_chain(e){return[this.convert_tokens_to_string(e)]}}class DecoderSequence extends Decoder{constructor(e){super(e),this.decoders=e.decoders.map(t=>Decoder.fromConfig(t))}decode_chain(e){return this.decoders.reduce((t,r)=>r.decode_chain(t),e)}}class BPEDecoder extends Decoder{constructor(e){super(e),this.suffix=this.config.suffix}decode_chain(e){return e.map((t,r)=>t.replaceAll(this.suffix,r===e.length-1?"":" "))}}class VitsDecoder extends Decoder{decode_chain(e){let t="";for(let r=1;rr.normalize("NFKC")).join("~"):e=e.normalize("NFKC"),e}}class PreTokenizerSequence extends PreTokenizer{constructor(e){super(),this.tokenizers=e.pretokenizers.map(t=>PreTokenizer.fromConfig(t))}pre_tokenize_text(e,t){return this.tokenizers.reduce((r,o)=>o.pre_tokenize(r,t),[e])}}class WhitespaceSplit extends PreTokenizer{constructor(e){super()}pre_tokenize_text(e,t){return whitespace_split(e)}}class ReplacePreTokenizer extends PreTokenizer{constructor(e){super(),this.config=e,this.pattern=createPattern(this.config.pattern),this.content=this.config.content}pre_tokenize_text(e,t){return this.pattern===null?[e]:[e.replaceAll(this.pattern,this.config.content)]}}const SPECIAL_TOKEN_ATTRIBUTES=["bos_token","eos_token","unk_token","sep_token","pad_token","cls_token","mask_token"];function padHelper(s,e,t,r){for(const o of Object.keys(s)){const c=e-s[o].length,l=t(o),h=new Array(c).fill(l);s[o]=r==="right"?mergeArrays(s[o],h):mergeArrays(h,s[o])}}function truncateHelper(s,e){for(const t of Object.keys(s))s[t].length=e}class PreTrainedTokenizer extends Callable{return_token_type_ids=!1;_default_chat_template=`{% for message in messages %}{{'<|im_start|>' + message['role'] + ' ' + message['content'] + '<|im_end|>' + ' '}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant ' }}{% endif %}`;constructor(e,t){super(),this._tokenizer_config=t,this.normalizer=Normalizer.fromConfig(e.normalizer),this.pre_tokenizer=PreTokenizer.fromConfig(e.pre_tokenizer),this.model=TokenizerModel.fromConfig(e.model,t),this.post_processor=PostProcessor.fromConfig(e.post_processor),this.decoder=Decoder.fromConfig(e.decoder),this.special_tokens=[],this.all_special_ids=[],this.added_tokens=[];for(const r of e.added_tokens){const o=new AddedToken(r);this.added_tokens.push(o),this.model.tokens_to_ids.set(o.content,o.id),this.model.vocab[o.id]=o.content,o.special&&(this.special_tokens.push(o.content),this.all_special_ids.push(o.id))}this.additional_special_tokens=t.additional_special_tokens??[],this.special_tokens.push(...this.additional_special_tokens),this.special_tokens=[...new Set(this.special_tokens)],this.decoder&&(this.decoder.added_tokens=this.added_tokens,this.decoder.end_of_word_suffix=this.model.end_of_word_suffix),this.added_tokens_regex=this.added_tokens.length>0?new RegExp(this.added_tokens.map(r=>`${r.lstrip?"\\s*":""}(${escapeRegExp(r.content)})${r.rstrip?"\\s*":""}`).join("|")):null,this.mask_token=this.getToken("mask_token"),this.mask_token_id=this.model.tokens_to_ids.get(this.mask_token),this.pad_token=this.getToken("pad_token","eos_token"),this.pad_token_id=this.model.tokens_to_ids.get(this.pad_token),this.sep_token=this.getToken("sep_token"),this.sep_token_id=this.model.tokens_to_ids.get(this.sep_token),this.unk_token=this.getToken("unk_token"),this.unk_token_id=this.model.tokens_to_ids.get(this.unk_token),this.model_max_length=t.model_max_length,this.remove_space=t.remove_space,this.clean_up_tokenization_spaces=t.clean_up_tokenization_spaces??!0,this.do_lowercase_and_remove_accent=t.do_lowercase_and_remove_accent??!1,this.padding_side="right",this.legacy=!1,this.chat_template=t.chat_template??null,this._compiled_template_cache=new Map}getToken(...e){for(const t of e){const r=this._tokenizer_config[t];if(r)if(typeof r=="object"){if(r.__type==="AddedToken")return r.content;throw Error(`Unknown token: ${r}`)}else return r}return null}static async from_pretrained(e,{progress_callback:t=null,config:r=null,cache_dir:o=null,local_files_only:c=!1,revision:l="main",legacy:h=null}={}){const p=await loadTokenizer(e,{progress_callback:t,config:r,cache_dir:o,local_files_only:c,revision:l,legacy:h});return new this(...p)}_call(e,{text_pair:t=null,add_special_tokens:r=!0,padding:o=!1,truncation:c=null,max_length:l=null,return_tensor:h=!0}={}){const p=Array.isArray(e);let f;if(p){if(e.length===0)throw Error("text array must be non-empty");if(t!==null){if(Array.isArray(t)){if(e.length!==t.length)throw Error("text and text_pair must have the same length")}else throw Error("text_pair must also be an array");f=e.map((i,n)=>this._encode_plus(i,t[n],{add_special_tokens:r}))}else f=e.map(i=>this._encode_plus(i,null,{add_special_tokens:r}))}else{if(e===null)throw Error("text may not be null");if(Array.isArray(t))throw Error("When specifying `text_pair`, since `text` is a string, `text_pair` must also be a string (i.e., not an array).");f=[this._encode_plus(e,t,{add_special_tokens:r})]}if(l===null?o==="max_length"?l=this.model_max_length:l=max(f.map(i=>i.input_ids.length))[0]:c||console.warn("Truncation was not explicitly activated but `max_length` is provided a specific value, please use `truncation=true` to explicitly truncate examples to max length."),l=Math.min(l,this.model_max_length),o||c)for(let i=0;il?c&&truncateHelper(f[i],l):o&&padHelper(f[i],l,n=>n==="input_ids"?this.pad_token_id:0,this.padding_side));const d={};if(h){if(!(o&&c)&&f.some(n=>{for(const a of Object.keys(n))if(n[a].length!==f[0][a]?.length)return!0;return!1}))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=true' and 'truncation=true' to have batched tensors with the same length.");const i=[f.length,f[0].input_ids.length];for(const n of Object.keys(f[0]))d[n]=new Tensor("int64",BigInt64Array.from(f.flatMap(a=>a[n]).map(BigInt)),i)}else{for(const i of Object.keys(f[0]))d[i]=f.map(n=>n[i]);if(!p)for(const i of Object.keys(d))d[i]=d[i][0]}return d}_encode_text(e){return e===null?null:(this.added_tokens_regex?e.split(this.added_tokens_regex).filter(o=>o):[e]).map((o,c)=>{if(this.added_tokens.find(h=>h.content===o)!==void 0)return o;{if(this.remove_space===!0&&(o=o.trim().split(/\s+/).join(" ")),this.do_lowercase_and_remove_accent&&(o=lowercase_and_remove_accent(o)),this.normalizer!==null&&(o=this.normalizer(o)),o.length===0)return[];const h=this.pre_tokenizer!==null?this.pre_tokenizer(o,{section_index:c}):[o];return this.model(h)}}).flat()}_encode_plus(e,t=null,{add_special_tokens:r=!0}={}){const o=this._encode_text(e),c=this._encode_text(t),l=this.post_processor?this.post_processor(o,c,{add_special_tokens:r}):{tokens:mergeArrays(o??[],c??[])},h=this.model.convert_tokens_to_ids(l.tokens),p={input_ids:h,attention_mask:new Array(h.length).fill(1)};return this.return_token_type_ids&&l.token_type_ids&&(p.token_type_ids=l.token_type_ids),p}encode(e,t=null,{add_special_tokens:r=!0}={}){const{input_ids:o}=this._encode_plus(e,t,{add_special_tokens:r});return o}batch_decode(e,t={}){return e instanceof Tensor&&(e=e.tolist()),e.map(r=>this.decode(r,t))}decode(e,t={}){if(e instanceof Tensor&&(e=prepareTensorForDecode(e)),!Array.isArray(e)||e.length===0||!isIntegralNumber(e[0]))throw Error("token_ids must be a non-empty array of integers.");return this.decode_single(e,t)}decode_single(e,{skip_special_tokens:t=!1,clean_up_tokenization_spaces:r=null}){let o=this.model.convert_ids_to_tokens(e);t&&(o=o.filter(l=>!this.special_tokens.includes(l)));let c=this.decoder?this.decoder(o):o.join(" ");return this.decoder&&this.decoder.end_of_word_suffix&&(c=c.replaceAll(this.decoder.end_of_word_suffix," "),t&&(c=c.trim())),(r??this.clean_up_tokenization_spaces)&&(c=clean_up_tokenization(c)),c}get default_chat_template(){return this._warned_about_chat_template||(console.warn("No chat template is defined for this tokenizer - using a default chat template that implements the ChatML format. If the default is not appropriate for your model, please set `tokenizer.chat_template` to an appropriate template. See https://huggingface.co/docs/transformers/main/chat_templating for more information."),this._warned_about_chat_template=!0),this._default_chat_template}apply_chat_template(e,{chat_template:t=null,add_generation_prompt:r=!1,tokenize:o=!0,padding:c=!1,truncation:l=!1,max_length:h=null,return_tensor:p=!0}={}){t??=this.chat_template??this.default_chat_template;let f=this._compiled_template_cache.get(t);f===void 0&&(f=new Template(t),this._compiled_template_cache.set(t,f));const d=Object.create(null);for(const n of SPECIAL_TOKEN_ATTRIBUTES){const a=this.getToken(n);a&&(d[n]=a)}const i=f.render({messages:e,add_generation_prompt:r,...d});return o?this._call(i,{add_special_tokens:!1,padding:c,truncation:l,max_length:h,return_tensor:p}).input_ids:i}}class BertTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class AlbertTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class MobileBertTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class SqueezeBertTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class DebertaTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class DebertaV2Tokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class HerbertTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class ConvBertTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class RoFormerTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class DistilBertTokenizer extends PreTrainedTokenizer{}class CamembertTokenizer extends PreTrainedTokenizer{}class XLMTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0;constructor(e,t){super(e,t),console.warn('WARNING: `XLMTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}}class ElectraTokenizer extends PreTrainedTokenizer{return_token_type_ids=!0}class T5Tokenizer extends PreTrainedTokenizer{}class GPT2Tokenizer extends PreTrainedTokenizer{_default_chat_template='{% for message in messages %}" "{{ message.content }}{{ eos_token }}" "{% endfor %}'}class BartTokenizer extends PreTrainedTokenizer{}class MBartTokenizer extends PreTrainedTokenizer{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{2}_[A-Z]{2}$/,this.language_codes=this.special_tokens.filter(r=>this.languageRegex.test(r)),this.lang_to_token=r=>r}_build_translation_inputs(e,t,r){return _build_translation_inputs(this,e,t,r)}}class MBart50Tokenizer extends MBartTokenizer{}class RobertaTokenizer extends PreTrainedTokenizer{}class BloomTokenizer extends GPT2Tokenizer{constructor(e,t){const r=".,!?…。,、।۔،",o=e.pre_tokenizer?.pretokenizers[0]?.pattern;o&&o.Regex===` ?[^(\\s|[${r}])]+`&&(o.Regex=` ?[^\\s${r}]+`),super(e,t)}}const SPIECE_UNDERLINE="▁";class LlamaTokenizer extends PreTrainedTokenizer{_default_chat_template=`{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% elif USE_DEFAULT_PROMPT == true and not '<>' in messages[0]['content'] %}{% set loop_messages = messages %}{% set system_message = 'DEFAULT_SYSTEM_MESSAGE' %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<> ' + system_message + ' <> ' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'system' %}{{ '<> ' + content.strip() + ' <> ' }}{% elif message['role'] == 'assistant' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %}`;DEFAULT_SYSTEM_PROMPT=`You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.`;constructor(e,t){super(e,t),this.use_default_system_prompt=t.use_default_system_prompt??!1,this.legacy=t.legacy??!0,this.legacy||(this.normalizer=null,this.pre_tokenizer=new MetaspacePreTokenizer({replacement:SPIECE_UNDERLINE,add_prefix_space:!0,prepend_scheme:"first"}))}_encode_text(e){if(e===null)return null;if(this.legacy||e.length===0)return super._encode_text(e);let t=super._encode_text(SPIECE_UNDERLINE+e.replaceAll(SPIECE_UNDERLINE," "));return t.length>1&&t[0]===SPIECE_UNDERLINE&&this.special_tokens.includes(t[1])&&(t=t.slice(1)),t}get default_chat_template(){return super.default_chat_template.replaceAll("USE_DEFAULT_PROMPT",this.use_default_system_prompt?"true":"false").replaceAll("DEFAULT_SYSTEM_MESSAGE",this.DEFAULT_SYSTEM_PROMPT.replaceAll(` `,"\\n").replaceAll("'","\\'"))}}class CodeLlamaTokenizer extends LlamaTokenizer{}class XLMRobertaTokenizer extends PreTrainedTokenizer{}class MPNetTokenizer extends PreTrainedTokenizer{}class FalconTokenizer extends PreTrainedTokenizer{}class GPTNeoXTokenizer extends PreTrainedTokenizer{}class EsmTokenizer extends PreTrainedTokenizer{}function _build_translation_inputs(s,e,t,r){if(!("language_codes"in s)||!Array.isArray(s.language_codes))throw new Error("Tokenizer must have `language_codes` attribute set and it should be an array of language ids.");if(!("languageRegex"in s)||!(s.languageRegex instanceof RegExp))throw new Error("Tokenizer must have `languageRegex` attribute set and it should be a regular expression.");if(!("lang_to_token"in s)||typeof s.lang_to_token!="function")throw new Error("Tokenizer must have `lang_to_token` attribute set and it should be a function.");const o=r.src_lang,c=r.tgt_lang;if(!s.language_codes.includes(c))throw new Error(`Target language code "${c}" is not valid. Must be one of: {${s.language_codes.join(", ")}}`);if(o!==void 0){if(!s.language_codes.includes(o))throw new Error(`Source language code "${o}" is not valid. Must be one of: {${s.language_codes.join(", ")}}`);for(const l of s.post_processor.config.single)if("SpecialToken"in l&&s.languageRegex.test(l.SpecialToken.id)){l.SpecialToken.id=s.lang_to_token(o);break}}return r.forced_bos_token_id=s.model.convert_tokens_to_ids([s.lang_to_token(c)])[0],s._call(e,t)}class NllbTokenizer extends PreTrainedTokenizer{constructor(e,t){super(e,t),this.languageRegex=/^[a-z]{3}_[A-Z][a-z]{3}$/,this.language_codes=this.special_tokens.filter(r=>this.languageRegex.test(r)),this.lang_to_token=r=>r}_build_translation_inputs(e,t,r){return _build_translation_inputs(this,e,t,r)}}class M2M100Tokenizer extends PreTrainedTokenizer{constructor(e,t){super(e,t),this.languageRegex=/^__[a-z]{2,3}__$/,this.language_codes=this.special_tokens.filter(r=>this.languageRegex.test(r)).map(r=>r.slice(2,-2)),this.lang_to_token=r=>`__${r}__`}_build_translation_inputs(e,t,r){return _build_translation_inputs(this,e,t,r)}}const WHISPER_LANGUAGES=[["en","english"],["zh","chinese"],["de","german"],["es","spanish"],["ru","russian"],["ko","korean"],["fr","french"],["ja","japanese"],["pt","portuguese"],["tr","turkish"],["pl","polish"],["ca","catalan"],["nl","dutch"],["ar","arabic"],["sv","swedish"],["it","italian"],["id","indonesian"],["hi","hindi"],["fi","finnish"],["vi","vietnamese"],["he","hebrew"],["uk","ukrainian"],["el","greek"],["ms","malay"],["cs","czech"],["ro","romanian"],["da","danish"],["hu","hungarian"],["ta","tamil"],["no","norwegian"],["th","thai"],["ur","urdu"],["hr","croatian"],["bg","bulgarian"],["lt","lithuanian"],["la","latin"],["mi","maori"],["ml","malayalam"],["cy","welsh"],["sk","slovak"],["te","telugu"],["fa","persian"],["lv","latvian"],["bn","bengali"],["sr","serbian"],["az","azerbaijani"],["sl","slovenian"],["kn","kannada"],["et","estonian"],["mk","macedonian"],["br","breton"],["eu","basque"],["is","icelandic"],["hy","armenian"],["ne","nepali"],["mn","mongolian"],["bs","bosnian"],["kk","kazakh"],["sq","albanian"],["sw","swahili"],["gl","galician"],["mr","marathi"],["pa","punjabi"],["si","sinhala"],["km","khmer"],["sn","shona"],["yo","yoruba"],["so","somali"],["af","afrikaans"],["oc","occitan"],["ka","georgian"],["be","belarusian"],["tg","tajik"],["sd","sindhi"],["gu","gujarati"],["am","amharic"],["yi","yiddish"],["lo","lao"],["uz","uzbek"],["fo","faroese"],["ht","haitian creole"],["ps","pashto"],["tk","turkmen"],["nn","nynorsk"],["mt","maltese"],["sa","sanskrit"],["lb","luxembourgish"],["my","myanmar"],["bo","tibetan"],["tl","tagalog"],["mg","malagasy"],["as","assamese"],["tt","tatar"],["haw","hawaiian"],["ln","lingala"],["ha","hausa"],["ba","bashkir"],["jw","javanese"],["su","sundanese"]],WHISPER_LANGUAGE_MAPPING=new Map(WHISPER_LANGUAGES),WHISPER_TO_LANGUAGE_CODE_MAPPING=new Map([...WHISPER_LANGUAGES.map(([s,e])=>[e,s]),["burmese","my"],["valencian","ca"],["flemish","nl"],["haitian","ht"],["letzeburgesch","lb"],["pushto","ps"],["panjabi","pa"],["moldavian","ro"],["moldovan","ro"],["sinhalese","si"],["castilian","es"]]);class WhisperTokenizer extends PreTrainedTokenizer{_default_chat_template='{% for message in messages %}" "{{ message.content }}{{ eos_token }}" "{% endfor %}';_decode_asr(e,{return_timestamps:t=!1,return_language:r=!1,time_precision:o=null,force_full_sequences:c=!0}={}){if(o===null)throw Error("Must specify time_precision");let l=null;const h=t==="word";function p(){return{language:l,timestamp:[null,null],text:""}}const f=[];let d=p(),i=0;const n=this.model.convert_tokens_to_ids(["<|notimestamps|>"])[0]+1;let a=[],u=[],m=!1,g=null;const _=new Set(this.all_special_ids);for(const v of e){const x=v.tokens,w=h?v.token_timestamps:null;let S=null,M=n;if("stride"in v){const[R,I,k]=v.stride;if(i-=I,g=R-k,I&&(M=I/o+n),k)for(let C=x.length-1;C>=0;--C){const z=x[C];if(z>=n){if(S!==null&&(z-n)*o=n){const k=(I-n)*o+i,C=round(k,2);if(S!==null&&I>=S)m=!0;else if(m||a.length>0&&I0?(a.push(T),h&&u.push(E)):a.every(R=>R.length===0)&&(d=p(),a=[],T=[],u=[],E=[])}if(a.length>0){if(c&&t)throw new Error("Whisper did not predict an ending timestamp, which can happen if audio is cut off in the middle of a word. Also make sure WhisperTimeStampLogitsProcessor was used during generation.");const[v,x]=this.findLongestCommonSequence(a,u),w=this.decode(v);d.text=w,h&&(d.words=this.collateWordTimestamps(v,x,l)),f.push(d)}let b=Object.create(null);const y=f.map(v=>v.text).join("");if(t||r){for(let v=0;v0;let h=l?[]:null,p=l?t[0]:null;for(let f=1;fC===R[z]).length,k=I/v+x;I>1&&k>i&&(i=k,n=[w,S,T,E])}const[u,m,g,_]=n,b=Math.floor((m+u)/2),y=Math.floor((_+g)/2);c.push(...r.slice(0,b)),r=d.slice(y),o=r.length,l&&(h.push(...p.slice(0,b)),p=t[f].slice(y))}return c.push(...r),l?(h.push(...p),[c,h]):[c,[]]}collateWordTimestamps(e,t,r){const[o,c,l]=this.combineTokensIntoWords(e,r),h=[];for(let p=0;p=o){const h=round((l-o)*r,2);c.push(`<|${h}|>`),c.push([])}else c[c.length-1].push(l);return c=c.map(l=>typeof l=="string"?l:super.decode(l,t)),c.join("")}splitTokensOnUnicode(e){const t=this.decode(e,{decode_with_timestamps:!0}),r="�",o=[],c=[],l=[];let h=[],p=[],f=0;for(let d=0;d=this.model.tokens_to_ids.get("<|endoftext|>"),u=d.startsWith(" "),m=d.trim(),g=p.test(m);if(a||u||g||c.length===0)c.push(d),l.push(i),h.push(n);else{const _=c.length-1;c[_]+=d,l[_].push(...i),h[_].push(...n)}}return[c,l,h]}mergePunctuations(e,t,r,o,c){const l=structuredClone(e),h=structuredClone(t),p=structuredClone(r);let f=l.length-2,d=l.length-1;for(;f>=0;)l[f].startsWith(" ")&&o.includes(l[f].trim())?(l[d]=l[f]+l[d],h[d]=mergeArrays(h[f],h[d]),p[d]=mergeArrays(p[f],p[d]),l[f]="",h[f]=[],p[f]=[]):d=f,--f;for(f=0,d=1;di),h.filter(i=>i.length>0),p.filter(i=>i.length>0)]}get_decoder_prompt_ids({language:e=null,task:t=null,no_timestamps:r=!0}={}){const o=[];if(e){e=e.toLowerCase();let c=WHISPER_TO_LANGUAGE_CODE_MAPPING.get(e);if(c===void 0)if(WHISPER_LANGUAGE_MAPPING.has(e))c=e;else{const p=e.length===2?WHISPER_LANGUAGE_MAPPING.keys():WHISPER_LANGUAGE_MAPPING.values();throw new Error(`Language "${e}" is not supported. Must be one of: ${JSON.stringify(p)}`)}const l=this.model.tokens_to_ids.get(`<|${c}|>`);if(l===void 0)throw new Error(`Unable to find language "${c}" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.`);o.push(l)}else o.push(null);if(t){if(t=t.toLowerCase(),t!=="transcribe"&&t!=="translate")throw new Error(`Task "${t}" is not supported. Must be one of: ["transcribe", "translate"]`);const c=this.model.tokens_to_ids.get(`<|${t}|>`);if(c===void 0)throw new Error(`Unable to find task "${t}" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.`);o.push(c)}else o.push(null);if(r){const c=this.model.tokens_to_ids.get("<|notimestamps|>");if(c===void 0)throw new Error('Unable to find "<|notimestamps|>" in model vocabulary. Please report this issue at https://github.com/xenova/transformers.js/issues/new/choose.');o.push(c)}return o.map((c,l)=>[l+1,c]).filter(c=>c[1]!==null)}}class CodeGenTokenizer extends PreTrainedTokenizer{}class CLIPTokenizer extends PreTrainedTokenizer{}class SiglipTokenizer extends PreTrainedTokenizer{}class MarianTokenizer extends PreTrainedTokenizer{constructor(e,t){super(e,t),this.languageRegex=/^(>>\w+<<)\s*/g,this.supported_language_codes=this.model.vocab.filter(r=>this.languageRegex.test(r)),console.warn('WARNING: `MarianTokenizer` is not yet supported by Hugging Face\'s "fast" tokenizers library. Therefore, you may experience slightly inaccurate results.')}_encode_text(e){if(e===null)return null;const[t,...r]=e.trim().split(this.languageRegex);if(r.length===0)return super._encode_text(t);if(r.length===2){const[o,c]=r;return this.supported_language_codes.includes(o)||console.warn(`Unsupported language code "${o}" detected, which may lead to unexpected behavior. Should be one of: ${JSON.stringify(this.supported_language_codes)}`),mergeArrays([o],super._encode_text(c))}}}class Wav2Vec2CTCTokenizer extends PreTrainedTokenizer{}class BlenderbotTokenizer extends PreTrainedTokenizer{_default_chat_template="{% for message in messages %}{% if message['role'] == 'user' %}{{ ' ' }}{% endif %}{{ message['content'] }}{% if not loop.last %}{{ ' ' }}{% endif %}{% endfor %}{{ eos_token }}"}class BlenderbotSmallTokenizer extends BlenderbotTokenizer{}class SpeechT5Tokenizer extends PreTrainedTokenizer{}class NougatTokenizer extends PreTrainedTokenizer{}class VitsTokenizer extends PreTrainedTokenizer{constructor(e,t){super(e,t),this.decoder=new VitsDecoder({})}}class AutoTokenizer{static TOKENIZER_CLASS_MAPPING={T5Tokenizer,DistilBertTokenizer,CamembertTokenizer,DebertaTokenizer,DebertaV2Tokenizer,BertTokenizer,HerbertTokenizer,ConvBertTokenizer,RoFormerTokenizer,XLMTokenizer,ElectraTokenizer,MobileBertTokenizer,SqueezeBertTokenizer,AlbertTokenizer,GPT2Tokenizer,BartTokenizer,MBartTokenizer,MBart50Tokenizer,RobertaTokenizer,WhisperTokenizer,CodeGenTokenizer,CLIPTokenizer,SiglipTokenizer,MarianTokenizer,BloomTokenizer,NllbTokenizer,M2M100Tokenizer,LlamaTokenizer,CodeLlamaTokenizer,XLMRobertaTokenizer,MPNetTokenizer,FalconTokenizer,GPTNeoXTokenizer,EsmTokenizer,Wav2Vec2CTCTokenizer,BlenderbotTokenizer,BlenderbotSmallTokenizer,SpeechT5Tokenizer,NougatTokenizer,VitsTokenizer,PreTrainedTokenizer};static async from_pretrained(e,{quantized:t=!0,progress_callback:r=null,config:o=null,cache_dir:c=null,local_files_only:l=!1,revision:h="main",legacy:p=null}={}){const[f,d]=await loadTokenizer(e,{quantized:t,progress_callback:r,config:o,cache_dir:c,local_files_only:l,revision:h,legacy:p}),i=d.tokenizer_class?.replace(/Fast$/,"")??"PreTrainedTokenizer";let n=this.TOKENIZER_CLASS_MAPPING[i];return n||(console.warn(`Unknown tokenizer class "${i}", attempting to construct from base class.`),n=PreTrainedTokenizer),new n(f,d)}}async function loadConfig(s,e){return await getModelJSON(s,"config.json",!0,e)}class PretrainedConfig{constructor(e){this.model_type=null,this.is_encoder_decoder=!1,Object.assign(this,e)}static async from_pretrained(e,{progress_callback:t=null,config:r=null,cache_dir:o=null,local_files_only:c=!1,revision:l="main"}={}){let h=r??await loadConfig(e,{progress_callback:t,config:r,cache_dir:o,local_files_only:c,revision:l});return new this(h)}}class AutoConfig{static async from_pretrained(...e){return PretrainedConfig.from_pretrained(...e)}}class LogitsProcessorList extends Callable{constructor(){super(),this.processors=[]}push(e){this.processors.push(e)}extend(e){this.processors.push(...e)}_call(e,t){for(let r of t)this.processors.forEach(o=>o(e,r))}[Symbol.iterator](){return this.processors.values()}}class LogitsProcessor extends Callable{_call(e,t){throw Error("`_call` should be implemented in a subclass")}}class ForceTokensLogitsProcessor extends LogitsProcessor{constructor(e){super(),this.force_token_map=Object.fromEntries(e??[])}_call(e,t){let r=this.force_token_map[e.length];return exists(r)&&(t.data.fill(-1/0),t.data[r]=0),t}}class ForcedBOSTokenLogitsProcessor extends LogitsProcessor{constructor(e){super(),this.bos_token_id=e}_call(e,t){return e.length===1&&(t.data.fill(-1/0),t.data[this.bos_token_id]=0),t}}class ForcedEOSTokenLogitsProcessor extends LogitsProcessor{constructor(e,t){super(),this.max_length=e,this.forced_eos_token_id=t}_call(e,t){}}class SuppressTokensAtBeginLogitsProcessor extends LogitsProcessor{constructor(e,t){super(),this.begin_suppress_tokens=e,this.begin_index=t}_call(e,t){if(e.length===this.begin_index)for(let r of this.begin_suppress_tokens)t.data[r]=-1/0;return t}}class WhisperTimeStampLogitsProcessor extends LogitsProcessor{constructor(e){super(),this.eos_token_id=e.eos_token_id,this.no_timestamps_token_id=e.no_timestamps_token_id,this.timestamp_begin=this.no_timestamps_token_id+1,this.begin_index=(e.forced_decoder_ids||[]).length+2,e.forced_decoder_ids.slice(-1)[0][1]===this.no_timestamps_token_id&&(this.begin_index-=1),this.max_initial_timestamp_index=e.max_initial_timestamp_index}_call(e,t){const r=t.data;if(r[this.no_timestamps_token_id]=-1/0,e.length===this.begin_index-1)return r.fill(-1/0),r[this.timestamp_begin]=0,t;const o=e.slice(this.begin_index),c=o.length>=1&&o[o.length-1]>=this.timestamp_begin,l=o.length<2||o[o.length-2]>=this.timestamp_begin;if(c&&(l?r.subarray(this.timestamp_begin).fill(-1/0):r.subarray(0,this.eos_token_id).fill(-1/0)),e.length===this.begin_index&&this.max_initial_timestamp_index!==null){const d=this.timestamp_begin+this.max_initial_timestamp_index;r.subarray(d+1).fill(-1/0)}const h=log_softmax(r),p=Math.log(h.subarray(this.timestamp_begin).map(Math.exp).reduce((d,i)=>d+i)),f=max(h.subarray(0,this.timestamp_begin))[0];return p>f&&r.subarray(0,this.timestamp_begin).fill(-1/0),t}}class NoRepeatNGramLogitsProcessor extends LogitsProcessor{constructor(e){super(),this.no_repeat_ngram_size=e}getNgrams(e){const t=e.length,r=[];for(let c=0;c0&&(o=o.map(c=>c/this.generation_config.temperature)),o}randomSelect(e){let t=e.reduce((o,c)=>o+c,0),r=Math.random()*t;for(let o=0;o1)return new BeamSearchSampler(e);if(e.num_return_sequences>1)throw Error(`num_return_sequences has to be 1 when doing greedy search, but is ${e.num_return_sequences}.`);return new GreedySampler(e)}}class GreedySampler extends Sampler{sample(e,t=-1){let r=this.getLogits(e,t);return[[max(r)[1],0]]}}class MultinomialSampler extends Sampler{sample(e,t=-1){let r=e.dims.at(-1);this.generation_config.top_k>0&&(r=Math.min(this.generation_config.top_k,r));const o=this.getLogits(e,t),c=getTopItems(o,r),l=softmax(c.map(h=>h[1]));return Array.from({length:this.generation_config.num_beams},()=>{const h=this.randomSelect(l);return[c[h][0],Math.log(l[h])]})}}class BeamSearchSampler extends Sampler{sample(e,t=-1){let r=e.dims.at(-1);this.generation_config.top_k>0&&(r=Math.min(this.generation_config.top_k,r));const o=this.getLogits(e,t),c=getTopItems(o,r),l=softmax(c.map(h=>h[1]));return Array.from({length:this.generation_config.num_beams},(h,p)=>[c[p][0],Math.log(l[p])])}}const{InferenceSession,Tensor:ONNXTensor,env}=ONNX,MODEL_TYPES={EncoderOnly:0,EncoderDecoder:1,Seq2Seq:2,Vision2Seq:3,DecoderOnly:4,MaskGeneration:5},MODEL_TYPE_MAPPING=new Map,MODEL_NAME_TO_CLASS_MAPPING=new Map,MODEL_CLASS_TO_NAME_MAPPING=new Map;async function constructSession(s,e,t){let r=`onnx/${e}${t.quantized?"_quantized":""}.onnx`,o=await getModelFile(s,r,!0,t);try{return await InferenceSession.create(o,{executionProviders})}catch(c){if(executionProviders.length===1&&executionProviders[0]==="wasm")throw c;return console.warn(c),console.warn("Something went wrong during model construction (most likely a missing operation). Using `wasm` as a fallback. "),await InferenceSession.create(o,{executionProviders:["wasm"]})}}function validateInputs(s,e){const t=Object.create(null),r=[];for(const l of s.inputNames){const h=e[l];if(!(h instanceof Tensor)){r.push(l);continue}t[l]=env.wasm.proxy?h.clone():h}if(r.length>0)throw new Error(`An error occurred during model execution: "Missing the following inputs: ${r.join(", ")}.`);const o=Object.keys(e).length,c=s.inputNames.length;if(o>c){let l=Object.keys(e).filter(h=>!s.inputNames.includes(h));console.warn(`WARNING: Too many inputs were provided (${o} > ${c}). The following inputs will be ignored: "${l.join(", ")}".`)}return t}async function sessionRun(s,e){const t=validateInputs(s,e);try{let r=await s.run(t);return r=replaceTensors(r),r}catch(r){throw console.error(`An error occurred during model execution: "${r}".`),console.error("Inputs given to model:",t),r}}function replaceTensors(s){for(let e in s)s[e]instanceof ONNXTensor?s[e]=new Tensor(s[e]):typeof s[e]=="object"&&replaceTensors(s[e]);return s}function toI64Tensor(s){if(s instanceof Tensor)return s;if(s.length===0)throw Error("items must be non-empty");if(Array.isArray(s[0])){if(s.some(e=>e.length!==s[0].length))throw Error("Unable to create tensor, you should probably activate truncation and/or padding with 'padding=True' and/or 'truncation=True' to have batched tensors with the same length.");return new Tensor("int64",BigInt64Array.from(s.flat().map(e=>BigInt(e))),[s.length,s[0].length])}else return new Tensor("int64",BigInt64Array.from(s.map(e=>BigInt(e))),[1,s.length])}function prepareAttentionMask(s,e){let t=s.config.pad_token_id??null,r=s.config.eos_token_id??null;isIntegralNumber(r)&&(r=[r]);let o=e.indexOf(t)!==-1,c=r===null||!r.includes(t);if(o&&c){let l=BigInt64Array.from(e.data.map(h=>h!=t));return new Tensor("int64",l,e.dims)}else return ones_like(e)}function preparePositionIds(s,e,t){if(!s.inputNames.includes("position_ids"))return;const r=new BigInt64Array(e.attention_mask.data.length);for(let o=0;o0&&o.push(new NoRepeatNGramLogitsProcessor(e.no_repeat_ngram_size)),e.bad_words_ids!==null&&o.push(new NoBadWordsLogitsProcessor(e.bad_words_ids,e.eos_token_id)),e.min_length!==null&&e.eos_token_id!==null&&e.min_length>0&&o.push(new MinLengthLogitsProcessor(e.min_length,e.eos_token_id)),e.min_new_tokens!==null&&e.eos_token_id!==null&&e.min_new_tokens>0&&o.push(new MinNewTokensLengthLogitsProcessor(t,e.min_new_tokens,e.eos_token_id)),e.forced_bos_token_id!==null&&o.push(new ForcedBOSTokenLogitsProcessor(e.forced_bos_token_id)),e.forced_eos_token_id!==null&&o.push(new ForcedEOSTokenLogitsProcessor(e.max_length,e.forced_eos_token_id)),e.begin_suppress_tokens!==null){let c=t>1||e.forced_bos_token_id===null?t:t+1;e.forced_decoder_ids!==null&&(c+=e.forced_decoder_ids[e.forced_decoder_ids.length-1][0]),o.push(new SuppressTokensAtBeginLogitsProcessor(e.begin_suppress_tokens,c))}return e.forced_decoder_ids!==null&&o.push(new ForceTokensLogitsProcessor(e.forced_decoder_ids)),r!==null&&o.extend(r),o}_get_generation_config(e){let t=new GenerationConfig(this.config);return"generation_config"in this&&Object.assign(t,this.generation_config),e!==null&&Object.assign(t,e),t}async generate(e,t=null,r=null,{inputs_attention_mask:o=null}={}){if(!this.can_generate){let g=`The current model class (${MODEL_CLASS_TO_NAME_MAPPING.get(this.constructor)}) is not compatible with \`.generate()\`, as it doesn't have a language model head.`;const _=this.config.model_type,b=MODEL_WITH_LM_HEAD_MAPPING_NAMES.get(_)??MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES.get(_)??MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES.get(_)??MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES.get(_);throw b&&(g+=` Please use the following class instead: '${b[0]}'`),Error(g)}if(!(e instanceof Tensor)&&!isTypedArray(e)&&!Array.isArray(e))throw Error(`\`inputs\` must be a Tensor, TypedArray, or Array, but is "${e.constructor.name}".`);let c;if(this.config.is_encoder_decoder)c=0;else if(c=e instanceof Tensor?e.dims.at(-1):e.length,c===0)throw Error("Must supply a non-empty array of input token ids.");t=this._get_generation_config(t),r=r??new LogitsProcessorList,r=this._get_logits_processor(t,c,r);let l=t.eos_token_id;l!==null&&!Array.isArray(l)&&(l=[l]);let h=1;const p=h+(t.max_new_tokens??1/0),f=Number.isInteger(t.max_length)&&(t.max_new_tokens??null)===null;let d=Sampler.getSampler(t),i=this.getStartBeams(e,t,h,o);for(;i.some(m=>!m.done)&&h=t.max_length){g.done=!0,m.push(g);continue}let _=await this.runBeam(g);t.output_attentions&&this.addAttentionsToBeam(g,_),t.output_scores;let b=_.logits.slice(null,-1,null);r(g.output_token_ids,b);let y=d(b);for(let[v,x]of y){let w={...g};this.updateBeam(w,v),w.score+=x,l&&l.includes(v)&&(w.done=!0),m.push(w)}}++h,m=this.groupBeams(m).map(g=>g.sort((_,b)=>b.score-_.score).slice(0,t.num_beams)),i=m.flat(),t.callback_function&&t.callback_function(i)}const n=this.groupBeams(i),a=m=>n.map(g=>t.num_return_sequences>1?g.slice(0,t.num_return_sequences).map(_=>_[m]):[g[0][m]]).flat(),u=a("output_token_ids");if(t.return_dict_in_generate){const m=a("decoder_attentions"),g=a("cross_attentions");return{sequences:u,decoder_attentions:m,cross_attentions:g}}else return u}addAttentionsToBeam(e,t){if(this.config.is_encoder_decoder){if(!t.cross_attentions||t.cross_attentions.length===0)throw Error("`output_attentions` is true, but the model did not produce cross-attentions. This is most likely because the model was not exported with `output_attentions=True`.");e.cross_attentions||(e.cross_attentions=[]),e.cross_attentions.push(t.cross_attentions)}if(!t.decoder_attentions||t.decoder_attentions.length===0)throw Error("`output_attentions` is true, but the model did not produce decoder-attentions. This is most likely because the model was not exported with `output_attentions=True`.");e.decoder_attentions||(e.decoder_attentions=[]),e.decoder_attentions.push(t.decoder_attentions)}groupBeams(e){const t=Object.create(null);for(const r of e)t[r.id]===void 0?t[r.id]=[r]:t[r.id].push(r);return Object.values(t)}getPastKeyValues(e,t){const r=Object.create(null);for(const o in e)if(o.startsWith("present")){let c=o.replace("present","past_key_values");t&&o.includes("encoder")?r[c]=t[c]:r[c]=e[o]}return r}getAttentions(e){const t=Object.create(null);for(const r of["cross_attentions","decoder_attentions"]){const o=[];for(const c in e)if(c.startsWith(r)){const l=c.split(".").pop();o[l]=e[c]}t[r]=o}return t}addPastKeyValues(e,t){if(t)Object.assign(e,t);else if(this.config.is_encoder_decoder&&(this.add_encoder_pkv??!0)){let o=[1,this.num_encoder_heads,0,this.encoder_dim_kv],c=[1,this.num_decoder_heads,0,this.decoder_dim_kv];for(let l=0;l{let d=Array.from({length:this.config.decoder_layers},(g,_)=>cat(f.map(b=>b[_]),2)),i=stack(t.map(([g,_])=>r?d[g].slice(null,_,null,[0,r]):d[g].slice(null,_)));i=i.transpose(1,0,2,3);let[n,a]=std_mean(i,-2,0,!0),u=i.clone();for(let g=0;gi[_+1]-i[_]),u=mergeArrays([1],a).map(g=>!!g),m=[];for(let g=0;go*c,1);e.input_labels=new Tensor("int64",new BigInt64Array(r).fill(1n),t)}return await sessionRun(this.prompt_encoder_mask_decoder,{input_points:e.input_points,input_labels:e.input_labels,image_embeddings:e.image_embeddings,image_positional_embeddings:e.image_positional_embeddings})}async _call(e){return new SamImageSegmentationOutput(await super._call(e))}}class SamImageSegmentationOutput extends ModelOutput{constructor({iou_scores:e,pred_masks:t}){super(),this.iou_scores=e,this.pred_masks=t}}class MarianPreTrainedModel extends PreTrainedModel{}class MarianModel extends MarianPreTrainedModel{}class MarianMTModel extends MarianPreTrainedModel{constructor(e,t,r,o){super(e,t),this.decoder_merged_session=r,this.generation_config=o,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.d_model/this.num_encoder_heads}}class M2M100PreTrainedModel extends PreTrainedModel{}class M2M100Model extends M2M100PreTrainedModel{}class M2M100ForConditionalGeneration extends M2M100PreTrainedModel{constructor(e,t,r,o){super(e,t),this.decoder_merged_session=r,this.generation_config=o,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.d_model/this.num_encoder_heads}}class Wav2Vec2PreTrainedModel extends PreTrainedModel{}class Wav2Vec2Model extends Wav2Vec2PreTrainedModel{}class Wav2Vec2ForCTC extends Wav2Vec2PreTrainedModel{async _call(e){return new CausalLMOutput(await super._call(e))}}class Wav2Vec2ForSequenceClassification extends Wav2Vec2PreTrainedModel{async _call(e){return new SequenceClassifierOutput(await super._call(e))}}class HubertModel extends Wav2Vec2PreTrainedModel{}class HubertForCTC extends Wav2Vec2PreTrainedModel{async _call(e){return new CausalLMOutput(await super._call(e))}}class HubertForSequenceClassification extends Wav2Vec2PreTrainedModel{async _call(e){return new SequenceClassifierOutput(await super._call(e))}}class WavLMPreTrainedModel extends PreTrainedModel{}class WavLMModel extends WavLMPreTrainedModel{}class WavLMForCTC extends WavLMPreTrainedModel{async _call(e){return new CausalLMOutput(await super._call(e))}}class WavLMForSequenceClassification extends WavLMPreTrainedModel{async _call(e){return new SequenceClassifierOutput(await super._call(e))}}class SpeechT5PreTrainedModel extends PreTrainedModel{}class SpeechT5ForSpeechToText extends SpeechT5PreTrainedModel{}class SpeechT5ForTextToSpeech extends SpeechT5PreTrainedModel{constructor(e,t,r,o){super(e,t),this.decoder_merged_session=r,this.generation_config=o,this.num_decoder_layers=this.config.decoder_layers,this.num_decoder_heads=this.config.decoder_attention_heads,this.decoder_dim_kv=this.config.hidden_size/this.num_decoder_heads,this.num_encoder_layers=this.config.encoder_layers,this.num_encoder_heads=this.config.encoder_attention_heads,this.encoder_dim_kv=this.config.hidden_size/this.num_encoder_heads}async generate_speech(e,t,{threshold:r=.5,minlenratio:o=0,maxlenratio:c=20,vocoder:l=null}={}){const h={input_ids:e},{encoder_outputs:p,encoder_attention_mask:f}=await encoderForward(this,h),d=p.dims[1]/this.config.reduction_factor,i=Math.floor(d*c),n=Math.floor(d*o),a=this.config.num_mel_bins;let u=[],m=null,g=null,_=0;for(;;){++_;const v=boolTensor(!!g);let x;g?x=g.output_sequence_out:x=new Tensor("float32",new Float32Array(a),[1,1,a]);let w={use_cache_branch:v,output_sequence:x,encoder_attention_mask:f,speaker_embeddings:t,encoder_hidden_states:p};this.addPastKeyValues(w,m),g=await sessionRun(this.decoder_merged_session,w),m=this.getPastKeyValues(g,m);const{prob:S,spectrum:M}=g;if(u.push(M),_>=n&&(Array.from(S.data).filter(T=>T>=r).length>0||_>=i))break}const b=cat(u),{waveform:y}=await sessionRun(l.session,{spectrogram:b});return{spectrogram:b,waveform:y}}}class SpeechT5HifiGan extends PreTrainedModel{main_input_name="spectrogram"}class TrOCRPreTrainedModel extends PreTrainedModel{constructor(e,t,r){super(e,t),this.generation_config=r,this.config.pad_token_id=this.config.eos_token_id,this.num_encoder_layers=this.num_decoder_layers=this.config.decoder_layers,this.num_encoder_heads=this.num_decoder_heads=this.config.decoder_attention_heads,this.encoder_dim_kv=this.decoder_dim_kv=this.config.d_model/this.num_decoder_heads}}class TrOCRForCausalLM extends TrOCRPreTrainedModel{}class MistralPreTrainedModel extends PreTrainedModel{constructor(e,t,r){super(e,t),this.generation_config=r,this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.num_key_value_heads,this.num_layers=this.config.num_hidden_layers,this.dim_kv=this.config.hidden_size/this.config.num_attention_heads}}class MistralModel extends MistralPreTrainedModel{}class MistralForCausalLM extends MistralPreTrainedModel{}class FalconPreTrainedModel extends PreTrainedModel{constructor(e,t,r){super(e,t),this.generation_config=r,this.config.pad_token_id=this.config.eos_token_id,this.num_heads=this.config.num_attention_heads,this.num_layers=this.config.num_hidden_layers,this.dim_kv=this.config.hidden_size/this.config.num_attention_heads}}class FalconModel extends FalconPreTrainedModel{}class FalconForCausalLM extends FalconPreTrainedModel{}class ClapPreTrainedModel extends PreTrainedModel{}class ClapModel extends ClapPreTrainedModel{}class ClapTextModelWithProjection extends ClapPreTrainedModel{static async from_pretrained(e,t={}){return t.model_file_name??="text_model",super.from_pretrained(e,t)}}class ClapAudioModelWithProjection extends ClapPreTrainedModel{static async from_pretrained(e,t={}){return t.model_file_name??="audio_model",super.from_pretrained(e,t)}}class VitsPreTrainedModel extends PreTrainedModel{}class VitsModel extends VitsPreTrainedModel{async _call(e){return new VitsModelOutput(await super._call(e))}}class SegformerPreTrainedModel extends PreTrainedModel{}class SegformerForImageClassification extends SegformerPreTrainedModel{}class SegformerForSemanticSegmentation extends SegformerPreTrainedModel{}class PretrainedMixin{static MODEL_CLASS_MAPPINGS=null;static BASE_IF_FAIL=!1;static async from_pretrained(e,{quantized:t=!0,progress_callback:r=null,config:o=null,cache_dir:c=null,local_files_only:l=!1,revision:h="main",model_file_name:p=null}={}){let f={quantized:t,progress_callback:r,config:o,cache_dir:c,local_files_only:l,revision:h,model_file_name:p};if(o=await AutoConfig.from_pretrained(e,f),f.config||(f.config=o),!this.MODEL_CLASS_MAPPINGS)throw new Error("`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: "+this.name);for(let d of this.MODEL_CLASS_MAPPINGS){const i=d.get(o.model_type);if(i)return await i[1].from_pretrained(e,f)}if(this.BASE_IF_FAIL)return console.warn(`Unknown model class "${o.model_type}", attempting to construct from base class.`),await PreTrainedModel.from_pretrained(e,f);throw Error(`Unsupported model type: ${o.model_type}`)}}const MODEL_MAPPING_NAMES_ENCODER_ONLY=new Map([["bert",["BertModel",BertModel]],["roformer",["RoFormerModel",RoFormerModel]],["electra",["ElectraModel",ElectraModel]],["esm",["EsmModel",EsmModel]],["convbert",["ConvBertModel",ConvBertModel]],["camembert",["CamembertModel",CamembertModel]],["deberta",["DebertaModel",DebertaModel]],["deberta-v2",["DebertaV2Model",DebertaV2Model]],["mpnet",["MPNetModel",MPNetModel]],["albert",["AlbertModel",AlbertModel]],["distilbert",["DistilBertModel",DistilBertModel]],["roberta",["RobertaModel",RobertaModel]],["xlm",["XLMModel",XLMModel]],["xlm-roberta",["XLMRobertaModel",XLMRobertaModel]],["clap",["ClapModel",ClapModel]],["clip",["CLIPModel",CLIPModel]],["clipseg",["CLIPSegModel",CLIPSegModel]],["chinese_clip",["ChineseCLIPModel",ChineseCLIPModel]],["siglip",["SiglipModel",SiglipModel]],["mobilebert",["MobileBertModel",MobileBertModel]],["squeezebert",["SqueezeBertModel",SqueezeBertModel]],["wav2vec2",["Wav2Vec2Model",Wav2Vec2Model]],["hubert",["HubertModel",HubertModel]],["wavlm",["WavLMModel",WavLMModel]],["audio-spectrogram-transformer",["ASTModel",ASTModel]],["vits",["VitsModel",VitsModel]],["detr",["DetrModel",DetrModel]],["table-transformer",["TableTransformerModel",TableTransformerModel]],["vit",["ViTModel",ViTModel]],["mobilevit",["MobileViTModel",MobileViTModel]],["owlvit",["OwlViTModel",OwlViTModel]],["beit",["BeitModel",BeitModel]],["deit",["DeiTModel",DeiTModel]],["convnext",["ConvNextModel",ConvNextModel]],["convnextv2",["ConvNextV2Model",ConvNextV2Model]],["dinov2",["Dinov2Model",Dinov2Model]],["resnet",["ResNetModel",ResNetModel]],["swin",["SwinModel",SwinModel]],["swin2sr",["Swin2SRModel",Swin2SRModel]],["donut-swin",["DonutSwinModel",DonutSwinModel]],["yolos",["YolosModel",YolosModel]],["dpt",["DPTModel",DPTModel]],["glpn",["GLPNModel",GLPNModel]],["hifigan",["SpeechT5HifiGan",SpeechT5HifiGan]]]),MODEL_MAPPING_NAMES_ENCODER_DECODER=new Map([["t5",["T5Model",T5Model]],["longt5",["LongT5Model",LongT5Model]],["mt5",["MT5Model",MT5Model]],["bart",["BartModel",BartModel]],["mbart",["MBartModel",MBartModel]],["marian",["MarianModel",MarianModel]],["whisper",["WhisperModel",WhisperModel]],["m2m_100",["M2M100Model",M2M100Model]],["blenderbot",["BlenderbotModel",BlenderbotModel]],["blenderbot-small",["BlenderbotSmallModel",BlenderbotSmallModel]]]),MODEL_MAPPING_NAMES_DECODER_ONLY=new Map([["bloom",["BloomModel",BloomModel]],["gpt2",["GPT2Model",GPT2Model]],["gptj",["GPTJModel",GPTJModel]],["gpt_bigcode",["GPTBigCodeModel",GPTBigCodeModel]],["gpt_neo",["GPTNeoModel",GPTNeoModel]],["gpt_neox",["GPTNeoXModel",GPTNeoXModel]],["codegen",["CodeGenModel",CodeGenModel]],["llama",["LlamaModel",LlamaModel]],["phi",["PhiModel",PhiModel]],["mpt",["MptModel",MptModel]],["opt",["OPTModel",OPTModel]],["mistral",["MistralModel",MistralModel]],["falcon",["FalconModel",FalconModel]]]),MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES=new Map([["speecht5",["SpeechT5ForSpeechToText",SpeechT5ForSpeechToText]],["whisper",["WhisperForConditionalGeneration",WhisperForConditionalGeneration]]]),MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES=new Map([["speecht5",["SpeechT5ForTextToSpeech",SpeechT5ForTextToSpeech]]]),MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES=new Map([["vits",["VitsModel",VitsModel]]]),MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES=new Map([["bert",["BertForSequenceClassification",BertForSequenceClassification]],["roformer",["RoFormerForSequenceClassification",RoFormerForSequenceClassification]],["electra",["ElectraForSequenceClassification",ElectraForSequenceClassification]],["esm",["EsmForSequenceClassification",EsmForSequenceClassification]],["convbert",["ConvBertForSequenceClassification",ConvBertForSequenceClassification]],["camembert",["CamembertForSequenceClassification",CamembertForSequenceClassification]],["deberta",["DebertaForSequenceClassification",DebertaForSequenceClassification]],["deberta-v2",["DebertaV2ForSequenceClassification",DebertaV2ForSequenceClassification]],["mpnet",["MPNetForSequenceClassification",MPNetForSequenceClassification]],["albert",["AlbertForSequenceClassification",AlbertForSequenceClassification]],["distilbert",["DistilBertForSequenceClassification",DistilBertForSequenceClassification]],["roberta",["RobertaForSequenceClassification",RobertaForSequenceClassification]],["xlm",["XLMForSequenceClassification",XLMForSequenceClassification]],["xlm-roberta",["XLMRobertaForSequenceClassification",XLMRobertaForSequenceClassification]],["bart",["BartForSequenceClassification",BartForSequenceClassification]],["mbart",["MBartForSequenceClassification",MBartForSequenceClassification]],["mobilebert",["MobileBertForSequenceClassification",MobileBertForSequenceClassification]],["squeezebert",["SqueezeBertForSequenceClassification",SqueezeBertForSequenceClassification]]]),MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES=new Map([["bert",["BertForTokenClassification",BertForTokenClassification]],["roformer",["RoFormerForTokenClassification",RoFormerForTokenClassification]],["electra",["ElectraForTokenClassification",ElectraForTokenClassification]],["esm",["EsmForTokenClassification",EsmForTokenClassification]],["convbert",["ConvBertForTokenClassification",ConvBertForTokenClassification]],["camembert",["CamembertForTokenClassification",CamembertForTokenClassification]],["deberta",["DebertaForTokenClassification",DebertaForTokenClassification]],["deberta-v2",["DebertaV2ForTokenClassification",DebertaV2ForTokenClassification]],["mpnet",["MPNetForTokenClassification",MPNetForTokenClassification]],["distilbert",["DistilBertForTokenClassification",DistilBertForTokenClassification]],["roberta",["RobertaForTokenClassification",RobertaForTokenClassification]],["xlm",["XLMForTokenClassification",XLMForTokenClassification]],["xlm-roberta",["XLMRobertaForTokenClassification",XLMRobertaForTokenClassification]]]),MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES=new Map([["t5",["T5ForConditionalGeneration",T5ForConditionalGeneration]],["longt5",["LongT5ForConditionalGeneration",LongT5ForConditionalGeneration]],["mt5",["MT5ForConditionalGeneration",MT5ForConditionalGeneration]],["bart",["BartForConditionalGeneration",BartForConditionalGeneration]],["mbart",["MBartForConditionalGeneration",MBartForConditionalGeneration]],["marian",["MarianMTModel",MarianMTModel]],["m2m_100",["M2M100ForConditionalGeneration",M2M100ForConditionalGeneration]],["blenderbot",["BlenderbotForConditionalGeneration",BlenderbotForConditionalGeneration]],["blenderbot-small",["BlenderbotSmallForConditionalGeneration",BlenderbotSmallForConditionalGeneration]]]),MODEL_WITH_LM_HEAD_MAPPING_NAMES=new Map([["bloom",["BloomForCausalLM",BloomForCausalLM]],["gpt2",["GPT2LMHeadModel",GPT2LMHeadModel]],["gptj",["GPTJForCausalLM",GPTJForCausalLM]],["gpt_bigcode",["GPTBigCodeForCausalLM",GPTBigCodeForCausalLM]],["gpt_neo",["GPTNeoForCausalLM",GPTNeoForCausalLM]],["gpt_neox",["GPTNeoXForCausalLM",GPTNeoXForCausalLM]],["codegen",["CodeGenForCausalLM",CodeGenForCausalLM]],["llama",["LlamaForCausalLM",LlamaForCausalLM]],["phi",["PhiForCausalLM",PhiForCausalLM]],["mpt",["MptForCausalLM",MptForCausalLM]],["opt",["OPTForCausalLM",OPTForCausalLM]],["mbart",["MBartForCausalLM",MBartForCausalLM]],["mistral",["MistralForCausalLM",MistralForCausalLM]],["falcon",["FalconForCausalLM",FalconForCausalLM]],["trocr",["TrOCRForCausalLM",TrOCRForCausalLM]]]),MODEL_FOR_MASKED_LM_MAPPING_NAMES=new Map([["bert",["BertForMaskedLM",BertForMaskedLM]],["roformer",["RoFormerForMaskedLM",RoFormerForMaskedLM]],["electra",["ElectraForMaskedLM",ElectraForMaskedLM]],["esm",["EsmForMaskedLM",EsmForMaskedLM]],["convbert",["ConvBertForMaskedLM",ConvBertForMaskedLM]],["camembert",["CamembertForMaskedLM",CamembertForMaskedLM]],["deberta",["DebertaForMaskedLM",DebertaForMaskedLM]],["deberta-v2",["DebertaV2ForMaskedLM",DebertaV2ForMaskedLM]],["mpnet",["MPNetForMaskedLM",MPNetForMaskedLM]],["albert",["AlbertForMaskedLM",AlbertForMaskedLM]],["distilbert",["DistilBertForMaskedLM",DistilBertForMaskedLM]],["roberta",["RobertaForMaskedLM",RobertaForMaskedLM]],["xlm",["XLMWithLMHeadModel",XLMWithLMHeadModel]],["xlm-roberta",["XLMRobertaForMaskedLM",XLMRobertaForMaskedLM]],["mobilebert",["MobileBertForMaskedLM",MobileBertForMaskedLM]],["squeezebert",["SqueezeBertForMaskedLM",SqueezeBertForMaskedLM]]]),MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES=new Map([["bert",["BertForQuestionAnswering",BertForQuestionAnswering]],["roformer",["RoFormerForQuestionAnswering",RoFormerForQuestionAnswering]],["electra",["ElectraForQuestionAnswering",ElectraForQuestionAnswering]],["convbert",["ConvBertForQuestionAnswering",ConvBertForQuestionAnswering]],["camembert",["CamembertForQuestionAnswering",CamembertForQuestionAnswering]],["deberta",["DebertaForQuestionAnswering",DebertaForQuestionAnswering]],["deberta-v2",["DebertaV2ForQuestionAnswering",DebertaV2ForQuestionAnswering]],["mpnet",["MPNetForQuestionAnswering",MPNetForQuestionAnswering]],["albert",["AlbertForQuestionAnswering",AlbertForQuestionAnswering]],["distilbert",["DistilBertForQuestionAnswering",DistilBertForQuestionAnswering]],["roberta",["RobertaForQuestionAnswering",RobertaForQuestionAnswering]],["xlm",["XLMForQuestionAnswering",XLMForQuestionAnswering]],["xlm-roberta",["XLMRobertaForQuestionAnswering",XLMRobertaForQuestionAnswering]],["mobilebert",["MobileBertForQuestionAnswering",MobileBertForQuestionAnswering]],["squeezebert",["SqueezeBertForQuestionAnswering",SqueezeBertForQuestionAnswering]]]),MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES=new Map([["vision-encoder-decoder",["VisionEncoderDecoderModel",VisionEncoderDecoderModel]]]),MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES=new Map([["vision-encoder-decoder",["VisionEncoderDecoderModel",VisionEncoderDecoderModel]]]),MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES=new Map([["vit",["ViTForImageClassification",ViTForImageClassification]],["mobilevit",["MobileViTForImageClassification",MobileViTForImageClassification]],["beit",["BeitForImageClassification",BeitForImageClassification]],["deit",["DeiTForImageClassification",DeiTForImageClassification]],["convnext",["ConvNextForImageClassification",ConvNextForImageClassification]],["convnextv2",["ConvNextV2ForImageClassification",ConvNextV2ForImageClassification]],["dinov2",["Dinov2ForImageClassification",Dinov2ForImageClassification]],["resnet",["ResNetForImageClassification",ResNetForImageClassification]],["swin",["SwinForImageClassification",SwinForImageClassification]],["segformer",["SegformerForImageClassification",SegformerForImageClassification]]]),MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES=new Map([["detr",["DetrForObjectDetection",DetrForObjectDetection]],["table-transformer",["TableTransformerForObjectDetection",TableTransformerForObjectDetection]],["yolos",["YolosForObjectDetection",YolosForObjectDetection]]]),MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES=new Map([["owlvit",["OwlViTForObjectDetection",OwlViTForObjectDetection]]]),MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES=new Map([["detr",["DetrForSegmentation",DetrForSegmentation]],["clipseg",["CLIPSegForImageSegmentation",CLIPSegForImageSegmentation]]]),MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES=new Map([["segformer",["SegformerForSemanticSegmentation",SegformerForSemanticSegmentation]]]),MODEL_FOR_MASK_GENERATION_MAPPING_NAMES=new Map([["sam",["SamModel",SamModel]]]),MODEL_FOR_CTC_MAPPING_NAMES=new Map([["wav2vec2",["Wav2Vec2ForCTC",Wav2Vec2ForCTC]],["wavlm",["WavLMForCTC",WavLMForCTC]],["hubert",["HubertForCTC",HubertForCTC]]]),MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES=new Map([["wav2vec2",["Wav2Vec2ForSequenceClassification",Wav2Vec2ForSequenceClassification]],["wavlm",["WavLMForSequenceClassification",WavLMForSequenceClassification]],["hubert",["HubertForSequenceClassification",HubertForSequenceClassification]],["audio-spectrogram-transformer",["ASTForAudioClassification",ASTForAudioClassification]]]),MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES=new Map([["vitmatte",["VitMatteForImageMatting",VitMatteForImageMatting]]]),MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES=new Map([["swin2sr",["Swin2SRForImageSuperResolution",Swin2SRForImageSuperResolution]]]),MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES=new Map([["dpt",["DPTForDepthEstimation",DPTForDepthEstimation]],["depth_anything",["DepthAnythingForDepthEstimation",DepthAnythingForDepthEstimation]],["glpn",["GLPNForDepthEstimation",GLPNForDepthEstimation]]]),MODEL_CLASS_TYPE_MAPPING=[[MODEL_MAPPING_NAMES_ENCODER_ONLY,MODEL_TYPES.EncoderOnly],[MODEL_MAPPING_NAMES_ENCODER_DECODER,MODEL_TYPES.EncoderDecoder],[MODEL_MAPPING_NAMES_DECODER_ONLY,MODEL_TYPES.DecoderOnly],[MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES,MODEL_TYPES.Seq2Seq],[MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES,MODEL_TYPES.Seq2Seq],[MODEL_WITH_LM_HEAD_MAPPING_NAMES,MODEL_TYPES.DecoderOnly],[MODEL_FOR_MASKED_LM_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,MODEL_TYPES.Vision2Seq],[MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_IMAGE_MATTING_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_MASK_GENERATION_MAPPING_NAMES,MODEL_TYPES.MaskGeneration],[MODEL_FOR_CTC_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES,MODEL_TYPES.EncoderOnly],[MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES,MODEL_TYPES.Seq2Seq],[MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES,MODEL_TYPES.EncoderOnly]];for(const[s,e]of MODEL_CLASS_TYPE_MAPPING)for(const[t,r]of s.values())MODEL_TYPE_MAPPING.set(t,e),MODEL_CLASS_TO_NAME_MAPPING.set(r,t),MODEL_NAME_TO_CLASS_MAPPING.set(t,r);const CUSTOM_MAPPING=[["CLIPTextModelWithProjection",CLIPTextModelWithProjection,MODEL_TYPES.EncoderOnly],["CLIPVisionModelWithProjection",CLIPVisionModelWithProjection,MODEL_TYPES.EncoderOnly],["SiglipTextModel",SiglipTextModel,MODEL_TYPES.EncoderOnly],["SiglipVisionModel",SiglipVisionModel,MODEL_TYPES.EncoderOnly],["ClapTextModelWithProjection",ClapTextModelWithProjection,MODEL_TYPES.EncoderOnly],["ClapAudioModelWithProjection",ClapAudioModelWithProjection,MODEL_TYPES.EncoderOnly]];for(const[s,e,t]of CUSTOM_MAPPING)MODEL_TYPE_MAPPING.set(s,t),MODEL_CLASS_TO_NAME_MAPPING.set(e,s),MODEL_NAME_TO_CLASS_MAPPING.set(s,e);class AutoModel extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=MODEL_CLASS_TYPE_MAPPING.map(e=>e[0]);static BASE_IF_FAIL=!0}class AutoModelForSequenceClassification extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES]}class AutoModelForTokenClassification extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES]}class AutoModelForSeq2SeqLM extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES]}class AutoModelForSpeechSeq2Seq extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES]}class AutoModelForTextToSpectrogram extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_TEXT_TO_SPECTROGRAM_MAPPING_NAMES]}class AutoModelForTextToWaveform extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_TEXT_TO_WAVEFORM_MAPPING_NAMES]}class AutoModelForCausalLM extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_WITH_LM_HEAD_MAPPING_NAMES]}class AutoModelForMaskedLM extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_MASKED_LM_MAPPING_NAMES]}class AutoModelForQuestionAnswering extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES]}class AutoModelForVision2Seq extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES]}class AutoModelForImageClassification extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES]}class AutoModelForImageSegmentation extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES]}class AutoModelForSemanticSegmentation extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES]}class AutoModelForObjectDetection extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES]}class AutoModelForZeroShotObjectDetection extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES]}class AutoModelForCTC extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_CTC_MAPPING_NAMES]}class AutoModelForAudioClassification extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES]}class AutoModelForDocumentQuestionAnswering extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES]}class AutoModelForImageToImage extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_IMAGE_TO_IMAGE_MAPPING_NAMES]}class AutoModelForDepthEstimation extends PretrainedMixin{static MODEL_CLASS_MAPPINGS=[MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES]}class Seq2SeqLMOutput extends ModelOutput{constructor({logits:e,past_key_values:t,encoder_outputs:r,decoder_attentions:o=null,cross_attentions:c=null}){super(),this.logits=e,this.past_key_values=t,this.encoder_outputs=r,this.decoder_attentions=o,this.cross_attentions=c}}class SequenceClassifierOutput extends ModelOutput{constructor({logits:e}){super(),this.logits=e}}class TokenClassifierOutput extends ModelOutput{constructor({logits:e}){super(),this.logits=e}}class MaskedLMOutput extends ModelOutput{constructor({logits:e}){super(),this.logits=e}}class QuestionAnsweringModelOutput extends ModelOutput{constructor({start_logits:e,end_logits:t}){super(),this.start_logits=e,this.end_logits=t}}class CausalLMOutput extends ModelOutput{constructor({logits:e}){super(),this.logits=e}}class ImageMattingOutput extends ModelOutput{constructor({alphas:e}){super(),this.alphas=e}}class VitsModelOutput extends ModelOutput{constructor({waveform:e,spectrogram:t}){super(),this.waveform=e,this.spectrogram=t}}const BROWSER_ENV=typeof self<"u",WEBWORKER_ENV=BROWSER_ENV&&self.constructor.name==="DedicatedWorkerGlobalScope";let createCanvasFunction,ImageDataClass,loadImageFunction;if(BROWSER_ENV)createCanvasFunction=(s,e)=>{if(!self.OffscreenCanvas)throw new Error("OffscreenCanvas not supported by this browser.");return new self.OffscreenCanvas(s,e)},loadImageFunction=self.createImageBitmap,ImageDataClass=self.ImageData;else if(sharp)loadImageFunction=async s=>{const t=(await s.metadata()).channels;let{data:r,info:o}=await s.raw().toBuffer({resolveWithObject:!0});const c=new RawImage(new Uint8ClampedArray(r),o.width,o.height,o.channels);return t!==void 0&&t!==o.channels&&c.convert(t),c};else throw new Error("Unable to load image processing library.");const RESAMPLING_MAPPING={0:"nearest",1:"lanczos",2:"bilinear",3:"bicubic",4:"box",5:"hamming"},CONTENT_TYPE_MAP=new Map([["png","image/png"],["jpg","image/jpeg"],["jpeg","image/jpeg"],["gif","image/gif"]]);class RawImage{constructor(e,t,r,o){this.data=e,this.width=t,this.height=r,this.channels=o}get size(){return[this.width,this.height]}static async read(e){if(e instanceof RawImage)return e;if(typeof e=="string"||e instanceof URL)return await this.fromURL(e);throw new Error(`Unsupported input type: ${typeof e}`)}static async fromURL(e){let t=await getFile(e);if(t.status!==200)throw new Error(`Unable to read image from "${e}" (${t.status} ${t.statusText})`);let r=await t.blob();return this.fromBlob(r)}static async fromBlob(e){if(BROWSER_ENV){let t=await loadImageFunction(e);const r=createCanvasFunction(t.width,t.height).getContext("2d");return r.drawImage(t,0,0),new this(r.getImageData(0,0,t.width,t.height).data,t.width,t.height,4)}else{let t=sharp(await e.arrayBuffer());return await loadImageFunction(t)}}static fromTensor(e,t="CHW"){if(e.dims.length!==3)throw new Error(`Tensor should have 3 dimensions, but has ${e.dims.length} dimensions.`);if(t==="CHW")e=e.transpose(1,2,0);else if(t!=="HWC")throw new Error(`Unsupported channel format: ${t}`);if(!(e.data instanceof Uint8ClampedArray||e.data instanceof Uint8Array))throw new Error(`Unsupported tensor type: ${e.type}`);switch(e.dims[2]){case 1:case 2:case 3:case 4:return new RawImage(e.data,e.dims[1],e.dims[0],e.dims[2]);default:throw new Error(`Unsupported number of channels: ${e.dims[2]}`)}}grayscale(){if(this.channels===1)return this;let e=new Uint8ClampedArray(this.width*this.height*1);switch(this.channels){case 3:case 4:for(let t=0,r=0;t=0?p=r:d=-r,o>=0?f=o:i=-o,h.drawImage(l,p,f,e,t,d,i,e,t),new RawImage(h.getImageData(0,0,e,t).data,e,t,4).convert(c)}else{let c=this.toSharp();if(r>=0&&o>=0)c=c.extract({left:Math.floor(r),top:Math.floor(o),width:e,height:t});else if(r<=0&&o<=0){let l=Math.floor(-o),h=Math.floor(-r);c=c.extend({top:l,left:h,right:e-this.width-h,bottom:t-this.height-l})}else{let l=[0,0],h=0;o<0?(l[0]=Math.floor(-o),l[1]=t-this.height-l[0]):h=Math.floor(o);let p=[0,0],f=0;r<0?(p[0]=Math.floor(-r),p[1]=e-this.width-p[0]):f=Math.floor(r),c=c.extend({top:l[0],bottom:l[1],left:p[0],right:p[1]}).extract({left:f,top:h,width:e,height:t})}return await loadImageFunction(c)}}async toBlob(e="image/png",t=1){if(!BROWSER_ENV)throw new Error("toBlob() is only supported in browser environments.");return await this.toCanvas().convertToBlob({type:e,quality:t})}toCanvas(){if(!BROWSER_ENV)throw new Error("toCanvas() is only supported in browser environments.");let e=this.clone().rgba(),t=createCanvasFunction(e.width,e.height),r=new ImageDataClass(e.data,e.width,e.height);return t.getContext("2d").putImageData(r,0,0),t}_update(e,t,r,o=null){return this.data=e,this.width=t,this.height=r,o!==null&&(this.channels=o),this}clone(){return new RawImage(this.data.slice(),this.width,this.height,this.channels)}convert(e){if(this.channels===e)return this;switch(e){case 1:this.grayscale();break;case 3:this.rgb();break;case 4:this.rgba();break;default:throw new Error(`Conversion failed due to unsupported number of channels: ${this.channels}`)}return this}async save(e){if(BROWSER_ENV){if(WEBWORKER_ENV)throw new Error("Unable to save an image from a Web Worker.");const t=e.split(".").pop().toLowerCase(),r=CONTENT_TYPE_MAP.get(t)??"image/png",o=await this.toBlob(r),c=URL.createObjectURL(o),l=document.createElement("a");l.href=c,l.download=e,l.click(),l.remove()}else{if(env$1.useFS)return await this.toSharp().toFile(e);throw new Error("Unable to save the image because filesystem is disabled in this environment.")}}toSharp(){if(BROWSER_ENV)throw new Error("toSharp() is only supported in server-side environments.");return sharp(this.data,{raw:{width:this.width,height:this.height,channels:this.channels}})}}async function read_audio(s,e){if(typeof AudioContext>"u")throw Error("Unable to load audio from path/URL since `AudioContext` is not available in your environment. Instead, audio data should be passed directly to the pipeline/processor. For more information and some example code, see https://huggingface.co/docs/transformers.js/guides/node-audio-processing.");const t=await(await getFile(s)).arrayBuffer(),r=new AudioContext({sampleRate:e});typeof e>"u"&&console.warn(`No sampling rate provided, using default of ${r.sampleRate}Hz.`);const o=await r.decodeAudioData(t);let c;if(o.numberOfChannels===2){const l=Math.sqrt(2),h=o.getChannelData(0),p=o.getChannelData(1);c=new Float32Array(h.length);for(let f=0;f2595*Math.log10(1+s/700),kaldi:s=>1127*Math.log(1+s/700),slaney:(s,e=1e3,t=15,r=27/Math.log(6.4))=>s>=e?t+Math.log(s/e)*r:3*s/200};function hertz_to_mel(s,e="htk"){const t=HERTZ_TO_MEL_MAPPING[e];if(!t)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof s=="number"?t(s):s.map(r=>t(r))}const MEL_TO_HERTZ_MAPPING={htk:s=>700*(10**(s/2595)-1),kaldi:s=>700*(Math.exp(s/1127)-1),slaney:(s,e=1e3,t=15,r=Math.log(6.4)/27)=>s>=t?e*Math.exp(r*(s-t)):200*s/3};function mel_to_hertz(s,e="htk"){const t=MEL_TO_HERTZ_MAPPING[e];if(!t)throw new Error('mel_scale should be one of "htk", "slaney" or "kaldi".');return typeof s=="number"?t(s):s.map(r=>t(r))}function _create_triangular_filter_bank(s,e){const t=Float64Array.from({length:e.length-1},(l,h)=>e[h+1]-e[h]),r=Array.from({length:s.length},()=>new Array(e.length));for(let l=0;lnew Array(s.length));for(let l=0;ls+r*c)}function mel_filter_bank(s,e,t,r,o,c=null,l="htk",h=!1){if(c!==null&&c!=="slaney")throw new Error('norm must be one of null or "slaney"');const p=hertz_to_mel(t,l),f=hertz_to_mel(r,l),d=linspace(p,f,e+2);let i=mel_to_hertz(d,l),n;if(h){const u=o/(s*2);n=hertz_to_mel(Float64Array.from({length:s},(m,g)=>g*u),l),i=d}else n=linspace(0,Math.floor(o/2),s);const a=_create_triangular_filter_bank(n,i);if(c!==null&&c==="slaney")for(let u=0;uo)throw Error(`frame_length (${t}) may not be larger than fft_length (${o})`);if(v!==t)throw new Error(`Length of the window (${v}) must equal frame_length (${t})`);if(r<=0)throw new Error("hop_length must be greater than zero");if(l){if(h!=="reflect")throw new Error(`pad_mode="${h}" not implemented yet.`);const O=Math.floor((o-1)/2)+1;s=padReflect(s,O,O)}const x=Math.floor(1+Math.floor((s.length-t)/r)),w=p?Math.floor(o/2)+1:o;let S=x,M=x;_!==null&&(_>x?b&&(M=_):M=S=_);const T=new FFT(o),E=new Float64Array(o),R=new Float64Array(T.outputBufferSize),I=new Array(S);for(let O=0;O=1;--$)E[$]-=f*E[$-1];E[0]*=1-f}for(let $=0;$r)throw new Error(`Length of the window (${s}) may not be larger than frame_length (${r})`);return l}function center_to_corners_format([s,e,t,r]){return[s-t/2,e-r/2,s+t/2,e+r/2]}function post_process_object_detection(s,e=.5,t=null,r=!1){const o=s.logits,c=s.pred_boxes,[l,h,p]=o.dims;if(t!==null&&t.length!==l)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");let f=[];for(let d=0;de&&_.push(y)}else{let y=max(g.data)[1];if(y===p-1)continue;_.push(y),b=softmax(g.data)}for(const y of _){let v=u[m].data;v=center_to_corners_format(v),i!==null&&(v=v.map((x,w)=>x*i[(w+1)%2])),n.boxes.push(v),n.classes.push(y),n.scores.push(b[y])}}f.push(n)}return f}function validate_audio_inputs(s,e){if(!(s instanceof Float32Array||s instanceof Float64Array))throw new Error(`${e} expects input to be a Float32Array or a Float64Array, but got ${s?.constructor?.name??typeof s} instead.If using the feature extractor directly, remember to use \`read_audio(url, sampling_rate)\` to obtain the raw audio data of the file/url.`)}function constraint_to_multiple_of(s,e,t=0,r=null){let o=Math.round(s/e)*e;return r!==null&&o>r&&(o=Math.floor(s/e)*e),oc?f=Math.floor(c*p/o):c>o&&(p=Math.floor(o*f/c)),await e.resize(f,p,{resample:r}))}async crop_margin(e,t=200){const r=e.clone().grayscale(),o=min(r.data)[0],l=max(r.data)[0]-o;if(l===0)return e;const h=t/255;let p=r.width,f=r.height,d=0,i=0;for(let n=0;nthis.preprocess(c)));return{pixel_values:stack(r.map(c=>c.pixel_values),0),original_sizes:r.map(c=>c.original_size),reshaped_input_sizes:r.map(c=>c.reshaped_input_size)}}}class SegformerFeatureExtractor extends ImageFeatureExtractor{post_process_semantic_segmentation(e,t=null){const r=e.logits,o=r.dims[0];if(t!==null&&t.length!==o)throw Error("Make sure that you pass in as many target sizes as the batch dimension of the logits");const c=[];for(let l=0;ln[b]&&(n[b]=_[b],i.data[b]=g)}const a=new Array(p.dims[0]),u=i.data;for(let g=0;gg!==void 0);c.push({segmentation:i,labels:m})}return c}}class DPTImageProcessor extends ImageFeatureExtractor{}class BitImageProcessor extends ImageFeatureExtractor{}class DPTFeatureExtractor extends ImageFeatureExtractor{}class GLPNFeatureExtractor extends ImageFeatureExtractor{}class CLIPFeatureExtractor extends ImageFeatureExtractor{}class ChineseCLIPFeatureExtractor extends ImageFeatureExtractor{}class SiglipImageProcessor extends ImageFeatureExtractor{}class ConvNextFeatureExtractor extends ImageFeatureExtractor{constructor(e){super(e),this.crop_pct=this.config.crop_pct??224/256}async resize(e){const t=this.size?.shortest_edge;if(t===void 0)throw new Error("Size dictionary must contain 'shortest_edge' key.");if(t<384){const r=Math.floor(t/this.crop_pct),[o,c]=this.get_resize_output_image_size(e,{shortest_edge:r});e=await e.resize(o,c,{resample:this.resample}),e=await e.center_crop(t,t)}else e=await e.resize(t,t,{resample:this.resample});return e}}class ConvNextImageProcessor extends ConvNextFeatureExtractor{}class ViTFeatureExtractor extends ImageFeatureExtractor{}class ViTImageProcessor extends ImageFeatureExtractor{}class MobileViTFeatureExtractor extends ImageFeatureExtractor{}class OwlViTFeatureExtractor extends ImageFeatureExtractor{post_process_object_detection(...e){return post_process_object_detection(...e)}}class DeiTFeatureExtractor extends ImageFeatureExtractor{}class BeitFeatureExtractor extends ImageFeatureExtractor{}class DonutFeatureExtractor extends ImageFeatureExtractor{pad_image(e,t,r,o={}){const[c,l,h]=t;let p=this.image_mean;Array.isArray(this.image_mean)||(p=new Array(h).fill(p));let f=this.image_std;Array.isArray(f)||(f=new Array(h).fill(p));const d=p.map((i,n)=>-i/this.image_std[n]);return super.pad_image(e,t,r,{center:!0,constant_values:d,...o})}}class NougatImageProcessor extends DonutFeatureExtractor{}class DetrFeatureExtractor extends ImageFeatureExtractor{async _call(e){const t=await super._call(e),r=[t.pixel_values.dims[0],64,64],o=new Tensor("int64",new BigInt64Array(r.reduce((c,l)=>c*l)).fill(1n),r);return{...t,pixel_mask:o}}post_process_object_detection(...e){return post_process_object_detection(...e)}remove_low_and_no_objects(e,t,r,o){let c=[],l=[],h=[];for(let p=0;pr&&(c.push(d),l.push(a),h.push(i))}return[c,l,h]}check_segment_validity(e,t,r,o=.5,c=.8){let l=[],h=0,p=0;for(let d=0;d=o&&++p;let f=h>0&&p>0;return f&&(f=h/p>c),[f,l]}compute_segments(e,t,r,o,c,l=null,h=null){let[p,f]=h??e[0].dims,d=new Tensor("int32",new Int32Array(p*f),[p,f]),i=[];if(h!==null)for(let m=0;ma[_]&&(n[_]=m,a[_]=e[m].data[_])}let u=0;for(let m=0;mo!==t.dims[c]))throw Error(`The first ${r.length} dimensions of 'input_points' and 'input_labels' must be the same.`);return new Tensor("int64",e.flat(1/0).map(BigInt),r)}async _call(e,t=null,r=null){const o=await super._call(e);if(t&&(o.input_points=this.reshape_input_points(t,o.original_sizes,o.reshaped_input_sizes)),r){if(!o.input_points)throw Error("`input_points` must be provided if `input_labels` are provided.");o.input_labels=this.add_input_labels(r,o.input_points)}return o}post_process_masks(e,t,r,{mask_threshold:o=0,binarize:c=!0,pad_size:l=null}={}){const h=[];l=l??this.pad_size;const p=[l.height,l.width];for(let f=0;fo&&(_[b]=1);g=new Tensor("bool",_,g.dims)}a.push(g)}h.push(stack(a))}return h}}class Swin2SRImageProcessor extends ImageFeatureExtractor{pad_image(e,t,r,o={}){const[c,l,h]=t;return super.pad_image(e,t,{width:c+(r-c%r)%r,height:l+(r-l%r)%r},{mode:"symmetric",center:!1,constant_values:-1,...o})}}class VitMatteImageProcessor extends ImageFeatureExtractor{async _call(e,t){Array.isArray(e)||(e=[e]),Array.isArray(t)||(t=[t]);const r=await Promise.all(e.map(l=>this.preprocess(l))),o=await Promise.all(t.map(l=>this.preprocess(l,{do_normalize:!1,do_convert_rgb:!1,do_convert_grayscale:!0})));return{pixel_values:stack(r.map((l,h)=>cat([l.pixel_values,o[h].pixel_values],0)),0),original_sizes:r.map(l=>l.original_size),reshaped_input_sizes:r.map(l=>l.reshaped_input_size)}}}class WhisperFeatureExtractor extends FeatureExtractor{constructor(e){super(e),this.config.mel_filters??=mel_filter_bank(Math.floor(1+this.config.n_fft/2),this.config.feature_size,0,8e3,this.config.sampling_rate,"slaney","slaney"),this.window=window_function(this.config.n_fft,"hann")}_extract_fbank_features(e){const{data:t,dims:r}=spectrogram(e,this.window,this.config.n_fft,this.config.hop_length,{power:2,mel_filters:this.config.mel_filters,log_mel:"log10",max_num_frames:this.config.nb_max_frames}),o=max(t)[0];for(let c=0;cthis.config.n_samples?(console.warn("Attempting to extract features for audio longer than 30 seconds. If using a pipeline to extract transcript from a long audio clip, remember to specify `chunk_length_s` and/or `stride_length_s`."),t=e.slice(0,this.config.n_samples)):(t=new Float32Array(this.config.n_samples),t.set(e));const{data:r,dims:o}=this._extract_fbank_features(t);return{input_features:new Tensor("float32",r,[1,...o])}}}class Wav2Vec2FeatureExtractor extends FeatureExtractor{_zero_mean_unit_var_norm(e){const r=e.reduce((c,l)=>c+l,0)/e.length,o=e.reduce((c,l)=>c+(l-r)**2,0)/e.length;return e.map(c=>(c-r)/Math.sqrt(o+1e-7))}async _call(e){validate_audio_inputs(e,"Wav2Vec2FeatureExtractor"),e instanceof Float64Array&&(e=new Float32Array(e));let t=e;this.config.do_normalize&&(t=this._zero_mean_unit_var_norm(t));const r=[1,t.length];return{input_values:new Tensor("float32",t,r),attention_mask:new Tensor("int64",new BigInt64Array(t.length).fill(1n),r)}}}class ASTFeatureExtractor extends FeatureExtractor{constructor(e){super(e);const t=this.config.sampling_rate,r=mel_filter_bank(256,this.config.num_mel_bins,20,Math.floor(t/2),t,null,"kaldi",!0);for(let o=0;o0)if(r==="rand_trunc"){l=!0;const p=Math.floor(Math.random()*(h+1));e=e.subarray(p,p+t),c=this._extract_fbank_features(e,this.mel_filters_slaney,this.config.nb_max_samples),c.dims=[1,...c.dims]}else throw new Error(`Truncation strategy "${r}" not implemented`);else{if(h<0){let p=new Float64Array(t);if(p.set(e),o==="repeat")for(let f=e.length;fRawImage.read(e)))}async function prepareAudios(s,e){return Array.isArray(s)||(s=[s]),await Promise.all(s.map(t=>typeof t=="string"||t instanceof URL?read_audio(t,e):t instanceof Float64Array?new Float32Array(t):t))}function get_bounding_box(s,e){e&&(s=s.map(l=>l|0));const[t,r,o,c]=s;return{xmin:t,ymin:r,xmax:o,ymax:c}}class Pipeline extends Callable{constructor({task:e,model:t,tokenizer:r=null,processor:o=null}){super(),this.task=e,this.model=t,this.tokenizer=r,this.processor=o}async dispose(){await this.model.dispose()}}class TextClassificationPipeline extends Pipeline{constructor(e){super(e)}async _call(e,{topk:t=1}={}){const r=this.tokenizer(e,{padding:!0,truncation:!0}),o=await this.model(r),c=this.model.config.problem_type==="multi_label_classification"?p=>p.sigmoid().data:p=>softmax(p.data),l=this.model.config.id2label,h=[];for(const p of o.logits){const f=c(p),i=getTopItems(f,t).map(n=>({label:l[n[0]],score:n[1]}));t===1?h.push(...i):h.push(i)}return Array.isArray(e)||t===1?h:h[0]}}class TokenClassificationPipeline extends Pipeline{constructor(e){super(e)}async _call(e,{ignore_labels:t=["O"]}={}){const r=Array.isArray(e),o=this.tokenizer(r?e:[e],{padding:!0,truncation:!0}),l=(await this.model(o)).logits,h=this.model.config.id2label,p=[];for(let f=0;f[a,u]).filter(a=>a[1]>f),i=Array.from(softmax(c.end_logits[h].data)).map((a,u)=>[a,u]).filter(a=>a[1]>f),n=product(d,i).filter(a=>a[0][1]<=a[1][1]).map(a=>[a[0][1],a[1][1],a[0][0]*a[1][0]]).sort((a,u)=>u[2]-a[2]);for(let a=0;a{const a=[...h];return a[p]=n[0],{score:n[1],token:n[0],token_str:this.tokenizer.model.vocab[n[0]],sequence:this.tokenizer.decode(a,{skip_special_tokens:!0})}}))}return Array.isArray(e)?c:c[0]}}class Text2TextGenerationPipeline extends Pipeline{_key="generated_text";constructor(e){super(e)}async _call(e,t={}){Array.isArray(e)||(e=[e]),this.model.config.prefix&&(e=e.map(p=>this.model.config.prefix+p));const r=this.model.config.task_specific_params;r&&r[this.task]&&r[this.task].prefix&&(e=e.map(p=>r[this.task].prefix+p));const o=this.tokenizer,c={padding:!0,truncation:!0};let l;this instanceof TranslationPipeline&&"_build_translation_inputs"in o?l=o._build_translation_inputs(e,c,t).input_ids:l=o(e,c).input_ids;const h=await this.model.generate(l,t);return o.batch_decode(h,{skip_special_tokens:!0}).map(p=>({[this._key]:p}))}}class SummarizationPipeline extends Text2TextGenerationPipeline{_key="summary_text";constructor(e){super(e)}}class TranslationPipeline extends Text2TextGenerationPipeline{_key="translation_text";constructor(e){super(e)}}class TextGenerationPipeline extends Pipeline{constructor(e){super(e)}async _call(e,t={}){const r=Array.isArray(e);r||(e=[e]);const o=t.add_special_tokens??!1;this.tokenizer.padding_side="left";const{input_ids:c,attention_mask:l}=this.tokenizer(e,{add_special_tokens:o,padding:!0,truncation:!0}),h=await this.model.generate(c,t,null,{inputs_attention_mask:l}),p=this.tokenizer.batch_decode(h,{skip_special_tokens:!0}),f=Array.from({length:e.length},d=>[]);for(let d=0;d[t.toLowerCase(),r])),this.entailment_id=this.label2id.entailment,this.entailment_id===void 0&&(console.warn("Could not find 'entailment' in label2id mapping. Using 2 as entailment_id."),this.entailment_id=2),this.contradiction_id=this.label2id.contradiction??this.label2id.not_entailment,this.contradiction_id===void 0&&(console.warn("Could not find 'contradiction' in label2id mapping. Using 0 as contradiction_id."),this.contradiction_id=0)}async _call(e,t,{hypothesis_template:r="This example is {}.",multi_label:o=!1}={}){const c=Array.isArray(e);c||(e=[e]),Array.isArray(t)||(t=[t]);const l=t.map(f=>r.replace("{}",f)),h=o||t.length===1,p=[];for(const f of e){const d=[];for(const a of l){const u=this.tokenizer(f,{text_pair:a,padding:!0,truncation:!0}),m=await this.model(u);h?d.push([m.logits.data[this.contradiction_id],m.logits.data[this.entailment_id]]):d.push(m.logits.data[this.entailment_id])}const n=(h?d.map(a=>softmax(a)[1]):softmax(d)).map((a,u)=>[a,u]).sort((a,u)=>u[0]-a[0]);p.push({sequence:f,labels:n.map(a=>t[a[1]]),scores:n.map(a=>a[0])})}return c?p:p[0]}}class FeatureExtractionPipeline extends Pipeline{constructor(e){super(e)}async _call(e,{pooling:t="none",normalize:r=!1}={}){const o=this.tokenizer(e,{padding:!0,truncation:!0}),c=await this.model(o);let l=c.last_hidden_state??c.logits;if(t!=="none")if(t==="mean")l=mean_pooling(l,o.attention_mask);else if(t==="cls")l=l.slice(null,0);else throw Error(`Pooling method '${t}' not supported.`);return r&&(l=l.normalize(2,-1)),l}}class AudioClassificationPipeline extends Pipeline{constructor(e){super(e)}async _call(e,{topk:t=null}={}){const r=!Array.isArray(e),o=this.processor.feature_extractor.config.sampling_rate,c=await prepareAudios(e,o),l=this.model.config.id2label,h=[];for(const p of c){const f=await this.processor(p),i=(await this.model(f)).logits[0],a=getTopItems(softmax(i.data),t).map(u=>({label:l[u[0]],score:u[1]}));t===1?h.push(...a):h.push(a)}return!r||t===1?h:h[0]}}class ZeroShotAudioClassificationPipeline extends Pipeline{constructor(e){super(e)}async _call(e,t,{hypothesis_template:r="This is a sound of {}."}={}){const o=!Array.isArray(e);o&&(e=[e]);const c=t.map(d=>r.replace("{}",d)),l=this.tokenizer(c,{padding:!0,truncation:!0}),h=this.processor.feature_extractor.config.sampling_rate,p=await prepareAudios(e,h),f=[];for(const d of p){const i=await this.processor(d),n=await this.model({...l,...i}),a=softmax(n.logits_per_audio.data);f.push([...a].map((u,m)=>({score:u,label:t[m]})))}return o?f[0]:f}}class AutomaticSpeechRecognitionPipeline extends Pipeline{constructor(e){super(e)}async _call(e,t={}){switch(this.model.config.model_type){case"whisper":return this._call_whisper(e,t);case"wav2vec2":case"hubert":return this._call_wav2vec2(e,t);default:throw new Error(`AutomaticSpeechRecognitionPipeline does not support model type '${this.model.config.model_type}'.`)}}async _call_wav2vec2(e,t={}){t.language&&console.warn('`language` parameter is not yet supported for `wav2vec2` models, defaulting to "English".'),t.task&&console.warn('`task` parameter is not yet supported for `wav2vec2` models, defaulting to "transcribe".');const r=!Array.isArray(e);r&&(e=[e]);const o=this.processor.feature_extractor.config.sampling_rate,c=await prepareAudios(e,o),l=[];for(const h of c){const p=await this.processor(h),d=(await this.model(p)).logits[0],i=[];for(const a of d)i.push(max(a.data)[1]);const n=this.tokenizer.decode(i);l.push({text:n})}return r?l[0]:l}async _call_whisper(e,t={}){const r=t.return_timestamps??!1,o=t.chunk_length_s??0,c=t.chunk_callback??null,l=t.force_full_sequences??!1;let h=t.stride_length_s??null;r==="word"&&(t.return_token_timestamps=!0);const p=pop(t,"language",null),f=pop(t,"task",null);if(p||f||r){if(t.forced_decoder_ids)throw new Error("Cannot specify `language`/`task`/`return_timestamps` and `forced_decoder_ids` at the same time.");const g=this.tokenizer.get_decoder_prompt_ids({language:p,task:f,no_timestamps:!r});g.length>0&&(t.forced_decoder_ids=g)}const d=!Array.isArray(e);d&&(e=[e]);const i=this.processor.feature_extractor.config.chunk_length/this.model.config.max_source_positions,n=this.processor.feature_extractor.config.hop_length,a=this.processor.feature_extractor.config.sampling_rate,u=await prepareAudios(e,a),m=[];for(const g of u){let _=[];if(o>0){if(h===null)h=o/6;else if(o<=h)throw Error("`chunk_length_s` must be larger than `stride_length_s`.");const v=a*o,x=a*h,w=v-2*x;let S=0;for(;S=g.length;_.push({stride:[M.length,E?0:x,R?0:x],input_features:T.input_features,is_last:R}),S+=w}}else _=[{stride:[g.length,0,0],input_features:(await this.processor(g)).input_features,is_last:!0}];for(const v of _){t.num_frames=Math.floor(v.stride[0]/n);const x=await this.model.generate(v.input_features,t);r==="word"?(v.tokens=x.sequences[0],v.token_timestamps=x.token_timestamps.tolist()[0].map(w=>round(w,2))):v.tokens=x[0],v.stride=v.stride.map(w=>w/a),c!==null&&c(v)}const[b,y]=this.tokenizer._decode_asr(_,{time_precision:i,return_timestamps:r,force_full_sequences:l});m.push({text:b,...y})}return d?m[0]:m}}class ImageToTextPipeline extends Pipeline{constructor(e){super(e)}async _call(e,t={}){const r=Array.isArray(e),o=await prepareImages(e),{pixel_values:c}=await this.processor(o),l=[];for(const h of c){h.dims=[1,...h.dims];const p=await this.model.generate(h,t),f=this.tokenizer.batch_decode(p,{skip_special_tokens:!0}).map(d=>({generated_text:d.trim()}));l.push(f)}return r?l:l[0]}}class ImageClassificationPipeline extends Pipeline{constructor(e){super(e)}async _call(e,{topk:t=1}={}){const r=Array.isArray(e),o=await prepareImages(e),{pixel_values:c}=await this.processor(o),l=await this.model({pixel_values:c}),h=this.model.config.id2label,p=[];for(const f of l.logits){const i=getTopItems(softmax(f.data),t).map(n=>({label:h[n[0]],score:n[1]}));t===1?p.push(...i):p.push(i)}return r||t===1?p:p[0]}}class ImageSegmentationPipeline extends Pipeline{constructor(e){super(e),this.subtasks_mapping={panoptic:"post_process_panoptic_segmentation",instance:"post_process_instance_segmentation",semantic:"post_process_semantic_segmentation"}}async _call(e,{threshold:t=.5,mask_threshold:r=.5,overlap_mask_area_threshold:o=.8,label_ids_to_fuse:c=null,target_sizes:l=null,subtask:h=null}={}){if(Array.isArray(e)&&e.length!==1)throw Error("Image segmentation pipeline currently only supports a batch size of 1.");const f=await prepareImages(e),d=f.map(_=>[_.height,_.width]),{pixel_values:i,pixel_mask:n}=await this.processor(f),a=await this.model({pixel_values:i,pixel_mask:n});let u=null;if(h!==null)u=this.subtasks_mapping[h];else for(let[_,b]of Object.entries(this.subtasks_mapping))if(b in this.processor.feature_extractor){u=this.processor.feature_extractor[b].bind(this.processor.feature_extractor),h=_;break}const m=this.model.config.id2label,g=[];if(h==="panoptic"||h==="instance"){const _=u(a,t,r,o,c,l??d)[0],b=_.segmentation;for(const y of _.segments_info){const v=new Uint8ClampedArray(b.data.length);for(let w=0;wr.replace("{}",n)),h=this.tokenizer(l,{padding:this.model.config.model_type==="siglip"?"max_length":!0,truncation:!0}),{pixel_values:p}=await this.processor(c),f=await this.model({...h,pixel_values:p}),d=this.model.config.model_type==="siglip"?n=>n.sigmoid().data:n=>softmax(n.data),i=[];for(const n of f.logits_per_image){const u=[...d(n)].map((m,g)=>({score:m,label:t[g]}));u.sort((m,g)=>g.score-m.score),i.push(u)}return o?i:i[0]}}class ObjectDetectionPipeline extends Pipeline{constructor(e){super(e)}async _call(e,{threshold:t=.9,percentage:r=!1}={}){const o=Array.isArray(e);if(o&&e.length!==1)throw Error("Object detection pipeline currently only supports a batch size of 1.");const c=await prepareImages(e),l=r?null:c.map(a=>[a.height,a.width]),{pixel_values:h,pixel_mask:p}=await this.processor(c),f=await this.model({pixel_values:h,pixel_mask:p}),d=this.processor.feature_extractor.post_process_object_detection(f,t,l),i=this.model.config.id2label,n=d.map(a=>a.boxes.map((u,m)=>({score:a.scores[m],label:i[a.classes[m]],box:get_bounding_box(u,!r)})));return o?n:n[0]}}class ZeroShotObjectDetectionPipeline extends Pipeline{constructor(e){super(e)}async _call(e,t,{threshold:r=.1,topk:o=null,percentage:c=!1}={}){const l=Array.isArray(e),h=await prepareImages(e),p=this.tokenizer(t,{padding:!0,truncation:!0}),f=await this.processor(h),d=[];for(let i=0;i({score:g.scores[y],label:t[g.classes[y]],box:get_bounding_box(b,!c)})).sort((b,y)=>y.score-b.score);o!==null&&(_=_.slice(0,o)),d.push(_)}return l?d:d[0]}}class DocumentQuestionAnsweringPipeline extends Pipeline{constructor(e){super(e)}async _call(e,t,r={}){const o=(await prepareImages(e))[0],{pixel_values:c}=await this.processor(o),l=`${t}`,h=this.tokenizer(l,{add_special_tokens:!1,padding:!0,truncation:!0}).input_ids,p=await this.model.generate(c,{...r,decoder_input_ids:h,max_length:this.model.config.decoder.max_position_embeddings}),d=this.tokenizer.batch_decode(p)[0].match(/(.*?)<\/s_answer>/);let i=null;return d&&d.length>=2&&(i=d[1].trim()),[{answer:i}]}}class TextToAudioPipeline extends Pipeline{DEFAULT_VOCODER_ID="Xenova/speecht5_hifigan";constructor(e){super(e),this.vocoder=e.vocoder??null}async _call(e,{speaker_embeddings:t=null}={}){return this.processor?this._call_text_to_spectrogram(e,{speaker_embeddings:t}):this._call_text_to_waveform(e)}async _call_text_to_waveform(e){const t=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:r}=await this.model(t),o=this.model.config.sampling_rate;return{audio:r.data,sampling_rate:o}}async _call_text_to_spectrogram(e,{speaker_embeddings:t}){if(this.vocoder||(console.log("No vocoder specified, using default HifiGan vocoder."),this.vocoder=await AutoModel.from_pretrained(this.DEFAULT_VOCODER_ID,{quantized:!1})),(typeof t=="string"||t instanceof URL)&&(t=new Float32Array(await(await fetch(t)).arrayBuffer())),t instanceof Float32Array)t=new Tensor("float32",t,[1,t.length]);else if(!(t instanceof Tensor))throw new Error("Speaker embeddings must be a `Tensor`, `Float32Array`, `string`, or `URL`.");const{input_ids:r}=this.tokenizer(e,{padding:!0,truncation:!0}),{waveform:o}=await this.model.generate_speech(r,t,{vocoder:this.vocoder}),c=this.processor.feature_extractor.config.sampling_rate;return{audio:o.data,sampling_rate:c}}}class ImageToImagePipeline extends Pipeline{constructor(e){super(e)}async _call(e){const t=await prepareImages(e),r=await this.processor(t),o=await this.model(r),c=[];for(const l of o.reconstruction){const h=l.squeeze().clamp_(0,1).mul_(255).round_().to("uint8");c.push(RawImage.fromTensor(h))}return c.length>1?c:c[0]}}class DepthEstimationPipeline extends Pipeline{constructor(e){super(e)}async _call(e){const t=await prepareImages(e),r=await this.processor(t),{predicted_depth:o}=await this.model(r),c=[];for(let l=0;l1?c:c[0]}}const SUPPORTED_TASKS=Object.freeze({"text-classification":{tokenizer:AutoTokenizer,pipeline:TextClassificationPipeline,model:AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-finetuned-sst-2-english"},type:"text"},"token-classification":{tokenizer:AutoTokenizer,pipeline:TokenClassificationPipeline,model:AutoModelForTokenClassification,default:{model:"Xenova/bert-base-multilingual-cased-ner-hrl"},type:"text"},"question-answering":{tokenizer:AutoTokenizer,pipeline:QuestionAnsweringPipeline,model:AutoModelForQuestionAnswering,default:{model:"Xenova/distilbert-base-cased-distilled-squad"},type:"text"},"fill-mask":{tokenizer:AutoTokenizer,pipeline:FillMaskPipeline,model:AutoModelForMaskedLM,default:{model:"Xenova/bert-base-uncased"},type:"text"},summarization:{tokenizer:AutoTokenizer,pipeline:SummarizationPipeline,model:AutoModelForSeq2SeqLM,default:{model:"Xenova/distilbart-cnn-6-6"},type:"text"},translation:{tokenizer:AutoTokenizer,pipeline:TranslationPipeline,model:AutoModelForSeq2SeqLM,default:{model:"Xenova/t5-small"},type:"text"},"text2text-generation":{tokenizer:AutoTokenizer,pipeline:Text2TextGenerationPipeline,model:AutoModelForSeq2SeqLM,default:{model:"Xenova/flan-t5-small"},type:"text"},"text-generation":{tokenizer:AutoTokenizer,pipeline:TextGenerationPipeline,model:AutoModelForCausalLM,default:{model:"Xenova/gpt2"},type:"text"},"zero-shot-classification":{tokenizer:AutoTokenizer,pipeline:ZeroShotClassificationPipeline,model:AutoModelForSequenceClassification,default:{model:"Xenova/distilbert-base-uncased-mnli"},type:"text"},"audio-classification":{pipeline:AudioClassificationPipeline,model:AutoModelForAudioClassification,processor:AutoProcessor,default:{model:"Xenova/wav2vec2-base-superb-ks"},type:"audio"},"zero-shot-audio-classification":{tokenizer:AutoTokenizer,pipeline:ZeroShotAudioClassificationPipeline,model:AutoModel,processor:AutoProcessor,default:{model:"Xenova/clap-htsat-unfused"},type:"multimodal"},"automatic-speech-recognition":{tokenizer:AutoTokenizer,pipeline:AutomaticSpeechRecognitionPipeline,model:[AutoModelForSpeechSeq2Seq,AutoModelForCTC],processor:AutoProcessor,default:{model:"Xenova/whisper-tiny.en"},type:"multimodal"},"text-to-audio":{tokenizer:AutoTokenizer,pipeline:TextToAudioPipeline,model:[AutoModelForTextToWaveform,AutoModelForTextToSpectrogram],processor:[AutoProcessor,null],default:{model:"Xenova/speecht5_tts"},type:"text"},"image-to-text":{tokenizer:AutoTokenizer,pipeline:ImageToTextPipeline,model:AutoModelForVision2Seq,processor:AutoProcessor,default:{model:"Xenova/vit-gpt2-image-captioning"},type:"multimodal"},"image-classification":{pipeline:ImageClassificationPipeline,model:AutoModelForImageClassification,processor:AutoProcessor,default:{model:"Xenova/vit-base-patch16-224"},type:"multimodal"},"image-segmentation":{pipeline:ImageSegmentationPipeline,model:[AutoModelForImageSegmentation,AutoModelForSemanticSegmentation],processor:AutoProcessor,default:{model:"Xenova/detr-resnet-50-panoptic"},type:"multimodal"},"zero-shot-image-classification":{tokenizer:AutoTokenizer,pipeline:ZeroShotImageClassificationPipeline,model:AutoModel,processor:AutoProcessor,default:{model:"Xenova/clip-vit-base-patch32"},type:"multimodal"},"object-detection":{pipeline:ObjectDetectionPipeline,model:AutoModelForObjectDetection,processor:AutoProcessor,default:{model:"Xenova/detr-resnet-50"},type:"multimodal"},"zero-shot-object-detection":{tokenizer:AutoTokenizer,pipeline:ZeroShotObjectDetectionPipeline,model:AutoModelForZeroShotObjectDetection,processor:AutoProcessor,default:{model:"Xenova/owlvit-base-patch32"},type:"multimodal"},"document-question-answering":{tokenizer:AutoTokenizer,pipeline:DocumentQuestionAnsweringPipeline,model:AutoModelForDocumentQuestionAnswering,processor:AutoProcessor,default:{model:"Xenova/donut-base-finetuned-docvqa"},type:"multimodal"},"image-to-image":{pipeline:ImageToImagePipeline,model:AutoModelForImageToImage,processor:AutoProcessor,default:{model:"Xenova/swin2SR-classical-sr-x2-64"},type:"image"},"depth-estimation":{pipeline:DepthEstimationPipeline,model:AutoModelForDepthEstimation,processor:AutoProcessor,default:{model:"Xenova/dpt-large"},type:"image"},"feature-extraction":{tokenizer:AutoTokenizer,pipeline:FeatureExtractionPipeline,model:AutoModel,default:{model:"Xenova/all-MiniLM-L6-v2"},type:"text"}}),TASK_ALIASES=Object.freeze({"sentiment-analysis":"text-classification",ner:"token-classification",asr:"automatic-speech-recognition","text-to-speech":"text-to-audio",embeddings:"feature-extraction"});async function pipeline(s,e=null,{quantized:t=!0,progress_callback:r=null,config:o=null,cache_dir:c=null,local_files_only:l=!1,revision:h="main"}={}){s=TASK_ALIASES[s]??s;const p=SUPPORTED_TASKS[s.split("_",1)[0]];if(!p)throw Error(`Unsupported pipeline: ${s}. Must be one of [${Object.keys(SUPPORTED_TASKS)}]`);e||(e=p.default.model,console.log(`No model specified. Using default model: "${e}".`));const f={quantized:t,progress_callback:r,config:o,cache_dir:c,local_files_only:l,revision:h},d=new Map([["tokenizer",p.tokenizer],["model",p.model],["processor",p.processor]]),i=await loadItems(d,e,f);i.task=s,dispatchCallback(r,{status:"ready",task:s,model:e});const n=p.pipeline;return new n(i)}async function loadItems(s,e,t){const r=Object.create(null),o=[];for(let[c,l]of s.entries()){if(!l)continue;let h;Array.isArray(l)?h=new Promise(async(p,f)=>{let d;for(let i of l){if(i===null){p(null);return}try{p(await i.from_pretrained(e,t));return}catch(n){d=n}}f(d)}):h=l.from_pretrained(e,t),r[c]=h,o.push(h)}await Promise.all(o);for(let[c,l]of Object.entries(r))r[c]=await l;return r}env$1.allowLocalModels=!1;env$1.backends.onnx.wasm.proxy=!0;const EXAMPLE_URL="https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/bread_small.png",DEFAULT_SCALE=.75,status=document.getElementById("status"),fileUpload=document.getElementById("upload"),imageContainer=document.getElementById("container"),example=document.getElementById("example");status.textContent="Loading model...";const depth_estimator=await pipeline("depth-estimation","Xenova/depth-anything-small-hf");status.textContent="Ready";example.addEventListener("click",s=>{s.preventDefault(),predict(EXAMPLE_URL)});fileUpload.addEventListener("change",function(s){const e=s.target.files[0];if(!e)return;const t=new FileReader;t.onload=r=>predict(r.target.result),t.readAsDataURL(e)});let onSliderChange;async function predict(s){imageContainer.innerHTML="";const e=await RawImage.fromURL(s),{canvas:t,setDisplacementMap:r}=setupScene(s,e.width,e.height);imageContainer.append(t),status.textContent="Analysing...";const{depth:o}=await depth_estimator(e);r(o.toCanvas()),status.textContent="";const c=document.createElement("input");c.type="range",c.min=0,c.max=1,c.step=.01,c.addEventListener("input",l=>{onSliderChange(parseFloat(l.target.value))}),c.defaultValue=DEFAULT_SCALE,imageContainer.append(c)}function setupScene(s,e,t){const r=document.createElement("canvas"),o=r.width=imageContainer.offsetWidth,c=r.height=imageContainer.offsetHeight,l=new Scene,h=new PerspectiveCamera(30,o/c,.01,10);h.position.z=2,l.add(h);const p=new WebGLRenderer({canvas:r,antialias:!0});p.setSize(o,c),p.setPixelRatio(window.devicePixelRatio);const f=new AmbientLight(16777215,2);l.add(f);const d=new TextureLoader().load(s);d.colorSpace=SRGBColorSpace;const i=new MeshStandardMaterial({map:d,side:DoubleSide});i.displacementScale=DEFAULT_SCALE;const n=y=>{i.displacementMap=new CanvasTexture(y),i.needsUpdate=!0};onSliderChange=y=>{i.displacementScale=y,i.needsUpdate=!0};const[u,m]=e>t?[1,t/e]:[e/t,1],g=new PlaneGeometry(u,m,e,t),_=new Mesh(g,i);l.add(_);const b=new OrbitControls(h,p.domElement);return b.enableDamping=!0,p.setAnimationLoop(()=>{p.render(l,h),b.update()}),window.addEventListener("resize",()=>{const y=imageContainer.offsetWidth,v=imageContainer.offsetHeight;h.aspect=y/v,h.updateProjectionMatrix(),p.setSize(y,v)},!1),{canvas:p.domElement,setDisplacementMap:n}}