@needle-tools/engine 5.1.0-experimental.0 → 5.1.0-experimental.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{Object3D as na,PlaneGeometry as ia,Layers as cr,MeshBasicMaterial as ra,DoubleSide as Ss,AdditiveBlending as sa,InstancedBufferAttribute as fn,DynamicDrawUsage as et,InstancedBufferGeometry as eu,Uniform as Et,ShaderMaterial as bs,BufferGeometry as ti,BufferAttribute as dt,Mesh as lr,MeshStandardMaterial as tu,MeshPhysicalMaterial as nu,ShaderChunk as iu,Triangle as mn,Vector3 as q,Box3 as zt,Matrix4 as kt,Line3 as qt,Plane as oa,Vector2 as nn,BackSide as ru,REVISION as aa,Ray as su,FrontSide as ca,LineSegments as la,LineLoop as ua,Line as ha,Points as da,Sphere as ou,BatchedMesh as au,Matrix3 as cu,Vector4 as xs,SkinnedMesh as lu,InterpolateDiscrete as uu,InterpolateLinear as pa,AnimationClip as hu,QuaternionKeyframeTrack as du,ColorKeyframeTrack as pu,VectorKeyframeTrack as fu,BooleanKeyframeTrack as mu,NumberKeyframeTrack as yu,PropertyBinding as fa}from"./three.min.js";function ur(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var ma={exports:{}},ya={exports:{}},ga;function gu(){return ga||(ga=1,function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e={rotl:function(t,n){return t<<n|t>>>32-n},rotr:function(t,n){return t<<32-n|t>>>n},endian:function(t){if(t.constructor==Number)return e.rotl(t,8)&16711935|e.rotl(t,24)&4278255360;for(var n=0;n<t.length;n++)t[n]=e.endian(t[n]);return t},randomBytes:function(t){for(var n=[];t>0;t--)n.push(Math.floor(Math.random()*256));return n},bytesToWords:function(t){for(var n=[],i=0,s=0;i<t.length;i++,s+=8)n[s>>>5]|=t[i]<<24-s%32;return n},wordsToBytes:function(t){for(var n=[],i=0;i<t.length*32;i+=8)n.push(t[i>>>5]>>>24-i%32&255);return n},bytesToHex:function(t){for(var n=[],i=0;i<t.length;i++)n.push((t[i]>>>4).toString(16)),n.push((t[i]&15).toString(16));return n.join("")},hexToBytes:function(t){for(var n=[],i=0;i<t.length;i+=2)n.push(parseInt(t.substr(i,2),16));return n},bytesToBase64:function(t){for(var n=[],i=0;i<t.length;i+=3)for(var s=t[i]<<16|t[i+1]<<8|t[i+2],a=0;a<4;a++)i*8+a*6<=t.length*8?n.push(r.charAt(s>>>6*(3-a)&63)):n.push("=");return n.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/ig,"");for(var n=[],i=0,s=0;i<t.length;s=++i%4)s!=0&&n.push((r.indexOf(t.charAt(i-1))&Math.pow(2,-2*s+8)-1)<<s*2|r.indexOf(t.charAt(i))>>>6-s*2);return n}};ya.exports=e}()),ya.exports}var ws,va;function Sa(){if(va)return ws;va=1;var r={utf8:{stringToBytes:function(e){return r.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(r.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n)&255);return t},bytesToString:function(e){for(var t=[],n=0;n<e.length;n++)t.push(String.fromCharCode(e[n]));return t.join("")}}};return ws=r,ws}var _s,ba;function vu(){if(ba)return _s;ba=1,_s=function(t){return t!=null&&(r(t)||e(t)||!!t._isBuffer)};function r(t){return!!t.constructor&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}function e(t){return typeof t.readFloatLE=="function"&&typeof t.slice=="function"&&r(t.slice(0,0))}return _s}var xa;function Su(){return xa||(xa=1,function(){var r=gu(),e=Sa().utf8,t=vu(),n=Sa().bin,i=function(s,a){s.constructor==String?a&&a.encoding==="binary"?s=n.stringToBytes(s):s=e.stringToBytes(s):t(s)?s=Array.prototype.slice.call(s,0):!Array.isArray(s)&&s.constructor!==Uint8Array&&(s=s.toString());for(var o=r.bytesToWords(s),c=s.length*8,l=1732584193,u=-271733879,d=-1732584194,f=271733878,m=0;m<o.length;m++)o[m]=(o[m]<<8|o[m]>>>24)&16711935|(o[m]<<24|o[m]>>>8)&4278255360;o[c>>>5]|=128<<c%32,o[(c+64>>>9<<4)+14]=c;for(var x=i._ff,_=i._gg,g=i._hh,v=i._ii,m=0;m<o.length;m+=16){var w=l,S=u,T=d,M=f;l=x(l,u,d,f,o[m+0],7,-680876936),f=x(f,l,u,d,o[m+1],12,-389564586),d=x(d,f,l,u,o[m+2],17,606105819),u=x(u,d,f,l,o[m+3],22,-1044525330),l=x(l,u,d,f,o[m+4],7,-176418897),f=x(f,l,u,d,o[m+5],12,1200080426),d=x(d,f,l,u,o[m+6],17,-1473231341),u=x(u,d,f,l,o[m+7],22,-45705983),l=x(l,u,d,f,o[m+8],7,1770035416),f=x(f,l,u,d,o[m+9],12,-1958414417),d=x(d,f,l,u,o[m+10],17,-42063),u=x(u,d,f,l,o[m+11],22,-1990404162),l=x(l,u,d,f,o[m+12],7,1804603682),f=x(f,l,u,d,o[m+13],12,-40341101),d=x(d,f,l,u,o[m+14],17,-1502002290),u=x(u,d,f,l,o[m+15],22,1236535329),l=_(l,u,d,f,o[m+1],5,-165796510),f=_(f,l,u,d,o[m+6],9,-1069501632),d=_(d,f,l,u,o[m+11],14,643717713),u=_(u,d,f,l,o[m+0],20,-373897302),l=_(l,u,d,f,o[m+5],5,-701558691),f=_(f,l,u,d,o[m+10],9,38016083),d=_(d,f,l,u,o[m+15],14,-660478335),u=_(u,d,f,l,o[m+4],20,-405537848),l=_(l,u,d,f,o[m+9],5,568446438),f=_(f,l,u,d,o[m+14],9,-1019803690),d=_(d,f,l,u,o[m+3],14,-187363961),u=_(u,d,f,l,o[m+8],20,1163531501),l=_(l,u,d,f,o[m+13],5,-1444681467),f=_(f,l,u,d,o[m+2],9,-51403784),d=_(d,f,l,u,o[m+7],14,1735328473),u=_(u,d,f,l,o[m+12],20,-1926607734),l=g(l,u,d,f,o[m+5],4,-378558),f=g(f,l,u,d,o[m+8],11,-2022574463),d=g(d,f,l,u,o[m+11],16,1839030562),u=g(u,d,f,l,o[m+14],23,-35309556),l=g(l,u,d,f,o[m+1],4,-1530992060),f=g(f,l,u,d,o[m+4],11,1272893353),d=g(d,f,l,u,o[m+7],16,-155497632),u=g(u,d,f,l,o[m+10],23,-1094730640),l=g(l,u,d,f,o[m+13],4,681279174),f=g(f,l,u,d,o[m+0],11,-358537222),d=g(d,f,l,u,o[m+3],16,-722521979),u=g(u,d,f,l,o[m+6],23,76029189),l=g(l,u,d,f,o[m+9],4,-640364487),f=g(f,l,u,d,o[m+12],11,-421815835),d=g(d,f,l,u,o[m+15],16,530742520),u=g(u,d,f,l,o[m+2],23,-995338651),l=v(l,u,d,f,o[m+0],6,-198630844),f=v(f,l,u,d,o[m+7],10,1126891415),d=v(d,f,l,u,o[m+14],15,-1416354905),u=v(u,d,f,l,o[m+5],21,-57434055),l=v(l,u,d,f,o[m+12],6,1700485571),f=v(f,l,u,d,o[m+3],10,-1894986606),d=v(d,f,l,u,o[m+10],15,-1051523),u=v(u,d,f,l,o[m+1],21,-2054922799),l=v(l,u,d,f,o[m+8],6,1873313359),f=v(f,l,u,d,o[m+15],10,-30611744),d=v(d,f,l,u,o[m+6],15,-1560198380),u=v(u,d,f,l,o[m+13],21,1309151649),l=v(l,u,d,f,o[m+4],6,-145523070),f=v(f,l,u,d,o[m+11],10,-1120210379),d=v(d,f,l,u,o[m+2],15,718787259),u=v(u,d,f,l,o[m+9],21,-343485551),l=l+w>>>0,u=u+S>>>0,d=d+T>>>0,f=f+M>>>0}return r.endian([l,u,d,f])};i._ff=function(s,a,o,c,l,u,d){var f=s+(a&o|~a&c)+(l>>>0)+d;return(f<<u|f>>>32-u)+a},i._gg=function(s,a,o,c,l,u,d){var f=s+(a&c|o&~c)+(l>>>0)+d;return(f<<u|f>>>32-u)+a},i._hh=function(s,a,o,c,l,u,d){var f=s+(a^o^c)+(l>>>0)+d;return(f<<u|f>>>32-u)+a},i._ii=function(s,a,o,c,l,u,d){var f=s+(o^(a|~c))+(l>>>0)+d;return(f<<u|f>>>32-u)+a},i._blocksize=16,i._digestsize=16,ma.exports=function(s,a){if(s==null)throw new Error("Illegal argument "+s);var o=r.wordsToBytes(i(s,a));return a&&a.asBytes?o:a&&a.asString?n.bytesToString(o):r.bytesToHex(o)}}()),ma.exports}var bu=Su();const wa=ur(bu),xu=Object.freeze(Object.defineProperty({__proto__:null,default:wa},Symbol.toStringTag,{value:"Module"})),wu=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function _u(r){return typeof r=="string"&&wu.test(r)}const Le=[];for(let r=0;r<256;++r)Le.push((r+256).toString(16).slice(1));function Tu(r,e=0){return Le[r[e+0]]+Le[r[e+1]]+Le[r[e+2]]+Le[r[e+3]]+"-"+Le[r[e+4]]+Le[r[e+5]]+"-"+Le[r[e+6]]+Le[r[e+7]]+"-"+Le[r[e+8]]+Le[r[e+9]]+"-"+Le[r[e+10]]+Le[r[e+11]]+Le[r[e+12]]+Le[r[e+13]]+Le[r[e+14]]+Le[r[e+15]]}function Mu(r){if(!_u(r))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(r.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(r.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(r.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(r.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(r.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function Cu(r){r=unescape(encodeURIComponent(r));const e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t));return e}const Pu="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Eu="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function ku(r,e,t){function n(i,s,a,o){var c;if(typeof i=="string"&&(i=Cu(i)),typeof s=="string"&&(s=Mu(s)),((c=s)===null||c===void 0?void 0:c.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(s),l.set(i,s.length),l=t(l),l[6]=l[6]&15|e,l[8]=l[8]&63|128,a){o=o||0;for(let u=0;u<16;++u)a[o+u]=l[u];return a}return Tu(l)}try{n.name=r}catch{}return n.DNS=Pu,n.URL=Eu,n}function Ru(r,e,t,n){switch(r){case 0:return e&t^~e&n;case 1:return e^t^n;case 2:return e&t^e&n^t&n;case 3:return e^t^n}}function Ts(r,e){return r<<e|r>>>32-e}function Au(r){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof r=="string"){const a=unescape(encodeURIComponent(r));r=[];for(let o=0;o<a.length;++o)r.push(a.charCodeAt(o))}else Array.isArray(r)||(r=Array.prototype.slice.call(r));r.push(128);const n=r.length/4+2,i=Math.ceil(n/16),s=new Array(i);for(let a=0;a<i;++a){const o=new Uint32Array(16);for(let c=0;c<16;++c)o[c]=r[a*64+c*4]<<24|r[a*64+c*4+1]<<16|r[a*64+c*4+2]<<8|r[a*64+c*4+3];s[a]=o}s[i-1][14]=(r.length-1)*8/Math.pow(2,32),s[i-1][14]=Math.floor(s[i-1][14]),s[i-1][15]=(r.length-1)*8&4294967295;for(let a=0;a<i;++a){const o=new Uint32Array(80);for(let m=0;m<16;++m)o[m]=s[a][m];for(let m=16;m<80;++m)o[m]=Ts(o[m-3]^o[m-8]^o[m-14]^o[m-16],1);let c=t[0],l=t[1],u=t[2],d=t[3],f=t[4];for(let m=0;m<80;++m){const x=Math.floor(m/20),_=Ts(c,5)+Ru(x,l,u,d)+f+e[x]+o[m]>>>0;f=d,d=u,u=Ts(l,30)>>>0,l=c,c=_}t[0]=t[0]+c>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+d>>>0,t[4]=t[4]+f>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const Ou=ku("v5",80,Au),Ms=2,Nt=4,Xt=4,_a=4,rn=new Int32Array(2),Ta=new Float32Array(rn.buffer),Ma=new Float64Array(rn.buffer),hr=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;class en{constructor(e,t){this.low=e|0,this.high=t|0}static create(e,t){return e==0&&t==0?en.ZERO:new en(e,t)}toFloat64(){return(this.low>>>0)+this.high*4294967296}equals(e){return this.low==e.low&&this.high==e.high}}en.ZERO=new en(0,0);var Cs;(function(r){r[r.UTF8_BYTES=1]="UTF8_BYTES",r[r.UTF16_STRING=2]="UTF16_STRING"})(Cs||(Cs={}));class Ti{constructor(e){this.bytes_=e,this.position_=0}static allocate(e){return new Ti(new Uint8Array(e))}clear(){this.position_=0}bytes(){return this.bytes_}position(){return this.position_}setPosition(e){this.position_=e}capacity(){return this.bytes_.length}readInt8(e){return this.readUint8(e)<<24>>24}readUint8(e){return this.bytes_[e]}readInt16(e){return this.readUint16(e)<<16>>16}readUint16(e){return this.bytes_[e]|this.bytes_[e+1]<<8}readInt32(e){return this.bytes_[e]|this.bytes_[e+1]<<8|this.bytes_[e+2]<<16|this.bytes_[e+3]<<24}readUint32(e){return this.readInt32(e)>>>0}readInt64(e){return new en(this.readInt32(e),this.readInt32(e+4))}readUint64(e){return new en(this.readUint32(e),this.readUint32(e+4))}readFloat32(e){return rn[0]=this.readInt32(e),Ta[0]}readFloat64(e){return rn[hr?0:1]=this.readInt32(e),rn[hr?1:0]=this.readInt32(e+4),Ma[0]}writeInt8(e,t){this.bytes_[e]=t}writeUint8(e,t){this.bytes_[e]=t}writeInt16(e,t){this.bytes_[e]=t,this.bytes_[e+1]=t>>8}writeUint16(e,t){this.bytes_[e]=t,this.bytes_[e+1]=t>>8}writeInt32(e,t){this.bytes_[e]=t,this.bytes_[e+1]=t>>8,this.bytes_[e+2]=t>>16,this.bytes_[e+3]=t>>24}writeUint32(e,t){this.bytes_[e]=t,this.bytes_[e+1]=t>>8,this.bytes_[e+2]=t>>16,this.bytes_[e+3]=t>>24}writeInt64(e,t){this.writeInt32(e,t.low),this.writeInt32(e+4,t.high)}writeUint64(e,t){this.writeUint32(e,t.low),this.writeUint32(e+4,t.high)}writeFloat32(e,t){Ta[0]=t,this.writeInt32(e,rn[0])}writeFloat64(e,t){Ma[0]=t,this.writeInt32(e,rn[hr?0:1]),this.writeInt32(e+4,rn[hr?1:0])}getBufferIdentifier(){if(this.bytes_.length<this.position_+Nt+Xt)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");let e="";for(let t=0;t<Xt;t++)e+=String.fromCharCode(this.readInt8(this.position_+Nt+t));return e}__offset(e,t){const n=e-this.readInt32(e);return t<this.readInt16(n)?this.readInt16(n+t):0}__union(e,t){return e.bb_pos=t+this.readInt32(t),e.bb=this,e}__string(e,t){e+=this.readInt32(e);const n=this.readInt32(e);let i="",s=0;if(e+=Nt,t===Cs.UTF8_BYTES)return this.bytes_.subarray(e,e+n);for(;s<n;){let a;const o=this.readUint8(e+s++);if(o<192)a=o;else{const c=this.readUint8(e+s++);if(o<224)a=(o&31)<<6|c&63;else{const l=this.readUint8(e+s++);if(o<240)a=(o&15)<<12|(c&63)<<6|l&63;else{const u=this.readUint8(e+s++);a=(o&7)<<18|(c&63)<<12|(l&63)<<6|u&63}}}a<65536?i+=String.fromCharCode(a):(a-=65536,i+=String.fromCharCode((a>>10)+55296,(a&1023)+56320))}return i}__union_with_string(e,t){return typeof e=="string"?this.__string(t):this.__union(e,t)}__indirect(e){return e+this.readInt32(e)}__vector(e){return e+this.readInt32(e)+Nt}__vector_len(e){return this.readInt32(e+this.readInt32(e))}__has_identifier(e){if(e.length!=Xt)throw new Error("FlatBuffers: file identifier must be length "+Xt);for(let t=0;t<Xt;t++)if(e.charCodeAt(t)!=this.readInt8(this.position()+Nt+t))return!1;return!0}createLong(e,t){return en.create(e,t)}createScalarList(e,t){const n=[];for(let i=0;i<t;++i)e(i)!==null&&n.push(e(i));return n}createObjList(e,t){const n=[];for(let i=0;i<t;++i){const s=e(i);s!==null&&n.push(s.unpack())}return n}}class Ao{constructor(e){this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null;let t;e?t=e:t=1024,this.bb=Ti.allocate(t),this.space=t}clear(){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,this.string_maps=null}forceDefaults(e){this.force_defaults=e}dataBuffer(){return this.bb}asUint8Array(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())}prep(e,t){e>this.minalign&&(this.minalign=e);const n=~(this.bb.capacity()-this.space+t)+1&e-1;for(;this.space<n+e+t;){const i=this.bb.capacity();this.bb=Ao.growByteBuffer(this.bb),this.space+=this.bb.capacity()-i}this.pad(n)}pad(e){for(let t=0;t<e;t++)this.bb.writeInt8(--this.space,0)}writeInt8(e){this.bb.writeInt8(this.space-=1,e)}writeInt16(e){this.bb.writeInt16(this.space-=2,e)}writeInt32(e){this.bb.writeInt32(this.space-=4,e)}writeInt64(e){this.bb.writeInt64(this.space-=8,e)}writeFloat32(e){this.bb.writeFloat32(this.space-=4,e)}writeFloat64(e){this.bb.writeFloat64(this.space-=8,e)}addInt8(e){this.prep(1,0),this.writeInt8(e)}addInt16(e){this.prep(2,0),this.writeInt16(e)}addInt32(e){this.prep(4,0),this.writeInt32(e)}addInt64(e){this.prep(8,0),this.writeInt64(e)}addFloat32(e){this.prep(4,0),this.writeFloat32(e)}addFloat64(e){this.prep(8,0),this.writeFloat64(e)}addFieldInt8(e,t,n){(this.force_defaults||t!=n)&&(this.addInt8(t),this.slot(e))}addFieldInt16(e,t,n){(this.force_defaults||t!=n)&&(this.addInt16(t),this.slot(e))}addFieldInt32(e,t,n){(this.force_defaults||t!=n)&&(this.addInt32(t),this.slot(e))}addFieldInt64(e,t,n){(this.force_defaults||!t.equals(n))&&(this.addInt64(t),this.slot(e))}addFieldFloat32(e,t,n){(this.force_defaults||t!=n)&&(this.addFloat32(t),this.slot(e))}addFieldFloat64(e,t,n){(this.force_defaults||t!=n)&&(this.addFloat64(t),this.slot(e))}addFieldOffset(e,t,n){(this.force_defaults||t!=n)&&(this.addOffset(t),this.slot(e))}addFieldStruct(e,t,n){t!=n&&(this.nested(t),this.slot(e))}nested(e){if(e!=this.offset())throw new Error("FlatBuffers: struct must be serialized inline.")}notNested(){if(this.isNested)throw new Error("FlatBuffers: object serialization must not be nested.")}slot(e){this.vtable!==null&&(this.vtable[e]=this.offset())}offset(){return this.bb.capacity()-this.space}static growByteBuffer(e){const t=e.capacity();if(t&3221225472)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");const n=t<<1,i=Ti.allocate(n);return i.setPosition(n-t),i.bytes().set(e.bytes(),n-t),i}addOffset(e){this.prep(Nt,0),this.writeInt32(this.offset()-e+Nt)}startObject(e){this.notNested(),this.vtable==null&&(this.vtable=[]),this.vtable_in_use=e;for(let t=0;t<e;t++)this.vtable[t]=0;this.isNested=!0,this.object_start=this.offset()}endObject(){if(this.vtable==null||!this.isNested)throw new Error("FlatBuffers: endObject called without startObject");this.addInt32(0);const e=this.offset();let t=this.vtable_in_use-1;for(;t>=0&&this.vtable[t]==0;t--);const n=t+1;for(;t>=0;t--)this.addInt16(this.vtable[t]!=0?e-this.vtable[t]:0);const i=2;this.addInt16(e-this.object_start);const s=(n+i)*Ms;this.addInt16(s);let a=0;const o=this.space;e:for(t=0;t<this.vtables.length;t++){const c=this.bb.capacity()-this.vtables[t];if(s==this.bb.readInt16(c)){for(let l=Ms;l<s;l+=Ms)if(this.bb.readInt16(o+l)!=this.bb.readInt16(c+l))continue e;a=this.vtables[t];break}}return a?(this.space=this.bb.capacity()-e,this.bb.writeInt32(this.space,a-e)):(this.vtables.push(this.offset()),this.bb.writeInt32(this.bb.capacity()-e,this.offset()-e)),this.isNested=!1,e}finish(e,t,n){const i=n?_a:0;if(t){const s=t;if(this.prep(this.minalign,Nt+Xt+i),s.length!=Xt)throw new Error("FlatBuffers: file identifier must be length "+Xt);for(let a=Xt-1;a>=0;a--)this.writeInt8(s.charCodeAt(a))}this.prep(this.minalign,Nt+i),this.addOffset(e),i&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(e,t){this.finish(e,t,!0)}requiredField(e,t){const n=this.bb.capacity()-e,i=n-this.bb.readInt32(n);if(this.bb.readInt16(i+t)==0)throw new Error("FlatBuffers: field "+t+" must be set")}startVector(e,t,n){this.notNested(),this.vector_num_elems=t,this.prep(Nt,e*t),this.prep(n,e*t)}endVector(){return this.writeInt32(this.vector_num_elems),this.offset()}createSharedString(e){if(!e)return 0;if(this.string_maps||(this.string_maps=new Map),this.string_maps.has(e))return this.string_maps.get(e);const t=this.createString(e);return this.string_maps.set(e,t),t}createString(e){if(!e)return 0;let t;if(e instanceof Uint8Array)t=e;else{t=[];let n=0;for(;n<e.length;){let i;const s=e.charCodeAt(n++);if(s<55296||s>=56320)i=s;else{const a=e.charCodeAt(n++);i=(s<<10)+a+-56613888}i<128?t.push(i):(i<2048?t.push(i>>6&31|192):(i<65536?t.push(i>>12&15|224):t.push(i>>18&7|240,i>>12&63|128),t.push(i>>6&63|128)),t.push(i&63|128))}}this.addInt8(0),this.startVector(1,t.length,1),this.bb.setPosition(this.space-=t.length);for(let n=0,i=this.space,s=this.bb.bytes();n<t.length;n++)s[i++]=t[n];return this.endVector()}createLong(e,t){return en.create(e,t)}createObjectOffset(e){return e===null?0:typeof e=="string"?this.createString(e):e.pack(this)}createObjectOffsetList(e){const t=[];for(let n=0;n<e.length;++n){const i=e[n];if(i!==null)t.push(this.createObjectOffset(i));else throw new Error("FlatBuffers: Argument for createObjectOffsetList cannot contain null.")}return t}createStructOffsetList(e,t){return t(this,e.length),this.createObjectOffsetList(e),this.endVector()}}const Ie={ComponentState:Object.freeze({DEFAULT:"default",TOUCHED:"touched",PRESSED:"pressed"}),ComponentProperty:Object.freeze({BUTTON:"button",X_AXIS:"xAxis",Y_AXIS:"yAxis",STATE:"state"}),ButtonTouchThreshold:.05,AxisTouchThreshold:.1,VisualResponseProperty:Object.freeze({TRANSFORM:"transform",VISIBILITY:"visibility"})};async function Ca(r){const e=await fetch(r);if(e.ok)return e.json();throw new Error(e.statusText)}async function Iu(r){return await Ca(`${r}/profilesList.json`)}async function Bu(r,e,t=null,n=!0){if(!r)throw new Error("No xrInputSource supplied");const i=await Iu(e);let s;if(r.profiles.some(c=>{const l=i[c];return l&&(s={profileId:c,profilePath:`${e}/${l.path}`,deprecated:!!l.deprecated}),!!s}),!s){if(!t)throw new Error("No matching profile name found");const c=i[t];if(!c)throw new Error(`No matching profile name found and default profile "${t}" missing.`);s={profileId:t,profilePath:`${e}/${c.path}`,deprecated:!!c.deprecated}}const a=await Ca(s.profilePath);let o;if(n){let c;if(r.handedness==="any"?c=a.layouts[Object.keys(a.layouts)[0]]:c=a.layouts[r.handedness],!c)throw new Error(`No matching handedness, ${r.handedness}, in profile ${s.profileId}`);c.assetPath&&(o=s.profilePath.replace("profile.json",c.assetPath))}return{profile:a,assetPath:o}}const zu={xAxis:0,yAxis:0,button:0,state:Ie.ComponentState.DEFAULT};function Nu(r=0,e=0){let t=r,n=e;if(Math.sqrt(r*r+e*e)>1){const i=Math.atan2(e,r);t=Math.cos(i),n=Math.sin(i)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:n*.5+.5}}class Uu{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===Ie.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(zu)}updateFromComponent({xAxis:e,yAxis:t,button:n,state:i}){const{normalizedXAxis:s,normalizedYAxis:a}=Nu(e,t);switch(this.componentProperty){case Ie.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?s:.5;break;case Ie.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?a:.5;break;case Ie.ComponentProperty.BUTTON:this.value=this.states.includes(i)?n:0;break;case Ie.ComponentProperty.STATE:this.valueNodeProperty===Ie.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(i):this.value=this.states.includes(i)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class Du{constructor(e,t){if(!e||!t||!t.visualResponses||!t.gamepadIndices||Object.keys(t.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=e,this.type=t.type,this.rootNodeName=t.rootNodeName,this.touchPointNodeName=t.touchPointNodeName,this.visualResponses={},Object.keys(t.visualResponses).forEach(n=>{const i=new Uu(t.visualResponses[n]);this.visualResponses[n]=i}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:Ie.ComponentState.DEFAULT,button:this.gamepadIndices.button!==void 0?0:void 0,xAxis:this.gamepadIndices.xAxis!==void 0?0:void 0,yAxis:this.gamepadIndices.yAxis!==void 0?0:void 0}}get data(){return{id:this.id,...this.values}}updateFromGamepad(e){if(this.values.state=Ie.ComponentState.DEFAULT,this.gamepadIndices.button!==void 0&&e.buttons.length>this.gamepadIndices.button){const t=e.buttons[this.gamepadIndices.button];this.values.button=t.value,this.values.button=this.values.button<0?0:this.values.button,this.values.button=this.values.button>1?1:this.values.button,t.pressed||this.values.button===1?this.values.state=Ie.ComponentState.PRESSED:(t.touched||this.values.button>Ie.ButtonTouchThreshold)&&(this.values.state=Ie.ComponentState.TOUCHED)}this.gamepadIndices.xAxis!==void 0&&e.axes.length>this.gamepadIndices.xAxis&&(this.values.xAxis=e.axes[this.gamepadIndices.xAxis],this.values.xAxis=this.values.xAxis<-1?-1:this.values.xAxis,this.values.xAxis=this.values.xAxis>1?1:this.values.xAxis,this.values.state===Ie.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>Ie.AxisTouchThreshold&&(this.values.state=Ie.ComponentState.TOUCHED)),this.gamepadIndices.yAxis!==void 0&&e.axes.length>this.gamepadIndices.yAxis&&(this.values.yAxis=e.axes[this.gamepadIndices.yAxis],this.values.yAxis=this.values.yAxis<-1?-1:this.values.yAxis,this.values.yAxis=this.values.yAxis>1?1:this.values.yAxis,this.values.state===Ie.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>Ie.AxisTouchThreshold&&(this.values.state=Ie.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class Lu{constructor(e,t,n){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=n,this.id=t.profileId,this.layoutDescription=t.layouts[e.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(i=>{const s=this.layoutDescription.components[i];this.components[i]=new Du(i,s)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const e=[];return Object.values(this.components).forEach(t=>{e.push(t.data)}),e}updateFromGamepad(){Object.values(this.components).forEach(e=>{e.updateFromGamepad(this.xrInputSource.gamepad)})}}const We=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Pa=1234567;const Ea=Math.PI/180,ka=180/Math.PI;function Fu(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(We[r&255]+We[r>>8&255]+We[r>>16&255]+We[r>>24&255]+"-"+We[e&255]+We[e>>8&255]+"-"+We[e>>16&15|64]+We[e>>24&255]+"-"+We[t&63|128]+We[t>>8&255]+"-"+We[t>>16&255]+We[t>>24&255]+We[n&255]+We[n>>8&255]+We[n>>16&255]+We[n>>24&255]).toLowerCase()}function Ut(r,e,t){return Math.max(e,Math.min(t,r))}function Ra(r,e){return(r%e+e)%e}function Vu(r,e,t,n,i){return n+(r-e)*(i-n)/(t-e)}function ju(r,e,t){return r!==e?(t-r)/(e-r):0}function Aa(r,e,t){return(1-t)*r+t*e}function Ju(r,e,t,n){return Aa(r,e,1-Math.exp(-t*n))}function Gu(r,e=1){return e-Math.abs(Ra(r,e*2)-e)}function Wu(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function Hu(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function qu(r,e){return r+Math.floor(Math.random()*(e-r+1))}function Xu(r,e){return r+Math.random()*(e-r)}function Yu(r){return r*(.5-Math.random())}function Zu(r){r!==void 0&&(Pa=r);let e=Pa+=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 Ku(r){return r*Ea}function Qu(r){return r*ka}function $u(r){return(r&r-1)===0&&r!==0}function eh(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function th(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function nh(r,e,t,n,i){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+n)/2),u=a((e+n)/2),d=s((e-n)/2),f=a((e-n)/2),m=s((n-e)/2),x=a((n-e)/2);switch(i){case"XYX":r.set(o*u,c*d,c*f,o*l);break;case"YZY":r.set(c*f,o*u,c*d,o*l);break;case"ZXZ":r.set(c*d,c*f,o*u,o*l);break;case"XZX":r.set(o*u,c*x,c*m,o*l);break;case"YXY":r.set(c*m,o*u,c*x,o*l);break;case"ZYZ":r.set(c*x,c*m,o*u,o*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function ih(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function rh(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}const Bn={DEG2RAD:Ea,RAD2DEG:ka,generateUUID:Fu,clamp:Ut,euclideanModulo:Ra,mapLinear:Vu,inverseLerp:ju,lerp:Aa,damp:Ju,pingpong:Gu,smoothstep:Wu,smootherstep:Hu,randInt:qu,randFloat:Xu,randFloatSpread:Yu,seededRandom:Zu,degToRad:Ku,radToDeg:Qu,isPowerOfTwo:$u,ceilPowerOfTwo:eh,floorPowerOfTwo:th,setQuaternionFromProperEuler:nh,normalize:rh,denormalize:ih};class ie{constructor(e=0,t=0,n=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,s,a,o){let c=n[i+0],l=n[i+1],u=n[i+2],d=n[i+3];const f=s[a+0],m=s[a+1],x=s[a+2],_=s[a+3];if(o===0){e[t+0]=c,e[t+1]=l,e[t+2]=u,e[t+3]=d;return}if(o===1){e[t+0]=f,e[t+1]=m,e[t+2]=x,e[t+3]=_;return}if(d!==_||c!==f||l!==m||u!==x){let g=1-o;const v=c*f+l*m+u*x+d*_,w=v>=0?1:-1,S=1-v*v;if(S>Number.EPSILON){const M=Math.sqrt(S),P=Math.atan2(M,v*w);g=Math.sin(g*P)/M,o=Math.sin(o*P)/M}const T=o*w;if(c=c*g+f*T,l=l*g+m*T,u=u*g+x*T,d=d*g+_*T,g===1-o){const M=1/Math.sqrt(c*c+l*l+u*u+d*d);c*=M,l*=M,u*=M,d*=M}}e[t]=c,e[t+1]=l,e[t+2]=u,e[t+3]=d}static multiplyQuaternionsFlat(e,t,n,i,s,a){const o=n[i],c=n[i+1],l=n[i+2],u=n[i+3],d=s[a],f=s[a+1],m=s[a+2],x=s[a+3];return e[t]=o*x+u*d+c*m-l*f,e[t+1]=c*x+u*f+l*d-o*m,e[t+2]=l*x+u*m+o*f-c*d,e[t+3]=u*x-o*d-c*f-l*m,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,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new ie(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 n=e._x,i=e._y,s=e._z,a=e._order,o=Math.cos,c=Math.sin,l=o(n/2),u=o(i/2),d=o(s/2),f=c(n/2),m=c(i/2),x=c(s/2);switch(a){case"XYZ":this._x=f*u*d+l*m*x,this._y=l*m*d-f*u*x,this._z=l*u*x+f*m*d,this._w=l*u*d-f*m*x;break;case"YXZ":this._x=f*u*d+l*m*x,this._y=l*m*d-f*u*x,this._z=l*u*x-f*m*d,this._w=l*u*d+f*m*x;break;case"ZXY":this._x=f*u*d-l*m*x,this._y=l*m*d+f*u*x,this._z=l*u*x+f*m*d,this._w=l*u*d-f*m*x;break;case"ZYX":this._x=f*u*d-l*m*x,this._y=l*m*d+f*u*x,this._z=l*u*x-f*m*d,this._w=l*u*d+f*m*x;break;case"YZX":this._x=f*u*d+l*m*x,this._y=l*m*d+f*u*x,this._z=l*u*x-f*m*d,this._w=l*u*d-f*m*x;break;case"XZY":this._x=f*u*d-l*m*x,this._y=l*m*d-f*u*x,this._z=l*u*x+f*m*d,this._w=l*u*d+f*m*x;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,n=t[0],i=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],u=t[6],d=t[10],f=n+o+d;if(f>0){const m=.5/Math.sqrt(f+1);this._w=.25/m,this._x=(u-c)*m,this._y=(s-l)*m,this._z=(a-i)*m}else if(n>o&&n>d){const m=2*Math.sqrt(1+n-o-d);this._w=(u-c)/m,this._x=.25*m,this._y=(i+a)/m,this._z=(s+l)/m}else if(o>d){const m=2*Math.sqrt(1+o-n-d);this._w=(s-l)/m,this._x=(i+a)/m,this._y=.25*m,this._z=(c+u)/m}else{const m=2*Math.sqrt(1+d-n-o);this._w=(a-i)/m,this._x=(s+l)/m,this._y=(c+u)/m,this._z=.25*m}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<Number.EPSILON?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(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=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Ut(this.dot(e),-1,1)))}rotateTowards(e,t){const n=this.angleTo(e);if(n===0)return this;const i=Math.min(1,t/n);return this.slerp(e,i),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 n=e._x,i=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,u=t._w;return this._x=n*u+a*o+i*l-s*c,this._y=i*u+a*c+s*o-n*l,this._z=s*u+a*l+n*c-i*o,this._w=a*u-n*o-i*c-s*l,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const n=this._x,i=this._y,s=this._z,a=this._w;let o=a*e._w+n*e._x+i*e._y+s*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=a,this._x=n,this._y=i,this._z=s,this;const c=1-o*o;if(c<=Number.EPSILON){const m=1-t;return this._w=m*a+t*this._w,this._x=m*n+t*this._x,this._y=m*i+t*this._y,this._z=m*s+t*this._z,this.normalize(),this}const l=Math.sqrt(c),u=Math.atan2(l,o),d=Math.sin((1-t)*u)/l,f=Math.sin(t*u)/l;return this._w=a*d+this._w*f,this._x=n*d+this._x*f,this._y=i*d+this._y*f,this._z=s*d+this._z*f,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}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}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 G{constructor(e=0,t=0,n=0){this.isVector3=!0,G.prototype.isVector3=!0,this.x=e,this.y=t,this.z=n}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,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 G(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(Oa.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Oa.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*i,this.y=s[1]*t+s[4]*n+s[7]*i,this.z=s[2]*t+s[5]*n+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=e.elements,a=1/(s[3]*t+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*i+s[12])*a,this.y=(s[1]*t+s[5]*n+s[9]*i+s[13])*a,this.z=(s[2]*t+s[6]*n+s[10]*i+s[14])*a,this}applyQuaternion(e){const t=this.x,n=this.y,i=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*i-o*n),u=2*(o*t-s*i),d=2*(s*n-a*t);return this.x=t+c*l+a*d-o*u,this.y=n+c*u+o*l-s*d,this.z=i+c*d+s*u-a*l,this}transformDirection(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*i,this.y=s[1]*t+s[5]*n+s[9]*i,this.z=s[2]*t+s[6]*n+s[10]*i,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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}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,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const n=e.x,i=e.y,s=e.z,a=t.x,o=t.y,c=t.z;return this.x=i*c-s*o,this.y=s*a-n*c,this.z=n*o-i*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return Ps.copy(this).projectOnVector(e),this.sub(Ps)}reflect(e){return this.sub(Ps.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 n=this.dot(e)/t;return Math.acos(Ut(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSphericalCoords(e,t,n){const i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,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(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,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}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}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Ps=new G,Oa=new ie,dr=2e3,Ia=2001;class It{constructor(e,t,n,i,s,a,o,c,l,u,d,f,m,x,_,g){this.isMatrix4=!0,It.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,n,i,s,a,o,c,l,u,d,f,m,x,_,g)}extractPosition(e){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(e)}multiplyToArray(e,t,n){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(e){return this.makeRotationFromQuaternion(e)}set(e,t,n,i,s,a,o,c,l,u,d,f,m,x,_,g){const v=this.elements;return v[0]=e,v[4]=t,v[8]=n,v[12]=i,v[1]=s,v[5]=a,v[9]=o,v[13]=c,v[2]=l,v[6]=u,v[10]=d,v[14]=f,v[3]=m,v[7]=x,v[11]=_,v[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 It().fromArray(this.elements)}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){const t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[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,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,n=e.elements,i=1/zn.setFromMatrixColumn(e,0).length(),s=1/zn.setFromMatrixColumn(e,1).length(),a=1/zn.setFromMatrixColumn(e,2).length();return t[0]=n[0]*i,t[1]=n[1]*i,t[2]=n[2]*i,t[3]=0,t[4]=n[4]*s,t[5]=n[5]*s,t[6]=n[6]*s,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,n=e.x,i=e.y,s=e.z,a=Math.cos(n),o=Math.sin(n),c=Math.cos(i),l=Math.sin(i),u=Math.cos(s),d=Math.sin(s);if(e.order==="XYZ"){const f=a*u,m=a*d,x=o*u,_=o*d;t[0]=c*u,t[4]=-c*d,t[8]=l,t[1]=m+x*l,t[5]=f-_*l,t[9]=-o*c,t[2]=_-f*l,t[6]=x+m*l,t[10]=a*c}else if(e.order==="YXZ"){const f=c*u,m=c*d,x=l*u,_=l*d;t[0]=f+_*o,t[4]=x*o-m,t[8]=a*l,t[1]=a*d,t[5]=a*u,t[9]=-o,t[2]=m*o-x,t[6]=_+f*o,t[10]=a*c}else if(e.order==="ZXY"){const f=c*u,m=c*d,x=l*u,_=l*d;t[0]=f-_*o,t[4]=-a*d,t[8]=x+m*o,t[1]=m+x*o,t[5]=a*u,t[9]=_-f*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const f=a*u,m=a*d,x=o*u,_=o*d;t[0]=c*u,t[4]=x*l-m,t[8]=f*l+_,t[1]=c*d,t[5]=_*l+f,t[9]=m*l-x,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const f=a*c,m=a*l,x=o*c,_=o*l;t[0]=c*u,t[4]=_-f*d,t[8]=x*d+m,t[1]=d,t[5]=a*u,t[9]=-o*u,t[2]=-l*u,t[6]=m*d+x,t[10]=f-_*d}else if(e.order==="XZY"){const f=a*c,m=a*l,x=o*c,_=o*l;t[0]=c*u,t[4]=-d,t[8]=l*u,t[1]=f*d+_,t[5]=a*u,t[9]=m*d-x,t[2]=x*d-m,t[6]=o*u,t[10]=_*d+f}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(sh,e,oh)}lookAt(e,t,n){const i=this.elements;return pt.subVectors(e,t),pt.lengthSq()===0&&(pt.z=1),pt.normalize(),sn.crossVectors(n,pt),sn.lengthSq()===0&&(Math.abs(n.z)===1?pt.x+=1e-4:pt.z+=1e-4,pt.normalize(),sn.crossVectors(n,pt)),sn.normalize(),pr.crossVectors(pt,sn),i[0]=sn.x,i[4]=pr.x,i[8]=pt.x,i[1]=sn.y,i[5]=pr.y,i[9]=pt.y,i[2]=sn.z,i[6]=pr.z,i[10]=pt.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,a=n[0],o=n[4],c=n[8],l=n[12],u=n[1],d=n[5],f=n[9],m=n[13],x=n[2],_=n[6],g=n[10],v=n[14],w=n[3],S=n[7],T=n[11],M=n[15],P=i[0],E=i[4],O=i[8],A=i[12],R=i[1],B=i[5],I=i[9],U=i[13],L=i[2],J=i[6],H=i[10],se=i[14],W=i[3],pe=i[7],ne=i[11],he=i[15];return s[0]=a*P+o*R+c*L+l*W,s[4]=a*E+o*B+c*J+l*pe,s[8]=a*O+o*I+c*H+l*ne,s[12]=a*A+o*U+c*se+l*he,s[1]=u*P+d*R+f*L+m*W,s[5]=u*E+d*B+f*J+m*pe,s[9]=u*O+d*I+f*H+m*ne,s[13]=u*A+d*U+f*se+m*he,s[2]=x*P+_*R+g*L+v*W,s[6]=x*E+_*B+g*J+v*pe,s[10]=x*O+_*I+g*H+v*ne,s[14]=x*A+_*U+g*se+v*he,s[3]=w*P+S*R+T*L+M*W,s[7]=w*E+S*B+T*J+M*pe,s[11]=w*O+S*I+T*H+M*ne,s[15]=w*A+S*U+T*se+M*he,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],n=e[4],i=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],u=e[2],d=e[6],f=e[10],m=e[14],x=e[3],_=e[7],g=e[11],v=e[15];return x*(+s*c*d-i*l*d-s*o*f+n*l*f+i*o*m-n*c*m)+_*(+t*c*m-t*l*f+s*a*f-i*a*m+i*l*u-s*c*u)+g*(+t*l*d-t*o*m-s*a*d+n*a*m+s*o*u-n*l*u)+v*(-i*o*u-t*c*d+t*o*f+i*a*d-n*a*f+n*c*u)}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,n){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=n),this}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],d=e[9],f=e[10],m=e[11],x=e[12],_=e[13],g=e[14],v=e[15],w=d*g*l-_*f*l+_*c*m-o*g*m-d*c*v+o*f*v,S=x*f*l-u*g*l-x*c*m+a*g*m+u*c*v-a*f*v,T=u*_*l-x*d*l+x*o*m-a*_*m-u*o*v+a*d*v,M=x*d*c-u*_*c-x*o*f+a*_*f+u*o*g-a*d*g,P=t*w+n*S+i*T+s*M;if(P===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/P;return e[0]=w*E,e[1]=(_*f*s-d*g*s-_*i*m+n*g*m+d*i*v-n*f*v)*E,e[2]=(o*g*s-_*c*s+_*i*l-n*g*l-o*i*v+n*c*v)*E,e[3]=(d*c*s-o*f*s-d*i*l+n*f*l+o*i*m-n*c*m)*E,e[4]=S*E,e[5]=(u*g*s-x*f*s+x*i*m-t*g*m-u*i*v+t*f*v)*E,e[6]=(x*c*s-a*g*s-x*i*l+t*g*l+a*i*v-t*c*v)*E,e[7]=(a*f*s-u*c*s+u*i*l-t*f*l-a*i*m+t*c*m)*E,e[8]=T*E,e[9]=(x*d*s-u*_*s-x*n*m+t*_*m+u*n*v-t*d*v)*E,e[10]=(a*_*s-x*o*s+x*n*l-t*_*l-a*n*v+t*o*v)*E,e[11]=(u*o*s-a*d*s-u*n*l+t*d*l+a*n*m-t*o*m)*E,e[12]=M*E,e[13]=(u*_*i-x*d*i+x*n*f-t*_*f-u*n*g+t*d*g)*E,e[14]=(x*o*i-a*_*i-x*n*c+t*_*c+a*n*g-t*o*g)*E,e[15]=(a*d*i-u*o*i+u*n*c-t*d*c-a*n*f+t*o*f)*E,this}scale(e){const t=this.elements,n=e.x,i=e.y,s=e.z;return t[0]*=n,t[4]*=i,t[8]*=s,t[1]*=n,t[5]*=i,t[9]*=s,t[2]*=n,t[6]*=i,t[10]*=s,t[3]*=n,t[7]*=i,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,i))}makeTranslation(e,t,n){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,n,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const n=Math.cos(t),i=Math.sin(t),s=1-n,a=e.x,o=e.y,c=e.z,l=s*a,u=s*o;return this.set(l*a+n,l*o-i*c,l*c+i*o,0,l*o+i*c,u*o+n,u*c-i*a,0,l*c-i*o,u*c+i*a,s*c*c+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,i,s,a){return this.set(1,n,s,0,e,1,a,0,t,i,1,0,0,0,0,1),this}compose(e,t,n){const i=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,u=a+a,d=o+o,f=s*l,m=s*u,x=s*d,_=a*u,g=a*d,v=o*d,w=c*l,S=c*u,T=c*d,M=n.x,P=n.y,E=n.z;return i[0]=(1-(_+v))*M,i[1]=(m+T)*M,i[2]=(x-S)*M,i[3]=0,i[4]=(m-T)*P,i[5]=(1-(f+v))*P,i[6]=(g+w)*P,i[7]=0,i[8]=(x+S)*E,i[9]=(g-w)*E,i[10]=(1-(f+_))*E,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,n){const i=this.elements;let s=zn.set(i[0],i[1],i[2]).length();const a=zn.set(i[4],i[5],i[6]).length(),o=zn.set(i[8],i[9],i[10]).length();this.determinant()<0&&(s=-s),e.x=i[12],e.y=i[13],e.z=i[14],Rt.copy(this);const c=1/s,l=1/a,u=1/o;return Rt.elements[0]*=c,Rt.elements[1]*=c,Rt.elements[2]*=c,Rt.elements[4]*=l,Rt.elements[5]*=l,Rt.elements[6]*=l,Rt.elements[8]*=u,Rt.elements[9]*=u,Rt.elements[10]*=u,t.setFromRotationMatrix(Rt),n.x=s,n.y=a,n.z=o,this}makePerspective(e,t,n,i,s,a,o=dr){const c=this.elements,l=2*s/(t-e),u=2*s/(n-i),d=(t+e)/(t-e),f=(n+i)/(n-i);let m,x;if(o===dr)m=-(a+s)/(a-s),x=-2*a*s/(a-s);else if(o===Ia)m=-a/(a-s),x=-a*s/(a-s);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=l,c[4]=0,c[8]=d,c[12]=0,c[1]=0,c[5]=u,c[9]=f,c[13]=0,c[2]=0,c[6]=0,c[10]=m,c[14]=x,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,i,s,a,o=dr){const c=this.elements,l=1/(t-e),u=1/(n-i),d=1/(a-s),f=(t+e)*l,m=(n+i)*u;let x,_;if(o===dr)x=(a+s)*d,_=-2*d;else if(o===Ia)x=s*d,_=-1*d;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-f,c[1]=0,c[5]=2*u,c[9]=0,c[13]=-m,c[2]=0,c[6]=0,c[10]=_,c[14]=-x,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<16;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}}const zn=new G,Rt=new It,sh=new G(0,0,0),oh=new G(1,1,1),sn=new G,pr=new G,pt=new G,Ba=new It,za=new ie;class Mi{constructor(e=0,t=0,n=0,i=Mi.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=i}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,n,i=this._order){return this._x=e,this._y=t,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new Mi(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,n=!0){const i=e.elements,s=i[0],a=i[4],o=i[8],c=i[1],l=i[5],u=i[9],d=i[2],f=i[6],m=i[10];switch(t){case"XYZ":this._y=Math.asin(Ut(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,m),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(f,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Ut(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,m),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-d,s),this._z=0);break;case"ZXY":this._x=Math.asin(Ut(f,-1,1)),Math.abs(f)<.9999999?(this._y=Math.atan2(-d,m),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Ut(d,-1,1)),Math.abs(d)<.9999999?(this._x=Math.atan2(f,m),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin(Ut(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-u,l),this._y=Math.atan2(-d,s)):(this._x=0,this._y=Math.atan2(o,m));break;case"XZY":this._z=Math.asin(-Ut(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(f,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-u,m),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return Ba.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Ba,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return za.setFromEuler(this),this.setFromQuaternion(za,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(e){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Mi.DEFAULT_ORDER="XYZ";class Xn{constructor(e=0,t=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 Xn(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,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}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 n=this.dot(e)/t;return Math.acos(Ut(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y;return t*t+n*n}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,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,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}rotateAround(e,t){const n=Math.cos(t),i=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*n-a*i+e.x,this.y=s*i+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}Xn.isVector2=!0;class ct{constructor(e=0,t=0,n=0,i=1){ct.prototype.isVector4=!0,this.x=e,this.y=t,this.z=n,this.w=i}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,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,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 ct(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}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,n=this.y,i=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*i+a[12]*s,this.y=a[1]*t+a[5]*n+a[9]*i+a[13]*s,this.z=a[2]*t+a[6]*n+a[10]*i+a[14]*s,this.w=a[3]*t+a[7]*n+a[11]*i+a[15]*s,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,n,i,s;const a=e.elements,o=a[0],c=a[4],l=a[8],u=a[1],d=a[5],f=a[9],m=a[2],x=a[6],_=a[10];if(Math.abs(c-u)<.01&&Math.abs(l-m)<.01&&Math.abs(f-x)<.01){if(Math.abs(c+u)<.1&&Math.abs(l+m)<.1&&Math.abs(f+x)<.1&&Math.abs(o+d+_-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const v=(o+1)/2,w=(d+1)/2,S=(_+1)/2,T=(c+u)/4,M=(l+m)/4,P=(f+x)/4;return v>w&&v>S?v<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(v),i=T/n,s=M/n):w>S?w<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(w),n=T/i,s=P/i):S<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(S),n=M/s,i=P/s),this.set(n,i,s,t),this}let g=Math.sqrt((x-f)*(x-f)+(l-m)*(l-m)+(u-c)*(u-c));return Math.abs(g)<.001&&(g=1),this.x=(x-f)/g,this.y=(l-m)/g,this.z=(u-c)/g,this.w=Math.acos((o+d+_-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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}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,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,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}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 Vt{constructor(e,t,n,i,s,a,o,c,l){Vt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,a,o,c,l)}set(e,t,n,i,s,a,o,c,l){const u=this.elements;return u[0]=e,u[1]=i,u[2]=o,u[3]=t,u[4]=s,u[5]=c,u[6]=n,u[7]=a,u[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.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 n=e.elements,i=t.elements,s=this.elements,a=n[0],o=n[3],c=n[6],l=n[1],u=n[4],d=n[7],f=n[2],m=n[5],x=n[8],_=i[0],g=i[3],v=i[6],w=i[1],S=i[4],T=i[7],M=i[2],P=i[5],E=i[8];return s[0]=a*_+o*w+c*M,s[3]=a*g+o*S+c*P,s[6]=a*v+o*T+c*E,s[1]=l*_+u*w+d*M,s[4]=l*g+u*S+d*P,s[7]=l*v+u*T+d*E,s[2]=f*_+m*w+x*M,s[5]=f*g+m*S+x*P,s[8]=f*v+m*T+x*E,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],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8];return t*a*u-t*o*l-n*s*u+n*o*c+i*s*l-i*a*c}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],d=u*a-o*l,f=o*c-u*s,m=l*s-a*c,x=t*d+n*f+i*m;if(x===0)return this.set(0,0,0,0,0,0,0,0,0);const _=1/x;return e[0]=d*_,e[1]=(i*l-u*n)*_,e[2]=(o*n-i*a)*_,e[3]=f*_,e[4]=(u*t-i*c)*_,e[5]=(i*s-o*t)*_,e[6]=m*_,e[7]=(n*c-l*t)*_,e[8]=(a*t-n*s)*_,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,n,i,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(n*c,n*l,-n*(c*a+l*o)+a+e,-i*l,i*c,-i*(-l*a+c*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(Es.makeScale(e,t)),this}rotate(e){return this.premultiply(Es.makeRotation(-e)),this}translate(e,t){return this.premultiply(Es.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),n=Math.sin(e);return this.set(t,-n,0,n,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,n=e.elements;for(let i=0;i<9;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new Vt().fromArray(this.elements)}}const Es=new Vt;var tt;(function(r){r[r.Random=0]="Random",r[r.Loop=1]="Loop",r[r.PingPong=2]="PingPong",r[r.Burst=3]="Burst"})(tt||(tt={}));function ni(r,e,t,n){let i;switch(tt.Random===r?e=Math.random():tt.Burst===r&&n.isBursting&&(e=n.burstParticleIndex/n.burstParticleCount),t>0?i=Math.floor(e/t)*t:i=e,r){case tt.Loop:i=i%1;break;case tt.PingPong:i=Math.abs(i%2-1);break}return i}class Mn{constructor(e,t,n,i){this.p=[e,t,n,i]}genValue(e){const t=e*e,n=e*e*e,i=1-e,s=i*i,a=s*i;return this.p[0]*a+this.p[1]*s*e*3+this.p[2]*i*t*3+this.p[3]*n}derivativeCoefficients(e){const t=[];for(let n=e,i=n.length-1;i>0;i--){const s=[];for(let a=0;a<i;a++){const o=i*(n[a+1]-n[a]);s.push(o)}t.push(s),n=s}return t}getSlope(e){const t=this.derivativeCoefficients(this.p)[0],n=1-e,i=n*n,s=n*e*2,a=e*e;return i*t[0]+s*t[1]+a*t[2]}controlCurve(e,t){this.p[1]=e/3+this.p[0],this.p[2]=this.p[3]-t/3}hull(e){let t=this.p,n=[],i,s=0,a=0,o=0;const c=[];for(c[s++]=t[0],c[s++]=t[1],c[s++]=t[2],c[s++]=t[3];t.length>1;){for(n=[],a=0,o=t.length-1;a<o;a++)i=e*t[a]+(1-e)*t[a+1],c[s++]=i,n.push(i);t=n}return c}split(e){const t=this.hull(e);return{left:new Mn(t[0],t[4],t[7],t[9]),right:new Mn(t[9],t[8],t[6],t[3]),span:t}}clone(){return new Mn(this.p[0],this.p[1],this.p[2],this.p[3])}toJSON(){return{p0:this.p[0],p1:this.p[1],p2:this.p[2],p3:this.p[3]}}static fromJSON(e){return new Mn(e.p0,e.p1,e.p2,e.p3)}}const ii=r=>({r:r.x,g:r.y,b:r.z,a:r.w}),ri=r=>new ct(r.r,r.g,r.b,r.a),ah=(r,e)=>{switch(e){case"Vector3":return new G(r.x,r.y,r.z);case"Vector4":return new ct(r.x,r.y,r.z,r.w);case"Color":return new G(r.r,r.g,r.b);case"Number":return r;default:return r}},ch=(r,e)=>{switch(e){case"Vector3":return{x:r.x,y:r.y,z:r.z};case"Vector4":return{x:r.x,y:r.y,z:r.z,w:r.w};case"Color":return{r:r.x,g:r.y,b:r.z};case"Number":return r;default:return r}};class ns{constructor(e,t){this.a=e,this.b=t,this.type="value"}startGen(e){}genColor(e,t){const n=Math.random();return t.copy(this.a).lerp(this.b,n)}toJSON(){return{type:"RandomColor",a:ii(this.a),b:ii(this.b)}}static fromJSON(e){return new ns(ri(e.a),ri(e.b))}clone(){return new ns(this.a.clone(),this.b.clone())}}class Yn{constructor(e,t){this.a=e,this.b=t,this.indexCount=-1,this.type="value"}startGen(e){this.indexCount=e.length,e.push(Math.random())}genColor(e,t){return this.indexCount===-1&&this.startGen(e),t.copy(this.a).lerp(this.b,e[this.indexCount])}toJSON(){return{type:"ColorRange",a:ii(this.a),b:ii(this.b)}}static fromJSON(e){return new Yn(ri(e.a),ri(e.b))}clone(){return new Yn(this.a.clone(),this.b.clone())}}class hn{constructor(e,t){this.subType=t,this.type="function",this.keys=e}findKey(e){let t=0,n=0,i=this.keys.length-1;for(;n+1<i;)if(t=Math.floor((n+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))n=t+1;else return t;for(let s=n;s<=i;s++)if(e>=this.getStartX(s)&&e<=this.getEndX(s))return s;return-1}getStartX(e){return this.keys[e][1]}getEndX(e){return e+1<this.keys.length?this.keys[e+1][1]:1}genValue(e,t){const n=this.findKey(t);return this.subType==="Number"?n===-1?this.keys[0][0]:n+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[n+1][0]-this.keys[n][0])*((t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))+this.keys[n][0]:n===-1?e.copy(this.keys[0][0]):n+1>=this.keys.length?e.copy(this.keys[this.keys.length-1][0]):e.copy(this.keys[n][0]).lerp(this.keys[n+1][0],(t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([e,t])=>({value:ch(e,this.subType),pos:t}))}}static fromJSON(e){return new hn(e.keys.map(t=>[ah(t.value,e.subType),t.pos]),e.subType)}clone(){return this.subType==="Number"?new hn(this.keys.map(([e,t])=>[e,t]),this.subType):new hn(this.keys.map(([e,t])=>[e.clone(),t]),this.subType)}}const fr=new G;class kn{constructor(e=[[new G(0,0,0),0],[new G(1,1,1),0]],t=[[1,0],[1,1]]){this.type="function",this.color=new hn(e,"Color"),this.alpha=new hn(t,"Number")}genColor(e,t,n){return this.color.genValue(fr,n),t.set(fr.x,fr.y,fr.z,this.alpha.genValue(1,n))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(e){if(e.functions){const t=e.functions.map(n=>[Yn.fromJSON(n.function).a,n.start]);return e.functions.length>0&&t.push([Yn.fromJSON(e.functions[e.functions.length-1].function).b,1]),new kn(t.map(n=>[new G(n[0].x,n[0].y,n[0].z),n[1]]),t.map(n=>[n[0].w,n[1]]))}else{const t=new kn;return t.alpha=hn.fromJSON(e.alpha),t.color=hn.fromJSON(e.color),t}}clone(){const e=new kn;return e.alpha=this.alpha.clone(),e.color=this.color.clone(),e}startGen(e){}}const ks=new ct;class is{constructor(e,t){this.indexCount=0,this.type="function",this.gradient1=e,this.gradient2=t}startGen(e){this.indexCount=e.length,e.push(Math.random())}genColor(e,t,n){return this.gradient1.genColor(e,t,n),this.gradient2.genColor(e,ks,n),e&&e[this.indexCount]!==void 0?t.lerp(ks,e[this.indexCount]):t.lerp(ks,Math.random()),t}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(e){return new is(kn.fromJSON(e.gradient1),kn.fromJSON(e.gradient2))}clone(){return new is(this.gradient1.clone(),this.gradient2.clone())}}class Cn{constructor(e){this.color=e,this.type="value"}startGen(e){}genColor(e,t){return t.copy(this.color)}toJSON(){return{type:"ConstantColor",color:ii(this.color)}}static fromJSON(e){return new Cn(ri(e.color))}clone(){return new Cn(this.color.clone())}}function Rs(r){switch(r.type){case"ConstantColor":return Cn.fromJSON(r);case"ColorRange":return Yn.fromJSON(r);case"RandomColor":return ns.fromJSON(r);case"Gradient":return kn.fromJSON(r);case"RandomColorBetweenGradient":return is.fromJSON(r);default:return new Cn(new ct(1,1,1,1))}}class te{constructor(e){this.value=e,this.type="value"}startGen(e){}genValue(e){return this.value}toJSON(){return{type:"ConstantValue",value:this.value}}static fromJSON(e){return new te(e.value)}clone(){return new te(this.value)}}class Pn{constructor(e,t){this.a=e,this.b=t,this.indexCount=-1,this.type="value"}startGen(e){this.indexCount=e.length,e.push(Math.random())}genValue(e){return this.indexCount===-1&&this.startGen(e),Bn.lerp(this.a,this.b,e[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(e){return new Pn(e.a,e.b)}clone(){return new Pn(this.a,this.b)}}class lh{constructor(){this.functions=new Array}findFunction(e){let t=0,n=0,i=this.functions.length-1;for(;n+1<i;)if(t=Math.floor((n+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))n=t+1;else return t;for(let s=n;s<=i;s++)if(e>=this.functions[s][1]&&e<=this.getEndX(s))return s;return-1}getStartX(e){return this.functions[e][1]}setStartX(e,t){e>0&&(this.functions[e][1]=t)}getEndX(e){return e+1<this.functions.length?this.functions[e+1][1]:1}setEndX(e,t){e+1<this.functions.length&&(this.functions[e+1][1]=t)}insertFunction(e,t){const n=this.findFunction(e);this.functions.splice(n+1,0,[t,e])}removeFunction(e){return this.functions.splice(e,1)[0][0]}getFunction(e){return this.functions[e][0]}setFunction(e,t){this.functions[e][0]=t}get numOfFunctions(){return this.functions.length}}class Ci extends lh{constructor(e=[[new Mn(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=e}genValue(e,t=0){const n=this.findFunction(t);return n===-1?0:this.functions[n][0].genValue((t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))}toSVG(e,t){if(t<1)return"";let n=["M",0,this.functions[0][0].p[0]].join(" ");for(let i=1/t;i<=1;i+=1/t)n=[n,"L",i*e,this.genValue(void 0,i)].join(" ");return n}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([e,t])=>({function:e.toJSON(),start:t}))}}static fromJSON(e){return new Ci(e.functions.map(t=>[Mn.fromJSON(t.function),t.start]))}clone(){return new Ci(this.functions.map(([e,t])=>[e.clone(),t]))}startGen(e){}}function Q(r){switch(r.type){case"ConstantValue":return te.fromJSON(r);case"IntervalValue":return Pn.fromJSON(r);case"PiecewiseBezier":return Ci.fromJSON(r);default:return new te(0)}}class Pi{constructor(){this.indexCount=0,this.type="rotation"}startGen(e){this.indexCount=e.length,e.push(new ie);let t,n,i,s,a,o;do t=Math.random()*2-1,n=Math.random()*2-1,i=t*t+n*n;while(i>1);do s=Math.random()*2-1,a=Math.random()*2-1,o=s*s+a*a;while(o>1);const c=Math.sqrt((1-i)/o);e[this.indexCount].set(t,n,c*s,c*a)}genValue(e,t,n,i){return this.indexCount===-1&&this.startGen(e),t.copy(e[this.indexCount]),t}toJSON(){return{type:"RandomQuat"}}static fromJSON(e){return new Pi}clone(){return new Pi}}class Ei{constructor(e,t){this.axis=e,this.angle=t,this.type="rotation"}startGen(e){this.angle.startGen(e)}genValue(e,t,n,i){return t.setFromAxisAngle(this.axis,this.angle.genValue(e,i)*n)}toJSON(){return{type:"AxisAngle",axis:{x:this.axis.x,y:this.axis.y,z:this.axis.z},angle:this.angle.toJSON()}}static fromJSON(e){return new Ei(new G(e.axis.x,e.axis.y,e.axis.z),Q(e.angle))}clone(){return new Ei(this.axis.clone(),this.angle.clone())}}class rs{constructor(e,t,n,i){this.angleX=e,this.angleY=t,this.angleZ=n,this.type="rotation",this.eular=new Mi(0,0,0,i)}startGen(e){this.angleX.startGen(e),this.angleY.startGen(e),this.angleZ.startGen(e)}genValue(e,t,n,i){return this.eular.set(this.angleX.genValue(e,i)*n,this.angleY.genValue(e,i)*n,this.angleZ.genValue(e,i)*n),t.setFromEuler(this.eular)}toJSON(){return{type:"Euler",angleX:this.angleX.toJSON(),angleY:this.angleY.toJSON(),angleZ:this.angleZ.toJSON(),eulerOrder:this.eular.order}}static fromJSON(e){return new rs(Q(e.angleX),Q(e.angleY),Q(e.angleZ),e.eulerOrder)}clone(){return new rs(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function Na(r){switch(r.type){case"AxisAngle":return Ei.fromJSON(r);case"Euler":return rs.fromJSON(r);case"RandomQuat":return Pi.fromJSON(r);default:return new Pi}}class En{constructor(e,t,n){this.x=e,this.y=t,this.z=n,this.type="vec3function"}startGen(e){this.x.startGen(e),this.y.startGen(e),this.z.startGen(e)}genValue(e,t,n){return t.set(this.x.genValue(e,n),this.y.genValue(e,n),this.z.genValue(e,n))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new En(Q(e.x),Q(e.y),Q(e.z))}clone(){return new En(this.x,this.y,this.z)}}function uh(r){return r.type==="Vector3Function"?En.fromJSON(r):new En(new te(0),new te(0),new te(0))}function mr(r){switch(r.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return Q(r);case"AxisAngle":case"RandomQuat":case"Euler":return Na(r);case"Vector3Function":return uh(r);default:return new te(0)}}class ki{constructor(e={}){var t,n,i,s,a,o,c;this.type="cone",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.angle=(s=e.angle)!==null&&s!==void 0?s:Math.PI/6,this.mode=(a=e.mode)!==null&&a!==void 0?a:tt.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new te(1),this.memory=[]}update(e,t){tt.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Bn.lerp(1-this.thickness,1,Math.random()),s=n*this.arc,a=Math.sqrt(i),o=Math.sin(s),c=Math.cos(s);e.position.x=a*c,e.position.y=a*o,e.position.z=0;const l=this.angle*a;e.velocity.set(0,0,Math.cos(l)).addScaledVector(e.position,Math.sin(l)).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius)}toJSON(){return{type:"cone",radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new ki({radius:e.radius,arc:e.arc,thickness:e.thickness,angle:e.angle,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new ki({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ri{constructor(e={}){var t,n,i,s,a,o;this.type="circle",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:tt.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new te(1),this.memory=[]}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Bn.lerp(1-this.thickness,1,Math.random()),s=n*this.arc;e.position.x=Math.cos(s),e.position.y=Math.sin(s),e.position.z=0,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*i)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Ri({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new Ri({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function yr(r,e){return Math.floor(Math.random()*(e-r))+r}const gr=new G(0,1,0),vr=new G(0,0,0),hh=new G(1,1,1),Ua=new G(0,0,1);class Ai{constructor(e={}){var t,n,i,s,a,o,c;this.type="donut",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.donutRadius=(s=e.donutRadius)!==null&&s!==void 0?s:this.radius*.2,this.mode=(a=e.mode)!==null&&a!==void 0?a:tt.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new te(1),this.memory=[],this._m1=new It}update(e,t){tt.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Bn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=i*Math.PI*2,c=Math.sin(a),l=Math.cos(a);e.position.x=this.radius*l,e.position.y=this.radius*c,e.position.z=0,e.velocity.z=this.donutRadius*s*Math.sin(o),e.velocity.x=this.donutRadius*s*Math.cos(o)*l,e.velocity.y=this.donutRadius*s*Math.cos(o)*c,e.position.add(e.velocity),e.velocity.normalize().multiplyScalar(e.startSpeed),e.rotation instanceof ie&&(this._m1.lookAt(vr,e.velocity,gr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"donut",radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Ai({radius:e.radius,arc:e.arc,thickness:e.thickness,donutRadius:e.donutRadius,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new Ai({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Oi{constructor(){this.type="point",this._m1=new It}update(e,t){}initialize(e){const t=Math.random(),n=Math.random(),i=t*Math.PI*2,s=Math.acos(2*n-1),a=Math.cbrt(Math.random()),o=Math.sin(i),c=Math.cos(i),l=Math.sin(s),u=Math.cos(s);e.velocity.x=a*l*c,e.velocity.y=a*l*o,e.velocity.z=a*u,e.velocity.multiplyScalar(e.startSpeed),e.position.setScalar(0),e.rotation instanceof ie&&(this._m1.lookAt(vr,e.position,gr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(e){return new Oi}clone(){return new Oi}}class Zn{constructor(e={}){var t,n,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:tt.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new te(1),this.memory=[],this._m1=new It}update(e,t){tt.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Bn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=Math.acos(2*i-1),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),d=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=d,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof ie&&(this._m1.lookAt(vr,e.position,gr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"sphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Zn({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new Zn({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ii{constructor(e={}){var t,n,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:tt.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new te(1),this.memory=[],this._m1=new It}update(e,t){tt.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Bn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=Math.acos(i),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),d=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=d,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof ie&&(this._m1.lookAt(vr,e.position,gr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"hemisphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Ii({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new Ii({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Bi{constructor(e={}){var t,n,i,s;this.type="grid",this.width=(t=e.width)!==null&&t!==void 0?t:1,this.height=(n=e.height)!==null&&n!==void 0?n:1,this.column=(i=e.column)!==null&&i!==void 0?i:10,this.row=(s=e.row)!==null&&s!==void 0?s:10}initialize(e){const t=Math.floor(Math.random()*this.row),n=Math.floor(Math.random()*this.column);e.position.x=n*this.width/this.column-this.width/2,e.position.y=t*this.height/this.row-this.height/2,e.position.z=0,e.velocity.set(0,0,e.startSpeed)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row}}static fromJSON(e){return new Bi(e)}clone(){return new Bi({width:this.width,height:this.height,column:this.column,row:this.row})}update(e,t){}}const As={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ri,loadJSON:Ri.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:ki,loadJSON:ki.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ai,loadJSON:Ai.fromJSON},point:{type:"point",params:[],constructor:Oi,loadJSON:Oi.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Zn,loadJSON:Zn.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ii,loadJSON:Ii.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:Bi,loadJSON:Bi.fromJSON}};function dh(r,e){return As[r.type].loadJSON(r,e)}class zi{constructor(e){this.color=e,this.type="ColorOverLife"}initialize(e){this.color.startGen(e.memory)}update(e,t){this.color.genColor(e.memory,e.color,e.age/e.life),e.color.x*=e.startColor.x,e.color.y*=e.startColor.y,e.color.z*=e.startColor.z,e.color.w*=e.startColor.w}frameUpdate(e){}toJSON(){return{type:this.type,color:this.color.toJSON()}}static fromJSON(e){return new zi(Rs(e.color))}clone(){return new zi(this.color.clone())}reset(){}}class Ni{constructor(e){this.angularVelocity=e,this.type="RotationOverLife"}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){typeof e.rotation=="number"&&(e.rotation+=t*this.angularVelocity.genValue(e.memory,e.age/e.life))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(e){return new Ni(Q(e.angularVelocity))}frameUpdate(e){}clone(){return new Ni(this.angularVelocity.clone())}reset(){}}class Ui{constructor(e){this.angularVelocity=e,this.type="Rotation3DOverLife",this.tempQuat=new ie,this.tempQuat2=new ie}initialize(e){e.rotation instanceof ie&&(e.angularVelocity=new ie,this.angularVelocity.startGen(e.memory))}update(e,t){e.rotation instanceof ie&&(this.angularVelocity.genValue(e.memory,this.tempQuat,t,e.age/e.life),e.rotation.multiply(this.tempQuat))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(e){return new Ui(Na(e.angularVelocity))}frameUpdate(e){}clone(){return new Ui(this.angularVelocity.clone())}reset(){}}class Di{initialize(e,t){this.ps=t,this.x.startGen(e.memory),this.y.startGen(e.memory),this.z.startGen(e.memory)}constructor(e,t,n){this.x=e,this.y=t,this.z=n,this.type="ForceOverLife",this._temp=new G,this._tempScale=new G,this._tempQ=new ie}update(e,t){this._temp.set(this.x.genValue(e.memory,e.age/e.life),this.y.genValue(e.memory,e.age/e.life),this.z.genValue(e.memory,e.age/e.life)),this.ps.worldSpace?e.velocity.addScaledVector(this._temp,t):(this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ),e.velocity.addScaledVector(this._temp,t))}toJSON(){return{type:this.type,x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new Di(Q(e.x),Q(e.y),Q(e.z))}frameUpdate(e){if(this.ps&&!this.ps.worldSpace){const t=this._temp,n=this._tempQ,i=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,n,i),n.invert(),i.set(1/i.x,1/i.y,1/i.z)}}clone(){return new Di(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class Li{initialize(e){this.size.startGen(e.memory)}constructor(e){this.size=e,this.type="SizeOverLife"}update(e){this.size instanceof En?this.size.genValue(e.memory,e.size,e.age/e.life).multiply(e.startSize):e.size.copy(e.startSize).multiplyScalar(this.size.genValue(e.memory,e.age/e.life))}toJSON(){return{type:this.type,size:this.size.toJSON()}}static fromJSON(e){return new Li(mr(e.size))}frameUpdate(e){}clone(){return new Li(this.size.clone())}reset(){}}class Fi{initialize(e){this.speed.startGen(e.memory)}constructor(e){this.speed=e,this.type="SpeedOverLife"}update(e){e.speedModifier=this.speed.genValue(e.memory,e.age/e.life)}toJSON(){return{type:this.type,speed:this.speed.toJSON()}}static fromJSON(e){return new Fi(Q(e.speed))}frameUpdate(e){}clone(){return new Fi(this.speed.clone())}reset(){}}class Vi{constructor(e){this.frame=e,this.type="FrameOverLife"}initialize(e){this.frame.startGen(e.memory)}update(e,t){this.frame instanceof Ci&&(e.uvTile=this.frame.genValue(e.memory,e.age/e.life))}frameUpdate(e){}toJSON(){return{type:this.type,frame:this.frame.toJSON()}}static fromJSON(e){return new Vi(Q(e.frame))}clone(){return new Vi(this.frame.clone())}reset(){}}class ji{constructor(e,t=new G(0,1,0)){this.orbitSpeed=e,this.axis=t,this.type="OrbitOverLife",this.temp=new G,this.rotation=new ie}initialize(e){this.orbitSpeed.startGen(e.memory)}update(e,t){this.temp.copy(e.position).projectOnVector(this.axis),this.rotation.setFromAxisAngle(this.axis,this.orbitSpeed.genValue(e.memory,e.age/e.life)*t),e.position.sub(this.temp),e.position.applyQuaternion(this.rotation),e.position.add(this.temp)}frameUpdate(e){}toJSON(){return{type:this.type,orbitSpeed:this.orbitSpeed.toJSON(),axis:[this.axis.x,this.axis.y,this.axis.z]}}static fromJSON(e){return new ji(Q(e.orbitSpeed),e.axis?new G(e.axis[0],e.axis[1],e.axis[2]):void 0)}clone(){return new ji(this.orbitSpeed.clone())}reset(){}}class Os{constructor(e){this.data=e,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class ph{constructor(){this.length=0,this.head=this.tail=null}isEmpty(){return this.head===null}clear(){this.length=0,this.head=this.tail=null}front(){return this.head===null?null:this.head.data}back(){return this.tail===null?null:this.tail.data}dequeue(){if(this.head){const e=this.head.data;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,e}}pop(){if(this.tail){const e=this.tail.data;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,e}}queue(e){const t=new Os(e);this.tail||(this.tail=t),this.head&&(this.head.prev=t,t.next=this.head),this.head=t,this.length++}push(e){const t=new Os(e);this.head||(this.head=t),this.tail&&(this.tail.next=t,t.prev=this.tail),this.tail=t,this.length++}insertBefore(e,t){const n=new Os(t);n.next=e,n.prev=e.prev,n.prev!==null&&(n.prev.next=n),n.next.prev=n,e==this.head&&(this.head=n),this.length++}remove(e){if(this.head===null||this.tail===null)return;let t=this.head;for(e===this.head.data&&(this.head=this.head.next),e===this.tail.data&&(this.tail=this.tail.prev);t.next!==null&&t.data!==e;)t=t.next;t.data===e&&(t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.length--)}*values(){let e=this.head;for(;e!==null;)yield e.data,e=e.next}}class fh{constructor(){this.startSpeed=0,this.startColor=new ct,this.startSize=new G(1,1,1),this.position=new G,this.velocity=new G,this.age=0,this.life=1,this.size=new G(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new ct,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class mh{constructor(e,t,n){this.position=e,this.size=t,this.color=n}}class Sr{constructor(){this.startSpeed=0,this.startColor=new ct,this.startSize=new G(1,1,1),this.position=new G,this.velocity=new G,this.age=0,this.life=1,this.size=new G(1,1,1),this.length=100,this.speedModifier=1,this.color=new ct,this.previous=new ph,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new mh(this.position.clone(),this.size.x,this.color.clone())):this.previous.length>0&&this.previous.dequeue();this.previous.length>this.length;)this.previous.dequeue()}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.previous.clear()}}class Ji{initialize(e){this.width.startGen(e.memory)}constructor(e){this.width=e,this.type="WidthOverLength"}update(e){if(e instanceof Sr){const t=e.previous.values();for(let n=0;n<e.previous.length;n++){const i=t.next();i.value.size=this.width.genValue(e.memory,(e.previous.length-n)/e.length)}}}frameUpdate(e){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(e){return new Ji(Q(e.width))}clone(){return new Ji(this.width.clone())}reset(){}}class Gi{constructor(e,t){this.direction=e,this.magnitude=t,this.type="ApplyForce",this.memory={data:[],dataCount:0},this.magnitudeValue=this.magnitude.genValue(this.memory)}initialize(e){}update(e,t){e.velocity.addScaledVector(this.direction,this.magnitudeValue*t)}frameUpdate(e){this.magnitudeValue=this.magnitude.genValue(this.memory)}toJSON(){return{type:this.type,direction:[this.direction.x,this.direction.y,this.direction.z],magnitude:this.magnitude.toJSON()}}static fromJSON(e){var t;return new Gi(new G(e.direction[0],e.direction[1],e.direction[2]),Q((t=e.magnitude)!==null&&t!==void 0?t:e.force))}clone(){return new Gi(this.direction.clone(),this.magnitude.clone())}reset(){}}class Wi{constructor(e,t){this.center=e,this.magnitude=t,this.type="GravityForce",this.temp=new G}initialize(e){}update(e,t){this.temp.copy(this.center).sub(e.position).normalize(),e.velocity.addScaledVector(this.temp,this.magnitude/e.position.distanceToSquared(this.center)*t)}frameUpdate(e){}toJSON(){return{type:this.type,center:[this.center.x,this.center.y,this.center.z],magnitude:this.magnitude}}static fromJSON(e){return new Wi(new G(e.center[0],e.center[1],e.center[2]),e.magnitude)}clone(){return new Wi(this.center.clone(),this.magnitude)}reset(){}}class Hi{constructor(e){this.angle=e,this.type="ChangeEmitDirection",this._temp=new G,this._q=new ie,this.memory={data:[],dataCount:0}}initialize(e){const t=e.velocity.length();t!=0&&(e.velocity.normalize(),e.velocity.x===0&&e.velocity.y===0?this._temp.set(0,e.velocity.z,0):this._temp.set(-e.velocity.y,e.velocity.x,0),this.angle.startGen(this.memory),this._q.setFromAxisAngle(this._temp.normalize(),this.angle.genValue(this.memory)),this._temp.copy(e.velocity),e.velocity.applyQuaternion(this._q),this._q.setFromAxisAngle(this._temp,Math.random()*Math.PI*2),e.velocity.applyQuaternion(this._q),e.velocity.setLength(t))}update(e,t){}frameUpdate(e){}toJSON(){return{type:this.type,angle:this.angle.toJSON()}}static fromJSON(e){return new Hi(Q(e.angle))}clone(){return new Hi(this.angle)}reset(){}}var Nn;(function(r){r[r.Death=0]="Death",r[r.Birth=1]="Birth",r[r.Frame=2]="Frame"})(Nn||(Nn={}));class qi{constructor(e,t,n,i=Nn.Frame,s=1){this.particleSystem=e,this.useVelocityAsBasis=t,this.subParticleSystem=n,this.mode=i,this.emitProbability=s,this.type="EmitSubParticleSystem",this.q_=new ie,this.v_=new G,this.v2_=new G,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(e){}update(e,t){this.mode===Nn.Frame?this.emit(e,t):this.mode===Nn.Birth&&e.age===0?this.emit(e,t):this.mode===Nn.Death&&e.age+t>=e.life&&this.emit(e,t)}emit(e,t){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const n=new It;this.setMatrixFromParticle(n,e),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:n,travelDistance:0,particle:e})}frameUpdate(e){if(this.subParticleSystem)for(let t=0;t<this.subEmissions.length;t++)if(this.subEmissions[t].time>=this.subParticleSystem.system.duration)this.subEmissions[t]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,t--;else{const n=this.subEmissions[t];n.particle&&n.particle.age<n.particle.life?this.setMatrixFromParticle(n.matrix,n.particle):n.particle=void 0,this.subParticleSystem.system.emit(e,n,n.matrix)}}toJSON(){return{type:this.type,subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(e,t){return new qi(t,e.useVelocityAsBasis,e.subParticleSystem,e.mode,e.emitProbability)}clone(){return new qi(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(e,t){let n;if(t.rotation===void 0||this.useVelocityAsBasis)if(t.velocity.x===0&&t.velocity.y===0&&(t.velocity.z===1||t.velocity.z===0))e.set(1,0,0,t.position.x,0,1,0,t.position.y,0,0,1,t.position.z,0,0,0,1);else{this.v_.copy(Ua).cross(t.velocity),this.v2_.copy(t.velocity).cross(this.v_);const i=this.v_.length(),s=this.v2_.length();e.set(this.v_.x/i,this.v2_.x/s,t.velocity.x,t.position.x,this.v_.y/i,this.v2_.y/s,t.velocity.y,t.position.y,this.v_.z/i,this.v2_.z/s,t.velocity.z,t.position.z,0,0,0,1)}else t.rotation instanceof ie?n=t.rotation:(this.q_.setFromAxisAngle(Ua,t.rotation),n=this.q_),e.compose(t.position,n,hh);this.particleSystem.worldSpace||e.multiplyMatrices(this.particleSystem.emitter.matrixWorld,e)}}const yh=.5*(Math.sqrt(3)-1),si=(3-Math.sqrt(3))/6,gh=1/3,Dt=1/6,vh=(Math.sqrt(5)-1)/4,Fe=(5-Math.sqrt(5))/20,Be=new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),Te=new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);class Da{constructor(e=Math.random){const t=typeof e=="function"?e:bh(e);this.p=Sh(t),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let n=0;n<512;n++)this.perm[n]=this.p[n&255],this.permMod12[n]=this.perm[n]%12}noise2D(e,t){const n=this.permMod12,i=this.perm;let s=0,a=0,o=0;const c=(e+t)*yh,l=Math.floor(e+c),u=Math.floor(t+c),d=(l+u)*si,f=l-d,m=u-d,x=e-f,_=t-m;let g,v;x>_?(g=1,v=0):(g=0,v=1);const w=x-g+si,S=_-v+si,T=x-1+2*si,M=_-1+2*si,P=l&255,E=u&255;let O=.5-x*x-_*_;if(O>=0){const B=n[P+i[E]]*3;O*=O,s=O*O*(Be[B]*x+Be[B+1]*_)}let A=.5-w*w-S*S;if(A>=0){const B=n[P+g+i[E+v]]*3;A*=A,a=A*A*(Be[B]*w+Be[B+1]*S)}let R=.5-T*T-M*M;if(R>=0){const B=n[P+1+i[E+1]]*3;R*=R,o=R*R*(Be[B]*T+Be[B+1]*M)}return 70*(s+a+o)}noise3D(e,t,n){const i=this.permMod12,s=this.perm;let a,o,c,l;const u=(e+t+n)*gh,d=Math.floor(e+u),f=Math.floor(t+u),m=Math.floor(n+u),x=(d+f+m)*Dt,_=d-x,g=f-x,v=m-x,w=e-_,S=t-g,T=n-v;let M,P,E,O,A,R;w>=S?S>=T?(M=1,P=0,E=0,O=1,A=1,R=0):w>=T?(M=1,P=0,E=0,O=1,A=0,R=1):(M=0,P=0,E=1,O=1,A=0,R=1):S<T?(M=0,P=0,E=1,O=0,A=1,R=1):w<T?(M=0,P=1,E=0,O=0,A=1,R=1):(M=0,P=1,E=0,O=1,A=1,R=0);const B=w-M+Dt,I=S-P+Dt,U=T-E+Dt,L=w-O+2*Dt,J=S-A+2*Dt,H=T-R+2*Dt,se=w-1+3*Dt,W=S-1+3*Dt,pe=T-1+3*Dt,ne=d&255,he=f&255,oe=m&255;let le=.6-w*w-S*S-T*T;if(le<0)a=0;else{const re=i[ne+s[he+s[oe]]]*3;le*=le,a=le*le*(Be[re]*w+Be[re+1]*S+Be[re+2]*T)}let xe=.6-B*B-I*I-U*U;if(xe<0)o=0;else{const re=i[ne+M+s[he+P+s[oe+E]]]*3;xe*=xe,o=xe*xe*(Be[re]*B+Be[re+1]*I+Be[re+2]*U)}let ge=.6-L*L-J*J-H*H;if(ge<0)c=0;else{const re=i[ne+O+s[he+A+s[oe+R]]]*3;ge*=ge,c=ge*ge*(Be[re]*L+Be[re+1]*J+Be[re+2]*H)}let de=.6-se*se-W*W-pe*pe;if(de<0)l=0;else{const re=i[ne+1+s[he+1+s[oe+1]]]*3;de*=de,l=de*de*(Be[re]*se+Be[re+1]*W+Be[re+2]*pe)}return 32*(a+o+c+l)}noise4D(e,t,n,i){const s=this.perm;let a,o,c,l,u;const d=(e+t+n+i)*vh,f=Math.floor(e+d),m=Math.floor(t+d),x=Math.floor(n+d),_=Math.floor(i+d),g=(f+m+x+_)*Fe,v=f-g,w=m-g,S=x-g,T=_-g,M=e-v,P=t-w,E=n-S,O=i-T;let A=0,R=0,B=0,I=0;M>P?A++:R++,M>E?A++:B++,M>O?A++:I++,P>E?R++:B++,P>O?R++:I++,E>O?B++:I++;const U=A>=3?1:0,L=R>=3?1:0,J=B>=3?1:0,H=I>=3?1:0,se=A>=2?1:0,W=R>=2?1:0,pe=B>=2?1:0,ne=I>=2?1:0,he=A>=1?1:0,oe=R>=1?1:0,le=B>=1?1:0,xe=I>=1?1:0,ge=M-U+Fe,de=P-L+Fe,re=E-J+Fe,Ze=O-H+Fe,Ue=M-se+2*Fe,ke=P-W+2*Fe,lt=E-pe+2*Fe,De=O-ne+2*Fe,ve=M-he+3*Fe,ue=P-oe+3*Fe,ft=E-le+3*Fe,Re=O-xe+3*Fe,fe=M-1+4*Fe,rt=P-1+4*Fe,wt=E-1+4*Fe,_t=O-1+4*Fe,st=f&255,Tt=m&255,mt=x&255,yt=_&255;let ut=.6-M*M-P*P-E*E-O*O;if(ut<0)a=0;else{const $=s[st+s[Tt+s[mt+s[yt]]]]%32*4;ut*=ut,a=ut*ut*(Te[$]*M+Te[$+1]*P+Te[$+2]*E+Te[$+3]*O)}let Ae=.6-ge*ge-de*de-re*re-Ze*Ze;if(Ae<0)o=0;else{const $=s[st+U+s[Tt+L+s[mt+J+s[yt+H]]]]%32*4;Ae*=Ae,o=Ae*Ae*(Te[$]*ge+Te[$+1]*de+Te[$+2]*re+Te[$+3]*Ze)}let Ke=.6-Ue*Ue-ke*ke-lt*lt-De*De;if(Ke<0)c=0;else{const $=s[st+se+s[Tt+W+s[mt+pe+s[yt+ne]]]]%32*4;Ke*=Ke,c=Ke*Ke*(Te[$]*Ue+Te[$+1]*ke+Te[$+2]*lt+Te[$+3]*De)}let ht=.6-ve*ve-ue*ue-ft*ft-Re*Re;if(ht<0)l=0;else{const $=s[st+he+s[Tt+oe+s[mt+le+s[yt+xe]]]]%32*4;ht*=ht,l=ht*ht*(Te[$]*ve+Te[$+1]*ue+Te[$+2]*ft+Te[$+3]*Re)}let Qe=.6-fe*fe-rt*rt-wt*wt-_t*_t;if(Qe<0)u=0;else{const $=s[st+1+s[Tt+1+s[mt+1+s[yt+1]]]]%32*4;Qe*=Qe,u=Qe*Qe*(Te[$]*fe+Te[$+1]*rt+Te[$+2]*wt+Te[$+3]*_t)}return 27*(a+o+c+l+u)}}function Sh(r){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let t=0;t<255;t++){const n=t+~~(r()*(256-t)),i=e[t];e[t]=e[n],e[n]=i}return e}function bh(r){let e=0,t=0,n=0,i=1;const s=xh();return e=s(" "),t=s(" "),n=s(" "),e-=s(r),e<0&&(e+=1),t-=s(r),t<0&&(t+=1),n-=s(r),n<0&&(n+=1),function(){const a=2091639*e+i*23283064365386963e-26;return e=t,t=n,n=a-(i=a|0)}}function xh(){let r=4022871197;return function(e){e=e.toString();for(let t=0;t<e.length;t++){r+=e.charCodeAt(t);let n=.02519603282416938*r;r=n>>>0,n-=r,n*=r,r=n>>>0,n-=r,r+=n*4294967296}return(r>>>0)*23283064365386963e-26}}class Xi{constructor(e,t,n,i){this.scale=e,this.octaves=t,this.velocityMultiplier=n,this.timeScale=i,this.type="TurbulenceField",this.generator=new Da,this.timeOffset=new G,this.temp=new G,this.temp2=new G,this.timeOffset.x=Math.random()/this.scale.x*this.timeScale.x,this.timeOffset.y=Math.random()/this.scale.y*this.timeScale.y,this.timeOffset.z=Math.random()/this.scale.z*this.timeScale.z}initialize(e){}update(e,t){const n=e.position.x/this.scale.x,i=e.position.y/this.scale.y,s=e.position.z/this.scale.z;this.temp.set(0,0,0);let a=1;for(let o=0;o<this.octaves;o++)this.temp2.set(this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.x*a)/a,this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.y*a)/a,this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.z*a)/a),this.temp.add(this.temp2),a*=2;this.temp.multiply(this.velocityMultiplier),e.velocity.addScaledVector(this.temp,t)}toJSON(){return{type:this.type,scale:[this.scale.x,this.scale.y,this.scale.z],octaves:this.octaves,velocityMultiplier:[this.velocityMultiplier.x,this.velocityMultiplier.y,this.velocityMultiplier.z],timeScale:[this.timeScale.x,this.timeScale.y,this.timeScale.z]}}frameUpdate(e){this.timeOffset.x+=e*this.timeScale.x,this.timeOffset.y+=e*this.timeScale.y,this.timeOffset.z+=e*this.timeScale.z}static fromJSON(e){return new Xi(new G(e.scale[0],e.scale[1],e.scale[2]),e.octaves,new G(e.velocityMultiplier[0],e.velocityMultiplier[1],e.velocityMultiplier[2]),new G(e.timeScale[0],e.timeScale[1],e.timeScale[2]))}clone(){return new Xi(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const Lt=[],Is=new G,Bs=new ie;class Yi{constructor(e,t,n=new te(1),i=new te(0)){if(this.frequency=e,this.power=t,this.positionAmount=n,this.rotationAmount=i,this.type="Noise",this.duration=0,Lt.length===0)for(let s=0;s<100;s++)Lt.push(new Da)}initialize(e){e.lastPosNoise=new G,typeof e.rotation=="number"?e.lastRotNoise=0:e.lastRotNoise=new ie,e.generatorIndex=[yr(0,100),yr(0,100),yr(0,100),yr(0,100)],this.positionAmount.startGen(e.memory),this.rotationAmount.startGen(e.memory),this.frequency.startGen(e.memory),this.power.startGen(e.memory)}update(e,t){let n=this.frequency.genValue(e.memory,e.age/e.life),i=this.power.genValue(e.memory,e.age/e.life),s=this.positionAmount.genValue(e.memory,e.age/e.life),a=this.rotationAmount.genValue(e.memory,e.age/e.life);s>0&&e.lastPosNoise!==void 0&&(e.position.sub(e.lastPosNoise),Is.set(Lt[e.generatorIndex[0]].noise2D(0,e.age*n)*i*s,Lt[e.generatorIndex[1]].noise2D(0,e.age*n)*i*s,Lt[e.generatorIndex[2]].noise2D(0,e.age*n)*i*s),e.position.add(Is),e.lastPosNoise.copy(Is)),a>0&&e.lastRotNoise!==void 0&&(typeof e.rotation=="number"?(e.rotation-=e.lastRotNoise,e.rotation+=Lt[e.generatorIndex[3]].noise2D(0,e.age*n)*Math.PI*i*a):(e.lastRotNoise.invert(),e.rotation.multiply(e.lastRotNoise),Bs.set(Lt[e.generatorIndex[0]].noise2D(0,e.age*n)*i*a,Lt[e.generatorIndex[1]].noise2D(0,e.age*n)*i*a,Lt[e.generatorIndex[2]].noise2D(0,e.age*n)*i*a,Lt[e.generatorIndex[3]].noise2D(0,e.age*n)*i*a).normalize(),e.rotation.multiply(Bs),e.lastRotNoise.copy(Bs)))}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON()}}frameUpdate(e){this.duration+=e}static fromJSON(e){return new Yi(Q(e.frequency),Q(e.power),Q(e.positionAmount),Q(e.rotationAmount))}clone(){return new Yi(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Zi{constructor(e,t){this.color=e,this.speedRange=t,this.type="ColorBySpeed"}initialize(e){this.color.startGen(e.memory)}update(e,t){const n=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(e.memory,e.color,n),e.color.x*=e.startColor.x,e.color.y*=e.startColor.y,e.color.z*=e.startColor.z,e.color.w*=e.startColor.w}frameUpdate(e){}toJSON(){return{type:this.type,color:this.color.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Zi(Rs(e.color),Pn.fromJSON(e.speedRange))}clone(){return new Zi(this.color.clone(),this.speedRange.clone())}reset(){}}class Ki{initialize(e){this.size.startGen(e.memory)}constructor(e,t){this.size=e,this.speedRange=t,this.type="SizeBySpeed"}update(e){const t=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.size instanceof En?this.size.genValue(e.memory,e.size,t).multiply(e.startSize):e.size.copy(e.startSize).multiplyScalar(this.size.genValue(e.memory,t))}toJSON(){return{type:this.type,size:this.size.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Ki(mr(e.size),Pn.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Ki(this.size.clone(),this.speedRange.clone())}reset(){}}class Qi{constructor(e,t){this.angularVelocity=e,this.speedRange=t,this.type="RotationBySpeed",this.tempQuat=new ie}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){if(typeof e.rotation=="number"){const n=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);e.rotation+=t*this.angularVelocity.genValue(e.memory,n)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Qi(Q(e.angularVelocity),Pn.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Qi(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class $i{initialize(e){this.speed.startGen(e.memory)}constructor(e,t){this.speed=e,this.dampen=t,this.type="LimitSpeedOverLife"}update(e,t){let n=e.velocity.length(),i=this.speed.genValue(e.memory,e.age/e.life);if(n>i){const s=(n-i)/n;e.velocity.multiplyScalar(1-s*this.dampen*t*20)}}toJSON(){return{type:this.type,speed:this.speed.toJSON(),dampen:this.dampen}}static fromJSON(e){return new $i(Q(e.speed),e.dampen)}frameUpdate(e){}clone(){return new $i(this.speed.clone(),this.dampen)}reset(){}}const br={ApplyForce:{type:"ApplyForce",constructor:Gi,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Gi.fromJSON},Noise:{type:"Noise",constructor:Yi,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Yi.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Xi,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Xi.fromJSON},GravityForce:{type:"GravityForce",constructor:Wi,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:Wi.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:zi,params:[["color",["colorFunc"]]],loadJSON:zi.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Ni,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Ni.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Ui,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Ui.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Li,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Li.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:Zi,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:Zi.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Qi,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Qi.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:Ki,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:Ki.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Fi,params:[["speed",["value","valueFunc"]]],loadJSON:Fi.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:Vi,params:[["frame",["value","valueFunc"]]],loadJSON:Vi.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:Di,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:Di.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:ji,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:ji.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Ji,params:[["width",["value","valueFunc"]]],loadJSON:Ji.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:Hi,params:[["angle",["value"]]],loadJSON:Hi.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:qi,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:qi.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:$i,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:$i.fromJSON}};function wh(r,e){return br[r.type]?br[r.type].loadJSON(r,e):null}const _h=[];function Th(r){if(!_h.find(e=>e.id===r.id)){for(const e of r.emitterShapes)As[e.type]||(As[e.type]=e);for(const e of r.behaviors)br[e.type]||(br[e.type]=e)}}var Mh=`
1
+ import{Object3D as ia,PlaneGeometry as eh,Layers as cr,MeshBasicMaterial as ra,DoubleSide as bs,AdditiveBlending as sa,InstancedBufferAttribute as fn,DynamicDrawUsage as et,InstancedBufferGeometry as th,Uniform as Et,ShaderMaterial as xs,BufferGeometry as ti,BufferAttribute as dt,Mesh as lr,MeshStandardMaterial as nh,MeshPhysicalMaterial as ih,ShaderChunk as rh,Triangle as mn,Vector3 as q,Box3 as zt,Matrix4 as kt,Line3 as qt,Plane as oa,Vector2 as nn,BackSide as sh,REVISION as aa,Ray as oh,FrontSide as ca,LineSegments as la,LineLoop as ha,Line as ua,Points as da,Sphere as ah,BatchedMesh as ch,Matrix3 as lh,Vector4 as ws,SkinnedMesh as hh,InterpolateDiscrete as uh,InterpolateLinear as pa,AnimationClip as dh,QuaternionKeyframeTrack as ph,ColorKeyframeTrack as fh,VectorKeyframeTrack as mh,BooleanKeyframeTrack as yh,NumberKeyframeTrack as gh,PropertyBinding as fa}from"./three.min.js";function hr(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var ma={exports:{}},ya={exports:{}},ga;function vh(){return ga||(ga=1,function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e={rotl:function(t,n){return t<<n|t>>>32-n},rotr:function(t,n){return t<<32-n|t>>>n},endian:function(t){if(t.constructor==Number)return e.rotl(t,8)&16711935|e.rotl(t,24)&4278255360;for(var n=0;n<t.length;n++)t[n]=e.endian(t[n]);return t},randomBytes:function(t){for(var n=[];t>0;t--)n.push(Math.floor(Math.random()*256));return n},bytesToWords:function(t){for(var n=[],i=0,s=0;i<t.length;i++,s+=8)n[s>>>5]|=t[i]<<24-s%32;return n},wordsToBytes:function(t){for(var n=[],i=0;i<t.length*32;i+=8)n.push(t[i>>>5]>>>24-i%32&255);return n},bytesToHex:function(t){for(var n=[],i=0;i<t.length;i++)n.push((t[i]>>>4).toString(16)),n.push((t[i]&15).toString(16));return n.join("")},hexToBytes:function(t){for(var n=[],i=0;i<t.length;i+=2)n.push(parseInt(t.substr(i,2),16));return n},bytesToBase64:function(t){for(var n=[],i=0;i<t.length;i+=3)for(var s=t[i]<<16|t[i+1]<<8|t[i+2],a=0;a<4;a++)i*8+a*6<=t.length*8?n.push(r.charAt(s>>>6*(3-a)&63)):n.push("=");return n.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/ig,"");for(var n=[],i=0,s=0;i<t.length;s=++i%4)s!=0&&n.push((r.indexOf(t.charAt(i-1))&Math.pow(2,-2*s+8)-1)<<s*2|r.indexOf(t.charAt(i))>>>6-s*2);return n}};ya.exports=e}()),ya.exports}var _s,va;function Sa(){if(va)return _s;va=1;var r={utf8:{stringToBytes:function(e){return r.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(r.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n)&255);return t},bytesToString:function(e){for(var t=[],n=0;n<e.length;n++)t.push(String.fromCharCode(e[n]));return t.join("")}}};return _s=r,_s}var Ts,ba;function Sh(){if(ba)return Ts;ba=1,Ts=function(t){return t!=null&&(r(t)||e(t)||!!t._isBuffer)};function r(t){return!!t.constructor&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}function e(t){return typeof t.readFloatLE=="function"&&typeof t.slice=="function"&&r(t.slice(0,0))}return Ts}var xa;function bh(){return xa||(xa=1,function(){var r=vh(),e=Sa().utf8,t=Sh(),n=Sa().bin,i=function(s,a){s.constructor==String?a&&a.encoding==="binary"?s=n.stringToBytes(s):s=e.stringToBytes(s):t(s)?s=Array.prototype.slice.call(s,0):!Array.isArray(s)&&s.constructor!==Uint8Array&&(s=s.toString());for(var o=r.bytesToWords(s),c=s.length*8,l=1732584193,u=-271733879,d=-1732584194,m=271733878,f=0;f<o.length;f++)o[f]=(o[f]<<8|o[f]>>>24)&16711935|(o[f]<<24|o[f]>>>8)&4278255360;o[c>>>5]|=128<<c%32,o[(c+64>>>9<<4)+14]=c;for(var x=i._ff,_=i._gg,g=i._hh,v=i._ii,f=0;f<o.length;f+=16){var w=l,S=u,T=d,C=m;l=x(l,u,d,m,o[f+0],7,-680876936),m=x(m,l,u,d,o[f+1],12,-389564586),d=x(d,m,l,u,o[f+2],17,606105819),u=x(u,d,m,l,o[f+3],22,-1044525330),l=x(l,u,d,m,o[f+4],7,-176418897),m=x(m,l,u,d,o[f+5],12,1200080426),d=x(d,m,l,u,o[f+6],17,-1473231341),u=x(u,d,m,l,o[f+7],22,-45705983),l=x(l,u,d,m,o[f+8],7,1770035416),m=x(m,l,u,d,o[f+9],12,-1958414417),d=x(d,m,l,u,o[f+10],17,-42063),u=x(u,d,m,l,o[f+11],22,-1990404162),l=x(l,u,d,m,o[f+12],7,1804603682),m=x(m,l,u,d,o[f+13],12,-40341101),d=x(d,m,l,u,o[f+14],17,-1502002290),u=x(u,d,m,l,o[f+15],22,1236535329),l=_(l,u,d,m,o[f+1],5,-165796510),m=_(m,l,u,d,o[f+6],9,-1069501632),d=_(d,m,l,u,o[f+11],14,643717713),u=_(u,d,m,l,o[f+0],20,-373897302),l=_(l,u,d,m,o[f+5],5,-701558691),m=_(m,l,u,d,o[f+10],9,38016083),d=_(d,m,l,u,o[f+15],14,-660478335),u=_(u,d,m,l,o[f+4],20,-405537848),l=_(l,u,d,m,o[f+9],5,568446438),m=_(m,l,u,d,o[f+14],9,-1019803690),d=_(d,m,l,u,o[f+3],14,-187363961),u=_(u,d,m,l,o[f+8],20,1163531501),l=_(l,u,d,m,o[f+13],5,-1444681467),m=_(m,l,u,d,o[f+2],9,-51403784),d=_(d,m,l,u,o[f+7],14,1735328473),u=_(u,d,m,l,o[f+12],20,-1926607734),l=g(l,u,d,m,o[f+5],4,-378558),m=g(m,l,u,d,o[f+8],11,-2022574463),d=g(d,m,l,u,o[f+11],16,1839030562),u=g(u,d,m,l,o[f+14],23,-35309556),l=g(l,u,d,m,o[f+1],4,-1530992060),m=g(m,l,u,d,o[f+4],11,1272893353),d=g(d,m,l,u,o[f+7],16,-155497632),u=g(u,d,m,l,o[f+10],23,-1094730640),l=g(l,u,d,m,o[f+13],4,681279174),m=g(m,l,u,d,o[f+0],11,-358537222),d=g(d,m,l,u,o[f+3],16,-722521979),u=g(u,d,m,l,o[f+6],23,76029189),l=g(l,u,d,m,o[f+9],4,-640364487),m=g(m,l,u,d,o[f+12],11,-421815835),d=g(d,m,l,u,o[f+15],16,530742520),u=g(u,d,m,l,o[f+2],23,-995338651),l=v(l,u,d,m,o[f+0],6,-198630844),m=v(m,l,u,d,o[f+7],10,1126891415),d=v(d,m,l,u,o[f+14],15,-1416354905),u=v(u,d,m,l,o[f+5],21,-57434055),l=v(l,u,d,m,o[f+12],6,1700485571),m=v(m,l,u,d,o[f+3],10,-1894986606),d=v(d,m,l,u,o[f+10],15,-1051523),u=v(u,d,m,l,o[f+1],21,-2054922799),l=v(l,u,d,m,o[f+8],6,1873313359),m=v(m,l,u,d,o[f+15],10,-30611744),d=v(d,m,l,u,o[f+6],15,-1560198380),u=v(u,d,m,l,o[f+13],21,1309151649),l=v(l,u,d,m,o[f+4],6,-145523070),m=v(m,l,u,d,o[f+11],10,-1120210379),d=v(d,m,l,u,o[f+2],15,718787259),u=v(u,d,m,l,o[f+9],21,-343485551),l=l+w>>>0,u=u+S>>>0,d=d+T>>>0,m=m+C>>>0}return r.endian([l,u,d,m])};i._ff=function(s,a,o,c,l,u,d){var m=s+(a&o|~a&c)+(l>>>0)+d;return(m<<u|m>>>32-u)+a},i._gg=function(s,a,o,c,l,u,d){var m=s+(a&c|o&~c)+(l>>>0)+d;return(m<<u|m>>>32-u)+a},i._hh=function(s,a,o,c,l,u,d){var m=s+(a^o^c)+(l>>>0)+d;return(m<<u|m>>>32-u)+a},i._ii=function(s,a,o,c,l,u,d){var m=s+(o^(a|~c))+(l>>>0)+d;return(m<<u|m>>>32-u)+a},i._blocksize=16,i._digestsize=16,ma.exports=function(s,a){if(s==null)throw new Error("Illegal argument "+s);var o=r.wordsToBytes(i(s,a));return a&&a.asBytes?o:a&&a.asString?n.bytesToString(o):r.bytesToHex(o)}}()),ma.exports}var xh=bh();const wa=hr(xh),wh=Object.freeze(Object.defineProperty({__proto__:null,default:wa},Symbol.toStringTag,{value:"Module"})),_h=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Th(r){return typeof r=="string"&&_h.test(r)}const Le=[];for(let r=0;r<256;++r)Le.push((r+256).toString(16).slice(1));function Mh(r,e=0){return Le[r[e+0]]+Le[r[e+1]]+Le[r[e+2]]+Le[r[e+3]]+"-"+Le[r[e+4]]+Le[r[e+5]]+"-"+Le[r[e+6]]+Le[r[e+7]]+"-"+Le[r[e+8]]+Le[r[e+9]]+"-"+Le[r[e+10]]+Le[r[e+11]]+Le[r[e+12]]+Le[r[e+13]]+Le[r[e+14]]+Le[r[e+15]]}function Ch(r){if(!Th(r))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(r.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(r.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(r.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(r.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(r.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function Ph(r){r=unescape(encodeURIComponent(r));const e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t));return e}const Eh="6ba7b810-9dad-11d1-80b4-00c04fd430c8",kh="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function Rh(r,e,t){function n(i,s,a,o){var c;if(typeof i=="string"&&(i=Ph(i)),typeof s=="string"&&(s=Ch(s)),((c=s)===null||c===void 0?void 0:c.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(s),l.set(i,s.length),l=t(l),l[6]=l[6]&15|e,l[8]=l[8]&63|128,a){o=o||0;for(let u=0;u<16;++u)a[o+u]=l[u];return a}return Mh(l)}try{n.name=r}catch{}return n.DNS=Eh,n.URL=kh,n}function Ah(r,e,t,n){switch(r){case 0:return e&t^~e&n;case 1:return e^t^n;case 2:return e&t^e&n^t&n;case 3:return e^t^n}}function Ms(r,e){return r<<e|r>>>32-e}function Oh(r){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof r=="string"){const a=unescape(encodeURIComponent(r));r=[];for(let o=0;o<a.length;++o)r.push(a.charCodeAt(o))}else Array.isArray(r)||(r=Array.prototype.slice.call(r));r.push(128);const n=r.length/4+2,i=Math.ceil(n/16),s=new Array(i);for(let a=0;a<i;++a){const o=new Uint32Array(16);for(let c=0;c<16;++c)o[c]=r[a*64+c*4]<<24|r[a*64+c*4+1]<<16|r[a*64+c*4+2]<<8|r[a*64+c*4+3];s[a]=o}s[i-1][14]=(r.length-1)*8/Math.pow(2,32),s[i-1][14]=Math.floor(s[i-1][14]),s[i-1][15]=(r.length-1)*8&4294967295;for(let a=0;a<i;++a){const o=new Uint32Array(80);for(let f=0;f<16;++f)o[f]=s[a][f];for(let f=16;f<80;++f)o[f]=Ms(o[f-3]^o[f-8]^o[f-14]^o[f-16],1);let c=t[0],l=t[1],u=t[2],d=t[3],m=t[4];for(let f=0;f<80;++f){const x=Math.floor(f/20),_=Ms(c,5)+Ah(x,l,u,d)+m+e[x]+o[f]>>>0;m=d,d=u,u=Ms(l,30)>>>0,l=c,c=_}t[0]=t[0]+c>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+d>>>0,t[4]=t[4]+m>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const Ih=Rh("v5",80,Oh),Cs=2,Nt=4,Xt=4,_a=4,rn=new Int32Array(2),Ta=new Float32Array(rn.buffer),Ma=new Float64Array(rn.buffer),ur=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;class en{constructor(e,t){this.low=e|0,this.high=t|0}static create(e,t){return e==0&&t==0?en.ZERO:new en(e,t)}toFloat64(){return(this.low>>>0)+this.high*4294967296}equals(e){return this.low==e.low&&this.high==e.high}}en.ZERO=new en(0,0);var Ps;(function(r){r[r.UTF8_BYTES=1]="UTF8_BYTES",r[r.UTF16_STRING=2]="UTF16_STRING"})(Ps||(Ps={}));class Ti{constructor(e){this.bytes_=e,this.position_=0}static allocate(e){return new Ti(new Uint8Array(e))}clear(){this.position_=0}bytes(){return this.bytes_}position(){return this.position_}setPosition(e){this.position_=e}capacity(){return this.bytes_.length}readInt8(e){return this.readUint8(e)<<24>>24}readUint8(e){return this.bytes_[e]}readInt16(e){return this.readUint16(e)<<16>>16}readUint16(e){return this.bytes_[e]|this.bytes_[e+1]<<8}readInt32(e){return this.bytes_[e]|this.bytes_[e+1]<<8|this.bytes_[e+2]<<16|this.bytes_[e+3]<<24}readUint32(e){return this.readInt32(e)>>>0}readInt64(e){return new en(this.readInt32(e),this.readInt32(e+4))}readUint64(e){return new en(this.readUint32(e),this.readUint32(e+4))}readFloat32(e){return rn[0]=this.readInt32(e),Ta[0]}readFloat64(e){return rn[ur?0:1]=this.readInt32(e),rn[ur?1:0]=this.readInt32(e+4),Ma[0]}writeInt8(e,t){this.bytes_[e]=t}writeUint8(e,t){this.bytes_[e]=t}writeInt16(e,t){this.bytes_[e]=t,this.bytes_[e+1]=t>>8}writeUint16(e,t){this.bytes_[e]=t,this.bytes_[e+1]=t>>8}writeInt32(e,t){this.bytes_[e]=t,this.bytes_[e+1]=t>>8,this.bytes_[e+2]=t>>16,this.bytes_[e+3]=t>>24}writeUint32(e,t){this.bytes_[e]=t,this.bytes_[e+1]=t>>8,this.bytes_[e+2]=t>>16,this.bytes_[e+3]=t>>24}writeInt64(e,t){this.writeInt32(e,t.low),this.writeInt32(e+4,t.high)}writeUint64(e,t){this.writeUint32(e,t.low),this.writeUint32(e+4,t.high)}writeFloat32(e,t){Ta[0]=t,this.writeInt32(e,rn[0])}writeFloat64(e,t){Ma[0]=t,this.writeInt32(e,rn[ur?0:1]),this.writeInt32(e+4,rn[ur?1:0])}getBufferIdentifier(){if(this.bytes_.length<this.position_+Nt+Xt)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");let e="";for(let t=0;t<Xt;t++)e+=String.fromCharCode(this.readInt8(this.position_+Nt+t));return e}__offset(e,t){const n=e-this.readInt32(e);return t<this.readInt16(n)?this.readInt16(n+t):0}__union(e,t){return e.bb_pos=t+this.readInt32(t),e.bb=this,e}__string(e,t){e+=this.readInt32(e);const n=this.readInt32(e);let i="",s=0;if(e+=Nt,t===Ps.UTF8_BYTES)return this.bytes_.subarray(e,e+n);for(;s<n;){let a;const o=this.readUint8(e+s++);if(o<192)a=o;else{const c=this.readUint8(e+s++);if(o<224)a=(o&31)<<6|c&63;else{const l=this.readUint8(e+s++);if(o<240)a=(o&15)<<12|(c&63)<<6|l&63;else{const u=this.readUint8(e+s++);a=(o&7)<<18|(c&63)<<12|(l&63)<<6|u&63}}}a<65536?i+=String.fromCharCode(a):(a-=65536,i+=String.fromCharCode((a>>10)+55296,(a&1023)+56320))}return i}__union_with_string(e,t){return typeof e=="string"?this.__string(t):this.__union(e,t)}__indirect(e){return e+this.readInt32(e)}__vector(e){return e+this.readInt32(e)+Nt}__vector_len(e){return this.readInt32(e+this.readInt32(e))}__has_identifier(e){if(e.length!=Xt)throw new Error("FlatBuffers: file identifier must be length "+Xt);for(let t=0;t<Xt;t++)if(e.charCodeAt(t)!=this.readInt8(this.position()+Nt+t))return!1;return!0}createLong(e,t){return en.create(e,t)}createScalarList(e,t){const n=[];for(let i=0;i<t;++i)e(i)!==null&&n.push(e(i));return n}createObjList(e,t){const n=[];for(let i=0;i<t;++i){const s=e(i);s!==null&&n.push(s.unpack())}return n}}class Oo{constructor(e){this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null;let t;e?t=e:t=1024,this.bb=Ti.allocate(t),this.space=t}clear(){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,this.string_maps=null}forceDefaults(e){this.force_defaults=e}dataBuffer(){return this.bb}asUint8Array(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())}prep(e,t){e>this.minalign&&(this.minalign=e);const n=~(this.bb.capacity()-this.space+t)+1&e-1;for(;this.space<n+e+t;){const i=this.bb.capacity();this.bb=Oo.growByteBuffer(this.bb),this.space+=this.bb.capacity()-i}this.pad(n)}pad(e){for(let t=0;t<e;t++)this.bb.writeInt8(--this.space,0)}writeInt8(e){this.bb.writeInt8(this.space-=1,e)}writeInt16(e){this.bb.writeInt16(this.space-=2,e)}writeInt32(e){this.bb.writeInt32(this.space-=4,e)}writeInt64(e){this.bb.writeInt64(this.space-=8,e)}writeFloat32(e){this.bb.writeFloat32(this.space-=4,e)}writeFloat64(e){this.bb.writeFloat64(this.space-=8,e)}addInt8(e){this.prep(1,0),this.writeInt8(e)}addInt16(e){this.prep(2,0),this.writeInt16(e)}addInt32(e){this.prep(4,0),this.writeInt32(e)}addInt64(e){this.prep(8,0),this.writeInt64(e)}addFloat32(e){this.prep(4,0),this.writeFloat32(e)}addFloat64(e){this.prep(8,0),this.writeFloat64(e)}addFieldInt8(e,t,n){(this.force_defaults||t!=n)&&(this.addInt8(t),this.slot(e))}addFieldInt16(e,t,n){(this.force_defaults||t!=n)&&(this.addInt16(t),this.slot(e))}addFieldInt32(e,t,n){(this.force_defaults||t!=n)&&(this.addInt32(t),this.slot(e))}addFieldInt64(e,t,n){(this.force_defaults||!t.equals(n))&&(this.addInt64(t),this.slot(e))}addFieldFloat32(e,t,n){(this.force_defaults||t!=n)&&(this.addFloat32(t),this.slot(e))}addFieldFloat64(e,t,n){(this.force_defaults||t!=n)&&(this.addFloat64(t),this.slot(e))}addFieldOffset(e,t,n){(this.force_defaults||t!=n)&&(this.addOffset(t),this.slot(e))}addFieldStruct(e,t,n){t!=n&&(this.nested(t),this.slot(e))}nested(e){if(e!=this.offset())throw new Error("FlatBuffers: struct must be serialized inline.")}notNested(){if(this.isNested)throw new Error("FlatBuffers: object serialization must not be nested.")}slot(e){this.vtable!==null&&(this.vtable[e]=this.offset())}offset(){return this.bb.capacity()-this.space}static growByteBuffer(e){const t=e.capacity();if(t&3221225472)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");const n=t<<1,i=Ti.allocate(n);return i.setPosition(n-t),i.bytes().set(e.bytes(),n-t),i}addOffset(e){this.prep(Nt,0),this.writeInt32(this.offset()-e+Nt)}startObject(e){this.notNested(),this.vtable==null&&(this.vtable=[]),this.vtable_in_use=e;for(let t=0;t<e;t++)this.vtable[t]=0;this.isNested=!0,this.object_start=this.offset()}endObject(){if(this.vtable==null||!this.isNested)throw new Error("FlatBuffers: endObject called without startObject");this.addInt32(0);const e=this.offset();let t=this.vtable_in_use-1;for(;t>=0&&this.vtable[t]==0;t--);const n=t+1;for(;t>=0;t--)this.addInt16(this.vtable[t]!=0?e-this.vtable[t]:0);const i=2;this.addInt16(e-this.object_start);const s=(n+i)*Cs;this.addInt16(s);let a=0;const o=this.space;e:for(t=0;t<this.vtables.length;t++){const c=this.bb.capacity()-this.vtables[t];if(s==this.bb.readInt16(c)){for(let l=Cs;l<s;l+=Cs)if(this.bb.readInt16(o+l)!=this.bb.readInt16(c+l))continue e;a=this.vtables[t];break}}return a?(this.space=this.bb.capacity()-e,this.bb.writeInt32(this.space,a-e)):(this.vtables.push(this.offset()),this.bb.writeInt32(this.bb.capacity()-e,this.offset()-e)),this.isNested=!1,e}finish(e,t,n){const i=n?_a:0;if(t){const s=t;if(this.prep(this.minalign,Nt+Xt+i),s.length!=Xt)throw new Error("FlatBuffers: file identifier must be length "+Xt);for(let a=Xt-1;a>=0;a--)this.writeInt8(s.charCodeAt(a))}this.prep(this.minalign,Nt+i),this.addOffset(e),i&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(e,t){this.finish(e,t,!0)}requiredField(e,t){const n=this.bb.capacity()-e,i=n-this.bb.readInt32(n);if(this.bb.readInt16(i+t)==0)throw new Error("FlatBuffers: field "+t+" must be set")}startVector(e,t,n){this.notNested(),this.vector_num_elems=t,this.prep(Nt,e*t),this.prep(n,e*t)}endVector(){return this.writeInt32(this.vector_num_elems),this.offset()}createSharedString(e){if(!e)return 0;if(this.string_maps||(this.string_maps=new Map),this.string_maps.has(e))return this.string_maps.get(e);const t=this.createString(e);return this.string_maps.set(e,t),t}createString(e){if(!e)return 0;let t;if(e instanceof Uint8Array)t=e;else{t=[];let n=0;for(;n<e.length;){let i;const s=e.charCodeAt(n++);if(s<55296||s>=56320)i=s;else{const a=e.charCodeAt(n++);i=(s<<10)+a+-56613888}i<128?t.push(i):(i<2048?t.push(i>>6&31|192):(i<65536?t.push(i>>12&15|224):t.push(i>>18&7|240,i>>12&63|128),t.push(i>>6&63|128)),t.push(i&63|128))}}this.addInt8(0),this.startVector(1,t.length,1),this.bb.setPosition(this.space-=t.length);for(let n=0,i=this.space,s=this.bb.bytes();n<t.length;n++)s[i++]=t[n];return this.endVector()}createLong(e,t){return en.create(e,t)}createObjectOffset(e){return e===null?0:typeof e=="string"?this.createString(e):e.pack(this)}createObjectOffsetList(e){const t=[];for(let n=0;n<e.length;++n){const i=e[n];if(i!==null)t.push(this.createObjectOffset(i));else throw new Error("FlatBuffers: Argument for createObjectOffsetList cannot contain null.")}return t}createStructOffsetList(e,t){return t(this,e.length),this.createObjectOffsetList(e),this.endVector()}}const Ie={ComponentState:Object.freeze({DEFAULT:"default",TOUCHED:"touched",PRESSED:"pressed"}),ComponentProperty:Object.freeze({BUTTON:"button",X_AXIS:"xAxis",Y_AXIS:"yAxis",STATE:"state"}),ButtonTouchThreshold:.05,AxisTouchThreshold:.1,VisualResponseProperty:Object.freeze({TRANSFORM:"transform",VISIBILITY:"visibility"})};async function Ca(r){const e=await fetch(r);if(e.ok)return e.json();throw new Error(e.statusText)}async function Bh(r){return await Ca(`${r}/profilesList.json`)}async function zh(r,e,t=null,n=!0){if(!r)throw new Error("No xrInputSource supplied");const i=await Bh(e);let s;if(r.profiles.some(c=>{const l=i[c];return l&&(s={profileId:c,profilePath:`${e}/${l.path}`,deprecated:!!l.deprecated}),!!s}),!s){if(!t)throw new Error("No matching profile name found");const c=i[t];if(!c)throw new Error(`No matching profile name found and default profile "${t}" missing.`);s={profileId:t,profilePath:`${e}/${c.path}`,deprecated:!!c.deprecated}}const a=await Ca(s.profilePath);let o;if(n){let c;if(r.handedness==="any"?c=a.layouts[Object.keys(a.layouts)[0]]:c=a.layouts[r.handedness],!c)throw new Error(`No matching handedness, ${r.handedness}, in profile ${s.profileId}`);c.assetPath&&(o=s.profilePath.replace("profile.json",c.assetPath))}return{profile:a,assetPath:o}}const Nh={xAxis:0,yAxis:0,button:0,state:Ie.ComponentState.DEFAULT};function Uh(r=0,e=0){let t=r,n=e;if(Math.sqrt(r*r+e*e)>1){const i=Math.atan2(e,r);t=Math.cos(i),n=Math.sin(i)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:n*.5+.5}}class Dh{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===Ie.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(Nh)}updateFromComponent({xAxis:e,yAxis:t,button:n,state:i}){const{normalizedXAxis:s,normalizedYAxis:a}=Uh(e,t);switch(this.componentProperty){case Ie.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?s:.5;break;case Ie.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?a:.5;break;case Ie.ComponentProperty.BUTTON:this.value=this.states.includes(i)?n:0;break;case Ie.ComponentProperty.STATE:this.valueNodeProperty===Ie.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(i):this.value=this.states.includes(i)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class Lh{constructor(e,t){if(!e||!t||!t.visualResponses||!t.gamepadIndices||Object.keys(t.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=e,this.type=t.type,this.rootNodeName=t.rootNodeName,this.touchPointNodeName=t.touchPointNodeName,this.visualResponses={},Object.keys(t.visualResponses).forEach(n=>{const i=new Dh(t.visualResponses[n]);this.visualResponses[n]=i}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:Ie.ComponentState.DEFAULT,button:this.gamepadIndices.button!==void 0?0:void 0,xAxis:this.gamepadIndices.xAxis!==void 0?0:void 0,yAxis:this.gamepadIndices.yAxis!==void 0?0:void 0}}get data(){return{id:this.id,...this.values}}updateFromGamepad(e){if(this.values.state=Ie.ComponentState.DEFAULT,this.gamepadIndices.button!==void 0&&e.buttons.length>this.gamepadIndices.button){const t=e.buttons[this.gamepadIndices.button];this.values.button=t.value,this.values.button=this.values.button<0?0:this.values.button,this.values.button=this.values.button>1?1:this.values.button,t.pressed||this.values.button===1?this.values.state=Ie.ComponentState.PRESSED:(t.touched||this.values.button>Ie.ButtonTouchThreshold)&&(this.values.state=Ie.ComponentState.TOUCHED)}this.gamepadIndices.xAxis!==void 0&&e.axes.length>this.gamepadIndices.xAxis&&(this.values.xAxis=e.axes[this.gamepadIndices.xAxis],this.values.xAxis=this.values.xAxis<-1?-1:this.values.xAxis,this.values.xAxis=this.values.xAxis>1?1:this.values.xAxis,this.values.state===Ie.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>Ie.AxisTouchThreshold&&(this.values.state=Ie.ComponentState.TOUCHED)),this.gamepadIndices.yAxis!==void 0&&e.axes.length>this.gamepadIndices.yAxis&&(this.values.yAxis=e.axes[this.gamepadIndices.yAxis],this.values.yAxis=this.values.yAxis<-1?-1:this.values.yAxis,this.values.yAxis=this.values.yAxis>1?1:this.values.yAxis,this.values.state===Ie.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>Ie.AxisTouchThreshold&&(this.values.state=Ie.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class Fh{constructor(e,t,n){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=n,this.id=t.profileId,this.layoutDescription=t.layouts[e.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(i=>{const s=this.layoutDescription.components[i];this.components[i]=new Lh(i,s)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const e=[];return Object.values(this.components).forEach(t=>{e.push(t.data)}),e}updateFromGamepad(){Object.values(this.components).forEach(e=>{e.updateFromGamepad(this.xrInputSource.gamepad)})}}const We=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Pa=1234567;const Ea=Math.PI/180,ka=180/Math.PI;function Vh(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(We[r&255]+We[r>>8&255]+We[r>>16&255]+We[r>>24&255]+"-"+We[e&255]+We[e>>8&255]+"-"+We[e>>16&15|64]+We[e>>24&255]+"-"+We[t&63|128]+We[t>>8&255]+"-"+We[t>>16&255]+We[t>>24&255]+We[n&255]+We[n>>8&255]+We[n>>16&255]+We[n>>24&255]).toLowerCase()}function Ut(r,e,t){return Math.max(e,Math.min(t,r))}function Ra(r,e){return(r%e+e)%e}function jh(r,e,t,n,i){return n+(r-e)*(i-n)/(t-e)}function Jh(r,e,t){return r!==e?(t-r)/(e-r):0}function Aa(r,e,t){return(1-t)*r+t*e}function Gh(r,e,t,n){return Aa(r,e,1-Math.exp(-t*n))}function Wh(r,e=1){return e-Math.abs(Ra(r,e*2)-e)}function Hh(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function qh(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function Xh(r,e){return r+Math.floor(Math.random()*(e-r+1))}function Yh(r,e){return r+Math.random()*(e-r)}function Zh(r){return r*(.5-Math.random())}function Kh(r){r!==void 0&&(Pa=r);let e=Pa+=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 Qh(r){return r*Ea}function $h(r){return r*ka}function eu(r){return(r&r-1)===0&&r!==0}function tu(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function nu(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function iu(r,e,t,n,i){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+n)/2),u=a((e+n)/2),d=s((e-n)/2),m=a((e-n)/2),f=s((n-e)/2),x=a((n-e)/2);switch(i){case"XYX":r.set(o*u,c*d,c*m,o*l);break;case"YZY":r.set(c*m,o*u,c*d,o*l);break;case"ZXZ":r.set(c*d,c*m,o*u,o*l);break;case"XZX":r.set(o*u,c*x,c*f,o*l);break;case"YXY":r.set(c*f,o*u,c*x,o*l);break;case"ZYZ":r.set(c*x,c*f,o*u,o*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function ru(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function su(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}const Bn={DEG2RAD:Ea,RAD2DEG:ka,generateUUID:Vh,clamp:Ut,euclideanModulo:Ra,mapLinear:jh,inverseLerp:Jh,lerp:Aa,damp:Gh,pingpong:Wh,smoothstep:Hh,smootherstep:qh,randInt:Xh,randFloat:Yh,randFloatSpread:Zh,seededRandom:Kh,degToRad:Qh,radToDeg:$h,isPowerOfTwo:eu,ceilPowerOfTwo:tu,floorPowerOfTwo:nu,setQuaternionFromProperEuler:iu,normalize:su,denormalize:ru};class ne{constructor(e=0,t=0,n=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,s,a,o){let c=n[i+0],l=n[i+1],u=n[i+2],d=n[i+3];const m=s[a+0],f=s[a+1],x=s[a+2],_=s[a+3];if(o===0){e[t+0]=c,e[t+1]=l,e[t+2]=u,e[t+3]=d;return}if(o===1){e[t+0]=m,e[t+1]=f,e[t+2]=x,e[t+3]=_;return}if(d!==_||c!==m||l!==f||u!==x){let g=1-o;const v=c*m+l*f+u*x+d*_,w=v>=0?1:-1,S=1-v*v;if(S>Number.EPSILON){const C=Math.sqrt(S),P=Math.atan2(C,v*w);g=Math.sin(g*P)/C,o=Math.sin(o*P)/C}const T=o*w;if(c=c*g+m*T,l=l*g+f*T,u=u*g+x*T,d=d*g+_*T,g===1-o){const C=1/Math.sqrt(c*c+l*l+u*u+d*d);c*=C,l*=C,u*=C,d*=C}}e[t]=c,e[t+1]=l,e[t+2]=u,e[t+3]=d}static multiplyQuaternionsFlat(e,t,n,i,s,a){const o=n[i],c=n[i+1],l=n[i+2],u=n[i+3],d=s[a],m=s[a+1],f=s[a+2],x=s[a+3];return e[t]=o*x+u*d+c*f-l*m,e[t+1]=c*x+u*m+l*d-o*f,e[t+2]=l*x+u*f+o*m-c*d,e[t+3]=u*x-o*d-c*m-l*f,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,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new ne(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 n=e._x,i=e._y,s=e._z,a=e._order,o=Math.cos,c=Math.sin,l=o(n/2),u=o(i/2),d=o(s/2),m=c(n/2),f=c(i/2),x=c(s/2);switch(a){case"XYZ":this._x=m*u*d+l*f*x,this._y=l*f*d-m*u*x,this._z=l*u*x+m*f*d,this._w=l*u*d-m*f*x;break;case"YXZ":this._x=m*u*d+l*f*x,this._y=l*f*d-m*u*x,this._z=l*u*x-m*f*d,this._w=l*u*d+m*f*x;break;case"ZXY":this._x=m*u*d-l*f*x,this._y=l*f*d+m*u*x,this._z=l*u*x+m*f*d,this._w=l*u*d-m*f*x;break;case"ZYX":this._x=m*u*d-l*f*x,this._y=l*f*d+m*u*x,this._z=l*u*x-m*f*d,this._w=l*u*d+m*f*x;break;case"YZX":this._x=m*u*d+l*f*x,this._y=l*f*d+m*u*x,this._z=l*u*x-m*f*d,this._w=l*u*d-m*f*x;break;case"XZY":this._x=m*u*d-l*f*x,this._y=l*f*d-m*u*x,this._z=l*u*x+m*f*d,this._w=l*u*d+m*f*x;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,n=t[0],i=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],u=t[6],d=t[10],m=n+o+d;if(m>0){const f=.5/Math.sqrt(m+1);this._w=.25/f,this._x=(u-c)*f,this._y=(s-l)*f,this._z=(a-i)*f}else if(n>o&&n>d){const f=2*Math.sqrt(1+n-o-d);this._w=(u-c)/f,this._x=.25*f,this._y=(i+a)/f,this._z=(s+l)/f}else if(o>d){const f=2*Math.sqrt(1+o-n-d);this._w=(s-l)/f,this._x=(i+a)/f,this._y=.25*f,this._z=(c+u)/f}else{const f=2*Math.sqrt(1+d-n-o);this._w=(a-i)/f,this._x=(s+l)/f,this._y=(c+u)/f,this._z=.25*f}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<Number.EPSILON?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(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=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Ut(this.dot(e),-1,1)))}rotateTowards(e,t){const n=this.angleTo(e);if(n===0)return this;const i=Math.min(1,t/n);return this.slerp(e,i),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 n=e._x,i=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,u=t._w;return this._x=n*u+a*o+i*l-s*c,this._y=i*u+a*c+s*o-n*l,this._z=s*u+a*l+n*c-i*o,this._w=a*u-n*o-i*c-s*l,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const n=this._x,i=this._y,s=this._z,a=this._w;let o=a*e._w+n*e._x+i*e._y+s*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=a,this._x=n,this._y=i,this._z=s,this;const c=1-o*o;if(c<=Number.EPSILON){const f=1-t;return this._w=f*a+t*this._w,this._x=f*n+t*this._x,this._y=f*i+t*this._y,this._z=f*s+t*this._z,this.normalize(),this}const l=Math.sqrt(c),u=Math.atan2(l,o),d=Math.sin((1-t)*u)/l,m=Math.sin(t*u)/l;return this._w=a*d+this._w*m,this._x=n*d+this._x*m,this._y=i*d+this._y*m,this._z=s*d+this._z*m,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}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}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 G{constructor(e=0,t=0,n=0){this.isVector3=!0,G.prototype.isVector3=!0,this.x=e,this.y=t,this.z=n}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,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 G(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(Oa.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Oa.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*i,this.y=s[1]*t+s[4]*n+s[7]*i,this.z=s[2]*t+s[5]*n+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=e.elements,a=1/(s[3]*t+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*i+s[12])*a,this.y=(s[1]*t+s[5]*n+s[9]*i+s[13])*a,this.z=(s[2]*t+s[6]*n+s[10]*i+s[14])*a,this}applyQuaternion(e){const t=this.x,n=this.y,i=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*i-o*n),u=2*(o*t-s*i),d=2*(s*n-a*t);return this.x=t+c*l+a*d-o*u,this.y=n+c*u+o*l-s*d,this.z=i+c*d+s*u-a*l,this}transformDirection(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*i,this.y=s[1]*t+s[5]*n+s[9]*i,this.z=s[2]*t+s[6]*n+s[10]*i,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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}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,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const n=e.x,i=e.y,s=e.z,a=t.x,o=t.y,c=t.z;return this.x=i*c-s*o,this.y=s*a-n*c,this.z=n*o-i*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return Es.copy(this).projectOnVector(e),this.sub(Es)}reflect(e){return this.sub(Es.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 n=this.dot(e)/t;return Math.acos(Ut(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSphericalCoords(e,t,n){const i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,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(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,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}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}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const Es=new G,Oa=new ne,dr=2e3,Ia=2001;class It{constructor(e,t,n,i,s,a,o,c,l,u,d,m,f,x,_,g){this.isMatrix4=!0,It.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,n,i,s,a,o,c,l,u,d,m,f,x,_,g)}extractPosition(e){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(e)}multiplyToArray(e,t,n){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(e){return this.makeRotationFromQuaternion(e)}set(e,t,n,i,s,a,o,c,l,u,d,m,f,x,_,g){const v=this.elements;return v[0]=e,v[4]=t,v[8]=n,v[12]=i,v[1]=s,v[5]=a,v[9]=o,v[13]=c,v[2]=l,v[6]=u,v[10]=d,v[14]=m,v[3]=f,v[7]=x,v[11]=_,v[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 It().fromArray(this.elements)}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){const t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[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,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,n=e.elements,i=1/zn.setFromMatrixColumn(e,0).length(),s=1/zn.setFromMatrixColumn(e,1).length(),a=1/zn.setFromMatrixColumn(e,2).length();return t[0]=n[0]*i,t[1]=n[1]*i,t[2]=n[2]*i,t[3]=0,t[4]=n[4]*s,t[5]=n[5]*s,t[6]=n[6]*s,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,n=e.x,i=e.y,s=e.z,a=Math.cos(n),o=Math.sin(n),c=Math.cos(i),l=Math.sin(i),u=Math.cos(s),d=Math.sin(s);if(e.order==="XYZ"){const m=a*u,f=a*d,x=o*u,_=o*d;t[0]=c*u,t[4]=-c*d,t[8]=l,t[1]=f+x*l,t[5]=m-_*l,t[9]=-o*c,t[2]=_-m*l,t[6]=x+f*l,t[10]=a*c}else if(e.order==="YXZ"){const m=c*u,f=c*d,x=l*u,_=l*d;t[0]=m+_*o,t[4]=x*o-f,t[8]=a*l,t[1]=a*d,t[5]=a*u,t[9]=-o,t[2]=f*o-x,t[6]=_+m*o,t[10]=a*c}else if(e.order==="ZXY"){const m=c*u,f=c*d,x=l*u,_=l*d;t[0]=m-_*o,t[4]=-a*d,t[8]=x+f*o,t[1]=f+x*o,t[5]=a*u,t[9]=_-m*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const m=a*u,f=a*d,x=o*u,_=o*d;t[0]=c*u,t[4]=x*l-f,t[8]=m*l+_,t[1]=c*d,t[5]=_*l+m,t[9]=f*l-x,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const m=a*c,f=a*l,x=o*c,_=o*l;t[0]=c*u,t[4]=_-m*d,t[8]=x*d+f,t[1]=d,t[5]=a*u,t[9]=-o*u,t[2]=-l*u,t[6]=f*d+x,t[10]=m-_*d}else if(e.order==="XZY"){const m=a*c,f=a*l,x=o*c,_=o*l;t[0]=c*u,t[4]=-d,t[8]=l*u,t[1]=m*d+_,t[5]=a*u,t[9]=f*d-x,t[2]=x*d-f,t[6]=o*u,t[10]=_*d+m}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(ou,e,au)}lookAt(e,t,n){const i=this.elements;return pt.subVectors(e,t),pt.lengthSq()===0&&(pt.z=1),pt.normalize(),sn.crossVectors(n,pt),sn.lengthSq()===0&&(Math.abs(n.z)===1?pt.x+=1e-4:pt.z+=1e-4,pt.normalize(),sn.crossVectors(n,pt)),sn.normalize(),pr.crossVectors(pt,sn),i[0]=sn.x,i[4]=pr.x,i[8]=pt.x,i[1]=sn.y,i[5]=pr.y,i[9]=pt.y,i[2]=sn.z,i[6]=pr.z,i[10]=pt.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,a=n[0],o=n[4],c=n[8],l=n[12],u=n[1],d=n[5],m=n[9],f=n[13],x=n[2],_=n[6],g=n[10],v=n[14],w=n[3],S=n[7],T=n[11],C=n[15],P=i[0],E=i[4],O=i[8],A=i[12],R=i[1],B=i[5],z=i[9],U=i[13],L=i[2],J=i[6],H=i[10],se=i[14],W=i[3],pe=i[7],te=i[11],ue=i[15];return s[0]=a*P+o*R+c*L+l*W,s[4]=a*E+o*B+c*J+l*pe,s[8]=a*O+o*z+c*H+l*te,s[12]=a*A+o*U+c*se+l*ue,s[1]=u*P+d*R+m*L+f*W,s[5]=u*E+d*B+m*J+f*pe,s[9]=u*O+d*z+m*H+f*te,s[13]=u*A+d*U+m*se+f*ue,s[2]=x*P+_*R+g*L+v*W,s[6]=x*E+_*B+g*J+v*pe,s[10]=x*O+_*z+g*H+v*te,s[14]=x*A+_*U+g*se+v*ue,s[3]=w*P+S*R+T*L+C*W,s[7]=w*E+S*B+T*J+C*pe,s[11]=w*O+S*z+T*H+C*te,s[15]=w*A+S*U+T*se+C*ue,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],n=e[4],i=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],u=e[2],d=e[6],m=e[10],f=e[14],x=e[3],_=e[7],g=e[11],v=e[15];return x*(+s*c*d-i*l*d-s*o*m+n*l*m+i*o*f-n*c*f)+_*(+t*c*f-t*l*m+s*a*m-i*a*f+i*l*u-s*c*u)+g*(+t*l*d-t*o*f-s*a*d+n*a*f+s*o*u-n*l*u)+v*(-i*o*u-t*c*d+t*o*m+i*a*d-n*a*m+n*c*u)}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,n){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=n),this}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],d=e[9],m=e[10],f=e[11],x=e[12],_=e[13],g=e[14],v=e[15],w=d*g*l-_*m*l+_*c*f-o*g*f-d*c*v+o*m*v,S=x*m*l-u*g*l-x*c*f+a*g*f+u*c*v-a*m*v,T=u*_*l-x*d*l+x*o*f-a*_*f-u*o*v+a*d*v,C=x*d*c-u*_*c-x*o*m+a*_*m+u*o*g-a*d*g,P=t*w+n*S+i*T+s*C;if(P===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/P;return e[0]=w*E,e[1]=(_*m*s-d*g*s-_*i*f+n*g*f+d*i*v-n*m*v)*E,e[2]=(o*g*s-_*c*s+_*i*l-n*g*l-o*i*v+n*c*v)*E,e[3]=(d*c*s-o*m*s-d*i*l+n*m*l+o*i*f-n*c*f)*E,e[4]=S*E,e[5]=(u*g*s-x*m*s+x*i*f-t*g*f-u*i*v+t*m*v)*E,e[6]=(x*c*s-a*g*s-x*i*l+t*g*l+a*i*v-t*c*v)*E,e[7]=(a*m*s-u*c*s+u*i*l-t*m*l-a*i*f+t*c*f)*E,e[8]=T*E,e[9]=(x*d*s-u*_*s-x*n*f+t*_*f+u*n*v-t*d*v)*E,e[10]=(a*_*s-x*o*s+x*n*l-t*_*l-a*n*v+t*o*v)*E,e[11]=(u*o*s-a*d*s-u*n*l+t*d*l+a*n*f-t*o*f)*E,e[12]=C*E,e[13]=(u*_*i-x*d*i+x*n*m-t*_*m-u*n*g+t*d*g)*E,e[14]=(x*o*i-a*_*i-x*n*c+t*_*c+a*n*g-t*o*g)*E,e[15]=(a*d*i-u*o*i+u*n*c-t*d*c-a*n*m+t*o*m)*E,this}scale(e){const t=this.elements,n=e.x,i=e.y,s=e.z;return t[0]*=n,t[4]*=i,t[8]*=s,t[1]*=n,t[5]*=i,t[9]*=s,t[2]*=n,t[6]*=i,t[10]*=s,t[3]*=n,t[7]*=i,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,i))}makeTranslation(e,t,n){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,n,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const n=Math.cos(t),i=Math.sin(t),s=1-n,a=e.x,o=e.y,c=e.z,l=s*a,u=s*o;return this.set(l*a+n,l*o-i*c,l*c+i*o,0,l*o+i*c,u*o+n,u*c-i*a,0,l*c-i*o,u*c+i*a,s*c*c+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,i,s,a){return this.set(1,n,s,0,e,1,a,0,t,i,1,0,0,0,0,1),this}compose(e,t,n){const i=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,u=a+a,d=o+o,m=s*l,f=s*u,x=s*d,_=a*u,g=a*d,v=o*d,w=c*l,S=c*u,T=c*d,C=n.x,P=n.y,E=n.z;return i[0]=(1-(_+v))*C,i[1]=(f+T)*C,i[2]=(x-S)*C,i[3]=0,i[4]=(f-T)*P,i[5]=(1-(m+v))*P,i[6]=(g+w)*P,i[7]=0,i[8]=(x+S)*E,i[9]=(g-w)*E,i[10]=(1-(m+_))*E,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,n){const i=this.elements;let s=zn.set(i[0],i[1],i[2]).length();const a=zn.set(i[4],i[5],i[6]).length(),o=zn.set(i[8],i[9],i[10]).length();this.determinant()<0&&(s=-s),e.x=i[12],e.y=i[13],e.z=i[14],Rt.copy(this);const c=1/s,l=1/a,u=1/o;return Rt.elements[0]*=c,Rt.elements[1]*=c,Rt.elements[2]*=c,Rt.elements[4]*=l,Rt.elements[5]*=l,Rt.elements[6]*=l,Rt.elements[8]*=u,Rt.elements[9]*=u,Rt.elements[10]*=u,t.setFromRotationMatrix(Rt),n.x=s,n.y=a,n.z=o,this}makePerspective(e,t,n,i,s,a,o=dr){const c=this.elements,l=2*s/(t-e),u=2*s/(n-i),d=(t+e)/(t-e),m=(n+i)/(n-i);let f,x;if(o===dr)f=-(a+s)/(a-s),x=-2*a*s/(a-s);else if(o===Ia)f=-a/(a-s),x=-a*s/(a-s);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=l,c[4]=0,c[8]=d,c[12]=0,c[1]=0,c[5]=u,c[9]=m,c[13]=0,c[2]=0,c[6]=0,c[10]=f,c[14]=x,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,i,s,a,o=dr){const c=this.elements,l=1/(t-e),u=1/(n-i),d=1/(a-s),m=(t+e)*l,f=(n+i)*u;let x,_;if(o===dr)x=(a+s)*d,_=-2*d;else if(o===Ia)x=s*d,_=-1*d;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-m,c[1]=0,c[5]=2*u,c[9]=0,c[13]=-f,c[2]=0,c[6]=0,c[10]=_,c[14]=-x,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<16;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}}const zn=new G,Rt=new It,ou=new G(0,0,0),au=new G(1,1,1),sn=new G,pr=new G,pt=new G,Ba=new It,za=new ne;class Mi{constructor(e=0,t=0,n=0,i=Mi.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=i}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,n,i=this._order){return this._x=e,this._y=t,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new Mi(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,n=!0){const i=e.elements,s=i[0],a=i[4],o=i[8],c=i[1],l=i[5],u=i[9],d=i[2],m=i[6],f=i[10];switch(t){case"XYZ":this._y=Math.asin(Ut(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,f),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(m,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Ut(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,f),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-d,s),this._z=0);break;case"ZXY":this._x=Math.asin(Ut(m,-1,1)),Math.abs(m)<.9999999?(this._y=Math.atan2(-d,f),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Ut(d,-1,1)),Math.abs(d)<.9999999?(this._x=Math.atan2(m,f),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin(Ut(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-u,l),this._y=Math.atan2(-d,s)):(this._x=0,this._y=Math.atan2(o,f));break;case"XZY":this._z=Math.asin(-Ut(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(m,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-u,f),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return Ba.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Ba,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return za.setFromEuler(this),this.setFromQuaternion(za,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(e){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._order}}Mi.DEFAULT_ORDER="XYZ";class Xn{constructor(e=0,t=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 Xn(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,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}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 n=this.dot(e)/t;return Math.acos(Ut(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y;return t*t+n*n}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,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,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}rotateAround(e,t){const n=Math.cos(t),i=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*n-a*i+e.x,this.y=s*i+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}Xn.isVector2=!0;class ct{constructor(e=0,t=0,n=0,i=1){ct.prototype.isVector4=!0,this.x=e,this.y=t,this.z=n,this.w=i}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,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,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 ct(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}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,n=this.y,i=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*i+a[12]*s,this.y=a[1]*t+a[5]*n+a[9]*i+a[13]*s,this.z=a[2]*t+a[6]*n+a[10]*i+a[14]*s,this.w=a[3]*t+a[7]*n+a[11]*i+a[15]*s,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,n,i,s;const a=e.elements,o=a[0],c=a[4],l=a[8],u=a[1],d=a[5],m=a[9],f=a[2],x=a[6],_=a[10];if(Math.abs(c-u)<.01&&Math.abs(l-f)<.01&&Math.abs(m-x)<.01){if(Math.abs(c+u)<.1&&Math.abs(l+f)<.1&&Math.abs(m+x)<.1&&Math.abs(o+d+_-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const v=(o+1)/2,w=(d+1)/2,S=(_+1)/2,T=(c+u)/4,C=(l+f)/4,P=(m+x)/4;return v>w&&v>S?v<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(v),i=T/n,s=C/n):w>S?w<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(w),n=T/i,s=P/i):S<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(S),n=C/s,i=P/s),this.set(n,i,s,t),this}let g=Math.sqrt((x-m)*(x-m)+(l-f)*(l-f)+(u-c)*(u-c));return Math.abs(g)<.001&&(g=1),this.x=(x-m)/g,this.y=(l-f)/g,this.z=(u-c)/g,this.w=Math.acos((o+d+_-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 n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}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,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,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}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 Vt{constructor(e,t,n,i,s,a,o,c,l){Vt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,a,o,c,l)}set(e,t,n,i,s,a,o,c,l){const u=this.elements;return u[0]=e,u[1]=i,u[2]=o,u[3]=t,u[4]=s,u[5]=c,u[6]=n,u[7]=a,u[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.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 n=e.elements,i=t.elements,s=this.elements,a=n[0],o=n[3],c=n[6],l=n[1],u=n[4],d=n[7],m=n[2],f=n[5],x=n[8],_=i[0],g=i[3],v=i[6],w=i[1],S=i[4],T=i[7],C=i[2],P=i[5],E=i[8];return s[0]=a*_+o*w+c*C,s[3]=a*g+o*S+c*P,s[6]=a*v+o*T+c*E,s[1]=l*_+u*w+d*C,s[4]=l*g+u*S+d*P,s[7]=l*v+u*T+d*E,s[2]=m*_+f*w+x*C,s[5]=m*g+f*S+x*P,s[8]=m*v+f*T+x*E,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],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8];return t*a*u-t*o*l-n*s*u+n*o*c+i*s*l-i*a*c}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],d=u*a-o*l,m=o*c-u*s,f=l*s-a*c,x=t*d+n*m+i*f;if(x===0)return this.set(0,0,0,0,0,0,0,0,0);const _=1/x;return e[0]=d*_,e[1]=(i*l-u*n)*_,e[2]=(o*n-i*a)*_,e[3]=m*_,e[4]=(u*t-i*c)*_,e[5]=(i*s-o*t)*_,e[6]=f*_,e[7]=(n*c-l*t)*_,e[8]=(a*t-n*s)*_,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,n,i,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(n*c,n*l,-n*(c*a+l*o)+a+e,-i*l,i*c,-i*(-l*a+c*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(ks.makeScale(e,t)),this}rotate(e){return this.premultiply(ks.makeRotation(-e)),this}translate(e,t){return this.premultiply(ks.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),n=Math.sin(e);return this.set(t,-n,0,n,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,n=e.elements;for(let i=0;i<9;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new Vt().fromArray(this.elements)}}const ks=new Vt;var tt;(function(r){r[r.Random=0]="Random",r[r.Loop=1]="Loop",r[r.PingPong=2]="PingPong",r[r.Burst=3]="Burst"})(tt||(tt={}));function ni(r,e,t,n){let i;switch(tt.Random===r?e=Math.random():tt.Burst===r&&n.isBursting&&(e=n.burstParticleIndex/n.burstParticleCount),t>0?i=Math.floor(e/t)*t:i=e,r){case tt.Loop:i=i%1;break;case tt.PingPong:i=Math.abs(i%2-1);break}return i}class Mn{constructor(e,t,n,i){this.p=[e,t,n,i]}genValue(e){const t=e*e,n=e*e*e,i=1-e,s=i*i,a=s*i;return this.p[0]*a+this.p[1]*s*e*3+this.p[2]*i*t*3+this.p[3]*n}derivativeCoefficients(e){const t=[];for(let n=e,i=n.length-1;i>0;i--){const s=[];for(let a=0;a<i;a++){const o=i*(n[a+1]-n[a]);s.push(o)}t.push(s),n=s}return t}getSlope(e){const t=this.derivativeCoefficients(this.p)[0],n=1-e,i=n*n,s=n*e*2,a=e*e;return i*t[0]+s*t[1]+a*t[2]}controlCurve(e,t){this.p[1]=e/3+this.p[0],this.p[2]=this.p[3]-t/3}hull(e){let t=this.p,n=[],i,s=0,a=0,o=0;const c=[];for(c[s++]=t[0],c[s++]=t[1],c[s++]=t[2],c[s++]=t[3];t.length>1;){for(n=[],a=0,o=t.length-1;a<o;a++)i=e*t[a]+(1-e)*t[a+1],c[s++]=i,n.push(i);t=n}return c}split(e){const t=this.hull(e);return{left:new Mn(t[0],t[4],t[7],t[9]),right:new Mn(t[9],t[8],t[6],t[3]),span:t}}clone(){return new Mn(this.p[0],this.p[1],this.p[2],this.p[3])}toJSON(){return{p0:this.p[0],p1:this.p[1],p2:this.p[2],p3:this.p[3]}}static fromJSON(e){return new Mn(e.p0,e.p1,e.p2,e.p3)}}const ii=r=>({r:r.x,g:r.y,b:r.z,a:r.w}),ri=r=>new ct(r.r,r.g,r.b,r.a),cu=(r,e)=>{switch(e){case"Vector3":return new G(r.x,r.y,r.z);case"Vector4":return new ct(r.x,r.y,r.z,r.w);case"Color":return new G(r.r,r.g,r.b);case"Number":return r;default:return r}},lu=(r,e)=>{switch(e){case"Vector3":return{x:r.x,y:r.y,z:r.z};case"Vector4":return{x:r.x,y:r.y,z:r.z,w:r.w};case"Color":return{r:r.x,g:r.y,b:r.z};case"Number":return r;default:return r}};class is{constructor(e,t){this.a=e,this.b=t,this.type="value"}startGen(e){}genColor(e,t){const n=Math.random();return t.copy(this.a).lerp(this.b,n)}toJSON(){return{type:"RandomColor",a:ii(this.a),b:ii(this.b)}}static fromJSON(e){return new is(ri(e.a),ri(e.b))}clone(){return new is(this.a.clone(),this.b.clone())}}class Yn{constructor(e,t){this.a=e,this.b=t,this.indexCount=-1,this.type="value"}startGen(e){this.indexCount=e.length,e.push(Math.random())}genColor(e,t){return this.indexCount===-1&&this.startGen(e),t.copy(this.a).lerp(this.b,e[this.indexCount])}toJSON(){return{type:"ColorRange",a:ii(this.a),b:ii(this.b)}}static fromJSON(e){return new Yn(ri(e.a),ri(e.b))}clone(){return new Yn(this.a.clone(),this.b.clone())}}class un{constructor(e,t){this.subType=t,this.type="function",this.keys=e}findKey(e){let t=0,n=0,i=this.keys.length-1;for(;n+1<i;)if(t=Math.floor((n+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))n=t+1;else return t;for(let s=n;s<=i;s++)if(e>=this.getStartX(s)&&e<=this.getEndX(s))return s;return-1}getStartX(e){return this.keys[e][1]}getEndX(e){return e+1<this.keys.length?this.keys[e+1][1]:1}genValue(e,t){const n=this.findKey(t);return this.subType==="Number"?n===-1?this.keys[0][0]:n+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[n+1][0]-this.keys[n][0])*((t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))+this.keys[n][0]:n===-1?e.copy(this.keys[0][0]):n+1>=this.keys.length?e.copy(this.keys[this.keys.length-1][0]):e.copy(this.keys[n][0]).lerp(this.keys[n+1][0],(t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([e,t])=>({value:lu(e,this.subType),pos:t}))}}static fromJSON(e){return new un(e.keys.map(t=>[cu(t.value,e.subType),t.pos]),e.subType)}clone(){return this.subType==="Number"?new un(this.keys.map(([e,t])=>[e,t]),this.subType):new un(this.keys.map(([e,t])=>[e.clone(),t]),this.subType)}}const fr=new G;class kn{constructor(e=[[new G(0,0,0),0],[new G(1,1,1),0]],t=[[1,0],[1,1]]){this.type="function",this.color=new un(e,"Color"),this.alpha=new un(t,"Number")}genColor(e,t,n){return this.color.genValue(fr,n),t.set(fr.x,fr.y,fr.z,this.alpha.genValue(1,n))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(e){if(e.functions){const t=e.functions.map(n=>[Yn.fromJSON(n.function).a,n.start]);return e.functions.length>0&&t.push([Yn.fromJSON(e.functions[e.functions.length-1].function).b,1]),new kn(t.map(n=>[new G(n[0].x,n[0].y,n[0].z),n[1]]),t.map(n=>[n[0].w,n[1]]))}else{const t=new kn;return t.alpha=un.fromJSON(e.alpha),t.color=un.fromJSON(e.color),t}}clone(){const e=new kn;return e.alpha=this.alpha.clone(),e.color=this.color.clone(),e}startGen(e){}}const Rs=new ct;class rs{constructor(e,t){this.indexCount=0,this.type="function",this.gradient1=e,this.gradient2=t}startGen(e){this.indexCount=e.length,e.push(Math.random())}genColor(e,t,n){return this.gradient1.genColor(e,t,n),this.gradient2.genColor(e,Rs,n),e&&e[this.indexCount]!==void 0?t.lerp(Rs,e[this.indexCount]):t.lerp(Rs,Math.random()),t}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(e){return new rs(kn.fromJSON(e.gradient1),kn.fromJSON(e.gradient2))}clone(){return new rs(this.gradient1.clone(),this.gradient2.clone())}}class Cn{constructor(e){this.color=e,this.type="value"}startGen(e){}genColor(e,t){return t.copy(this.color)}toJSON(){return{type:"ConstantColor",color:ii(this.color)}}static fromJSON(e){return new Cn(ri(e.color))}clone(){return new Cn(this.color.clone())}}function As(r){switch(r.type){case"ConstantColor":return Cn.fromJSON(r);case"ColorRange":return Yn.fromJSON(r);case"RandomColor":return is.fromJSON(r);case"Gradient":return kn.fromJSON(r);case"RandomColorBetweenGradient":return rs.fromJSON(r);default:return new Cn(new ct(1,1,1,1))}}class ie{constructor(e){this.value=e,this.type="value"}startGen(e){}genValue(e){return this.value}toJSON(){return{type:"ConstantValue",value:this.value}}static fromJSON(e){return new ie(e.value)}clone(){return new ie(this.value)}}class Pn{constructor(e,t){this.a=e,this.b=t,this.indexCount=-1,this.type="value"}startGen(e){this.indexCount=e.length,e.push(Math.random())}genValue(e){return this.indexCount===-1&&this.startGen(e),Bn.lerp(this.a,this.b,e[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(e){return new Pn(e.a,e.b)}clone(){return new Pn(this.a,this.b)}}class hu{constructor(){this.functions=new Array}findFunction(e){let t=0,n=0,i=this.functions.length-1;for(;n+1<i;)if(t=Math.floor((n+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))n=t+1;else return t;for(let s=n;s<=i;s++)if(e>=this.functions[s][1]&&e<=this.getEndX(s))return s;return-1}getStartX(e){return this.functions[e][1]}setStartX(e,t){e>0&&(this.functions[e][1]=t)}getEndX(e){return e+1<this.functions.length?this.functions[e+1][1]:1}setEndX(e,t){e+1<this.functions.length&&(this.functions[e+1][1]=t)}insertFunction(e,t){const n=this.findFunction(e);this.functions.splice(n+1,0,[t,e])}removeFunction(e){return this.functions.splice(e,1)[0][0]}getFunction(e){return this.functions[e][0]}setFunction(e,t){this.functions[e][0]=t}get numOfFunctions(){return this.functions.length}}class Ci extends hu{constructor(e=[[new Mn(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=e}genValue(e,t=0){const n=this.findFunction(t);return n===-1?0:this.functions[n][0].genValue((t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))}toSVG(e,t){if(t<1)return"";let n=["M",0,this.functions[0][0].p[0]].join(" ");for(let i=1/t;i<=1;i+=1/t)n=[n,"L",i*e,this.genValue(void 0,i)].join(" ");return n}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([e,t])=>({function:e.toJSON(),start:t}))}}static fromJSON(e){return new Ci(e.functions.map(t=>[Mn.fromJSON(t.function),t.start]))}clone(){return new Ci(this.functions.map(([e,t])=>[e.clone(),t]))}startGen(e){}}function Q(r){switch(r.type){case"ConstantValue":return ie.fromJSON(r);case"IntervalValue":return Pn.fromJSON(r);case"PiecewiseBezier":return Ci.fromJSON(r);default:return new ie(0)}}class Pi{constructor(){this.indexCount=0,this.type="rotation"}startGen(e){this.indexCount=e.length,e.push(new ne);let t,n,i,s,a,o;do t=Math.random()*2-1,n=Math.random()*2-1,i=t*t+n*n;while(i>1);do s=Math.random()*2-1,a=Math.random()*2-1,o=s*s+a*a;while(o>1);const c=Math.sqrt((1-i)/o);e[this.indexCount].set(t,n,c*s,c*a)}genValue(e,t,n,i){return this.indexCount===-1&&this.startGen(e),t.copy(e[this.indexCount]),t}toJSON(){return{type:"RandomQuat"}}static fromJSON(e){return new Pi}clone(){return new Pi}}class Ei{constructor(e,t){this.axis=e,this.angle=t,this.type="rotation"}startGen(e){this.angle.startGen(e)}genValue(e,t,n,i){return t.setFromAxisAngle(this.axis,this.angle.genValue(e,i)*n)}toJSON(){return{type:"AxisAngle",axis:{x:this.axis.x,y:this.axis.y,z:this.axis.z},angle:this.angle.toJSON()}}static fromJSON(e){return new Ei(new G(e.axis.x,e.axis.y,e.axis.z),Q(e.angle))}clone(){return new Ei(this.axis.clone(),this.angle.clone())}}class ss{constructor(e,t,n,i){this.angleX=e,this.angleY=t,this.angleZ=n,this.type="rotation",this.eular=new Mi(0,0,0,i)}startGen(e){this.angleX.startGen(e),this.angleY.startGen(e),this.angleZ.startGen(e)}genValue(e,t,n,i){return this.eular.set(this.angleX.genValue(e,i)*n,this.angleY.genValue(e,i)*n,this.angleZ.genValue(e,i)*n),t.setFromEuler(this.eular)}toJSON(){return{type:"Euler",angleX:this.angleX.toJSON(),angleY:this.angleY.toJSON(),angleZ:this.angleZ.toJSON(),eulerOrder:this.eular.order}}static fromJSON(e){return new ss(Q(e.angleX),Q(e.angleY),Q(e.angleZ),e.eulerOrder)}clone(){return new ss(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function Na(r){switch(r.type){case"AxisAngle":return Ei.fromJSON(r);case"Euler":return ss.fromJSON(r);case"RandomQuat":return Pi.fromJSON(r);default:return new Pi}}class En{constructor(e,t,n){this.x=e,this.y=t,this.z=n,this.type="vec3function"}startGen(e){this.x.startGen(e),this.y.startGen(e),this.z.startGen(e)}genValue(e,t,n){return t.set(this.x.genValue(e,n),this.y.genValue(e,n),this.z.genValue(e,n))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new En(Q(e.x),Q(e.y),Q(e.z))}clone(){return new En(this.x,this.y,this.z)}}function uu(r){return r.type==="Vector3Function"?En.fromJSON(r):new En(new ie(0),new ie(0),new ie(0))}function mr(r){switch(r.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return Q(r);case"AxisAngle":case"RandomQuat":case"Euler":return Na(r);case"Vector3Function":return uu(r);default:return new ie(0)}}class ki{constructor(e={}){var t,n,i,s,a,o,c;this.type="cone",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.angle=(s=e.angle)!==null&&s!==void 0?s:Math.PI/6,this.mode=(a=e.mode)!==null&&a!==void 0?a:tt.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new ie(1),this.memory=[]}update(e,t){tt.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Bn.lerp(1-this.thickness,1,Math.random()),s=n*this.arc,a=Math.sqrt(i),o=Math.sin(s),c=Math.cos(s);e.position.x=a*c,e.position.y=a*o,e.position.z=0;const l=this.angle*a;e.velocity.set(0,0,Math.cos(l)).addScaledVector(e.position,Math.sin(l)).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius)}toJSON(){return{type:"cone",radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new ki({radius:e.radius,arc:e.arc,thickness:e.thickness,angle:e.angle,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new ki({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ri{constructor(e={}){var t,n,i,s,a,o;this.type="circle",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:tt.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ie(1),this.memory=[]}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Bn.lerp(1-this.thickness,1,Math.random()),s=n*this.arc;e.position.x=Math.cos(s),e.position.y=Math.sin(s),e.position.z=0,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*i)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Ri({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new Ri({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function yr(r,e){return Math.floor(Math.random()*(e-r))+r}const gr=new G(0,1,0),vr=new G(0,0,0),du=new G(1,1,1),Ua=new G(0,0,1);class Ai{constructor(e={}){var t,n,i,s,a,o,c;this.type="donut",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.donutRadius=(s=e.donutRadius)!==null&&s!==void 0?s:this.radius*.2,this.mode=(a=e.mode)!==null&&a!==void 0?a:tt.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new ie(1),this.memory=[],this._m1=new It}update(e,t){tt.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Bn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=i*Math.PI*2,c=Math.sin(a),l=Math.cos(a);e.position.x=this.radius*l,e.position.y=this.radius*c,e.position.z=0,e.velocity.z=this.donutRadius*s*Math.sin(o),e.velocity.x=this.donutRadius*s*Math.cos(o)*l,e.velocity.y=this.donutRadius*s*Math.cos(o)*c,e.position.add(e.velocity),e.velocity.normalize().multiplyScalar(e.startSpeed),e.rotation instanceof ne&&(this._m1.lookAt(vr,e.velocity,gr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"donut",radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Ai({radius:e.radius,arc:e.arc,thickness:e.thickness,donutRadius:e.donutRadius,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new Ai({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Oi{constructor(){this.type="point",this._m1=new It}update(e,t){}initialize(e){const t=Math.random(),n=Math.random(),i=t*Math.PI*2,s=Math.acos(2*n-1),a=Math.cbrt(Math.random()),o=Math.sin(i),c=Math.cos(i),l=Math.sin(s),u=Math.cos(s);e.velocity.x=a*l*c,e.velocity.y=a*l*o,e.velocity.z=a*u,e.velocity.multiplyScalar(e.startSpeed),e.position.setScalar(0),e.rotation instanceof ne&&(this._m1.lookAt(vr,e.position,gr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(e){return new Oi}clone(){return new Oi}}class Zn{constructor(e={}){var t,n,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:tt.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ie(1),this.memory=[],this._m1=new It}update(e,t){tt.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Bn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=Math.acos(2*i-1),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),d=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=d,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof ne&&(this._m1.lookAt(vr,e.position,gr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"sphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Zn({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new Zn({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ii{constructor(e={}){var t,n,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:tt.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ie(1),this.memory=[],this._m1=new It}update(e,t){tt.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ni(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Bn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=Math.acos(i),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),d=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=d,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof ne&&(this._m1.lookAt(vr,e.position,gr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"hemisphere",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new Ii({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Q(e.speed):void 0,spread:e.spread})}clone(){return new Ii({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Bi{constructor(e={}){var t,n,i,s;this.type="grid",this.width=(t=e.width)!==null&&t!==void 0?t:1,this.height=(n=e.height)!==null&&n!==void 0?n:1,this.column=(i=e.column)!==null&&i!==void 0?i:10,this.row=(s=e.row)!==null&&s!==void 0?s:10}initialize(e){const t=Math.floor(Math.random()*this.row),n=Math.floor(Math.random()*this.column);e.position.x=n*this.width/this.column-this.width/2,e.position.y=t*this.height/this.row-this.height/2,e.position.z=0,e.velocity.set(0,0,e.startSpeed)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row}}static fromJSON(e){return new Bi(e)}clone(){return new Bi({width:this.width,height:this.height,column:this.column,row:this.row})}update(e,t){}}const Os={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ri,loadJSON:Ri.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:ki,loadJSON:ki.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ai,loadJSON:Ai.fromJSON},point:{type:"point",params:[],constructor:Oi,loadJSON:Oi.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Zn,loadJSON:Zn.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ii,loadJSON:Ii.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:Bi,loadJSON:Bi.fromJSON}};function pu(r,e){return Os[r.type].loadJSON(r,e)}class zi{constructor(e){this.color=e,this.type="ColorOverLife"}initialize(e){this.color.startGen(e.memory)}update(e,t){this.color.genColor(e.memory,e.color,e.age/e.life),e.color.x*=e.startColor.x,e.color.y*=e.startColor.y,e.color.z*=e.startColor.z,e.color.w*=e.startColor.w}frameUpdate(e){}toJSON(){return{type:this.type,color:this.color.toJSON()}}static fromJSON(e){return new zi(As(e.color))}clone(){return new zi(this.color.clone())}reset(){}}class Ni{constructor(e){this.angularVelocity=e,this.type="RotationOverLife"}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){typeof e.rotation=="number"&&(e.rotation+=t*this.angularVelocity.genValue(e.memory,e.age/e.life))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(e){return new Ni(Q(e.angularVelocity))}frameUpdate(e){}clone(){return new Ni(this.angularVelocity.clone())}reset(){}}class Ui{constructor(e){this.angularVelocity=e,this.type="Rotation3DOverLife",this.tempQuat=new ne,this.tempQuat2=new ne}initialize(e){e.rotation instanceof ne&&(e.angularVelocity=new ne,this.angularVelocity.startGen(e.memory))}update(e,t){e.rotation instanceof ne&&(this.angularVelocity.genValue(e.memory,this.tempQuat,t,e.age/e.life),e.rotation.multiply(this.tempQuat))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(e){return new Ui(Na(e.angularVelocity))}frameUpdate(e){}clone(){return new Ui(this.angularVelocity.clone())}reset(){}}class Di{initialize(e,t){this.ps=t,this.x.startGen(e.memory),this.y.startGen(e.memory),this.z.startGen(e.memory)}constructor(e,t,n){this.x=e,this.y=t,this.z=n,this.type="ForceOverLife",this._temp=new G,this._tempScale=new G,this._tempQ=new ne}update(e,t){this._temp.set(this.x.genValue(e.memory,e.age/e.life),this.y.genValue(e.memory,e.age/e.life),this.z.genValue(e.memory,e.age/e.life)),this.ps.worldSpace?e.velocity.addScaledVector(this._temp,t):(this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ),e.velocity.addScaledVector(this._temp,t))}toJSON(){return{type:this.type,x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new Di(Q(e.x),Q(e.y),Q(e.z))}frameUpdate(e){if(this.ps&&!this.ps.worldSpace){const t=this._temp,n=this._tempQ,i=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,n,i),n.invert(),i.set(1/i.x,1/i.y,1/i.z)}}clone(){return new Di(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class Li{initialize(e){this.size.startGen(e.memory)}constructor(e){this.size=e,this.type="SizeOverLife"}update(e){this.size instanceof En?this.size.genValue(e.memory,e.size,e.age/e.life).multiply(e.startSize):e.size.copy(e.startSize).multiplyScalar(this.size.genValue(e.memory,e.age/e.life))}toJSON(){return{type:this.type,size:this.size.toJSON()}}static fromJSON(e){return new Li(mr(e.size))}frameUpdate(e){}clone(){return new Li(this.size.clone())}reset(){}}class Fi{initialize(e){this.speed.startGen(e.memory)}constructor(e){this.speed=e,this.type="SpeedOverLife"}update(e){e.speedModifier=this.speed.genValue(e.memory,e.age/e.life)}toJSON(){return{type:this.type,speed:this.speed.toJSON()}}static fromJSON(e){return new Fi(Q(e.speed))}frameUpdate(e){}clone(){return new Fi(this.speed.clone())}reset(){}}class Vi{constructor(e){this.frame=e,this.type="FrameOverLife"}initialize(e){this.frame.startGen(e.memory)}update(e,t){this.frame instanceof Ci&&(e.uvTile=this.frame.genValue(e.memory,e.age/e.life))}frameUpdate(e){}toJSON(){return{type:this.type,frame:this.frame.toJSON()}}static fromJSON(e){return new Vi(Q(e.frame))}clone(){return new Vi(this.frame.clone())}reset(){}}class ji{constructor(e,t=new G(0,1,0)){this.orbitSpeed=e,this.axis=t,this.type="OrbitOverLife",this.temp=new G,this.rotation=new ne}initialize(e){this.orbitSpeed.startGen(e.memory)}update(e,t){this.temp.copy(e.position).projectOnVector(this.axis),this.rotation.setFromAxisAngle(this.axis,this.orbitSpeed.genValue(e.memory,e.age/e.life)*t),e.position.sub(this.temp),e.position.applyQuaternion(this.rotation),e.position.add(this.temp)}frameUpdate(e){}toJSON(){return{type:this.type,orbitSpeed:this.orbitSpeed.toJSON(),axis:[this.axis.x,this.axis.y,this.axis.z]}}static fromJSON(e){return new ji(Q(e.orbitSpeed),e.axis?new G(e.axis[0],e.axis[1],e.axis[2]):void 0)}clone(){return new ji(this.orbitSpeed.clone())}reset(){}}class Is{constructor(e){this.data=e,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class fu{constructor(){this.length=0,this.head=this.tail=null}isEmpty(){return this.head===null}clear(){this.length=0,this.head=this.tail=null}front(){return this.head===null?null:this.head.data}back(){return this.tail===null?null:this.tail.data}dequeue(){if(this.head){const e=this.head.data;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,e}}pop(){if(this.tail){const e=this.tail.data;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,e}}queue(e){const t=new Is(e);this.tail||(this.tail=t),this.head&&(this.head.prev=t,t.next=this.head),this.head=t,this.length++}push(e){const t=new Is(e);this.head||(this.head=t),this.tail&&(this.tail.next=t,t.prev=this.tail),this.tail=t,this.length++}insertBefore(e,t){const n=new Is(t);n.next=e,n.prev=e.prev,n.prev!==null&&(n.prev.next=n),n.next.prev=n,e==this.head&&(this.head=n),this.length++}remove(e){if(this.head===null||this.tail===null)return;let t=this.head;for(e===this.head.data&&(this.head=this.head.next),e===this.tail.data&&(this.tail=this.tail.prev);t.next!==null&&t.data!==e;)t=t.next;t.data===e&&(t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.length--)}*values(){let e=this.head;for(;e!==null;)yield e.data,e=e.next}}class mu{constructor(){this.startSpeed=0,this.startColor=new ct,this.startSize=new G(1,1,1),this.position=new G,this.velocity=new G,this.age=0,this.life=1,this.size=new G(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new ct,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class yu{constructor(e,t,n){this.position=e,this.size=t,this.color=n}}class Sr{constructor(){this.startSpeed=0,this.startColor=new ct,this.startSize=new G(1,1,1),this.position=new G,this.velocity=new G,this.age=0,this.life=1,this.size=new G(1,1,1),this.length=100,this.speedModifier=1,this.color=new ct,this.previous=new fu,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new yu(this.position.clone(),this.size.x,this.color.clone())):this.previous.length>0&&this.previous.dequeue();this.previous.length>this.length;)this.previous.dequeue()}get died(){return this.age>=this.life}reset(){this.memory.length=0,this.previous.clear()}}class Ji{initialize(e){this.width.startGen(e.memory)}constructor(e){this.width=e,this.type="WidthOverLength"}update(e){if(e instanceof Sr){const t=e.previous.values();for(let n=0;n<e.previous.length;n++){const i=t.next();i.value.size=this.width.genValue(e.memory,(e.previous.length-n)/e.length)}}}frameUpdate(e){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(e){return new Ji(Q(e.width))}clone(){return new Ji(this.width.clone())}reset(){}}class Gi{constructor(e,t){this.direction=e,this.magnitude=t,this.type="ApplyForce",this.memory={data:[],dataCount:0},this.magnitudeValue=this.magnitude.genValue(this.memory)}initialize(e){}update(e,t){e.velocity.addScaledVector(this.direction,this.magnitudeValue*t)}frameUpdate(e){this.magnitudeValue=this.magnitude.genValue(this.memory)}toJSON(){return{type:this.type,direction:[this.direction.x,this.direction.y,this.direction.z],magnitude:this.magnitude.toJSON()}}static fromJSON(e){var t;return new Gi(new G(e.direction[0],e.direction[1],e.direction[2]),Q((t=e.magnitude)!==null&&t!==void 0?t:e.force))}clone(){return new Gi(this.direction.clone(),this.magnitude.clone())}reset(){}}class Wi{constructor(e,t){this.center=e,this.magnitude=t,this.type="GravityForce",this.temp=new G}initialize(e){}update(e,t){this.temp.copy(this.center).sub(e.position).normalize(),e.velocity.addScaledVector(this.temp,this.magnitude/e.position.distanceToSquared(this.center)*t)}frameUpdate(e){}toJSON(){return{type:this.type,center:[this.center.x,this.center.y,this.center.z],magnitude:this.magnitude}}static fromJSON(e){return new Wi(new G(e.center[0],e.center[1],e.center[2]),e.magnitude)}clone(){return new Wi(this.center.clone(),this.magnitude)}reset(){}}class Hi{constructor(e){this.angle=e,this.type="ChangeEmitDirection",this._temp=new G,this._q=new ne,this.memory={data:[],dataCount:0}}initialize(e){const t=e.velocity.length();t!=0&&(e.velocity.normalize(),e.velocity.x===0&&e.velocity.y===0?this._temp.set(0,e.velocity.z,0):this._temp.set(-e.velocity.y,e.velocity.x,0),this.angle.startGen(this.memory),this._q.setFromAxisAngle(this._temp.normalize(),this.angle.genValue(this.memory)),this._temp.copy(e.velocity),e.velocity.applyQuaternion(this._q),this._q.setFromAxisAngle(this._temp,Math.random()*Math.PI*2),e.velocity.applyQuaternion(this._q),e.velocity.setLength(t))}update(e,t){}frameUpdate(e){}toJSON(){return{type:this.type,angle:this.angle.toJSON()}}static fromJSON(e){return new Hi(Q(e.angle))}clone(){return new Hi(this.angle)}reset(){}}var Nn;(function(r){r[r.Death=0]="Death",r[r.Birth=1]="Birth",r[r.Frame=2]="Frame"})(Nn||(Nn={}));class qi{constructor(e,t,n,i=Nn.Frame,s=1){this.particleSystem=e,this.useVelocityAsBasis=t,this.subParticleSystem=n,this.mode=i,this.emitProbability=s,this.type="EmitSubParticleSystem",this.q_=new ne,this.v_=new G,this.v2_=new G,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(e){}update(e,t){this.mode===Nn.Frame?this.emit(e,t):this.mode===Nn.Birth&&e.age===0?this.emit(e,t):this.mode===Nn.Death&&e.age+t>=e.life&&this.emit(e,t)}emit(e,t){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const n=new It;this.setMatrixFromParticle(n,e),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:n,travelDistance:0,particle:e})}frameUpdate(e){if(this.subParticleSystem)for(let t=0;t<this.subEmissions.length;t++)if(this.subEmissions[t].time>=this.subParticleSystem.system.duration)this.subEmissions[t]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,t--;else{const n=this.subEmissions[t];n.particle&&n.particle.age<n.particle.life?this.setMatrixFromParticle(n.matrix,n.particle):n.particle=void 0,this.subParticleSystem.system.emit(e,n,n.matrix)}}toJSON(){return{type:this.type,subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(e,t){return new qi(t,e.useVelocityAsBasis,e.subParticleSystem,e.mode,e.emitProbability)}clone(){return new qi(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(e,t){let n;if(t.rotation===void 0||this.useVelocityAsBasis)if(t.velocity.x===0&&t.velocity.y===0&&(t.velocity.z===1||t.velocity.z===0))e.set(1,0,0,t.position.x,0,1,0,t.position.y,0,0,1,t.position.z,0,0,0,1);else{this.v_.copy(Ua).cross(t.velocity),this.v2_.copy(t.velocity).cross(this.v_);const i=this.v_.length(),s=this.v2_.length();e.set(this.v_.x/i,this.v2_.x/s,t.velocity.x,t.position.x,this.v_.y/i,this.v2_.y/s,t.velocity.y,t.position.y,this.v_.z/i,this.v2_.z/s,t.velocity.z,t.position.z,0,0,0,1)}else t.rotation instanceof ne?n=t.rotation:(this.q_.setFromAxisAngle(Ua,t.rotation),n=this.q_),e.compose(t.position,n,du);this.particleSystem.worldSpace||e.multiplyMatrices(this.particleSystem.emitter.matrixWorld,e)}}const gu=.5*(Math.sqrt(3)-1),si=(3-Math.sqrt(3))/6,vu=1/3,Dt=1/6,Su=(Math.sqrt(5)-1)/4,Fe=(5-Math.sqrt(5))/20,Be=new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0,1,0,1,-1,0,1,1,0,-1,-1,0,-1,0,1,1,0,-1,1,0,1,-1,0,-1,-1]),Te=new Float32Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);class Da{constructor(e=Math.random){const t=typeof e=="function"?e:xu(e);this.p=bu(t),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let n=0;n<512;n++)this.perm[n]=this.p[n&255],this.permMod12[n]=this.perm[n]%12}noise2D(e,t){const n=this.permMod12,i=this.perm;let s=0,a=0,o=0;const c=(e+t)*gu,l=Math.floor(e+c),u=Math.floor(t+c),d=(l+u)*si,m=l-d,f=u-d,x=e-m,_=t-f;let g,v;x>_?(g=1,v=0):(g=0,v=1);const w=x-g+si,S=_-v+si,T=x-1+2*si,C=_-1+2*si,P=l&255,E=u&255;let O=.5-x*x-_*_;if(O>=0){const B=n[P+i[E]]*3;O*=O,s=O*O*(Be[B]*x+Be[B+1]*_)}let A=.5-w*w-S*S;if(A>=0){const B=n[P+g+i[E+v]]*3;A*=A,a=A*A*(Be[B]*w+Be[B+1]*S)}let R=.5-T*T-C*C;if(R>=0){const B=n[P+1+i[E+1]]*3;R*=R,o=R*R*(Be[B]*T+Be[B+1]*C)}return 70*(s+a+o)}noise3D(e,t,n){const i=this.permMod12,s=this.perm;let a,o,c,l;const u=(e+t+n)*vu,d=Math.floor(e+u),m=Math.floor(t+u),f=Math.floor(n+u),x=(d+m+f)*Dt,_=d-x,g=m-x,v=f-x,w=e-_,S=t-g,T=n-v;let C,P,E,O,A,R;w>=S?S>=T?(C=1,P=0,E=0,O=1,A=1,R=0):w>=T?(C=1,P=0,E=0,O=1,A=0,R=1):(C=0,P=0,E=1,O=1,A=0,R=1):S<T?(C=0,P=0,E=1,O=0,A=1,R=1):w<T?(C=0,P=1,E=0,O=0,A=1,R=1):(C=0,P=1,E=0,O=1,A=1,R=0);const B=w-C+Dt,z=S-P+Dt,U=T-E+Dt,L=w-O+2*Dt,J=S-A+2*Dt,H=T-R+2*Dt,se=w-1+3*Dt,W=S-1+3*Dt,pe=T-1+3*Dt,te=d&255,ue=m&255,oe=f&255;let le=.6-w*w-S*S-T*T;if(le<0)a=0;else{const re=i[te+s[ue+s[oe]]]*3;le*=le,a=le*le*(Be[re]*w+Be[re+1]*S+Be[re+2]*T)}let xe=.6-B*B-z*z-U*U;if(xe<0)o=0;else{const re=i[te+C+s[ue+P+s[oe+E]]]*3;xe*=xe,o=xe*xe*(Be[re]*B+Be[re+1]*z+Be[re+2]*U)}let ge=.6-L*L-J*J-H*H;if(ge<0)c=0;else{const re=i[te+O+s[ue+A+s[oe+R]]]*3;ge*=ge,c=ge*ge*(Be[re]*L+Be[re+1]*J+Be[re+2]*H)}let de=.6-se*se-W*W-pe*pe;if(de<0)l=0;else{const re=i[te+1+s[ue+1+s[oe+1]]]*3;de*=de,l=de*de*(Be[re]*se+Be[re+1]*W+Be[re+2]*pe)}return 32*(a+o+c+l)}noise4D(e,t,n,i){const s=this.perm;let a,o,c,l,u;const d=(e+t+n+i)*Su,m=Math.floor(e+d),f=Math.floor(t+d),x=Math.floor(n+d),_=Math.floor(i+d),g=(m+f+x+_)*Fe,v=m-g,w=f-g,S=x-g,T=_-g,C=e-v,P=t-w,E=n-S,O=i-T;let A=0,R=0,B=0,z=0;C>P?A++:R++,C>E?A++:B++,C>O?A++:z++,P>E?R++:B++,P>O?R++:z++,E>O?B++:z++;const U=A>=3?1:0,L=R>=3?1:0,J=B>=3?1:0,H=z>=3?1:0,se=A>=2?1:0,W=R>=2?1:0,pe=B>=2?1:0,te=z>=2?1:0,ue=A>=1?1:0,oe=R>=1?1:0,le=B>=1?1:0,xe=z>=1?1:0,ge=C-U+Fe,de=P-L+Fe,re=E-J+Fe,Ze=O-H+Fe,Ue=C-se+2*Fe,ke=P-W+2*Fe,lt=E-pe+2*Fe,De=O-te+2*Fe,ve=C-ue+3*Fe,he=P-oe+3*Fe,ft=E-le+3*Fe,Re=O-xe+3*Fe,fe=C-1+4*Fe,rt=P-1+4*Fe,wt=E-1+4*Fe,_t=O-1+4*Fe,st=m&255,Tt=f&255,mt=x&255,yt=_&255;let ht=.6-C*C-P*P-E*E-O*O;if(ht<0)a=0;else{const $=s[st+s[Tt+s[mt+s[yt]]]]%32*4;ht*=ht,a=ht*ht*(Te[$]*C+Te[$+1]*P+Te[$+2]*E+Te[$+3]*O)}let Ae=.6-ge*ge-de*de-re*re-Ze*Ze;if(Ae<0)o=0;else{const $=s[st+U+s[Tt+L+s[mt+J+s[yt+H]]]]%32*4;Ae*=Ae,o=Ae*Ae*(Te[$]*ge+Te[$+1]*de+Te[$+2]*re+Te[$+3]*Ze)}let Ke=.6-Ue*Ue-ke*ke-lt*lt-De*De;if(Ke<0)c=0;else{const $=s[st+se+s[Tt+W+s[mt+pe+s[yt+te]]]]%32*4;Ke*=Ke,c=Ke*Ke*(Te[$]*Ue+Te[$+1]*ke+Te[$+2]*lt+Te[$+3]*De)}let ut=.6-ve*ve-he*he-ft*ft-Re*Re;if(ut<0)l=0;else{const $=s[st+ue+s[Tt+oe+s[mt+le+s[yt+xe]]]]%32*4;ut*=ut,l=ut*ut*(Te[$]*ve+Te[$+1]*he+Te[$+2]*ft+Te[$+3]*Re)}let Qe=.6-fe*fe-rt*rt-wt*wt-_t*_t;if(Qe<0)u=0;else{const $=s[st+1+s[Tt+1+s[mt+1+s[yt+1]]]]%32*4;Qe*=Qe,u=Qe*Qe*(Te[$]*fe+Te[$+1]*rt+Te[$+2]*wt+Te[$+3]*_t)}return 27*(a+o+c+l+u)}}function bu(r){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let t=0;t<255;t++){const n=t+~~(r()*(256-t)),i=e[t];e[t]=e[n],e[n]=i}return e}function xu(r){let e=0,t=0,n=0,i=1;const s=wu();return e=s(" "),t=s(" "),n=s(" "),e-=s(r),e<0&&(e+=1),t-=s(r),t<0&&(t+=1),n-=s(r),n<0&&(n+=1),function(){const a=2091639*e+i*23283064365386963e-26;return e=t,t=n,n=a-(i=a|0)}}function wu(){let r=4022871197;return function(e){e=e.toString();for(let t=0;t<e.length;t++){r+=e.charCodeAt(t);let n=.02519603282416938*r;r=n>>>0,n-=r,n*=r,r=n>>>0,n-=r,r+=n*4294967296}return(r>>>0)*23283064365386963e-26}}class Xi{constructor(e,t,n,i){this.scale=e,this.octaves=t,this.velocityMultiplier=n,this.timeScale=i,this.type="TurbulenceField",this.generator=new Da,this.timeOffset=new G,this.temp=new G,this.temp2=new G,this.timeOffset.x=Math.random()/this.scale.x*this.timeScale.x,this.timeOffset.y=Math.random()/this.scale.y*this.timeScale.y,this.timeOffset.z=Math.random()/this.scale.z*this.timeScale.z}initialize(e){}update(e,t){const n=e.position.x/this.scale.x,i=e.position.y/this.scale.y,s=e.position.z/this.scale.z;this.temp.set(0,0,0);let a=1;for(let o=0;o<this.octaves;o++)this.temp2.set(this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.x*a)/a,this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.y*a)/a,this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.z*a)/a),this.temp.add(this.temp2),a*=2;this.temp.multiply(this.velocityMultiplier),e.velocity.addScaledVector(this.temp,t)}toJSON(){return{type:this.type,scale:[this.scale.x,this.scale.y,this.scale.z],octaves:this.octaves,velocityMultiplier:[this.velocityMultiplier.x,this.velocityMultiplier.y,this.velocityMultiplier.z],timeScale:[this.timeScale.x,this.timeScale.y,this.timeScale.z]}}frameUpdate(e){this.timeOffset.x+=e*this.timeScale.x,this.timeOffset.y+=e*this.timeScale.y,this.timeOffset.z+=e*this.timeScale.z}static fromJSON(e){return new Xi(new G(e.scale[0],e.scale[1],e.scale[2]),e.octaves,new G(e.velocityMultiplier[0],e.velocityMultiplier[1],e.velocityMultiplier[2]),new G(e.timeScale[0],e.timeScale[1],e.timeScale[2]))}clone(){return new Xi(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const Lt=[],Bs=new G,zs=new ne;class Yi{constructor(e,t,n=new ie(1),i=new ie(0)){if(this.frequency=e,this.power=t,this.positionAmount=n,this.rotationAmount=i,this.type="Noise",this.duration=0,Lt.length===0)for(let s=0;s<100;s++)Lt.push(new Da)}initialize(e){e.lastPosNoise=new G,typeof e.rotation=="number"?e.lastRotNoise=0:e.lastRotNoise=new ne,e.generatorIndex=[yr(0,100),yr(0,100),yr(0,100),yr(0,100)],this.positionAmount.startGen(e.memory),this.rotationAmount.startGen(e.memory),this.frequency.startGen(e.memory),this.power.startGen(e.memory)}update(e,t){let n=this.frequency.genValue(e.memory,e.age/e.life),i=this.power.genValue(e.memory,e.age/e.life),s=this.positionAmount.genValue(e.memory,e.age/e.life),a=this.rotationAmount.genValue(e.memory,e.age/e.life);s>0&&e.lastPosNoise!==void 0&&(e.position.sub(e.lastPosNoise),Bs.set(Lt[e.generatorIndex[0]].noise2D(0,e.age*n)*i*s,Lt[e.generatorIndex[1]].noise2D(0,e.age*n)*i*s,Lt[e.generatorIndex[2]].noise2D(0,e.age*n)*i*s),e.position.add(Bs),e.lastPosNoise.copy(Bs)),a>0&&e.lastRotNoise!==void 0&&(typeof e.rotation=="number"?(e.rotation-=e.lastRotNoise,e.rotation+=Lt[e.generatorIndex[3]].noise2D(0,e.age*n)*Math.PI*i*a):(e.lastRotNoise.invert(),e.rotation.multiply(e.lastRotNoise),zs.set(Lt[e.generatorIndex[0]].noise2D(0,e.age*n)*i*a,Lt[e.generatorIndex[1]].noise2D(0,e.age*n)*i*a,Lt[e.generatorIndex[2]].noise2D(0,e.age*n)*i*a,Lt[e.generatorIndex[3]].noise2D(0,e.age*n)*i*a).normalize(),e.rotation.multiply(zs),e.lastRotNoise.copy(zs)))}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON()}}frameUpdate(e){this.duration+=e}static fromJSON(e){return new Yi(Q(e.frequency),Q(e.power),Q(e.positionAmount),Q(e.rotationAmount))}clone(){return new Yi(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Zi{constructor(e,t){this.color=e,this.speedRange=t,this.type="ColorBySpeed"}initialize(e){this.color.startGen(e.memory)}update(e,t){const n=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(e.memory,e.color,n),e.color.x*=e.startColor.x,e.color.y*=e.startColor.y,e.color.z*=e.startColor.z,e.color.w*=e.startColor.w}frameUpdate(e){}toJSON(){return{type:this.type,color:this.color.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Zi(As(e.color),Pn.fromJSON(e.speedRange))}clone(){return new Zi(this.color.clone(),this.speedRange.clone())}reset(){}}class Ki{initialize(e){this.size.startGen(e.memory)}constructor(e,t){this.size=e,this.speedRange=t,this.type="SizeBySpeed"}update(e){const t=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.size instanceof En?this.size.genValue(e.memory,e.size,t).multiply(e.startSize):e.size.copy(e.startSize).multiplyScalar(this.size.genValue(e.memory,t))}toJSON(){return{type:this.type,size:this.size.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Ki(mr(e.size),Pn.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Ki(this.size.clone(),this.speedRange.clone())}reset(){}}class Qi{constructor(e,t){this.angularVelocity=e,this.speedRange=t,this.type="RotationBySpeed",this.tempQuat=new ne}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){if(typeof e.rotation=="number"){const n=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);e.rotation+=t*this.angularVelocity.genValue(e.memory,n)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Qi(Q(e.angularVelocity),Pn.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Qi(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class $i{initialize(e){this.speed.startGen(e.memory)}constructor(e,t){this.speed=e,this.dampen=t,this.type="LimitSpeedOverLife"}update(e,t){let n=e.velocity.length(),i=this.speed.genValue(e.memory,e.age/e.life);if(n>i){const s=(n-i)/n;e.velocity.multiplyScalar(1-s*this.dampen*t*20)}}toJSON(){return{type:this.type,speed:this.speed.toJSON(),dampen:this.dampen}}static fromJSON(e){return new $i(Q(e.speed),e.dampen)}frameUpdate(e){}clone(){return new $i(this.speed.clone(),this.dampen)}reset(){}}const br={ApplyForce:{type:"ApplyForce",constructor:Gi,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Gi.fromJSON},Noise:{type:"Noise",constructor:Yi,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Yi.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Xi,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Xi.fromJSON},GravityForce:{type:"GravityForce",constructor:Wi,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:Wi.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:zi,params:[["color",["colorFunc"]]],loadJSON:zi.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Ni,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Ni.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Ui,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Ui.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Li,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Li.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:Zi,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:Zi.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Qi,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Qi.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:Ki,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:Ki.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Fi,params:[["speed",["value","valueFunc"]]],loadJSON:Fi.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:Vi,params:[["frame",["value","valueFunc"]]],loadJSON:Vi.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:Di,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:Di.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:ji,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:ji.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Ji,params:[["width",["value","valueFunc"]]],loadJSON:Ji.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:Hi,params:[["angle",["value"]]],loadJSON:Hi.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:qi,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:qi.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:$i,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:$i.fromJSON}};function _u(r,e){return br[r.type]?br[r.type].loadJSON(r,e):null}const Tu=[];function Mu(r){if(!Tu.find(e=>e.id===r.id)){for(const e of r.emitterShapes)Os[e.type]||(Os[e.type]=e);for(const e of r.behaviors)br[e.type]||(br[e.type]=e)}}class er{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new mn;this._triangleIndexToArea.length=0;let n=0;if(!e.getIndex())return;const i=e.getIndex().array,s=i.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),i[a*3],i[a*3+1],i[a*3+2]),n+=t.getArea(),this._triangleIndexToArea.push(n);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new q,this._tempB=new q,this._tempC=new q,e&&(this.geometry=e)}initialize(e){const t=this._geometry;if(!t||t.getIndex()===null){e.position.set(0,0,0),e.velocity.set(0,0,1).multiplyScalar(e.startSpeed);return}const n=this._triangleIndexToArea.length-1;let i=0,s=n;const a=Math.random()*this._triangleIndexToArea[n];for(;i+1<s;){const f=Math.floor((i+s)/2);a<this._triangleIndexToArea[f]?s=f:i=f}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=t.getIndex().array[i*3],u=t.getIndex().array[i*3+1],d=t.getIndex().array[i*3+2],m=t.getAttribute("position");this._tempA.fromBufferAttribute(m,l),this._tempB.fromBufferAttribute(m,u),this._tempC.fromBufferAttribute(m,d),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,o).addScaledVector(this._tempC,c),e.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),e.velocity.copy(this._tempA).normalize().multiplyScalar(e.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(e,t){return new er(t.geometries[e.geometry])}clone(){return new er(this._geometry)}update(e,t){}}const Cu={id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:er,loadJSON:er.fromJSON}],behaviors:[]};var Pu=`
2
2
  #ifdef SOFT_PARTICLES
3
3
 
4
4
  /* #ifdef LOGDEPTH
@@ -20,7 +20,7 @@ import{Object3D as na,PlaneGeometry as ia,Layers as cr,MeshBasicMaterial as ra,D
20
20
 
21
21
  //gl_FragColor = vec4(softParticlesFade , 0, 0, 1);
22
22
  #endif
23
- `,Ch=`
23
+ `,Eu=`
24
24
  #ifdef SOFT_PARTICLES
25
25
 
26
26
  uniform sampler2D depthTexture;
@@ -42,17 +42,17 @@ import{Object3D as na,PlaneGeometry as ia,Layers as cr,MeshBasicMaterial as ra,D
42
42
  }
43
43
 
44
44
  #endif
45
- `,Ph=`
45
+ `,ku=`
46
46
  #ifdef SOFT_PARTICLES
47
47
  varying vec4 projPosition;
48
48
  varying float linearDepth;
49
49
  #endif
50
- `,Eh=`
50
+ `,Ru=`
51
51
  #ifdef SOFT_PARTICLES
52
52
  projPosition = gl_Position;
53
53
  linearDepth = -mvPosition.z;
54
54
  #endif
55
- `,kh=`
55
+ `,Au=`
56
56
  #ifdef USE_MAP
57
57
  vec4 texelColor = texture2D( map, vUv);
58
58
  #ifdef TILE_BLEND
@@ -60,7 +60,7 @@ import{Object3D as na,PlaneGeometry as ia,Layers as cr,MeshBasicMaterial as ra,D
60
60
  #endif
61
61
  diffuseColor *= texelColor;
62
62
  #endif
63
- `,Rh=`
63
+ `,Ou=`
64
64
  #if defined( USE_UV ) || defined( USE_ANISOTROPY )
65
65
 
66
66
  varying vec2 vUv;
@@ -211,7 +211,7 @@ import{Object3D as na,PlaneGeometry as ia,Layers as cr,MeshBasicMaterial as ra,D
211
211
  varying vec2 vThicknessMapUv;
212
212
 
213
213
  #endif
214
- `,Ah=`
214
+ `,Iu=`
215
215
  #ifdef UV_TILE
216
216
  attribute float uvTile;
217
217
  uniform vec2 tileCount;
@@ -381,7 +381,7 @@ import{Object3D as na,PlaneGeometry as ia,Layers as cr,MeshBasicMaterial as ra,D
381
381
  varying vec2 vThicknessMapUv;
382
382
 
383
383
  #endif
384
- `,Oh=`
384
+ `,Bu=`
385
385
  #ifdef UV_TILE
386
386
  mat3 tileTransform = makeTileTransform(floor(uvTile));
387
387
  #ifdef TILE_BLEND
@@ -519,7 +519,7 @@ vThicknessMapUv = ( tileTransform * thicknessMapTransform * vec3( THICKNESSMAP_U
519
519
 
520
520
  #endif
521
521
 
522
- `;const on=iu;function Ih(){on.tile_pars_vertex=Ah,on.tile_vertex=Oh,on.tile_pars_fragment=Rh,on.tile_fragment=kh,on.soft_pars_vertex=Ph,on.soft_vertex=Eh,on.soft_pars_fragment=Ch,on.soft_fragment=Mh}class Bh extends na{constructor(e){super(),this.type="ParticleEmitter",this.system=e}clone(){const e=this.system.clone();return e.emitter.copy(this,!0),e.emitter}dispose(){}extractFromCache(e){const t=[];for(const n in e){const i=e[n];delete i.metadata,t.push(i)}return t}toJSON(e,t={}){const n=this.children;this.children=this.children.filter(s=>s.type!=="ParticleSystemPreview");const i=super.toJSON(e);return this.children=n,this.system!==null&&(i.object.ps=this.system.toJSON(e,t)),i}}var V;(function(r){r[r.BillBoard=0]="BillBoard",r[r.StretchedBillBoard=1]="StretchedBillBoard",r[r.Mesh=2]="Mesh",r[r.Trail=3]="Trail",r[r.HorizontalBillBoard=4]="HorizontalBillBoard",r[r.VerticalBillBoard=5]="VerticalBillBoard"})(V||(V={}));class La extends lr{constructor(e){super(),this.type="VFXBatch",this.maxParticles=1e3,this.systems=new Set;const t=new cr;t.mask=e.layers.mask;const n=e.material.clone();n.defines={},Object.assign(n.defines,e.material.defines),this.settings={instancingGeometry:e.instancingGeometry,renderMode:e.renderMode,renderOrder:e.renderOrder,material:n,uTileCount:e.uTileCount,vTileCount:e.vTileCount,blendTiles:e.blendTiles,softParticles:e.softParticles,softNearFade:e.softNearFade,softFarFade:e.softFarFade,layers:t},this.frustumCulled=!1,this.renderOrder=this.settings.renderOrder}addSystem(e){this.systems.add(e)}removeSystem(e){this.systems.delete(e)}applyDepthTexture(e){const t=this.material.uniforms.depthTexture;t&&t.value!==e&&(t.value=e,this.material.needsUpdate=!0)}}const zh=new G(0,0,1),zs=new ie,Nh=new G,Uh=new G;new G;const Fa=60,Dh=new ia(1,1,1,1);class ss{set time(e){this.emissionState.time=e}get time(){return this.emissionState.time}get layers(){return this.rendererSettings.layers}get texture(){return this.rendererSettings.material.map}set texture(e){this.rendererSettings.material.map=e,this.neededToUpdateRender=!0}get material(){return this.rendererSettings.material}set material(e){this.rendererSettings.material=e,this.neededToUpdateRender=!0}get uTileCount(){return this.rendererSettings.uTileCount}set uTileCount(e){this.rendererSettings.uTileCount=e,this.neededToUpdateRender=!0}get vTileCount(){return this.rendererSettings.vTileCount}set vTileCount(e){this.rendererSettings.vTileCount=e,this.neededToUpdateRender=!0}get blendTiles(){return this.rendererSettings.blendTiles}set blendTiles(e){this.rendererSettings.blendTiles=e,this.neededToUpdateRender=!0}get softParticles(){return this.rendererSettings.softParticles}set softParticles(e){this.rendererSettings.softParticles=e,this.neededToUpdateRender=!0}get softNearFade(){return this.rendererSettings.softNearFade}set softNearFade(e){this.rendererSettings.softNearFade=e,this.neededToUpdateRender=!0}get softFarFade(){return this.rendererSettings.softFarFade}set softFarFade(e){this.rendererSettings.softFarFade=e,this.neededToUpdateRender=!0}get instancingGeometry(){return this.rendererSettings.instancingGeometry}set instancingGeometry(e){this.restart(),this.particles.length=0,this.rendererSettings.instancingGeometry=e,this.neededToUpdateRender=!0}get renderMode(){return this.rendererSettings.renderMode}set renderMode(e){if((this.rendererSettings.renderMode!=V.Trail&&e===V.Trail||this.rendererSettings.renderMode==V.Trail&&e!==V.Trail)&&(this.restart(),this.particles.length=0),this.rendererSettings.renderMode!==e)switch(e){case V.Trail:this.rendererEmitterSettings={startLength:new te(30),followLocalOrigin:!1};break;case V.Mesh:this.rendererEmitterSettings={geometry:new ia(1,1)},this.startRotation=new Ei(new G(0,1,0),new te(0));break;case V.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2},this.rendererSettings.renderMode===V.Mesh&&(this.startRotation=new te(0));break;case V.BillBoard:case V.VerticalBillBoard:case V.HorizontalBillBoard:this.rendererEmitterSettings={},this.rendererSettings.renderMode===V.Mesh&&(this.startRotation=new te(0));break}this.rendererSettings.renderMode=e,this.neededToUpdateRender=!0}get renderOrder(){return this.rendererSettings.renderOrder}set renderOrder(e){this.rendererSettings.renderOrder=e,this.neededToUpdateRender=!0}get blending(){return this.rendererSettings.material.blending}set blending(e){this.rendererSettings.material.blending=e,this.neededToUpdateRender=!0}constructor(e){var t,n,i,s,a,o,c,l,u,d,f,m,x,_,g,v,w,S,T,M,P,E,O,A,R,B;if(this.temp=new G,this.travelDistance=0,this.normalMatrix=new Vt,this.memory=[],this.listeners={},this.firstTimeUpdate=!0,this.autoDestroy=e.autoDestroy===void 0?!1:e.autoDestroy,this.duration=(t=e.duration)!==null&&t!==void 0?t:1,this.looping=e.looping===void 0?!0:e.looping,this.prewarm=e.prewarm===void 0?!1:e.prewarm,this.startLife=(n=e.startLife)!==null&&n!==void 0?n:new te(5),this.startSpeed=(i=e.startSpeed)!==null&&i!==void 0?i:new te(0),this.startRotation=(s=e.startRotation)!==null&&s!==void 0?s:new te(0),this.startSize=(a=e.startSize)!==null&&a!==void 0?a:new te(1),this.startColor=(o=e.startColor)!==null&&o!==void 0?o:new Cn(new ct(1,1,1,1)),this.emissionOverTime=(c=e.emissionOverTime)!==null&&c!==void 0?c:new te(10),this.emissionOverDistance=(l=e.emissionOverDistance)!==null&&l!==void 0?l:new te(0),this.emissionBursts=(u=e.emissionBursts)!==null&&u!==void 0?u:[],this.onlyUsedByOther=(d=e.onlyUsedByOther)!==null&&d!==void 0?d:!1,this.emitterShape=(f=e.shape)!==null&&f!==void 0?f:new Zn,this.behaviors=(m=e.behaviors)!==null&&m!==void 0?m:new Array,this.worldSpace=(x=e.worldSpace)!==null&&x!==void 0?x:!1,this.rendererEmitterSettings=(_=e.rendererEmitterSettings)!==null&&_!==void 0?_:{},e.renderMode===V.StretchedBillBoard){const I=this.rendererEmitterSettings;e.speedFactor!==void 0&&(I.speedFactor=e.speedFactor),I.speedFactor=(g=I.speedFactor)!==null&&g!==void 0?g:0,I.lengthFactor=(v=I.lengthFactor)!==null&&v!==void 0?v:0}this.rendererSettings={instancingGeometry:(w=e.instancingGeometry)!==null&&w!==void 0?w:Dh,renderMode:(S=e.renderMode)!==null&&S!==void 0?S:V.BillBoard,renderOrder:(T=e.renderOrder)!==null&&T!==void 0?T:0,material:e.material,uTileCount:(M=e.uTileCount)!==null&&M!==void 0?M:1,vTileCount:(P=e.vTileCount)!==null&&P!==void 0?P:1,blendTiles:(E=e.blendTiles)!==null&&E!==void 0?E:!1,softParticles:(O=e.softParticles)!==null&&O!==void 0?O:!1,softNearFade:(A=e.softNearFade)!==null&&A!==void 0?A:0,softFarFade:(R=e.softFarFade)!==null&&R!==void 0?R:0,layers:(B=e.layers)!==null&&B!==void 0?B:new cr},this.neededToUpdateRender=!0,this.particles=new Array,this.startTileIndex=e.startTileIndex||new te(0),this.emitter=new Bh(this),this.paused=!1,this.particleNum=0,this.emissionState={isBursting:!1,burstParticleIndex:0,burstParticleCount:0,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,travelDistance:0},this.emissionBursts.forEach(I=>I.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1}pause(){this.paused=!0}play(){this.paused=!1}stop(){this.restart(),this.pause()}spawn(e,t,n){zs.setFromRotationMatrix(n);const i=Nh,s=zs,a=Uh;n.decompose(i,s,a);for(let o=0;o<e;o++){for(t.burstParticleIndex=o,this.particleNum++;this.particles.length<this.particleNum;)this.rendererSettings.renderMode===V.Trail?this.particles.push(new Sr):this.particles.push(new fh);const c=this.particles[this.particleNum-1];if(c.reset(),c.speedModifier=1,this.startColor.startGen(c.memory),this.startColor.genColor(c.memory,c.startColor,this.emissionState.time),c.color.copy(c.startColor),this.startSpeed.startGen(c.memory),c.startSpeed=this.startSpeed.genValue(c.memory,t.time/this.duration),this.startLife.startGen(c.memory),c.life=this.startLife.genValue(c.memory,t.time/this.duration),c.age=0,this.startSize.startGen(c.memory),this.startSize.type==="vec3function")this.startSize.genValue(c.memory,c.startSize,t.time/this.duration);else{const l=this.startSize.genValue(c.memory,t.time/this.duration);c.startSize.set(l,l,l)}if(this.startTileIndex.startGen(c.memory),c.uvTile=this.startTileIndex.genValue(c.memory),c.size.copy(c.startSize),this.rendererSettings.renderMode===V.Mesh||this.rendererSettings.renderMode===V.BillBoard||this.rendererSettings.renderMode===V.VerticalBillBoard||this.rendererSettings.renderMode===V.HorizontalBillBoard||this.rendererSettings.renderMode===V.StretchedBillBoard){const l=c;this.startRotation.startGen(c.memory),this.rendererSettings.renderMode===V.Mesh?(l.rotation instanceof ie||(l.rotation=new ie),this.startRotation.type==="rotation"?this.startRotation.genValue(c.memory,l.rotation,1,t.time/this.duration):l.rotation.setFromAxisAngle(zh,this.startRotation.genValue(l.memory,t.time/this.duration))):this.startRotation.type==="rotation"?l.rotation=0:l.rotation=this.startRotation.genValue(l.memory,t.time/this.duration)}else if(this.rendererSettings.renderMode===V.Trail){const l=c;this.rendererEmitterSettings.startLength.startGen(l.memory),l.length=this.rendererEmitterSettings.startLength.genValue(l.memory,t.time/this.duration)}if(this.emitterShape.initialize(c,t),this.rendererSettings.renderMode===V.Trail&&this.rendererEmitterSettings.followLocalOrigin){const l=c;l.localPosition=new G().copy(l.position)}this.worldSpace?(c.position.applyMatrix4(n),c.startSize.multiply(a).abs(),c.size.copy(c.startSize),c.velocity.multiply(a).applyMatrix3(this.normalMatrix),c.rotation&&c.rotation instanceof ie&&c.rotation.multiplyQuaternions(zs,c.rotation)):this.onlyUsedByOther&&(c.parentMatrix=n);for(let l=0;l<this.behaviors.length;l++)this.behaviors[l].initialize(c,this)}}endEmit(){this.emitEnded=!0,this.autoDestroy&&(this.markForDestroy=!0),this.fire({type:"emitEnd",particleSystem:this})}dispose(){this._renderer&&this._renderer.deleteSystem(this),this.emitter.dispose(),this.emitter.parent&&this.emitter.parent.remove(this.emitter),this.fire({type:"destroy",particleSystem:this})}restart(){this.memory.length=0,this.paused=!1,this.particleNum=0,this.emissionState.isBursting=!1,this.emissionState.burstIndex=0,this.emissionState.burstWaveIndex=0,this.emissionState.time=0,this.emissionState.waitEmiting=0,this.behaviors.forEach(e=>{e.reset()}),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1,this.emissionBursts.forEach(e=>e.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory)}update(e){if(this.paused)return;let t=this.emitter;for(;t.parent;)t=t.parent;if(t.type!=="Scene"){this.dispose();return}if(this.firstTimeUpdate&&(this.firstTimeUpdate=!1,this.emitter.updateWorldMatrix(!0,!1)),this.emitEnded&&this.particleNum===0){this.markForDestroy&&this.emitter.parent&&this.dispose();return}if(this.looping&&this.prewarm&&!this.prewarmed){this.prewarmed=!0;for(let n=0;n<this.duration*Fa;n++)this.update(1/Fa)}e>.1&&(e=.1),this.neededToUpdateRender&&(this._renderer&&this._renderer.updateSystem(this),this.neededToUpdateRender=!1),this.onlyUsedByOther||this.emit(e,this.emissionState,this.emitter.matrixWorld),this.emitterShape.update(this,e);for(let n=0;n<this.behaviors.length;n++){this.behaviors[n].frameUpdate(e);for(let i=0;i<this.particleNum;i++)this.particles[i].died||this.behaviors[n].update(this.particles[i],e)}for(let n=0;n<this.particleNum;n++)this.rendererEmitterSettings.followLocalOrigin&&this.particles[n].localPosition?(this.particles[n].position.copy(this.particles[n].localPosition),this.particles[n].parentMatrix?this.particles[n].position.applyMatrix4(this.particles[n].parentMatrix):this.particles[n].position.applyMatrix4(this.emitter.matrixWorld)):this.particles[n].position.addScaledVector(this.particles[n].velocity,e*this.particles[n].speedModifier),this.particles[n].age+=e;if(this.rendererSettings.renderMode===V.Trail)for(let n=0;n<this.particleNum;n++)this.particles[n].update();for(let n=0;n<this.particleNum;n++){const i=this.particles[n];i.died&&(!(i instanceof Sr)||i.previous.length===0)&&(this.particles[n]=this.particles[this.particleNum-1],this.particles[this.particleNum-1]=i,this.particleNum--,n--,this.fire({type:"particleDied",particleSystem:this,particle:i}))}}emit(e,t,n){t.time>this.duration&&(this.looping?(t.time-=this.duration,t.burstIndex=0,this.behaviors.forEach(s=>{s.reset()})):!this.emitEnded&&!this.onlyUsedByOther&&this.endEmit()),this.normalMatrix.getNormalMatrix(n);const i=Math.ceil(t.waitEmiting);for(this.spawn(i,t,n),t.waitEmiting-=i;t.burstIndex<this.emissionBursts.length&&this.emissionBursts[t.burstIndex].time<=t.time;){if(Math.random()<this.emissionBursts[t.burstIndex].probability){const s=this.emissionBursts[t.burstIndex].count.genValue(this.memory,this.time);t.isBursting=!0,t.burstParticleCount=s,this.spawn(s,t,n),t.isBursting=!1}t.burstIndex++}if(!this.emitEnded&&(t.waitEmiting+=e*this.emissionOverTime.genValue(this.memory,t.time/this.duration),t.previousWorldPos!=null)){this.temp.set(n.elements[12],n.elements[13],n.elements[14]),t.travelDistance+=t.previousWorldPos.distanceTo(this.temp);const s=this.emissionOverDistance.genValue(this.memory,t.time/this.duration);if(t.travelDistance*s>0){const a=Math.floor(t.travelDistance*s);t.travelDistance-=a/s,t.waitEmiting+=a}}t.previousWorldPos===void 0&&(t.previousWorldPos=new G),t.previousWorldPos.set(n.elements[12],n.elements[13],n.elements[14]),t.time+=e}toJSON(e,t={}){var n;if((e===void 0||typeof e=="string")&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}}),e.materials[this.rendererSettings.material.uuid]=this.rendererSettings.material.toJSON(e),t.useUrlForImage&&((n=this.texture)===null||n===void 0?void 0:n.source)!==void 0){const a=this.texture.source;e.images[a.uuid]={uuid:a.uuid,url:this.texture.image.url}}let i;this.renderMode===V.Trail?i={startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===V.Mesh?i={}:this.renderMode===V.StretchedBillBoard?i={speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:i={};const s=this.rendererSettings.instancingGeometry;return e.geometries&&!e.geometries[s.uuid]&&(e.geometries[s.uuid]=s.toJSON()),{version:"3.0",autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,shape:this.emitterShape.toJSON(),startLife:this.startLife.toJSON(),startSpeed:this.startSpeed.toJSON(),startRotation:this.startRotation.toJSON(),startSize:this.startSize.toJSON(),startColor:this.startColor.toJSON(),emissionOverTime:this.emissionOverTime.toJSON(),emissionOverDistance:this.emissionOverDistance.toJSON(),emissionBursts:this.emissionBursts.map(a=>({time:a.time,count:a.count.toJSON(),probability:a.probability,interval:a.interval,cycle:a.cycle})),onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry.uuid,renderOrder:this.renderOrder,renderMode:this.renderMode,rendererEmitterSettings:i,material:this.rendererSettings.material.uuid,layers:this.layers.mask,startTileIndex:this.startTileIndex.toJSON(),uTileCount:this.uTileCount,vTileCount:this.vTileCount,blendTiles:this.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,behaviors:this.behaviors.map(a=>a.toJSON()),worldSpace:this.worldSpace}}static fromJSON(e,t,n){var i,s;const a=dh(e.shape,t);let o;if(e.renderMode===V.Trail){const u=e.rendererEmitterSettings;o={startLength:u.startLength!=null?Q(u.startLength):new te(30),followLocalOrigin:u.followLocalOrigin}}else e.renderMode===V.Mesh?o={}:e.renderMode===V.StretchedBillBoard?(o=e.rendererEmitterSettings,e.speedFactor!=null&&(o.speedFactor=e.speedFactor)):o={};const c=new cr;e.layers&&(c.mask=e.layers);const l=new ss({autoDestroy:e.autoDestroy,looping:e.looping,prewarm:e.prewarm,duration:e.duration,shape:a,startLife:Q(e.startLife),startSpeed:Q(e.startSpeed),startRotation:mr(e.startRotation),startSize:mr(e.startSize),startColor:Rs(e.startColor),emissionOverTime:Q(e.emissionOverTime),emissionOverDistance:Q(e.emissionOverDistance),emissionBursts:(i=e.emissionBursts)===null||i===void 0?void 0:i.map(u=>{var d,f,m;return{time:u.time,count:typeof u.count=="number"?new te(u.count):Q(u.count),probability:(d=u.probability)!==null&&d!==void 0?d:1,interval:(f=u.interval)!==null&&f!==void 0?f:.1,cycle:(m=u.cycle)!==null&&m!==void 0?m:1}}),onlyUsedByOther:e.onlyUsedByOther,instancingGeometry:t.geometries[e.instancingGeometry],renderMode:e.renderMode,rendererEmitterSettings:o,renderOrder:e.renderOrder,layers:c,material:e.material?t.materials[e.material]:e.texture?new ra({map:t.textures[e.texture],transparent:(s=e.transparent)!==null&&s!==void 0?s:!0,blending:e.blending,side:Ss}):new ra({color:16777215,transparent:!0,blending:sa,side:Ss}),startTileIndex:typeof e.startTileIndex=="number"?new te(e.startTileIndex):Q(e.startTileIndex),uTileCount:e.uTileCount,vTileCount:e.vTileCount,blendTiles:e.blendTiles,softParticles:e.softParticles,softFarFade:e.softFarFade,softNearFade:e.softNearFade,behaviors:[],worldSpace:e.worldSpace});return l.behaviors=e.behaviors.map(u=>{const d=wh(u,l);return d.type==="EmitSubParticleSystem"&&(n[u.subParticleSystem]=d),d}),l}addBehavior(e){this.behaviors.push(e)}getRendererSettings(){return this.rendererSettings}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeAllEventListeners(e){this.listeners[e]&&(this.listeners[e]=[])}removeEventListener(e,t){if(this.listeners[e]){const n=this.listeners[e].indexOf(t);n!==-1&&this.listeners[e].splice(n,1)}}fire(e){this.listeners[e.type]&&this.listeners[e.type].forEach(t=>t(e))}clone(){const e=[];for(const s of this.emissionBursts){const a={};Object.assign(a,s),e.push(a)}const t=[];for(const s of this.behaviors)t.push(s.clone());let n;this.renderMode===V.Trail?n={startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===V.StretchedBillBoard?n={lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:n={};const i=new cr;return i.mask=this.layers.mask,new ss({autoDestroy:this.autoDestroy,looping:this.looping,duration:this.duration,shape:this.emitterShape.clone(),startLife:this.startLife.clone(),startSpeed:this.startSpeed.clone(),startRotation:this.startRotation.clone(),startSize:this.startSize.clone(),startColor:this.startColor.clone(),emissionOverTime:this.emissionOverTime.clone(),emissionOverDistance:this.emissionOverDistance.clone(),emissionBursts:e,onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry,renderMode:this.renderMode,renderOrder:this.renderOrder,rendererEmitterSettings:n,material:this.rendererSettings.material,startTileIndex:this.startTileIndex,uTileCount:this.uTileCount,vTileCount:this.vTileCount,blendTiles:this.blendTiles,softParticles:this.softParticles,softFarFade:this.softFarFade,softNearFade:this.softNearFade,behaviors:t,worldSpace:this.worldSpace,layers:i})}}var Ns=`
522
+ `;const on=rh;function zu(){on.tile_pars_vertex=Iu,on.tile_vertex=Bu,on.tile_pars_fragment=Ou,on.tile_fragment=Au,on.soft_pars_vertex=ku,on.soft_vertex=Ru,on.soft_pars_fragment=Eu,on.soft_fragment=Pu}class Nu extends ia{constructor(e){super(),this.type="ParticleEmitter",this.system=e}clone(){const e=this.system.clone();return e.emitter.copy(this,!0),e.emitter}dispose(){}extractFromCache(e){const t=[];for(const n in e){const i=e[n];delete i.metadata,t.push(i)}return t}toJSON(e,t={}){const n=this.children;this.children=this.children.filter(s=>s.type!=="ParticleSystemPreview");const i=super.toJSON(e);return this.children=n,this.system!==null&&(i.object.ps=this.system.toJSON(e,t)),i}}var V;(function(r){r[r.BillBoard=0]="BillBoard",r[r.StretchedBillBoard=1]="StretchedBillBoard",r[r.Mesh=2]="Mesh",r[r.Trail=3]="Trail",r[r.HorizontalBillBoard=4]="HorizontalBillBoard",r[r.VerticalBillBoard=5]="VerticalBillBoard"})(V||(V={}));class La extends lr{constructor(e){super(),this.type="VFXBatch",this.maxParticles=1e3,this.systems=new Set;const t=new cr;t.mask=e.layers.mask;const n=e.material.clone();n.defines={},Object.assign(n.defines,e.material.defines),this.settings={instancingGeometry:e.instancingGeometry,renderMode:e.renderMode,renderOrder:e.renderOrder,material:n,uTileCount:e.uTileCount,vTileCount:e.vTileCount,blendTiles:e.blendTiles,softParticles:e.softParticles,softNearFade:e.softNearFade,softFarFade:e.softFarFade,layers:t},this.frustumCulled=!1,this.renderOrder=this.settings.renderOrder}addSystem(e){this.systems.add(e)}removeSystem(e){this.systems.delete(e)}applyDepthTexture(e){const t=this.material.uniforms.depthTexture;t&&t.value!==e&&(t.value=e,this.material.needsUpdate=!0)}getVisibleSystems(){return Array.from(this.systems).filter(e=>e.emitter.visible)}}const Uu=new G(0,0,1),Ns=new ne,Du=new G,Lu=new G;new G;const Fa=60,xr=new eh(1,1,1,1);class os{set time(e){this.emissionState.time=e}get time(){return this.emissionState.time}get layers(){return this.rendererSettings.layers}get texture(){return this.rendererSettings.material.map}set texture(e){this.rendererSettings.material.map=e,this.neededToUpdateRender=!0}get material(){return this.rendererSettings.material}set material(e){this.rendererSettings.material=e,this.neededToUpdateRender=!0}get uTileCount(){return this.rendererSettings.uTileCount}set uTileCount(e){this.rendererSettings.uTileCount=e,this.neededToUpdateRender=!0}get vTileCount(){return this.rendererSettings.vTileCount}set vTileCount(e){this.rendererSettings.vTileCount=e,this.neededToUpdateRender=!0}get blendTiles(){return this.rendererSettings.blendTiles}set blendTiles(e){this.rendererSettings.blendTiles=e,this.neededToUpdateRender=!0}get softParticles(){return this.rendererSettings.softParticles}set softParticles(e){this.rendererSettings.softParticles=e,this.neededToUpdateRender=!0}get softNearFade(){return this.rendererSettings.softNearFade}set softNearFade(e){this.rendererSettings.softNearFade=e,this.neededToUpdateRender=!0}get softFarFade(){return this.rendererSettings.softFarFade}set softFarFade(e){this.rendererSettings.softFarFade=e,this.neededToUpdateRender=!0}get instancingGeometry(){return this.rendererSettings.instancingGeometry}set instancingGeometry(e){this.restart(),this.particles.length=0,this.rendererSettings.instancingGeometry=e,this.neededToUpdateRender=!0}get renderMode(){return this.rendererSettings.renderMode}set renderMode(e){if(this.rendererSettings.renderMode!==e){let t=!1;switch(this.rendererSettings.renderMode===V.Trail&&(t=!0),this.rendererSettings.renderMode===V.Mesh&&(this.startRotation=new ie(0)),e){case V.Trail:this.rendererEmitterSettings={startLength:new ie(30),followLocalOrigin:!1},t=!0;break;case V.Mesh:this.rendererEmitterSettings={geometry:xr},this.startRotation=new Ei(new G(0,1,0),new ie(0));break;case V.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2},this.rendererSettings.instancingGeometry=xr;break;case V.BillBoard:case V.VerticalBillBoard:case V.HorizontalBillBoard:this.rendererEmitterSettings={},this.rendererSettings.instancingGeometry=xr;break}this.rendererSettings.renderMode=e,t&&(this.restart(),this.particles.length=0),this.neededToUpdateRender=!0}}get renderOrder(){return this.rendererSettings.renderOrder}set renderOrder(e){this.rendererSettings.renderOrder=e,this.neededToUpdateRender=!0}get blending(){return this.rendererSettings.material.blending}set blending(e){this.rendererSettings.material.blending=e,this.neededToUpdateRender=!0}constructor(e){if(this.temp=new G,this.travelDistance=0,this.normalMatrix=new Vt,this.memory=[],this.listeners={},this.firstTimeUpdate=!0,this.autoDestroy=e.autoDestroy===void 0?!1:e.autoDestroy,this.duration=e.duration??1,this.looping=e.looping===void 0?!0:e.looping,this.prewarm=e.prewarm===void 0?!1:e.prewarm,this.startLife=e.startLife??new ie(5),this.startSpeed=e.startSpeed??new ie(0),this.startRotation=e.startRotation??new ie(0),this.startSize=e.startSize??new ie(1),this.startColor=e.startColor??new Cn(new ct(1,1,1,1)),this.emissionOverTime=e.emissionOverTime??new ie(10),this.emissionOverDistance=e.emissionOverDistance??new ie(0),this.emissionBursts=e.emissionBursts??[],this.onlyUsedByOther=e.onlyUsedByOther??!1,this.emitterShape=e.shape??new Zn,this.behaviors=e.behaviors??new Array,this.worldSpace=e.worldSpace??!1,this.rendererEmitterSettings=e.rendererEmitterSettings??{},e.renderMode===V.StretchedBillBoard){const t=this.rendererEmitterSettings;e.speedFactor!==void 0&&(t.speedFactor=e.speedFactor),t.speedFactor=t.speedFactor??0,t.lengthFactor=t.lengthFactor??0}this.rendererSettings={instancingGeometry:e.instancingGeometry??xr,renderMode:e.renderMode??V.BillBoard,renderOrder:e.renderOrder??0,material:e.material,uTileCount:e.uTileCount??1,vTileCount:e.vTileCount??1,blendTiles:e.blendTiles??!1,softParticles:e.softParticles??!1,softNearFade:e.softNearFade??0,softFarFade:e.softFarFade??0,layers:e.layers??new cr},this.neededToUpdateRender=!0,this.particles=new Array,this.startTileIndex=e.startTileIndex||new ie(0),this.emitter=new Nu(this),this.paused=!1,this.particleNum=0,this.emissionState={isBursting:!1,burstParticleIndex:0,burstParticleCount:0,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,travelDistance:0},this.emissionBursts.forEach(t=>t.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1}pause(){this.paused=!0}play(){this.paused=!1}stop(){this.restart(),this.pause()}spawn(e,t,n){Ns.setFromRotationMatrix(n);const i=Du,s=Ns,a=Lu;n.decompose(i,s,a);for(let o=0;o<e;o++){for(t.burstParticleIndex=o,this.particleNum++;this.particles.length<this.particleNum;)this.rendererSettings.renderMode===V.Trail?this.particles.push(new Sr):this.particles.push(new mu);const c=this.particles[this.particleNum-1];if(c.reset(),c.speedModifier=1,this.startColor.startGen(c.memory),this.startColor.genColor(c.memory,c.startColor,this.emissionState.time),c.color.copy(c.startColor),this.startSpeed.startGen(c.memory),c.startSpeed=this.startSpeed.genValue(c.memory,t.time/this.duration),this.startLife.startGen(c.memory),c.life=this.startLife.genValue(c.memory,t.time/this.duration),c.age=0,this.startSize.startGen(c.memory),this.startSize.type==="vec3function")this.startSize.genValue(c.memory,c.startSize,t.time/this.duration);else{const l=this.startSize.genValue(c.memory,t.time/this.duration);c.startSize.set(l,l,l)}if(this.startTileIndex.startGen(c.memory),c.uvTile=this.startTileIndex.genValue(c.memory),c.size.copy(c.startSize),this.rendererSettings.renderMode===V.Mesh||this.rendererSettings.renderMode===V.BillBoard||this.rendererSettings.renderMode===V.VerticalBillBoard||this.rendererSettings.renderMode===V.HorizontalBillBoard||this.rendererSettings.renderMode===V.StretchedBillBoard){const l=c;this.startRotation.startGen(c.memory),this.rendererSettings.renderMode===V.Mesh?(l.rotation instanceof ne||(l.rotation=new ne),this.startRotation.type==="rotation"?this.startRotation.genValue(c.memory,l.rotation,1,t.time/this.duration):l.rotation.setFromAxisAngle(Uu,this.startRotation.genValue(l.memory,t.time/this.duration))):this.startRotation.type==="rotation"?l.rotation=0:l.rotation=this.startRotation.genValue(l.memory,t.time/this.duration)}else if(this.rendererSettings.renderMode===V.Trail){const l=c;this.rendererEmitterSettings.startLength.startGen(l.memory),l.length=this.rendererEmitterSettings.startLength.genValue(l.memory,t.time/this.duration)}if(this.emitterShape.initialize(c,t),this.rendererSettings.renderMode===V.Trail&&this.rendererEmitterSettings.followLocalOrigin){const l=c;l.localPosition=new G().copy(l.position)}this.worldSpace?(c.position.applyMatrix4(n),c.startSize.multiply(a).abs(),c.size.copy(c.startSize),c.velocity.multiply(a).applyMatrix3(this.normalMatrix),c.rotation&&c.rotation instanceof ne&&c.rotation.multiplyQuaternions(Ns,c.rotation)):this.onlyUsedByOther&&(c.parentMatrix=n);for(let l=0;l<this.behaviors.length;l++)this.behaviors[l].initialize(c,this)}}endEmit(){this.emitEnded=!0,this.autoDestroy&&(this.markForDestroy=!0),this.fire({type:"emitEnd",particleSystem:this})}dispose(){this._renderer&&this._renderer.deleteSystem(this),this.emitter.dispose(),this.emitter.parent&&this.emitter.parent.remove(this.emitter),this.fire({type:"destroy",particleSystem:this})}restart(){this.memory.length=0,this.paused=!1,this.particleNum=0,this.emissionState.isBursting=!1,this.emissionState.burstIndex=0,this.emissionState.burstWaveIndex=0,this.emissionState.time=0,this.emissionState.waitEmiting=0,this.behaviors.forEach(e=>{e.reset()}),this.emitEnded=!1,this.markForDestroy=!1,this.prewarmed=!1,this.emissionBursts.forEach(e=>e.count.startGen(this.memory)),this.emissionOverDistance.startGen(this.memory)}update(e){if(this.paused)return;let t=this.emitter;for(;t.parent;)t=t.parent;if(t.type!=="Scene"){this.dispose();return}if(this.firstTimeUpdate&&(this.firstTimeUpdate=!1,this.emitter.updateWorldMatrix(!0,!1)),this.emitEnded&&this.particleNum===0){this.markForDestroy&&this.emitter.parent&&this.dispose();return}if(this.looping&&this.prewarm&&!this.prewarmed){this.prewarmed=!0;for(let n=0;n<this.duration*Fa;n++)this.update(1/Fa)}e>.1&&(e=.1),this.neededToUpdateRender&&(this._renderer&&this._renderer.updateSystem(this),this.neededToUpdateRender=!1),this.onlyUsedByOther||this.emit(e,this.emissionState,this.emitter.matrixWorld),this.emitterShape.update(this,e);for(let n=0;n<this.behaviors.length;n++){this.behaviors[n].frameUpdate(e);for(let i=0;i<this.particleNum;i++)this.particles[i].died||this.behaviors[n].update(this.particles[i],e)}for(let n=0;n<this.particleNum;n++)this.rendererEmitterSettings.followLocalOrigin&&this.particles[n].localPosition?(this.particles[n].position.copy(this.particles[n].localPosition),this.particles[n].parentMatrix?this.particles[n].position.applyMatrix4(this.particles[n].parentMatrix):this.particles[n].position.applyMatrix4(this.emitter.matrixWorld)):this.particles[n].position.addScaledVector(this.particles[n].velocity,e*this.particles[n].speedModifier),this.particles[n].age+=e;if(this.rendererSettings.renderMode===V.Trail)for(let n=0;n<this.particleNum;n++)this.particles[n].update();for(let n=0;n<this.particleNum;n++){const i=this.particles[n];i.died&&(!(i instanceof Sr)||i.previous.length===0)&&(this.particles[n]=this.particles[this.particleNum-1],this.particles[this.particleNum-1]=i,this.particleNum--,n--,this.fire({type:"particleDied",particleSystem:this,particle:i}))}}emit(e,t,n){t.time>this.duration&&(this.looping?(t.time-=this.duration,t.burstIndex=0,this.behaviors.forEach(s=>{s.reset()})):!this.emitEnded&&!this.onlyUsedByOther&&this.endEmit()),this.normalMatrix.getNormalMatrix(n);const i=Math.ceil(t.waitEmiting);for(this.spawn(i,t,n),t.waitEmiting-=i;t.burstIndex<this.emissionBursts.length&&this.emissionBursts[t.burstIndex].time<=t.time;){if(Math.random()<this.emissionBursts[t.burstIndex].probability){const s=this.emissionBursts[t.burstIndex].count.genValue(this.memory,this.time);t.isBursting=!0,t.burstParticleCount=s,this.spawn(s,t,n),t.isBursting=!1}t.burstIndex++}if(!this.emitEnded&&(t.waitEmiting+=e*this.emissionOverTime.genValue(this.memory,t.time/this.duration),t.previousWorldPos!=null)){this.temp.set(n.elements[12],n.elements[13],n.elements[14]),t.travelDistance+=t.previousWorldPos.distanceTo(this.temp);const s=this.emissionOverDistance.genValue(this.memory,t.time/this.duration);if(t.travelDistance*s>0){const a=Math.floor(t.travelDistance*s);t.travelDistance-=a/s,t.waitEmiting+=a}}t.previousWorldPos===void 0&&(t.previousWorldPos=new G),t.previousWorldPos.set(n.elements[12],n.elements[13],n.elements[14]),t.time+=e}toJSON(e,t={}){if((e===void 0||typeof e=="string")&&(e={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}}),e.materials[this.rendererSettings.material.uuid]=this.rendererSettings.material.toJSON(e),t.useUrlForImage&&this.texture?.source!==void 0){const s=this.texture.source;e.images[s.uuid]={uuid:s.uuid,url:this.texture.image.url}}let n;this.renderMode===V.Trail?n={startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===V.Mesh?n={}:this.renderMode===V.StretchedBillBoard?n={speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:n={};const i=this.rendererSettings.instancingGeometry;return e.geometries&&!e.geometries[i.uuid]&&(e.geometries[i.uuid]=i.toJSON()),{version:"3.0",autoDestroy:this.autoDestroy,looping:this.looping,prewarm:this.prewarm,duration:this.duration,shape:this.emitterShape.toJSON(),startLife:this.startLife.toJSON(),startSpeed:this.startSpeed.toJSON(),startRotation:this.startRotation.toJSON(),startSize:this.startSize.toJSON(),startColor:this.startColor.toJSON(),emissionOverTime:this.emissionOverTime.toJSON(),emissionOverDistance:this.emissionOverDistance.toJSON(),emissionBursts:this.emissionBursts.map(s=>({time:s.time,count:s.count.toJSON(),probability:s.probability,interval:s.interval,cycle:s.cycle})),onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry.uuid,renderOrder:this.renderOrder,renderMode:this.renderMode,rendererEmitterSettings:n,material:this.rendererSettings.material.uuid,layers:this.layers.mask,startTileIndex:this.startTileIndex.toJSON(),uTileCount:this.uTileCount,vTileCount:this.vTileCount,blendTiles:this.blendTiles,softParticles:this.rendererSettings.softParticles,softFarFade:this.rendererSettings.softFarFade,softNearFade:this.rendererSettings.softNearFade,behaviors:this.behaviors.map(s=>s.toJSON()),worldSpace:this.worldSpace}}static fromJSON(e,t,n){const i=pu(e.shape,t);let s;if(e.renderMode===V.Trail){const c=e.rendererEmitterSettings;s={startLength:c.startLength!=null?Q(c.startLength):new ie(30),followLocalOrigin:c.followLocalOrigin}}else e.renderMode===V.Mesh?s={}:e.renderMode===V.StretchedBillBoard?(s=e.rendererEmitterSettings,e.speedFactor!=null&&(s.speedFactor=e.speedFactor)):s={};const a=new cr;e.layers&&(a.mask=e.layers);const o=new os({autoDestroy:e.autoDestroy,looping:e.looping,prewarm:e.prewarm,duration:e.duration,shape:i,startLife:Q(e.startLife),startSpeed:Q(e.startSpeed),startRotation:mr(e.startRotation),startSize:mr(e.startSize),startColor:As(e.startColor),emissionOverTime:Q(e.emissionOverTime),emissionOverDistance:Q(e.emissionOverDistance),emissionBursts:e.emissionBursts?.map(c=>({time:c.time,count:typeof c.count=="number"?new ie(c.count):Q(c.count),probability:c.probability??1,interval:c.interval??.1,cycle:c.cycle??1})),onlyUsedByOther:e.onlyUsedByOther,instancingGeometry:t.geometries[e.instancingGeometry],renderMode:e.renderMode,rendererEmitterSettings:s,renderOrder:e.renderOrder,layers:a,material:e.material?t.materials[e.material]:e.texture?new ra({map:t.textures[e.texture],transparent:e.transparent??!0,blending:e.blending,side:bs}):new ra({color:16777215,transparent:!0,blending:sa,side:bs}),startTileIndex:typeof e.startTileIndex=="number"?new ie(e.startTileIndex):Q(e.startTileIndex),uTileCount:e.uTileCount,vTileCount:e.vTileCount,blendTiles:e.blendTiles,softParticles:e.softParticles,softFarFade:e.softFarFade,softNearFade:e.softNearFade,behaviors:[],worldSpace:e.worldSpace});return o.behaviors=e.behaviors.map(c=>{const l=_u(c,o);return l&&l.type==="EmitSubParticleSystem"&&(n[c.subParticleSystem]=l),l}).filter(c=>c!==null),o}addBehavior(e){this.behaviors.push(e)}getRendererSettings(){return this.rendererSettings}addEventListener(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)}removeAllEventListeners(e){this.listeners[e]&&(this.listeners[e]=[])}removeEventListener(e,t){if(this.listeners[e]){const n=this.listeners[e].indexOf(t);n!==-1&&this.listeners[e].splice(n,1)}}fire(e){this.listeners[e.type]&&this.listeners[e.type].forEach(t=>t(e))}clone(){const e=[];for(const s of this.emissionBursts){const a={};Object.assign(a,s),e.push(a)}const t=[];for(const s of this.behaviors)t.push(s.clone());let n;this.renderMode===V.Trail?n={startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===V.StretchedBillBoard?n={lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:n={};const i=new cr;return i.mask=this.layers.mask,new os({autoDestroy:this.autoDestroy,looping:this.looping,duration:this.duration,shape:this.emitterShape.clone(),startLife:this.startLife.clone(),startSpeed:this.startSpeed.clone(),startRotation:this.startRotation.clone(),startSize:this.startSize.clone(),startColor:this.startColor.clone(),emissionOverTime:this.emissionOverTime.clone(),emissionOverDistance:this.emissionOverDistance.clone(),emissionBursts:e,onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry,renderMode:this.renderMode,renderOrder:this.renderOrder,rendererEmitterSettings:n,material:this.rendererSettings.material,startTileIndex:this.startTileIndex,uTileCount:this.uTileCount,vTileCount:this.vTileCount,blendTiles:this.blendTiles,softParticles:this.softParticles,softFarFade:this.softFarFade,softNearFade:this.softNearFade,behaviors:t,worldSpace:this.worldSpace,layers:i})}}var Us=`
523
523
 
524
524
  #include <common>
525
525
  #include <color_pars_fragment>
@@ -554,7 +554,7 @@ void main() {
554
554
  #include <soft_fragment>
555
555
  #include <tonemapping_fragment>
556
556
  }
557
- `,Us=`
557
+ `,Ds=`
558
558
  #define STANDARD
559
559
 
560
560
  #ifdef PHYSICAL
@@ -719,7 +719,7 @@ outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoat
719
719
  #include <fog_fragment>
720
720
  #include <premultiplied_alpha_fragment>
721
721
  #include <dithering_fragment>
722
- }`,Lh=`
722
+ }`,Fu=`
723
723
  #include <common>
724
724
  #include <color_pars_vertex>
725
725
  #include <logdepthbuf_pars_vertex>
@@ -765,7 +765,7 @@ void main() {
765
765
  #include <tile_vertex>
766
766
  #include <soft_vertex>
767
767
  }
768
- `,Fh=`
768
+ `,Vu=`
769
769
  #include <common>
770
770
  #include <color_pars_vertex>
771
771
  #include <logdepthbuf_pars_vertex>
@@ -802,7 +802,7 @@ void main() {
802
802
  #include <tile_vertex>
803
803
  #include <soft_vertex>
804
804
  }
805
- `,Ds=`
805
+ `,Ls=`
806
806
  #define STANDARD
807
807
  varying vec3 vViewPosition;
808
808
  #ifdef USE_TRANSMISSION
@@ -887,7 +887,7 @@ void main() {
887
887
  vWorldPosition = worldPosition.xyz;
888
888
  #endif
889
889
  }
890
- `,Vh=`
890
+ `,ju=`
891
891
  #include <common>
892
892
  #include <color_pars_vertex>
893
893
  #include <logdepthbuf_pars_vertex>
@@ -928,7 +928,7 @@ void main() {
928
928
  #include <tile_vertex>
929
929
  #include <soft_vertex>
930
930
  }
931
- `;function Ls(r){return r===0?"uv":`uv${r}`}class jh extends tu{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=Ds,e.fragmentShader=Us}}class Jh extends nu{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=Ds,e.fragmentShader=Us}}class Gh extends La{constructor(e){super(e),this.vector_=new G,this.vector2_=new G,this.vector3_=new G,this.quaternion_=new ie,this.quaternion2_=new ie,this.quaternion3_=new ie,this.rotationMat_=new Vt,this.rotationMat2_=new Vt,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new fn(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(et),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new fn(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(et),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===V.Mesh?(this.rotationBuffer=new fn(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(et),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===V.BillBoard||this.settings.renderMode===V.HorizontalBillBoard||this.settings.renderMode===V.VerticalBillBoard||this.settings.renderMode===V.StretchedBillBoard)&&(this.rotationBuffer=new fn(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(et),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new fn(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(et),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new fn(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(et),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===V.StretchedBillBoard&&(this.velocityBuffer=new fn(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(et),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new eu,this.geometry.setIndex(this.settings.instancingGeometry.getIndex()),this.settings.instancingGeometry.hasAttribute("normal")&&this.geometry.setAttribute("normal",this.settings.instancingGeometry.getAttribute("normal")),this.geometry.setAttribute("position",this.settings.instancingGeometry.getAttribute("position")),this.geometry.setAttribute("uv",this.settings.instancingGeometry.getAttribute("uv")),this.buildExpandableBuffers()}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={},t={};this.settings.material.type!=="MeshStandardMaterial"&&this.settings.material.type!=="MeshPhysicalMaterial"&&(e.map=new Et(this.settings.material.map)),this.settings.material.alphaTest&&(t.USE_ALPHATEST="",e.alphaTest=new Et(this.settings.material.alphaTest)),t.USE_UV="";const n=this.settings.uTileCount,i=this.settings.vTileCount;(n>1||i>1)&&(t.UV_TILE="",e.tileCount=new Et(new Xn(n,i))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.material.normalMap&&(t.USE_NORMALMAP="",t.NORMALMAP_UV=Ls(this.settings.material.normalMap.channel),e.normalMapTransform=new Et(new Vt().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(t.USE_MAP="",this.settings.blendTiles&&(t.TILE_BLEND=""),t.MAP_UV=Ls(this.settings.material.map.channel),e.mapTransform=new Et(new Vt().copy(this.settings.material.map.matrix))),t.USE_COLOR_ALPHA="";let s;if(this.settings.softParticles){t.SOFT_PARTICLES="";const o=this.settings.softNearFade,c=1/(this.settings.softFarFade-this.settings.softNearFade);e.softParams=new Et(new Xn(o,c)),e.depthTexture=new Et(null);const l=e.projParams=new Et(new ct);s=(u,d,f)=>{l.value.set(f.near,f.far,0,0)}}let a=!1;if(this.settings.renderMode===V.BillBoard||this.settings.renderMode===V.VerticalBillBoard||this.settings.renderMode===V.HorizontalBillBoard||this.settings.renderMode===V.Mesh){let o,c;this.settings.renderMode===V.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(t.USE_COLOR="",o=Ds,c=Us,a=!0):(o=Fh,c=Ns):(o=Lh,c=Ns),this.settings.renderMode===V.VerticalBillBoard?t.VERTICAL="":this.settings.renderMode===V.HorizontalBillBoard&&(t.HORIZONTAL="");let l=!1;this.settings.renderMode===V.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new jh({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new Jh({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0)),l||(this.material=new bs({uniforms:e,defines:t,vertexShader:o,fragmentShader:c,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest,lights:a}))}else if(this.settings.renderMode===V.StretchedBillBoard)e.speedFactor=new Et(1),this.material=new bs({uniforms:e,defines:t,vertexShader:Vh,fragmentShader:Ns,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest});else throw new Error("render mode unavailable");this.material&&s&&(this.material.onBeforeRender=s)}update(){let e=0,t=0;this.systems.forEach(n=>{t+=n.particleNum}),t>this.maxParticles&&this.expandBuffers(t),this.systems.forEach(n=>{n.emitter.updateMatrixWorld&&(n.emitter.updateWorldMatrix(!0,!1),n.emitter.updateMatrixWorld(!0));const i=n.particles,s=n.particleNum,a=this.quaternion2_,o=this.vector2_,c=this.vector3_;n.emitter.matrixWorld.decompose(o,a,c),this.rotationMat_.setFromMatrix4(n.emitter.matrixWorld);for(let l=0;l<s;l++,e++){const u=i[l];if(this.settings.renderMode===V.Mesh){let f;if(n.worldSpace)f=u.rotation;else{let m;u.parentMatrix?m=this.quaternion3_.setFromRotationMatrix(u.parentMatrix):m=a,f=this.quaternion_,f.copy(m).multiply(u.rotation)}this.rotationBuffer.setXYZW(e,f.x,f.y,f.z,f.w)}else(this.settings.renderMode===V.StretchedBillBoard||this.settings.renderMode===V.VerticalBillBoard||this.settings.renderMode===V.HorizontalBillBoard||this.settings.renderMode===V.BillBoard)&&this.rotationBuffer.setX(e,u.rotation);let d;if(n.worldSpace?d=u.position:(d=this.vector_,u.parentMatrix?d.copy(u.position).applyMatrix4(u.parentMatrix):d.copy(u.position).applyMatrix4(n.emitter.matrixWorld)),this.offsetBuffer.setXYZ(e,d.x,d.y,d.z),this.colorBuffer.setXYZW(e,u.color.x,u.color.y,u.color.z,u.color.w),n.worldSpace?this.sizeBuffer.setXYZ(e,u.size.x,u.size.y,u.size.z):u.parentMatrix?this.sizeBuffer.setXYZ(e,u.size.x,u.size.y,u.size.z):this.sizeBuffer.setXYZ(e,u.size.x*Math.abs(c.x),u.size.y*Math.abs(c.y),u.size.z*Math.abs(c.z)),this.uvTileBuffer.setX(e,u.uvTile),this.settings.renderMode===V.StretchedBillBoard&&this.velocityBuffer){let f=n.rendererEmitterSettings.speedFactor;f===0&&(f=.001);const m=n.rendererEmitterSettings.lengthFactor;let x;n.worldSpace?x=u.velocity:(x=this.vector_,u.parentMatrix?(this.rotationMat2_.setFromMatrix4(u.parentMatrix),x.copy(u.velocity).applyMatrix3(this.rotationMat2_)):x.copy(u.velocity).applyMatrix3(this.rotationMat_)),this.velocityBuffer.setXYZW(e,x.x*f,x.y*f,x.z*f,m)}}}),this.geometry.instanceCount=e,e>0&&(this.offsetBuffer.clearUpdateRanges(),this.offsetBuffer.addUpdateRange(0,e*3),this.offsetBuffer.needsUpdate=!0,this.sizeBuffer.clearUpdateRanges(),this.sizeBuffer.addUpdateRange(0,e*3),this.sizeBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.uvTileBuffer.clearUpdateRanges(),this.uvTileBuffer.addUpdateRange(0,e),this.uvTileBuffer.needsUpdate=!0,this.settings.renderMode===V.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,e*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===V.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===V.StretchedBillBoard||this.settings.renderMode===V.HorizontalBillBoard||this.settings.renderMode===V.VerticalBillBoard||this.settings.renderMode===V.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var Wh=`
931
+ `;function Fs(r){return r===0?"uv":`uv${r}`}class Ju extends nh{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=Ls,e.fragmentShader=Ds}}class Gu extends ih{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=Ls,e.fragmentShader=Ds}}class Wu extends La{constructor(e){super(e),this.vector_=new G,this.vector2_=new G,this.vector3_=new G,this.quaternion_=new ne,this.quaternion2_=new ne,this.quaternion3_=new ne,this.rotationMat_=new Vt,this.rotationMat2_=new Vt,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new fn(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(et),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new fn(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(et),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===V.Mesh?(this.rotationBuffer=new fn(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(et),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===V.BillBoard||this.settings.renderMode===V.HorizontalBillBoard||this.settings.renderMode===V.VerticalBillBoard||this.settings.renderMode===V.StretchedBillBoard)&&(this.rotationBuffer=new fn(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(et),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new fn(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(et),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new fn(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(et),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===V.StretchedBillBoard&&(this.velocityBuffer=new fn(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(et),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new th,this.geometry.setIndex(this.settings.instancingGeometry.getIndex()),this.settings.instancingGeometry.hasAttribute("normal")&&this.geometry.setAttribute("normal",this.settings.instancingGeometry.getAttribute("normal")),this.geometry.setAttribute("position",this.settings.instancingGeometry.getAttribute("position")),this.settings.instancingGeometry.hasAttribute("uv")&&this.geometry.setAttribute("uv",this.settings.instancingGeometry.getAttribute("uv")),this.buildExpandableBuffers()}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={},t={};this.settings.material.type!=="MeshStandardMaterial"&&this.settings.material.type!=="MeshPhysicalMaterial"&&(e.map=new Et(this.settings.material.map)),this.settings.material.alphaTest&&(t.USE_ALPHATEST="",e.alphaTest=new Et(this.settings.material.alphaTest)),t.USE_UV="";const n=this.settings.uTileCount,i=this.settings.vTileCount;(n>1||i>1)&&(t.UV_TILE="",e.tileCount=new Et(new Xn(n,i))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.material.normalMap&&(t.USE_NORMALMAP="",t.NORMALMAP_UV=Fs(this.settings.material.normalMap.channel),e.normalMapTransform=new Et(new Vt().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(t.USE_MAP="",this.settings.blendTiles&&(t.TILE_BLEND=""),t.MAP_UV=Fs(this.settings.material.map.channel),e.mapTransform=new Et(new Vt().copy(this.settings.material.map.matrix))),t.USE_COLOR_ALPHA="";let s;if(this.settings.softParticles){t.SOFT_PARTICLES="";const o=this.settings.softNearFade,c=1/(this.settings.softFarFade-this.settings.softNearFade);e.softParams=new Et(new Xn(o,c)),e.depthTexture=new Et(null);const l=e.projParams=new Et(new ct);s=(u,d,m)=>{l.value.set(m.near,m.far,0,0)}}let a=!1;if(this.settings.renderMode===V.BillBoard||this.settings.renderMode===V.VerticalBillBoard||this.settings.renderMode===V.HorizontalBillBoard||this.settings.renderMode===V.Mesh){let o,c;this.settings.renderMode===V.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(t.USE_COLOR="",o=Ls,c=Ds,a=!0):(o=Vu,c=Us):(o=Fu,c=Us),this.settings.renderMode===V.VerticalBillBoard?t.VERTICAL="":this.settings.renderMode===V.HorizontalBillBoard&&(t.HORIZONTAL="");let l=!1;this.settings.renderMode===V.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new Ju({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new Gu({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0)),l||(this.material=new xs({uniforms:e,defines:t,vertexShader:o,fragmentShader:c,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest,lights:a}))}else if(this.settings.renderMode===V.StretchedBillBoard)e.speedFactor=new Et(1),this.material=new xs({uniforms:e,defines:t,vertexShader:ju,fragmentShader:Us,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,blending:this.settings.material.blending,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha,side:this.settings.material.side,alphaTest:this.settings.material.alphaTest,depthTest:this.settings.material.depthTest});else throw new Error("render mode unavailable");this.material&&s&&(this.material.onBeforeRender=s)}update(){let e=0,t=0;const n=this.getVisibleSystems();for(const i of n)t+=i.particleNum;t>this.maxParticles&&this.expandBuffers(t);for(const i of n){i.emitter.updateMatrixWorld&&(i.emitter.updateWorldMatrix(!0,!1),i.emitter.updateMatrixWorld(!0));const s=i.particles,a=i.particleNum,o=this.quaternion2_,c=this.vector2_,l=this.vector3_;i.emitter.matrixWorld.decompose(c,o,l),this.rotationMat_.setFromMatrix4(i.emitter.matrixWorld);for(let u=0;u<a;u++,e++){const d=s[u];if(this.settings.renderMode===V.Mesh){let f;if(i.worldSpace)f=d.rotation;else{let x;d.parentMatrix?x=this.quaternion3_.setFromRotationMatrix(d.parentMatrix):x=o,f=this.quaternion_,f.copy(x).multiply(d.rotation)}this.rotationBuffer.setXYZW(e,f.x,f.y,f.z,f.w)}else(this.settings.renderMode===V.StretchedBillBoard||this.settings.renderMode===V.VerticalBillBoard||this.settings.renderMode===V.HorizontalBillBoard||this.settings.renderMode===V.BillBoard)&&this.rotationBuffer.setX(e,d.rotation);let m;if(i.worldSpace?m=d.position:(m=this.vector_,d.parentMatrix?m.copy(d.position).applyMatrix4(d.parentMatrix):m.copy(d.position).applyMatrix4(i.emitter.matrixWorld)),this.offsetBuffer.setXYZ(e,m.x,m.y,m.z),this.colorBuffer.setXYZW(e,d.color.x,d.color.y,d.color.z,d.color.w),i.worldSpace?this.sizeBuffer.setXYZ(e,d.size.x,d.size.y,d.size.z):d.parentMatrix?this.sizeBuffer.setXYZ(e,d.size.x,d.size.y,d.size.z):this.sizeBuffer.setXYZ(e,d.size.x*Math.abs(l.x),d.size.y*Math.abs(l.y),d.size.z*Math.abs(l.z)),this.uvTileBuffer.setX(e,d.uvTile),this.settings.renderMode===V.StretchedBillBoard&&this.velocityBuffer){let f=i.rendererEmitterSettings.speedFactor;f===0&&(f=.001);const x=i.rendererEmitterSettings.lengthFactor;let _;i.worldSpace?_=d.velocity:(_=this.vector_,d.parentMatrix?(this.rotationMat2_.setFromMatrix4(d.parentMatrix),_.copy(d.velocity).applyMatrix3(this.rotationMat2_)):_.copy(d.velocity).applyMatrix3(this.rotationMat_)),this.velocityBuffer.setXYZW(e,_.x*f,_.y*f,_.z*f,x)}}}this.geometry.instanceCount=e,e>0&&(this.offsetBuffer.clearUpdateRanges(),this.offsetBuffer.addUpdateRange(0,e*3),this.offsetBuffer.needsUpdate=!0,this.sizeBuffer.clearUpdateRanges(),this.sizeBuffer.addUpdateRange(0,e*3),this.sizeBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.uvTileBuffer.clearUpdateRanges(),this.uvTileBuffer.addUpdateRange(0,e),this.uvTileBuffer.needsUpdate=!0,this.settings.renderMode===V.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,e*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===V.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===V.StretchedBillBoard||this.settings.renderMode===V.HorizontalBillBoard||this.settings.renderMode===V.VerticalBillBoard||this.settings.renderMode===V.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var Hu=`
932
932
 
933
933
  #include <common>
934
934
  #include <tile_pars_fragment>
@@ -961,7 +961,7 @@ void main() {
961
961
 
962
962
  #include <fog_fragment>
963
963
  #include <tonemapping_fragment>
964
- }`,Hh=`
964
+ }`,qu=`
965
965
  #include <common>
966
966
  #include <tile_pars_vertex>
967
967
  #include <color_pars_vertex>
@@ -1036,7 +1036,7 @@ void main() {
1036
1036
  vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
1037
1037
 
1038
1038
  #include <fog_vertex>
1039
- }`;class qh extends La{constructor(e){super(e),this.vector_=new G,this.vector2_=new G,this.vector3_=new G,this.quaternion_=new ie,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new ti,this.indexBuffer=new dt(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(et),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new dt(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(et),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new dt(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(et),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new dt(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(et),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new dt(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(et),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new dt(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(et),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new dt(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(et),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new dt(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(et),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new Xn(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},t={};if(t.USE_UV="",t.USE_COLOR_ALPHA="",this.settings.material.map&&(t.USE_MAP="",t.MAP_UV=Ls(this.settings.material.map.channel),e.map=new Et(this.settings.material.map),e.mapTransform=new Et(new Vt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===V.Trail)this.material=new bs({uniforms:e,defines:t,vertexShader:Hh,fragmentShader:Wh,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||sa,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let e=0,t=0,n=0;this.systems.forEach(i=>{for(let s=0;s<i.particleNum;s++)n+=i.particles[s].previous.length*2}),n>this.maxParticles&&this.expandBuffers(n),this.systems.forEach(i=>{i.emitter.updateMatrixWorld&&(i.emitter.updateWorldMatrix(!0,!1),i.emitter.updateMatrixWorld(!0));const s=this.quaternion_,a=this.vector2_,o=this.vector3_;i.emitter.matrixWorld.decompose(a,s,o);const c=i.particles,l=i.particleNum,u=this.settings.uTileCount,d=this.settings.vTileCount,f=1/u,m=1/d;for(let x=0;x<l;x++){const _=c[x],g=_.uvTile%d,v=Math.floor(_.uvTile/d+.001),w=_.previous.values();let S=w.next(),T=S.value,M=T;S.done||(S=w.next());let P;S.value!==void 0?P=S.value:P=M;for(let E=0;E<_.previous.length;E++,e+=2){if(this.positionBuffer.setXYZ(e,M.position.x,M.position.y,M.position.z),this.positionBuffer.setXYZ(e+1,M.position.x,M.position.y,M.position.z),i.worldSpace?(this.positionBuffer.setXYZ(e,M.position.x,M.position.y,M.position.z),this.positionBuffer.setXYZ(e+1,M.position.x,M.position.y,M.position.z)):(_.parentMatrix?this.vector_.copy(M.position).applyMatrix4(_.parentMatrix):this.vector_.copy(M.position).applyMatrix4(i.emitter.matrixWorld),this.positionBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),i.worldSpace?(this.previousBuffer.setXYZ(e,T.position.x,T.position.y,T.position.z),this.previousBuffer.setXYZ(e+1,T.position.x,T.position.y,T.position.z)):(_.parentMatrix?this.vector_.copy(T.position).applyMatrix4(_.parentMatrix):this.vector_.copy(T.position).applyMatrix4(i.emitter.matrixWorld),this.previousBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),i.worldSpace?(this.nextBuffer.setXYZ(e,P.position.x,P.position.y,P.position.z),this.nextBuffer.setXYZ(e+1,P.position.x,P.position.y,P.position.z)):(_.parentMatrix?this.vector_.copy(P.position).applyMatrix4(_.parentMatrix):this.vector_.copy(P.position).applyMatrix4(i.emitter.matrixWorld),this.nextBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(e,-1),this.sideBuffer.setX(e+1,1),i.worldSpace)this.widthBuffer.setX(e,M.size),this.widthBuffer.setX(e+1,M.size);else if(_.parentMatrix)this.widthBuffer.setX(e,M.size),this.widthBuffer.setX(e+1,M.size);else{const O=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(e,M.size*O),this.widthBuffer.setX(e+1,M.size*O)}this.uvBuffer.setXY(e,(E/_.previous.length+g)*f,(d-v-1)*m),this.uvBuffer.setXY(e+1,(E/_.previous.length+g)*f,(d-v)*m),this.colorBuffer.setXYZW(e,M.color.x,M.color.y,M.color.z,M.color.w),this.colorBuffer.setXYZW(e+1,M.color.x,M.color.y,M.color.z,M.color.w),E+1<_.previous.length&&(this.indexBuffer.setX(t*3,e),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+2),t++,this.indexBuffer.setX(t*3,e+2),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+3),t++),T=M,M=P,S.done||(S=w.next(),S.value!==void 0&&(P=S.value))}}}),this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,e*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,e*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,e*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,e),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,e),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,e*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,t*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,t*3)}dispose(){this.geometry.dispose()}}class er{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new mn;this._triangleIndexToArea.length=0;let n=0;if(!e.getIndex())return;const i=e.getIndex().array,s=i.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),i[a*3],i[a*3+1],i[a*3+2]),n+=t.getArea(),this._triangleIndexToArea.push(n);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new q,this._tempB=new q,this._tempC=new q,e&&(this.geometry=e)}initialize(e){const t=this._geometry;if(!t||t.getIndex()===null){e.position.set(0,0,0),e.velocity.set(0,0,1).multiplyScalar(e.startSpeed);return}const n=this._triangleIndexToArea.length-1;let i=0,s=n;const a=Math.random()*this._triangleIndexToArea[n];for(;i+1<s;){const m=Math.floor((i+s)/2);a<this._triangleIndexToArea[m]?s=m:i=m}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=t.getIndex().array[i*3],u=t.getIndex().array[i*3+1],d=t.getIndex().array[i*3+2],f=t.getAttribute("position");this._tempA.fromBufferAttribute(f,l),this._tempB.fromBufferAttribute(f,u),this._tempC.fromBufferAttribute(f,d),this._tempB.sub(this._tempA),this._tempC.sub(this._tempA),this._tempA.addScaledVector(this._tempB,o).addScaledVector(this._tempC,c),e.position.copy(this._tempA),this._tempA.copy(this._tempB).cross(this._tempC).normalize(),e.velocity.copy(this._tempA).normalize().multiplyScalar(e.startSpeed)}toJSON(){return{type:"mesh_surface",mesh:this._geometry?this._geometry.uuid:""}}static fromJSON(e,t){return new er(t.geometries[e.geometry])}clone(){return new er(this._geometry)}update(e,t){}}Th({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:er,loadJSON:er.fromJSON}],behaviors:[]});class Oo extends na{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(e,t){return e.material.side===t.material.side&&e.material.blending===t.material.blending&&e.material.blendSrc===t.material.blendSrc&&e.material.blendDst===t.material.blendDst&&e.material.blendEquation===t.material.blendEquation&&e.material.premultipliedAlpha===t.material.premultipliedAlpha&&e.material.transparent===t.material.transparent&&e.material.depthTest===t.material.depthTest&&e.material.type===t.material.type&&e.material.alphaTest===t.material.alphaTest&&e.material.map===t.material.map&&e.renderMode===t.renderMode&&e.blendTiles===t.blendTiles&&e.softParticles===t.softParticles&&e.softFarFade===t.softFarFade&&e.softNearFade===t.softNearFade&&e.uTileCount===t.uTileCount&&e.vTileCount===t.vTileCount&&e.instancingGeometry===t.instancingGeometry&&e.renderOrder===t.renderOrder&&e.layers.mask===t.layers.mask}addSystem(e){e._renderer=this;const t=e.getRendererSettings();for(let i=0;i<this.batches.length;i++)if(Oo.equals(this.batches[i].settings,t)){this.batches[i].addSystem(e),this.systemToBatchIndex.set(e,i);return}let n;switch(t.renderMode){case V.Trail:n=new qh(t);break;case V.Mesh:case V.BillBoard:case V.VerticalBillBoard:case V.HorizontalBillBoard:case V.StretchedBillBoard:n=new Gh(t);break}this.depthTexture&&n.applyDepthTexture(this.depthTexture),n.addSystem(e),this.batches.push(n),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(n)}deleteSystem(e){const t=this.systemToBatchIndex.get(e);t!=null&&(this.batches[t].removeSystem(e),this.systemToBatchIndex.delete(e))}setDepthTexture(e){this.depthTexture=e;for(const t of this.batches)t.applyDepthTexture(e)}updateSystem(e){this.deleteSystem(e),this.addSystem(e)}update(e){this.systemToBatchIndex.forEach((t,n)=>{n.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const Xh=Oo;Ih(),console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const Va=Math.sqrt(5),Yh=(Va-1)/4,Ve=(5-Va)/20,xr=r=>Math.floor(r)|0,wr=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function Zh(r=Math.random){const e=Kh(r),t=new Float64Array(e).map(a=>wr[a%32*4]),n=new Float64Array(e).map(a=>wr[a%32*4+1]),i=new Float64Array(e).map(a=>wr[a%32*4+2]),s=new Float64Array(e).map(a=>wr[a%32*4+3]);return function(a,o,c,l){let u,d,f,m,x;const _=(a+o+c+l)*Yh,g=xr(a+_),v=xr(o+_),w=xr(c+_),S=xr(l+_),T=(g+v+w+S)*Ve,M=g-T,P=v-T,E=w-T,O=S-T,A=a-M,R=o-P,B=c-E,I=l-O;let U=0,L=0,J=0,H=0;A>R?U++:L++,A>B?U++:J++,A>I?U++:H++,R>B?L++:J++,R>I?L++:H++,B>I?J++:H++;const se=U>=3?1:0,W=L>=3?1:0,pe=J>=3?1:0,ne=H>=3?1:0,he=U>=2?1:0,oe=L>=2?1:0,le=J>=2?1:0,xe=H>=2?1:0,ge=U>=1?1:0,de=L>=1?1:0,re=J>=1?1:0,Ze=H>=1?1:0,Ue=A-se+Ve,ke=R-W+Ve,lt=B-pe+Ve,De=I-ne+Ve,ve=A-he+2*Ve,ue=R-oe+2*Ve,ft=B-le+2*Ve,Re=I-xe+2*Ve,fe=A-ge+3*Ve,rt=R-de+3*Ve,wt=B-re+3*Ve,_t=I-Ze+3*Ve,st=A-1+4*Ve,Tt=R-1+4*Ve,mt=B-1+4*Ve,yt=I-1+4*Ve,ut=g&255,Ae=v&255,Ke=w&255,ht=S&255;let Qe=.6-A*A-R*R-B*B-I*I;if(Qe<0)u=0;else{const ae=ut+e[Ae+e[Ke+e[ht]]];Qe*=Qe,u=Qe*Qe*(t[ae]*A+n[ae]*R+i[ae]*B+s[ae]*I)}let $=.6-Ue*Ue-ke*ke-lt*lt-De*De;if($<0)d=0;else{const ae=ut+se+e[Ae+W+e[Ke+pe+e[ht+ne]]];$*=$,d=$*$*(t[ae]*Ue+n[ae]*ke+i[ae]*lt+s[ae]*De)}let Mt=.6-ve*ve-ue*ue-ft*ft-Re*Re;if(Mt<0)f=0;else{const ae=ut+he+e[Ae+oe+e[Ke+le+e[ht+xe]]];Mt*=Mt,f=Mt*Mt*(t[ae]*ve+n[ae]*ue+i[ae]*ft+s[ae]*Re)}let jt=.6-fe*fe-rt*rt-wt*wt-_t*_t;if(jt<0)m=0;else{const ae=ut+ge+e[Ae+de+e[Ke+re+e[ht+Ze]]];jt*=jt,m=jt*jt*(t[ae]*fe+n[ae]*rt+i[ae]*wt+s[ae]*_t)}let Ct=.6-st*st-Tt*Tt-mt*mt-yt*yt;if(Ct<0)x=0;else{const ae=ut+1+e[Ae+1+e[Ke+1+e[ht+1]]];Ct*=Ct,x=Ct*Ct*(t[ae]*st+n[ae]*Tt+i[ae]*mt+s[ae]*yt)}return 27*(u+d+f+m+x)}}function Kh(r){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const n=t+~~(r()*(256-t)),i=e[t];e[t]=e[n],e[n]=i}for(let t=256;t<512;t++)e[t]=e[t-256];return e}var Qh=Object.defineProperty,$h=(r,e,t)=>e in r?Qh(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Me=(r,e,t)=>($h(r,typeof e!="symbol"?e+"":e,t),t);(function(){class r{}class e extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class t extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class n extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class i extends r{constructor(p,y="unrestricted"){super(),Me(this,"type"),Me(this,"value"),this.value=p,this.type=y}}class s extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class a extends r{}class o extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class c extends r{}class l extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class u extends r{constructor(p,y="integer"){super(),Me(this,"value"),Me(this,"type"),this.value=p,this.type=y}}class d extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class f extends r{constructor(p,y,b){super(),Me(this,"value"),Me(this,"type"),Me(this,"unit"),this.value=p,this.type=y,this.unit=b}}class m extends r{}class x extends r{}class _ extends r{}class g extends r{}class v extends r{}class w extends r{}class S extends r{}class T extends r{}class M extends r{}class P extends r{}class E extends r{}class O extends r{}class A{constructor(p){Me(this,"input"),Me(this,"index",0),this.input=p}consume(){const p=this.input.codePointAt(this.index);return p!==void 0&&(this.index+=String.fromCodePoint(p).length),p}reconsume(p){p!==void 0&&(this.index-=String.fromCodePoint(p).length)}peek(){const p=[];let y=this.index;for(let b=0;b<3&&y<this.input.length;b++){const C=this.input.codePointAt(y);p.push(C),y+=String.fromCodePoint(C).length}return p}}function R(h){return h===10}function B(h){return R(h)||h===8192||h===32}function I(h){return h>=48&&h<=57}function U(h){return I(h)||h>=65&&h<=70||h>=97&&h<=102}function L(h){return function(p){return function(y){return y>=65&&y<=90}(p)||function(y){return y>=97&&y<=122}(p)}(h)||function(p){return p>=128}(h)||h===95}function J(h){return L(h)||I(h)||h===45}function H(h){return h>=0&&h<=8||h===11||h>=14&&h<=31||h===127}function se(h,p){return h===92&&!R(p)}function W(h,p,y){return h===45?L(p)||p===45||se(p,y):!!L(h)||h===92&&se(h,p)}function pe(h,p,y){return h===43||h===45?I(p)||p===46&&I(y):I(h===46?p:h)}function ne(h){const p=h.consume();if(U(p)){let y=[p];for(;U(...h.peek())&&y.length<5;)y.push(h.consume());B(...h.peek())&&h.consume();const b=parseInt(String.fromCodePoint(...y),16);return b===0||b>1114111?65533:b}return p===void 0?65533:p}function he(h,p){const y=new s("");for(;;){const b=h.consume();if(b===p||b===void 0)return y;if(b===10)return h.reconsume(b),new a;if(b===92){const C=h.peek()[0];C===void 0||(R(C)?h.consume():y.value+=String.fromCodePoint(ne(h)))}else y.value+=String.fromCodePoint(b)}}function oe(h){let p="";for(;;){const y=h.consume();if(J(y))p+=String.fromCodePoint(y);else{if(!se(...h.peek()))return h.reconsume(y),p;p+=String.fromCodePoint(ne(h))}}}function le(h){let p=function(y){let b="integer",C="";for([43,45].includes(y.peek()[0])&&(C+=String.fromCodePoint(y.consume()));I(...y.peek());)C+=String.fromCodePoint(y.consume());if(y.peek()[0]===46&&I(y.peek()[1]))for(C+=String.fromCodePoint(y.consume(),y.consume()),b="number";I(...y.peek());)C+=String.fromCodePoint(y.consume());return[69,101].includes(y.peek()[0])&&([45,43].includes(y.peek()[1])&&I(y.peek()[2])?(C+=String.fromCodePoint(y.consume(),y.consume(),y.consume()),b="number"):I(y.peek()[1])&&(C+=String.fromCodePoint(y.consume(),y.consume()),b="number")),{value:parseFloat(C),type:b}}(h);return W(...h.peek())?new f(p.value,p.type,oe(h)):h.peek()[0]===37?(h.consume(),new d(p.value)):new u(p.value,p.type)}function xe(h){for(;;){const p=h.consume();if(p===41||p===void 0)return;se(...h.peek())&&ne(h)}}function ge(h){const p=oe(h);if(p.match(/url/i)&&h.peek()[0]===40){for(h.consume();B(h.peek()[0])&&B(h.peek()[1]);)h.consume();return[34,39].includes(h.peek()[0])||B(h.peek()[0])&&[34,39].includes(h.peek()[1])?new t(p):function(y){const b=new o("");for(;B(...y.peek());)y.consume();for(;;){const C=y.consume();if(C===41||C===void 0)return b;if(B(C)){for(;B(...y.peek());)y.consume();return y.peek()[0]===41||y.peek()[0]===void 0?(y.consume(),b):(xe(y),new c)}if([34,39,40].includes(C)||H(C))return xe(y),new c;if(C===92){if(!se(...y.peek()))return xe(y),new c;b.value+=ne(y)}else b.value+=String.fromCodePoint(C)}}(h)}return h.peek()[0]===40?(h.consume(),new t(p)):new e(p)}function de(h){const p=h.consume(),y=h.peek();if(B(p)){for(;B(...h.peek());)h.consume();return new m}if(p===34)return he(h,p);if(p===35){if(J(y[0])||se(...y)){const b=new i;return W(...y)&&(b.type="id"),b.value=oe(h),b}return new l(String.fromCodePoint(p))}return p===39?he(h,p):p===40?new M:p===41?new P:p===43?pe(...y)?(h.reconsume(p),le(h)):new l(String.fromCodePoint(p)):p===44?new w:p===45?pe(...h.peek())?(h.reconsume(p),le(h)):h.peek()[0]===45&&h.peek()[1]===62?(h.consume(),h.consume(),new _):W(...h.peek())?(h.reconsume(p),ge(h)):new l(String.fromCodePoint(p)):p===46?pe(...h.peek())?(h.reconsume(p),le(h)):new l(String.fromCodePoint(p)):p===58?new g:p===59?new v:p===60?y[0]===33&&y[1]===45&&y[2]===45?(h.consume(),h.consume(),h.consume(),new x):new l(String.fromCodePoint(p)):p===64?W(...y)?new n(oe(h)):new l(String.fromCodePoint(p)):p===91?new S:p===92?se(...y)?(h.reconsume(p),ge(h)):new l(String.fromCodePoint(p)):p===93?new T:p===123?new E:p===125?new O:I(p)?(h.reconsume(p),le(h)):L(p)?(h.reconsume(p),ge(h)):p===void 0?void 0:new l(String.fromCodePoint(p))}const re=new Set(["px","deg","s","hz","dppx","number","fr"]);function Ze(h){return re.has(h.toLowerCase())}function Ue(h,p){if(["x","y"].includes(h))return h;if(!p)throw new Error("To determine the normalized axis the computedStyle of the source is required.");const y=p.writingMode=="horizontal-tb";if(h==="block")h=y?"y":"x";else{if(h!=="inline")throw new TypeError(`Invalid axis \u201C${h}\u201D`);h=y?"x":"y"}return h}function ke(h){const p=[];let y=0;function b(){let k=0;const z=y;for(;y<h.length;){const D=h.slice(y,y+1);if(/\s/.test(D)&&k===0)break;if(D==="(")k+=1;else if(D===")"&&(k-=1,k===0)){y++;break}y++}return h.slice(z,y)}function C(){for(;/\s/.test(h.slice(y,y+1));)y++}for(;y<h.length;){const k=h.slice(y,y+1);/\s/.test(k)?C():p.push(b())}return p}function lt(h,p){return h.reduce((y,b)=>(y.has(b[p])?y.get(b[p]).push(b):y.set(b[p],[b]),y),new Map)}function De(h,p){const y=[],b=[];for(const C of h)p(C)?y.push(C):b.push(C);return[y,b]}function ve(h,p={}){function y(b){return Array.from(b).map(C=>ve(C,p))}if(h instanceof CSSUnitValue){if(h.unit==="percent"&&p.percentageReference){const C=h.value/100*p.percentageReference.value,k=p.percentageReference.unit;return new CSSUnitValue(C,k)}const b=h.toSum();if(b&&b.values.length===1&&(h=b.values[0]),h instanceof CSSUnitValue&&h.unit==="em"&&p.fontSize&&(h=new CSSUnitValue(h.value*p.fontSize.value,p.fontSize.unit)),h instanceof CSSKeywordValue){if(h.value==="e")return new CSSUnitValue(Math.E,"number");if(h.value==="pi")return new CSSUnitValue(Math.PI,"number")}return h}if(!h.operator)return h;switch(h.operator){case"sum":h=new CSSMathSum(...y(h.values));break;case"product":h=new CSSMathProduct(...y(h.values));break;case"negate":h=new CSSMathNegate(ve(h.value,p));break;case"clamp":h=new CSSMathClamp(ve(h.lower,p),ve(h.value,p),ve(h.upper,p));break;case"invert":h=new CSSMathInvert(ve(h.value,p));break;case"min":h=new CSSMathMin(...y(h.values));break;case"max":h=new CSSMathMax(...y(h.values))}if(h instanceof CSSMathMin||h instanceof CSSMathMax){const b=Array.from(h.values);if(b.every(C=>C instanceof CSSUnitValue&&C.unit!=="percent"&&Ze(C.unit)&&C.unit===b[0].unit)){const C=Math[h.operator].apply(Math,b.map(({value:k})=>k));return new CSSUnitValue(C,b[0].unit)}}if(h instanceof CSSMathMin||h instanceof CSSMathMax){const b=Array.from(h.values),[C,k]=De(b,D=>D instanceof CSSUnitValue&&D.unit!=="percent"),z=Array.from(lt(C,"unit").values());if(z.some(D=>D.length>0)){const D=z.map(N=>{const F=Math[h.operator].apply(Math,N.map(({value:X})=>X));return new CSSUnitValue(F,N[0].unit)});h=h instanceof CSSMathMin?new CSSMathMin(...D,...k):new CSSMathMax(...D,...k)}return b.length===1?b[0]:h}if(h instanceof CSSMathNegate)return h.value instanceof CSSUnitValue?new CSSUnitValue(0-h.value.value,h.value.unit):h.value instanceof CSSMathNegate?h.value.value:h;if(h instanceof CSSMathInvert)return h.value instanceof CSSMathInvert?h.value.value:h;if(h instanceof CSSMathSum){let b=function(k){const z=k.filter(D=>D instanceof CSSUnitValue);return[...k.filter(D=>!(D instanceof CSSUnitValue)),...Array.from(lt(z,"unit").entries()).map(([D,N])=>{const F=N.reduce((X,{value:Z})=>X+Z,0);return new CSSUnitValue(F,D)})]},C=[];for(const k of h.values)k instanceof CSSMathSum?C.push(...k.values):C.push(k);return C=b(C),C.length===1?C[0]:new CSSMathSum(...C)}if(h instanceof CSSMathProduct){let b=[];for(const z of h.values)z instanceof CSSMathProduct?b.push(...z.values):b.push(z);const[C,k]=De(b,z=>z instanceof CSSUnitValue&&z.unit==="number");if(C.length>1){const z=C.reduce((D,{value:N})=>D*N,1);b=[new CSSUnitValue(z,"number"),...k]}if(b.length===2){let z,D;for(const N of b)N instanceof CSSUnitValue&&N.unit==="number"?z=N:N instanceof CSSMathSum&&[...N.values].every(F=>F instanceof CSSUnitValue)&&(D=N);if(z&&D)return new CSSMathSum(...[...D.values].map(N=>new CSSUnitValue(N.value*z.value,N.unit)))}if(b.every(z=>z instanceof CSSUnitValue&&Ze(z.unit)||z instanceof CSSMathInvert&&z.value instanceof CSSUnitValue&&Ze(z.value.unit))){const z=new CSSMathProduct(...b).toSum();if(z&&z.values.length===1)return z.values[0]}return new CSSMathProduct(...b)}return h}const ue=null,ft=["percent","length","angle","time","frequency","resolution","flex"],Re={fontRelativeLengths:{units:new Set(["em","rem","ex","rex","cap","rcap","ch","rch","ic","ric","lh","rlh"])},viewportRelativeLengths:{units:new Set(["vw","lvw","svw","dvw","vh","lvh","svh","dvh","vi","lvi","svi","dvi","vb","lvb","svb","dvb","vmin","lvmin","svmin","dvmin","vmax","lvmax","svmax","dvmax"])},absoluteLengths:{units:new Set(["cm","mm","Q","in","pt","pc","px"]),compatible:!0,canonicalUnit:"px",ratios:{cm:96/2.54,mm:96/2.54/10,Q:96/2.54/40,in:96,pc:16,pt:96/72,px:1}},angle:{units:new Set(["deg","grad","rad","turn"]),compatible:!0,canonicalUnit:"deg",ratios:{deg:1,grad:.9,rad:180/Math.PI,turn:360}},time:{units:new Set(["s","ms"]),compatible:!0,canonicalUnit:"s",ratios:{s:1,ms:.001}},frequency:{units:new Set(["hz","khz"]),compatible:!0,canonicalUnit:"hz",ratios:{hz:1,khz:1e3}},resolution:{units:new Set(["dpi","dpcm","dppx"]),compatible:!0,canonicalUnit:"dppx",ratios:{dpi:1/96,dpcm:2.54/96,dppx:1}}},fe=new Map;for(const h of Object.values(Re))if(h.compatible)for(const p of h.units)fe.set(p,h);function rt(h){return fe.get(h)}function wt(h,p){const y={...h};for(const b of Object.keys(p))y[b]?y[b]+=p[b]:y[b]=p[b];return y}function _t(h){return h==="number"?{}:h==="percent"?{percent:1}:Re.absoluteLengths.units.has(h)||Re.fontRelativeLengths.units.has(h)||Re.viewportRelativeLengths.units.has(h)?{length:1}:Re.angle.units.has(h)?{angle:1}:Re.time.units.has(h)?{time:1}:Re.frequency.units.has(h)?{frequency:1}:Re.resolution.units.has(h)?{resolution:1}:h==="fr"?{flex:1}:ue}function st(h){if(h instanceof CSSUnitValue){let{unit:p,value:y}=h;const b=rt(h.unit);return b&&p!==b.canonicalUnit&&(y*=b.ratios[p],p=b.canonicalUnit),p==="number"?[[y,{}]]:[[y,{[p]:1}]]}if(h instanceof CSSMathInvert){if(!(h.value instanceof CSSUnitValue))throw new Error("Not implemented");const p=st(h.value);if(p===ue||p.length>1)return ue;const y=p[0],b={};for(const[C,k]of Object.entries(y[1]))b[C]=-1*k;return p[0]=[1/y[0],b],p}if(h instanceof CSSMathProduct){let p=[[1,{}]];for(const y of h.values){const b=st(y),C=[];if(b===ue)return ue;for(const k of p)for(const z of b)C.push([k[0]*z[0],wt(k[1],z[1])]);p=C}return p}throw new Error("Not implemented")}function Tt(h,p){if(_t(p)===ue)throw new SyntaxError("The string did not match the expected pattern.");const y=st(h);if(!y)throw new TypeError;if(y.length>1)throw new TypeError("Sum has more than one item");const b=function(C,k){const z=C.unit,D=C.value,N=rt(z),F=rt(k);return!F||N!==F?ue:new CSSUnitValue(D*F.ratios[z]/F.ratios[k],k)}(mt(y[0]),p);if(b===ue)throw new TypeError;return b}function mt(h){const[p,y]=h,b=Object.entries(y);if(b.length>1)return ue;if(b.length===0)return new CSSUnitValue(p,"number");const C=b[0];return C[1]!==1?ue:new CSSUnitValue(p,C[0])}function yt(h,...p){if(p&&p.length)throw new Error("Not implemented");const y=st(h).map(b=>mt(b));if(y.some(b=>b===ue))throw new TypeError("Type error");return new CSSMathSum(...y)}function ut(h,p){if(h.percentHint&&p.percentHint&&h.percentHint!==p.percentHint)return ue;const y={...h,percentHint:h.percentHint??p.percentHint};for(const b of ft)p[b]&&(y[b]??(y[b]=0),y[b]+=p[b]);return y}class Ae{constructor(p,y){Me(this,"name"),Me(this,"values"),this.name=p,this.values=y}}class Ke{constructor(p,y){Me(this,"value"),Me(this,"associatedToken"),this.value=p,this.associatedToken=y}}function ht(h){if(Array.isArray(h))return h;if(typeof h=="string")return function(p){const y=new A(p),b=[];for(;;){const C=de(y);if(C===void 0)return b;b.push(C)}}(h);throw new TypeError("Invalid input type "+typeof h)}function Qe(h){const p=h.shift();return p instanceof E||p instanceof S||p instanceof M?function(y,b){let C;if(b instanceof E)C=O;else if(b instanceof M)C=P;else{if(!(b instanceof S))return;C=T}const k=new Ke([],b);for(;;){const z=y.shift();if(z instanceof C||z===void 0)return k;y.unshift(z),k.value.push(Qe(y))}}(h,p):p instanceof t?function(y,b){const C=new Ae(y.value,[]);for(;;){const k=b.shift();if(k instanceof P||k===void 0)return C;b.unshift(k),C.values.push(Qe(b))}}(p,h):p}function $(h){if(h instanceof M||h instanceof P)return 6;if(h instanceof l)switch(h.value){case"*":case"/":return 4;case"+":case"-":return 2}}function Mt(h){return h[h.length-1]}function jt(h,p,y){const b=["+","-"].includes(h.value)?"ADDITION":"MULTIPLICATION",C=p.type===b?p.values:[p],k=y.type===b?y.values:[y];return h.value==="-"?k[0]={type:"NEGATE",value:k[0]}:h.value==="/"&&(k[0]={type:"INVERT",value:k[0]}),{type:b,values:[...C,...k]}}function Ct(h){if(h.type==="ADDITION")return new CSSMathSum(...h.values.map(p=>Ct(p)));if(h.type==="MULTIPLICATION")return new CSSMathProduct(...h.values.map(p=>Ct(p)));if(h.type==="NEGATE")return new CSSMathNegate(Ct(h.value));if(h.type==="INVERT")return new CSSMathInvert(Ct(h.value));if(h instanceof Ke)return ae(new Ae("calc",h.value));if(h instanceof e){if(h.value==="e")return new CSSUnitValue(Math.E,"number");if(h.value==="pi")return new CSSUnitValue(Math.PI,"number");throw new SyntaxError("Invalid math expression")}return Io(h)}function ae(h){if(h.name==="min"||h.name==="max"){const b=h.values.filter(C=>!(C instanceof m||C instanceof w)).map(C=>ve(ae(new Ae("calc",C))));return h.name==="min"?new CSSMathMin(...b):new CSSMathMax(...b)}if(h.name!=="calc")return null;const p=Ct(function(b){const C=[],k=[];for(;b.length;){const z=b.shift();if(z instanceof u||z instanceof f||z instanceof d||z instanceof Ae||z instanceof Ke||z instanceof e)k.push(z);else if(z instanceof l&&["*","/","+","-"].includes(z.value)){for(;C.length&&!(Mt(C)instanceof M)&&$(Mt(C))>$(z);){const D=C.pop(),N=k.pop(),F=k.pop();k.push(jt(D,F,N))}C.push(z)}else if(z instanceof M)C.push(z);else if(z instanceof P){if(!C.length)return null;for(;!(Mt(C)instanceof M);){const D=C.pop(),N=k.pop(),F=k.pop();k.push(jt(D,F,N))}if(!(Mt(C)instanceof M))return null;C.pop()}else if(!(z instanceof m))return null}for(;C.length;){if(Mt(C)instanceof M)return null;const z=C.pop(),D=k.pop(),N=k.pop();k.push(jt(z,N,D))}return k[0]}([...h.values]));let y;try{y=ve(p)}catch{new CSSStyleSheet().insertRule("error",0)}return y instanceof CSSUnitValue?new CSSMathSum(y):y}function Io(h){return h instanceof Ae&&["calc","min","max","clamp"].includes(h.name)?ae(h):h instanceof u&&h.value===0&&!h.unit?new CSSUnitValue(0,"px"):h instanceof u?new CSSUnitValue(h.value,"number"):h instanceof d?new CSSUnitValue(h.value,"percent"):h instanceof f?new CSSUnitValue(h.value,h.unit):void 0}function Nl(h){const p=function(y){const b=ht(y);for(;b[0]instanceof m;)b.shift();if(b[0]===void 0)return null;const C=Qe(b);for(;b[0]instanceof m;)b.shift();return b[0]===void 0?C:null}(h);return p===null&&new CSSStyleSheet().insertRule("error",0),p instanceof u||p instanceof d||p instanceof f||p instanceof Ae||new CSSStyleSheet().insertRule("error",0),p instanceof f&&_t(p.unit)===null&&new CSSStyleSheet().insertRule("error",0),Io(p)}(function(){let h=new WeakMap;function p(k){const z=[];for(let N=0;N<k.length;N++)z[N]=typeof(D=k[N])=="number"?new CSSUnitValue(D,"number"):D;var D;return z}class y{static parse(z){return z instanceof y?z:ve(Nl(z),{})}}class b extends y{constructor(z,D,N,F){super(),h.set(this,{values:p(z),operator:D,name:N||D,delimiter:F||", "})}get operator(){return h.get(this).operator}get values(){return h.get(this).values}toString(){const z=h.get(this);return`${z.name}(${z.values.join(z.delimiter)})`}}const C={CSSNumericValue:y,CSSMathValue:b,CSSUnitValue:class extends y{constructor(k,z){super(),h.set(this,{value:k,unit:z})}get value(){return h.get(this).value}set value(k){h.get(this).value=k}get unit(){return h.get(this).unit}to(k){return Tt(this,k)}toSum(...k){return yt(this,...k)}type(){return _t(h.get(this).unit)}toString(){const k=h.get(this);return`${k.value}${function(z){switch(z){case"percent":return"%";case"number":return"";default:return z.toLowerCase()}}(k.unit)}`}},CSSKeywordValue:class{constructor(k){this.value=k}toString(){return this.value.toString()}},CSSMathSum:class extends b{constructor(k){super(arguments,"sum","calc"," + ")}},CSSMathProduct:class extends b{constructor(k){super(arguments,"product","calc"," * ")}toSum(...k){return yt(this,...k)}type(){return h.get(this).values.map(k=>k.type()).reduce(ut)}},CSSMathNegate:class extends b{constructor(k){super([arguments[0]],"negate","-")}get value(){return h.get(this).values[0]}type(){return this.value.type()}},CSSMathInvert:class extends b{constructor(k){super([1,arguments[0]],"invert","calc"," / ")}get value(){return h.get(this).values[1]}type(){return function(k){const z={};for(const D of ft)z[D]=-1*k[D];return z}(h.get(this).values[1].type())}},CSSMathMax:class extends b{constructor(){super(arguments,"max")}},CSSMathMin:class extends b{constructor(){super(arguments,"min")}}};if(!window.CSS&&!Reflect.defineProperty(window,"CSS",{value:{}}))throw Error("Error installing CSSOM support");window.CSSUnitValue||["number","percent","em","ex","px","cm","mm","in","pt","pc","Q","vw","vh","vmin","vmax","rems","ch","deg","rad","grad","turn","ms","s","Hz","kHz","dppx","dpi","dpcm","fr"].forEach(k=>{if(!Reflect.defineProperty(CSS,k,{value:z=>new CSSUnitValue(z,k)}))throw Error(`Error installing CSS.${k}`)});for(let[k,z]of Object.entries(C))if(!(k in window)&&!Reflect.defineProperty(window,k,{value:z}))throw Error(`Error installing CSSOM support for ${k}`)})();const Bo="block";let Ge=new WeakMap,Jt=new WeakMap;const tr=["entry","exit","cover","contain","entry-crossing","exit-crossing"];function zo(h){return h===document.scrollingElement?document:h}function dn(h){as(h);let p=Ge.get(h).animations;if(p.length===0)return;let y=h.currentTime;for(let b=0;b<p.length;b++)p[b].tickAnimation(y)}function No(h,p){if(!h)return null;const y=Jt.get(h).sourceMeasurements,b=getComputedStyle(h);let C=y.scrollTop;return Ue(p,b)==="x"&&(C=Math.abs(y.scrollLeft)),C}function os(h,p){const y=ve(h,p);if(y instanceof CSSUnitValue){if(y.unit==="px")return y.value;throw TypeError("Unhandled unit type "+y.unit)}throw TypeError("Unsupported value type: "+typeof h)}function as(h){if(!(h instanceof Rn))return void function(y){const b=Ge.get(y);if(!b.anonymousSource)return;const C=Do(b.anonymousSource,b.anonymousTarget);Qn(y,C)}(h);const p=h.subject;if(!p||getComputedStyle(p).display=="none")return void Qn(h,null);Qn(h,ps(p))}function Uo(h){return["block","inline","x","y"].includes(h)}function cs(h){const p=getComputedStyle(h);return{scrollLeft:h.scrollLeft,scrollTop:h.scrollTop,scrollWidth:h.scrollWidth,scrollHeight:h.scrollHeight,clientWidth:h.clientWidth,clientHeight:h.clientHeight,writingMode:p.writingMode,direction:p.direction,scrollPaddingTop:p.scrollPaddingTop,scrollPaddingBottom:p.scrollPaddingBottom,scrollPaddingLeft:p.scrollPaddingLeft,scrollPaddingRight:p.scrollPaddingRight}}function ls(h,p){if(!h||!p)return;let y=0,b=0,C=p;const k=h.offsetParent;for(;C&&C!=k;)b+=C.offsetLeft,y+=C.offsetTop,C=C.offsetParent;b-=h.offsetLeft+h.clientLeft,y-=h.offsetTop+h.clientTop;const z=getComputedStyle(p);return{top:y,left:b,offsetWidth:p.offsetWidth,offsetHeight:p.offsetHeight,fontSize:z.fontSize}}function nr(h){let p=Jt.get(h);p.sourceMeasurements=cs(h);for(const y of p.timelineRefs){const b=y.deref();b instanceof Rn&&(Ge.get(b).subjectMeasurements=ls(h,b.subject))}p.updateScheduled||(setTimeout(()=>{for(const y of p.timelineRefs){const b=y.deref();b&&dn(b)}p.updateScheduled=!1}),p.updateScheduled=!0)}function Qn(h,p){const y=Ge.get(h),b=y.source;if(b!=p){if(b){const C=Jt.get(b);if(C){C.timelineRefs.delete(h);const k=Array.from(C.timelineRefs).filter(z=>z.deref()===void 0);for(const z of k)C.timelineRefs.delete(z);C.timelineRefs.size===0&&(C.disconnect(),Jt.delete(b))}}if(y.source=p,p){let C=Jt.get(p);if(!C){C={timelineRefs:new Set,sourceMeasurements:cs(p)},Jt.set(p,C);const k=new ResizeObserver(N=>{for(const F of N)nr(y.source)});k.observe(p);for(const N of p.children)k.observe(N);const z=new MutationObserver(N=>{for(const F of N)nr(F.target)});z.observe(p,{attributes:!0,attributeFilter:["style","class"]});const D=()=>{C.sourceMeasurements.scrollLeft=p.scrollLeft,C.sourceMeasurements.scrollTop=p.scrollTop;for(const N of C.timelineRefs){const F=N.deref();F&&dn(F)}};zo(p).addEventListener("scroll",D),C.disconnect=()=>{k.disconnect(),z.disconnect(),zo(p).removeEventListener("scroll",D)}}C.timelineRefs.add(new WeakRef(h))}}}function us(h,p){let y=Ge.get(h).animations;for(let b=0;b<y.length;b++)y[b].animation==p&&y.splice(b,1)}function hs(h,p,y){let b=Ge.get(h).animations;for(let C=0;C<b.length;C++)if(b[C].animation==p)return;b.push({animation:p,tickAnimation:y}),queueMicrotask(()=>{dn(h)})}class $e{constructor(p){if(Ge.set(this,{source:null,axis:Bo,anonymousSource:p?p.anonymousSource:null,anonymousTarget:p?p.anonymousTarget:null,subject:null,inset:null,animations:[],subjectMeasurements:null}),Qn(this,p&&p.source!==void 0?p.source:document.scrollingElement),p&&p.axis!==void 0&&p.axis!=Bo){if(!Uo(p.axis))throw TypeError("Invalid axis");Ge.get(this).axis=p.axis}dn(this)}set source(p){Qn(this,p),dn(this)}get source(){return Ge.get(this).source}set axis(p){if(!Uo(p))throw TypeError("Invalid axis");Ge.get(this).axis=p,dn(this)}get axis(){return Ge.get(this).axis}get duration(){return CSS.percent(100)}get phase(){const p=this.source;if(!p)return"inactive";let y=getComputedStyle(p);return y.display=="none"?"inactive":p==document.scrollingElement||y.overflow!="visible"&&y.overflow!="clip"?"active":"inactive"}get currentTime(){const p=this.source;if(!p||!p.isConnected||this.phase=="inactive")return null;const y=getComputedStyle(p);if(y.display==="inline"||y.display==="none")return null;const b=this.axis,C=No(p,b),k=function(z,D){const N=Jt.get(z).sourceMeasurements,F=getComputedStyle(z).writingMode=="horizontal-tb";return D==="block"?D=F?"y":"x":D==="inline"&&(D=F?"x":"y"),D==="y"?N.scrollHeight-N.clientHeight:D==="x"?N.scrollWidth-N.clientWidth:void 0}(p,b);return k>0?CSS.percent(100*C/k):CSS.percent(100)}get __polyfill(){return!0}}function ds(h,p){let y=h.parentElement;for(;y!=null;){if(p(y))return y;y=y.parentElement}}function Do(h,p){switch(h){case"root":return document.scrollingElement;case"nearest":return ps(p);case"self":return p;default:throw new TypeError("Invalid ScrollTimeline Source Type.")}}function Ul(h){switch(getComputedStyle(h).display){case"block":case"inline-block":case"list-item":case"table":case"table-caption":case"flow-root":case"flex":case"grid":return!0}return!1}function Lo(h){const p=getComputedStyle(h);return p.transform!="none"||p.perspective!="none"||p.willChange=="transform"||p.willChange=="perspective"||p.filter!="none"||p.willChange=="filter"||p.backdropFilter!="none"}function Dl(h){return getComputedStyle(h).position!="static"||Lo(h)}function Ll(h){switch(getComputedStyle(h).position){case"static":case"relative":case"sticky":return ds(h,Ul);case"absolute":return ds(h,Dl);case"fixed":return ds(h,Lo)}}function ps(h){if(h&&h.isConnected){for(;h=Ll(h);)switch(getComputedStyle(h)["overflow-x"]){case"auto":case"scroll":case"hidden":return h==document.body&&getComputedStyle(document.scrollingElement).overflow=="visible"?document.scrollingElement:h}return document.scrollingElement}}function $n(h,p){const y=Ge.get(h),b=y.subjectMeasurements,C=Jt.get(y.source).sourceMeasurements;return h.phase==="inactive"?null:h instanceof Rn?fs(p,C,b,y.axis,y.inset):null}function fs(h,p,y,b,C){const k=p.direction=="rtl"||p.writingMode=="vertical-rl";let z,D,N={fontSize:y.fontSize};Ue(b,p)==="x"?(z=y.offsetWidth,D=y.left,N.scrollPadding=[p.scrollPaddingLeft,p.scrollPaddingRight],k&&(D+=p.scrollWidth-p.clientWidth,N.scrollPadding=[p.scrollPaddingRight,p.scrollPaddingLeft]),N.containerSize=p.clientWidth):(z=y.offsetHeight,D=y.top,N.scrollPadding=[p.scrollPaddingTop,p.scrollPaddingBottom],N.containerSize=p.clientHeight);const F=function(vs,ar){const Kl={start:0,end:0};if(!vs)return Kl;const[Ql,$l]=[vs.start,vs.end].map((ea,ta)=>ea==="auto"?ar.scrollPadding[ta]==="auto"?0:parseFloat(ar.scrollPadding[ta]):os(ea,{percentageReference:CSS.px(ar.containerSize),fontSize:CSS.px(parseFloat(ar.fontSize))}));return{start:Ql,end:$l}}(C,N),X=D-N.containerSize+F.end,Z=D+z-F.start,K=X+z,me=Z-z,_e=Math.min(K,me),ot=Math.max(K,me);let Pt,gt;const $o=z>N.containerSize-F.start-F.end;switch(h){case"cover":Pt=X,gt=Z;break;case"contain":Pt=_e,gt=ot;break;case"entry":Pt=X,gt=_e;break;case"exit":Pt=ot,gt=Z;break;case"entry-crossing":Pt=X,gt=$o?ot:_e;break;case"exit-crossing":Pt=$o?_e:ot,gt=Z}return{start:Pt,end:gt}}function Fo(h,p){if(h instanceof Rn){const{rangeName:y,offset:b}=p;return Vo($n(h,y),b,$n(h,"cover"),h.subject)}if(h instanceof $e){const{axis:y,source:b}=h,{sourceMeasurements:C}=Jt.get(b);let k;return k=Ue(y,C)==="x"?C.scrollWidth-C.clientWidth:C.scrollHeight-C.clientHeight,os(p,{percentageReference:CSS.px(k)})/k}unsupportedTimeline(h)}function Vo(h,p,y,b){if(!h||!y)return 0;let C=getComputedStyle(b);return(os(p,{percentageReference:CSS.px(h.end-h.start),fontSize:CSS.px(parseFloat(C.fontSize))})+h.start-y.start)/(y.end-y.start)}let Rn=class extends $e{constructor(h){super(h);const p=Ge.get(this);p.subject=h&&h.subject?h.subject:void 0,h&&h.inset&&(p.inset=function(y){if(!y)return{start:0,end:0};let b;if(b=typeof y=="string"?ke(y).map(C=>{if(C==="auto")return"auto";try{return CSSNumericValue.parse(C)}catch{throw TypeError(`Could not parse inset "${y}"`)}}):Array.isArray(y)?y:[y],b.length===0||b.length>2)throw TypeError("Invalid inset");for(const C of b){if(C==="auto")continue;const k=C.type();if(k.length!==1&&k.percent!==1)throw TypeError("Invalid inset")}return{start:b[0],end:b[1]??b[0]}}(h.inset)),p.subject&&(new ResizeObserver(()=>{nr(p.source)}).observe(p.subject),new MutationObserver(()=>{nr(p.source)}).observe(p.subject,{attributes:!0,attributeFilter:["class","style"]})),as(this),p.subjectMeasurements=ls(p.source,p.subject),dn(this)}get source(){return as(this),Ge.get(this).source}set source(h){throw new Error("Cannot set the source of a view timeline")}get subject(){return Ge.get(this).subject}get axis(){return Ge.get(this).axis}get currentTime(){const h=No(this.source,this.axis);if(h==null)return null;const p=$n(this,"cover");if(!p)return null;const y=(h-p.start)/(p.end-p.start);return CSS.percent(100*y)}get startOffset(){return CSS.px($n(this,"cover").start)}get endOffset(){return CSS.px($n(this,"cover").end)}};const Fl=document.getAnimations,Vl=window.Element.prototype.getAnimations,jl=window.Element.prototype.animate,jo=window.Animation;class An{constructor(){this.state="pending",this.nativeResolve=this.nativeReject=null,this.promise=new Promise((p,y)=>{this.nativeResolve=p,this.nativeReject=y})}resolve(p){this.state="resolved",this.nativeResolve(p)}reject(p){this.state="rejected",this.promise.catch(()=>{}),this.nativeReject(p)}}function ei(h){h.readyPromise=new An,requestAnimationFrame(()=>{var p;(((p=h.timeline)==null?void 0:p.currentTime)??null)!==null&&(ir(h),h.pendingTask!=="play"||h.startTime===null&&h.holdTime===null?h.pendingTask==="pause"&&Wo(h):Go(h))})}function Jo(){return new DOMException("The user aborted a request","AbortError")}function pn(h,p){if(p===null)return p;if(typeof p!="number")throw new DOMException(`Unexpected value: ${p}. Cannot convert to CssNumberish`,"InvalidStateError");const y=h.rangeDuration??100,b=Wt(h),C=b?y*p/b:0;return CSS.percent(C)}function Se(h,p){if(h.timeline){if(p===null)return p;if(p.unit==="percent"){const y=h.rangeDuration??100,b=Wt(h);return p.value*b/y}throw new DOMException("CSSNumericValue must be a percentage for progress based animations.","NotSupportedError")}{if(p==null||typeof p=="number")return p;const y=p.to("ms");if(y)return y.value;throw new DOMException("CSSNumericValue must be either a number or a time value for time based animations.","InvalidStateError")}}function Go(h){const p=Se(h,h.timeline.currentTime);if(h.holdTime!=null)Bt(h),h.animation.playbackRate==0?h.startTime=p:(h.startTime=p-h.holdTime/h.animation.playbackRate,h.holdTime=null);else if(h.startTime!==null&&h.pendingPlaybackRate!==null){const y=(p-h.startTime)*h.animation.playbackRate;Bt(h);const b=h.animation.playbackRate;b==0?(h.holdTime=null,h.startTime=p):h.startTime=p-y/b}h.readyPromise&&h.readyPromise.state=="pending"&&h.readyPromise.resolve(h.proxy),Gt(h,!1,!1),Ht(h),h.pendingTask=null}function Wo(h){const p=Se(h,h.timeline.currentTime);h.startTime!=null&&h.holdTime==null&&(h.holdTime=(p-h.startTime)*h.animation.playbackRate),Bt(h),h.startTime=null,h.readyPromise.resolve(h.proxy),Gt(h,!1,!1),Ht(h),h.pendingTask=null}function Ho(h){if(!h.finishedPromise||h.finishedPromise.state!="pending"||h.proxy.playState!="finished")return;h.finishedPromise.resolve(h.proxy),h.animation.pause();const p=new CustomEvent("finish",{detail:{currentTime:h.proxy.currentTime,timelineTime:h.proxy.timeline.currentTime}});Object.defineProperty(p,"currentTime",{get:function(){return this.detail.currentTime}}),Object.defineProperty(p,"timelineTime",{get:function(){return this.detail.timelineTime}}),requestAnimationFrame(()=>{queueMicrotask(()=>{h.animation.dispatchEvent(p)})})}function On(h){return h.pendingPlaybackRate!==null?h.pendingPlaybackRate:h.animation.playbackRate}function Bt(h){h.pendingPlaybackRate!==null&&(h.animation.playbackRate=h.pendingPlaybackRate,h.pendingPlaybackRate=null)}function qo(h){if(!h.timeline)return null;const p=Se(h,h.timeline.currentTime);if(p===null||h.startTime===null)return null;let y=(p-h.startTime)*h.animation.playbackRate;return y==-0&&(y=0),y}function Gt(h,p,y){if(!h.timeline)return;let b=p?Se(h,h.proxy.currentTime):qo(h);if(b&&h.startTime!=null&&!h.proxy.pending){const C=On(h),k=Wt(h);let z=h.previousCurrentTime;C>0&&b>=k&&h.previousCurrentTime!=null?((z===null||z<k)&&(z=k),h.holdTime=p?b:z):C<0&&b<=0?((z==null||z>0)&&(z=0),h.holdTime=p?b:z):C!=0&&(p&&h.holdTime!==null&&(h.startTime=function(D,N){if(!D.timeline)return null;const F=Se(D,D.timeline.currentTime);return F==null?null:F-N/D.animation.playbackRate}(h,h.holdTime)),h.holdTime=null)}Ht(h),h.previousCurrentTime=Se(h,h.proxy.currentTime),h.proxy.playState=="finished"?(h.finishedPromise||(h.finishedPromise=new An),h.finishedPromise.state=="pending"&&(y?Ho(h):Promise.resolve().then(()=>{Ho(h)}))):(h.finishedPromise&&h.finishedPromise.state=="resolved"&&(h.finishedPromise=new An),h.animation.playState!="paused"&&h.animation.pause())}function Wt(h){const p=function(b){const C=b.proxy.effect.getTiming();return b.normalizedTiming||C}(h),y=p.delay+p.endDelay+p.iterations*p.duration;return Math.max(0,y)}function Ht(h){if(h.timeline)if(h.startTime!==null){const p=h.timeline.currentTime;if(p==null)return;ms(h,(Se(h,p)-h.startTime)*h.animation.playbackRate)}else h.holdTime!==null&&ms(h,h.holdTime)}function ms(h,p){const y=h.timeline,b=h.animation.playbackRate,C=y.currentTime&&y.currentTime.value==(b<0?0:100)?b<0?.001:-.001:0;h.animation.currentTime=p+C}function ys(h,p){if(!h.timeline)return;const y=h.proxy.playState=="paused"&&h.proxy.pending;let b=!1,C=Se(h,h.proxy.currentTime);On(h)==0&&C==null&&(h.holdTime=0),C==null&&(h.autoAlignStartTime=!0),(h.proxy.playState==="finished"||y)&&(h.holdTime=null,h.startTime=null,h.autoAlignStartTime=!0),h.holdTime&&(h.startTime=null),h.pendingTask&&(h.pendingTask=null,b=!0),(h.holdTime!==null||h.autoAlignStartTime||y||h.pendingPlaybackRate!==null)&&(h.readyPromise&&!b&&(h.readyPromise=null),Ht(h),h.readyPromise||ei(h),h.pendingTask="play",hs(h.timeline,h.animation,gs.bind(h.proxy)),Gt(h,!1,!1))}function gs(h){const p=Y.get(this);if(!p)return;if(h==null)return void(p.proxy.playState!=="paused"&&p.animation.playState!="idle"&&p.animation.cancel());ir(p),p.pendingTask&&requestAnimationFrame(()=>{p.pendingTask!=="play"||p.startTime===null&&p.holdTime===null?p.pendingTask==="pause"&&Wo(p):Go(p)});const y=this.playState;if(y=="running"||y=="finished"){const b=Se(p,h);ms(p,(b-Se(p,this.startTime))*this.playbackRate),Gt(p,!1,!1)}}function Xo(h){h.specifiedTiming=null}let Y=new WeakMap;window.addEventListener("pagehide",h=>{Y=new WeakMap},!1);let Yo=new WeakMap;function ir(h){if(!h.autoAlignStartTime||!h.timeline||!h.timeline.currentTime||h.proxy.playState==="idle"||h.proxy.playState==="paused"&&h.holdTime!==null)return;const p=h.rangeDuration;let y,b;try{y=CSS.percent(100*function(k){if(!k.animationRange)return 0;const z=k.animationRange.start==="normal"?Zo(k.timeline):k.animationRange.start;return Fo(k.timeline,z)}(h))}catch(k){y=CSS.percent(0),h.animationRange.start="normal",console.warn("Exception when calculating start offset",k)}try{b=CSS.percent(100*(1-function(k){if(!k.animationRange)return 0;const z=k.animationRange.end==="normal"?Ko(k.timeline):k.animationRange.end;return 1-Fo(k.timeline,z)}(h)))}catch(k){b=CSS.percent(100),h.animationRange.end="normal",console.warn("Exception when calculating end offset",k)}h.rangeDuration=b.value-y.value;const C=On(h);h.startTime=Se(h,C>=0?y:b),h.holdTime=null,h.rangeDuration!==p&&Xo(h)}function rr(h){throw new Error("Unsupported timeline class")}function Zo(h){return h instanceof ViewTimeline?{rangeName:"cover",offset:CSS.percent(0)}:h instanceof $e?CSS.percent(0):void rr()}function Ko(h){return h instanceof ViewTimeline?{rangeName:"cover",offset:CSS.percent(100)}:h instanceof $e?CSS.percent(100):void rr()}function Jl(h,p){if(!p)return{start:"normal",end:"normal"};const y={start:Zo(h),end:Ko(h)};if(h instanceof ViewTimeline){const b=ke(p),C=[],k=[];if(b.forEach(z=>{if(tr.includes(z))C.push(z);else try{k.push(CSSNumericValue.parse(z))}catch{throw TypeError(`Could not parse range "${p}"`)}}),C.length>2||k.length>2||k.length==1)throw TypeError("Invalid time range or unsupported time range format.");return C.length&&(y.start.rangeName=C[0],y.end.rangeName=C.length>1?C[1]:C[0]),k.length>1&&(y.start.offset=k[0],y.end.offset=k[1]),y}if(h instanceof $e){const b=p.split(" ");if(b.length!=2)throw TypeError("Invalid time range or unsupported time range format.");return y.start=CSSNumericValue.parse(b[0]),y.end=CSSNumericValue.parse(b[1]),y}rr()}function sr(h,p,y){if(!p||p==="normal")return"normal";if(h instanceof ViewTimeline){let b="cover",C=y==="start"?CSS.percent(0):CSS.percent(100);if(p instanceof Object)p.rangeName!==void 0&&(b=p.rangeName),p.offset!==void 0&&(C=p.offset);else{const k=ke(p);k.length===1?tr.includes(k[0])?b=k[0]:C=ve(CSSNumericValue.parse(k[0]),{}):k.length===2&&(b=k[0],C=ve(CSSNumericValue.parse(k[1]),{}))}if(!tr.includes(b))throw TypeError("Invalid range name");return{rangeName:b,offset:C}}if(h instanceof $e)return CSSNumericValue.parse(p);rr()}class or{constructor(p,y,b={}){const C=y instanceof $e,k=p instanceof jo?p:new jo(p,C?void 0:y);Yo.set(k,this),Y.set(this,{animation:k,timeline:C?y:void 0,playState:C?"idle":null,readyPromise:null,finishedPromise:null,startTime:null,holdTime:null,rangeDuration:null,previousCurrentTime:null,autoAlignStartTime:!1,pendingPlaybackRate:null,pendingTask:null,specifiedTiming:null,normalizedTiming:null,effect:null,animationRange:C?Jl(y,b["animation-range"]):null,proxy:this})}get effect(){const p=Y.get(this);return p.timeline?(p.effect||(p.effect=function(y){const b=y.animation.effect,C=b.updateTiming,k={apply:function(F){b.getTiming();const X=F.apply(b);if(y.timeline){const Z=y.duration??100;X.localTime=pn(y,X.localTime),X.endTime=pn(y,X.endTime),X.activeDuration=pn(y,X.activeDuration);const K=Wt(y),me=X.iterations?(K-X.delay-X.endDelay)/X.iterations:0;X.duration=K?CSS.percent(Z*me/K):CSS.percent(0),y.timeline.currentTime===void 0&&(X.localTime=null)}return X}},z={apply:function(F,X){if(y.specifiedTiming)return y.specifiedTiming;y.specifiedTiming=F.apply(b);let Z,K=Object.assign({},y.specifiedTiming);if(K.duration===1/0)throw TypeError("Effect duration cannot be Infinity when used with Scroll Timelines");return(K.duration===null||K.duration==="auto"||y.autoDurationEffect)&&y.timeline&&(y.autoDurationEffect=!0,K.delay=0,K.endDelay=0,Z=K.iterations?1e5:0,K.duration=K.iterations?(Z-K.delay-K.endDelay)/K.iterations:0,K.duration<0&&(K.duration=0,K.endDelay=Z-K.delay),C.apply(b,[K])),y.normalizedTiming=K,y.specifiedTiming}},D={apply:function(F,X,Z){if(Z&&Z.length){if(y.timeline&&Z[0]){const K=Z[0],me=K.duration;if(me===1/0)throw TypeError("Effect duration cannot be Infinity when used with Scroll Timelines");if(K.iterations===1/0)throw TypeError("Effect iterations cannot be Infinity when used with Scroll Timelines");me!==void 0&&me!=="auto"&&(y.autoDurationEffect=null)}y.specifiedTiming&&F.apply(b,[y.specifiedTiming]),F.apply(b,Z),Xo(y)}}},N=new Proxy(b,{get:function(F,X){const Z=F[X];return typeof Z=="function"?Z.bind(b):Z},set:function(F,X,Z){return F[X]=Z,!0}});return N.getComputedTiming=new Proxy(b.getComputedTiming,k),N.getTiming=new Proxy(b.getTiming,z),N.updateTiming=new Proxy(b.updateTiming,D),N}(p)),p.effect):p.animation.effect}set effect(p){const y=Y.get(this);y.animation.effect=p,y.effect=null,y.autoDurationEffect=null}get timeline(){const p=Y.get(this);return p.timeline||p.animation.timeline}set timeline(p){const y=Y.get(this),b=this.timeline;if(b==p)return;const C=this.playState,k=this.currentTime;let z,D=Wt(y);z=k===null?null:D===0?0:Se(y,k)/D;const N=b instanceof $e,F=p instanceof $e,X=this.pending;if(N&&us(y.timeline,y.animation),F)return y.timeline=p,Bt(y),y.autoAlignStartTime=!0,y.startTime=null,y.holdTime=null,C!=="running"&&C!=="finished"||(y.readyPromise&&y.readyPromise.state!=="resolved"||ei(y),y.pendingTask="play",hs(y.timeline,y.animation,gs.bind(this))),C==="paused"&&z!==null&&(y.holdTime=z*D),X&&(y.readyPromise&&y.readyPromise.state!="resolved"||ei(y),y.pendingTask=C=="paused"?"pause":"play"),y.startTime!==null&&(y.holdTime=null),void Gt(y,!1,!1);if(y.animation.timeline!=p)throw TypeError("Unsupported timeline: "+p);if(us(y.timeline,y.animation),y.timeline=null,N)switch(k!==null&&(y.animation.currentTime=z*Wt(y)),C){case"paused":y.animation.pause();break;case"running":case"finished":y.animation.play()}}get startTime(){const p=Y.get(this);return p.timeline?pn(p,p.startTime):p.animation.startTime}set startTime(p){const y=Y.get(this);if(p=Se(y,p),!y.timeline)return void(y.animation.startTime=p);y.autoAlignStartTime=!1,Se(y,y.timeline.currentTime)==null&&y.startTime!=null&&(y.holdTime=null,Ht(y));const b=Se(y,this.currentTime);Bt(y),y.startTime=p,y.startTime!==null&&y.animation.playbackRate!=0?y.holdTime=null:y.holdTime=b,y.pendingTask&&(y.pendingTask=null,y.readyPromise.resolve(this)),Gt(y,!0,!1),Ht(y)}get currentTime(){const p=Y.get(this);return p.timeline?p.holdTime!=null?pn(p,p.holdTime):pn(p,qo(p)):p.animation.currentTime}set currentTime(p){const y=Y.get(this);y.timeline?(function(b,C){if(C==null&&b.currentTime!==null)throw new TypeError;C=Se(b,C),b.autoAlignStartTime=!1,b.holdTime!==null||b.startTime===null||b.timeline.phase==="inactive"||b.animation.playbackRate===0?b.holdTime=C:b.startTime=Se(b,b.timeline.currentTime)-C/b.animation.playbackRate,b.timeline.phase==="inactive"&&(b.startTime=null),b.previousCurrentTime=null}(y,p),y.pendingTask=="pause"&&(y.holdTime=Se(y,p),Bt(y),y.startTime=null,y.pendingTask=null,y.readyPromise.resolve(this)),Gt(y,!0,!1)):y.animation.currentTime=p}get playbackRate(){return Y.get(this).animation.playbackRate}set playbackRate(p){const y=Y.get(this);if(!y.timeline)return void(y.animation.playbackRate=p);y.pendingPlaybackRate=null;const b=this.currentTime;y.animation.playbackRate=p,b!==null&&(this.currentTime=b)}get playState(){const p=Y.get(this);if(!p.timeline)return p.animation.playState;const y=Se(p,this.currentTime);return y===null&&p.startTime===null&&p.pendingTask==null?"idle":p.pendingTask=="pause"||p.startTime===null&&p.pendingTask!="play"?"paused":y!=null&&(p.animation.playbackRate>0&&y>=Wt(p)||p.animation.playbackRate<0&&y<=0)?"finished":"running"}get rangeStart(){var p;return((p=Y.get(this).animationRange)==null?void 0:p.start)??"normal"}set rangeStart(p){const y=Y.get(this);if(!y.timeline)return y.animation.rangeStart=p;y.timeline instanceof $e&&(y.animationRange.start=sr(y.timeline,p,"start"),ir(y),Ht(y))}get rangeEnd(){var p;return((p=Y.get(this).animationRange)==null?void 0:p.end)??"normal"}set rangeEnd(p){const y=Y.get(this);if(!y.timeline)return y.animation.rangeEnd=p;y.timeline instanceof $e&&(y.animationRange.end=sr(y.timeline,p,"end"),ir(y),Ht(y))}get replaceState(){return Y.get(this).animation.pending}get pending(){const p=Y.get(this);return p.timeline?!!p.readyPromise&&p.readyPromise.state=="pending":p.animation.pending}finish(){const p=Y.get(this);if(!p.timeline)return void p.animation.finish();const y=On(p),b=Wt(p);if(y==0)throw new DOMException("Cannot finish Animation with a playbackRate of 0.","InvalidStateError");if(y>0&&b==1/0)throw new DOMException("Cannot finish Animation with an infinite target effect end.","InvalidStateError");Bt(p);const C=y<0?0:b;this.currentTime=pn(p,C);const k=Se(p,p.timeline.currentTime);p.startTime===null&&k!==null&&(p.startTime=k-C/p.animation.playbackRate),p.pendingTask=="pause"&&p.startTime!==null&&(p.holdTime=null,p.pendingTask=null,p.readyPromise.resolve(this)),p.pendingTask=="play"&&p.startTime!==null&&(p.pendingTask=null,p.readyPromise.resolve(this)),Gt(p,!0,!0)}play(){const p=Y.get(this);p.timeline?ys(p):p.animation.play()}pause(){const p=Y.get(this);p.timeline?this.playState!="paused"&&(p.animation.currentTime===null&&(p.autoAlignStartTime=!0),p.pendingTask=="play"?p.pendingTask=null:p.readyPromise=null,p.readyPromise||ei(p),p.pendingTask="pause",hs(p.timeline,p.animation,gs.bind(p.proxy))):p.animation.pause()}reverse(){const p=Y.get(this),y=On(p),b=Se(p,this.currentTime),C=Wt(p)==1/0,k=y!=0&&(y<0||b>0||!C);if(!p.timeline||!k)return k&&(p.pendingPlaybackRate=-On(p)),void p.animation.reverse();if(p.timeline.phase=="inactive")throw new DOMException("Cannot reverse an animation with no active timeline","InvalidStateError");this.updatePlaybackRate(-y),ys(p)}updatePlaybackRate(p){const y=Y.get(this);if(y.pendingPlaybackRate=p,!y.timeline)return void y.animation.updatePlaybackRate(p);const b=this.playState;if(!y.readyPromise||y.readyPromise.state!="pending")switch(b){case"idle":case"paused":Bt(y);break;case"finished":const C=Se(y,y.timeline.currentTime),k=C!==null?(C-y.startTime)*y.animation.playbackRate:null;y.startTime=p==0?C:C!=null&&k!=null?(C-k)/p:null,Bt(y),Gt(y,!1,!1),Ht(y);break;default:ys(y)}}persist(){Y.get(this).animation.persist()}get id(){return Y.get(this).animation.id}set id(p){Y.get(this).animation.id=p}cancel(){const p=Y.get(this);p.timeline?(this.playState!="idle"&&(function(y){y.pendingTask&&(y.pendingTask=null,Bt(y),y.readyPromise.reject(Jo()),ei(y),y.readyPromise.resolve(y.proxy))}(p),p.finishedPromise&&p.finishedPromise.state=="pending"&&p.finishedPromise.reject(Jo()),p.finishedPromise=new An,p.animation.cancel()),p.startTime=null,p.holdTime=null,us(p.timeline,p.animation)):p.animation.cancel()}get onfinish(){return Y.get(this).animation.onfinish}set onfinish(p){Y.get(this).animation.onfinish=p}get oncancel(){return Y.get(this).animation.oncancel}set oncancel(p){Y.get(this).animation.oncancel=p}get onremove(){return Y.get(this).animation.onremove}set onremove(p){Y.get(this).animation.onremove=p}get finished(){const p=Y.get(this);return p.timeline?(p.finishedPromise||(p.finishedPromise=new An),p.finishedPromise.promise):p.animation.finished}get ready(){const p=Y.get(this);return p.timeline?(p.readyPromise||(p.readyPromise=new An,p.readyPromise.resolve(this)),p.readyPromise.promise):p.animation.ready}addEventListener(p,y,b){Y.get(this).animation.addEventListener(p,y,b)}removeEventListener(p,y,b){Y.get(this).animation.removeEventListener(p,y,b)}dispatchEvent(p){Y.get(this).animation.dispatchEvent(p)}}function Gl(h,p){const y=p.timeline;y instanceof $e&&delete p.timeline;const b=jl.apply(this,[h,p]),C=new or(b,y);return y instanceof $e&&(b.pause(),Y.get(C).animationRange={start:sr(y,p.rangeStart,"start"),end:sr(y,p.rangeEnd,"end")},C.play()),C}function Qo(h){for(let p=0;p<h.length;++p){let y=Yo.get(h[p]);y&&(h[p]=y)}return h}function Wl(h){return Qo(Vl.apply(this,[h]))}function Hl(h){return Qo(Fl.apply(this,[h]))}const Oe={IDENTIFIER:/[\w\\\@_-]+/g,WHITE_SPACE:/\s*/g,TIME:/^[0-9]+(s|ms)/,SCROLL_TIMELINE:/scroll-timeline\s*:([^;}]+)/,SCROLL_TIMELINE_NAME:/scroll-timeline-name\s*:([^;}]+)/,SCROLL_TIMELINE_AXIS:/scroll-timeline-axis\s*:([^;}]+)/,VIEW_TIMELINE:/view-timeline\s*:([^;}]+)/,VIEW_TIMELINE_NAME:/view-timeline-name\s*:([^;}]+)/,VIEW_TIMELINE_AXIS:/view-timeline-axis\s*:([^;}]+)/,VIEW_TIMELINE_INSET:/view-timeline-inset\s*:([^;}]+)/,ANIMATION_TIMELINE:/animation-timeline\s*:([^;}]+)/,ANIMATION_TIME_RANGE:/animation-range\s*:([^;}]+)/,ANIMATION_NAME:/animation-name\s*:([^;}]+)/,ANIMATION:/animation\s*:([^;}]+)/,ANONYMOUS_SCROLL_TIMELINE:/scroll\(([^)]*)\)/,ANONYMOUS_VIEW_TIMELINE:/view\(([^)]*)\)/},In=["block","inline","x","y"],ql=["nearest","root","self"],tn=new class{constructor(){this.cssRulesWithTimelineName=[],this.nextAnonymousTimelineNameIndex=0,this.anonymousScrollTimelineOptions=new Map,this.anonymousViewTimelineOptions=new Map,this.sourceSelectorToScrollTimeline=[],this.subjectSelectorToViewTimeline=[],this.keyframeNamesSelectors=new Map}transpileStyleSheet(h,p,y){const b={sheetSrc:h,index:0,name:y};for(;b.index<b.sheetSrc.length&&(this.eatWhitespace(b),!(b.index>=b.sheetSrc.length));){if(this.lookAhead("/*",b)){for(;this.lookAhead("/*",b);)this.eatComment(b),this.eatWhitespace(b);continue}const C=this.parseQualifiedRule(b);C&&(p?this.parseKeyframesAndSaveNameMapping(C,b):this.handleScrollTimelineProps(C,b))}return b.sheetSrc}getAnimationTimelineOptions(h,p){for(let y=this.cssRulesWithTimelineName.length-1;y>=0;y--){const b=this.cssRulesWithTimelineName[y];try{if(p.matches(b.selector)&&(!b["animation-name"]||b["animation-name"]==h))return{"animation-timeline":b["animation-timeline"],"animation-range":b["animation-range"]}}catch{}}return null}getAnonymousScrollTimelineOptions(h,p){const y=this.anonymousScrollTimelineOptions.get(h);return y?{anonymousSource:y.source,anonymousTarget:p,source:Do(y.source??"nearest",p),axis:y.axis?y.axis:"block"}:null}getScrollTimelineOptions(h,p){const y=this.getAnonymousScrollTimelineOptions(h,p);if(y)return y;for(let b=this.sourceSelectorToScrollTimeline.length-1;b>=0;b--){const C=this.sourceSelectorToScrollTimeline[b];if(C.name==h){const k=this.findPreviousSiblingOrAncestorMatchingSelector(p,C.selector);if(k)return{source:k,...C.axis?{axis:C.axis}:{}}}}return null}findPreviousSiblingOrAncestorMatchingSelector(h,p){let y=h;for(;y;){if(y.matches(p))return y;y=y.previousElementSibling||y.parentElement}return null}getAnonymousViewTimelineOptions(h,p){const y=this.anonymousViewTimelineOptions.get(h);return y?{subject:p,axis:y.axis?y.axis:"block",inset:y.inset?y.inset:"auto"}:null}getViewTimelineOptions(h,p){const y=this.getAnonymousViewTimelineOptions(h,p);if(y)return y;for(let b=this.subjectSelectorToViewTimeline.length-1;b>=0;b--){const C=this.subjectSelectorToViewTimeline[b];if(C.name==h){const k=this.findPreviousSiblingOrAncestorMatchingSelector(p,C.selector);if(k)return{subject:k,axis:C.axis,inset:C.inset}}}return null}handleScrollTimelineProps(h,p){if(h.selector.includes("@keyframes"))return;const y=h.block.contents.includes("animation-name:"),b=h.block.contents.includes("animation-timeline:"),C=h.block.contents.includes("animation:");if(this.saveSourceSelectorToScrollTimeline(h),this.saveSubjectSelectorToViewTimeline(h),!b&&!y&&!C)return;let k=[],z=[],D=!1;b&&(k=this.extractScrollTimelineNames(h.block.contents)),y&&(z=this.extractMatches(h.block.contents,Oe.ANIMATION_NAME)),b&&y||(C&&this.extractMatches(h.block.contents,Oe.ANIMATION).forEach(N=>{const F=this.extractAnimationName(N);F&&b&&z.push(F),b&&(this.hasDuration(N)||(this.hasAutoDuration(N)&&(h.block.contents=h.block.contents.replace("auto"," ")),h.block.contents=h.block.contents.replace(N," 1s "+N),D=!0))}),D&&this.replacePart(h.block.startIndex,h.block.endIndex,h.block.contents,p)),this.saveRelationInList(h,k,z)}saveSourceSelectorToScrollTimeline(h){const p=h.block.contents.includes("scroll-timeline:"),y=h.block.contents.includes("scroll-timeline-name:"),b=h.block.contents.includes("scroll-timeline-axis:");if(!p&&!y)return;let C=[];if(p){const z=this.extractMatches(h.block.contents,Oe.SCROLL_TIMELINE);for(const D of z){const N=this.split(D);let F={selector:h.selector,name:""};N.length==1?F.name=N[0]:N.length==2&&(In.includes(N[0])?(F.axis=N[0],F.name=N[1]):(F.axis=N[1],F.name=N[0])),C.push(F)}}if(y){const z=this.extractMatches(h.block.contents,Oe.SCROLL_TIMELINE_NAME);for(let D=0;D<z.length;D++)if(D<C.length)C[D].name=z[D];else{let N={selector:h.selector,name:z[D]};C.push(N)}}let k=[];if(b){const z=this.extractMatches(h.block.contents,Oe.SCROLL_TIMELINE_AXIS);if(k=z.filter(D=>In.includes(D)),k.length!=z.length)throw new Error("Invalid axis")}for(let z=0;z<C.length;z++)k.length&&(C[z].axis=k[z%C.length]);this.sourceSelectorToScrollTimeline.push(...C)}saveSubjectSelectorToViewTimeline(h){const p=h.block.contents.includes("view-timeline:"),y=h.block.contents.includes("view-timeline-name:"),b=h.block.contents.includes("view-timeline-axis:"),C=h.block.contents.includes("view-timeline-inset:");if(!p&&!y)return;let k=[];if(p){const N=this.extractMatches(h.block.contents,Oe.VIEW_TIMELINE);for(let F of N){const X=this.split(F);let Z={selector:h.selector,name:"",inset:null};X.length==1?Z.name=X[0]:X.length==2&&(In.includes(X[0])?(Z.axis=X[0],Z.name=X[1]):(Z.axis=X[1],Z.name=X[0])),k.push(Z)}}if(y){const N=this.extractMatches(h.block.contents,Oe.VIEW_TIMELINE_NAME);for(let F=0;F<N.length;F++)if(F<k.length)k[F].name=N[F];else{let X={selector:h.selector,name:N[F],inset:null};k.push(X)}}let z=[],D=[];if(C&&(z=this.extractMatches(h.block.contents,Oe.VIEW_TIMELINE_INSET)),b){const N=this.extractMatches(h.block.contents,Oe.VIEW_TIMELINE_AXIS);if(D=N.filter(F=>In.includes(F)),D.length!=N.length)throw new Error("Invalid axis")}for(let N=0;N<k.length;N++)z.length&&(k[N].inset=z[N%k.length]),D.length&&(k[N].axis=D[N%k.length]);this.subjectSelectorToViewTimeline.push(...k)}hasDuration(h){return h.split(" ").filter(p=>{return y=p,Oe.TIME.exec(y);var y}).length>=1}hasAutoDuration(h){return h.split(" ").filter(p=>p==="auto").length>=1}saveRelationInList(h,p,y){let b=[];h.block.contents.includes("animation-range:")&&(b=this.extractMatches(h.block.contents,Oe.ANIMATION_TIME_RANGE));const C=Math.max(p.length,y.length,b.length);for(let k=0;k<C;k++)this.cssRulesWithTimelineName.push({selector:h.selector,"animation-timeline":p[k%p.length],...y.length?{"animation-name":y[k%y.length]}:{},...b.length?{"animation-range":b[k%b.length]}:{}})}extractScrollTimelineNames(h){const p=Oe.ANIMATION_TIMELINE.exec(h)[1].trim(),y=[];return p.split(",").map(b=>b.trim()).forEach(b=>{if(function(C){return(C.startsWith("scroll")||C.startsWith("view"))&&C.includes("(")}(b)){const C=this.saveAnonymousTimelineName(b);y.push(C)}else y.push(b)}),y}saveAnonymousTimelineName(h){const p=":t"+this.nextAnonymousTimelineNameIndex++;return h.startsWith("scroll(")?this.anonymousScrollTimelineOptions.set(p,this.parseAnonymousScrollTimeline(h)):this.anonymousViewTimelineOptions.set(p,this.parseAnonymousViewTimeline(h)),p}parseAnonymousScrollTimeline(h){const p=Oe.ANONYMOUS_SCROLL_TIMELINE.exec(h);if(!p)return null;const y=p[1],b={};return y.split(" ").forEach(C=>{In.includes(C)?b.axis=C:ql.includes(C)&&(b.source=C)}),b}parseAnonymousViewTimeline(h){const p=Oe.ANONYMOUS_VIEW_TIMELINE.exec(h);if(!p)return null;const y=p[1],b={};return y.split(" ").forEach(C=>{In.includes(C)?b.axis=C:b.inset=b.inset?`${b.inset} ${C}`:C}),b}extractAnimationName(h){return this.findMatchingEntryInContainer(h,this.keyframeNamesSelectors)}findMatchingEntryInContainer(h,p){const y=h.split(" ").filter(b=>p.has(b));return y?y[0]:null}parseIdentifier(h){Oe.IDENTIFIER.lastIndex=h.index;const p=Oe.IDENTIFIER.exec(h.sheetSrc);if(!p)throw this.parseError(h,"Expected an identifier");return h.index+=p[0].length,p[0]}parseKeyframesAndSaveNameMapping(h,p){if(h.selector.startsWith("@keyframes")){const y=this.replaceKeyframesAndGetMapping(h,p);h.selector.split(" ").forEach((b,C)=>{C>0&&this.keyframeNamesSelectors.set(b,y)})}}replaceKeyframesAndGetMapping(h,p){function y(N){return tr.some(F=>N.startsWith(F))}const b=h.block.contents,C=function(N){let F=0,X=-1,Z=-1;const K=[];for(let me=0;me<N.length;me++)N[me]=="{"?F++:N[me]=="}"&&F--,F==1&&N[me]!="{"&&N[me]!="}"&&X==-1&&(X=me),F==2&&N[me]=="{"&&(Z=me,K.push({start:X,end:Z}),X=Z=-1);return K}(b);if(C.length==0)return new Map;const k=new Map;let z=!1;const D=[];D.push(b.substring(0,C[0].start));for(let N=0;N<C.length;N++){const F=b.substring(C[N].start,C[N].end);let X=[];F.split(",").forEach(Z=>{const K=Z.split(" ").map(_e=>_e.trim()).filter(_e=>_e!="").join(" "),me=k.size;k.set(me,K),X.push(`${me}%`),y(K)&&(z=!0)}),D.push(X.join(",")),N==C.length-1?D.push(b.substring(C[N].end)):D.push(b.substring(C[N].end,C[N+1].start))}return z?(h.block.contents=D.join(""),this.replacePart(h.block.startIndex,h.block.endIndex,h.block.contents,p),k):new Map}parseQualifiedRule(h){const p=h.index,y=this.parseSelector(h).trim();if(y)return{selector:y,block:this.eatBlock(h),startIndex:p,endIndex:h.index}}removeEnclosingDoubleQuotes(h){let p=h[0]=='"'?1:0,y=h[h.length-1]=='"'?h.length-1:h.length;return h.substring(p,y)}assertString(h,p){if(h.sheetSrc.substr(h.index,p.length)!=p)throw this.parseError(h,`Did not find expected sequence ${p}`);h.index+=p.length}replacePart(h,p,y,b){if(b.sheetSrc=b.sheetSrc.slice(0,h)+y+b.sheetSrc.slice(p),b.index>=p){const C=b.index-p;b.index=h+y.length+C}}eatComment(h){this.assertString(h,"/*"),this.eatUntil("*/",h,!0),this.assertString(h,"*/")}eatBlock(h){const p=h.index;this.assertString(h,"{");let y=1;for(;y!=0;)this.lookAhead("/*",h)?this.eatComment(h):(h.sheetSrc[h.index]==="{"?y++:h.sheetSrc[h.index]==="}"&&y--,this.advance(h));const b=h.index;return{startIndex:p,endIndex:b,contents:h.sheetSrc.slice(p,b)}}advance(h){if(h.index++,h.index>h.sheetSrc.length)throw this.parseError(h,"Advanced beyond the end")}parseError(h,p){return Error(`(${h.name?h.name:"<anonymous file>"}): ${p}`)}eatUntil(h,p,y=!1){const b=p.index;for(;!this.lookAhead(h,p);)this.advance(p);return y&&(p.sheetSrc=p.sheetSrc.slice(0,b)+" ".repeat(p.index-b)+p.sheetSrc.slice(p.index)),p.sheetSrc.slice(b,p.index)}parseSelector(h){let p=h.index;if(this.eatUntil("{",h),p===h.index)throw Error("Empty selector");return h.sheetSrc.slice(p,h.index)}eatWhitespace(h){Oe.WHITE_SPACE.lastIndex=h.index;const p=Oe.WHITE_SPACE.exec(h.sheetSrc);p&&(h.index+=p[0].length)}lookAhead(h,p){return p.sheetSrc.substr(p.index,h.length)==h}peek(h){return h.sheetSrc[h.index]}extractMatches(h,p,y=","){return p.exec(h)[1].trim().split(y).map(b=>b.trim())}split(h){return h.split(" ").map(p=>p.trim()).filter(p=>p!="")}};function Xl(h,p,y,b,C,k){const z=cs(p),D=ls(p,y);return Vo(fs(h,z,D,b,C),k,fs("cover",z,D,b,C),y)}function Yl(h,p,y){const b=tn.getAnimationTimelineOptions(p,y);if(!b)return null;const C=b["animation-timeline"];if(!C)return null;let k=tn.getScrollTimelineOptions(C,y)||tn.getViewTimelineOptions(C,y);return k?(k.subject&&function(z,D){const N=ps(D.subject),F=D.axis||D.axis;function X(K,me){let _e=null;for(const[ot,Pt]of K)if(ot==100*me.offset){if(Pt=="from")_e=0;else if(Pt=="to")_e=100;else{const gt=Pt.split(" ");_e=gt.length==1?parseFloat(gt[0]):100*Xl(gt[0],N,D.subject,F,D.inset,CSS.percent(parseFloat(gt[1])))}break}return _e}const Z=tn.keyframeNamesSelectors.get(z.animationName);if(Z&&Z.size){const K=[];z.effect.getKeyframes().forEach(_e=>{const ot=X(Z,_e);ot!==null&&ot>=0&&ot<=100&&(_e.offset=ot/100,K.push(_e))});const me=K.sort((_e,ot)=>_e.offset<ot.offset?-1:_e.affset>ot.offset?1:0);z.effect.setKeyframes(me)}}(h,k),{timeline:k.source?new $e(k):new Rn(k),animOptions:b}):null}function Zl(){if(CSS.supports("animation-timeline: --works"))return!0;(function(){function p(b){if(b.innerHTML.trim().length===0||"aphrodite"in b.dataset)return;let C=tn.transpileStyleSheet(b.innerHTML,!0);C=tn.transpileStyleSheet(C,!1),b.innerHTML=C}function y(b){b.type!="text/css"&&b.rel!="stylesheet"||!b.href||new URL(b.href,document.baseURI).origin==location.origin&&fetch(b.getAttribute("href")).then(async C=>{const k=await C.text();let z=tn.transpileStyleSheet(k,!0);if(z=tn.transpileStyleSheet(k,!1),z!=k){const D=new Blob([z],{type:"text/css"}),N=URL.createObjectURL(D);b.setAttribute("href",N)}})}new MutationObserver(b=>{for(const C of b)for(const k of C.addedNodes)k instanceof HTMLStyleElement&&p(k),k instanceof HTMLLinkElement&&y(k)}).observe(document.documentElement,{childList:!0,subtree:!0}),document.querySelectorAll("style").forEach(b=>p(b)),document.querySelectorAll("link").forEach(b=>y(b))})();const h=CSS.supports;CSS.supports=p=>(p=p.replaceAll(/(animation-timeline|scroll-timeline(-(name|axis))?|view-timeline(-(name|axis|inset))?|timeline-scope)\s*:/g,"--supported-property:"),h(p)),window.addEventListener("animationstart",p=>{p.target.getAnimations().filter(y=>y.animationName===p.animationName).forEach(y=>{const b=Yl(y,y.animationName,p.target);if(b)if(!b.timeline||y instanceof or)y.timeline=b.timeline;else{const C=new or(y,b.timeline,b.animOptions);y.pause(),C.play()}})})}(function(){if(!Zl()){if(!Reflect.defineProperty(window,"ScrollTimeline",{value:$e}))throw Error("Error installing ScrollTimeline polyfill: could not attach ScrollTimeline to window");if(!Reflect.defineProperty(window,"ViewTimeline",{value:Rn}))throw Error("Error installing ViewTimeline polyfill: could not attach ViewTimeline to window");if(!Reflect.defineProperty(Element.prototype,"animate",{value:Gl}))throw Error("Error installing ScrollTimeline polyfill: could not attach WAAPI's animate to DOM Element");if(!Reflect.defineProperty(window,"Animation",{value:or}))throw Error("Error installing Animation constructor.");if(!Reflect.defineProperty(Element.prototype,"getAnimations",{value:Wl}))throw Error("Error installing ScrollTimeline polyfill: could not attach WAAPI's getAnimations to DOM Element");if(!Reflect.defineProperty(document,"getAnimations",{value:Hl}))throw Error("Error installing ScrollTimeline polyfill: could not attach WAAPI's getAnimations to document")}})()})();var ja={exports:{}},Ja;function Ga(){return Ja||(Ja=1,function(r){var e={};e.useBlobBuilder=function(){try{return new Blob([]),!1}catch{return!0}}(),e.useArrayBufferView=!e.useBlobBuilder&&function(){try{return new Blob([new Uint8Array([])]).size===0}catch{return!0}}(),r.exports.binaryFeatures=e;var t=r.exports.BlobBuilder;typeof window<"u"&&(t=r.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder);function n(){this._pieces=[],this._parts=[]}n.prototype.append=function(i){typeof i=="number"?this._pieces.push(i):(this.flush(),this._parts.push(i))},n.prototype.flush=function(){if(this._pieces.length>0){var i=new Uint8Array(this._pieces);e.useArrayBufferView||(i=i.buffer),this._parts.push(i),this._pieces=[]}},n.prototype.getBuffer=function(){if(this.flush(),e.useBlobBuilder){for(var i=new t,s=0,a=this._parts.length;s<a;s++)i.append(this._parts[s]);return i.getBlob()}else return new Blob(this._parts)},r.exports.BufferBuilder=n}(ja)),ja.exports}var Fs,Wa;function ed(){if(Wa)return Fs;Wa=1;var r=Ga().BufferBuilder,e=Ga().binaryFeatures,t={unpack:function(o){var c=new n(o);return c.unpack()},pack:function(o){var c=new i;c.pack(o);var l=c.getBuffer();return l}};Fs=t;function n(o){this.index=0,this.dataBuffer=o,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}n.prototype.unpack=function(){var o=this.unpack_uint8();if(o<128)return o;if((o^224)<32)return(o^224)-32;var c;if((c=o^160)<=15)return this.unpack_raw(c);if((c=o^176)<=15)return this.unpack_string(c);if((c=o^144)<=15)return this.unpack_array(c);if((c=o^128)<=15)return this.unpack_map(c);switch(o){case 192:return null;case 193:return;case 194:return!1;case 195:return!0;case 202:return this.unpack_float();case 203:return this.unpack_double();case 204:return this.unpack_uint8();case 205:return this.unpack_uint16();case 206:return this.unpack_uint32();case 207:return this.unpack_uint64();case 208:return this.unpack_int8();case 209:return this.unpack_int16();case 210:return this.unpack_int32();case 211:return this.unpack_int64();case 212:return;case 213:return;case 214:return;case 215:return;case 216:return c=this.unpack_uint16(),this.unpack_string(c);case 217:return c=this.unpack_uint32(),this.unpack_string(c);case 218:return c=this.unpack_uint16(),this.unpack_raw(c);case 219:return c=this.unpack_uint32(),this.unpack_raw(c);case 220:return c=this.unpack_uint16(),this.unpack_array(c);case 221:return c=this.unpack_uint32(),this.unpack_array(c);case 222:return c=this.unpack_uint16(),this.unpack_map(c);case 223:return c=this.unpack_uint32(),this.unpack_map(c)}},n.prototype.unpack_uint8=function(){var o=this.dataView[this.index]&255;return this.index++,o},n.prototype.unpack_uint16=function(){var o=this.read(2),c=(o[0]&255)*256+(o[1]&255);return this.index+=2,c},n.prototype.unpack_uint32=function(){var o=this.read(4),c=((o[0]*256+o[1])*256+o[2])*256+o[3];return this.index+=4,c},n.prototype.unpack_uint64=function(){var o=this.read(8),c=((((((o[0]*256+o[1])*256+o[2])*256+o[3])*256+o[4])*256+o[5])*256+o[6])*256+o[7];return this.index+=8,c},n.prototype.unpack_int8=function(){var o=this.unpack_uint8();return o<128?o:o-256},n.prototype.unpack_int16=function(){var o=this.unpack_uint16();return o<32768?o:o-65536},n.prototype.unpack_int32=function(){var o=this.unpack_uint32();return o<Math.pow(2,31)?o:o-Math.pow(2,32)},n.prototype.unpack_int64=function(){var o=this.unpack_uint64();return o<Math.pow(2,63)?o:o-Math.pow(2,64)},n.prototype.unpack_raw=function(o){if(this.length<this.index+o)throw new Error("BinaryPackFailure: index is out of range "+this.index+" "+o+" "+this.length);var c=this.dataBuffer.slice(this.index,this.index+o);return this.index+=o,c},n.prototype.unpack_string=function(o){for(var c=this.read(o),l=0,u="",d,f;l<o;)d=c[l],d<128?(u+=String.fromCharCode(d),l++):(d^192)<32?(f=(d^192)<<6|c[l+1]&63,u+=String.fromCharCode(f),l+=2):(f=(d&15)<<12|(c[l+1]&63)<<6|c[l+2]&63,u+=String.fromCharCode(f),l+=3);return this.index+=o,u},n.prototype.unpack_array=function(o){for(var c=new Array(o),l=0;l<o;l++)c[l]=this.unpack();return c},n.prototype.unpack_map=function(o){for(var c={},l=0;l<o;l++){var u=this.unpack(),d=this.unpack();c[u]=d}return c},n.prototype.unpack_float=function(){var o=this.unpack_uint32(),c=o>>31,l=(o>>23&255)-127,u=o&8388607|8388608;return(c===0?1:-1)*u*Math.pow(2,l-23)},n.prototype.unpack_double=function(){var o=this.unpack_uint32(),c=this.unpack_uint32(),l=o>>31,u=(o>>20&2047)-1023,d=o&1048575|1048576,f=d*Math.pow(2,u-20)+c*Math.pow(2,u-52);return(l===0?1:-1)*f},n.prototype.read=function(o){var c=this.index;if(c+o<=this.length)return this.dataView.subarray(c,c+o);throw new Error("BinaryPackFailure: read index out of range")};function i(){this.bufferBuilder=new r}i.prototype.getBuffer=function(){return this.bufferBuilder.getBuffer()},i.prototype.pack=function(o){var c=typeof o;if(c==="string")this.pack_string(o);else if(c==="number")Math.floor(o)===o?this.pack_integer(o):this.pack_double(o);else if(c==="boolean")o===!0?this.bufferBuilder.append(195):o===!1&&this.bufferBuilder.append(194);else if(c==="undefined")this.bufferBuilder.append(192);else if(c==="object")if(o===null)this.bufferBuilder.append(192);else{var l=o.constructor;if(l==Array)this.pack_array(o);else if(l==Blob||l==File||o instanceof Blob||o instanceof File)this.pack_bin(o);else if(l==ArrayBuffer)e.useArrayBufferView?this.pack_bin(new Uint8Array(o)):this.pack_bin(o);else if("BYTES_PER_ELEMENT"in o)e.useArrayBufferView?this.pack_bin(new Uint8Array(o.buffer)):this.pack_bin(o.buffer);else if(l==Object||l.toString().startsWith("class"))this.pack_object(o);else if(l==Date)this.pack_string(o.toString());else if(typeof o.toBinaryPack=="function")this.bufferBuilder.append(o.toBinaryPack());else throw new Error('Type "'+l.toString()+'" not yet supported')}else throw new Error('Type "'+c+'" not yet supported');this.bufferBuilder.flush()},i.prototype.pack_bin=function(o){var c=o.length||o.byteLength||o.size;if(c<=15)this.pack_uint8(160+c);else if(c<=65535)this.bufferBuilder.append(218),this.pack_uint16(c);else if(c<=4294967295)this.bufferBuilder.append(219),this.pack_uint32(c);else throw new Error("Invalid length");this.bufferBuilder.append(o)},i.prototype.pack_string=function(o){var c=a(o);if(c<=15)this.pack_uint8(176+c);else if(c<=65535)this.bufferBuilder.append(216),this.pack_uint16(c);else if(c<=4294967295)this.bufferBuilder.append(217),this.pack_uint32(c);else throw new Error("Invalid length");this.bufferBuilder.append(o)},i.prototype.pack_array=function(o){var c=o.length;if(c<=15)this.pack_uint8(144+c);else if(c<=65535)this.bufferBuilder.append(220),this.pack_uint16(c);else if(c<=4294967295)this.bufferBuilder.append(221),this.pack_uint32(c);else throw new Error("Invalid length");for(var l=0;l<c;l++)this.pack(o[l])},i.prototype.pack_integer=function(o){if(o>=-32&&o<=127)this.bufferBuilder.append(o&255);else if(o>=0&&o<=255)this.bufferBuilder.append(204),this.pack_uint8(o);else if(o>=-128&&o<=127)this.bufferBuilder.append(208),this.pack_int8(o);else if(o>=0&&o<=65535)this.bufferBuilder.append(205),this.pack_uint16(o);else if(o>=-32768&&o<=32767)this.bufferBuilder.append(209),this.pack_int16(o);else if(o>=0&&o<=4294967295)this.bufferBuilder.append(206),this.pack_uint32(o);else if(o>=-2147483648&&o<=2147483647)this.bufferBuilder.append(210),this.pack_int32(o);else if(o>=-9223372036854776e3&&o<=9223372036854776e3)this.bufferBuilder.append(211),this.pack_int64(o);else if(o>=0&&o<=18446744073709552e3)this.bufferBuilder.append(207),this.pack_uint64(o);else throw new Error("Invalid integer")},i.prototype.pack_double=function(o){var c=0;o<0&&(c=1,o=-o);var l=Math.floor(Math.log(o)/Math.LN2),u=o/Math.pow(2,l)-1,d=Math.floor(u*Math.pow(2,52)),f=Math.pow(2,32),m=c<<31|l+1023<<20|d/f&1048575,x=d%f;this.bufferBuilder.append(203),this.pack_int32(m),this.pack_int32(x)},i.prototype.pack_object=function(o){var c=Object.keys(o),l=c.length;if(l<=15)this.pack_uint8(128+l);else if(l<=65535)this.bufferBuilder.append(222),this.pack_uint16(l);else if(l<=4294967295)this.bufferBuilder.append(223),this.pack_uint32(l);else throw new Error("Invalid length");for(var u in o)o.hasOwnProperty(u)&&(this.pack(u),this.pack(o[u]))},i.prototype.pack_uint8=function(o){this.bufferBuilder.append(o)},i.prototype.pack_uint16=function(o){this.bufferBuilder.append(o>>8),this.bufferBuilder.append(o&255)},i.prototype.pack_uint32=function(o){var c=o&4294967295;this.bufferBuilder.append((c&4278190080)>>>24),this.bufferBuilder.append((c&16711680)>>>16),this.bufferBuilder.append((c&65280)>>>8),this.bufferBuilder.append(c&255)},i.prototype.pack_uint64=function(o){var c=o/Math.pow(2,32),l=o%Math.pow(2,32);this.bufferBuilder.append((c&4278190080)>>>24),this.bufferBuilder.append((c&16711680)>>>16),this.bufferBuilder.append((c&65280)>>>8),this.bufferBuilder.append(c&255),this.bufferBuilder.append((l&4278190080)>>>24),this.bufferBuilder.append((l&16711680)>>>16),this.bufferBuilder.append((l&65280)>>>8),this.bufferBuilder.append(l&255)},i.prototype.pack_int8=function(o){this.bufferBuilder.append(o&255)},i.prototype.pack_int16=function(o){this.bufferBuilder.append((o&65280)>>8),this.bufferBuilder.append(o&255)},i.prototype.pack_int32=function(o){this.bufferBuilder.append(o>>>24&255),this.bufferBuilder.append((o&16711680)>>>16),this.bufferBuilder.append((o&65280)>>>8),this.bufferBuilder.append(o&255)},i.prototype.pack_int64=function(o){var c=Math.floor(o/Math.pow(2,32)),l=o%Math.pow(2,32);this.bufferBuilder.append((c&4278190080)>>>24),this.bufferBuilder.append((c&16711680)>>>16),this.bufferBuilder.append((c&65280)>>>8),this.bufferBuilder.append(c&255),this.bufferBuilder.append((l&4278190080)>>>24),this.bufferBuilder.append((l&16711680)>>>16),this.bufferBuilder.append((l&65280)>>>8),this.bufferBuilder.append(l&255)};function s(o){var c=o.charCodeAt(0);return c<=2047?"00":c<=65535?"000":c<=2097151?"0000":c<=67108863?"00000":"000000"}function a(o){return o.length>600?new Blob([o]).size:o.replace(/[^\u0000-\u007F]/g,s).length}return Fs}var td=ed();const Ha=ur(td);let qa=!0,Xa=!0;function oi(r,e,t){const n=r.match(e);return n&&n.length>=t&&parseInt(n[t],10)}function Un(r,e,t){if(!r.RTCPeerConnection)return;const n=r.RTCPeerConnection.prototype,i=n.addEventListener;n.addEventListener=function(a,o){if(a!==e)return i.apply(this,arguments);const c=l=>{const u=t(l);u&&(o.handleEvent?o.handleEvent(u):o(u))};return this._eventMap=this._eventMap||{},this._eventMap[e]||(this._eventMap[e]=new Map),this._eventMap[e].set(o,c),i.apply(this,[a,c])};const s=n.removeEventListener;n.removeEventListener=function(a,o){if(a!==e||!this._eventMap||!this._eventMap[e])return s.apply(this,arguments);if(!this._eventMap[e].has(o))return s.apply(this,arguments);const c=this._eventMap[e].get(o);return this._eventMap[e].delete(o),this._eventMap[e].size===0&&delete this._eventMap[e],Object.keys(this._eventMap).length===0&&delete this._eventMap,s.apply(this,[a,c])},Object.defineProperty(n,"on"+e,{get(){return this["_on"+e]},set(a){this["_on"+e]&&(this.removeEventListener(e,this["_on"+e]),delete this["_on"+e]),a&&this.addEventListener(e,this["_on"+e]=a)},enumerable:!0,configurable:!0})}function nd(r){return typeof r!="boolean"?new Error("Argument type: "+typeof r+". Please use a boolean."):(qa=r,r?"adapter.js logging disabled":"adapter.js logging enabled")}function id(r){return typeof r!="boolean"?new Error("Argument type: "+typeof r+". Please use a boolean."):(Xa=!r,"adapter.js deprecation warnings "+(r?"disabled":"enabled"))}function Vs(){if(typeof window=="object"){if(qa)return;typeof console<"u"&&typeof console.log=="function"&&console.log.apply(console,arguments)}}function _r(r,e){Xa&&console.warn(r+" is deprecated, please use "+e+" instead.")}function rd(r){const e={browser:null,version:null};if(typeof r>"u"||!r.navigator)return e.browser="Not a browser.",e;const{navigator:t}=r;if(t.mozGetUserMedia)e.browser="firefox",e.version=oi(t.userAgent,/Firefox\/(\d+)\./,1);else if(t.webkitGetUserMedia||r.isSecureContext===!1&&r.webkitRTCPeerConnection&&!r.RTCIceGatherer)e.browser="chrome",e.version=oi(t.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(t.mediaDevices&&t.userAgent.match(/Edge\/(\d+).(\d+)$/))e.browser="edge",e.version=oi(t.userAgent,/Edge\/(\d+).(\d+)$/,2);else if(r.RTCPeerConnection&&t.userAgent.match(/AppleWebKit\/(\d+)\./))e.browser="safari",e.version=oi(t.userAgent,/AppleWebKit\/(\d+)\./,1),e.supportsUnifiedPlan=r.RTCRtpTransceiver&&"currentDirection"in r.RTCRtpTransceiver.prototype;else return e.browser="Not a supported browser.",e;return e}function Ya(r){return Object.prototype.toString.call(r)==="[object Object]"}function Za(r){return Ya(r)?Object.keys(r).reduce(function(e,t){const n=Ya(r[t]),i=n?Za(r[t]):r[t],s=n&&!Object.keys(i).length;return i===void 0||s?e:Object.assign(e,{[t]:i})},{}):r}function js(r,e,t){!e||t.has(e.id)||(t.set(e.id,e),Object.keys(e).forEach(n=>{n.endsWith("Id")?js(r,r.get(e[n]),t):n.endsWith("Ids")&&e[n].forEach(i=>{js(r,r.get(i),t)})}))}function Ka(r,e,t){const n=t?"outbound-rtp":"inbound-rtp",i=new Map;if(e===null)return i;const s=[];return r.forEach(a=>{a.type==="track"&&a.trackIdentifier===e.id&&s.push(a)}),s.forEach(a=>{r.forEach(o=>{o.type===n&&o.trackId===a.id&&js(r,o,i)})}),i}const Qa=Vs;function $a(r,e){const t=r&&r.navigator;if(!t.mediaDevices)return;const n=function(o){if(typeof o!="object"||o.mandatory||o.optional)return o;const c={};return Object.keys(o).forEach(l=>{if(l==="require"||l==="advanced"||l==="mediaSource")return;const u=typeof o[l]=="object"?o[l]:{ideal:o[l]};u.exact!==void 0&&typeof u.exact=="number"&&(u.min=u.max=u.exact);const d=function(f,m){return f?f+m.charAt(0).toUpperCase()+m.slice(1):m==="deviceId"?"sourceId":m};if(u.ideal!==void 0){c.optional=c.optional||[];let f={};typeof u.ideal=="number"?(f[d("min",l)]=u.ideal,c.optional.push(f),f={},f[d("max",l)]=u.ideal,c.optional.push(f)):(f[d("",l)]=u.ideal,c.optional.push(f))}u.exact!==void 0&&typeof u.exact!="number"?(c.mandatory=c.mandatory||{},c.mandatory[d("",l)]=u.exact):["min","max"].forEach(f=>{u[f]!==void 0&&(c.mandatory=c.mandatory||{},c.mandatory[d(f,l)]=u[f])})}),o.advanced&&(c.optional=(c.optional||[]).concat(o.advanced)),c},i=function(o,c){if(e.version>=61)return c(o);if(o=JSON.parse(JSON.stringify(o)),o&&typeof o.audio=="object"){const l=function(u,d,f){d in u&&!(f in u)&&(u[f]=u[d],delete u[d])};o=JSON.parse(JSON.stringify(o)),l(o.audio,"autoGainControl","googAutoGainControl"),l(o.audio,"noiseSuppression","googNoiseSuppression"),o.audio=n(o.audio)}if(o&&typeof o.video=="object"){let l=o.video.facingMode;l=l&&(typeof l=="object"?l:{ideal:l});const u=e.version<66;if(l&&(l.exact==="user"||l.exact==="environment"||l.ideal==="user"||l.ideal==="environment")&&!(t.mediaDevices.getSupportedConstraints&&t.mediaDevices.getSupportedConstraints().facingMode&&!u)){delete o.video.facingMode;let d;if(l.exact==="environment"||l.ideal==="environment"?d=["back","rear"]:(l.exact==="user"||l.ideal==="user")&&(d=["front"]),d)return t.mediaDevices.enumerateDevices().then(f=>{f=f.filter(x=>x.kind==="videoinput");let m=f.find(x=>d.some(_=>x.label.toLowerCase().includes(_)));return!m&&f.length&&d.includes("back")&&(m=f[f.length-1]),m&&(o.video.deviceId=l.exact?{exact:m.deviceId}:{ideal:m.deviceId}),o.video=n(o.video),Qa("chrome: "+JSON.stringify(o)),c(o)})}o.video=n(o.video)}return Qa("chrome: "+JSON.stringify(o)),c(o)},s=function(o){return e.version>=64?o:{name:{PermissionDeniedError:"NotAllowedError",PermissionDismissedError:"NotAllowedError",InvalidStateError:"NotAllowedError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotAllowedError",MediaDeviceKillSwitchOn:"NotAllowedError",TabCaptureError:"AbortError",ScreenCaptureError:"AbortError",DeviceCaptureError:"AbortError"}[o.name]||o.name,message:o.message,constraint:o.constraint||o.constraintName,toString(){return this.name+(this.message&&": ")+this.message}}},a=function(o,c,l){i(o,u=>{t.webkitGetUserMedia(u,c,d=>{l&&l(s(d))})})};if(t.getUserMedia=a.bind(t),t.mediaDevices.getUserMedia){const o=t.mediaDevices.getUserMedia.bind(t.mediaDevices);Object.getOwnPropertyDescriptor(t.mediaDevices,"getUserMedia")?.writable&&(t.mediaDevices.getUserMedia=function(c){return i(c,l=>o(l).then(u=>{if(l.audio&&!u.getAudioTracks().length||l.video&&!u.getVideoTracks().length)throw u.getTracks().forEach(d=>{d.stop()}),new DOMException("","NotFoundError");return u},u=>Promise.reject(s(u))))})}}function sd(r,e){if(!(r.navigator.mediaDevices&&"getDisplayMedia"in r.navigator.mediaDevices)&&r.navigator.mediaDevices){if(typeof e!="function"){console.error("shimGetDisplayMedia: getSourceId argument is not a function");return}r.navigator.mediaDevices.getDisplayMedia=function(t){return e(t).then(n=>{const i=t.video&&t.video.width,s=t.video&&t.video.height,a=t.video&&t.video.frameRate;return t.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:n,maxFrameRate:a||3}},i&&(t.video.mandatory.maxWidth=i),s&&(t.video.mandatory.maxHeight=s),r.navigator.mediaDevices.getUserMedia(t)})}}}function ec(r){r.MediaStream=r.MediaStream||r.webkitMediaStream}function tc(r){if(typeof r=="object"&&r.RTCPeerConnection&&!("ontrack"in r.RTCPeerConnection.prototype)){Object.defineProperty(r.RTCPeerConnection.prototype,"ontrack",{get(){return this._ontrack},set(t){this._ontrack&&this.removeEventListener("track",this._ontrack),this.addEventListener("track",this._ontrack=t)},enumerable:!0,configurable:!0});const e=r.RTCPeerConnection.prototype.setRemoteDescription;r.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",n=>{let i;r.RTCPeerConnection.prototype.getReceivers?i=this.getReceivers().find(a=>a.track&&a.track.id===n.track.id):i={track:n.track};const s=new Event("track");s.track=n.track,s.receiver=i,s.transceiver={receiver:i},s.streams=[t.stream],this.dispatchEvent(s)}),t.stream.getTracks().forEach(n=>{let i;r.RTCPeerConnection.prototype.getReceivers?i=this.getReceivers().find(a=>a.track&&a.track.id===n.id):i={track:n};const s=new Event("track");s.track=n,s.receiver=i,s.transceiver={receiver:i},s.streams=[t.stream],this.dispatchEvent(s)})},this.addEventListener("addstream",this._ontrackpoly)),e.apply(this,arguments)}}else Un(r,"track",e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e))}function nc(r){if(typeof r=="object"&&r.RTCPeerConnection&&!("getSenders"in r.RTCPeerConnection.prototype)&&"createDTMFSender"in r.RTCPeerConnection.prototype){const e=function(i,s){return{track:s,get dtmf(){return this._dtmf===void 0&&(s.kind==="audio"?this._dtmf=i.createDTMFSender(s):this._dtmf=null),this._dtmf},_pc:i}};if(!r.RTCPeerConnection.prototype.getSenders){r.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=r.RTCPeerConnection.prototype.addTrack;r.RTCPeerConnection.prototype.addTrack=function(a,o){let c=i.apply(this,arguments);return c||(c=e(this,a),this._senders.push(c)),c};const s=r.RTCPeerConnection.prototype.removeTrack;r.RTCPeerConnection.prototype.removeTrack=function(a){s.apply(this,arguments);const o=this._senders.indexOf(a);o!==-1&&this._senders.splice(o,1)}}const t=r.RTCPeerConnection.prototype.addStream;r.RTCPeerConnection.prototype.addStream=function(i){this._senders=this._senders||[],t.apply(this,[i]),i.getTracks().forEach(s=>{this._senders.push(e(this,s))})};const n=r.RTCPeerConnection.prototype.removeStream;r.RTCPeerConnection.prototype.removeStream=function(i){this._senders=this._senders||[],n.apply(this,[i]),i.getTracks().forEach(s=>{const a=this._senders.find(o=>o.track===s);a&&this._senders.splice(this._senders.indexOf(a),1)})}}else if(typeof r=="object"&&r.RTCPeerConnection&&"getSenders"in r.RTCPeerConnection.prototype&&"createDTMFSender"in r.RTCPeerConnection.prototype&&r.RTCRtpSender&&!("dtmf"in r.RTCRtpSender.prototype)){const e=r.RTCPeerConnection.prototype.getSenders;r.RTCPeerConnection.prototype.getSenders=function(){const t=e.apply(this,[]);return t.forEach(n=>n._pc=this),t},Object.defineProperty(r.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function ic(r){if(!r.RTCPeerConnection)return;const e=r.RTCPeerConnection.prototype.getStats;r.RTCPeerConnection.prototype.getStats=function(){const[t,n,i]=arguments;if(arguments.length>0&&typeof t=="function")return e.apply(this,arguments);if(e.length===0&&(arguments.length===0||typeof t!="function"))return e.apply(this,[]);const s=function(o){const c={};return o.result().forEach(l=>{const u={id:l.id,timestamp:l.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[l.type]||l.type};l.names().forEach(d=>{u[d]=l.stat(d)}),c[u.id]=u}),c},a=function(o){return new Map(Object.keys(o).map(c=>[c,o[c]]))};if(arguments.length>=2){const o=function(c){n(a(s(c)))};return e.apply(this,[o,t])}return new Promise((o,c)=>{e.apply(this,[function(l){o(a(s(l)))},c])}).then(n,i)}}function rc(r){if(!(typeof r=="object"&&r.RTCPeerConnection&&r.RTCRtpSender&&r.RTCRtpReceiver))return;if(!("getStats"in r.RTCRtpSender.prototype)){const t=r.RTCPeerConnection.prototype.getSenders;t&&(r.RTCPeerConnection.prototype.getSenders=function(){const i=t.apply(this,[]);return i.forEach(s=>s._pc=this),i});const n=r.RTCPeerConnection.prototype.addTrack;n&&(r.RTCPeerConnection.prototype.addTrack=function(){const i=n.apply(this,arguments);return i._pc=this,i}),r.RTCRtpSender.prototype.getStats=function(){const i=this;return this._pc.getStats().then(s=>Ka(s,i.track,!0))}}if(!("getStats"in r.RTCRtpReceiver.prototype)){const t=r.RTCPeerConnection.prototype.getReceivers;t&&(r.RTCPeerConnection.prototype.getReceivers=function(){const n=t.apply(this,[]);return n.forEach(i=>i._pc=this),n}),Un(r,"track",n=>(n.receiver._pc=n.srcElement,n)),r.RTCRtpReceiver.prototype.getStats=function(){const n=this;return this._pc.getStats().then(i=>Ka(i,n.track,!1))}}if(!("getStats"in r.RTCRtpSender.prototype&&"getStats"in r.RTCRtpReceiver.prototype))return;const e=r.RTCPeerConnection.prototype.getStats;r.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof r.MediaStreamTrack){const t=arguments[0];let n,i,s;return this.getSenders().forEach(a=>{a.track===t&&(n?s=!0:n=a)}),this.getReceivers().forEach(a=>(a.track===t&&(i?s=!0:i=a),a.track===t)),s||n&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):n?n.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return e.apply(this,arguments)}}function sc(r){r.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(s=>this._shimmedLocalStreams[s][0])};const e=r.RTCPeerConnection.prototype.addTrack;r.RTCPeerConnection.prototype.addTrack=function(s,a){if(!a)return e.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const o=e.apply(this,arguments);return this._shimmedLocalStreams[a.id]?this._shimmedLocalStreams[a.id].indexOf(o)===-1&&this._shimmedLocalStreams[a.id].push(o):this._shimmedLocalStreams[a.id]=[a,o],o};const t=r.RTCPeerConnection.prototype.addStream;r.RTCPeerConnection.prototype.addStream=function(s){this._shimmedLocalStreams=this._shimmedLocalStreams||{},s.getTracks().forEach(c=>{if(this.getSenders().find(l=>l.track===c))throw new DOMException("Track already exists.","InvalidAccessError")});const a=this.getSenders();t.apply(this,arguments);const o=this.getSenders().filter(c=>a.indexOf(c)===-1);this._shimmedLocalStreams[s.id]=[s].concat(o)};const n=r.RTCPeerConnection.prototype.removeStream;r.RTCPeerConnection.prototype.removeStream=function(s){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[s.id],n.apply(this,arguments)};const i=r.RTCPeerConnection.prototype.removeTrack;r.RTCPeerConnection.prototype.removeTrack=function(s){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},s&&Object.keys(this._shimmedLocalStreams).forEach(a=>{const o=this._shimmedLocalStreams[a].indexOf(s);o!==-1&&this._shimmedLocalStreams[a].splice(o,1),this._shimmedLocalStreams[a].length===1&&delete this._shimmedLocalStreams[a]}),i.apply(this,arguments)}}function oc(r,e){if(!r.RTCPeerConnection)return;if(r.RTCPeerConnection.prototype.addTrack&&e.version>=65)return sc(r);const t=r.RTCPeerConnection.prototype.getLocalStreams;r.RTCPeerConnection.prototype.getLocalStreams=function(){const l=t.apply(this);return this._reverseStreams=this._reverseStreams||{},l.map(u=>this._reverseStreams[u.id])};const n=r.RTCPeerConnection.prototype.addStream;r.RTCPeerConnection.prototype.addStream=function(l){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},l.getTracks().forEach(u=>{if(this.getSenders().find(d=>d.track===u))throw new DOMException("Track already exists.","InvalidAccessError")}),!this._reverseStreams[l.id]){const u=new r.MediaStream(l.getTracks());this._streams[l.id]=u,this._reverseStreams[u.id]=l,l=u}n.apply(this,[l])};const i=r.RTCPeerConnection.prototype.removeStream;r.RTCPeerConnection.prototype.removeStream=function(l){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},i.apply(this,[this._streams[l.id]||l]),delete this._reverseStreams[this._streams[l.id]?this._streams[l.id].id:l.id],delete this._streams[l.id]},r.RTCPeerConnection.prototype.addTrack=function(l,u){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const d=[].slice.call(arguments,1);if(d.length!==1||!d[0].getTracks().find(m=>m===l))throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.","NotSupportedError");if(this.getSenders().find(m=>m.track===l))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const f=this._streams[u.id];if(f)f.addTrack(l),Promise.resolve().then(()=>{this.dispatchEvent(new Event("negotiationneeded"))});else{const m=new r.MediaStream([l]);this._streams[u.id]=m,this._reverseStreams[m.id]=u,this.addStream(m)}return this.getSenders().find(m=>m.track===l)};function s(l,u){let d=u.sdp;return Object.keys(l._reverseStreams||[]).forEach(f=>{const m=l._reverseStreams[f],x=l._streams[m.id];d=d.replace(new RegExp(x.id,"g"),m.id)}),new RTCSessionDescription({type:u.type,sdp:d})}function a(l,u){let d=u.sdp;return Object.keys(l._reverseStreams||[]).forEach(f=>{const m=l._reverseStreams[f],x=l._streams[m.id];d=d.replace(new RegExp(m.id,"g"),x.id)}),new RTCSessionDescription({type:u.type,sdp:d})}["createOffer","createAnswer"].forEach(function(l){const u=r.RTCPeerConnection.prototype[l],d={[l](){const f=arguments;return arguments.length&&typeof arguments[0]=="function"?u.apply(this,[m=>{const x=s(this,m);f[0].apply(null,[x])},m=>{f[1]&&f[1].apply(null,m)},arguments[2]]):u.apply(this,arguments).then(m=>s(this,m))}};r.RTCPeerConnection.prototype[l]=d[l]});const o=r.RTCPeerConnection.prototype.setLocalDescription;r.RTCPeerConnection.prototype.setLocalDescription=function(){return!arguments.length||!arguments[0].type?o.apply(this,arguments):(arguments[0]=a(this,arguments[0]),o.apply(this,arguments))};const c=Object.getOwnPropertyDescriptor(r.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(r.RTCPeerConnection.prototype,"localDescription",{get(){const l=c.get.apply(this);return l.type===""?l:s(this,l)}}),r.RTCPeerConnection.prototype.removeTrack=function(l){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!l._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(l._pc!==this)throw new DOMException("Sender was not created by this connection.","InvalidAccessError");this._streams=this._streams||{};let u;Object.keys(this._streams).forEach(d=>{this._streams[d].getTracks().find(f=>l.track===f)&&(u=this._streams[d])}),u&&(u.getTracks().length===1?this.removeStream(this._reverseStreams[u.id]):u.removeTrack(l.track),this.dispatchEvent(new Event("negotiationneeded")))}}function Js(r,e){!r.RTCPeerConnection&&r.webkitRTCPeerConnection&&(r.RTCPeerConnection=r.webkitRTCPeerConnection),r.RTCPeerConnection&&e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){const n=r.RTCPeerConnection.prototype[t],i={[t](){return arguments[0]=new(t==="addIceCandidate"?r.RTCIceCandidate:r.RTCSessionDescription)(arguments[0]),n.apply(this,arguments)}};r.RTCPeerConnection.prototype[t]=i[t]})}function ac(r,e){Un(r,"negotiationneeded",t=>{const n=t.target;if(!((e.version<72||n.getConfiguration&&n.getConfiguration().sdpSemantics==="plan-b")&&n.signalingState!=="stable"))return t})}const cc=Object.freeze(Object.defineProperty({__proto__:null,fixNegotiationNeeded:ac,shimAddTrackRemoveTrack:oc,shimAddTrackRemoveTrackWithNative:sc,shimGetDisplayMedia:sd,shimGetSendersWithDtmf:nc,shimGetStats:ic,shimGetUserMedia:$a,shimMediaStream:ec,shimOnTrack:tc,shimPeerConnection:Js,shimSenderReceiverGetStats:rc},Symbol.toStringTag,{value:"Module"}));function od(r,e){let t=!1;return r=JSON.parse(JSON.stringify(r)),r.filter(n=>{if(n&&(n.urls||n.url)){let i=n.urls||n.url;n.url&&!n.urls&&_r("RTCIceServer.url","RTCIceServer.urls");const s=typeof i=="string";return s&&(i=[i]),i=i.filter(a=>{if(a.indexOf("stun:")===0)return!1;const o=a.startsWith("turn")&&!a.startsWith("turn:[")&&a.includes("transport=udp");return o&&!t?(t=!0,!0):o&&!t}),delete n.url,n.urls=s?i[0]:i,!!i.length}})}var lc={exports:{}},uc;function hc(){return uc||(uc=1,function(r){var e={};e.generateIdentifier=function(){return Math.random().toString(36).substr(2,10)},e.localCName=e.generateIdentifier(),e.splitLines=function(t){return t.trim().split(`
1039
+ }`;class Xu extends La{constructor(e){super(e),this.vector_=new G,this.vector2_=new G,this.vector3_=new G,this.quaternion_=new ne,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new ti,this.indexBuffer=new dt(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(et),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new dt(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(et),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new dt(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(et),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new dt(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(et),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new dt(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(et),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new dt(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(et),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new dt(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(et),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new dt(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(et),this.geometry.setAttribute("color",this.colorBuffer)}expandBuffers(e){for(;e>=this.maxParticles;)this.maxParticles*=2;this.setupBuffers()}rebuildMaterial(){this.layers.mask=this.settings.layers.mask;const e={lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},resolution:{value:new Xn(1,1)},sizeAttenuation:{value:1},visibility:{value:1},alphaTest:{value:0}},t={};if(t.USE_UV="",t.USE_COLOR_ALPHA="",this.settings.material.map&&(t.USE_MAP="",t.MAP_UV=Fs(this.settings.material.map.channel),e.map=new Et(this.settings.material.map),e.mapTransform=new Et(new Vt().copy(this.settings.material.map.matrix))),this.settings.material.defines&&this.settings.material.defines.USE_COLOR_AS_ALPHA!==void 0&&(t.USE_COLOR_AS_ALPHA=""),this.settings.renderMode===V.Trail)this.material=new xs({uniforms:e,defines:t,vertexShader:qu,fragmentShader:Hu,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||sa,blendDst:this.settings.material.blendDst,blendSrc:this.settings.material.blendSrc,blendEquation:this.settings.material.blendEquation,premultipliedAlpha:this.settings.material.premultipliedAlpha});else throw new Error("render mode unavailable")}update(){let e=0,t=0,n=0;const i=this.getVisibleSystems();for(const s of i)for(let a=0;a<s.particleNum;a++)n+=s.particles[a].previous.length*2;n>this.maxParticles&&this.expandBuffers(n);for(const s of i){s.emitter.updateMatrixWorld&&(s.emitter.updateWorldMatrix(!0,!1),s.emitter.updateMatrixWorld(!0));const a=this.quaternion_,o=this.vector2_,c=this.vector3_;s.emitter.matrixWorld.decompose(o,a,c);const l=s.particles,u=s.particleNum,d=this.settings.uTileCount,m=this.settings.vTileCount,f=1/d,x=1/m;for(let _=0;_<u;_++){const g=l[_],v=g.uvTile%m,w=Math.floor(g.uvTile/m+.001),S=g.previous.values();let T=S.next(),C=T.value,P=C;T.done||(T=S.next());let E;T.value!==void 0?E=T.value:E=P;for(let O=0;O<g.previous.length;O++,e+=2){if(this.positionBuffer.setXYZ(e,P.position.x,P.position.y,P.position.z),this.positionBuffer.setXYZ(e+1,P.position.x,P.position.y,P.position.z),s.worldSpace?(this.positionBuffer.setXYZ(e,P.position.x,P.position.y,P.position.z),this.positionBuffer.setXYZ(e+1,P.position.x,P.position.y,P.position.z)):(g.parentMatrix?this.vector_.copy(P.position).applyMatrix4(g.parentMatrix):this.vector_.copy(P.position).applyMatrix4(s.emitter.matrixWorld),this.positionBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.positionBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),s.worldSpace?(this.previousBuffer.setXYZ(e,C.position.x,C.position.y,C.position.z),this.previousBuffer.setXYZ(e+1,C.position.x,C.position.y,C.position.z)):(g.parentMatrix?this.vector_.copy(C.position).applyMatrix4(g.parentMatrix):this.vector_.copy(C.position).applyMatrix4(s.emitter.matrixWorld),this.previousBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.previousBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),s.worldSpace?(this.nextBuffer.setXYZ(e,E.position.x,E.position.y,E.position.z),this.nextBuffer.setXYZ(e+1,E.position.x,E.position.y,E.position.z)):(g.parentMatrix?this.vector_.copy(E.position).applyMatrix4(g.parentMatrix):this.vector_.copy(E.position).applyMatrix4(s.emitter.matrixWorld),this.nextBuffer.setXYZ(e,this.vector_.x,this.vector_.y,this.vector_.z),this.nextBuffer.setXYZ(e+1,this.vector_.x,this.vector_.y,this.vector_.z)),this.sideBuffer.setX(e,1),this.sideBuffer.setX(e+1,-1),s.worldSpace)this.widthBuffer.setX(e,P.size),this.widthBuffer.setX(e+1,P.size);else if(g.parentMatrix)this.widthBuffer.setX(e,P.size),this.widthBuffer.setX(e+1,P.size);else{const A=(Math.abs(c.x)+Math.abs(c.y)+Math.abs(c.z))/3;this.widthBuffer.setX(e,P.size*A),this.widthBuffer.setX(e+1,P.size*A)}this.uvBuffer.setXY(e,(O/g.previous.length+v)*f,(m-w-1)*x),this.uvBuffer.setXY(e+1,(O/g.previous.length+v)*f,(m-w)*x),this.colorBuffer.setXYZW(e,P.color.x,P.color.y,P.color.z,P.color.w),this.colorBuffer.setXYZW(e+1,P.color.x,P.color.y,P.color.z,P.color.w),O+1<g.previous.length&&(this.indexBuffer.setX(t*3,e),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+2),t++,this.indexBuffer.setX(t*3,e+2),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+3),t++),C=P,P=E,T.done||(T=S.next(),T.value!==void 0&&(E=T.value))}}}this.positionBuffer.clearUpdateRanges(),this.positionBuffer.addUpdateRange(0,e*3),this.positionBuffer.needsUpdate=!0,this.previousBuffer.clearUpdateRanges(),this.previousBuffer.addUpdateRange(0,e*3),this.previousBuffer.needsUpdate=!0,this.nextBuffer.clearUpdateRanges(),this.nextBuffer.addUpdateRange(0,e*3),this.nextBuffer.needsUpdate=!0,this.sideBuffer.clearUpdateRanges(),this.sideBuffer.addUpdateRange(0,e),this.sideBuffer.needsUpdate=!0,this.widthBuffer.clearUpdateRanges(),this.widthBuffer.addUpdateRange(0,e),this.widthBuffer.needsUpdate=!0,this.uvBuffer.clearUpdateRanges(),this.uvBuffer.addUpdateRange(0,e*2),this.uvBuffer.needsUpdate=!0,this.colorBuffer.clearUpdateRanges(),this.colorBuffer.addUpdateRange(0,e*4),this.colorBuffer.needsUpdate=!0,this.indexBuffer.clearUpdateRanges(),this.indexBuffer.addUpdateRange(0,t*3),this.indexBuffer.needsUpdate=!0,this.geometry.setDrawRange(0,t*3)}dispose(){this.geometry.dispose()}}class Io extends ia{constructor(){super(),this.batches=[],this.systemToBatchIndex=new Map,this.type="BatchedRenderer",this.depthTexture=null}static equals(e,t){return e.material.side===t.material.side&&e.material.blending===t.material.blending&&e.material.blendSrc===t.material.blendSrc&&e.material.blendDst===t.material.blendDst&&e.material.blendEquation===t.material.blendEquation&&e.material.premultipliedAlpha===t.material.premultipliedAlpha&&e.material.transparent===t.material.transparent&&e.material.depthTest===t.material.depthTest&&e.material.type===t.material.type&&e.material.alphaTest===t.material.alphaTest&&e.material.map===t.material.map&&e.renderMode===t.renderMode&&e.blendTiles===t.blendTiles&&e.softParticles===t.softParticles&&e.softFarFade===t.softFarFade&&e.softNearFade===t.softNearFade&&e.uTileCount===t.uTileCount&&e.vTileCount===t.vTileCount&&e.instancingGeometry===t.instancingGeometry&&e.renderOrder===t.renderOrder&&e.layers.mask===t.layers.mask}addSystem(e){e._renderer=this;const t=e.getRendererSettings();for(let i=0;i<this.batches.length;i++)if(Io.equals(this.batches[i].settings,t)){this.batches[i].addSystem(e),this.systemToBatchIndex.set(e,i);return}let n;switch(t.renderMode){case V.Trail:n=new Xu(t);break;case V.Mesh:case V.BillBoard:case V.VerticalBillBoard:case V.HorizontalBillBoard:case V.StretchedBillBoard:n=new Wu(t);break}this.depthTexture&&n.applyDepthTexture(this.depthTexture),n.addSystem(e),this.batches.push(n),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(n)}deleteSystem(e){const t=this.systemToBatchIndex.get(e);t!=null&&(this.batches[t].removeSystem(e),this.systemToBatchIndex.delete(e))}setDepthTexture(e){this.depthTexture=e;for(const t of this.batches)t.applyDepthTexture(e)}updateSystem(e){this.deleteSystem(e),this.addSystem(e)}update(e){this.systemToBatchIndex.forEach((t,n)=>{n.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const Yu=Io;zu(),Mu(Cu),console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const Va=Math.sqrt(5),Zu=(Va-1)/4,Ve=(5-Va)/20,wr=r=>Math.floor(r)|0,_r=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function Ku(r=Math.random){const e=Qu(r),t=new Float64Array(e).map(a=>_r[a%32*4]),n=new Float64Array(e).map(a=>_r[a%32*4+1]),i=new Float64Array(e).map(a=>_r[a%32*4+2]),s=new Float64Array(e).map(a=>_r[a%32*4+3]);return function(a,o,c,l){let u,d,m,f,x;const _=(a+o+c+l)*Zu,g=wr(a+_),v=wr(o+_),w=wr(c+_),S=wr(l+_),T=(g+v+w+S)*Ve,C=g-T,P=v-T,E=w-T,O=S-T,A=a-C,R=o-P,B=c-E,z=l-O;let U=0,L=0,J=0,H=0;A>R?U++:L++,A>B?U++:J++,A>z?U++:H++,R>B?L++:J++,R>z?L++:H++,B>z?J++:H++;const se=U>=3?1:0,W=L>=3?1:0,pe=J>=3?1:0,te=H>=3?1:0,ue=U>=2?1:0,oe=L>=2?1:0,le=J>=2?1:0,xe=H>=2?1:0,ge=U>=1?1:0,de=L>=1?1:0,re=J>=1?1:0,Ze=H>=1?1:0,Ue=A-se+Ve,ke=R-W+Ve,lt=B-pe+Ve,De=z-te+Ve,ve=A-ue+2*Ve,he=R-oe+2*Ve,ft=B-le+2*Ve,Re=z-xe+2*Ve,fe=A-ge+3*Ve,rt=R-de+3*Ve,wt=B-re+3*Ve,_t=z-Ze+3*Ve,st=A-1+4*Ve,Tt=R-1+4*Ve,mt=B-1+4*Ve,yt=z-1+4*Ve,ht=g&255,Ae=v&255,Ke=w&255,ut=S&255;let Qe=.6-A*A-R*R-B*B-z*z;if(Qe<0)u=0;else{const ae=ht+e[Ae+e[Ke+e[ut]]];Qe*=Qe,u=Qe*Qe*(t[ae]*A+n[ae]*R+i[ae]*B+s[ae]*z)}let $=.6-Ue*Ue-ke*ke-lt*lt-De*De;if($<0)d=0;else{const ae=ht+se+e[Ae+W+e[Ke+pe+e[ut+te]]];$*=$,d=$*$*(t[ae]*Ue+n[ae]*ke+i[ae]*lt+s[ae]*De)}let Mt=.6-ve*ve-he*he-ft*ft-Re*Re;if(Mt<0)m=0;else{const ae=ht+ue+e[Ae+oe+e[Ke+le+e[ut+xe]]];Mt*=Mt,m=Mt*Mt*(t[ae]*ve+n[ae]*he+i[ae]*ft+s[ae]*Re)}let jt=.6-fe*fe-rt*rt-wt*wt-_t*_t;if(jt<0)f=0;else{const ae=ht+ge+e[Ae+de+e[Ke+re+e[ut+Ze]]];jt*=jt,f=jt*jt*(t[ae]*fe+n[ae]*rt+i[ae]*wt+s[ae]*_t)}let Ct=.6-st*st-Tt*Tt-mt*mt-yt*yt;if(Ct<0)x=0;else{const ae=ht+1+e[Ae+1+e[Ke+1+e[ut+1]]];Ct*=Ct,x=Ct*Ct*(t[ae]*st+n[ae]*Tt+i[ae]*mt+s[ae]*yt)}return 27*(u+d+m+f+x)}}function Qu(r){const e=new Uint8Array(512);for(let t=0;t<512/2;t++)e[t]=t;for(let t=0;t<512/2-1;t++){const n=t+~~(r()*(256-t)),i=e[t];e[t]=e[n],e[n]=i}for(let t=256;t<512;t++)e[t]=e[t-256];return e}var $u=Object.defineProperty,ed=(r,e,t)=>e in r?$u(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Me=(r,e,t)=>(ed(r,typeof e!="symbol"?e+"":e,t),t);(function(){class r{}class e extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class t extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class n extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class i extends r{constructor(p,y="unrestricted"){super(),Me(this,"type"),Me(this,"value"),this.value=p,this.type=y}}class s extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class a extends r{}class o extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class c extends r{}class l extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class u extends r{constructor(p,y="integer"){super(),Me(this,"value"),Me(this,"type"),this.value=p,this.type=y}}class d extends r{constructor(p){super(),Me(this,"value"),this.value=p}}class m extends r{constructor(p,y,b){super(),Me(this,"value"),Me(this,"type"),Me(this,"unit"),this.value=p,this.type=y,this.unit=b}}class f extends r{}class x extends r{}class _ extends r{}class g extends r{}class v extends r{}class w extends r{}class S extends r{}class T extends r{}class C extends r{}class P extends r{}class E extends r{}class O extends r{}class A{constructor(p){Me(this,"input"),Me(this,"index",0),this.input=p}consume(){const p=this.input.codePointAt(this.index);return p!==void 0&&(this.index+=String.fromCodePoint(p).length),p}reconsume(p){p!==void 0&&(this.index-=String.fromCodePoint(p).length)}peek(){const p=[];let y=this.index;for(let b=0;b<3&&y<this.input.length;b++){const M=this.input.codePointAt(y);p.push(M),y+=String.fromCodePoint(M).length}return p}}function R(h){return h===10}function B(h){return R(h)||h===8192||h===32}function z(h){return h>=48&&h<=57}function U(h){return z(h)||h>=65&&h<=70||h>=97&&h<=102}function L(h){return function(p){return function(y){return y>=65&&y<=90}(p)||function(y){return y>=97&&y<=122}(p)}(h)||function(p){return p>=128}(h)||h===95}function J(h){return L(h)||z(h)||h===45}function H(h){return h>=0&&h<=8||h===11||h>=14&&h<=31||h===127}function se(h,p){return h===92&&!R(p)}function W(h,p,y){return h===45?L(p)||p===45||se(p,y):!!L(h)||h===92&&se(h,p)}function pe(h,p,y){return h===43||h===45?z(p)||p===46&&z(y):z(h===46?p:h)}function te(h){const p=h.consume();if(U(p)){let y=[p];for(;U(...h.peek())&&y.length<5;)y.push(h.consume());B(...h.peek())&&h.consume();const b=parseInt(String.fromCodePoint(...y),16);return b===0||b>1114111?65533:b}return p===void 0?65533:p}function ue(h,p){const y=new s("");for(;;){const b=h.consume();if(b===p||b===void 0)return y;if(b===10)return h.reconsume(b),new a;if(b===92){const M=h.peek()[0];M===void 0||(R(M)?h.consume():y.value+=String.fromCodePoint(te(h)))}else y.value+=String.fromCodePoint(b)}}function oe(h){let p="";for(;;){const y=h.consume();if(J(y))p+=String.fromCodePoint(y);else{if(!se(...h.peek()))return h.reconsume(y),p;p+=String.fromCodePoint(te(h))}}}function le(h){let p=function(y){let b="integer",M="";for([43,45].includes(y.peek()[0])&&(M+=String.fromCodePoint(y.consume()));z(...y.peek());)M+=String.fromCodePoint(y.consume());if(y.peek()[0]===46&&z(y.peek()[1]))for(M+=String.fromCodePoint(y.consume(),y.consume()),b="number";z(...y.peek());)M+=String.fromCodePoint(y.consume());return[69,101].includes(y.peek()[0])&&([45,43].includes(y.peek()[1])&&z(y.peek()[2])?(M+=String.fromCodePoint(y.consume(),y.consume(),y.consume()),b="number"):z(y.peek()[1])&&(M+=String.fromCodePoint(y.consume(),y.consume()),b="number")),{value:parseFloat(M),type:b}}(h);return W(...h.peek())?new m(p.value,p.type,oe(h)):h.peek()[0]===37?(h.consume(),new d(p.value)):new u(p.value,p.type)}function xe(h){for(;;){const p=h.consume();if(p===41||p===void 0)return;se(...h.peek())&&te(h)}}function ge(h){const p=oe(h);if(p.match(/url/i)&&h.peek()[0]===40){for(h.consume();B(h.peek()[0])&&B(h.peek()[1]);)h.consume();return[34,39].includes(h.peek()[0])||B(h.peek()[0])&&[34,39].includes(h.peek()[1])?new t(p):function(y){const b=new o("");for(;B(...y.peek());)y.consume();for(;;){const M=y.consume();if(M===41||M===void 0)return b;if(B(M)){for(;B(...y.peek());)y.consume();return y.peek()[0]===41||y.peek()[0]===void 0?(y.consume(),b):(xe(y),new c)}if([34,39,40].includes(M)||H(M))return xe(y),new c;if(M===92){if(!se(...y.peek()))return xe(y),new c;b.value+=te(y)}else b.value+=String.fromCodePoint(M)}}(h)}return h.peek()[0]===40?(h.consume(),new t(p)):new e(p)}function de(h){const p=h.consume(),y=h.peek();if(B(p)){for(;B(...h.peek());)h.consume();return new f}if(p===34)return ue(h,p);if(p===35){if(J(y[0])||se(...y)){const b=new i;return W(...y)&&(b.type="id"),b.value=oe(h),b}return new l(String.fromCodePoint(p))}return p===39?ue(h,p):p===40?new C:p===41?new P:p===43?pe(...y)?(h.reconsume(p),le(h)):new l(String.fromCodePoint(p)):p===44?new w:p===45?pe(...h.peek())?(h.reconsume(p),le(h)):h.peek()[0]===45&&h.peek()[1]===62?(h.consume(),h.consume(),new _):W(...h.peek())?(h.reconsume(p),ge(h)):new l(String.fromCodePoint(p)):p===46?pe(...h.peek())?(h.reconsume(p),le(h)):new l(String.fromCodePoint(p)):p===58?new g:p===59?new v:p===60?y[0]===33&&y[1]===45&&y[2]===45?(h.consume(),h.consume(),h.consume(),new x):new l(String.fromCodePoint(p)):p===64?W(...y)?new n(oe(h)):new l(String.fromCodePoint(p)):p===91?new S:p===92?se(...y)?(h.reconsume(p),ge(h)):new l(String.fromCodePoint(p)):p===93?new T:p===123?new E:p===125?new O:z(p)?(h.reconsume(p),le(h)):L(p)?(h.reconsume(p),ge(h)):p===void 0?void 0:new l(String.fromCodePoint(p))}const re=new Set(["px","deg","s","hz","dppx","number","fr"]);function Ze(h){return re.has(h.toLowerCase())}function Ue(h,p){if(["x","y"].includes(h))return h;if(!p)throw new Error("To determine the normalized axis the computedStyle of the source is required.");const y=p.writingMode=="horizontal-tb";if(h==="block")h=y?"y":"x";else{if(h!=="inline")throw new TypeError(`Invalid axis \u201C${h}\u201D`);h=y?"x":"y"}return h}function ke(h){const p=[];let y=0;function b(){let k=0;const I=y;for(;y<h.length;){const D=h.slice(y,y+1);if(/\s/.test(D)&&k===0)break;if(D==="(")k+=1;else if(D===")"&&(k-=1,k===0)){y++;break}y++}return h.slice(I,y)}function M(){for(;/\s/.test(h.slice(y,y+1));)y++}for(;y<h.length;){const k=h.slice(y,y+1);/\s/.test(k)?M():p.push(b())}return p}function lt(h,p){return h.reduce((y,b)=>(y.has(b[p])?y.get(b[p]).push(b):y.set(b[p],[b]),y),new Map)}function De(h,p){const y=[],b=[];for(const M of h)p(M)?y.push(M):b.push(M);return[y,b]}function ve(h,p={}){function y(b){return Array.from(b).map(M=>ve(M,p))}if(h instanceof CSSUnitValue){if(h.unit==="percent"&&p.percentageReference){const M=h.value/100*p.percentageReference.value,k=p.percentageReference.unit;return new CSSUnitValue(M,k)}const b=h.toSum();if(b&&b.values.length===1&&(h=b.values[0]),h instanceof CSSUnitValue&&h.unit==="em"&&p.fontSize&&(h=new CSSUnitValue(h.value*p.fontSize.value,p.fontSize.unit)),h instanceof CSSKeywordValue){if(h.value==="e")return new CSSUnitValue(Math.E,"number");if(h.value==="pi")return new CSSUnitValue(Math.PI,"number")}return h}if(!h.operator)return h;switch(h.operator){case"sum":h=new CSSMathSum(...y(h.values));break;case"product":h=new CSSMathProduct(...y(h.values));break;case"negate":h=new CSSMathNegate(ve(h.value,p));break;case"clamp":h=new CSSMathClamp(ve(h.lower,p),ve(h.value,p),ve(h.upper,p));break;case"invert":h=new CSSMathInvert(ve(h.value,p));break;case"min":h=new CSSMathMin(...y(h.values));break;case"max":h=new CSSMathMax(...y(h.values))}if(h instanceof CSSMathMin||h instanceof CSSMathMax){const b=Array.from(h.values);if(b.every(M=>M instanceof CSSUnitValue&&M.unit!=="percent"&&Ze(M.unit)&&M.unit===b[0].unit)){const M=Math[h.operator].apply(Math,b.map(({value:k})=>k));return new CSSUnitValue(M,b[0].unit)}}if(h instanceof CSSMathMin||h instanceof CSSMathMax){const b=Array.from(h.values),[M,k]=De(b,D=>D instanceof CSSUnitValue&&D.unit!=="percent"),I=Array.from(lt(M,"unit").values());if(I.some(D=>D.length>0)){const D=I.map(N=>{const F=Math[h.operator].apply(Math,N.map(({value:X})=>X));return new CSSUnitValue(F,N[0].unit)});h=h instanceof CSSMathMin?new CSSMathMin(...D,...k):new CSSMathMax(...D,...k)}return b.length===1?b[0]:h}if(h instanceof CSSMathNegate)return h.value instanceof CSSUnitValue?new CSSUnitValue(0-h.value.value,h.value.unit):h.value instanceof CSSMathNegate?h.value.value:h;if(h instanceof CSSMathInvert)return h.value instanceof CSSMathInvert?h.value.value:h;if(h instanceof CSSMathSum){let b=function(k){const I=k.filter(D=>D instanceof CSSUnitValue);return[...k.filter(D=>!(D instanceof CSSUnitValue)),...Array.from(lt(I,"unit").entries()).map(([D,N])=>{const F=N.reduce((X,{value:Z})=>X+Z,0);return new CSSUnitValue(F,D)})]},M=[];for(const k of h.values)k instanceof CSSMathSum?M.push(...k.values):M.push(k);return M=b(M),M.length===1?M[0]:new CSSMathSum(...M)}if(h instanceof CSSMathProduct){let b=[];for(const I of h.values)I instanceof CSSMathProduct?b.push(...I.values):b.push(I);const[M,k]=De(b,I=>I instanceof CSSUnitValue&&I.unit==="number");if(M.length>1){const I=M.reduce((D,{value:N})=>D*N,1);b=[new CSSUnitValue(I,"number"),...k]}if(b.length===2){let I,D;for(const N of b)N instanceof CSSUnitValue&&N.unit==="number"?I=N:N instanceof CSSMathSum&&[...N.values].every(F=>F instanceof CSSUnitValue)&&(D=N);if(I&&D)return new CSSMathSum(...[...D.values].map(N=>new CSSUnitValue(N.value*I.value,N.unit)))}if(b.every(I=>I instanceof CSSUnitValue&&Ze(I.unit)||I instanceof CSSMathInvert&&I.value instanceof CSSUnitValue&&Ze(I.value.unit))){const I=new CSSMathProduct(...b).toSum();if(I&&I.values.length===1)return I.values[0]}return new CSSMathProduct(...b)}return h}const he=null,ft=["percent","length","angle","time","frequency","resolution","flex"],Re={fontRelativeLengths:{units:new Set(["em","rem","ex","rex","cap","rcap","ch","rch","ic","ric","lh","rlh"])},viewportRelativeLengths:{units:new Set(["vw","lvw","svw","dvw","vh","lvh","svh","dvh","vi","lvi","svi","dvi","vb","lvb","svb","dvb","vmin","lvmin","svmin","dvmin","vmax","lvmax","svmax","dvmax"])},absoluteLengths:{units:new Set(["cm","mm","Q","in","pt","pc","px"]),compatible:!0,canonicalUnit:"px",ratios:{cm:96/2.54,mm:96/2.54/10,Q:96/2.54/40,in:96,pc:16,pt:96/72,px:1}},angle:{units:new Set(["deg","grad","rad","turn"]),compatible:!0,canonicalUnit:"deg",ratios:{deg:1,grad:.9,rad:180/Math.PI,turn:360}},time:{units:new Set(["s","ms"]),compatible:!0,canonicalUnit:"s",ratios:{s:1,ms:.001}},frequency:{units:new Set(["hz","khz"]),compatible:!0,canonicalUnit:"hz",ratios:{hz:1,khz:1e3}},resolution:{units:new Set(["dpi","dpcm","dppx"]),compatible:!0,canonicalUnit:"dppx",ratios:{dpi:1/96,dpcm:2.54/96,dppx:1}}},fe=new Map;for(const h of Object.values(Re))if(h.compatible)for(const p of h.units)fe.set(p,h);function rt(h){return fe.get(h)}function wt(h,p){const y={...h};for(const b of Object.keys(p))y[b]?y[b]+=p[b]:y[b]=p[b];return y}function _t(h){return h==="number"?{}:h==="percent"?{percent:1}:Re.absoluteLengths.units.has(h)||Re.fontRelativeLengths.units.has(h)||Re.viewportRelativeLengths.units.has(h)?{length:1}:Re.angle.units.has(h)?{angle:1}:Re.time.units.has(h)?{time:1}:Re.frequency.units.has(h)?{frequency:1}:Re.resolution.units.has(h)?{resolution:1}:h==="fr"?{flex:1}:he}function st(h){if(h instanceof CSSUnitValue){let{unit:p,value:y}=h;const b=rt(h.unit);return b&&p!==b.canonicalUnit&&(y*=b.ratios[p],p=b.canonicalUnit),p==="number"?[[y,{}]]:[[y,{[p]:1}]]}if(h instanceof CSSMathInvert){if(!(h.value instanceof CSSUnitValue))throw new Error("Not implemented");const p=st(h.value);if(p===he||p.length>1)return he;const y=p[0],b={};for(const[M,k]of Object.entries(y[1]))b[M]=-1*k;return p[0]=[1/y[0],b],p}if(h instanceof CSSMathProduct){let p=[[1,{}]];for(const y of h.values){const b=st(y),M=[];if(b===he)return he;for(const k of p)for(const I of b)M.push([k[0]*I[0],wt(k[1],I[1])]);p=M}return p}throw new Error("Not implemented")}function Tt(h,p){if(_t(p)===he)throw new SyntaxError("The string did not match the expected pattern.");const y=st(h);if(!y)throw new TypeError;if(y.length>1)throw new TypeError("Sum has more than one item");const b=function(M,k){const I=M.unit,D=M.value,N=rt(I),F=rt(k);return!F||N!==F?he:new CSSUnitValue(D*F.ratios[I]/F.ratios[k],k)}(mt(y[0]),p);if(b===he)throw new TypeError;return b}function mt(h){const[p,y]=h,b=Object.entries(y);if(b.length>1)return he;if(b.length===0)return new CSSUnitValue(p,"number");const M=b[0];return M[1]!==1?he:new CSSUnitValue(p,M[0])}function yt(h,...p){if(p&&p.length)throw new Error("Not implemented");const y=st(h).map(b=>mt(b));if(y.some(b=>b===he))throw new TypeError("Type error");return new CSSMathSum(...y)}function ht(h,p){if(h.percentHint&&p.percentHint&&h.percentHint!==p.percentHint)return he;const y={...h,percentHint:h.percentHint??p.percentHint};for(const b of ft)p[b]&&(y[b]??(y[b]=0),y[b]+=p[b]);return y}class Ae{constructor(p,y){Me(this,"name"),Me(this,"values"),this.name=p,this.values=y}}class Ke{constructor(p,y){Me(this,"value"),Me(this,"associatedToken"),this.value=p,this.associatedToken=y}}function ut(h){if(Array.isArray(h))return h;if(typeof h=="string")return function(p){const y=new A(p),b=[];for(;;){const M=de(y);if(M===void 0)return b;b.push(M)}}(h);throw new TypeError("Invalid input type "+typeof h)}function Qe(h){const p=h.shift();return p instanceof E||p instanceof S||p instanceof C?function(y,b){let M;if(b instanceof E)M=O;else if(b instanceof C)M=P;else{if(!(b instanceof S))return;M=T}const k=new Ke([],b);for(;;){const I=y.shift();if(I instanceof M||I===void 0)return k;y.unshift(I),k.value.push(Qe(y))}}(h,p):p instanceof t?function(y,b){const M=new Ae(y.value,[]);for(;;){const k=b.shift();if(k instanceof P||k===void 0)return M;b.unshift(k),M.values.push(Qe(b))}}(p,h):p}function $(h){if(h instanceof C||h instanceof P)return 6;if(h instanceof l)switch(h.value){case"*":case"/":return 4;case"+":case"-":return 2}}function Mt(h){return h[h.length-1]}function jt(h,p,y){const b=["+","-"].includes(h.value)?"ADDITION":"MULTIPLICATION",M=p.type===b?p.values:[p],k=y.type===b?y.values:[y];return h.value==="-"?k[0]={type:"NEGATE",value:k[0]}:h.value==="/"&&(k[0]={type:"INVERT",value:k[0]}),{type:b,values:[...M,...k]}}function Ct(h){if(h.type==="ADDITION")return new CSSMathSum(...h.values.map(p=>Ct(p)));if(h.type==="MULTIPLICATION")return new CSSMathProduct(...h.values.map(p=>Ct(p)));if(h.type==="NEGATE")return new CSSMathNegate(Ct(h.value));if(h.type==="INVERT")return new CSSMathInvert(Ct(h.value));if(h instanceof Ke)return ae(new Ae("calc",h.value));if(h instanceof e){if(h.value==="e")return new CSSUnitValue(Math.E,"number");if(h.value==="pi")return new CSSUnitValue(Math.PI,"number");throw new SyntaxError("Invalid math expression")}return Bo(h)}function ae(h){if(h.name==="min"||h.name==="max"){const b=h.values.filter(M=>!(M instanceof f||M instanceof w)).map(M=>ve(ae(new Ae("calc",M))));return h.name==="min"?new CSSMathMin(...b):new CSSMathMax(...b)}if(h.name!=="calc")return null;const p=Ct(function(b){const M=[],k=[];for(;b.length;){const I=b.shift();if(I instanceof u||I instanceof m||I instanceof d||I instanceof Ae||I instanceof Ke||I instanceof e)k.push(I);else if(I instanceof l&&["*","/","+","-"].includes(I.value)){for(;M.length&&!(Mt(M)instanceof C)&&$(Mt(M))>$(I);){const D=M.pop(),N=k.pop(),F=k.pop();k.push(jt(D,F,N))}M.push(I)}else if(I instanceof C)M.push(I);else if(I instanceof P){if(!M.length)return null;for(;!(Mt(M)instanceof C);){const D=M.pop(),N=k.pop(),F=k.pop();k.push(jt(D,F,N))}if(!(Mt(M)instanceof C))return null;M.pop()}else if(!(I instanceof f))return null}for(;M.length;){if(Mt(M)instanceof C)return null;const I=M.pop(),D=k.pop(),N=k.pop();k.push(jt(I,N,D))}return k[0]}([...h.values]));let y;try{y=ve(p)}catch{new CSSStyleSheet().insertRule("error",0)}return y instanceof CSSUnitValue?new CSSMathSum(y):y}function Bo(h){return h instanceof Ae&&["calc","min","max","clamp"].includes(h.name)?ae(h):h instanceof u&&h.value===0&&!h.unit?new CSSUnitValue(0,"px"):h instanceof u?new CSSUnitValue(h.value,"number"):h instanceof d?new CSSUnitValue(h.value,"percent"):h instanceof m?new CSSUnitValue(h.value,h.unit):void 0}function Nl(h){const p=function(y){const b=ut(y);for(;b[0]instanceof f;)b.shift();if(b[0]===void 0)return null;const M=Qe(b);for(;b[0]instanceof f;)b.shift();return b[0]===void 0?M:null}(h);return p===null&&new CSSStyleSheet().insertRule("error",0),p instanceof u||p instanceof d||p instanceof m||p instanceof Ae||new CSSStyleSheet().insertRule("error",0),p instanceof m&&_t(p.unit)===null&&new CSSStyleSheet().insertRule("error",0),Bo(p)}(function(){let h=new WeakMap;function p(k){const I=[];for(let N=0;N<k.length;N++)I[N]=typeof(D=k[N])=="number"?new CSSUnitValue(D,"number"):D;var D;return I}class y{static parse(I){return I instanceof y?I:ve(Nl(I),{})}}class b extends y{constructor(I,D,N,F){super(),h.set(this,{values:p(I),operator:D,name:N||D,delimiter:F||", "})}get operator(){return h.get(this).operator}get values(){return h.get(this).values}toString(){const I=h.get(this);return`${I.name}(${I.values.join(I.delimiter)})`}}const M={CSSNumericValue:y,CSSMathValue:b,CSSUnitValue:class extends y{constructor(k,I){super(),h.set(this,{value:k,unit:I})}get value(){return h.get(this).value}set value(k){h.get(this).value=k}get unit(){return h.get(this).unit}to(k){return Tt(this,k)}toSum(...k){return yt(this,...k)}type(){return _t(h.get(this).unit)}toString(){const k=h.get(this);return`${k.value}${function(I){switch(I){case"percent":return"%";case"number":return"";default:return I.toLowerCase()}}(k.unit)}`}},CSSKeywordValue:class{constructor(k){this.value=k}toString(){return this.value.toString()}},CSSMathSum:class extends b{constructor(k){super(arguments,"sum","calc"," + ")}},CSSMathProduct:class extends b{constructor(k){super(arguments,"product","calc"," * ")}toSum(...k){return yt(this,...k)}type(){return h.get(this).values.map(k=>k.type()).reduce(ht)}},CSSMathNegate:class extends b{constructor(k){super([arguments[0]],"negate","-")}get value(){return h.get(this).values[0]}type(){return this.value.type()}},CSSMathInvert:class extends b{constructor(k){super([1,arguments[0]],"invert","calc"," / ")}get value(){return h.get(this).values[1]}type(){return function(k){const I={};for(const D of ft)I[D]=-1*k[D];return I}(h.get(this).values[1].type())}},CSSMathMax:class extends b{constructor(){super(arguments,"max")}},CSSMathMin:class extends b{constructor(){super(arguments,"min")}}};if(!window.CSS&&!Reflect.defineProperty(window,"CSS",{value:{}}))throw Error("Error installing CSSOM support");window.CSSUnitValue||["number","percent","em","ex","px","cm","mm","in","pt","pc","Q","vw","vh","vmin","vmax","rems","ch","deg","rad","grad","turn","ms","s","Hz","kHz","dppx","dpi","dpcm","fr"].forEach(k=>{if(!Reflect.defineProperty(CSS,k,{value:I=>new CSSUnitValue(I,k)}))throw Error(`Error installing CSS.${k}`)});for(let[k,I]of Object.entries(M))if(!(k in window)&&!Reflect.defineProperty(window,k,{value:I}))throw Error(`Error installing CSSOM support for ${k}`)})();const zo="block";let Ge=new WeakMap,Jt=new WeakMap;const tr=["entry","exit","cover","contain","entry-crossing","exit-crossing"];function No(h){return h===document.scrollingElement?document:h}function dn(h){cs(h);let p=Ge.get(h).animations;if(p.length===0)return;let y=h.currentTime;for(let b=0;b<p.length;b++)p[b].tickAnimation(y)}function Uo(h,p){if(!h)return null;const y=Jt.get(h).sourceMeasurements,b=getComputedStyle(h);let M=y.scrollTop;return Ue(p,b)==="x"&&(M=Math.abs(y.scrollLeft)),M}function as(h,p){const y=ve(h,p);if(y instanceof CSSUnitValue){if(y.unit==="px")return y.value;throw TypeError("Unhandled unit type "+y.unit)}throw TypeError("Unsupported value type: "+typeof h)}function cs(h){if(!(h instanceof Rn))return void function(y){const b=Ge.get(y);if(!b.anonymousSource)return;const M=Lo(b.anonymousSource,b.anonymousTarget);Qn(y,M)}(h);const p=h.subject;if(!p||getComputedStyle(p).display=="none")return void Qn(h,null);Qn(h,fs(p))}function Do(h){return["block","inline","x","y"].includes(h)}function ls(h){const p=getComputedStyle(h);return{scrollLeft:h.scrollLeft,scrollTop:h.scrollTop,scrollWidth:h.scrollWidth,scrollHeight:h.scrollHeight,clientWidth:h.clientWidth,clientHeight:h.clientHeight,writingMode:p.writingMode,direction:p.direction,scrollPaddingTop:p.scrollPaddingTop,scrollPaddingBottom:p.scrollPaddingBottom,scrollPaddingLeft:p.scrollPaddingLeft,scrollPaddingRight:p.scrollPaddingRight}}function hs(h,p){if(!h||!p)return;let y=0,b=0,M=p;const k=h.offsetParent;for(;M&&M!=k;)b+=M.offsetLeft,y+=M.offsetTop,M=M.offsetParent;b-=h.offsetLeft+h.clientLeft,y-=h.offsetTop+h.clientTop;const I=getComputedStyle(p);return{top:y,left:b,offsetWidth:p.offsetWidth,offsetHeight:p.offsetHeight,fontSize:I.fontSize}}function nr(h){let p=Jt.get(h);p.sourceMeasurements=ls(h);for(const y of p.timelineRefs){const b=y.deref();b instanceof Rn&&(Ge.get(b).subjectMeasurements=hs(h,b.subject))}p.updateScheduled||(setTimeout(()=>{for(const y of p.timelineRefs){const b=y.deref();b&&dn(b)}p.updateScheduled=!1}),p.updateScheduled=!0)}function Qn(h,p){const y=Ge.get(h),b=y.source;if(b!=p){if(b){const M=Jt.get(b);if(M){M.timelineRefs.delete(h);const k=Array.from(M.timelineRefs).filter(I=>I.deref()===void 0);for(const I of k)M.timelineRefs.delete(I);M.timelineRefs.size===0&&(M.disconnect(),Jt.delete(b))}}if(y.source=p,p){let M=Jt.get(p);if(!M){M={timelineRefs:new Set,sourceMeasurements:ls(p)},Jt.set(p,M);const k=new ResizeObserver(N=>{for(const F of N)nr(y.source)});k.observe(p);for(const N of p.children)k.observe(N);const I=new MutationObserver(N=>{for(const F of N)nr(F.target)});I.observe(p,{attributes:!0,attributeFilter:["style","class"]});const D=()=>{M.sourceMeasurements.scrollLeft=p.scrollLeft,M.sourceMeasurements.scrollTop=p.scrollTop;for(const N of M.timelineRefs){const F=N.deref();F&&dn(F)}};No(p).addEventListener("scroll",D),M.disconnect=()=>{k.disconnect(),I.disconnect(),No(p).removeEventListener("scroll",D)}}M.timelineRefs.add(new WeakRef(h))}}}function us(h,p){let y=Ge.get(h).animations;for(let b=0;b<y.length;b++)y[b].animation==p&&y.splice(b,1)}function ds(h,p,y){let b=Ge.get(h).animations;for(let M=0;M<b.length;M++)if(b[M].animation==p)return;b.push({animation:p,tickAnimation:y}),queueMicrotask(()=>{dn(h)})}class $e{constructor(p){if(Ge.set(this,{source:null,axis:zo,anonymousSource:p?p.anonymousSource:null,anonymousTarget:p?p.anonymousTarget:null,subject:null,inset:null,animations:[],subjectMeasurements:null}),Qn(this,p&&p.source!==void 0?p.source:document.scrollingElement),p&&p.axis!==void 0&&p.axis!=zo){if(!Do(p.axis))throw TypeError("Invalid axis");Ge.get(this).axis=p.axis}dn(this)}set source(p){Qn(this,p),dn(this)}get source(){return Ge.get(this).source}set axis(p){if(!Do(p))throw TypeError("Invalid axis");Ge.get(this).axis=p,dn(this)}get axis(){return Ge.get(this).axis}get duration(){return CSS.percent(100)}get phase(){const p=this.source;if(!p)return"inactive";let y=getComputedStyle(p);return y.display=="none"?"inactive":p==document.scrollingElement||y.overflow!="visible"&&y.overflow!="clip"?"active":"inactive"}get currentTime(){const p=this.source;if(!p||!p.isConnected||this.phase=="inactive")return null;const y=getComputedStyle(p);if(y.display==="inline"||y.display==="none")return null;const b=this.axis,M=Uo(p,b),k=function(I,D){const N=Jt.get(I).sourceMeasurements,F=getComputedStyle(I).writingMode=="horizontal-tb";return D==="block"?D=F?"y":"x":D==="inline"&&(D=F?"x":"y"),D==="y"?N.scrollHeight-N.clientHeight:D==="x"?N.scrollWidth-N.clientWidth:void 0}(p,b);return k>0?CSS.percent(100*M/k):CSS.percent(100)}get __polyfill(){return!0}}function ps(h,p){let y=h.parentElement;for(;y!=null;){if(p(y))return y;y=y.parentElement}}function Lo(h,p){switch(h){case"root":return document.scrollingElement;case"nearest":return fs(p);case"self":return p;default:throw new TypeError("Invalid ScrollTimeline Source Type.")}}function Ul(h){switch(getComputedStyle(h).display){case"block":case"inline-block":case"list-item":case"table":case"table-caption":case"flow-root":case"flex":case"grid":return!0}return!1}function Fo(h){const p=getComputedStyle(h);return p.transform!="none"||p.perspective!="none"||p.willChange=="transform"||p.willChange=="perspective"||p.filter!="none"||p.willChange=="filter"||p.backdropFilter!="none"}function Dl(h){return getComputedStyle(h).position!="static"||Fo(h)}function Ll(h){switch(getComputedStyle(h).position){case"static":case"relative":case"sticky":return ps(h,Ul);case"absolute":return ps(h,Dl);case"fixed":return ps(h,Fo)}}function fs(h){if(h&&h.isConnected){for(;h=Ll(h);)switch(getComputedStyle(h)["overflow-x"]){case"auto":case"scroll":case"hidden":return h==document.body&&getComputedStyle(document.scrollingElement).overflow=="visible"?document.scrollingElement:h}return document.scrollingElement}}function $n(h,p){const y=Ge.get(h),b=y.subjectMeasurements,M=Jt.get(y.source).sourceMeasurements;return h.phase==="inactive"?null:h instanceof Rn?ms(p,M,b,y.axis,y.inset):null}function ms(h,p,y,b,M){const k=p.direction=="rtl"||p.writingMode=="vertical-rl";let I,D,N={fontSize:y.fontSize};Ue(b,p)==="x"?(I=y.offsetWidth,D=y.left,N.scrollPadding=[p.scrollPaddingLeft,p.scrollPaddingRight],k&&(D+=p.scrollWidth-p.clientWidth,N.scrollPadding=[p.scrollPaddingRight,p.scrollPaddingLeft]),N.containerSize=p.clientWidth):(I=y.offsetHeight,D=y.top,N.scrollPadding=[p.scrollPaddingTop,p.scrollPaddingBottom],N.containerSize=p.clientHeight);const F=function(Ss,ar){const Kl={start:0,end:0};if(!Ss)return Kl;const[Ql,$l]=[Ss.start,Ss.end].map((ta,na)=>ta==="auto"?ar.scrollPadding[na]==="auto"?0:parseFloat(ar.scrollPadding[na]):as(ta,{percentageReference:CSS.px(ar.containerSize),fontSize:CSS.px(parseFloat(ar.fontSize))}));return{start:Ql,end:$l}}(M,N),X=D-N.containerSize+F.end,Z=D+I-F.start,K=X+I,me=Z-I,_e=Math.min(K,me),ot=Math.max(K,me);let Pt,gt;const ea=I>N.containerSize-F.start-F.end;switch(h){case"cover":Pt=X,gt=Z;break;case"contain":Pt=_e,gt=ot;break;case"entry":Pt=X,gt=_e;break;case"exit":Pt=ot,gt=Z;break;case"entry-crossing":Pt=X,gt=ea?ot:_e;break;case"exit-crossing":Pt=ea?_e:ot,gt=Z}return{start:Pt,end:gt}}function Vo(h,p){if(h instanceof Rn){const{rangeName:y,offset:b}=p;return jo($n(h,y),b,$n(h,"cover"),h.subject)}if(h instanceof $e){const{axis:y,source:b}=h,{sourceMeasurements:M}=Jt.get(b);let k;return k=Ue(y,M)==="x"?M.scrollWidth-M.clientWidth:M.scrollHeight-M.clientHeight,as(p,{percentageReference:CSS.px(k)})/k}unsupportedTimeline(h)}function jo(h,p,y,b){if(!h||!y)return 0;let M=getComputedStyle(b);return(as(p,{percentageReference:CSS.px(h.end-h.start),fontSize:CSS.px(parseFloat(M.fontSize))})+h.start-y.start)/(y.end-y.start)}let Rn=class extends $e{constructor(h){super(h);const p=Ge.get(this);p.subject=h&&h.subject?h.subject:void 0,h&&h.inset&&(p.inset=function(y){if(!y)return{start:0,end:0};let b;if(b=typeof y=="string"?ke(y).map(M=>{if(M==="auto")return"auto";try{return CSSNumericValue.parse(M)}catch{throw TypeError(`Could not parse inset "${y}"`)}}):Array.isArray(y)?y:[y],b.length===0||b.length>2)throw TypeError("Invalid inset");for(const M of b){if(M==="auto")continue;const k=M.type();if(k.length!==1&&k.percent!==1)throw TypeError("Invalid inset")}return{start:b[0],end:b[1]??b[0]}}(h.inset)),p.subject&&(new ResizeObserver(()=>{nr(p.source)}).observe(p.subject),new MutationObserver(()=>{nr(p.source)}).observe(p.subject,{attributes:!0,attributeFilter:["class","style"]})),cs(this),p.subjectMeasurements=hs(p.source,p.subject),dn(this)}get source(){return cs(this),Ge.get(this).source}set source(h){throw new Error("Cannot set the source of a view timeline")}get subject(){return Ge.get(this).subject}get axis(){return Ge.get(this).axis}get currentTime(){const h=Uo(this.source,this.axis);if(h==null)return null;const p=$n(this,"cover");if(!p)return null;const y=(h-p.start)/(p.end-p.start);return CSS.percent(100*y)}get startOffset(){return CSS.px($n(this,"cover").start)}get endOffset(){return CSS.px($n(this,"cover").end)}};const Fl=document.getAnimations,Vl=window.Element.prototype.getAnimations,jl=window.Element.prototype.animate,Jo=window.Animation;class An{constructor(){this.state="pending",this.nativeResolve=this.nativeReject=null,this.promise=new Promise((p,y)=>{this.nativeResolve=p,this.nativeReject=y})}resolve(p){this.state="resolved",this.nativeResolve(p)}reject(p){this.state="rejected",this.promise.catch(()=>{}),this.nativeReject(p)}}function ei(h){h.readyPromise=new An,requestAnimationFrame(()=>{var p;(((p=h.timeline)==null?void 0:p.currentTime)??null)!==null&&(ir(h),h.pendingTask!=="play"||h.startTime===null&&h.holdTime===null?h.pendingTask==="pause"&&Ho(h):Wo(h))})}function Go(){return new DOMException("The user aborted a request","AbortError")}function pn(h,p){if(p===null)return p;if(typeof p!="number")throw new DOMException(`Unexpected value: ${p}. Cannot convert to CssNumberish`,"InvalidStateError");const y=h.rangeDuration??100,b=Wt(h),M=b?y*p/b:0;return CSS.percent(M)}function Se(h,p){if(h.timeline){if(p===null)return p;if(p.unit==="percent"){const y=h.rangeDuration??100,b=Wt(h);return p.value*b/y}throw new DOMException("CSSNumericValue must be a percentage for progress based animations.","NotSupportedError")}{if(p==null||typeof p=="number")return p;const y=p.to("ms");if(y)return y.value;throw new DOMException("CSSNumericValue must be either a number or a time value for time based animations.","InvalidStateError")}}function Wo(h){const p=Se(h,h.timeline.currentTime);if(h.holdTime!=null)Bt(h),h.animation.playbackRate==0?h.startTime=p:(h.startTime=p-h.holdTime/h.animation.playbackRate,h.holdTime=null);else if(h.startTime!==null&&h.pendingPlaybackRate!==null){const y=(p-h.startTime)*h.animation.playbackRate;Bt(h);const b=h.animation.playbackRate;b==0?(h.holdTime=null,h.startTime=p):h.startTime=p-y/b}h.readyPromise&&h.readyPromise.state=="pending"&&h.readyPromise.resolve(h.proxy),Gt(h,!1,!1),Ht(h),h.pendingTask=null}function Ho(h){const p=Se(h,h.timeline.currentTime);h.startTime!=null&&h.holdTime==null&&(h.holdTime=(p-h.startTime)*h.animation.playbackRate),Bt(h),h.startTime=null,h.readyPromise.resolve(h.proxy),Gt(h,!1,!1),Ht(h),h.pendingTask=null}function qo(h){if(!h.finishedPromise||h.finishedPromise.state!="pending"||h.proxy.playState!="finished")return;h.finishedPromise.resolve(h.proxy),h.animation.pause();const p=new CustomEvent("finish",{detail:{currentTime:h.proxy.currentTime,timelineTime:h.proxy.timeline.currentTime}});Object.defineProperty(p,"currentTime",{get:function(){return this.detail.currentTime}}),Object.defineProperty(p,"timelineTime",{get:function(){return this.detail.timelineTime}}),requestAnimationFrame(()=>{queueMicrotask(()=>{h.animation.dispatchEvent(p)})})}function On(h){return h.pendingPlaybackRate!==null?h.pendingPlaybackRate:h.animation.playbackRate}function Bt(h){h.pendingPlaybackRate!==null&&(h.animation.playbackRate=h.pendingPlaybackRate,h.pendingPlaybackRate=null)}function Xo(h){if(!h.timeline)return null;const p=Se(h,h.timeline.currentTime);if(p===null||h.startTime===null)return null;let y=(p-h.startTime)*h.animation.playbackRate;return y==-0&&(y=0),y}function Gt(h,p,y){if(!h.timeline)return;let b=p?Se(h,h.proxy.currentTime):Xo(h);if(b&&h.startTime!=null&&!h.proxy.pending){const M=On(h),k=Wt(h);let I=h.previousCurrentTime;M>0&&b>=k&&h.previousCurrentTime!=null?((I===null||I<k)&&(I=k),h.holdTime=p?b:I):M<0&&b<=0?((I==null||I>0)&&(I=0),h.holdTime=p?b:I):M!=0&&(p&&h.holdTime!==null&&(h.startTime=function(D,N){if(!D.timeline)return null;const F=Se(D,D.timeline.currentTime);return F==null?null:F-N/D.animation.playbackRate}(h,h.holdTime)),h.holdTime=null)}Ht(h),h.previousCurrentTime=Se(h,h.proxy.currentTime),h.proxy.playState=="finished"?(h.finishedPromise||(h.finishedPromise=new An),h.finishedPromise.state=="pending"&&(y?qo(h):Promise.resolve().then(()=>{qo(h)}))):(h.finishedPromise&&h.finishedPromise.state=="resolved"&&(h.finishedPromise=new An),h.animation.playState!="paused"&&h.animation.pause())}function Wt(h){const p=function(b){const M=b.proxy.effect.getTiming();return b.normalizedTiming||M}(h),y=p.delay+p.endDelay+p.iterations*p.duration;return Math.max(0,y)}function Ht(h){if(h.timeline)if(h.startTime!==null){const p=h.timeline.currentTime;if(p==null)return;ys(h,(Se(h,p)-h.startTime)*h.animation.playbackRate)}else h.holdTime!==null&&ys(h,h.holdTime)}function ys(h,p){const y=h.timeline,b=h.animation.playbackRate,M=y.currentTime&&y.currentTime.value==(b<0?0:100)?b<0?.001:-.001:0;h.animation.currentTime=p+M}function gs(h,p){if(!h.timeline)return;const y=h.proxy.playState=="paused"&&h.proxy.pending;let b=!1,M=Se(h,h.proxy.currentTime);On(h)==0&&M==null&&(h.holdTime=0),M==null&&(h.autoAlignStartTime=!0),(h.proxy.playState==="finished"||y)&&(h.holdTime=null,h.startTime=null,h.autoAlignStartTime=!0),h.holdTime&&(h.startTime=null),h.pendingTask&&(h.pendingTask=null,b=!0),(h.holdTime!==null||h.autoAlignStartTime||y||h.pendingPlaybackRate!==null)&&(h.readyPromise&&!b&&(h.readyPromise=null),Ht(h),h.readyPromise||ei(h),h.pendingTask="play",ds(h.timeline,h.animation,vs.bind(h.proxy)),Gt(h,!1,!1))}function vs(h){const p=Y.get(this);if(!p)return;if(h==null)return void(p.proxy.playState!=="paused"&&p.animation.playState!="idle"&&p.animation.cancel());ir(p),p.pendingTask&&requestAnimationFrame(()=>{p.pendingTask!=="play"||p.startTime===null&&p.holdTime===null?p.pendingTask==="pause"&&Ho(p):Wo(p)});const y=this.playState;if(y=="running"||y=="finished"){const b=Se(p,h);ys(p,(b-Se(p,this.startTime))*this.playbackRate),Gt(p,!1,!1)}}function Yo(h){h.specifiedTiming=null}let Y=new WeakMap;window.addEventListener("pagehide",h=>{Y=new WeakMap},!1);let Zo=new WeakMap;function ir(h){if(!h.autoAlignStartTime||!h.timeline||!h.timeline.currentTime||h.proxy.playState==="idle"||h.proxy.playState==="paused"&&h.holdTime!==null)return;const p=h.rangeDuration;let y,b;try{y=CSS.percent(100*function(k){if(!k.animationRange)return 0;const I=k.animationRange.start==="normal"?Ko(k.timeline):k.animationRange.start;return Vo(k.timeline,I)}(h))}catch(k){y=CSS.percent(0),h.animationRange.start="normal",console.warn("Exception when calculating start offset",k)}try{b=CSS.percent(100*(1-function(k){if(!k.animationRange)return 0;const I=k.animationRange.end==="normal"?Qo(k.timeline):k.animationRange.end;return 1-Vo(k.timeline,I)}(h)))}catch(k){b=CSS.percent(100),h.animationRange.end="normal",console.warn("Exception when calculating end offset",k)}h.rangeDuration=b.value-y.value;const M=On(h);h.startTime=Se(h,M>=0?y:b),h.holdTime=null,h.rangeDuration!==p&&Yo(h)}function rr(h){throw new Error("Unsupported timeline class")}function Ko(h){return h instanceof ViewTimeline?{rangeName:"cover",offset:CSS.percent(0)}:h instanceof $e?CSS.percent(0):void rr()}function Qo(h){return h instanceof ViewTimeline?{rangeName:"cover",offset:CSS.percent(100)}:h instanceof $e?CSS.percent(100):void rr()}function Jl(h,p){if(!p)return{start:"normal",end:"normal"};const y={start:Ko(h),end:Qo(h)};if(h instanceof ViewTimeline){const b=ke(p),M=[],k=[];if(b.forEach(I=>{if(tr.includes(I))M.push(I);else try{k.push(CSSNumericValue.parse(I))}catch{throw TypeError(`Could not parse range "${p}"`)}}),M.length>2||k.length>2||k.length==1)throw TypeError("Invalid time range or unsupported time range format.");return M.length&&(y.start.rangeName=M[0],y.end.rangeName=M.length>1?M[1]:M[0]),k.length>1&&(y.start.offset=k[0],y.end.offset=k[1]),y}if(h instanceof $e){const b=p.split(" ");if(b.length!=2)throw TypeError("Invalid time range or unsupported time range format.");return y.start=CSSNumericValue.parse(b[0]),y.end=CSSNumericValue.parse(b[1]),y}rr()}function sr(h,p,y){if(!p||p==="normal")return"normal";if(h instanceof ViewTimeline){let b="cover",M=y==="start"?CSS.percent(0):CSS.percent(100);if(p instanceof Object)p.rangeName!==void 0&&(b=p.rangeName),p.offset!==void 0&&(M=p.offset);else{const k=ke(p);k.length===1?tr.includes(k[0])?b=k[0]:M=ve(CSSNumericValue.parse(k[0]),{}):k.length===2&&(b=k[0],M=ve(CSSNumericValue.parse(k[1]),{}))}if(!tr.includes(b))throw TypeError("Invalid range name");return{rangeName:b,offset:M}}if(h instanceof $e)return CSSNumericValue.parse(p);rr()}class or{constructor(p,y,b={}){const M=y instanceof $e,k=p instanceof Jo?p:new Jo(p,M?void 0:y);Zo.set(k,this),Y.set(this,{animation:k,timeline:M?y:void 0,playState:M?"idle":null,readyPromise:null,finishedPromise:null,startTime:null,holdTime:null,rangeDuration:null,previousCurrentTime:null,autoAlignStartTime:!1,pendingPlaybackRate:null,pendingTask:null,specifiedTiming:null,normalizedTiming:null,effect:null,animationRange:M?Jl(y,b["animation-range"]):null,proxy:this})}get effect(){const p=Y.get(this);return p.timeline?(p.effect||(p.effect=function(y){const b=y.animation.effect,M=b.updateTiming,k={apply:function(F){b.getTiming();const X=F.apply(b);if(y.timeline){const Z=y.duration??100;X.localTime=pn(y,X.localTime),X.endTime=pn(y,X.endTime),X.activeDuration=pn(y,X.activeDuration);const K=Wt(y),me=X.iterations?(K-X.delay-X.endDelay)/X.iterations:0;X.duration=K?CSS.percent(Z*me/K):CSS.percent(0),y.timeline.currentTime===void 0&&(X.localTime=null)}return X}},I={apply:function(F,X){if(y.specifiedTiming)return y.specifiedTiming;y.specifiedTiming=F.apply(b);let Z,K=Object.assign({},y.specifiedTiming);if(K.duration===1/0)throw TypeError("Effect duration cannot be Infinity when used with Scroll Timelines");return(K.duration===null||K.duration==="auto"||y.autoDurationEffect)&&y.timeline&&(y.autoDurationEffect=!0,K.delay=0,K.endDelay=0,Z=K.iterations?1e5:0,K.duration=K.iterations?(Z-K.delay-K.endDelay)/K.iterations:0,K.duration<0&&(K.duration=0,K.endDelay=Z-K.delay),M.apply(b,[K])),y.normalizedTiming=K,y.specifiedTiming}},D={apply:function(F,X,Z){if(Z&&Z.length){if(y.timeline&&Z[0]){const K=Z[0],me=K.duration;if(me===1/0)throw TypeError("Effect duration cannot be Infinity when used with Scroll Timelines");if(K.iterations===1/0)throw TypeError("Effect iterations cannot be Infinity when used with Scroll Timelines");me!==void 0&&me!=="auto"&&(y.autoDurationEffect=null)}y.specifiedTiming&&F.apply(b,[y.specifiedTiming]),F.apply(b,Z),Yo(y)}}},N=new Proxy(b,{get:function(F,X){const Z=F[X];return typeof Z=="function"?Z.bind(b):Z},set:function(F,X,Z){return F[X]=Z,!0}});return N.getComputedTiming=new Proxy(b.getComputedTiming,k),N.getTiming=new Proxy(b.getTiming,I),N.updateTiming=new Proxy(b.updateTiming,D),N}(p)),p.effect):p.animation.effect}set effect(p){const y=Y.get(this);y.animation.effect=p,y.effect=null,y.autoDurationEffect=null}get timeline(){const p=Y.get(this);return p.timeline||p.animation.timeline}set timeline(p){const y=Y.get(this),b=this.timeline;if(b==p)return;const M=this.playState,k=this.currentTime;let I,D=Wt(y);I=k===null?null:D===0?0:Se(y,k)/D;const N=b instanceof $e,F=p instanceof $e,X=this.pending;if(N&&us(y.timeline,y.animation),F)return y.timeline=p,Bt(y),y.autoAlignStartTime=!0,y.startTime=null,y.holdTime=null,M!=="running"&&M!=="finished"||(y.readyPromise&&y.readyPromise.state!=="resolved"||ei(y),y.pendingTask="play",ds(y.timeline,y.animation,vs.bind(this))),M==="paused"&&I!==null&&(y.holdTime=I*D),X&&(y.readyPromise&&y.readyPromise.state!="resolved"||ei(y),y.pendingTask=M=="paused"?"pause":"play"),y.startTime!==null&&(y.holdTime=null),void Gt(y,!1,!1);if(y.animation.timeline!=p)throw TypeError("Unsupported timeline: "+p);if(us(y.timeline,y.animation),y.timeline=null,N)switch(k!==null&&(y.animation.currentTime=I*Wt(y)),M){case"paused":y.animation.pause();break;case"running":case"finished":y.animation.play()}}get startTime(){const p=Y.get(this);return p.timeline?pn(p,p.startTime):p.animation.startTime}set startTime(p){const y=Y.get(this);if(p=Se(y,p),!y.timeline)return void(y.animation.startTime=p);y.autoAlignStartTime=!1,Se(y,y.timeline.currentTime)==null&&y.startTime!=null&&(y.holdTime=null,Ht(y));const b=Se(y,this.currentTime);Bt(y),y.startTime=p,y.startTime!==null&&y.animation.playbackRate!=0?y.holdTime=null:y.holdTime=b,y.pendingTask&&(y.pendingTask=null,y.readyPromise.resolve(this)),Gt(y,!0,!1),Ht(y)}get currentTime(){const p=Y.get(this);return p.timeline?p.holdTime!=null?pn(p,p.holdTime):pn(p,Xo(p)):p.animation.currentTime}set currentTime(p){const y=Y.get(this);y.timeline?(function(b,M){if(M==null&&b.currentTime!==null)throw new TypeError;M=Se(b,M),b.autoAlignStartTime=!1,b.holdTime!==null||b.startTime===null||b.timeline.phase==="inactive"||b.animation.playbackRate===0?b.holdTime=M:b.startTime=Se(b,b.timeline.currentTime)-M/b.animation.playbackRate,b.timeline.phase==="inactive"&&(b.startTime=null),b.previousCurrentTime=null}(y,p),y.pendingTask=="pause"&&(y.holdTime=Se(y,p),Bt(y),y.startTime=null,y.pendingTask=null,y.readyPromise.resolve(this)),Gt(y,!0,!1)):y.animation.currentTime=p}get playbackRate(){return Y.get(this).animation.playbackRate}set playbackRate(p){const y=Y.get(this);if(!y.timeline)return void(y.animation.playbackRate=p);y.pendingPlaybackRate=null;const b=this.currentTime;y.animation.playbackRate=p,b!==null&&(this.currentTime=b)}get playState(){const p=Y.get(this);if(!p.timeline)return p.animation.playState;const y=Se(p,this.currentTime);return y===null&&p.startTime===null&&p.pendingTask==null?"idle":p.pendingTask=="pause"||p.startTime===null&&p.pendingTask!="play"?"paused":y!=null&&(p.animation.playbackRate>0&&y>=Wt(p)||p.animation.playbackRate<0&&y<=0)?"finished":"running"}get rangeStart(){var p;return((p=Y.get(this).animationRange)==null?void 0:p.start)??"normal"}set rangeStart(p){const y=Y.get(this);if(!y.timeline)return y.animation.rangeStart=p;y.timeline instanceof $e&&(y.animationRange.start=sr(y.timeline,p,"start"),ir(y),Ht(y))}get rangeEnd(){var p;return((p=Y.get(this).animationRange)==null?void 0:p.end)??"normal"}set rangeEnd(p){const y=Y.get(this);if(!y.timeline)return y.animation.rangeEnd=p;y.timeline instanceof $e&&(y.animationRange.end=sr(y.timeline,p,"end"),ir(y),Ht(y))}get replaceState(){return Y.get(this).animation.pending}get pending(){const p=Y.get(this);return p.timeline?!!p.readyPromise&&p.readyPromise.state=="pending":p.animation.pending}finish(){const p=Y.get(this);if(!p.timeline)return void p.animation.finish();const y=On(p),b=Wt(p);if(y==0)throw new DOMException("Cannot finish Animation with a playbackRate of 0.","InvalidStateError");if(y>0&&b==1/0)throw new DOMException("Cannot finish Animation with an infinite target effect end.","InvalidStateError");Bt(p);const M=y<0?0:b;this.currentTime=pn(p,M);const k=Se(p,p.timeline.currentTime);p.startTime===null&&k!==null&&(p.startTime=k-M/p.animation.playbackRate),p.pendingTask=="pause"&&p.startTime!==null&&(p.holdTime=null,p.pendingTask=null,p.readyPromise.resolve(this)),p.pendingTask=="play"&&p.startTime!==null&&(p.pendingTask=null,p.readyPromise.resolve(this)),Gt(p,!0,!0)}play(){const p=Y.get(this);p.timeline?gs(p):p.animation.play()}pause(){const p=Y.get(this);p.timeline?this.playState!="paused"&&(p.animation.currentTime===null&&(p.autoAlignStartTime=!0),p.pendingTask=="play"?p.pendingTask=null:p.readyPromise=null,p.readyPromise||ei(p),p.pendingTask="pause",ds(p.timeline,p.animation,vs.bind(p.proxy))):p.animation.pause()}reverse(){const p=Y.get(this),y=On(p),b=Se(p,this.currentTime),M=Wt(p)==1/0,k=y!=0&&(y<0||b>0||!M);if(!p.timeline||!k)return k&&(p.pendingPlaybackRate=-On(p)),void p.animation.reverse();if(p.timeline.phase=="inactive")throw new DOMException("Cannot reverse an animation with no active timeline","InvalidStateError");this.updatePlaybackRate(-y),gs(p)}updatePlaybackRate(p){const y=Y.get(this);if(y.pendingPlaybackRate=p,!y.timeline)return void y.animation.updatePlaybackRate(p);const b=this.playState;if(!y.readyPromise||y.readyPromise.state!="pending")switch(b){case"idle":case"paused":Bt(y);break;case"finished":const M=Se(y,y.timeline.currentTime),k=M!==null?(M-y.startTime)*y.animation.playbackRate:null;y.startTime=p==0?M:M!=null&&k!=null?(M-k)/p:null,Bt(y),Gt(y,!1,!1),Ht(y);break;default:gs(y)}}persist(){Y.get(this).animation.persist()}get id(){return Y.get(this).animation.id}set id(p){Y.get(this).animation.id=p}cancel(){const p=Y.get(this);p.timeline?(this.playState!="idle"&&(function(y){y.pendingTask&&(y.pendingTask=null,Bt(y),y.readyPromise.reject(Go()),ei(y),y.readyPromise.resolve(y.proxy))}(p),p.finishedPromise&&p.finishedPromise.state=="pending"&&p.finishedPromise.reject(Go()),p.finishedPromise=new An,p.animation.cancel()),p.startTime=null,p.holdTime=null,us(p.timeline,p.animation)):p.animation.cancel()}get onfinish(){return Y.get(this).animation.onfinish}set onfinish(p){Y.get(this).animation.onfinish=p}get oncancel(){return Y.get(this).animation.oncancel}set oncancel(p){Y.get(this).animation.oncancel=p}get onremove(){return Y.get(this).animation.onremove}set onremove(p){Y.get(this).animation.onremove=p}get finished(){const p=Y.get(this);return p.timeline?(p.finishedPromise||(p.finishedPromise=new An),p.finishedPromise.promise):p.animation.finished}get ready(){const p=Y.get(this);return p.timeline?(p.readyPromise||(p.readyPromise=new An,p.readyPromise.resolve(this)),p.readyPromise.promise):p.animation.ready}addEventListener(p,y,b){Y.get(this).animation.addEventListener(p,y,b)}removeEventListener(p,y,b){Y.get(this).animation.removeEventListener(p,y,b)}dispatchEvent(p){Y.get(this).animation.dispatchEvent(p)}}function Gl(h,p){const y=p.timeline;y instanceof $e&&delete p.timeline;const b=jl.apply(this,[h,p]),M=new or(b,y);return y instanceof $e&&(b.pause(),Y.get(M).animationRange={start:sr(y,p.rangeStart,"start"),end:sr(y,p.rangeEnd,"end")},M.play()),M}function $o(h){for(let p=0;p<h.length;++p){let y=Zo.get(h[p]);y&&(h[p]=y)}return h}function Wl(h){return $o(Vl.apply(this,[h]))}function Hl(h){return $o(Fl.apply(this,[h]))}const Oe={IDENTIFIER:/[\w\\\@_-]+/g,WHITE_SPACE:/\s*/g,TIME:/^[0-9]+(s|ms)/,SCROLL_TIMELINE:/scroll-timeline\s*:([^;}]+)/,SCROLL_TIMELINE_NAME:/scroll-timeline-name\s*:([^;}]+)/,SCROLL_TIMELINE_AXIS:/scroll-timeline-axis\s*:([^;}]+)/,VIEW_TIMELINE:/view-timeline\s*:([^;}]+)/,VIEW_TIMELINE_NAME:/view-timeline-name\s*:([^;}]+)/,VIEW_TIMELINE_AXIS:/view-timeline-axis\s*:([^;}]+)/,VIEW_TIMELINE_INSET:/view-timeline-inset\s*:([^;}]+)/,ANIMATION_TIMELINE:/animation-timeline\s*:([^;}]+)/,ANIMATION_TIME_RANGE:/animation-range\s*:([^;}]+)/,ANIMATION_NAME:/animation-name\s*:([^;}]+)/,ANIMATION:/animation\s*:([^;}]+)/,ANONYMOUS_SCROLL_TIMELINE:/scroll\(([^)]*)\)/,ANONYMOUS_VIEW_TIMELINE:/view\(([^)]*)\)/},In=["block","inline","x","y"],ql=["nearest","root","self"],tn=new class{constructor(){this.cssRulesWithTimelineName=[],this.nextAnonymousTimelineNameIndex=0,this.anonymousScrollTimelineOptions=new Map,this.anonymousViewTimelineOptions=new Map,this.sourceSelectorToScrollTimeline=[],this.subjectSelectorToViewTimeline=[],this.keyframeNamesSelectors=new Map}transpileStyleSheet(h,p,y){const b={sheetSrc:h,index:0,name:y};for(;b.index<b.sheetSrc.length&&(this.eatWhitespace(b),!(b.index>=b.sheetSrc.length));){if(this.lookAhead("/*",b)){for(;this.lookAhead("/*",b);)this.eatComment(b),this.eatWhitespace(b);continue}const M=this.parseQualifiedRule(b);M&&(p?this.parseKeyframesAndSaveNameMapping(M,b):this.handleScrollTimelineProps(M,b))}return b.sheetSrc}getAnimationTimelineOptions(h,p){for(let y=this.cssRulesWithTimelineName.length-1;y>=0;y--){const b=this.cssRulesWithTimelineName[y];try{if(p.matches(b.selector)&&(!b["animation-name"]||b["animation-name"]==h))return{"animation-timeline":b["animation-timeline"],"animation-range":b["animation-range"]}}catch{}}return null}getAnonymousScrollTimelineOptions(h,p){const y=this.anonymousScrollTimelineOptions.get(h);return y?{anonymousSource:y.source,anonymousTarget:p,source:Lo(y.source??"nearest",p),axis:y.axis?y.axis:"block"}:null}getScrollTimelineOptions(h,p){const y=this.getAnonymousScrollTimelineOptions(h,p);if(y)return y;for(let b=this.sourceSelectorToScrollTimeline.length-1;b>=0;b--){const M=this.sourceSelectorToScrollTimeline[b];if(M.name==h){const k=this.findPreviousSiblingOrAncestorMatchingSelector(p,M.selector);if(k)return{source:k,...M.axis?{axis:M.axis}:{}}}}return null}findPreviousSiblingOrAncestorMatchingSelector(h,p){let y=h;for(;y;){if(y.matches(p))return y;y=y.previousElementSibling||y.parentElement}return null}getAnonymousViewTimelineOptions(h,p){const y=this.anonymousViewTimelineOptions.get(h);return y?{subject:p,axis:y.axis?y.axis:"block",inset:y.inset?y.inset:"auto"}:null}getViewTimelineOptions(h,p){const y=this.getAnonymousViewTimelineOptions(h,p);if(y)return y;for(let b=this.subjectSelectorToViewTimeline.length-1;b>=0;b--){const M=this.subjectSelectorToViewTimeline[b];if(M.name==h){const k=this.findPreviousSiblingOrAncestorMatchingSelector(p,M.selector);if(k)return{subject:k,axis:M.axis,inset:M.inset}}}return null}handleScrollTimelineProps(h,p){if(h.selector.includes("@keyframes"))return;const y=h.block.contents.includes("animation-name:"),b=h.block.contents.includes("animation-timeline:"),M=h.block.contents.includes("animation:");if(this.saveSourceSelectorToScrollTimeline(h),this.saveSubjectSelectorToViewTimeline(h),!b&&!y&&!M)return;let k=[],I=[],D=!1;b&&(k=this.extractScrollTimelineNames(h.block.contents)),y&&(I=this.extractMatches(h.block.contents,Oe.ANIMATION_NAME)),b&&y||(M&&this.extractMatches(h.block.contents,Oe.ANIMATION).forEach(N=>{const F=this.extractAnimationName(N);F&&b&&I.push(F),b&&(this.hasDuration(N)||(this.hasAutoDuration(N)&&(h.block.contents=h.block.contents.replace("auto"," ")),h.block.contents=h.block.contents.replace(N," 1s "+N),D=!0))}),D&&this.replacePart(h.block.startIndex,h.block.endIndex,h.block.contents,p)),this.saveRelationInList(h,k,I)}saveSourceSelectorToScrollTimeline(h){const p=h.block.contents.includes("scroll-timeline:"),y=h.block.contents.includes("scroll-timeline-name:"),b=h.block.contents.includes("scroll-timeline-axis:");if(!p&&!y)return;let M=[];if(p){const I=this.extractMatches(h.block.contents,Oe.SCROLL_TIMELINE);for(const D of I){const N=this.split(D);let F={selector:h.selector,name:""};N.length==1?F.name=N[0]:N.length==2&&(In.includes(N[0])?(F.axis=N[0],F.name=N[1]):(F.axis=N[1],F.name=N[0])),M.push(F)}}if(y){const I=this.extractMatches(h.block.contents,Oe.SCROLL_TIMELINE_NAME);for(let D=0;D<I.length;D++)if(D<M.length)M[D].name=I[D];else{let N={selector:h.selector,name:I[D]};M.push(N)}}let k=[];if(b){const I=this.extractMatches(h.block.contents,Oe.SCROLL_TIMELINE_AXIS);if(k=I.filter(D=>In.includes(D)),k.length!=I.length)throw new Error("Invalid axis")}for(let I=0;I<M.length;I++)k.length&&(M[I].axis=k[I%M.length]);this.sourceSelectorToScrollTimeline.push(...M)}saveSubjectSelectorToViewTimeline(h){const p=h.block.contents.includes("view-timeline:"),y=h.block.contents.includes("view-timeline-name:"),b=h.block.contents.includes("view-timeline-axis:"),M=h.block.contents.includes("view-timeline-inset:");if(!p&&!y)return;let k=[];if(p){const N=this.extractMatches(h.block.contents,Oe.VIEW_TIMELINE);for(let F of N){const X=this.split(F);let Z={selector:h.selector,name:"",inset:null};X.length==1?Z.name=X[0]:X.length==2&&(In.includes(X[0])?(Z.axis=X[0],Z.name=X[1]):(Z.axis=X[1],Z.name=X[0])),k.push(Z)}}if(y){const N=this.extractMatches(h.block.contents,Oe.VIEW_TIMELINE_NAME);for(let F=0;F<N.length;F++)if(F<k.length)k[F].name=N[F];else{let X={selector:h.selector,name:N[F],inset:null};k.push(X)}}let I=[],D=[];if(M&&(I=this.extractMatches(h.block.contents,Oe.VIEW_TIMELINE_INSET)),b){const N=this.extractMatches(h.block.contents,Oe.VIEW_TIMELINE_AXIS);if(D=N.filter(F=>In.includes(F)),D.length!=N.length)throw new Error("Invalid axis")}for(let N=0;N<k.length;N++)I.length&&(k[N].inset=I[N%k.length]),D.length&&(k[N].axis=D[N%k.length]);this.subjectSelectorToViewTimeline.push(...k)}hasDuration(h){return h.split(" ").filter(p=>{return y=p,Oe.TIME.exec(y);var y}).length>=1}hasAutoDuration(h){return h.split(" ").filter(p=>p==="auto").length>=1}saveRelationInList(h,p,y){let b=[];h.block.contents.includes("animation-range:")&&(b=this.extractMatches(h.block.contents,Oe.ANIMATION_TIME_RANGE));const M=Math.max(p.length,y.length,b.length);for(let k=0;k<M;k++)this.cssRulesWithTimelineName.push({selector:h.selector,"animation-timeline":p[k%p.length],...y.length?{"animation-name":y[k%y.length]}:{},...b.length?{"animation-range":b[k%b.length]}:{}})}extractScrollTimelineNames(h){const p=Oe.ANIMATION_TIMELINE.exec(h)[1].trim(),y=[];return p.split(",").map(b=>b.trim()).forEach(b=>{if(function(M){return(M.startsWith("scroll")||M.startsWith("view"))&&M.includes("(")}(b)){const M=this.saveAnonymousTimelineName(b);y.push(M)}else y.push(b)}),y}saveAnonymousTimelineName(h){const p=":t"+this.nextAnonymousTimelineNameIndex++;return h.startsWith("scroll(")?this.anonymousScrollTimelineOptions.set(p,this.parseAnonymousScrollTimeline(h)):this.anonymousViewTimelineOptions.set(p,this.parseAnonymousViewTimeline(h)),p}parseAnonymousScrollTimeline(h){const p=Oe.ANONYMOUS_SCROLL_TIMELINE.exec(h);if(!p)return null;const y=p[1],b={};return y.split(" ").forEach(M=>{In.includes(M)?b.axis=M:ql.includes(M)&&(b.source=M)}),b}parseAnonymousViewTimeline(h){const p=Oe.ANONYMOUS_VIEW_TIMELINE.exec(h);if(!p)return null;const y=p[1],b={};return y.split(" ").forEach(M=>{In.includes(M)?b.axis=M:b.inset=b.inset?`${b.inset} ${M}`:M}),b}extractAnimationName(h){return this.findMatchingEntryInContainer(h,this.keyframeNamesSelectors)}findMatchingEntryInContainer(h,p){const y=h.split(" ").filter(b=>p.has(b));return y?y[0]:null}parseIdentifier(h){Oe.IDENTIFIER.lastIndex=h.index;const p=Oe.IDENTIFIER.exec(h.sheetSrc);if(!p)throw this.parseError(h,"Expected an identifier");return h.index+=p[0].length,p[0]}parseKeyframesAndSaveNameMapping(h,p){if(h.selector.startsWith("@keyframes")){const y=this.replaceKeyframesAndGetMapping(h,p);h.selector.split(" ").forEach((b,M)=>{M>0&&this.keyframeNamesSelectors.set(b,y)})}}replaceKeyframesAndGetMapping(h,p){function y(N){return tr.some(F=>N.startsWith(F))}const b=h.block.contents,M=function(N){let F=0,X=-1,Z=-1;const K=[];for(let me=0;me<N.length;me++)N[me]=="{"?F++:N[me]=="}"&&F--,F==1&&N[me]!="{"&&N[me]!="}"&&X==-1&&(X=me),F==2&&N[me]=="{"&&(Z=me,K.push({start:X,end:Z}),X=Z=-1);return K}(b);if(M.length==0)return new Map;const k=new Map;let I=!1;const D=[];D.push(b.substring(0,M[0].start));for(let N=0;N<M.length;N++){const F=b.substring(M[N].start,M[N].end);let X=[];F.split(",").forEach(Z=>{const K=Z.split(" ").map(_e=>_e.trim()).filter(_e=>_e!="").join(" "),me=k.size;k.set(me,K),X.push(`${me}%`),y(K)&&(I=!0)}),D.push(X.join(",")),N==M.length-1?D.push(b.substring(M[N].end)):D.push(b.substring(M[N].end,M[N+1].start))}return I?(h.block.contents=D.join(""),this.replacePart(h.block.startIndex,h.block.endIndex,h.block.contents,p),k):new Map}parseQualifiedRule(h){const p=h.index,y=this.parseSelector(h).trim();if(y)return{selector:y,block:this.eatBlock(h),startIndex:p,endIndex:h.index}}removeEnclosingDoubleQuotes(h){let p=h[0]=='"'?1:0,y=h[h.length-1]=='"'?h.length-1:h.length;return h.substring(p,y)}assertString(h,p){if(h.sheetSrc.substr(h.index,p.length)!=p)throw this.parseError(h,`Did not find expected sequence ${p}`);h.index+=p.length}replacePart(h,p,y,b){if(b.sheetSrc=b.sheetSrc.slice(0,h)+y+b.sheetSrc.slice(p),b.index>=p){const M=b.index-p;b.index=h+y.length+M}}eatComment(h){this.assertString(h,"/*"),this.eatUntil("*/",h,!0),this.assertString(h,"*/")}eatBlock(h){const p=h.index;this.assertString(h,"{");let y=1;for(;y!=0;)this.lookAhead("/*",h)?this.eatComment(h):(h.sheetSrc[h.index]==="{"?y++:h.sheetSrc[h.index]==="}"&&y--,this.advance(h));const b=h.index;return{startIndex:p,endIndex:b,contents:h.sheetSrc.slice(p,b)}}advance(h){if(h.index++,h.index>h.sheetSrc.length)throw this.parseError(h,"Advanced beyond the end")}parseError(h,p){return Error(`(${h.name?h.name:"<anonymous file>"}): ${p}`)}eatUntil(h,p,y=!1){const b=p.index;for(;!this.lookAhead(h,p);)this.advance(p);return y&&(p.sheetSrc=p.sheetSrc.slice(0,b)+" ".repeat(p.index-b)+p.sheetSrc.slice(p.index)),p.sheetSrc.slice(b,p.index)}parseSelector(h){let p=h.index;if(this.eatUntil("{",h),p===h.index)throw Error("Empty selector");return h.sheetSrc.slice(p,h.index)}eatWhitespace(h){Oe.WHITE_SPACE.lastIndex=h.index;const p=Oe.WHITE_SPACE.exec(h.sheetSrc);p&&(h.index+=p[0].length)}lookAhead(h,p){return p.sheetSrc.substr(p.index,h.length)==h}peek(h){return h.sheetSrc[h.index]}extractMatches(h,p,y=","){return p.exec(h)[1].trim().split(y).map(b=>b.trim())}split(h){return h.split(" ").map(p=>p.trim()).filter(p=>p!="")}};function Xl(h,p,y,b,M,k){const I=ls(p),D=hs(p,y);return jo(ms(h,I,D,b,M),k,ms("cover",I,D,b,M),y)}function Yl(h,p,y){const b=tn.getAnimationTimelineOptions(p,y);if(!b)return null;const M=b["animation-timeline"];if(!M)return null;let k=tn.getScrollTimelineOptions(M,y)||tn.getViewTimelineOptions(M,y);return k?(k.subject&&function(I,D){const N=fs(D.subject),F=D.axis||D.axis;function X(K,me){let _e=null;for(const[ot,Pt]of K)if(ot==100*me.offset){if(Pt=="from")_e=0;else if(Pt=="to")_e=100;else{const gt=Pt.split(" ");_e=gt.length==1?parseFloat(gt[0]):100*Xl(gt[0],N,D.subject,F,D.inset,CSS.percent(parseFloat(gt[1])))}break}return _e}const Z=tn.keyframeNamesSelectors.get(I.animationName);if(Z&&Z.size){const K=[];I.effect.getKeyframes().forEach(_e=>{const ot=X(Z,_e);ot!==null&&ot>=0&&ot<=100&&(_e.offset=ot/100,K.push(_e))});const me=K.sort((_e,ot)=>_e.offset<ot.offset?-1:_e.affset>ot.offset?1:0);I.effect.setKeyframes(me)}}(h,k),{timeline:k.source?new $e(k):new Rn(k),animOptions:b}):null}function Zl(){if(CSS.supports("animation-timeline: --works"))return!0;(function(){function p(b){if(b.innerHTML.trim().length===0||"aphrodite"in b.dataset)return;let M=tn.transpileStyleSheet(b.innerHTML,!0);M=tn.transpileStyleSheet(M,!1),b.innerHTML=M}function y(b){b.type!="text/css"&&b.rel!="stylesheet"||!b.href||new URL(b.href,document.baseURI).origin==location.origin&&fetch(b.getAttribute("href")).then(async M=>{const k=await M.text();let I=tn.transpileStyleSheet(k,!0);if(I=tn.transpileStyleSheet(k,!1),I!=k){const D=new Blob([I],{type:"text/css"}),N=URL.createObjectURL(D);b.setAttribute("href",N)}})}new MutationObserver(b=>{for(const M of b)for(const k of M.addedNodes)k instanceof HTMLStyleElement&&p(k),k instanceof HTMLLinkElement&&y(k)}).observe(document.documentElement,{childList:!0,subtree:!0}),document.querySelectorAll("style").forEach(b=>p(b)),document.querySelectorAll("link").forEach(b=>y(b))})();const h=CSS.supports;CSS.supports=p=>(p=p.replaceAll(/(animation-timeline|scroll-timeline(-(name|axis))?|view-timeline(-(name|axis|inset))?|timeline-scope)\s*:/g,"--supported-property:"),h(p)),window.addEventListener("animationstart",p=>{p.target.getAnimations().filter(y=>y.animationName===p.animationName).forEach(y=>{const b=Yl(y,y.animationName,p.target);if(b)if(!b.timeline||y instanceof or)y.timeline=b.timeline;else{const M=new or(y,b.timeline,b.animOptions);y.pause(),M.play()}})})}(function(){if(!Zl()){if(!Reflect.defineProperty(window,"ScrollTimeline",{value:$e}))throw Error("Error installing ScrollTimeline polyfill: could not attach ScrollTimeline to window");if(!Reflect.defineProperty(window,"ViewTimeline",{value:Rn}))throw Error("Error installing ViewTimeline polyfill: could not attach ViewTimeline to window");if(!Reflect.defineProperty(Element.prototype,"animate",{value:Gl}))throw Error("Error installing ScrollTimeline polyfill: could not attach WAAPI's animate to DOM Element");if(!Reflect.defineProperty(window,"Animation",{value:or}))throw Error("Error installing Animation constructor.");if(!Reflect.defineProperty(Element.prototype,"getAnimations",{value:Wl}))throw Error("Error installing ScrollTimeline polyfill: could not attach WAAPI's getAnimations to DOM Element");if(!Reflect.defineProperty(document,"getAnimations",{value:Hl}))throw Error("Error installing ScrollTimeline polyfill: could not attach WAAPI's getAnimations to document")}})()})();var ja={exports:{}},Ja;function Ga(){return Ja||(Ja=1,function(r){var e={};e.useBlobBuilder=function(){try{return new Blob([]),!1}catch{return!0}}(),e.useArrayBufferView=!e.useBlobBuilder&&function(){try{return new Blob([new Uint8Array([])]).size===0}catch{return!0}}(),r.exports.binaryFeatures=e;var t=r.exports.BlobBuilder;typeof window<"u"&&(t=r.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder);function n(){this._pieces=[],this._parts=[]}n.prototype.append=function(i){typeof i=="number"?this._pieces.push(i):(this.flush(),this._parts.push(i))},n.prototype.flush=function(){if(this._pieces.length>0){var i=new Uint8Array(this._pieces);e.useArrayBufferView||(i=i.buffer),this._parts.push(i),this._pieces=[]}},n.prototype.getBuffer=function(){if(this.flush(),e.useBlobBuilder){for(var i=new t,s=0,a=this._parts.length;s<a;s++)i.append(this._parts[s]);return i.getBlob()}else return new Blob(this._parts)},r.exports.BufferBuilder=n}(ja)),ja.exports}var Vs,Wa;function td(){if(Wa)return Vs;Wa=1;var r=Ga().BufferBuilder,e=Ga().binaryFeatures,t={unpack:function(o){var c=new n(o);return c.unpack()},pack:function(o){var c=new i;c.pack(o);var l=c.getBuffer();return l}};Vs=t;function n(o){this.index=0,this.dataBuffer=o,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}n.prototype.unpack=function(){var o=this.unpack_uint8();if(o<128)return o;if((o^224)<32)return(o^224)-32;var c;if((c=o^160)<=15)return this.unpack_raw(c);if((c=o^176)<=15)return this.unpack_string(c);if((c=o^144)<=15)return this.unpack_array(c);if((c=o^128)<=15)return this.unpack_map(c);switch(o){case 192:return null;case 193:return;case 194:return!1;case 195:return!0;case 202:return this.unpack_float();case 203:return this.unpack_double();case 204:return this.unpack_uint8();case 205:return this.unpack_uint16();case 206:return this.unpack_uint32();case 207:return this.unpack_uint64();case 208:return this.unpack_int8();case 209:return this.unpack_int16();case 210:return this.unpack_int32();case 211:return this.unpack_int64();case 212:return;case 213:return;case 214:return;case 215:return;case 216:return c=this.unpack_uint16(),this.unpack_string(c);case 217:return c=this.unpack_uint32(),this.unpack_string(c);case 218:return c=this.unpack_uint16(),this.unpack_raw(c);case 219:return c=this.unpack_uint32(),this.unpack_raw(c);case 220:return c=this.unpack_uint16(),this.unpack_array(c);case 221:return c=this.unpack_uint32(),this.unpack_array(c);case 222:return c=this.unpack_uint16(),this.unpack_map(c);case 223:return c=this.unpack_uint32(),this.unpack_map(c)}},n.prototype.unpack_uint8=function(){var o=this.dataView[this.index]&255;return this.index++,o},n.prototype.unpack_uint16=function(){var o=this.read(2),c=(o[0]&255)*256+(o[1]&255);return this.index+=2,c},n.prototype.unpack_uint32=function(){var o=this.read(4),c=((o[0]*256+o[1])*256+o[2])*256+o[3];return this.index+=4,c},n.prototype.unpack_uint64=function(){var o=this.read(8),c=((((((o[0]*256+o[1])*256+o[2])*256+o[3])*256+o[4])*256+o[5])*256+o[6])*256+o[7];return this.index+=8,c},n.prototype.unpack_int8=function(){var o=this.unpack_uint8();return o<128?o:o-256},n.prototype.unpack_int16=function(){var o=this.unpack_uint16();return o<32768?o:o-65536},n.prototype.unpack_int32=function(){var o=this.unpack_uint32();return o<Math.pow(2,31)?o:o-Math.pow(2,32)},n.prototype.unpack_int64=function(){var o=this.unpack_uint64();return o<Math.pow(2,63)?o:o-Math.pow(2,64)},n.prototype.unpack_raw=function(o){if(this.length<this.index+o)throw new Error("BinaryPackFailure: index is out of range "+this.index+" "+o+" "+this.length);var c=this.dataBuffer.slice(this.index,this.index+o);return this.index+=o,c},n.prototype.unpack_string=function(o){for(var c=this.read(o),l=0,u="",d,m;l<o;)d=c[l],d<128?(u+=String.fromCharCode(d),l++):(d^192)<32?(m=(d^192)<<6|c[l+1]&63,u+=String.fromCharCode(m),l+=2):(m=(d&15)<<12|(c[l+1]&63)<<6|c[l+2]&63,u+=String.fromCharCode(m),l+=3);return this.index+=o,u},n.prototype.unpack_array=function(o){for(var c=new Array(o),l=0;l<o;l++)c[l]=this.unpack();return c},n.prototype.unpack_map=function(o){for(var c={},l=0;l<o;l++){var u=this.unpack(),d=this.unpack();c[u]=d}return c},n.prototype.unpack_float=function(){var o=this.unpack_uint32(),c=o>>31,l=(o>>23&255)-127,u=o&8388607|8388608;return(c===0?1:-1)*u*Math.pow(2,l-23)},n.prototype.unpack_double=function(){var o=this.unpack_uint32(),c=this.unpack_uint32(),l=o>>31,u=(o>>20&2047)-1023,d=o&1048575|1048576,m=d*Math.pow(2,u-20)+c*Math.pow(2,u-52);return(l===0?1:-1)*m},n.prototype.read=function(o){var c=this.index;if(c+o<=this.length)return this.dataView.subarray(c,c+o);throw new Error("BinaryPackFailure: read index out of range")};function i(){this.bufferBuilder=new r}i.prototype.getBuffer=function(){return this.bufferBuilder.getBuffer()},i.prototype.pack=function(o){var c=typeof o;if(c==="string")this.pack_string(o);else if(c==="number")Math.floor(o)===o?this.pack_integer(o):this.pack_double(o);else if(c==="boolean")o===!0?this.bufferBuilder.append(195):o===!1&&this.bufferBuilder.append(194);else if(c==="undefined")this.bufferBuilder.append(192);else if(c==="object")if(o===null)this.bufferBuilder.append(192);else{var l=o.constructor;if(l==Array)this.pack_array(o);else if(l==Blob||l==File||o instanceof Blob||o instanceof File)this.pack_bin(o);else if(l==ArrayBuffer)e.useArrayBufferView?this.pack_bin(new Uint8Array(o)):this.pack_bin(o);else if("BYTES_PER_ELEMENT"in o)e.useArrayBufferView?this.pack_bin(new Uint8Array(o.buffer)):this.pack_bin(o.buffer);else if(l==Object||l.toString().startsWith("class"))this.pack_object(o);else if(l==Date)this.pack_string(o.toString());else if(typeof o.toBinaryPack=="function")this.bufferBuilder.append(o.toBinaryPack());else throw new Error('Type "'+l.toString()+'" not yet supported')}else throw new Error('Type "'+c+'" not yet supported');this.bufferBuilder.flush()},i.prototype.pack_bin=function(o){var c=o.length||o.byteLength||o.size;if(c<=15)this.pack_uint8(160+c);else if(c<=65535)this.bufferBuilder.append(218),this.pack_uint16(c);else if(c<=4294967295)this.bufferBuilder.append(219),this.pack_uint32(c);else throw new Error("Invalid length");this.bufferBuilder.append(o)},i.prototype.pack_string=function(o){var c=a(o);if(c<=15)this.pack_uint8(176+c);else if(c<=65535)this.bufferBuilder.append(216),this.pack_uint16(c);else if(c<=4294967295)this.bufferBuilder.append(217),this.pack_uint32(c);else throw new Error("Invalid length");this.bufferBuilder.append(o)},i.prototype.pack_array=function(o){var c=o.length;if(c<=15)this.pack_uint8(144+c);else if(c<=65535)this.bufferBuilder.append(220),this.pack_uint16(c);else if(c<=4294967295)this.bufferBuilder.append(221),this.pack_uint32(c);else throw new Error("Invalid length");for(var l=0;l<c;l++)this.pack(o[l])},i.prototype.pack_integer=function(o){if(o>=-32&&o<=127)this.bufferBuilder.append(o&255);else if(o>=0&&o<=255)this.bufferBuilder.append(204),this.pack_uint8(o);else if(o>=-128&&o<=127)this.bufferBuilder.append(208),this.pack_int8(o);else if(o>=0&&o<=65535)this.bufferBuilder.append(205),this.pack_uint16(o);else if(o>=-32768&&o<=32767)this.bufferBuilder.append(209),this.pack_int16(o);else if(o>=0&&o<=4294967295)this.bufferBuilder.append(206),this.pack_uint32(o);else if(o>=-2147483648&&o<=2147483647)this.bufferBuilder.append(210),this.pack_int32(o);else if(o>=-9223372036854776e3&&o<=9223372036854776e3)this.bufferBuilder.append(211),this.pack_int64(o);else if(o>=0&&o<=18446744073709552e3)this.bufferBuilder.append(207),this.pack_uint64(o);else throw new Error("Invalid integer")},i.prototype.pack_double=function(o){var c=0;o<0&&(c=1,o=-o);var l=Math.floor(Math.log(o)/Math.LN2),u=o/Math.pow(2,l)-1,d=Math.floor(u*Math.pow(2,52)),m=Math.pow(2,32),f=c<<31|l+1023<<20|d/m&1048575,x=d%m;this.bufferBuilder.append(203),this.pack_int32(f),this.pack_int32(x)},i.prototype.pack_object=function(o){var c=Object.keys(o),l=c.length;if(l<=15)this.pack_uint8(128+l);else if(l<=65535)this.bufferBuilder.append(222),this.pack_uint16(l);else if(l<=4294967295)this.bufferBuilder.append(223),this.pack_uint32(l);else throw new Error("Invalid length");for(var u in o)o.hasOwnProperty(u)&&(this.pack(u),this.pack(o[u]))},i.prototype.pack_uint8=function(o){this.bufferBuilder.append(o)},i.prototype.pack_uint16=function(o){this.bufferBuilder.append(o>>8),this.bufferBuilder.append(o&255)},i.prototype.pack_uint32=function(o){var c=o&4294967295;this.bufferBuilder.append((c&4278190080)>>>24),this.bufferBuilder.append((c&16711680)>>>16),this.bufferBuilder.append((c&65280)>>>8),this.bufferBuilder.append(c&255)},i.prototype.pack_uint64=function(o){var c=o/Math.pow(2,32),l=o%Math.pow(2,32);this.bufferBuilder.append((c&4278190080)>>>24),this.bufferBuilder.append((c&16711680)>>>16),this.bufferBuilder.append((c&65280)>>>8),this.bufferBuilder.append(c&255),this.bufferBuilder.append((l&4278190080)>>>24),this.bufferBuilder.append((l&16711680)>>>16),this.bufferBuilder.append((l&65280)>>>8),this.bufferBuilder.append(l&255)},i.prototype.pack_int8=function(o){this.bufferBuilder.append(o&255)},i.prototype.pack_int16=function(o){this.bufferBuilder.append((o&65280)>>8),this.bufferBuilder.append(o&255)},i.prototype.pack_int32=function(o){this.bufferBuilder.append(o>>>24&255),this.bufferBuilder.append((o&16711680)>>>16),this.bufferBuilder.append((o&65280)>>>8),this.bufferBuilder.append(o&255)},i.prototype.pack_int64=function(o){var c=Math.floor(o/Math.pow(2,32)),l=o%Math.pow(2,32);this.bufferBuilder.append((c&4278190080)>>>24),this.bufferBuilder.append((c&16711680)>>>16),this.bufferBuilder.append((c&65280)>>>8),this.bufferBuilder.append(c&255),this.bufferBuilder.append((l&4278190080)>>>24),this.bufferBuilder.append((l&16711680)>>>16),this.bufferBuilder.append((l&65280)>>>8),this.bufferBuilder.append(l&255)};function s(o){var c=o.charCodeAt(0);return c<=2047?"00":c<=65535?"000":c<=2097151?"0000":c<=67108863?"00000":"000000"}function a(o){return o.length>600?new Blob([o]).size:o.replace(/[^\u0000-\u007F]/g,s).length}return Vs}var nd=td();const Ha=hr(nd);let qa=!0,Xa=!0;function oi(r,e,t){const n=r.match(e);return n&&n.length>=t&&parseInt(n[t],10)}function Un(r,e,t){if(!r.RTCPeerConnection)return;const n=r.RTCPeerConnection.prototype,i=n.addEventListener;n.addEventListener=function(a,o){if(a!==e)return i.apply(this,arguments);const c=l=>{const u=t(l);u&&(o.handleEvent?o.handleEvent(u):o(u))};return this._eventMap=this._eventMap||{},this._eventMap[e]||(this._eventMap[e]=new Map),this._eventMap[e].set(o,c),i.apply(this,[a,c])};const s=n.removeEventListener;n.removeEventListener=function(a,o){if(a!==e||!this._eventMap||!this._eventMap[e])return s.apply(this,arguments);if(!this._eventMap[e].has(o))return s.apply(this,arguments);const c=this._eventMap[e].get(o);return this._eventMap[e].delete(o),this._eventMap[e].size===0&&delete this._eventMap[e],Object.keys(this._eventMap).length===0&&delete this._eventMap,s.apply(this,[a,c])},Object.defineProperty(n,"on"+e,{get(){return this["_on"+e]},set(a){this["_on"+e]&&(this.removeEventListener(e,this["_on"+e]),delete this["_on"+e]),a&&this.addEventListener(e,this["_on"+e]=a)},enumerable:!0,configurable:!0})}function id(r){return typeof r!="boolean"?new Error("Argument type: "+typeof r+". Please use a boolean."):(qa=r,r?"adapter.js logging disabled":"adapter.js logging enabled")}function rd(r){return typeof r!="boolean"?new Error("Argument type: "+typeof r+". Please use a boolean."):(Xa=!r,"adapter.js deprecation warnings "+(r?"disabled":"enabled"))}function js(){if(typeof window=="object"){if(qa)return;typeof console<"u"&&typeof console.log=="function"&&console.log.apply(console,arguments)}}function Tr(r,e){Xa&&console.warn(r+" is deprecated, please use "+e+" instead.")}function sd(r){const e={browser:null,version:null};if(typeof r>"u"||!r.navigator)return e.browser="Not a browser.",e;const{navigator:t}=r;if(t.mozGetUserMedia)e.browser="firefox",e.version=oi(t.userAgent,/Firefox\/(\d+)\./,1);else if(t.webkitGetUserMedia||r.isSecureContext===!1&&r.webkitRTCPeerConnection&&!r.RTCIceGatherer)e.browser="chrome",e.version=oi(t.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(t.mediaDevices&&t.userAgent.match(/Edge\/(\d+).(\d+)$/))e.browser="edge",e.version=oi(t.userAgent,/Edge\/(\d+).(\d+)$/,2);else if(r.RTCPeerConnection&&t.userAgent.match(/AppleWebKit\/(\d+)\./))e.browser="safari",e.version=oi(t.userAgent,/AppleWebKit\/(\d+)\./,1),e.supportsUnifiedPlan=r.RTCRtpTransceiver&&"currentDirection"in r.RTCRtpTransceiver.prototype;else return e.browser="Not a supported browser.",e;return e}function Ya(r){return Object.prototype.toString.call(r)==="[object Object]"}function Za(r){return Ya(r)?Object.keys(r).reduce(function(e,t){const n=Ya(r[t]),i=n?Za(r[t]):r[t],s=n&&!Object.keys(i).length;return i===void 0||s?e:Object.assign(e,{[t]:i})},{}):r}function Js(r,e,t){!e||t.has(e.id)||(t.set(e.id,e),Object.keys(e).forEach(n=>{n.endsWith("Id")?Js(r,r.get(e[n]),t):n.endsWith("Ids")&&e[n].forEach(i=>{Js(r,r.get(i),t)})}))}function Ka(r,e,t){const n=t?"outbound-rtp":"inbound-rtp",i=new Map;if(e===null)return i;const s=[];return r.forEach(a=>{a.type==="track"&&a.trackIdentifier===e.id&&s.push(a)}),s.forEach(a=>{r.forEach(o=>{o.type===n&&o.trackId===a.id&&Js(r,o,i)})}),i}const Qa=js;function $a(r,e){const t=r&&r.navigator;if(!t.mediaDevices)return;const n=function(o){if(typeof o!="object"||o.mandatory||o.optional)return o;const c={};return Object.keys(o).forEach(l=>{if(l==="require"||l==="advanced"||l==="mediaSource")return;const u=typeof o[l]=="object"?o[l]:{ideal:o[l]};u.exact!==void 0&&typeof u.exact=="number"&&(u.min=u.max=u.exact);const d=function(m,f){return m?m+f.charAt(0).toUpperCase()+f.slice(1):f==="deviceId"?"sourceId":f};if(u.ideal!==void 0){c.optional=c.optional||[];let m={};typeof u.ideal=="number"?(m[d("min",l)]=u.ideal,c.optional.push(m),m={},m[d("max",l)]=u.ideal,c.optional.push(m)):(m[d("",l)]=u.ideal,c.optional.push(m))}u.exact!==void 0&&typeof u.exact!="number"?(c.mandatory=c.mandatory||{},c.mandatory[d("",l)]=u.exact):["min","max"].forEach(m=>{u[m]!==void 0&&(c.mandatory=c.mandatory||{},c.mandatory[d(m,l)]=u[m])})}),o.advanced&&(c.optional=(c.optional||[]).concat(o.advanced)),c},i=function(o,c){if(e.version>=61)return c(o);if(o=JSON.parse(JSON.stringify(o)),o&&typeof o.audio=="object"){const l=function(u,d,m){d in u&&!(m in u)&&(u[m]=u[d],delete u[d])};o=JSON.parse(JSON.stringify(o)),l(o.audio,"autoGainControl","googAutoGainControl"),l(o.audio,"noiseSuppression","googNoiseSuppression"),o.audio=n(o.audio)}if(o&&typeof o.video=="object"){let l=o.video.facingMode;l=l&&(typeof l=="object"?l:{ideal:l});const u=e.version<66;if(l&&(l.exact==="user"||l.exact==="environment"||l.ideal==="user"||l.ideal==="environment")&&!(t.mediaDevices.getSupportedConstraints&&t.mediaDevices.getSupportedConstraints().facingMode&&!u)){delete o.video.facingMode;let d;if(l.exact==="environment"||l.ideal==="environment"?d=["back","rear"]:(l.exact==="user"||l.ideal==="user")&&(d=["front"]),d)return t.mediaDevices.enumerateDevices().then(m=>{m=m.filter(x=>x.kind==="videoinput");let f=m.find(x=>d.some(_=>x.label.toLowerCase().includes(_)));return!f&&m.length&&d.includes("back")&&(f=m[m.length-1]),f&&(o.video.deviceId=l.exact?{exact:f.deviceId}:{ideal:f.deviceId}),o.video=n(o.video),Qa("chrome: "+JSON.stringify(o)),c(o)})}o.video=n(o.video)}return Qa("chrome: "+JSON.stringify(o)),c(o)},s=function(o){return e.version>=64?o:{name:{PermissionDeniedError:"NotAllowedError",PermissionDismissedError:"NotAllowedError",InvalidStateError:"NotAllowedError",DevicesNotFoundError:"NotFoundError",ConstraintNotSatisfiedError:"OverconstrainedError",TrackStartError:"NotReadableError",MediaDeviceFailedDueToShutdown:"NotAllowedError",MediaDeviceKillSwitchOn:"NotAllowedError",TabCaptureError:"AbortError",ScreenCaptureError:"AbortError",DeviceCaptureError:"AbortError"}[o.name]||o.name,message:o.message,constraint:o.constraint||o.constraintName,toString(){return this.name+(this.message&&": ")+this.message}}},a=function(o,c,l){i(o,u=>{t.webkitGetUserMedia(u,c,d=>{l&&l(s(d))})})};if(t.getUserMedia=a.bind(t),t.mediaDevices.getUserMedia){const o=t.mediaDevices.getUserMedia.bind(t.mediaDevices);Object.getOwnPropertyDescriptor(t.mediaDevices,"getUserMedia")?.writable&&(t.mediaDevices.getUserMedia=function(c){return i(c,l=>o(l).then(u=>{if(l.audio&&!u.getAudioTracks().length||l.video&&!u.getVideoTracks().length)throw u.getTracks().forEach(d=>{d.stop()}),new DOMException("","NotFoundError");return u},u=>Promise.reject(s(u))))})}}function od(r,e){if(!(r.navigator.mediaDevices&&"getDisplayMedia"in r.navigator.mediaDevices)&&r.navigator.mediaDevices){if(typeof e!="function"){console.error("shimGetDisplayMedia: getSourceId argument is not a function");return}r.navigator.mediaDevices.getDisplayMedia=function(t){return e(t).then(n=>{const i=t.video&&t.video.width,s=t.video&&t.video.height,a=t.video&&t.video.frameRate;return t.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:n,maxFrameRate:a||3}},i&&(t.video.mandatory.maxWidth=i),s&&(t.video.mandatory.maxHeight=s),r.navigator.mediaDevices.getUserMedia(t)})}}}function ec(r){r.MediaStream=r.MediaStream||r.webkitMediaStream}function tc(r){if(typeof r=="object"&&r.RTCPeerConnection&&!("ontrack"in r.RTCPeerConnection.prototype)){Object.defineProperty(r.RTCPeerConnection.prototype,"ontrack",{get(){return this._ontrack},set(t){this._ontrack&&this.removeEventListener("track",this._ontrack),this.addEventListener("track",this._ontrack=t)},enumerable:!0,configurable:!0});const e=r.RTCPeerConnection.prototype.setRemoteDescription;r.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",n=>{let i;r.RTCPeerConnection.prototype.getReceivers?i=this.getReceivers().find(a=>a.track&&a.track.id===n.track.id):i={track:n.track};const s=new Event("track");s.track=n.track,s.receiver=i,s.transceiver={receiver:i},s.streams=[t.stream],this.dispatchEvent(s)}),t.stream.getTracks().forEach(n=>{let i;r.RTCPeerConnection.prototype.getReceivers?i=this.getReceivers().find(a=>a.track&&a.track.id===n.id):i={track:n};const s=new Event("track");s.track=n,s.receiver=i,s.transceiver={receiver:i},s.streams=[t.stream],this.dispatchEvent(s)})},this.addEventListener("addstream",this._ontrackpoly)),e.apply(this,arguments)}}else Un(r,"track",e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e))}function nc(r){if(typeof r=="object"&&r.RTCPeerConnection&&!("getSenders"in r.RTCPeerConnection.prototype)&&"createDTMFSender"in r.RTCPeerConnection.prototype){const e=function(i,s){return{track:s,get dtmf(){return this._dtmf===void 0&&(s.kind==="audio"?this._dtmf=i.createDTMFSender(s):this._dtmf=null),this._dtmf},_pc:i}};if(!r.RTCPeerConnection.prototype.getSenders){r.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=r.RTCPeerConnection.prototype.addTrack;r.RTCPeerConnection.prototype.addTrack=function(a,o){let c=i.apply(this,arguments);return c||(c=e(this,a),this._senders.push(c)),c};const s=r.RTCPeerConnection.prototype.removeTrack;r.RTCPeerConnection.prototype.removeTrack=function(a){s.apply(this,arguments);const o=this._senders.indexOf(a);o!==-1&&this._senders.splice(o,1)}}const t=r.RTCPeerConnection.prototype.addStream;r.RTCPeerConnection.prototype.addStream=function(i){this._senders=this._senders||[],t.apply(this,[i]),i.getTracks().forEach(s=>{this._senders.push(e(this,s))})};const n=r.RTCPeerConnection.prototype.removeStream;r.RTCPeerConnection.prototype.removeStream=function(i){this._senders=this._senders||[],n.apply(this,[i]),i.getTracks().forEach(s=>{const a=this._senders.find(o=>o.track===s);a&&this._senders.splice(this._senders.indexOf(a),1)})}}else if(typeof r=="object"&&r.RTCPeerConnection&&"getSenders"in r.RTCPeerConnection.prototype&&"createDTMFSender"in r.RTCPeerConnection.prototype&&r.RTCRtpSender&&!("dtmf"in r.RTCRtpSender.prototype)){const e=r.RTCPeerConnection.prototype.getSenders;r.RTCPeerConnection.prototype.getSenders=function(){const t=e.apply(this,[]);return t.forEach(n=>n._pc=this),t},Object.defineProperty(r.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=this._pc.createDTMFSender(this.track):this._dtmf=null),this._dtmf}})}}function ic(r){if(!r.RTCPeerConnection)return;const e=r.RTCPeerConnection.prototype.getStats;r.RTCPeerConnection.prototype.getStats=function(){const[t,n,i]=arguments;if(arguments.length>0&&typeof t=="function")return e.apply(this,arguments);if(e.length===0&&(arguments.length===0||typeof t!="function"))return e.apply(this,[]);const s=function(o){const c={};return o.result().forEach(l=>{const u={id:l.id,timestamp:l.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[l.type]||l.type};l.names().forEach(d=>{u[d]=l.stat(d)}),c[u.id]=u}),c},a=function(o){return new Map(Object.keys(o).map(c=>[c,o[c]]))};if(arguments.length>=2){const o=function(c){n(a(s(c)))};return e.apply(this,[o,t])}return new Promise((o,c)=>{e.apply(this,[function(l){o(a(s(l)))},c])}).then(n,i)}}function rc(r){if(!(typeof r=="object"&&r.RTCPeerConnection&&r.RTCRtpSender&&r.RTCRtpReceiver))return;if(!("getStats"in r.RTCRtpSender.prototype)){const t=r.RTCPeerConnection.prototype.getSenders;t&&(r.RTCPeerConnection.prototype.getSenders=function(){const i=t.apply(this,[]);return i.forEach(s=>s._pc=this),i});const n=r.RTCPeerConnection.prototype.addTrack;n&&(r.RTCPeerConnection.prototype.addTrack=function(){const i=n.apply(this,arguments);return i._pc=this,i}),r.RTCRtpSender.prototype.getStats=function(){const i=this;return this._pc.getStats().then(s=>Ka(s,i.track,!0))}}if(!("getStats"in r.RTCRtpReceiver.prototype)){const t=r.RTCPeerConnection.prototype.getReceivers;t&&(r.RTCPeerConnection.prototype.getReceivers=function(){const n=t.apply(this,[]);return n.forEach(i=>i._pc=this),n}),Un(r,"track",n=>(n.receiver._pc=n.srcElement,n)),r.RTCRtpReceiver.prototype.getStats=function(){const n=this;return this._pc.getStats().then(i=>Ka(i,n.track,!1))}}if(!("getStats"in r.RTCRtpSender.prototype&&"getStats"in r.RTCRtpReceiver.prototype))return;const e=r.RTCPeerConnection.prototype.getStats;r.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof r.MediaStreamTrack){const t=arguments[0];let n,i,s;return this.getSenders().forEach(a=>{a.track===t&&(n?s=!0:n=a)}),this.getReceivers().forEach(a=>(a.track===t&&(i?s=!0:i=a),a.track===t)),s||n&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):n?n.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return e.apply(this,arguments)}}function sc(r){r.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(s=>this._shimmedLocalStreams[s][0])};const e=r.RTCPeerConnection.prototype.addTrack;r.RTCPeerConnection.prototype.addTrack=function(s,a){if(!a)return e.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const o=e.apply(this,arguments);return this._shimmedLocalStreams[a.id]?this._shimmedLocalStreams[a.id].indexOf(o)===-1&&this._shimmedLocalStreams[a.id].push(o):this._shimmedLocalStreams[a.id]=[a,o],o};const t=r.RTCPeerConnection.prototype.addStream;r.RTCPeerConnection.prototype.addStream=function(s){this._shimmedLocalStreams=this._shimmedLocalStreams||{},s.getTracks().forEach(c=>{if(this.getSenders().find(l=>l.track===c))throw new DOMException("Track already exists.","InvalidAccessError")});const a=this.getSenders();t.apply(this,arguments);const o=this.getSenders().filter(c=>a.indexOf(c)===-1);this._shimmedLocalStreams[s.id]=[s].concat(o)};const n=r.RTCPeerConnection.prototype.removeStream;r.RTCPeerConnection.prototype.removeStream=function(s){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[s.id],n.apply(this,arguments)};const i=r.RTCPeerConnection.prototype.removeTrack;r.RTCPeerConnection.prototype.removeTrack=function(s){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},s&&Object.keys(this._shimmedLocalStreams).forEach(a=>{const o=this._shimmedLocalStreams[a].indexOf(s);o!==-1&&this._shimmedLocalStreams[a].splice(o,1),this._shimmedLocalStreams[a].length===1&&delete this._shimmedLocalStreams[a]}),i.apply(this,arguments)}}function oc(r,e){if(!r.RTCPeerConnection)return;if(r.RTCPeerConnection.prototype.addTrack&&e.version>=65)return sc(r);const t=r.RTCPeerConnection.prototype.getLocalStreams;r.RTCPeerConnection.prototype.getLocalStreams=function(){const l=t.apply(this);return this._reverseStreams=this._reverseStreams||{},l.map(u=>this._reverseStreams[u.id])};const n=r.RTCPeerConnection.prototype.addStream;r.RTCPeerConnection.prototype.addStream=function(l){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},l.getTracks().forEach(u=>{if(this.getSenders().find(d=>d.track===u))throw new DOMException("Track already exists.","InvalidAccessError")}),!this._reverseStreams[l.id]){const u=new r.MediaStream(l.getTracks());this._streams[l.id]=u,this._reverseStreams[u.id]=l,l=u}n.apply(this,[l])};const i=r.RTCPeerConnection.prototype.removeStream;r.RTCPeerConnection.prototype.removeStream=function(l){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},i.apply(this,[this._streams[l.id]||l]),delete this._reverseStreams[this._streams[l.id]?this._streams[l.id].id:l.id],delete this._streams[l.id]},r.RTCPeerConnection.prototype.addTrack=function(l,u){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const d=[].slice.call(arguments,1);if(d.length!==1||!d[0].getTracks().find(f=>f===l))throw new DOMException("The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.","NotSupportedError");if(this.getSenders().find(f=>f.track===l))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const m=this._streams[u.id];if(m)m.addTrack(l),Promise.resolve().then(()=>{this.dispatchEvent(new Event("negotiationneeded"))});else{const f=new r.MediaStream([l]);this._streams[u.id]=f,this._reverseStreams[f.id]=u,this.addStream(f)}return this.getSenders().find(f=>f.track===l)};function s(l,u){let d=u.sdp;return Object.keys(l._reverseStreams||[]).forEach(m=>{const f=l._reverseStreams[m],x=l._streams[f.id];d=d.replace(new RegExp(x.id,"g"),f.id)}),new RTCSessionDescription({type:u.type,sdp:d})}function a(l,u){let d=u.sdp;return Object.keys(l._reverseStreams||[]).forEach(m=>{const f=l._reverseStreams[m],x=l._streams[f.id];d=d.replace(new RegExp(f.id,"g"),x.id)}),new RTCSessionDescription({type:u.type,sdp:d})}["createOffer","createAnswer"].forEach(function(l){const u=r.RTCPeerConnection.prototype[l],d={[l](){const m=arguments;return arguments.length&&typeof arguments[0]=="function"?u.apply(this,[f=>{const x=s(this,f);m[0].apply(null,[x])},f=>{m[1]&&m[1].apply(null,f)},arguments[2]]):u.apply(this,arguments).then(f=>s(this,f))}};r.RTCPeerConnection.prototype[l]=d[l]});const o=r.RTCPeerConnection.prototype.setLocalDescription;r.RTCPeerConnection.prototype.setLocalDescription=function(){return!arguments.length||!arguments[0].type?o.apply(this,arguments):(arguments[0]=a(this,arguments[0]),o.apply(this,arguments))};const c=Object.getOwnPropertyDescriptor(r.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(r.RTCPeerConnection.prototype,"localDescription",{get(){const l=c.get.apply(this);return l.type===""?l:s(this,l)}}),r.RTCPeerConnection.prototype.removeTrack=function(l){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!l._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(l._pc!==this)throw new DOMException("Sender was not created by this connection.","InvalidAccessError");this._streams=this._streams||{};let u;Object.keys(this._streams).forEach(d=>{this._streams[d].getTracks().find(m=>l.track===m)&&(u=this._streams[d])}),u&&(u.getTracks().length===1?this.removeStream(this._reverseStreams[u.id]):u.removeTrack(l.track),this.dispatchEvent(new Event("negotiationneeded")))}}function Gs(r,e){!r.RTCPeerConnection&&r.webkitRTCPeerConnection&&(r.RTCPeerConnection=r.webkitRTCPeerConnection),r.RTCPeerConnection&&e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){const n=r.RTCPeerConnection.prototype[t],i={[t](){return arguments[0]=new(t==="addIceCandidate"?r.RTCIceCandidate:r.RTCSessionDescription)(arguments[0]),n.apply(this,arguments)}};r.RTCPeerConnection.prototype[t]=i[t]})}function ac(r,e){Un(r,"negotiationneeded",t=>{const n=t.target;if(!((e.version<72||n.getConfiguration&&n.getConfiguration().sdpSemantics==="plan-b")&&n.signalingState!=="stable"))return t})}const cc=Object.freeze(Object.defineProperty({__proto__:null,fixNegotiationNeeded:ac,shimAddTrackRemoveTrack:oc,shimAddTrackRemoveTrackWithNative:sc,shimGetDisplayMedia:od,shimGetSendersWithDtmf:nc,shimGetStats:ic,shimGetUserMedia:$a,shimMediaStream:ec,shimOnTrack:tc,shimPeerConnection:Gs,shimSenderReceiverGetStats:rc},Symbol.toStringTag,{value:"Module"}));function ad(r,e){let t=!1;return r=JSON.parse(JSON.stringify(r)),r.filter(n=>{if(n&&(n.urls||n.url)){let i=n.urls||n.url;n.url&&!n.urls&&Tr("RTCIceServer.url","RTCIceServer.urls");const s=typeof i=="string";return s&&(i=[i]),i=i.filter(a=>{if(a.indexOf("stun:")===0)return!1;const o=a.startsWith("turn")&&!a.startsWith("turn:[")&&a.includes("transport=udp");return o&&!t?(t=!0,!0):o&&!t}),delete n.url,n.urls=s?i[0]:i,!!i.length}})}var lc={exports:{}},hc;function uc(){return hc||(hc=1,function(r){var e={};e.generateIdentifier=function(){return Math.random().toString(36).substr(2,10)},e.localCName=e.generateIdentifier(),e.splitLines=function(t){return t.trim().split(`
1040
1040
  `).map(function(n){return n.trim()})},e.splitSections=function(t){var n=t.split(`
1041
1041
  m=`);return n.map(function(i,s){return(s>0?"m="+i:i).trim()+`\r
1042
1042
  `})},e.getDescription=function(t){var n=e.splitSections(t);return n&&n[0]},e.getMediaSections=function(t){var n=e.splitSections(t);return n.shift(),n},e.matchPrefix=function(t,n){return e.splitLines(t).filter(function(i){return i.indexOf(n)===0})},e.parseCandidate=function(t){var n;t.indexOf("a=candidate:")===0?n=t.substring(12).split(" "):n=t.substring(10).split(" ");for(var i={foundation:n[0],component:parseInt(n[1],10),protocol:n[2].toLowerCase(),priority:parseInt(n[3],10),ip:n[4],address:n[4],port:parseInt(n[5],10),type:n[7]},s=8;s<n.length;s+=2)switch(n[s]){case"raddr":i.relatedAddress=n[s+1];break;case"rport":i.relatedPort=parseInt(n[s+1],10);break;case"tcptype":i.tcpType=n[s+1];break;case"ufrag":i.ufrag=n[s+1],i.usernameFragment=n[s+1];break;default:i[n[s]]=n[s+1];break}return i},e.writeCandidate=function(t){var n=[];n.push(t.foundation),n.push(t.component),n.push(t.protocol.toUpperCase()),n.push(t.priority),n.push(t.address||t.ip),n.push(t.port);var i=t.type;return n.push("typ"),n.push(i),i!=="host"&&t.relatedAddress&&t.relatedPort&&(n.push("raddr"),n.push(t.relatedAddress),n.push("rport"),n.push(t.relatedPort)),t.tcpType&&t.protocol.toLowerCase()==="tcp"&&(n.push("tcptype"),n.push(t.tcpType)),(t.usernameFragment||t.ufrag)&&(n.push("ufrag"),n.push(t.usernameFragment||t.ufrag)),"candidate:"+n.join(" ")},e.parseIceOptions=function(t){return t.substr(14).split(" ")},e.parseRtpMap=function(t){var n=t.substr(9).split(" "),i={payloadType:parseInt(n.shift(),10)};return n=n[0].split("/"),i.name=n[0],i.clockRate=parseInt(n[1],10),i.channels=n.length===3?parseInt(n[2],10):1,i.numChannels=i.channels,i},e.writeRtpMap=function(t){var n=t.payloadType;t.preferredPayloadType!==void 0&&(n=t.preferredPayloadType);var i=t.channels||t.numChannels||1;return"a=rtpmap:"+n+" "+t.name+"/"+t.clockRate+(i!==1?"/"+i:"")+`\r
@@ -1053,7 +1053,7 @@ a=ice-pwd:`+t.password+`\r
1053
1053
  `,i+=`a=rtcp:9 IN IP4 0.0.0.0\r
1054
1054
  `,n.codecs.forEach(function(a){i+=e.writeRtpMap(a),i+=e.writeFmtp(a),i+=e.writeRtcpFb(a)});var s=0;return n.codecs.forEach(function(a){a.maxptime>s&&(s=a.maxptime)}),s>0&&(i+="a=maxptime:"+s+`\r
1055
1055
  `),i+=`a=rtcp-mux\r
1056
- `,n.headerExtensions&&n.headerExtensions.forEach(function(a){i+=e.writeExtmap(a)}),i},e.parseRtpEncodingParameters=function(t){var n=[],i=e.parseRtpParameters(t),s=i.fecMechanisms.indexOf("RED")!==-1,a=i.fecMechanisms.indexOf("ULPFEC")!==-1,o=e.matchPrefix(t,"a=ssrc:").map(function(f){return e.parseSsrcMedia(f)}).filter(function(f){return f.attribute==="cname"}),c=o.length>0&&o[0].ssrc,l,u=e.matchPrefix(t,"a=ssrc-group:FID").map(function(f){var m=f.substr(17).split(" ");return m.map(function(x){return parseInt(x,10)})});u.length>0&&u[0].length>1&&u[0][0]===c&&(l=u[0][1]),i.codecs.forEach(function(f){if(f.name.toUpperCase()==="RTX"&&f.parameters.apt){var m={ssrc:c,codecPayloadType:parseInt(f.parameters.apt,10)};c&&l&&(m.rtx={ssrc:l}),n.push(m),s&&(m=JSON.parse(JSON.stringify(m)),m.fec={ssrc:c,mechanism:a?"red+ulpfec":"red"},n.push(m))}}),n.length===0&&c&&n.push({ssrc:c});var d=e.matchPrefix(t,"b=");return d.length&&(d[0].indexOf("b=TIAS:")===0?d=parseInt(d[0].substr(7),10):d[0].indexOf("b=AS:")===0?d=parseInt(d[0].substr(5),10)*1e3*.95-2e3*8:d=void 0,n.forEach(function(f){f.maxBitrate=d})),n},e.parseRtcpParameters=function(t){var n={},i=e.matchPrefix(t,"a=ssrc:").map(function(o){return e.parseSsrcMedia(o)}).filter(function(o){return o.attribute==="cname"})[0];i&&(n.cname=i.value,n.ssrc=i.ssrc);var s=e.matchPrefix(t,"a=rtcp-rsize");n.reducedSize=s.length>0,n.compound=s.length===0;var a=e.matchPrefix(t,"a=rtcp-mux");return n.mux=a.length>0,n},e.parseMsid=function(t){var n,i=e.matchPrefix(t,"a=msid:");if(i.length===1)return n=i[0].substr(7).split(" "),{stream:n[0],track:n[1]};var s=e.matchPrefix(t,"a=ssrc:").map(function(a){return e.parseSsrcMedia(a)}).filter(function(a){return a.attribute==="msid"});if(s.length>0)return n=s[0].value.split(" "),{stream:n[0],track:n[1]}},e.parseSctpDescription=function(t){var n=e.parseMLine(t),i=e.matchPrefix(t,"a=max-message-size:"),s;i.length>0&&(s=parseInt(i[0].substr(19),10)),isNaN(s)&&(s=65536);var a=e.matchPrefix(t,"a=sctp-port:");if(a.length>0)return{port:parseInt(a[0].substr(12),10),protocol:n.fmt,maxMessageSize:s};var o=e.matchPrefix(t,"a=sctpmap:");if(o.length>0){var c=e.matchPrefix(t,"a=sctpmap:")[0].substr(10).split(" ");return{port:parseInt(c[0],10),protocol:c[1],maxMessageSize:s}}},e.writeSctpDescription=function(t,n){var i=[];return t.protocol!=="DTLS/SCTP"?i=["m="+t.kind+" 9 "+t.protocol+" "+n.protocol+`\r
1056
+ `,n.headerExtensions&&n.headerExtensions.forEach(function(a){i+=e.writeExtmap(a)}),i},e.parseRtpEncodingParameters=function(t){var n=[],i=e.parseRtpParameters(t),s=i.fecMechanisms.indexOf("RED")!==-1,a=i.fecMechanisms.indexOf("ULPFEC")!==-1,o=e.matchPrefix(t,"a=ssrc:").map(function(m){return e.parseSsrcMedia(m)}).filter(function(m){return m.attribute==="cname"}),c=o.length>0&&o[0].ssrc,l,u=e.matchPrefix(t,"a=ssrc-group:FID").map(function(m){var f=m.substr(17).split(" ");return f.map(function(x){return parseInt(x,10)})});u.length>0&&u[0].length>1&&u[0][0]===c&&(l=u[0][1]),i.codecs.forEach(function(m){if(m.name.toUpperCase()==="RTX"&&m.parameters.apt){var f={ssrc:c,codecPayloadType:parseInt(m.parameters.apt,10)};c&&l&&(f.rtx={ssrc:l}),n.push(f),s&&(f=JSON.parse(JSON.stringify(f)),f.fec={ssrc:c,mechanism:a?"red+ulpfec":"red"},n.push(f))}}),n.length===0&&c&&n.push({ssrc:c});var d=e.matchPrefix(t,"b=");return d.length&&(d[0].indexOf("b=TIAS:")===0?d=parseInt(d[0].substr(7),10):d[0].indexOf("b=AS:")===0?d=parseInt(d[0].substr(5),10)*1e3*.95-2e3*8:d=void 0,n.forEach(function(m){m.maxBitrate=d})),n},e.parseRtcpParameters=function(t){var n={},i=e.matchPrefix(t,"a=ssrc:").map(function(o){return e.parseSsrcMedia(o)}).filter(function(o){return o.attribute==="cname"})[0];i&&(n.cname=i.value,n.ssrc=i.ssrc);var s=e.matchPrefix(t,"a=rtcp-rsize");n.reducedSize=s.length>0,n.compound=s.length===0;var a=e.matchPrefix(t,"a=rtcp-mux");return n.mux=a.length>0,n},e.parseMsid=function(t){var n,i=e.matchPrefix(t,"a=msid:");if(i.length===1)return n=i[0].substr(7).split(" "),{stream:n[0],track:n[1]};var s=e.matchPrefix(t,"a=ssrc:").map(function(a){return e.parseSsrcMedia(a)}).filter(function(a){return a.attribute==="msid"});if(s.length>0)return n=s[0].value.split(" "),{stream:n[0],track:n[1]}},e.parseSctpDescription=function(t){var n=e.parseMLine(t),i=e.matchPrefix(t,"a=max-message-size:"),s;i.length>0&&(s=parseInt(i[0].substr(19),10)),isNaN(s)&&(s=65536);var a=e.matchPrefix(t,"a=sctp-port:");if(a.length>0)return{port:parseInt(a[0].substr(12),10),protocol:n.fmt,maxMessageSize:s};var o=e.matchPrefix(t,"a=sctpmap:");if(o.length>0){var c=e.matchPrefix(t,"a=sctpmap:")[0].substr(10).split(" ");return{port:parseInt(c[0],10),protocol:c[1],maxMessageSize:s}}},e.writeSctpDescription=function(t,n){var i=[];return t.protocol!=="DTLS/SCTP"?i=["m="+t.kind+" 9 "+t.protocol+" "+n.protocol+`\r
1057
1057
  `,`c=IN IP4 0.0.0.0\r
1058
1058
  `,"a=sctp-port:"+n.port+`\r
1059
1059
  `]:i=["m="+t.kind+" 9 "+t.protocol+" "+n.port+`\r
@@ -1074,25 +1074,25 @@ t=0 0\r
1074
1074
  `;a+="a="+o,a+="a=ssrc:"+t.sendEncodingParameters[0].ssrc+" "+o,t.sendEncodingParameters[0].rtx&&(a+="a=ssrc:"+t.sendEncodingParameters[0].rtx.ssrc+" "+o,a+="a=ssrc-group:FID "+t.sendEncodingParameters[0].ssrc+" "+t.sendEncodingParameters[0].rtx.ssrc+`\r
1075
1075
  `)}return a+="a=ssrc:"+t.sendEncodingParameters[0].ssrc+" cname:"+e.localCName+`\r
1076
1076
  `,t.rtpSender&&t.sendEncodingParameters[0].rtx&&(a+="a=ssrc:"+t.sendEncodingParameters[0].rtx.ssrc+" cname:"+e.localCName+`\r
1077
- `),a},e.getDirection=function(t,n){for(var i=e.splitLines(t),s=0;s<i.length;s++)switch(i[s]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return i[s].substr(2)}return n?e.getDirection(n):"sendrecv"},e.getKind=function(t){var n=e.splitLines(t),i=n[0].split(" ");return i[0].substr(2)},e.isRejected=function(t){return t.split(" ",2)[1]==="0"},e.parseMLine=function(t){var n=e.splitLines(t),i=n[0].substr(2).split(" ");return{kind:i[0],port:parseInt(i[1],10),protocol:i[2],fmt:i.slice(3).join(" ")}},e.parseOLine=function(t){var n=e.matchPrefix(t,"o=")[0],i=n.substr(2).split(" ");return{username:i[0],sessionId:i[1],sessionVersion:parseInt(i[2],10),netType:i[3],addressType:i[4],address:i[5]}},e.isValidSDP=function(t){if(typeof t!="string"||t.length===0)return!1;for(var n=e.splitLines(t),i=0;i<n.length;i++)if(n[i].length<2||n[i].charAt(1)!=="=")return!1;return!0},r.exports=e}(lc)),lc.exports}var Gs,dc;function ad(){if(dc)return Gs;dc=1;var r=hc();function e(c){return{inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[c.type]||c.type}function t(c,l,u,d,f){var m=r.writeRtpDescription(c.kind,l);if(m+=r.writeIceParameters(c.iceGatherer.getLocalParameters()),m+=r.writeDtlsParameters(c.dtlsTransport.getLocalParameters(),u==="offer"?"actpass":f||"active"),m+="a=mid:"+c.mid+`\r
1078
- `,c.rtpSender&&c.rtpReceiver?m+=`a=sendrecv\r
1079
- `:c.rtpSender?m+=`a=sendonly\r
1080
- `:c.rtpReceiver?m+=`a=recvonly\r
1081
- `:m+=`a=inactive\r
1077
+ `),a},e.getDirection=function(t,n){for(var i=e.splitLines(t),s=0;s<i.length;s++)switch(i[s]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return i[s].substr(2)}return n?e.getDirection(n):"sendrecv"},e.getKind=function(t){var n=e.splitLines(t),i=n[0].split(" ");return i[0].substr(2)},e.isRejected=function(t){return t.split(" ",2)[1]==="0"},e.parseMLine=function(t){var n=e.splitLines(t),i=n[0].substr(2).split(" ");return{kind:i[0],port:parseInt(i[1],10),protocol:i[2],fmt:i.slice(3).join(" ")}},e.parseOLine=function(t){var n=e.matchPrefix(t,"o=")[0],i=n.substr(2).split(" ");return{username:i[0],sessionId:i[1],sessionVersion:parseInt(i[2],10),netType:i[3],addressType:i[4],address:i[5]}},e.isValidSDP=function(t){if(typeof t!="string"||t.length===0)return!1;for(var n=e.splitLines(t),i=0;i<n.length;i++)if(n[i].length<2||n[i].charAt(1)!=="=")return!1;return!0},r.exports=e}(lc)),lc.exports}var Ws,dc;function cd(){if(dc)return Ws;dc=1;var r=uc();function e(c){return{inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[c.type]||c.type}function t(c,l,u,d,m){var f=r.writeRtpDescription(c.kind,l);if(f+=r.writeIceParameters(c.iceGatherer.getLocalParameters()),f+=r.writeDtlsParameters(c.dtlsTransport.getLocalParameters(),u==="offer"?"actpass":m||"active"),f+="a=mid:"+c.mid+`\r
1078
+ `,c.rtpSender&&c.rtpReceiver?f+=`a=sendrecv\r
1079
+ `:c.rtpSender?f+=`a=sendonly\r
1080
+ `:c.rtpReceiver?f+=`a=recvonly\r
1081
+ `:f+=`a=inactive\r
1082
1082
  `,c.rtpSender){var x=c.rtpSender._initialTrackId||c.rtpSender.track.id;c.rtpSender._initialTrackId=x;var _="msid:"+(d?d.id:"-")+" "+x+`\r
1083
- `;m+="a="+_,m+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" "+_,c.sendEncodingParameters[0].rtx&&(m+="a=ssrc:"+c.sendEncodingParameters[0].rtx.ssrc+" "+_,m+="a=ssrc-group:FID "+c.sendEncodingParameters[0].ssrc+" "+c.sendEncodingParameters[0].rtx.ssrc+`\r
1084
- `)}return m+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" cname:"+r.localCName+`\r
1085
- `,c.rtpSender&&c.sendEncodingParameters[0].rtx&&(m+="a=ssrc:"+c.sendEncodingParameters[0].rtx.ssrc+" cname:"+r.localCName+`\r
1086
- `),m}function n(c,l){var u=!1;return c=JSON.parse(JSON.stringify(c)),c.filter(function(d){if(d&&(d.urls||d.url)){var f=d.urls||d.url;d.url&&!d.urls&&console.warn("RTCIceServer.url is deprecated! Use urls instead.");var m=typeof f=="string";return m&&(f=[f]),f=f.filter(function(x){var _=x.indexOf("turn:")===0&&x.indexOf("transport=udp")!==-1&&x.indexOf("turn:[")===-1&&!u;return _?(u=!0,!0):x.indexOf("stun:")===0&&l>=14393&&x.indexOf("?transport=udp")===-1}),delete d.url,d.urls=m?f[0]:f,!!f.length}})}function i(c,l){var u={codecs:[],headerExtensions:[],fecMechanisms:[]},d=function(m,x){m=parseInt(m,10);for(var _=0;_<x.length;_++)if(x[_].payloadType===m||x[_].preferredPayloadType===m)return x[_]},f=function(m,x,_,g){var v=d(m.parameters.apt,_),w=d(x.parameters.apt,g);return v&&w&&v.name.toLowerCase()===w.name.toLowerCase()};return c.codecs.forEach(function(m){for(var x=0;x<l.codecs.length;x++){var _=l.codecs[x];if(m.name.toLowerCase()===_.name.toLowerCase()&&m.clockRate===_.clockRate){if(m.name.toLowerCase()==="rtx"&&m.parameters&&_.parameters.apt&&!f(m,_,c.codecs,l.codecs))continue;_=JSON.parse(JSON.stringify(_)),_.numChannels=Math.min(m.numChannels,_.numChannels),u.codecs.push(_),_.rtcpFeedback=_.rtcpFeedback.filter(function(g){for(var v=0;v<m.rtcpFeedback.length;v++)if(m.rtcpFeedback[v].type===g.type&&m.rtcpFeedback[v].parameter===g.parameter)return!0;return!1});break}}}),c.headerExtensions.forEach(function(m){for(var x=0;x<l.headerExtensions.length;x++){var _=l.headerExtensions[x];if(m.uri===_.uri){u.headerExtensions.push(_);break}}}),u}function s(c,l,u){return{offer:{setLocalDescription:["stable","have-local-offer"],setRemoteDescription:["stable","have-remote-offer"]},answer:{setLocalDescription:["have-remote-offer","have-local-pranswer"],setRemoteDescription:["have-local-offer","have-remote-pranswer"]}}[l][c].indexOf(u)!==-1}function a(c,l){var u=c.getRemoteCandidates().find(function(d){return l.foundation===d.foundation&&l.ip===d.ip&&l.port===d.port&&l.priority===d.priority&&l.protocol===d.protocol&&l.type===d.type});return u||c.addRemoteCandidate(l),!u}function o(c,l){var u=new Error(l);return u.name=c,u.code={NotSupportedError:9,InvalidStateError:11,InvalidAccessError:15,TypeError:void 0,OperationError:void 0}[c],u}return Gs=function(c,l){function u(g,v){v.addTrack(g),v.dispatchEvent(new c.MediaStreamTrackEvent("addtrack",{track:g}))}function d(g,v){v.removeTrack(g),v.dispatchEvent(new c.MediaStreamTrackEvent("removetrack",{track:g}))}function f(g,v,w,S){var T=new Event("track");T.track=v,T.receiver=w,T.transceiver={receiver:w},T.streams=S,c.setTimeout(function(){g._dispatchEvent("track",T)})}var m=function(g){var v=this,w=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach(function(T){v[T]=w[T].bind(w)}),this.canTrickleIceCandidates=null,this.needNegotiation=!1,this.localStreams=[],this.remoteStreams=[],this._localDescription=null,this._remoteDescription=null,this.signalingState="stable",this.iceConnectionState="new",this.connectionState="new",this.iceGatheringState="new",g=JSON.parse(JSON.stringify(g||{})),this.usingBundle=g.bundlePolicy==="max-bundle",g.rtcpMuxPolicy==="negotiate")throw o("NotSupportedError","rtcpMuxPolicy 'negotiate' is not supported");switch(g.rtcpMuxPolicy||(g.rtcpMuxPolicy="require"),g.iceTransportPolicy){case"all":case"relay":break;default:g.iceTransportPolicy="all";break}switch(g.bundlePolicy){case"balanced":case"max-compat":case"max-bundle":break;default:g.bundlePolicy="balanced";break}if(g.iceServers=n(g.iceServers||[],l),this._iceGatherers=[],g.iceCandidatePoolSize)for(var S=g.iceCandidatePoolSize;S>0;S--)this._iceGatherers.push(new c.RTCIceGatherer({iceServers:g.iceServers,gatherPolicy:g.iceTransportPolicy}));else g.iceCandidatePoolSize=0;this._config=g,this.transceivers=[],this._sdpSessionId=r.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(m.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(m.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),m.prototype.onicecandidate=null,m.prototype.onaddstream=null,m.prototype.ontrack=null,m.prototype.onremovestream=null,m.prototype.onsignalingstatechange=null,m.prototype.oniceconnectionstatechange=null,m.prototype.onconnectionstatechange=null,m.prototype.onicegatheringstatechange=null,m.prototype.onnegotiationneeded=null,m.prototype.ondatachannel=null,m.prototype._dispatchEvent=function(g,v){this._isClosed||(this.dispatchEvent(v),typeof this["on"+g]=="function"&&this["on"+g](v))},m.prototype._emitGatheringStateChange=function(){var g=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",g)},m.prototype.getConfiguration=function(){return this._config},m.prototype.getLocalStreams=function(){return this.localStreams},m.prototype.getRemoteStreams=function(){return this.remoteStreams},m.prototype._createTransceiver=function(g,v){var w=this.transceivers.length>0,S={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:g,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&w)S.iceTransport=this.transceivers[0].iceTransport,S.dtlsTransport=this.transceivers[0].dtlsTransport;else{var T=this._createIceAndDtlsTransports();S.iceTransport=T.iceTransport,S.dtlsTransport=T.dtlsTransport}return v||this.transceivers.push(S),S},m.prototype.addTrack=function(g,v){if(this._isClosed)throw o("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var w=this.transceivers.find(function(M){return M.track===g});if(w)throw o("InvalidAccessError","Track already exists.");for(var S,T=0;T<this.transceivers.length;T++)!this.transceivers[T].track&&this.transceivers[T].kind===g.kind&&(S=this.transceivers[T]);return S||(S=this._createTransceiver(g.kind)),this._maybeFireNegotiationNeeded(),this.localStreams.indexOf(v)===-1&&this.localStreams.push(v),S.track=g,S.stream=v,S.rtpSender=new c.RTCRtpSender(g,S.dtlsTransport),S.rtpSender},m.prototype.addStream=function(g){var v=this;if(l>=15025)g.getTracks().forEach(function(S){v.addTrack(S,g)});else{var w=g.clone();g.getTracks().forEach(function(S,T){var M=w.getTracks()[T];S.addEventListener("enabled",function(P){M.enabled=P.enabled})}),w.getTracks().forEach(function(S){v.addTrack(S,w)})}},m.prototype.removeTrack=function(g){if(this._isClosed)throw o("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(g instanceof c.RTCRtpSender))throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");var v=this.transceivers.find(function(T){return T.rtpSender===g});if(!v)throw o("InvalidAccessError","Sender was not created by this connection.");var w=v.stream;v.rtpSender.stop(),v.rtpSender=null,v.track=null,v.stream=null;var S=this.transceivers.map(function(T){return T.stream});S.indexOf(w)===-1&&this.localStreams.indexOf(w)>-1&&this.localStreams.splice(this.localStreams.indexOf(w),1),this._maybeFireNegotiationNeeded()},m.prototype.removeStream=function(g){var v=this;g.getTracks().forEach(function(w){var S=v.getSenders().find(function(T){return T.track===w});S&&v.removeTrack(S)})},m.prototype.getSenders=function(){return this.transceivers.filter(function(g){return!!g.rtpSender}).map(function(g){return g.rtpSender})},m.prototype.getReceivers=function(){return this.transceivers.filter(function(g){return!!g.rtpReceiver}).map(function(g){return g.rtpReceiver})},m.prototype._createIceGatherer=function(g,v){var w=this;if(v&&g>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var S=new c.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(S,"state",{value:"new",writable:!0}),this.transceivers[g].bufferedCandidateEvents=[],this.transceivers[g].bufferCandidates=function(T){var M=!T.candidate||Object.keys(T.candidate).length===0;S.state=M?"completed":"gathering",w.transceivers[g].bufferedCandidateEvents!==null&&w.transceivers[g].bufferedCandidateEvents.push(T)},S.addEventListener("localcandidate",this.transceivers[g].bufferCandidates),S},m.prototype._gather=function(g,v){var w=this,S=this.transceivers[v].iceGatherer;if(!S.onlocalcandidate){var T=this.transceivers[v].bufferedCandidateEvents;this.transceivers[v].bufferedCandidateEvents=null,S.removeEventListener("localcandidate",this.transceivers[v].bufferCandidates),S.onlocalcandidate=function(M){if(!(w.usingBundle&&v>0)){var P=new Event("icecandidate");P.candidate={sdpMid:g,sdpMLineIndex:v};var E=M.candidate,O=!E||Object.keys(E).length===0;if(O)(S.state==="new"||S.state==="gathering")&&(S.state="completed");else{S.state==="new"&&(S.state="gathering"),E.component=1,E.ufrag=S.getLocalParameters().usernameFragment;var A=r.writeCandidate(E);P.candidate=Object.assign(P.candidate,r.parseCandidate(A)),P.candidate.candidate=A,P.candidate.toJSON=function(){return{candidate:P.candidate.candidate,sdpMid:P.candidate.sdpMid,sdpMLineIndex:P.candidate.sdpMLineIndex,usernameFragment:P.candidate.usernameFragment}}}var R=r.getMediaSections(w._localDescription.sdp);O?R[P.candidate.sdpMLineIndex]+=`a=end-of-candidates\r
1083
+ `;f+="a="+_,f+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" "+_,c.sendEncodingParameters[0].rtx&&(f+="a=ssrc:"+c.sendEncodingParameters[0].rtx.ssrc+" "+_,f+="a=ssrc-group:FID "+c.sendEncodingParameters[0].ssrc+" "+c.sendEncodingParameters[0].rtx.ssrc+`\r
1084
+ `)}return f+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" cname:"+r.localCName+`\r
1085
+ `,c.rtpSender&&c.sendEncodingParameters[0].rtx&&(f+="a=ssrc:"+c.sendEncodingParameters[0].rtx.ssrc+" cname:"+r.localCName+`\r
1086
+ `),f}function n(c,l){var u=!1;return c=JSON.parse(JSON.stringify(c)),c.filter(function(d){if(d&&(d.urls||d.url)){var m=d.urls||d.url;d.url&&!d.urls&&console.warn("RTCIceServer.url is deprecated! Use urls instead.");var f=typeof m=="string";return f&&(m=[m]),m=m.filter(function(x){var _=x.indexOf("turn:")===0&&x.indexOf("transport=udp")!==-1&&x.indexOf("turn:[")===-1&&!u;return _?(u=!0,!0):x.indexOf("stun:")===0&&l>=14393&&x.indexOf("?transport=udp")===-1}),delete d.url,d.urls=f?m[0]:m,!!m.length}})}function i(c,l){var u={codecs:[],headerExtensions:[],fecMechanisms:[]},d=function(f,x){f=parseInt(f,10);for(var _=0;_<x.length;_++)if(x[_].payloadType===f||x[_].preferredPayloadType===f)return x[_]},m=function(f,x,_,g){var v=d(f.parameters.apt,_),w=d(x.parameters.apt,g);return v&&w&&v.name.toLowerCase()===w.name.toLowerCase()};return c.codecs.forEach(function(f){for(var x=0;x<l.codecs.length;x++){var _=l.codecs[x];if(f.name.toLowerCase()===_.name.toLowerCase()&&f.clockRate===_.clockRate){if(f.name.toLowerCase()==="rtx"&&f.parameters&&_.parameters.apt&&!m(f,_,c.codecs,l.codecs))continue;_=JSON.parse(JSON.stringify(_)),_.numChannels=Math.min(f.numChannels,_.numChannels),u.codecs.push(_),_.rtcpFeedback=_.rtcpFeedback.filter(function(g){for(var v=0;v<f.rtcpFeedback.length;v++)if(f.rtcpFeedback[v].type===g.type&&f.rtcpFeedback[v].parameter===g.parameter)return!0;return!1});break}}}),c.headerExtensions.forEach(function(f){for(var x=0;x<l.headerExtensions.length;x++){var _=l.headerExtensions[x];if(f.uri===_.uri){u.headerExtensions.push(_);break}}}),u}function s(c,l,u){return{offer:{setLocalDescription:["stable","have-local-offer"],setRemoteDescription:["stable","have-remote-offer"]},answer:{setLocalDescription:["have-remote-offer","have-local-pranswer"],setRemoteDescription:["have-local-offer","have-remote-pranswer"]}}[l][c].indexOf(u)!==-1}function a(c,l){var u=c.getRemoteCandidates().find(function(d){return l.foundation===d.foundation&&l.ip===d.ip&&l.port===d.port&&l.priority===d.priority&&l.protocol===d.protocol&&l.type===d.type});return u||c.addRemoteCandidate(l),!u}function o(c,l){var u=new Error(l);return u.name=c,u.code={NotSupportedError:9,InvalidStateError:11,InvalidAccessError:15,TypeError:void 0,OperationError:void 0}[c],u}return Ws=function(c,l){function u(g,v){v.addTrack(g),v.dispatchEvent(new c.MediaStreamTrackEvent("addtrack",{track:g}))}function d(g,v){v.removeTrack(g),v.dispatchEvent(new c.MediaStreamTrackEvent("removetrack",{track:g}))}function m(g,v,w,S){var T=new Event("track");T.track=v,T.receiver=w,T.transceiver={receiver:w},T.streams=S,c.setTimeout(function(){g._dispatchEvent("track",T)})}var f=function(g){var v=this,w=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach(function(T){v[T]=w[T].bind(w)}),this.canTrickleIceCandidates=null,this.needNegotiation=!1,this.localStreams=[],this.remoteStreams=[],this._localDescription=null,this._remoteDescription=null,this.signalingState="stable",this.iceConnectionState="new",this.connectionState="new",this.iceGatheringState="new",g=JSON.parse(JSON.stringify(g||{})),this.usingBundle=g.bundlePolicy==="max-bundle",g.rtcpMuxPolicy==="negotiate")throw o("NotSupportedError","rtcpMuxPolicy 'negotiate' is not supported");switch(g.rtcpMuxPolicy||(g.rtcpMuxPolicy="require"),g.iceTransportPolicy){case"all":case"relay":break;default:g.iceTransportPolicy="all";break}switch(g.bundlePolicy){case"balanced":case"max-compat":case"max-bundle":break;default:g.bundlePolicy="balanced";break}if(g.iceServers=n(g.iceServers||[],l),this._iceGatherers=[],g.iceCandidatePoolSize)for(var S=g.iceCandidatePoolSize;S>0;S--)this._iceGatherers.push(new c.RTCIceGatherer({iceServers:g.iceServers,gatherPolicy:g.iceTransportPolicy}));else g.iceCandidatePoolSize=0;this._config=g,this.transceivers=[],this._sdpSessionId=r.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(f.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(f.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),f.prototype.onicecandidate=null,f.prototype.onaddstream=null,f.prototype.ontrack=null,f.prototype.onremovestream=null,f.prototype.onsignalingstatechange=null,f.prototype.oniceconnectionstatechange=null,f.prototype.onconnectionstatechange=null,f.prototype.onicegatheringstatechange=null,f.prototype.onnegotiationneeded=null,f.prototype.ondatachannel=null,f.prototype._dispatchEvent=function(g,v){this._isClosed||(this.dispatchEvent(v),typeof this["on"+g]=="function"&&this["on"+g](v))},f.prototype._emitGatheringStateChange=function(){var g=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",g)},f.prototype.getConfiguration=function(){return this._config},f.prototype.getLocalStreams=function(){return this.localStreams},f.prototype.getRemoteStreams=function(){return this.remoteStreams},f.prototype._createTransceiver=function(g,v){var w=this.transceivers.length>0,S={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:g,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&w)S.iceTransport=this.transceivers[0].iceTransport,S.dtlsTransport=this.transceivers[0].dtlsTransport;else{var T=this._createIceAndDtlsTransports();S.iceTransport=T.iceTransport,S.dtlsTransport=T.dtlsTransport}return v||this.transceivers.push(S),S},f.prototype.addTrack=function(g,v){if(this._isClosed)throw o("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var w=this.transceivers.find(function(C){return C.track===g});if(w)throw o("InvalidAccessError","Track already exists.");for(var S,T=0;T<this.transceivers.length;T++)!this.transceivers[T].track&&this.transceivers[T].kind===g.kind&&(S=this.transceivers[T]);return S||(S=this._createTransceiver(g.kind)),this._maybeFireNegotiationNeeded(),this.localStreams.indexOf(v)===-1&&this.localStreams.push(v),S.track=g,S.stream=v,S.rtpSender=new c.RTCRtpSender(g,S.dtlsTransport),S.rtpSender},f.prototype.addStream=function(g){var v=this;if(l>=15025)g.getTracks().forEach(function(S){v.addTrack(S,g)});else{var w=g.clone();g.getTracks().forEach(function(S,T){var C=w.getTracks()[T];S.addEventListener("enabled",function(P){C.enabled=P.enabled})}),w.getTracks().forEach(function(S){v.addTrack(S,w)})}},f.prototype.removeTrack=function(g){if(this._isClosed)throw o("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(g instanceof c.RTCRtpSender))throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");var v=this.transceivers.find(function(T){return T.rtpSender===g});if(!v)throw o("InvalidAccessError","Sender was not created by this connection.");var w=v.stream;v.rtpSender.stop(),v.rtpSender=null,v.track=null,v.stream=null;var S=this.transceivers.map(function(T){return T.stream});S.indexOf(w)===-1&&this.localStreams.indexOf(w)>-1&&this.localStreams.splice(this.localStreams.indexOf(w),1),this._maybeFireNegotiationNeeded()},f.prototype.removeStream=function(g){var v=this;g.getTracks().forEach(function(w){var S=v.getSenders().find(function(T){return T.track===w});S&&v.removeTrack(S)})},f.prototype.getSenders=function(){return this.transceivers.filter(function(g){return!!g.rtpSender}).map(function(g){return g.rtpSender})},f.prototype.getReceivers=function(){return this.transceivers.filter(function(g){return!!g.rtpReceiver}).map(function(g){return g.rtpReceiver})},f.prototype._createIceGatherer=function(g,v){var w=this;if(v&&g>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var S=new c.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(S,"state",{value:"new",writable:!0}),this.transceivers[g].bufferedCandidateEvents=[],this.transceivers[g].bufferCandidates=function(T){var C=!T.candidate||Object.keys(T.candidate).length===0;S.state=C?"completed":"gathering",w.transceivers[g].bufferedCandidateEvents!==null&&w.transceivers[g].bufferedCandidateEvents.push(T)},S.addEventListener("localcandidate",this.transceivers[g].bufferCandidates),S},f.prototype._gather=function(g,v){var w=this,S=this.transceivers[v].iceGatherer;if(!S.onlocalcandidate){var T=this.transceivers[v].bufferedCandidateEvents;this.transceivers[v].bufferedCandidateEvents=null,S.removeEventListener("localcandidate",this.transceivers[v].bufferCandidates),S.onlocalcandidate=function(C){if(!(w.usingBundle&&v>0)){var P=new Event("icecandidate");P.candidate={sdpMid:g,sdpMLineIndex:v};var E=C.candidate,O=!E||Object.keys(E).length===0;if(O)(S.state==="new"||S.state==="gathering")&&(S.state="completed");else{S.state==="new"&&(S.state="gathering"),E.component=1,E.ufrag=S.getLocalParameters().usernameFragment;var A=r.writeCandidate(E);P.candidate=Object.assign(P.candidate,r.parseCandidate(A)),P.candidate.candidate=A,P.candidate.toJSON=function(){return{candidate:P.candidate.candidate,sdpMid:P.candidate.sdpMid,sdpMLineIndex:P.candidate.sdpMLineIndex,usernameFragment:P.candidate.usernameFragment}}}var R=r.getMediaSections(w._localDescription.sdp);O?R[P.candidate.sdpMLineIndex]+=`a=end-of-candidates\r
1087
1087
  `:R[P.candidate.sdpMLineIndex]+="a="+P.candidate.candidate+`\r
1088
- `,w._localDescription.sdp=r.getDescription(w._localDescription.sdp)+R.join("");var B=w.transceivers.every(function(I){return I.iceGatherer&&I.iceGatherer.state==="completed"});w.iceGatheringState!=="gathering"&&(w.iceGatheringState="gathering",w._emitGatheringStateChange()),O||w._dispatchEvent("icecandidate",P),B&&(w._dispatchEvent("icecandidate",new Event("icecandidate")),w.iceGatheringState="complete",w._emitGatheringStateChange())}},c.setTimeout(function(){T.forEach(function(M){S.onlocalcandidate(M)})},0)}},m.prototype._createIceAndDtlsTransports=function(){var g=this,v=new c.RTCIceTransport(null);v.onicestatechange=function(){g._updateIceConnectionState(),g._updateConnectionState()};var w=new c.RTCDtlsTransport(v);return w.ondtlsstatechange=function(){g._updateConnectionState()},w.onerror=function(){Object.defineProperty(w,"state",{value:"failed",writable:!0}),g._updateConnectionState()},{iceTransport:v,dtlsTransport:w}},m.prototype._disposeIceAndDtlsTransports=function(g){var v=this.transceivers[g].iceGatherer;v&&(delete v.onlocalcandidate,delete this.transceivers[g].iceGatherer);var w=this.transceivers[g].iceTransport;w&&(delete w.onicestatechange,delete this.transceivers[g].iceTransport);var S=this.transceivers[g].dtlsTransport;S&&(delete S.ondtlsstatechange,delete S.onerror,delete this.transceivers[g].dtlsTransport)},m.prototype._transceive=function(g,v,w){var S=i(g.localCapabilities,g.remoteCapabilities);v&&g.rtpSender&&(S.encodings=g.sendEncodingParameters,S.rtcp={cname:r.localCName,compound:g.rtcpParameters.compound},g.recvEncodingParameters.length&&(S.rtcp.ssrc=g.recvEncodingParameters[0].ssrc),g.rtpSender.send(S)),w&&g.rtpReceiver&&S.codecs.length>0&&(g.kind==="video"&&g.recvEncodingParameters&&l<15019&&g.recvEncodingParameters.forEach(function(T){delete T.rtx}),g.recvEncodingParameters.length?S.encodings=g.recvEncodingParameters:S.encodings=[{}],S.rtcp={compound:g.rtcpParameters.compound},g.rtcpParameters.cname&&(S.rtcp.cname=g.rtcpParameters.cname),g.sendEncodingParameters.length&&(S.rtcp.ssrc=g.sendEncodingParameters[0].ssrc),g.rtpReceiver.receive(S))},m.prototype.setLocalDescription=function(g){var v=this;if(["offer","answer"].indexOf(g.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+g.type+'"'));if(!s("setLocalDescription",g.type,v.signalingState)||v._isClosed)return Promise.reject(o("InvalidStateError","Can not set local "+g.type+" in state "+v.signalingState));var w,S;if(g.type==="offer")w=r.splitSections(g.sdp),S=w.shift(),w.forEach(function(M,P){var E=r.parseRtpParameters(M);v.transceivers[P].localCapabilities=E}),v.transceivers.forEach(function(M,P){v._gather(M.mid,P)});else if(g.type==="answer"){w=r.splitSections(v._remoteDescription.sdp),S=w.shift();var T=r.matchPrefix(S,"a=ice-lite").length>0;w.forEach(function(M,P){var E=v.transceivers[P],O=E.iceGatherer,A=E.iceTransport,R=E.dtlsTransport,B=E.localCapabilities,I=E.remoteCapabilities,U=r.isRejected(M)&&r.matchPrefix(M,"a=bundle-only").length===0;if(!U&&!E.rejected){var L=r.getIceParameters(M,S),J=r.getDtlsParameters(M,S);T&&(J.role="server"),(!v.usingBundle||P===0)&&(v._gather(E.mid,P),A.state==="new"&&A.start(O,L,T?"controlling":"controlled"),R.state==="new"&&R.start(J));var H=i(B,I);v._transceive(E,H.codecs.length>0,!1)}})}return v._localDescription={type:g.type,sdp:g.sdp},g.type==="offer"?v._updateSignalingState("have-local-offer"):v._updateSignalingState("stable"),Promise.resolve()},m.prototype.setRemoteDescription=function(g){var v=this;if(["offer","answer"].indexOf(g.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+g.type+'"'));if(!s("setRemoteDescription",g.type,v.signalingState)||v._isClosed)return Promise.reject(o("InvalidStateError","Can not set remote "+g.type+" in state "+v.signalingState));var w={};v.remoteStreams.forEach(function(A){w[A.id]=A});var S=[],T=r.splitSections(g.sdp),M=T.shift(),P=r.matchPrefix(M,"a=ice-lite").length>0,E=r.matchPrefix(M,"a=group:BUNDLE ").length>0;v.usingBundle=E;var O=r.matchPrefix(M,"a=ice-options:")[0];return O?v.canTrickleIceCandidates=O.substr(14).split(" ").indexOf("trickle")>=0:v.canTrickleIceCandidates=!1,T.forEach(function(A,R){var B=r.splitLines(A),I=r.getKind(A),U=r.isRejected(A)&&r.matchPrefix(A,"a=bundle-only").length===0,L=B[0].substr(2).split(" ")[2],J=r.getDirection(A,M),H=r.parseMsid(A),se=r.getMid(A)||r.generateIdentifier();if(U||I==="application"&&(L==="DTLS/SCTP"||L==="UDP/DTLS/SCTP")){v.transceivers[R]={mid:se,kind:I,protocol:L,rejected:!0};return}!U&&v.transceivers[R]&&v.transceivers[R].rejected&&(v.transceivers[R]=v._createTransceiver(I,!0));var W,pe,ne,he,oe,le,xe,ge,de,re=r.parseRtpParameters(A),Ze,Ue;U||(Ze=r.getIceParameters(A,M),Ue=r.getDtlsParameters(A,M),Ue.role="client"),xe=r.parseRtpEncodingParameters(A);var ke=r.parseRtcpParameters(A),lt=r.matchPrefix(A,"a=end-of-candidates",M).length>0,De=r.matchPrefix(A,"a=candidate:").map(function(fe){return r.parseCandidate(fe)}).filter(function(fe){return fe.component===1});if((g.type==="offer"||g.type==="answer")&&!U&&E&&R>0&&v.transceivers[R]&&(v._disposeIceAndDtlsTransports(R),v.transceivers[R].iceGatherer=v.transceivers[0].iceGatherer,v.transceivers[R].iceTransport=v.transceivers[0].iceTransport,v.transceivers[R].dtlsTransport=v.transceivers[0].dtlsTransport,v.transceivers[R].rtpSender&&v.transceivers[R].rtpSender.setTransport(v.transceivers[0].dtlsTransport),v.transceivers[R].rtpReceiver&&v.transceivers[R].rtpReceiver.setTransport(v.transceivers[0].dtlsTransport)),g.type==="offer"&&!U){W=v.transceivers[R]||v._createTransceiver(I),W.mid=se,W.iceGatherer||(W.iceGatherer=v._createIceGatherer(R,E)),De.length&&W.iceTransport.state==="new"&&(lt&&(!E||R===0)?W.iceTransport.setRemoteCandidates(De):De.forEach(function(fe){a(W.iceTransport,fe)})),ge=c.RTCRtpReceiver.getCapabilities(I),l<15019&&(ge.codecs=ge.codecs.filter(function(fe){return fe.name!=="rtx"})),le=W.sendEncodingParameters||[{ssrc:(2*R+2)*1001}];var ve=!1;if(J==="sendrecv"||J==="sendonly"){if(ve=!W.rtpReceiver,oe=W.rtpReceiver||new c.RTCRtpReceiver(W.dtlsTransport,I),ve){var ue;de=oe.track,H&&H.stream==="-"||(H?(w[H.stream]||(w[H.stream]=new c.MediaStream,Object.defineProperty(w[H.stream],"id",{get:function(){return H.stream}})),Object.defineProperty(de,"id",{get:function(){return H.track}}),ue=w[H.stream]):(w.default||(w.default=new c.MediaStream),ue=w.default)),ue&&(u(de,ue),W.associatedRemoteMediaStreams.push(ue)),S.push([de,oe,ue])}}else W.rtpReceiver&&W.rtpReceiver.track&&(W.associatedRemoteMediaStreams.forEach(function(fe){var rt=fe.getTracks().find(function(wt){return wt.id===W.rtpReceiver.track.id});rt&&d(rt,fe)}),W.associatedRemoteMediaStreams=[]);W.localCapabilities=ge,W.remoteCapabilities=re,W.rtpReceiver=oe,W.rtcpParameters=ke,W.sendEncodingParameters=le,W.recvEncodingParameters=xe,v._transceive(v.transceivers[R],!1,ve)}else if(g.type==="answer"&&!U){W=v.transceivers[R],pe=W.iceGatherer,ne=W.iceTransport,he=W.dtlsTransport,oe=W.rtpReceiver,le=W.sendEncodingParameters,ge=W.localCapabilities,v.transceivers[R].recvEncodingParameters=xe,v.transceivers[R].remoteCapabilities=re,v.transceivers[R].rtcpParameters=ke,De.length&&ne.state==="new"&&((P||lt)&&(!E||R===0)?ne.setRemoteCandidates(De):De.forEach(function(fe){a(W.iceTransport,fe)})),(!E||R===0)&&(ne.state==="new"&&ne.start(pe,Ze,"controlling"),he.state==="new"&&he.start(Ue));var ft=i(W.localCapabilities,W.remoteCapabilities),Re=ft.codecs.filter(function(fe){return fe.name.toLowerCase()==="rtx"}).length;!Re&&W.sendEncodingParameters[0].rtx&&delete W.sendEncodingParameters[0].rtx,v._transceive(W,J==="sendrecv"||J==="recvonly",J==="sendrecv"||J==="sendonly"),oe&&(J==="sendrecv"||J==="sendonly")?(de=oe.track,H?(w[H.stream]||(w[H.stream]=new c.MediaStream),u(de,w[H.stream]),S.push([de,oe,w[H.stream]])):(w.default||(w.default=new c.MediaStream),u(de,w.default),S.push([de,oe,w.default]))):delete W.rtpReceiver}}),v._dtlsRole===void 0&&(v._dtlsRole=g.type==="offer"?"active":"passive"),v._remoteDescription={type:g.type,sdp:g.sdp},g.type==="offer"?v._updateSignalingState("have-remote-offer"):v._updateSignalingState("stable"),Object.keys(w).forEach(function(A){var R=w[A];if(R.getTracks().length){if(v.remoteStreams.indexOf(R)===-1){v.remoteStreams.push(R);var B=new Event("addstream");B.stream=R,c.setTimeout(function(){v._dispatchEvent("addstream",B)})}S.forEach(function(I){var U=I[0],L=I[1];R.id===I[2].id&&f(v,U,L,[R])})}}),S.forEach(function(A){A[2]||f(v,A[0],A[1],[])}),c.setTimeout(function(){v&&v.transceivers&&v.transceivers.forEach(function(A){A.iceTransport&&A.iceTransport.state==="new"&&A.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),A.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},m.prototype.close=function(){this.transceivers.forEach(function(g){g.iceTransport&&g.iceTransport.stop(),g.dtlsTransport&&g.dtlsTransport.stop(),g.rtpSender&&g.rtpSender.stop(),g.rtpReceiver&&g.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState("closed")},m.prototype._updateSignalingState=function(g){this.signalingState=g;var v=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",v)},m.prototype._maybeFireNegotiationNeeded=function(){var g=this;this.signalingState!=="stable"||this.needNegotiation===!0||(this.needNegotiation=!0,c.setTimeout(function(){if(g.needNegotiation){g.needNegotiation=!1;var v=new Event("negotiationneeded");g._dispatchEvent("negotiationneeded",v)}},0))},m.prototype._updateIceConnectionState=function(){var g,v={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(S){S.iceTransport&&!S.rejected&&v[S.iceTransport.state]++}),g="new",v.failed>0?g="failed":v.checking>0?g="checking":v.disconnected>0?g="disconnected":v.new>0?g="new":v.connected>0?g="connected":v.completed>0&&(g="completed"),g!==this.iceConnectionState){this.iceConnectionState=g;var w=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",w)}},m.prototype._updateConnectionState=function(){var g,v={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(S){S.iceTransport&&S.dtlsTransport&&!S.rejected&&(v[S.iceTransport.state]++,v[S.dtlsTransport.state]++)}),v.connected+=v.completed,g="new",v.failed>0?g="failed":v.connecting>0?g="connecting":v.disconnected>0?g="disconnected":v.new>0?g="new":v.connected>0&&(g="connected"),g!==this.connectionState){this.connectionState=g;var w=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",w)}},m.prototype.createOffer=function(){var g=this;if(g._isClosed)return Promise.reject(o("InvalidStateError","Can not call createOffer after close"));var v=g.transceivers.filter(function(P){return P.kind==="audio"}).length,w=g.transceivers.filter(function(P){return P.kind==="video"}).length,S=arguments[0];if(S){if(S.mandatory||S.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");S.offerToReceiveAudio!==void 0&&(S.offerToReceiveAudio===!0?v=1:S.offerToReceiveAudio===!1?v=0:v=S.offerToReceiveAudio),S.offerToReceiveVideo!==void 0&&(S.offerToReceiveVideo===!0?w=1:S.offerToReceiveVideo===!1?w=0:w=S.offerToReceiveVideo)}for(g.transceivers.forEach(function(P){P.kind==="audio"?(v--,v<0&&(P.wantReceive=!1)):P.kind==="video"&&(w--,w<0&&(P.wantReceive=!1))});v>0||w>0;)v>0&&(g._createTransceiver("audio"),v--),w>0&&(g._createTransceiver("video"),w--);var T=r.writeSessionBoilerplate(g._sdpSessionId,g._sdpSessionVersion++);g.transceivers.forEach(function(P,E){var O=P.track,A=P.kind,R=P.mid||r.generateIdentifier();P.mid=R,P.iceGatherer||(P.iceGatherer=g._createIceGatherer(E,g.usingBundle));var B=c.RTCRtpSender.getCapabilities(A);l<15019&&(B.codecs=B.codecs.filter(function(U){return U.name!=="rtx"})),B.codecs.forEach(function(U){U.name==="H264"&&U.parameters["level-asymmetry-allowed"]===void 0&&(U.parameters["level-asymmetry-allowed"]="1"),P.remoteCapabilities&&P.remoteCapabilities.codecs&&P.remoteCapabilities.codecs.forEach(function(L){U.name.toLowerCase()===L.name.toLowerCase()&&U.clockRate===L.clockRate&&(U.preferredPayloadType=L.payloadType)})}),B.headerExtensions.forEach(function(U){var L=P.remoteCapabilities&&P.remoteCapabilities.headerExtensions||[];L.forEach(function(J){U.uri===J.uri&&(U.id=J.id)})});var I=P.sendEncodingParameters||[{ssrc:(2*E+1)*1001}];O&&l>=15019&&A==="video"&&!I[0].rtx&&(I[0].rtx={ssrc:I[0].ssrc+1}),P.wantReceive&&(P.rtpReceiver=new c.RTCRtpReceiver(P.dtlsTransport,A)),P.localCapabilities=B,P.sendEncodingParameters=I}),g._config.bundlePolicy!=="max-compat"&&(T+="a=group:BUNDLE "+g.transceivers.map(function(P){return P.mid}).join(" ")+`\r
1088
+ `,w._localDescription.sdp=r.getDescription(w._localDescription.sdp)+R.join("");var B=w.transceivers.every(function(z){return z.iceGatherer&&z.iceGatherer.state==="completed"});w.iceGatheringState!=="gathering"&&(w.iceGatheringState="gathering",w._emitGatheringStateChange()),O||w._dispatchEvent("icecandidate",P),B&&(w._dispatchEvent("icecandidate",new Event("icecandidate")),w.iceGatheringState="complete",w._emitGatheringStateChange())}},c.setTimeout(function(){T.forEach(function(C){S.onlocalcandidate(C)})},0)}},f.prototype._createIceAndDtlsTransports=function(){var g=this,v=new c.RTCIceTransport(null);v.onicestatechange=function(){g._updateIceConnectionState(),g._updateConnectionState()};var w=new c.RTCDtlsTransport(v);return w.ondtlsstatechange=function(){g._updateConnectionState()},w.onerror=function(){Object.defineProperty(w,"state",{value:"failed",writable:!0}),g._updateConnectionState()},{iceTransport:v,dtlsTransport:w}},f.prototype._disposeIceAndDtlsTransports=function(g){var v=this.transceivers[g].iceGatherer;v&&(delete v.onlocalcandidate,delete this.transceivers[g].iceGatherer);var w=this.transceivers[g].iceTransport;w&&(delete w.onicestatechange,delete this.transceivers[g].iceTransport);var S=this.transceivers[g].dtlsTransport;S&&(delete S.ondtlsstatechange,delete S.onerror,delete this.transceivers[g].dtlsTransport)},f.prototype._transceive=function(g,v,w){var S=i(g.localCapabilities,g.remoteCapabilities);v&&g.rtpSender&&(S.encodings=g.sendEncodingParameters,S.rtcp={cname:r.localCName,compound:g.rtcpParameters.compound},g.recvEncodingParameters.length&&(S.rtcp.ssrc=g.recvEncodingParameters[0].ssrc),g.rtpSender.send(S)),w&&g.rtpReceiver&&S.codecs.length>0&&(g.kind==="video"&&g.recvEncodingParameters&&l<15019&&g.recvEncodingParameters.forEach(function(T){delete T.rtx}),g.recvEncodingParameters.length?S.encodings=g.recvEncodingParameters:S.encodings=[{}],S.rtcp={compound:g.rtcpParameters.compound},g.rtcpParameters.cname&&(S.rtcp.cname=g.rtcpParameters.cname),g.sendEncodingParameters.length&&(S.rtcp.ssrc=g.sendEncodingParameters[0].ssrc),g.rtpReceiver.receive(S))},f.prototype.setLocalDescription=function(g){var v=this;if(["offer","answer"].indexOf(g.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+g.type+'"'));if(!s("setLocalDescription",g.type,v.signalingState)||v._isClosed)return Promise.reject(o("InvalidStateError","Can not set local "+g.type+" in state "+v.signalingState));var w,S;if(g.type==="offer")w=r.splitSections(g.sdp),S=w.shift(),w.forEach(function(C,P){var E=r.parseRtpParameters(C);v.transceivers[P].localCapabilities=E}),v.transceivers.forEach(function(C,P){v._gather(C.mid,P)});else if(g.type==="answer"){w=r.splitSections(v._remoteDescription.sdp),S=w.shift();var T=r.matchPrefix(S,"a=ice-lite").length>0;w.forEach(function(C,P){var E=v.transceivers[P],O=E.iceGatherer,A=E.iceTransport,R=E.dtlsTransport,B=E.localCapabilities,z=E.remoteCapabilities,U=r.isRejected(C)&&r.matchPrefix(C,"a=bundle-only").length===0;if(!U&&!E.rejected){var L=r.getIceParameters(C,S),J=r.getDtlsParameters(C,S);T&&(J.role="server"),(!v.usingBundle||P===0)&&(v._gather(E.mid,P),A.state==="new"&&A.start(O,L,T?"controlling":"controlled"),R.state==="new"&&R.start(J));var H=i(B,z);v._transceive(E,H.codecs.length>0,!1)}})}return v._localDescription={type:g.type,sdp:g.sdp},g.type==="offer"?v._updateSignalingState("have-local-offer"):v._updateSignalingState("stable"),Promise.resolve()},f.prototype.setRemoteDescription=function(g){var v=this;if(["offer","answer"].indexOf(g.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+g.type+'"'));if(!s("setRemoteDescription",g.type,v.signalingState)||v._isClosed)return Promise.reject(o("InvalidStateError","Can not set remote "+g.type+" in state "+v.signalingState));var w={};v.remoteStreams.forEach(function(A){w[A.id]=A});var S=[],T=r.splitSections(g.sdp),C=T.shift(),P=r.matchPrefix(C,"a=ice-lite").length>0,E=r.matchPrefix(C,"a=group:BUNDLE ").length>0;v.usingBundle=E;var O=r.matchPrefix(C,"a=ice-options:")[0];return O?v.canTrickleIceCandidates=O.substr(14).split(" ").indexOf("trickle")>=0:v.canTrickleIceCandidates=!1,T.forEach(function(A,R){var B=r.splitLines(A),z=r.getKind(A),U=r.isRejected(A)&&r.matchPrefix(A,"a=bundle-only").length===0,L=B[0].substr(2).split(" ")[2],J=r.getDirection(A,C),H=r.parseMsid(A),se=r.getMid(A)||r.generateIdentifier();if(U||z==="application"&&(L==="DTLS/SCTP"||L==="UDP/DTLS/SCTP")){v.transceivers[R]={mid:se,kind:z,protocol:L,rejected:!0};return}!U&&v.transceivers[R]&&v.transceivers[R].rejected&&(v.transceivers[R]=v._createTransceiver(z,!0));var W,pe,te,ue,oe,le,xe,ge,de,re=r.parseRtpParameters(A),Ze,Ue;U||(Ze=r.getIceParameters(A,C),Ue=r.getDtlsParameters(A,C),Ue.role="client"),xe=r.parseRtpEncodingParameters(A);var ke=r.parseRtcpParameters(A),lt=r.matchPrefix(A,"a=end-of-candidates",C).length>0,De=r.matchPrefix(A,"a=candidate:").map(function(fe){return r.parseCandidate(fe)}).filter(function(fe){return fe.component===1});if((g.type==="offer"||g.type==="answer")&&!U&&E&&R>0&&v.transceivers[R]&&(v._disposeIceAndDtlsTransports(R),v.transceivers[R].iceGatherer=v.transceivers[0].iceGatherer,v.transceivers[R].iceTransport=v.transceivers[0].iceTransport,v.transceivers[R].dtlsTransport=v.transceivers[0].dtlsTransport,v.transceivers[R].rtpSender&&v.transceivers[R].rtpSender.setTransport(v.transceivers[0].dtlsTransport),v.transceivers[R].rtpReceiver&&v.transceivers[R].rtpReceiver.setTransport(v.transceivers[0].dtlsTransport)),g.type==="offer"&&!U){W=v.transceivers[R]||v._createTransceiver(z),W.mid=se,W.iceGatherer||(W.iceGatherer=v._createIceGatherer(R,E)),De.length&&W.iceTransport.state==="new"&&(lt&&(!E||R===0)?W.iceTransport.setRemoteCandidates(De):De.forEach(function(fe){a(W.iceTransport,fe)})),ge=c.RTCRtpReceiver.getCapabilities(z),l<15019&&(ge.codecs=ge.codecs.filter(function(fe){return fe.name!=="rtx"})),le=W.sendEncodingParameters||[{ssrc:(2*R+2)*1001}];var ve=!1;if(J==="sendrecv"||J==="sendonly"){if(ve=!W.rtpReceiver,oe=W.rtpReceiver||new c.RTCRtpReceiver(W.dtlsTransport,z),ve){var he;de=oe.track,H&&H.stream==="-"||(H?(w[H.stream]||(w[H.stream]=new c.MediaStream,Object.defineProperty(w[H.stream],"id",{get:function(){return H.stream}})),Object.defineProperty(de,"id",{get:function(){return H.track}}),he=w[H.stream]):(w.default||(w.default=new c.MediaStream),he=w.default)),he&&(u(de,he),W.associatedRemoteMediaStreams.push(he)),S.push([de,oe,he])}}else W.rtpReceiver&&W.rtpReceiver.track&&(W.associatedRemoteMediaStreams.forEach(function(fe){var rt=fe.getTracks().find(function(wt){return wt.id===W.rtpReceiver.track.id});rt&&d(rt,fe)}),W.associatedRemoteMediaStreams=[]);W.localCapabilities=ge,W.remoteCapabilities=re,W.rtpReceiver=oe,W.rtcpParameters=ke,W.sendEncodingParameters=le,W.recvEncodingParameters=xe,v._transceive(v.transceivers[R],!1,ve)}else if(g.type==="answer"&&!U){W=v.transceivers[R],pe=W.iceGatherer,te=W.iceTransport,ue=W.dtlsTransport,oe=W.rtpReceiver,le=W.sendEncodingParameters,ge=W.localCapabilities,v.transceivers[R].recvEncodingParameters=xe,v.transceivers[R].remoteCapabilities=re,v.transceivers[R].rtcpParameters=ke,De.length&&te.state==="new"&&((P||lt)&&(!E||R===0)?te.setRemoteCandidates(De):De.forEach(function(fe){a(W.iceTransport,fe)})),(!E||R===0)&&(te.state==="new"&&te.start(pe,Ze,"controlling"),ue.state==="new"&&ue.start(Ue));var ft=i(W.localCapabilities,W.remoteCapabilities),Re=ft.codecs.filter(function(fe){return fe.name.toLowerCase()==="rtx"}).length;!Re&&W.sendEncodingParameters[0].rtx&&delete W.sendEncodingParameters[0].rtx,v._transceive(W,J==="sendrecv"||J==="recvonly",J==="sendrecv"||J==="sendonly"),oe&&(J==="sendrecv"||J==="sendonly")?(de=oe.track,H?(w[H.stream]||(w[H.stream]=new c.MediaStream),u(de,w[H.stream]),S.push([de,oe,w[H.stream]])):(w.default||(w.default=new c.MediaStream),u(de,w.default),S.push([de,oe,w.default]))):delete W.rtpReceiver}}),v._dtlsRole===void 0&&(v._dtlsRole=g.type==="offer"?"active":"passive"),v._remoteDescription={type:g.type,sdp:g.sdp},g.type==="offer"?v._updateSignalingState("have-remote-offer"):v._updateSignalingState("stable"),Object.keys(w).forEach(function(A){var R=w[A];if(R.getTracks().length){if(v.remoteStreams.indexOf(R)===-1){v.remoteStreams.push(R);var B=new Event("addstream");B.stream=R,c.setTimeout(function(){v._dispatchEvent("addstream",B)})}S.forEach(function(z){var U=z[0],L=z[1];R.id===z[2].id&&m(v,U,L,[R])})}}),S.forEach(function(A){A[2]||m(v,A[0],A[1],[])}),c.setTimeout(function(){v&&v.transceivers&&v.transceivers.forEach(function(A){A.iceTransport&&A.iceTransport.state==="new"&&A.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),A.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},f.prototype.close=function(){this.transceivers.forEach(function(g){g.iceTransport&&g.iceTransport.stop(),g.dtlsTransport&&g.dtlsTransport.stop(),g.rtpSender&&g.rtpSender.stop(),g.rtpReceiver&&g.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState("closed")},f.prototype._updateSignalingState=function(g){this.signalingState=g;var v=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",v)},f.prototype._maybeFireNegotiationNeeded=function(){var g=this;this.signalingState!=="stable"||this.needNegotiation===!0||(this.needNegotiation=!0,c.setTimeout(function(){if(g.needNegotiation){g.needNegotiation=!1;var v=new Event("negotiationneeded");g._dispatchEvent("negotiationneeded",v)}},0))},f.prototype._updateIceConnectionState=function(){var g,v={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(S){S.iceTransport&&!S.rejected&&v[S.iceTransport.state]++}),g="new",v.failed>0?g="failed":v.checking>0?g="checking":v.disconnected>0?g="disconnected":v.new>0?g="new":v.connected>0?g="connected":v.completed>0&&(g="completed"),g!==this.iceConnectionState){this.iceConnectionState=g;var w=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",w)}},f.prototype._updateConnectionState=function(){var g,v={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(S){S.iceTransport&&S.dtlsTransport&&!S.rejected&&(v[S.iceTransport.state]++,v[S.dtlsTransport.state]++)}),v.connected+=v.completed,g="new",v.failed>0?g="failed":v.connecting>0?g="connecting":v.disconnected>0?g="disconnected":v.new>0?g="new":v.connected>0&&(g="connected"),g!==this.connectionState){this.connectionState=g;var w=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",w)}},f.prototype.createOffer=function(){var g=this;if(g._isClosed)return Promise.reject(o("InvalidStateError","Can not call createOffer after close"));var v=g.transceivers.filter(function(P){return P.kind==="audio"}).length,w=g.transceivers.filter(function(P){return P.kind==="video"}).length,S=arguments[0];if(S){if(S.mandatory||S.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");S.offerToReceiveAudio!==void 0&&(S.offerToReceiveAudio===!0?v=1:S.offerToReceiveAudio===!1?v=0:v=S.offerToReceiveAudio),S.offerToReceiveVideo!==void 0&&(S.offerToReceiveVideo===!0?w=1:S.offerToReceiveVideo===!1?w=0:w=S.offerToReceiveVideo)}for(g.transceivers.forEach(function(P){P.kind==="audio"?(v--,v<0&&(P.wantReceive=!1)):P.kind==="video"&&(w--,w<0&&(P.wantReceive=!1))});v>0||w>0;)v>0&&(g._createTransceiver("audio"),v--),w>0&&(g._createTransceiver("video"),w--);var T=r.writeSessionBoilerplate(g._sdpSessionId,g._sdpSessionVersion++);g.transceivers.forEach(function(P,E){var O=P.track,A=P.kind,R=P.mid||r.generateIdentifier();P.mid=R,P.iceGatherer||(P.iceGatherer=g._createIceGatherer(E,g.usingBundle));var B=c.RTCRtpSender.getCapabilities(A);l<15019&&(B.codecs=B.codecs.filter(function(U){return U.name!=="rtx"})),B.codecs.forEach(function(U){U.name==="H264"&&U.parameters["level-asymmetry-allowed"]===void 0&&(U.parameters["level-asymmetry-allowed"]="1"),P.remoteCapabilities&&P.remoteCapabilities.codecs&&P.remoteCapabilities.codecs.forEach(function(L){U.name.toLowerCase()===L.name.toLowerCase()&&U.clockRate===L.clockRate&&(U.preferredPayloadType=L.payloadType)})}),B.headerExtensions.forEach(function(U){var L=P.remoteCapabilities&&P.remoteCapabilities.headerExtensions||[];L.forEach(function(J){U.uri===J.uri&&(U.id=J.id)})});var z=P.sendEncodingParameters||[{ssrc:(2*E+1)*1001}];O&&l>=15019&&A==="video"&&!z[0].rtx&&(z[0].rtx={ssrc:z[0].ssrc+1}),P.wantReceive&&(P.rtpReceiver=new c.RTCRtpReceiver(P.dtlsTransport,A)),P.localCapabilities=B,P.sendEncodingParameters=z}),g._config.bundlePolicy!=="max-compat"&&(T+="a=group:BUNDLE "+g.transceivers.map(function(P){return P.mid}).join(" ")+`\r
1089
1089
  `),T+=`a=ice-options:trickle\r
1090
1090
  `,g.transceivers.forEach(function(P,E){T+=t(P,P.localCapabilities,"offer",P.stream,g._dtlsRole),T+=`a=rtcp-rsize\r
1091
1091
  `,P.iceGatherer&&g.iceGatheringState!=="new"&&(E===0||!g.usingBundle)&&(P.iceGatherer.getLocalCandidates().forEach(function(O){O.component=1,T+="a="+r.writeCandidate(O)+`\r
1092
1092
  `}),P.iceGatherer.state==="completed"&&(T+=`a=end-of-candidates\r
1093
- `))});var M=new c.RTCSessionDescription({type:"offer",sdp:T});return Promise.resolve(M)},m.prototype.createAnswer=function(){var g=this;if(g._isClosed)return Promise.reject(o("InvalidStateError","Can not call createAnswer after close"));if(!(g.signalingState==="have-remote-offer"||g.signalingState==="have-local-pranswer"))return Promise.reject(o("InvalidStateError","Can not call createAnswer in signalingState "+g.signalingState));var v=r.writeSessionBoilerplate(g._sdpSessionId,g._sdpSessionVersion++);g.usingBundle&&(v+="a=group:BUNDLE "+g.transceivers.map(function(T){return T.mid}).join(" ")+`\r
1093
+ `))});var C=new c.RTCSessionDescription({type:"offer",sdp:T});return Promise.resolve(C)},f.prototype.createAnswer=function(){var g=this;if(g._isClosed)return Promise.reject(o("InvalidStateError","Can not call createAnswer after close"));if(!(g.signalingState==="have-remote-offer"||g.signalingState==="have-local-pranswer"))return Promise.reject(o("InvalidStateError","Can not call createAnswer in signalingState "+g.signalingState));var v=r.writeSessionBoilerplate(g._sdpSessionId,g._sdpSessionVersion++);g.usingBundle&&(v+="a=group:BUNDLE "+g.transceivers.map(function(T){return T.mid}).join(" ")+`\r
1094
1094
  `),v+=`a=ice-options:trickle\r
1095
- `;var w=r.getMediaSections(g._remoteDescription.sdp).length;g.transceivers.forEach(function(T,M){if(!(M+1>w)){if(T.rejected){T.kind==="application"?T.protocol==="DTLS/SCTP"?v+=`m=application 0 DTLS/SCTP 5000\r
1095
+ `;var w=r.getMediaSections(g._remoteDescription.sdp).length;g.transceivers.forEach(function(T,C){if(!(C+1>w)){if(T.rejected){T.kind==="application"?T.protocol==="DTLS/SCTP"?v+=`m=application 0 DTLS/SCTP 5000\r
1096
1096
  `:v+="m=application 0 "+T.protocol+` webrtc-datachannel\r
1097
1097
  `:T.kind==="audio"?v+=`m=audio 0 UDP/TLS/RTP/SAVPF 0\r
1098
1098
  a=rtpmap:0 PCMU/8000\r
@@ -1102,15 +1102,15 @@ a=rtpmap:120 VP8/90000\r
1102
1102
  a=inactive\r
1103
1103
  a=mid:`+T.mid+`\r
1104
1104
  `;return}if(T.stream){var P;T.kind==="audio"?P=T.stream.getAudioTracks()[0]:T.kind==="video"&&(P=T.stream.getVideoTracks()[0]),P&&l>=15019&&T.kind==="video"&&!T.sendEncodingParameters[0].rtx&&(T.sendEncodingParameters[0].rtx={ssrc:T.sendEncodingParameters[0].ssrc+1})}var E=i(T.localCapabilities,T.remoteCapabilities),O=E.codecs.filter(function(A){return A.name.toLowerCase()==="rtx"}).length;!O&&T.sendEncodingParameters[0].rtx&&delete T.sendEncodingParameters[0].rtx,v+=t(T,E,"answer",T.stream,g._dtlsRole),T.rtcpParameters&&T.rtcpParameters.reducedSize&&(v+=`a=rtcp-rsize\r
1105
- `)}});var S=new c.RTCSessionDescription({type:"answer",sdp:v});return Promise.resolve(S)},m.prototype.addIceCandidate=function(g){var v=this,w;return g&&!(g.sdpMLineIndex!==void 0||g.sdpMid)?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise(function(S,T){if(v._remoteDescription)if(!g||g.candidate==="")for(var M=0;M<v.transceivers.length&&!(!v.transceivers[M].rejected&&(v.transceivers[M].iceTransport.addRemoteCandidate({}),w=r.getMediaSections(v._remoteDescription.sdp),w[M]+=`a=end-of-candidates\r
1106
- `,v._remoteDescription.sdp=r.getDescription(v._remoteDescription.sdp)+w.join(""),v.usingBundle));M++);else{var P=g.sdpMLineIndex;if(g.sdpMid){for(var E=0;E<v.transceivers.length;E++)if(v.transceivers[E].mid===g.sdpMid){P=E;break}}var O=v.transceivers[P];if(O){if(O.rejected)return S();var A=Object.keys(g.candidate).length>0?r.parseCandidate(g.candidate):{};if(A.protocol==="tcp"&&(A.port===0||A.port===9)||A.component&&A.component!==1)return S();if((P===0||P>0&&O.iceTransport!==v.transceivers[0].iceTransport)&&!a(O.iceTransport,A))return T(o("OperationError","Can not add ICE candidate"));var R=g.candidate.trim();R.indexOf("a=")===0&&(R=R.substr(2)),w=r.getMediaSections(v._remoteDescription.sdp),w[P]+="a="+(A.type?R:"end-of-candidates")+`\r
1107
- `,v._remoteDescription.sdp=r.getDescription(v._remoteDescription.sdp)+w.join("")}else return T(o("OperationError","Can not add ICE candidate"))}else return T(o("InvalidStateError","Can not add ICE candidate without a remote description"));S()})},m.prototype.getStats=function(g){if(g&&g instanceof c.MediaStreamTrack){var v=null;if(this.transceivers.forEach(function(S){S.rtpSender&&S.rtpSender.track===g?v=S.rtpSender:S.rtpReceiver&&S.rtpReceiver.track===g&&(v=S.rtpReceiver)}),!v)throw o("InvalidAccessError","Invalid selector.");return v.getStats()}var w=[];return this.transceivers.forEach(function(S){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(T){S[T]&&w.push(S[T].getStats())})}),Promise.all(w).then(function(S){var T=new Map;return S.forEach(function(M){M.forEach(function(P){T.set(P.id,P)})}),T})};var x=["RTCRtpSender","RTCRtpReceiver","RTCIceGatherer","RTCIceTransport","RTCDtlsTransport"];x.forEach(function(g){var v=c[g];if(v&&v.prototype&&v.prototype.getStats){var w=v.prototype.getStats;v.prototype.getStats=function(){return w.apply(this).then(function(S){var T=new Map;return Object.keys(S).forEach(function(M){S[M].type=e(S[M]),T.set(M,S[M])}),T})}}});var _=["createOffer","createAnswer"];return _.forEach(function(g){var v=m.prototype[g];m.prototype[g]=function(){var w=arguments;return typeof w[0]=="function"||typeof w[1]=="function"?v.apply(this,[arguments[2]]).then(function(S){typeof w[0]=="function"&&w[0].apply(null,[S])},function(S){typeof w[1]=="function"&&w[1].apply(null,[S])}):v.apply(this,arguments)}}),_=["setLocalDescription","setRemoteDescription","addIceCandidate"],_.forEach(function(g){var v=m.prototype[g];m.prototype[g]=function(){var w=arguments;return typeof w[1]=="function"||typeof w[2]=="function"?v.apply(this,arguments).then(function(){typeof w[1]=="function"&&w[1].apply(null)},function(S){typeof w[2]=="function"&&w[2].apply(null,[S])}):v.apply(this,arguments)}}),["getStats"].forEach(function(g){var v=m.prototype[g];m.prototype[g]=function(){var w=arguments;return typeof w[1]=="function"?v.apply(this,arguments).then(function(){typeof w[1]=="function"&&w[1].apply(null)}):v.apply(this,arguments)}}),m},Gs}var cd=ad();const ld=ur(cd);function pc(r){const e=r&&r.navigator,t=function(i){return{name:{PermissionDeniedError:"NotAllowedError"}[i.name]||i.name,message:i.message,constraint:i.constraint,toString(){return this.name}}},n=e.mediaDevices.getUserMedia.bind(e.mediaDevices);Object.getOwnPropertyDescriptor(e.mediaDevices,"getUserMedia")?.writable&&(e.mediaDevices.getUserMedia=function(i){return n(i).catch(s=>Promise.reject(t(s)))})}function fc(r){"getDisplayMedia"in r.navigator&&r.navigator.mediaDevices&&(r.navigator.mediaDevices&&"getDisplayMedia"in r.navigator.mediaDevices||(r.navigator.mediaDevices.getDisplayMedia=r.navigator.getDisplayMedia.bind(r.navigator)))}function Ws(r,e){if(r.RTCIceGatherer&&(r.RTCIceCandidate||(r.RTCIceCandidate=function(n){return n}),r.RTCSessionDescription||(r.RTCSessionDescription=function(n){return n}),e.version<15025)){const n=Object.getOwnPropertyDescriptor(r.MediaStreamTrack.prototype,"enabled");Object.defineProperty(r.MediaStreamTrack.prototype,"enabled",{set(i){n.set.call(this,i);const s=new Event("enabled");s.enabled=i,this.dispatchEvent(s)}})}r.RTCRtpSender&&!("dtmf"in r.RTCRtpSender.prototype)&&Object.defineProperty(r.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=new r.RTCDtmfSender(this):this.track.kind==="video"&&(this._dtmf=null)),this._dtmf}}),r.RTCDtmfSender&&!r.RTCDTMFSender&&(r.RTCDTMFSender=r.RTCDtmfSender);const t=ld(r,e.version);r.RTCPeerConnection=function(n){return n&&n.iceServers&&(n.iceServers=od(n.iceServers,e.version),Vs("ICE servers after filtering:",n.iceServers)),new t(n)},r.RTCPeerConnection.prototype=t.prototype}function mc(r){r.RTCRtpSender&&!("replaceTrack"in r.RTCRtpSender.prototype)&&(r.RTCRtpSender.prototype.replaceTrack=r.RTCRtpSender.prototype.setTrack)}const yc=Object.freeze(Object.defineProperty({__proto__:null,shimGetDisplayMedia:fc,shimGetUserMedia:pc,shimPeerConnection:Ws,shimReplaceTrack:mc},Symbol.toStringTag,{value:"Module"}));function gc(r,e){const t=r&&r.navigator,n=r&&r.MediaStreamTrack;if(t.getUserMedia=function(i,s,a){_r("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),t.mediaDevices.getUserMedia(i).then(s,a)},!(e.version>55&&"autoGainControl"in t.mediaDevices.getSupportedConstraints())){const i=function(a,o,c){o in a&&!(c in a)&&(a[c]=a[o],delete a[o])},s=t.mediaDevices.getUserMedia.bind(t.mediaDevices);if(Object.getOwnPropertyDescriptor(t.mediaDevices,"getUserMedia")?.writable&&(t.mediaDevices.getUserMedia=function(a){return typeof a=="object"&&typeof a.audio=="object"&&(a=JSON.parse(JSON.stringify(a)),i(a.audio,"autoGainControl","mozAutoGainControl"),i(a.audio,"noiseSuppression","mozNoiseSuppression")),s(a)}),n&&n.prototype.getSettings){const a=n.prototype.getSettings;n.prototype.getSettings=function(){const o=a.apply(this,arguments);return i(o,"mozAutoGainControl","autoGainControl"),i(o,"mozNoiseSuppression","noiseSuppression"),o}}if(n&&n.prototype.applyConstraints){const a=n.prototype.applyConstraints;n.prototype.applyConstraints=function(o){return this.kind==="audio"&&typeof o=="object"&&(o=JSON.parse(JSON.stringify(o)),i(o,"autoGainControl","mozAutoGainControl"),i(o,"noiseSuppression","mozNoiseSuppression")),a.apply(this,[o])}}}}function ud(r,e){r.navigator.mediaDevices&&"getDisplayMedia"in r.navigator.mediaDevices||r.navigator.mediaDevices&&(r.navigator.mediaDevices.getDisplayMedia=function(t){if(!(t&&t.video)){const n=new DOMException("getDisplayMedia without video constraints is undefined");return n.name="NotFoundError",n.code=8,Promise.reject(n)}return t.video===!0?t.video={mediaSource:e}:t.video.mediaSource=e,r.navigator.mediaDevices.getUserMedia(t)})}function vc(r){typeof r=="object"&&r.RTCTrackEvent&&"receiver"in r.RTCTrackEvent.prototype&&!("transceiver"in r.RTCTrackEvent.prototype)&&Object.defineProperty(r.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Hs(r,e){if(typeof r!="object"||!(r.RTCPeerConnection||r.mozRTCPeerConnection))return;!r.RTCPeerConnection&&r.mozRTCPeerConnection&&(r.RTCPeerConnection=r.mozRTCPeerConnection),e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(i){const s=r.RTCPeerConnection.prototype[i],a={[i](){return arguments[0]=new(i==="addIceCandidate"?r.RTCIceCandidate:r.RTCSessionDescription)(arguments[0]),s.apply(this,arguments)}};r.RTCPeerConnection.prototype[i]=a[i]});const t={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},n=r.RTCPeerConnection.prototype.getStats;r.RTCPeerConnection.prototype.getStats=function(){const[i,s,a]=arguments;return n.apply(this,[i||null]).then(o=>{if(e.version<53&&!s)try{o.forEach(c=>{c.type=t[c.type]||c.type})}catch(c){if(c.name!=="TypeError")throw c;o.forEach((l,u)=>{o.set(u,Object.assign({},l,{type:t[l.type]||l.type}))})}return o}).then(s,a)}}function Sc(r){if(!(typeof r=="object"&&r.RTCPeerConnection&&r.RTCRtpSender)||r.RTCRtpSender&&"getStats"in r.RTCRtpSender.prototype)return;const e=r.RTCPeerConnection.prototype.getSenders;e&&(r.RTCPeerConnection.prototype.getSenders=function(){const n=e.apply(this,[]);return n.forEach(i=>i._pc=this),n});const t=r.RTCPeerConnection.prototype.addTrack;t&&(r.RTCPeerConnection.prototype.addTrack=function(){const n=t.apply(this,arguments);return n._pc=this,n}),r.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function bc(r){if(!(typeof r=="object"&&r.RTCPeerConnection&&r.RTCRtpSender)||r.RTCRtpSender&&"getStats"in r.RTCRtpReceiver.prototype)return;const e=r.RTCPeerConnection.prototype.getReceivers;e&&(r.RTCPeerConnection.prototype.getReceivers=function(){const t=e.apply(this,[]);return t.forEach(n=>n._pc=this),t}),Un(r,"track",t=>(t.receiver._pc=t.srcElement,t)),r.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function xc(r){!r.RTCPeerConnection||"removeStream"in r.RTCPeerConnection.prototype||(r.RTCPeerConnection.prototype.removeStream=function(e){_r("removeStream","removeTrack"),this.getSenders().forEach(t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)})})}function wc(r){r.DataChannel&&!r.RTCDataChannel&&(r.RTCDataChannel=r.DataChannel)}function _c(r){if(!(typeof r=="object"&&r.RTCPeerConnection))return;const e=r.RTCPeerConnection.prototype.addTransceiver;e&&(r.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const t=arguments[1],n=t&&"sendEncodings"in t;n&&t.sendEncodings.forEach(s=>{if("rid"in s&&!/^[a-z0-9]{0,16}$/i.test(s.rid))throw new TypeError("Invalid RID value provided.");if("scaleResolutionDownBy"in s&&!(parseFloat(s.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in s&&!(parseFloat(s.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")});const i=e.apply(this,arguments);if(n){const{sender:s}=i,a=s.getParameters();(!("encodings"in a)||a.encodings.length===1&&Object.keys(a.encodings[0]).length===0)&&(a.encodings=t.sendEncodings,s.sendEncodings=t.sendEncodings,this.setParametersPromises.push(s.setParameters(a).then(()=>{delete s.sendEncodings}).catch(()=>{delete s.sendEncodings})))}return i})}function Tc(r){if(!(typeof r=="object"&&r.RTCRtpSender))return;const e=r.RTCRtpSender.prototype.getParameters;e&&(r.RTCRtpSender.prototype.getParameters=function(){const t=e.apply(this,arguments);return"encodings"in t||(t.encodings=[].concat(this.sendEncodings||[{}])),t})}function Mc(r){if(!(typeof r=="object"&&r.RTCPeerConnection))return;const e=r.RTCPeerConnection.prototype.createOffer;r.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>e.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):e.apply(this,arguments)}}function Cc(r){if(!(typeof r=="object"&&r.RTCPeerConnection))return;const e=r.RTCPeerConnection.prototype.createAnswer;r.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>e.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):e.apply(this,arguments)}}const Pc=Object.freeze(Object.defineProperty({__proto__:null,shimAddTransceiver:_c,shimCreateAnswer:Cc,shimCreateOffer:Mc,shimGetDisplayMedia:ud,shimGetParameters:Tc,shimGetUserMedia:gc,shimOnTrack:vc,shimPeerConnection:Hs,shimRTCDataChannel:wc,shimReceiverGetStats:bc,shimRemoveStream:xc,shimSenderGetStats:Sc},Symbol.toStringTag,{value:"Module"}));function Ec(r){if(!(typeof r!="object"||!r.RTCPeerConnection)){if("getLocalStreams"in r.RTCPeerConnection.prototype||(r.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in r.RTCPeerConnection.prototype)){const e=r.RTCPeerConnection.prototype.addTrack;r.RTCPeerConnection.prototype.addStream=function(t){this._localStreams||(this._localStreams=[]),this._localStreams.includes(t)||this._localStreams.push(t),t.getAudioTracks().forEach(n=>e.call(this,n,t)),t.getVideoTracks().forEach(n=>e.call(this,n,t))},r.RTCPeerConnection.prototype.addTrack=function(t,...n){return n&&n.forEach(i=>{this._localStreams?this._localStreams.includes(i)||this._localStreams.push(i):this._localStreams=[i]}),e.apply(this,arguments)}}"removeStream"in r.RTCPeerConnection.prototype||(r.RTCPeerConnection.prototype.removeStream=function(e){this._localStreams||(this._localStreams=[]);const t=this._localStreams.indexOf(e);if(t===-1)return;this._localStreams.splice(t,1);const n=e.getTracks();this.getSenders().forEach(i=>{n.includes(i.track)&&this.removeTrack(i)})})}}function kc(r){if(!(typeof r!="object"||!r.RTCPeerConnection)&&("getRemoteStreams"in r.RTCPeerConnection.prototype||(r.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in r.RTCPeerConnection.prototype))){Object.defineProperty(r.RTCPeerConnection.prototype,"onaddstream",{get(){return this._onaddstream},set(t){this._onaddstream&&(this.removeEventListener("addstream",this._onaddstream),this.removeEventListener("track",this._onaddstreampoly)),this.addEventListener("addstream",this._onaddstream=t),this.addEventListener("track",this._onaddstreampoly=n=>{n.streams.forEach(i=>{if(this._remoteStreams||(this._remoteStreams=[]),this._remoteStreams.includes(i))return;this._remoteStreams.push(i);const s=new Event("addstream");s.stream=i,this.dispatchEvent(s)})})}});const e=r.RTCPeerConnection.prototype.setRemoteDescription;r.RTCPeerConnection.prototype.setRemoteDescription=function(){const t=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(n){n.streams.forEach(i=>{if(t._remoteStreams||(t._remoteStreams=[]),t._remoteStreams.indexOf(i)>=0)return;t._remoteStreams.push(i);const s=new Event("addstream");s.stream=i,t.dispatchEvent(s)})}),e.apply(t,arguments)}}}function Rc(r){if(typeof r!="object"||!r.RTCPeerConnection)return;const e=r.RTCPeerConnection.prototype,t=e.createOffer,n=e.createAnswer,i=e.setLocalDescription,s=e.setRemoteDescription,a=e.addIceCandidate;e.createOffer=function(c,l){const u=arguments.length>=2?arguments[2]:arguments[0],d=t.apply(this,[u]);return l?(d.then(c,l),Promise.resolve()):d},e.createAnswer=function(c,l){const u=arguments.length>=2?arguments[2]:arguments[0],d=n.apply(this,[u]);return l?(d.then(c,l),Promise.resolve()):d};let o=function(c,l,u){const d=i.apply(this,[c]);return u?(d.then(l,u),Promise.resolve()):d};e.setLocalDescription=o,o=function(c,l,u){const d=s.apply(this,[c]);return u?(d.then(l,u),Promise.resolve()):d},e.setRemoteDescription=o,o=function(c,l,u){const d=a.apply(this,[c]);return u?(d.then(l,u),Promise.resolve()):d},e.addIceCandidate=o}function Ac(r){const e=r&&r.navigator;if(e.mediaDevices&&e.mediaDevices.getUserMedia){const t=e.mediaDevices,n=t.getUserMedia.bind(t);e.mediaDevices.getUserMedia=i=>n(Oc(i))}!e.getUserMedia&&e.mediaDevices&&e.mediaDevices.getUserMedia&&(e.getUserMedia=function(t,n,i){e.mediaDevices.getUserMedia(t).then(n,i)}.bind(e))}function Oc(r){return r&&r.video!==void 0?Object.assign({},r,{video:Za(r.video)}):r}function Ic(r){if(!r.RTCPeerConnection)return;const e=r.RTCPeerConnection;r.RTCPeerConnection=function(t,n){if(t&&t.iceServers){const i=[];for(let s=0;s<t.iceServers.length;s++){let a=t.iceServers[s];!a.hasOwnProperty("urls")&&a.hasOwnProperty("url")?(_r("RTCIceServer.url","RTCIceServer.urls"),a=JSON.parse(JSON.stringify(a)),a.urls=a.url,delete a.url,i.push(a)):i.push(t.iceServers[s])}t.iceServers=i}return new e(t,n)},r.RTCPeerConnection.prototype=e.prototype,"generateCertificate"in e&&Object.defineProperty(r.RTCPeerConnection,"generateCertificate",{get(){return e.generateCertificate}})}function Bc(r){typeof r=="object"&&r.RTCTrackEvent&&"receiver"in r.RTCTrackEvent.prototype&&!("transceiver"in r.RTCTrackEvent.prototype)&&Object.defineProperty(r.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function zc(r){const e=r.RTCPeerConnection.prototype.createOffer;r.RTCPeerConnection.prototype.createOffer=function(t){if(t){typeof t.offerToReceiveAudio<"u"&&(t.offerToReceiveAudio=!!t.offerToReceiveAudio);const n=this.getTransceivers().find(s=>s.receiver.track.kind==="audio");t.offerToReceiveAudio===!1&&n?n.direction==="sendrecv"?n.setDirection?n.setDirection("sendonly"):n.direction="sendonly":n.direction==="recvonly"&&(n.setDirection?n.setDirection("inactive"):n.direction="inactive"):t.offerToReceiveAudio===!0&&!n&&this.addTransceiver("audio"),typeof t.offerToReceiveVideo<"u"&&(t.offerToReceiveVideo=!!t.offerToReceiveVideo);const i=this.getTransceivers().find(s=>s.receiver.track.kind==="video");t.offerToReceiveVideo===!1&&i?i.direction==="sendrecv"?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":i.direction==="recvonly"&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):t.offerToReceiveVideo===!0&&!i&&this.addTransceiver("video")}return e.apply(this,arguments)}}function Nc(r){typeof r!="object"||r.AudioContext||(r.AudioContext=r.webkitAudioContext)}const Uc=Object.freeze(Object.defineProperty({__proto__:null,shimAudioContext:Nc,shimCallbacksAPI:Rc,shimConstraints:Oc,shimCreateOfferLegacy:zc,shimGetUserMedia:Ac,shimLocalStreamsAPI:Ec,shimRTCIceServerUrls:Ic,shimRemoteStreamsAPI:kc,shimTrackEventTransceiver:Bc},Symbol.toStringTag,{value:"Module"}));var hd=hc();const Tr=ur(hd);function Mr(r){if(!r.RTCIceCandidate||r.RTCIceCandidate&&"foundation"in r.RTCIceCandidate.prototype)return;const e=r.RTCIceCandidate;r.RTCIceCandidate=function(t){if(typeof t=="object"&&t.candidate&&t.candidate.indexOf("a=")===0&&(t=JSON.parse(JSON.stringify(t)),t.candidate=t.candidate.substr(2)),t.candidate&&t.candidate.length){const n=new e(t),i=Tr.parseCandidate(t.candidate),s=Object.assign(n,i);return s.toJSON=function(){return{candidate:s.candidate,sdpMid:s.sdpMid,sdpMLineIndex:s.sdpMLineIndex,usernameFragment:s.usernameFragment}},s}return new e(t)},r.RTCIceCandidate.prototype=e.prototype,Un(r,"icecandidate",t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new r.RTCIceCandidate(t.candidate),writable:"false"}),t))}function ai(r,e){if(!r.RTCPeerConnection)return;"sctp"in r.RTCPeerConnection.prototype||Object.defineProperty(r.RTCPeerConnection.prototype,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp}});const t=function(o){if(!o||!o.sdp)return!1;const c=Tr.splitSections(o.sdp);return c.shift(),c.some(l=>{const u=Tr.parseMLine(l);return u&&u.kind==="application"&&u.protocol.indexOf("SCTP")!==-1})},n=function(o){const c=o.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(c===null||c.length<2)return-1;const l=parseInt(c[1],10);return l!==l?-1:l},i=function(o){let c=65536;return e.browser==="firefox"&&(e.version<57?o===-1?c=16384:c=2147483637:e.version<60?c=e.version===57?65535:65536:c=2147483637),c},s=function(o,c){let l=65536;e.browser==="firefox"&&e.version===57&&(l=65535);const u=Tr.matchPrefix(o.sdp,"a=max-message-size:");return u.length>0?l=parseInt(u[0].substr(19),10):e.browser==="firefox"&&c!==-1&&(l=2147483637),l},a=r.RTCPeerConnection.prototype.setRemoteDescription;r.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,e.browser==="chrome"&&e.version>=76){const{sdpSemantics:o}=this.getConfiguration();o==="plan-b"&&Object.defineProperty(this,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp},enumerable:!0,configurable:!0})}if(t(arguments[0])){const o=n(arguments[0]),c=i(o),l=s(arguments[0],o);let u;c===0&&l===0?u=Number.POSITIVE_INFINITY:c===0||l===0?u=Math.max(c,l):u=Math.min(c,l);const d={};Object.defineProperty(d,"maxMessageSize",{get(){return u}}),this._sctp=d}return a.apply(this,arguments)}}function ci(r){if(!(r.RTCPeerConnection&&"createDataChannel"in r.RTCPeerConnection.prototype))return;function e(n,i){const s=n.send;n.send=function(){const a=arguments[0],o=a.length||a.size||a.byteLength;if(n.readyState==="open"&&i.sctp&&o>i.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+i.sctp.maxMessageSize+" bytes)");return s.apply(n,arguments)}}const t=r.RTCPeerConnection.prototype.createDataChannel;r.RTCPeerConnection.prototype.createDataChannel=function(){const n=t.apply(this,arguments);return e(n,this),n},Un(r,"datachannel",n=>(e(n.channel,n.target),n))}function qs(r){if(!r.RTCPeerConnection||"connectionState"in r.RTCPeerConnection.prototype)return;const e=r.RTCPeerConnection.prototype;Object.defineProperty(e,"connectionState",{get(){return{completed:"connected",checking:"connecting"}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(e,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(t){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),t&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=t)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach(t=>{const n=e[t];e[t]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=i=>{const s=i.target;if(s._lastConnectionState!==s.connectionState){s._lastConnectionState=s.connectionState;const a=new Event("connectionstatechange",i);s.dispatchEvent(a)}return i},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),n.apply(this,arguments)}})}function Xs(r,e){if(!r.RTCPeerConnection||e.browser==="chrome"&&e.version>=71||e.browser==="safari"&&e.version>=605)return;const t=r.RTCPeerConnection.prototype.setRemoteDescription;r.RTCPeerConnection.prototype.setRemoteDescription=function(n){if(n&&n.sdp&&n.sdp.indexOf(`
1105
+ `)}});var S=new c.RTCSessionDescription({type:"answer",sdp:v});return Promise.resolve(S)},f.prototype.addIceCandidate=function(g){var v=this,w;return g&&!(g.sdpMLineIndex!==void 0||g.sdpMid)?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise(function(S,T){if(v._remoteDescription)if(!g||g.candidate==="")for(var C=0;C<v.transceivers.length&&!(!v.transceivers[C].rejected&&(v.transceivers[C].iceTransport.addRemoteCandidate({}),w=r.getMediaSections(v._remoteDescription.sdp),w[C]+=`a=end-of-candidates\r
1106
+ `,v._remoteDescription.sdp=r.getDescription(v._remoteDescription.sdp)+w.join(""),v.usingBundle));C++);else{var P=g.sdpMLineIndex;if(g.sdpMid){for(var E=0;E<v.transceivers.length;E++)if(v.transceivers[E].mid===g.sdpMid){P=E;break}}var O=v.transceivers[P];if(O){if(O.rejected)return S();var A=Object.keys(g.candidate).length>0?r.parseCandidate(g.candidate):{};if(A.protocol==="tcp"&&(A.port===0||A.port===9)||A.component&&A.component!==1)return S();if((P===0||P>0&&O.iceTransport!==v.transceivers[0].iceTransport)&&!a(O.iceTransport,A))return T(o("OperationError","Can not add ICE candidate"));var R=g.candidate.trim();R.indexOf("a=")===0&&(R=R.substr(2)),w=r.getMediaSections(v._remoteDescription.sdp),w[P]+="a="+(A.type?R:"end-of-candidates")+`\r
1107
+ `,v._remoteDescription.sdp=r.getDescription(v._remoteDescription.sdp)+w.join("")}else return T(o("OperationError","Can not add ICE candidate"))}else return T(o("InvalidStateError","Can not add ICE candidate without a remote description"));S()})},f.prototype.getStats=function(g){if(g&&g instanceof c.MediaStreamTrack){var v=null;if(this.transceivers.forEach(function(S){S.rtpSender&&S.rtpSender.track===g?v=S.rtpSender:S.rtpReceiver&&S.rtpReceiver.track===g&&(v=S.rtpReceiver)}),!v)throw o("InvalidAccessError","Invalid selector.");return v.getStats()}var w=[];return this.transceivers.forEach(function(S){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(T){S[T]&&w.push(S[T].getStats())})}),Promise.all(w).then(function(S){var T=new Map;return S.forEach(function(C){C.forEach(function(P){T.set(P.id,P)})}),T})};var x=["RTCRtpSender","RTCRtpReceiver","RTCIceGatherer","RTCIceTransport","RTCDtlsTransport"];x.forEach(function(g){var v=c[g];if(v&&v.prototype&&v.prototype.getStats){var w=v.prototype.getStats;v.prototype.getStats=function(){return w.apply(this).then(function(S){var T=new Map;return Object.keys(S).forEach(function(C){S[C].type=e(S[C]),T.set(C,S[C])}),T})}}});var _=["createOffer","createAnswer"];return _.forEach(function(g){var v=f.prototype[g];f.prototype[g]=function(){var w=arguments;return typeof w[0]=="function"||typeof w[1]=="function"?v.apply(this,[arguments[2]]).then(function(S){typeof w[0]=="function"&&w[0].apply(null,[S])},function(S){typeof w[1]=="function"&&w[1].apply(null,[S])}):v.apply(this,arguments)}}),_=["setLocalDescription","setRemoteDescription","addIceCandidate"],_.forEach(function(g){var v=f.prototype[g];f.prototype[g]=function(){var w=arguments;return typeof w[1]=="function"||typeof w[2]=="function"?v.apply(this,arguments).then(function(){typeof w[1]=="function"&&w[1].apply(null)},function(S){typeof w[2]=="function"&&w[2].apply(null,[S])}):v.apply(this,arguments)}}),["getStats"].forEach(function(g){var v=f.prototype[g];f.prototype[g]=function(){var w=arguments;return typeof w[1]=="function"?v.apply(this,arguments).then(function(){typeof w[1]=="function"&&w[1].apply(null)}):v.apply(this,arguments)}}),f},Ws}var ld=cd();const hd=hr(ld);function pc(r){const e=r&&r.navigator,t=function(i){return{name:{PermissionDeniedError:"NotAllowedError"}[i.name]||i.name,message:i.message,constraint:i.constraint,toString(){return this.name}}},n=e.mediaDevices.getUserMedia.bind(e.mediaDevices);Object.getOwnPropertyDescriptor(e.mediaDevices,"getUserMedia")?.writable&&(e.mediaDevices.getUserMedia=function(i){return n(i).catch(s=>Promise.reject(t(s)))})}function fc(r){"getDisplayMedia"in r.navigator&&r.navigator.mediaDevices&&(r.navigator.mediaDevices&&"getDisplayMedia"in r.navigator.mediaDevices||(r.navigator.mediaDevices.getDisplayMedia=r.navigator.getDisplayMedia.bind(r.navigator)))}function Hs(r,e){if(r.RTCIceGatherer&&(r.RTCIceCandidate||(r.RTCIceCandidate=function(n){return n}),r.RTCSessionDescription||(r.RTCSessionDescription=function(n){return n}),e.version<15025)){const n=Object.getOwnPropertyDescriptor(r.MediaStreamTrack.prototype,"enabled");Object.defineProperty(r.MediaStreamTrack.prototype,"enabled",{set(i){n.set.call(this,i);const s=new Event("enabled");s.enabled=i,this.dispatchEvent(s)}})}r.RTCRtpSender&&!("dtmf"in r.RTCRtpSender.prototype)&&Object.defineProperty(r.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=new r.RTCDtmfSender(this):this.track.kind==="video"&&(this._dtmf=null)),this._dtmf}}),r.RTCDtmfSender&&!r.RTCDTMFSender&&(r.RTCDTMFSender=r.RTCDtmfSender);const t=hd(r,e.version);r.RTCPeerConnection=function(n){return n&&n.iceServers&&(n.iceServers=ad(n.iceServers,e.version),js("ICE servers after filtering:",n.iceServers)),new t(n)},r.RTCPeerConnection.prototype=t.prototype}function mc(r){r.RTCRtpSender&&!("replaceTrack"in r.RTCRtpSender.prototype)&&(r.RTCRtpSender.prototype.replaceTrack=r.RTCRtpSender.prototype.setTrack)}const yc=Object.freeze(Object.defineProperty({__proto__:null,shimGetDisplayMedia:fc,shimGetUserMedia:pc,shimPeerConnection:Hs,shimReplaceTrack:mc},Symbol.toStringTag,{value:"Module"}));function gc(r,e){const t=r&&r.navigator,n=r&&r.MediaStreamTrack;if(t.getUserMedia=function(i,s,a){Tr("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),t.mediaDevices.getUserMedia(i).then(s,a)},!(e.version>55&&"autoGainControl"in t.mediaDevices.getSupportedConstraints())){const i=function(a,o,c){o in a&&!(c in a)&&(a[c]=a[o],delete a[o])},s=t.mediaDevices.getUserMedia.bind(t.mediaDevices);if(Object.getOwnPropertyDescriptor(t.mediaDevices,"getUserMedia")?.writable&&(t.mediaDevices.getUserMedia=function(a){return typeof a=="object"&&typeof a.audio=="object"&&(a=JSON.parse(JSON.stringify(a)),i(a.audio,"autoGainControl","mozAutoGainControl"),i(a.audio,"noiseSuppression","mozNoiseSuppression")),s(a)}),n&&n.prototype.getSettings){const a=n.prototype.getSettings;n.prototype.getSettings=function(){const o=a.apply(this,arguments);return i(o,"mozAutoGainControl","autoGainControl"),i(o,"mozNoiseSuppression","noiseSuppression"),o}}if(n&&n.prototype.applyConstraints){const a=n.prototype.applyConstraints;n.prototype.applyConstraints=function(o){return this.kind==="audio"&&typeof o=="object"&&(o=JSON.parse(JSON.stringify(o)),i(o,"autoGainControl","mozAutoGainControl"),i(o,"noiseSuppression","mozNoiseSuppression")),a.apply(this,[o])}}}}function ud(r,e){r.navigator.mediaDevices&&"getDisplayMedia"in r.navigator.mediaDevices||r.navigator.mediaDevices&&(r.navigator.mediaDevices.getDisplayMedia=function(t){if(!(t&&t.video)){const n=new DOMException("getDisplayMedia without video constraints is undefined");return n.name="NotFoundError",n.code=8,Promise.reject(n)}return t.video===!0?t.video={mediaSource:e}:t.video.mediaSource=e,r.navigator.mediaDevices.getUserMedia(t)})}function vc(r){typeof r=="object"&&r.RTCTrackEvent&&"receiver"in r.RTCTrackEvent.prototype&&!("transceiver"in r.RTCTrackEvent.prototype)&&Object.defineProperty(r.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function qs(r,e){if(typeof r!="object"||!(r.RTCPeerConnection||r.mozRTCPeerConnection))return;!r.RTCPeerConnection&&r.mozRTCPeerConnection&&(r.RTCPeerConnection=r.mozRTCPeerConnection),e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(i){const s=r.RTCPeerConnection.prototype[i],a={[i](){return arguments[0]=new(i==="addIceCandidate"?r.RTCIceCandidate:r.RTCSessionDescription)(arguments[0]),s.apply(this,arguments)}};r.RTCPeerConnection.prototype[i]=a[i]});const t={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},n=r.RTCPeerConnection.prototype.getStats;r.RTCPeerConnection.prototype.getStats=function(){const[i,s,a]=arguments;return n.apply(this,[i||null]).then(o=>{if(e.version<53&&!s)try{o.forEach(c=>{c.type=t[c.type]||c.type})}catch(c){if(c.name!=="TypeError")throw c;o.forEach((l,u)=>{o.set(u,Object.assign({},l,{type:t[l.type]||l.type}))})}return o}).then(s,a)}}function Sc(r){if(!(typeof r=="object"&&r.RTCPeerConnection&&r.RTCRtpSender)||r.RTCRtpSender&&"getStats"in r.RTCRtpSender.prototype)return;const e=r.RTCPeerConnection.prototype.getSenders;e&&(r.RTCPeerConnection.prototype.getSenders=function(){const n=e.apply(this,[]);return n.forEach(i=>i._pc=this),n});const t=r.RTCPeerConnection.prototype.addTrack;t&&(r.RTCPeerConnection.prototype.addTrack=function(){const n=t.apply(this,arguments);return n._pc=this,n}),r.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function bc(r){if(!(typeof r=="object"&&r.RTCPeerConnection&&r.RTCRtpSender)||r.RTCRtpSender&&"getStats"in r.RTCRtpReceiver.prototype)return;const e=r.RTCPeerConnection.prototype.getReceivers;e&&(r.RTCPeerConnection.prototype.getReceivers=function(){const t=e.apply(this,[]);return t.forEach(n=>n._pc=this),t}),Un(r,"track",t=>(t.receiver._pc=t.srcElement,t)),r.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function xc(r){!r.RTCPeerConnection||"removeStream"in r.RTCPeerConnection.prototype||(r.RTCPeerConnection.prototype.removeStream=function(e){Tr("removeStream","removeTrack"),this.getSenders().forEach(t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)})})}function wc(r){r.DataChannel&&!r.RTCDataChannel&&(r.RTCDataChannel=r.DataChannel)}function _c(r){if(!(typeof r=="object"&&r.RTCPeerConnection))return;const e=r.RTCPeerConnection.prototype.addTransceiver;e&&(r.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const t=arguments[1],n=t&&"sendEncodings"in t;n&&t.sendEncodings.forEach(s=>{if("rid"in s&&!/^[a-z0-9]{0,16}$/i.test(s.rid))throw new TypeError("Invalid RID value provided.");if("scaleResolutionDownBy"in s&&!(parseFloat(s.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in s&&!(parseFloat(s.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")});const i=e.apply(this,arguments);if(n){const{sender:s}=i,a=s.getParameters();(!("encodings"in a)||a.encodings.length===1&&Object.keys(a.encodings[0]).length===0)&&(a.encodings=t.sendEncodings,s.sendEncodings=t.sendEncodings,this.setParametersPromises.push(s.setParameters(a).then(()=>{delete s.sendEncodings}).catch(()=>{delete s.sendEncodings})))}return i})}function Tc(r){if(!(typeof r=="object"&&r.RTCRtpSender))return;const e=r.RTCRtpSender.prototype.getParameters;e&&(r.RTCRtpSender.prototype.getParameters=function(){const t=e.apply(this,arguments);return"encodings"in t||(t.encodings=[].concat(this.sendEncodings||[{}])),t})}function Mc(r){if(!(typeof r=="object"&&r.RTCPeerConnection))return;const e=r.RTCPeerConnection.prototype.createOffer;r.RTCPeerConnection.prototype.createOffer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>e.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):e.apply(this,arguments)}}function Cc(r){if(!(typeof r=="object"&&r.RTCPeerConnection))return;const e=r.RTCPeerConnection.prototype.createAnswer;r.RTCPeerConnection.prototype.createAnswer=function(){return this.setParametersPromises&&this.setParametersPromises.length?Promise.all(this.setParametersPromises).then(()=>e.apply(this,arguments)).finally(()=>{this.setParametersPromises=[]}):e.apply(this,arguments)}}const Pc=Object.freeze(Object.defineProperty({__proto__:null,shimAddTransceiver:_c,shimCreateAnswer:Cc,shimCreateOffer:Mc,shimGetDisplayMedia:ud,shimGetParameters:Tc,shimGetUserMedia:gc,shimOnTrack:vc,shimPeerConnection:qs,shimRTCDataChannel:wc,shimReceiverGetStats:bc,shimRemoveStream:xc,shimSenderGetStats:Sc},Symbol.toStringTag,{value:"Module"}));function Ec(r){if(!(typeof r!="object"||!r.RTCPeerConnection)){if("getLocalStreams"in r.RTCPeerConnection.prototype||(r.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in r.RTCPeerConnection.prototype)){const e=r.RTCPeerConnection.prototype.addTrack;r.RTCPeerConnection.prototype.addStream=function(t){this._localStreams||(this._localStreams=[]),this._localStreams.includes(t)||this._localStreams.push(t),t.getAudioTracks().forEach(n=>e.call(this,n,t)),t.getVideoTracks().forEach(n=>e.call(this,n,t))},r.RTCPeerConnection.prototype.addTrack=function(t,...n){return n&&n.forEach(i=>{this._localStreams?this._localStreams.includes(i)||this._localStreams.push(i):this._localStreams=[i]}),e.apply(this,arguments)}}"removeStream"in r.RTCPeerConnection.prototype||(r.RTCPeerConnection.prototype.removeStream=function(e){this._localStreams||(this._localStreams=[]);const t=this._localStreams.indexOf(e);if(t===-1)return;this._localStreams.splice(t,1);const n=e.getTracks();this.getSenders().forEach(i=>{n.includes(i.track)&&this.removeTrack(i)})})}}function kc(r){if(!(typeof r!="object"||!r.RTCPeerConnection)&&("getRemoteStreams"in r.RTCPeerConnection.prototype||(r.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in r.RTCPeerConnection.prototype))){Object.defineProperty(r.RTCPeerConnection.prototype,"onaddstream",{get(){return this._onaddstream},set(t){this._onaddstream&&(this.removeEventListener("addstream",this._onaddstream),this.removeEventListener("track",this._onaddstreampoly)),this.addEventListener("addstream",this._onaddstream=t),this.addEventListener("track",this._onaddstreampoly=n=>{n.streams.forEach(i=>{if(this._remoteStreams||(this._remoteStreams=[]),this._remoteStreams.includes(i))return;this._remoteStreams.push(i);const s=new Event("addstream");s.stream=i,this.dispatchEvent(s)})})}});const e=r.RTCPeerConnection.prototype.setRemoteDescription;r.RTCPeerConnection.prototype.setRemoteDescription=function(){const t=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(n){n.streams.forEach(i=>{if(t._remoteStreams||(t._remoteStreams=[]),t._remoteStreams.indexOf(i)>=0)return;t._remoteStreams.push(i);const s=new Event("addstream");s.stream=i,t.dispatchEvent(s)})}),e.apply(t,arguments)}}}function Rc(r){if(typeof r!="object"||!r.RTCPeerConnection)return;const e=r.RTCPeerConnection.prototype,t=e.createOffer,n=e.createAnswer,i=e.setLocalDescription,s=e.setRemoteDescription,a=e.addIceCandidate;e.createOffer=function(c,l){const u=arguments.length>=2?arguments[2]:arguments[0],d=t.apply(this,[u]);return l?(d.then(c,l),Promise.resolve()):d},e.createAnswer=function(c,l){const u=arguments.length>=2?arguments[2]:arguments[0],d=n.apply(this,[u]);return l?(d.then(c,l),Promise.resolve()):d};let o=function(c,l,u){const d=i.apply(this,[c]);return u?(d.then(l,u),Promise.resolve()):d};e.setLocalDescription=o,o=function(c,l,u){const d=s.apply(this,[c]);return u?(d.then(l,u),Promise.resolve()):d},e.setRemoteDescription=o,o=function(c,l,u){const d=a.apply(this,[c]);return u?(d.then(l,u),Promise.resolve()):d},e.addIceCandidate=o}function Ac(r){const e=r&&r.navigator;if(e.mediaDevices&&e.mediaDevices.getUserMedia){const t=e.mediaDevices,n=t.getUserMedia.bind(t);e.mediaDevices.getUserMedia=i=>n(Oc(i))}!e.getUserMedia&&e.mediaDevices&&e.mediaDevices.getUserMedia&&(e.getUserMedia=function(t,n,i){e.mediaDevices.getUserMedia(t).then(n,i)}.bind(e))}function Oc(r){return r&&r.video!==void 0?Object.assign({},r,{video:Za(r.video)}):r}function Ic(r){if(!r.RTCPeerConnection)return;const e=r.RTCPeerConnection;r.RTCPeerConnection=function(t,n){if(t&&t.iceServers){const i=[];for(let s=0;s<t.iceServers.length;s++){let a=t.iceServers[s];!a.hasOwnProperty("urls")&&a.hasOwnProperty("url")?(Tr("RTCIceServer.url","RTCIceServer.urls"),a=JSON.parse(JSON.stringify(a)),a.urls=a.url,delete a.url,i.push(a)):i.push(t.iceServers[s])}t.iceServers=i}return new e(t,n)},r.RTCPeerConnection.prototype=e.prototype,"generateCertificate"in e&&Object.defineProperty(r.RTCPeerConnection,"generateCertificate",{get(){return e.generateCertificate}})}function Bc(r){typeof r=="object"&&r.RTCTrackEvent&&"receiver"in r.RTCTrackEvent.prototype&&!("transceiver"in r.RTCTrackEvent.prototype)&&Object.defineProperty(r.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function zc(r){const e=r.RTCPeerConnection.prototype.createOffer;r.RTCPeerConnection.prototype.createOffer=function(t){if(t){typeof t.offerToReceiveAudio<"u"&&(t.offerToReceiveAudio=!!t.offerToReceiveAudio);const n=this.getTransceivers().find(s=>s.receiver.track.kind==="audio");t.offerToReceiveAudio===!1&&n?n.direction==="sendrecv"?n.setDirection?n.setDirection("sendonly"):n.direction="sendonly":n.direction==="recvonly"&&(n.setDirection?n.setDirection("inactive"):n.direction="inactive"):t.offerToReceiveAudio===!0&&!n&&this.addTransceiver("audio"),typeof t.offerToReceiveVideo<"u"&&(t.offerToReceiveVideo=!!t.offerToReceiveVideo);const i=this.getTransceivers().find(s=>s.receiver.track.kind==="video");t.offerToReceiveVideo===!1&&i?i.direction==="sendrecv"?i.setDirection?i.setDirection("sendonly"):i.direction="sendonly":i.direction==="recvonly"&&(i.setDirection?i.setDirection("inactive"):i.direction="inactive"):t.offerToReceiveVideo===!0&&!i&&this.addTransceiver("video")}return e.apply(this,arguments)}}function Nc(r){typeof r!="object"||r.AudioContext||(r.AudioContext=r.webkitAudioContext)}const Uc=Object.freeze(Object.defineProperty({__proto__:null,shimAudioContext:Nc,shimCallbacksAPI:Rc,shimConstraints:Oc,shimCreateOfferLegacy:zc,shimGetUserMedia:Ac,shimLocalStreamsAPI:Ec,shimRTCIceServerUrls:Ic,shimRemoteStreamsAPI:kc,shimTrackEventTransceiver:Bc},Symbol.toStringTag,{value:"Module"}));var dd=uc();const Mr=hr(dd);function Cr(r){if(!r.RTCIceCandidate||r.RTCIceCandidate&&"foundation"in r.RTCIceCandidate.prototype)return;const e=r.RTCIceCandidate;r.RTCIceCandidate=function(t){if(typeof t=="object"&&t.candidate&&t.candidate.indexOf("a=")===0&&(t=JSON.parse(JSON.stringify(t)),t.candidate=t.candidate.substr(2)),t.candidate&&t.candidate.length){const n=new e(t),i=Mr.parseCandidate(t.candidate),s=Object.assign(n,i);return s.toJSON=function(){return{candidate:s.candidate,sdpMid:s.sdpMid,sdpMLineIndex:s.sdpMLineIndex,usernameFragment:s.usernameFragment}},s}return new e(t)},r.RTCIceCandidate.prototype=e.prototype,Un(r,"icecandidate",t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new r.RTCIceCandidate(t.candidate),writable:"false"}),t))}function ai(r,e){if(!r.RTCPeerConnection)return;"sctp"in r.RTCPeerConnection.prototype||Object.defineProperty(r.RTCPeerConnection.prototype,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp}});const t=function(o){if(!o||!o.sdp)return!1;const c=Mr.splitSections(o.sdp);return c.shift(),c.some(l=>{const u=Mr.parseMLine(l);return u&&u.kind==="application"&&u.protocol.indexOf("SCTP")!==-1})},n=function(o){const c=o.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);if(c===null||c.length<2)return-1;const l=parseInt(c[1],10);return l!==l?-1:l},i=function(o){let c=65536;return e.browser==="firefox"&&(e.version<57?o===-1?c=16384:c=2147483637:e.version<60?c=e.version===57?65535:65536:c=2147483637),c},s=function(o,c){let l=65536;e.browser==="firefox"&&e.version===57&&(l=65535);const u=Mr.matchPrefix(o.sdp,"a=max-message-size:");return u.length>0?l=parseInt(u[0].substr(19),10):e.browser==="firefox"&&c!==-1&&(l=2147483637),l},a=r.RTCPeerConnection.prototype.setRemoteDescription;r.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,e.browser==="chrome"&&e.version>=76){const{sdpSemantics:o}=this.getConfiguration();o==="plan-b"&&Object.defineProperty(this,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp},enumerable:!0,configurable:!0})}if(t(arguments[0])){const o=n(arguments[0]),c=i(o),l=s(arguments[0],o);let u;c===0&&l===0?u=Number.POSITIVE_INFINITY:c===0||l===0?u=Math.max(c,l):u=Math.min(c,l);const d={};Object.defineProperty(d,"maxMessageSize",{get(){return u}}),this._sctp=d}return a.apply(this,arguments)}}function ci(r){if(!(r.RTCPeerConnection&&"createDataChannel"in r.RTCPeerConnection.prototype))return;function e(n,i){const s=n.send;n.send=function(){const a=arguments[0],o=a.length||a.size||a.byteLength;if(n.readyState==="open"&&i.sctp&&o>i.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+i.sctp.maxMessageSize+" bytes)");return s.apply(n,arguments)}}const t=r.RTCPeerConnection.prototype.createDataChannel;r.RTCPeerConnection.prototype.createDataChannel=function(){const n=t.apply(this,arguments);return e(n,this),n},Un(r,"datachannel",n=>(e(n.channel,n.target),n))}function Xs(r){if(!r.RTCPeerConnection||"connectionState"in r.RTCPeerConnection.prototype)return;const e=r.RTCPeerConnection.prototype;Object.defineProperty(e,"connectionState",{get(){return{completed:"connected",checking:"connecting"}[this.iceConnectionState]||this.iceConnectionState},enumerable:!0,configurable:!0}),Object.defineProperty(e,"onconnectionstatechange",{get(){return this._onconnectionstatechange||null},set(t){this._onconnectionstatechange&&(this.removeEventListener("connectionstatechange",this._onconnectionstatechange),delete this._onconnectionstatechange),t&&this.addEventListener("connectionstatechange",this._onconnectionstatechange=t)},enumerable:!0,configurable:!0}),["setLocalDescription","setRemoteDescription"].forEach(t=>{const n=e[t];e[t]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=i=>{const s=i.target;if(s._lastConnectionState!==s.connectionState){s._lastConnectionState=s.connectionState;const a=new Event("connectionstatechange",i);s.dispatchEvent(a)}return i},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),n.apply(this,arguments)}})}function Ys(r,e){if(!r.RTCPeerConnection||e.browser==="chrome"&&e.version>=71||e.browser==="safari"&&e.version>=605)return;const t=r.RTCPeerConnection.prototype.setRemoteDescription;r.RTCPeerConnection.prototype.setRemoteDescription=function(n){if(n&&n.sdp&&n.sdp.indexOf(`
1108
1108
  a=extmap-allow-mixed`)!==-1){const i=n.sdp.split(`
1109
1109
  `).filter(s=>s.trim()!=="a=extmap-allow-mixed").join(`
1110
- `);r.RTCSessionDescription&&n instanceof r.RTCSessionDescription?arguments[0]=new r.RTCSessionDescription({type:n.type,sdp:i}):n.sdp=i}return t.apply(this,arguments)}}function Cr(r,e){if(!(r.RTCPeerConnection&&r.RTCPeerConnection.prototype))return;const t=r.RTCPeerConnection.prototype.addIceCandidate;!t||t.length===0||(r.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?(e.browser==="chrome"&&e.version<78||e.browser==="firefox"&&e.version<68||e.browser==="safari")&&arguments[0]&&arguments[0].candidate===""?Promise.resolve():t.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}const dd=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:Xs,shimAddIceCandidateNullOrEmpty:Cr,shimConnectionState:qs,shimMaxMessageSize:ai,shimRTCIceCandidate:Mr,shimSendThrowTypeError:ci},Symbol.toStringTag,{value:"Module"}));function pd({window:r}={},e={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const t=Vs,n=rd(r),i={browserDetails:n,commonShim:dd,extractVersion:oi,disableLog:nd,disableWarnings:id};switch(n.browser){case"chrome":if(!cc||!Js||!e.shimChrome)return t("Chrome shim is not included in this adapter release."),i;if(n.version===null)return t("Chrome shim can not determine version, not shimming."),i;t("adapter.js shimming chrome."),i.browserShim=cc,Cr(r,n),$a(r,n),ec(r),Js(r,n),tc(r),oc(r,n),nc(r),ic(r),rc(r),ac(r,n),Mr(r),qs(r),ai(r,n),ci(r),Xs(r,n);break;case"firefox":if(!Pc||!Hs||!e.shimFirefox)return t("Firefox shim is not included in this adapter release."),i;t("adapter.js shimming firefox."),i.browserShim=Pc,Cr(r,n),gc(r,n),Hs(r,n),vc(r),xc(r),Sc(r),bc(r),wc(r),_c(r),Tc(r),Mc(r),Cc(r),Mr(r),qs(r),ai(r,n),ci(r);break;case"edge":if(!yc||!Ws||!e.shimEdge)return t("MS edge shim is not included in this adapter release."),i;t("adapter.js shimming edge."),i.browserShim=yc,pc(r),fc(r),Ws(r,n),mc(r),ai(r,n),ci(r);break;case"safari":if(!Uc||!e.shimSafari)return t("Safari shim is not included in this adapter release."),i;t("adapter.js shimming safari."),i.browserShim=Uc,Cr(r,n),Ic(r),zc(r),Rc(r),Ec(r),kc(r),Bc(r),Ac(r),Nc(r),Mr(r),ai(r,n),ci(r),Xs(r,n);break;default:t("Unsupported browser!");break}return i}const Dc=pd({window:typeof window>"u"?void 0:window});function Ft(r,e,t,n){Object.defineProperty(r,e,{get:t,set:n,enumerable:!0,configurable:!0})}var Ys=Dc.default||Dc,li=new(function(){function r(){this.isIOS=["iPad","iPhone","iPod"].includes(navigator.platform),this.supportedBrowsers=["firefox","chrome","safari"],this.minFirefoxVersion=59,this.minChromeVersion=72,this.minSafariVersion=605}return r.prototype.isWebRTCSupported=function(){return typeof RTCPeerConnection<"u"},r.prototype.isBrowserSupported=function(){var e=this.getBrowser(),t=this.getVersion(),n=this.supportedBrowsers.includes(e);return n?e==="chrome"?t>=this.minChromeVersion:e==="firefox"?t>=this.minFirefoxVersion:e==="safari"?!this.isIOS&&t>=this.minSafariVersion:!1:!1},r.prototype.getBrowser=function(){return Ys.browserDetails.browser},r.prototype.getVersion=function(){return Ys.browserDetails.version||0},r.prototype.isUnifiedPlanSupported=function(){var e=this.getBrowser(),t=Ys.browserDetails.version||0;if(e==="chrome"&&t<this.minChromeVersion)return!1;if(e==="firefox"&&t>=this.minFirefoxVersion)return!0;if(!window.RTCRtpTransceiver||!("currentDirection"in RTCRtpTransceiver.prototype))return!1;var n,i=!1;try{n=new RTCPeerConnection,n.addTransceiver("audio"),i=!0}catch{}finally{n&&n.close()}return i},r.prototype.toString=function(){return`Supports:
1110
+ `);r.RTCSessionDescription&&n instanceof r.RTCSessionDescription?arguments[0]=new r.RTCSessionDescription({type:n.type,sdp:i}):n.sdp=i}return t.apply(this,arguments)}}function Pr(r,e){if(!(r.RTCPeerConnection&&r.RTCPeerConnection.prototype))return;const t=r.RTCPeerConnection.prototype.addIceCandidate;!t||t.length===0||(r.RTCPeerConnection.prototype.addIceCandidate=function(){return arguments[0]?(e.browser==="chrome"&&e.version<78||e.browser==="firefox"&&e.version<68||e.browser==="safari")&&arguments[0]&&arguments[0].candidate===""?Promise.resolve():t.apply(this,arguments):(arguments[1]&&arguments[1].apply(null),Promise.resolve())})}const pd=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:Ys,shimAddIceCandidateNullOrEmpty:Pr,shimConnectionState:Xs,shimMaxMessageSize:ai,shimRTCIceCandidate:Cr,shimSendThrowTypeError:ci},Symbol.toStringTag,{value:"Module"}));function fd({window:r}={},e={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const t=js,n=sd(r),i={browserDetails:n,commonShim:pd,extractVersion:oi,disableLog:id,disableWarnings:rd};switch(n.browser){case"chrome":if(!cc||!Gs||!e.shimChrome)return t("Chrome shim is not included in this adapter release."),i;if(n.version===null)return t("Chrome shim can not determine version, not shimming."),i;t("adapter.js shimming chrome."),i.browserShim=cc,Pr(r,n),$a(r,n),ec(r),Gs(r,n),tc(r),oc(r,n),nc(r),ic(r),rc(r),ac(r,n),Cr(r),Xs(r),ai(r,n),ci(r),Ys(r,n);break;case"firefox":if(!Pc||!qs||!e.shimFirefox)return t("Firefox shim is not included in this adapter release."),i;t("adapter.js shimming firefox."),i.browserShim=Pc,Pr(r,n),gc(r,n),qs(r,n),vc(r),xc(r),Sc(r),bc(r),wc(r),_c(r),Tc(r),Mc(r),Cc(r),Cr(r),Xs(r),ai(r,n),ci(r);break;case"edge":if(!yc||!Hs||!e.shimEdge)return t("MS edge shim is not included in this adapter release."),i;t("adapter.js shimming edge."),i.browserShim=yc,pc(r),fc(r),Hs(r,n),mc(r),ai(r,n),ci(r);break;case"safari":if(!Uc||!e.shimSafari)return t("Safari shim is not included in this adapter release."),i;t("adapter.js shimming safari."),i.browserShim=Uc,Pr(r,n),Ic(r),zc(r),Rc(r),Ec(r),kc(r),Bc(r),Ac(r),Nc(r),Cr(r),ai(r,n),ci(r),Ys(r,n);break;default:t("Unsupported browser!");break}return i}const Dc=fd({window:typeof window>"u"?void 0:window});function Ft(r,e,t,n){Object.defineProperty(r,e,{get:t,set:n,enumerable:!0,configurable:!0})}var Zs=Dc.default||Dc,li=new(function(){function r(){this.isIOS=["iPad","iPhone","iPod"].includes(navigator.platform),this.supportedBrowsers=["firefox","chrome","safari"],this.minFirefoxVersion=59,this.minChromeVersion=72,this.minSafariVersion=605}return r.prototype.isWebRTCSupported=function(){return typeof RTCPeerConnection<"u"},r.prototype.isBrowserSupported=function(){var e=this.getBrowser(),t=this.getVersion(),n=this.supportedBrowsers.includes(e);return n?e==="chrome"?t>=this.minChromeVersion:e==="firefox"?t>=this.minFirefoxVersion:e==="safari"?!this.isIOS&&t>=this.minSafariVersion:!1:!1},r.prototype.getBrowser=function(){return Zs.browserDetails.browser},r.prototype.getVersion=function(){return Zs.browserDetails.version||0},r.prototype.isUnifiedPlanSupported=function(){var e=this.getBrowser(),t=Zs.browserDetails.version||0;if(e==="chrome"&&t<this.minChromeVersion)return!1;if(e==="firefox"&&t>=this.minFirefoxVersion)return!0;if(!window.RTCRtpTransceiver||!("currentDirection"in RTCRtpTransceiver.prototype))return!1;var n,i=!1;try{n=new RTCPeerConnection,n.addTransceiver("audio"),i=!0}catch{}finally{n&&n.close()}return i},r.prototype.toString=function(){return`Supports:
1111
1111
  browser:`.concat(this.getBrowser(),`
1112
1112
  version:`).concat(this.getVersion(),`
1113
1113
  isIOS:`).concat(this.isIOS,`
1114
1114
  isWebRTCSupported:`).concat(this.isWebRTCSupported(),`
1115
1115
  isBrowserSupported:`).concat(this.isBrowserSupported(),`
1116
- isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},r}()),Lc={iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:["turn:eu-0.turn.peerjs.com:3478","turn:us-0.turn.peerjs.com:3478"],username:"peerjs",credential:"peerjsp"}],sdpSemantics:"unified-plan"},fd=function(){function r(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=Lc,this.browser=li.getBrowser(),this.browserVersion=li.getVersion(),this.supports=function(){var e={browser:li.isBrowserSupported(),webRTC:li.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(Lc),e.audioVideo=!0;var n=void 0;try{n=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!n.ordered;try{n.binaryType="blob",e.binaryBlob=!li.isIOS}catch{}}catch{}finally{n&&n.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=Ha.pack,this.unpack=Ha.unpack,this._dataCount=1}return r.prototype.noop=function(){},r.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},r.prototype.chunk=function(e){for(var t=[],n=e.size,i=Math.ceil(n/ee.chunkedMTU),s=0,a=0;a<n;){var o=Math.min(n,a+ee.chunkedMTU),c=e.slice(a,o),l={__peerData:this._dataCount,n:s,data:c,total:i};t.push(l),a=o,s++}return this._dataCount++,t},r.prototype.blobToArrayBuffer=function(e,t){var n=new FileReader;return n.onload=function(i){i.target&&t(i.target.result)},n.readAsArrayBuffer(e),n},r.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t.buffer},r.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},r.prototype.isSecure=function(){return location.protocol==="https:"},r}(),ee=new fd,Fc={};Ft(Fc,"Peer",()=>to,r=>to=r);var ui={},md=Object.prototype.hasOwnProperty,nt="~";function hi(){}Object.create&&(hi.prototype=Object.create(null),new hi().__proto__||(nt=!1));function yd(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Vc(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new yd(t,n||r,i),a=nt?nt+e:e;return r._events[a]?r._events[a].fn?r._events[a]=[r._events[a],s]:r._events[a].push(s):(r._events[a]=s,r._eventsCount++),r}function Pr(r,e){--r._eventsCount===0?r._events=new hi:delete r._events[e]}function He(){this._events=new hi,this._eventsCount=0}He.prototype.eventNames=function(){var r=[],e,t;if(this._eventsCount===0)return r;for(t in e=this._events)md.call(e,t)&&r.push(nt?t.slice(1):t);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},He.prototype.listeners=function(r){var e=nt?nt+r:r,t=this._events[e];if(!t)return[];if(t.fn)return[t.fn];for(var n=0,i=t.length,s=new Array(i);n<i;n++)s[n]=t[n].fn;return s},He.prototype.listenerCount=function(r){var e=nt?nt+r:r,t=this._events[e];return t?t.fn?1:t.length:0},He.prototype.emit=function(r,e,t,n,i,s){var a=nt?nt+r:r;if(!this._events[a])return!1;var o=this._events[a],c=arguments.length,l,u;if(o.fn){switch(o.once&&this.removeListener(r,o.fn,void 0,!0),c){case 1:return o.fn.call(o.context),!0;case 2:return o.fn.call(o.context,e),!0;case 3:return o.fn.call(o.context,e,t),!0;case 4:return o.fn.call(o.context,e,t,n),!0;case 5:return o.fn.call(o.context,e,t,n,i),!0;case 6:return o.fn.call(o.context,e,t,n,i,s),!0}for(u=1,l=new Array(c-1);u<c;u++)l[u-1]=arguments[u];o.fn.apply(o.context,l)}else{var d=o.length,f;for(u=0;u<d;u++)switch(o[u].once&&this.removeListener(r,o[u].fn,void 0,!0),c){case 1:o[u].fn.call(o[u].context);break;case 2:o[u].fn.call(o[u].context,e);break;case 3:o[u].fn.call(o[u].context,e,t);break;case 4:o[u].fn.call(o[u].context,e,t,n);break;default:if(!l)for(f=1,l=new Array(c-1);f<c;f++)l[f-1]=arguments[f];o[u].fn.apply(o[u].context,l)}}return!0},He.prototype.on=function(r,e,t){return Vc(this,r,e,t,!1)},He.prototype.once=function(r,e,t){return Vc(this,r,e,t,!0)},He.prototype.removeListener=function(r,e,t,n){var i=nt?nt+r:r;if(!this._events[i])return this;if(!e)return Pr(this,i),this;var s=this._events[i];if(s.fn)s.fn===e&&(!n||s.once)&&(!t||s.context===t)&&Pr(this,i);else{for(var a=0,o=[],c=s.length;a<c;a++)(s[a].fn!==e||n&&!s[a].once||t&&s[a].context!==t)&&o.push(s[a]);o.length?this._events[i]=o.length===1?o[0]:o:Pr(this,i)}return this},He.prototype.removeAllListeners=function(r){var e;return r?(e=nt?nt+r:r,this._events[e]&&Pr(this,e)):(this._events=new hi,this._eventsCount=0),this},He.prototype.off=He.prototype.removeListener,He.prototype.addListener=He.prototype.on,He.prefixed=nt,He.EventEmitter=He,ui=He;var j={};Ft(j,"LogLevel",()=>at,r=>at=r),Ft(j,"default",()=>jc,r=>jc=r);var yn=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},gn=function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},gd="PeerJS: ",at;(function(r){r[r.Disabled=0]="Disabled",r[r.Errors=1]="Errors",r[r.Warnings=2]="Warnings",r[r.All=3]="All"})(at||(at={}));var vd=function(){function r(){this._logLevel=at.Disabled}return Object.defineProperty(r.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),r.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=at.All&&this._print.apply(this,gn([at.All],yn(e),!1))},r.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=at.Warnings&&this._print.apply(this,gn([at.Warnings],yn(e),!1))},r.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=at.Errors&&this._print.apply(this,gn([at.Errors],yn(e),!1))},r.prototype.setLogFunction=function(e){this._print=e},r.prototype._print=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var i=gn([gd],yn(t),!1);for(var s in i)i[s]instanceof Error&&(i[s]="("+i[s].name+") "+i[s].message);e>=at.All?console.log.apply(console,gn([],yn(i),!1)):e>=at.Warnings?console.warn.apply(console,gn(["WARNING"],yn(i),!1)):e>=at.Errors&&console.error.apply(console,gn(["ERROR"],yn(i),!1))},r}(),jc=new vd,Jc={};Ft(Jc,"Socket",()=>Gc,r=>Gc=r);var At;(function(r){r.Data="data",r.Media="media"})(At||(At={}));var we;(function(r){r.BrowserIncompatible="browser-incompatible",r.Disconnected="disconnected",r.InvalidID="invalid-id",r.InvalidKey="invalid-key",r.Network="network",r.PeerUnavailable="peer-unavailable",r.SslUnavailable="ssl-unavailable",r.ServerError="server-error",r.SocketError="socket-error",r.SocketClosed="socket-closed",r.UnavailableID="unavailable-id",r.WebRTC="webrtc"})(we||(we={}));var Yt;(function(r){r.Binary="binary",r.BinaryUTF8="binary-utf8",r.JSON="json"})(Yt||(Yt={}));var Zt;(function(r){r.Message="message",r.Disconnected="disconnected",r.Error="error",r.Close="close"})(Zt||(Zt={}));var je;(function(r){r.Heartbeat="HEARTBEAT",r.Candidate="CANDIDATE",r.Offer="OFFER",r.Answer="ANSWER",r.Open="OPEN",r.Error="ERROR",r.IdTaken="ID-TAKEN",r.InvalidKey="INVALID-KEY",r.Leave="LEAVE",r.Expire="EXPIRE"})(je||(je={}));var Zs={};Zs=JSON.parse('{"name":"peerjs","version":"1.4.7","keywords":["peerjs","webrtc","p2p","rtc"],"description":"PeerJS client","homepage":"https://peerjs.com","bugs":{"url":"https://github.com/peers/peerjs/issues"},"repository":{"type":"git","url":"https://github.com/peers/peerjs"},"license":"MIT","contributors":["Michelle Bu <michelle@michellebu.com>","afrokick <devbyru@gmail.com>","ericz <really.ez@gmail.com>","Jairo <kidandcat@gmail.com>","Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>","Jairo Caro-Accino Viciana <jairo@galax.be>","Carlos Caballero <carlos.caballero.gonzalez@gmail.com>","hc <hheennrryy@gmail.com>","Muhammad Asif <capripio@gmail.com>","PrashoonB <prashoonbhattacharjee@gmail.com>","Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>","akotynski <aleksanderkotbury@gmail.com>","lmb <i@lmb.io>","Jairooo <jairocaro@msn.com>","Moritz St\xFCckler <moritz.stueckler@gmail.com>","Simon <crydotsnakegithub@gmail.com>","Denis Lukov <denismassters@gmail.com>","Philipp Hancke <fippo@andyet.net>","Hans Oksendahl <hansoksendahl@gmail.com>","Jess <jessachandler@gmail.com>","khankuan <khankuan@gmail.com>","DUODVK <kurmanov.work@gmail.com>","XiZhao <kwang1imsa@gmail.com>","Matthias Lohr <matthias@lohr.me>","=frank tree <=frnktrb@googlemail.com>","Andre Eckardt <aeckardt@outlook.com>","Chris Cowan <agentme49@gmail.com>","Alex Chuev <alex@chuev.com>","alxnull <alxnull@e.mail.de>","Yemel Jardi <angel.jardi@gmail.com>","Ben Parnell <benjaminparnell.94@gmail.com>","Benny Lichtner <bennlich@gmail.com>","fresheneesz <bitetrudpublic@gmail.com>","bob.barstead@exaptive.com <bob.barstead@exaptive.com>","chandika <chandika@gmail.com>","emersion <contact@emersion.fr>","Christopher Van <cvan@users.noreply.github.com>","eddieherm <edhermoso@gmail.com>","Eduardo Pinho <enet4mikeenet@gmail.com>","Evandro Zanatta <ezanatta@tray.net.br>","Gardner Bickford <gardner@users.noreply.github.com>","Gian Luca <gianluca.cecchi@cynny.com>","PatrickJS <github@gdi2290.com>","jonnyf <github@jonathanfoss.co.uk>","Hizkia Felix <hizkifw@gmail.com>","Hristo Oskov <hristo.oskov@gmail.com>","Isaac Madwed <i.madwed@gmail.com>","Ilya Konanykhin <ilya.konanykhin@gmail.com>","jasonbarry <jasbarry@me.com>","Jonathan Burke <jonathan.burke.1311@googlemail.com>","Josh Hamit <josh.hamit@gmail.com>","Jordan Austin <jrax86@gmail.com>","Joel Wetzell <jwetzell@yahoo.com>","xizhao <kevin.wang@cloudera.com>","Alberto Torres <kungfoobar@gmail.com>","Jonathan Mayol <mayoljonathan@gmail.com>","Jefferson Felix <me@jsfelix.dev>","Rolf Erik Lekang <me@rolflekang.com>","Kevin Mai-Husan Chia <mhchia@users.noreply.github.com>","Pepijn de Vos <pepijndevos@gmail.com>","JooYoung <qkdlql@naver.com>","Tobias Speicher <rootcommander@gmail.com>","Steve Blaurock <sblaurock@gmail.com>","Kyrylo Shegeda <shegeda@ualberta.ca>","Diwank Singh Tomer <singh@diwank.name>","So\u0308ren Balko <Soeren.Balko@gmail.com>","Arpit Solanki <solankiarpit1997@gmail.com>","Yuki Ito <yuki@gnnk.net>","Artur Zayats <zag2art@gmail.com>"],"funding":{"type":"opencollective","url":"https://opencollective.com/peer"},"collective":{"type":"opencollective","url":"https://opencollective.com/peer"},"files":["dist/*"],"sideEffects":["lib/global.ts","lib/supports.ts"],"main":"dist/bundler.cjs","module":"dist/bundler.mjs","browser-minified":"dist/peerjs.min.js","browser-unminified":"dist/peerjs.js","types":"dist/types.d.ts","engines":{"node":">= 10"},"targets":{"types":{"source":"lib/exports.ts"},"main":{"source":"lib/exports.ts","sourceMap":{"inlineSources":true}},"module":{"source":"lib/exports.ts","includeNodeModules":["eventemitter3"],"sourceMap":{"inlineSources":true}},"browser-minified":{"context":"browser","outputFormat":"global","optimize":true,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"},"browser-unminified":{"context":"browser","outputFormat":"global","optimize":false,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"}},"scripts":{"contributors":"git-authors-cli --print=false && prettier --write package.json && git add package.json package-lock.json && git commit -m \\"chore(contributors): update and sort contributors list\\"","check":"tsc --noEmit","watch":"parcel watch","build":"rm -rf dist && parcel build","prepublishOnly":"npm run build","test":"mocha -r ts-node/register -r jsdom-global/register test/**/*.ts","format":"prettier --write .","semantic-release":"semantic-release"},"devDependencies":{"@parcel/config-default":"^2.5.0","@parcel/packager-ts":"^2.5.0","@parcel/transformer-typescript-tsc":"^2.5.0","@parcel/transformer-typescript-types":"^2.5.0","@semantic-release/changelog":"^6.0.1","@semantic-release/git":"^10.0.1","@types/chai":"^4.3.0","@types/mocha":"^9.1.0","@types/node":"^17.0.18","chai":"^4.3.6","git-authors-cli":"^1.0.40","jsdom":"^19.0.0","jsdom-global":"^3.0.2","mocha":"^9.2.0","mock-socket":"8.0.5","parcel":"^2.5.0","parcel-transformer-tsc-sourcemaps":"^1.0.2","prettier":"^2.6.2","semantic-release":"^19.0.2","standard":"^16.0.4","ts-node":"^10.5.0","typescript":"^4.5.5"},"dependencies":{"@swc/helpers":"^0.3.13","eventemitter3":"^4.0.7","peerjs-js-binarypack":"1.0.1","webrtc-adapter":"^7.7.1"}}');var Sd=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),bd=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},xd=function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},wd=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Gc=function(r){Sd(e,r);function e(t,n,i,s,a,o){o===void 0&&(o=5e3);var c=r.call(this)||this;c.pingInterval=o,c._disconnected=!0,c._messagesQueue=[];var l=t?"wss://":"ws://";return c._baseUrl=l+n+":"+i+s+"peerjs?key="+a,c}return e.prototype.start=function(t,n){var i=this;this._id=t;var s="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(n);this._socket||!this._disconnected||(this._socket=new WebSocket(s+"&version="+Zs.version),this._disconnected=!1,this._socket.onmessage=function(a){var o;try{o=JSON.parse(a.data),j.default.log("Server message received:",o)}catch{j.default.log("Invalid server message",a.data);return}i.emit(Zt.Message,o)},this._socket.onclose=function(a){i._disconnected||(j.default.log("Socket closed.",a),i._cleanup(),i._disconnected=!0,i.emit(Zt.Disconnected))},this._socket.onopen=function(){i._disconnected||(i._sendQueuedMessages(),j.default.log("Socket open"),i._scheduleHeartbeat())})},e.prototype._scheduleHeartbeat=function(){var t=this;this._wsPingTimer=setTimeout(function(){t._sendHeartbeat()},this.pingInterval)},e.prototype._sendHeartbeat=function(){if(!this._wsOpen()){j.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:je.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,n,i=xd([],bd(this._messagesQueue),!1);this._messagesQueue=[];try{for(var s=wd(i),a=s.next();!a.done;a=s.next()){var o=a.value;this.send(o)}}catch(c){t={error:c}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},e.prototype.send=function(t){if(!this._disconnected){if(!this._id){this._messagesQueue.push(t);return}if(!t.type){this.emit(Zt.Error,"Invalid message");return}if(this._wsOpen()){var n=JSON.stringify(t);this._socket.send(n)}}},e.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},e.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)},e}(ui.EventEmitter),Ks={};Ft(Ks,"MediaConnection",()=>qc,r=>qc=r);var Qs={};Ft(Qs,"Negotiator",()=>Wc,r=>Wc=r);var Er=function(){return Er=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},Er.apply(this,arguments)},kr=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(n.next(u))}catch(d){a(d)}}function c(u){try{l(n.throw(u))}catch(d){a(d)}}function l(u){u.done?s(u.value):i(u.value).then(o,c)}l((n=n.apply(r,e||[])).next())})},Rr=function(r,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(s=l[0]&2?i.return:l[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,l[1])).done)return s;switch(i=0,s&&(l=[l[0]&2,s.value]),l[0]){case 0:case 1:s=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,i=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!s||l[1]>s[0]&&l[1]<s[3])){t.label=l[1];break}if(l[0]===6&&t.label<s[1]){t.label=s[1],s=l;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(l);break}s[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(u){l=[6,u],i=0}finally{n=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},Wc=function(){function r(e){this.connection=e}return r.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===At.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===At.Data){var n=this.connection,i={ordered:!!e.reliable},s=t.createDataChannel(n.label,i);n.initialize(s)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},r.prototype._startPeerConnection=function(){j.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},r.prototype._setupListeners=function(e){var t=this,n=this.connection.peer,i=this.connection.connectionId,s=this.connection.type,a=this.connection.provider;j.default.log("Listening for ICE candidates."),e.onicecandidate=function(o){!o.candidate||!o.candidate.candidate||(j.default.log("Received ICE candidates for ".concat(n,":"),o.candidate),a.socket.send({type:je.Candidate,payload:{candidate:o.candidate,type:s,connectionId:i},dst:n}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":j.default.log("iceConnectionState is failed, closing connections to "+n),t.connection.emit("error",new Error("Negotiation of connection to "+n+" failed.")),t.connection.close();break;case"closed":j.default.log("iceConnectionState is closed, closing connections to "+n),t.connection.emit("error",new Error("Connection to "+n+" closed.")),t.connection.close();break;case"disconnected":j.default.log("iceConnectionState changed to disconnected on the connection with "+n);break;case"completed":e.onicecandidate=ee.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},j.default.log("Listening for data channel"),e.ondatachannel=function(o){j.default.log("Received data channel");var c=o.channel,l=a.getConnection(n,i);l.initialize(c)},j.default.log("Listening for remote stream"),e.ontrack=function(o){j.default.log("Received remote stream");var c=o.streams[0],l=a.getConnection(n,i);if(l.type===At.Media){var u=l;t._addStreamToMediaConnection(c,u)}}},r.prototype.cleanup=function(){j.default.log("Cleaning up PeerConnection to "+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!=="closed",n=!1;if(this.connection.type===At.Data){var i=this.connection,s=i.dataChannel;s&&(n=!!s.readyState&&s.readyState!=="closed")}(t||n)&&e.close()}},r.prototype._makeOffer=function(){return kr(this,void 0,Promise,function(){var e,t,n,i,s,a,o;return Rr(this,function(c){switch(c.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,c.label=1;case 1:return c.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:n=c.sent(),j.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),c.label=3;case 3:return c.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return c.sent(),j.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),i={sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:ee.browser},this.connection.type===At.Data&&(s=this.connection,i=Er(Er({},i),{label:s.label,reliable:s.reliable,serialization:s.serialization})),t.socket.send({type:je.Offer,payload:i,dst:this.connection.peer}),[3,6];case 5:return a=c.sent(),a!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(t.emitError(we.WebRTC,a),j.default.log("Failed to setLocalDescription, ",a)),[3,6];case 6:return[3,8];case 7:return o=c.sent(),t.emitError(we.WebRTC,o),j.default.log("Failed to createOffer, ",o),[3,8];case 8:return[2]}})})},r.prototype._makeAnswer=function(){return kr(this,void 0,Promise,function(){var e,t,n,i,s;return Rr(this,function(a){switch(a.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,a.label=1;case 1:return a.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:n=a.sent(),j.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),a.label=3;case 3:return a.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return a.sent(),j.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),t.socket.send({type:je.Answer,payload:{sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,browser:ee.browser},dst:this.connection.peer}),[3,6];case 5:return i=a.sent(),t.emitError(we.WebRTC,i),j.default.log("Failed to setLocalDescription, ",i),[3,6];case 6:return[3,8];case 7:return s=a.sent(),t.emitError(we.WebRTC,s),j.default.log("Failed to create answer, ",s),[3,8];case 8:return[2]}})})},r.prototype.handleSDP=function(e,t){return kr(this,void 0,Promise,function(){var n,i,s,a;return Rr(this,function(o){switch(o.label){case 0:t=new RTCSessionDescription(t),n=this.connection.peerConnection,i=this.connection.provider,j.default.log("Setting remote description",t),s=this,o.label=1;case 1:return o.trys.push([1,5,,6]),[4,n.setRemoteDescription(t)];case 2:return o.sent(),j.default.log("Set remoteDescription:".concat(e," for:").concat(this.connection.peer)),e!=="OFFER"?[3,4]:[4,s._makeAnswer()];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:return a=o.sent(),i.emitError(we.WebRTC,a),j.default.log("Failed to setRemoteDescription, ",a),[3,6];case 6:return[2]}})})},r.prototype.handleCandidate=function(e){return kr(this,void 0,Promise,function(){var t,n,i,s,a,o;return Rr(this,function(c){switch(c.label){case 0:j.default.log("handleCandidate:",e),t=e.candidate,n=e.sdpMLineIndex,i=e.sdpMid,s=this.connection.peerConnection,a=this.connection.provider,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,s.addIceCandidate(new RTCIceCandidate({sdpMid:i,sdpMLineIndex:n,candidate:t}))];case 2:return c.sent(),j.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return o=c.sent(),a.emitError(we.WebRTC,o),j.default.log("Failed to handleCandidate, ",o),[3,4];case 4:return[2]}})})},r.prototype._addTracksToConnection=function(e,t){if(j.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return j.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(n){t.addTrack(n,e)})},r.prototype._addStreamToMediaConnection=function(e,t){j.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},r}(),$s={};Ft($s,"BaseConnection",()=>Hc,r=>Hc=r);var _d=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Hc=function(r){_d(e,r);function e(t,n,i){var s=r.call(this)||this;return s.peer=t,s.provider=n,s.options=i,s._open=!1,s.metadata=i.metadata,s}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e}(ui.EventEmitter),Td=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Ar=function(){return Ar=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},Ar.apply(this,arguments)},Md=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},qc=function(r){Td(e,r);function e(t,n,i){var s=r.call(this,t,n,i)||this;return s._localStream=s.options._stream,s.connectionId=s.options.connectionId||e.ID_PREFIX+ee.randomToken(),s._negotiator=new Qs.Negotiator(s),s._localStream&&s._negotiator.startConnection({_stream:s._localStream,originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return At.Media},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localStream",{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteStream",{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),e.prototype.addStream=function(t){j.default.log("Receiving stream",t),this._remoteStream=t,r.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var n=t.type,i=t.payload;switch(t.type){case je.Answer:this._negotiator.handleSDP(n,i.sdp),this._open=!0;break;case je.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:j.default.warn("Unrecognized message type:".concat(n," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,n){var i,s;if(n===void 0&&(n={}),this._localStream){j.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,n&&n.sdpTransform&&(this.options.sdpTransform=n.sdpTransform),this._negotiator.startConnection(Ar(Ar({},this.options._payload),{_stream:t}));var a=this.provider._getMessages(this.connectionId);try{for(var o=Md(a),c=o.next();!c.done;c=o.next()){var l=c.value;this.handleMessage(l)}}catch(u){i={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}this._open=!0},e.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,r.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e}($s.BaseConnection),eo={};Ft(eo,"DataConnection",()=>Zc,r=>Zc=r);var Xc={};Ft(Xc,"EncodingQueue",()=>Yc,r=>Yc=r);var Cd=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Yc=function(r){Cd(e,r);function e(){var t=r.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(n){t._processing=!1,n.target&&t.emit("done",n.target.result),t.doNextTask()},t.fileReader.onerror=function(n){j.default.error("EncodingQueue error:",n),t._processing=!1,t.destroy(),t.emit("error",n)},t}return Object.defineProperty(e.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),e.prototype.enque=function(t){this.queue.push(t),!this.processing&&this.doNextTask()},e.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},e.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},e}(ui.EventEmitter),Pd=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Ed=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Zc=function(r){Pd(e,r);function e(t,n,i){var s=r.call(this,t,n,i)||this;return s.stringify=JSON.stringify,s.parse=JSON.parse,s._buffer=[],s._bufferSize=0,s._buffering=!1,s._chunkedData={},s._encodingQueue=new Xc.EncodingQueue,s.connectionId=s.options.connectionId||e.ID_PREFIX+ee.randomToken(),s.label=s.options.label||s.connectionId,s.serialization=s.options.serialization||Yt.Binary,s.reliable=!!s.options.reliable,s._encodingQueue.on("done",function(a){s._bufferedSend(a)}),s._encodingQueue.on("error",function(){j.default.error("DC#".concat(s.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),s.close()}),s._negotiator=new Qs.Negotiator(s),s._negotiator.startConnection(s.options._payload||{originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return At.Data},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataChannel",{get:function(){return this._dc},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bufferSize",{get:function(){return this._bufferSize},enumerable:!1,configurable:!0}),e.prototype.initialize=function(t){this._dc=t,this._configureDataChannel()},e.prototype._configureDataChannel=function(){var t=this;(!ee.supports.binaryBlob||ee.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){j.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(n){j.default.log("DC#".concat(t.connectionId," dc onmessage:"),n.data),t._handleDataMessage(n)},this.dataChannel.onclose=function(){j.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var n=this,i=t.data,s=i.constructor,a=this.serialization===Yt.Binary||this.serialization===Yt.BinaryUTF8,o=i;if(a){if(s===Blob){ee.blobToArrayBuffer(i,function(l){var u=ee.unpack(l);n.emit("data",u)});return}else if(s===ArrayBuffer)o=ee.unpack(i);else if(s===String){var c=ee.binaryStringToArrayBuffer(i);o=ee.unpack(c)}}else this.serialization===Yt.JSON&&(o=this.parse(i));if(o.__peerData){this._handleChunk(o);return}r.prototype.emit.call(this,"data",o)},e.prototype._handleChunk=function(t){var n=t.__peerData,i=this._chunkedData[n]||{data:[],count:0,total:t.total};if(i.data[t.n]=t.data,i.count++,this._chunkedData[n]=i,i.total===i.count){delete this._chunkedData[n];var s=new Blob(i.data);this._handleDataMessage({data:s})}},e.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),this._encodingQueue=null),this.open&&(this._open=!1,r.prototype.emit.call(this,"close"))},e.prototype.send=function(t,n){if(!this.open){r.prototype.emit.call(this,"error",new Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===Yt.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===Yt.Binary||this.serialization===Yt.BinaryUTF8){var i=ee.pack(t);if(!n&&i.size>ee.chunkedMTU){this._sendChunks(i);return}ee.supports.binaryBlob?this._bufferedSend(i):this._encodingQueue.enque(i)}else this._bufferedSend(t)},e.prototype._bufferedSend=function(t){(this._buffering||!this._trySend(t))&&(this._buffer.push(t),this._bufferSize=this._buffer.length)},e.prototype._trySend=function(t){var n=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){n._buffering=!1,n._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(i){return j.default.error("DC#:".concat(this.connectionId," Error when sending:"),i),this._buffering=!0,this.close(),!1}return!0},e.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},e.prototype._sendChunks=function(t){var n,i,s=ee.chunk(t);j.default.log("DC#".concat(this.connectionId," Try to send ").concat(s.length," chunks..."));try{for(var a=Ed(s),o=a.next();!o.done;o=a.next()){var c=o.value;this.send(c,!0)}}catch(l){n={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}},e.prototype.handleMessage=function(t){var n=t.payload;switch(t.type){case je.Answer:this._negotiator.handleSDP(t.type,n.sdp);break;case je.Candidate:this._negotiator.handleCandidate(n.candidate);break;default:j.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e}($s.BaseConnection),Kc={};Ft(Kc,"API",()=>el,r=>el=r);var Qc=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(n.next(u))}catch(d){a(d)}}function c(u){try{l(n.throw(u))}catch(d){a(d)}}function l(u){u.done?s(u.value):i(u.value).then(o,c)}l((n=n.apply(r,e||[])).next())})},$c=function(r,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(s=l[0]&2?i.return:l[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,l[1])).done)return s;switch(i=0,s&&(l=[l[0]&2,s.value]),l[0]){case 0:case 1:s=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,i=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!s||l[1]>s[0]&&l[1]<s[3])){t.label=l[1];break}if(l[0]===6&&t.label<s[1]){t.label=s[1],s=l;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(l);break}s[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(u){l=[6,u],i=0}finally{n=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},el=function(){function r(e){this._options=e}return r.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",n=this._options,i=n.host,s=n.port,a=n.path,o=n.key,c=new URL("".concat(t,"://").concat(i,":").concat(s).concat(a).concat(o,"/").concat(e));return c.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),c.searchParams.set("version",Zs.version),fetch(c.href,{referrerPolicy:this._options.referrerPolicy})},r.prototype.retrieveId=function(){return Qc(this,void 0,Promise,function(){var e,t,n;return $c(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=i.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=i.sent(),j.default.error("Error retrieving ID",t),n="",this._options.path==="/"&&this._options.host!==ee.CLOUD_HOST&&(n=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+n);case 3:return[2]}})})},r.prototype.listAllPeers=function(){return Qc(this,void 0,Promise,function(){var e,t,n;return $c(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=i.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===ee.CLOUD_HOST?t="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":t="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+t)):new Error("Error. Status:".concat(e.status));return[2,e.json()];case 2:throw n=i.sent(),j.default.error("Error retrieving list peers",n),new Error("Could not get list peers from the server."+n);case 3:return[2]}})})},r}(),kd=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),di=function(){return di=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},di.apply(this,arguments)},pi=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Rd=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},to=function(r){kd(e,r);function e(t,n){var i=r.call(this)||this;i._id=null,i._lastServerId=null,i._destroyed=!1,i._disconnected=!1,i._open=!1,i._connections=new Map,i._lostMessages=new Map;var s;return t&&t.constructor==Object?n=t:t&&(s=t.toString()),n=di({debug:0,host:ee.CLOUD_HOST,port:ee.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:ee.randomToken(),config:ee.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},n),i._options=n,i._options.host==="/"&&(i._options.host=window.location.hostname),i._options.path&&(i._options.path[0]!=="/"&&(i._options.path="/"+i._options.path),i._options.path[i._options.path.length-1]!=="/"&&(i._options.path+="/")),i._options.secure===void 0&&i._options.host!==ee.CLOUD_HOST?i._options.secure=ee.isSecure():i._options.host==ee.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&j.default.setLogFunction(i._options.logFunction),j.default.logLevel=i._options.debug||0,i._api=new Kc.API(n),i._socket=i._createServerConnection(),!ee.supports.audioVideo&&!ee.supports.data?(i._delayedAbort(we.BrowserIncompatible,"The current browser does not support WebRTC"),i):s&&!ee.validateId(s)?(i._delayedAbort(we.InvalidID,'ID "'.concat(s,'" is invalid')),i):(s?i._initialize(s):i._api.retrieveId().then(function(a){return i._initialize(a)}).catch(function(a){return i._abort(we.ServerError,a)}),i)}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){var t,n,i=Object.create(null);try{for(var s=pi(this._connections),a=s.next();!a.done;a=s.next()){var o=Rd(a.value,2),c=o[0],l=o[1];i[c]=l}}catch(u){t={error:u}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return i},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),e.prototype._createServerConnection=function(){var t=this,n=new Jc.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return n.on(Zt.Message,function(i){t._handleMessage(i)}),n.on(Zt.Error,function(i){t._abort(we.SocketError,i)}),n.on(Zt.Disconnected,function(){t.disconnected||(t.emitError(we.Network,"Lost connection to server."),t.disconnect())}),n.on(Zt.Close,function(){t.disconnected||t._abort(we.SocketClosed,"Underlying socket is already closed.")}),n},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var n,i,s=t.type,a=t.payload,o=t.src;switch(s){case je.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case je.Error:this._abort(we.ServerError,a.msg);break;case je.IdTaken:this._abort(we.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case je.InvalidKey:this._abort(we.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case je.Leave:j.default.log("Received leave message from ".concat(o)),this._cleanupPeer(o),this._connections.delete(o);break;case je.Expire:this.emitError(we.PeerUnavailable,"Could not connect to peer ".concat(o));break;case je.Offer:var x=a.connectionId,_=this.getConnection(o,x);if(_&&(_.close(),j.default.warn("Offer received for existing Connection ID:".concat(x))),a.type===At.Media){var c=new Ks.MediaConnection(o,this,{connectionId:x,_payload:a,metadata:a.metadata});_=c,this._addConnection(o,_),this.emit("call",c)}else if(a.type===At.Data){var l=new eo.DataConnection(o,this,{connectionId:x,_payload:a,metadata:a.metadata,label:a.label,serialization:a.serialization,reliable:a.reliable});_=l,this._addConnection(o,_),this.emit("connection",l)}else{j.default.warn("Received malformed connection type:".concat(a.type));return}var u=this._getMessages(x);try{for(var d=pi(u),f=d.next();!f.done;f=d.next()){var m=f.value;_.handleMessage(m)}}catch(g){n={error:g}}finally{try{f&&!f.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}break;default:if(!a){j.default.warn("You received a malformed message from ".concat(o," of type ").concat(s));return}var x=a.connectionId,_=this.getConnection(o,x);_&&_.peerConnection?_.handleMessage(t):x?this._storeMessage(x,t):j.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,n){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(n)},e.prototype._getMessages=function(t){var n=this._lostMessages.get(t);return n?(this._lostMessages.delete(t),n):[]},e.prototype.connect=function(t,n){if(n===void 0&&(n={}),this.disconnected){j.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),this.emitError(we.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var i=new eo.DataConnection(t,this,n);return this._addConnection(t,i),i},e.prototype.call=function(t,n,i){if(i===void 0&&(i={}),this.disconnected){j.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),this.emitError(we.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!n){j.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var s=new Ks.MediaConnection(t,this,di(di({},i),{_stream:n}));return this._addConnection(t,s),s},e.prototype._addConnection=function(t,n){j.default.log("add connection ".concat(n.type,":").concat(n.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(n)},e.prototype._removeConnection=function(t){var n=this._connections.get(t.peer);if(n){var i=n.indexOf(t);i!==-1&&n.splice(i,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,n){var i,s,a=this._connections.get(t);if(!a)return null;try{for(var o=pi(a),c=o.next();!c.done;c=o.next()){var l=c.value;if(l.connectionId===n)return l}}catch(u){i={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}return null},e.prototype._delayedAbort=function(t,n){var i=this;setTimeout(function(){i._abort(t,n)},0)},e.prototype._abort=function(t,n){j.default.error("Aborting!"),this.emitError(t,n),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,n){j.default.error("Error:",n);var i;typeof n=="string"?i=new Error(n):i=n,i.type=t,this.emit("error",i)},e.prototype.destroy=function(){this.destroyed||(j.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},e.prototype._cleanup=function(){var t,n;try{for(var i=pi(this._connections.keys()),s=i.next();!s.done;s=i.next()){var a=s.value;this._cleanupPeer(a),this._connections.delete(a)}}catch(o){t={error:o}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var n,i,s=this._connections.get(t);if(s)try{for(var a=pi(s),o=a.next();!o.done;o=a.next()){var c=o.value;c.close()}}catch(l){n={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;j.default.log("Disconnect peer with ID:".concat(t)),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=t,this._id=null,this.emit("disconnected",t)}},e.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)j.default.log("Attempting reconnection to server with ID ".concat(this._lastServerId)),this._disconnected=!1,this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(!this.disconnected&&!this.open)j.default.error("In a hurry? We're still trying to make the initial connection!");else throw new Error("Peer ".concat(this.id," cannot reconnect because it is not disconnected from the server!"))}},e.prototype.listAllPeers=function(t){var n=this;t===void 0&&(t=function(i){}),this._api.listAllPeers().then(function(i){return t(i)}).catch(function(i){return n._abort(we.ServerError,i)})},e.DEFAULT_KEY="peerjs",e}(ui.EventEmitter),Ad=Fc.Peer;const Od=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return to},default:Ad,util:ee},Symbol.toStringTag,{value:"Module"}));class Id{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Base must be a positive integer or zero");if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=e,this.expMax=t,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}var ce;(function(r){r.open="open",r.close="close",r.error="error",r.message="message",r.retry="retry",r.reconnect="reconnect"})(ce||(ce={}));class tl{constructor(e,t,n){var i,s,a,o,c,l,u,d,f,m,x,_,g,v,w;this._closedByUser=!1,this.handleOpenEvent=S=>this.handleEvent(ce.open,S),this.handleErrorEvent=S=>this.handleEvent(ce.error,S),this.handleCloseEvent=S=>this.handleEvent(ce.close,S),this.handleMessageEvent=S=>this.handleEvent(ce.message,S),this._url=e,this._protocols=t,this._options={buffer:n?.buffer,retry:{maxRetries:(i=n?.retry)===null||i===void 0?void 0:i.maxRetries,instantReconnect:(s=n?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=n?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=n?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(u=(l=n?.listeners)===null||l===void 0?void 0:l.close)!==null&&u!==void 0?u:[]],error:[...(f=(d=n?.listeners)===null||d===void 0?void 0:d.error)!==null&&f!==void 0?f:[]],message:[...(x=(m=n?.listeners)===null||m===void 0?void 0:m.message)!==null&&x!==void 0?x:[]],retry:[...(g=(_=n?.listeners)===null||_===void 0?void 0:_.retry)!==null&&g!==void 0?g:[]],reconnect:[...(w=(v=n?.listeners)===null||v===void 0?void 0:v.reconnect)!==null&&w!==void 0?w:[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,n){this._options.listeners[e].push({listener:t,options:n})}removeEventListener(e,t,n){const i=s=>s.listener!==t||s.options!==n;this._options.listeners[e]=this._options.listeners[e].filter(i)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(ce.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(ce.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(ce.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(ce.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(ce.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(ce.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(ce.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(ce.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const n=this._options.listeners[e],i=[];n.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&i.push({listener:s,options:a})}),this._options.listeners[e]=i}handleEvent(e,t){switch(e){case ce.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case ce.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const n={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},i=new CustomEvent(ce.reconnect,{detail:n});this.dispatchEvent(ce.reconnect,i),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case ce.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const e=n=>{const i=new CustomEvent(ce.retry,{detail:n});this.handleEvent(ce.retry,i)},t={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class Bd{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{maxRetries:e})}),this}get maxRetries(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.maxRetries}withInstantReconnect(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{instantReconnect:e})}),this}get instantReconnect(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.instantReconnect}withBackoff(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{backoff:e})}),this}get backoff(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){var e;return(e=this._options)===null||e===void 0?void 0:e.buffer}onOpen(e,t){return this.addListener(ce.open,e,t),this}onClose(e,t){return this.addListener(ce.close,e,t),this}onError(e,t){return this.addListener(ce.error,e,t),this}onMessage(e,t){return this.addListener(ce.message,e,t),this}onRetry(e,t){return this.addListener(ce.retry,e,t),this}onReconnect(e,t){return this.addListener(ce.reconnect,e,t),this}build(){return new tl(this._url,this._protocols,this._options)}addListener(e,t,n){var i,s,a,o,c,l,u,d,f,m,x,_,g,v,w,S,T,M,P,E,O;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(i=this._options)===null||i===void 0?void 0:i.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(f=(d=(u=this._options)===null||u===void 0?void 0:u.listeners)===null||d===void 0?void 0:d.error)!==null&&f!==void 0?f:[],message:(_=(x=(m=this._options)===null||m===void 0?void 0:m.listeners)===null||x===void 0?void 0:x.message)!==null&&_!==void 0?_:[],retry:(w=(v=(g=this._options)===null||g===void 0?void 0:g.listeners)===null||v===void 0?void 0:v.retry)!==null&&w!==void 0?w:[],reconnect:(M=(T=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||T===void 0?void 0:T.reconnect)!==null&&M!==void 0?M:[],[e]:[...(O=(E=(P=this._options)===null||P===void 0?void 0:P.listeners)===null||E===void 0?void 0:E[e])!==null&&O!==void 0?O:[],{listener:t,options:n}]}}),this}}const zd=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Id,Websocket:tl,WebsocketBuilder:Bd,get WebsocketEvent(){return ce}},Symbol.toStringTag,{value:"Module"})),no=0,nl=1,il=2,io=2,ro=1.25,rl=1,qe=32,Pe=qe/4,sl=65535,Or=Math.pow(2,-24),Ir=Symbol("SKIP_GENERATION"),ol={strategy:no,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Ir]:!1};function be(r,e,t){return t.min.x=e[r],t.min.y=e[r+1],t.min.z=e[r+2],t.max.x=e[r+3],t.max.y=e[r+4],t.max.z=e[r+5],t}function al(r){let e=-1,t=-1/0;for(let n=0;n<3;n++){const i=r[n+3]-r[n];i>t&&(t=i,e=n)}return e}function cl(r,e){e.set(r)}function ll(r,e,t){let n,i;for(let s=0;s<3;s++){const a=s+3;n=r[s],i=e[s],t[s]=n<i?n:i,n=r[a],i=e[a],t[a]=n>i?n:i}}function Br(r,e,t){for(let n=0;n<3;n++){const i=e[r+2*n],s=e[r+2*n+1],a=i-s,o=i+s;a<t[n]&&(t[n]=a),o>t[n+3]&&(t[n+3]=o)}}function fi(r){const e=r[3]-r[0],t=r[4]-r[1],n=r[5]-r[2];return 2*(e*t+t*n+n*e)}function Ee(r,e){return e[r+15]===sl}function Xe(r,e){return e[r+6]}function it(r,e){return e[r+14]}function ze(r){return r+Pe}function Ne(r,e){const t=e[r+6];return r+t*Pe}function so(r,e){return e[r+7]}function oo(r,e,t,n,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0,d=1/0,f=1/0,m=1/0,x=-1/0,_=-1/0,g=-1/0;const v=r.offset||0;for(let w=(e-v)*6,S=(e+t-v)*6;w<S;w+=6){const T=r[w+0],M=r[w+1],P=T-M,E=T+M;P<s&&(s=P),E>c&&(c=E),T<d&&(d=T),T>x&&(x=T);const O=r[w+2],A=r[w+3],R=O-A,B=O+A;R<a&&(a=R),B>l&&(l=B),O<f&&(f=O),O>_&&(_=O);const I=r[w+4],U=r[w+5],L=I-U,J=I+U;L<o&&(o=L),J>u&&(u=J),I<m&&(m=I),I>g&&(g=I)}n[0]=s,n[1]=a,n[2]=o,n[3]=c,n[4]=l,n[5]=u,i[0]=d,i[1]=f,i[2]=m,i[3]=x,i[4]=_,i[5]=g}const Kt=32,Nd=(r,e)=>r.candidate-e.candidate,an=new Array(Kt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),zr=new Float32Array(6);function Ud(r,e,t,n,i,s){let a=-1,o=0;if(s===no)a=al(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===nl)a=al(r),a!==-1&&(o=Dd(t,n,i,a));else if(s===il){const c=fi(r);let l=ro*i;const u=t.offset||0,d=(n-u)*6,f=(n+i-u)*6;for(let m=0;m<3;m++){const x=e[m],_=(e[m+3]-x)/Kt;if(i<Kt/4){const g=[...an];g.length=i;let v=0;for(let S=d;S<f;S+=6,v++){const T=g[v];T.candidate=t[S+2*m],T.count=0;const{bounds:M,leftCacheBounds:P,rightCacheBounds:E}=T;for(let O=0;O<3;O++)E[O]=1/0,E[O+3]=-1/0,P[O]=1/0,P[O+3]=-1/0,M[O]=1/0,M[O+3]=-1/0;Br(S,t,M)}g.sort(Nd);let w=i;for(let S=0;S<w;S++){const T=g[S];for(;S+1<w&&g[S+1].candidate===T.candidate;)g.splice(S+1,1),w--}for(let S=d;S<f;S+=6){const T=t[S+2*m];for(let M=0;M<w;M++){const P=g[M];T>=P.candidate?Br(S,t,P.rightCacheBounds):(Br(S,t,P.leftCacheBounds),P.count++)}}for(let S=0;S<w;S++){const T=g[S],M=T.count,P=i-T.count,E=T.leftCacheBounds,O=T.rightCacheBounds;let A=0;M!==0&&(A=fi(E)/c);let R=0;P!==0&&(R=fi(O)/c);const B=rl+ro*(A*M+R*P);B<l&&(a=m,l=B,o=T.candidate)}}else{for(let w=0;w<Kt;w++){const S=an[w];S.count=0,S.candidate=x+_+w*_;const T=S.bounds;for(let M=0;M<3;M++)T[M]=1/0,T[M+3]=-1/0}for(let w=d;w<f;w+=6){let S=~~((t[w+2*m]-x)/_);S>=Kt&&(S=Kt-1);const T=an[S];T.count++,Br(w,t,T.bounds)}const g=an[Kt-1];cl(g.bounds,g.rightCacheBounds);for(let w=Kt-2;w>=0;w--){const S=an[w],T=an[w+1];ll(S.bounds,T.rightCacheBounds,S.rightCacheBounds)}let v=0;for(let w=0;w<Kt-1;w++){const S=an[w],T=S.count,M=S.bounds,P=an[w+1].rightCacheBounds;T!==0&&(v===0?cl(M,zr):ll(M,zr,zr)),v+=T;let E=0,O=0;v!==0&&(E=fi(zr)/c);const A=i-v;A!==0&&(O=fi(P)/c);const R=rl+ro*(E*v+O*A);R<l&&(a=m,l=R,o=S.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function Dd(r,e,t,n){let i=0;const s=r.offset;for(let a=e,o=e+t;a<o;a++)i+=r[(a-s)*6+n*2];return i/t}class ao{constructor(){this.boundingData=new Float32Array(6)}}function Ld(r,e,t,n,i,s){let a=n,o=n+i-1;const c=s.pos,l=s.axis*2,u=t.offset||0;for(;;){for(;a<=o&&t[(a-u)*6+l]<c;)a++;for(;a<=o&&t[(o-u)*6+l]>=c;)o--;if(a<o){for(let d=0;d<e;d++){let f=r[a*e+d];r[a*e+d]=r[o*e+d],r[o*e+d]=f}for(let d=0;d<6;d++){const f=a-u,m=o-u,x=t[f*6+d];t[f*6+d]=t[m*6+d],t[m*6+d]=x}a++,o--}else return a}}let ul,Nr,co,hl;const Fd=Math.pow(2,32);function lo(r){return"count"in r?1:1+lo(r.left)+lo(r.right)}function Vd(r,e,t){return ul=new Float32Array(t),Nr=new Uint32Array(t),co=new Uint16Array(t),hl=new Uint8Array(t),uo(r,e)}function uo(r,e){const t=r/4,n=r/2,i="count"in e,s=e.boundingData;for(let a=0;a<6;a++)ul[t+a]=s[a];if(i)return e.buffer?(hl.set(new Uint8Array(e.buffer),r),r+e.buffer.byteLength):(Nr[t+6]=e.offset,co[n+14]=e.count,co[n+15]=sl,r+qe);{const{left:a,right:o,splitAxis:c}=e,l=r+qe;let u=uo(l,a);const d=r/qe,f=u/qe-d;if(f>Fd)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Nr[t+6]=f,Nr[t+7]=c,uo(u,o)}}function jd(r,e,t,n,i){const{maxDepth:s,verbose:a,maxLeafSize:o,strategy:c,onProgress:l}=i,u=r.primitiveBuffer,d=r.primitiveBufferStride,f=new Float32Array(6);let m=!1;const x=new ao;return oo(e,t,n,x.boundingData,f),g(x,t,n,f),x;function _(v){l&&l(v/n)}function g(v,w,S,T=null,M=0){if(!m&&M>=s&&(m=!0,a&&console.warn(`BVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`)),S<=o||M>=s)return _(w+S),v.offset=w,v.count=S,v;const P=Ud(v.boundingData,T,e,w,S,c);if(P.axis===-1)return _(w+S),v.offset=w,v.count=S,v;const E=Ld(u,d,e,w,S,P);if(E===w||E===w+S)_(w+S),v.offset=w,v.count=S;else{v.splitAxis=P.axis;const O=new ao,A=w,R=E-w;v.left=O,oo(e,A,R,O.boundingData,f),g(O,A,R,f,M+1);const B=new ao,I=E,U=S-R;v.right=B,oo(e,I,U,B.boundingData,f),g(B,I,U,f,M+1)}return v}}function Jd(r,e){const t=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=r.getRootRanges(e.range),i=n[0],s=n[n.length-1],a={offset:i.offset,count:s.offset+s.count-i.offset},o=new Float32Array(6*a.count);o.offset=a.offset,r.computePrimitiveBounds(a.offset,a.count,o),r._roots=n.map(c=>{const l=jd(r,o,c.offset,c.count,e),u=lo(l),d=new t(qe*u);return Vd(0,l,d),d})}class ho{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Gd{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const ye=new Gd;let cn,Dn;const Ln=[],Ur=new ho(()=>new zt);function Wd(r,e,t,n,i,s){cn=Ur.getPrimitive(),Dn=Ur.getPrimitive(),Ln.push(cn,Dn),ye.setBuffer(r._roots[e]);const a=po(0,r.geometry,t,n,i,s);ye.clearBuffer(),Ur.releasePrimitive(cn),Ur.releasePrimitive(Dn),Ln.pop(),Ln.pop();const o=Ln.length;return o>0&&(Dn=Ln[o-1],cn=Ln[o-2]),a}function po(r,e,t,n,i=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=ye;let u=r*2;if(Ee(u,c)){const d=Xe(r,l),f=it(u,c);return be(r,o,cn),n(d,f,!1,a,s+r/Pe,cn)}else{let d=function(B){const{uint16Array:I,uint32Array:U}=ye;let L=B*2;for(;!Ee(L,I);)B=ze(B),L=B*2;return Xe(B,U)},f=function(B){const{uint16Array:I,uint32Array:U}=ye;let L=B*2;for(;!Ee(L,I);)B=Ne(B,U),L=B*2;return Xe(B,U)+it(L,I)};const m=ze(r),x=Ne(r,l);let _=m,g=x,v,w,S,T;if(i&&(S=cn,T=Dn,be(_,o,S),be(g,o,T),v=i(S),w=i(T),w<v)){_=x,g=m;const B=v;v=w,w=B,S=T}S||(S=cn,be(_,o,S));const M=Ee(_*2,c),P=t(S,M,v,a+1,s+_/Pe);let E;if(P===io){const B=d(_),I=f(_)-B;E=n(B,I,!0,a+1,s+_/Pe,S)}else E=P&&po(_,e,t,n,i,s,a+1);if(E)return!0;T=Dn,be(g,o,T);const O=Ee(g*2,c),A=t(T,O,w,a+1,s+g/Pe);let R;if(A===io){const B=d(g),I=f(g)-B;R=n(B,I,!0,a+1,s+g/Pe,T)}else R=A&&po(g,e,t,n,i,s,a+1);return!!R}}const mi=new ye.constructor,Dr=new ye.constructor,ln=new ho(()=>new zt),Fn=new zt,Vn=new zt,fo=new zt,mo=new zt;let yo=!1;function Hd(r,e,t,n){if(yo)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");yo=!0;const i=r._roots,s=e._roots;let a,o=0,c=0;const l=new kt().copy(t).invert();for(let u=0,d=i.length;u<d;u++){mi.setBuffer(i[u]),c=0;const f=ln.getPrimitive();be(0,mi.float32Array,f),f.applyMatrix4(l);for(let m=0,x=s.length;m<x&&(Dr.setBuffer(s[m]),a=Ot(0,0,t,l,n,o,c,0,0,f),Dr.clearBuffer(),c+=s[m].byteLength/qe,!a);m++);if(ln.releasePrimitive(f),mi.clearBuffer(),o+=i[u].byteLength/qe,a)break}return yo=!1,a}function Ot(r,e,t,n,i,s=0,a=0,o=0,c=0,l=null,u=!1){let d,f;u?(d=Dr,f=mi):(d=mi,f=Dr);const m=d.float32Array,x=d.uint32Array,_=d.uint16Array,g=f.float32Array,v=f.uint32Array,w=f.uint16Array,S=r*2,T=e*2,M=Ee(S,_),P=Ee(T,w);let E=!1;if(P&&M)u?E=i(Xe(e,v),it(e*2,w),Xe(r,x),it(r*2,_),c,a+e/Pe,o,s+r/Pe):E=i(Xe(r,x),it(r*2,_),Xe(e,v),it(e*2,w),o,s+r/Pe,c,a+e/Pe);else if(P){const O=ln.getPrimitive();be(e,g,O),O.applyMatrix4(t);const A=ze(r),R=Ne(r,x);be(A,m,Fn),be(R,m,Vn);const B=O.intersectsBox(Fn),I=O.intersectsBox(Vn);E=B&&Ot(e,A,n,t,i,a,s,c,o+1,O,!u)||I&&Ot(e,R,n,t,i,a,s,c,o+1,O,!u),ln.releasePrimitive(O)}else{const O=ze(e),A=Ne(e,v);be(O,g,fo),be(A,g,mo);const R=l.intersectsBox(fo),B=l.intersectsBox(mo);if(R&&B)E=Ot(r,O,t,n,i,s,a,o,c+1,l,u)||Ot(r,A,t,n,i,s,a,o,c+1,l,u);else if(R)if(M)E=Ot(r,O,t,n,i,s,a,o,c+1,l,u);else{const I=ln.getPrimitive();I.copy(fo).applyMatrix4(t);const U=ze(r),L=Ne(r,x);be(U,m,Fn),be(L,m,Vn);const J=I.intersectsBox(Fn),H=I.intersectsBox(Vn);E=J&&Ot(O,U,n,t,i,a,s,c,o+1,I,!u)||H&&Ot(O,L,n,t,i,a,s,c,o+1,I,!u),ln.releasePrimitive(I)}else if(B)if(M)E=Ot(r,A,t,n,i,s,a,o,c+1,l,u);else{const I=ln.getPrimitive();I.copy(mo).applyMatrix4(t);const U=ze(r),L=Ne(r,x);be(U,m,Fn),be(L,m,Vn);const J=I.intersectsBox(Fn),H=I.intersectsBox(Vn);E=J&&Ot(A,U,n,t,i,a,s,c,o+1,I,!u)||H&&Ot(A,L,n,t,i,a,s,c,o+1,I,!u),ln.releasePrimitive(I)}}return E}const dl=new zt,jn=new Float32Array(6);class pl{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...ol,...e},Jd(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,n,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0;for(let d=e,f=e+t;d<f;d++){this.writePrimitiveBounds(d,jn,0);const[m,x,_,g,v,w]=jn;m<s&&(s=m),g>c&&(c=g),x<a&&(a=x),v>l&&(l=v),_<o&&(o=_),w>u&&(u=w)}return n[i+0]=s,n[i+1]=a,n[i+2]=o,n[i+3]=c,n[i+4]=l,n[i+5]=u,n}computePrimitiveBounds(e,t,n){const i=n.offset||0;for(let s=e,a=e+t;s<a;s++){this.writePrimitiveBounds(s,jn,0);const[o,c,l,u,d,f]=jn,m=(o+u)/2,x=(c+d)/2,_=(l+f)/2,g=(u-o)/2,v=(d-c)/2,w=(f-l)/2,S=(s-i)*6;n[S+0]=m,n[S+1]=g+(Math.abs(m)+g)*Or,n[S+2]=x,n[S+3]=v+(Math.abs(x)+v)*Or,n[S+4]=_,n[S+5]=w+(Math.abs(_)+w)*Or}return n}shiftPrimitiveOffsets(e){const t=this._indirectBuffer;if(t)for(let n=0,i=t.length;n<i;n++)t[n]+=e;else{const n=this._roots;for(let i=0;i<n.length;i++){const s=n[i],a=new Uint32Array(s),o=new Uint16Array(s),c=s.byteLength/qe;for(let l=0;l<c;l++){const u=Pe*l,d=2*u;Ee(d,o)&&(a[u+6]+=e)}}}}traverse(e,t=0){const n=this._roots[t],i=new Uint32Array(n),s=new Uint16Array(n);a(0);function a(o,c=0){const l=o*2,u=Ee(l,s);if(u){const d=i[o+6],f=s[l+14];e(c,u,new Float32Array(n,o*4,6),d,f)}else{const d=ze(o),f=Ne(o,i),m=so(o,i);e(c,u,new Float32Array(n,o*4,6),m)||(a(d,c+1),a(f,c+1))}}}refit(){const e=this._roots;for(let t=0,n=e.length;t<n;t++){const i=e[t],s=new Uint32Array(i),a=new Uint16Array(i),o=new Float32Array(i),c=i.byteLength/qe;for(let l=c-1;l>=0;l--){const u=l*Pe,d=u*2;if(Ee(d,a)){const f=Xe(u,s),m=it(d,a);this.writePrimitiveRangeBounds(f,m,jn,0),o.set(jn,u)}else{const f=ze(u),m=Ne(u,s);for(let x=0;x<3;x++){const _=o[f+x],g=o[f+x+3],v=o[m+x],w=o[m+x+3];o[u+x]=_<v?_:v,o[u+x+3]=g>w?g:w}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{be(0,new Float32Array(t),dl),e.union(dl)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:i,intersectsPrimitive:s,scratchPrimitive:a,iterate:o}=e;if(i&&s){const d=i;i=(f,m,x,_,g)=>d(f,m,x,_,g)?!0:o(f,m,this,s,x,_,a)}else i||(s?i=(d,f,m,x)=>o(d,f,this,s,m,x,a):i=(d,f,m)=>m);let c=!1,l=0;const u=this._roots;for(let d=0,f=u.length;d<f;d++){const m=u[d];if(c=Wd(this,d,n,i,t,l),c)break;l+=m.byteLength/qe}return c}bvhcast(e,t,n){let{intersectsRanges:i}=n;return Hd(this,e,t,i)}}function qd(){return typeof SharedArrayBuffer<"u"}function go(r){return r.index?r.index.count:r.attributes.position.count}function Lr(r){return go(r)/3}function Xd(r,e=ArrayBuffer){return r>65535?new Uint32Array(new e(4*r)):new Uint16Array(new e(2*r))}function Yd(r,e){if(!r.index){const t=r.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Xd(t,n);r.setIndex(new dt(i,1));for(let s=0;s<t;s++)i[s]=s}}function Zd(r,e,t){const n=go(r)/t,i=e||r.drawRange,s=i.start/t,a=(i.start+i.count)/t,o=Math.max(0,s),c=Math.min(n,a)-o;return{offset:Math.floor(o),count:Math.floor(c)}}function Kd(r,e){return r.groups.map(t=>({offset:t.start/e,count:t.count/e}))}function fl(r,e,t){const n=Zd(r,e,t),i=Kd(r,t);if(!i.length)return[n];const s=[],a=n.offset,o=n.offset+n.count,c=go(r)/t,l=[];for(const f of i){const{offset:m,count:x}=f,_=m,g=isFinite(x)?x:c-m,v=m+g;_<o&&v>a&&(l.push({pos:Math.max(a,_),isStart:!0}),l.push({pos:Math.min(o,v),isStart:!1}))}l.sort((f,m)=>f.pos!==m.pos?f.pos-m.pos:f.type==="end"?-1:1);let u=0,d=null;for(const f of l){const m=f.pos;u!==0&&m!==d&&s.push({offset:d,count:m-d}),u+=f.isStart?1:-1,d=m}return s}function ml(r,e){const t=r[r.length-1],n=t.offset+t.count>2**16,i=r.reduce((l,u)=>l+u.count,0),s=n?4:2,a=e?new SharedArrayBuffer(i*s):new ArrayBuffer(i*s),o=n?new Uint32Array(a):new Uint16Array(a);let c=0;for(let l=0;l<r.length;l++){const{offset:u,count:d}=r[l];for(let f=0;f<d;f++)o[c+f]=u+f;c+=d}return o}class yl extends pl{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(t.useSharedArrayBuffer&&!qd())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?n=>this._indirectBuffer[n]:n=>n,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...ol,...t},t[Ir]||this.init(t)}init(e){const{geometry:t,primitiveStride:n}=this;if(e.indirect){const i=fl(t,e.range,n),s=ml(i,e.useSharedArrayBuffer);this._indirectBuffer=s}else Yd(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new zt))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:fl(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class Qt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,i=-1/0;for(let s=0,a=e.length;s<a;s++){const o=e[s][t];n=o<n?o:n,i=o>i?o:i}this.min=n,this.max=i}setFromPoints(e,t){let n=1/0,i=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);n=c<n?c:n,i=c>i?c:i}this.min=n,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}Qt.prototype.setFromBox=function(){const r=new q;return function(e,t){const n=t.min,i=t.max;let s=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let l=0;l<=1;l++){r.x=n.x*o+i.x*(1-o),r.y=n.y*c+i.y*(1-c),r.z=n.z*l+i.z*(1-l);const u=e.dot(r);s=Math.min(u,s),a=Math.max(u,a)}this.min=s,this.max=a}}();const Qd=function(){const r=new q,e=new q,t=new q;return function(n,i,s){const a=n.start,o=r,c=i.start,l=e;t.subVectors(a,c),r.subVectors(n.end,n.start),e.subVectors(i.end,i.start);const u=t.dot(l),d=l.dot(o),f=l.dot(l),m=t.dot(o),x=o.dot(o)*f-d*d;let _,g;x!==0?_=(u*d-m*f)/x:_=0,g=(u+_*d)/f,s.x=_,s.y=g}}(),vo=function(){const r=new nn,e=new q,t=new q;return function(n,i,s,a){Qd(n,i,r);let o=r.x,c=r.y;if(o>=0&&o<=1&&c>=0&&c<=1){n.at(o,s),i.at(c,a);return}else if(o>=0&&o<=1){c<0?i.at(0,a):i.at(1,a),n.closestPointToPoint(a,!0,s);return}else if(c>=0&&c<=1){o<0?n.at(0,s):n.at(1,s),i.closestPointToPoint(s,!0,a);return}else{let l;o<0?l=n.start:l=n.end;let u;c<0?u=i.start:u=i.end;const d=e,f=t;if(n.closestPointToPoint(u,!0,e),i.closestPointToPoint(l,!0,t),d.distanceToSquared(u)<=f.distanceToSquared(l)){s.copy(d),a.copy(u);return}else{s.copy(l),a.copy(f);return}}}}(),$d=function(){const r=new q,e=new q,t=new oa,n=new qt;return function(i,s){const{radius:a,center:o}=i,{a:c,b:l,c:u}=s;if(n.start=c,n.end=l,n.closestPointToPoint(o,!0,r).distanceTo(o)<=a||(n.start=c,n.end=u,n.closestPointToPoint(o,!0,r).distanceTo(o)<=a)||(n.start=l,n.end=u,n.closestPointToPoint(o,!0,r).distanceTo(o)<=a))return!0;const d=s.getPlane(t);if(Math.abs(d.distanceToPoint(o))<=a){const f=d.projectPoint(o,e);if(s.containsPoint(f))return!0}return!1}}(),ep=["x","y","z"],$t=1e-15,gl=$t*$t;function vt(r){return Math.abs(r)<$t}class St extends mn{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new q),this.satBounds=new Array(4).fill().map(()=>new Qt),this.points=[this.a,this.b,this.c],this.plane=new oa,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new qt,this.needsUpdate=!0}intersectsSphere(e){return $d(e,this)}update(){const e=this.a,t=this.b,n=this.c,i=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,i);const l=s[1],u=a[1];l.subVectors(e,t),u.setFromPoints(l,i);const d=s[2],f=a[2];d.subVectors(t,n),f.setFromPoints(d,i);const m=s[3],x=a[3];m.subVectors(n,e),x.setFromPoints(m,i);const _=l.length(),g=d.length(),v=m.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,_<$t?g<$t||v<$t?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):g<$t?v<$t?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):v<$t&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}St.prototype.closestPointToSegment=function(){const r=new q,e=new q,t=new qt;return function(n,i=null,s=null){const{start:a,end:o}=n,c=this.points;let l,u=1/0;for(let d=0;d<3;d++){const f=(d+1)%3;t.start.copy(c[d]),t.end.copy(c[f]),vo(t,n,r,e),l=r.distanceToSquared(e),l<u&&(u=l,i&&i.copy(r),s&&s.copy(e))}return this.closestPointToPoint(a,r),l=a.distanceToSquared(r),l<u&&(u=l,i&&i.copy(r),s&&s.copy(a)),this.closestPointToPoint(o,r),l=o.distanceToSquared(r),l<u&&(u=l,i&&i.copy(r),s&&s.copy(o)),Math.sqrt(u)}}(),St.prototype.intersectsTriangle=function(){const r=new St,e=new Qt,t=new Qt,n=new q,i=new q,s=new q,a=new q,o=new qt,c=new qt,l=new q,u=new nn,d=new nn;function f(S,T,M,P){const E=n;!S.isDegenerateIntoPoint&&!S.isDegenerateIntoSegment?E.copy(S.plane.normal):E.copy(T.plane.normal);const O=S.satBounds,A=S.satAxes;for(let I=1;I<4;I++){const U=O[I],L=A[I];if(e.setFromPoints(L,T.points),U.isSeparated(e)||(a.copy(E).cross(L),e.setFromPoints(a,S.points),t.setFromPoints(a,T.points),e.isSeparated(t)))return!1}const R=T.satBounds,B=T.satAxes;for(let I=1;I<4;I++){const U=R[I],L=B[I];if(e.setFromPoints(L,S.points),U.isSeparated(e)||(a.crossVectors(E,L),e.setFromPoints(a,S.points),t.setFromPoints(a,T.points),e.isSeparated(t)))return!1}return M&&(P||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),M.start.set(0,0,0),M.end.set(0,0,0)),!0}function m(S,T,M,P,E,O,A,R,B,I,U){let L=A/(A-R);I.x=P+(E-P)*L,U.start.subVectors(T,S).multiplyScalar(L).add(S),L=A/(A-B),I.y=P+(O-P)*L,U.end.subVectors(M,S).multiplyScalar(L).add(S)}function x(S,T,M,P,E,O,A,R,B,I,U){if(E>0)m(S.c,S.a,S.b,P,T,M,B,A,R,I,U);else if(O>0)m(S.b,S.a,S.c,M,T,P,R,A,B,I,U);else if(R*B>0||A!=0)m(S.a,S.b,S.c,T,M,P,A,R,B,I,U);else if(R!=0)m(S.b,S.a,S.c,M,T,P,R,A,B,I,U);else if(B!=0)m(S.c,S.a,S.b,P,T,M,B,A,R,I,U);else return!0;return!1}function _(S,T,M,P){const E=T.degenerateSegment,O=S.plane.distanceToPoint(E.start),A=S.plane.distanceToPoint(E.end);return vt(O)?vt(A)?f(S,T,M,P):(M&&(M.start.copy(E.start),M.end.copy(E.start)),S.containsPoint(E.start)):vt(A)?(M&&(M.start.copy(E.end),M.end.copy(E.end)),S.containsPoint(E.end)):S.plane.intersectLine(E,n)!=null?(M&&(M.start.copy(n),M.end.copy(n)),S.containsPoint(n)):!1}function g(S,T,M){const P=T.a;return vt(S.plane.distanceToPoint(P))&&S.containsPoint(P)?(M&&(M.start.copy(P),M.end.copy(P)),!0):!1}function v(S,T,M){const P=S.degenerateSegment,E=T.a;return P.closestPointToPoint(E,!0,n),E.distanceToSquared(n)<gl?(M&&(M.start.copy(E),M.end.copy(E)),!0):!1}function w(S,T,M,P){if(S.isDegenerateIntoSegment)if(T.isDegenerateIntoSegment){const E=S.degenerateSegment,O=T.degenerateSegment,A=i,R=s;E.delta(A),O.delta(R);const B=n.subVectors(O.start,E.start),I=A.x*R.y-A.y*R.x;if(vt(I))return!1;const U=(B.x*R.y-B.y*R.x)/I,L=-(A.x*B.y-A.y*B.x)/I;if(U<0||U>1||L<0||L>1)return!1;const J=E.start.z+A.z*U,H=O.start.z+R.z*L;return vt(J-H)?(M&&(M.start.copy(E.start).addScaledVector(A,U),M.end.copy(E.start).addScaledVector(A,U)),!0):!1}else return T.isDegenerateIntoPoint?v(S,T,M):_(T,S,M,P);else{if(S.isDegenerateIntoPoint)return T.isDegenerateIntoPoint?T.a.distanceToSquared(S.a)<gl?(M&&(M.start.copy(S.a),M.end.copy(S.a)),!0):!1:T.isDegenerateIntoSegment?v(T,S,M):g(T,S,M);if(T.isDegenerateIntoPoint)return g(S,T,M);if(T.isDegenerateIntoSegment)return _(S,T,M,P)}}return function(S,T=null,M=!1){this.needsUpdate&&this.update(),S.isExtendedTriangle?S.needsUpdate&&S.update():(r.copy(S),r.update(),S=r);const P=w(this,S,T,M);if(P!==void 0)return P;const E=this.plane,O=S.plane;let A=O.distanceToPoint(this.a),R=O.distanceToPoint(this.b),B=O.distanceToPoint(this.c);vt(A)&&(A=0),vt(R)&&(R=0),vt(B)&&(B=0);const I=A*R,U=A*B;if(I>0&&U>0)return!1;let L=E.distanceToPoint(S.a),J=E.distanceToPoint(S.b),H=E.distanceToPoint(S.c);vt(L)&&(L=0),vt(J)&&(J=0),vt(H)&&(H=0);const se=L*J,W=L*H;if(se>0&&W>0)return!1;i.copy(E.normal),s.copy(O.normal);const pe=i.cross(s);let ne=0,he=Math.abs(pe.x);const oe=Math.abs(pe.y);oe>he&&(he=oe,ne=1),Math.abs(pe.z)>he&&(ne=2);const le=ep[ne],xe=this.a[le],ge=this.b[le],de=this.c[le],re=S.a[le],Ze=S.b[le],Ue=S.c[le];if(x(this,xe,ge,de,I,U,A,R,B,u,o))return f(this,S,T,M);if(x(S,re,Ze,Ue,se,W,L,J,H,d,c))return f(this,S,T,M);if(u.y<u.x){const ke=u.y;u.y=u.x,u.x=ke,l.copy(o.start),o.start.copy(o.end),o.end.copy(l)}if(d.y<d.x){const ke=d.y;d.y=d.x,d.x=ke,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<d.x||d.y<u.x?!1:(T&&(d.x>u.x?T.start.copy(c.start):T.start.copy(o.start),d.y<u.y?T.end.copy(c.end):T.end.copy(o.end)),!0)}}(),St.prototype.distanceToPoint=function(){const r=new q;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}}(),St.prototype.distanceToTriangle=function(){const r=new q,e=new q,t=["a","b","c"],n=new qt,i=new qt;return function(s,a=null,o=null){const c=a||o?n:null;if(this.intersectsTriangle(s,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let l=1/0;for(let u=0;u<3;u++){let d;const f=t[u],m=s[f];this.closestPointToPoint(m,r),d=m.distanceToSquared(r),d<l&&(l=d,a&&a.copy(r),o&&o.copy(m));const x=this[f];s.closestPointToPoint(x,r),d=x.distanceToSquared(r),d<l&&(l=d,a&&a.copy(x),o&&o.copy(r))}for(let u=0;u<3;u++){const d=t[u],f=t[(u+1)%3];n.set(this[d],this[f]);for(let m=0;m<3;m++){const x=t[m],_=t[(m+1)%3];i.set(s[x],s[_]),vo(n,i,r,e);const g=r.distanceToSquared(e);g<l&&(l=g,a&&a.copy(r),o&&o.copy(e))}}return Math.sqrt(l)}}();class Ye{constructor(e,t,n){this.isOrientedBox=!0,this.min=new q,this.max=new q,this.matrix=new kt,this.invMatrix=new kt,this.points=new Array(8).fill().map(()=>new q),this.satAxes=new Array(3).fill().map(()=>new q),this.satBounds=new Array(3).fill().map(()=>new Qt),this.alignedSatBounds=new Array(3).fill().map(()=>new Qt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}Ye.prototype.update=function(){return function(){const r=this.matrix,e=this.min,t=this.max,n=this.points;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let u=0;u<=1;u++){const d=1*c|2*l|4*u,f=n[d];f.x=c?t.x:e.x,f.y=l?t.y:e.y,f.z=u?t.z:e.z,f.applyMatrix4(r)}const i=this.satBounds,s=this.satAxes,a=n[0];for(let c=0;c<3;c++){const l=s[c],u=i[c],d=1<<c,f=n[d];l.subVectors(a,f),u.setFromPoints(l,n)}const o=this.alignedSatBounds;o[0].setFromPointsField(n,"x"),o[1].setFromPointsField(n,"y"),o[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Ye.prototype.intersectsBox=function(){const r=new Qt;return function(e){this.needsUpdate&&this.update();const t=e.min,n=e.max,i=this.satBounds,s=this.satAxes,a=this.alignedSatBounds;if(r.min=t.x,r.max=n.x,a[0].isSeparated(r)||(r.min=t.y,r.max=n.y,a[1].isSeparated(r))||(r.min=t.z,r.max=n.z,a[2].isSeparated(r)))return!1;for(let o=0;o<3;o++){const c=s[o],l=i[o];if(r.setFromBox(c,e),l.isSeparated(r))return!1}return!0}}(),Ye.prototype.intersectsTriangle=function(){const r=new St,e=new Array(3),t=new Qt,n=new Qt,i=new q;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(r.copy(s),r.update(),s=r);const a=this.satBounds,o=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let d=0;d<3;d++){const f=a[d],m=o[d];if(t.setFromPoints(m,e),f.isSeparated(t))return!1}const c=s.satBounds,l=s.satAxes,u=this.points;for(let d=0;d<3;d++){const f=c[d],m=l[d];if(t.setFromPoints(m,u),f.isSeparated(t))return!1}for(let d=0;d<3;d++){const f=o[d];for(let m=0;m<4;m++){const x=l[m];if(i.crossVectors(f,x),t.setFromPoints(i,e),n.setFromPoints(i,u),t.isSeparated(n))return!1}}return!0}}(),Ye.prototype.closestPointToPoint=function(){return function(r,e){return this.needsUpdate&&this.update(),e.copy(r).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Ye.prototype.distanceToPoint=function(){const r=new q;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}}(),Ye.prototype.distanceToBox=function(){const r=["x","y","z"],e=new Array(12).fill().map(()=>new qt),t=new Array(12).fill().map(()=>new qt),n=new q,i=new q;return function(s,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(s))return(o||c)&&(s.getCenter(i),this.closestPointToPoint(i,n),s.closestPointToPoint(n,i),o&&o.copy(n),c&&c.copy(i)),0;const l=a*a,u=s.min,d=s.max,f=this.points;let m=1/0;for(let _=0;_<8;_++){const g=f[_];i.copy(g).clamp(u,d);const v=g.distanceToSquared(i);if(v<m&&(m=v,o&&o.copy(g),c&&c.copy(i),v<l))return Math.sqrt(v)}let x=0;for(let _=0;_<3;_++)for(let g=0;g<=1;g++)for(let v=0;v<=1;v++){const w=(_+1)%3,S=(_+2)%3,T=g<<w|v<<S,M=1<<_|g<<w|v<<S,P=f[T],E=f[M];e[x].set(P,E);const O=r[_],A=r[w],R=r[S],B=t[x],I=B.start,U=B.end;I[O]=u[O],I[A]=g?u[A]:d[A],I[R]=v?u[R]:d[A],U[O]=d[O],U[A]=g?u[A]:d[A],U[R]=v?u[R]:d[A],x++}for(let _=0;_<=1;_++)for(let g=0;g<=1;g++)for(let v=0;v<=1;v++){i.x=_?d.x:u.x,i.y=g?d.y:u.y,i.z=v?d.z:u.z,this.closestPointToPoint(i,n);const w=i.distanceToSquared(n);if(w<m&&(m=w,o&&o.copy(n),c&&c.copy(i),w<l))return Math.sqrt(w)}for(let _=0;_<12;_++){const g=e[_];for(let v=0;v<12;v++){const w=t[v];vo(g,w,n,i);const S=n.distanceToSquared(i);if(S<m&&(m=S,o&&o.copy(n),c&&c.copy(i),S<l))return Math.sqrt(S)}}return Math.sqrt(m)}}();class tp extends ho{constructor(){super(()=>new St)}}const bt=new tp,yi=new q,So=new q;function np(r,e,t={},n=0,i=1/0){const s=n*n,a=i*i;let o=1/0,c=null;if(r.shapecast({boundsTraverseOrder:u=>(yi.copy(e).clamp(u.min,u.max),yi.distanceToSquared(e)),intersectsBounds:(u,d,f)=>f<o&&f<a,intersectsTriangle:(u,d)=>{u.closestPointToPoint(e,yi);const f=e.distanceToSquared(yi);return f<o&&(So.copy(yi),o=f,c=d),f<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(So):t.point=So.clone(),t.distance=l,t.faceIndex=c,t}const Fr=parseInt(aa)>=169,ip=parseInt(aa)<=161,vn=new q,Sn=new q,bn=new q,Vr=new nn,jr=new nn,Jr=new nn,vl=new q,Sl=new q,bl=new q,gi=new q;function rp(r,e,t,n,i,s,a,o){let c;if(s===ru?c=r.intersectTriangle(n,t,e,!0,i):c=r.intersectTriangle(e,t,n,s!==Ss,i),c===null)return null;const l=r.origin.distanceTo(i);return l<a||l>o?null:{distance:l,point:i.clone()}}function xl(r,e,t,n,i,s,a,o,c,l,u){vn.fromBufferAttribute(e,s),Sn.fromBufferAttribute(e,a),bn.fromBufferAttribute(e,o);const d=rp(r,vn,Sn,bn,gi,c,l,u);if(d){if(n){Vr.fromBufferAttribute(n,s),jr.fromBufferAttribute(n,a),Jr.fromBufferAttribute(n,o),d.uv=new nn;const m=mn.getInterpolation(gi,vn,Sn,bn,Vr,jr,Jr,d.uv);Fr||(d.uv=m)}if(i){Vr.fromBufferAttribute(i,s),jr.fromBufferAttribute(i,a),Jr.fromBufferAttribute(i,o),d.uv1=new nn;const m=mn.getInterpolation(gi,vn,Sn,bn,Vr,jr,Jr,d.uv1);Fr||(d.uv1=m),ip&&(d.uv2=d.uv1)}if(t){vl.fromBufferAttribute(t,s),Sl.fromBufferAttribute(t,a),bl.fromBufferAttribute(t,o),d.normal=new q;const m=mn.getInterpolation(gi,vn,Sn,bn,vl,Sl,bl,d.normal);d.normal.dot(r.direction)>0&&d.normal.multiplyScalar(-1),Fr||(d.normal=m)}const f={a:s,b:a,c:o,normal:new q,materialIndex:0};if(mn.getNormal(vn,Sn,bn,f.normal),d.face=f,d.faceIndex=s,Fr){const m=new q;mn.getBarycoord(gi,vn,Sn,bn,m),d.barycoord=m}}return d}function wl(r){return r&&r.isMaterial?r.side:r}function Gr(r,e,t,n,i,s,a){const o=n*3;let c=o+0,l=o+1,u=o+2;const{index:d,groups:f}=r;r.index&&(c=d.getX(c),l=d.getX(l),u=d.getX(u));const{position:m,normal:x,uv:_,uv1:g}=r.attributes;if(Array.isArray(e)){const v=n*3;for(let w=0,S=f.length;w<S;w++){const{start:T,count:M,materialIndex:P}=f[w];if(v>=T&&v<T+M){const E=wl(e[P]),O=xl(t,m,x,_,g,c,l,u,E,s,a);if(O)if(O.faceIndex=n,O.face.materialIndex=P,i)i.push(O);else return O}}}else{const v=wl(e),w=xl(t,m,x,_,g,c,l,u,v,s,a);if(w)if(w.faceIndex=n,w.face.materialIndex=0,i)i.push(w);else return w}return null}function Ce(r,e,t,n){const i=r.a,s=r.b,a=r.c;let o=e,c=e+1,l=e+2;t&&(o=t.getX(o),c=t.getX(c),l=t.getX(l)),i.x=n.getX(o),i.y=n.getY(o),i.z=n.getZ(o),s.x=n.getX(c),s.y=n.getY(c),s.z=n.getZ(c),a.x=n.getX(l),a.y=n.getY(l),a.z=n.getZ(l)}function sp(r,e,t,n,i,s,a,o){const{geometry:c,_indirectBuffer:l}=r;for(let u=n,d=n+i;u<d;u++)Gr(c,e,t,u,s,a,o)}function op(r,e,t,n,i,s,a){const{geometry:o,_indirectBuffer:c}=r;let l=1/0,u=null;for(let d=n,f=n+i;d<f;d++){let m;m=Gr(o,e,t,d,null,s,a),m&&m.distance<l&&(u=m,l=m.distance)}return u}function ap(r,e,t,n,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=r,d=e+r;u<d;u++){let f;if(f=u,Ce(a,f*3,c,l),a.needsUpdate=!0,n(a,f,i,s))return!0}return!1}function cp(r,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=r.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const u=r._roots;for(let f=0,m=u.length;f<m;f++)s=u[f],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),d(0,l),l+=s.byteLength;function d(f,m,x=!1){const _=f*2;if(Ee(_,o)){const g=Xe(f,a),v=it(_,o);let w=1/0,S=1/0,T=1/0,M=-1/0,P=-1/0,E=-1/0;for(let O=3*g,A=3*(g+v);O<A;O++){let R=n[O];const B=i.getX(R),I=i.getY(R),U=i.getZ(R);B<w&&(w=B),B>M&&(M=B),I<S&&(S=I),I>P&&(P=I),U<T&&(T=U),U>E&&(E=U)}return c[f+0]!==w||c[f+1]!==S||c[f+2]!==T||c[f+3]!==M||c[f+4]!==P||c[f+5]!==E?(c[f+0]=w,c[f+1]=S,c[f+2]=T,c[f+3]=M,c[f+4]=P,c[f+5]=E,!0):!1}else{const g=ze(f),v=Ne(f,a);let w=x,S=!1,T=!1;if(e){if(!w){const R=g/Pe+m/qe,B=v/Pe+m/qe;S=e.has(R),T=e.has(B),w=!S&&!T}}else S=!0,T=!0;const M=w||S,P=w||T;let E=!1;M&&(E=d(g,m,w));let O=!1;P&&(O=d(v,m,w));const A=E||O;if(A)for(let R=0;R<3;R++){const B=g+R,I=v+R,U=c[B],L=c[B+3],J=c[I],H=c[I+3];c[f+R]=U<J?U:J,c[f+R+3]=L>H?L:H}return A}}}function un(r,e,t,n,i){let s,a,o,c,l,u;const d=1/t.direction.x,f=1/t.direction.y,m=1/t.direction.z,x=t.origin.x,_=t.origin.y,g=t.origin.z;let v=e[r],w=e[r+3],S=e[r+1],T=e[r+3+1],M=e[r+2],P=e[r+3+2];return d>=0?(s=(v-x)*d,a=(w-x)*d):(s=(w-x)*d,a=(v-x)*d),f>=0?(o=(S-_)*f,c=(T-_)*f):(o=(T-_)*f,c=(S-_)*f),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),m>=0?(l=(M-g)*m,u=(P-g)*m):(l=(P-g)*m,u=(M-g)*m),s>u||l>a)?!1:((l>s||s!==s)&&(s=l),(u<a||a!==a)&&(a=u),s<=i&&a>=n)}function lp(r,e,t,n,i,s,a,o){const{geometry:c,_indirectBuffer:l}=r;for(let u=n,d=n+i;u<d;u++){let f=l?l[u]:u;Gr(c,e,t,f,s,a,o)}}function up(r,e,t,n,i,s,a){const{geometry:o,_indirectBuffer:c}=r;let l=1/0,u=null;for(let d=n,f=n+i;d<f;d++){let m;m=Gr(o,e,t,c?c[d]:d,null,s,a),m&&m.distance<l&&(u=m,l=m.distance)}return u}function hp(r,e,t,n,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=r,d=e+r;u<d;u++){let f;if(f=t.resolveTriangleIndex(u),Ce(a,f*3,c,l),a.needsUpdate=!0,n(a,f,i,s))return!0}return!1}function dp(r,e,t,n,i,s,a){ye.setBuffer(r._roots[e]),bo(0,r,t,n,i,s,a),ye.clearBuffer()}function bo(r,e,t,n,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=ye,u=r*2;if(Ee(u,c)){const d=Xe(r,l),f=it(u,c);sp(e,t,n,d,f,i,s,a)}else{const d=ze(r);un(d,o,n,s,a)&&bo(d,e,t,n,i,s,a);const f=Ne(r,l);un(f,o,n,s,a)&&bo(f,e,t,n,i,s,a)}}const pp=["x","y","z"];function fp(r,e,t,n,i,s){ye.setBuffer(r._roots[e]);const a=xo(0,r,t,n,i,s);return ye.clearBuffer(),a}function xo(r,e,t,n,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=ye;let l=r*2;if(Ee(l,o)){const u=Xe(r,c),d=it(l,o);return op(e,t,n,u,d,i,s)}else{const u=so(r,c),d=pp[u],f=n.direction[d]>=0;let m,x;f?(m=ze(r),x=Ne(r,c)):(m=Ne(r,c),x=ze(r));const _=un(m,a,n,i,s)?xo(m,e,t,n,i,s):null;if(_){const v=_.point[d];if(f?v<=a[x+u]:v>=a[x+u+3])return _}const g=un(x,a,n,i,s)?xo(x,e,t,n,i,s):null;return _&&g?_.distance<=g.distance?_:g:_||g||null}}const Wr=new zt,Jn=new St,Gn=new St,vi=new kt,_l=new Ye,Hr=new Ye;function mp(r,e,t,n){ye.setBuffer(r._roots[e]);const i=wo(0,r,t,n);return ye.clearBuffer(),i}function wo(r,e,t,n,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=ye;let c=r*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),_l.set(t.boundingBox.min,t.boundingBox.max,n),i=_l),Ee(c,a)){const l=e.geometry,u=l.index,d=l.attributes.position,f=t.index,m=t.attributes.position,x=Xe(r,o),_=it(c,a);if(vi.copy(n).invert(),t.boundsTree)return be(r,s,Hr),Hr.matrix.copy(vi),Hr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:g=>Hr.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(n),g.b.applyMatrix4(n),g.c.applyMatrix4(n),g.needsUpdate=!0;for(let v=x*3,w=(_+x)*3;v<w;v+=3)if(Ce(Gn,v,u,d),Gn.needsUpdate=!0,g.intersectsTriangle(Gn))return!0;return!1}});{const g=Lr(t);for(let v=x*3,w=(_+x)*3;v<w;v+=3){Ce(Jn,v,u,d),Jn.a.applyMatrix4(vi),Jn.b.applyMatrix4(vi),Jn.c.applyMatrix4(vi),Jn.needsUpdate=!0;for(let S=0,T=g*3;S<T;S+=3)if(Ce(Gn,S,f,m),Gn.needsUpdate=!0,Jn.intersectsTriangle(Gn))return!0}}}else{const l=ze(r),u=Ne(r,o);return be(l,s,Wr),!!(i.intersectsBox(Wr)&&wo(l,e,t,n,i)||(be(u,s,Wr),i.intersectsBox(Wr)&&wo(u,e,t,n,i)))}}const qr=new kt,_o=new Ye,Si=new Ye,yp=new q,gp=new q,vp=new q,Sp=new q;function bp(r,e,t,n={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),_o.set(e.boundingBox.min,e.boundingBox.max,t),_o.needsUpdate=!0;const o=r.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,d=e.index,f=bt.getPrimitive(),m=bt.getPrimitive();let x=yp,_=gp,g=null,v=null;i&&(g=vp,v=Sp);let w=1/0,S=null,T=null;return qr.copy(t).invert(),Si.matrix.copy(qr),r.shapecast({boundsTraverseOrder:M=>_o.distanceToBox(M),intersectsBounds:(M,P,E)=>E<w&&E<a?(P&&(Si.min.copy(M.min),Si.max.copy(M.max),Si.needsUpdate=!0),!0):!1,intersectsRange:(M,P)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:E=>Si.distanceToBox(E),intersectsBounds:(E,O,A)=>A<w&&A<a,intersectsRange:(E,O)=>{for(let A=E,R=E+O;A<R;A++){Ce(m,3*A,d,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let B=M,I=M+P;B<I;B++){Ce(f,3*B,l,c),f.needsUpdate=!0;const U=f.distanceToTriangle(m,x,g);if(U<w&&(_.copy(x),v&&v.copy(g),w=U,S=B,T=A),U<s)return!0}}}});{const E=Lr(e);for(let O=0,A=E;O<A;O++){Ce(m,3*O,d,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let R=M,B=M+P;R<B;R++){Ce(f,3*R,l,c),f.needsUpdate=!0;const I=f.distanceToTriangle(m,x,g);if(I<w&&(_.copy(x),v&&v.copy(g),w=I,S=R,T=O),I<s)return!0}}}}}),bt.releasePrimitive(f),bt.releasePrimitive(m),w===1/0?null:(n.point?n.point.copy(_):n.point=_.clone(),n.distance=w,n.faceIndex=S,i&&(i.point?i.point.copy(v):i.point=v.clone(),i.point.applyMatrix4(qr),_.applyMatrix4(qr),i.distance=_.sub(i.point).length(),i.faceIndex=T),n)}function xp(r,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=r.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const u=r._roots;for(let f=0,m=u.length;f<m;f++)s=u[f],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),d(0,l),l+=s.byteLength;function d(f,m,x=!1){const _=f*2;if(Ee(_,o)){const g=Xe(f,a),v=it(_,o);let w=1/0,S=1/0,T=1/0,M=-1/0,P=-1/0,E=-1/0;for(let O=g,A=g+v;O<A;O++){const R=3*r.resolveTriangleIndex(O);for(let B=0;B<3;B++){let I=R+B;I=n?n[I]:I;const U=i.getX(I),L=i.getY(I),J=i.getZ(I);U<w&&(w=U),U>M&&(M=U),L<S&&(S=L),L>P&&(P=L),J<T&&(T=J),J>E&&(E=J)}}return c[f+0]!==w||c[f+1]!==S||c[f+2]!==T||c[f+3]!==M||c[f+4]!==P||c[f+5]!==E?(c[f+0]=w,c[f+1]=S,c[f+2]=T,c[f+3]=M,c[f+4]=P,c[f+5]=E,!0):!1}else{const g=ze(f),v=Ne(f,a);let w=x,S=!1,T=!1;if(e){if(!w){const R=g/Pe+m/qe,B=v/Pe+m/qe;S=e.has(R),T=e.has(B),w=!S&&!T}}else S=!0,T=!0;const M=w||S,P=w||T;let E=!1;M&&(E=d(g,m,w));let O=!1;P&&(O=d(v,m,w));const A=E||O;if(A)for(let R=0;R<3;R++){const B=g+R,I=v+R,U=c[B],L=c[B+3],J=c[I],H=c[I+3];c[f+R]=U<J?U:J,c[f+R+3]=L>H?L:H}return A}}}function wp(r,e,t,n,i,s,a){ye.setBuffer(r._roots[e]),To(0,r,t,n,i,s,a),ye.clearBuffer()}function To(r,e,t,n,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=ye,u=r*2;if(Ee(u,c)){const d=Xe(r,l),f=it(u,c);lp(e,t,n,d,f,i,s,a)}else{const d=ze(r);un(d,o,n,s,a)&&To(d,e,t,n,i,s,a);const f=Ne(r,l);un(f,o,n,s,a)&&To(f,e,t,n,i,s,a)}}const _p=["x","y","z"];function Tp(r,e,t,n,i,s){ye.setBuffer(r._roots[e]);const a=Mo(0,r,t,n,i,s);return ye.clearBuffer(),a}function Mo(r,e,t,n,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=ye;let l=r*2;if(Ee(l,o)){const u=Xe(r,c),d=it(l,o);return up(e,t,n,u,d,i,s)}else{const u=so(r,c),d=_p[u],f=n.direction[d]>=0;let m,x;f?(m=ze(r),x=Ne(r,c)):(m=Ne(r,c),x=ze(r));const _=un(m,a,n,i,s)?Mo(m,e,t,n,i,s):null;if(_){const v=_.point[d];if(f?v<=a[x+u]:v>=a[x+u+3])return _}const g=un(x,a,n,i,s)?Mo(x,e,t,n,i,s):null;return _&&g?_.distance<=g.distance?_:g:_||g||null}}const Xr=new zt,Wn=new St,Hn=new St,bi=new kt,Tl=new Ye,Yr=new Ye;function Mp(r,e,t,n){ye.setBuffer(r._roots[e]);const i=Co(0,r,t,n);return ye.clearBuffer(),i}function Co(r,e,t,n,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=ye;let c=r*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Tl.set(t.boundingBox.min,t.boundingBox.max,n),i=Tl),Ee(c,a)){const l=e.geometry,u=l.index,d=l.attributes.position,f=t.index,m=t.attributes.position,x=Xe(r,o),_=it(c,a);if(bi.copy(n).invert(),t.boundsTree)return be(r,s,Yr),Yr.matrix.copy(bi),Yr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:g=>Yr.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(n),g.b.applyMatrix4(n),g.c.applyMatrix4(n),g.needsUpdate=!0;for(let v=x,w=_+x;v<w;v++)if(Ce(Hn,3*e.resolveTriangleIndex(v),u,d),Hn.needsUpdate=!0,g.intersectsTriangle(Hn))return!0;return!1}});{const g=Lr(t);for(let v=x,w=_+x;v<w;v++){const S=e.resolveTriangleIndex(v);Ce(Wn,3*S,u,d),Wn.a.applyMatrix4(bi),Wn.b.applyMatrix4(bi),Wn.c.applyMatrix4(bi),Wn.needsUpdate=!0;for(let T=0,M=g*3;T<M;T+=3)if(Ce(Hn,T,f,m),Hn.needsUpdate=!0,Wn.intersectsTriangle(Hn))return!0}}}else{const l=ze(r),u=Ne(r,o);return be(l,s,Xr),!!(i.intersectsBox(Xr)&&Co(l,e,t,n,i)||(be(u,s,Xr),i.intersectsBox(Xr)&&Co(u,e,t,n,i)))}}const Zr=new kt,Po=new Ye,xi=new Ye,Cp=new q,Pp=new q,Ep=new q,kp=new q;function Rp(r,e,t,n={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Po.set(e.boundingBox.min,e.boundingBox.max,t),Po.needsUpdate=!0;const o=r.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,d=e.index,f=bt.getPrimitive(),m=bt.getPrimitive();let x=Cp,_=Pp,g=null,v=null;i&&(g=Ep,v=kp);let w=1/0,S=null,T=null;return Zr.copy(t).invert(),xi.matrix.copy(Zr),r.shapecast({boundsTraverseOrder:M=>Po.distanceToBox(M),intersectsBounds:(M,P,E)=>E<w&&E<a?(P&&(xi.min.copy(M.min),xi.max.copy(M.max),xi.needsUpdate=!0),!0):!1,intersectsRange:(M,P)=>{if(e.boundsTree){const E=e.boundsTree;return E.shapecast({boundsTraverseOrder:O=>xi.distanceToBox(O),intersectsBounds:(O,A,R)=>R<w&&R<a,intersectsRange:(O,A)=>{for(let R=O,B=O+A;R<B;R++){const I=E.resolveTriangleIndex(R);Ce(m,3*I,d,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let U=M,L=M+P;U<L;U++){const J=r.resolveTriangleIndex(U);Ce(f,3*J,l,c),f.needsUpdate=!0;const H=f.distanceToTriangle(m,x,g);if(H<w&&(_.copy(x),v&&v.copy(g),w=H,S=U,T=R),H<s)return!0}}}})}else{const E=Lr(e);for(let O=0,A=E;O<A;O++){Ce(m,3*O,d,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let R=M,B=M+P;R<B;R++){const I=r.resolveTriangleIndex(R);Ce(f,3*I,l,c),f.needsUpdate=!0;const U=f.distanceToTriangle(m,x,g);if(U<w&&(_.copy(x),v&&v.copy(g),w=U,S=R,T=O),U<s)return!0}}}}}),bt.releasePrimitive(f),bt.releasePrimitive(m),w===1/0?null:(n.point?n.point.copy(_):n.point=_.clone(),n.distance=w,n.faceIndex=S,i&&(i.point?i.point.copy(v):i.point=v.clone(),i.point.applyMatrix4(Zr),_.applyMatrix4(Zr),i.distance=_.sub(i.point).length(),i.faceIndex=T),n)}function Ml(r,e,t){return r===null?null:(r.point.applyMatrix4(e.matrixWorld),r.distance=r.point.distanceTo(t.ray.origin),r.object=e,r)}const Kr=new Ye,Qr=new su,Cl=new q,Pl=new kt,El=new q,Eo=["getX","getY","getZ"];class Kn extends yl{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,i=e._roots,s=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=i.map(c=>c.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=s?s.slice():null):(o.roots=i,o.index=a?a.array:null,o.indirectBuffer=s),o}static deserialize(e,t,n={}){n={setIndex:!0,indirect:!!e.indirectBuffer,...n};const{index:i,roots:s,indirectBuffer:a}=e;e.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),c(s));const o=new Kn(t,{...n,[Ir]:!0});if(o._roots=s,o._indirectBuffer=a||null,n.setIndex){const l=t.getIndex();if(l===null){const u=new dt(e.index,1,!1);t.setIndex(u)}else l.array!==i&&(l.array.set(i),l.needsUpdate=!0)}return o;function c(l){for(let u=0;u<l.length;u++){const d=l[u],f=new Uint32Array(d),m=new Uint16Array(d);for(let x=0,_=d.byteLength/qe;x<_;x++){const g=Pe*x,v=2*g;Ee(v,m)||(f[g+6]=f[g+6]/Pe-x)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),t={...t,maxLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){const i=this.geometry,s=this._indirectBuffer,a=i.attributes.position,o=i.index?i.index.array:null,c=(s?s[e]:e)*3;let l=c+0,u=c+1,d=c+2;o&&(l=o[l],u=o[u],d=o[d]);for(let f=0;f<3;f++){const m=a[Eo[f]](l),x=a[Eo[f]](u),_=a[Eo[f]](d);let g=m;x<g&&(g=x),_<g&&(g=_);let v=m;x>v&&(v=x),_>v&&(v=_),t[n+f]=g,t[n+f+3]=v}return t}computePrimitiveBounds(e,t,n){const i=this.geometry,s=this._indirectBuffer,a=i.attributes.position,o=i.index?i.index.array:null,c=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=a.array,u=a.offset||0;let d=3;a.isInterleavedBufferAttribute&&(d=a.data.stride);const f=["getX","getY","getZ"],m=n.offset;for(let x=e,_=e+t;x<_;x++){const g=(s?s[x]:x)*3,v=(x-m)*6;let w=g+0,S=g+1,T=g+2;o&&(w=o[w],S=o[S],T=o[T]),c||(w=w*d+u,S=S*d+u,T=T*d+u);for(let M=0;M<3;M++){let P,E,O;c?(P=a[f[M]](w),E=a[f[M]](S),O=a[f[M]](T)):(P=l[w+M],E=l[S+M],O=l[T+M]);let A=P;E<A&&(A=E),O<A&&(A=O);let R=P;E>R&&(R=E),O>R&&(R=O);const B=(R-A)/2,I=M*2;n[v+I+0]=A+B,n[v+I+1]=B+(Math.abs(A)+B)*Or}}return n}raycastObject3D(e,t,n=[]){const{material:i}=e;if(i===void 0)return;Pl.copy(e.matrixWorld).invert(),Qr.copy(t.ray).applyMatrix4(Pl),El.setFromMatrixScale(e.matrixWorld),Cl.copy(Qr.direction).multiply(El);const s=Cl.length(),a=t.near/s,o=t.far/s;if(t.firstHitOnly===!0){let c=this.raycastFirst(Qr,i,a,o);c=Ml(c,e,t),c&&n.push(c)}else{const c=this.raycast(Qr,i,a,o);for(let l=0,u=c.length;l<u;l++){const d=Ml(c[l],e,t);d&&n.push(d)}}return n}refit(e=null){return(this.indirect?xp:cp)(this,e)}raycast(e,t=ca,n=0,i=1/0){const s=this._roots,a=[],o=this.indirect?wp:dp;for(let c=0,l=s.length;c<l;c++)o(this,c,t,e,a,n,i);return a}raycastFirst(e,t=ca,n=0,i=1/0){const s=this._roots;let a=null;const o=this.indirect?Tp:fp;for(let c=0,l=s.length;c<l;c++){const u=o(this,c,t,e,n,i);u!=null&&(a==null||u.distance<a.distance)&&(a=u)}return a}intersectsGeometry(e,t){let n=!1;const i=this._roots,s=this.indirect?Mp:mp;for(let a=0,o=i.length;a<o&&(n=s(this,a,e,t),!n);a++);return n}shapecast(e){const t=bt.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?hp:ap});return bt.releasePrimitive(t),n}bvhcast(e,t,n){let{intersectsRanges:i,intersectsTriangles:s}=n;const a=bt.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?x=>{const _=this.resolveTriangleIndex(x);Ce(a,_*3,o,c)}:x=>{Ce(a,x*3,o,c)},u=bt.getPrimitive(),d=e.geometry.index,f=e.geometry.attributes.position,m=e.indirect?x=>{const _=e.resolveTriangleIndex(x);Ce(u,_*3,d,f)}:x=>{Ce(u,x*3,d,f)};if(s){if(!(e instanceof Kn))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const x=(_,g,v,w,S,T,M,P)=>{for(let E=v,O=v+w;E<O;E++){m(E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let A=_,R=_+g;A<R;A++)if(l(A),a.needsUpdate=!0,s(a,u,A,E,S,T,M,P))return!0}return!1};if(i){const _=i;i=function(g,v,w,S,T,M,P,E){return _(g,v,w,S,T,M,P,E)?!0:x(g,v,w,S,T,M,P,E)}}else i=x}return super.bvhcast(e,t,{intersectsRanges:i})}intersectsBox(e,t){return Kr.set(e.min,e.max,t),Kr.needsUpdate=!0,this.shapecast({intersectsBounds:n=>Kr.intersectsBox(n),intersectsTriangle:n=>Kr.intersectsTriangle(n)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},i={},s=0,a=1/0){return(this.indirect?Rp:bp)(this,e,t,n,i,s,a)}closestPointToPoint(e,t={},n=0,i=1/0){return np(this,e,t,n,i)}}const qn={Mesh:lr.prototype.raycast,Line:ha.prototype.raycast,LineSegments:la.prototype.raycast,LineLoop:ua.prototype.raycast,Points:da.prototype.raycast,BatchedMesh:au.prototype.raycast},Je=new lr,$r=[];function Ap(r,e){if(this.isBatchedMesh)Op.call(this,r,e);else{const{geometry:t}=this;if(t.boundsTree)t.boundsTree.raycastObject3D(this,r,e);else{let n;if(this instanceof lr)n=qn.Mesh;else if(this instanceof la)n=qn.LineSegments;else if(this instanceof ua)n=qn.LineLoop;else if(this instanceof ha)n=qn.Line;else if(this instanceof da)n=qn.Points;else throw new Error("BVH: Fallback raycast function not found.");n.call(this,r,e)}}}function Op(r,e){if(this.boundsTrees){const t=this.boundsTrees,n=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,s=this.matrixWorld;Je.material=this.material,Je.geometry=this.geometry;const a=Je.geometry.boundsTree,o=Je.geometry.drawRange;Je.geometry.boundingSphere===null&&(Je.geometry.boundingSphere=new ou);for(let c=0,l=n.length;c<l;c++){if(!this.getVisibleAt(c))continue;const u=n[c].geometryIndex;if(Je.geometry.boundsTree=t[u],this.getMatrixAt(c,Je.matrixWorld).premultiply(s),!Je.geometry.boundsTree){this.getBoundingBoxAt(u,Je.geometry.boundingBox),this.getBoundingSphereAt(u,Je.geometry.boundingSphere);const d=i[u];Je.geometry.setDrawRange(d.start,d.count)}Je.raycast(r,$r);for(let d=0,f=$r.length;d<f;d++){const m=$r[d];m.object=this,m.batchId=c,e.push(m)}$r.length=0}Je.geometry.boundsTree=a,Je.geometry.drawRange=o,Je.material=null,Je.geometry=null}else qn.BatchedMesh.call(this,r,e)}function Ip(r={}){const{type:e=Kn}=r;return this.boundsTree=new e(this,r),this.boundsTree}const xn=new q,wn=new q,_n=new q,kl=new xs,es=new q,ko=new q,Rl=new xs,Al=new xs,ts=new kt,Ol=new kt;function wi(r,e){if(!r&&!e)return;const t=r.count===e.count,n=r.normalized===e.normalized,i=r.array.constructor===e.array.constructor,s=r.itemSize===e.itemSize;if(!t||!n||!i||!s)throw new Error}function _i(r,e=null){const t=r.array.constructor,n=r.normalized,i=r.itemSize,s=e===null?r.count:e;return new dt(new t(i*s),i,n)}function Il(r,e,t=0){if(r.isInterleavedBufferAttribute){const n=r.itemSize;for(let i=0,s=r.count;i<s;i++){const a=i+t;e.setX(a,r.getX(i)),n>=2&&e.setY(a,r.getY(i)),n>=3&&e.setZ(a,r.getZ(i)),n>=4&&e.setW(a,r.getW(i))}}else{const n=e.array,i=n.constructor,s=n.BYTES_PER_ELEMENT*r.itemSize*t;new i(n.buffer,s,r.array.length).set(r.array)}}function Bp(r,e,t){const n=r.elements,i=e.elements;for(let s=0,a=i.length;s<a;s++)n[s]+=i[s]*t}function Bl(r,e,t){const n=r.skeleton,i=r.geometry,s=n.bones,a=n.boneInverses;Rl.fromBufferAttribute(i.attributes.skinIndex,e),Al.fromBufferAttribute(i.attributes.skinWeight,e),ts.elements.fill(0);for(let o=0;o<4;o++){const c=Al.getComponent(o);if(c!==0){const l=Rl.getComponent(o);Ol.multiplyMatrices(s[l].matrixWorld,a[l]),Bp(ts,Ol,c)}}return ts.multiply(r.bindMatrix).premultiply(r.bindMatrixInverse),t.transformDirection(ts),t}function Ro(r,e,t,n,i){es.set(0,0,0);for(let s=0,a=r.length;s<a;s++){const o=e[s],c=r[s];o!==0&&(ko.fromBufferAttribute(c,n),t?es.addScaledVector(ko,o):es.addScaledVector(ko.sub(i),o))}i.add(es)}function zp(r,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new ti){const n=r[0].index!==null,{useGroups:i=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(r[0].attributes)),c={};let l=0;t.clearGroups();for(let u=0;u<r.length;++u){const d=r[u];let f=0;if(n!==(d.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const m in d.attributes){if(!o.has(m))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+m+'" attribute exists among all geometries, or in none of them.');c[m]===void 0&&(c[m]=[]),c[m].push(d.attributes[m]),f++}if(f!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(i){let m;if(n)m=d.index.count;else if(d.attributes.position!==void 0)m=d.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,m,u),l+=m}}if(n){let u=!1;if(!t.index){let d=0;for(let f=0;f<r.length;++f)d+=r[f].index.count;t.setIndex(new dt(new Uint32Array(d),1,!1)),u=!0}if(s||u){const d=t.index;let f=0,m=0;for(let x=0;x<r.length;++x){const _=r[x],g=_.index;if(a[x]!==!0)for(let v=0;v<g.count;++v)d.setX(f,g.getX(v)+m),f++;m+=_.attributes.position.count}}}for(const u in c){const d=c[u];if(!(u in t.attributes)){let x=0;for(const _ in d)x+=d[_].count;t.setAttribute(u,_i(c[u][0],x))}const f=t.attributes[u];let m=0;for(let x=0,_=d.length;x<_;x++){const g=d[x];a[x]!==!0&&Il(g,f,m),m+=g.count}}return t}function Np(r,e){if(r===null||e===null)return r===e;if(r.length!==e.length)return!1;for(let t=0,n=r.length;t<n;t++)if(r[t]!==e[t])return!1;return!0}function Up(r){const{index:e,attributes:t}=r;if(e)for(let n=0,i=e.count;n<i;n+=3){const s=e.getX(n),a=e.getX(n+2);e.setX(n,a),e.setX(n+2,s)}else for(const n in t){const i=t[n],s=i.itemSize;for(let a=0,o=i.count;a<o;a+=3)for(let c=0;c<s;c++){const l=i.getComponent(a,c),u=i.getComponent(a+2,c);i.setComponent(a,c,u),i.setComponent(a+2,c,l)}}return r}class Dp{constructor(e){this.matrixWorld=new kt,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,n=e.skeleton,i=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=i,n){n.boneTexture||n.computeBoneTexture(),n.update();const s=n.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==s.length?this.boneMatrices=s.slice():this.boneMatrices.set(s)}else this.boneMatrices=null}didChange(){const e=this.mesh,t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&Np(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===n)}}class Lp{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(n=>{n.traverseVisible(i=>{i.isMesh&&t.push(i)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(t.length).fill().map(()=>new ti),this._diffMap=new WeakMap}getMaterials(){const e=[];return this.meshes.forEach(t=>{Array.isArray(t.material)?e.push(...t.material):e.push(t.material)}),e}generate(e=new ti){let t=[];const{meshes:n,useGroups:i,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=n.length;o<c;o++){const l=n[o],u=s[o],d=a.get(l);!d||d.didChange(l)?(this._convertToStaticGeometry(l,u),t.push(!1),d?d.update():a.set(l,new Dp(l))):t.push(!0)}if(s.length===0){e.setIndex(null);const o=e.attributes;for(const c in o)e.deleteAttribute(c);for(const c in this.attributes)e.setAttribute(this.attributes[c],new dt(new Float32Array(0),4,!1))}else zp(s,{useGroups:i,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new ti){const n=e.geometry,i=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=n.attributes,c=t.attributes;!t.index&&n.index&&(t.index=n.index.clone()),c.position||t.setAttribute("position",_i(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",_i(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",_i(o.tangent)),wi(n.index,t.index),wi(o.position,c.position),s&&wi(o.normal,c.normal),a&&wi(o.tangent,c.tangent);const l=o.position,u=s?o.normal:null,d=a?o.tangent:null,f=n.morphAttributes.position,m=n.morphAttributes.normal,x=n.morphAttributes.tangent,_=n.morphTargetsRelative,g=e.morphTargetInfluences,v=new cu;v.getNormalMatrix(e.matrixWorld),n.index&&t.index.array.set(n.index.array);for(let w=0,S=o.position.count;w<S;w++)xn.fromBufferAttribute(l,w),u&&wn.fromBufferAttribute(u,w),d&&(kl.fromBufferAttribute(d,w),_n.fromBufferAttribute(d,w)),g&&(f&&Ro(f,g,_,w,xn),m&&Ro(m,g,_,w,wn),x&&Ro(x,g,_,w,_n)),e.isSkinnedMesh&&(e.applyBoneTransform(w,xn),u&&Bl(e,w,wn),d&&Bl(e,w,_n)),i&&xn.applyMatrix4(e.matrixWorld),c.position.setXYZ(w,xn.x,xn.y,xn.z),u&&(i&&wn.applyNormalMatrix(v),c.normal.setXYZ(w,wn.x,wn.y,wn.z)),d&&(i&&_n.transformDirection(e.matrixWorld),c.tangent.setXYZW(w,_n.x,_n.y,_n.z,kl.w));for(const w in this.attributes){const S=this.attributes[w];S==="position"||S==="tangent"||S==="normal"||!(S in o)||(c[S]||t.setAttribute(S,_i(o[S])),wi(o[S],c[S]),Il(o[S],c[S]))}return e.matrixWorld.determinant()<0&&Up(t),t}}const Fp=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:nl,BVH:pl,CENTER:no,CONTAINED:io,ExtendedTriangle:St,GeometryBVH:yl,MeshBVH:Kn,OrientedBox:Ye,SAH:il,SKIP_GENERATION:Ir,StaticGeometryGenerator:Lp,acceleratedRaycast:Ap,computeBoundsTree:Ip,generateIndirectBuffer:ml},Symbol.toStringTag,{value:"Module"}));class Vp{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}const xt={node:"node",material:"material",camera:"camera",light:"light"},Tn="KHR_animation_pointer",jp={CUBICSPLINE:void 0,LINEAR:pa,STEP:uu};class Jp{constructor(e){this.name=Tn,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,n=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",n)}loadAnimationTargetFromChannelWithAnimationPointer(e){Wp();const t=e.target,n=t.extensions&&t.extensions[Tn]&&t.path&&t.path==="pointer";if(!n)return null;let i,s=xt.node,a;if(n){const c=t.extensions[Tn];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=xt.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=xt.light:l.startsWith("/cameras/")&&(s=xt.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case xt.material:const u=("/materials/"+a.toString()+"/").length,d=l.substring(0,u);switch(i=l.substring(u),i){case"pbrMetallicRoughness/baseColorFactor":i="color";break;case"pbrMetallicRoughness/roughnessFactor":i="roughness";break;case"pbrMetallicRoughness/metallicFactor":i="metalness";break;case"emissiveFactor":i="emissive";break;case"alphaCutoff":i="alphaTest";break;case"occlusionTexture/strength":i="aoMapIntensity";break;case"normalTexture/scale":i="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":i="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":i="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":i="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":i="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":i="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":i="transmission";break;case"extensions/KHR_materials_ior/ior":i="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":i="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":i="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":i="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":i="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":i="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":i="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":i="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":i="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":i="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":i="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":i="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":i="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":i="specularColor";break}l=d+i;break;case xt.node:const f=("/nodes/"+a.toString()+"/").length,m=l.substring(0,f);switch(i=l.substring(f),i){case"translation":i="position";break;case"rotation":i="quaternion";break;case"scale":i="scale";break;case"weights":i="morphTargetInfluences";break;case"extensions/KHR_node_visibility/visible":i="visible";break}l=m+i;break;case xt.light:const x=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(i=l.substring(x),i){case"color":break;case"intensity":break;case"spot/innerConeAngle":i="penumbra";break;case"spot/outerConeAngle":i="angle";break;case"range":i="distance";break}l="/lights/"+a.toString()+"/"+i;break;case xt.camera:const _=("/cameras/"+a.toString()+"/").length,g=l.substring(0,_);switch(i=l.substring(_),i){case"perspective/yfov":i="fov";break;case"perspective/znear":case"orthographic/znear":i="near";break;case"perspective/zfar":case"orthographic/zfar":i="far";break;case"perspective/aspect":i="aspect";break;case"orthographic/xmag":i="zoom";break;case"orthographic/ymag":i="zoom";break}l=g+i;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[Tn].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===xt.node?o=this.parser.getDependency("node",a):s===xt.material?o=this.parser.getDependency("material",a):s===xt.light?o=this.parser.getDependency("light",a):s===xt.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,n,i,s){if(!(s.extensions&&s.extensions[Tn]&&s.path&&s.path==="pointer"))return null;let a=s.extensions[Tn].pointer;if(!a)return null;const o=[];a=a.replaceAll("/",".");const c=a.split(".");var l=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(c[2]=l,c[3]==="morphTargetInfluences"&&e.type==="Group"){for(const f of e.children)f instanceof lu&&f.morphTargetInfluences&&(c[3]=f.name,c[4]="morphTargetInfluences",d(this.parser));return o}d(this.parser);function u(f,m){try{const x=m.split(".").filter(Boolean),_=x[x.length-1].replace(/\[.*\]$/,"");return _ in f?typeof f[_]=="boolean":!1}catch{return!1}}function d(f){a=c.join(".");let m,x=!1;switch(n.itemSize){case 1:Object.prototype.toString.call(n.array)==="[object Uint8Array]"&&u(e,a)?(m=mu,x=!0):m=yu;break;case 2:case 3:m=fu;break;case 4:a.endsWith(".quaternion")?m=du:m=pu;break}if(!m){console.warn("Unsupported output accessor format",n);return}const _=i.interpolation!==void 0?jp[i.interpolation]:pa;let g=f._getArrayFromAccessor(n);a.endsWith(".fov")&&(g=g.map(w=>w/Math.PI*180)),x&&(g=g.map(w=>w>0));const v=new m(a,t.array,g,_);if(_==="CUBICSPLINE"&&f._createCubicSplineTrackInterpolant(v),o.push(v),a&&n.itemSize===4&&a.startsWith(".materials.")&&a.endsWith(".color")){const w=new Float32Array(g.length/4);for(let T=0,M=g.length/4;T<M;T+=1)w[T]=g[T*4+3];const S=new m(a.replace(".color",".opacity"),t.array,w,_);_==="CUBICSPLINE"&&f._createCubicSplineTrackInterpolant(v),o.push(S)}}return o}_tryResolveTargetId(e,t){let n="";return t==="node"?n=e.substring(7):t==="material"?n=e.substring(11):t==="light"?n=e.substring(39):t==="camera"&&(n=e.substring(9)),n=n.substring(0,n.indexOf("/")),Number.parseInt(n)}loadAnimation(e){const t=this,n=this.parser.json,i=this.parser,s=n.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],u=[],d=[];for(let f=0,m=s.channels.length;f<m;f++){const x=s.channels[f],_=s.samplers[x.sampler],g=x.target,v=s.parameters!==void 0?s.parameters[_.input]:_.input,w=s.parameters!==void 0?s.parameters[_.output]:_.output;let S=t.loadAnimationTargetFromChannelWithAnimationPointer(x);S||(S=t.loadAnimationTargetFromChannel(x)),o.push(S),c.push(i.getDependency("accessor",v)),l.push(i.getDependency("accessor",w)),u.push(_),d.push(g)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(u),Promise.all(d)]).then(function(f){const m=f[0],x=f[1],_=f[2],g=f[3],v=f[4],w=[];for(let S=0,T=m.length;S<T;S++){const M=m[S],P=x[S],E=_[S],O=g[S],A=v[S];if(M===void 0)continue;M.updateMatrix&&(M.updateMatrix(),M.matrixAutoUpdate=!0);let R=t.createAnimationTracksWithAnimationPointer(M,P,E,O,A);if(R||(R=i._createAnimationTracks(M,P,E,O,A)),R)for(let B=0;B<R.length;B++)w.push(R[B])}return new hu(a,void 0,w)})}}let zl=!1,Gp=null;function Wp(){if(zl)return;zl=!0;const r=Gp||=fa.findNode;fa.findNode=function(e,t){if(!t)return r(e,t);if(t.startsWith(".materials.")){const n=t.substring(11).substring(t.indexOf(".")),i=n.indexOf("."),s=i<0?n:n.substring(0,i);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(n.endsWith(".map")?a=a.map:n.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const n=t.split(".");let i;for(let s=1;s<n.length;s++){const a=n[s];if(a.length==36)i=e.getObjectByProperty("uuid",a);else if(i&&i[a]){const o=Number.parseInt(a);let c=a;o>=0&&(c=o),i=i[c]}else{const o=e.getObjectByName(a);o&&(i=o)}}if(!i){const s=r(e,n[2]);return s||console.warn(Tn+": Property binding not found",t,e,e.name,n),s}return i}return r(e,t)}}const Hp=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Jp},Symbol.toStringTag,{value:"Module"}));export{Xh as BatchedParticleRenderer,Ao as Builder,Ti as ByteBuffer,Cn as ConstantColor,te as ConstantValue,It as Matrix4,Kn as MeshBVH,Lu as MotionController,ss as ParticleSystem,V as RenderMode,_a as SIZE_PREFIX_LENGTH,Sr as TrailParticle,ct as Vector4,Vp as WorkerBase,xu as _md5,Od as bundler,Zh as createNoise4D,Bu as fetchProfile,zd as index,Fp as index$1,Hp as index$2,wa as md5,Ou as v5};
1116
+ isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},r}()),Lc={iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:["turn:eu-0.turn.peerjs.com:3478","turn:us-0.turn.peerjs.com:3478"],username:"peerjs",credential:"peerjsp"}],sdpSemantics:"unified-plan"},md=function(){function r(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=Lc,this.browser=li.getBrowser(),this.browserVersion=li.getVersion(),this.supports=function(){var e={browser:li.isBrowserSupported(),webRTC:li.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(Lc),e.audioVideo=!0;var n=void 0;try{n=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!n.ordered;try{n.binaryType="blob",e.binaryBlob=!li.isIOS}catch{}}catch{}finally{n&&n.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=Ha.pack,this.unpack=Ha.unpack,this._dataCount=1}return r.prototype.noop=function(){},r.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},r.prototype.chunk=function(e){for(var t=[],n=e.size,i=Math.ceil(n/ee.chunkedMTU),s=0,a=0;a<n;){var o=Math.min(n,a+ee.chunkedMTU),c=e.slice(a,o),l={__peerData:this._dataCount,n:s,data:c,total:i};t.push(l),a=o,s++}return this._dataCount++,t},r.prototype.blobToArrayBuffer=function(e,t){var n=new FileReader;return n.onload=function(i){i.target&&t(i.target.result)},n.readAsArrayBuffer(e),n},r.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t.buffer},r.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},r.prototype.isSecure=function(){return location.protocol==="https:"},r}(),ee=new md,Fc={};Ft(Fc,"Peer",()=>no,r=>no=r);var hi={},yd=Object.prototype.hasOwnProperty,nt="~";function ui(){}Object.create&&(ui.prototype=Object.create(null),new ui().__proto__||(nt=!1));function gd(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Vc(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new gd(t,n||r,i),a=nt?nt+e:e;return r._events[a]?r._events[a].fn?r._events[a]=[r._events[a],s]:r._events[a].push(s):(r._events[a]=s,r._eventsCount++),r}function Er(r,e){--r._eventsCount===0?r._events=new ui:delete r._events[e]}function He(){this._events=new ui,this._eventsCount=0}He.prototype.eventNames=function(){var r=[],e,t;if(this._eventsCount===0)return r;for(t in e=this._events)yd.call(e,t)&&r.push(nt?t.slice(1):t);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(e)):r},He.prototype.listeners=function(r){var e=nt?nt+r:r,t=this._events[e];if(!t)return[];if(t.fn)return[t.fn];for(var n=0,i=t.length,s=new Array(i);n<i;n++)s[n]=t[n].fn;return s},He.prototype.listenerCount=function(r){var e=nt?nt+r:r,t=this._events[e];return t?t.fn?1:t.length:0},He.prototype.emit=function(r,e,t,n,i,s){var a=nt?nt+r:r;if(!this._events[a])return!1;var o=this._events[a],c=arguments.length,l,u;if(o.fn){switch(o.once&&this.removeListener(r,o.fn,void 0,!0),c){case 1:return o.fn.call(o.context),!0;case 2:return o.fn.call(o.context,e),!0;case 3:return o.fn.call(o.context,e,t),!0;case 4:return o.fn.call(o.context,e,t,n),!0;case 5:return o.fn.call(o.context,e,t,n,i),!0;case 6:return o.fn.call(o.context,e,t,n,i,s),!0}for(u=1,l=new Array(c-1);u<c;u++)l[u-1]=arguments[u];o.fn.apply(o.context,l)}else{var d=o.length,m;for(u=0;u<d;u++)switch(o[u].once&&this.removeListener(r,o[u].fn,void 0,!0),c){case 1:o[u].fn.call(o[u].context);break;case 2:o[u].fn.call(o[u].context,e);break;case 3:o[u].fn.call(o[u].context,e,t);break;case 4:o[u].fn.call(o[u].context,e,t,n);break;default:if(!l)for(m=1,l=new Array(c-1);m<c;m++)l[m-1]=arguments[m];o[u].fn.apply(o[u].context,l)}}return!0},He.prototype.on=function(r,e,t){return Vc(this,r,e,t,!1)},He.prototype.once=function(r,e,t){return Vc(this,r,e,t,!0)},He.prototype.removeListener=function(r,e,t,n){var i=nt?nt+r:r;if(!this._events[i])return this;if(!e)return Er(this,i),this;var s=this._events[i];if(s.fn)s.fn===e&&(!n||s.once)&&(!t||s.context===t)&&Er(this,i);else{for(var a=0,o=[],c=s.length;a<c;a++)(s[a].fn!==e||n&&!s[a].once||t&&s[a].context!==t)&&o.push(s[a]);o.length?this._events[i]=o.length===1?o[0]:o:Er(this,i)}return this},He.prototype.removeAllListeners=function(r){var e;return r?(e=nt?nt+r:r,this._events[e]&&Er(this,e)):(this._events=new ui,this._eventsCount=0),this},He.prototype.off=He.prototype.removeListener,He.prototype.addListener=He.prototype.on,He.prefixed=nt,He.EventEmitter=He,hi=He;var j={};Ft(j,"LogLevel",()=>at,r=>at=r),Ft(j,"default",()=>jc,r=>jc=r);var yn=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},gn=function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},vd="PeerJS: ",at;(function(r){r[r.Disabled=0]="Disabled",r[r.Errors=1]="Errors",r[r.Warnings=2]="Warnings",r[r.All=3]="All"})(at||(at={}));var Sd=function(){function r(){this._logLevel=at.Disabled}return Object.defineProperty(r.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),r.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=at.All&&this._print.apply(this,gn([at.All],yn(e),!1))},r.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=at.Warnings&&this._print.apply(this,gn([at.Warnings],yn(e),!1))},r.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=at.Errors&&this._print.apply(this,gn([at.Errors],yn(e),!1))},r.prototype.setLogFunction=function(e){this._print=e},r.prototype._print=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var i=gn([vd],yn(t),!1);for(var s in i)i[s]instanceof Error&&(i[s]="("+i[s].name+") "+i[s].message);e>=at.All?console.log.apply(console,gn([],yn(i),!1)):e>=at.Warnings?console.warn.apply(console,gn(["WARNING"],yn(i),!1)):e>=at.Errors&&console.error.apply(console,gn(["ERROR"],yn(i),!1))},r}(),jc=new Sd,Jc={};Ft(Jc,"Socket",()=>Gc,r=>Gc=r);var At;(function(r){r.Data="data",r.Media="media"})(At||(At={}));var we;(function(r){r.BrowserIncompatible="browser-incompatible",r.Disconnected="disconnected",r.InvalidID="invalid-id",r.InvalidKey="invalid-key",r.Network="network",r.PeerUnavailable="peer-unavailable",r.SslUnavailable="ssl-unavailable",r.ServerError="server-error",r.SocketError="socket-error",r.SocketClosed="socket-closed",r.UnavailableID="unavailable-id",r.WebRTC="webrtc"})(we||(we={}));var Yt;(function(r){r.Binary="binary",r.BinaryUTF8="binary-utf8",r.JSON="json"})(Yt||(Yt={}));var Zt;(function(r){r.Message="message",r.Disconnected="disconnected",r.Error="error",r.Close="close"})(Zt||(Zt={}));var je;(function(r){r.Heartbeat="HEARTBEAT",r.Candidate="CANDIDATE",r.Offer="OFFER",r.Answer="ANSWER",r.Open="OPEN",r.Error="ERROR",r.IdTaken="ID-TAKEN",r.InvalidKey="INVALID-KEY",r.Leave="LEAVE",r.Expire="EXPIRE"})(je||(je={}));var Ks={};Ks=JSON.parse('{"name":"peerjs","version":"1.4.7","keywords":["peerjs","webrtc","p2p","rtc"],"description":"PeerJS client","homepage":"https://peerjs.com","bugs":{"url":"https://github.com/peers/peerjs/issues"},"repository":{"type":"git","url":"https://github.com/peers/peerjs"},"license":"MIT","contributors":["Michelle Bu <michelle@michellebu.com>","afrokick <devbyru@gmail.com>","ericz <really.ez@gmail.com>","Jairo <kidandcat@gmail.com>","Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>","Jairo Caro-Accino Viciana <jairo@galax.be>","Carlos Caballero <carlos.caballero.gonzalez@gmail.com>","hc <hheennrryy@gmail.com>","Muhammad Asif <capripio@gmail.com>","PrashoonB <prashoonbhattacharjee@gmail.com>","Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>","akotynski <aleksanderkotbury@gmail.com>","lmb <i@lmb.io>","Jairooo <jairocaro@msn.com>","Moritz St\xFCckler <moritz.stueckler@gmail.com>","Simon <crydotsnakegithub@gmail.com>","Denis Lukov <denismassters@gmail.com>","Philipp Hancke <fippo@andyet.net>","Hans Oksendahl <hansoksendahl@gmail.com>","Jess <jessachandler@gmail.com>","khankuan <khankuan@gmail.com>","DUODVK <kurmanov.work@gmail.com>","XiZhao <kwang1imsa@gmail.com>","Matthias Lohr <matthias@lohr.me>","=frank tree <=frnktrb@googlemail.com>","Andre Eckardt <aeckardt@outlook.com>","Chris Cowan <agentme49@gmail.com>","Alex Chuev <alex@chuev.com>","alxnull <alxnull@e.mail.de>","Yemel Jardi <angel.jardi@gmail.com>","Ben Parnell <benjaminparnell.94@gmail.com>","Benny Lichtner <bennlich@gmail.com>","fresheneesz <bitetrudpublic@gmail.com>","bob.barstead@exaptive.com <bob.barstead@exaptive.com>","chandika <chandika@gmail.com>","emersion <contact@emersion.fr>","Christopher Van <cvan@users.noreply.github.com>","eddieherm <edhermoso@gmail.com>","Eduardo Pinho <enet4mikeenet@gmail.com>","Evandro Zanatta <ezanatta@tray.net.br>","Gardner Bickford <gardner@users.noreply.github.com>","Gian Luca <gianluca.cecchi@cynny.com>","PatrickJS <github@gdi2290.com>","jonnyf <github@jonathanfoss.co.uk>","Hizkia Felix <hizkifw@gmail.com>","Hristo Oskov <hristo.oskov@gmail.com>","Isaac Madwed <i.madwed@gmail.com>","Ilya Konanykhin <ilya.konanykhin@gmail.com>","jasonbarry <jasbarry@me.com>","Jonathan Burke <jonathan.burke.1311@googlemail.com>","Josh Hamit <josh.hamit@gmail.com>","Jordan Austin <jrax86@gmail.com>","Joel Wetzell <jwetzell@yahoo.com>","xizhao <kevin.wang@cloudera.com>","Alberto Torres <kungfoobar@gmail.com>","Jonathan Mayol <mayoljonathan@gmail.com>","Jefferson Felix <me@jsfelix.dev>","Rolf Erik Lekang <me@rolflekang.com>","Kevin Mai-Husan Chia <mhchia@users.noreply.github.com>","Pepijn de Vos <pepijndevos@gmail.com>","JooYoung <qkdlql@naver.com>","Tobias Speicher <rootcommander@gmail.com>","Steve Blaurock <sblaurock@gmail.com>","Kyrylo Shegeda <shegeda@ualberta.ca>","Diwank Singh Tomer <singh@diwank.name>","So\u0308ren Balko <Soeren.Balko@gmail.com>","Arpit Solanki <solankiarpit1997@gmail.com>","Yuki Ito <yuki@gnnk.net>","Artur Zayats <zag2art@gmail.com>"],"funding":{"type":"opencollective","url":"https://opencollective.com/peer"},"collective":{"type":"opencollective","url":"https://opencollective.com/peer"},"files":["dist/*"],"sideEffects":["lib/global.ts","lib/supports.ts"],"main":"dist/bundler.cjs","module":"dist/bundler.mjs","browser-minified":"dist/peerjs.min.js","browser-unminified":"dist/peerjs.js","types":"dist/types.d.ts","engines":{"node":">= 10"},"targets":{"types":{"source":"lib/exports.ts"},"main":{"source":"lib/exports.ts","sourceMap":{"inlineSources":true}},"module":{"source":"lib/exports.ts","includeNodeModules":["eventemitter3"],"sourceMap":{"inlineSources":true}},"browser-minified":{"context":"browser","outputFormat":"global","optimize":true,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"},"browser-unminified":{"context":"browser","outputFormat":"global","optimize":false,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"}},"scripts":{"contributors":"git-authors-cli --print=false && prettier --write package.json && git add package.json package-lock.json && git commit -m \\"chore(contributors): update and sort contributors list\\"","check":"tsc --noEmit","watch":"parcel watch","build":"rm -rf dist && parcel build","prepublishOnly":"npm run build","test":"mocha -r ts-node/register -r jsdom-global/register test/**/*.ts","format":"prettier --write .","semantic-release":"semantic-release"},"devDependencies":{"@parcel/config-default":"^2.5.0","@parcel/packager-ts":"^2.5.0","@parcel/transformer-typescript-tsc":"^2.5.0","@parcel/transformer-typescript-types":"^2.5.0","@semantic-release/changelog":"^6.0.1","@semantic-release/git":"^10.0.1","@types/chai":"^4.3.0","@types/mocha":"^9.1.0","@types/node":"^17.0.18","chai":"^4.3.6","git-authors-cli":"^1.0.40","jsdom":"^19.0.0","jsdom-global":"^3.0.2","mocha":"^9.2.0","mock-socket":"8.0.5","parcel":"^2.5.0","parcel-transformer-tsc-sourcemaps":"^1.0.2","prettier":"^2.6.2","semantic-release":"^19.0.2","standard":"^16.0.4","ts-node":"^10.5.0","typescript":"^4.5.5"},"dependencies":{"@swc/helpers":"^0.3.13","eventemitter3":"^4.0.7","peerjs-js-binarypack":"1.0.1","webrtc-adapter":"^7.7.1"}}');var bd=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),xd=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},wd=function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},_d=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Gc=function(r){bd(e,r);function e(t,n,i,s,a,o){o===void 0&&(o=5e3);var c=r.call(this)||this;c.pingInterval=o,c._disconnected=!0,c._messagesQueue=[];var l=t?"wss://":"ws://";return c._baseUrl=l+n+":"+i+s+"peerjs?key="+a,c}return e.prototype.start=function(t,n){var i=this;this._id=t;var s="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(n);this._socket||!this._disconnected||(this._socket=new WebSocket(s+"&version="+Ks.version),this._disconnected=!1,this._socket.onmessage=function(a){var o;try{o=JSON.parse(a.data),j.default.log("Server message received:",o)}catch{j.default.log("Invalid server message",a.data);return}i.emit(Zt.Message,o)},this._socket.onclose=function(a){i._disconnected||(j.default.log("Socket closed.",a),i._cleanup(),i._disconnected=!0,i.emit(Zt.Disconnected))},this._socket.onopen=function(){i._disconnected||(i._sendQueuedMessages(),j.default.log("Socket open"),i._scheduleHeartbeat())})},e.prototype._scheduleHeartbeat=function(){var t=this;this._wsPingTimer=setTimeout(function(){t._sendHeartbeat()},this.pingInterval)},e.prototype._sendHeartbeat=function(){if(!this._wsOpen()){j.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:je.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,n,i=wd([],xd(this._messagesQueue),!1);this._messagesQueue=[];try{for(var s=_d(i),a=s.next();!a.done;a=s.next()){var o=a.value;this.send(o)}}catch(c){t={error:c}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},e.prototype.send=function(t){if(!this._disconnected){if(!this._id){this._messagesQueue.push(t);return}if(!t.type){this.emit(Zt.Error,"Invalid message");return}if(this._wsOpen()){var n=JSON.stringify(t);this._socket.send(n)}}},e.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},e.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)},e}(hi.EventEmitter),Qs={};Ft(Qs,"MediaConnection",()=>qc,r=>qc=r);var $s={};Ft($s,"Negotiator",()=>Wc,r=>Wc=r);var kr=function(){return kr=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},kr.apply(this,arguments)},Rr=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(n.next(u))}catch(d){a(d)}}function c(u){try{l(n.throw(u))}catch(d){a(d)}}function l(u){u.done?s(u.value):i(u.value).then(o,c)}l((n=n.apply(r,e||[])).next())})},Ar=function(r,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(s=l[0]&2?i.return:l[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,l[1])).done)return s;switch(i=0,s&&(l=[l[0]&2,s.value]),l[0]){case 0:case 1:s=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,i=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!s||l[1]>s[0]&&l[1]<s[3])){t.label=l[1];break}if(l[0]===6&&t.label<s[1]){t.label=s[1],s=l;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(l);break}s[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(u){l=[6,u],i=0}finally{n=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},Wc=function(){function r(e){this.connection=e}return r.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===At.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===At.Data){var n=this.connection,i={ordered:!!e.reliable},s=t.createDataChannel(n.label,i);n.initialize(s)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},r.prototype._startPeerConnection=function(){j.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},r.prototype._setupListeners=function(e){var t=this,n=this.connection.peer,i=this.connection.connectionId,s=this.connection.type,a=this.connection.provider;j.default.log("Listening for ICE candidates."),e.onicecandidate=function(o){!o.candidate||!o.candidate.candidate||(j.default.log("Received ICE candidates for ".concat(n,":"),o.candidate),a.socket.send({type:je.Candidate,payload:{candidate:o.candidate,type:s,connectionId:i},dst:n}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":j.default.log("iceConnectionState is failed, closing connections to "+n),t.connection.emit("error",new Error("Negotiation of connection to "+n+" failed.")),t.connection.close();break;case"closed":j.default.log("iceConnectionState is closed, closing connections to "+n),t.connection.emit("error",new Error("Connection to "+n+" closed.")),t.connection.close();break;case"disconnected":j.default.log("iceConnectionState changed to disconnected on the connection with "+n);break;case"completed":e.onicecandidate=ee.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},j.default.log("Listening for data channel"),e.ondatachannel=function(o){j.default.log("Received data channel");var c=o.channel,l=a.getConnection(n,i);l.initialize(c)},j.default.log("Listening for remote stream"),e.ontrack=function(o){j.default.log("Received remote stream");var c=o.streams[0],l=a.getConnection(n,i);if(l.type===At.Media){var u=l;t._addStreamToMediaConnection(c,u)}}},r.prototype.cleanup=function(){j.default.log("Cleaning up PeerConnection to "+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!=="closed",n=!1;if(this.connection.type===At.Data){var i=this.connection,s=i.dataChannel;s&&(n=!!s.readyState&&s.readyState!=="closed")}(t||n)&&e.close()}},r.prototype._makeOffer=function(){return Rr(this,void 0,Promise,function(){var e,t,n,i,s,a,o;return Ar(this,function(c){switch(c.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,c.label=1;case 1:return c.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:n=c.sent(),j.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),c.label=3;case 3:return c.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return c.sent(),j.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),i={sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:ee.browser},this.connection.type===At.Data&&(s=this.connection,i=kr(kr({},i),{label:s.label,reliable:s.reliable,serialization:s.serialization})),t.socket.send({type:je.Offer,payload:i,dst:this.connection.peer}),[3,6];case 5:return a=c.sent(),a!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(t.emitError(we.WebRTC,a),j.default.log("Failed to setLocalDescription, ",a)),[3,6];case 6:return[3,8];case 7:return o=c.sent(),t.emitError(we.WebRTC,o),j.default.log("Failed to createOffer, ",o),[3,8];case 8:return[2]}})})},r.prototype._makeAnswer=function(){return Rr(this,void 0,Promise,function(){var e,t,n,i,s;return Ar(this,function(a){switch(a.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,a.label=1;case 1:return a.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:n=a.sent(),j.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),a.label=3;case 3:return a.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return a.sent(),j.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),t.socket.send({type:je.Answer,payload:{sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,browser:ee.browser},dst:this.connection.peer}),[3,6];case 5:return i=a.sent(),t.emitError(we.WebRTC,i),j.default.log("Failed to setLocalDescription, ",i),[3,6];case 6:return[3,8];case 7:return s=a.sent(),t.emitError(we.WebRTC,s),j.default.log("Failed to create answer, ",s),[3,8];case 8:return[2]}})})},r.prototype.handleSDP=function(e,t){return Rr(this,void 0,Promise,function(){var n,i,s,a;return Ar(this,function(o){switch(o.label){case 0:t=new RTCSessionDescription(t),n=this.connection.peerConnection,i=this.connection.provider,j.default.log("Setting remote description",t),s=this,o.label=1;case 1:return o.trys.push([1,5,,6]),[4,n.setRemoteDescription(t)];case 2:return o.sent(),j.default.log("Set remoteDescription:".concat(e," for:").concat(this.connection.peer)),e!=="OFFER"?[3,4]:[4,s._makeAnswer()];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:return a=o.sent(),i.emitError(we.WebRTC,a),j.default.log("Failed to setRemoteDescription, ",a),[3,6];case 6:return[2]}})})},r.prototype.handleCandidate=function(e){return Rr(this,void 0,Promise,function(){var t,n,i,s,a,o;return Ar(this,function(c){switch(c.label){case 0:j.default.log("handleCandidate:",e),t=e.candidate,n=e.sdpMLineIndex,i=e.sdpMid,s=this.connection.peerConnection,a=this.connection.provider,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,s.addIceCandidate(new RTCIceCandidate({sdpMid:i,sdpMLineIndex:n,candidate:t}))];case 2:return c.sent(),j.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return o=c.sent(),a.emitError(we.WebRTC,o),j.default.log("Failed to handleCandidate, ",o),[3,4];case 4:return[2]}})})},r.prototype._addTracksToConnection=function(e,t){if(j.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return j.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(n){t.addTrack(n,e)})},r.prototype._addStreamToMediaConnection=function(e,t){j.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},r}(),eo={};Ft(eo,"BaseConnection",()=>Hc,r=>Hc=r);var Td=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Hc=function(r){Td(e,r);function e(t,n,i){var s=r.call(this)||this;return s.peer=t,s.provider=n,s.options=i,s._open=!1,s.metadata=i.metadata,s}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e}(hi.EventEmitter),Md=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Or=function(){return Or=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},Or.apply(this,arguments)},Cd=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},qc=function(r){Md(e,r);function e(t,n,i){var s=r.call(this,t,n,i)||this;return s._localStream=s.options._stream,s.connectionId=s.options.connectionId||e.ID_PREFIX+ee.randomToken(),s._negotiator=new $s.Negotiator(s),s._localStream&&s._negotiator.startConnection({_stream:s._localStream,originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return At.Media},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localStream",{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteStream",{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),e.prototype.addStream=function(t){j.default.log("Receiving stream",t),this._remoteStream=t,r.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var n=t.type,i=t.payload;switch(t.type){case je.Answer:this._negotiator.handleSDP(n,i.sdp),this._open=!0;break;case je.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:j.default.warn("Unrecognized message type:".concat(n," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,n){var i,s;if(n===void 0&&(n={}),this._localStream){j.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,n&&n.sdpTransform&&(this.options.sdpTransform=n.sdpTransform),this._negotiator.startConnection(Or(Or({},this.options._payload),{_stream:t}));var a=this.provider._getMessages(this.connectionId);try{for(var o=Cd(a),c=o.next();!c.done;c=o.next()){var l=c.value;this.handleMessage(l)}}catch(u){i={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}this._open=!0},e.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,r.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e}(eo.BaseConnection),to={};Ft(to,"DataConnection",()=>Zc,r=>Zc=r);var Xc={};Ft(Xc,"EncodingQueue",()=>Yc,r=>Yc=r);var Pd=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Yc=function(r){Pd(e,r);function e(){var t=r.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(n){t._processing=!1,n.target&&t.emit("done",n.target.result),t.doNextTask()},t.fileReader.onerror=function(n){j.default.error("EncodingQueue error:",n),t._processing=!1,t.destroy(),t.emit("error",n)},t}return Object.defineProperty(e.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),e.prototype.enque=function(t){this.queue.push(t),!this.processing&&this.doNextTask()},e.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},e.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},e}(hi.EventEmitter),Ed=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),kd=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Zc=function(r){Ed(e,r);function e(t,n,i){var s=r.call(this,t,n,i)||this;return s.stringify=JSON.stringify,s.parse=JSON.parse,s._buffer=[],s._bufferSize=0,s._buffering=!1,s._chunkedData={},s._encodingQueue=new Xc.EncodingQueue,s.connectionId=s.options.connectionId||e.ID_PREFIX+ee.randomToken(),s.label=s.options.label||s.connectionId,s.serialization=s.options.serialization||Yt.Binary,s.reliable=!!s.options.reliable,s._encodingQueue.on("done",function(a){s._bufferedSend(a)}),s._encodingQueue.on("error",function(){j.default.error("DC#".concat(s.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),s.close()}),s._negotiator=new $s.Negotiator(s),s._negotiator.startConnection(s.options._payload||{originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return At.Data},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataChannel",{get:function(){return this._dc},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bufferSize",{get:function(){return this._bufferSize},enumerable:!1,configurable:!0}),e.prototype.initialize=function(t){this._dc=t,this._configureDataChannel()},e.prototype._configureDataChannel=function(){var t=this;(!ee.supports.binaryBlob||ee.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){j.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(n){j.default.log("DC#".concat(t.connectionId," dc onmessage:"),n.data),t._handleDataMessage(n)},this.dataChannel.onclose=function(){j.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var n=this,i=t.data,s=i.constructor,a=this.serialization===Yt.Binary||this.serialization===Yt.BinaryUTF8,o=i;if(a){if(s===Blob){ee.blobToArrayBuffer(i,function(l){var u=ee.unpack(l);n.emit("data",u)});return}else if(s===ArrayBuffer)o=ee.unpack(i);else if(s===String){var c=ee.binaryStringToArrayBuffer(i);o=ee.unpack(c)}}else this.serialization===Yt.JSON&&(o=this.parse(i));if(o.__peerData){this._handleChunk(o);return}r.prototype.emit.call(this,"data",o)},e.prototype._handleChunk=function(t){var n=t.__peerData,i=this._chunkedData[n]||{data:[],count:0,total:t.total};if(i.data[t.n]=t.data,i.count++,this._chunkedData[n]=i,i.total===i.count){delete this._chunkedData[n];var s=new Blob(i.data);this._handleDataMessage({data:s})}},e.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),this._encodingQueue=null),this.open&&(this._open=!1,r.prototype.emit.call(this,"close"))},e.prototype.send=function(t,n){if(!this.open){r.prototype.emit.call(this,"error",new Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===Yt.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===Yt.Binary||this.serialization===Yt.BinaryUTF8){var i=ee.pack(t);if(!n&&i.size>ee.chunkedMTU){this._sendChunks(i);return}ee.supports.binaryBlob?this._bufferedSend(i):this._encodingQueue.enque(i)}else this._bufferedSend(t)},e.prototype._bufferedSend=function(t){(this._buffering||!this._trySend(t))&&(this._buffer.push(t),this._bufferSize=this._buffer.length)},e.prototype._trySend=function(t){var n=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){n._buffering=!1,n._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(i){return j.default.error("DC#:".concat(this.connectionId," Error when sending:"),i),this._buffering=!0,this.close(),!1}return!0},e.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},e.prototype._sendChunks=function(t){var n,i,s=ee.chunk(t);j.default.log("DC#".concat(this.connectionId," Try to send ").concat(s.length," chunks..."));try{for(var a=kd(s),o=a.next();!o.done;o=a.next()){var c=o.value;this.send(c,!0)}}catch(l){n={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}},e.prototype.handleMessage=function(t){var n=t.payload;switch(t.type){case je.Answer:this._negotiator.handleSDP(t.type,n.sdp);break;case je.Candidate:this._negotiator.handleCandidate(n.candidate);break;default:j.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e}(eo.BaseConnection),Kc={};Ft(Kc,"API",()=>el,r=>el=r);var Qc=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(n.next(u))}catch(d){a(d)}}function c(u){try{l(n.throw(u))}catch(d){a(d)}}function l(u){u.done?s(u.value):i(u.value).then(o,c)}l((n=n.apply(r,e||[])).next())})},$c=function(r,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(s=l[0]&2?i.return:l[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,l[1])).done)return s;switch(i=0,s&&(l=[l[0]&2,s.value]),l[0]){case 0:case 1:s=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,i=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!s||l[1]>s[0]&&l[1]<s[3])){t.label=l[1];break}if(l[0]===6&&t.label<s[1]){t.label=s[1],s=l;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(l);break}s[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(u){l=[6,u],i=0}finally{n=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},el=function(){function r(e){this._options=e}return r.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",n=this._options,i=n.host,s=n.port,a=n.path,o=n.key,c=new URL("".concat(t,"://").concat(i,":").concat(s).concat(a).concat(o,"/").concat(e));return c.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),c.searchParams.set("version",Ks.version),fetch(c.href,{referrerPolicy:this._options.referrerPolicy})},r.prototype.retrieveId=function(){return Qc(this,void 0,Promise,function(){var e,t,n;return $c(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=i.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=i.sent(),j.default.error("Error retrieving ID",t),n="",this._options.path==="/"&&this._options.host!==ee.CLOUD_HOST&&(n=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+n);case 3:return[2]}})})},r.prototype.listAllPeers=function(){return Qc(this,void 0,Promise,function(){var e,t,n;return $c(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=i.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===ee.CLOUD_HOST?t="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":t="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+t)):new Error("Error. Status:".concat(e.status));return[2,e.json()];case 2:throw n=i.sent(),j.default.error("Error retrieving list peers",n),new Error("Could not get list peers from the server."+n);case 3:return[2]}})})},r}(),Rd=function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),di=function(){return di=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},di.apply(this,arguments)},pi=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ad=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},no=function(r){Rd(e,r);function e(t,n){var i=r.call(this)||this;i._id=null,i._lastServerId=null,i._destroyed=!1,i._disconnected=!1,i._open=!1,i._connections=new Map,i._lostMessages=new Map;var s;return t&&t.constructor==Object?n=t:t&&(s=t.toString()),n=di({debug:0,host:ee.CLOUD_HOST,port:ee.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:ee.randomToken(),config:ee.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},n),i._options=n,i._options.host==="/"&&(i._options.host=window.location.hostname),i._options.path&&(i._options.path[0]!=="/"&&(i._options.path="/"+i._options.path),i._options.path[i._options.path.length-1]!=="/"&&(i._options.path+="/")),i._options.secure===void 0&&i._options.host!==ee.CLOUD_HOST?i._options.secure=ee.isSecure():i._options.host==ee.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&j.default.setLogFunction(i._options.logFunction),j.default.logLevel=i._options.debug||0,i._api=new Kc.API(n),i._socket=i._createServerConnection(),!ee.supports.audioVideo&&!ee.supports.data?(i._delayedAbort(we.BrowserIncompatible,"The current browser does not support WebRTC"),i):s&&!ee.validateId(s)?(i._delayedAbort(we.InvalidID,'ID "'.concat(s,'" is invalid')),i):(s?i._initialize(s):i._api.retrieveId().then(function(a){return i._initialize(a)}).catch(function(a){return i._abort(we.ServerError,a)}),i)}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){var t,n,i=Object.create(null);try{for(var s=pi(this._connections),a=s.next();!a.done;a=s.next()){var o=Ad(a.value,2),c=o[0],l=o[1];i[c]=l}}catch(u){t={error:u}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return i},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),e.prototype._createServerConnection=function(){var t=this,n=new Jc.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return n.on(Zt.Message,function(i){t._handleMessage(i)}),n.on(Zt.Error,function(i){t._abort(we.SocketError,i)}),n.on(Zt.Disconnected,function(){t.disconnected||(t.emitError(we.Network,"Lost connection to server."),t.disconnect())}),n.on(Zt.Close,function(){t.disconnected||t._abort(we.SocketClosed,"Underlying socket is already closed.")}),n},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var n,i,s=t.type,a=t.payload,o=t.src;switch(s){case je.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case je.Error:this._abort(we.ServerError,a.msg);break;case je.IdTaken:this._abort(we.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case je.InvalidKey:this._abort(we.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case je.Leave:j.default.log("Received leave message from ".concat(o)),this._cleanupPeer(o),this._connections.delete(o);break;case je.Expire:this.emitError(we.PeerUnavailable,"Could not connect to peer ".concat(o));break;case je.Offer:var x=a.connectionId,_=this.getConnection(o,x);if(_&&(_.close(),j.default.warn("Offer received for existing Connection ID:".concat(x))),a.type===At.Media){var c=new Qs.MediaConnection(o,this,{connectionId:x,_payload:a,metadata:a.metadata});_=c,this._addConnection(o,_),this.emit("call",c)}else if(a.type===At.Data){var l=new to.DataConnection(o,this,{connectionId:x,_payload:a,metadata:a.metadata,label:a.label,serialization:a.serialization,reliable:a.reliable});_=l,this._addConnection(o,_),this.emit("connection",l)}else{j.default.warn("Received malformed connection type:".concat(a.type));return}var u=this._getMessages(x);try{for(var d=pi(u),m=d.next();!m.done;m=d.next()){var f=m.value;_.handleMessage(f)}}catch(g){n={error:g}}finally{try{m&&!m.done&&(i=d.return)&&i.call(d)}finally{if(n)throw n.error}}break;default:if(!a){j.default.warn("You received a malformed message from ".concat(o," of type ").concat(s));return}var x=a.connectionId,_=this.getConnection(o,x);_&&_.peerConnection?_.handleMessage(t):x?this._storeMessage(x,t):j.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,n){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(n)},e.prototype._getMessages=function(t){var n=this._lostMessages.get(t);return n?(this._lostMessages.delete(t),n):[]},e.prototype.connect=function(t,n){if(n===void 0&&(n={}),this.disconnected){j.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),this.emitError(we.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var i=new to.DataConnection(t,this,n);return this._addConnection(t,i),i},e.prototype.call=function(t,n,i){if(i===void 0&&(i={}),this.disconnected){j.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),this.emitError(we.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!n){j.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var s=new Qs.MediaConnection(t,this,di(di({},i),{_stream:n}));return this._addConnection(t,s),s},e.prototype._addConnection=function(t,n){j.default.log("add connection ".concat(n.type,":").concat(n.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(n)},e.prototype._removeConnection=function(t){var n=this._connections.get(t.peer);if(n){var i=n.indexOf(t);i!==-1&&n.splice(i,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,n){var i,s,a=this._connections.get(t);if(!a)return null;try{for(var o=pi(a),c=o.next();!c.done;c=o.next()){var l=c.value;if(l.connectionId===n)return l}}catch(u){i={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}return null},e.prototype._delayedAbort=function(t,n){var i=this;setTimeout(function(){i._abort(t,n)},0)},e.prototype._abort=function(t,n){j.default.error("Aborting!"),this.emitError(t,n),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,n){j.default.error("Error:",n);var i;typeof n=="string"?i=new Error(n):i=n,i.type=t,this.emit("error",i)},e.prototype.destroy=function(){this.destroyed||(j.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},e.prototype._cleanup=function(){var t,n;try{for(var i=pi(this._connections.keys()),s=i.next();!s.done;s=i.next()){var a=s.value;this._cleanupPeer(a),this._connections.delete(a)}}catch(o){t={error:o}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var n,i,s=this._connections.get(t);if(s)try{for(var a=pi(s),o=a.next();!o.done;o=a.next()){var c=o.value;c.close()}}catch(l){n={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;j.default.log("Disconnect peer with ID:".concat(t)),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=t,this._id=null,this.emit("disconnected",t)}},e.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)j.default.log("Attempting reconnection to server with ID ".concat(this._lastServerId)),this._disconnected=!1,this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(!this.disconnected&&!this.open)j.default.error("In a hurry? We're still trying to make the initial connection!");else throw new Error("Peer ".concat(this.id," cannot reconnect because it is not disconnected from the server!"))}},e.prototype.listAllPeers=function(t){var n=this;t===void 0&&(t=function(i){}),this._api.listAllPeers().then(function(i){return t(i)}).catch(function(i){return n._abort(we.ServerError,i)})},e.DEFAULT_KEY="peerjs",e}(hi.EventEmitter),Od=Fc.Peer;const Id=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return no},default:Od,util:ee},Symbol.toStringTag,{value:"Module"}));class Bd{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Base must be a positive integer or zero");if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=e,this.expMax=t,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}var ce;(function(r){r.open="open",r.close="close",r.error="error",r.message="message",r.retry="retry",r.reconnect="reconnect"})(ce||(ce={}));class tl{constructor(e,t,n){var i,s,a,o,c,l,u,d,m,f,x,_,g,v,w;this._closedByUser=!1,this.handleOpenEvent=S=>this.handleEvent(ce.open,S),this.handleErrorEvent=S=>this.handleEvent(ce.error,S),this.handleCloseEvent=S=>this.handleEvent(ce.close,S),this.handleMessageEvent=S=>this.handleEvent(ce.message,S),this._url=e,this._protocols=t,this._options={buffer:n?.buffer,retry:{maxRetries:(i=n?.retry)===null||i===void 0?void 0:i.maxRetries,instantReconnect:(s=n?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=n?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=n?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(u=(l=n?.listeners)===null||l===void 0?void 0:l.close)!==null&&u!==void 0?u:[]],error:[...(m=(d=n?.listeners)===null||d===void 0?void 0:d.error)!==null&&m!==void 0?m:[]],message:[...(x=(f=n?.listeners)===null||f===void 0?void 0:f.message)!==null&&x!==void 0?x:[]],retry:[...(g=(_=n?.listeners)===null||_===void 0?void 0:_.retry)!==null&&g!==void 0?g:[]],reconnect:[...(w=(v=n?.listeners)===null||v===void 0?void 0:v.reconnect)!==null&&w!==void 0?w:[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,n){this._options.listeners[e].push({listener:t,options:n})}removeEventListener(e,t,n){const i=s=>s.listener!==t||s.options!==n;this._options.listeners[e]=this._options.listeners[e].filter(i)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(ce.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(ce.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(ce.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(ce.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(ce.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(ce.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(ce.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(ce.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const n=this._options.listeners[e],i=[];n.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&i.push({listener:s,options:a})}),this._options.listeners[e]=i}handleEvent(e,t){switch(e){case ce.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case ce.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const n={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},i=new CustomEvent(ce.reconnect,{detail:n});this.dispatchEvent(ce.reconnect,i),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case ce.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const e=n=>{const i=new CustomEvent(ce.retry,{detail:n});this.handleEvent(ce.retry,i)},t={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class zd{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{maxRetries:e})}),this}get maxRetries(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.maxRetries}withInstantReconnect(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{instantReconnect:e})}),this}get instantReconnect(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.instantReconnect}withBackoff(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{backoff:e})}),this}get backoff(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){var e;return(e=this._options)===null||e===void 0?void 0:e.buffer}onOpen(e,t){return this.addListener(ce.open,e,t),this}onClose(e,t){return this.addListener(ce.close,e,t),this}onError(e,t){return this.addListener(ce.error,e,t),this}onMessage(e,t){return this.addListener(ce.message,e,t),this}onRetry(e,t){return this.addListener(ce.retry,e,t),this}onReconnect(e,t){return this.addListener(ce.reconnect,e,t),this}build(){return new tl(this._url,this._protocols,this._options)}addListener(e,t,n){var i,s,a,o,c,l,u,d,m,f,x,_,g,v,w,S,T,C,P,E,O;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(i=this._options)===null||i===void 0?void 0:i.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(m=(d=(u=this._options)===null||u===void 0?void 0:u.listeners)===null||d===void 0?void 0:d.error)!==null&&m!==void 0?m:[],message:(_=(x=(f=this._options)===null||f===void 0?void 0:f.listeners)===null||x===void 0?void 0:x.message)!==null&&_!==void 0?_:[],retry:(w=(v=(g=this._options)===null||g===void 0?void 0:g.listeners)===null||v===void 0?void 0:v.retry)!==null&&w!==void 0?w:[],reconnect:(C=(T=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||T===void 0?void 0:T.reconnect)!==null&&C!==void 0?C:[],[e]:[...(O=(E=(P=this._options)===null||P===void 0?void 0:P.listeners)===null||E===void 0?void 0:E[e])!==null&&O!==void 0?O:[],{listener:t,options:n}]}}),this}}const Nd=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Bd,Websocket:tl,WebsocketBuilder:zd,get WebsocketEvent(){return ce}},Symbol.toStringTag,{value:"Module"})),io=0,nl=1,il=2,ro=2,so=1.25,rl=1,qe=32,Pe=qe/4,sl=65535,Ir=Math.pow(2,-24),Br=Symbol("SKIP_GENERATION"),ol={strategy:io,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Br]:!1};function be(r,e,t){return t.min.x=e[r],t.min.y=e[r+1],t.min.z=e[r+2],t.max.x=e[r+3],t.max.y=e[r+4],t.max.z=e[r+5],t}function al(r){let e=-1,t=-1/0;for(let n=0;n<3;n++){const i=r[n+3]-r[n];i>t&&(t=i,e=n)}return e}function cl(r,e){e.set(r)}function ll(r,e,t){let n,i;for(let s=0;s<3;s++){const a=s+3;n=r[s],i=e[s],t[s]=n<i?n:i,n=r[a],i=e[a],t[a]=n>i?n:i}}function zr(r,e,t){for(let n=0;n<3;n++){const i=e[r+2*n],s=e[r+2*n+1],a=i-s,o=i+s;a<t[n]&&(t[n]=a),o>t[n+3]&&(t[n+3]=o)}}function fi(r){const e=r[3]-r[0],t=r[4]-r[1],n=r[5]-r[2];return 2*(e*t+t*n+n*e)}function Ee(r,e){return e[r+15]===sl}function Xe(r,e){return e[r+6]}function it(r,e){return e[r+14]}function ze(r){return r+Pe}function Ne(r,e){const t=e[r+6];return r+t*Pe}function oo(r,e){return e[r+7]}function ao(r,e,t,n,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0,d=1/0,m=1/0,f=1/0,x=-1/0,_=-1/0,g=-1/0;const v=r.offset||0;for(let w=(e-v)*6,S=(e+t-v)*6;w<S;w+=6){const T=r[w+0],C=r[w+1],P=T-C,E=T+C;P<s&&(s=P),E>c&&(c=E),T<d&&(d=T),T>x&&(x=T);const O=r[w+2],A=r[w+3],R=O-A,B=O+A;R<a&&(a=R),B>l&&(l=B),O<m&&(m=O),O>_&&(_=O);const z=r[w+4],U=r[w+5],L=z-U,J=z+U;L<o&&(o=L),J>u&&(u=J),z<f&&(f=z),z>g&&(g=z)}n[0]=s,n[1]=a,n[2]=o,n[3]=c,n[4]=l,n[5]=u,i[0]=d,i[1]=m,i[2]=f,i[3]=x,i[4]=_,i[5]=g}const Kt=32,Ud=(r,e)=>r.candidate-e.candidate,an=new Array(Kt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Nr=new Float32Array(6);function Dd(r,e,t,n,i,s){let a=-1,o=0;if(s===io)a=al(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===nl)a=al(r),a!==-1&&(o=Ld(t,n,i,a));else if(s===il){const c=fi(r);let l=so*i;const u=t.offset||0,d=(n-u)*6,m=(n+i-u)*6;for(let f=0;f<3;f++){const x=e[f],_=(e[f+3]-x)/Kt;if(i<Kt/4){const g=[...an];g.length=i;let v=0;for(let S=d;S<m;S+=6,v++){const T=g[v];T.candidate=t[S+2*f],T.count=0;const{bounds:C,leftCacheBounds:P,rightCacheBounds:E}=T;for(let O=0;O<3;O++)E[O]=1/0,E[O+3]=-1/0,P[O]=1/0,P[O+3]=-1/0,C[O]=1/0,C[O+3]=-1/0;zr(S,t,C)}g.sort(Ud);let w=i;for(let S=0;S<w;S++){const T=g[S];for(;S+1<w&&g[S+1].candidate===T.candidate;)g.splice(S+1,1),w--}for(let S=d;S<m;S+=6){const T=t[S+2*f];for(let C=0;C<w;C++){const P=g[C];T>=P.candidate?zr(S,t,P.rightCacheBounds):(zr(S,t,P.leftCacheBounds),P.count++)}}for(let S=0;S<w;S++){const T=g[S],C=T.count,P=i-T.count,E=T.leftCacheBounds,O=T.rightCacheBounds;let A=0;C!==0&&(A=fi(E)/c);let R=0;P!==0&&(R=fi(O)/c);const B=rl+so*(A*C+R*P);B<l&&(a=f,l=B,o=T.candidate)}}else{for(let w=0;w<Kt;w++){const S=an[w];S.count=0,S.candidate=x+_+w*_;const T=S.bounds;for(let C=0;C<3;C++)T[C]=1/0,T[C+3]=-1/0}for(let w=d;w<m;w+=6){let S=~~((t[w+2*f]-x)/_);S>=Kt&&(S=Kt-1);const T=an[S];T.count++,zr(w,t,T.bounds)}const g=an[Kt-1];cl(g.bounds,g.rightCacheBounds);for(let w=Kt-2;w>=0;w--){const S=an[w],T=an[w+1];ll(S.bounds,T.rightCacheBounds,S.rightCacheBounds)}let v=0;for(let w=0;w<Kt-1;w++){const S=an[w],T=S.count,C=S.bounds,P=an[w+1].rightCacheBounds;T!==0&&(v===0?cl(C,Nr):ll(C,Nr,Nr)),v+=T;let E=0,O=0;v!==0&&(E=fi(Nr)/c);const A=i-v;A!==0&&(O=fi(P)/c);const R=rl+so*(E*v+O*A);R<l&&(a=f,l=R,o=S.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function Ld(r,e,t,n){let i=0;const s=r.offset;for(let a=e,o=e+t;a<o;a++)i+=r[(a-s)*6+n*2];return i/t}class co{constructor(){this.boundingData=new Float32Array(6)}}function Fd(r,e,t,n,i,s){let a=n,o=n+i-1;const c=s.pos,l=s.axis*2,u=t.offset||0;for(;;){for(;a<=o&&t[(a-u)*6+l]<c;)a++;for(;a<=o&&t[(o-u)*6+l]>=c;)o--;if(a<o){for(let d=0;d<e;d++){let m=r[a*e+d];r[a*e+d]=r[o*e+d],r[o*e+d]=m}for(let d=0;d<6;d++){const m=a-u,f=o-u,x=t[m*6+d];t[m*6+d]=t[f*6+d],t[f*6+d]=x}a++,o--}else return a}}let hl,Ur,lo,ul;const Vd=Math.pow(2,32);function ho(r){return"count"in r?1:1+ho(r.left)+ho(r.right)}function jd(r,e,t){return hl=new Float32Array(t),Ur=new Uint32Array(t),lo=new Uint16Array(t),ul=new Uint8Array(t),uo(r,e)}function uo(r,e){const t=r/4,n=r/2,i="count"in e,s=e.boundingData;for(let a=0;a<6;a++)hl[t+a]=s[a];if(i)return e.buffer?(ul.set(new Uint8Array(e.buffer),r),r+e.buffer.byteLength):(Ur[t+6]=e.offset,lo[n+14]=e.count,lo[n+15]=sl,r+qe);{const{left:a,right:o,splitAxis:c}=e,l=r+qe;let u=uo(l,a);const d=r/qe,m=u/qe-d;if(m>Vd)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Ur[t+6]=m,Ur[t+7]=c,uo(u,o)}}function Jd(r,e,t,n,i){const{maxDepth:s,verbose:a,maxLeafSize:o,strategy:c,onProgress:l}=i,u=r.primitiveBuffer,d=r.primitiveBufferStride,m=new Float32Array(6);let f=!1;const x=new co;return ao(e,t,n,x.boundingData,m),g(x,t,n,m),x;function _(v){l&&l(v/n)}function g(v,w,S,T=null,C=0){if(!f&&C>=s&&(f=!0,a&&console.warn(`BVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`)),S<=o||C>=s)return _(w+S),v.offset=w,v.count=S,v;const P=Dd(v.boundingData,T,e,w,S,c);if(P.axis===-1)return _(w+S),v.offset=w,v.count=S,v;const E=Fd(u,d,e,w,S,P);if(E===w||E===w+S)_(w+S),v.offset=w,v.count=S;else{v.splitAxis=P.axis;const O=new co,A=w,R=E-w;v.left=O,ao(e,A,R,O.boundingData,m),g(O,A,R,m,C+1);const B=new co,z=E,U=S-R;v.right=B,ao(e,z,U,B.boundingData,m),g(B,z,U,m,C+1)}return v}}function Gd(r,e){const t=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=r.getRootRanges(e.range),i=n[0],s=n[n.length-1],a={offset:i.offset,count:s.offset+s.count-i.offset},o=new Float32Array(6*a.count);o.offset=a.offset,r.computePrimitiveBounds(a.offset,a.count,o),r._roots=n.map(c=>{const l=Jd(r,o,c.offset,c.count,e),u=ho(l),d=new t(qe*u);return jd(0,l,d),d})}class po{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Wd{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const ye=new Wd;let cn,Dn;const Ln=[],Dr=new po(()=>new zt);function Hd(r,e,t,n,i,s){cn=Dr.getPrimitive(),Dn=Dr.getPrimitive(),Ln.push(cn,Dn),ye.setBuffer(r._roots[e]);const a=fo(0,r.geometry,t,n,i,s);ye.clearBuffer(),Dr.releasePrimitive(cn),Dr.releasePrimitive(Dn),Ln.pop(),Ln.pop();const o=Ln.length;return o>0&&(Dn=Ln[o-1],cn=Ln[o-2]),a}function fo(r,e,t,n,i=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=ye;let u=r*2;if(Ee(u,c)){const d=Xe(r,l),m=it(u,c);return be(r,o,cn),n(d,m,!1,a,s+r/Pe,cn)}else{let d=function(B){const{uint16Array:z,uint32Array:U}=ye;let L=B*2;for(;!Ee(L,z);)B=ze(B),L=B*2;return Xe(B,U)},m=function(B){const{uint16Array:z,uint32Array:U}=ye;let L=B*2;for(;!Ee(L,z);)B=Ne(B,U),L=B*2;return Xe(B,U)+it(L,z)};const f=ze(r),x=Ne(r,l);let _=f,g=x,v,w,S,T;if(i&&(S=cn,T=Dn,be(_,o,S),be(g,o,T),v=i(S),w=i(T),w<v)){_=x,g=f;const B=v;v=w,w=B,S=T}S||(S=cn,be(_,o,S));const C=Ee(_*2,c),P=t(S,C,v,a+1,s+_/Pe);let E;if(P===ro){const B=d(_),z=m(_)-B;E=n(B,z,!0,a+1,s+_/Pe,S)}else E=P&&fo(_,e,t,n,i,s,a+1);if(E)return!0;T=Dn,be(g,o,T);const O=Ee(g*2,c),A=t(T,O,w,a+1,s+g/Pe);let R;if(A===ro){const B=d(g),z=m(g)-B;R=n(B,z,!0,a+1,s+g/Pe,T)}else R=A&&fo(g,e,t,n,i,s,a+1);return!!R}}const mi=new ye.constructor,Lr=new ye.constructor,ln=new po(()=>new zt),Fn=new zt,Vn=new zt,mo=new zt,yo=new zt;let go=!1;function qd(r,e,t,n){if(go)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");go=!0;const i=r._roots,s=e._roots;let a,o=0,c=0;const l=new kt().copy(t).invert();for(let u=0,d=i.length;u<d;u++){mi.setBuffer(i[u]),c=0;const m=ln.getPrimitive();be(0,mi.float32Array,m),m.applyMatrix4(l);for(let f=0,x=s.length;f<x&&(Lr.setBuffer(s[f]),a=Ot(0,0,t,l,n,o,c,0,0,m),Lr.clearBuffer(),c+=s[f].byteLength/qe,!a);f++);if(ln.releasePrimitive(m),mi.clearBuffer(),o+=i[u].byteLength/qe,a)break}return go=!1,a}function Ot(r,e,t,n,i,s=0,a=0,o=0,c=0,l=null,u=!1){let d,m;u?(d=Lr,m=mi):(d=mi,m=Lr);const f=d.float32Array,x=d.uint32Array,_=d.uint16Array,g=m.float32Array,v=m.uint32Array,w=m.uint16Array,S=r*2,T=e*2,C=Ee(S,_),P=Ee(T,w);let E=!1;if(P&&C)u?E=i(Xe(e,v),it(e*2,w),Xe(r,x),it(r*2,_),c,a+e/Pe,o,s+r/Pe):E=i(Xe(r,x),it(r*2,_),Xe(e,v),it(e*2,w),o,s+r/Pe,c,a+e/Pe);else if(P){const O=ln.getPrimitive();be(e,g,O),O.applyMatrix4(t);const A=ze(r),R=Ne(r,x);be(A,f,Fn),be(R,f,Vn);const B=O.intersectsBox(Fn),z=O.intersectsBox(Vn);E=B&&Ot(e,A,n,t,i,a,s,c,o+1,O,!u)||z&&Ot(e,R,n,t,i,a,s,c,o+1,O,!u),ln.releasePrimitive(O)}else{const O=ze(e),A=Ne(e,v);be(O,g,mo),be(A,g,yo);const R=l.intersectsBox(mo),B=l.intersectsBox(yo);if(R&&B)E=Ot(r,O,t,n,i,s,a,o,c+1,l,u)||Ot(r,A,t,n,i,s,a,o,c+1,l,u);else if(R)if(C)E=Ot(r,O,t,n,i,s,a,o,c+1,l,u);else{const z=ln.getPrimitive();z.copy(mo).applyMatrix4(t);const U=ze(r),L=Ne(r,x);be(U,f,Fn),be(L,f,Vn);const J=z.intersectsBox(Fn),H=z.intersectsBox(Vn);E=J&&Ot(O,U,n,t,i,a,s,c,o+1,z,!u)||H&&Ot(O,L,n,t,i,a,s,c,o+1,z,!u),ln.releasePrimitive(z)}else if(B)if(C)E=Ot(r,A,t,n,i,s,a,o,c+1,l,u);else{const z=ln.getPrimitive();z.copy(yo).applyMatrix4(t);const U=ze(r),L=Ne(r,x);be(U,f,Fn),be(L,f,Vn);const J=z.intersectsBox(Fn),H=z.intersectsBox(Vn);E=J&&Ot(A,U,n,t,i,a,s,c,o+1,z,!u)||H&&Ot(A,L,n,t,i,a,s,c,o+1,z,!u),ln.releasePrimitive(z)}}return E}const dl=new zt,jn=new Float32Array(6);class pl{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...ol,...e},Gd(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,n,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0;for(let d=e,m=e+t;d<m;d++){this.writePrimitiveBounds(d,jn,0);const[f,x,_,g,v,w]=jn;f<s&&(s=f),g>c&&(c=g),x<a&&(a=x),v>l&&(l=v),_<o&&(o=_),w>u&&(u=w)}return n[i+0]=s,n[i+1]=a,n[i+2]=o,n[i+3]=c,n[i+4]=l,n[i+5]=u,n}computePrimitiveBounds(e,t,n){const i=n.offset||0;for(let s=e,a=e+t;s<a;s++){this.writePrimitiveBounds(s,jn,0);const[o,c,l,u,d,m]=jn,f=(o+u)/2,x=(c+d)/2,_=(l+m)/2,g=(u-o)/2,v=(d-c)/2,w=(m-l)/2,S=(s-i)*6;n[S+0]=f,n[S+1]=g+(Math.abs(f)+g)*Ir,n[S+2]=x,n[S+3]=v+(Math.abs(x)+v)*Ir,n[S+4]=_,n[S+5]=w+(Math.abs(_)+w)*Ir}return n}shiftPrimitiveOffsets(e){const t=this._indirectBuffer;if(t)for(let n=0,i=t.length;n<i;n++)t[n]+=e;else{const n=this._roots;for(let i=0;i<n.length;i++){const s=n[i],a=new Uint32Array(s),o=new Uint16Array(s),c=s.byteLength/qe;for(let l=0;l<c;l++){const u=Pe*l,d=2*u;Ee(d,o)&&(a[u+6]+=e)}}}}traverse(e,t=0){const n=this._roots[t],i=new Uint32Array(n),s=new Uint16Array(n);a(0);function a(o,c=0){const l=o*2,u=Ee(l,s);if(u){const d=i[o+6],m=s[l+14];e(c,u,new Float32Array(n,o*4,6),d,m)}else{const d=ze(o),m=Ne(o,i),f=oo(o,i);e(c,u,new Float32Array(n,o*4,6),f)||(a(d,c+1),a(m,c+1))}}}refit(){const e=this._roots;for(let t=0,n=e.length;t<n;t++){const i=e[t],s=new Uint32Array(i),a=new Uint16Array(i),o=new Float32Array(i),c=i.byteLength/qe;for(let l=c-1;l>=0;l--){const u=l*Pe,d=u*2;if(Ee(d,a)){const m=Xe(u,s),f=it(d,a);this.writePrimitiveRangeBounds(m,f,jn,0),o.set(jn,u)}else{const m=ze(u),f=Ne(u,s);for(let x=0;x<3;x++){const _=o[m+x],g=o[m+x+3],v=o[f+x],w=o[f+x+3];o[u+x]=_<v?_:v,o[u+x+3]=g>w?g:w}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{be(0,new Float32Array(t),dl),e.union(dl)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:i,intersectsPrimitive:s,scratchPrimitive:a,iterate:o}=e;if(i&&s){const d=i;i=(m,f,x,_,g)=>d(m,f,x,_,g)?!0:o(m,f,this,s,x,_,a)}else i||(s?i=(d,m,f,x)=>o(d,m,this,s,f,x,a):i=(d,m,f)=>f);let c=!1,l=0;const u=this._roots;for(let d=0,m=u.length;d<m;d++){const f=u[d];if(c=Hd(this,d,n,i,t,l),c)break;l+=f.byteLength/qe}return c}bvhcast(e,t,n){let{intersectsRanges:i}=n;return qd(this,e,t,i)}}function Xd(){return typeof SharedArrayBuffer<"u"}function vo(r){return r.index?r.index.count:r.attributes.position.count}function Fr(r){return vo(r)/3}function Yd(r,e=ArrayBuffer){return r>65535?new Uint32Array(new e(4*r)):new Uint16Array(new e(2*r))}function Zd(r,e){if(!r.index){const t=r.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Yd(t,n);r.setIndex(new dt(i,1));for(let s=0;s<t;s++)i[s]=s}}function Kd(r,e,t){const n=vo(r)/t,i=e||r.drawRange,s=i.start/t,a=(i.start+i.count)/t,o=Math.max(0,s),c=Math.min(n,a)-o;return{offset:Math.floor(o),count:Math.floor(c)}}function Qd(r,e){return r.groups.map(t=>({offset:t.start/e,count:t.count/e}))}function fl(r,e,t){const n=Kd(r,e,t),i=Qd(r,t);if(!i.length)return[n];const s=[],a=n.offset,o=n.offset+n.count,c=vo(r)/t,l=[];for(const m of i){const{offset:f,count:x}=m,_=f,g=isFinite(x)?x:c-f,v=f+g;_<o&&v>a&&(l.push({pos:Math.max(a,_),isStart:!0}),l.push({pos:Math.min(o,v),isStart:!1}))}l.sort((m,f)=>m.pos!==f.pos?m.pos-f.pos:m.type==="end"?-1:1);let u=0,d=null;for(const m of l){const f=m.pos;u!==0&&f!==d&&s.push({offset:d,count:f-d}),u+=m.isStart?1:-1,d=f}return s}function ml(r,e){const t=r[r.length-1],n=t.offset+t.count>2**16,i=r.reduce((l,u)=>l+u.count,0),s=n?4:2,a=e?new SharedArrayBuffer(i*s):new ArrayBuffer(i*s),o=n?new Uint32Array(a):new Uint16Array(a);let c=0;for(let l=0;l<r.length;l++){const{offset:u,count:d}=r[l];for(let m=0;m<d;m++)o[c+m]=u+m;c+=d}return o}class yl extends pl{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(t.useSharedArrayBuffer&&!Xd())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?n=>this._indirectBuffer[n]:n=>n,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...ol,...t},t[Br]||this.init(t)}init(e){const{geometry:t,primitiveStride:n}=this;if(e.indirect){const i=fl(t,e.range,n),s=ml(i,e.useSharedArrayBuffer);this._indirectBuffer=s}else Zd(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new zt))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:fl(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class Qt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,i=-1/0;for(let s=0,a=e.length;s<a;s++){const o=e[s][t];n=o<n?o:n,i=o>i?o:i}this.min=n,this.max=i}setFromPoints(e,t){let n=1/0,i=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);n=c<n?c:n,i=c>i?c:i}this.min=n,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}Qt.prototype.setFromBox=function(){const r=new q;return function(e,t){const n=t.min,i=t.max;let s=1/0,a=-1/0;for(let o=0;o<=1;o++)for(let c=0;c<=1;c++)for(let l=0;l<=1;l++){r.x=n.x*o+i.x*(1-o),r.y=n.y*c+i.y*(1-c),r.z=n.z*l+i.z*(1-l);const u=e.dot(r);s=Math.min(u,s),a=Math.max(u,a)}this.min=s,this.max=a}}();const $d=function(){const r=new q,e=new q,t=new q;return function(n,i,s){const a=n.start,o=r,c=i.start,l=e;t.subVectors(a,c),r.subVectors(n.end,n.start),e.subVectors(i.end,i.start);const u=t.dot(l),d=l.dot(o),m=l.dot(l),f=t.dot(o),x=o.dot(o)*m-d*d;let _,g;x!==0?_=(u*d-f*m)/x:_=0,g=(u+_*d)/m,s.x=_,s.y=g}}(),So=function(){const r=new nn,e=new q,t=new q;return function(n,i,s,a){$d(n,i,r);let o=r.x,c=r.y;if(o>=0&&o<=1&&c>=0&&c<=1){n.at(o,s),i.at(c,a);return}else if(o>=0&&o<=1){c<0?i.at(0,a):i.at(1,a),n.closestPointToPoint(a,!0,s);return}else if(c>=0&&c<=1){o<0?n.at(0,s):n.at(1,s),i.closestPointToPoint(s,!0,a);return}else{let l;o<0?l=n.start:l=n.end;let u;c<0?u=i.start:u=i.end;const d=e,m=t;if(n.closestPointToPoint(u,!0,e),i.closestPointToPoint(l,!0,t),d.distanceToSquared(u)<=m.distanceToSquared(l)){s.copy(d),a.copy(u);return}else{s.copy(l),a.copy(m);return}}}}(),ep=function(){const r=new q,e=new q,t=new oa,n=new qt;return function(i,s){const{radius:a,center:o}=i,{a:c,b:l,c:u}=s;if(n.start=c,n.end=l,n.closestPointToPoint(o,!0,r).distanceTo(o)<=a||(n.start=c,n.end=u,n.closestPointToPoint(o,!0,r).distanceTo(o)<=a)||(n.start=l,n.end=u,n.closestPointToPoint(o,!0,r).distanceTo(o)<=a))return!0;const d=s.getPlane(t);if(Math.abs(d.distanceToPoint(o))<=a){const m=d.projectPoint(o,e);if(s.containsPoint(m))return!0}return!1}}(),tp=["x","y","z"],$t=1e-15,gl=$t*$t;function vt(r){return Math.abs(r)<$t}class St extends mn{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new q),this.satBounds=new Array(4).fill().map(()=>new Qt),this.points=[this.a,this.b,this.c],this.plane=new oa,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new qt,this.needsUpdate=!0}intersectsSphere(e){return ep(e,this)}update(){const e=this.a,t=this.b,n=this.c,i=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,i);const l=s[1],u=a[1];l.subVectors(e,t),u.setFromPoints(l,i);const d=s[2],m=a[2];d.subVectors(t,n),m.setFromPoints(d,i);const f=s[3],x=a[3];f.subVectors(n,e),x.setFromPoints(f,i);const _=l.length(),g=d.length(),v=f.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,_<$t?g<$t||v<$t?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):g<$t?v<$t?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):v<$t&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}St.prototype.closestPointToSegment=function(){const r=new q,e=new q,t=new qt;return function(n,i=null,s=null){const{start:a,end:o}=n,c=this.points;let l,u=1/0;for(let d=0;d<3;d++){const m=(d+1)%3;t.start.copy(c[d]),t.end.copy(c[m]),So(t,n,r,e),l=r.distanceToSquared(e),l<u&&(u=l,i&&i.copy(r),s&&s.copy(e))}return this.closestPointToPoint(a,r),l=a.distanceToSquared(r),l<u&&(u=l,i&&i.copy(r),s&&s.copy(a)),this.closestPointToPoint(o,r),l=o.distanceToSquared(r),l<u&&(u=l,i&&i.copy(r),s&&s.copy(o)),Math.sqrt(u)}}(),St.prototype.intersectsTriangle=function(){const r=new St,e=new Qt,t=new Qt,n=new q,i=new q,s=new q,a=new q,o=new qt,c=new qt,l=new q,u=new nn,d=new nn;function m(S,T,C,P){const E=n;!S.isDegenerateIntoPoint&&!S.isDegenerateIntoSegment?E.copy(S.plane.normal):E.copy(T.plane.normal);const O=S.satBounds,A=S.satAxes;for(let z=1;z<4;z++){const U=O[z],L=A[z];if(e.setFromPoints(L,T.points),U.isSeparated(e)||(a.copy(E).cross(L),e.setFromPoints(a,S.points),t.setFromPoints(a,T.points),e.isSeparated(t)))return!1}const R=T.satBounds,B=T.satAxes;for(let z=1;z<4;z++){const U=R[z],L=B[z];if(e.setFromPoints(L,S.points),U.isSeparated(e)||(a.crossVectors(E,L),e.setFromPoints(a,S.points),t.setFromPoints(a,T.points),e.isSeparated(t)))return!1}return C&&(P||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),C.start.set(0,0,0),C.end.set(0,0,0)),!0}function f(S,T,C,P,E,O,A,R,B,z,U){let L=A/(A-R);z.x=P+(E-P)*L,U.start.subVectors(T,S).multiplyScalar(L).add(S),L=A/(A-B),z.y=P+(O-P)*L,U.end.subVectors(C,S).multiplyScalar(L).add(S)}function x(S,T,C,P,E,O,A,R,B,z,U){if(E>0)f(S.c,S.a,S.b,P,T,C,B,A,R,z,U);else if(O>0)f(S.b,S.a,S.c,C,T,P,R,A,B,z,U);else if(R*B>0||A!=0)f(S.a,S.b,S.c,T,C,P,A,R,B,z,U);else if(R!=0)f(S.b,S.a,S.c,C,T,P,R,A,B,z,U);else if(B!=0)f(S.c,S.a,S.b,P,T,C,B,A,R,z,U);else return!0;return!1}function _(S,T,C,P){const E=T.degenerateSegment,O=S.plane.distanceToPoint(E.start),A=S.plane.distanceToPoint(E.end);return vt(O)?vt(A)?m(S,T,C,P):(C&&(C.start.copy(E.start),C.end.copy(E.start)),S.containsPoint(E.start)):vt(A)?(C&&(C.start.copy(E.end),C.end.copy(E.end)),S.containsPoint(E.end)):S.plane.intersectLine(E,n)!=null?(C&&(C.start.copy(n),C.end.copy(n)),S.containsPoint(n)):!1}function g(S,T,C){const P=T.a;return vt(S.plane.distanceToPoint(P))&&S.containsPoint(P)?(C&&(C.start.copy(P),C.end.copy(P)),!0):!1}function v(S,T,C){const P=S.degenerateSegment,E=T.a;return P.closestPointToPoint(E,!0,n),E.distanceToSquared(n)<gl?(C&&(C.start.copy(E),C.end.copy(E)),!0):!1}function w(S,T,C,P){if(S.isDegenerateIntoSegment)if(T.isDegenerateIntoSegment){const E=S.degenerateSegment,O=T.degenerateSegment,A=i,R=s;E.delta(A),O.delta(R);const B=n.subVectors(O.start,E.start),z=A.x*R.y-A.y*R.x;if(vt(z))return!1;const U=(B.x*R.y-B.y*R.x)/z,L=-(A.x*B.y-A.y*B.x)/z;if(U<0||U>1||L<0||L>1)return!1;const J=E.start.z+A.z*U,H=O.start.z+R.z*L;return vt(J-H)?(C&&(C.start.copy(E.start).addScaledVector(A,U),C.end.copy(E.start).addScaledVector(A,U)),!0):!1}else return T.isDegenerateIntoPoint?v(S,T,C):_(T,S,C,P);else{if(S.isDegenerateIntoPoint)return T.isDegenerateIntoPoint?T.a.distanceToSquared(S.a)<gl?(C&&(C.start.copy(S.a),C.end.copy(S.a)),!0):!1:T.isDegenerateIntoSegment?v(T,S,C):g(T,S,C);if(T.isDegenerateIntoPoint)return g(S,T,C);if(T.isDegenerateIntoSegment)return _(S,T,C,P)}}return function(S,T=null,C=!1){this.needsUpdate&&this.update(),S.isExtendedTriangle?S.needsUpdate&&S.update():(r.copy(S),r.update(),S=r);const P=w(this,S,T,C);if(P!==void 0)return P;const E=this.plane,O=S.plane;let A=O.distanceToPoint(this.a),R=O.distanceToPoint(this.b),B=O.distanceToPoint(this.c);vt(A)&&(A=0),vt(R)&&(R=0),vt(B)&&(B=0);const z=A*R,U=A*B;if(z>0&&U>0)return!1;let L=E.distanceToPoint(S.a),J=E.distanceToPoint(S.b),H=E.distanceToPoint(S.c);vt(L)&&(L=0),vt(J)&&(J=0),vt(H)&&(H=0);const se=L*J,W=L*H;if(se>0&&W>0)return!1;i.copy(E.normal),s.copy(O.normal);const pe=i.cross(s);let te=0,ue=Math.abs(pe.x);const oe=Math.abs(pe.y);oe>ue&&(ue=oe,te=1),Math.abs(pe.z)>ue&&(te=2);const le=tp[te],xe=this.a[le],ge=this.b[le],de=this.c[le],re=S.a[le],Ze=S.b[le],Ue=S.c[le];if(x(this,xe,ge,de,z,U,A,R,B,u,o))return m(this,S,T,C);if(x(S,re,Ze,Ue,se,W,L,J,H,d,c))return m(this,S,T,C);if(u.y<u.x){const ke=u.y;u.y=u.x,u.x=ke,l.copy(o.start),o.start.copy(o.end),o.end.copy(l)}if(d.y<d.x){const ke=d.y;d.y=d.x,d.x=ke,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<d.x||d.y<u.x?!1:(T&&(d.x>u.x?T.start.copy(c.start):T.start.copy(o.start),d.y<u.y?T.end.copy(c.end):T.end.copy(o.end)),!0)}}(),St.prototype.distanceToPoint=function(){const r=new q;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}}(),St.prototype.distanceToTriangle=function(){const r=new q,e=new q,t=["a","b","c"],n=new qt,i=new qt;return function(s,a=null,o=null){const c=a||o?n:null;if(this.intersectsTriangle(s,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let l=1/0;for(let u=0;u<3;u++){let d;const m=t[u],f=s[m];this.closestPointToPoint(f,r),d=f.distanceToSquared(r),d<l&&(l=d,a&&a.copy(r),o&&o.copy(f));const x=this[m];s.closestPointToPoint(x,r),d=x.distanceToSquared(r),d<l&&(l=d,a&&a.copy(x),o&&o.copy(r))}for(let u=0;u<3;u++){const d=t[u],m=t[(u+1)%3];n.set(this[d],this[m]);for(let f=0;f<3;f++){const x=t[f],_=t[(f+1)%3];i.set(s[x],s[_]),So(n,i,r,e);const g=r.distanceToSquared(e);g<l&&(l=g,a&&a.copy(r),o&&o.copy(e))}}return Math.sqrt(l)}}();class Ye{constructor(e,t,n){this.isOrientedBox=!0,this.min=new q,this.max=new q,this.matrix=new kt,this.invMatrix=new kt,this.points=new Array(8).fill().map(()=>new q),this.satAxes=new Array(3).fill().map(()=>new q),this.satBounds=new Array(3).fill().map(()=>new Qt),this.alignedSatBounds=new Array(3).fill().map(()=>new Qt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}Ye.prototype.update=function(){return function(){const r=this.matrix,e=this.min,t=this.max,n=this.points;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let u=0;u<=1;u++){const d=1*c|2*l|4*u,m=n[d];m.x=c?t.x:e.x,m.y=l?t.y:e.y,m.z=u?t.z:e.z,m.applyMatrix4(r)}const i=this.satBounds,s=this.satAxes,a=n[0];for(let c=0;c<3;c++){const l=s[c],u=i[c],d=1<<c,m=n[d];l.subVectors(a,m),u.setFromPoints(l,n)}const o=this.alignedSatBounds;o[0].setFromPointsField(n,"x"),o[1].setFromPointsField(n,"y"),o[2].setFromPointsField(n,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),Ye.prototype.intersectsBox=function(){const r=new Qt;return function(e){this.needsUpdate&&this.update();const t=e.min,n=e.max,i=this.satBounds,s=this.satAxes,a=this.alignedSatBounds;if(r.min=t.x,r.max=n.x,a[0].isSeparated(r)||(r.min=t.y,r.max=n.y,a[1].isSeparated(r))||(r.min=t.z,r.max=n.z,a[2].isSeparated(r)))return!1;for(let o=0;o<3;o++){const c=s[o],l=i[o];if(r.setFromBox(c,e),l.isSeparated(r))return!1}return!0}}(),Ye.prototype.intersectsTriangle=function(){const r=new St,e=new Array(3),t=new Qt,n=new Qt,i=new q;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(r.copy(s),r.update(),s=r);const a=this.satBounds,o=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let d=0;d<3;d++){const m=a[d],f=o[d];if(t.setFromPoints(f,e),m.isSeparated(t))return!1}const c=s.satBounds,l=s.satAxes,u=this.points;for(let d=0;d<3;d++){const m=c[d],f=l[d];if(t.setFromPoints(f,u),m.isSeparated(t))return!1}for(let d=0;d<3;d++){const m=o[d];for(let f=0;f<4;f++){const x=l[f];if(i.crossVectors(m,x),t.setFromPoints(i,e),n.setFromPoints(i,u),t.isSeparated(n))return!1}}return!0}}(),Ye.prototype.closestPointToPoint=function(){return function(r,e){return this.needsUpdate&&this.update(),e.copy(r).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),Ye.prototype.distanceToPoint=function(){const r=new q;return function(e){return this.closestPointToPoint(e,r),e.distanceTo(r)}}(),Ye.prototype.distanceToBox=function(){const r=["x","y","z"],e=new Array(12).fill().map(()=>new qt),t=new Array(12).fill().map(()=>new qt),n=new q,i=new q;return function(s,a=0,o=null,c=null){if(this.needsUpdate&&this.update(),this.intersectsBox(s))return(o||c)&&(s.getCenter(i),this.closestPointToPoint(i,n),s.closestPointToPoint(n,i),o&&o.copy(n),c&&c.copy(i)),0;const l=a*a,u=s.min,d=s.max,m=this.points;let f=1/0;for(let _=0;_<8;_++){const g=m[_];i.copy(g).clamp(u,d);const v=g.distanceToSquared(i);if(v<f&&(f=v,o&&o.copy(g),c&&c.copy(i),v<l))return Math.sqrt(v)}let x=0;for(let _=0;_<3;_++)for(let g=0;g<=1;g++)for(let v=0;v<=1;v++){const w=(_+1)%3,S=(_+2)%3,T=g<<w|v<<S,C=1<<_|g<<w|v<<S,P=m[T],E=m[C];e[x].set(P,E);const O=r[_],A=r[w],R=r[S],B=t[x],z=B.start,U=B.end;z[O]=u[O],z[A]=g?u[A]:d[A],z[R]=v?u[R]:d[A],U[O]=d[O],U[A]=g?u[A]:d[A],U[R]=v?u[R]:d[A],x++}for(let _=0;_<=1;_++)for(let g=0;g<=1;g++)for(let v=0;v<=1;v++){i.x=_?d.x:u.x,i.y=g?d.y:u.y,i.z=v?d.z:u.z,this.closestPointToPoint(i,n);const w=i.distanceToSquared(n);if(w<f&&(f=w,o&&o.copy(n),c&&c.copy(i),w<l))return Math.sqrt(w)}for(let _=0;_<12;_++){const g=e[_];for(let v=0;v<12;v++){const w=t[v];So(g,w,n,i);const S=n.distanceToSquared(i);if(S<f&&(f=S,o&&o.copy(n),c&&c.copy(i),S<l))return Math.sqrt(S)}}return Math.sqrt(f)}}();class np extends po{constructor(){super(()=>new St)}}const bt=new np,yi=new q,bo=new q;function ip(r,e,t={},n=0,i=1/0){const s=n*n,a=i*i;let o=1/0,c=null;if(r.shapecast({boundsTraverseOrder:u=>(yi.copy(e).clamp(u.min,u.max),yi.distanceToSquared(e)),intersectsBounds:(u,d,m)=>m<o&&m<a,intersectsTriangle:(u,d)=>{u.closestPointToPoint(e,yi);const m=e.distanceToSquared(yi);return m<o&&(bo.copy(yi),o=m,c=d),m<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(bo):t.point=bo.clone(),t.distance=l,t.faceIndex=c,t}const Vr=parseInt(aa)>=169,rp=parseInt(aa)<=161,vn=new q,Sn=new q,bn=new q,jr=new nn,Jr=new nn,Gr=new nn,vl=new q,Sl=new q,bl=new q,gi=new q;function sp(r,e,t,n,i,s,a,o){let c;if(s===sh?c=r.intersectTriangle(n,t,e,!0,i):c=r.intersectTriangle(e,t,n,s!==bs,i),c===null)return null;const l=r.origin.distanceTo(i);return l<a||l>o?null:{distance:l,point:i.clone()}}function xl(r,e,t,n,i,s,a,o,c,l,u){vn.fromBufferAttribute(e,s),Sn.fromBufferAttribute(e,a),bn.fromBufferAttribute(e,o);const d=sp(r,vn,Sn,bn,gi,c,l,u);if(d){if(n){jr.fromBufferAttribute(n,s),Jr.fromBufferAttribute(n,a),Gr.fromBufferAttribute(n,o),d.uv=new nn;const f=mn.getInterpolation(gi,vn,Sn,bn,jr,Jr,Gr,d.uv);Vr||(d.uv=f)}if(i){jr.fromBufferAttribute(i,s),Jr.fromBufferAttribute(i,a),Gr.fromBufferAttribute(i,o),d.uv1=new nn;const f=mn.getInterpolation(gi,vn,Sn,bn,jr,Jr,Gr,d.uv1);Vr||(d.uv1=f),rp&&(d.uv2=d.uv1)}if(t){vl.fromBufferAttribute(t,s),Sl.fromBufferAttribute(t,a),bl.fromBufferAttribute(t,o),d.normal=new q;const f=mn.getInterpolation(gi,vn,Sn,bn,vl,Sl,bl,d.normal);d.normal.dot(r.direction)>0&&d.normal.multiplyScalar(-1),Vr||(d.normal=f)}const m={a:s,b:a,c:o,normal:new q,materialIndex:0};if(mn.getNormal(vn,Sn,bn,m.normal),d.face=m,d.faceIndex=s,Vr){const f=new q;mn.getBarycoord(gi,vn,Sn,bn,f),d.barycoord=f}}return d}function wl(r){return r&&r.isMaterial?r.side:r}function Wr(r,e,t,n,i,s,a){const o=n*3;let c=o+0,l=o+1,u=o+2;const{index:d,groups:m}=r;r.index&&(c=d.getX(c),l=d.getX(l),u=d.getX(u));const{position:f,normal:x,uv:_,uv1:g}=r.attributes;if(Array.isArray(e)){const v=n*3;for(let w=0,S=m.length;w<S;w++){const{start:T,count:C,materialIndex:P}=m[w];if(v>=T&&v<T+C){const E=wl(e[P]),O=xl(t,f,x,_,g,c,l,u,E,s,a);if(O)if(O.faceIndex=n,O.face.materialIndex=P,i)i.push(O);else return O}}}else{const v=wl(e),w=xl(t,f,x,_,g,c,l,u,v,s,a);if(w)if(w.faceIndex=n,w.face.materialIndex=0,i)i.push(w);else return w}return null}function Ce(r,e,t,n){const i=r.a,s=r.b,a=r.c;let o=e,c=e+1,l=e+2;t&&(o=t.getX(o),c=t.getX(c),l=t.getX(l)),i.x=n.getX(o),i.y=n.getY(o),i.z=n.getZ(o),s.x=n.getX(c),s.y=n.getY(c),s.z=n.getZ(c),a.x=n.getX(l),a.y=n.getY(l),a.z=n.getZ(l)}function op(r,e,t,n,i,s,a,o){const{geometry:c,_indirectBuffer:l}=r;for(let u=n,d=n+i;u<d;u++)Wr(c,e,t,u,s,a,o)}function ap(r,e,t,n,i,s,a){const{geometry:o,_indirectBuffer:c}=r;let l=1/0,u=null;for(let d=n,m=n+i;d<m;d++){let f;f=Wr(o,e,t,d,null,s,a),f&&f.distance<l&&(u=f,l=f.distance)}return u}function cp(r,e,t,n,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=r,d=e+r;u<d;u++){let m;if(m=u,Ce(a,m*3,c,l),a.needsUpdate=!0,n(a,m,i,s))return!0}return!1}function lp(r,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=r.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const u=r._roots;for(let m=0,f=u.length;m<f;m++)s=u[m],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),d(0,l),l+=s.byteLength;function d(m,f,x=!1){const _=m*2;if(Ee(_,o)){const g=Xe(m,a),v=it(_,o);let w=1/0,S=1/0,T=1/0,C=-1/0,P=-1/0,E=-1/0;for(let O=3*g,A=3*(g+v);O<A;O++){let R=n[O];const B=i.getX(R),z=i.getY(R),U=i.getZ(R);B<w&&(w=B),B>C&&(C=B),z<S&&(S=z),z>P&&(P=z),U<T&&(T=U),U>E&&(E=U)}return c[m+0]!==w||c[m+1]!==S||c[m+2]!==T||c[m+3]!==C||c[m+4]!==P||c[m+5]!==E?(c[m+0]=w,c[m+1]=S,c[m+2]=T,c[m+3]=C,c[m+4]=P,c[m+5]=E,!0):!1}else{const g=ze(m),v=Ne(m,a);let w=x,S=!1,T=!1;if(e){if(!w){const R=g/Pe+f/qe,B=v/Pe+f/qe;S=e.has(R),T=e.has(B),w=!S&&!T}}else S=!0,T=!0;const C=w||S,P=w||T;let E=!1;C&&(E=d(g,f,w));let O=!1;P&&(O=d(v,f,w));const A=E||O;if(A)for(let R=0;R<3;R++){const B=g+R,z=v+R,U=c[B],L=c[B+3],J=c[z],H=c[z+3];c[m+R]=U<J?U:J,c[m+R+3]=L>H?L:H}return A}}}function hn(r,e,t,n,i){let s,a,o,c,l,u;const d=1/t.direction.x,m=1/t.direction.y,f=1/t.direction.z,x=t.origin.x,_=t.origin.y,g=t.origin.z;let v=e[r],w=e[r+3],S=e[r+1],T=e[r+3+1],C=e[r+2],P=e[r+3+2];return d>=0?(s=(v-x)*d,a=(w-x)*d):(s=(w-x)*d,a=(v-x)*d),m>=0?(o=(S-_)*m,c=(T-_)*m):(o=(T-_)*m,c=(S-_)*m),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),f>=0?(l=(C-g)*f,u=(P-g)*f):(l=(P-g)*f,u=(C-g)*f),s>u||l>a)?!1:((l>s||s!==s)&&(s=l),(u<a||a!==a)&&(a=u),s<=i&&a>=n)}function hp(r,e,t,n,i,s,a,o){const{geometry:c,_indirectBuffer:l}=r;for(let u=n,d=n+i;u<d;u++){let m=l?l[u]:u;Wr(c,e,t,m,s,a,o)}}function up(r,e,t,n,i,s,a){const{geometry:o,_indirectBuffer:c}=r;let l=1/0,u=null;for(let d=n,m=n+i;d<m;d++){let f;f=Wr(o,e,t,c?c[d]:d,null,s,a),f&&f.distance<l&&(u=f,l=f.distance)}return u}function dp(r,e,t,n,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=r,d=e+r;u<d;u++){let m;if(m=t.resolveTriangleIndex(u),Ce(a,m*3,c,l),a.needsUpdate=!0,n(a,m,i,s))return!0}return!1}function pp(r,e,t,n,i,s,a){ye.setBuffer(r._roots[e]),xo(0,r,t,n,i,s,a),ye.clearBuffer()}function xo(r,e,t,n,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=ye,u=r*2;if(Ee(u,c)){const d=Xe(r,l),m=it(u,c);op(e,t,n,d,m,i,s,a)}else{const d=ze(r);hn(d,o,n,s,a)&&xo(d,e,t,n,i,s,a);const m=Ne(r,l);hn(m,o,n,s,a)&&xo(m,e,t,n,i,s,a)}}const fp=["x","y","z"];function mp(r,e,t,n,i,s){ye.setBuffer(r._roots[e]);const a=wo(0,r,t,n,i,s);return ye.clearBuffer(),a}function wo(r,e,t,n,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=ye;let l=r*2;if(Ee(l,o)){const u=Xe(r,c),d=it(l,o);return ap(e,t,n,u,d,i,s)}else{const u=oo(r,c),d=fp[u],m=n.direction[d]>=0;let f,x;m?(f=ze(r),x=Ne(r,c)):(f=Ne(r,c),x=ze(r));const _=hn(f,a,n,i,s)?wo(f,e,t,n,i,s):null;if(_){const v=_.point[d];if(m?v<=a[x+u]:v>=a[x+u+3])return _}const g=hn(x,a,n,i,s)?wo(x,e,t,n,i,s):null;return _&&g?_.distance<=g.distance?_:g:_||g||null}}const Hr=new zt,Jn=new St,Gn=new St,vi=new kt,_l=new Ye,qr=new Ye;function yp(r,e,t,n){ye.setBuffer(r._roots[e]);const i=_o(0,r,t,n);return ye.clearBuffer(),i}function _o(r,e,t,n,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=ye;let c=r*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),_l.set(t.boundingBox.min,t.boundingBox.max,n),i=_l),Ee(c,a)){const l=e.geometry,u=l.index,d=l.attributes.position,m=t.index,f=t.attributes.position,x=Xe(r,o),_=it(c,a);if(vi.copy(n).invert(),t.boundsTree)return be(r,s,qr),qr.matrix.copy(vi),qr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:g=>qr.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(n),g.b.applyMatrix4(n),g.c.applyMatrix4(n),g.needsUpdate=!0;for(let v=x*3,w=(_+x)*3;v<w;v+=3)if(Ce(Gn,v,u,d),Gn.needsUpdate=!0,g.intersectsTriangle(Gn))return!0;return!1}});{const g=Fr(t);for(let v=x*3,w=(_+x)*3;v<w;v+=3){Ce(Jn,v,u,d),Jn.a.applyMatrix4(vi),Jn.b.applyMatrix4(vi),Jn.c.applyMatrix4(vi),Jn.needsUpdate=!0;for(let S=0,T=g*3;S<T;S+=3)if(Ce(Gn,S,m,f),Gn.needsUpdate=!0,Jn.intersectsTriangle(Gn))return!0}}}else{const l=ze(r),u=Ne(r,o);return be(l,s,Hr),!!(i.intersectsBox(Hr)&&_o(l,e,t,n,i)||(be(u,s,Hr),i.intersectsBox(Hr)&&_o(u,e,t,n,i)))}}const Xr=new kt,To=new Ye,Si=new Ye,gp=new q,vp=new q,Sp=new q,bp=new q;function xp(r,e,t,n={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),To.set(e.boundingBox.min,e.boundingBox.max,t),To.needsUpdate=!0;const o=r.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,d=e.index,m=bt.getPrimitive(),f=bt.getPrimitive();let x=gp,_=vp,g=null,v=null;i&&(g=Sp,v=bp);let w=1/0,S=null,T=null;return Xr.copy(t).invert(),Si.matrix.copy(Xr),r.shapecast({boundsTraverseOrder:C=>To.distanceToBox(C),intersectsBounds:(C,P,E)=>E<w&&E<a?(P&&(Si.min.copy(C.min),Si.max.copy(C.max),Si.needsUpdate=!0),!0):!1,intersectsRange:(C,P)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:E=>Si.distanceToBox(E),intersectsBounds:(E,O,A)=>A<w&&A<a,intersectsRange:(E,O)=>{for(let A=E,R=E+O;A<R;A++){Ce(f,3*A,d,u),f.a.applyMatrix4(t),f.b.applyMatrix4(t),f.c.applyMatrix4(t),f.needsUpdate=!0;for(let B=C,z=C+P;B<z;B++){Ce(m,3*B,l,c),m.needsUpdate=!0;const U=m.distanceToTriangle(f,x,g);if(U<w&&(_.copy(x),v&&v.copy(g),w=U,S=B,T=A),U<s)return!0}}}});{const E=Fr(e);for(let O=0,A=E;O<A;O++){Ce(f,3*O,d,u),f.a.applyMatrix4(t),f.b.applyMatrix4(t),f.c.applyMatrix4(t),f.needsUpdate=!0;for(let R=C,B=C+P;R<B;R++){Ce(m,3*R,l,c),m.needsUpdate=!0;const z=m.distanceToTriangle(f,x,g);if(z<w&&(_.copy(x),v&&v.copy(g),w=z,S=R,T=O),z<s)return!0}}}}}),bt.releasePrimitive(m),bt.releasePrimitive(f),w===1/0?null:(n.point?n.point.copy(_):n.point=_.clone(),n.distance=w,n.faceIndex=S,i&&(i.point?i.point.copy(v):i.point=v.clone(),i.point.applyMatrix4(Xr),_.applyMatrix4(Xr),i.distance=_.sub(i.point).length(),i.faceIndex=T),n)}function wp(r,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=r.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const u=r._roots;for(let m=0,f=u.length;m<f;m++)s=u[m],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),d(0,l),l+=s.byteLength;function d(m,f,x=!1){const _=m*2;if(Ee(_,o)){const g=Xe(m,a),v=it(_,o);let w=1/0,S=1/0,T=1/0,C=-1/0,P=-1/0,E=-1/0;for(let O=g,A=g+v;O<A;O++){const R=3*r.resolveTriangleIndex(O);for(let B=0;B<3;B++){let z=R+B;z=n?n[z]:z;const U=i.getX(z),L=i.getY(z),J=i.getZ(z);U<w&&(w=U),U>C&&(C=U),L<S&&(S=L),L>P&&(P=L),J<T&&(T=J),J>E&&(E=J)}}return c[m+0]!==w||c[m+1]!==S||c[m+2]!==T||c[m+3]!==C||c[m+4]!==P||c[m+5]!==E?(c[m+0]=w,c[m+1]=S,c[m+2]=T,c[m+3]=C,c[m+4]=P,c[m+5]=E,!0):!1}else{const g=ze(m),v=Ne(m,a);let w=x,S=!1,T=!1;if(e){if(!w){const R=g/Pe+f/qe,B=v/Pe+f/qe;S=e.has(R),T=e.has(B),w=!S&&!T}}else S=!0,T=!0;const C=w||S,P=w||T;let E=!1;C&&(E=d(g,f,w));let O=!1;P&&(O=d(v,f,w));const A=E||O;if(A)for(let R=0;R<3;R++){const B=g+R,z=v+R,U=c[B],L=c[B+3],J=c[z],H=c[z+3];c[m+R]=U<J?U:J,c[m+R+3]=L>H?L:H}return A}}}function _p(r,e,t,n,i,s,a){ye.setBuffer(r._roots[e]),Mo(0,r,t,n,i,s,a),ye.clearBuffer()}function Mo(r,e,t,n,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=ye,u=r*2;if(Ee(u,c)){const d=Xe(r,l),m=it(u,c);hp(e,t,n,d,m,i,s,a)}else{const d=ze(r);hn(d,o,n,s,a)&&Mo(d,e,t,n,i,s,a);const m=Ne(r,l);hn(m,o,n,s,a)&&Mo(m,e,t,n,i,s,a)}}const Tp=["x","y","z"];function Mp(r,e,t,n,i,s){ye.setBuffer(r._roots[e]);const a=Co(0,r,t,n,i,s);return ye.clearBuffer(),a}function Co(r,e,t,n,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=ye;let l=r*2;if(Ee(l,o)){const u=Xe(r,c),d=it(l,o);return up(e,t,n,u,d,i,s)}else{const u=oo(r,c),d=Tp[u],m=n.direction[d]>=0;let f,x;m?(f=ze(r),x=Ne(r,c)):(f=Ne(r,c),x=ze(r));const _=hn(f,a,n,i,s)?Co(f,e,t,n,i,s):null;if(_){const v=_.point[d];if(m?v<=a[x+u]:v>=a[x+u+3])return _}const g=hn(x,a,n,i,s)?Co(x,e,t,n,i,s):null;return _&&g?_.distance<=g.distance?_:g:_||g||null}}const Yr=new zt,Wn=new St,Hn=new St,bi=new kt,Tl=new Ye,Zr=new Ye;function Cp(r,e,t,n){ye.setBuffer(r._roots[e]);const i=Po(0,r,t,n);return ye.clearBuffer(),i}function Po(r,e,t,n,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=ye;let c=r*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Tl.set(t.boundingBox.min,t.boundingBox.max,n),i=Tl),Ee(c,a)){const l=e.geometry,u=l.index,d=l.attributes.position,m=t.index,f=t.attributes.position,x=Xe(r,o),_=it(c,a);if(bi.copy(n).invert(),t.boundsTree)return be(r,s,Zr),Zr.matrix.copy(bi),Zr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:g=>Zr.intersectsBox(g),intersectsTriangle:g=>{g.a.applyMatrix4(n),g.b.applyMatrix4(n),g.c.applyMatrix4(n),g.needsUpdate=!0;for(let v=x,w=_+x;v<w;v++)if(Ce(Hn,3*e.resolveTriangleIndex(v),u,d),Hn.needsUpdate=!0,g.intersectsTriangle(Hn))return!0;return!1}});{const g=Fr(t);for(let v=x,w=_+x;v<w;v++){const S=e.resolveTriangleIndex(v);Ce(Wn,3*S,u,d),Wn.a.applyMatrix4(bi),Wn.b.applyMatrix4(bi),Wn.c.applyMatrix4(bi),Wn.needsUpdate=!0;for(let T=0,C=g*3;T<C;T+=3)if(Ce(Hn,T,m,f),Hn.needsUpdate=!0,Wn.intersectsTriangle(Hn))return!0}}}else{const l=ze(r),u=Ne(r,o);return be(l,s,Yr),!!(i.intersectsBox(Yr)&&Po(l,e,t,n,i)||(be(u,s,Yr),i.intersectsBox(Yr)&&Po(u,e,t,n,i)))}}const Kr=new kt,Eo=new Ye,xi=new Ye,Pp=new q,Ep=new q,kp=new q,Rp=new q;function Ap(r,e,t,n={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Eo.set(e.boundingBox.min,e.boundingBox.max,t),Eo.needsUpdate=!0;const o=r.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,d=e.index,m=bt.getPrimitive(),f=bt.getPrimitive();let x=Pp,_=Ep,g=null,v=null;i&&(g=kp,v=Rp);let w=1/0,S=null,T=null;return Kr.copy(t).invert(),xi.matrix.copy(Kr),r.shapecast({boundsTraverseOrder:C=>Eo.distanceToBox(C),intersectsBounds:(C,P,E)=>E<w&&E<a?(P&&(xi.min.copy(C.min),xi.max.copy(C.max),xi.needsUpdate=!0),!0):!1,intersectsRange:(C,P)=>{if(e.boundsTree){const E=e.boundsTree;return E.shapecast({boundsTraverseOrder:O=>xi.distanceToBox(O),intersectsBounds:(O,A,R)=>R<w&&R<a,intersectsRange:(O,A)=>{for(let R=O,B=O+A;R<B;R++){const z=E.resolveTriangleIndex(R);Ce(f,3*z,d,u),f.a.applyMatrix4(t),f.b.applyMatrix4(t),f.c.applyMatrix4(t),f.needsUpdate=!0;for(let U=C,L=C+P;U<L;U++){const J=r.resolveTriangleIndex(U);Ce(m,3*J,l,c),m.needsUpdate=!0;const H=m.distanceToTriangle(f,x,g);if(H<w&&(_.copy(x),v&&v.copy(g),w=H,S=U,T=R),H<s)return!0}}}})}else{const E=Fr(e);for(let O=0,A=E;O<A;O++){Ce(f,3*O,d,u),f.a.applyMatrix4(t),f.b.applyMatrix4(t),f.c.applyMatrix4(t),f.needsUpdate=!0;for(let R=C,B=C+P;R<B;R++){const z=r.resolveTriangleIndex(R);Ce(m,3*z,l,c),m.needsUpdate=!0;const U=m.distanceToTriangle(f,x,g);if(U<w&&(_.copy(x),v&&v.copy(g),w=U,S=R,T=O),U<s)return!0}}}}}),bt.releasePrimitive(m),bt.releasePrimitive(f),w===1/0?null:(n.point?n.point.copy(_):n.point=_.clone(),n.distance=w,n.faceIndex=S,i&&(i.point?i.point.copy(v):i.point=v.clone(),i.point.applyMatrix4(Kr),_.applyMatrix4(Kr),i.distance=_.sub(i.point).length(),i.faceIndex=T),n)}function Ml(r,e,t){return r===null?null:(r.point.applyMatrix4(e.matrixWorld),r.distance=r.point.distanceTo(t.ray.origin),r.object=e,r)}const Qr=new Ye,$r=new oh,Cl=new q,Pl=new kt,El=new q,ko=["getX","getY","getZ"];class Kn extends yl{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,i=e._roots,s=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=i.map(c=>c.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=s?s.slice():null):(o.roots=i,o.index=a?a.array:null,o.indirectBuffer=s),o}static deserialize(e,t,n={}){n={setIndex:!0,indirect:!!e.indirectBuffer,...n};const{index:i,roots:s,indirectBuffer:a}=e;e.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),c(s));const o=new Kn(t,{...n,[Br]:!0});if(o._roots=s,o._indirectBuffer=a||null,n.setIndex){const l=t.getIndex();if(l===null){const u=new dt(e.index,1,!1);t.setIndex(u)}else l.array!==i&&(l.array.set(i),l.needsUpdate=!0)}return o;function c(l){for(let u=0;u<l.length;u++){const d=l[u],m=new Uint32Array(d),f=new Uint16Array(d);for(let x=0,_=d.byteLength/qe;x<_;x++){const g=Pe*x,v=2*g;Ee(v,f)||(m[g+6]=m[g+6]/Pe-x)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),t={...t,maxLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){const i=this.geometry,s=this._indirectBuffer,a=i.attributes.position,o=i.index?i.index.array:null,c=(s?s[e]:e)*3;let l=c+0,u=c+1,d=c+2;o&&(l=o[l],u=o[u],d=o[d]);for(let m=0;m<3;m++){const f=a[ko[m]](l),x=a[ko[m]](u),_=a[ko[m]](d);let g=f;x<g&&(g=x),_<g&&(g=_);let v=f;x>v&&(v=x),_>v&&(v=_),t[n+m]=g,t[n+m+3]=v}return t}computePrimitiveBounds(e,t,n){const i=this.geometry,s=this._indirectBuffer,a=i.attributes.position,o=i.index?i.index.array:null,c=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=a.array,u=a.offset||0;let d=3;a.isInterleavedBufferAttribute&&(d=a.data.stride);const m=["getX","getY","getZ"],f=n.offset;for(let x=e,_=e+t;x<_;x++){const g=(s?s[x]:x)*3,v=(x-f)*6;let w=g+0,S=g+1,T=g+2;o&&(w=o[w],S=o[S],T=o[T]),c||(w=w*d+u,S=S*d+u,T=T*d+u);for(let C=0;C<3;C++){let P,E,O;c?(P=a[m[C]](w),E=a[m[C]](S),O=a[m[C]](T)):(P=l[w+C],E=l[S+C],O=l[T+C]);let A=P;E<A&&(A=E),O<A&&(A=O);let R=P;E>R&&(R=E),O>R&&(R=O);const B=(R-A)/2,z=C*2;n[v+z+0]=A+B,n[v+z+1]=B+(Math.abs(A)+B)*Ir}}return n}raycastObject3D(e,t,n=[]){const{material:i}=e;if(i===void 0)return;Pl.copy(e.matrixWorld).invert(),$r.copy(t.ray).applyMatrix4(Pl),El.setFromMatrixScale(e.matrixWorld),Cl.copy($r.direction).multiply(El);const s=Cl.length(),a=t.near/s,o=t.far/s;if(t.firstHitOnly===!0){let c=this.raycastFirst($r,i,a,o);c=Ml(c,e,t),c&&n.push(c)}else{const c=this.raycast($r,i,a,o);for(let l=0,u=c.length;l<u;l++){const d=Ml(c[l],e,t);d&&n.push(d)}}return n}refit(e=null){return(this.indirect?wp:lp)(this,e)}raycast(e,t=ca,n=0,i=1/0){const s=this._roots,a=[],o=this.indirect?_p:pp;for(let c=0,l=s.length;c<l;c++)o(this,c,t,e,a,n,i);return a}raycastFirst(e,t=ca,n=0,i=1/0){const s=this._roots;let a=null;const o=this.indirect?Mp:mp;for(let c=0,l=s.length;c<l;c++){const u=o(this,c,t,e,n,i);u!=null&&(a==null||u.distance<a.distance)&&(a=u)}return a}intersectsGeometry(e,t){let n=!1;const i=this._roots,s=this.indirect?Cp:yp;for(let a=0,o=i.length;a<o&&(n=s(this,a,e,t),!n);a++);return n}shapecast(e){const t=bt.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?dp:cp});return bt.releasePrimitive(t),n}bvhcast(e,t,n){let{intersectsRanges:i,intersectsTriangles:s}=n;const a=bt.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?x=>{const _=this.resolveTriangleIndex(x);Ce(a,_*3,o,c)}:x=>{Ce(a,x*3,o,c)},u=bt.getPrimitive(),d=e.geometry.index,m=e.geometry.attributes.position,f=e.indirect?x=>{const _=e.resolveTriangleIndex(x);Ce(u,_*3,d,m)}:x=>{Ce(u,x*3,d,m)};if(s){if(!(e instanceof Kn))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const x=(_,g,v,w,S,T,C,P)=>{for(let E=v,O=v+w;E<O;E++){f(E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let A=_,R=_+g;A<R;A++)if(l(A),a.needsUpdate=!0,s(a,u,A,E,S,T,C,P))return!0}return!1};if(i){const _=i;i=function(g,v,w,S,T,C,P,E){return _(g,v,w,S,T,C,P,E)?!0:x(g,v,w,S,T,C,P,E)}}else i=x}return super.bvhcast(e,t,{intersectsRanges:i})}intersectsBox(e,t){return Qr.set(e.min,e.max,t),Qr.needsUpdate=!0,this.shapecast({intersectsBounds:n=>Qr.intersectsBox(n),intersectsTriangle:n=>Qr.intersectsTriangle(n)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},i={},s=0,a=1/0){return(this.indirect?Ap:xp)(this,e,t,n,i,s,a)}closestPointToPoint(e,t={},n=0,i=1/0){return ip(this,e,t,n,i)}}const qn={Mesh:lr.prototype.raycast,Line:ua.prototype.raycast,LineSegments:la.prototype.raycast,LineLoop:ha.prototype.raycast,Points:da.prototype.raycast,BatchedMesh:ch.prototype.raycast},Je=new lr,es=[];function Op(r,e){if(this.isBatchedMesh)Ip.call(this,r,e);else{const{geometry:t}=this;if(t.boundsTree)t.boundsTree.raycastObject3D(this,r,e);else{let n;if(this instanceof lr)n=qn.Mesh;else if(this instanceof la)n=qn.LineSegments;else if(this instanceof ha)n=qn.LineLoop;else if(this instanceof ua)n=qn.Line;else if(this instanceof da)n=qn.Points;else throw new Error("BVH: Fallback raycast function not found.");n.call(this,r,e)}}}function Ip(r,e){if(this.boundsTrees){const t=this.boundsTrees,n=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,s=this.matrixWorld;Je.material=this.material,Je.geometry=this.geometry;const a=Je.geometry.boundsTree,o=Je.geometry.drawRange;Je.geometry.boundingSphere===null&&(Je.geometry.boundingSphere=new ah);for(let c=0,l=n.length;c<l;c++){if(!this.getVisibleAt(c))continue;const u=n[c].geometryIndex;if(Je.geometry.boundsTree=t[u],this.getMatrixAt(c,Je.matrixWorld).premultiply(s),!Je.geometry.boundsTree){this.getBoundingBoxAt(u,Je.geometry.boundingBox),this.getBoundingSphereAt(u,Je.geometry.boundingSphere);const d=i[u];Je.geometry.setDrawRange(d.start,d.count)}Je.raycast(r,es);for(let d=0,m=es.length;d<m;d++){const f=es[d];f.object=this,f.batchId=c,e.push(f)}es.length=0}Je.geometry.boundsTree=a,Je.geometry.drawRange=o,Je.material=null,Je.geometry=null}else qn.BatchedMesh.call(this,r,e)}function Bp(r={}){const{type:e=Kn}=r;return this.boundsTree=new e(this,r),this.boundsTree}const xn=new q,wn=new q,_n=new q,kl=new ws,ts=new q,Ro=new q,Rl=new ws,Al=new ws,ns=new kt,Ol=new kt;function wi(r,e){if(!r&&!e)return;const t=r.count===e.count,n=r.normalized===e.normalized,i=r.array.constructor===e.array.constructor,s=r.itemSize===e.itemSize;if(!t||!n||!i||!s)throw new Error}function _i(r,e=null){const t=r.array.constructor,n=r.normalized,i=r.itemSize,s=e===null?r.count:e;return new dt(new t(i*s),i,n)}function Il(r,e,t=0){if(r.isInterleavedBufferAttribute){const n=r.itemSize;for(let i=0,s=r.count;i<s;i++){const a=i+t;e.setX(a,r.getX(i)),n>=2&&e.setY(a,r.getY(i)),n>=3&&e.setZ(a,r.getZ(i)),n>=4&&e.setW(a,r.getW(i))}}else{const n=e.array,i=n.constructor,s=n.BYTES_PER_ELEMENT*r.itemSize*t;new i(n.buffer,s,r.array.length).set(r.array)}}function zp(r,e,t){const n=r.elements,i=e.elements;for(let s=0,a=i.length;s<a;s++)n[s]+=i[s]*t}function Bl(r,e,t){const n=r.skeleton,i=r.geometry,s=n.bones,a=n.boneInverses;Rl.fromBufferAttribute(i.attributes.skinIndex,e),Al.fromBufferAttribute(i.attributes.skinWeight,e),ns.elements.fill(0);for(let o=0;o<4;o++){const c=Al.getComponent(o);if(c!==0){const l=Rl.getComponent(o);Ol.multiplyMatrices(s[l].matrixWorld,a[l]),zp(ns,Ol,c)}}return ns.multiply(r.bindMatrix).premultiply(r.bindMatrixInverse),t.transformDirection(ns),t}function Ao(r,e,t,n,i){ts.set(0,0,0);for(let s=0,a=r.length;s<a;s++){const o=e[s],c=r[s];o!==0&&(Ro.fromBufferAttribute(c,n),t?ts.addScaledVector(Ro,o):ts.addScaledVector(Ro.sub(i),o))}i.add(ts)}function Np(r,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new ti){const n=r[0].index!==null,{useGroups:i=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(r[0].attributes)),c={};let l=0;t.clearGroups();for(let u=0;u<r.length;++u){const d=r[u];let m=0;if(n!==(d.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const f in d.attributes){if(!o.has(f))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.');c[f]===void 0&&(c[f]=[]),c[f].push(d.attributes[f]),m++}if(m!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(i){let f;if(n)f=d.index.count;else if(d.attributes.position!==void 0)f=d.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,f,u),l+=f}}if(n){let u=!1;if(!t.index){let d=0;for(let m=0;m<r.length;++m)d+=r[m].index.count;t.setIndex(new dt(new Uint32Array(d),1,!1)),u=!0}if(s||u){const d=t.index;let m=0,f=0;for(let x=0;x<r.length;++x){const _=r[x],g=_.index;if(a[x]!==!0)for(let v=0;v<g.count;++v)d.setX(m,g.getX(v)+f),m++;f+=_.attributes.position.count}}}for(const u in c){const d=c[u];if(!(u in t.attributes)){let x=0;for(const _ in d)x+=d[_].count;t.setAttribute(u,_i(c[u][0],x))}const m=t.attributes[u];let f=0;for(let x=0,_=d.length;x<_;x++){const g=d[x];a[x]!==!0&&Il(g,m,f),f+=g.count}}return t}function Up(r,e){if(r===null||e===null)return r===e;if(r.length!==e.length)return!1;for(let t=0,n=r.length;t<n;t++)if(r[t]!==e[t])return!1;return!0}function Dp(r){const{index:e,attributes:t}=r;if(e)for(let n=0,i=e.count;n<i;n+=3){const s=e.getX(n),a=e.getX(n+2);e.setX(n,a),e.setX(n+2,s)}else for(const n in t){const i=t[n],s=i.itemSize;for(let a=0,o=i.count;a<o;a+=3)for(let c=0;c<s;c++){const l=i.getComponent(a,c),u=i.getComponent(a+2,c);i.setComponent(a,c,u),i.setComponent(a+2,c,l)}}return r}class Lp{constructor(e){this.matrixWorld=new kt,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,n=e.skeleton,i=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=i,n){n.boneTexture||n.computeBoneTexture(),n.update();const s=n.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==s.length?this.boneMatrices=s.slice():this.boneMatrices.set(s)}else this.boneMatrices=null}didChange(){const e=this.mesh,t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&Up(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===n)}}class Fp{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(n=>{n.traverseVisible(i=>{i.isMesh&&t.push(i)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(t.length).fill().map(()=>new ti),this._diffMap=new WeakMap}getMaterials(){const e=[];return this.meshes.forEach(t=>{Array.isArray(t.material)?e.push(...t.material):e.push(t.material)}),e}generate(e=new ti){let t=[];const{meshes:n,useGroups:i,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=n.length;o<c;o++){const l=n[o],u=s[o],d=a.get(l);!d||d.didChange(l)?(this._convertToStaticGeometry(l,u),t.push(!1),d?d.update():a.set(l,new Lp(l))):t.push(!0)}if(s.length===0){e.setIndex(null);const o=e.attributes;for(const c in o)e.deleteAttribute(c);for(const c in this.attributes)e.setAttribute(this.attributes[c],new dt(new Float32Array(0),4,!1))}else Np(s,{useGroups:i,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new ti){const n=e.geometry,i=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=n.attributes,c=t.attributes;!t.index&&n.index&&(t.index=n.index.clone()),c.position||t.setAttribute("position",_i(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",_i(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",_i(o.tangent)),wi(n.index,t.index),wi(o.position,c.position),s&&wi(o.normal,c.normal),a&&wi(o.tangent,c.tangent);const l=o.position,u=s?o.normal:null,d=a?o.tangent:null,m=n.morphAttributes.position,f=n.morphAttributes.normal,x=n.morphAttributes.tangent,_=n.morphTargetsRelative,g=e.morphTargetInfluences,v=new lh;v.getNormalMatrix(e.matrixWorld),n.index&&t.index.array.set(n.index.array);for(let w=0,S=o.position.count;w<S;w++)xn.fromBufferAttribute(l,w),u&&wn.fromBufferAttribute(u,w),d&&(kl.fromBufferAttribute(d,w),_n.fromBufferAttribute(d,w)),g&&(m&&Ao(m,g,_,w,xn),f&&Ao(f,g,_,w,wn),x&&Ao(x,g,_,w,_n)),e.isSkinnedMesh&&(e.applyBoneTransform(w,xn),u&&Bl(e,w,wn),d&&Bl(e,w,_n)),i&&xn.applyMatrix4(e.matrixWorld),c.position.setXYZ(w,xn.x,xn.y,xn.z),u&&(i&&wn.applyNormalMatrix(v),c.normal.setXYZ(w,wn.x,wn.y,wn.z)),d&&(i&&_n.transformDirection(e.matrixWorld),c.tangent.setXYZW(w,_n.x,_n.y,_n.z,kl.w));for(const w in this.attributes){const S=this.attributes[w];S==="position"||S==="tangent"||S==="normal"||!(S in o)||(c[S]||t.setAttribute(S,_i(o[S])),wi(o[S],c[S]),Il(o[S],c[S]))}return e.matrixWorld.determinant()<0&&Dp(t),t}}const Vp=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:nl,BVH:pl,CENTER:io,CONTAINED:ro,ExtendedTriangle:St,GeometryBVH:yl,MeshBVH:Kn,OrientedBox:Ye,SAH:il,SKIP_GENERATION:Br,StaticGeometryGenerator:Fp,acceleratedRaycast:Op,computeBoundsTree:Bp,generateIndirectBuffer:ml},Symbol.toStringTag,{value:"Module"}));class jp{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}const xt={node:"node",material:"material",camera:"camera",light:"light"},Tn="KHR_animation_pointer",Jp={CUBICSPLINE:void 0,LINEAR:pa,STEP:uh};class Gp{constructor(e){this.name=Tn,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,n=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",n)}loadAnimationTargetFromChannelWithAnimationPointer(e){Hp();const t=e.target,n=t.extensions&&t.extensions[Tn]&&t.path&&t.path==="pointer";if(!n)return null;let i,s=xt.node,a;if(n){const c=t.extensions[Tn];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=xt.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=xt.light:l.startsWith("/cameras/")&&(s=xt.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case xt.material:const u=("/materials/"+a.toString()+"/").length,d=l.substring(0,u);switch(i=l.substring(u),i){case"pbrMetallicRoughness/baseColorFactor":i="color";break;case"pbrMetallicRoughness/roughnessFactor":i="roughness";break;case"pbrMetallicRoughness/metallicFactor":i="metalness";break;case"emissiveFactor":i="emissive";break;case"alphaCutoff":i="alphaTest";break;case"occlusionTexture/strength":i="aoMapIntensity";break;case"normalTexture/scale":i="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":i="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":i="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":i="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":i="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":i="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":i="transmission";break;case"extensions/KHR_materials_ior/ior":i="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":i="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":i="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":i="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":i="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":i="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":i="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":i="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":i="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":i="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":i="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":i="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":i="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":i="specularColor";break}l=d+i;break;case xt.node:const m=("/nodes/"+a.toString()+"/").length,f=l.substring(0,m);switch(i=l.substring(m),i){case"translation":i="position";break;case"rotation":i="quaternion";break;case"scale":i="scale";break;case"weights":i="morphTargetInfluences";break;case"extensions/KHR_node_visibility/visible":i="visible";break}l=f+i;break;case xt.light:const x=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(i=l.substring(x),i){case"color":break;case"intensity":break;case"spot/innerConeAngle":i="penumbra";break;case"spot/outerConeAngle":i="angle";break;case"range":i="distance";break}l="/lights/"+a.toString()+"/"+i;break;case xt.camera:const _=("/cameras/"+a.toString()+"/").length,g=l.substring(0,_);switch(i=l.substring(_),i){case"perspective/yfov":i="fov";break;case"perspective/znear":case"orthographic/znear":i="near";break;case"perspective/zfar":case"orthographic/zfar":i="far";break;case"perspective/aspect":i="aspect";break;case"orthographic/xmag":i="zoom";break;case"orthographic/ymag":i="zoom";break}l=g+i;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[Tn].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===xt.node?o=this.parser.getDependency("node",a):s===xt.material?o=this.parser.getDependency("material",a):s===xt.light?o=this.parser.getDependency("light",a):s===xt.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,n,i,s){if(!(s.extensions&&s.extensions[Tn]&&s.path&&s.path==="pointer"))return null;let a=s.extensions[Tn].pointer;if(!a)return null;const o=[];a=a.replaceAll("/",".");const c=a.split(".");var l=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(c[2]=l,c[3]==="morphTargetInfluences"&&e.type==="Group"){for(const m of e.children)m instanceof hh&&m.morphTargetInfluences&&(c[3]=m.name,c[4]="morphTargetInfluences",d(this.parser));return o}d(this.parser);function u(m,f){try{const x=f.split(".").filter(Boolean),_=x[x.length-1].replace(/\[.*\]$/,"");return _ in m?typeof m[_]=="boolean":!1}catch{return!1}}function d(m){a=c.join(".");let f,x=!1;switch(n.itemSize){case 1:Object.prototype.toString.call(n.array)==="[object Uint8Array]"&&u(e,a)?(f=yh,x=!0):f=gh;break;case 2:case 3:f=mh;break;case 4:a.endsWith(".quaternion")?f=ph:f=fh;break}if(!f){console.warn("Unsupported output accessor format",n);return}const _=i.interpolation!==void 0?Jp[i.interpolation]:pa;let g=m._getArrayFromAccessor(n);a.endsWith(".fov")&&(g=g.map(w=>w/Math.PI*180)),x&&(g=g.map(w=>w>0));const v=new f(a,t.array,g,_);if(_==="CUBICSPLINE"&&m._createCubicSplineTrackInterpolant(v),o.push(v),a&&n.itemSize===4&&a.startsWith(".materials.")&&a.endsWith(".color")){const w=new Float32Array(g.length/4);for(let T=0,C=g.length/4;T<C;T+=1)w[T]=g[T*4+3];const S=new f(a.replace(".color",".opacity"),t.array,w,_);_==="CUBICSPLINE"&&m._createCubicSplineTrackInterpolant(v),o.push(S)}}return o}_tryResolveTargetId(e,t){let n="";return t==="node"?n=e.substring(7):t==="material"?n=e.substring(11):t==="light"?n=e.substring(39):t==="camera"&&(n=e.substring(9)),n=n.substring(0,n.indexOf("/")),Number.parseInt(n)}loadAnimation(e){const t=this,n=this.parser.json,i=this.parser,s=n.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],u=[],d=[];for(let m=0,f=s.channels.length;m<f;m++){const x=s.channels[m],_=s.samplers[x.sampler],g=x.target,v=s.parameters!==void 0?s.parameters[_.input]:_.input,w=s.parameters!==void 0?s.parameters[_.output]:_.output;let S=t.loadAnimationTargetFromChannelWithAnimationPointer(x);S||(S=t.loadAnimationTargetFromChannel(x)),o.push(S),c.push(i.getDependency("accessor",v)),l.push(i.getDependency("accessor",w)),u.push(_),d.push(g)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(u),Promise.all(d)]).then(function(m){const f=m[0],x=m[1],_=m[2],g=m[3],v=m[4],w=[];for(let S=0,T=f.length;S<T;S++){const C=f[S],P=x[S],E=_[S],O=g[S],A=v[S];if(C===void 0)continue;C.updateMatrix&&(C.updateMatrix(),C.matrixAutoUpdate=!0);let R=t.createAnimationTracksWithAnimationPointer(C,P,E,O,A);if(R||(R=i._createAnimationTracks(C,P,E,O,A)),R)for(let B=0;B<R.length;B++)w.push(R[B])}return new dh(a,void 0,w)})}}let zl=!1,Wp=null;function Hp(){if(zl)return;zl=!0;const r=Wp||=fa.findNode;fa.findNode=function(e,t){if(!t)return r(e,t);if(t.startsWith(".materials.")){const n=t.substring(11).substring(t.indexOf(".")),i=n.indexOf("."),s=i<0?n:n.substring(0,i);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(n.endsWith(".map")?a=a.map:n.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const n=t.split(".");let i;for(let s=1;s<n.length;s++){const a=n[s];if(a.length==36)i=e.getObjectByProperty("uuid",a);else if(i&&i[a]){const o=Number.parseInt(a);let c=a;o>=0&&(c=o),i=i[c]}else{const o=e.getObjectByName(a);o&&(i=o)}}if(!i){const s=r(e,n[2]);return s||console.warn(Tn+": Property binding not found",t,e,e.name,n),s}return i}return r(e,t)}}const qp=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Gp},Symbol.toStringTag,{value:"Module"}));export{Yu as BatchedParticleRenderer,Oo as Builder,Ti as ByteBuffer,Cn as ConstantColor,ie as ConstantValue,It as Matrix4,Kn as MeshBVH,Fh as MotionController,os as ParticleSystem,V as RenderMode,_a as SIZE_PREFIX_LENGTH,Sr as TrailParticle,ct as Vector4,jp as WorkerBase,wh as _md5,Id as bundler,Ku as createNoise4D,zh as fetchProfile,Nd as index,Vp as index$1,qp as index$2,wa as md5,Ih as v5};