@needle-tools/engine 4.8.6-next.f3ce848 → 4.8.7-next.3c34e8b
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.
- package/CHANGELOG.md +4 -0
- package/components.needle.json +1 -1
- package/dist/{gltf-progressive-DXRy9EQz.js → gltf-progressive-BcHT3Nyo.js} +1 -1
- package/dist/{gltf-progressive-C-U_onhf.umd.cjs → gltf-progressive-CH3Q4H06.umd.cjs} +1 -1
- package/dist/{gltf-progressive-DViD_J_l.min.js → gltf-progressive-DR6HqF_h.min.js} +1 -1
- package/dist/{needle-engine.bundle-C4N-adas.umd.cjs → needle-engine.bundle-BgFqEj5W.umd.cjs} +134 -134
- package/dist/{needle-engine.bundle-CJSl-mXb.min.js → needle-engine.bundle-BthqMTPI.min.js} +124 -124
- package/dist/{needle-engine.bundle-fXDFH_oR.js → needle-engine.bundle-Fj5SzBaF.js} +3850 -3812
- package/dist/needle-engine.js +394 -393
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-61aXdqNz.umd.cjs → postprocessing-CVb_x9YY.umd.cjs} +1 -1
- package/dist/{postprocessing-D9jDHD0U.js → postprocessing-ORx-0eCx.js} +1 -1
- package/dist/{postprocessing-Be9Ds4NK.min.js → postprocessing-Ywv5oKkX.min.js} +1 -1
- package/dist/three-examples-BX_Sktc9.min.js +501 -0
- package/dist/{three-examples-BihZ_R96.js → three-examples-CNexix3E.js} +2436 -2781
- package/dist/{three-examples-Ce6Th3bv.umd.cjs → three-examples-DWxXVnws.umd.cjs} +21 -21
- package/dist/{vendor-BRpzuoJE.min.js → vendor-C43vobGc.min.js} +37 -37
- package/dist/{vendor-p_xp9KuJ.js → vendor-Z4SPrTcP.js} +2402 -2047
- package/dist/vendor-xfQ8tKF3.umd.cjs +1121 -0
- package/lib/engine/api.d.ts +1 -0
- package/lib/engine/api.js +1 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/engine_addressables.d.ts +12 -12
- package/lib/engine/engine_addressables.js +30 -23
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_animation.d.ts +1 -3
- package/lib/engine/engine_animation.js +15 -9
- package/lib/engine/engine_animation.js.map +1 -1
- package/lib/engine/engine_feature_flags.d.ts +3 -0
- package/lib/engine/engine_feature_flags.js +6 -0
- package/lib/engine/engine_feature_flags.js.map +1 -0
- package/lib/engine/engine_loaders.js +15 -11
- package/lib/engine/engine_loaders.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.d.ts +2 -1
- package/lib/engine/engine_mainloop_utils.js +16 -4
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/extensions/extensions.js +2 -2
- package/lib/engine/extensions/extensions.js.map +1 -1
- package/lib/engine/js-extensions/Object3D.js +19 -0
- package/lib/engine/js-extensions/Object3D.js.map +1 -1
- package/lib/engine-components/Animation.js +2 -1
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimationUtilsAutoplay.js +1 -6
- package/lib/engine-components/AnimationUtilsAutoplay.js.map +1 -1
- package/lib/engine-components/DropListener.d.ts +17 -12
- package/lib/engine-components/DropListener.js +34 -31
- package/lib/engine-components/DropListener.js.map +1 -1
- package/lib/engine-components/LookAtConstraint.d.ts +5 -1
- package/lib/engine-components/LookAtConstraint.js +8 -0
- package/lib/engine-components/LookAtConstraint.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +5 -7
- package/lib/engine-components/OrbitControls.js +12 -11
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.d.ts +1 -1
- package/lib/engine-components/webxr/WebXRImageTracking.js +12 -10
- package/lib/engine-components/webxr/WebXRImageTracking.js.map +1 -1
- package/package.json +3 -2
- package/plugins/vite/alias.js +45 -23
- package/src/engine/api.ts +2 -1
- package/src/engine/engine_addressables.ts +44 -33
- package/src/engine/engine_animation.ts +17 -9
- package/src/engine/engine_feature_flags.ts +8 -0
- package/src/engine/engine_loaders.ts +18 -13
- package/src/engine/engine_mainloop_utils.ts +21 -6
- package/src/engine/extensions/extensions.ts +2 -2
- package/src/engine/js-extensions/Object3D.ts +25 -2
- package/src/engine-components/Animation.ts +1 -1
- package/src/engine-components/AnimationUtilsAutoplay.ts +1 -6
- package/src/engine-components/DropListener.ts +40 -31
- package/src/engine-components/LookAtConstraint.ts +9 -1
- package/src/engine-components/OrbitControls.ts +19 -16
- package/src/engine-components/webxr/WebXRImageTracking.ts +16 -14
- package/dist/three-examples-DKY9Nfge.min.js +0 -501
- package/dist/vendor-Ja-vKV-a.umd.cjs +0 -1121
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{PlaneGeometry as gs,ShaderChunk as Fa,Object3D as vs,Layers as hi,MeshBasicMaterial as _s,DoubleSide as sn,AdditiveBlending as bs,InstancedBufferAttribute as Ct,DynamicDrawUsage as ge,InstancedBufferGeometry as La,Uniform$1 as Le,ShaderMaterial as on,BufferGeometry as ar,BufferAttribute as Te,Mesh as an,MeshStandardMaterial as Va,MeshPhysicalMaterial as ja,Triangle as Pt,Vector3 as I,Plane as xs,Line3 as ht,Vector2 as Vt,Sphere as Ss,Matrix4 as Ve,Box3 as Ye,BackSide as Ja,REVISION as Ga,FrontSide as ws,BatchedMesh as Wa,Ray as Xa,Matrix3 as qa,Vector4 as cn}from"./three-CsmWHVn7.min.js";const ne={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 Ms(n){const e=await fetch(n);if(e.ok)return e.json();throw new Error(e.statusText)}async function Ha(n){return await Ms(`${n}/profilesList.json`)}async function Ya(n,e,t=null,r=!0){if(!n)throw new Error("No xrInputSource supplied");const i=await Ha(e);let s;if(n.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 Ms(s.profilePath);let o;if(r){let c;if(n.handedness==="any"?c=a.layouts[Object.keys(a.layouts)[0]]:c=a.layouts[n.handedness],!c)throw new Error(`No matching handedness, ${n.handedness}, in profile ${s.profileId}`);c.assetPath&&(o=s.profilePath.replace("profile.json",c.assetPath))}return{profile:a,assetPath:o}}const Za={xAxis:0,yAxis:0,button:0,state:ne.ComponentState.DEFAULT};function Qa(n=0,e=0){let t=n,r=e;if(Math.sqrt(n*n+e*e)>1){const i=Math.atan2(e,n);t=Math.cos(i),r=Math.sin(i)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:r*.5+.5}}class Ka{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===ne.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(Za)}updateFromComponent({xAxis:e,yAxis:t,button:r,state:i}){const{normalizedXAxis:s,normalizedYAxis:a}=Qa(e,t);switch(this.componentProperty){case ne.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?s:.5;break;case ne.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?a:.5;break;case ne.ComponentProperty.BUTTON:this.value=this.states.includes(i)?r:0;break;case ne.ComponentProperty.STATE:this.valueNodeProperty===ne.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 $a{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(r=>{const i=new Ka(t.visualResponses[r]);this.visualResponses[r]=i}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:ne.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=ne.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=ne.ComponentState.PRESSED:(t.touched||this.values.button>ne.ButtonTouchThreshold)&&(this.values.state=ne.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===ne.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>ne.AxisTouchThreshold&&(this.values.state=ne.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===ne.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>ne.AxisTouchThreshold&&(this.values.state=ne.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class ec{constructor(e,t,r){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=r,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 $a(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 ln=2,Ze=4,ut=4,Ts=4,gt=new Int32Array(2),Cs=new Float32Array(gt.buffer),Ps=new Float64Array(gt.buffer),ui=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;class yt{constructor(e,t){this.low=e|0,this.high=t|0}static create(e,t){return e==0&&t==0?yt.ZERO:new yt(e,t)}toFloat64(){return(this.low>>>0)+this.high*4294967296}equals(e){return this.low==e.low&&this.high==e.high}}yt.ZERO=new yt(0,0);var hn;(function(n){n[n.UTF8_BYTES=1]="UTF8_BYTES",n[n.UTF16_STRING=2]="UTF16_STRING"})(hn||(hn={}));class Or{constructor(e){this.bytes_=e,this.position_=0}static allocate(e){return new Or(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 yt(this.readInt32(e),this.readInt32(e+4))}readUint64(e){return new yt(this.readUint32(e),this.readUint32(e+4))}readFloat32(e){return gt[0]=this.readInt32(e),Cs[0]}readFloat64(e){return gt[ui?0:1]=this.readInt32(e),gt[ui?1:0]=this.readInt32(e+4),Ps[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){Cs[0]=t,this.writeInt32(e,gt[0])}writeFloat64(e,t){Ps[0]=t,this.writeInt32(e,gt[ui?0:1]),this.writeInt32(e+4,gt[ui?1:0])}getBufferIdentifier(){if(this.bytes_.length<this.position_+Ze+ut)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");let e="";for(let t=0;t<ut;t++)e+=String.fromCharCode(this.readInt8(this.position_+Ze+t));return e}__offset(e,t){const r=e-this.readInt32(e);return t<this.readInt16(r)?this.readInt16(r+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 r=this.readInt32(e);let i="",s=0;if(e+=Ze,t===hn.UTF8_BYTES)return this.bytes_.subarray(e,e+r);for(;s<r;){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 h=this.readUint8(e+s++);a=(o&7)<<18|(c&63)<<12|(l&63)<<6|h&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)+Ze}__vector_len(e){return this.readInt32(e+this.readInt32(e))}__has_identifier(e){if(e.length!=ut)throw new Error("FlatBuffers: file identifier must be length "+ut);for(let t=0;t<ut;t++)if(e.charCodeAt(t)!=this.readInt8(this.position()+Ze+t))return!1;return!0}createLong(e,t){return yt.create(e,t)}createScalarList(e,t){const r=[];for(let i=0;i<t;++i)e(i)!==null&&r.push(e(i));return r}createObjList(e,t){const r=[];for(let i=0;i<t;++i){const s=e(i);s!==null&&r.push(s.unpack())}return r}}class ms{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=Or.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 r=~(this.bb.capacity()-this.space+t)+1&e-1;for(;this.space<r+e+t;){const i=this.bb.capacity();this.bb=ms.growByteBuffer(this.bb),this.space+=this.bb.capacity()-i}this.pad(r)}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,r){(this.force_defaults||t!=r)&&(this.addInt8(t),this.slot(e))}addFieldInt16(e,t,r){(this.force_defaults||t!=r)&&(this.addInt16(t),this.slot(e))}addFieldInt32(e,t,r){(this.force_defaults||t!=r)&&(this.addInt32(t),this.slot(e))}addFieldInt64(e,t,r){(this.force_defaults||!t.equals(r))&&(this.addInt64(t),this.slot(e))}addFieldFloat32(e,t,r){(this.force_defaults||t!=r)&&(this.addFloat32(t),this.slot(e))}addFieldFloat64(e,t,r){(this.force_defaults||t!=r)&&(this.addFloat64(t),this.slot(e))}addFieldOffset(e,t,r){(this.force_defaults||t!=r)&&(this.addOffset(t),this.slot(e))}addFieldStruct(e,t,r){t!=r&&(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 r=t<<1,i=Or.allocate(r);return i.setPosition(r-t),i.bytes().set(e.bytes(),r-t),i}addOffset(e){this.prep(Ze,0),this.writeInt32(this.offset()-e+Ze)}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 r=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=(r+i)*ln;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=ln;l<s;l+=ln)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,r){const i=r?Ts:0;if(t){const s=t;if(this.prep(this.minalign,Ze+ut+i),s.length!=ut)throw new Error("FlatBuffers: file identifier must be length "+ut);for(let a=ut-1;a>=0;a--)this.writeInt8(s.charCodeAt(a))}this.prep(this.minalign,Ze+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 r=this.bb.capacity()-e,i=r-this.bb.readInt32(r);if(this.bb.readInt16(i+t)==0)throw new Error("FlatBuffers: field "+t+" must be set")}startVector(e,t,r){this.notNested(),this.vector_num_elems=t,this.prep(Ze,e*t),this.prep(r,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 r=0;for(;r<e.length;){let i;const s=e.charCodeAt(r++);if(s<55296||s>=56320)i=s;else{const a=e.charCodeAt(r++);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 r=0,i=this.space,s=this.bb.bytes();r<t.length;r++)s[i++]=t[r];return this.endVector()}createLong(e,t){return yt.create(e,t)}createObjectOffset(e){return e===null?0:typeof e=="string"?this.createString(e):e.pack(this)}createObjectOffsetList(e){const t=[];for(let r=0;r<e.length;++r){const i=e[r];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()}}function di(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Es={exports:{}},ks;function As(){return ks||(ks=1,function(n){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}}(),n.exports.binaryFeatures=e;var t=n.exports.BlobBuilder;typeof window<"u"&&(t=n.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder);function r(){this._pieces=[],this._parts=[]}r.prototype.append=function(i){typeof i=="number"?this._pieces.push(i):(this.flush(),this._parts.push(i))},r.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=[]}},r.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)},n.exports.BufferBuilder=r}(Es)),Es.exports}var un,Rs;function tc(){if(Rs)return un;Rs=1;var n=As().BufferBuilder,e=As().binaryFeatures,t={unpack:function(o){var c=new r(o);return c.unpack()},pack:function(o){var c=new i;c.pack(o);var l=c.getBuffer();return l}};un=t;function r(o){this.index=0,this.dataBuffer=o,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}r.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)}},r.prototype.unpack_uint8=function(){var o=this.dataView[this.index]&255;return this.index++,o},r.prototype.unpack_uint16=function(){var o=this.read(2),c=(o[0]&255)*256+(o[1]&255);return this.index+=2,c},r.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},r.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},r.prototype.unpack_int8=function(){var o=this.unpack_uint8();return o<128?o:o-256},r.prototype.unpack_int16=function(){var o=this.unpack_uint16();return o<32768?o:o-65536},r.prototype.unpack_int32=function(){var o=this.unpack_uint32();return o<Math.pow(2,31)?o:o-Math.pow(2,32)},r.prototype.unpack_int64=function(){var o=this.unpack_uint64();return o<Math.pow(2,63)?o:o-Math.pow(2,64)},r.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},r.prototype.unpack_string=function(o){for(var c=this.read(o),l=0,h="",u,d;l<o;)u=c[l],u<128?(h+=String.fromCharCode(u),l++):(u^192)<32?(d=(u^192)<<6|c[l+1]&63,h+=String.fromCharCode(d),l+=2):(d=(u&15)<<12|(c[l+1]&63)<<6|c[l+2]&63,h+=String.fromCharCode(d),l+=3);return this.index+=o,h},r.prototype.unpack_array=function(o){for(var c=new Array(o),l=0;l<o;l++)c[l]=this.unpack();return c},r.prototype.unpack_map=function(o){for(var c={},l=0;l<o;l++){var h=this.unpack(),u=this.unpack();c[h]=u}return c},r.prototype.unpack_float=function(){var o=this.unpack_uint32(),c=o>>31,l=(o>>23&255)-127,h=o&8388607|8388608;return(c===0?1:-1)*h*Math.pow(2,l-23)},r.prototype.unpack_double=function(){var o=this.unpack_uint32(),c=this.unpack_uint32(),l=o>>31,h=(o>>20&2047)-1023,u=o&1048575|1048576,d=u*Math.pow(2,h-20)+c*Math.pow(2,h-52);return(l===0?1:-1)*d},r.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 n}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),h=o/Math.pow(2,l)-1,u=Math.floor(h*Math.pow(2,52)),d=Math.pow(2,32),p=c<<31|l+1023<<20|u/d&1048575,y=u%d;this.bufferBuilder.append(203),this.pack_int32(p),this.pack_int32(y)},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 h in o)o.hasOwnProperty(h)&&(this.pack(h),this.pack(o[h]))},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 un}var rc=tc();const Os=di(rc);let zs=!0,Bs=!0;function cr(n,e,t){const r=n.match(e);return r&&r.length>=t&&parseInt(r[t],10)}function jt(n,e,t){if(!n.RTCPeerConnection)return;const r=n.RTCPeerConnection.prototype,i=r.addEventListener;r.addEventListener=function(a,o){if(a!==e)return i.apply(this,arguments);const c=l=>{const h=t(l);h&&(o.handleEvent?o.handleEvent(h):o(h))};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=r.removeEventListener;r.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(r,"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 ic(n){return typeof n!="boolean"?new Error("Argument type: "+typeof n+". Please use a boolean."):(zs=n,n?"adapter.js logging disabled":"adapter.js logging enabled")}function nc(n){return typeof n!="boolean"?new Error("Argument type: "+typeof n+". Please use a boolean."):(Bs=!n,"adapter.js deprecation warnings "+(n?"disabled":"enabled"))}function dn(){if(typeof window=="object"){if(zs)return;typeof console<"u"&&typeof console.log=="function"&&console.log.apply(console,arguments)}}function pi(n,e){Bs&&console.warn(n+" is deprecated, please use "+e+" instead.")}function sc(n){const e={browser:null,version:null};if(typeof n>"u"||!n.navigator)return e.browser="Not a browser.",e;const{navigator:t}=n;if(t.mozGetUserMedia)e.browser="firefox",e.version=cr(t.userAgent,/Firefox\/(\d+)\./,1);else if(t.webkitGetUserMedia||n.isSecureContext===!1&&n.webkitRTCPeerConnection&&!n.RTCIceGatherer)e.browser="chrome",e.version=cr(t.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(t.mediaDevices&&t.userAgent.match(/Edge\/(\d+).(\d+)$/))e.browser="edge",e.version=cr(t.userAgent,/Edge\/(\d+).(\d+)$/,2);else if(n.RTCPeerConnection&&t.userAgent.match(/AppleWebKit\/(\d+)\./))e.browser="safari",e.version=cr(t.userAgent,/AppleWebKit\/(\d+)\./,1),e.supportsUnifiedPlan=n.RTCRtpTransceiver&&"currentDirection"in n.RTCRtpTransceiver.prototype;else return e.browser="Not a supported browser.",e;return e}function Is(n){return Object.prototype.toString.call(n)==="[object Object]"}function Us(n){return Is(n)?Object.keys(n).reduce(function(e,t){const r=Is(n[t]),i=r?Us(n[t]):n[t],s=r&&!Object.keys(i).length;return i===void 0||s?e:Object.assign(e,{[t]:i})},{}):n}function pn(n,e,t){!e||t.has(e.id)||(t.set(e.id,e),Object.keys(e).forEach(r=>{r.endsWith("Id")?pn(n,n.get(e[r]),t):r.endsWith("Ids")&&e[r].forEach(i=>{pn(n,n.get(i),t)})}))}function Ns(n,e,t){const r=t?"outbound-rtp":"inbound-rtp",i=new Map;if(e===null)return i;const s=[];return n.forEach(a=>{a.type==="track"&&a.trackIdentifier===e.id&&s.push(a)}),s.forEach(a=>{n.forEach(o=>{o.type===r&&o.trackId===a.id&&pn(n,o,i)})}),i}const Ds=dn;function Fs(n,e){const t=n&&n.navigator;if(!t.mediaDevices)return;const r=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 h=typeof o[l]=="object"?o[l]:{ideal:o[l]};h.exact!==void 0&&typeof h.exact=="number"&&(h.min=h.max=h.exact);const u=function(d,p){return d?d+p.charAt(0).toUpperCase()+p.slice(1):p==="deviceId"?"sourceId":p};if(h.ideal!==void 0){c.optional=c.optional||[];let d={};typeof h.ideal=="number"?(d[u("min",l)]=h.ideal,c.optional.push(d),d={},d[u("max",l)]=h.ideal,c.optional.push(d)):(d[u("",l)]=h.ideal,c.optional.push(d))}h.exact!==void 0&&typeof h.exact!="number"?(c.mandatory=c.mandatory||{},c.mandatory[u("",l)]=h.exact):["min","max"].forEach(d=>{h[d]!==void 0&&(c.mandatory=c.mandatory||{},c.mandatory[u(d,l)]=h[d])})}),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(h,u,d){u in h&&!(d in h)&&(h[d]=h[u],delete h[u])};o=JSON.parse(JSON.stringify(o)),l(o.audio,"autoGainControl","googAutoGainControl"),l(o.audio,"noiseSuppression","googNoiseSuppression"),o.audio=r(o.audio)}if(o&&typeof o.video=="object"){let l=o.video.facingMode;l=l&&(typeof l=="object"?l:{ideal:l});const h=e.version<66;if(l&&(l.exact==="user"||l.exact==="environment"||l.ideal==="user"||l.ideal==="environment")&&!(t.mediaDevices.getSupportedConstraints&&t.mediaDevices.getSupportedConstraints().facingMode&&!h)){delete o.video.facingMode;let u;if(l.exact==="environment"||l.ideal==="environment"?u=["back","rear"]:(l.exact==="user"||l.ideal==="user")&&(u=["front"]),u)return t.mediaDevices.enumerateDevices().then(d=>{d=d.filter(y=>y.kind==="videoinput");let p=d.find(y=>u.some(g=>y.label.toLowerCase().includes(g)));return!p&&d.length&&u.includes("back")&&(p=d[d.length-1]),p&&(o.video.deviceId=l.exact?{exact:p.deviceId}:{ideal:p.deviceId}),o.video=r(o.video),Ds("chrome: "+JSON.stringify(o)),c(o)})}o.video=r(o.video)}return Ds("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,h=>{t.webkitGetUserMedia(h,c,u=>{l&&l(s(u))})})};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(h=>{if(l.audio&&!h.getAudioTracks().length||l.video&&!h.getVideoTracks().length)throw h.getTracks().forEach(u=>{u.stop()}),new DOMException("","NotFoundError");return h},h=>Promise.reject(s(h))))})}}function oc(n,e){if(!(n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices)&&n.navigator.mediaDevices){if(typeof e!="function"){console.error("shimGetDisplayMedia: getSourceId argument is not a function");return}n.navigator.mediaDevices.getDisplayMedia=function(t){return e(t).then(r=>{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:r,maxFrameRate:a||3}},i&&(t.video.mandatory.maxWidth=i),s&&(t.video.mandatory.maxHeight=s),n.navigator.mediaDevices.getUserMedia(t)})}}}function Ls(n){n.MediaStream=n.MediaStream||n.webkitMediaStream}function Vs(n){if(typeof n=="object"&&n.RTCPeerConnection&&!("ontrack"in n.RTCPeerConnection.prototype)){Object.defineProperty(n.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=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",r=>{let i;n.RTCPeerConnection.prototype.getReceivers?i=this.getReceivers().find(a=>a.track&&a.track.id===r.track.id):i={track:r.track};const s=new Event("track");s.track=r.track,s.receiver=i,s.transceiver={receiver:i},s.streams=[t.stream],this.dispatchEvent(s)}),t.stream.getTracks().forEach(r=>{let i;n.RTCPeerConnection.prototype.getReceivers?i=this.getReceivers().find(a=>a.track&&a.track.id===r.id):i={track:r};const s=new Event("track");s.track=r,s.receiver=i,s.transceiver={receiver:i},s.streams=[t.stream],this.dispatchEvent(s)})},this.addEventListener("addstream",this._ontrackpoly)),e.apply(this,arguments)}}else jt(n,"track",e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e))}function js(n){if(typeof n=="object"&&n.RTCPeerConnection&&!("getSenders"in n.RTCPeerConnection.prototype)&&"createDTMFSender"in n.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(!n.RTCPeerConnection.prototype.getSenders){n.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=n.RTCPeerConnection.prototype.addTrack;n.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=n.RTCPeerConnection.prototype.removeTrack;n.RTCPeerConnection.prototype.removeTrack=function(a){s.apply(this,arguments);const o=this._senders.indexOf(a);o!==-1&&this._senders.splice(o,1)}}const t=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(i){this._senders=this._senders||[],t.apply(this,[i]),i.getTracks().forEach(s=>{this._senders.push(e(this,s))})};const r=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(i){this._senders=this._senders||[],r.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 n=="object"&&n.RTCPeerConnection&&"getSenders"in n.RTCPeerConnection.prototype&&"createDTMFSender"in n.RTCPeerConnection.prototype&&n.RTCRtpSender&&!("dtmf"in n.RTCRtpSender.prototype)){const e=n.RTCPeerConnection.prototype.getSenders;n.RTCPeerConnection.prototype.getSenders=function(){const t=e.apply(this,[]);return t.forEach(r=>r._pc=this),t},Object.defineProperty(n.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 Js(n){if(!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){const[t,r,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 h={id:l.id,timestamp:l.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[l.type]||l.type};l.names().forEach(u=>{h[u]=l.stat(u)}),c[h.id]=h}),c},a=function(o){return new Map(Object.keys(o).map(c=>[c,o[c]]))};if(arguments.length>=2){const o=function(c){r(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(r,i)}}function Gs(n){if(!(typeof n=="object"&&n.RTCPeerConnection&&n.RTCRtpSender&&n.RTCRtpReceiver))return;if(!("getStats"in n.RTCRtpSender.prototype)){const t=n.RTCPeerConnection.prototype.getSenders;t&&(n.RTCPeerConnection.prototype.getSenders=function(){const i=t.apply(this,[]);return i.forEach(s=>s._pc=this),i});const r=n.RTCPeerConnection.prototype.addTrack;r&&(n.RTCPeerConnection.prototype.addTrack=function(){const i=r.apply(this,arguments);return i._pc=this,i}),n.RTCRtpSender.prototype.getStats=function(){const i=this;return this._pc.getStats().then(s=>Ns(s,i.track,!0))}}if(!("getStats"in n.RTCRtpReceiver.prototype)){const t=n.RTCPeerConnection.prototype.getReceivers;t&&(n.RTCPeerConnection.prototype.getReceivers=function(){const r=t.apply(this,[]);return r.forEach(i=>i._pc=this),r}),jt(n,"track",r=>(r.receiver._pc=r.srcElement,r)),n.RTCRtpReceiver.prototype.getStats=function(){const r=this;return this._pc.getStats().then(i=>Ns(i,r.track,!1))}}if(!("getStats"in n.RTCRtpSender.prototype&&"getStats"in n.RTCRtpReceiver.prototype))return;const e=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof n.MediaStreamTrack){const t=arguments[0];let r,i,s;return this.getSenders().forEach(a=>{a.track===t&&(r?s=!0:r=a)}),this.getReceivers().forEach(a=>(a.track===t&&(i?s=!0:i=a),a.track===t)),s||r&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):r?r.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return e.apply(this,arguments)}}function Ws(n){n.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(s=>this._shimmedLocalStreams[s][0])};const e=n.RTCPeerConnection.prototype.addTrack;n.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=n.RTCPeerConnection.prototype.addStream;n.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 r=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(s){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[s.id],r.apply(this,arguments)};const i=n.RTCPeerConnection.prototype.removeTrack;n.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 Xs(n,e){if(!n.RTCPeerConnection)return;if(n.RTCPeerConnection.prototype.addTrack&&e.version>=65)return Ws(n);const t=n.RTCPeerConnection.prototype.getLocalStreams;n.RTCPeerConnection.prototype.getLocalStreams=function(){const l=t.apply(this);return this._reverseStreams=this._reverseStreams||{},l.map(h=>this._reverseStreams[h.id])};const r=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(l){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},l.getTracks().forEach(h=>{if(this.getSenders().find(u=>u.track===h))throw new DOMException("Track already exists.","InvalidAccessError")}),!this._reverseStreams[l.id]){const h=new n.MediaStream(l.getTracks());this._streams[l.id]=h,this._reverseStreams[h.id]=l,l=h}r.apply(this,[l])};const i=n.RTCPeerConnection.prototype.removeStream;n.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]},n.RTCPeerConnection.prototype.addTrack=function(l,h){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const u=[].slice.call(arguments,1);if(u.length!==1||!u[0].getTracks().find(p=>p===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(p=>p.track===l))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const d=this._streams[h.id];if(d)d.addTrack(l),Promise.resolve().then(()=>{this.dispatchEvent(new Event("negotiationneeded"))});else{const p=new n.MediaStream([l]);this._streams[h.id]=p,this._reverseStreams[p.id]=h,this.addStream(p)}return this.getSenders().find(p=>p.track===l)};function s(l,h){let u=h.sdp;return Object.keys(l._reverseStreams||[]).forEach(d=>{const p=l._reverseStreams[d],y=l._streams[p.id];u=u.replace(new RegExp(y.id,"g"),p.id)}),new RTCSessionDescription({type:h.type,sdp:u})}function a(l,h){let u=h.sdp;return Object.keys(l._reverseStreams||[]).forEach(d=>{const p=l._reverseStreams[d],y=l._streams[p.id];u=u.replace(new RegExp(p.id,"g"),y.id)}),new RTCSessionDescription({type:h.type,sdp:u})}["createOffer","createAnswer"].forEach(function(l){const h=n.RTCPeerConnection.prototype[l],u={[l](){const d=arguments;return arguments.length&&typeof arguments[0]=="function"?h.apply(this,[p=>{const y=s(this,p);d[0].apply(null,[y])},p=>{d[1]&&d[1].apply(null,p)},arguments[2]]):h.apply(this,arguments).then(p=>s(this,p))}};n.RTCPeerConnection.prototype[l]=u[l]});const o=n.RTCPeerConnection.prototype.setLocalDescription;n.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(n.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(n.RTCPeerConnection.prototype,"localDescription",{get(){const l=c.get.apply(this);return l.type===""?l:s(this,l)}}),n.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 h;Object.keys(this._streams).forEach(u=>{this._streams[u].getTracks().find(d=>l.track===d)&&(h=this._streams[u])}),h&&(h.getTracks().length===1?this.removeStream(this._reverseStreams[h.id]):h.removeTrack(l.track),this.dispatchEvent(new Event("negotiationneeded")))}}function fn(n,e){!n.RTCPeerConnection&&n.webkitRTCPeerConnection&&(n.RTCPeerConnection=n.webkitRTCPeerConnection),n.RTCPeerConnection&&e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){const r=n.RTCPeerConnection.prototype[t],i={[t](){return arguments[0]=new(t==="addIceCandidate"?n.RTCIceCandidate:n.RTCSessionDescription)(arguments[0]),r.apply(this,arguments)}};n.RTCPeerConnection.prototype[t]=i[t]})}function qs(n,e){jt(n,"negotiationneeded",t=>{const r=t.target;if(!((e.version<72||r.getConfiguration&&r.getConfiguration().sdpSemantics==="plan-b")&&r.signalingState!=="stable"))return t})}const Hs=Object.freeze(Object.defineProperty({__proto__:null,fixNegotiationNeeded:qs,shimAddTrackRemoveTrack:Xs,shimAddTrackRemoveTrackWithNative:Ws,shimGetDisplayMedia:oc,shimGetSendersWithDtmf:js,shimGetStats:Js,shimGetUserMedia:Fs,shimMediaStream:Ls,shimOnTrack:Vs,shimPeerConnection:fn,shimSenderReceiverGetStats:Gs},Symbol.toStringTag,{value:"Module"}));function ac(n,e){let t=!1;return n=JSON.parse(JSON.stringify(n)),n.filter(r=>{if(r&&(r.urls||r.url)){let i=r.urls||r.url;r.url&&!r.urls&&pi("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 r.url,r.urls=s?i[0]:i,!!i.length}})}var Ys={exports:{}},Zs;function Qs(){return Zs||(Zs=1,function(n){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(`
|
|
1
|
+
import{PlaneGeometry as bs,ShaderChunk as Ga,Object3D as _s,Layers as di,MeshBasicMaterial as xs,DoubleSide as an,AdditiveBlending as Ss,InstancedBufferAttribute as Pt,DynamicDrawUsage as ge,InstancedBufferGeometry as Wa,Uniform$1 as Ve,ShaderMaterial as cn,BufferGeometry as lr,BufferAttribute as Te,Mesh as ln,MeshStandardMaterial as Ha,MeshPhysicalMaterial as Xa,Triangle as Et,Vector3 as I,Plane as ws,Line3 as ut,Vector2 as Jt,Sphere as Ms,Matrix4 as je,Box3 as Ze,BackSide as qa,REVISION as Ya,FrontSide as Ts,BatchedMesh as Za,Ray as Ka,Matrix3 as Qa,Vector4 as hn,SkinnedMesh as $a,InterpolateDiscrete as ec,InterpolateLinear as Cs,AnimationClip as tc,QuaternionKeyframeTrack as rc,ColorKeyframeTrack as ic,VectorKeyframeTrack as nc,NumberKeyframeTrack as sc,PropertyBinding as Ps}from"./three-CsmWHVn7.min.js";const ne={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 Es(n){const e=await fetch(n);if(e.ok)return e.json();throw new Error(e.statusText)}async function oc(n){return await Es(`${n}/profilesList.json`)}async function ac(n,e,t=null,r=!0){if(!n)throw new Error("No xrInputSource supplied");const i=await oc(e);let s;if(n.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 Es(s.profilePath);let o;if(r){let c;if(n.handedness==="any"?c=a.layouts[Object.keys(a.layouts)[0]]:c=a.layouts[n.handedness],!c)throw new Error(`No matching handedness, ${n.handedness}, in profile ${s.profileId}`);c.assetPath&&(o=s.profilePath.replace("profile.json",c.assetPath))}return{profile:a,assetPath:o}}const cc={xAxis:0,yAxis:0,button:0,state:ne.ComponentState.DEFAULT};function lc(n=0,e=0){let t=n,r=e;if(Math.sqrt(n*n+e*e)>1){const i=Math.atan2(e,n);t=Math.cos(i),r=Math.sin(i)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:r*.5+.5}}class hc{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===ne.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(cc)}updateFromComponent({xAxis:e,yAxis:t,button:r,state:i}){const{normalizedXAxis:s,normalizedYAxis:a}=lc(e,t);switch(this.componentProperty){case ne.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?s:.5;break;case ne.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?a:.5;break;case ne.ComponentProperty.BUTTON:this.value=this.states.includes(i)?r:0;break;case ne.ComponentProperty.STATE:this.valueNodeProperty===ne.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 uc{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(r=>{const i=new hc(t.visualResponses[r]);this.visualResponses[r]=i}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:ne.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=ne.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=ne.ComponentState.PRESSED:(t.touched||this.values.button>ne.ButtonTouchThreshold)&&(this.values.state=ne.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===ne.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>ne.AxisTouchThreshold&&(this.values.state=ne.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===ne.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>ne.AxisTouchThreshold&&(this.values.state=ne.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class dc{constructor(e,t,r){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=r,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 uc(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 un=2,Ke=4,dt=4,ks=4,vt=new Int32Array(2),Rs=new Float32Array(vt.buffer),As=new Float64Array(vt.buffer),pi=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;class gt{constructor(e,t){this.low=e|0,this.high=t|0}static create(e,t){return e==0&&t==0?gt.ZERO:new gt(e,t)}toFloat64(){return(this.low>>>0)+this.high*4294967296}equals(e){return this.low==e.low&&this.high==e.high}}gt.ZERO=new gt(0,0);var dn;(function(n){n[n.UTF8_BYTES=1]="UTF8_BYTES",n[n.UTF16_STRING=2]="UTF16_STRING"})(dn||(dn={}));class Br{constructor(e){this.bytes_=e,this.position_=0}static allocate(e){return new Br(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 gt(this.readInt32(e),this.readInt32(e+4))}readUint64(e){return new gt(this.readUint32(e),this.readUint32(e+4))}readFloat32(e){return vt[0]=this.readInt32(e),Rs[0]}readFloat64(e){return vt[pi?0:1]=this.readInt32(e),vt[pi?1:0]=this.readInt32(e+4),As[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){Rs[0]=t,this.writeInt32(e,vt[0])}writeFloat64(e,t){As[0]=t,this.writeInt32(e,vt[pi?0:1]),this.writeInt32(e+4,vt[pi?1:0])}getBufferIdentifier(){if(this.bytes_.length<this.position_+Ke+dt)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");let e="";for(let t=0;t<dt;t++)e+=String.fromCharCode(this.readInt8(this.position_+Ke+t));return e}__offset(e,t){const r=e-this.readInt32(e);return t<this.readInt16(r)?this.readInt16(r+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 r=this.readInt32(e);let i="",s=0;if(e+=Ke,t===dn.UTF8_BYTES)return this.bytes_.subarray(e,e+r);for(;s<r;){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 h=this.readUint8(e+s++);a=(o&7)<<18|(c&63)<<12|(l&63)<<6|h&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)+Ke}__vector_len(e){return this.readInt32(e+this.readInt32(e))}__has_identifier(e){if(e.length!=dt)throw new Error("FlatBuffers: file identifier must be length "+dt);for(let t=0;t<dt;t++)if(e.charCodeAt(t)!=this.readInt8(this.position()+Ke+t))return!1;return!0}createLong(e,t){return gt.create(e,t)}createScalarList(e,t){const r=[];for(let i=0;i<t;++i)e(i)!==null&&r.push(e(i));return r}createObjList(e,t){const r=[];for(let i=0;i<t;++i){const s=e(i);s!==null&&r.push(s.unpack())}return r}}class gs{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=Br.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 r=~(this.bb.capacity()-this.space+t)+1&e-1;for(;this.space<r+e+t;){const i=this.bb.capacity();this.bb=gs.growByteBuffer(this.bb),this.space+=this.bb.capacity()-i}this.pad(r)}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,r){(this.force_defaults||t!=r)&&(this.addInt8(t),this.slot(e))}addFieldInt16(e,t,r){(this.force_defaults||t!=r)&&(this.addInt16(t),this.slot(e))}addFieldInt32(e,t,r){(this.force_defaults||t!=r)&&(this.addInt32(t),this.slot(e))}addFieldInt64(e,t,r){(this.force_defaults||!t.equals(r))&&(this.addInt64(t),this.slot(e))}addFieldFloat32(e,t,r){(this.force_defaults||t!=r)&&(this.addFloat32(t),this.slot(e))}addFieldFloat64(e,t,r){(this.force_defaults||t!=r)&&(this.addFloat64(t),this.slot(e))}addFieldOffset(e,t,r){(this.force_defaults||t!=r)&&(this.addOffset(t),this.slot(e))}addFieldStruct(e,t,r){t!=r&&(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 r=t<<1,i=Br.allocate(r);return i.setPosition(r-t),i.bytes().set(e.bytes(),r-t),i}addOffset(e){this.prep(Ke,0),this.writeInt32(this.offset()-e+Ke)}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 r=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=(r+i)*un;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=un;l<s;l+=un)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,r){const i=r?ks:0;if(t){const s=t;if(this.prep(this.minalign,Ke+dt+i),s.length!=dt)throw new Error("FlatBuffers: file identifier must be length "+dt);for(let a=dt-1;a>=0;a--)this.writeInt8(s.charCodeAt(a))}this.prep(this.minalign,Ke+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 r=this.bb.capacity()-e,i=r-this.bb.readInt32(r);if(this.bb.readInt16(i+t)==0)throw new Error("FlatBuffers: field "+t+" must be set")}startVector(e,t,r){this.notNested(),this.vector_num_elems=t,this.prep(Ke,e*t),this.prep(r,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 r=0;for(;r<e.length;){let i;const s=e.charCodeAt(r++);if(s<55296||s>=56320)i=s;else{const a=e.charCodeAt(r++);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 r=0,i=this.space,s=this.bb.bytes();r<t.length;r++)s[i++]=t[r];return this.endVector()}createLong(e,t){return gt.create(e,t)}createObjectOffset(e){return e===null?0:typeof e=="string"?this.createString(e):e.pack(this)}createObjectOffsetList(e){const t=[];for(let r=0;r<e.length;++r){const i=e[r];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()}}function fi(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Os={exports:{}},zs;function Bs(){return zs||(zs=1,function(n){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}}(),n.exports.binaryFeatures=e;var t=n.exports.BlobBuilder;typeof window<"u"&&(t=n.exports.BlobBuilder=window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder||window.BlobBuilder);function r(){this._pieces=[],this._parts=[]}r.prototype.append=function(i){typeof i=="number"?this._pieces.push(i):(this.flush(),this._parts.push(i))},r.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=[]}},r.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)},n.exports.BufferBuilder=r}(Os)),Os.exports}var pn,Is;function pc(){if(Is)return pn;Is=1;var n=Bs().BufferBuilder,e=Bs().binaryFeatures,t={unpack:function(o){var c=new r(o);return c.unpack()},pack:function(o){var c=new i;c.pack(o);var l=c.getBuffer();return l}};pn=t;function r(o){this.index=0,this.dataBuffer=o,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}r.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)}},r.prototype.unpack_uint8=function(){var o=this.dataView[this.index]&255;return this.index++,o},r.prototype.unpack_uint16=function(){var o=this.read(2),c=(o[0]&255)*256+(o[1]&255);return this.index+=2,c},r.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},r.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},r.prototype.unpack_int8=function(){var o=this.unpack_uint8();return o<128?o:o-256},r.prototype.unpack_int16=function(){var o=this.unpack_uint16();return o<32768?o:o-65536},r.prototype.unpack_int32=function(){var o=this.unpack_uint32();return o<Math.pow(2,31)?o:o-Math.pow(2,32)},r.prototype.unpack_int64=function(){var o=this.unpack_uint64();return o<Math.pow(2,63)?o:o-Math.pow(2,64)},r.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},r.prototype.unpack_string=function(o){for(var c=this.read(o),l=0,h="",u,d;l<o;)u=c[l],u<128?(h+=String.fromCharCode(u),l++):(u^192)<32?(d=(u^192)<<6|c[l+1]&63,h+=String.fromCharCode(d),l+=2):(d=(u&15)<<12|(c[l+1]&63)<<6|c[l+2]&63,h+=String.fromCharCode(d),l+=3);return this.index+=o,h},r.prototype.unpack_array=function(o){for(var c=new Array(o),l=0;l<o;l++)c[l]=this.unpack();return c},r.prototype.unpack_map=function(o){for(var c={},l=0;l<o;l++){var h=this.unpack(),u=this.unpack();c[h]=u}return c},r.prototype.unpack_float=function(){var o=this.unpack_uint32(),c=o>>31,l=(o>>23&255)-127,h=o&8388607|8388608;return(c===0?1:-1)*h*Math.pow(2,l-23)},r.prototype.unpack_double=function(){var o=this.unpack_uint32(),c=this.unpack_uint32(),l=o>>31,h=(o>>20&2047)-1023,u=o&1048575|1048576,d=u*Math.pow(2,h-20)+c*Math.pow(2,h-52);return(l===0?1:-1)*d},r.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 n}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),h=o/Math.pow(2,l)-1,u=Math.floor(h*Math.pow(2,52)),d=Math.pow(2,32),p=c<<31|l+1023<<20|u/d&1048575,y=u%d;this.bufferBuilder.append(203),this.pack_int32(p),this.pack_int32(y)},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 h in o)o.hasOwnProperty(h)&&(this.pack(h),this.pack(o[h]))},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 pn}var fc=pc();const Ns=fi(fc);let Us=!0,Ds=!0;function hr(n,e,t){const r=n.match(e);return r&&r.length>=t&&parseInt(r[t],10)}function Gt(n,e,t){if(!n.RTCPeerConnection)return;const r=n.RTCPeerConnection.prototype,i=r.addEventListener;r.addEventListener=function(a,o){if(a!==e)return i.apply(this,arguments);const c=l=>{const h=t(l);h&&(o.handleEvent?o.handleEvent(h):o(h))};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=r.removeEventListener;r.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(r,"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 mc(n){return typeof n!="boolean"?new Error("Argument type: "+typeof n+". Please use a boolean."):(Us=n,n?"adapter.js logging disabled":"adapter.js logging enabled")}function yc(n){return typeof n!="boolean"?new Error("Argument type: "+typeof n+". Please use a boolean."):(Ds=!n,"adapter.js deprecation warnings "+(n?"disabled":"enabled"))}function fn(){if(typeof window=="object"){if(Us)return;typeof console<"u"&&typeof console.log=="function"&&console.log.apply(console,arguments)}}function mi(n,e){Ds&&console.warn(n+" is deprecated, please use "+e+" instead.")}function gc(n){const e={browser:null,version:null};if(typeof n>"u"||!n.navigator)return e.browser="Not a browser.",e;const{navigator:t}=n;if(t.mozGetUserMedia)e.browser="firefox",e.version=hr(t.userAgent,/Firefox\/(\d+)\./,1);else if(t.webkitGetUserMedia||n.isSecureContext===!1&&n.webkitRTCPeerConnection&&!n.RTCIceGatherer)e.browser="chrome",e.version=hr(t.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(t.mediaDevices&&t.userAgent.match(/Edge\/(\d+).(\d+)$/))e.browser="edge",e.version=hr(t.userAgent,/Edge\/(\d+).(\d+)$/,2);else if(n.RTCPeerConnection&&t.userAgent.match(/AppleWebKit\/(\d+)\./))e.browser="safari",e.version=hr(t.userAgent,/AppleWebKit\/(\d+)\./,1),e.supportsUnifiedPlan=n.RTCRtpTransceiver&&"currentDirection"in n.RTCRtpTransceiver.prototype;else return e.browser="Not a supported browser.",e;return e}function Fs(n){return Object.prototype.toString.call(n)==="[object Object]"}function Ls(n){return Fs(n)?Object.keys(n).reduce(function(e,t){const r=Fs(n[t]),i=r?Ls(n[t]):n[t],s=r&&!Object.keys(i).length;return i===void 0||s?e:Object.assign(e,{[t]:i})},{}):n}function mn(n,e,t){!e||t.has(e.id)||(t.set(e.id,e),Object.keys(e).forEach(r=>{r.endsWith("Id")?mn(n,n.get(e[r]),t):r.endsWith("Ids")&&e[r].forEach(i=>{mn(n,n.get(i),t)})}))}function Vs(n,e,t){const r=t?"outbound-rtp":"inbound-rtp",i=new Map;if(e===null)return i;const s=[];return n.forEach(a=>{a.type==="track"&&a.trackIdentifier===e.id&&s.push(a)}),s.forEach(a=>{n.forEach(o=>{o.type===r&&o.trackId===a.id&&mn(n,o,i)})}),i}const js=fn;function Js(n,e){const t=n&&n.navigator;if(!t.mediaDevices)return;const r=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 h=typeof o[l]=="object"?o[l]:{ideal:o[l]};h.exact!==void 0&&typeof h.exact=="number"&&(h.min=h.max=h.exact);const u=function(d,p){return d?d+p.charAt(0).toUpperCase()+p.slice(1):p==="deviceId"?"sourceId":p};if(h.ideal!==void 0){c.optional=c.optional||[];let d={};typeof h.ideal=="number"?(d[u("min",l)]=h.ideal,c.optional.push(d),d={},d[u("max",l)]=h.ideal,c.optional.push(d)):(d[u("",l)]=h.ideal,c.optional.push(d))}h.exact!==void 0&&typeof h.exact!="number"?(c.mandatory=c.mandatory||{},c.mandatory[u("",l)]=h.exact):["min","max"].forEach(d=>{h[d]!==void 0&&(c.mandatory=c.mandatory||{},c.mandatory[u(d,l)]=h[d])})}),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(h,u,d){u in h&&!(d in h)&&(h[d]=h[u],delete h[u])};o=JSON.parse(JSON.stringify(o)),l(o.audio,"autoGainControl","googAutoGainControl"),l(o.audio,"noiseSuppression","googNoiseSuppression"),o.audio=r(o.audio)}if(o&&typeof o.video=="object"){let l=o.video.facingMode;l=l&&(typeof l=="object"?l:{ideal:l});const h=e.version<66;if(l&&(l.exact==="user"||l.exact==="environment"||l.ideal==="user"||l.ideal==="environment")&&!(t.mediaDevices.getSupportedConstraints&&t.mediaDevices.getSupportedConstraints().facingMode&&!h)){delete o.video.facingMode;let u;if(l.exact==="environment"||l.ideal==="environment"?u=["back","rear"]:(l.exact==="user"||l.ideal==="user")&&(u=["front"]),u)return t.mediaDevices.enumerateDevices().then(d=>{d=d.filter(y=>y.kind==="videoinput");let p=d.find(y=>u.some(g=>y.label.toLowerCase().includes(g)));return!p&&d.length&&u.includes("back")&&(p=d[d.length-1]),p&&(o.video.deviceId=l.exact?{exact:p.deviceId}:{ideal:p.deviceId}),o.video=r(o.video),js("chrome: "+JSON.stringify(o)),c(o)})}o.video=r(o.video)}return js("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,h=>{t.webkitGetUserMedia(h,c,u=>{l&&l(s(u))})})};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(h=>{if(l.audio&&!h.getAudioTracks().length||l.video&&!h.getVideoTracks().length)throw h.getTracks().forEach(u=>{u.stop()}),new DOMException("","NotFoundError");return h},h=>Promise.reject(s(h))))})}}function vc(n,e){if(!(n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices)&&n.navigator.mediaDevices){if(typeof e!="function"){console.error("shimGetDisplayMedia: getSourceId argument is not a function");return}n.navigator.mediaDevices.getDisplayMedia=function(t){return e(t).then(r=>{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:r,maxFrameRate:a||3}},i&&(t.video.mandatory.maxWidth=i),s&&(t.video.mandatory.maxHeight=s),n.navigator.mediaDevices.getUserMedia(t)})}}}function Gs(n){n.MediaStream=n.MediaStream||n.webkitMediaStream}function Ws(n){if(typeof n=="object"&&n.RTCPeerConnection&&!("ontrack"in n.RTCPeerConnection.prototype)){Object.defineProperty(n.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=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){return this._ontrackpoly||(this._ontrackpoly=t=>{t.stream.addEventListener("addtrack",r=>{let i;n.RTCPeerConnection.prototype.getReceivers?i=this.getReceivers().find(a=>a.track&&a.track.id===r.track.id):i={track:r.track};const s=new Event("track");s.track=r.track,s.receiver=i,s.transceiver={receiver:i},s.streams=[t.stream],this.dispatchEvent(s)}),t.stream.getTracks().forEach(r=>{let i;n.RTCPeerConnection.prototype.getReceivers?i=this.getReceivers().find(a=>a.track&&a.track.id===r.id):i={track:r};const s=new Event("track");s.track=r,s.receiver=i,s.transceiver={receiver:i},s.streams=[t.stream],this.dispatchEvent(s)})},this.addEventListener("addstream",this._ontrackpoly)),e.apply(this,arguments)}}else Gt(n,"track",e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e))}function Hs(n){if(typeof n=="object"&&n.RTCPeerConnection&&!("getSenders"in n.RTCPeerConnection.prototype)&&"createDTMFSender"in n.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(!n.RTCPeerConnection.prototype.getSenders){n.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const i=n.RTCPeerConnection.prototype.addTrack;n.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=n.RTCPeerConnection.prototype.removeTrack;n.RTCPeerConnection.prototype.removeTrack=function(a){s.apply(this,arguments);const o=this._senders.indexOf(a);o!==-1&&this._senders.splice(o,1)}}const t=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(i){this._senders=this._senders||[],t.apply(this,[i]),i.getTracks().forEach(s=>{this._senders.push(e(this,s))})};const r=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(i){this._senders=this._senders||[],r.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 n=="object"&&n.RTCPeerConnection&&"getSenders"in n.RTCPeerConnection.prototype&&"createDTMFSender"in n.RTCPeerConnection.prototype&&n.RTCRtpSender&&!("dtmf"in n.RTCRtpSender.prototype)){const e=n.RTCPeerConnection.prototype.getSenders;n.RTCPeerConnection.prototype.getSenders=function(){const t=e.apply(this,[]);return t.forEach(r=>r._pc=this),t},Object.defineProperty(n.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 Xs(n){if(!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){const[t,r,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 h={id:l.id,timestamp:l.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[l.type]||l.type};l.names().forEach(u=>{h[u]=l.stat(u)}),c[h.id]=h}),c},a=function(o){return new Map(Object.keys(o).map(c=>[c,o[c]]))};if(arguments.length>=2){const o=function(c){r(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(r,i)}}function qs(n){if(!(typeof n=="object"&&n.RTCPeerConnection&&n.RTCRtpSender&&n.RTCRtpReceiver))return;if(!("getStats"in n.RTCRtpSender.prototype)){const t=n.RTCPeerConnection.prototype.getSenders;t&&(n.RTCPeerConnection.prototype.getSenders=function(){const i=t.apply(this,[]);return i.forEach(s=>s._pc=this),i});const r=n.RTCPeerConnection.prototype.addTrack;r&&(n.RTCPeerConnection.prototype.addTrack=function(){const i=r.apply(this,arguments);return i._pc=this,i}),n.RTCRtpSender.prototype.getStats=function(){const i=this;return this._pc.getStats().then(s=>Vs(s,i.track,!0))}}if(!("getStats"in n.RTCRtpReceiver.prototype)){const t=n.RTCPeerConnection.prototype.getReceivers;t&&(n.RTCPeerConnection.prototype.getReceivers=function(){const r=t.apply(this,[]);return r.forEach(i=>i._pc=this),r}),Gt(n,"track",r=>(r.receiver._pc=r.srcElement,r)),n.RTCRtpReceiver.prototype.getStats=function(){const r=this;return this._pc.getStats().then(i=>Vs(i,r.track,!1))}}if(!("getStats"in n.RTCRtpSender.prototype&&"getStats"in n.RTCRtpReceiver.prototype))return;const e=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){if(arguments.length>0&&arguments[0]instanceof n.MediaStreamTrack){const t=arguments[0];let r,i,s;return this.getSenders().forEach(a=>{a.track===t&&(r?s=!0:r=a)}),this.getReceivers().forEach(a=>(a.track===t&&(i?s=!0:i=a),a.track===t)),s||r&&i?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):r?r.getStats():i?i.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return e.apply(this,arguments)}}function Ys(n){n.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(s=>this._shimmedLocalStreams[s][0])};const e=n.RTCPeerConnection.prototype.addTrack;n.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=n.RTCPeerConnection.prototype.addStream;n.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 r=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(s){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[s.id],r.apply(this,arguments)};const i=n.RTCPeerConnection.prototype.removeTrack;n.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 Zs(n,e){if(!n.RTCPeerConnection)return;if(n.RTCPeerConnection.prototype.addTrack&&e.version>=65)return Ys(n);const t=n.RTCPeerConnection.prototype.getLocalStreams;n.RTCPeerConnection.prototype.getLocalStreams=function(){const l=t.apply(this);return this._reverseStreams=this._reverseStreams||{},l.map(h=>this._reverseStreams[h.id])};const r=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(l){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},l.getTracks().forEach(h=>{if(this.getSenders().find(u=>u.track===h))throw new DOMException("Track already exists.","InvalidAccessError")}),!this._reverseStreams[l.id]){const h=new n.MediaStream(l.getTracks());this._streams[l.id]=h,this._reverseStreams[h.id]=l,l=h}r.apply(this,[l])};const i=n.RTCPeerConnection.prototype.removeStream;n.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]},n.RTCPeerConnection.prototype.addTrack=function(l,h){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const u=[].slice.call(arguments,1);if(u.length!==1||!u[0].getTracks().find(p=>p===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(p=>p.track===l))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const d=this._streams[h.id];if(d)d.addTrack(l),Promise.resolve().then(()=>{this.dispatchEvent(new Event("negotiationneeded"))});else{const p=new n.MediaStream([l]);this._streams[h.id]=p,this._reverseStreams[p.id]=h,this.addStream(p)}return this.getSenders().find(p=>p.track===l)};function s(l,h){let u=h.sdp;return Object.keys(l._reverseStreams||[]).forEach(d=>{const p=l._reverseStreams[d],y=l._streams[p.id];u=u.replace(new RegExp(y.id,"g"),p.id)}),new RTCSessionDescription({type:h.type,sdp:u})}function a(l,h){let u=h.sdp;return Object.keys(l._reverseStreams||[]).forEach(d=>{const p=l._reverseStreams[d],y=l._streams[p.id];u=u.replace(new RegExp(p.id,"g"),y.id)}),new RTCSessionDescription({type:h.type,sdp:u})}["createOffer","createAnswer"].forEach(function(l){const h=n.RTCPeerConnection.prototype[l],u={[l](){const d=arguments;return arguments.length&&typeof arguments[0]=="function"?h.apply(this,[p=>{const y=s(this,p);d[0].apply(null,[y])},p=>{d[1]&&d[1].apply(null,p)},arguments[2]]):h.apply(this,arguments).then(p=>s(this,p))}};n.RTCPeerConnection.prototype[l]=u[l]});const o=n.RTCPeerConnection.prototype.setLocalDescription;n.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(n.RTCPeerConnection.prototype,"localDescription");Object.defineProperty(n.RTCPeerConnection.prototype,"localDescription",{get(){const l=c.get.apply(this);return l.type===""?l:s(this,l)}}),n.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 h;Object.keys(this._streams).forEach(u=>{this._streams[u].getTracks().find(d=>l.track===d)&&(h=this._streams[u])}),h&&(h.getTracks().length===1?this.removeStream(this._reverseStreams[h.id]):h.removeTrack(l.track),this.dispatchEvent(new Event("negotiationneeded")))}}function yn(n,e){!n.RTCPeerConnection&&n.webkitRTCPeerConnection&&(n.RTCPeerConnection=n.webkitRTCPeerConnection),n.RTCPeerConnection&&e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){const r=n.RTCPeerConnection.prototype[t],i={[t](){return arguments[0]=new(t==="addIceCandidate"?n.RTCIceCandidate:n.RTCSessionDescription)(arguments[0]),r.apply(this,arguments)}};n.RTCPeerConnection.prototype[t]=i[t]})}function Ks(n,e){Gt(n,"negotiationneeded",t=>{const r=t.target;if(!((e.version<72||r.getConfiguration&&r.getConfiguration().sdpSemantics==="plan-b")&&r.signalingState!=="stable"))return t})}const Qs=Object.freeze(Object.defineProperty({__proto__:null,fixNegotiationNeeded:Ks,shimAddTrackRemoveTrack:Zs,shimAddTrackRemoveTrackWithNative:Ys,shimGetDisplayMedia:vc,shimGetSendersWithDtmf:Hs,shimGetStats:Xs,shimGetUserMedia:Js,shimMediaStream:Gs,shimOnTrack:Ws,shimPeerConnection:yn,shimSenderReceiverGetStats:qs},Symbol.toStringTag,{value:"Module"}));function bc(n,e){let t=!1;return n=JSON.parse(JSON.stringify(n)),n.filter(r=>{if(r&&(r.urls||r.url)){let i=r.urls||r.url;r.url&&!r.urls&&mi("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 r.url,r.urls=s?i[0]:i,!!i.length}})}var $s={exports:{}},eo;function to(){return eo||(eo=1,function(n){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(`
|
|
2
2
|
`).map(function(r){return r.trim()})},e.splitSections=function(t){var r=t.split(`
|
|
3
3
|
m=`);return r.map(function(i,s){return(s>0?"m="+i:i).trim()+`\r
|
|
4
4
|
`})},e.getDescription=function(t){var r=e.splitSections(t);return r&&r[0]},e.getMediaSections=function(t){var r=e.splitSections(t);return r.shift(),r},e.matchPrefix=function(t,r){return e.splitLines(t).filter(function(i){return i.indexOf(r)===0})},e.parseCandidate=function(t){var r;t.indexOf("a=candidate:")===0?r=t.substring(12).split(" "):r=t.substring(10).split(" ");for(var i={foundation:r[0],component:parseInt(r[1],10),protocol:r[2].toLowerCase(),priority:parseInt(r[3],10),ip:r[4],address:r[4],port:parseInt(r[5],10),type:r[7]},s=8;s<r.length;s+=2)switch(r[s]){case"raddr":i.relatedAddress=r[s+1];break;case"rport":i.relatedPort=parseInt(r[s+1],10);break;case"tcptype":i.tcpType=r[s+1];break;case"ufrag":i.ufrag=r[s+1],i.usernameFragment=r[s+1];break;default:i[r[s]]=r[s+1];break}return i},e.writeCandidate=function(t){var r=[];r.push(t.foundation),r.push(t.component),r.push(t.protocol.toUpperCase()),r.push(t.priority),r.push(t.address||t.ip),r.push(t.port);var i=t.type;return r.push("typ"),r.push(i),i!=="host"&&t.relatedAddress&&t.relatedPort&&(r.push("raddr"),r.push(t.relatedAddress),r.push("rport"),r.push(t.relatedPort)),t.tcpType&&t.protocol.toLowerCase()==="tcp"&&(r.push("tcptype"),r.push(t.tcpType)),(t.usernameFragment||t.ufrag)&&(r.push("ufrag"),r.push(t.usernameFragment||t.ufrag)),"candidate:"+r.join(" ")},e.parseIceOptions=function(t){return t.substr(14).split(" ")},e.parseRtpMap=function(t){var r=t.substr(9).split(" "),i={payloadType:parseInt(r.shift(),10)};return r=r[0].split("/"),i.name=r[0],i.clockRate=parseInt(r[1],10),i.channels=r.length===3?parseInt(r[2],10):1,i.numChannels=i.channels,i},e.writeRtpMap=function(t){var r=t.payloadType;t.preferredPayloadType!==void 0&&(r=t.preferredPayloadType);var i=t.channels||t.numChannels||1;return"a=rtpmap:"+r+" "+t.name+"/"+t.clockRate+(i!==1?"/"+i:"")+`\r
|
|
@@ -36,7 +36,7 @@ t=0 0\r
|
|
|
36
36
|
`;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
|
|
37
37
|
`)}return a+="a=ssrc:"+t.sendEncodingParameters[0].ssrc+" cname:"+e.localCName+`\r
|
|
38
38
|
`,t.rtpSender&&t.sendEncodingParameters[0].rtx&&(a+="a=ssrc:"+t.sendEncodingParameters[0].rtx.ssrc+" cname:"+e.localCName+`\r
|
|
39
|
-
`),a},e.getDirection=function(t,r){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 r?e.getDirection(r):"sendrecv"},e.getKind=function(t){var r=e.splitLines(t),i=r[0].split(" ");return i[0].substr(2)},e.isRejected=function(t){return t.split(" ",2)[1]==="0"},e.parseMLine=function(t){var r=e.splitLines(t),i=r[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 r=e.matchPrefix(t,"o=")[0],i=r.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 r=e.splitLines(t),i=0;i<r.length;i++)if(r[i].length<2||r[i].charAt(1)!=="=")return!1;return!0},n.exports=e}(
|
|
39
|
+
`),a},e.getDirection=function(t,r){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 r?e.getDirection(r):"sendrecv"},e.getKind=function(t){var r=e.splitLines(t),i=r[0].split(" ");return i[0].substr(2)},e.isRejected=function(t){return t.split(" ",2)[1]==="0"},e.parseMLine=function(t){var r=e.splitLines(t),i=r[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 r=e.matchPrefix(t,"o=")[0],i=r.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 r=e.splitLines(t),i=0;i<r.length;i++)if(r[i].length<2||r[i].charAt(1)!=="=")return!1;return!0},n.exports=e}($s)),$s.exports}var gn,ro;function _c(){if(ro)return gn;ro=1;var n=to();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,h,u,d){var p=n.writeRtpDescription(c.kind,l);if(p+=n.writeIceParameters(c.iceGatherer.getLocalParameters()),p+=n.writeDtlsParameters(c.dtlsTransport.getLocalParameters(),h==="offer"?"actpass":d||"active"),p+="a=mid:"+c.mid+`\r
|
|
40
40
|
`,c.rtpSender&&c.rtpReceiver?p+=`a=sendrecv\r
|
|
41
41
|
`:c.rtpSender?p+=`a=sendonly\r
|
|
42
42
|
`:c.rtpReceiver?p+=`a=recvonly\r
|
|
@@ -45,42 +45,42 @@ t=0 0\r
|
|
|
45
45
|
`;p+="a="+g,p+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" "+g,c.sendEncodingParameters[0].rtx&&(p+="a=ssrc:"+c.sendEncodingParameters[0].rtx.ssrc+" "+g,p+="a=ssrc-group:FID "+c.sendEncodingParameters[0].ssrc+" "+c.sendEncodingParameters[0].rtx.ssrc+`\r
|
|
46
46
|
`)}return p+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" cname:"+n.localCName+`\r
|
|
47
47
|
`,c.rtpSender&&c.sendEncodingParameters[0].rtx&&(p+="a=ssrc:"+c.sendEncodingParameters[0].rtx.ssrc+" cname:"+n.localCName+`\r
|
|
48
|
-
`),p}function r(c,l){var h=!1;return c=JSON.parse(JSON.stringify(c)),c.filter(function(u){if(u&&(u.urls||u.url)){var d=u.urls||u.url;u.url&&!u.urls&&console.warn("RTCIceServer.url is deprecated! Use urls instead.");var p=typeof d=="string";return p&&(d=[d]),d=d.filter(function(y){var g=y.indexOf("turn:")===0&&y.indexOf("transport=udp")!==-1&&y.indexOf("turn:[")===-1&&!h;return g?(h=!0,!0):y.indexOf("stun:")===0&&l>=14393&&y.indexOf("?transport=udp")===-1}),delete u.url,u.urls=p?d[0]:d,!!d.length}})}function i(c,l){var h={codecs:[],headerExtensions:[],fecMechanisms:[]},u=function(p,y){p=parseInt(p,10);for(var g=0;g<y.length;g++)if(y[g].payloadType===p||y[g].preferredPayloadType===p)return y[g]},d=function(p,y,g,f){var m=u(p.parameters.apt,g),
|
|
48
|
+
`),p}function r(c,l){var h=!1;return c=JSON.parse(JSON.stringify(c)),c.filter(function(u){if(u&&(u.urls||u.url)){var d=u.urls||u.url;u.url&&!u.urls&&console.warn("RTCIceServer.url is deprecated! Use urls instead.");var p=typeof d=="string";return p&&(d=[d]),d=d.filter(function(y){var g=y.indexOf("turn:")===0&&y.indexOf("transport=udp")!==-1&&y.indexOf("turn:[")===-1&&!h;return g?(h=!0,!0):y.indexOf("stun:")===0&&l>=14393&&y.indexOf("?transport=udp")===-1}),delete u.url,u.urls=p?d[0]:d,!!d.length}})}function i(c,l){var h={codecs:[],headerExtensions:[],fecMechanisms:[]},u=function(p,y){p=parseInt(p,10);for(var g=0;g<y.length;g++)if(y[g].payloadType===p||y[g].preferredPayloadType===p)return y[g]},d=function(p,y,g,f){var m=u(p.parameters.apt,g),b=u(y.parameters.apt,f);return m&&b&&m.name.toLowerCase()===b.name.toLowerCase()};return c.codecs.forEach(function(p){for(var y=0;y<l.codecs.length;y++){var g=l.codecs[y];if(p.name.toLowerCase()===g.name.toLowerCase()&&p.clockRate===g.clockRate){if(p.name.toLowerCase()==="rtx"&&p.parameters&&g.parameters.apt&&!d(p,g,c.codecs,l.codecs))continue;g=JSON.parse(JSON.stringify(g)),g.numChannels=Math.min(p.numChannels,g.numChannels),h.codecs.push(g),g.rtcpFeedback=g.rtcpFeedback.filter(function(f){for(var m=0;m<p.rtcpFeedback.length;m++)if(p.rtcpFeedback[m].type===f.type&&p.rtcpFeedback[m].parameter===f.parameter)return!0;return!1});break}}}),c.headerExtensions.forEach(function(p){for(var y=0;y<l.headerExtensions.length;y++){var g=l.headerExtensions[y];if(p.uri===g.uri){h.headerExtensions.push(g);break}}}),h}function s(c,l,h){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(h)!==-1}function a(c,l){var h=c.getRemoteCandidates().find(function(u){return l.foundation===u.foundation&&l.ip===u.ip&&l.port===u.port&&l.priority===u.priority&&l.protocol===u.protocol&&l.type===u.type});return h||c.addRemoteCandidate(l),!h}function o(c,l){var h=new Error(l);return h.name=c,h.code={NotSupportedError:9,InvalidStateError:11,InvalidAccessError:15,TypeError:void 0,OperationError:void 0}[c],h}return gn=function(c,l){function h(f,m){m.addTrack(f),m.dispatchEvent(new c.MediaStreamTrackEvent("addtrack",{track:f}))}function u(f,m){m.removeTrack(f),m.dispatchEvent(new c.MediaStreamTrackEvent("removetrack",{track:f}))}function d(f,m,b,v){var x=new Event("track");x.track=m,x.receiver=b,x.transceiver={receiver:b},x.streams=v,c.setTimeout(function(){f._dispatchEvent("track",x)})}var p=function(f){var m=this,b=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach(function(x){m[x]=b[x].bind(b)}),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",f=JSON.parse(JSON.stringify(f||{})),this.usingBundle=f.bundlePolicy==="max-bundle",f.rtcpMuxPolicy==="negotiate")throw o("NotSupportedError","rtcpMuxPolicy 'negotiate' is not supported");switch(f.rtcpMuxPolicy||(f.rtcpMuxPolicy="require"),f.iceTransportPolicy){case"all":case"relay":break;default:f.iceTransportPolicy="all";break}switch(f.bundlePolicy){case"balanced":case"max-compat":case"max-bundle":break;default:f.bundlePolicy="balanced";break}if(f.iceServers=r(f.iceServers||[],l),this._iceGatherers=[],f.iceCandidatePoolSize)for(var v=f.iceCandidatePoolSize;v>0;v--)this._iceGatherers.push(new c.RTCIceGatherer({iceServers:f.iceServers,gatherPolicy:f.iceTransportPolicy}));else f.iceCandidatePoolSize=0;this._config=f,this.transceivers=[],this._sdpSessionId=n.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(p.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(p.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),p.prototype.onicecandidate=null,p.prototype.onaddstream=null,p.prototype.ontrack=null,p.prototype.onremovestream=null,p.prototype.onsignalingstatechange=null,p.prototype.oniceconnectionstatechange=null,p.prototype.onconnectionstatechange=null,p.prototype.onicegatheringstatechange=null,p.prototype.onnegotiationneeded=null,p.prototype.ondatachannel=null,p.prototype._dispatchEvent=function(f,m){this._isClosed||(this.dispatchEvent(m),typeof this["on"+f]=="function"&&this["on"+f](m))},p.prototype._emitGatheringStateChange=function(){var f=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",f)},p.prototype.getConfiguration=function(){return this._config},p.prototype.getLocalStreams=function(){return this.localStreams},p.prototype.getRemoteStreams=function(){return this.remoteStreams},p.prototype._createTransceiver=function(f,m){var b=this.transceivers.length>0,v={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:f,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&b)v.iceTransport=this.transceivers[0].iceTransport,v.dtlsTransport=this.transceivers[0].dtlsTransport;else{var x=this._createIceAndDtlsTransports();v.iceTransport=x.iceTransport,v.dtlsTransport=x.dtlsTransport}return m||this.transceivers.push(v),v},p.prototype.addTrack=function(f,m){if(this._isClosed)throw o("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var b=this.transceivers.find(function(_){return _.track===f});if(b)throw o("InvalidAccessError","Track already exists.");for(var v,x=0;x<this.transceivers.length;x++)!this.transceivers[x].track&&this.transceivers[x].kind===f.kind&&(v=this.transceivers[x]);return v||(v=this._createTransceiver(f.kind)),this._maybeFireNegotiationNeeded(),this.localStreams.indexOf(m)===-1&&this.localStreams.push(m),v.track=f,v.stream=m,v.rtpSender=new c.RTCRtpSender(f,v.dtlsTransport),v.rtpSender},p.prototype.addStream=function(f){var m=this;if(l>=15025)f.getTracks().forEach(function(v){m.addTrack(v,f)});else{var b=f.clone();f.getTracks().forEach(function(v,x){var _=b.getTracks()[x];v.addEventListener("enabled",function(S){_.enabled=S.enabled})}),b.getTracks().forEach(function(v){m.addTrack(v,b)})}},p.prototype.removeTrack=function(f){if(this._isClosed)throw o("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(f instanceof c.RTCRtpSender))throw new TypeError("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.");var m=this.transceivers.find(function(x){return x.rtpSender===f});if(!m)throw o("InvalidAccessError","Sender was not created by this connection.");var b=m.stream;m.rtpSender.stop(),m.rtpSender=null,m.track=null,m.stream=null;var v=this.transceivers.map(function(x){return x.stream});v.indexOf(b)===-1&&this.localStreams.indexOf(b)>-1&&this.localStreams.splice(this.localStreams.indexOf(b),1),this._maybeFireNegotiationNeeded()},p.prototype.removeStream=function(f){var m=this;f.getTracks().forEach(function(b){var v=m.getSenders().find(function(x){return x.track===b});v&&m.removeTrack(v)})},p.prototype.getSenders=function(){return this.transceivers.filter(function(f){return!!f.rtpSender}).map(function(f){return f.rtpSender})},p.prototype.getReceivers=function(){return this.transceivers.filter(function(f){return!!f.rtpReceiver}).map(function(f){return f.rtpReceiver})},p.prototype._createIceGatherer=function(f,m){var b=this;if(m&&f>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var v=new c.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(v,"state",{value:"new",writable:!0}),this.transceivers[f].bufferedCandidateEvents=[],this.transceivers[f].bufferCandidates=function(x){var _=!x.candidate||Object.keys(x.candidate).length===0;v.state=_?"completed":"gathering",b.transceivers[f].bufferedCandidateEvents!==null&&b.transceivers[f].bufferedCandidateEvents.push(x)},v.addEventListener("localcandidate",this.transceivers[f].bufferCandidates),v},p.prototype._gather=function(f,m){var b=this,v=this.transceivers[m].iceGatherer;if(!v.onlocalcandidate){var x=this.transceivers[m].bufferedCandidateEvents;this.transceivers[m].bufferedCandidateEvents=null,v.removeEventListener("localcandidate",this.transceivers[m].bufferCandidates),v.onlocalcandidate=function(_){if(!(b.usingBundle&&m>0)){var S=new Event("icecandidate");S.candidate={sdpMid:f,sdpMLineIndex:m};var w=_.candidate,C=!w||Object.keys(w).length===0;if(C)(v.state==="new"||v.state==="gathering")&&(v.state="completed");else{v.state==="new"&&(v.state="gathering"),w.component=1,w.ufrag=v.getLocalParameters().usernameFragment;var M=n.writeCandidate(w);S.candidate=Object.assign(S.candidate,n.parseCandidate(M)),S.candidate.candidate=M,S.candidate.toJSON=function(){return{candidate:S.candidate.candidate,sdpMid:S.candidate.sdpMid,sdpMLineIndex:S.candidate.sdpMLineIndex,usernameFragment:S.candidate.usernameFragment}}}var T=n.getMediaSections(b._localDescription.sdp);C?T[S.candidate.sdpMLineIndex]+=`a=end-of-candidates\r
|
|
49
49
|
`:T[S.candidate.sdpMLineIndex]+="a="+S.candidate.candidate+`\r
|
|
50
|
-
`,v._localDescription.sdp=n.getDescription(v._localDescription.sdp)+T.join("");var E=v.transceivers.every(function(P){return P.iceGatherer&&P.iceGatherer.state==="completed"});v.iceGatheringState!=="gathering"&&(v.iceGatheringState="gathering",v._emitGatheringStateChange()),C||v._dispatchEvent("icecandidate",S),E&&(v._dispatchEvent("icecandidate",new Event("icecandidate")),v.iceGatheringState="complete",v._emitGatheringStateChange())}},c.setTimeout(function(){b.forEach(function(x){_.onlocalcandidate(x)})},0)}},p.prototype._createIceAndDtlsTransports=function(){var f=this,m=new c.RTCIceTransport(null);m.onicestatechange=function(){f._updateIceConnectionState(),f._updateConnectionState()};var v=new c.RTCDtlsTransport(m);return v.ondtlsstatechange=function(){f._updateConnectionState()},v.onerror=function(){Object.defineProperty(v,"state",{value:"failed",writable:!0}),f._updateConnectionState()},{iceTransport:m,dtlsTransport:v}},p.prototype._disposeIceAndDtlsTransports=function(f){var m=this.transceivers[f].iceGatherer;m&&(delete m.onlocalcandidate,delete this.transceivers[f].iceGatherer);var v=this.transceivers[f].iceTransport;v&&(delete v.onicestatechange,delete this.transceivers[f].iceTransport);var _=this.transceivers[f].dtlsTransport;_&&(delete _.ondtlsstatechange,delete _.onerror,delete this.transceivers[f].dtlsTransport)},p.prototype._transceive=function(f,m,v){var _=i(f.localCapabilities,f.remoteCapabilities);m&&f.rtpSender&&(_.encodings=f.sendEncodingParameters,_.rtcp={cname:n.localCName,compound:f.rtcpParameters.compound},f.recvEncodingParameters.length&&(_.rtcp.ssrc=f.recvEncodingParameters[0].ssrc),f.rtpSender.send(_)),v&&f.rtpReceiver&&_.codecs.length>0&&(f.kind==="video"&&f.recvEncodingParameters&&l<15019&&f.recvEncodingParameters.forEach(function(b){delete b.rtx}),f.recvEncodingParameters.length?_.encodings=f.recvEncodingParameters:_.encodings=[{}],_.rtcp={compound:f.rtcpParameters.compound},f.rtcpParameters.cname&&(_.rtcp.cname=f.rtcpParameters.cname),f.sendEncodingParameters.length&&(_.rtcp.ssrc=f.sendEncodingParameters[0].ssrc),f.rtpReceiver.receive(_))},p.prototype.setLocalDescription=function(f){var m=this;if(["offer","answer"].indexOf(f.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+f.type+'"'));if(!s("setLocalDescription",f.type,m.signalingState)||m._isClosed)return Promise.reject(o("InvalidStateError","Can not set local "+f.type+" in state "+m.signalingState));var v,_;if(f.type==="offer")v=n.splitSections(f.sdp),_=v.shift(),v.forEach(function(x,S){var w=n.parseRtpParameters(x);m.transceivers[S].localCapabilities=w}),m.transceivers.forEach(function(x,S){m._gather(x.mid,S)});else if(f.type==="answer"){v=n.splitSections(m._remoteDescription.sdp),_=v.shift();var b=n.matchPrefix(_,"a=ice-lite").length>0;v.forEach(function(x,S){var w=m.transceivers[S],C=w.iceGatherer,M=w.iceTransport,T=w.dtlsTransport,E=w.localCapabilities,P=w.remoteCapabilities,k=n.isRejected(x)&&n.matchPrefix(x,"a=bundle-only").length===0;if(!k&&!w.rejected){var R=n.getIceParameters(x,_),U=n.getDtlsParameters(x,_);b&&(U.role="server"),(!m.usingBundle||S===0)&&(m._gather(w.mid,S),M.state==="new"&&M.start(C,R,b?"controlling":"controlled"),T.state==="new"&&T.start(U));var N=i(E,P);m._transceive(w,N.codecs.length>0,!1)}})}return m._localDescription={type:f.type,sdp:f.sdp},f.type==="offer"?m._updateSignalingState("have-local-offer"):m._updateSignalingState("stable"),Promise.resolve()},p.prototype.setRemoteDescription=function(f){var m=this;if(["offer","answer"].indexOf(f.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+f.type+'"'));if(!s("setRemoteDescription",f.type,m.signalingState)||m._isClosed)return Promise.reject(o("InvalidStateError","Can not set remote "+f.type+" in state "+m.signalingState));var v={};m.remoteStreams.forEach(function(M){v[M.id]=M});var _=[],b=n.splitSections(f.sdp),x=b.shift(),S=n.matchPrefix(x,"a=ice-lite").length>0,w=n.matchPrefix(x,"a=group:BUNDLE ").length>0;m.usingBundle=w;var C=n.matchPrefix(x,"a=ice-options:")[0];return C?m.canTrickleIceCandidates=C.substr(14).split(" ").indexOf("trickle")>=0:m.canTrickleIceCandidates=!1,b.forEach(function(M,T){var E=n.splitLines(M),P=n.getKind(M),k=n.isRejected(M)&&n.matchPrefix(M,"a=bundle-only").length===0,R=E[0].substr(2).split(" ")[2],U=n.getDirection(M,x),N=n.parseMsid(M),G=n.getMid(M)||n.generateIdentifier();if(k||P==="application"&&(R==="DTLS/SCTP"||R==="UDP/DTLS/SCTP")){m.transceivers[T]={mid:G,kind:P,protocol:R,rejected:!0};return}!k&&m.transceivers[T]&&m.transceivers[T].rejected&&(m.transceivers[T]=m._createTransceiver(P,!0));var B,oe,Q,re,$,me,ye,ie,H,W=n.parseRtpParameters(M),rt,ze;k||(rt=n.getIceParameters(M,x),ze=n.getDtlsParameters(M,x),ze.role="client"),ye=n.parseRtpEncodingParameters(M);var Xe=n.parseRtcpParameters(M),qe=n.matchPrefix(M,"a=end-of-candidates",x).length>0,be=n.matchPrefix(M,"a=candidate:").map(function(Y){return n.parseCandidate(Y)}).filter(function(Y){return Y.component===1});if((f.type==="offer"||f.type==="answer")&&!k&&w&&T>0&&m.transceivers[T]&&(m._disposeIceAndDtlsTransports(T),m.transceivers[T].iceGatherer=m.transceivers[0].iceGatherer,m.transceivers[T].iceTransport=m.transceivers[0].iceTransport,m.transceivers[T].dtlsTransport=m.transceivers[0].dtlsTransport,m.transceivers[T].rtpSender&&m.transceivers[T].rtpSender.setTransport(m.transceivers[0].dtlsTransport),m.transceivers[T].rtpReceiver&&m.transceivers[T].rtpReceiver.setTransport(m.transceivers[0].dtlsTransport)),f.type==="offer"&&!k){B=m.transceivers[T]||m._createTransceiver(P),B.mid=G,B.iceGatherer||(B.iceGatherer=m._createIceGatherer(T,w)),be.length&&B.iceTransport.state==="new"&&(qe&&(!w||T===0)?B.iceTransport.setRemoteCandidates(be):be.forEach(function(Y){a(B.iceTransport,Y)})),ie=c.RTCRtpReceiver.getCapabilities(P),l<15019&&(ie.codecs=ie.codecs.filter(function(Y){return Y.name!=="rtx"})),me=B.sendEncodingParameters||[{ssrc:(2*T+2)*1001}];var Be=!1;if(U==="sendrecv"||U==="sendonly"){if(Be=!B.rtpReceiver,$=B.rtpReceiver||new c.RTCRtpReceiver(B.dtlsTransport,P),Be){var xe;H=$.track,N&&N.stream==="-"||(N?(v[N.stream]||(v[N.stream]=new c.MediaStream,Object.defineProperty(v[N.stream],"id",{get:function(){return N.stream}})),Object.defineProperty(H,"id",{get:function(){return N.track}}),xe=v[N.stream]):(v.default||(v.default=new c.MediaStream),xe=v.default)),xe&&(h(H,xe),B.associatedRemoteMediaStreams.push(xe)),_.push([H,$,xe])}}else B.rtpReceiver&&B.rtpReceiver.track&&(B.associatedRemoteMediaStreams.forEach(function(Y){var He=Y.getTracks().find(function(st){return st.id===B.rtpReceiver.track.id});He&&u(He,Y)}),B.associatedRemoteMediaStreams=[]);B.localCapabilities=ie,B.remoteCapabilities=W,B.rtpReceiver=$,B.rtcpParameters=Xe,B.sendEncodingParameters=me,B.recvEncodingParameters=ye,m._transceive(m.transceivers[T],!1,Be)}else if(f.type==="answer"&&!k){B=m.transceivers[T],oe=B.iceGatherer,Q=B.iceTransport,re=B.dtlsTransport,$=B.rtpReceiver,me=B.sendEncodingParameters,ie=B.localCapabilities,m.transceivers[T].recvEncodingParameters=ye,m.transceivers[T].remoteCapabilities=W,m.transceivers[T].rtcpParameters=Xe,be.length&&Q.state==="new"&&((S||qe)&&(!w||T===0)?Q.setRemoteCandidates(be):be.forEach(function(Y){a(B.iceTransport,Y)})),(!w||T===0)&&(Q.state==="new"&&Q.start(oe,rt,"controlling"),re.state==="new"&&re.start(ze));var it=i(B.localCapabilities,B.remoteCapabilities),nt=it.codecs.filter(function(Y){return Y.name.toLowerCase()==="rtx"}).length;!nt&&B.sendEncodingParameters[0].rtx&&delete B.sendEncodingParameters[0].rtx,m._transceive(B,U==="sendrecv"||U==="recvonly",U==="sendrecv"||U==="sendonly"),$&&(U==="sendrecv"||U==="sendonly")?(H=$.track,N?(v[N.stream]||(v[N.stream]=new c.MediaStream),h(H,v[N.stream]),_.push([H,$,v[N.stream]])):(v.default||(v.default=new c.MediaStream),h(H,v.default),_.push([H,$,v.default]))):delete B.rtpReceiver}}),m._dtlsRole===void 0&&(m._dtlsRole=f.type==="offer"?"active":"passive"),m._remoteDescription={type:f.type,sdp:f.sdp},f.type==="offer"?m._updateSignalingState("have-remote-offer"):m._updateSignalingState("stable"),Object.keys(v).forEach(function(M){var T=v[M];if(T.getTracks().length){if(m.remoteStreams.indexOf(T)===-1){m.remoteStreams.push(T);var E=new Event("addstream");E.stream=T,c.setTimeout(function(){m._dispatchEvent("addstream",E)})}_.forEach(function(P){var k=P[0],R=P[1];T.id===P[2].id&&d(m,k,R,[T])})}}),_.forEach(function(M){M[2]||d(m,M[0],M[1],[])}),c.setTimeout(function(){m&&m.transceivers&&m.transceivers.forEach(function(M){M.iceTransport&&M.iceTransport.state==="new"&&M.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),M.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},p.prototype.close=function(){this.transceivers.forEach(function(f){f.iceTransport&&f.iceTransport.stop(),f.dtlsTransport&&f.dtlsTransport.stop(),f.rtpSender&&f.rtpSender.stop(),f.rtpReceiver&&f.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState("closed")},p.prototype._updateSignalingState=function(f){this.signalingState=f;var m=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",m)},p.prototype._maybeFireNegotiationNeeded=function(){var f=this;this.signalingState!=="stable"||this.needNegotiation===!0||(this.needNegotiation=!0,c.setTimeout(function(){if(f.needNegotiation){f.needNegotiation=!1;var m=new Event("negotiationneeded");f._dispatchEvent("negotiationneeded",m)}},0))},p.prototype._updateIceConnectionState=function(){var f,m={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(_){_.iceTransport&&!_.rejected&&m[_.iceTransport.state]++}),f="new",m.failed>0?f="failed":m.checking>0?f="checking":m.disconnected>0?f="disconnected":m.new>0?f="new":m.connected>0?f="connected":m.completed>0&&(f="completed"),f!==this.iceConnectionState){this.iceConnectionState=f;var v=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",v)}},p.prototype._updateConnectionState=function(){var f,m={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(_){_.iceTransport&&_.dtlsTransport&&!_.rejected&&(m[_.iceTransport.state]++,m[_.dtlsTransport.state]++)}),m.connected+=m.completed,f="new",m.failed>0?f="failed":m.connecting>0?f="connecting":m.disconnected>0?f="disconnected":m.new>0?f="new":m.connected>0&&(f="connected"),f!==this.connectionState){this.connectionState=f;var v=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",v)}},p.prototype.createOffer=function(){var f=this;if(f._isClosed)return Promise.reject(o("InvalidStateError","Can not call createOffer after close"));var m=f.transceivers.filter(function(S){return S.kind==="audio"}).length,v=f.transceivers.filter(function(S){return S.kind==="video"}).length,_=arguments[0];if(_){if(_.mandatory||_.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");_.offerToReceiveAudio!==void 0&&(_.offerToReceiveAudio===!0?m=1:_.offerToReceiveAudio===!1?m=0:m=_.offerToReceiveAudio),_.offerToReceiveVideo!==void 0&&(_.offerToReceiveVideo===!0?v=1:_.offerToReceiveVideo===!1?v=0:v=_.offerToReceiveVideo)}for(f.transceivers.forEach(function(S){S.kind==="audio"?(m--,m<0&&(S.wantReceive=!1)):S.kind==="video"&&(v--,v<0&&(S.wantReceive=!1))});m>0||v>0;)m>0&&(f._createTransceiver("audio"),m--),v>0&&(f._createTransceiver("video"),v--);var b=n.writeSessionBoilerplate(f._sdpSessionId,f._sdpSessionVersion++);f.transceivers.forEach(function(S,w){var C=S.track,M=S.kind,T=S.mid||n.generateIdentifier();S.mid=T,S.iceGatherer||(S.iceGatherer=f._createIceGatherer(w,f.usingBundle));var E=c.RTCRtpSender.getCapabilities(M);l<15019&&(E.codecs=E.codecs.filter(function(k){return k.name!=="rtx"})),E.codecs.forEach(function(k){k.name==="H264"&&k.parameters["level-asymmetry-allowed"]===void 0&&(k.parameters["level-asymmetry-allowed"]="1"),S.remoteCapabilities&&S.remoteCapabilities.codecs&&S.remoteCapabilities.codecs.forEach(function(R){k.name.toLowerCase()===R.name.toLowerCase()&&k.clockRate===R.clockRate&&(k.preferredPayloadType=R.payloadType)})}),E.headerExtensions.forEach(function(k){var R=S.remoteCapabilities&&S.remoteCapabilities.headerExtensions||[];R.forEach(function(U){k.uri===U.uri&&(k.id=U.id)})});var P=S.sendEncodingParameters||[{ssrc:(2*w+1)*1001}];C&&l>=15019&&M==="video"&&!P[0].rtx&&(P[0].rtx={ssrc:P[0].ssrc+1}),S.wantReceive&&(S.rtpReceiver=new c.RTCRtpReceiver(S.dtlsTransport,M)),S.localCapabilities=E,S.sendEncodingParameters=P}),f._config.bundlePolicy!=="max-compat"&&(b+="a=group:BUNDLE "+f.transceivers.map(function(S){return S.mid}).join(" ")+`\r
|
|
51
|
-
`),
|
|
52
|
-
`,f.transceivers.forEach(function(S,w){
|
|
53
|
-
`,S.iceGatherer&&f.iceGatheringState!=="new"&&(w===0||!f.usingBundle)&&(S.iceGatherer.getLocalCandidates().forEach(function(C){C.component=1,
|
|
54
|
-
`}),S.iceGatherer.state==="completed"&&(
|
|
55
|
-
`))});var
|
|
50
|
+
`,b._localDescription.sdp=n.getDescription(b._localDescription.sdp)+T.join("");var E=b.transceivers.every(function(P){return P.iceGatherer&&P.iceGatherer.state==="completed"});b.iceGatheringState!=="gathering"&&(b.iceGatheringState="gathering",b._emitGatheringStateChange()),C||b._dispatchEvent("icecandidate",S),E&&(b._dispatchEvent("icecandidate",new Event("icecandidate")),b.iceGatheringState="complete",b._emitGatheringStateChange())}},c.setTimeout(function(){x.forEach(function(_){v.onlocalcandidate(_)})},0)}},p.prototype._createIceAndDtlsTransports=function(){var f=this,m=new c.RTCIceTransport(null);m.onicestatechange=function(){f._updateIceConnectionState(),f._updateConnectionState()};var b=new c.RTCDtlsTransport(m);return b.ondtlsstatechange=function(){f._updateConnectionState()},b.onerror=function(){Object.defineProperty(b,"state",{value:"failed",writable:!0}),f._updateConnectionState()},{iceTransport:m,dtlsTransport:b}},p.prototype._disposeIceAndDtlsTransports=function(f){var m=this.transceivers[f].iceGatherer;m&&(delete m.onlocalcandidate,delete this.transceivers[f].iceGatherer);var b=this.transceivers[f].iceTransport;b&&(delete b.onicestatechange,delete this.transceivers[f].iceTransport);var v=this.transceivers[f].dtlsTransport;v&&(delete v.ondtlsstatechange,delete v.onerror,delete this.transceivers[f].dtlsTransport)},p.prototype._transceive=function(f,m,b){var v=i(f.localCapabilities,f.remoteCapabilities);m&&f.rtpSender&&(v.encodings=f.sendEncodingParameters,v.rtcp={cname:n.localCName,compound:f.rtcpParameters.compound},f.recvEncodingParameters.length&&(v.rtcp.ssrc=f.recvEncodingParameters[0].ssrc),f.rtpSender.send(v)),b&&f.rtpReceiver&&v.codecs.length>0&&(f.kind==="video"&&f.recvEncodingParameters&&l<15019&&f.recvEncodingParameters.forEach(function(x){delete x.rtx}),f.recvEncodingParameters.length?v.encodings=f.recvEncodingParameters:v.encodings=[{}],v.rtcp={compound:f.rtcpParameters.compound},f.rtcpParameters.cname&&(v.rtcp.cname=f.rtcpParameters.cname),f.sendEncodingParameters.length&&(v.rtcp.ssrc=f.sendEncodingParameters[0].ssrc),f.rtpReceiver.receive(v))},p.prototype.setLocalDescription=function(f){var m=this;if(["offer","answer"].indexOf(f.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+f.type+'"'));if(!s("setLocalDescription",f.type,m.signalingState)||m._isClosed)return Promise.reject(o("InvalidStateError","Can not set local "+f.type+" in state "+m.signalingState));var b,v;if(f.type==="offer")b=n.splitSections(f.sdp),v=b.shift(),b.forEach(function(_,S){var w=n.parseRtpParameters(_);m.transceivers[S].localCapabilities=w}),m.transceivers.forEach(function(_,S){m._gather(_.mid,S)});else if(f.type==="answer"){b=n.splitSections(m._remoteDescription.sdp),v=b.shift();var x=n.matchPrefix(v,"a=ice-lite").length>0;b.forEach(function(_,S){var w=m.transceivers[S],C=w.iceGatherer,M=w.iceTransport,T=w.dtlsTransport,E=w.localCapabilities,P=w.remoteCapabilities,k=n.isRejected(_)&&n.matchPrefix(_,"a=bundle-only").length===0;if(!k&&!w.rejected){var A=n.getIceParameters(_,v),N=n.getDtlsParameters(_,v);x&&(N.role="server"),(!m.usingBundle||S===0)&&(m._gather(w.mid,S),M.state==="new"&&M.start(C,A,x?"controlling":"controlled"),T.state==="new"&&T.start(N));var U=i(E,P);m._transceive(w,U.codecs.length>0,!1)}})}return m._localDescription={type:f.type,sdp:f.sdp},f.type==="offer"?m._updateSignalingState("have-local-offer"):m._updateSignalingState("stable"),Promise.resolve()},p.prototype.setRemoteDescription=function(f){var m=this;if(["offer","answer"].indexOf(f.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+f.type+'"'));if(!s("setRemoteDescription",f.type,m.signalingState)||m._isClosed)return Promise.reject(o("InvalidStateError","Can not set remote "+f.type+" in state "+m.signalingState));var b={};m.remoteStreams.forEach(function(M){b[M.id]=M});var v=[],x=n.splitSections(f.sdp),_=x.shift(),S=n.matchPrefix(_,"a=ice-lite").length>0,w=n.matchPrefix(_,"a=group:BUNDLE ").length>0;m.usingBundle=w;var C=n.matchPrefix(_,"a=ice-options:")[0];return C?m.canTrickleIceCandidates=C.substr(14).split(" ").indexOf("trickle")>=0:m.canTrickleIceCandidates=!1,x.forEach(function(M,T){var E=n.splitLines(M),P=n.getKind(M),k=n.isRejected(M)&&n.matchPrefix(M,"a=bundle-only").length===0,A=E[0].substr(2).split(" ")[2],N=n.getDirection(M,_),U=n.parseMsid(M),G=n.getMid(M)||n.generateIdentifier();if(k||P==="application"&&(A==="DTLS/SCTP"||A==="UDP/DTLS/SCTP")){m.transceivers[T]={mid:G,kind:P,protocol:A,rejected:!0};return}!k&&m.transceivers[T]&&m.transceivers[T].rejected&&(m.transceivers[T]=m._createTransceiver(P,!0));var B,oe,K,re,$,me,ye,ie,q,W=n.parseRtpParameters(M),it,Be;k||(it=n.getIceParameters(M,_),Be=n.getDtlsParameters(M,_),Be.role="client"),ye=n.parseRtpEncodingParameters(M);var Xe=n.parseRtcpParameters(M),qe=n.matchPrefix(M,"a=end-of-candidates",_).length>0,_e=n.matchPrefix(M,"a=candidate:").map(function(Y){return n.parseCandidate(Y)}).filter(function(Y){return Y.component===1});if((f.type==="offer"||f.type==="answer")&&!k&&w&&T>0&&m.transceivers[T]&&(m._disposeIceAndDtlsTransports(T),m.transceivers[T].iceGatherer=m.transceivers[0].iceGatherer,m.transceivers[T].iceTransport=m.transceivers[0].iceTransport,m.transceivers[T].dtlsTransport=m.transceivers[0].dtlsTransport,m.transceivers[T].rtpSender&&m.transceivers[T].rtpSender.setTransport(m.transceivers[0].dtlsTransport),m.transceivers[T].rtpReceiver&&m.transceivers[T].rtpReceiver.setTransport(m.transceivers[0].dtlsTransport)),f.type==="offer"&&!k){B=m.transceivers[T]||m._createTransceiver(P),B.mid=G,B.iceGatherer||(B.iceGatherer=m._createIceGatherer(T,w)),_e.length&&B.iceTransport.state==="new"&&(qe&&(!w||T===0)?B.iceTransport.setRemoteCandidates(_e):_e.forEach(function(Y){a(B.iceTransport,Y)})),ie=c.RTCRtpReceiver.getCapabilities(P),l<15019&&(ie.codecs=ie.codecs.filter(function(Y){return Y.name!=="rtx"})),me=B.sendEncodingParameters||[{ssrc:(2*T+2)*1001}];var Ie=!1;if(N==="sendrecv"||N==="sendonly"){if(Ie=!B.rtpReceiver,$=B.rtpReceiver||new c.RTCRtpReceiver(B.dtlsTransport,P),Ie){var xe;q=$.track,U&&U.stream==="-"||(U?(b[U.stream]||(b[U.stream]=new c.MediaStream,Object.defineProperty(b[U.stream],"id",{get:function(){return U.stream}})),Object.defineProperty(q,"id",{get:function(){return U.track}}),xe=b[U.stream]):(b.default||(b.default=new c.MediaStream),xe=b.default)),xe&&(h(q,xe),B.associatedRemoteMediaStreams.push(xe)),v.push([q,$,xe])}}else B.rtpReceiver&&B.rtpReceiver.track&&(B.associatedRemoteMediaStreams.forEach(function(Y){var Ye=Y.getTracks().find(function(ot){return ot.id===B.rtpReceiver.track.id});Ye&&u(Ye,Y)}),B.associatedRemoteMediaStreams=[]);B.localCapabilities=ie,B.remoteCapabilities=W,B.rtpReceiver=$,B.rtcpParameters=Xe,B.sendEncodingParameters=me,B.recvEncodingParameters=ye,m._transceive(m.transceivers[T],!1,Ie)}else if(f.type==="answer"&&!k){B=m.transceivers[T],oe=B.iceGatherer,K=B.iceTransport,re=B.dtlsTransport,$=B.rtpReceiver,me=B.sendEncodingParameters,ie=B.localCapabilities,m.transceivers[T].recvEncodingParameters=ye,m.transceivers[T].remoteCapabilities=W,m.transceivers[T].rtcpParameters=Xe,_e.length&&K.state==="new"&&((S||qe)&&(!w||T===0)?K.setRemoteCandidates(_e):_e.forEach(function(Y){a(B.iceTransport,Y)})),(!w||T===0)&&(K.state==="new"&&K.start(oe,it,"controlling"),re.state==="new"&&re.start(Be));var nt=i(B.localCapabilities,B.remoteCapabilities),st=nt.codecs.filter(function(Y){return Y.name.toLowerCase()==="rtx"}).length;!st&&B.sendEncodingParameters[0].rtx&&delete B.sendEncodingParameters[0].rtx,m._transceive(B,N==="sendrecv"||N==="recvonly",N==="sendrecv"||N==="sendonly"),$&&(N==="sendrecv"||N==="sendonly")?(q=$.track,U?(b[U.stream]||(b[U.stream]=new c.MediaStream),h(q,b[U.stream]),v.push([q,$,b[U.stream]])):(b.default||(b.default=new c.MediaStream),h(q,b.default),v.push([q,$,b.default]))):delete B.rtpReceiver}}),m._dtlsRole===void 0&&(m._dtlsRole=f.type==="offer"?"active":"passive"),m._remoteDescription={type:f.type,sdp:f.sdp},f.type==="offer"?m._updateSignalingState("have-remote-offer"):m._updateSignalingState("stable"),Object.keys(b).forEach(function(M){var T=b[M];if(T.getTracks().length){if(m.remoteStreams.indexOf(T)===-1){m.remoteStreams.push(T);var E=new Event("addstream");E.stream=T,c.setTimeout(function(){m._dispatchEvent("addstream",E)})}v.forEach(function(P){var k=P[0],A=P[1];T.id===P[2].id&&d(m,k,A,[T])})}}),v.forEach(function(M){M[2]||d(m,M[0],M[1],[])}),c.setTimeout(function(){m&&m.transceivers&&m.transceivers.forEach(function(M){M.iceTransport&&M.iceTransport.state==="new"&&M.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),M.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},p.prototype.close=function(){this.transceivers.forEach(function(f){f.iceTransport&&f.iceTransport.stop(),f.dtlsTransport&&f.dtlsTransport.stop(),f.rtpSender&&f.rtpSender.stop(),f.rtpReceiver&&f.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState("closed")},p.prototype._updateSignalingState=function(f){this.signalingState=f;var m=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",m)},p.prototype._maybeFireNegotiationNeeded=function(){var f=this;this.signalingState!=="stable"||this.needNegotiation===!0||(this.needNegotiation=!0,c.setTimeout(function(){if(f.needNegotiation){f.needNegotiation=!1;var m=new Event("negotiationneeded");f._dispatchEvent("negotiationneeded",m)}},0))},p.prototype._updateIceConnectionState=function(){var f,m={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(v){v.iceTransport&&!v.rejected&&m[v.iceTransport.state]++}),f="new",m.failed>0?f="failed":m.checking>0?f="checking":m.disconnected>0?f="disconnected":m.new>0?f="new":m.connected>0?f="connected":m.completed>0&&(f="completed"),f!==this.iceConnectionState){this.iceConnectionState=f;var b=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",b)}},p.prototype._updateConnectionState=function(){var f,m={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(v){v.iceTransport&&v.dtlsTransport&&!v.rejected&&(m[v.iceTransport.state]++,m[v.dtlsTransport.state]++)}),m.connected+=m.completed,f="new",m.failed>0?f="failed":m.connecting>0?f="connecting":m.disconnected>0?f="disconnected":m.new>0?f="new":m.connected>0&&(f="connected"),f!==this.connectionState){this.connectionState=f;var b=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",b)}},p.prototype.createOffer=function(){var f=this;if(f._isClosed)return Promise.reject(o("InvalidStateError","Can not call createOffer after close"));var m=f.transceivers.filter(function(S){return S.kind==="audio"}).length,b=f.transceivers.filter(function(S){return S.kind==="video"}).length,v=arguments[0];if(v){if(v.mandatory||v.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");v.offerToReceiveAudio!==void 0&&(v.offerToReceiveAudio===!0?m=1:v.offerToReceiveAudio===!1?m=0:m=v.offerToReceiveAudio),v.offerToReceiveVideo!==void 0&&(v.offerToReceiveVideo===!0?b=1:v.offerToReceiveVideo===!1?b=0:b=v.offerToReceiveVideo)}for(f.transceivers.forEach(function(S){S.kind==="audio"?(m--,m<0&&(S.wantReceive=!1)):S.kind==="video"&&(b--,b<0&&(S.wantReceive=!1))});m>0||b>0;)m>0&&(f._createTransceiver("audio"),m--),b>0&&(f._createTransceiver("video"),b--);var x=n.writeSessionBoilerplate(f._sdpSessionId,f._sdpSessionVersion++);f.transceivers.forEach(function(S,w){var C=S.track,M=S.kind,T=S.mid||n.generateIdentifier();S.mid=T,S.iceGatherer||(S.iceGatherer=f._createIceGatherer(w,f.usingBundle));var E=c.RTCRtpSender.getCapabilities(M);l<15019&&(E.codecs=E.codecs.filter(function(k){return k.name!=="rtx"})),E.codecs.forEach(function(k){k.name==="H264"&&k.parameters["level-asymmetry-allowed"]===void 0&&(k.parameters["level-asymmetry-allowed"]="1"),S.remoteCapabilities&&S.remoteCapabilities.codecs&&S.remoteCapabilities.codecs.forEach(function(A){k.name.toLowerCase()===A.name.toLowerCase()&&k.clockRate===A.clockRate&&(k.preferredPayloadType=A.payloadType)})}),E.headerExtensions.forEach(function(k){var A=S.remoteCapabilities&&S.remoteCapabilities.headerExtensions||[];A.forEach(function(N){k.uri===N.uri&&(k.id=N.id)})});var P=S.sendEncodingParameters||[{ssrc:(2*w+1)*1001}];C&&l>=15019&&M==="video"&&!P[0].rtx&&(P[0].rtx={ssrc:P[0].ssrc+1}),S.wantReceive&&(S.rtpReceiver=new c.RTCRtpReceiver(S.dtlsTransport,M)),S.localCapabilities=E,S.sendEncodingParameters=P}),f._config.bundlePolicy!=="max-compat"&&(x+="a=group:BUNDLE "+f.transceivers.map(function(S){return S.mid}).join(" ")+`\r
|
|
51
|
+
`),x+=`a=ice-options:trickle\r
|
|
52
|
+
`,f.transceivers.forEach(function(S,w){x+=t(S,S.localCapabilities,"offer",S.stream,f._dtlsRole),x+=`a=rtcp-rsize\r
|
|
53
|
+
`,S.iceGatherer&&f.iceGatheringState!=="new"&&(w===0||!f.usingBundle)&&(S.iceGatherer.getLocalCandidates().forEach(function(C){C.component=1,x+="a="+n.writeCandidate(C)+`\r
|
|
54
|
+
`}),S.iceGatherer.state==="completed"&&(x+=`a=end-of-candidates\r
|
|
55
|
+
`))});var _=new c.RTCSessionDescription({type:"offer",sdp:x});return Promise.resolve(_)},p.prototype.createAnswer=function(){var f=this;if(f._isClosed)return Promise.reject(o("InvalidStateError","Can not call createAnswer after close"));if(!(f.signalingState==="have-remote-offer"||f.signalingState==="have-local-pranswer"))return Promise.reject(o("InvalidStateError","Can not call createAnswer in signalingState "+f.signalingState));var m=n.writeSessionBoilerplate(f._sdpSessionId,f._sdpSessionVersion++);f.usingBundle&&(m+="a=group:BUNDLE "+f.transceivers.map(function(x){return x.mid}).join(" ")+`\r
|
|
56
56
|
`),m+=`a=ice-options:trickle\r
|
|
57
|
-
`;var
|
|
58
|
-
`:m+="m=application 0 "+
|
|
59
|
-
`:
|
|
57
|
+
`;var b=n.getMediaSections(f._remoteDescription.sdp).length;f.transceivers.forEach(function(x,_){if(!(_+1>b)){if(x.rejected){x.kind==="application"?x.protocol==="DTLS/SCTP"?m+=`m=application 0 DTLS/SCTP 5000\r
|
|
58
|
+
`:m+="m=application 0 "+x.protocol+` webrtc-datachannel\r
|
|
59
|
+
`:x.kind==="audio"?m+=`m=audio 0 UDP/TLS/RTP/SAVPF 0\r
|
|
60
60
|
a=rtpmap:0 PCMU/8000\r
|
|
61
|
-
`:
|
|
61
|
+
`:x.kind==="video"&&(m+=`m=video 0 UDP/TLS/RTP/SAVPF 120\r
|
|
62
62
|
a=rtpmap:120 VP8/90000\r
|
|
63
63
|
`),m+=`c=IN IP4 0.0.0.0\r
|
|
64
64
|
a=inactive\r
|
|
65
|
-
a=mid:`+
|
|
66
|
-
`;return}if(
|
|
67
|
-
`)}});var
|
|
68
|
-
`,m._remoteDescription.sdp=n.getDescription(m._remoteDescription.sdp)+
|
|
69
|
-
`,m._remoteDescription.sdp=n.getDescription(m._remoteDescription.sdp)+v.join("")}else return b(o("OperationError","Can not add ICE candidate"))}else return b(o("InvalidStateError","Can not add ICE candidate without a remote description"));_()})},p.prototype.getStats=function(f){if(f&&f instanceof c.MediaStreamTrack){var m=null;if(this.transceivers.forEach(function(_){_.rtpSender&&_.rtpSender.track===f?m=_.rtpSender:_.rtpReceiver&&_.rtpReceiver.track===f&&(m=_.rtpReceiver)}),!m)throw o("InvalidAccessError","Invalid selector.");return m.getStats()}var v=[];return this.transceivers.forEach(function(_){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(b){_[b]&&v.push(_[b].getStats())})}),Promise.all(v).then(function(_){var b=new Map;return _.forEach(function(x){x.forEach(function(S){b.set(S.id,S)})}),b})};var y=["RTCRtpSender","RTCRtpReceiver","RTCIceGatherer","RTCIceTransport","RTCDtlsTransport"];y.forEach(function(f){var m=c[f];if(m&&m.prototype&&m.prototype.getStats){var v=m.prototype.getStats;m.prototype.getStats=function(){return v.apply(this).then(function(_){var b=new Map;return Object.keys(_).forEach(function(x){_[x].type=e(_[x]),b.set(x,_[x])}),b})}}});var g=["createOffer","createAnswer"];return g.forEach(function(f){var m=p.prototype[f];p.prototype[f]=function(){var v=arguments;return typeof v[0]=="function"||typeof v[1]=="function"?m.apply(this,[arguments[2]]).then(function(_){typeof v[0]=="function"&&v[0].apply(null,[_])},function(_){typeof v[1]=="function"&&v[1].apply(null,[_])}):m.apply(this,arguments)}}),g=["setLocalDescription","setRemoteDescription","addIceCandidate"],g.forEach(function(f){var m=p.prototype[f];p.prototype[f]=function(){var v=arguments;return typeof v[1]=="function"||typeof v[2]=="function"?m.apply(this,arguments).then(function(){typeof v[1]=="function"&&v[1].apply(null)},function(_){typeof v[2]=="function"&&v[2].apply(null,[_])}):m.apply(this,arguments)}}),["getStats"].forEach(function(f){var m=p.prototype[f];p.prototype[f]=function(){var v=arguments;return typeof v[1]=="function"?m.apply(this,arguments).then(function(){typeof v[1]=="function"&&v[1].apply(null)}):m.apply(this,arguments)}}),p},mn}var lc=cc();const hc=di(lc);function $s(n){const e=n&&n.navigator,t=function(i){return{name:{PermissionDeniedError:"NotAllowedError"}[i.name]||i.name,message:i.message,constraint:i.constraint,toString(){return this.name}}},r=e.mediaDevices.getUserMedia.bind(e.mediaDevices);Object.getOwnPropertyDescriptor(e.mediaDevices,"getUserMedia")?.writable&&(e.mediaDevices.getUserMedia=function(i){return r(i).catch(s=>Promise.reject(t(s)))})}function eo(n){"getDisplayMedia"in n.navigator&&n.navigator.mediaDevices&&(n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices||(n.navigator.mediaDevices.getDisplayMedia=n.navigator.getDisplayMedia.bind(n.navigator)))}function yn(n,e){if(n.RTCIceGatherer&&(n.RTCIceCandidate||(n.RTCIceCandidate=function(r){return r}),n.RTCSessionDescription||(n.RTCSessionDescription=function(r){return r}),e.version<15025)){const r=Object.getOwnPropertyDescriptor(n.MediaStreamTrack.prototype,"enabled");Object.defineProperty(n.MediaStreamTrack.prototype,"enabled",{set(i){r.set.call(this,i);const s=new Event("enabled");s.enabled=i,this.dispatchEvent(s)}})}n.RTCRtpSender&&!("dtmf"in n.RTCRtpSender.prototype)&&Object.defineProperty(n.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=new n.RTCDtmfSender(this):this.track.kind==="video"&&(this._dtmf=null)),this._dtmf}}),n.RTCDtmfSender&&!n.RTCDTMFSender&&(n.RTCDTMFSender=n.RTCDtmfSender);const t=hc(n,e.version);n.RTCPeerConnection=function(r){return r&&r.iceServers&&(r.iceServers=ac(r.iceServers,e.version),dn("ICE servers after filtering:",r.iceServers)),new t(r)},n.RTCPeerConnection.prototype=t.prototype}function to(n){n.RTCRtpSender&&!("replaceTrack"in n.RTCRtpSender.prototype)&&(n.RTCRtpSender.prototype.replaceTrack=n.RTCRtpSender.prototype.setTrack)}const ro=Object.freeze(Object.defineProperty({__proto__:null,shimGetDisplayMedia:eo,shimGetUserMedia:$s,shimPeerConnection:yn,shimReplaceTrack:to},Symbol.toStringTag,{value:"Module"}));function io(n,e){const t=n&&n.navigator,r=n&&n.MediaStreamTrack;if(t.getUserMedia=function(i,s,a){pi("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)}),r&&r.prototype.getSettings){const a=r.prototype.getSettings;r.prototype.getSettings=function(){const o=a.apply(this,arguments);return i(o,"mozAutoGainControl","autoGainControl"),i(o,"mozNoiseSuppression","noiseSuppression"),o}}if(r&&r.prototype.applyConstraints){const a=r.prototype.applyConstraints;r.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 uc(n,e){n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices||n.navigator.mediaDevices&&(n.navigator.mediaDevices.getDisplayMedia=function(t){if(!(t&&t.video)){const r=new DOMException("getDisplayMedia without video constraints is undefined");return r.name="NotFoundError",r.code=8,Promise.reject(r)}return t.video===!0?t.video={mediaSource:e}:t.video.mediaSource=e,n.navigator.mediaDevices.getUserMedia(t)})}function no(n){typeof n=="object"&&n.RTCTrackEvent&&"receiver"in n.RTCTrackEvent.prototype&&!("transceiver"in n.RTCTrackEvent.prototype)&&Object.defineProperty(n.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function gn(n,e){if(typeof n!="object"||!(n.RTCPeerConnection||n.mozRTCPeerConnection))return;!n.RTCPeerConnection&&n.mozRTCPeerConnection&&(n.RTCPeerConnection=n.mozRTCPeerConnection),e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(i){const s=n.RTCPeerConnection.prototype[i],a={[i](){return arguments[0]=new(i==="addIceCandidate"?n.RTCIceCandidate:n.RTCSessionDescription)(arguments[0]),s.apply(this,arguments)}};n.RTCPeerConnection.prototype[i]=a[i]});const t={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},r=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){const[i,s,a]=arguments;return r.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,h)=>{o.set(h,Object.assign({},l,{type:t[l.type]||l.type}))})}return o}).then(s,a)}}function so(n){if(!(typeof n=="object"&&n.RTCPeerConnection&&n.RTCRtpSender)||n.RTCRtpSender&&"getStats"in n.RTCRtpSender.prototype)return;const e=n.RTCPeerConnection.prototype.getSenders;e&&(n.RTCPeerConnection.prototype.getSenders=function(){const r=e.apply(this,[]);return r.forEach(i=>i._pc=this),r});const t=n.RTCPeerConnection.prototype.addTrack;t&&(n.RTCPeerConnection.prototype.addTrack=function(){const r=t.apply(this,arguments);return r._pc=this,r}),n.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function oo(n){if(!(typeof n=="object"&&n.RTCPeerConnection&&n.RTCRtpSender)||n.RTCRtpSender&&"getStats"in n.RTCRtpReceiver.prototype)return;const e=n.RTCPeerConnection.prototype.getReceivers;e&&(n.RTCPeerConnection.prototype.getReceivers=function(){const t=e.apply(this,[]);return t.forEach(r=>r._pc=this),t}),jt(n,"track",t=>(t.receiver._pc=t.srcElement,t)),n.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function ao(n){!n.RTCPeerConnection||"removeStream"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.removeStream=function(e){pi("removeStream","removeTrack"),this.getSenders().forEach(t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)})})}function co(n){n.DataChannel&&!n.RTCDataChannel&&(n.RTCDataChannel=n.DataChannel)}function lo(n){if(!(typeof n=="object"&&n.RTCPeerConnection))return;const e=n.RTCPeerConnection.prototype.addTransceiver;e&&(n.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const t=arguments[1],r=t&&"sendEncodings"in t;r&&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(r){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 ho(n){if(!(typeof n=="object"&&n.RTCRtpSender))return;const e=n.RTCRtpSender.prototype.getParameters;e&&(n.RTCRtpSender.prototype.getParameters=function(){const t=e.apply(this,arguments);return"encodings"in t||(t.encodings=[].concat(this.sendEncodings||[{}])),t})}function uo(n){if(!(typeof n=="object"&&n.RTCPeerConnection))return;const e=n.RTCPeerConnection.prototype.createOffer;n.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 po(n){if(!(typeof n=="object"&&n.RTCPeerConnection))return;const e=n.RTCPeerConnection.prototype.createAnswer;n.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 fo=Object.freeze(Object.defineProperty({__proto__:null,shimAddTransceiver:lo,shimCreateAnswer:po,shimCreateOffer:uo,shimGetDisplayMedia:uc,shimGetParameters:ho,shimGetUserMedia:io,shimOnTrack:no,shimPeerConnection:gn,shimRTCDataChannel:co,shimReceiverGetStats:oo,shimRemoveStream:ao,shimSenderGetStats:so},Symbol.toStringTag,{value:"Module"}));function mo(n){if(!(typeof n!="object"||!n.RTCPeerConnection)){if("getLocalStreams"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in n.RTCPeerConnection.prototype)){const e=n.RTCPeerConnection.prototype.addTrack;n.RTCPeerConnection.prototype.addStream=function(t){this._localStreams||(this._localStreams=[]),this._localStreams.includes(t)||this._localStreams.push(t),t.getAudioTracks().forEach(r=>e.call(this,r,t)),t.getVideoTracks().forEach(r=>e.call(this,r,t))},n.RTCPeerConnection.prototype.addTrack=function(t,...r){return r&&r.forEach(i=>{this._localStreams?this._localStreams.includes(i)||this._localStreams.push(i):this._localStreams=[i]}),e.apply(this,arguments)}}"removeStream"in n.RTCPeerConnection.prototype||(n.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 r=e.getTracks();this.getSenders().forEach(i=>{r.includes(i.track)&&this.removeTrack(i)})})}}function yo(n){if(!(typeof n!="object"||!n.RTCPeerConnection)&&("getRemoteStreams"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in n.RTCPeerConnection.prototype))){Object.defineProperty(n.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=r=>{r.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=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){const t=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(r){r.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 go(n){if(typeof n!="object"||!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype,t=e.createOffer,r=e.createAnswer,i=e.setLocalDescription,s=e.setRemoteDescription,a=e.addIceCandidate;e.createOffer=function(c,l){const h=arguments.length>=2?arguments[2]:arguments[0],u=t.apply(this,[h]);return l?(u.then(c,l),Promise.resolve()):u},e.createAnswer=function(c,l){const h=arguments.length>=2?arguments[2]:arguments[0],u=r.apply(this,[h]);return l?(u.then(c,l),Promise.resolve()):u};let o=function(c,l,h){const u=i.apply(this,[c]);return h?(u.then(l,h),Promise.resolve()):u};e.setLocalDescription=o,o=function(c,l,h){const u=s.apply(this,[c]);return h?(u.then(l,h),Promise.resolve()):u},e.setRemoteDescription=o,o=function(c,l,h){const u=a.apply(this,[c]);return h?(u.then(l,h),Promise.resolve()):u},e.addIceCandidate=o}function vo(n){const e=n&&n.navigator;if(e.mediaDevices&&e.mediaDevices.getUserMedia){const t=e.mediaDevices,r=t.getUserMedia.bind(t);e.mediaDevices.getUserMedia=i=>r(_o(i))}!e.getUserMedia&&e.mediaDevices&&e.mediaDevices.getUserMedia&&(e.getUserMedia=function(t,r,i){e.mediaDevices.getUserMedia(t).then(r,i)}.bind(e))}function _o(n){return n&&n.video!==void 0?Object.assign({},n,{video:Us(n.video)}):n}function bo(n){if(!n.RTCPeerConnection)return;const e=n.RTCPeerConnection;n.RTCPeerConnection=function(t,r){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")?(pi("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,r)},n.RTCPeerConnection.prototype=e.prototype,"generateCertificate"in e&&Object.defineProperty(n.RTCPeerConnection,"generateCertificate",{get(){return e.generateCertificate}})}function xo(n){typeof n=="object"&&n.RTCTrackEvent&&"receiver"in n.RTCTrackEvent.prototype&&!("transceiver"in n.RTCTrackEvent.prototype)&&Object.defineProperty(n.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function So(n){const e=n.RTCPeerConnection.prototype.createOffer;n.RTCPeerConnection.prototype.createOffer=function(t){if(t){typeof t.offerToReceiveAudio<"u"&&(t.offerToReceiveAudio=!!t.offerToReceiveAudio);const r=this.getTransceivers().find(s=>s.receiver.track.kind==="audio");t.offerToReceiveAudio===!1&&r?r.direction==="sendrecv"?r.setDirection?r.setDirection("sendonly"):r.direction="sendonly":r.direction==="recvonly"&&(r.setDirection?r.setDirection("inactive"):r.direction="inactive"):t.offerToReceiveAudio===!0&&!r&&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 wo(n){typeof n!="object"||n.AudioContext||(n.AudioContext=n.webkitAudioContext)}const Mo=Object.freeze(Object.defineProperty({__proto__:null,shimAudioContext:wo,shimCallbacksAPI:go,shimConstraints:_o,shimCreateOfferLegacy:So,shimGetUserMedia:vo,shimLocalStreamsAPI:mo,shimRTCIceServerUrls:bo,shimRemoteStreamsAPI:yo,shimTrackEventTransceiver:xo},Symbol.toStringTag,{value:"Module"}));var dc=Qs();const fi=di(dc);function mi(n){if(!n.RTCIceCandidate||n.RTCIceCandidate&&"foundation"in n.RTCIceCandidate.prototype)return;const e=n.RTCIceCandidate;n.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 r=new e(t),i=fi.parseCandidate(t.candidate),s=Object.assign(r,i);return s.toJSON=function(){return{candidate:s.candidate,sdpMid:s.sdpMid,sdpMLineIndex:s.sdpMLineIndex,usernameFragment:s.usernameFragment}},s}return new e(t)},n.RTCIceCandidate.prototype=e.prototype,jt(n,"icecandidate",t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new n.RTCIceCandidate(t.candidate),writable:"false"}),t))}function lr(n,e){if(!n.RTCPeerConnection)return;"sctp"in n.RTCPeerConnection.prototype||Object.defineProperty(n.RTCPeerConnection.prototype,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp}});const t=function(o){if(!o||!o.sdp)return!1;const c=fi.splitSections(o.sdp);return c.shift(),c.some(l=>{const h=fi.parseMLine(l);return h&&h.kind==="application"&&h.protocol.indexOf("SCTP")!==-1})},r=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 h=fi.matchPrefix(o.sdp,"a=max-message-size:");return h.length>0?l=parseInt(h[0].substr(19),10):e.browser==="firefox"&&c!==-1&&(l=2147483637),l},a=n.RTCPeerConnection.prototype.setRemoteDescription;n.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=r(arguments[0]),c=i(o),l=s(arguments[0],o);let h;c===0&&l===0?h=Number.POSITIVE_INFINITY:c===0||l===0?h=Math.max(c,l):h=Math.min(c,l);const u={};Object.defineProperty(u,"maxMessageSize",{get(){return h}}),this._sctp=u}return a.apply(this,arguments)}}function hr(n){if(!(n.RTCPeerConnection&&"createDataChannel"in n.RTCPeerConnection.prototype))return;function e(r,i){const s=r.send;r.send=function(){const a=arguments[0],o=a.length||a.size||a.byteLength;if(r.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(r,arguments)}}const t=n.RTCPeerConnection.prototype.createDataChannel;n.RTCPeerConnection.prototype.createDataChannel=function(){const r=t.apply(this,arguments);return e(r,this),r},jt(n,"datachannel",r=>(e(r.channel,r.target),r))}function vn(n){if(!n.RTCPeerConnection||"connectionState"in n.RTCPeerConnection.prototype)return;const e=n.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 r=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)),r.apply(this,arguments)}})}function _n(n,e){if(!n.RTCPeerConnection||e.browser==="chrome"&&e.version>=71||e.browser==="safari"&&e.version>=605)return;const t=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(r){if(r&&r.sdp&&r.sdp.indexOf(`
|
|
65
|
+
a=mid:`+x.mid+`\r
|
|
66
|
+
`;return}if(x.stream){var S;x.kind==="audio"?S=x.stream.getAudioTracks()[0]:x.kind==="video"&&(S=x.stream.getVideoTracks()[0]),S&&l>=15019&&x.kind==="video"&&!x.sendEncodingParameters[0].rtx&&(x.sendEncodingParameters[0].rtx={ssrc:x.sendEncodingParameters[0].ssrc+1})}var w=i(x.localCapabilities,x.remoteCapabilities),C=w.codecs.filter(function(M){return M.name.toLowerCase()==="rtx"}).length;!C&&x.sendEncodingParameters[0].rtx&&delete x.sendEncodingParameters[0].rtx,m+=t(x,w,"answer",x.stream,f._dtlsRole),x.rtcpParameters&&x.rtcpParameters.reducedSize&&(m+=`a=rtcp-rsize\r
|
|
67
|
+
`)}});var v=new c.RTCSessionDescription({type:"answer",sdp:m});return Promise.resolve(v)},p.prototype.addIceCandidate=function(f){var m=this,b;return f&&!(f.sdpMLineIndex!==void 0||f.sdpMid)?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise(function(v,x){if(m._remoteDescription)if(!f||f.candidate==="")for(var _=0;_<m.transceivers.length&&!(!m.transceivers[_].rejected&&(m.transceivers[_].iceTransport.addRemoteCandidate({}),b=n.getMediaSections(m._remoteDescription.sdp),b[_]+=`a=end-of-candidates\r
|
|
68
|
+
`,m._remoteDescription.sdp=n.getDescription(m._remoteDescription.sdp)+b.join(""),m.usingBundle));_++);else{var S=f.sdpMLineIndex;if(f.sdpMid){for(var w=0;w<m.transceivers.length;w++)if(m.transceivers[w].mid===f.sdpMid){S=w;break}}var C=m.transceivers[S];if(C){if(C.rejected)return v();var M=Object.keys(f.candidate).length>0?n.parseCandidate(f.candidate):{};if(M.protocol==="tcp"&&(M.port===0||M.port===9)||M.component&&M.component!==1)return v();if((S===0||S>0&&C.iceTransport!==m.transceivers[0].iceTransport)&&!a(C.iceTransport,M))return x(o("OperationError","Can not add ICE candidate"));var T=f.candidate.trim();T.indexOf("a=")===0&&(T=T.substr(2)),b=n.getMediaSections(m._remoteDescription.sdp),b[S]+="a="+(M.type?T:"end-of-candidates")+`\r
|
|
69
|
+
`,m._remoteDescription.sdp=n.getDescription(m._remoteDescription.sdp)+b.join("")}else return x(o("OperationError","Can not add ICE candidate"))}else return x(o("InvalidStateError","Can not add ICE candidate without a remote description"));v()})},p.prototype.getStats=function(f){if(f&&f instanceof c.MediaStreamTrack){var m=null;if(this.transceivers.forEach(function(v){v.rtpSender&&v.rtpSender.track===f?m=v.rtpSender:v.rtpReceiver&&v.rtpReceiver.track===f&&(m=v.rtpReceiver)}),!m)throw o("InvalidAccessError","Invalid selector.");return m.getStats()}var b=[];return this.transceivers.forEach(function(v){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(x){v[x]&&b.push(v[x].getStats())})}),Promise.all(b).then(function(v){var x=new Map;return v.forEach(function(_){_.forEach(function(S){x.set(S.id,S)})}),x})};var y=["RTCRtpSender","RTCRtpReceiver","RTCIceGatherer","RTCIceTransport","RTCDtlsTransport"];y.forEach(function(f){var m=c[f];if(m&&m.prototype&&m.prototype.getStats){var b=m.prototype.getStats;m.prototype.getStats=function(){return b.apply(this).then(function(v){var x=new Map;return Object.keys(v).forEach(function(_){v[_].type=e(v[_]),x.set(_,v[_])}),x})}}});var g=["createOffer","createAnswer"];return g.forEach(function(f){var m=p.prototype[f];p.prototype[f]=function(){var b=arguments;return typeof b[0]=="function"||typeof b[1]=="function"?m.apply(this,[arguments[2]]).then(function(v){typeof b[0]=="function"&&b[0].apply(null,[v])},function(v){typeof b[1]=="function"&&b[1].apply(null,[v])}):m.apply(this,arguments)}}),g=["setLocalDescription","setRemoteDescription","addIceCandidate"],g.forEach(function(f){var m=p.prototype[f];p.prototype[f]=function(){var b=arguments;return typeof b[1]=="function"||typeof b[2]=="function"?m.apply(this,arguments).then(function(){typeof b[1]=="function"&&b[1].apply(null)},function(v){typeof b[2]=="function"&&b[2].apply(null,[v])}):m.apply(this,arguments)}}),["getStats"].forEach(function(f){var m=p.prototype[f];p.prototype[f]=function(){var b=arguments;return typeof b[1]=="function"?m.apply(this,arguments).then(function(){typeof b[1]=="function"&&b[1].apply(null)}):m.apply(this,arguments)}}),p},gn}var xc=_c();const Sc=fi(xc);function io(n){const e=n&&n.navigator,t=function(i){return{name:{PermissionDeniedError:"NotAllowedError"}[i.name]||i.name,message:i.message,constraint:i.constraint,toString(){return this.name}}},r=e.mediaDevices.getUserMedia.bind(e.mediaDevices);Object.getOwnPropertyDescriptor(e.mediaDevices,"getUserMedia")?.writable&&(e.mediaDevices.getUserMedia=function(i){return r(i).catch(s=>Promise.reject(t(s)))})}function no(n){"getDisplayMedia"in n.navigator&&n.navigator.mediaDevices&&(n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices||(n.navigator.mediaDevices.getDisplayMedia=n.navigator.getDisplayMedia.bind(n.navigator)))}function vn(n,e){if(n.RTCIceGatherer&&(n.RTCIceCandidate||(n.RTCIceCandidate=function(r){return r}),n.RTCSessionDescription||(n.RTCSessionDescription=function(r){return r}),e.version<15025)){const r=Object.getOwnPropertyDescriptor(n.MediaStreamTrack.prototype,"enabled");Object.defineProperty(n.MediaStreamTrack.prototype,"enabled",{set(i){r.set.call(this,i);const s=new Event("enabled");s.enabled=i,this.dispatchEvent(s)}})}n.RTCRtpSender&&!("dtmf"in n.RTCRtpSender.prototype)&&Object.defineProperty(n.RTCRtpSender.prototype,"dtmf",{get(){return this._dtmf===void 0&&(this.track.kind==="audio"?this._dtmf=new n.RTCDtmfSender(this):this.track.kind==="video"&&(this._dtmf=null)),this._dtmf}}),n.RTCDtmfSender&&!n.RTCDTMFSender&&(n.RTCDTMFSender=n.RTCDtmfSender);const t=Sc(n,e.version);n.RTCPeerConnection=function(r){return r&&r.iceServers&&(r.iceServers=bc(r.iceServers,e.version),fn("ICE servers after filtering:",r.iceServers)),new t(r)},n.RTCPeerConnection.prototype=t.prototype}function so(n){n.RTCRtpSender&&!("replaceTrack"in n.RTCRtpSender.prototype)&&(n.RTCRtpSender.prototype.replaceTrack=n.RTCRtpSender.prototype.setTrack)}const oo=Object.freeze(Object.defineProperty({__proto__:null,shimGetDisplayMedia:no,shimGetUserMedia:io,shimPeerConnection:vn,shimReplaceTrack:so},Symbol.toStringTag,{value:"Module"}));function ao(n,e){const t=n&&n.navigator,r=n&&n.MediaStreamTrack;if(t.getUserMedia=function(i,s,a){mi("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)}),r&&r.prototype.getSettings){const a=r.prototype.getSettings;r.prototype.getSettings=function(){const o=a.apply(this,arguments);return i(o,"mozAutoGainControl","autoGainControl"),i(o,"mozNoiseSuppression","noiseSuppression"),o}}if(r&&r.prototype.applyConstraints){const a=r.prototype.applyConstraints;r.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 wc(n,e){n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices||n.navigator.mediaDevices&&(n.navigator.mediaDevices.getDisplayMedia=function(t){if(!(t&&t.video)){const r=new DOMException("getDisplayMedia without video constraints is undefined");return r.name="NotFoundError",r.code=8,Promise.reject(r)}return t.video===!0?t.video={mediaSource:e}:t.video.mediaSource=e,n.navigator.mediaDevices.getUserMedia(t)})}function co(n){typeof n=="object"&&n.RTCTrackEvent&&"receiver"in n.RTCTrackEvent.prototype&&!("transceiver"in n.RTCTrackEvent.prototype)&&Object.defineProperty(n.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function bn(n,e){if(typeof n!="object"||!(n.RTCPeerConnection||n.mozRTCPeerConnection))return;!n.RTCPeerConnection&&n.mozRTCPeerConnection&&(n.RTCPeerConnection=n.mozRTCPeerConnection),e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(i){const s=n.RTCPeerConnection.prototype[i],a={[i](){return arguments[0]=new(i==="addIceCandidate"?n.RTCIceCandidate:n.RTCSessionDescription)(arguments[0]),s.apply(this,arguments)}};n.RTCPeerConnection.prototype[i]=a[i]});const t={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},r=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){const[i,s,a]=arguments;return r.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,h)=>{o.set(h,Object.assign({},l,{type:t[l.type]||l.type}))})}return o}).then(s,a)}}function lo(n){if(!(typeof n=="object"&&n.RTCPeerConnection&&n.RTCRtpSender)||n.RTCRtpSender&&"getStats"in n.RTCRtpSender.prototype)return;const e=n.RTCPeerConnection.prototype.getSenders;e&&(n.RTCPeerConnection.prototype.getSenders=function(){const r=e.apply(this,[]);return r.forEach(i=>i._pc=this),r});const t=n.RTCPeerConnection.prototype.addTrack;t&&(n.RTCPeerConnection.prototype.addTrack=function(){const r=t.apply(this,arguments);return r._pc=this,r}),n.RTCRtpSender.prototype.getStats=function(){return this.track?this._pc.getStats(this.track):Promise.resolve(new Map)}}function ho(n){if(!(typeof n=="object"&&n.RTCPeerConnection&&n.RTCRtpSender)||n.RTCRtpSender&&"getStats"in n.RTCRtpReceiver.prototype)return;const e=n.RTCPeerConnection.prototype.getReceivers;e&&(n.RTCPeerConnection.prototype.getReceivers=function(){const t=e.apply(this,[]);return t.forEach(r=>r._pc=this),t}),Gt(n,"track",t=>(t.receiver._pc=t.srcElement,t)),n.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function uo(n){!n.RTCPeerConnection||"removeStream"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.removeStream=function(e){mi("removeStream","removeTrack"),this.getSenders().forEach(t=>{t.track&&e.getTracks().includes(t.track)&&this.removeTrack(t)})})}function po(n){n.DataChannel&&!n.RTCDataChannel&&(n.RTCDataChannel=n.DataChannel)}function fo(n){if(!(typeof n=="object"&&n.RTCPeerConnection))return;const e=n.RTCPeerConnection.prototype.addTransceiver;e&&(n.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const t=arguments[1],r=t&&"sendEncodings"in t;r&&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(r){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 mo(n){if(!(typeof n=="object"&&n.RTCRtpSender))return;const e=n.RTCRtpSender.prototype.getParameters;e&&(n.RTCRtpSender.prototype.getParameters=function(){const t=e.apply(this,arguments);return"encodings"in t||(t.encodings=[].concat(this.sendEncodings||[{}])),t})}function yo(n){if(!(typeof n=="object"&&n.RTCPeerConnection))return;const e=n.RTCPeerConnection.prototype.createOffer;n.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 go(n){if(!(typeof n=="object"&&n.RTCPeerConnection))return;const e=n.RTCPeerConnection.prototype.createAnswer;n.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 vo=Object.freeze(Object.defineProperty({__proto__:null,shimAddTransceiver:fo,shimCreateAnswer:go,shimCreateOffer:yo,shimGetDisplayMedia:wc,shimGetParameters:mo,shimGetUserMedia:ao,shimOnTrack:co,shimPeerConnection:bn,shimRTCDataChannel:po,shimReceiverGetStats:ho,shimRemoveStream:uo,shimSenderGetStats:lo},Symbol.toStringTag,{value:"Module"}));function bo(n){if(!(typeof n!="object"||!n.RTCPeerConnection)){if("getLocalStreams"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.getLocalStreams=function(){return this._localStreams||(this._localStreams=[]),this._localStreams}),!("addStream"in n.RTCPeerConnection.prototype)){const e=n.RTCPeerConnection.prototype.addTrack;n.RTCPeerConnection.prototype.addStream=function(t){this._localStreams||(this._localStreams=[]),this._localStreams.includes(t)||this._localStreams.push(t),t.getAudioTracks().forEach(r=>e.call(this,r,t)),t.getVideoTracks().forEach(r=>e.call(this,r,t))},n.RTCPeerConnection.prototype.addTrack=function(t,...r){return r&&r.forEach(i=>{this._localStreams?this._localStreams.includes(i)||this._localStreams.push(i):this._localStreams=[i]}),e.apply(this,arguments)}}"removeStream"in n.RTCPeerConnection.prototype||(n.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 r=e.getTracks();this.getSenders().forEach(i=>{r.includes(i.track)&&this.removeTrack(i)})})}}function _o(n){if(!(typeof n!="object"||!n.RTCPeerConnection)&&("getRemoteStreams"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.getRemoteStreams=function(){return this._remoteStreams?this._remoteStreams:[]}),!("onaddstream"in n.RTCPeerConnection.prototype))){Object.defineProperty(n.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=r=>{r.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=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){const t=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(r){r.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 xo(n){if(typeof n!="object"||!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype,t=e.createOffer,r=e.createAnswer,i=e.setLocalDescription,s=e.setRemoteDescription,a=e.addIceCandidate;e.createOffer=function(c,l){const h=arguments.length>=2?arguments[2]:arguments[0],u=t.apply(this,[h]);return l?(u.then(c,l),Promise.resolve()):u},e.createAnswer=function(c,l){const h=arguments.length>=2?arguments[2]:arguments[0],u=r.apply(this,[h]);return l?(u.then(c,l),Promise.resolve()):u};let o=function(c,l,h){const u=i.apply(this,[c]);return h?(u.then(l,h),Promise.resolve()):u};e.setLocalDescription=o,o=function(c,l,h){const u=s.apply(this,[c]);return h?(u.then(l,h),Promise.resolve()):u},e.setRemoteDescription=o,o=function(c,l,h){const u=a.apply(this,[c]);return h?(u.then(l,h),Promise.resolve()):u},e.addIceCandidate=o}function So(n){const e=n&&n.navigator;if(e.mediaDevices&&e.mediaDevices.getUserMedia){const t=e.mediaDevices,r=t.getUserMedia.bind(t);e.mediaDevices.getUserMedia=i=>r(wo(i))}!e.getUserMedia&&e.mediaDevices&&e.mediaDevices.getUserMedia&&(e.getUserMedia=function(t,r,i){e.mediaDevices.getUserMedia(t).then(r,i)}.bind(e))}function wo(n){return n&&n.video!==void 0?Object.assign({},n,{video:Ls(n.video)}):n}function Mo(n){if(!n.RTCPeerConnection)return;const e=n.RTCPeerConnection;n.RTCPeerConnection=function(t,r){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")?(mi("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,r)},n.RTCPeerConnection.prototype=e.prototype,"generateCertificate"in e&&Object.defineProperty(n.RTCPeerConnection,"generateCertificate",{get(){return e.generateCertificate}})}function To(n){typeof n=="object"&&n.RTCTrackEvent&&"receiver"in n.RTCTrackEvent.prototype&&!("transceiver"in n.RTCTrackEvent.prototype)&&Object.defineProperty(n.RTCTrackEvent.prototype,"transceiver",{get(){return{receiver:this.receiver}}})}function Co(n){const e=n.RTCPeerConnection.prototype.createOffer;n.RTCPeerConnection.prototype.createOffer=function(t){if(t){typeof t.offerToReceiveAudio<"u"&&(t.offerToReceiveAudio=!!t.offerToReceiveAudio);const r=this.getTransceivers().find(s=>s.receiver.track.kind==="audio");t.offerToReceiveAudio===!1&&r?r.direction==="sendrecv"?r.setDirection?r.setDirection("sendonly"):r.direction="sendonly":r.direction==="recvonly"&&(r.setDirection?r.setDirection("inactive"):r.direction="inactive"):t.offerToReceiveAudio===!0&&!r&&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 Po(n){typeof n!="object"||n.AudioContext||(n.AudioContext=n.webkitAudioContext)}const Eo=Object.freeze(Object.defineProperty({__proto__:null,shimAudioContext:Po,shimCallbacksAPI:xo,shimConstraints:wo,shimCreateOfferLegacy:Co,shimGetUserMedia:So,shimLocalStreamsAPI:bo,shimRTCIceServerUrls:Mo,shimRemoteStreamsAPI:_o,shimTrackEventTransceiver:To},Symbol.toStringTag,{value:"Module"}));var Mc=to();const yi=fi(Mc);function gi(n){if(!n.RTCIceCandidate||n.RTCIceCandidate&&"foundation"in n.RTCIceCandidate.prototype)return;const e=n.RTCIceCandidate;n.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 r=new e(t),i=yi.parseCandidate(t.candidate),s=Object.assign(r,i);return s.toJSON=function(){return{candidate:s.candidate,sdpMid:s.sdpMid,sdpMLineIndex:s.sdpMLineIndex,usernameFragment:s.usernameFragment}},s}return new e(t)},n.RTCIceCandidate.prototype=e.prototype,Gt(n,"icecandidate",t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new n.RTCIceCandidate(t.candidate),writable:"false"}),t))}function ur(n,e){if(!n.RTCPeerConnection)return;"sctp"in n.RTCPeerConnection.prototype||Object.defineProperty(n.RTCPeerConnection.prototype,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp}});const t=function(o){if(!o||!o.sdp)return!1;const c=yi.splitSections(o.sdp);return c.shift(),c.some(l=>{const h=yi.parseMLine(l);return h&&h.kind==="application"&&h.protocol.indexOf("SCTP")!==-1})},r=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 h=yi.matchPrefix(o.sdp,"a=max-message-size:");return h.length>0?l=parseInt(h[0].substr(19),10):e.browser==="firefox"&&c!==-1&&(l=2147483637),l},a=n.RTCPeerConnection.prototype.setRemoteDescription;n.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=r(arguments[0]),c=i(o),l=s(arguments[0],o);let h;c===0&&l===0?h=Number.POSITIVE_INFINITY:c===0||l===0?h=Math.max(c,l):h=Math.min(c,l);const u={};Object.defineProperty(u,"maxMessageSize",{get(){return h}}),this._sctp=u}return a.apply(this,arguments)}}function dr(n){if(!(n.RTCPeerConnection&&"createDataChannel"in n.RTCPeerConnection.prototype))return;function e(r,i){const s=r.send;r.send=function(){const a=arguments[0],o=a.length||a.size||a.byteLength;if(r.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(r,arguments)}}const t=n.RTCPeerConnection.prototype.createDataChannel;n.RTCPeerConnection.prototype.createDataChannel=function(){const r=t.apply(this,arguments);return e(r,this),r},Gt(n,"datachannel",r=>(e(r.channel,r.target),r))}function _n(n){if(!n.RTCPeerConnection||"connectionState"in n.RTCPeerConnection.prototype)return;const e=n.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 r=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)),r.apply(this,arguments)}})}function xn(n,e){if(!n.RTCPeerConnection||e.browser==="chrome"&&e.version>=71||e.browser==="safari"&&e.version>=605)return;const t=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(r){if(r&&r.sdp&&r.sdp.indexOf(`
|
|
70
70
|
a=extmap-allow-mixed`)!==-1){const i=r.sdp.split(`
|
|
71
71
|
`).filter(s=>s.trim()!=="a=extmap-allow-mixed").join(`
|
|
72
|
-
`);n.RTCSessionDescription&&r instanceof n.RTCSessionDescription?arguments[0]=new n.RTCSessionDescription({type:r.type,sdp:i}):r.sdp=i}return t.apply(this,arguments)}}function
|
|
72
|
+
`);n.RTCSessionDescription&&r instanceof n.RTCSessionDescription?arguments[0]=new n.RTCSessionDescription({type:r.type,sdp:i}):r.sdp=i}return t.apply(this,arguments)}}function vi(n,e){if(!(n.RTCPeerConnection&&n.RTCPeerConnection.prototype))return;const t=n.RTCPeerConnection.prototype.addIceCandidate;!t||t.length===0||(n.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 Tc=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:xn,shimAddIceCandidateNullOrEmpty:vi,shimConnectionState:_n,shimMaxMessageSize:ur,shimRTCIceCandidate:gi,shimSendThrowTypeError:dr},Symbol.toStringTag,{value:"Module"}));function Cc({window:n}={},e={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const t=fn,r=gc(n),i={browserDetails:r,commonShim:Tc,extractVersion:hr,disableLog:mc,disableWarnings:yc};switch(r.browser){case"chrome":if(!Qs||!yn||!e.shimChrome)return t("Chrome shim is not included in this adapter release."),i;if(r.version===null)return t("Chrome shim can not determine version, not shimming."),i;t("adapter.js shimming chrome."),i.browserShim=Qs,vi(n,r),Js(n,r),Gs(n),yn(n,r),Ws(n),Zs(n,r),Hs(n),Xs(n),qs(n),Ks(n,r),gi(n),_n(n),ur(n,r),dr(n),xn(n,r);break;case"firefox":if(!vo||!bn||!e.shimFirefox)return t("Firefox shim is not included in this adapter release."),i;t("adapter.js shimming firefox."),i.browserShim=vo,vi(n,r),ao(n,r),bn(n,r),co(n),uo(n),lo(n),ho(n),po(n),fo(n),mo(n),yo(n),go(n),gi(n),_n(n),ur(n,r),dr(n);break;case"edge":if(!oo||!vn||!e.shimEdge)return t("MS edge shim is not included in this adapter release."),i;t("adapter.js shimming edge."),i.browserShim=oo,io(n),no(n),vn(n,r),so(n),ur(n,r),dr(n);break;case"safari":if(!Eo||!e.shimSafari)return t("Safari shim is not included in this adapter release."),i;t("adapter.js shimming safari."),i.browserShim=Eo,vi(n,r),Mo(n),Co(n),xo(n),bo(n),_o(n),To(n),So(n),Po(n),gi(n),ur(n,r),dr(n),xn(n,r);break;default:t("Unsupported browser!");break}return i}const ko=Cc({window:typeof window>"u"?void 0:window});function Qe(n,e,t,r){Object.defineProperty(n,e,{get:t,set:r,enumerable:!0,configurable:!0})}var Sn=ko.default||ko,pr=new(function(){function n(){this.isIOS=["iPad","iPhone","iPod"].includes(navigator.platform),this.supportedBrowsers=["firefox","chrome","safari"],this.minFirefoxVersion=59,this.minChromeVersion=72,this.minSafariVersion=605}return n.prototype.isWebRTCSupported=function(){return typeof RTCPeerConnection<"u"},n.prototype.isBrowserSupported=function(){var e=this.getBrowser(),t=this.getVersion(),r=this.supportedBrowsers.includes(e);return r?e==="chrome"?t>=this.minChromeVersion:e==="firefox"?t>=this.minFirefoxVersion:e==="safari"?!this.isIOS&&t>=this.minSafariVersion:!1:!1},n.prototype.getBrowser=function(){return Sn.browserDetails.browser},n.prototype.getVersion=function(){return Sn.browserDetails.version||0},n.prototype.isUnifiedPlanSupported=function(){var e=this.getBrowser(),t=Sn.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 r,i=!1;try{r=new RTCPeerConnection,r.addTransceiver("audio"),i=!0}catch{}finally{r&&r.close()}return i},n.prototype.toString=function(){return`Supports:
|
|
73
73
|
browser:`.concat(this.getBrowser(),`
|
|
74
74
|
version:`).concat(this.getVersion(),`
|
|
75
75
|
isIOS:`).concat(this.isIOS,`
|
|
76
76
|
isWebRTCSupported:`).concat(this.isWebRTCSupported(),`
|
|
77
77
|
isBrowserSupported:`).concat(this.isBrowserSupported(),`
|
|
78
|
-
isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},n}()),Co={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"},mc=function(){function n(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=Co,this.browser=ur.getBrowser(),this.browserVersion=ur.getVersion(),this.supports=function(){var e={browser:ur.isBrowserSupported(),webRTC:ur.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(Co),e.audioVideo=!0;var r=void 0;try{r=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!r.ordered;try{r.binaryType="blob",e.binaryBlob=!ur.isIOS}catch{}}catch{}finally{r&&r.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=Os.pack,this.unpack=Os.unpack,this._dataCount=1}return n.prototype.noop=function(){},n.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},n.prototype.chunk=function(e){for(var t=[],r=e.size,i=Math.ceil(r/F.chunkedMTU),s=0,a=0;a<r;){var o=Math.min(r,a+F.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},n.prototype.blobToArrayBuffer=function(e,t){var r=new FileReader;return r.onload=function(i){i.target&&t(i.target.result)},r.readAsArrayBuffer(e),r},n.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)&255;return t.buffer},n.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},n.prototype.isSecure=function(){return location.protocol==="https:"},n}(),F=new mc,Po={};Qe(Po,"Peer",()=>Cn,n=>Cn=n);var dr={},yc=Object.prototype.hasOwnProperty,ve="~";function pr(){}Object.create&&(pr.prototype=Object.create(null),new pr().__proto__||(ve=!1));function gc(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function Eo(n,e,t,r,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new gc(t,r||n,i),a=ve?ve+e:e;return n._events[a]?n._events[a].fn?n._events[a]=[n._events[a],s]:n._events[a].push(s):(n._events[a]=s,n._eventsCount++),n}function gi(n,e){--n._eventsCount===0?n._events=new pr:delete n._events[e]}function de(){this._events=new pr,this._eventsCount=0}de.prototype.eventNames=function(){var n=[],e,t;if(this._eventsCount===0)return n;for(t in e=this._events)yc.call(e,t)&&n.push(ve?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},de.prototype.listeners=function(n){var e=ve?ve+n:n,t=this._events[e];if(!t)return[];if(t.fn)return[t.fn];for(var r=0,i=t.length,s=new Array(i);r<i;r++)s[r]=t[r].fn;return s},de.prototype.listenerCount=function(n){var e=ve?ve+n:n,t=this._events[e];return t?t.fn?1:t.length:0},de.prototype.emit=function(n,e,t,r,i,s){var a=ve?ve+n:n;if(!this._events[a])return!1;var o=this._events[a],c=arguments.length,l,h;if(o.fn){switch(o.once&&this.removeListener(n,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,r),!0;case 5:return o.fn.call(o.context,e,t,r,i),!0;case 6:return o.fn.call(o.context,e,t,r,i,s),!0}for(h=1,l=new Array(c-1);h<c;h++)l[h-1]=arguments[h];o.fn.apply(o.context,l)}else{var u=o.length,d;for(h=0;h<u;h++)switch(o[h].once&&this.removeListener(n,o[h].fn,void 0,!0),c){case 1:o[h].fn.call(o[h].context);break;case 2:o[h].fn.call(o[h].context,e);break;case 3:o[h].fn.call(o[h].context,e,t);break;case 4:o[h].fn.call(o[h].context,e,t,r);break;default:if(!l)for(d=1,l=new Array(c-1);d<c;d++)l[d-1]=arguments[d];o[h].fn.apply(o[h].context,l)}}return!0},de.prototype.on=function(n,e,t){return Eo(this,n,e,t,!1)},de.prototype.once=function(n,e,t){return Eo(this,n,e,t,!0)},de.prototype.removeListener=function(n,e,t,r){var i=ve?ve+n:n;if(!this._events[i])return this;if(!e)return gi(this,i),this;var s=this._events[i];if(s.fn)s.fn===e&&(!r||s.once)&&(!t||s.context===t)&&gi(this,i);else{for(var a=0,o=[],c=s.length;a<c;a++)(s[a].fn!==e||r&&!s[a].once||t&&s[a].context!==t)&&o.push(s[a]);o.length?this._events[i]=o.length===1?o[0]:o:gi(this,i)}return this},de.prototype.removeAllListeners=function(n){var e;return n?(e=ve?ve+n:n,this._events[e]&&gi(this,e)):(this._events=new pr,this._eventsCount=0),this},de.prototype.off=de.prototype.removeListener,de.prototype.addListener=de.prototype.on,de.prefixed=ve,de.EventEmitter=de,dr=de;var O={};Qe(O,"LogLevel",()=>Se,n=>Se=n),Qe(O,"default",()=>ko,n=>ko=n);var Et=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var r=t.call(n),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(a)throw a.error}}return s},kt=function(n,e,t){if(t||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return n.concat(s||Array.prototype.slice.call(e))},vc="PeerJS: ",Se;(function(n){n[n.Disabled=0]="Disabled",n[n.Errors=1]="Errors",n[n.Warnings=2]="Warnings",n[n.All=3]="All"})(Se||(Se={}));var _c=function(){function n(){this._logLevel=Se.Disabled}return Object.defineProperty(n.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),n.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=Se.All&&this._print.apply(this,kt([Se.All],Et(e),!1))},n.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=Se.Warnings&&this._print.apply(this,kt([Se.Warnings],Et(e),!1))},n.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=Se.Errors&&this._print.apply(this,kt([Se.Errors],Et(e),!1))},n.prototype.setLogFunction=function(e){this._print=e},n.prototype._print=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var i=kt([vc],Et(t),!1);for(var s in i)i[s]instanceof Error&&(i[s]="("+i[s].name+") "+i[s].message);e>=Se.All?console.log.apply(console,kt([],Et(i),!1)):e>=Se.Warnings?console.warn.apply(console,kt(["WARNING"],Et(i),!1)):e>=Se.Errors&&console.error.apply(console,kt(["ERROR"],Et(i),!1))},n}(),ko=new _c,Ao={};Qe(Ao,"Socket",()=>Ro,n=>Ro=n);var je;(function(n){n.Data="data",n.Media="media"})(je||(je={}));var K;(function(n){n.BrowserIncompatible="browser-incompatible",n.Disconnected="disconnected",n.InvalidID="invalid-id",n.InvalidKey="invalid-key",n.Network="network",n.PeerUnavailable="peer-unavailable",n.SslUnavailable="ssl-unavailable",n.ServerError="server-error",n.SocketError="socket-error",n.SocketClosed="socket-closed",n.UnavailableID="unavailable-id",n.WebRTC="webrtc"})(K||(K={}));var dt;(function(n){n.Binary="binary",n.BinaryUTF8="binary-utf8",n.JSON="json"})(dt||(dt={}));var pt;(function(n){n.Message="message",n.Disconnected="disconnected",n.Error="error",n.Close="close"})(pt||(pt={}));var ae;(function(n){n.Heartbeat="HEARTBEAT",n.Candidate="CANDIDATE",n.Offer="OFFER",n.Answer="ANSWER",n.Open="OPEN",n.Error="ERROR",n.IdTaken="ID-TAKEN",n.InvalidKey="INVALID-KEY",n.Leave="LEAVE",n.Expire="EXPIRE"})(ae||(ae={}));var xn={};xn=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 bc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),xc=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var r=t.call(n),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(a)throw a.error}}return s},Sc=function(n,e,t){if(t||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return n.concat(s||Array.prototype.slice.call(e))},wc=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ro=function(n){bc(e,n);function e(t,r,i,s,a,o){o===void 0&&(o=5e3);var c=n.call(this)||this;c.pingInterval=o,c._disconnected=!0,c._messagesQueue=[];var l=t?"wss://":"ws://";return c._baseUrl=l+r+":"+i+s+"peerjs?key="+a,c}return e.prototype.start=function(t,r){var i=this;this._id=t;var s="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(r);this._socket||!this._disconnected||(this._socket=new WebSocket(s+"&version="+xn.version),this._disconnected=!1,this._socket.onmessage=function(a){var o;try{o=JSON.parse(a.data),O.default.log("Server message received:",o)}catch{O.default.log("Invalid server message",a.data);return}i.emit(pt.Message,o)},this._socket.onclose=function(a){i._disconnected||(O.default.log("Socket closed.",a),i._cleanup(),i._disconnected=!0,i.emit(pt.Disconnected))},this._socket.onopen=function(){i._disconnected||(i._sendQueuedMessages(),O.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()){O.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:ae.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,r,i=Sc([],xc(this._messagesQueue),!1);this._messagesQueue=[];try{for(var s=wc(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&&(r=s.return)&&r.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(pt.Error,"Invalid message");return}if(this._wsOpen()){var r=JSON.stringify(t);this._socket.send(r)}}},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}(dr.EventEmitter),Sn={};Qe(Sn,"MediaConnection",()=>Bo,n=>Bo=n);var wn={};Qe(wn,"Negotiator",()=>Oo,n=>Oo=n);var vi=function(){return vi=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},vi.apply(this,arguments)},_i=function(n,e,t,r){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(h){try{l(r.next(h))}catch(u){a(u)}}function c(h){try{l(r.throw(h))}catch(u){a(u)}}function l(h){h.done?s(h.value):i(h.value).then(o,c)}l((r=r.apply(n,e||[])).next())})},bi=function(n,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,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(h){return c([l,h])}}function c(l){if(r)throw new TypeError("Generator is already executing.");for(;t;)try{if(r=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(n,t)}catch(h){l=[6,h],i=0}finally{r=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},Oo=function(){function n(e){this.connection=e}return n.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===je.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===je.Data){var r=this.connection,i={ordered:!!e.reliable},s=t.createDataChannel(r.label,i);r.initialize(s)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},n.prototype._startPeerConnection=function(){O.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},n.prototype._setupListeners=function(e){var t=this,r=this.connection.peer,i=this.connection.connectionId,s=this.connection.type,a=this.connection.provider;O.default.log("Listening for ICE candidates."),e.onicecandidate=function(o){!o.candidate||!o.candidate.candidate||(O.default.log("Received ICE candidates for ".concat(r,":"),o.candidate),a.socket.send({type:ae.Candidate,payload:{candidate:o.candidate,type:s,connectionId:i},dst:r}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":O.default.log("iceConnectionState is failed, closing connections to "+r),t.connection.emit("error",new Error("Negotiation of connection to "+r+" failed.")),t.connection.close();break;case"closed":O.default.log("iceConnectionState is closed, closing connections to "+r),t.connection.emit("error",new Error("Connection to "+r+" closed.")),t.connection.close();break;case"disconnected":O.default.log("iceConnectionState changed to disconnected on the connection with "+r);break;case"completed":e.onicecandidate=F.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},O.default.log("Listening for data channel"),e.ondatachannel=function(o){O.default.log("Received data channel");var c=o.channel,l=a.getConnection(r,i);l.initialize(c)},O.default.log("Listening for remote stream"),e.ontrack=function(o){O.default.log("Received remote stream");var c=o.streams[0],l=a.getConnection(r,i);if(l.type===je.Media){var h=l;t._addStreamToMediaConnection(c,h)}}},n.prototype.cleanup=function(){O.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",r=!1;if(this.connection.type===je.Data){var i=this.connection,s=i.dataChannel;s&&(r=!!s.readyState&&s.readyState!=="closed")}(t||r)&&e.close()}},n.prototype._makeOffer=function(){return _i(this,void 0,Promise,function(){var e,t,r,i,s,a,o;return bi(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:r=c.sent(),O.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(r.sdp=this.connection.options.sdpTransform(r.sdp)||r.sdp),c.label=3;case 3:return c.trys.push([3,5,,6]),[4,e.setLocalDescription(r)];case 4:return c.sent(),O.default.log("Set localDescription:",r,"for:".concat(this.connection.peer)),i={sdp:r,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:F.browser},this.connection.type===je.Data&&(s=this.connection,i=vi(vi({},i),{label:s.label,reliable:s.reliable,serialization:s.serialization})),t.socket.send({type:ae.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(K.WebRTC,a),O.default.log("Failed to setLocalDescription, ",a)),[3,6];case 6:return[3,8];case 7:return o=c.sent(),t.emitError(K.WebRTC,o),O.default.log("Failed to createOffer, ",o),[3,8];case 8:return[2]}})})},n.prototype._makeAnswer=function(){return _i(this,void 0,Promise,function(){var e,t,r,i,s;return bi(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:r=a.sent(),O.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(r.sdp=this.connection.options.sdpTransform(r.sdp)||r.sdp),a.label=3;case 3:return a.trys.push([3,5,,6]),[4,e.setLocalDescription(r)];case 4:return a.sent(),O.default.log("Set localDescription:",r,"for:".concat(this.connection.peer)),t.socket.send({type:ae.Answer,payload:{sdp:r,type:this.connection.type,connectionId:this.connection.connectionId,browser:F.browser},dst:this.connection.peer}),[3,6];case 5:return i=a.sent(),t.emitError(K.WebRTC,i),O.default.log("Failed to setLocalDescription, ",i),[3,6];case 6:return[3,8];case 7:return s=a.sent(),t.emitError(K.WebRTC,s),O.default.log("Failed to create answer, ",s),[3,8];case 8:return[2]}})})},n.prototype.handleSDP=function(e,t){return _i(this,void 0,Promise,function(){var r,i,s,a;return bi(this,function(o){switch(o.label){case 0:t=new RTCSessionDescription(t),r=this.connection.peerConnection,i=this.connection.provider,O.default.log("Setting remote description",t),s=this,o.label=1;case 1:return o.trys.push([1,5,,6]),[4,r.setRemoteDescription(t)];case 2:return o.sent(),O.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(K.WebRTC,a),O.default.log("Failed to setRemoteDescription, ",a),[3,6];case 6:return[2]}})})},n.prototype.handleCandidate=function(e){return _i(this,void 0,Promise,function(){var t,r,i,s,a,o;return bi(this,function(c){switch(c.label){case 0:O.default.log("handleCandidate:",e),t=e.candidate,r=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:r,candidate:t}))];case 2:return c.sent(),O.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return o=c.sent(),a.emitError(K.WebRTC,o),O.default.log("Failed to handleCandidate, ",o),[3,4];case 4:return[2]}})})},n.prototype._addTracksToConnection=function(e,t){if(O.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return O.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(r){t.addTrack(r,e)})},n.prototype._addStreamToMediaConnection=function(e,t){O.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},n}(),Mn={};Qe(Mn,"BaseConnection",()=>zo,n=>zo=n);var Mc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),zo=function(n){Mc(e,n);function e(t,r,i){var s=n.call(this)||this;return s.peer=t,s.provider=r,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}(dr.EventEmitter),Tc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),xi=function(){return xi=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},xi.apply(this,arguments)},Cc=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Bo=function(n){Tc(e,n);function e(t,r,i){var s=n.call(this,t,r,i)||this;return s._localStream=s.options._stream,s.connectionId=s.options.connectionId||e.ID_PREFIX+F.randomToken(),s._negotiator=new wn.Negotiator(s),s._localStream&&s._negotiator.startConnection({_stream:s._localStream,originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return je.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){O.default.log("Receiving stream",t),this._remoteStream=t,n.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var r=t.type,i=t.payload;switch(t.type){case ae.Answer:this._negotiator.handleSDP(r,i.sdp),this._open=!0;break;case ae.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:O.default.warn("Unrecognized message type:".concat(r," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,r){var i,s;if(r===void 0&&(r={}),this._localStream){O.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,r&&r.sdpTransform&&(this.options.sdpTransform=r.sdpTransform),this._negotiator.startConnection(xi(xi({},this.options._payload),{_stream:t}));var a=this.provider._getMessages(this.connectionId);try{for(var o=Cc(a),c=o.next();!c.done;c=o.next()){var l=c.value;this.handleMessage(l)}}catch(h){i={error:h}}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,n.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e}(Mn.BaseConnection),Tn={};Qe(Tn,"DataConnection",()=>No,n=>No=n);var Io={};Qe(Io,"EncodingQueue",()=>Uo,n=>Uo=n);var Pc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),Uo=function(n){Pc(e,n);function e(){var t=n.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(r){t._processing=!1,r.target&&t.emit("done",r.target.result),t.doNextTask()},t.fileReader.onerror=function(r){O.default.error("EncodingQueue error:",r),t._processing=!1,t.destroy(),t.emit("error",r)},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}(dr.EventEmitter),Ec=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),kc=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},No=function(n){Ec(e,n);function e(t,r,i){var s=n.call(this,t,r,i)||this;return s.stringify=JSON.stringify,s.parse=JSON.parse,s._buffer=[],s._bufferSize=0,s._buffering=!1,s._chunkedData={},s._encodingQueue=new Io.EncodingQueue,s.connectionId=s.options.connectionId||e.ID_PREFIX+F.randomToken(),s.label=s.options.label||s.connectionId,s.serialization=s.options.serialization||dt.Binary,s.reliable=!!s.options.reliable,s._encodingQueue.on("done",function(a){s._bufferedSend(a)}),s._encodingQueue.on("error",function(){O.default.error("DC#".concat(s.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),s.close()}),s._negotiator=new wn.Negotiator(s),s._negotiator.startConnection(s.options._payload||{originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return je.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;(!F.supports.binaryBlob||F.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){O.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(r){O.default.log("DC#".concat(t.connectionId," dc onmessage:"),r.data),t._handleDataMessage(r)},this.dataChannel.onclose=function(){O.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var r=this,i=t.data,s=i.constructor,a=this.serialization===dt.Binary||this.serialization===dt.BinaryUTF8,o=i;if(a){if(s===Blob){F.blobToArrayBuffer(i,function(l){var h=F.unpack(l);r.emit("data",h)});return}else if(s===ArrayBuffer)o=F.unpack(i);else if(s===String){var c=F.binaryStringToArrayBuffer(i);o=F.unpack(c)}}else this.serialization===dt.JSON&&(o=this.parse(i));if(o.__peerData){this._handleChunk(o);return}n.prototype.emit.call(this,"data",o)},e.prototype._handleChunk=function(t){var r=t.__peerData,i=this._chunkedData[r]||{data:[],count:0,total:t.total};if(i.data[t.n]=t.data,i.count++,this._chunkedData[r]=i,i.total===i.count){delete this._chunkedData[r];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,n.prototype.emit.call(this,"close"))},e.prototype.send=function(t,r){if(!this.open){n.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===dt.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===dt.Binary||this.serialization===dt.BinaryUTF8){var i=F.pack(t);if(!r&&i.size>F.chunkedMTU){this._sendChunks(i);return}F.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 r=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){r._buffering=!1,r._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(i){return O.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 r,i,s=F.chunk(t);O.default.log("DC#".concat(this.connectionId," Try to send ").concat(s.length," chunks..."));try{for(var a=kc(s),o=a.next();!o.done;o=a.next()){var c=o.value;this.send(c,!0)}}catch(l){r={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}},e.prototype.handleMessage=function(t){var r=t.payload;switch(t.type){case ae.Answer:this._negotiator.handleSDP(t.type,r.sdp);break;case ae.Candidate:this._negotiator.handleCandidate(r.candidate);break;default:O.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e}(Mn.BaseConnection),Do={};Qe(Do,"API",()=>Vo,n=>Vo=n);var Fo=function(n,e,t,r){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(h){try{l(r.next(h))}catch(u){a(u)}}function c(h){try{l(r.throw(h))}catch(u){a(u)}}function l(h){h.done?s(h.value):i(h.value).then(o,c)}l((r=r.apply(n,e||[])).next())})},Lo=function(n,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,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(h){return c([l,h])}}function c(l){if(r)throw new TypeError("Generator is already executing.");for(;t;)try{if(r=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(n,t)}catch(h){l=[6,h],i=0}finally{r=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},Vo=function(){function n(e){this._options=e}return n.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",r=this._options,i=r.host,s=r.port,a=r.path,o=r.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",xn.version),fetch(c.href,{referrerPolicy:this._options.referrerPolicy})},n.prototype.retrieveId=function(){return Fo(this,void 0,Promise,function(){var e,t,r;return Lo(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(),O.default.error("Error retrieving ID",t),r="",this._options.path==="/"&&this._options.host!==F.CLOUD_HOST&&(r=" 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."+r);case 3:return[2]}})})},n.prototype.listAllPeers=function(){return Fo(this,void 0,Promise,function(){var e,t,r;return Lo(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===F.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 r=i.sent(),O.default.error("Error retrieving list peers",r),new Error("Could not get list peers from the server."+r);case 3:return[2]}})})},n}(),Ac=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),fr=function(){return fr=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},fr.apply(this,arguments)},mr=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Rc=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var r=t.call(n),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(a)throw a.error}}return s},Cn=function(n){Ac(e,n);function e(t,r){var i=n.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?r=t:t&&(s=t.toString()),r=fr({debug:0,host:F.CLOUD_HOST,port:F.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:F.randomToken(),config:F.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},r),i._options=r,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!==F.CLOUD_HOST?i._options.secure=F.isSecure():i._options.host==F.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&O.default.setLogFunction(i._options.logFunction),O.default.logLevel=i._options.debug||0,i._api=new Do.API(r),i._socket=i._createServerConnection(),!F.supports.audioVideo&&!F.supports.data?(i._delayedAbort(K.BrowserIncompatible,"The current browser does not support WebRTC"),i):s&&!F.validateId(s)?(i._delayedAbort(K.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(K.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,r,i=Object.create(null);try{for(var s=mr(this._connections),a=s.next();!a.done;a=s.next()){var o=Rc(a.value,2),c=o[0],l=o[1];i[c]=l}}catch(h){t={error:h}}finally{try{a&&!a.done&&(r=s.return)&&r.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,r=new Ao.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return r.on(pt.Message,function(i){t._handleMessage(i)}),r.on(pt.Error,function(i){t._abort(K.SocketError,i)}),r.on(pt.Disconnected,function(){t.disconnected||(t.emitError(K.Network,"Lost connection to server."),t.disconnect())}),r.on(pt.Close,function(){t.disconnected||t._abort(K.SocketClosed,"Underlying socket is already closed.")}),r},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var r,i,s=t.type,a=t.payload,o=t.src;switch(s){case ae.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case ae.Error:this._abort(K.ServerError,a.msg);break;case ae.IdTaken:this._abort(K.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case ae.InvalidKey:this._abort(K.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case ae.Leave:O.default.log("Received leave message from ".concat(o)),this._cleanupPeer(o),this._connections.delete(o);break;case ae.Expire:this.emitError(K.PeerUnavailable,"Could not connect to peer ".concat(o));break;case ae.Offer:var y=a.connectionId,g=this.getConnection(o,y);if(g&&(g.close(),O.default.warn("Offer received for existing Connection ID:".concat(y))),a.type===je.Media){var c=new Sn.MediaConnection(o,this,{connectionId:y,_payload:a,metadata:a.metadata});g=c,this._addConnection(o,g),this.emit("call",c)}else if(a.type===je.Data){var l=new Tn.DataConnection(o,this,{connectionId:y,_payload:a,metadata:a.metadata,label:a.label,serialization:a.serialization,reliable:a.reliable});g=l,this._addConnection(o,g),this.emit("connection",l)}else{O.default.warn("Received malformed connection type:".concat(a.type));return}var h=this._getMessages(y);try{for(var u=mr(h),d=u.next();!d.done;d=u.next()){var p=d.value;g.handleMessage(p)}}catch(f){r={error:f}}finally{try{d&&!d.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}break;default:if(!a){O.default.warn("You received a malformed message from ".concat(o," of type ").concat(s));return}var y=a.connectionId,g=this.getConnection(o,y);g&&g.peerConnection?g.handleMessage(t):y?this._storeMessage(y,t):O.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,r){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(r)},e.prototype._getMessages=function(t){var r=this._lostMessages.get(t);return r?(this._lostMessages.delete(t),r):[]},e.prototype.connect=function(t,r){if(r===void 0&&(r={}),this.disconnected){O.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(K.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var i=new Tn.DataConnection(t,this,r);return this._addConnection(t,i),i},e.prototype.call=function(t,r,i){if(i===void 0&&(i={}),this.disconnected){O.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(K.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!r){O.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var s=new Sn.MediaConnection(t,this,fr(fr({},i),{_stream:r}));return this._addConnection(t,s),s},e.prototype._addConnection=function(t,r){O.default.log("add connection ".concat(r.type,":").concat(r.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(r)},e.prototype._removeConnection=function(t){var r=this._connections.get(t.peer);if(r){var i=r.indexOf(t);i!==-1&&r.splice(i,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,r){var i,s,a=this._connections.get(t);if(!a)return null;try{for(var o=mr(a),c=o.next();!c.done;c=o.next()){var l=c.value;if(l.connectionId===r)return l}}catch(h){i={error:h}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}return null},e.prototype._delayedAbort=function(t,r){var i=this;setTimeout(function(){i._abort(t,r)},0)},e.prototype._abort=function(t,r){O.default.error("Aborting!"),this.emitError(t,r),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,r){O.default.error("Error:",r);var i;typeof r=="string"?i=new Error(r):i=r,i.type=t,this.emit("error",i)},e.prototype.destroy=function(){this.destroyed||(O.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,r;try{for(var i=mr(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&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var r,i,s=this._connections.get(t);if(s)try{for(var a=mr(s),o=a.next();!o.done;o=a.next()){var c=o.value;c.close()}}catch(l){r={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;O.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)O.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)O.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 r=this;t===void 0&&(t=function(i){}),this._api.listAllPeers().then(function(i){return t(i)}).catch(function(i){return r._abort(K.ServerError,i)})},e.DEFAULT_KEY="peerjs",e}(dr.EventEmitter),jo=Po.Peer;const Oc=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return Cn},default:jo,util:F},Symbol.toStringTag,{value:"Module"})),zc=/^(?:[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 Bc(n){return typeof n=="string"&&zc.test(n)}const ce=[];for(let n=0;n<256;++n)ce.push((n+256).toString(16).slice(1));function Ic(n,e=0){return ce[n[e+0]]+ce[n[e+1]]+ce[n[e+2]]+ce[n[e+3]]+"-"+ce[n[e+4]]+ce[n[e+5]]+"-"+ce[n[e+6]]+ce[n[e+7]]+"-"+ce[n[e+8]]+ce[n[e+9]]+"-"+ce[n[e+10]]+ce[n[e+11]]+ce[n[e+12]]+ce[n[e+13]]+ce[n[e+14]]+ce[n[e+15]]}function Uc(n){if(!Bc(n))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.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 Nc(n){n=unescape(encodeURIComponent(n));const e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}const Dc="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Fc="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function Lc(n,e,t){function r(i,s,a,o){var c;if(typeof i=="string"&&(i=Nc(i)),typeof s=="string"&&(s=Uc(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 h=0;h<16;++h)a[o+h]=l[h];return a}return Ic(l)}try{r.name=n}catch{}return r.DNS=Dc,r.URL=Fc,r}function Vc(n,e,t,r){switch(n){case 0:return e&t^~e&r;case 1:return e^t^r;case 2:return e&t^e&r^t&r;case 3:return e^t^r}}function Pn(n,e){return n<<e|n>>>32-e}function jc(n){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof n=="string"){const a=unescape(encodeURIComponent(n));n=[];for(let o=0;o<a.length;++o)n.push(a.charCodeAt(o))}else Array.isArray(n)||(n=Array.prototype.slice.call(n));n.push(128);const r=n.length/4+2,i=Math.ceil(r/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]=n[a*64+c*4]<<24|n[a*64+c*4+1]<<16|n[a*64+c*4+2]<<8|n[a*64+c*4+3];s[a]=o}s[i-1][14]=(n.length-1)*8/Math.pow(2,32),s[i-1][14]=Math.floor(s[i-1][14]),s[i-1][15]=(n.length-1)*8&4294967295;for(let a=0;a<i;++a){const o=new Uint32Array(80);for(let p=0;p<16;++p)o[p]=s[a][p];for(let p=16;p<80;++p)o[p]=Pn(o[p-3]^o[p-8]^o[p-14]^o[p-16],1);let c=t[0],l=t[1],h=t[2],u=t[3],d=t[4];for(let p=0;p<80;++p){const y=Math.floor(p/20),g=Pn(c,5)+Vc(y,l,h,u)+d+e[y]+o[p]>>>0;d=u,u=h,h=Pn(l,30)>>>0,l=c,c=g}t[0]=t[0]+c>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+h>>>0,t[3]=t[3]+u>>>0,t[4]=t[4]+d>>>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 Jc=Lc("v5",80,jc);var Jo={exports:{}},Go={exports:{}},Wo;function Gc(){return Wo||(Wo=1,function(){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e={rotl:function(t,r){return t<<r|t>>>32-r},rotr:function(t,r){return t<<32-r|t>>>r},endian:function(t){if(t.constructor==Number)return e.rotl(t,8)&16711935|e.rotl(t,24)&4278255360;for(var r=0;r<t.length;r++)t[r]=e.endian(t[r]);return t},randomBytes:function(t){for(var r=[];t>0;t--)r.push(Math.floor(Math.random()*256));return r},bytesToWords:function(t){for(var r=[],i=0,s=0;i<t.length;i++,s+=8)r[s>>>5]|=t[i]<<24-s%32;return r},wordsToBytes:function(t){for(var r=[],i=0;i<t.length*32;i+=8)r.push(t[i>>>5]>>>24-i%32&255);return r},bytesToHex:function(t){for(var r=[],i=0;i<t.length;i++)r.push((t[i]>>>4).toString(16)),r.push((t[i]&15).toString(16));return r.join("")},hexToBytes:function(t){for(var r=[],i=0;i<t.length;i+=2)r.push(parseInt(t.substr(i,2),16));return r},bytesToBase64:function(t){for(var r=[],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?r.push(n.charAt(s>>>6*(3-a)&63)):r.push("=");return r.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/ig,"");for(var r=[],i=0,s=0;i<t.length;s=++i%4)s!=0&&r.push((n.indexOf(t.charAt(i-1))&Math.pow(2,-2*s+8)-1)<<s*2|n.indexOf(t.charAt(i))>>>6-s*2);return r}};Go.exports=e}()),Go.exports}var En,Xo;function qo(){if(Xo)return En;Xo=1;var n={utf8:{stringToBytes:function(e){return n.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(n.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],r=0;r<e.length;r++)t.push(e.charCodeAt(r)&255);return t},bytesToString:function(e){for(var t=[],r=0;r<e.length;r++)t.push(String.fromCharCode(e[r]));return t.join("")}}};return En=n,En}/*!
|
|
78
|
+
isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},n}()),Ro={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"},Pc=function(){function n(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=Ro,this.browser=pr.getBrowser(),this.browserVersion=pr.getVersion(),this.supports=function(){var e={browser:pr.isBrowserSupported(),webRTC:pr.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(Ro),e.audioVideo=!0;var r=void 0;try{r=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!r.ordered;try{r.binaryType="blob",e.binaryBlob=!pr.isIOS}catch{}}catch{}finally{r&&r.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=Ns.pack,this.unpack=Ns.unpack,this._dataCount=1}return n.prototype.noop=function(){},n.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},n.prototype.chunk=function(e){for(var t=[],r=e.size,i=Math.ceil(r/F.chunkedMTU),s=0,a=0;a<r;){var o=Math.min(r,a+F.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},n.prototype.blobToArrayBuffer=function(e,t){var r=new FileReader;return r.onload=function(i){i.target&&t(i.target.result)},r.readAsArrayBuffer(e),r},n.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),r=0;r<e.length;r++)t[r]=e.charCodeAt(r)&255;return t.buffer},n.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},n.prototype.isSecure=function(){return location.protocol==="https:"},n}(),F=new Pc,Ao={};Qe(Ao,"Peer",()=>En,n=>En=n);var fr={},Ec=Object.prototype.hasOwnProperty,ve="~";function mr(){}Object.create&&(mr.prototype=Object.create(null),new mr().__proto__||(ve=!1));function kc(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function Oo(n,e,t,r,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new kc(t,r||n,i),a=ve?ve+e:e;return n._events[a]?n._events[a].fn?n._events[a]=[n._events[a],s]:n._events[a].push(s):(n._events[a]=s,n._eventsCount++),n}function bi(n,e){--n._eventsCount===0?n._events=new mr:delete n._events[e]}function de(){this._events=new mr,this._eventsCount=0}de.prototype.eventNames=function(){var n=[],e,t;if(this._eventsCount===0)return n;for(t in e=this._events)Ec.call(e,t)&&n.push(ve?t.slice(1):t);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},de.prototype.listeners=function(n){var e=ve?ve+n:n,t=this._events[e];if(!t)return[];if(t.fn)return[t.fn];for(var r=0,i=t.length,s=new Array(i);r<i;r++)s[r]=t[r].fn;return s},de.prototype.listenerCount=function(n){var e=ve?ve+n:n,t=this._events[e];return t?t.fn?1:t.length:0},de.prototype.emit=function(n,e,t,r,i,s){var a=ve?ve+n:n;if(!this._events[a])return!1;var o=this._events[a],c=arguments.length,l,h;if(o.fn){switch(o.once&&this.removeListener(n,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,r),!0;case 5:return o.fn.call(o.context,e,t,r,i),!0;case 6:return o.fn.call(o.context,e,t,r,i,s),!0}for(h=1,l=new Array(c-1);h<c;h++)l[h-1]=arguments[h];o.fn.apply(o.context,l)}else{var u=o.length,d;for(h=0;h<u;h++)switch(o[h].once&&this.removeListener(n,o[h].fn,void 0,!0),c){case 1:o[h].fn.call(o[h].context);break;case 2:o[h].fn.call(o[h].context,e);break;case 3:o[h].fn.call(o[h].context,e,t);break;case 4:o[h].fn.call(o[h].context,e,t,r);break;default:if(!l)for(d=1,l=new Array(c-1);d<c;d++)l[d-1]=arguments[d];o[h].fn.apply(o[h].context,l)}}return!0},de.prototype.on=function(n,e,t){return Oo(this,n,e,t,!1)},de.prototype.once=function(n,e,t){return Oo(this,n,e,t,!0)},de.prototype.removeListener=function(n,e,t,r){var i=ve?ve+n:n;if(!this._events[i])return this;if(!e)return bi(this,i),this;var s=this._events[i];if(s.fn)s.fn===e&&(!r||s.once)&&(!t||s.context===t)&&bi(this,i);else{for(var a=0,o=[],c=s.length;a<c;a++)(s[a].fn!==e||r&&!s[a].once||t&&s[a].context!==t)&&o.push(s[a]);o.length?this._events[i]=o.length===1?o[0]:o:bi(this,i)}return this},de.prototype.removeAllListeners=function(n){var e;return n?(e=ve?ve+n:n,this._events[e]&&bi(this,e)):(this._events=new mr,this._eventsCount=0),this},de.prototype.off=de.prototype.removeListener,de.prototype.addListener=de.prototype.on,de.prefixed=ve,de.EventEmitter=de,fr=de;var O={};Qe(O,"LogLevel",()=>Se,n=>Se=n),Qe(O,"default",()=>zo,n=>zo=n);var kt=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var r=t.call(n),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(a)throw a.error}}return s},Rt=function(n,e,t){if(t||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return n.concat(s||Array.prototype.slice.call(e))},Rc="PeerJS: ",Se;(function(n){n[n.Disabled=0]="Disabled",n[n.Errors=1]="Errors",n[n.Warnings=2]="Warnings",n[n.All=3]="All"})(Se||(Se={}));var Ac=function(){function n(){this._logLevel=Se.Disabled}return Object.defineProperty(n.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),n.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=Se.All&&this._print.apply(this,Rt([Se.All],kt(e),!1))},n.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=Se.Warnings&&this._print.apply(this,Rt([Se.Warnings],kt(e),!1))},n.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=Se.Errors&&this._print.apply(this,Rt([Se.Errors],kt(e),!1))},n.prototype.setLogFunction=function(e){this._print=e},n.prototype._print=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var i=Rt([Rc],kt(t),!1);for(var s in i)i[s]instanceof Error&&(i[s]="("+i[s].name+") "+i[s].message);e>=Se.All?console.log.apply(console,Rt([],kt(i),!1)):e>=Se.Warnings?console.warn.apply(console,Rt(["WARNING"],kt(i),!1)):e>=Se.Errors&&console.error.apply(console,Rt(["ERROR"],kt(i),!1))},n}(),zo=new Ac,Bo={};Qe(Bo,"Socket",()=>Io,n=>Io=n);var Je;(function(n){n.Data="data",n.Media="media"})(Je||(Je={}));var Q;(function(n){n.BrowserIncompatible="browser-incompatible",n.Disconnected="disconnected",n.InvalidID="invalid-id",n.InvalidKey="invalid-key",n.Network="network",n.PeerUnavailable="peer-unavailable",n.SslUnavailable="ssl-unavailable",n.ServerError="server-error",n.SocketError="socket-error",n.SocketClosed="socket-closed",n.UnavailableID="unavailable-id",n.WebRTC="webrtc"})(Q||(Q={}));var pt;(function(n){n.Binary="binary",n.BinaryUTF8="binary-utf8",n.JSON="json"})(pt||(pt={}));var ft;(function(n){n.Message="message",n.Disconnected="disconnected",n.Error="error",n.Close="close"})(ft||(ft={}));var ae;(function(n){n.Heartbeat="HEARTBEAT",n.Candidate="CANDIDATE",n.Offer="OFFER",n.Answer="ANSWER",n.Open="OPEN",n.Error="ERROR",n.IdTaken="ID-TAKEN",n.InvalidKey="INVALID-KEY",n.Leave="LEAVE",n.Expire="EXPIRE"})(ae||(ae={}));var wn={};wn=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 Oc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),zc=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var r=t.call(n),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(a)throw a.error}}return s},Bc=function(n,e,t){if(t||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return n.concat(s||Array.prototype.slice.call(e))},Ic=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Io=function(n){Oc(e,n);function e(t,r,i,s,a,o){o===void 0&&(o=5e3);var c=n.call(this)||this;c.pingInterval=o,c._disconnected=!0,c._messagesQueue=[];var l=t?"wss://":"ws://";return c._baseUrl=l+r+":"+i+s+"peerjs?key="+a,c}return e.prototype.start=function(t,r){var i=this;this._id=t;var s="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(r);this._socket||!this._disconnected||(this._socket=new WebSocket(s+"&version="+wn.version),this._disconnected=!1,this._socket.onmessage=function(a){var o;try{o=JSON.parse(a.data),O.default.log("Server message received:",o)}catch{O.default.log("Invalid server message",a.data);return}i.emit(ft.Message,o)},this._socket.onclose=function(a){i._disconnected||(O.default.log("Socket closed.",a),i._cleanup(),i._disconnected=!0,i.emit(ft.Disconnected))},this._socket.onopen=function(){i._disconnected||(i._sendQueuedMessages(),O.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()){O.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:ae.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,r,i=Bc([],zc(this._messagesQueue),!1);this._messagesQueue=[];try{for(var s=Ic(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&&(r=s.return)&&r.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(ft.Error,"Invalid message");return}if(this._wsOpen()){var r=JSON.stringify(t);this._socket.send(r)}}},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}(fr.EventEmitter),Mn={};Qe(Mn,"MediaConnection",()=>Do,n=>Do=n);var Tn={};Qe(Tn,"Negotiator",()=>No,n=>No=n);var _i=function(){return _i=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},_i.apply(this,arguments)},xi=function(n,e,t,r){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(h){try{l(r.next(h))}catch(u){a(u)}}function c(h){try{l(r.throw(h))}catch(u){a(u)}}function l(h){h.done?s(h.value):i(h.value).then(o,c)}l((r=r.apply(n,e||[])).next())})},Si=function(n,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,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(h){return c([l,h])}}function c(l){if(r)throw new TypeError("Generator is already executing.");for(;t;)try{if(r=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(n,t)}catch(h){l=[6,h],i=0}finally{r=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},No=function(){function n(e){this.connection=e}return n.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===Je.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===Je.Data){var r=this.connection,i={ordered:!!e.reliable},s=t.createDataChannel(r.label,i);r.initialize(s)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},n.prototype._startPeerConnection=function(){O.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},n.prototype._setupListeners=function(e){var t=this,r=this.connection.peer,i=this.connection.connectionId,s=this.connection.type,a=this.connection.provider;O.default.log("Listening for ICE candidates."),e.onicecandidate=function(o){!o.candidate||!o.candidate.candidate||(O.default.log("Received ICE candidates for ".concat(r,":"),o.candidate),a.socket.send({type:ae.Candidate,payload:{candidate:o.candidate,type:s,connectionId:i},dst:r}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":O.default.log("iceConnectionState is failed, closing connections to "+r),t.connection.emit("error",new Error("Negotiation of connection to "+r+" failed.")),t.connection.close();break;case"closed":O.default.log("iceConnectionState is closed, closing connections to "+r),t.connection.emit("error",new Error("Connection to "+r+" closed.")),t.connection.close();break;case"disconnected":O.default.log("iceConnectionState changed to disconnected on the connection with "+r);break;case"completed":e.onicecandidate=F.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},O.default.log("Listening for data channel"),e.ondatachannel=function(o){O.default.log("Received data channel");var c=o.channel,l=a.getConnection(r,i);l.initialize(c)},O.default.log("Listening for remote stream"),e.ontrack=function(o){O.default.log("Received remote stream");var c=o.streams[0],l=a.getConnection(r,i);if(l.type===Je.Media){var h=l;t._addStreamToMediaConnection(c,h)}}},n.prototype.cleanup=function(){O.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",r=!1;if(this.connection.type===Je.Data){var i=this.connection,s=i.dataChannel;s&&(r=!!s.readyState&&s.readyState!=="closed")}(t||r)&&e.close()}},n.prototype._makeOffer=function(){return xi(this,void 0,Promise,function(){var e,t,r,i,s,a,o;return Si(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:r=c.sent(),O.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(r.sdp=this.connection.options.sdpTransform(r.sdp)||r.sdp),c.label=3;case 3:return c.trys.push([3,5,,6]),[4,e.setLocalDescription(r)];case 4:return c.sent(),O.default.log("Set localDescription:",r,"for:".concat(this.connection.peer)),i={sdp:r,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:F.browser},this.connection.type===Je.Data&&(s=this.connection,i=_i(_i({},i),{label:s.label,reliable:s.reliable,serialization:s.serialization})),t.socket.send({type:ae.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(Q.WebRTC,a),O.default.log("Failed to setLocalDescription, ",a)),[3,6];case 6:return[3,8];case 7:return o=c.sent(),t.emitError(Q.WebRTC,o),O.default.log("Failed to createOffer, ",o),[3,8];case 8:return[2]}})})},n.prototype._makeAnswer=function(){return xi(this,void 0,Promise,function(){var e,t,r,i,s;return Si(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:r=a.sent(),O.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(r.sdp=this.connection.options.sdpTransform(r.sdp)||r.sdp),a.label=3;case 3:return a.trys.push([3,5,,6]),[4,e.setLocalDescription(r)];case 4:return a.sent(),O.default.log("Set localDescription:",r,"for:".concat(this.connection.peer)),t.socket.send({type:ae.Answer,payload:{sdp:r,type:this.connection.type,connectionId:this.connection.connectionId,browser:F.browser},dst:this.connection.peer}),[3,6];case 5:return i=a.sent(),t.emitError(Q.WebRTC,i),O.default.log("Failed to setLocalDescription, ",i),[3,6];case 6:return[3,8];case 7:return s=a.sent(),t.emitError(Q.WebRTC,s),O.default.log("Failed to create answer, ",s),[3,8];case 8:return[2]}})})},n.prototype.handleSDP=function(e,t){return xi(this,void 0,Promise,function(){var r,i,s,a;return Si(this,function(o){switch(o.label){case 0:t=new RTCSessionDescription(t),r=this.connection.peerConnection,i=this.connection.provider,O.default.log("Setting remote description",t),s=this,o.label=1;case 1:return o.trys.push([1,5,,6]),[4,r.setRemoteDescription(t)];case 2:return o.sent(),O.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(Q.WebRTC,a),O.default.log("Failed to setRemoteDescription, ",a),[3,6];case 6:return[2]}})})},n.prototype.handleCandidate=function(e){return xi(this,void 0,Promise,function(){var t,r,i,s,a,o;return Si(this,function(c){switch(c.label){case 0:O.default.log("handleCandidate:",e),t=e.candidate,r=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:r,candidate:t}))];case 2:return c.sent(),O.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return o=c.sent(),a.emitError(Q.WebRTC,o),O.default.log("Failed to handleCandidate, ",o),[3,4];case 4:return[2]}})})},n.prototype._addTracksToConnection=function(e,t){if(O.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return O.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(r){t.addTrack(r,e)})},n.prototype._addStreamToMediaConnection=function(e,t){O.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},n}(),Cn={};Qe(Cn,"BaseConnection",()=>Uo,n=>Uo=n);var Nc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),Uo=function(n){Nc(e,n);function e(t,r,i){var s=n.call(this)||this;return s.peer=t,s.provider=r,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}(fr.EventEmitter),Uc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),wi=function(){return wi=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},wi.apply(this,arguments)},Dc=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Do=function(n){Uc(e,n);function e(t,r,i){var s=n.call(this,t,r,i)||this;return s._localStream=s.options._stream,s.connectionId=s.options.connectionId||e.ID_PREFIX+F.randomToken(),s._negotiator=new Tn.Negotiator(s),s._localStream&&s._negotiator.startConnection({_stream:s._localStream,originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return Je.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){O.default.log("Receiving stream",t),this._remoteStream=t,n.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var r=t.type,i=t.payload;switch(t.type){case ae.Answer:this._negotiator.handleSDP(r,i.sdp),this._open=!0;break;case ae.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:O.default.warn("Unrecognized message type:".concat(r," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,r){var i,s;if(r===void 0&&(r={}),this._localStream){O.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,r&&r.sdpTransform&&(this.options.sdpTransform=r.sdpTransform),this._negotiator.startConnection(wi(wi({},this.options._payload),{_stream:t}));var a=this.provider._getMessages(this.connectionId);try{for(var o=Dc(a),c=o.next();!c.done;c=o.next()){var l=c.value;this.handleMessage(l)}}catch(h){i={error:h}}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,n.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e}(Cn.BaseConnection),Pn={};Qe(Pn,"DataConnection",()=>Vo,n=>Vo=n);var Fo={};Qe(Fo,"EncodingQueue",()=>Lo,n=>Lo=n);var Fc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),Lo=function(n){Fc(e,n);function e(){var t=n.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(r){t._processing=!1,r.target&&t.emit("done",r.target.result),t.doNextTask()},t.fileReader.onerror=function(r){O.default.error("EncodingQueue error:",r),t._processing=!1,t.destroy(),t.emit("error",r)},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}(fr.EventEmitter),Lc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),Vc=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Vo=function(n){Lc(e,n);function e(t,r,i){var s=n.call(this,t,r,i)||this;return s.stringify=JSON.stringify,s.parse=JSON.parse,s._buffer=[],s._bufferSize=0,s._buffering=!1,s._chunkedData={},s._encodingQueue=new Fo.EncodingQueue,s.connectionId=s.options.connectionId||e.ID_PREFIX+F.randomToken(),s.label=s.options.label||s.connectionId,s.serialization=s.options.serialization||pt.Binary,s.reliable=!!s.options.reliable,s._encodingQueue.on("done",function(a){s._bufferedSend(a)}),s._encodingQueue.on("error",function(){O.default.error("DC#".concat(s.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),s.close()}),s._negotiator=new Tn.Negotiator(s),s._negotiator.startConnection(s.options._payload||{originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return Je.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;(!F.supports.binaryBlob||F.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){O.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(r){O.default.log("DC#".concat(t.connectionId," dc onmessage:"),r.data),t._handleDataMessage(r)},this.dataChannel.onclose=function(){O.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var r=this,i=t.data,s=i.constructor,a=this.serialization===pt.Binary||this.serialization===pt.BinaryUTF8,o=i;if(a){if(s===Blob){F.blobToArrayBuffer(i,function(l){var h=F.unpack(l);r.emit("data",h)});return}else if(s===ArrayBuffer)o=F.unpack(i);else if(s===String){var c=F.binaryStringToArrayBuffer(i);o=F.unpack(c)}}else this.serialization===pt.JSON&&(o=this.parse(i));if(o.__peerData){this._handleChunk(o);return}n.prototype.emit.call(this,"data",o)},e.prototype._handleChunk=function(t){var r=t.__peerData,i=this._chunkedData[r]||{data:[],count:0,total:t.total};if(i.data[t.n]=t.data,i.count++,this._chunkedData[r]=i,i.total===i.count){delete this._chunkedData[r];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,n.prototype.emit.call(this,"close"))},e.prototype.send=function(t,r){if(!this.open){n.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===pt.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===pt.Binary||this.serialization===pt.BinaryUTF8){var i=F.pack(t);if(!r&&i.size>F.chunkedMTU){this._sendChunks(i);return}F.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 r=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){r._buffering=!1,r._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(i){return O.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 r,i,s=F.chunk(t);O.default.log("DC#".concat(this.connectionId," Try to send ").concat(s.length," chunks..."));try{for(var a=Vc(s),o=a.next();!o.done;o=a.next()){var c=o.value;this.send(c,!0)}}catch(l){r={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}},e.prototype.handleMessage=function(t){var r=t.payload;switch(t.type){case ae.Answer:this._negotiator.handleSDP(t.type,r.sdp);break;case ae.Candidate:this._negotiator.handleCandidate(r.candidate);break;default:O.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e}(Cn.BaseConnection),jo={};Qe(jo,"API",()=>Wo,n=>Wo=n);var Jo=function(n,e,t,r){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(h){try{l(r.next(h))}catch(u){a(u)}}function c(h){try{l(r.throw(h))}catch(u){a(u)}}function l(h){h.done?s(h.value):i(h.value).then(o,c)}l((r=r.apply(n,e||[])).next())})},Go=function(n,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,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(h){return c([l,h])}}function c(l){if(r)throw new TypeError("Generator is already executing.");for(;t;)try{if(r=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(n,t)}catch(h){l=[6,h],i=0}finally{r=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},Wo=function(){function n(e){this._options=e}return n.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",r=this._options,i=r.host,s=r.port,a=r.path,o=r.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",wn.version),fetch(c.href,{referrerPolicy:this._options.referrerPolicy})},n.prototype.retrieveId=function(){return Jo(this,void 0,Promise,function(){var e,t,r;return Go(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(),O.default.error("Error retrieving ID",t),r="",this._options.path==="/"&&this._options.host!==F.CLOUD_HOST&&(r=" 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."+r);case 3:return[2]}})})},n.prototype.listAllPeers=function(){return Jo(this,void 0,Promise,function(){var e,t,r;return Go(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===F.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 r=i.sent(),O.default.error("Error retrieving list peers",r),new Error("Could not get list peers from the server."+r);case 3:return[2]}})})},n}(),jc=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},n(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");n(e,t);function r(){this.constructor=e}e.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}}(),yr=function(){return yr=Object.assign||function(n){for(var e,t=1,r=arguments.length;t<r;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},yr.apply(this,arguments)},gr=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],r=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&r>=n.length&&(n=void 0),{value:n&&n[r++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Jc=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var r=t.call(n),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(a)throw a.error}}return s},En=function(n){jc(e,n);function e(t,r){var i=n.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?r=t:t&&(s=t.toString()),r=yr({debug:0,host:F.CLOUD_HOST,port:F.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:F.randomToken(),config:F.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},r),i._options=r,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!==F.CLOUD_HOST?i._options.secure=F.isSecure():i._options.host==F.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&O.default.setLogFunction(i._options.logFunction),O.default.logLevel=i._options.debug||0,i._api=new jo.API(r),i._socket=i._createServerConnection(),!F.supports.audioVideo&&!F.supports.data?(i._delayedAbort(Q.BrowserIncompatible,"The current browser does not support WebRTC"),i):s&&!F.validateId(s)?(i._delayedAbort(Q.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(Q.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,r,i=Object.create(null);try{for(var s=gr(this._connections),a=s.next();!a.done;a=s.next()){var o=Jc(a.value,2),c=o[0],l=o[1];i[c]=l}}catch(h){t={error:h}}finally{try{a&&!a.done&&(r=s.return)&&r.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,r=new Bo.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return r.on(ft.Message,function(i){t._handleMessage(i)}),r.on(ft.Error,function(i){t._abort(Q.SocketError,i)}),r.on(ft.Disconnected,function(){t.disconnected||(t.emitError(Q.Network,"Lost connection to server."),t.disconnect())}),r.on(ft.Close,function(){t.disconnected||t._abort(Q.SocketClosed,"Underlying socket is already closed.")}),r},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var r,i,s=t.type,a=t.payload,o=t.src;switch(s){case ae.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case ae.Error:this._abort(Q.ServerError,a.msg);break;case ae.IdTaken:this._abort(Q.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case ae.InvalidKey:this._abort(Q.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case ae.Leave:O.default.log("Received leave message from ".concat(o)),this._cleanupPeer(o),this._connections.delete(o);break;case ae.Expire:this.emitError(Q.PeerUnavailable,"Could not connect to peer ".concat(o));break;case ae.Offer:var y=a.connectionId,g=this.getConnection(o,y);if(g&&(g.close(),O.default.warn("Offer received for existing Connection ID:".concat(y))),a.type===Je.Media){var c=new Mn.MediaConnection(o,this,{connectionId:y,_payload:a,metadata:a.metadata});g=c,this._addConnection(o,g),this.emit("call",c)}else if(a.type===Je.Data){var l=new Pn.DataConnection(o,this,{connectionId:y,_payload:a,metadata:a.metadata,label:a.label,serialization:a.serialization,reliable:a.reliable});g=l,this._addConnection(o,g),this.emit("connection",l)}else{O.default.warn("Received malformed connection type:".concat(a.type));return}var h=this._getMessages(y);try{for(var u=gr(h),d=u.next();!d.done;d=u.next()){var p=d.value;g.handleMessage(p)}}catch(f){r={error:f}}finally{try{d&&!d.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}break;default:if(!a){O.default.warn("You received a malformed message from ".concat(o," of type ").concat(s));return}var y=a.connectionId,g=this.getConnection(o,y);g&&g.peerConnection?g.handleMessage(t):y?this._storeMessage(y,t):O.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,r){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(r)},e.prototype._getMessages=function(t){var r=this._lostMessages.get(t);return r?(this._lostMessages.delete(t),r):[]},e.prototype.connect=function(t,r){if(r===void 0&&(r={}),this.disconnected){O.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(Q.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var i=new Pn.DataConnection(t,this,r);return this._addConnection(t,i),i},e.prototype.call=function(t,r,i){if(i===void 0&&(i={}),this.disconnected){O.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(Q.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!r){O.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var s=new Mn.MediaConnection(t,this,yr(yr({},i),{_stream:r}));return this._addConnection(t,s),s},e.prototype._addConnection=function(t,r){O.default.log("add connection ".concat(r.type,":").concat(r.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(r)},e.prototype._removeConnection=function(t){var r=this._connections.get(t.peer);if(r){var i=r.indexOf(t);i!==-1&&r.splice(i,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,r){var i,s,a=this._connections.get(t);if(!a)return null;try{for(var o=gr(a),c=o.next();!c.done;c=o.next()){var l=c.value;if(l.connectionId===r)return l}}catch(h){i={error:h}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}return null},e.prototype._delayedAbort=function(t,r){var i=this;setTimeout(function(){i._abort(t,r)},0)},e.prototype._abort=function(t,r){O.default.error("Aborting!"),this.emitError(t,r),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,r){O.default.error("Error:",r);var i;typeof r=="string"?i=new Error(r):i=r,i.type=t,this.emit("error",i)},e.prototype.destroy=function(){this.destroyed||(O.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,r;try{for(var i=gr(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&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var r,i,s=this._connections.get(t);if(s)try{for(var a=gr(s),o=a.next();!o.done;o=a.next()){var c=o.value;c.close()}}catch(l){r={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;O.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)O.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)O.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 r=this;t===void 0&&(t=function(i){}),this._api.listAllPeers().then(function(i){return t(i)}).catch(function(i){return r._abort(Q.ServerError,i)})},e.DEFAULT_KEY="peerjs",e}(fr.EventEmitter),Ho=Ao.Peer;const Gc=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return En},default:Ho,util:F},Symbol.toStringTag,{value:"Module"})),Wc=/^(?:[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 Hc(n){return typeof n=="string"&&Wc.test(n)}const ce=[];for(let n=0;n<256;++n)ce.push((n+256).toString(16).slice(1));function Xc(n,e=0){return ce[n[e+0]]+ce[n[e+1]]+ce[n[e+2]]+ce[n[e+3]]+"-"+ce[n[e+4]]+ce[n[e+5]]+"-"+ce[n[e+6]]+ce[n[e+7]]+"-"+ce[n[e+8]]+ce[n[e+9]]+"-"+ce[n[e+10]]+ce[n[e+11]]+ce[n[e+12]]+ce[n[e+13]]+ce[n[e+14]]+ce[n[e+15]]}function qc(n){if(!Hc(n))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.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 Yc(n){n=unescape(encodeURIComponent(n));const e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}const Zc="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Kc="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function Qc(n,e,t){function r(i,s,a,o){var c;if(typeof i=="string"&&(i=Yc(i)),typeof s=="string"&&(s=qc(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 h=0;h<16;++h)a[o+h]=l[h];return a}return Xc(l)}try{r.name=n}catch{}return r.DNS=Zc,r.URL=Kc,r}function $c(n,e,t,r){switch(n){case 0:return e&t^~e&r;case 1:return e^t^r;case 2:return e&t^e&r^t&r;case 3:return e^t^r}}function kn(n,e){return n<<e|n>>>32-e}function el(n){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof n=="string"){const a=unescape(encodeURIComponent(n));n=[];for(let o=0;o<a.length;++o)n.push(a.charCodeAt(o))}else Array.isArray(n)||(n=Array.prototype.slice.call(n));n.push(128);const r=n.length/4+2,i=Math.ceil(r/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]=n[a*64+c*4]<<24|n[a*64+c*4+1]<<16|n[a*64+c*4+2]<<8|n[a*64+c*4+3];s[a]=o}s[i-1][14]=(n.length-1)*8/Math.pow(2,32),s[i-1][14]=Math.floor(s[i-1][14]),s[i-1][15]=(n.length-1)*8&4294967295;for(let a=0;a<i;++a){const o=new Uint32Array(80);for(let p=0;p<16;++p)o[p]=s[a][p];for(let p=16;p<80;++p)o[p]=kn(o[p-3]^o[p-8]^o[p-14]^o[p-16],1);let c=t[0],l=t[1],h=t[2],u=t[3],d=t[4];for(let p=0;p<80;++p){const y=Math.floor(p/20),g=kn(c,5)+$c(y,l,h,u)+d+e[y]+o[p]>>>0;d=u,u=h,h=kn(l,30)>>>0,l=c,c=g}t[0]=t[0]+c>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+h>>>0,t[3]=t[3]+u>>>0,t[4]=t[4]+d>>>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 tl=Qc("v5",80,el);var Xo={exports:{}},qo={exports:{}},Yo;function rl(){return Yo||(Yo=1,function(){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e={rotl:function(t,r){return t<<r|t>>>32-r},rotr:function(t,r){return t<<32-r|t>>>r},endian:function(t){if(t.constructor==Number)return e.rotl(t,8)&16711935|e.rotl(t,24)&4278255360;for(var r=0;r<t.length;r++)t[r]=e.endian(t[r]);return t},randomBytes:function(t){for(var r=[];t>0;t--)r.push(Math.floor(Math.random()*256));return r},bytesToWords:function(t){for(var r=[],i=0,s=0;i<t.length;i++,s+=8)r[s>>>5]|=t[i]<<24-s%32;return r},wordsToBytes:function(t){for(var r=[],i=0;i<t.length*32;i+=8)r.push(t[i>>>5]>>>24-i%32&255);return r},bytesToHex:function(t){for(var r=[],i=0;i<t.length;i++)r.push((t[i]>>>4).toString(16)),r.push((t[i]&15).toString(16));return r.join("")},hexToBytes:function(t){for(var r=[],i=0;i<t.length;i+=2)r.push(parseInt(t.substr(i,2),16));return r},bytesToBase64:function(t){for(var r=[],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?r.push(n.charAt(s>>>6*(3-a)&63)):r.push("=");return r.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/ig,"");for(var r=[],i=0,s=0;i<t.length;s=++i%4)s!=0&&r.push((n.indexOf(t.charAt(i-1))&Math.pow(2,-2*s+8)-1)<<s*2|n.indexOf(t.charAt(i))>>>6-s*2);return r}};qo.exports=e}()),qo.exports}var Rn,Zo;function Ko(){if(Zo)return Rn;Zo=1;var n={utf8:{stringToBytes:function(e){return n.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(n.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],r=0;r<e.length;r++)t.push(e.charCodeAt(r)&255);return t},bytesToString:function(e){for(var t=[],r=0;r<e.length;r++)t.push(String.fromCharCode(e[r]));return t.join("")}}};return Rn=n,Rn}/*!
|
|
79
79
|
* Determine if an object is a Buffer
|
|
80
80
|
*
|
|
81
81
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
82
82
|
* @license MIT
|
|
83
|
-
*/var kn,Ho;function Wc(){if(Ho)return kn;Ho=1,kn=function(t){return t!=null&&(n(t)||e(t)||!!t._isBuffer)};function n(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"&&n(t.slice(0,0))}return kn}var Yo;function Xc(){return Yo||(Yo=1,function(){var n=Gc(),e=qo().utf8,t=Wc(),r=qo().bin,i=function(s,a){s.constructor==String?a&&a.encoding==="binary"?s=r.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=n.bytesToWords(s),c=s.length*8,l=1732584193,h=-271733879,u=-1732584194,d=271733878,p=0;p<o.length;p++)o[p]=(o[p]<<8|o[p]>>>24)&16711935|(o[p]<<24|o[p]>>>8)&4278255360;o[c>>>5]|=128<<c%32,o[(c+64>>>9<<4)+14]=c;for(var y=i._ff,g=i._gg,f=i._hh,m=i._ii,p=0;p<o.length;p+=16){var v=l,_=h,b=u,x=d;l=y(l,h,u,d,o[p+0],7,-680876936),d=y(d,l,h,u,o[p+1],12,-389564586),u=y(u,d,l,h,o[p+2],17,606105819),h=y(h,u,d,l,o[p+3],22,-1044525330),l=y(l,h,u,d,o[p+4],7,-176418897),d=y(d,l,h,u,o[p+5],12,1200080426),u=y(u,d,l,h,o[p+6],17,-1473231341),h=y(h,u,d,l,o[p+7],22,-45705983),l=y(l,h,u,d,o[p+8],7,1770035416),d=y(d,l,h,u,o[p+9],12,-1958414417),u=y(u,d,l,h,o[p+10],17,-42063),h=y(h,u,d,l,o[p+11],22,-1990404162),l=y(l,h,u,d,o[p+12],7,1804603682),d=y(d,l,h,u,o[p+13],12,-40341101),u=y(u,d,l,h,o[p+14],17,-1502002290),h=y(h,u,d,l,o[p+15],22,1236535329),l=g(l,h,u,d,o[p+1],5,-165796510),d=g(d,l,h,u,o[p+6],9,-1069501632),u=g(u,d,l,h,o[p+11],14,643717713),h=g(h,u,d,l,o[p+0],20,-373897302),l=g(l,h,u,d,o[p+5],5,-701558691),d=g(d,l,h,u,o[p+10],9,38016083),u=g(u,d,l,h,o[p+15],14,-660478335),h=g(h,u,d,l,o[p+4],20,-405537848),l=g(l,h,u,d,o[p+9],5,568446438),d=g(d,l,h,u,o[p+14],9,-1019803690),u=g(u,d,l,h,o[p+3],14,-187363961),h=g(h,u,d,l,o[p+8],20,1163531501),l=g(l,h,u,d,o[p+13],5,-1444681467),d=g(d,l,h,u,o[p+2],9,-51403784),u=g(u,d,l,h,o[p+7],14,1735328473),h=g(h,u,d,l,o[p+12],20,-1926607734),l=f(l,h,u,d,o[p+5],4,-378558),d=f(d,l,h,u,o[p+8],11,-2022574463),u=f(u,d,l,h,o[p+11],16,1839030562),h=f(h,u,d,l,o[p+14],23,-35309556),l=f(l,h,u,d,o[p+1],4,-1530992060),d=f(d,l,h,u,o[p+4],11,1272893353),u=f(u,d,l,h,o[p+7],16,-155497632),h=f(h,u,d,l,o[p+10],23,-1094730640),l=f(l,h,u,d,o[p+13],4,681279174),d=f(d,l,h,u,o[p+0],11,-358537222),u=f(u,d,l,h,o[p+3],16,-722521979),h=f(h,u,d,l,o[p+6],23,76029189),l=f(l,h,u,d,o[p+9],4,-640364487),d=f(d,l,h,u,o[p+12],11,-421815835),u=f(u,d,l,h,o[p+15],16,530742520),h=f(h,u,d,l,o[p+2],23,-995338651),l=m(l,h,u,d,o[p+0],6,-198630844),d=m(d,l,h,u,o[p+7],10,1126891415),u=m(u,d,l,h,o[p+14],15,-1416354905),h=m(h,u,d,l,o[p+5],21,-57434055),l=m(l,h,u,d,o[p+12],6,1700485571),d=m(d,l,h,u,o[p+3],10,-1894986606),u=m(u,d,l,h,o[p+10],15,-1051523),h=m(h,u,d,l,o[p+1],21,-2054922799),l=m(l,h,u,d,o[p+8],6,1873313359),d=m(d,l,h,u,o[p+15],10,-30611744),u=m(u,d,l,h,o[p+6],15,-1560198380),h=m(h,u,d,l,o[p+13],21,1309151649),l=m(l,h,u,d,o[p+4],6,-145523070),d=m(d,l,h,u,o[p+11],10,-1120210379),u=m(u,d,l,h,o[p+2],15,718787259),h=m(h,u,d,l,o[p+9],21,-343485551),l=l+v>>>0,h=h+_>>>0,u=u+b>>>0,d=d+x>>>0}return n.endian([l,h,u,d])};i._ff=function(s,a,o,c,l,h,u){var d=s+(a&o|~a&c)+(l>>>0)+u;return(d<<h|d>>>32-h)+a},i._gg=function(s,a,o,c,l,h,u){var d=s+(a&c|o&~c)+(l>>>0)+u;return(d<<h|d>>>32-h)+a},i._hh=function(s,a,o,c,l,h,u){var d=s+(a^o^c)+(l>>>0)+u;return(d<<h|d>>>32-h)+a},i._ii=function(s,a,o,c,l,h,u){var d=s+(o^(a|~c))+(l>>>0)+u;return(d<<h|d>>>32-h)+a},i._blocksize=16,i._digestsize=16,Jo.exports=function(s,a){if(s==null)throw new Error("Illegal argument "+s);var o=n.wordsToBytes(i(s,a));return a&&a.asBytes?o:a&&a.asString?r.bytesToString(o):n.bytesToHex(o)}}()),Jo.exports}var qc=Xc();const Hc=di(qc),pe=["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 Zo=1234567;const Qo=Math.PI/180,Ko=180/Math.PI;function Yc(){const n=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(pe[n&255]+pe[n>>8&255]+pe[n>>16&255]+pe[n>>24&255]+"-"+pe[e&255]+pe[e>>8&255]+"-"+pe[e>>16&15|64]+pe[e>>24&255]+"-"+pe[t&63|128]+pe[t>>8&255]+"-"+pe[t>>16&255]+pe[t>>24&255]+pe[r&255]+pe[r>>8&255]+pe[r>>16&255]+pe[r>>24&255]).toLowerCase()}function Ke(n,e,t){return Math.max(e,Math.min(t,n))}function $o(n,e){return(n%e+e)%e}function Zc(n,e,t,r,i){return r+(n-e)*(i-r)/(t-e)}function Qc(n,e,t){return n!==e?(t-n)/(e-n):0}function ea(n,e,t){return(1-t)*n+t*e}function Kc(n,e,t,r){return ea(n,e,1-Math.exp(-t*r))}function $c(n,e=1){return e-Math.abs($o(n,e*2)-e)}function el(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*(3-2*n))}function tl(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*n*(n*(n*6-15)+10))}function rl(n,e){return n+Math.floor(Math.random()*(e-n+1))}function il(n,e){return n+Math.random()*(e-n)}function nl(n){return n*(.5-Math.random())}function sl(n){n!==void 0&&(Zo=n);let e=Zo+=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 ol(n){return n*Qo}function al(n){return n*Ko}function cl(n){return(n&n-1)===0&&n!==0}function ll(n){return Math.pow(2,Math.ceil(Math.log(n)/Math.LN2))}function hl(n){return Math.pow(2,Math.floor(Math.log(n)/Math.LN2))}function ul(n,e,t,r,i){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+r)/2),h=a((e+r)/2),u=s((e-r)/2),d=a((e-r)/2),p=s((r-e)/2),y=a((r-e)/2);switch(i){case"XYX":n.set(o*h,c*u,c*d,o*l);break;case"YZY":n.set(c*d,o*h,c*u,o*l);break;case"ZXZ":n.set(c*u,c*d,o*h,o*l);break;case"XZX":n.set(o*h,c*y,c*p,o*l);break;case"YXY":n.set(c*p,o*h,c*y,o*l);break;case"ZYZ":n.set(c*y,c*p,o*h,o*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function dl(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return n/4294967295;case Uint16Array:return n/65535;case Uint8Array:return n/255;case Int32Array:return Math.max(n/2147483647,-1);case Int16Array:return Math.max(n/32767,-1);case Int8Array:return Math.max(n/127,-1);default:throw new Error("Invalid component type.")}}function pl(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return Math.round(n*4294967295);case Uint16Array:return Math.round(n*65535);case Uint8Array:return Math.round(n*255);case Int32Array:return Math.round(n*2147483647);case Int16Array:return Math.round(n*32767);case Int8Array:return Math.round(n*127);default:throw new Error("Invalid component type.")}}const Jt={DEG2RAD:Qo,RAD2DEG:Ko,generateUUID:Yc,clamp:Ke,euclideanModulo:$o,mapLinear:Zc,inverseLerp:Qc,lerp:ea,damp:Kc,pingpong:$c,smoothstep:el,smootherstep:tl,randInt:rl,randFloat:il,randFloatSpread:nl,seededRandom:sl,degToRad:ol,radToDeg:al,isPowerOfTwo:cl,ceilPowerOfTwo:ll,floorPowerOfTwo:hl,setQuaternionFromProperEuler:ul,normalize:pl,denormalize:dl};class j{constructor(e=0,t=0,r=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=r,this._w=i}static slerpFlat(e,t,r,i,s,a,o){let c=r[i+0],l=r[i+1],h=r[i+2],u=r[i+3];const d=s[a+0],p=s[a+1],y=s[a+2],g=s[a+3];if(o===0){e[t+0]=c,e[t+1]=l,e[t+2]=h,e[t+3]=u;return}if(o===1){e[t+0]=d,e[t+1]=p,e[t+2]=y,e[t+3]=g;return}if(u!==g||c!==d||l!==p||h!==y){let f=1-o;const m=c*d+l*p+h*y+u*g,v=m>=0?1:-1,_=1-m*m;if(_>Number.EPSILON){const x=Math.sqrt(_),S=Math.atan2(x,m*v);f=Math.sin(f*S)/x,o=Math.sin(o*S)/x}const b=o*v;if(c=c*f+d*b,l=l*f+p*b,h=h*f+y*b,u=u*f+g*b,f===1-o){const x=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=x,l*=x,h*=x,u*=x}}e[t]=c,e[t+1]=l,e[t+2]=h,e[t+3]=u}static multiplyQuaternionsFlat(e,t,r,i,s,a){const o=r[i],c=r[i+1],l=r[i+2],h=r[i+3],u=s[a],d=s[a+1],p=s[a+2],y=s[a+3];return e[t]=o*y+h*u+c*p-l*d,e[t+1]=c*y+h*d+l*u-o*p,e[t+2]=l*y+h*p+o*d-c*u,e[t+3]=h*y-o*u-c*d-l*p,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,r,i){return this._x=e,this._y=t,this._z=r,this._w=i,this._onChangeCallback(),this}clone(){return new j(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const r=e._x,i=e._y,s=e._z,a=e._order,o=Math.cos,c=Math.sin,l=o(r/2),h=o(i/2),u=o(s/2),d=c(r/2),p=c(i/2),y=c(s/2);switch(a){case"XYZ":this._x=d*h*u+l*p*y,this._y=l*p*u-d*h*y,this._z=l*h*y+d*p*u,this._w=l*h*u-d*p*y;break;case"YXZ":this._x=d*h*u+l*p*y,this._y=l*p*u-d*h*y,this._z=l*h*y-d*p*u,this._w=l*h*u+d*p*y;break;case"ZXY":this._x=d*h*u-l*p*y,this._y=l*p*u+d*h*y,this._z=l*h*y+d*p*u,this._w=l*h*u-d*p*y;break;case"ZYX":this._x=d*h*u-l*p*y,this._y=l*p*u+d*h*y,this._z=l*h*y-d*p*u,this._w=l*h*u+d*p*y;break;case"YZX":this._x=d*h*u+l*p*y,this._y=l*p*u+d*h*y,this._z=l*h*y-d*p*u,this._w=l*h*u-d*p*y;break;case"XZY":this._x=d*h*u-l*p*y,this._y=l*p*u-d*h*y,this._z=l*h*y+d*p*u,this._w=l*h*u+d*p*y;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,r=t[0],i=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],h=t[6],u=t[10],d=r+o+u;if(d>0){const p=.5/Math.sqrt(d+1);this._w=.25/p,this._x=(h-c)*p,this._y=(s-l)*p,this._z=(a-i)*p}else if(r>o&&r>u){const p=2*Math.sqrt(1+r-o-u);this._w=(h-c)/p,this._x=.25*p,this._y=(i+a)/p,this._z=(s+l)/p}else if(o>u){const p=2*Math.sqrt(1+o-r-u);this._w=(s-l)/p,this._x=(i+a)/p,this._y=.25*p,this._z=(c+h)/p}else{const p=2*Math.sqrt(1+u-r-o);this._w=(a-i)/p,this._x=(s+l)/p,this._y=(c+h)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let r=e.dot(t)+1;return r<Number.EPSILON?(r=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=r):(this._x=0,this._y=-e.z,this._z=e.y,this._w=r)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=r),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Ke(this.dot(e),-1,1)))}rotateTowards(e,t){const r=this.angleTo(e);if(r===0)return this;const i=Math.min(1,t/r);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 r=e._x,i=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,h=t._w;return this._x=r*h+a*o+i*l-s*c,this._y=i*h+a*c+s*o-r*l,this._z=s*h+a*l+r*c-i*o,this._w=a*h-r*o-i*c-s*l,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const r=this._x,i=this._y,s=this._z,a=this._w;let o=a*e._w+r*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=r,this._y=i,this._z=s,this;const c=1-o*o;if(c<=Number.EPSILON){const p=1-t;return this._w=p*a+t*this._w,this._x=p*r+t*this._x,this._y=p*i+t*this._y,this._z=p*s+t*this._z,this.normalize(),this}const l=Math.sqrt(c),h=Math.atan2(l,o),u=Math.sin((1-t)*h)/l,d=Math.sin(t*h)/l;return this._w=a*u+this._w*d,this._x=r*u+this._x*d,this._y=i*u+this._y*d,this._z=s*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(e,t,r){return this.copy(e).slerp(t,r)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),r=Math.random(),i=Math.sqrt(1-r),s=Math.sqrt(r);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 z{constructor(e=0,t=0,r=0){this.isVector3=!0,z.prototype.isVector3=!0,this.x=e,this.y=t,this.z=r}set(e,t,r){return r===void 0&&(r=this.z),this.x=e,this.y=t,this.z=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new z(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(ta.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(ta.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,r=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*r+s[6]*i,this.y=s[1]*t+s[4]*r+s[7]*i,this.z=s[2]*t+s[5]*r+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,r=this.y,i=this.z,s=e.elements,a=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*a,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*a,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*a,this}applyQuaternion(e){const t=this.x,r=this.y,i=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*i-o*r),h=2*(o*t-s*i),u=2*(s*r-a*t);return this.x=t+c*l+a*u-o*h,this.y=r+c*h+o*l-s*u,this.z=i+c*u+s*h-a*l,this}transformDirection(e){const t=this.x,r=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*r+s[8]*i,this.y=s[1]*t+s[5]*r+s[9]*i,this.z=s[2]*t+s[6]*r+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 r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const r=e.x,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-r*c,this.z=r*o-i*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const r=e.dot(this)/t;return this.copy(e).multiplyScalar(r)}projectOnPlane(e){return An.copy(this).projectOnVector(e),this.sub(An)}reflect(e){return this.sub(An.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const r=this.dot(e)/t;return Math.acos(Ke(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,r=this.y-e.y,i=this.z-e.z;return t*t+r*r+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,r){const i=Math.sin(t)*e;return this.x=i*Math.sin(r),this.y=Math.cos(t)*e,this.z=i*Math.cos(r),this}setFromCylindricalCoords(e,t,r){return this.x=e*Math.sin(t),this.y=r,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),r=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=r,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,r=Math.sqrt(1-t*t);return this.x=r*Math.cos(e),this.y=t,this.z=r*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 An=new z,ta=new j,Si=2e3,ra=2001;class We{constructor(e,t,r,i,s,a,o,c,l,h,u,d,p,y,g,f){this.isMatrix4=!0,We.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,r,i,s,a,o,c,l,h,u,d,p,y,g,f)}extractPosition(e){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(e)}multiplyToArray(e,t,r){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(e){return this.makeRotationFromQuaternion(e)}set(e,t,r,i,s,a,o,c,l,h,u,d,p,y,g,f){const m=this.elements;return m[0]=e,m[4]=t,m[8]=r,m[12]=i,m[1]=s,m[5]=a,m[9]=o,m[13]=c,m[2]=l,m[6]=h,m[10]=u,m[14]=d,m[3]=p,m[7]=y,m[11]=g,m[15]=f,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 We().fromArray(this.elements)}copy(e){const t=this.elements,r=e.elements;return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],t[9]=r[9],t[10]=r[10],t[11]=r[11],t[12]=r[12],t[13]=r[13],t[14]=r[14],t[15]=r[15],this}copyPosition(e){const t=this.elements,r=e.elements;return t[12]=r[12],t[13]=r[13],t[14]=r[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,r){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),r.setFromMatrixColumn(this,2),this}makeBasis(e,t,r){return this.set(e.x,t.x,r.x,0,e.y,t.y,r.y,0,e.z,t.z,r.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,r=e.elements,i=1/Gt.setFromMatrixColumn(e,0).length(),s=1/Gt.setFromMatrixColumn(e,1).length(),a=1/Gt.setFromMatrixColumn(e,2).length();return t[0]=r[0]*i,t[1]=r[1]*i,t[2]=r[2]*i,t[3]=0,t[4]=r[4]*s,t[5]=r[5]*s,t[6]=r[6]*s,t[7]=0,t[8]=r[8]*a,t[9]=r[9]*a,t[10]=r[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,r=e.x,i=e.y,s=e.z,a=Math.cos(r),o=Math.sin(r),c=Math.cos(i),l=Math.sin(i),h=Math.cos(s),u=Math.sin(s);if(e.order==="XYZ"){const d=a*h,p=a*u,y=o*h,g=o*u;t[0]=c*h,t[4]=-c*u,t[8]=l,t[1]=p+y*l,t[5]=d-g*l,t[9]=-o*c,t[2]=g-d*l,t[6]=y+p*l,t[10]=a*c}else if(e.order==="YXZ"){const d=c*h,p=c*u,y=l*h,g=l*u;t[0]=d+g*o,t[4]=y*o-p,t[8]=a*l,t[1]=a*u,t[5]=a*h,t[9]=-o,t[2]=p*o-y,t[6]=g+d*o,t[10]=a*c}else if(e.order==="ZXY"){const d=c*h,p=c*u,y=l*h,g=l*u;t[0]=d-g*o,t[4]=-a*u,t[8]=y+p*o,t[1]=p+y*o,t[5]=a*h,t[9]=g-d*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const d=a*h,p=a*u,y=o*h,g=o*u;t[0]=c*h,t[4]=y*l-p,t[8]=d*l+g,t[1]=c*u,t[5]=g*l+d,t[9]=p*l-y,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const d=a*c,p=a*l,y=o*c,g=o*l;t[0]=c*h,t[4]=g-d*u,t[8]=y*u+p,t[1]=u,t[5]=a*h,t[9]=-o*h,t[2]=-l*h,t[6]=p*u+y,t[10]=d-g*u}else if(e.order==="XZY"){const d=a*c,p=a*l,y=o*c,g=o*l;t[0]=c*h,t[4]=-u,t[8]=l*h,t[1]=d*u+g,t[5]=a*h,t[9]=p*u-y,t[2]=y*u-p,t[6]=o*h,t[10]=g*u+d}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(fl,e,ml)}lookAt(e,t,r){const i=this.elements;return Ce.subVectors(e,t),Ce.lengthSq()===0&&(Ce.z=1),Ce.normalize(),vt.crossVectors(r,Ce),vt.lengthSq()===0&&(Math.abs(r.z)===1?Ce.x+=1e-4:Ce.z+=1e-4,Ce.normalize(),vt.crossVectors(r,Ce)),vt.normalize(),wi.crossVectors(Ce,vt),i[0]=vt.x,i[4]=wi.x,i[8]=Ce.x,i[1]=vt.y,i[5]=wi.y,i[9]=Ce.y,i[2]=vt.z,i[6]=wi.z,i[10]=Ce.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const r=e.elements,i=t.elements,s=this.elements,a=r[0],o=r[4],c=r[8],l=r[12],h=r[1],u=r[5],d=r[9],p=r[13],y=r[2],g=r[6],f=r[10],m=r[14],v=r[3],_=r[7],b=r[11],x=r[15],S=i[0],w=i[4],C=i[8],M=i[12],T=i[1],E=i[5],P=i[9],k=i[13],R=i[2],U=i[6],N=i[10],G=i[14],B=i[3],oe=i[7],Q=i[11],re=i[15];return s[0]=a*S+o*T+c*R+l*B,s[4]=a*w+o*E+c*U+l*oe,s[8]=a*C+o*P+c*N+l*Q,s[12]=a*M+o*k+c*G+l*re,s[1]=h*S+u*T+d*R+p*B,s[5]=h*w+u*E+d*U+p*oe,s[9]=h*C+u*P+d*N+p*Q,s[13]=h*M+u*k+d*G+p*re,s[2]=y*S+g*T+f*R+m*B,s[6]=y*w+g*E+f*U+m*oe,s[10]=y*C+g*P+f*N+m*Q,s[14]=y*M+g*k+f*G+m*re,s[3]=v*S+_*T+b*R+x*B,s[7]=v*w+_*E+b*U+x*oe,s[11]=v*C+_*P+b*N+x*Q,s[15]=v*M+_*k+b*G+x*re,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],r=e[4],i=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],h=e[2],u=e[6],d=e[10],p=e[14],y=e[3],g=e[7],f=e[11],m=e[15];return y*(+s*c*u-i*l*u-s*o*d+r*l*d+i*o*p-r*c*p)+g*(+t*c*p-t*l*d+s*a*d-i*a*p+i*l*h-s*c*h)+f*(+t*l*u-t*o*p-s*a*u+r*a*p+s*o*h-r*l*h)+m*(-i*o*h-t*c*u+t*o*d+i*a*u-r*a*d+r*c*h)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,r){const 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]=r),this}invert(){const e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8],u=e[9],d=e[10],p=e[11],y=e[12],g=e[13],f=e[14],m=e[15],v=u*f*l-g*d*l+g*c*p-o*f*p-u*c*m+o*d*m,_=y*d*l-h*f*l-y*c*p+a*f*p+h*c*m-a*d*m,b=h*g*l-y*u*l+y*o*p-a*g*p-h*o*m+a*u*m,x=y*u*c-h*g*c-y*o*d+a*g*d+h*o*f-a*u*f,S=t*v+r*_+i*b+s*x;if(S===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const w=1/S;return e[0]=v*w,e[1]=(g*d*s-u*f*s-g*i*p+r*f*p+u*i*m-r*d*m)*w,e[2]=(o*f*s-g*c*s+g*i*l-r*f*l-o*i*m+r*c*m)*w,e[3]=(u*c*s-o*d*s-u*i*l+r*d*l+o*i*p-r*c*p)*w,e[4]=_*w,e[5]=(h*f*s-y*d*s+y*i*p-t*f*p-h*i*m+t*d*m)*w,e[6]=(y*c*s-a*f*s-y*i*l+t*f*l+a*i*m-t*c*m)*w,e[7]=(a*d*s-h*c*s+h*i*l-t*d*l-a*i*p+t*c*p)*w,e[8]=b*w,e[9]=(y*u*s-h*g*s-y*r*p+t*g*p+h*r*m-t*u*m)*w,e[10]=(a*g*s-y*o*s+y*r*l-t*g*l-a*r*m+t*o*m)*w,e[11]=(h*o*s-a*u*s-h*r*l+t*u*l+a*r*p-t*o*p)*w,e[12]=x*w,e[13]=(h*g*i-y*u*i+y*r*d-t*g*d-h*r*f+t*u*f)*w,e[14]=(y*o*i-a*g*i-y*r*c+t*g*c+a*r*f-t*o*f)*w,e[15]=(a*u*i-h*o*i+h*r*c-t*u*c-a*r*d+t*o*d)*w,this}scale(e){const t=this.elements,r=e.x,i=e.y,s=e.z;return t[0]*=r,t[4]*=i,t[8]*=s,t[1]*=r,t[5]*=i,t[9]*=s,t[2]*=r,t[6]*=i,t[10]*=s,t[3]*=r,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],r=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,r,i))}makeTranslation(e,t,r){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,r,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),r=Math.sin(e);return this.set(1,0,0,0,0,t,-r,0,0,r,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,0,r,0,0,1,0,0,-r,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,-r,0,0,r,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const r=Math.cos(t),i=Math.sin(t),s=1-r,a=e.x,o=e.y,c=e.z,l=s*a,h=s*o;return this.set(l*a+r,l*o-i*c,l*c+i*o,0,l*o+i*c,h*o+r,h*c-i*a,0,l*c-i*o,h*c+i*a,s*c*c+r,0,0,0,0,1),this}makeScale(e,t,r){return this.set(e,0,0,0,0,t,0,0,0,0,r,0,0,0,0,1),this}makeShear(e,t,r,i,s,a){return this.set(1,r,s,0,e,1,a,0,t,i,1,0,0,0,0,1),this}compose(e,t,r){const i=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,h=a+a,u=o+o,d=s*l,p=s*h,y=s*u,g=a*h,f=a*u,m=o*u,v=c*l,_=c*h,b=c*u,x=r.x,S=r.y,w=r.z;return i[0]=(1-(g+m))*x,i[1]=(p+b)*x,i[2]=(y-_)*x,i[3]=0,i[4]=(p-b)*S,i[5]=(1-(d+m))*S,i[6]=(f+v)*S,i[7]=0,i[8]=(y+_)*w,i[9]=(f-v)*w,i[10]=(1-(d+g))*w,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,r){const i=this.elements;let s=Gt.set(i[0],i[1],i[2]).length();const a=Gt.set(i[4],i[5],i[6]).length(),o=Gt.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],Je.copy(this);const c=1/s,l=1/a,h=1/o;return Je.elements[0]*=c,Je.elements[1]*=c,Je.elements[2]*=c,Je.elements[4]*=l,Je.elements[5]*=l,Je.elements[6]*=l,Je.elements[8]*=h,Je.elements[9]*=h,Je.elements[10]*=h,t.setFromRotationMatrix(Je),r.x=s,r.y=a,r.z=o,this}makePerspective(e,t,r,i,s,a,o=Si){const c=this.elements,l=2*s/(t-e),h=2*s/(r-i),u=(t+e)/(t-e),d=(r+i)/(r-i);let p,y;if(o===Si)p=-(a+s)/(a-s),y=-2*a*s/(a-s);else if(o===ra)p=-a/(a-s),y=-a*s/(a-s);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=l,c[4]=0,c[8]=u,c[12]=0,c[1]=0,c[5]=h,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=y,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,r,i,s,a,o=Si){const c=this.elements,l=1/(t-e),h=1/(r-i),u=1/(a-s),d=(t+e)*l,p=(r+i)*h;let y,g;if(o===Si)y=(a+s)*u,g=-2*u;else if(o===ra)y=s*u,g=-1*u;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-d,c[1]=0,c[5]=2*h,c[9]=0,c[13]=-p,c[2]=0,c[6]=0,c[10]=g,c[14]=-y,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,r=e.elements;for(let i=0;i<16;i++)if(t[i]!==r[i])return!1;return!0}fromArray(e,t=0){for(let r=0;r<16;r++)this.elements[r]=e[r+t];return this}toArray(e=[],t=0){const r=this.elements;return e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3],e[t+4]=r[4],e[t+5]=r[5],e[t+6]=r[6],e[t+7]=r[7],e[t+8]=r[8],e[t+9]=r[9],e[t+10]=r[10],e[t+11]=r[11],e[t+12]=r[12],e[t+13]=r[13],e[t+14]=r[14],e[t+15]=r[15],e}}const Gt=new z,Je=new We,fl=new z(0,0,0),ml=new z(1,1,1),vt=new z,wi=new z,Ce=new z,ia=new We,na=new j;class Br{constructor(e=0,t=0,r=0,i=Br.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=r,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,r,i=this._order){return this._x=e,this._y=t,this._z=r,this._order=i,this._onChangeCallback(),this}clone(){return new Br(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,r=!0){const i=e.elements,s=i[0],a=i[4],o=i[8],c=i[1],l=i[5],h=i[9],u=i[2],d=i[6],p=i[10];switch(t){case"XYZ":this._y=Math.asin(Ke(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,p),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Ke(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,p),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin(Ke(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,p),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Ke(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,p),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin(Ke(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(o,p));break;case"XZY":this._z=Math.asin(-Ke(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-h,p),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,r===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,r){return ia.makeRotationFromQuaternion(e),this.setFromRotationMatrix(ia,t,r)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return na.setFromEuler(this),this.setFromQuaternion(na,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}}Br.DEFAULT_ORDER="XYZ";class tr{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 tr(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,r=this.y,i=e.elements;return this.x=i[0]*t+i[3]*r+i[6],this.y=i[1]*t+i[4]*r+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 r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const r=this.dot(e)/t;return Math.acos(Ke(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,r=this.y-e.y;return t*t+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}rotateAround(e,t){const r=Math.cos(t),i=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*r-a*i+e.x,this.y=s*i+a*r+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}tr.isVector2=!0;class Me{constructor(e=0,t=0,r=0,i=1){Me.prototype.isVector4=!0,this.x=e,this.y=t,this.z=r,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,r,i){return this.x=e,this.y=t,this.z=r,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 Me(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,r=this.y,i=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*r+a[8]*i+a[12]*s,this.y=a[1]*t+a[5]*r+a[9]*i+a[13]*s,this.z=a[2]*t+a[6]*r+a[10]*i+a[14]*s,this.w=a[3]*t+a[7]*r+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,r,i,s;const a=e.elements,o=a[0],c=a[4],l=a[8],h=a[1],u=a[5],d=a[9],p=a[2],y=a[6],g=a[10];if(Math.abs(c-h)<.01&&Math.abs(l-p)<.01&&Math.abs(d-y)<.01){if(Math.abs(c+h)<.1&&Math.abs(l+p)<.1&&Math.abs(d+y)<.1&&Math.abs(o+u+g-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const m=(o+1)/2,v=(u+1)/2,_=(g+1)/2,b=(c+h)/4,x=(l+p)/4,S=(d+y)/4;return m>v&&m>_?m<.01?(r=0,i=.707106781,s=.707106781):(r=Math.sqrt(m),i=b/r,s=x/r):v>_?v<.01?(r=.707106781,i=0,s=.707106781):(i=Math.sqrt(v),r=b/i,s=S/i):_<.01?(r=.707106781,i=.707106781,s=0):(s=Math.sqrt(_),r=x/s,i=S/s),this.set(r,i,s,t),this}let f=Math.sqrt((y-d)*(y-d)+(l-p)*(l-p)+(h-c)*(h-c));return Math.abs(f)<.001&&(f=1),this.x=(y-d)/f,this.y=(l-p)/f,this.z=(h-c)/f,this.w=Math.acos((o+u+g-1)/2),this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this.w=e.w+(t.w-e.w)*r,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}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 tt{constructor(e,t,r,i,s,a,o,c,l){tt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,r,i,s,a,o,c,l)}set(e,t,r,i,s,a,o,c,l){const h=this.elements;return h[0]=e,h[1]=i,h[2]=o,h[3]=t,h[4]=s,h[5]=c,h[6]=r,h[7]=a,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,r=e.elements;return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],this}extractBasis(e,t,r){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),r.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const r=e.elements,i=t.elements,s=this.elements,a=r[0],o=r[3],c=r[6],l=r[1],h=r[4],u=r[7],d=r[2],p=r[5],y=r[8],g=i[0],f=i[3],m=i[6],v=i[1],_=i[4],b=i[7],x=i[2],S=i[5],w=i[8];return s[0]=a*g+o*v+c*x,s[3]=a*f+o*_+c*S,s[6]=a*m+o*b+c*w,s[1]=l*g+h*v+u*x,s[4]=l*f+h*_+u*S,s[7]=l*m+h*b+u*w,s[2]=d*g+p*v+y*x,s[5]=d*f+p*_+y*S,s[8]=d*m+p*b+y*w,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8];return t*a*h-t*o*l-r*s*h+r*o*c+i*s*l-i*a*c}invert(){const e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8],u=h*a-o*l,d=o*c-h*s,p=l*s-a*c,y=t*u+r*d+i*p;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const g=1/y;return e[0]=u*g,e[1]=(i*l-h*r)*g,e[2]=(o*r-i*a)*g,e[3]=d*g,e[4]=(h*t-i*c)*g,e[5]=(i*s-o*t)*g,e[6]=p*g,e[7]=(r*c-l*t)*g,e[8]=(a*t-r*s)*g,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,r,i,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(r*c,r*l,-r*(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(Rn.makeScale(e,t)),this}rotate(e){return this.premultiply(Rn.makeRotation(-e)),this}translate(e,t){return this.premultiply(Rn.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,-r,0,r,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,r=e.elements;for(let i=0;i<9;i++)if(t[i]!==r[i])return!1;return!0}fromArray(e,t=0){for(let r=0;r<9;r++)this.elements[r]=e[r+t];return this}toArray(e=[],t=0){const r=this.elements;return e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3],e[t+4]=r[4],e[t+5]=r[5],e[t+6]=r[6],e[t+7]=r[7],e[t+8]=r[8],e}clone(){return new tt().fromArray(this.elements)}}const Rn=new tt;var _e;(function(n){n[n.Random=0]="Random",n[n.Loop=1]="Loop",n[n.PingPong=2]="PingPong",n[n.Burst=3]="Burst"})(_e||(_e={}));function yr(n,e,t,r){let i;switch(_e.Random===n?e=Math.random():_e.Burst===n&&r.isBursting&&(e=r.burstParticleIndex/r.burstParticleCount),t>0?i=Math.floor(e/t)*t:i=e,n){case _e.Loop:i=i%1;break;case _e.PingPong:i=Math.abs(i%2-1);break}return i}class Ut{constructor(e,t,r,i){this.p=[e,t,r,i]}genValue(e){const t=e*e,r=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]*r}derivativeCoefficients(e){const t=[];for(let r=e,i=r.length-1;i>0;i--){const s=[];for(let a=0;a<i;a++){const o=i*(r[a+1]-r[a]);s.push(o)}t.push(s),r=s}return t}getSlope(e){const t=this.derivativeCoefficients(this.p)[0],r=1-e,i=r*r,s=r*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,r=[],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(r=[],a=0,o=t.length-1;a<o;a++)i=e*t[a]+(1-e)*t[a+1],c[s++]=i,r.push(i);t=r}return c}split(e){const t=this.hull(e);return{left:new Ut(t[0],t[4],t[7],t[9]),right:new Ut(t[9],t[8],t[6],t[3]),span:t}}clone(){return new Ut(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 Ut(e.p0,e.p1,e.p2,e.p3)}}const gr=n=>({r:n.x,g:n.y,b:n.z,a:n.w}),vr=n=>new Me(n.r,n.g,n.b,n.a),yl=(n,e)=>{switch(e){case"Vector3":return new z(n.x,n.y,n.z);case"Vector4":return new Me(n.x,n.y,n.z,n.w);case"Color":return new z(n.r,n.g,n.b);case"Number":return n;default:return n}},gl=(n,e)=>{switch(e){case"Vector3":return{x:n.x,y:n.y,z:n.z};case"Vector4":return{x:n.x,y:n.y,z:n.z,w:n.w};case"Color":return{r:n.x,g:n.y,b:n.z};case"Number":return n;default:return n}};class en{constructor(e,t){this.a=e,this.b=t,this.type="value"}startGen(e){}genColor(e,t){const r=Math.random();return t.copy(this.a).lerp(this.b,r)}toJSON(){return{type:"RandomColor",a:gr(this.a),b:gr(this.b)}}static fromJSON(e){return new en(vr(e.a),vr(e.b))}clone(){return new en(this.a.clone(),this.b.clone())}}class rr{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:gr(this.a),b:gr(this.b)}}static fromJSON(e){return new rr(vr(e.a),vr(e.b))}clone(){return new rr(this.a.clone(),this.b.clone())}}class Mt{constructor(e,t){this.subType=t,this.type="function",this.keys=e}findKey(e){let t=0,r=0,i=this.keys.length-1;for(;r+1<i;)if(t=Math.floor((r+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))r=t+1;else return t;for(let s=r;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 r=this.findKey(t);return this.subType==="Number"?r===-1?this.keys[0][0]:r+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[r+1][0]-this.keys[r][0])*((t-this.getStartX(r))/(this.getEndX(r)-this.getStartX(r)))+this.keys[r][0]:r===-1?e.copy(this.keys[0][0]):r+1>=this.keys.length?e.copy(this.keys[this.keys.length-1][0]):e.copy(this.keys[r][0]).lerp(this.keys[r+1][0],(t-this.getStartX(r))/(this.getEndX(r)-this.getStartX(r)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([e,t])=>({value:gl(e,this.subType),pos:t}))}}static fromJSON(e){return new Mt(e.keys.map(t=>[yl(t.value,e.subType),t.pos]),e.subType)}clone(){return this.subType==="Number"?new Mt(this.keys.map(([e,t])=>[e,t]),this.subType):new Mt(this.keys.map(([e,t])=>[e.clone(),t]),this.subType)}}const Mi=new z;class Lt{constructor(e=[[new z(0,0,0),0],[new z(1,1,1),0]],t=[[1,0],[1,1]]){this.type="function",this.color=new Mt(e,"Color"),this.alpha=new Mt(t,"Number")}genColor(e,t,r){return this.color.genValue(Mi,r),t.set(Mi.x,Mi.y,Mi.z,this.alpha.genValue(1,r))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(e){if(e.functions){const t=e.functions.map(r=>[rr.fromJSON(r.function).a,r.start]);return e.functions.length>0&&t.push([rr.fromJSON(e.functions[e.functions.length-1].function).b,1]),new Lt(t.map(r=>[new z(r[0].x,r[0].y,r[0].z),r[1]]),t.map(r=>[r[0].w,r[1]]))}else{const t=new Lt;return t.alpha=Mt.fromJSON(e.alpha),t.color=Mt.fromJSON(e.color),t}}clone(){const e=new Lt;return e.alpha=this.alpha.clone(),e.color=this.color.clone(),e}startGen(e){}}const On=new Me;class tn{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,r){return this.gradient1.genColor(e,t,r),this.gradient2.genColor(e,On,r),e&&e[this.indexCount]!==void 0?t.lerp(On,e[this.indexCount]):t.lerp(On,Math.random()),t}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(e){return new tn(Lt.fromJSON(e.gradient1),Lt.fromJSON(e.gradient2))}clone(){return new tn(this.gradient1.clone(),this.gradient2.clone())}}class Nt{constructor(e){this.color=e,this.type="value"}startGen(e){}genColor(e,t){return t.copy(this.color)}toJSON(){return{type:"ConstantColor",color:gr(this.color)}}static fromJSON(e){return new Nt(vr(e.color))}clone(){return new Nt(this.color.clone())}}function zn(n){switch(n.type){case"ConstantColor":return Nt.fromJSON(n);case"ColorRange":return rr.fromJSON(n);case"RandomColor":return en.fromJSON(n);case"Gradient":return Lt.fromJSON(n);case"RandomColorBetweenGradient":return tn.fromJSON(n);default:return new Nt(new Me(1,1,1,1))}}class L{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 L(e.value)}clone(){return new L(this.value)}}class Dt{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),Jt.lerp(this.a,this.b,e[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(e){return new Dt(e.a,e.b)}clone(){return new Dt(this.a,this.b)}}class vl{constructor(){this.functions=new Array}findFunction(e){let t=0,r=0,i=this.functions.length-1;for(;r+1<i;)if(t=Math.floor((r+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))r=t+1;else return t;for(let s=r;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 r=this.findFunction(e);this.functions.splice(r+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 Ir extends vl{constructor(e=[[new Ut(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=e}genValue(e,t=0){const r=this.findFunction(t);return r===-1?0:this.functions[r][0].genValue((t-this.getStartX(r))/(this.getEndX(r)-this.getStartX(r)))}toSVG(e,t){if(t<1)return"";let r=["M",0,this.functions[0][0].p[0]].join(" ");for(let i=1/t;i<=1;i+=1/t)r=[r,"L",i*e,this.genValue(void 0,i)].join(" ");return r}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([e,t])=>({function:e.toJSON(),start:t}))}}static fromJSON(e){return new Ir(e.functions.map(t=>[Ut.fromJSON(t.function),t.start]))}clone(){return new Ir(this.functions.map(([e,t])=>[e.clone(),t]))}startGen(e){}}function D(n){switch(n.type){case"ConstantValue":return L.fromJSON(n);case"IntervalValue":return Dt.fromJSON(n);case"PiecewiseBezier":return Ir.fromJSON(n);default:return new L(0)}}class Ur{constructor(){this.indexCount=0,this.type="rotation"}startGen(e){this.indexCount=e.length,e.push(new j);let t,r,i,s,a,o;do t=Math.random()*2-1,r=Math.random()*2-1,i=t*t+r*r;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,r,c*s,c*a)}genValue(e,t,r,i){return this.indexCount===-1&&this.startGen(e),t.copy(e[this.indexCount]),t}toJSON(){return{type:"RandomQuat"}}static fromJSON(e){return new Ur}clone(){return new Ur}}class Nr{constructor(e,t){this.axis=e,this.angle=t,this.type="rotation"}startGen(e){this.angle.startGen(e)}genValue(e,t,r,i){return t.setFromAxisAngle(this.axis,this.angle.genValue(e,i)*r)}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 Nr(new z(e.axis.x,e.axis.y,e.axis.z),D(e.angle))}clone(){return new Nr(this.axis.clone(),this.angle.clone())}}class rn{constructor(e,t,r,i){this.angleX=e,this.angleY=t,this.angleZ=r,this.type="rotation",this.eular=new Br(0,0,0,i)}startGen(e){this.angleX.startGen(e),this.angleY.startGen(e),this.angleZ.startGen(e)}genValue(e,t,r,i){return this.eular.set(this.angleX.genValue(e,i)*r,this.angleY.genValue(e,i)*r,this.angleZ.genValue(e,i)*r),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 rn(D(e.angleX),D(e.angleY),D(e.angleZ),e.eulerOrder)}clone(){return new rn(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function sa(n){switch(n.type){case"AxisAngle":return Nr.fromJSON(n);case"Euler":return rn.fromJSON(n);case"RandomQuat":return Ur.fromJSON(n);default:return new Ur}}class Ft{constructor(e,t,r){this.x=e,this.y=t,this.z=r,this.type="vec3function"}startGen(e){this.x.startGen(e),this.y.startGen(e),this.z.startGen(e)}genValue(e,t,r){return t.set(this.x.genValue(e,r),this.y.genValue(e,r),this.z.genValue(e,r))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new Ft(D(e.x),D(e.y),D(e.z))}clone(){return new Ft(this.x,this.y,this.z)}}function _l(n){switch(n.type){case"Vector3Function":return Ft.fromJSON(n);default:return new Ft(new L(0),new L(0),new L(0))}}function Ti(n){switch(n.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return D(n);case"AxisAngle":case"RandomQuat":case"Euler":return sa(n);case"Vector3Function":return _l(n);default:return new L(0)}}class Dr{constructor(e={}){var t,r,i,s,a,o,c;this.type="cone",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r: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:_e.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new L(1),this.memory=[]}update(e,t){_e.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const r=yr(this.mode,this.currentValue,this.spread,t),i=Jt.lerp(1-this.thickness,1,Math.random()),s=r*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 Dr({radius:e.radius,arc:e.arc,thickness:e.thickness,angle:e.angle,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new Dr({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Fr{constructor(e={}){var t,r,i,s,a,o;this.type="circle",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:_e.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new L(1),this.memory=[]}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const r=yr(this.mode,this.currentValue,this.spread,t),i=Jt.lerp(1-this.thickness,1,Math.random()),s=r*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 Fr({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new Fr({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function Ci(n,e){return Math.floor(Math.random()*(e-n))+n}const Pi=new z(0,1,0),Ei=new z(0,0,0),bl=new z(1,1,1),oa=new z(0,0,1);class Lr{constructor(e={}){var t,r,i,s,a,o,c;this.type="donut",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r: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:_e.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new L(1),this.memory=[],this._m1=new We}update(e,t){_e.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const r=yr(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jt.lerp(1-this.thickness,1,Math.random()),a=r*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 j&&(this._m1.lookAt(Ei,e.velocity,Pi),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 Lr({radius:e.radius,arc:e.arc,thickness:e.thickness,donutRadius:e.donutRadius,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new Lr({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Vr{constructor(){this.type="point",this._m1=new We}update(e,t){}initialize(e){const t=Math.random(),r=Math.random(),i=t*Math.PI*2,s=Math.acos(2*r-1),a=Math.cbrt(Math.random()),o=Math.sin(i),c=Math.cos(i),l=Math.sin(s),h=Math.cos(s);e.velocity.x=a*l*c,e.velocity.y=a*l*o,e.velocity.z=a*h,e.velocity.multiplyScalar(e.startSpeed),e.position.setScalar(0),e.rotation instanceof j&&(this._m1.lookAt(Ei,e.position,Pi),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(e){return new Vr}clone(){return new Vr}}class ir{constructor(e={}){var t,r,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:_e.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new L(1),this.memory=[],this._m1=new We}update(e,t){_e.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const r=yr(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jt.lerp(1-this.thickness,1,Math.random()),a=r*this.arc,o=Math.acos(2*i-1),c=Math.sin(a),l=Math.cos(a),h=Math.sin(o),u=Math.cos(o);e.position.x=h*l,e.position.y=h*c,e.position.z=u,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof j&&(this._m1.lookAt(Ei,e.position,Pi),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 ir({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new ir({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class jr{constructor(e={}){var t,r,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:_e.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new L(1),this.memory=[],this._m1=new We}update(e,t){_e.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const r=yr(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jt.lerp(1-this.thickness,1,Math.random()),a=r*this.arc,o=Math.acos(i),c=Math.sin(a),l=Math.cos(a),h=Math.sin(o),u=Math.cos(o);e.position.x=h*l,e.position.y=h*c,e.position.z=u,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof j&&(this._m1.lookAt(Ei,e.position,Pi),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 jr({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new jr({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Jr{constructor(e={}){var t,r,i,s;this.type="grid",this.width=(t=e.width)!==null&&t!==void 0?t:1,this.height=(r=e.height)!==null&&r!==void 0?r: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),r=Math.floor(Math.random()*this.column);e.position.x=r*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 Jr(e)}clone(){return new Jr({width:this.width,height:this.height,column:this.column,row:this.row})}update(e,t){}}const Bn={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Fr,loadJSON:Fr.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Dr,loadJSON:Dr.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Lr,loadJSON:Lr.fromJSON},point:{type:"point",params:[],constructor:Vr,loadJSON:Vr.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:ir,loadJSON:ir.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:jr,loadJSON:jr.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:Jr,loadJSON:Jr.fromJSON}};function xl(n,e){return Bn[n.type].loadJSON(n,e)}class Gr{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 Gr(zn(e.color))}clone(){return new Gr(this.color.clone())}reset(){}}class Wr{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 Wr(D(e.angularVelocity))}frameUpdate(e){}clone(){return new Wr(this.angularVelocity.clone())}reset(){}}class Xr{constructor(e){this.angularVelocity=e,this.type="Rotation3DOverLife",this.tempQuat=new j,this.tempQuat2=new j}initialize(e){e.rotation instanceof j&&(e.angularVelocity=new j,this.angularVelocity.startGen(e.memory))}update(e,t){e.rotation instanceof j&&(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 Xr(sa(e.angularVelocity))}frameUpdate(e){}clone(){return new Xr(this.angularVelocity.clone())}reset(){}}class qr{initialize(e,t){this.ps=t,this.x.startGen(e.memory),this.y.startGen(e.memory),this.z.startGen(e.memory)}constructor(e,t,r){this.x=e,this.y=t,this.z=r,this.type="ForceOverLife",this._temp=new z,this._tempScale=new z,this._tempQ=new j}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 qr(D(e.x),D(e.y),D(e.z))}frameUpdate(e){if(this.ps&&!this.ps.worldSpace){const t=this._temp,r=this._tempQ,i=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,r,i),r.invert(),i.set(1/i.x,1/i.y,1/i.z)}}clone(){return new qr(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class Hr{initialize(e){this.size.startGen(e.memory)}constructor(e){this.size=e,this.type="SizeOverLife"}update(e){this.size instanceof Ft?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 Hr(Ti(e.size))}frameUpdate(e){}clone(){return new Hr(this.size.clone())}reset(){}}class Yr{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 Yr(D(e.speed))}frameUpdate(e){}clone(){return new Yr(this.speed.clone())}reset(){}}class Zr{constructor(e){this.frame=e,this.type="FrameOverLife"}initialize(e){this.frame.startGen(e.memory)}update(e,t){this.frame instanceof Ir&&(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 Zr(D(e.frame))}clone(){return new Zr(this.frame.clone())}reset(){}}class Qr{constructor(e,t=new z(0,1,0)){this.orbitSpeed=e,this.axis=t,this.type="OrbitOverLife",this.temp=new z,this.rotation=new j}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 Qr(D(e.orbitSpeed),e.axis?new z(e.axis[0],e.axis[1],e.axis[2]):void 0)}clone(){return new Qr(this.orbitSpeed.clone())}reset(){}}class In{constructor(e){this.data=e,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class Sl{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 In(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 In(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 r=new In(t);r.next=e,r.prev=e.prev,r.prev!==null&&(r.prev.next=r),r.next.prev=r,e==this.head&&(this.head=r),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 wl{constructor(){this.startSpeed=0,this.startColor=new Me,this.startSize=new z(1,1,1),this.position=new z,this.velocity=new z,this.age=0,this.life=1,this.size=new z(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new Me,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class Ml{constructor(e,t,r){this.position=e,this.size=t,this.color=r}}class ki{constructor(){this.startSpeed=0,this.startColor=new Me,this.startSize=new z(1,1,1),this.position=new z,this.velocity=new z,this.age=0,this.life=1,this.size=new z(1,1,1),this.length=100,this.speedModifier=1,this.color=new Me,this.previous=new Sl,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new Ml(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 Kr{initialize(e){this.width.startGen(e.memory)}constructor(e){this.width=e,this.type="WidthOverLength"}update(e){if(e instanceof ki){const t=e.previous.values();for(let r=0;r<e.previous.length;r++){const i=t.next();i.value.size=this.width.genValue(e.memory,(e.previous.length-r)/e.length)}}}frameUpdate(e){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(e){return new Kr(D(e.width))}clone(){return new Kr(this.width.clone())}reset(){}}class $r{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 $r(new z(e.direction[0],e.direction[1],e.direction[2]),D((t=e.magnitude)!==null&&t!==void 0?t:e.force))}clone(){return new $r(this.direction.clone(),this.magnitude.clone())}reset(){}}class ei{constructor(e,t){this.center=e,this.magnitude=t,this.type="GravityForce",this.temp=new z}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 ei(new z(e.center[0],e.center[1],e.center[2]),e.magnitude)}clone(){return new ei(this.center.clone(),this.magnitude)}reset(){}}class ti{constructor(e){this.angle=e,this.type="ChangeEmitDirection",this._temp=new z,this._q=new j,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 ti(D(e.angle))}clone(){return new ti(this.angle)}reset(){}}var Wt;(function(n){n[n.Death=0]="Death",n[n.Birth=1]="Birth",n[n.Frame=2]="Frame"})(Wt||(Wt={}));class ri{constructor(e,t,r,i=Wt.Frame,s=1){this.particleSystem=e,this.useVelocityAsBasis=t,this.subParticleSystem=r,this.mode=i,this.emitProbability=s,this.type="EmitSubParticleSystem",this.q_=new j,this.v_=new z,this.v2_=new z,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(e){}update(e,t){this.mode===Wt.Frame?this.emit(e,t):this.mode===Wt.Birth&&e.age===0?this.emit(e,t):this.mode===Wt.Death&&e.age+t>=e.life&&this.emit(e,t)}emit(e,t){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const r=new We;this.setMatrixFromParticle(r,e),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:r,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 r=this.subEmissions[t];r.particle&&r.particle.age<r.particle.life?this.setMatrixFromParticle(r.matrix,r.particle):r.particle=void 0,this.subParticleSystem.system.emit(e,r,r.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 ri(t,e.useVelocityAsBasis,e.subParticleSystem,e.mode,e.emitProbability)}clone(){return new ri(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(e,t){let r;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(oa).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 j?r=t.rotation:(this.q_.setFromAxisAngle(oa,t.rotation),r=this.q_),e.compose(t.position,r,bl);this.particleSystem.worldSpace||e.multiplyMatrices(this.particleSystem.emitter.matrixWorld,e)}}const Tl=.5*(Math.sqrt(3)-1),_r=(3-Math.sqrt(3))/6,Cl=1/3,$e=1/6,Pl=(Math.sqrt(5)-1)/4,le=(5-Math.sqrt(5))/20,se=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]),ee=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 aa{constructor(e=Math.random){const t=typeof e=="function"?e:kl(e);this.p=El(t),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let r=0;r<512;r++)this.perm[r]=this.p[r&255],this.permMod12[r]=this.perm[r]%12}noise2D(e,t){const r=this.permMod12,i=this.perm;let s=0,a=0,o=0;const c=(e+t)*Tl,l=Math.floor(e+c),h=Math.floor(t+c),u=(l+h)*_r,d=l-u,p=h-u,y=e-d,g=t-p;let f,m;y>g?(f=1,m=0):(f=0,m=1);const v=y-f+_r,_=g-m+_r,b=y-1+2*_r,x=g-1+2*_r,S=l&255,w=h&255;let C=.5-y*y-g*g;if(C>=0){const E=r[S+i[w]]*3;C*=C,s=C*C*(se[E]*y+se[E+1]*g)}let M=.5-v*v-_*_;if(M>=0){const E=r[S+f+i[w+m]]*3;M*=M,a=M*M*(se[E]*v+se[E+1]*_)}let T=.5-b*b-x*x;if(T>=0){const E=r[S+1+i[w+1]]*3;T*=T,o=T*T*(se[E]*b+se[E+1]*x)}return 70*(s+a+o)}noise3D(e,t,r){const i=this.permMod12,s=this.perm;let a,o,c,l;const h=(e+t+r)*Cl,u=Math.floor(e+h),d=Math.floor(t+h),p=Math.floor(r+h),y=(u+d+p)*$e,g=u-y,f=d-y,m=p-y,v=e-g,_=t-f,b=r-m;let x,S,w,C,M,T;v>=_?_>=b?(x=1,S=0,w=0,C=1,M=1,T=0):v>=b?(x=1,S=0,w=0,C=1,M=0,T=1):(x=0,S=0,w=1,C=1,M=0,T=1):_<b?(x=0,S=0,w=1,C=0,M=1,T=1):v<b?(x=0,S=1,w=0,C=0,M=1,T=1):(x=0,S=1,w=0,C=1,M=1,T=0);const E=v-x+$e,P=_-S+$e,k=b-w+$e,R=v-C+2*$e,U=_-M+2*$e,N=b-T+2*$e,G=v-1+3*$e,B=_-1+3*$e,oe=b-1+3*$e,Q=u&255,re=d&255,$=p&255;let me=.6-v*v-_*_-b*b;if(me<0)a=0;else{const W=i[Q+s[re+s[$]]]*3;me*=me,a=me*me*(se[W]*v+se[W+1]*_+se[W+2]*b)}let ye=.6-E*E-P*P-k*k;if(ye<0)o=0;else{const W=i[Q+x+s[re+S+s[$+w]]]*3;ye*=ye,o=ye*ye*(se[W]*E+se[W+1]*P+se[W+2]*k)}let ie=.6-R*R-U*U-N*N;if(ie<0)c=0;else{const W=i[Q+C+s[re+M+s[$+T]]]*3;ie*=ie,c=ie*ie*(se[W]*R+se[W+1]*U+se[W+2]*N)}let H=.6-G*G-B*B-oe*oe;if(H<0)l=0;else{const W=i[Q+1+s[re+1+s[$+1]]]*3;H*=H,l=H*H*(se[W]*G+se[W+1]*B+se[W+2]*oe)}return 32*(a+o+c+l)}noise4D(e,t,r,i){const s=this.perm;let a,o,c,l,h;const u=(e+t+r+i)*Pl,d=Math.floor(e+u),p=Math.floor(t+u),y=Math.floor(r+u),g=Math.floor(i+u),f=(d+p+y+g)*le,m=d-f,v=p-f,_=y-f,b=g-f,x=e-m,S=t-v,w=r-_,C=i-b;let M=0,T=0,E=0,P=0;x>S?M++:T++,x>w?M++:E++,x>C?M++:P++,S>w?T++:E++,S>C?T++:P++,w>C?E++:P++;const k=M>=3?1:0,R=T>=3?1:0,U=E>=3?1:0,N=P>=3?1:0,G=M>=2?1:0,B=T>=2?1:0,oe=E>=2?1:0,Q=P>=2?1:0,re=M>=1?1:0,$=T>=1?1:0,me=E>=1?1:0,ye=P>=1?1:0,ie=x-k+le,H=S-R+le,W=w-U+le,rt=C-N+le,ze=x-G+2*le,Xe=S-B+2*le,qe=w-oe+2*le,be=C-Q+2*le,Be=x-re+3*le,xe=S-$+3*le,it=w-me+3*le,nt=C-ye+3*le,Y=x-1+4*le,He=S-1+4*le,st=w-1+4*le,Tt=C-1+4*le,ot=d&255,at=p&255,ct=y&255,lt=g&255;let Ie=.6-x*x-S*S-w*w-C*C;if(Ie<0)a=0;else{const V=s[ot+s[at+s[ct+s[lt]]]]%32*4;Ie*=Ie,a=Ie*Ie*(ee[V]*x+ee[V+1]*S+ee[V+2]*w+ee[V+3]*C)}let Ue=.6-ie*ie-H*H-W*W-rt*rt;if(Ue<0)o=0;else{const V=s[ot+k+s[at+R+s[ct+U+s[lt+N]]]]%32*4;Ue*=Ue,o=Ue*Ue*(ee[V]*ie+ee[V+1]*H+ee[V+2]*W+ee[V+3]*rt)}let Ne=.6-ze*ze-Xe*Xe-qe*qe-be*be;if(Ne<0)c=0;else{const V=s[ot+G+s[at+B+s[ct+oe+s[lt+Q]]]]%32*4;Ne*=Ne,c=Ne*Ne*(ee[V]*ze+ee[V+1]*Xe+ee[V+2]*qe+ee[V+3]*be)}let De=.6-Be*Be-xe*xe-it*it-nt*nt;if(De<0)l=0;else{const V=s[ot+re+s[at+$+s[ct+me+s[lt+ye]]]]%32*4;De*=De,l=De*De*(ee[V]*Be+ee[V+1]*xe+ee[V+2]*it+ee[V+3]*nt)}let Fe=.6-Y*Y-He*He-st*st-Tt*Tt;if(Fe<0)h=0;else{const V=s[ot+1+s[at+1+s[ct+1+s[lt+1]]]]%32*4;Fe*=Fe,h=Fe*Fe*(ee[V]*Y+ee[V+1]*He+ee[V+2]*st+ee[V+3]*Tt)}return 27*(a+o+c+l+h)}}function El(n){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let t=0;t<255;t++){const r=t+~~(n()*(256-t)),i=e[t];e[t]=e[r],e[r]=i}return e}function kl(n){let e=0,t=0,r=0,i=1;const s=Al();return e=s(" "),t=s(" "),r=s(" "),e-=s(n),e<0&&(e+=1),t-=s(n),t<0&&(t+=1),r-=s(n),r<0&&(r+=1),function(){const a=2091639*e+i*23283064365386963e-26;return e=t,t=r,r=a-(i=a|0)}}function Al(){let n=4022871197;return function(e){e=e.toString();for(let t=0;t<e.length;t++){n+=e.charCodeAt(t);let r=.02519603282416938*n;n=r>>>0,r-=n,r*=n,n=r>>>0,r-=n,n+=r*4294967296}return(n>>>0)*23283064365386963e-26}}class ii{constructor(e,t,r,i){this.scale=e,this.octaves=t,this.velocityMultiplier=r,this.timeScale=i,this.type="TurbulenceField",this.generator=new aa,this.timeOffset=new z,this.temp=new z,this.temp2=new z,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 r=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(r*a,i*a,s*a,this.timeOffset.x*a)/a,this.generator.noise4D(r*a,i*a,s*a,this.timeOffset.y*a)/a,this.generator.noise4D(r*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 ii(new z(e.scale[0],e.scale[1],e.scale[2]),e.octaves,new z(e.velocityMultiplier[0],e.velocityMultiplier[1],e.velocityMultiplier[2]),new z(e.timeScale[0],e.timeScale[1],e.timeScale[2]))}clone(){return new ii(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const et=[],Un=new z,Nn=new j;class ni{constructor(e,t,r=new L(1),i=new L(0)){if(this.frequency=e,this.power=t,this.positionAmount=r,this.rotationAmount=i,this.type="Noise",this.duration=0,et.length===0)for(let s=0;s<100;s++)et.push(new aa)}initialize(e){e.lastPosNoise=new z,typeof e.rotation=="number"?e.lastRotNoise=0:e.lastRotNoise=new j,e.generatorIndex=[Ci(0,100),Ci(0,100),Ci(0,100),Ci(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 r=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),Un.set(et[e.generatorIndex[0]].noise2D(0,e.age*r)*i*s,et[e.generatorIndex[1]].noise2D(0,e.age*r)*i*s,et[e.generatorIndex[2]].noise2D(0,e.age*r)*i*s),e.position.add(Un),e.lastPosNoise.copy(Un)),a>0&&e.lastRotNoise!==void 0&&(typeof e.rotation=="number"?(e.rotation-=e.lastRotNoise,e.rotation+=et[e.generatorIndex[3]].noise2D(0,e.age*r)*Math.PI*i*a):(e.lastRotNoise.invert(),e.rotation.multiply(e.lastRotNoise),Nn.set(et[e.generatorIndex[0]].noise2D(0,e.age*r)*i*a,et[e.generatorIndex[1]].noise2D(0,e.age*r)*i*a,et[e.generatorIndex[2]].noise2D(0,e.age*r)*i*a,et[e.generatorIndex[3]].noise2D(0,e.age*r)*i*a).normalize(),e.rotation.multiply(Nn),e.lastRotNoise.copy(Nn)))}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 ni(D(e.frequency),D(e.power),D(e.positionAmount),D(e.rotationAmount))}clone(){return new ni(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class si{constructor(e,t){this.color=e,this.speedRange=t,this.type="ColorBySpeed"}initialize(e){this.color.startGen(e.memory)}update(e,t){const r=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(e.memory,e.color,r),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 si(zn(e.color),Dt.fromJSON(e.speedRange))}clone(){return new si(this.color.clone(),this.speedRange.clone())}reset(){}}class oi{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 Ft?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 oi(Ti(e.size),Dt.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new oi(this.size.clone(),this.speedRange.clone())}reset(){}}class ai{constructor(e,t){this.angularVelocity=e,this.speedRange=t,this.type="RotationBySpeed",this.tempQuat=new j}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){if(typeof e.rotation=="number"){const r=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);e.rotation+=t*this.angularVelocity.genValue(e.memory,r)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new ai(D(e.angularVelocity),Dt.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new ai(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class ci{initialize(e){this.speed.startGen(e.memory)}constructor(e,t){this.speed=e,this.dampen=t,this.type="LimitSpeedOverLife"}update(e,t){let r=e.velocity.length(),i=this.speed.genValue(e.memory,e.age/e.life);if(r>i){const s=(r-i)/r;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 ci(D(e.speed),e.dampen)}frameUpdate(e){}clone(){return new ci(this.speed.clone(),this.dampen)}reset(){}}const Ai={ApplyForce:{type:"ApplyForce",constructor:$r,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:$r.fromJSON},Noise:{type:"Noise",constructor:ni,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:ni.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:ii,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:ii.fromJSON},GravityForce:{type:"GravityForce",constructor:ei,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:ei.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:Gr,params:[["color",["colorFunc"]]],loadJSON:Gr.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Wr,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Wr.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Xr,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Xr.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Hr,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Hr.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:si,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:si.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:ai,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:ai.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:oi,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:oi.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Yr,params:[["speed",["value","valueFunc"]]],loadJSON:Yr.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:Zr,params:[["frame",["value","valueFunc"]]],loadJSON:Zr.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:qr,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:qr.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:Qr,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:Qr.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Kr,params:[["width",["value","valueFunc"]]],loadJSON:Kr.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:ti,params:[["angle",["value"]]],loadJSON:ti.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:ri,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:ri.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:ci,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:ci.fromJSON}};function Rl(n,e){return Ai[n.type]?Ai[n.type].loadJSON(n,e):null}const Ol=[];function zl(n){if(!Ol.find(e=>e.id===n.id)){for(const e of n.emitterShapes)Bn[e.type]||(Bn[e.type]=e);for(const e of n.behaviors)Ai[e.type]||(Ai[e.type]=e)}}var Bl=`
|
|
83
|
+
*/var An,Qo;function il(){if(Qo)return An;Qo=1,An=function(t){return t!=null&&(n(t)||e(t)||!!t._isBuffer)};function n(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"&&n(t.slice(0,0))}return An}var $o;function nl(){return $o||($o=1,function(){var n=rl(),e=Ko().utf8,t=il(),r=Ko().bin,i=function(s,a){s.constructor==String?a&&a.encoding==="binary"?s=r.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=n.bytesToWords(s),c=s.length*8,l=1732584193,h=-271733879,u=-1732584194,d=271733878,p=0;p<o.length;p++)o[p]=(o[p]<<8|o[p]>>>24)&16711935|(o[p]<<24|o[p]>>>8)&4278255360;o[c>>>5]|=128<<c%32,o[(c+64>>>9<<4)+14]=c;for(var y=i._ff,g=i._gg,f=i._hh,m=i._ii,p=0;p<o.length;p+=16){var b=l,v=h,x=u,_=d;l=y(l,h,u,d,o[p+0],7,-680876936),d=y(d,l,h,u,o[p+1],12,-389564586),u=y(u,d,l,h,o[p+2],17,606105819),h=y(h,u,d,l,o[p+3],22,-1044525330),l=y(l,h,u,d,o[p+4],7,-176418897),d=y(d,l,h,u,o[p+5],12,1200080426),u=y(u,d,l,h,o[p+6],17,-1473231341),h=y(h,u,d,l,o[p+7],22,-45705983),l=y(l,h,u,d,o[p+8],7,1770035416),d=y(d,l,h,u,o[p+9],12,-1958414417),u=y(u,d,l,h,o[p+10],17,-42063),h=y(h,u,d,l,o[p+11],22,-1990404162),l=y(l,h,u,d,o[p+12],7,1804603682),d=y(d,l,h,u,o[p+13],12,-40341101),u=y(u,d,l,h,o[p+14],17,-1502002290),h=y(h,u,d,l,o[p+15],22,1236535329),l=g(l,h,u,d,o[p+1],5,-165796510),d=g(d,l,h,u,o[p+6],9,-1069501632),u=g(u,d,l,h,o[p+11],14,643717713),h=g(h,u,d,l,o[p+0],20,-373897302),l=g(l,h,u,d,o[p+5],5,-701558691),d=g(d,l,h,u,o[p+10],9,38016083),u=g(u,d,l,h,o[p+15],14,-660478335),h=g(h,u,d,l,o[p+4],20,-405537848),l=g(l,h,u,d,o[p+9],5,568446438),d=g(d,l,h,u,o[p+14],9,-1019803690),u=g(u,d,l,h,o[p+3],14,-187363961),h=g(h,u,d,l,o[p+8],20,1163531501),l=g(l,h,u,d,o[p+13],5,-1444681467),d=g(d,l,h,u,o[p+2],9,-51403784),u=g(u,d,l,h,o[p+7],14,1735328473),h=g(h,u,d,l,o[p+12],20,-1926607734),l=f(l,h,u,d,o[p+5],4,-378558),d=f(d,l,h,u,o[p+8],11,-2022574463),u=f(u,d,l,h,o[p+11],16,1839030562),h=f(h,u,d,l,o[p+14],23,-35309556),l=f(l,h,u,d,o[p+1],4,-1530992060),d=f(d,l,h,u,o[p+4],11,1272893353),u=f(u,d,l,h,o[p+7],16,-155497632),h=f(h,u,d,l,o[p+10],23,-1094730640),l=f(l,h,u,d,o[p+13],4,681279174),d=f(d,l,h,u,o[p+0],11,-358537222),u=f(u,d,l,h,o[p+3],16,-722521979),h=f(h,u,d,l,o[p+6],23,76029189),l=f(l,h,u,d,o[p+9],4,-640364487),d=f(d,l,h,u,o[p+12],11,-421815835),u=f(u,d,l,h,o[p+15],16,530742520),h=f(h,u,d,l,o[p+2],23,-995338651),l=m(l,h,u,d,o[p+0],6,-198630844),d=m(d,l,h,u,o[p+7],10,1126891415),u=m(u,d,l,h,o[p+14],15,-1416354905),h=m(h,u,d,l,o[p+5],21,-57434055),l=m(l,h,u,d,o[p+12],6,1700485571),d=m(d,l,h,u,o[p+3],10,-1894986606),u=m(u,d,l,h,o[p+10],15,-1051523),h=m(h,u,d,l,o[p+1],21,-2054922799),l=m(l,h,u,d,o[p+8],6,1873313359),d=m(d,l,h,u,o[p+15],10,-30611744),u=m(u,d,l,h,o[p+6],15,-1560198380),h=m(h,u,d,l,o[p+13],21,1309151649),l=m(l,h,u,d,o[p+4],6,-145523070),d=m(d,l,h,u,o[p+11],10,-1120210379),u=m(u,d,l,h,o[p+2],15,718787259),h=m(h,u,d,l,o[p+9],21,-343485551),l=l+b>>>0,h=h+v>>>0,u=u+x>>>0,d=d+_>>>0}return n.endian([l,h,u,d])};i._ff=function(s,a,o,c,l,h,u){var d=s+(a&o|~a&c)+(l>>>0)+u;return(d<<h|d>>>32-h)+a},i._gg=function(s,a,o,c,l,h,u){var d=s+(a&c|o&~c)+(l>>>0)+u;return(d<<h|d>>>32-h)+a},i._hh=function(s,a,o,c,l,h,u){var d=s+(a^o^c)+(l>>>0)+u;return(d<<h|d>>>32-h)+a},i._ii=function(s,a,o,c,l,h,u){var d=s+(o^(a|~c))+(l>>>0)+u;return(d<<h|d>>>32-h)+a},i._blocksize=16,i._digestsize=16,Xo.exports=function(s,a){if(s==null)throw new Error("Illegal argument "+s);var o=n.wordsToBytes(i(s,a));return a&&a.asBytes?o:a&&a.asString?r.bytesToString(o):n.bytesToHex(o)}}()),Xo.exports}var sl=nl();const ol=fi(sl),pe=["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 ea=1234567;const ta=Math.PI/180,ra=180/Math.PI;function al(){const n=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,r=Math.random()*4294967295|0;return(pe[n&255]+pe[n>>8&255]+pe[n>>16&255]+pe[n>>24&255]+"-"+pe[e&255]+pe[e>>8&255]+"-"+pe[e>>16&15|64]+pe[e>>24&255]+"-"+pe[t&63|128]+pe[t>>8&255]+"-"+pe[t>>16&255]+pe[t>>24&255]+pe[r&255]+pe[r>>8&255]+pe[r>>16&255]+pe[r>>24&255]).toLowerCase()}function $e(n,e,t){return Math.max(e,Math.min(t,n))}function ia(n,e){return(n%e+e)%e}function cl(n,e,t,r,i){return r+(n-e)*(i-r)/(t-e)}function ll(n,e,t){return n!==e?(t-n)/(e-n):0}function na(n,e,t){return(1-t)*n+t*e}function hl(n,e,t,r){return na(n,e,1-Math.exp(-t*r))}function ul(n,e=1){return e-Math.abs(ia(n,e*2)-e)}function dl(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*(3-2*n))}function pl(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*n*(n*(n*6-15)+10))}function fl(n,e){return n+Math.floor(Math.random()*(e-n+1))}function ml(n,e){return n+Math.random()*(e-n)}function yl(n){return n*(.5-Math.random())}function gl(n){n!==void 0&&(ea=n);let e=ea+=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 vl(n){return n*ta}function bl(n){return n*ra}function _l(n){return(n&n-1)===0&&n!==0}function xl(n){return Math.pow(2,Math.ceil(Math.log(n)/Math.LN2))}function Sl(n){return Math.pow(2,Math.floor(Math.log(n)/Math.LN2))}function wl(n,e,t,r,i){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+r)/2),h=a((e+r)/2),u=s((e-r)/2),d=a((e-r)/2),p=s((r-e)/2),y=a((r-e)/2);switch(i){case"XYX":n.set(o*h,c*u,c*d,o*l);break;case"YZY":n.set(c*d,o*h,c*u,o*l);break;case"ZXZ":n.set(c*u,c*d,o*h,o*l);break;case"XZX":n.set(o*h,c*y,c*p,o*l);break;case"YXY":n.set(c*p,o*h,c*y,o*l);break;case"ZYZ":n.set(c*y,c*p,o*h,o*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function Ml(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return n/4294967295;case Uint16Array:return n/65535;case Uint8Array:return n/255;case Int32Array:return Math.max(n/2147483647,-1);case Int16Array:return Math.max(n/32767,-1);case Int8Array:return Math.max(n/127,-1);default:throw new Error("Invalid component type.")}}function Tl(n,e){switch(e.constructor){case Float32Array:return n;case Uint32Array:return Math.round(n*4294967295);case Uint16Array:return Math.round(n*65535);case Uint8Array:return Math.round(n*255);case Int32Array:return Math.round(n*2147483647);case Int16Array:return Math.round(n*32767);case Int8Array:return Math.round(n*127);default:throw new Error("Invalid component type.")}}const Wt={DEG2RAD:ta,RAD2DEG:ra,generateUUID:al,clamp:$e,euclideanModulo:ia,mapLinear:cl,inverseLerp:ll,lerp:na,damp:hl,pingpong:ul,smoothstep:dl,smootherstep:pl,randInt:fl,randFloat:ml,randFloatSpread:yl,seededRandom:gl,degToRad:vl,radToDeg:bl,isPowerOfTwo:_l,ceilPowerOfTwo:xl,floorPowerOfTwo:Sl,setQuaternionFromProperEuler:wl,normalize:Tl,denormalize:Ml};class j{constructor(e=0,t=0,r=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=r,this._w=i}static slerpFlat(e,t,r,i,s,a,o){let c=r[i+0],l=r[i+1],h=r[i+2],u=r[i+3];const d=s[a+0],p=s[a+1],y=s[a+2],g=s[a+3];if(o===0){e[t+0]=c,e[t+1]=l,e[t+2]=h,e[t+3]=u;return}if(o===1){e[t+0]=d,e[t+1]=p,e[t+2]=y,e[t+3]=g;return}if(u!==g||c!==d||l!==p||h!==y){let f=1-o;const m=c*d+l*p+h*y+u*g,b=m>=0?1:-1,v=1-m*m;if(v>Number.EPSILON){const _=Math.sqrt(v),S=Math.atan2(_,m*b);f=Math.sin(f*S)/_,o=Math.sin(o*S)/_}const x=o*b;if(c=c*f+d*x,l=l*f+p*x,h=h*f+y*x,u=u*f+g*x,f===1-o){const _=1/Math.sqrt(c*c+l*l+h*h+u*u);c*=_,l*=_,h*=_,u*=_}}e[t]=c,e[t+1]=l,e[t+2]=h,e[t+3]=u}static multiplyQuaternionsFlat(e,t,r,i,s,a){const o=r[i],c=r[i+1],l=r[i+2],h=r[i+3],u=s[a],d=s[a+1],p=s[a+2],y=s[a+3];return e[t]=o*y+h*u+c*p-l*d,e[t+1]=c*y+h*d+l*u-o*p,e[t+2]=l*y+h*p+o*d-c*u,e[t+3]=h*y-o*u-c*d-l*p,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,r,i){return this._x=e,this._y=t,this._z=r,this._w=i,this._onChangeCallback(),this}clone(){return new j(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const r=e._x,i=e._y,s=e._z,a=e._order,o=Math.cos,c=Math.sin,l=o(r/2),h=o(i/2),u=o(s/2),d=c(r/2),p=c(i/2),y=c(s/2);switch(a){case"XYZ":this._x=d*h*u+l*p*y,this._y=l*p*u-d*h*y,this._z=l*h*y+d*p*u,this._w=l*h*u-d*p*y;break;case"YXZ":this._x=d*h*u+l*p*y,this._y=l*p*u-d*h*y,this._z=l*h*y-d*p*u,this._w=l*h*u+d*p*y;break;case"ZXY":this._x=d*h*u-l*p*y,this._y=l*p*u+d*h*y,this._z=l*h*y+d*p*u,this._w=l*h*u-d*p*y;break;case"ZYX":this._x=d*h*u-l*p*y,this._y=l*p*u+d*h*y,this._z=l*h*y-d*p*u,this._w=l*h*u+d*p*y;break;case"YZX":this._x=d*h*u+l*p*y,this._y=l*p*u+d*h*y,this._z=l*h*y-d*p*u,this._w=l*h*u-d*p*y;break;case"XZY":this._x=d*h*u-l*p*y,this._y=l*p*u-d*h*y,this._z=l*h*y+d*p*u,this._w=l*h*u+d*p*y;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const r=t/2,i=Math.sin(r);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(r),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,r=t[0],i=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],h=t[6],u=t[10],d=r+o+u;if(d>0){const p=.5/Math.sqrt(d+1);this._w=.25/p,this._x=(h-c)*p,this._y=(s-l)*p,this._z=(a-i)*p}else if(r>o&&r>u){const p=2*Math.sqrt(1+r-o-u);this._w=(h-c)/p,this._x=.25*p,this._y=(i+a)/p,this._z=(s+l)/p}else if(o>u){const p=2*Math.sqrt(1+o-r-u);this._w=(s-l)/p,this._x=(i+a)/p,this._y=.25*p,this._z=(c+h)/p}else{const p=2*Math.sqrt(1+u-r-o);this._w=(a-i)/p,this._x=(s+l)/p,this._y=(c+h)/p,this._z=.25*p}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let r=e.dot(t)+1;return r<Number.EPSILON?(r=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=r):(this._x=0,this._y=-e.z,this._z=e.y,this._w=r)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=r),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs($e(this.dot(e),-1,1)))}rotateTowards(e,t){const r=this.angleTo(e);if(r===0)return this;const i=Math.min(1,t/r);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 r=e._x,i=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,h=t._w;return this._x=r*h+a*o+i*l-s*c,this._y=i*h+a*c+s*o-r*l,this._z=s*h+a*l+r*c-i*o,this._w=a*h-r*o-i*c-s*l,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const r=this._x,i=this._y,s=this._z,a=this._w;let o=a*e._w+r*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=r,this._y=i,this._z=s,this;const c=1-o*o;if(c<=Number.EPSILON){const p=1-t;return this._w=p*a+t*this._w,this._x=p*r+t*this._x,this._y=p*i+t*this._y,this._z=p*s+t*this._z,this.normalize(),this}const l=Math.sqrt(c),h=Math.atan2(l,o),u=Math.sin((1-t)*h)/l,d=Math.sin(t*h)/l;return this._w=a*u+this._w*d,this._x=r*u+this._x*d,this._y=i*u+this._y*d,this._z=s*u+this._z*d,this._onChangeCallback(),this}slerpQuaternions(e,t,r){return this.copy(e).slerp(t,r)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),r=Math.random(),i=Math.sqrt(1-r),s=Math.sqrt(r);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 z{constructor(e=0,t=0,r=0){this.isVector3=!0,z.prototype.isVector3=!0,this.x=e,this.y=t,this.z=r}set(e,t,r){return r===void 0&&(r=this.z),this.x=e,this.y=t,this.z=r,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new z(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(sa.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(sa.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,r=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*r+s[6]*i,this.y=s[1]*t+s[4]*r+s[7]*i,this.z=s[2]*t+s[5]*r+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,r=this.y,i=this.z,s=e.elements,a=1/(s[3]*t+s[7]*r+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*r+s[8]*i+s[12])*a,this.y=(s[1]*t+s[5]*r+s[9]*i+s[13])*a,this.z=(s[2]*t+s[6]*r+s[10]*i+s[14])*a,this}applyQuaternion(e){const t=this.x,r=this.y,i=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*i-o*r),h=2*(o*t-s*i),u=2*(s*r-a*t);return this.x=t+c*l+a*u-o*h,this.y=r+c*h+o*l-s*u,this.z=i+c*u+s*h-a*l,this}transformDirection(e){const t=this.x,r=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*r+s[8]*i,this.y=s[1]*t+s[5]*r+s[9]*i,this.z=s[2]*t+s[6]*r+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 r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const r=e.x,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-r*c,this.z=r*o-i*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const r=e.dot(this)/t;return this.copy(e).multiplyScalar(r)}projectOnPlane(e){return On.copy(this).projectOnVector(e),this.sub(On)}reflect(e){return this.sub(On.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const r=this.dot(e)/t;return Math.acos($e(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,r=this.y-e.y,i=this.z-e.z;return t*t+r*r+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,r){const i=Math.sin(t)*e;return this.x=i*Math.sin(r),this.y=Math.cos(t)*e,this.z=i*Math.cos(r),this}setFromCylindricalCoords(e,t,r){return this.x=e*Math.sin(t),this.y=r,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),r=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=r,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,r=Math.sqrt(1-t*t);return this.x=r*Math.cos(e),this.y=t,this.z=r*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 On=new z,sa=new j,Mi=2e3,oa=2001;class He{constructor(e,t,r,i,s,a,o,c,l,h,u,d,p,y,g,f){this.isMatrix4=!0,He.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,r,i,s,a,o,c,l,h,u,d,p,y,g,f)}extractPosition(e){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(e)}multiplyToArray(e,t,r){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(e){return this.makeRotationFromQuaternion(e)}set(e,t,r,i,s,a,o,c,l,h,u,d,p,y,g,f){const m=this.elements;return m[0]=e,m[4]=t,m[8]=r,m[12]=i,m[1]=s,m[5]=a,m[9]=o,m[13]=c,m[2]=l,m[6]=h,m[10]=u,m[14]=d,m[3]=p,m[7]=y,m[11]=g,m[15]=f,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 He().fromArray(this.elements)}copy(e){const t=this.elements,r=e.elements;return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],t[9]=r[9],t[10]=r[10],t[11]=r[11],t[12]=r[12],t[13]=r[13],t[14]=r[14],t[15]=r[15],this}copyPosition(e){const t=this.elements,r=e.elements;return t[12]=r[12],t[13]=r[13],t[14]=r[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,r){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),r.setFromMatrixColumn(this,2),this}makeBasis(e,t,r){return this.set(e.x,t.x,r.x,0,e.y,t.y,r.y,0,e.z,t.z,r.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,r=e.elements,i=1/Ht.setFromMatrixColumn(e,0).length(),s=1/Ht.setFromMatrixColumn(e,1).length(),a=1/Ht.setFromMatrixColumn(e,2).length();return t[0]=r[0]*i,t[1]=r[1]*i,t[2]=r[2]*i,t[3]=0,t[4]=r[4]*s,t[5]=r[5]*s,t[6]=r[6]*s,t[7]=0,t[8]=r[8]*a,t[9]=r[9]*a,t[10]=r[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,r=e.x,i=e.y,s=e.z,a=Math.cos(r),o=Math.sin(r),c=Math.cos(i),l=Math.sin(i),h=Math.cos(s),u=Math.sin(s);if(e.order==="XYZ"){const d=a*h,p=a*u,y=o*h,g=o*u;t[0]=c*h,t[4]=-c*u,t[8]=l,t[1]=p+y*l,t[5]=d-g*l,t[9]=-o*c,t[2]=g-d*l,t[6]=y+p*l,t[10]=a*c}else if(e.order==="YXZ"){const d=c*h,p=c*u,y=l*h,g=l*u;t[0]=d+g*o,t[4]=y*o-p,t[8]=a*l,t[1]=a*u,t[5]=a*h,t[9]=-o,t[2]=p*o-y,t[6]=g+d*o,t[10]=a*c}else if(e.order==="ZXY"){const d=c*h,p=c*u,y=l*h,g=l*u;t[0]=d-g*o,t[4]=-a*u,t[8]=y+p*o,t[1]=p+y*o,t[5]=a*h,t[9]=g-d*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const d=a*h,p=a*u,y=o*h,g=o*u;t[0]=c*h,t[4]=y*l-p,t[8]=d*l+g,t[1]=c*u,t[5]=g*l+d,t[9]=p*l-y,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const d=a*c,p=a*l,y=o*c,g=o*l;t[0]=c*h,t[4]=g-d*u,t[8]=y*u+p,t[1]=u,t[5]=a*h,t[9]=-o*h,t[2]=-l*h,t[6]=p*u+y,t[10]=d-g*u}else if(e.order==="XZY"){const d=a*c,p=a*l,y=o*c,g=o*l;t[0]=c*h,t[4]=-u,t[8]=l*h,t[1]=d*u+g,t[5]=a*h,t[9]=p*u-y,t[2]=y*u-p,t[6]=o*h,t[10]=g*u+d}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(Cl,e,Pl)}lookAt(e,t,r){const i=this.elements;return Ce.subVectors(e,t),Ce.lengthSq()===0&&(Ce.z=1),Ce.normalize(),bt.crossVectors(r,Ce),bt.lengthSq()===0&&(Math.abs(r.z)===1?Ce.x+=1e-4:Ce.z+=1e-4,Ce.normalize(),bt.crossVectors(r,Ce)),bt.normalize(),Ti.crossVectors(Ce,bt),i[0]=bt.x,i[4]=Ti.x,i[8]=Ce.x,i[1]=bt.y,i[5]=Ti.y,i[9]=Ce.y,i[2]=bt.z,i[6]=Ti.z,i[10]=Ce.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const r=e.elements,i=t.elements,s=this.elements,a=r[0],o=r[4],c=r[8],l=r[12],h=r[1],u=r[5],d=r[9],p=r[13],y=r[2],g=r[6],f=r[10],m=r[14],b=r[3],v=r[7],x=r[11],_=r[15],S=i[0],w=i[4],C=i[8],M=i[12],T=i[1],E=i[5],P=i[9],k=i[13],A=i[2],N=i[6],U=i[10],G=i[14],B=i[3],oe=i[7],K=i[11],re=i[15];return s[0]=a*S+o*T+c*A+l*B,s[4]=a*w+o*E+c*N+l*oe,s[8]=a*C+o*P+c*U+l*K,s[12]=a*M+o*k+c*G+l*re,s[1]=h*S+u*T+d*A+p*B,s[5]=h*w+u*E+d*N+p*oe,s[9]=h*C+u*P+d*U+p*K,s[13]=h*M+u*k+d*G+p*re,s[2]=y*S+g*T+f*A+m*B,s[6]=y*w+g*E+f*N+m*oe,s[10]=y*C+g*P+f*U+m*K,s[14]=y*M+g*k+f*G+m*re,s[3]=b*S+v*T+x*A+_*B,s[7]=b*w+v*E+x*N+_*oe,s[11]=b*C+v*P+x*U+_*K,s[15]=b*M+v*k+x*G+_*re,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],r=e[4],i=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],h=e[2],u=e[6],d=e[10],p=e[14],y=e[3],g=e[7],f=e[11],m=e[15];return y*(+s*c*u-i*l*u-s*o*d+r*l*d+i*o*p-r*c*p)+g*(+t*c*p-t*l*d+s*a*d-i*a*p+i*l*h-s*c*h)+f*(+t*l*u-t*o*p-s*a*u+r*a*p+s*o*h-r*l*h)+m*(-i*o*h-t*c*u+t*o*d+i*a*u-r*a*d+r*c*h)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,r){const 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]=r),this}invert(){const e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8],u=e[9],d=e[10],p=e[11],y=e[12],g=e[13],f=e[14],m=e[15],b=u*f*l-g*d*l+g*c*p-o*f*p-u*c*m+o*d*m,v=y*d*l-h*f*l-y*c*p+a*f*p+h*c*m-a*d*m,x=h*g*l-y*u*l+y*o*p-a*g*p-h*o*m+a*u*m,_=y*u*c-h*g*c-y*o*d+a*g*d+h*o*f-a*u*f,S=t*b+r*v+i*x+s*_;if(S===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const w=1/S;return e[0]=b*w,e[1]=(g*d*s-u*f*s-g*i*p+r*f*p+u*i*m-r*d*m)*w,e[2]=(o*f*s-g*c*s+g*i*l-r*f*l-o*i*m+r*c*m)*w,e[3]=(u*c*s-o*d*s-u*i*l+r*d*l+o*i*p-r*c*p)*w,e[4]=v*w,e[5]=(h*f*s-y*d*s+y*i*p-t*f*p-h*i*m+t*d*m)*w,e[6]=(y*c*s-a*f*s-y*i*l+t*f*l+a*i*m-t*c*m)*w,e[7]=(a*d*s-h*c*s+h*i*l-t*d*l-a*i*p+t*c*p)*w,e[8]=x*w,e[9]=(y*u*s-h*g*s-y*r*p+t*g*p+h*r*m-t*u*m)*w,e[10]=(a*g*s-y*o*s+y*r*l-t*g*l-a*r*m+t*o*m)*w,e[11]=(h*o*s-a*u*s-h*r*l+t*u*l+a*r*p-t*o*p)*w,e[12]=_*w,e[13]=(h*g*i-y*u*i+y*r*d-t*g*d-h*r*f+t*u*f)*w,e[14]=(y*o*i-a*g*i-y*r*c+t*g*c+a*r*f-t*o*f)*w,e[15]=(a*u*i-h*o*i+h*r*c-t*u*c-a*r*d+t*o*d)*w,this}scale(e){const t=this.elements,r=e.x,i=e.y,s=e.z;return t[0]*=r,t[4]*=i,t[8]*=s,t[1]*=r,t[5]*=i,t[9]*=s,t[2]*=r,t[6]*=i,t[10]*=s,t[3]*=r,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],r=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,r,i))}makeTranslation(e,t,r){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,r,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),r=Math.sin(e);return this.set(1,0,0,0,0,t,-r,0,0,r,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,0,r,0,0,1,0,0,-r,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,-r,0,0,r,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const r=Math.cos(t),i=Math.sin(t),s=1-r,a=e.x,o=e.y,c=e.z,l=s*a,h=s*o;return this.set(l*a+r,l*o-i*c,l*c+i*o,0,l*o+i*c,h*o+r,h*c-i*a,0,l*c-i*o,h*c+i*a,s*c*c+r,0,0,0,0,1),this}makeScale(e,t,r){return this.set(e,0,0,0,0,t,0,0,0,0,r,0,0,0,0,1),this}makeShear(e,t,r,i,s,a){return this.set(1,r,s,0,e,1,a,0,t,i,1,0,0,0,0,1),this}compose(e,t,r){const i=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,h=a+a,u=o+o,d=s*l,p=s*h,y=s*u,g=a*h,f=a*u,m=o*u,b=c*l,v=c*h,x=c*u,_=r.x,S=r.y,w=r.z;return i[0]=(1-(g+m))*_,i[1]=(p+x)*_,i[2]=(y-v)*_,i[3]=0,i[4]=(p-x)*S,i[5]=(1-(d+m))*S,i[6]=(f+b)*S,i[7]=0,i[8]=(y+v)*w,i[9]=(f-b)*w,i[10]=(1-(d+g))*w,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,r){const i=this.elements;let s=Ht.set(i[0],i[1],i[2]).length();const a=Ht.set(i[4],i[5],i[6]).length(),o=Ht.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],Ge.copy(this);const c=1/s,l=1/a,h=1/o;return Ge.elements[0]*=c,Ge.elements[1]*=c,Ge.elements[2]*=c,Ge.elements[4]*=l,Ge.elements[5]*=l,Ge.elements[6]*=l,Ge.elements[8]*=h,Ge.elements[9]*=h,Ge.elements[10]*=h,t.setFromRotationMatrix(Ge),r.x=s,r.y=a,r.z=o,this}makePerspective(e,t,r,i,s,a,o=Mi){const c=this.elements,l=2*s/(t-e),h=2*s/(r-i),u=(t+e)/(t-e),d=(r+i)/(r-i);let p,y;if(o===Mi)p=-(a+s)/(a-s),y=-2*a*s/(a-s);else if(o===oa)p=-a/(a-s),y=-a*s/(a-s);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=l,c[4]=0,c[8]=u,c[12]=0,c[1]=0,c[5]=h,c[9]=d,c[13]=0,c[2]=0,c[6]=0,c[10]=p,c[14]=y,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,r,i,s,a,o=Mi){const c=this.elements,l=1/(t-e),h=1/(r-i),u=1/(a-s),d=(t+e)*l,p=(r+i)*h;let y,g;if(o===Mi)y=(a+s)*u,g=-2*u;else if(o===oa)y=s*u,g=-1*u;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-d,c[1]=0,c[5]=2*h,c[9]=0,c[13]=-p,c[2]=0,c[6]=0,c[10]=g,c[14]=-y,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,r=e.elements;for(let i=0;i<16;i++)if(t[i]!==r[i])return!1;return!0}fromArray(e,t=0){for(let r=0;r<16;r++)this.elements[r]=e[r+t];return this}toArray(e=[],t=0){const r=this.elements;return e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3],e[t+4]=r[4],e[t+5]=r[5],e[t+6]=r[6],e[t+7]=r[7],e[t+8]=r[8],e[t+9]=r[9],e[t+10]=r[10],e[t+11]=r[11],e[t+12]=r[12],e[t+13]=r[13],e[t+14]=r[14],e[t+15]=r[15],e}}const Ht=new z,Ge=new He,Cl=new z(0,0,0),Pl=new z(1,1,1),bt=new z,Ti=new z,Ce=new z,aa=new He,ca=new j;class Nr{constructor(e=0,t=0,r=0,i=Nr.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=r,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,r,i=this._order){return this._x=e,this._y=t,this._z=r,this._order=i,this._onChangeCallback(),this}clone(){return new Nr(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,r=!0){const i=e.elements,s=i[0],a=i[4],o=i[8],c=i[1],l=i[5],h=i[9],u=i[2],d=i[6],p=i[10];switch(t){case"XYZ":this._y=Math.asin($e(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-h,p),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(d,l),this._z=0);break;case"YXZ":this._x=Math.asin(-$e(h,-1,1)),Math.abs(h)<.9999999?(this._y=Math.atan2(o,p),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-u,s),this._z=0);break;case"ZXY":this._x=Math.asin($e(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,p),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-$e(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,p),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin($e(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-h,l),this._y=Math.atan2(-u,s)):(this._x=0,this._y=Math.atan2(o,p));break;case"XZY":this._z=Math.asin(-$e(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(d,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-h,p),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,r===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,r){return aa.makeRotationFromQuaternion(e),this.setFromRotationMatrix(aa,t,r)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return ca.setFromEuler(this),this.setFromQuaternion(ca,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}}Nr.DEFAULT_ORDER="XYZ";class ir{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 ir(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,r=this.y,i=e.elements;return this.x=i[0]*t+i[3]*r+i[6],this.y=i[1]*t+i[4]*r+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 r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const r=this.dot(e)/t;return Math.acos($e(r,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,r=this.y-e.y;return t*t+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}rotateAround(e,t){const r=Math.cos(t),i=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*r-a*i+e.x,this.y=s*i+a*r+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}ir.isVector2=!0;class Me{constructor(e=0,t=0,r=0,i=1){Me.prototype.isVector4=!0,this.x=e,this.y=t,this.z=r,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,r,i){return this.x=e,this.y=t,this.z=r,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 Me(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,r=this.y,i=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*r+a[8]*i+a[12]*s,this.y=a[1]*t+a[5]*r+a[9]*i+a[13]*s,this.z=a[2]*t+a[6]*r+a[10]*i+a[14]*s,this.w=a[3]*t+a[7]*r+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,r,i,s;const a=e.elements,o=a[0],c=a[4],l=a[8],h=a[1],u=a[5],d=a[9],p=a[2],y=a[6],g=a[10];if(Math.abs(c-h)<.01&&Math.abs(l-p)<.01&&Math.abs(d-y)<.01){if(Math.abs(c+h)<.1&&Math.abs(l+p)<.1&&Math.abs(d+y)<.1&&Math.abs(o+u+g-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const m=(o+1)/2,b=(u+1)/2,v=(g+1)/2,x=(c+h)/4,_=(l+p)/4,S=(d+y)/4;return m>b&&m>v?m<.01?(r=0,i=.707106781,s=.707106781):(r=Math.sqrt(m),i=x/r,s=_/r):b>v?b<.01?(r=.707106781,i=0,s=.707106781):(i=Math.sqrt(b),r=x/i,s=S/i):v<.01?(r=.707106781,i=.707106781,s=0):(s=Math.sqrt(v),r=_/s,i=S/s),this.set(r,i,s,t),this}let f=Math.sqrt((y-d)*(y-d)+(l-p)*(l-p)+(h-c)*(h-c));return Math.abs(f)<.001&&(f=1),this.x=(y-d)/f,this.y=(l-p)/f,this.z=(h-c)/f,this.w=Math.acos((o+u+g-1)/2),this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const r=this.length();return this.divideScalar(r||1).multiplyScalar(Math.max(e,Math.min(t,r)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,r){return this.x=e.x+(t.x-e.x)*r,this.y=e.y+(t.y-e.y)*r,this.z=e.z+(t.z-e.z)*r,this.w=e.w+(t.w-e.w)*r,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}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 rt{constructor(e,t,r,i,s,a,o,c,l){rt.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,r,i,s,a,o,c,l)}set(e,t,r,i,s,a,o,c,l){const h=this.elements;return h[0]=e,h[1]=i,h[2]=o,h[3]=t,h[4]=s,h[5]=c,h[6]=r,h[7]=a,h[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,r=e.elements;return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],this}extractBasis(e,t,r){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),r.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const r=e.elements,i=t.elements,s=this.elements,a=r[0],o=r[3],c=r[6],l=r[1],h=r[4],u=r[7],d=r[2],p=r[5],y=r[8],g=i[0],f=i[3],m=i[6],b=i[1],v=i[4],x=i[7],_=i[2],S=i[5],w=i[8];return s[0]=a*g+o*b+c*_,s[3]=a*f+o*v+c*S,s[6]=a*m+o*x+c*w,s[1]=l*g+h*b+u*_,s[4]=l*f+h*v+u*S,s[7]=l*m+h*x+u*w,s[2]=d*g+p*b+y*_,s[5]=d*f+p*v+y*S,s[8]=d*m+p*x+y*w,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8];return t*a*h-t*o*l-r*s*h+r*o*c+i*s*l-i*a*c}invert(){const e=this.elements,t=e[0],r=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],h=e[8],u=h*a-o*l,d=o*c-h*s,p=l*s-a*c,y=t*u+r*d+i*p;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const g=1/y;return e[0]=u*g,e[1]=(i*l-h*r)*g,e[2]=(o*r-i*a)*g,e[3]=d*g,e[4]=(h*t-i*c)*g,e[5]=(i*s-o*t)*g,e[6]=p*g,e[7]=(r*c-l*t)*g,e[8]=(a*t-r*s)*g,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,r,i,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(r*c,r*l,-r*(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(zn.makeScale(e,t)),this}rotate(e){return this.premultiply(zn.makeRotation(-e)),this}translate(e,t){return this.premultiply(zn.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),r=Math.sin(e);return this.set(t,-r,0,r,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,r=e.elements;for(let i=0;i<9;i++)if(t[i]!==r[i])return!1;return!0}fromArray(e,t=0){for(let r=0;r<9;r++)this.elements[r]=e[r+t];return this}toArray(e=[],t=0){const r=this.elements;return e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3],e[t+4]=r[4],e[t+5]=r[5],e[t+6]=r[6],e[t+7]=r[7],e[t+8]=r[8],e}clone(){return new rt().fromArray(this.elements)}}const zn=new rt;var be;(function(n){n[n.Random=0]="Random",n[n.Loop=1]="Loop",n[n.PingPong=2]="PingPong",n[n.Burst=3]="Burst"})(be||(be={}));function vr(n,e,t,r){let i;switch(be.Random===n?e=Math.random():be.Burst===n&&r.isBursting&&(e=r.burstParticleIndex/r.burstParticleCount),t>0?i=Math.floor(e/t)*t:i=e,n){case be.Loop:i=i%1;break;case be.PingPong:i=Math.abs(i%2-1);break}return i}class Dt{constructor(e,t,r,i){this.p=[e,t,r,i]}genValue(e){const t=e*e,r=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]*r}derivativeCoefficients(e){const t=[];for(let r=e,i=r.length-1;i>0;i--){const s=[];for(let a=0;a<i;a++){const o=i*(r[a+1]-r[a]);s.push(o)}t.push(s),r=s}return t}getSlope(e){const t=this.derivativeCoefficients(this.p)[0],r=1-e,i=r*r,s=r*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,r=[],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(r=[],a=0,o=t.length-1;a<o;a++)i=e*t[a]+(1-e)*t[a+1],c[s++]=i,r.push(i);t=r}return c}split(e){const t=this.hull(e);return{left:new Dt(t[0],t[4],t[7],t[9]),right:new Dt(t[9],t[8],t[6],t[3]),span:t}}clone(){return new Dt(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 Dt(e.p0,e.p1,e.p2,e.p3)}}const br=n=>({r:n.x,g:n.y,b:n.z,a:n.w}),_r=n=>new Me(n.r,n.g,n.b,n.a),El=(n,e)=>{switch(e){case"Vector3":return new z(n.x,n.y,n.z);case"Vector4":return new Me(n.x,n.y,n.z,n.w);case"Color":return new z(n.r,n.g,n.b);case"Number":return n;default:return n}},kl=(n,e)=>{switch(e){case"Vector3":return{x:n.x,y:n.y,z:n.z};case"Vector4":return{x:n.x,y:n.y,z:n.z,w:n.w};case"Color":return{r:n.x,g:n.y,b:n.z};case"Number":return n;default:return n}};class rn{constructor(e,t){this.a=e,this.b=t,this.type="value"}startGen(e){}genColor(e,t){const r=Math.random();return t.copy(this.a).lerp(this.b,r)}toJSON(){return{type:"RandomColor",a:br(this.a),b:br(this.b)}}static fromJSON(e){return new rn(_r(e.a),_r(e.b))}clone(){return new rn(this.a.clone(),this.b.clone())}}class nr{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:br(this.a),b:br(this.b)}}static fromJSON(e){return new nr(_r(e.a),_r(e.b))}clone(){return new nr(this.a.clone(),this.b.clone())}}class Tt{constructor(e,t){this.subType=t,this.type="function",this.keys=e}findKey(e){let t=0,r=0,i=this.keys.length-1;for(;r+1<i;)if(t=Math.floor((r+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))r=t+1;else return t;for(let s=r;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 r=this.findKey(t);return this.subType==="Number"?r===-1?this.keys[0][0]:r+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[r+1][0]-this.keys[r][0])*((t-this.getStartX(r))/(this.getEndX(r)-this.getStartX(r)))+this.keys[r][0]:r===-1?e.copy(this.keys[0][0]):r+1>=this.keys.length?e.copy(this.keys[this.keys.length-1][0]):e.copy(this.keys[r][0]).lerp(this.keys[r+1][0],(t-this.getStartX(r))/(this.getEndX(r)-this.getStartX(r)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([e,t])=>({value:kl(e,this.subType),pos:t}))}}static fromJSON(e){return new Tt(e.keys.map(t=>[El(t.value,e.subType),t.pos]),e.subType)}clone(){return this.subType==="Number"?new Tt(this.keys.map(([e,t])=>[e,t]),this.subType):new Tt(this.keys.map(([e,t])=>[e.clone(),t]),this.subType)}}const Ci=new z;class jt{constructor(e=[[new z(0,0,0),0],[new z(1,1,1),0]],t=[[1,0],[1,1]]){this.type="function",this.color=new Tt(e,"Color"),this.alpha=new Tt(t,"Number")}genColor(e,t,r){return this.color.genValue(Ci,r),t.set(Ci.x,Ci.y,Ci.z,this.alpha.genValue(1,r))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(e){if(e.functions){const t=e.functions.map(r=>[nr.fromJSON(r.function).a,r.start]);return e.functions.length>0&&t.push([nr.fromJSON(e.functions[e.functions.length-1].function).b,1]),new jt(t.map(r=>[new z(r[0].x,r[0].y,r[0].z),r[1]]),t.map(r=>[r[0].w,r[1]]))}else{const t=new jt;return t.alpha=Tt.fromJSON(e.alpha),t.color=Tt.fromJSON(e.color),t}}clone(){const e=new jt;return e.alpha=this.alpha.clone(),e.color=this.color.clone(),e}startGen(e){}}const Bn=new Me;class nn{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,r){return this.gradient1.genColor(e,t,r),this.gradient2.genColor(e,Bn,r),e&&e[this.indexCount]!==void 0?t.lerp(Bn,e[this.indexCount]):t.lerp(Bn,Math.random()),t}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(e){return new nn(jt.fromJSON(e.gradient1),jt.fromJSON(e.gradient2))}clone(){return new nn(this.gradient1.clone(),this.gradient2.clone())}}class Ft{constructor(e){this.color=e,this.type="value"}startGen(e){}genColor(e,t){return t.copy(this.color)}toJSON(){return{type:"ConstantColor",color:br(this.color)}}static fromJSON(e){return new Ft(_r(e.color))}clone(){return new Ft(this.color.clone())}}function In(n){switch(n.type){case"ConstantColor":return Ft.fromJSON(n);case"ColorRange":return nr.fromJSON(n);case"RandomColor":return rn.fromJSON(n);case"Gradient":return jt.fromJSON(n);case"RandomColorBetweenGradient":return nn.fromJSON(n);default:return new Ft(new Me(1,1,1,1))}}class L{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 L(e.value)}clone(){return new L(this.value)}}class Lt{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),Wt.lerp(this.a,this.b,e[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(e){return new Lt(e.a,e.b)}clone(){return new Lt(this.a,this.b)}}class Rl{constructor(){this.functions=new Array}findFunction(e){let t=0,r=0,i=this.functions.length-1;for(;r+1<i;)if(t=Math.floor((r+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))r=t+1;else return t;for(let s=r;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 r=this.findFunction(e);this.functions.splice(r+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 Ur extends Rl{constructor(e=[[new Dt(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=e}genValue(e,t=0){const r=this.findFunction(t);return r===-1?0:this.functions[r][0].genValue((t-this.getStartX(r))/(this.getEndX(r)-this.getStartX(r)))}toSVG(e,t){if(t<1)return"";let r=["M",0,this.functions[0][0].p[0]].join(" ");for(let i=1/t;i<=1;i+=1/t)r=[r,"L",i*e,this.genValue(void 0,i)].join(" ");return r}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([e,t])=>({function:e.toJSON(),start:t}))}}static fromJSON(e){return new Ur(e.functions.map(t=>[Dt.fromJSON(t.function),t.start]))}clone(){return new Ur(this.functions.map(([e,t])=>[e.clone(),t]))}startGen(e){}}function D(n){switch(n.type){case"ConstantValue":return L.fromJSON(n);case"IntervalValue":return Lt.fromJSON(n);case"PiecewiseBezier":return Ur.fromJSON(n);default:return new L(0)}}class Dr{constructor(){this.indexCount=0,this.type="rotation"}startGen(e){this.indexCount=e.length,e.push(new j);let t,r,i,s,a,o;do t=Math.random()*2-1,r=Math.random()*2-1,i=t*t+r*r;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,r,c*s,c*a)}genValue(e,t,r,i){return this.indexCount===-1&&this.startGen(e),t.copy(e[this.indexCount]),t}toJSON(){return{type:"RandomQuat"}}static fromJSON(e){return new Dr}clone(){return new Dr}}class Fr{constructor(e,t){this.axis=e,this.angle=t,this.type="rotation"}startGen(e){this.angle.startGen(e)}genValue(e,t,r,i){return t.setFromAxisAngle(this.axis,this.angle.genValue(e,i)*r)}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 Fr(new z(e.axis.x,e.axis.y,e.axis.z),D(e.angle))}clone(){return new Fr(this.axis.clone(),this.angle.clone())}}class sn{constructor(e,t,r,i){this.angleX=e,this.angleY=t,this.angleZ=r,this.type="rotation",this.eular=new Nr(0,0,0,i)}startGen(e){this.angleX.startGen(e),this.angleY.startGen(e),this.angleZ.startGen(e)}genValue(e,t,r,i){return this.eular.set(this.angleX.genValue(e,i)*r,this.angleY.genValue(e,i)*r,this.angleZ.genValue(e,i)*r),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 sn(D(e.angleX),D(e.angleY),D(e.angleZ),e.eulerOrder)}clone(){return new sn(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function la(n){switch(n.type){case"AxisAngle":return Fr.fromJSON(n);case"Euler":return sn.fromJSON(n);case"RandomQuat":return Dr.fromJSON(n);default:return new Dr}}class Vt{constructor(e,t,r){this.x=e,this.y=t,this.z=r,this.type="vec3function"}startGen(e){this.x.startGen(e),this.y.startGen(e),this.z.startGen(e)}genValue(e,t,r){return t.set(this.x.genValue(e,r),this.y.genValue(e,r),this.z.genValue(e,r))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new Vt(D(e.x),D(e.y),D(e.z))}clone(){return new Vt(this.x,this.y,this.z)}}function Al(n){switch(n.type){case"Vector3Function":return Vt.fromJSON(n);default:return new Vt(new L(0),new L(0),new L(0))}}function Pi(n){switch(n.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return D(n);case"AxisAngle":case"RandomQuat":case"Euler":return la(n);case"Vector3Function":return Al(n);default:return new L(0)}}class Lr{constructor(e={}){var t,r,i,s,a,o,c;this.type="cone",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r: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:be.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new L(1),this.memory=[]}update(e,t){be.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const r=vr(this.mode,this.currentValue,this.spread,t),i=Wt.lerp(1-this.thickness,1,Math.random()),s=r*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 Lr({radius:e.radius,arc:e.arc,thickness:e.thickness,angle:e.angle,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new Lr({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Vr{constructor(e={}){var t,r,i,s,a,o;this.type="circle",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:be.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new L(1),this.memory=[]}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const r=vr(this.mode,this.currentValue,this.spread,t),i=Wt.lerp(1-this.thickness,1,Math.random()),s=r*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 Vr({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new Vr({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function Ei(n,e){return Math.floor(Math.random()*(e-n))+n}const ki=new z(0,1,0),Ri=new z(0,0,0),Ol=new z(1,1,1),ha=new z(0,0,1);class jr{constructor(e={}){var t,r,i,s,a,o,c;this.type="donut",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r: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:be.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new L(1),this.memory=[],this._m1=new He}update(e,t){be.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const r=vr(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Wt.lerp(1-this.thickness,1,Math.random()),a=r*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 j&&(this._m1.lookAt(Ri,e.velocity,ki),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 jr({radius:e.radius,arc:e.arc,thickness:e.thickness,donutRadius:e.donutRadius,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new jr({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Jr{constructor(){this.type="point",this._m1=new He}update(e,t){}initialize(e){const t=Math.random(),r=Math.random(),i=t*Math.PI*2,s=Math.acos(2*r-1),a=Math.cbrt(Math.random()),o=Math.sin(i),c=Math.cos(i),l=Math.sin(s),h=Math.cos(s);e.velocity.x=a*l*c,e.velocity.y=a*l*o,e.velocity.z=a*h,e.velocity.multiplyScalar(e.startSpeed),e.position.setScalar(0),e.rotation instanceof j&&(this._m1.lookAt(Ri,e.position,ki),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(e){return new Jr}clone(){return new Jr}}class sr{constructor(e={}){var t,r,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:be.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new L(1),this.memory=[],this._m1=new He}update(e,t){be.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const r=vr(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Wt.lerp(1-this.thickness,1,Math.random()),a=r*this.arc,o=Math.acos(2*i-1),c=Math.sin(a),l=Math.cos(a),h=Math.sin(o),u=Math.cos(o);e.position.x=h*l,e.position.y=h*c,e.position.z=u,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof j&&(this._m1.lookAt(Ri,e.position,ki),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 sr({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new sr({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Gr{constructor(e={}){var t,r,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(r=e.arc)!==null&&r!==void 0?r:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:be.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new L(1),this.memory=[],this._m1=new He}update(e,t){be.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const r=vr(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Wt.lerp(1-this.thickness,1,Math.random()),a=r*this.arc,o=Math.acos(i),c=Math.sin(a),l=Math.cos(a),h=Math.sin(o),u=Math.cos(o);e.position.x=h*l,e.position.y=h*c,e.position.z=u,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof j&&(this._m1.lookAt(Ri,e.position,ki),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 Gr({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?D(e.speed):void 0,spread:e.spread})}clone(){return new Gr({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Wr{constructor(e={}){var t,r,i,s;this.type="grid",this.width=(t=e.width)!==null&&t!==void 0?t:1,this.height=(r=e.height)!==null&&r!==void 0?r: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),r=Math.floor(Math.random()*this.column);e.position.x=r*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 Wr(e)}clone(){return new Wr({width:this.width,height:this.height,column:this.column,row:this.row})}update(e,t){}}const Nn={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Vr,loadJSON:Vr.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Lr,loadJSON:Lr.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:jr,loadJSON:jr.fromJSON},point:{type:"point",params:[],constructor:Jr,loadJSON:Jr.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:sr,loadJSON:sr.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Gr,loadJSON:Gr.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:Wr,loadJSON:Wr.fromJSON}};function zl(n,e){return Nn[n.type].loadJSON(n,e)}class Hr{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 Hr(In(e.color))}clone(){return new Hr(this.color.clone())}reset(){}}class Xr{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 Xr(D(e.angularVelocity))}frameUpdate(e){}clone(){return new Xr(this.angularVelocity.clone())}reset(){}}class qr{constructor(e){this.angularVelocity=e,this.type="Rotation3DOverLife",this.tempQuat=new j,this.tempQuat2=new j}initialize(e){e.rotation instanceof j&&(e.angularVelocity=new j,this.angularVelocity.startGen(e.memory))}update(e,t){e.rotation instanceof j&&(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 qr(la(e.angularVelocity))}frameUpdate(e){}clone(){return new qr(this.angularVelocity.clone())}reset(){}}class Yr{initialize(e,t){this.ps=t,this.x.startGen(e.memory),this.y.startGen(e.memory),this.z.startGen(e.memory)}constructor(e,t,r){this.x=e,this.y=t,this.z=r,this.type="ForceOverLife",this._temp=new z,this._tempScale=new z,this._tempQ=new j}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 Yr(D(e.x),D(e.y),D(e.z))}frameUpdate(e){if(this.ps&&!this.ps.worldSpace){const t=this._temp,r=this._tempQ,i=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,r,i),r.invert(),i.set(1/i.x,1/i.y,1/i.z)}}clone(){return new Yr(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class Zr{initialize(e){this.size.startGen(e.memory)}constructor(e){this.size=e,this.type="SizeOverLife"}update(e){this.size instanceof Vt?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 Zr(Pi(e.size))}frameUpdate(e){}clone(){return new Zr(this.size.clone())}reset(){}}class Kr{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 Kr(D(e.speed))}frameUpdate(e){}clone(){return new Kr(this.speed.clone())}reset(){}}class Qr{constructor(e){this.frame=e,this.type="FrameOverLife"}initialize(e){this.frame.startGen(e.memory)}update(e,t){this.frame instanceof Ur&&(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 Qr(D(e.frame))}clone(){return new Qr(this.frame.clone())}reset(){}}class $r{constructor(e,t=new z(0,1,0)){this.orbitSpeed=e,this.axis=t,this.type="OrbitOverLife",this.temp=new z,this.rotation=new j}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 $r(D(e.orbitSpeed),e.axis?new z(e.axis[0],e.axis[1],e.axis[2]):void 0)}clone(){return new $r(this.orbitSpeed.clone())}reset(){}}class Un{constructor(e){this.data=e,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class Bl{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 Un(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 Un(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 r=new Un(t);r.next=e,r.prev=e.prev,r.prev!==null&&(r.prev.next=r),r.next.prev=r,e==this.head&&(this.head=r),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 Il{constructor(){this.startSpeed=0,this.startColor=new Me,this.startSize=new z(1,1,1),this.position=new z,this.velocity=new z,this.age=0,this.life=1,this.size=new z(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new Me,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class Nl{constructor(e,t,r){this.position=e,this.size=t,this.color=r}}class Ai{constructor(){this.startSpeed=0,this.startColor=new Me,this.startSize=new z(1,1,1),this.position=new z,this.velocity=new z,this.age=0,this.life=1,this.size=new z(1,1,1),this.length=100,this.speedModifier=1,this.color=new Me,this.previous=new Bl,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new Nl(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 ei{initialize(e){this.width.startGen(e.memory)}constructor(e){this.width=e,this.type="WidthOverLength"}update(e){if(e instanceof Ai){const t=e.previous.values();for(let r=0;r<e.previous.length;r++){const i=t.next();i.value.size=this.width.genValue(e.memory,(e.previous.length-r)/e.length)}}}frameUpdate(e){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(e){return new ei(D(e.width))}clone(){return new ei(this.width.clone())}reset(){}}class ti{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 ti(new z(e.direction[0],e.direction[1],e.direction[2]),D((t=e.magnitude)!==null&&t!==void 0?t:e.force))}clone(){return new ti(this.direction.clone(),this.magnitude.clone())}reset(){}}class ri{constructor(e,t){this.center=e,this.magnitude=t,this.type="GravityForce",this.temp=new z}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 ri(new z(e.center[0],e.center[1],e.center[2]),e.magnitude)}clone(){return new ri(this.center.clone(),this.magnitude)}reset(){}}class ii{constructor(e){this.angle=e,this.type="ChangeEmitDirection",this._temp=new z,this._q=new j,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 ii(D(e.angle))}clone(){return new ii(this.angle)}reset(){}}var Xt;(function(n){n[n.Death=0]="Death",n[n.Birth=1]="Birth",n[n.Frame=2]="Frame"})(Xt||(Xt={}));class ni{constructor(e,t,r,i=Xt.Frame,s=1){this.particleSystem=e,this.useVelocityAsBasis=t,this.subParticleSystem=r,this.mode=i,this.emitProbability=s,this.type="EmitSubParticleSystem",this.q_=new j,this.v_=new z,this.v2_=new z,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(e){}update(e,t){this.mode===Xt.Frame?this.emit(e,t):this.mode===Xt.Birth&&e.age===0?this.emit(e,t):this.mode===Xt.Death&&e.age+t>=e.life&&this.emit(e,t)}emit(e,t){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const r=new He;this.setMatrixFromParticle(r,e),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:r,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 r=this.subEmissions[t];r.particle&&r.particle.age<r.particle.life?this.setMatrixFromParticle(r.matrix,r.particle):r.particle=void 0,this.subParticleSystem.system.emit(e,r,r.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 ni(t,e.useVelocityAsBasis,e.subParticleSystem,e.mode,e.emitProbability)}clone(){return new ni(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(e,t){let r;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(ha).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 j?r=t.rotation:(this.q_.setFromAxisAngle(ha,t.rotation),r=this.q_),e.compose(t.position,r,Ol);this.particleSystem.worldSpace||e.multiplyMatrices(this.particleSystem.emitter.matrixWorld,e)}}const Ul=.5*(Math.sqrt(3)-1),xr=(3-Math.sqrt(3))/6,Dl=1/3,et=1/6,Fl=(Math.sqrt(5)-1)/4,le=(5-Math.sqrt(5))/20,se=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]),ee=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 ua{constructor(e=Math.random){const t=typeof e=="function"?e:Vl(e);this.p=Ll(t),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let r=0;r<512;r++)this.perm[r]=this.p[r&255],this.permMod12[r]=this.perm[r]%12}noise2D(e,t){const r=this.permMod12,i=this.perm;let s=0,a=0,o=0;const c=(e+t)*Ul,l=Math.floor(e+c),h=Math.floor(t+c),u=(l+h)*xr,d=l-u,p=h-u,y=e-d,g=t-p;let f,m;y>g?(f=1,m=0):(f=0,m=1);const b=y-f+xr,v=g-m+xr,x=y-1+2*xr,_=g-1+2*xr,S=l&255,w=h&255;let C=.5-y*y-g*g;if(C>=0){const E=r[S+i[w]]*3;C*=C,s=C*C*(se[E]*y+se[E+1]*g)}let M=.5-b*b-v*v;if(M>=0){const E=r[S+f+i[w+m]]*3;M*=M,a=M*M*(se[E]*b+se[E+1]*v)}let T=.5-x*x-_*_;if(T>=0){const E=r[S+1+i[w+1]]*3;T*=T,o=T*T*(se[E]*x+se[E+1]*_)}return 70*(s+a+o)}noise3D(e,t,r){const i=this.permMod12,s=this.perm;let a,o,c,l;const h=(e+t+r)*Dl,u=Math.floor(e+h),d=Math.floor(t+h),p=Math.floor(r+h),y=(u+d+p)*et,g=u-y,f=d-y,m=p-y,b=e-g,v=t-f,x=r-m;let _,S,w,C,M,T;b>=v?v>=x?(_=1,S=0,w=0,C=1,M=1,T=0):b>=x?(_=1,S=0,w=0,C=1,M=0,T=1):(_=0,S=0,w=1,C=1,M=0,T=1):v<x?(_=0,S=0,w=1,C=0,M=1,T=1):b<x?(_=0,S=1,w=0,C=0,M=1,T=1):(_=0,S=1,w=0,C=1,M=1,T=0);const E=b-_+et,P=v-S+et,k=x-w+et,A=b-C+2*et,N=v-M+2*et,U=x-T+2*et,G=b-1+3*et,B=v-1+3*et,oe=x-1+3*et,K=u&255,re=d&255,$=p&255;let me=.6-b*b-v*v-x*x;if(me<0)a=0;else{const W=i[K+s[re+s[$]]]*3;me*=me,a=me*me*(se[W]*b+se[W+1]*v+se[W+2]*x)}let ye=.6-E*E-P*P-k*k;if(ye<0)o=0;else{const W=i[K+_+s[re+S+s[$+w]]]*3;ye*=ye,o=ye*ye*(se[W]*E+se[W+1]*P+se[W+2]*k)}let ie=.6-A*A-N*N-U*U;if(ie<0)c=0;else{const W=i[K+C+s[re+M+s[$+T]]]*3;ie*=ie,c=ie*ie*(se[W]*A+se[W+1]*N+se[W+2]*U)}let q=.6-G*G-B*B-oe*oe;if(q<0)l=0;else{const W=i[K+1+s[re+1+s[$+1]]]*3;q*=q,l=q*q*(se[W]*G+se[W+1]*B+se[W+2]*oe)}return 32*(a+o+c+l)}noise4D(e,t,r,i){const s=this.perm;let a,o,c,l,h;const u=(e+t+r+i)*Fl,d=Math.floor(e+u),p=Math.floor(t+u),y=Math.floor(r+u),g=Math.floor(i+u),f=(d+p+y+g)*le,m=d-f,b=p-f,v=y-f,x=g-f,_=e-m,S=t-b,w=r-v,C=i-x;let M=0,T=0,E=0,P=0;_>S?M++:T++,_>w?M++:E++,_>C?M++:P++,S>w?T++:E++,S>C?T++:P++,w>C?E++:P++;const k=M>=3?1:0,A=T>=3?1:0,N=E>=3?1:0,U=P>=3?1:0,G=M>=2?1:0,B=T>=2?1:0,oe=E>=2?1:0,K=P>=2?1:0,re=M>=1?1:0,$=T>=1?1:0,me=E>=1?1:0,ye=P>=1?1:0,ie=_-k+le,q=S-A+le,W=w-N+le,it=C-U+le,Be=_-G+2*le,Xe=S-B+2*le,qe=w-oe+2*le,_e=C-K+2*le,Ie=_-re+3*le,xe=S-$+3*le,nt=w-me+3*le,st=C-ye+3*le,Y=_-1+4*le,Ye=S-1+4*le,ot=w-1+4*le,Ct=C-1+4*le,at=d&255,ct=p&255,lt=y&255,ht=g&255;let Ne=.6-_*_-S*S-w*w-C*C;if(Ne<0)a=0;else{const V=s[at+s[ct+s[lt+s[ht]]]]%32*4;Ne*=Ne,a=Ne*Ne*(ee[V]*_+ee[V+1]*S+ee[V+2]*w+ee[V+3]*C)}let Ue=.6-ie*ie-q*q-W*W-it*it;if(Ue<0)o=0;else{const V=s[at+k+s[ct+A+s[lt+N+s[ht+U]]]]%32*4;Ue*=Ue,o=Ue*Ue*(ee[V]*ie+ee[V+1]*q+ee[V+2]*W+ee[V+3]*it)}let De=.6-Be*Be-Xe*Xe-qe*qe-_e*_e;if(De<0)c=0;else{const V=s[at+G+s[ct+B+s[lt+oe+s[ht+K]]]]%32*4;De*=De,c=De*De*(ee[V]*Be+ee[V+1]*Xe+ee[V+2]*qe+ee[V+3]*_e)}let Fe=.6-Ie*Ie-xe*xe-nt*nt-st*st;if(Fe<0)l=0;else{const V=s[at+re+s[ct+$+s[lt+me+s[ht+ye]]]]%32*4;Fe*=Fe,l=Fe*Fe*(ee[V]*Ie+ee[V+1]*xe+ee[V+2]*nt+ee[V+3]*st)}let Le=.6-Y*Y-Ye*Ye-ot*ot-Ct*Ct;if(Le<0)h=0;else{const V=s[at+1+s[ct+1+s[lt+1+s[ht+1]]]]%32*4;Le*=Le,h=Le*Le*(ee[V]*Y+ee[V+1]*Ye+ee[V+2]*ot+ee[V+3]*Ct)}return 27*(a+o+c+l+h)}}function Ll(n){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let t=0;t<255;t++){const r=t+~~(n()*(256-t)),i=e[t];e[t]=e[r],e[r]=i}return e}function Vl(n){let e=0,t=0,r=0,i=1;const s=jl();return e=s(" "),t=s(" "),r=s(" "),e-=s(n),e<0&&(e+=1),t-=s(n),t<0&&(t+=1),r-=s(n),r<0&&(r+=1),function(){const a=2091639*e+i*23283064365386963e-26;return e=t,t=r,r=a-(i=a|0)}}function jl(){let n=4022871197;return function(e){e=e.toString();for(let t=0;t<e.length;t++){n+=e.charCodeAt(t);let r=.02519603282416938*n;n=r>>>0,r-=n,r*=n,n=r>>>0,r-=n,n+=r*4294967296}return(n>>>0)*23283064365386963e-26}}class si{constructor(e,t,r,i){this.scale=e,this.octaves=t,this.velocityMultiplier=r,this.timeScale=i,this.type="TurbulenceField",this.generator=new ua,this.timeOffset=new z,this.temp=new z,this.temp2=new z,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 r=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(r*a,i*a,s*a,this.timeOffset.x*a)/a,this.generator.noise4D(r*a,i*a,s*a,this.timeOffset.y*a)/a,this.generator.noise4D(r*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 si(new z(e.scale[0],e.scale[1],e.scale[2]),e.octaves,new z(e.velocityMultiplier[0],e.velocityMultiplier[1],e.velocityMultiplier[2]),new z(e.timeScale[0],e.timeScale[1],e.timeScale[2]))}clone(){return new si(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const tt=[],Dn=new z,Fn=new j;class oi{constructor(e,t,r=new L(1),i=new L(0)){if(this.frequency=e,this.power=t,this.positionAmount=r,this.rotationAmount=i,this.type="Noise",this.duration=0,tt.length===0)for(let s=0;s<100;s++)tt.push(new ua)}initialize(e){e.lastPosNoise=new z,typeof e.rotation=="number"?e.lastRotNoise=0:e.lastRotNoise=new j,e.generatorIndex=[Ei(0,100),Ei(0,100),Ei(0,100),Ei(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 r=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),Dn.set(tt[e.generatorIndex[0]].noise2D(0,e.age*r)*i*s,tt[e.generatorIndex[1]].noise2D(0,e.age*r)*i*s,tt[e.generatorIndex[2]].noise2D(0,e.age*r)*i*s),e.position.add(Dn),e.lastPosNoise.copy(Dn)),a>0&&e.lastRotNoise!==void 0&&(typeof e.rotation=="number"?(e.rotation-=e.lastRotNoise,e.rotation+=tt[e.generatorIndex[3]].noise2D(0,e.age*r)*Math.PI*i*a):(e.lastRotNoise.invert(),e.rotation.multiply(e.lastRotNoise),Fn.set(tt[e.generatorIndex[0]].noise2D(0,e.age*r)*i*a,tt[e.generatorIndex[1]].noise2D(0,e.age*r)*i*a,tt[e.generatorIndex[2]].noise2D(0,e.age*r)*i*a,tt[e.generatorIndex[3]].noise2D(0,e.age*r)*i*a).normalize(),e.rotation.multiply(Fn),e.lastRotNoise.copy(Fn)))}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 oi(D(e.frequency),D(e.power),D(e.positionAmount),D(e.rotationAmount))}clone(){return new oi(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class ai{constructor(e,t){this.color=e,this.speedRange=t,this.type="ColorBySpeed"}initialize(e){this.color.startGen(e.memory)}update(e,t){const r=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(e.memory,e.color,r),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 ai(In(e.color),Lt.fromJSON(e.speedRange))}clone(){return new ai(this.color.clone(),this.speedRange.clone())}reset(){}}class ci{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 Vt?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 ci(Pi(e.size),Lt.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new ci(this.size.clone(),this.speedRange.clone())}reset(){}}class li{constructor(e,t){this.angularVelocity=e,this.speedRange=t,this.type="RotationBySpeed",this.tempQuat=new j}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){if(typeof e.rotation=="number"){const r=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);e.rotation+=t*this.angularVelocity.genValue(e.memory,r)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new li(D(e.angularVelocity),Lt.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new li(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class hi{initialize(e){this.speed.startGen(e.memory)}constructor(e,t){this.speed=e,this.dampen=t,this.type="LimitSpeedOverLife"}update(e,t){let r=e.velocity.length(),i=this.speed.genValue(e.memory,e.age/e.life);if(r>i){const s=(r-i)/r;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 hi(D(e.speed),e.dampen)}frameUpdate(e){}clone(){return new hi(this.speed.clone(),this.dampen)}reset(){}}const Oi={ApplyForce:{type:"ApplyForce",constructor:ti,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:ti.fromJSON},Noise:{type:"Noise",constructor:oi,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:oi.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:si,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:si.fromJSON},GravityForce:{type:"GravityForce",constructor:ri,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:ri.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:Hr,params:[["color",["colorFunc"]]],loadJSON:Hr.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Xr,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Xr.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:qr,params:[["angularVelocity",["rotationFunc"]]],loadJSON:qr.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Zr,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Zr.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:ai,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:ai.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:li,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:li.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:ci,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:ci.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Kr,params:[["speed",["value","valueFunc"]]],loadJSON:Kr.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:Qr,params:[["frame",["value","valueFunc"]]],loadJSON:Qr.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:Yr,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:Yr.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:$r,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:$r.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:ei,params:[["width",["value","valueFunc"]]],loadJSON:ei.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:ii,params:[["angle",["value"]]],loadJSON:ii.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:ni,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:ni.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:hi,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:hi.fromJSON}};function Jl(n,e){return Oi[n.type]?Oi[n.type].loadJSON(n,e):null}const Gl=[];function Wl(n){if(!Gl.find(e=>e.id===n.id)){for(const e of n.emitterShapes)Nn[e.type]||(Nn[e.type]=e);for(const e of n.behaviors)Oi[e.type]||(Oi[e.type]=e)}}var Hl=`
|
|
84
84
|
#ifdef SOFT_PARTICLES
|
|
85
85
|
|
|
86
86
|
/* #ifdef LOGDEPTH
|
|
@@ -102,7 +102,7 @@ a=extmap-allow-mixed`)!==-1){const i=r.sdp.split(`
|
|
|
102
102
|
|
|
103
103
|
//gl_FragColor = vec4(softParticlesFade , 0, 0, 1);
|
|
104
104
|
#endif
|
|
105
|
-
`,
|
|
105
|
+
`,Xl=`
|
|
106
106
|
#ifdef SOFT_PARTICLES
|
|
107
107
|
|
|
108
108
|
uniform sampler2D depthTexture;
|
|
@@ -124,17 +124,17 @@ a=extmap-allow-mixed`)!==-1){const i=r.sdp.split(`
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
#endif
|
|
127
|
-
`,
|
|
127
|
+
`,ql=`
|
|
128
128
|
#ifdef SOFT_PARTICLES
|
|
129
129
|
varying vec4 projPosition;
|
|
130
130
|
varying float linearDepth;
|
|
131
131
|
#endif
|
|
132
|
-
`,
|
|
132
|
+
`,Yl=`
|
|
133
133
|
#ifdef SOFT_PARTICLES
|
|
134
134
|
projPosition = gl_Position;
|
|
135
135
|
linearDepth = -mvPosition.z;
|
|
136
136
|
#endif
|
|
137
|
-
`,
|
|
137
|
+
`,Zl=`
|
|
138
138
|
#ifdef USE_MAP
|
|
139
139
|
vec4 texelColor = texture2D( map, vUv);
|
|
140
140
|
#ifdef TILE_BLEND
|
|
@@ -142,7 +142,7 @@ a=extmap-allow-mixed`)!==-1){const i=r.sdp.split(`
|
|
|
142
142
|
#endif
|
|
143
143
|
diffuseColor *= texelColor;
|
|
144
144
|
#endif
|
|
145
|
-
`,
|
|
145
|
+
`,Kl=`
|
|
146
146
|
#if defined( USE_UV ) || defined( USE_ANISOTROPY )
|
|
147
147
|
|
|
148
148
|
varying vec2 vUv;
|
|
@@ -293,7 +293,7 @@ a=extmap-allow-mixed`)!==-1){const i=r.sdp.split(`
|
|
|
293
293
|
varying vec2 vThicknessMapUv;
|
|
294
294
|
|
|
295
295
|
#endif
|
|
296
|
-
`,
|
|
296
|
+
`,Ql=`
|
|
297
297
|
#ifdef UV_TILE
|
|
298
298
|
attribute float uvTile;
|
|
299
299
|
uniform vec2 tileCount;
|
|
@@ -463,7 +463,7 @@ a=extmap-allow-mixed`)!==-1){const i=r.sdp.split(`
|
|
|
463
463
|
varying vec2 vThicknessMapUv;
|
|
464
464
|
|
|
465
465
|
#endif
|
|
466
|
-
|
|
466
|
+
`,$l=`
|
|
467
467
|
#ifdef UV_TILE
|
|
468
468
|
mat3 tileTransform = makeTileTransform(floor(uvTile));
|
|
469
469
|
#ifdef TILE_BLEND
|
|
@@ -601,7 +601,7 @@ vThicknessMapUv = ( tileTransform * thicknessMapTransform * vec3( THICKNESSMAP_U
|
|
|
601
601
|
|
|
602
602
|
#endif
|
|
603
603
|
|
|
604
|
-
`;const _t=Fa;function jl(){_t.tile_pars_vertex=Ll,_t.tile_vertex=Vl,_t.tile_pars_fragment=Fl,_t.tile_fragment=Dl,_t.soft_pars_vertex=Ul,_t.soft_vertex=Nl,_t.soft_pars_fragment=Il,_t.soft_fragment=Bl}class Jl extends vs{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 r in e){const i=e[r];delete i.metadata,t.push(i)}return t}toJSON(e,t={}){const r=this.children;this.children=this.children.filter(s=>s.type!=="ParticleSystemPreview");const i=super.toJSON(e);return this.children=r,this.system!==null&&(i.object.ps=this.system.toJSON(e,t)),i}}var A;(function(n){n[n.BillBoard=0]="BillBoard",n[n.StretchedBillBoard=1]="StretchedBillBoard",n[n.Mesh=2]="Mesh",n[n.Trail=3]="Trail",n[n.HorizontalBillBoard=4]="HorizontalBillBoard",n[n.VerticalBillBoard=5]="VerticalBillBoard"})(A||(A={}));class ca extends an{constructor(e){super(),this.type="VFXBatch",this.maxParticles=1e3,this.systems=new Set;const t=new hi;t.mask=e.layers.mask;const r=e.material.clone();r.defines={},Object.assign(r.defines,e.material.defines),this.settings={instancingGeometry:e.instancingGeometry,renderMode:e.renderMode,renderOrder:e.renderOrder,material:r,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 Gl=new z(0,0,1),Dn=new j,Wl=new z,Xl=new z;new z;const la=60,ql=new gs(1,1,1,1);class nn{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!=A.Trail&&e===A.Trail||this.rendererSettings.renderMode==A.Trail&&e!==A.Trail)&&(this.restart(),this.particles.length=0),this.rendererSettings.renderMode!==e)switch(e){case A.Trail:this.rendererEmitterSettings={startLength:new L(30),followLocalOrigin:!1};break;case A.Mesh:this.rendererEmitterSettings={geometry:new gs(1,1)},this.startRotation=new Nr(new z(0,1,0),new L(0));break;case A.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2},this.rendererSettings.renderMode===A.Mesh&&(this.startRotation=new L(0));break;case A.BillBoard:case A.VerticalBillBoard:case A.HorizontalBillBoard:this.rendererEmitterSettings={},this.rendererSettings.renderMode===A.Mesh&&(this.startRotation=new L(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,r,i,s,a,o,c,l,h,u,d,p,y,g,f,m,v,_,b,x,S,w,C,M,T,E;if(this.temp=new z,this.travelDistance=0,this.normalMatrix=new tt,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=(r=e.startLife)!==null&&r!==void 0?r:new L(5),this.startSpeed=(i=e.startSpeed)!==null&&i!==void 0?i:new L(0),this.startRotation=(s=e.startRotation)!==null&&s!==void 0?s:new L(0),this.startSize=(a=e.startSize)!==null&&a!==void 0?a:new L(1),this.startColor=(o=e.startColor)!==null&&o!==void 0?o:new Nt(new Me(1,1,1,1)),this.emissionOverTime=(c=e.emissionOverTime)!==null&&c!==void 0?c:new L(10),this.emissionOverDistance=(l=e.emissionOverDistance)!==null&&l!==void 0?l:new L(0),this.emissionBursts=(h=e.emissionBursts)!==null&&h!==void 0?h:[],this.onlyUsedByOther=(u=e.onlyUsedByOther)!==null&&u!==void 0?u:!1,this.emitterShape=(d=e.shape)!==null&&d!==void 0?d:new ir,this.behaviors=(p=e.behaviors)!==null&&p!==void 0?p:new Array,this.worldSpace=(y=e.worldSpace)!==null&&y!==void 0?y:!1,this.rendererEmitterSettings=(g=e.rendererEmitterSettings)!==null&&g!==void 0?g:{},e.renderMode===A.StretchedBillBoard){const P=this.rendererEmitterSettings;e.speedFactor!==void 0&&(P.speedFactor=e.speedFactor),P.speedFactor=(f=P.speedFactor)!==null&&f!==void 0?f:0,P.lengthFactor=(m=P.lengthFactor)!==null&&m!==void 0?m:0}this.rendererSettings={instancingGeometry:(v=e.instancingGeometry)!==null&&v!==void 0?v:ql,renderMode:(_=e.renderMode)!==null&&_!==void 0?_:A.BillBoard,renderOrder:(b=e.renderOrder)!==null&&b!==void 0?b:0,material:e.material,uTileCount:(x=e.uTileCount)!==null&&x!==void 0?x:1,vTileCount:(S=e.vTileCount)!==null&&S!==void 0?S:1,blendTiles:(w=e.blendTiles)!==null&&w!==void 0?w:!1,softParticles:(C=e.softParticles)!==null&&C!==void 0?C:!1,softNearFade:(M=e.softNearFade)!==null&&M!==void 0?M:0,softFarFade:(T=e.softFarFade)!==null&&T!==void 0?T:0,layers:(E=e.layers)!==null&&E!==void 0?E:new hi},this.neededToUpdateRender=!0,this.particles=new Array,this.startTileIndex=e.startTileIndex||new L(0),this.emitter=new Jl(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(P=>P.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,r){Dn.setFromRotationMatrix(r);const i=Wl,s=Dn,a=Xl;r.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===A.Trail?this.particles.push(new ki):this.particles.push(new wl);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===A.Mesh||this.rendererSettings.renderMode===A.BillBoard||this.rendererSettings.renderMode===A.VerticalBillBoard||this.rendererSettings.renderMode===A.HorizontalBillBoard||this.rendererSettings.renderMode===A.StretchedBillBoard){const l=c;this.startRotation.startGen(c.memory),this.rendererSettings.renderMode===A.Mesh?(l.rotation instanceof j||(l.rotation=new j),this.startRotation.type==="rotation"?this.startRotation.genValue(c.memory,l.rotation,1,t.time/this.duration):l.rotation.setFromAxisAngle(Gl,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===A.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===A.Trail&&this.rendererEmitterSettings.followLocalOrigin){const l=c;l.localPosition=new z().copy(l.position)}this.worldSpace?(c.position.applyMatrix4(r),c.startSize.multiply(a).abs(),c.size.copy(c.startSize),c.velocity.multiply(a).applyMatrix3(this.normalMatrix),c.rotation&&c.rotation instanceof j&&c.rotation.multiplyQuaternions(Dn,c.rotation)):this.onlyUsedByOther&&(c.parentMatrix=r);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 r=0;r<this.duration*la;r++)this.update(1/la)}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 r=0;r<this.behaviors.length;r++){this.behaviors[r].frameUpdate(e);for(let i=0;i<this.particleNum;i++)this.particles[i].died||this.behaviors[r].update(this.particles[i],e)}for(let r=0;r<this.particleNum;r++)this.rendererEmitterSettings.followLocalOrigin&&this.particles[r].localPosition?(this.particles[r].position.copy(this.particles[r].localPosition),this.particles[r].parentMatrix?this.particles[r].position.applyMatrix4(this.particles[r].parentMatrix):this.particles[r].position.applyMatrix4(this.emitter.matrixWorld)):this.particles[r].position.addScaledVector(this.particles[r].velocity,e*this.particles[r].speedModifier),this.particles[r].age+=e;if(this.rendererSettings.renderMode===A.Trail)for(let r=0;r<this.particleNum;r++)this.particles[r].update();for(let r=0;r<this.particleNum;r++){const i=this.particles[r];i.died&&(!(i instanceof ki)||i.previous.length===0)&&(this.particles[r]=this.particles[this.particleNum-1],this.particles[this.particleNum-1]=i,this.particleNum--,r--,this.fire({type:"particleDied",particleSystem:this,particle:i}))}}emit(e,t,r){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(r);const i=Math.ceil(t.waitEmiting);for(this.spawn(i,t,r),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,r),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(r.elements[12],r.elements[13],r.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 z),t.previousWorldPos.set(r.elements[12],r.elements[13],r.elements[14]),t.time+=e}toJSON(e,t={}){var r;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&&((r=this.texture)===null||r===void 0?void 0:r.source)!==void 0){const a=this.texture.source;e.images[a.uuid]={uuid:a.uuid,url:this.texture.image.url}}let i;this.renderMode===A.Trail?i={startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===A.Mesh?i={}:this.renderMode===A.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,r){var i,s;const a=xl(e.shape,t);let o;if(e.renderMode===A.Trail){const h=e.rendererEmitterSettings;o={startLength:h.startLength!=null?D(h.startLength):new L(30),followLocalOrigin:h.followLocalOrigin}}else e.renderMode===A.Mesh?o={}:e.renderMode===A.StretchedBillBoard?(o=e.rendererEmitterSettings,e.speedFactor!=null&&(o.speedFactor=e.speedFactor)):o={};const c=new hi;e.layers&&(c.mask=e.layers);const l=new nn({autoDestroy:e.autoDestroy,looping:e.looping,prewarm:e.prewarm,duration:e.duration,shape:a,startLife:D(e.startLife),startSpeed:D(e.startSpeed),startRotation:Ti(e.startRotation),startSize:Ti(e.startSize),startColor:zn(e.startColor),emissionOverTime:D(e.emissionOverTime),emissionOverDistance:D(e.emissionOverDistance),emissionBursts:(i=e.emissionBursts)===null||i===void 0?void 0:i.map(h=>{var u,d,p;return{time:h.time,count:typeof h.count=="number"?new L(h.count):D(h.count),probability:(u=h.probability)!==null&&u!==void 0?u:1,interval:(d=h.interval)!==null&&d!==void 0?d:.1,cycle:(p=h.cycle)!==null&&p!==void 0?p: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 _s({map:t.textures[e.texture],transparent:(s=e.transparent)!==null&&s!==void 0?s:!0,blending:e.blending,side:sn}):new _s({color:16777215,transparent:!0,blending:bs,side:sn}),startTileIndex:typeof e.startTileIndex=="number"?new L(e.startTileIndex):D(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(h=>{const u=Rl(h,l);return u.type==="EmitSubParticleSystem"&&(r[h.subParticleSystem]=u),u}),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 r=this.listeners[e].indexOf(t);r!==-1&&this.listeners[e].splice(r,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 r;this.renderMode===A.Trail?r={startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===A.StretchedBillBoard?r={lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:r={};const i=new hi;return i.mask=this.layers.mask,new nn({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:r,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 Fn=`
|
|
604
|
+
`;const _t=Ga;function eh(){_t.tile_pars_vertex=Ql,_t.tile_vertex=$l,_t.tile_pars_fragment=Kl,_t.tile_fragment=Zl,_t.soft_pars_vertex=ql,_t.soft_vertex=Yl,_t.soft_pars_fragment=Xl,_t.soft_fragment=Hl}class th extends _s{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 r in e){const i=e[r];delete i.metadata,t.push(i)}return t}toJSON(e,t={}){const r=this.children;this.children=this.children.filter(s=>s.type!=="ParticleSystemPreview");const i=super.toJSON(e);return this.children=r,this.system!==null&&(i.object.ps=this.system.toJSON(e,t)),i}}var R;(function(n){n[n.BillBoard=0]="BillBoard",n[n.StretchedBillBoard=1]="StretchedBillBoard",n[n.Mesh=2]="Mesh",n[n.Trail=3]="Trail",n[n.HorizontalBillBoard=4]="HorizontalBillBoard",n[n.VerticalBillBoard=5]="VerticalBillBoard"})(R||(R={}));class da extends ln{constructor(e){super(),this.type="VFXBatch",this.maxParticles=1e3,this.systems=new Set;const t=new di;t.mask=e.layers.mask;const r=e.material.clone();r.defines={},Object.assign(r.defines,e.material.defines),this.settings={instancingGeometry:e.instancingGeometry,renderMode:e.renderMode,renderOrder:e.renderOrder,material:r,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 rh=new z(0,0,1),Ln=new j,ih=new z,nh=new z;new z;const pa=60,sh=new bs(1,1,1,1);class on{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!=R.Trail&&e===R.Trail||this.rendererSettings.renderMode==R.Trail&&e!==R.Trail)&&(this.restart(),this.particles.length=0),this.rendererSettings.renderMode!==e)switch(e){case R.Trail:this.rendererEmitterSettings={startLength:new L(30),followLocalOrigin:!1};break;case R.Mesh:this.rendererEmitterSettings={geometry:new bs(1,1)},this.startRotation=new Fr(new z(0,1,0),new L(0));break;case R.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2},this.rendererSettings.renderMode===R.Mesh&&(this.startRotation=new L(0));break;case R.BillBoard:case R.VerticalBillBoard:case R.HorizontalBillBoard:this.rendererEmitterSettings={},this.rendererSettings.renderMode===R.Mesh&&(this.startRotation=new L(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,r,i,s,a,o,c,l,h,u,d,p,y,g,f,m,b,v,x,_,S,w,C,M,T,E;if(this.temp=new z,this.travelDistance=0,this.normalMatrix=new rt,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=(r=e.startLife)!==null&&r!==void 0?r:new L(5),this.startSpeed=(i=e.startSpeed)!==null&&i!==void 0?i:new L(0),this.startRotation=(s=e.startRotation)!==null&&s!==void 0?s:new L(0),this.startSize=(a=e.startSize)!==null&&a!==void 0?a:new L(1),this.startColor=(o=e.startColor)!==null&&o!==void 0?o:new Ft(new Me(1,1,1,1)),this.emissionOverTime=(c=e.emissionOverTime)!==null&&c!==void 0?c:new L(10),this.emissionOverDistance=(l=e.emissionOverDistance)!==null&&l!==void 0?l:new L(0),this.emissionBursts=(h=e.emissionBursts)!==null&&h!==void 0?h:[],this.onlyUsedByOther=(u=e.onlyUsedByOther)!==null&&u!==void 0?u:!1,this.emitterShape=(d=e.shape)!==null&&d!==void 0?d:new sr,this.behaviors=(p=e.behaviors)!==null&&p!==void 0?p:new Array,this.worldSpace=(y=e.worldSpace)!==null&&y!==void 0?y:!1,this.rendererEmitterSettings=(g=e.rendererEmitterSettings)!==null&&g!==void 0?g:{},e.renderMode===R.StretchedBillBoard){const P=this.rendererEmitterSettings;e.speedFactor!==void 0&&(P.speedFactor=e.speedFactor),P.speedFactor=(f=P.speedFactor)!==null&&f!==void 0?f:0,P.lengthFactor=(m=P.lengthFactor)!==null&&m!==void 0?m:0}this.rendererSettings={instancingGeometry:(b=e.instancingGeometry)!==null&&b!==void 0?b:sh,renderMode:(v=e.renderMode)!==null&&v!==void 0?v:R.BillBoard,renderOrder:(x=e.renderOrder)!==null&&x!==void 0?x:0,material:e.material,uTileCount:(_=e.uTileCount)!==null&&_!==void 0?_:1,vTileCount:(S=e.vTileCount)!==null&&S!==void 0?S:1,blendTiles:(w=e.blendTiles)!==null&&w!==void 0?w:!1,softParticles:(C=e.softParticles)!==null&&C!==void 0?C:!1,softNearFade:(M=e.softNearFade)!==null&&M!==void 0?M:0,softFarFade:(T=e.softFarFade)!==null&&T!==void 0?T:0,layers:(E=e.layers)!==null&&E!==void 0?E:new di},this.neededToUpdateRender=!0,this.particles=new Array,this.startTileIndex=e.startTileIndex||new L(0),this.emitter=new th(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(P=>P.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,r){Ln.setFromRotationMatrix(r);const i=ih,s=Ln,a=nh;r.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===R.Trail?this.particles.push(new Ai):this.particles.push(new Il);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===R.Mesh||this.rendererSettings.renderMode===R.BillBoard||this.rendererSettings.renderMode===R.VerticalBillBoard||this.rendererSettings.renderMode===R.HorizontalBillBoard||this.rendererSettings.renderMode===R.StretchedBillBoard){const l=c;this.startRotation.startGen(c.memory),this.rendererSettings.renderMode===R.Mesh?(l.rotation instanceof j||(l.rotation=new j),this.startRotation.type==="rotation"?this.startRotation.genValue(c.memory,l.rotation,1,t.time/this.duration):l.rotation.setFromAxisAngle(rh,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===R.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===R.Trail&&this.rendererEmitterSettings.followLocalOrigin){const l=c;l.localPosition=new z().copy(l.position)}this.worldSpace?(c.position.applyMatrix4(r),c.startSize.multiply(a).abs(),c.size.copy(c.startSize),c.velocity.multiply(a).applyMatrix3(this.normalMatrix),c.rotation&&c.rotation instanceof j&&c.rotation.multiplyQuaternions(Ln,c.rotation)):this.onlyUsedByOther&&(c.parentMatrix=r);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 r=0;r<this.duration*pa;r++)this.update(1/pa)}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 r=0;r<this.behaviors.length;r++){this.behaviors[r].frameUpdate(e);for(let i=0;i<this.particleNum;i++)this.particles[i].died||this.behaviors[r].update(this.particles[i],e)}for(let r=0;r<this.particleNum;r++)this.rendererEmitterSettings.followLocalOrigin&&this.particles[r].localPosition?(this.particles[r].position.copy(this.particles[r].localPosition),this.particles[r].parentMatrix?this.particles[r].position.applyMatrix4(this.particles[r].parentMatrix):this.particles[r].position.applyMatrix4(this.emitter.matrixWorld)):this.particles[r].position.addScaledVector(this.particles[r].velocity,e*this.particles[r].speedModifier),this.particles[r].age+=e;if(this.rendererSettings.renderMode===R.Trail)for(let r=0;r<this.particleNum;r++)this.particles[r].update();for(let r=0;r<this.particleNum;r++){const i=this.particles[r];i.died&&(!(i instanceof Ai)||i.previous.length===0)&&(this.particles[r]=this.particles[this.particleNum-1],this.particles[this.particleNum-1]=i,this.particleNum--,r--,this.fire({type:"particleDied",particleSystem:this,particle:i}))}}emit(e,t,r){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(r);const i=Math.ceil(t.waitEmiting);for(this.spawn(i,t,r),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,r),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(r.elements[12],r.elements[13],r.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 z),t.previousWorldPos.set(r.elements[12],r.elements[13],r.elements[14]),t.time+=e}toJSON(e,t={}){var r;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&&((r=this.texture)===null||r===void 0?void 0:r.source)!==void 0){const a=this.texture.source;e.images[a.uuid]={uuid:a.uuid,url:this.texture.image.url}}let i;this.renderMode===R.Trail?i={startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===R.Mesh?i={}:this.renderMode===R.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,r){var i,s;const a=zl(e.shape,t);let o;if(e.renderMode===R.Trail){const h=e.rendererEmitterSettings;o={startLength:h.startLength!=null?D(h.startLength):new L(30),followLocalOrigin:h.followLocalOrigin}}else e.renderMode===R.Mesh?o={}:e.renderMode===R.StretchedBillBoard?(o=e.rendererEmitterSettings,e.speedFactor!=null&&(o.speedFactor=e.speedFactor)):o={};const c=new di;e.layers&&(c.mask=e.layers);const l=new on({autoDestroy:e.autoDestroy,looping:e.looping,prewarm:e.prewarm,duration:e.duration,shape:a,startLife:D(e.startLife),startSpeed:D(e.startSpeed),startRotation:Pi(e.startRotation),startSize:Pi(e.startSize),startColor:In(e.startColor),emissionOverTime:D(e.emissionOverTime),emissionOverDistance:D(e.emissionOverDistance),emissionBursts:(i=e.emissionBursts)===null||i===void 0?void 0:i.map(h=>{var u,d,p;return{time:h.time,count:typeof h.count=="number"?new L(h.count):D(h.count),probability:(u=h.probability)!==null&&u!==void 0?u:1,interval:(d=h.interval)!==null&&d!==void 0?d:.1,cycle:(p=h.cycle)!==null&&p!==void 0?p: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 xs({map:t.textures[e.texture],transparent:(s=e.transparent)!==null&&s!==void 0?s:!0,blending:e.blending,side:an}):new xs({color:16777215,transparent:!0,blending:Ss,side:an}),startTileIndex:typeof e.startTileIndex=="number"?new L(e.startTileIndex):D(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(h=>{const u=Jl(h,l);return u.type==="EmitSubParticleSystem"&&(r[h.subParticleSystem]=u),u}),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 r=this.listeners[e].indexOf(t);r!==-1&&this.listeners[e].splice(r,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 r;this.renderMode===R.Trail?r={startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===R.StretchedBillBoard?r={lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:r={};const i=new di;return i.mask=this.layers.mask,new on({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:r,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 Vn=`
|
|
605
605
|
|
|
606
606
|
#include <common>
|
|
607
607
|
#include <color_pars_fragment>
|
|
@@ -636,7 +636,7 @@ void main() {
|
|
|
636
636
|
#include <soft_fragment>
|
|
637
637
|
#include <tonemapping_fragment>
|
|
638
638
|
}
|
|
639
|
-
`,
|
|
639
|
+
`,jn=`
|
|
640
640
|
#define STANDARD
|
|
641
641
|
|
|
642
642
|
#ifdef PHYSICAL
|
|
@@ -801,7 +801,7 @@ outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoat
|
|
|
801
801
|
#include <fog_fragment>
|
|
802
802
|
#include <premultiplied_alpha_fragment>
|
|
803
803
|
#include <dithering_fragment>
|
|
804
|
-
}`,
|
|
804
|
+
}`,oh=`
|
|
805
805
|
#include <common>
|
|
806
806
|
#include <color_pars_vertex>
|
|
807
807
|
#include <logdepthbuf_pars_vertex>
|
|
@@ -847,7 +847,7 @@ void main() {
|
|
|
847
847
|
#include <tile_vertex>
|
|
848
848
|
#include <soft_vertex>
|
|
849
849
|
}
|
|
850
|
-
`,
|
|
850
|
+
`,ah=`
|
|
851
851
|
#include <common>
|
|
852
852
|
#include <color_pars_vertex>
|
|
853
853
|
#include <logdepthbuf_pars_vertex>
|
|
@@ -884,7 +884,7 @@ void main() {
|
|
|
884
884
|
#include <tile_vertex>
|
|
885
885
|
#include <soft_vertex>
|
|
886
886
|
}
|
|
887
|
-
`,
|
|
887
|
+
`,Jn=`
|
|
888
888
|
#define STANDARD
|
|
889
889
|
varying vec3 vViewPosition;
|
|
890
890
|
#ifdef USE_TRANSMISSION
|
|
@@ -969,7 +969,7 @@ void main() {
|
|
|
969
969
|
vWorldPosition = worldPosition.xyz;
|
|
970
970
|
#endif
|
|
971
971
|
}
|
|
972
|
-
`,
|
|
972
|
+
`,ch=`
|
|
973
973
|
#include <common>
|
|
974
974
|
#include <color_pars_vertex>
|
|
975
975
|
#include <logdepthbuf_pars_vertex>
|
|
@@ -1010,7 +1010,7 @@ void main() {
|
|
|
1010
1010
|
#include <tile_vertex>
|
|
1011
1011
|
#include <soft_vertex>
|
|
1012
1012
|
}
|
|
1013
|
-
`;function
|
|
1013
|
+
`;function Gn(n){return n===0?"uv":`uv${n}`}class lh extends Ha{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=Jn,e.fragmentShader=jn}}class hh extends Xa{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=Jn,e.fragmentShader=jn}}class uh extends da{constructor(e){super(e),this.vector_=new z,this.vector2_=new z,this.vector3_=new z,this.quaternion_=new j,this.quaternion2_=new j,this.quaternion3_=new j,this.rotationMat_=new rt,this.rotationMat2_=new rt,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new Pt(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(ge),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new Pt(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(ge),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===R.Mesh?(this.rotationBuffer=new Pt(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(ge),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===R.BillBoard||this.settings.renderMode===R.HorizontalBillBoard||this.settings.renderMode===R.VerticalBillBoard||this.settings.renderMode===R.StretchedBillBoard)&&(this.rotationBuffer=new Pt(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(ge),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new Pt(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(ge),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new Pt(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(ge),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===R.StretchedBillBoard&&(this.velocityBuffer=new Pt(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(ge),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new Wa,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 Ve(this.settings.material.map)),this.settings.material.alphaTest&&(t.USE_ALPHATEST="",e.alphaTest=new Ve(this.settings.material.alphaTest)),t.USE_UV="";const r=this.settings.uTileCount,i=this.settings.vTileCount;(r>1||i>1)&&(t.UV_TILE="",e.tileCount=new Ve(new ir(r,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=Gn(this.settings.material.normalMap.channel),e.normalMapTransform=new Ve(new rt().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(t.USE_MAP="",this.settings.blendTiles&&(t.TILE_BLEND=""),t.MAP_UV=Gn(this.settings.material.map.channel),e.mapTransform=new Ve(new rt().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 Ve(new ir(o,c)),e.depthTexture=new Ve(null);const l=e.projParams=new Ve(new Me);s=(h,u,d)=>{l.value.set(d.near,d.far,0,0)}}let a=!1;if(this.settings.renderMode===R.BillBoard||this.settings.renderMode===R.VerticalBillBoard||this.settings.renderMode===R.HorizontalBillBoard||this.settings.renderMode===R.Mesh){let o,c;this.settings.renderMode===R.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(t.USE_COLOR="",o=Jn,c=jn,a=!0):(o=ah,c=Vn):(o=oh,c=Vn),this.settings.renderMode===R.VerticalBillBoard?t.VERTICAL="":this.settings.renderMode===R.HorizontalBillBoard&&(t.HORIZONTAL="");let l=!1;this.settings.renderMode===R.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new lh({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new hh({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0)),l||(this.material=new cn({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===R.StretchedBillBoard)e.speedFactor=new Ve(1),this.material=new cn({uniforms:e,defines:t,vertexShader:ch,fragmentShader:Vn,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(r=>{t+=r.particleNum}),t>this.maxParticles&&this.expandBuffers(t),this.systems.forEach(r=>{r.emitter.updateMatrixWorld&&(r.emitter.updateWorldMatrix(!0,!1),r.emitter.updateMatrixWorld(!0));const i=r.particles,s=r.particleNum,a=this.quaternion2_,o=this.vector2_,c=this.vector3_;r.emitter.matrixWorld.decompose(o,a,c),this.rotationMat_.setFromMatrix4(r.emitter.matrixWorld);for(let l=0;l<s;l++,e++){const h=i[l];if(this.settings.renderMode===R.Mesh){let d;if(r.worldSpace)d=h.rotation;else{let p;h.parentMatrix?p=this.quaternion3_.setFromRotationMatrix(h.parentMatrix):p=a,d=this.quaternion_,d.copy(p).multiply(h.rotation)}this.rotationBuffer.setXYZW(e,d.x,d.y,d.z,d.w)}else(this.settings.renderMode===R.StretchedBillBoard||this.settings.renderMode===R.VerticalBillBoard||this.settings.renderMode===R.HorizontalBillBoard||this.settings.renderMode===R.BillBoard)&&this.rotationBuffer.setX(e,h.rotation);let u;if(r.worldSpace?u=h.position:(u=this.vector_,h.parentMatrix?u.copy(h.position).applyMatrix4(h.parentMatrix):u.copy(h.position).applyMatrix4(r.emitter.matrixWorld)),this.offsetBuffer.setXYZ(e,u.x,u.y,u.z),this.colorBuffer.setXYZW(e,h.color.x,h.color.y,h.color.z,h.color.w),r.worldSpace?this.sizeBuffer.setXYZ(e,h.size.x,h.size.y,h.size.z):h.parentMatrix?this.sizeBuffer.setXYZ(e,h.size.x,h.size.y,h.size.z):this.sizeBuffer.setXYZ(e,h.size.x*Math.abs(c.x),h.size.y*Math.abs(c.y),h.size.z*Math.abs(c.z)),this.uvTileBuffer.setX(e,h.uvTile),this.settings.renderMode===R.StretchedBillBoard&&this.velocityBuffer){let d=r.rendererEmitterSettings.speedFactor;d===0&&(d=.001);const p=r.rendererEmitterSettings.lengthFactor;let y;r.worldSpace?y=h.velocity:(y=this.vector_,h.parentMatrix?(this.rotationMat2_.setFromMatrix4(h.parentMatrix),y.copy(h.velocity).applyMatrix3(this.rotationMat2_)):y.copy(h.velocity).applyMatrix3(this.rotationMat_)),this.velocityBuffer.setXYZW(e,y.x*d,y.y*d,y.z*d,p)}}}),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===R.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,e*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===R.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===R.StretchedBillBoard||this.settings.renderMode===R.HorizontalBillBoard||this.settings.renderMode===R.VerticalBillBoard||this.settings.renderMode===R.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var dh=`
|
|
1014
1014
|
|
|
1015
1015
|
#include <common>
|
|
1016
1016
|
#include <tile_pars_fragment>
|
|
@@ -1043,7 +1043,7 @@ void main() {
|
|
|
1043
1043
|
|
|
1044
1044
|
#include <fog_fragment>
|
|
1045
1045
|
#include <tonemapping_fragment>
|
|
1046
|
-
}`,
|
|
1046
|
+
}`,ph=`
|
|
1047
1047
|
#include <common>
|
|
1048
1048
|
#include <tile_pars_vertex>
|
|
1049
1049
|
#include <color_pars_vertex>
|
|
@@ -1118,4 +1118,4 @@ void main() {
|
|
|
1118
1118
|
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
1119
1119
|
|
|
1120
1120
|
#include <fog_vertex>
|
|
1121
|
-
}`;class rh extends ca{constructor(e){super(e),this.vector_=new z,this.vector2_=new z,this.vector3_=new z,this.quaternion_=new j,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new ar,this.indexBuffer=new Te(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(ge),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(ge),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(ge),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(ge),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new Te(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(ge),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new Te(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(ge),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new Te(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(ge),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new Te(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(ge),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 tr(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=jn(this.settings.material.map.channel),e.map=new Le(this.settings.material.map),e.mapTransform=new Le(new tt().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===A.Trail)this.material=new on({uniforms:e,defines:t,vertexShader:th,fragmentShader:eh,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||bs,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,r=0;this.systems.forEach(i=>{for(let s=0;s<i.particleNum;s++)r+=i.particles[s].previous.length*2}),r>this.maxParticles&&this.expandBuffers(r),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,h=this.settings.uTileCount,u=this.settings.vTileCount,d=1/h,p=1/u;for(let y=0;y<l;y++){const g=c[y],f=g.uvTile%u,m=Math.floor(g.uvTile/u+.001),v=g.previous.values();let _=v.next(),b=_.value,x=b;_.done||(_=v.next());let S;_.value!==void 0?S=_.value:S=x;for(let w=0;w<g.previous.length;w++,e+=2){if(this.positionBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z),i.worldSpace?(this.positionBuffer.setXYZ(e,x.position.x,x.position.y,x.position.z),this.positionBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z)):(g.parentMatrix?this.vector_.copy(x.position).applyMatrix4(g.parentMatrix):this.vector_.copy(x.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,b.position.x,b.position.y,b.position.z),this.previousBuffer.setXYZ(e+1,b.position.x,b.position.y,b.position.z)):(g.parentMatrix?this.vector_.copy(b.position).applyMatrix4(g.parentMatrix):this.vector_.copy(b.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,S.position.x,S.position.y,S.position.z),this.nextBuffer.setXYZ(e+1,S.position.x,S.position.y,S.position.z)):(g.parentMatrix?this.vector_.copy(S.position).applyMatrix4(g.parentMatrix):this.vector_.copy(S.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,x.size),this.widthBuffer.setX(e+1,x.size);else if(g.parentMatrix)this.widthBuffer.setX(e,x.size),this.widthBuffer.setX(e+1,x.size);else{const C=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(e,x.size*C),this.widthBuffer.setX(e+1,x.size*C)}this.uvBuffer.setXY(e,(w/g.previous.length+f)*d,(u-m-1)*p),this.uvBuffer.setXY(e+1,(w/g.previous.length+f)*d,(u-m)*p),this.colorBuffer.setXYZW(e,x.color.x,x.color.y,x.color.z,x.color.w),this.colorBuffer.setXYZW(e+1,x.color.x,x.color.y,x.color.z,x.color.w),w+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++),b=x,x=S,_.done||(_=v.next(),_.value!==void 0&&(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 li{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new Pt;this._triangleIndexToArea.length=0;let r=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]),r+=t.getArea(),this._triangleIndexToArea.push(r);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new I,this._tempB=new I,this._tempC=new I,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 r=this._triangleIndexToArea.length-1;let i=0,s=r;const a=Math.random()*this._triangleIndexToArea[r];for(;i+1<s;){const p=Math.floor((i+s)/2);a<this._triangleIndexToArea[p]?s=p:i=p}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=t.getIndex().array[i*3],h=t.getIndex().array[i*3+1],u=t.getIndex().array[i*3+2],d=t.getAttribute("position");this._tempA.fromBufferAttribute(d,l),this._tempB.fromBufferAttribute(d,h),this._tempC.fromBufferAttribute(d,u),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 li(t.geometries[e.geometry])}clone(){return new li(this._geometry)}update(e,t){}}zl({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:li,loadJSON:li.fromJSON}],behaviors:[]});class ys extends vs{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(ys.equals(this.batches[i].settings,t)){this.batches[i].addSystem(e),this.systemToBatchIndex.set(e,i);return}let r;switch(t.renderMode){case A.Trail:r=new rh(t);break;case A.Mesh:case A.BillBoard:case A.VerticalBillBoard:case A.HorizontalBillBoard:case A.StretchedBillBoard:r=new $l(t);break}this.depthTexture&&r.applyDepthTexture(this.depthTexture),r.addSystem(e),this.batches.push(r),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(r)}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,r)=>{r.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const ih=ys;jl(),console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const ha=Math.sqrt(5),nh=(ha-1)/4,he=(5-ha)/20,Ri=n=>Math.floor(n)|0,Oi=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 sh(n=Math.random){const e=oh(n),t=new Float64Array(e).map(a=>Oi[a%32*4]),r=new Float64Array(e).map(a=>Oi[a%32*4+1]),i=new Float64Array(e).map(a=>Oi[a%32*4+2]),s=new Float64Array(e).map(a=>Oi[a%32*4+3]);return function(a,o,c,l){let h,u,d,p,y;const g=(a+o+c+l)*nh,f=Ri(a+g),m=Ri(o+g),v=Ri(c+g),_=Ri(l+g),b=(f+m+v+_)*he,x=f-b,S=m-b,w=v-b,C=_-b,M=a-x,T=o-S,E=c-w,P=l-C;let k=0,R=0,U=0,N=0;M>T?k++:R++,M>E?k++:U++,M>P?k++:N++,T>E?R++:U++,T>P?R++:N++,E>P?U++:N++;const G=k>=3?1:0,B=R>=3?1:0,oe=U>=3?1:0,Q=N>=3?1:0,re=k>=2?1:0,$=R>=2?1:0,me=U>=2?1:0,ye=N>=2?1:0,ie=k>=1?1:0,H=R>=1?1:0,W=U>=1?1:0,rt=N>=1?1:0,ze=M-G+he,Xe=T-B+he,qe=E-oe+he,be=P-Q+he,Be=M-re+2*he,xe=T-$+2*he,it=E-me+2*he,nt=P-ye+2*he,Y=M-ie+3*he,He=T-H+3*he,st=E-W+3*he,Tt=P-rt+3*he,ot=M-1+4*he,at=T-1+4*he,ct=E-1+4*he,lt=P-1+4*he,Ie=f&255,Ue=m&255,Ne=v&255,De=_&255;let Fe=.6-M*M-T*T-E*E-P*P;if(Fe<0)h=0;else{const q=Ie+e[Ue+e[Ne+e[De]]];Fe*=Fe,h=Fe*Fe*(t[q]*M+r[q]*T+i[q]*E+s[q]*P)}let V=.6-ze*ze-Xe*Xe-qe*qe-be*be;if(V<0)u=0;else{const q=Ie+G+e[Ue+B+e[Ne+oe+e[De+Q]]];V*=V,u=V*V*(t[q]*ze+r[q]*Xe+i[q]*qe+s[q]*be)}let nr=.6-Be*Be-xe*xe-it*it-nt*nt;if(nr<0)d=0;else{const q=Ie+re+e[Ue+$+e[Ne+me+e[De+ye]]];nr*=nr,d=nr*nr*(t[q]*Be+r[q]*xe+i[q]*it+s[q]*nt)}let sr=.6-Y*Y-He*He-st*st-Tt*Tt;if(sr<0)p=0;else{const q=Ie+ie+e[Ue+H+e[Ne+W+e[De+rt]]];sr*=sr,p=sr*sr*(t[q]*Y+r[q]*He+i[q]*st+s[q]*Tt)}let or=.6-ot*ot-at*at-ct*ct-lt*lt;if(or<0)y=0;else{const q=Ie+1+e[Ue+1+e[Ne+1+e[De+1]]];or*=or,y=or*or*(t[q]*ot+r[q]*at+i[q]*ct+s[q]*lt)}return 27*(h+u+d+p+y)}}function oh(n){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 r=t+~~(n()*(256-t)),i=e[t];e[t]=e[r],e[r]=i}for(let t=256;t<512;t++)e[t]=e[t-256];return e}class ah{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 J;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(J||(J={}));class ua{constructor(e,t,r){var i,s,a,o,c,l,h,u,d,p,y,g,f,m,v;this._closedByUser=!1,this.handleOpenEvent=_=>this.handleEvent(J.open,_),this.handleErrorEvent=_=>this.handleEvent(J.error,_),this.handleCloseEvent=_=>this.handleEvent(J.close,_),this.handleMessageEvent=_=>this.handleEvent(J.message,_),this._url=e,this._protocols=t,this._options={buffer:r?.buffer,retry:{maxRetries:(i=r?.retry)===null||i===void 0?void 0:i.maxRetries,instantReconnect:(s=r?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=r?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=r?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(h=(l=r?.listeners)===null||l===void 0?void 0:l.close)!==null&&h!==void 0?h:[]],error:[...(d=(u=r?.listeners)===null||u===void 0?void 0:u.error)!==null&&d!==void 0?d:[]],message:[...(y=(p=r?.listeners)===null||p===void 0?void 0:p.message)!==null&&y!==void 0?y:[]],retry:[...(f=(g=r?.listeners)===null||g===void 0?void 0:g.retry)!==null&&f!==void 0?f:[]],reconnect:[...(v=(m=r?.listeners)===null||m===void 0?void 0:m.reconnect)!==null&&v!==void 0?v:[]]}},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,r){this._options.listeners[e].push({listener:t,options:r})}removeEventListener(e,t,r){const i=s=>s.listener!==t||s.options!==r;this._options.listeners[e]=this._options.listeners[e].filter(i)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(J.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(J.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(J.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(J.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(J.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(J.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(J.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(J.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const r=this._options.listeners[e],i=[];r.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 J.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case J.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const r={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},i=new CustomEvent(J.reconnect,{detail:r});this.dispatchEvent(J.reconnect,i),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case J.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=r=>{const i=new CustomEvent(J.retry,{detail:r});this.handleEvent(J.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 ch{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(J.open,e,t),this}onClose(e,t){return this.addListener(J.close,e,t),this}onError(e,t){return this.addListener(J.error,e,t),this}onMessage(e,t){return this.addListener(J.message,e,t),this}onRetry(e,t){return this.addListener(J.retry,e,t),this}onReconnect(e,t){return this.addListener(J.reconnect,e,t),this}build(){return new ua(this._url,this._protocols,this._options)}addListener(e,t,r){var i,s,a,o,c,l,h,u,d,p,y,g,f,m,v,_,b,x,S,w,C;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:(d=(u=(h=this._options)===null||h===void 0?void 0:h.listeners)===null||u===void 0?void 0:u.error)!==null&&d!==void 0?d:[],message:(g=(y=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||y===void 0?void 0:y.message)!==null&&g!==void 0?g:[],retry:(v=(m=(f=this._options)===null||f===void 0?void 0:f.listeners)===null||m===void 0?void 0:m.retry)!==null&&v!==void 0?v:[],reconnect:(x=(b=(_=this._options)===null||_===void 0?void 0:_.listeners)===null||b===void 0?void 0:b.reconnect)!==null&&x!==void 0?x:[],[e]:[...(C=(w=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||w===void 0?void 0:w[e])!==null&&C!==void 0?C:[],{listener:t,options:r}]}}),this}}const lh=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:ah,Websocket:ua,WebsocketBuilder:ch,get WebsocketEvent(){return J}},Symbol.toStringTag,{value:"Module"})),Jn=0,da=1,pa=2,Gn=2,Wn=1.25,fa=1,br=32,zi=65535,hh=Math.pow(2,-24),Xn=Symbol("SKIP_GENERATION");function uh(n){return n.index?n.index.count:n.attributes.position.count}function Xt(n){return uh(n)/3}function dh(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function ph(n,e){if(!n.index){const t=n.attributes.position.count,r=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=dh(t,r);n.setIndex(new Te(i,1));for(let s=0;s<t;s++)i[s]=s}}function ma(n,e){const t=Xt(n),r=e||n.drawRange,i=r.start/3,s=(r.start+r.count)/3,a=Math.max(0,i),o=Math.min(t,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function ya(n,e){if(!n.groups||!n.groups.length)return ma(n,e);const t=[],r=new Set,i=e||n.drawRange,s=i.start/3,a=(i.start+i.count)/3;for(const c of n.groups){const l=c.start/3,h=(c.start+c.count)/3;r.add(Math.max(s,l)),r.add(Math.min(a,h))}const o=Array.from(r.values()).sort((c,l)=>c-l);for(let c=0;c<o.length-1;c++){const l=o[c],h=o[c+1];t.push({offset:Math.floor(l),count:Math.floor(h-l)})}return t}function fh(n,e){const t=Xt(n),r=ya(n,e).sort((a,o)=>a.offset-o.offset),i=r[r.length-1];i.count=Math.min(t-i.offset,i.count);let s=0;return r.forEach(({count:a})=>s+=a),t!==s}function qn(n,e,t,r,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,h=-1/0,u=1/0,d=1/0,p=1/0,y=-1/0,g=-1/0,f=-1/0;for(let m=e*6,v=(e+t)*6;m<v;m+=6){const _=n[m+0],b=n[m+1],x=_-b,S=_+b;x<s&&(s=x),S>c&&(c=S),_<u&&(u=_),_>y&&(y=_);const w=n[m+2],C=n[m+3],M=w-C,T=w+C;M<a&&(a=M),T>l&&(l=T),w<d&&(d=w),w>g&&(g=w);const E=n[m+4],P=n[m+5],k=E-P,R=E+P;k<o&&(o=k),R>h&&(h=R),E<p&&(p=E),E>f&&(f=E)}r[0]=s,r[1]=a,r[2]=o,r[3]=c,r[4]=l,r[5]=h,i[0]=u,i[1]=d,i[2]=p,i[3]=y,i[4]=g,i[5]=f}function mh(n,e=null,t=null,r=null){const i=n.attributes.position,s=n.index?n.index.array:null,a=Xt(n),o=i.normalized;let c;e===null?(c=new Float32Array(a*6),t=0,r=a):(c=e,t=t||0,r=r||a);const l=i.array,h=i.offset||0;let u=3;i.isInterleavedBufferAttribute&&(u=i.data.stride);const d=["getX","getY","getZ"];for(let p=t;p<t+r;p++){const y=p*3,g=p*6;let f=y+0,m=y+1,v=y+2;s&&(f=s[f],m=s[m],v=s[v]),o||(f=f*u+h,m=m*u+h,v=v*u+h);for(let _=0;_<3;_++){let b,x,S;o?(b=i[d[_]](f),x=i[d[_]](m),S=i[d[_]](v)):(b=l[f+_],x=l[m+_],S=l[v+_]);let w=b;x<w&&(w=x),S<w&&(w=S);let C=b;x>C&&(C=x),S>C&&(C=S);const M=(C-w)/2,T=_*2;c[g+T+0]=w+M,c[g+T+1]=M+(Math.abs(w)+M)*hh}}return c}function Z(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function ga(n){let e=-1,t=-1/0;for(let r=0;r<3;r++){const i=n[r+3]-n[r];i>t&&(t=i,e=r)}return e}function va(n,e){e.set(n)}function _a(n,e,t){let r,i;for(let s=0;s<3;s++){const a=s+3;r=n[s],i=e[s],t[s]=r<i?r:i,r=n[a],i=e[a],t[a]=r>i?r:i}}function Bi(n,e,t){for(let r=0;r<3;r++){const i=e[n+2*r],s=e[n+2*r+1],a=i-s,o=i+s;a<t[r]&&(t[r]=a),o>t[r+3]&&(t[r+3]=o)}}function xr(n){const e=n[3]-n[0],t=n[4]-n[1],r=n[5]-n[2];return 2*(e*t+t*r+r*e)}const ft=32,yh=(n,e)=>n.candidate-e.candidate,bt=new Array(ft).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ii=new Float32Array(6);function gh(n,e,t,r,i,s){let a=-1,o=0;if(s===Jn)a=ga(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===da)a=ga(n),a!==-1&&(o=vh(t,r,i,a));else if(s===pa){const c=xr(n);let l=Wn*i;const h=r*6,u=(r+i)*6;for(let d=0;d<3;d++){const p=e[d],y=(e[d+3]-p)/ft;if(i<ft/4){const g=[...bt];g.length=i;let f=0;for(let v=h;v<u;v+=6,f++){const _=g[f];_.candidate=t[v+2*d],_.count=0;const{bounds:b,leftCacheBounds:x,rightCacheBounds:S}=_;for(let w=0;w<3;w++)S[w]=1/0,S[w+3]=-1/0,x[w]=1/0,x[w+3]=-1/0,b[w]=1/0,b[w+3]=-1/0;Bi(v,t,b)}g.sort(yh);let m=i;for(let v=0;v<m;v++){const _=g[v];for(;v+1<m&&g[v+1].candidate===_.candidate;)g.splice(v+1,1),m--}for(let v=h;v<u;v+=6){const _=t[v+2*d];for(let b=0;b<m;b++){const x=g[b];_>=x.candidate?Bi(v,t,x.rightCacheBounds):(Bi(v,t,x.leftCacheBounds),x.count++)}}for(let v=0;v<m;v++){const _=g[v],b=_.count,x=i-_.count,S=_.leftCacheBounds,w=_.rightCacheBounds;let C=0;b!==0&&(C=xr(S)/c);let M=0;x!==0&&(M=xr(w)/c);const T=fa+Wn*(C*b+M*x);T<l&&(a=d,l=T,o=_.candidate)}}else{for(let m=0;m<ft;m++){const v=bt[m];v.count=0,v.candidate=p+y+m*y;const _=v.bounds;for(let b=0;b<3;b++)_[b]=1/0,_[b+3]=-1/0}for(let m=h;m<u;m+=6){let v=~~((t[m+2*d]-p)/y);v>=ft&&(v=ft-1);const _=bt[v];_.count++,Bi(m,t,_.bounds)}const g=bt[ft-1];va(g.bounds,g.rightCacheBounds);for(let m=ft-2;m>=0;m--){const v=bt[m],_=bt[m+1];_a(v.bounds,_.rightCacheBounds,v.rightCacheBounds)}let f=0;for(let m=0;m<ft-1;m++){const v=bt[m],_=v.count,b=v.bounds,x=bt[m+1].rightCacheBounds;_!==0&&(f===0?va(b,Ii):_a(b,Ii,Ii)),f+=_;let S=0,w=0;f!==0&&(S=xr(Ii)/c);const C=i-f;C!==0&&(w=xr(x)/c);const M=fa+Wn*(S*f+w*C);M<l&&(a=d,l=M,o=v.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function vh(n,e,t,r){let i=0;for(let s=e,a=e+t;s<a;s++)i+=n[s*6+r*2];return i/t}class Hn{constructor(){this.boundingData=new Float32Array(6)}}function _h(n,e,t,r,i,s){let a=r,o=r+i-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){for(let h=0;h<3;h++){let u=e[a*3+h];e[a*3+h]=e[o*3+h],e[o*3+h]=u}for(let h=0;h<6;h++){let u=t[a*6+h];t[a*6+h]=t[o*6+h],t[o*6+h]=u}a++,o--}else return a}}function bh(n,e,t,r,i,s){let a=r,o=r+i-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){let h=n[a];n[a]=n[o],n[o]=h;for(let u=0;u<6;u++){let d=t[a*6+u];t[a*6+u]=t[o*6+u],t[o*6+u]=d}a++,o--}else return a}}function we(n,e){return e[n+15]===65535}function Pe(n,e){return e[n+6]}function Ee(n,e){return e[n+14]}function ke(n){return n+8}function Ae(n,e){return e[n+6]}function ba(n,e){return e[n+7]}let xa,Sr,Ui,Sa;const xh=Math.pow(2,32);function Yn(n){return"count"in n?1:1+Yn(n.left)+Yn(n.right)}function Sh(n,e,t){return xa=new Float32Array(t),Sr=new Uint32Array(t),Ui=new Uint16Array(t),Sa=new Uint8Array(t),Zn(n,e)}function Zn(n,e){const t=n/4,r=n/2,i="count"in e,s=e.boundingData;for(let a=0;a<6;a++)xa[t+a]=s[a];if(i)if(e.buffer){const a=e.buffer;Sa.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=br){const l=o/2;we(l,Ui)||(Sr[o/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,o=e.count;return Sr[t+6]=a,Ui[r+14]=o,Ui[r+15]=zi,n+br}else{const a=e.left,o=e.right,c=e.splitAxis;let l;if(l=Zn(n+br,a),l/4>xh)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Sr[t+6]=l/4,l=Zn(l,o),Sr[t+7]=c,l}}function wh(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,r=t>2**16,i=r?4:2,s=e?new SharedArrayBuffer(t*i):new ArrayBuffer(t*i),a=r?new Uint32Array(s):new Uint16Array(s);for(let o=0,c=a.length;o<c;o++)a[o]=o;return a}function Mh(n,e,t,r,i){const{maxDepth:s,verbose:a,maxLeafTris:o,strategy:c,onProgress:l,indirect:h}=i,u=n._indirectBuffer,d=n.geometry,p=d.index?d.index.array:null,y=h?bh:_h,g=Xt(d),f=new Float32Array(6);let m=!1;const v=new Hn;return qn(e,t,r,v.boundingData,f),b(v,t,r,f),v;function _(x){l&&l(x/g)}function b(x,S,w,C=null,M=0){if(!m&&M>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d))),w<=o||M>=s)return _(S+w),x.offset=S,x.count=w,x;const T=gh(x.boundingData,C,e,S,w,c);if(T.axis===-1)return _(S+w),x.offset=S,x.count=w,x;const E=y(u,p,e,S,w,T);if(E===S||E===S+w)_(S+w),x.offset=S,x.count=w;else{x.splitAxis=T.axis;const P=new Hn,k=S,R=E-S;x.left=P,qn(e,k,R,P.boundingData,f),b(P,k,R,f,M+1);const U=new Hn,N=E,G=w-R;x.right=U,qn(e,N,G,U.boundingData,f),b(U,N,G,f,M+1)}return x}}function Th(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=wh(t,e.useSharedArrayBuffer),fh(t,e.range)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),n._indirectBuffer||ph(t,e);const r=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=mh(t),s=e.indirect?ma(t,e.range):ya(t,e.range);n._roots=s.map(a=>{const o=Mh(n,i,a.offset,a.count,e),c=Yn(o),l=new r(br*c);return Sh(0,o,l),l})}class mt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let r=1/0,i=-1/0;for(let s=0,a=e.length;s<a;s++){const o=e[s][t];r=o<r?o:r,i=o>i?o:i}this.min=r,this.max=i}setFromPoints(e,t){let r=1/0,i=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);r=c<r?c:r,i=c>i?c:i}this.min=r,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}mt.prototype.setFromBox=function(){const n=new I;return function(e,t){const r=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++){n.x=r.x*o+i.x*(1-o),n.y=r.y*c+i.y*(1-c),n.z=r.z*l+i.z*(1-l);const h=e.dot(n);s=Math.min(h,s),a=Math.max(h,a)}this.min=s,this.max=a}}();const Ch=function(){const n=new I,e=new I,t=new I;return function(r,i,s){const a=r.start,o=n,c=i.start,l=e;t.subVectors(a,c),n.subVectors(r.end,r.start),e.subVectors(i.end,i.start);const h=t.dot(l),u=l.dot(o),d=l.dot(l),p=t.dot(o),y=o.dot(o)*d-u*u;let g,f;y!==0?g=(h*u-p*d)/y:g=0,f=(h+g*u)/d,s.x=g,s.y=f}}(),Qn=function(){const n=new Vt,e=new I,t=new I;return function(r,i,s,a){Ch(r,i,n);let o=n.x,c=n.y;if(o>=0&&o<=1&&c>=0&&c<=1){r.at(o,s),i.at(c,a);return}else if(o>=0&&o<=1){c<0?i.at(0,a):i.at(1,a),r.closestPointToPoint(a,!0,s);return}else if(c>=0&&c<=1){o<0?r.at(0,s):r.at(1,s),i.closestPointToPoint(s,!0,a);return}else{let l;o<0?l=r.start:l=r.end;let h;c<0?h=i.start:h=i.end;const u=e,d=t;if(r.closestPointToPoint(h,!0,e),i.closestPointToPoint(l,!0,t),u.distanceToSquared(h)<=d.distanceToSquared(l)){s.copy(u),a.copy(h);return}else{s.copy(l),a.copy(d);return}}}}(),Ph=function(){const n=new I,e=new I,t=new xs,r=new ht;return function(i,s){const{radius:a,center:o}=i,{a:c,b:l,c:h}=s;if(r.start=c,r.end=l,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a||(r.start=c,r.end=h,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a)||(r.start=l,r.end=h,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a))return!0;const u=s.getPlane(t);if(Math.abs(u.distanceToPoint(o))<=a){const d=u.projectPoint(o,e);if(s.containsPoint(d))return!0}return!1}}(),Eh=1e-15;function Kn(n){return Math.abs(n)<Eh}class Re extends Pt{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new I),this.satBounds=new Array(4).fill().map(()=>new mt),this.points=[this.a,this.b,this.c],this.sphere=new Ss,this.plane=new xs,this.needsUpdate=!0}intersectsSphere(e){return Ph(e,this)}update(){const e=this.a,t=this.b,r=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],h=a[1];l.subVectors(e,t),h.setFromPoints(l,i);const u=s[2],d=a[2];u.subVectors(t,r),d.setFromPoints(u,i);const p=s[3],y=a[3];p.subVectors(r,e),y.setFromPoints(p,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}Re.prototype.closestPointToSegment=function(){const n=new I,e=new I,t=new ht;return function(r,i=null,s=null){const{start:a,end:o}=r,c=this.points;let l,h=1/0;for(let u=0;u<3;u++){const d=(u+1)%3;t.start.copy(c[u]),t.end.copy(c[d]),Qn(t,r,n,e),l=n.distanceToSquared(e),l<h&&(h=l,i&&i.copy(n),s&&s.copy(e))}return this.closestPointToPoint(a,n),l=a.distanceToSquared(n),l<h&&(h=l,i&&i.copy(n),s&&s.copy(a)),this.closestPointToPoint(o,n),l=o.distanceToSquared(n),l<h&&(h=l,i&&i.copy(n),s&&s.copy(o)),Math.sqrt(h)}}(),Re.prototype.intersectsTriangle=function(){const n=new Re,e=new Array(3),t=new Array(3),r=new mt,i=new mt,s=new I,a=new I,o=new I,c=new I,l=new I,h=new ht,u=new ht,d=new ht,p=new I;function y(g,f,m){const v=g.points;let _=0,b=-1;for(let x=0;x<3;x++){const{start:S,end:w}=h;S.copy(v[x]),w.copy(v[(x+1)%3]),h.delta(a);const C=Kn(f.distanceToPoint(S));if(Kn(f.normal.dot(a))&&C){m.copy(h),_=2;break}const M=f.intersectLine(h,p);if(!M&&C&&p.copy(S),(M||C)&&!Kn(p.distanceTo(w))){if(_<=1)(_===1?m.start:m.end).copy(p),C&&(b=_);else if(_>=2){(b===1?m.start:m.end).copy(p),_=2;break}if(_++,_===2&&b===-1)break}}return _}return function(g,f=null,m=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(n.copy(g),n.update(),g=n);const v=this.plane,_=g.plane;if(Math.abs(v.normal.dot(_.normal))>1-1e-10){const b=this.satBounds,x=this.satAxes;t[0]=g.a,t[1]=g.b,t[2]=g.c;for(let C=0;C<4;C++){const M=b[C],T=x[C];if(r.setFromPoints(T,t),M.isSeparated(r))return!1}const S=g.satBounds,w=g.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let C=0;C<4;C++){const M=S[C],T=w[C];if(r.setFromPoints(T,e),M.isSeparated(r))return!1}for(let C=0;C<4;C++){const M=x[C];for(let T=0;T<4;T++){const E=w[T];if(s.crossVectors(M,E),r.setFromPoints(s,e),i.setFromPoints(s,t),r.isSeparated(i))return!1}}return f&&(m||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),f.start.set(0,0,0),f.end.set(0,0,0)),!0}else{const b=y(this,_,u);if(b===1&&g.containsPoint(u.end))return f&&(f.start.copy(u.end),f.end.copy(u.end)),!0;if(b!==2)return!1;const x=y(g,v,d);if(x===1&&this.containsPoint(d.end))return f&&(f.start.copy(d.end),f.end.copy(d.end)),!0;if(x!==2)return!1;if(u.delta(o),d.delta(c),o.dot(c)<0){let P=d.start;d.start=d.end,d.end=P}const S=u.start.dot(o),w=u.end.dot(o),C=d.start.dot(o),M=d.end.dot(o),T=w<C,E=S<M;return S!==M&&C!==w&&T===E?!1:(f&&(l.subVectors(u.start,d.start),l.dot(o)>0?f.start.copy(u.start):f.start.copy(d.start),l.subVectors(u.end,d.end),l.dot(o)<0?f.end.copy(u.end):f.end.copy(d.end)),!0)}}}(),Re.prototype.distanceToPoint=function(){const n=new I;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),Re.prototype.distanceToTriangle=function(){const n=new I,e=new I,t=["a","b","c"],r=new ht,i=new ht;return function(s,a=null,o=null){const c=a||o?r:null;if(this.intersectsTriangle(s,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let l=1/0;for(let h=0;h<3;h++){let u;const d=t[h],p=s[d];this.closestPointToPoint(p,n),u=p.distanceToSquared(n),u<l&&(l=u,a&&a.copy(n),o&&o.copy(p));const y=this[d];s.closestPointToPoint(y,n),u=y.distanceToSquared(n),u<l&&(l=u,a&&a.copy(y),o&&o.copy(n))}for(let h=0;h<3;h++){const u=t[h],d=t[(h+1)%3];r.set(this[u],this[d]);for(let p=0;p<3;p++){const y=t[p],g=t[(p+1)%3];i.set(s[y],s[g]),Qn(r,i,n,e);const f=n.distanceToSquared(e);f<l&&(l=f,a&&a.copy(n),o&&o.copy(e))}}return Math.sqrt(l)}}();class fe{constructor(e,t,r){this.isOrientedBox=!0,this.min=new I,this.max=new I,this.matrix=new Ve,this.invMatrix=new Ve,this.points=new Array(8).fill().map(()=>new I),this.satAxes=new Array(3).fill().map(()=>new I),this.satBounds=new Array(3).fill().map(()=>new mt),this.alignedSatBounds=new Array(3).fill().map(()=>new mt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),r&&this.matrix.copy(r)}set(e,t,r){this.min.copy(e),this.max.copy(t),this.matrix.copy(r),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}fe.prototype.update=function(){return function(){const n=this.matrix,e=this.min,t=this.max,r=this.points;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let h=0;h<=1;h++){const u=1*c|2*l|4*h,d=r[u];d.x=c?t.x:e.x,d.y=l?t.y:e.y,d.z=h?t.z:e.z,d.applyMatrix4(n)}const i=this.satBounds,s=this.satAxes,a=r[0];for(let c=0;c<3;c++){const l=s[c],h=i[c],u=1<<c,d=r[u];l.subVectors(a,d),h.setFromPoints(l,r)}const o=this.alignedSatBounds;o[0].setFromPointsField(r,"x"),o[1].setFromPointsField(r,"y"),o[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),fe.prototype.intersectsBox=function(){const n=new mt;return function(e){this.needsUpdate&&this.update();const t=e.min,r=e.max,i=this.satBounds,s=this.satAxes,a=this.alignedSatBounds;if(n.min=t.x,n.max=r.x,a[0].isSeparated(n)||(n.min=t.y,n.max=r.y,a[1].isSeparated(n))||(n.min=t.z,n.max=r.z,a[2].isSeparated(n)))return!1;for(let o=0;o<3;o++){const c=s[o],l=i[o];if(n.setFromBox(c,e),l.isSeparated(n))return!1}return!0}}(),fe.prototype.intersectsTriangle=function(){const n=new Re,e=new Array(3),t=new mt,r=new mt,i=new I;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(n.copy(s),n.update(),s=n);const a=this.satBounds,o=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let u=0;u<3;u++){const d=a[u],p=o[u];if(t.setFromPoints(p,e),d.isSeparated(t))return!1}const c=s.satBounds,l=s.satAxes,h=this.points;for(let u=0;u<3;u++){const d=c[u],p=l[u];if(t.setFromPoints(p,h),d.isSeparated(t))return!1}for(let u=0;u<3;u++){const d=o[u];for(let p=0;p<4;p++){const y=l[p];if(i.crossVectors(d,y),t.setFromPoints(i,e),r.setFromPoints(i,h),t.isSeparated(r))return!1}}return!0}}(),fe.prototype.closestPointToPoint=function(){return function(n,e){return this.needsUpdate&&this.update(),e.copy(n).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),fe.prototype.distanceToPoint=function(){const n=new I;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),fe.prototype.distanceToBox=function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new ht),t=new Array(12).fill().map(()=>new ht),r=new I,i=new I;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,r),s.closestPointToPoint(r,i),o&&o.copy(r),c&&c.copy(i)),0;const l=a*a,h=s.min,u=s.max,d=this.points;let p=1/0;for(let g=0;g<8;g++){const f=d[g];i.copy(f).clamp(h,u);const m=f.distanceToSquared(i);if(m<p&&(p=m,o&&o.copy(f),c&&c.copy(i),m<l))return Math.sqrt(m)}let y=0;for(let g=0;g<3;g++)for(let f=0;f<=1;f++)for(let m=0;m<=1;m++){const v=(g+1)%3,_=(g+2)%3,b=f<<v|m<<_,x=1<<g|f<<v|m<<_,S=d[b],w=d[x];e[y].set(S,w);const C=n[g],M=n[v],T=n[_],E=t[y],P=E.start,k=E.end;P[C]=h[C],P[M]=f?h[M]:u[M],P[T]=m?h[T]:u[M],k[C]=u[C],k[M]=f?h[M]:u[M],k[T]=m?h[T]:u[M],y++}for(let g=0;g<=1;g++)for(let f=0;f<=1;f++)for(let m=0;m<=1;m++){i.x=g?u.x:h.x,i.y=f?u.y:h.y,i.z=m?u.z:h.z,this.closestPointToPoint(i,r);const v=i.distanceToSquared(r);if(v<p&&(p=v,o&&o.copy(r),c&&c.copy(i),v<l))return Math.sqrt(v)}for(let g=0;g<12;g++){const f=e[g];for(let m=0;m<12;m++){const v=t[m];Qn(f,v,r,i);const _=r.distanceToSquared(i);if(_<p&&(p=_,o&&o.copy(r),c&&c.copy(i),_<l))return Math.sqrt(_)}}return Math.sqrt(p)}}();class $n{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 kh extends $n{constructor(){super(()=>new Re)}}const Oe=new kh;class Ah{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=r=>{t&&e.push(t),t=r,this.float32Array=new Float32Array(r),this.uint16Array=new Uint16Array(r),this.uint32Array=new Uint32Array(r)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const X=new Ah;let xt,qt;const Ht=[],Ni=new $n(()=>new Ye);function Rh(n,e,t,r,i,s){xt=Ni.getPrimitive(),qt=Ni.getPrimitive(),Ht.push(xt,qt),X.setBuffer(n._roots[e]);const a=es(0,n.geometry,t,r,i,s);X.clearBuffer(),Ni.releasePrimitive(xt),Ni.releasePrimitive(qt),Ht.pop(),Ht.pop();const o=Ht.length;return o>0&&(qt=Ht[o-1],xt=Ht[o-2]),a}function es(n,e,t,r,i=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=X;let h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);return Z(n,o,xt),r(u,d,!1,a,s+n,xt)}else{let u=function(E){const{uint16Array:P,uint32Array:k}=X;let R=E*2;for(;!we(R,P);)E=ke(E),R=E*2;return Pe(E,k)},d=function(E){const{uint16Array:P,uint32Array:k}=X;let R=E*2;for(;!we(R,P);)E=Ae(E,k),R=E*2;return Pe(E,k)+Ee(R,P)};const p=ke(n),y=Ae(n,l);let g=p,f=y,m,v,_,b;if(i&&(_=xt,b=qt,Z(g,o,_),Z(f,o,b),m=i(_),v=i(b),v<m)){g=y,f=p;const E=m;m=v,v=E,_=b}_||(_=xt,Z(g,o,_));const x=we(g*2,c),S=t(_,x,m,a+1,s+g);let w;if(S===Gn){const E=u(g),P=d(g)-E;w=r(E,P,!0,a+1,s+g,_)}else w=S&&es(g,e,t,r,i,s,a+1);if(w)return!0;b=qt,Z(f,o,b);const C=we(f*2,c),M=t(b,C,v,a+1,s+f);let T;if(M===Gn){const E=u(f),P=d(f)-E;T=r(E,P,!0,a+1,s+f,b)}else T=M&&es(f,e,t,r,i,s,a+1);return!!T}}const wr=new I,ts=new I;function Oh(n,e,t={},r=0,i=1/0){const s=r*r,a=i*i;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:h=>(wr.copy(e).clamp(h.min,h.max),wr.distanceToSquared(e)),intersectsBounds:(h,u,d)=>d<o&&d<a,intersectsTriangle:(h,u)=>{h.closestPointToPoint(e,wr);const d=e.distanceToSquared(wr);return d<o&&(ts.copy(wr),o=d,c=u),d<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(ts):t.point=ts.clone(),t.distance=l,t.faceIndex=c,t}const zh=parseInt(Ga)>=169,At=new I,Rt=new I,Ot=new I,Di=new Vt,Fi=new Vt,Li=new Vt,wa=new I,Ma=new I,Ta=new I,Mr=new I;function Bh(n,e,t,r,i,s,a,o){let c;if(s===Ja?c=n.intersectTriangle(r,t,e,!0,i):c=n.intersectTriangle(e,t,r,s!==sn,i),c===null)return null;const l=n.origin.distanceTo(i);return l<a||l>o?null:{distance:l,point:i.clone()}}function Ih(n,e,t,r,i,s,a,o,c,l,h){At.fromBufferAttribute(e,s),Rt.fromBufferAttribute(e,a),Ot.fromBufferAttribute(e,o);const u=Bh(n,At,Rt,Ot,Mr,c,l,h);if(u){const d=new I;Pt.getBarycoord(Mr,At,Rt,Ot,d),r&&(Di.fromBufferAttribute(r,s),Fi.fromBufferAttribute(r,a),Li.fromBufferAttribute(r,o),u.uv=Pt.getInterpolation(Mr,At,Rt,Ot,Di,Fi,Li,new Vt)),i&&(Di.fromBufferAttribute(i,s),Fi.fromBufferAttribute(i,a),Li.fromBufferAttribute(i,o),u.uv1=Pt.getInterpolation(Mr,At,Rt,Ot,Di,Fi,Li,new Vt)),t&&(wa.fromBufferAttribute(t,s),Ma.fromBufferAttribute(t,a),Ta.fromBufferAttribute(t,o),u.normal=Pt.getInterpolation(Mr,At,Rt,Ot,wa,Ma,Ta,new I),u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1));const p={a:s,b:a,c:o,normal:new I,materialIndex:0};Pt.getNormal(At,Rt,Ot,p.normal),u.face=p,u.faceIndex=s,zh&&(u.barycoord=d)}return u}function Vi(n,e,t,r,i,s,a){const o=r*3;let c=o+0,l=o+1,h=o+2;const u=n.index;n.index&&(c=u.getX(c),l=u.getX(l),h=u.getX(h));const{position:d,normal:p,uv:y,uv1:g}=n.attributes,f=Ih(t,d,p,y,g,c,l,h,e,s,a);return f?(f.faceIndex=r,i&&i.push(f),f):null}function te(n,e,t,r){const i=n.a,s=n.b,a=n.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=r.getX(o),i.y=r.getY(o),i.z=r.getZ(o),s.x=r.getX(c),s.y=r.getY(c),s.z=r.getZ(c),a.x=r.getX(l),a.y=r.getY(l),a.z=r.getZ(l)}function Uh(n,e,t,r,i,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let h=r,u=r+i;h<u;h++)Vi(c,e,t,h,s,a,o)}function Nh(n,e,t,r,i,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,h=null;for(let u=r,d=r+i;u<d;u++){let p;p=Vi(o,e,t,u,null,s,a),p&&p.distance<l&&(h=p,l=p.distance)}return h}function Dh(n,e,t,r,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let h=n,u=e+n;h<u;h++){let d;if(d=h,te(a,d*3,c,l),a.needsUpdate=!0,r(a,d,i,s))return!0}return!1}function Fh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,r=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const h=n._roots;for(let d=0,p=h.length;d<p;d++)s=h[d],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),u(0,l),l+=s.byteLength;function u(d,p,y=!1){const g=d*2;if(o[g+15]===zi){const f=a[d+6],m=o[g+14];let v=1/0,_=1/0,b=1/0,x=-1/0,S=-1/0,w=-1/0;for(let C=3*f,M=3*(f+m);C<M;C++){let T=r[C];const E=i.getX(T),P=i.getY(T),k=i.getZ(T);E<v&&(v=E),E>x&&(x=E),P<_&&(_=P),P>S&&(S=P),k<b&&(b=k),k>w&&(w=k)}return c[d+0]!==v||c[d+1]!==_||c[d+2]!==b||c[d+3]!==x||c[d+4]!==S||c[d+5]!==w?(c[d+0]=v,c[d+1]=_,c[d+2]=b,c[d+3]=x,c[d+4]=S,c[d+5]=w,!0):!1}else{const f=d+8,m=a[d+6],v=f+p,_=m+p;let b=y,x=!1,S=!1;e?b||(x=e.has(v),S=e.has(_),b=!x&&!S):(x=!0,S=!0);const w=b||x,C=b||S;let M=!1;w&&(M=u(f,p,b));let T=!1;C&&(T=u(m,p,b));const E=M||T;if(E)for(let P=0;P<3;P++){const k=f+P,R=m+P,U=c[k],N=c[k+3],G=c[R],B=c[R+3];c[d+P]=U<G?U:G,c[d+P+3]=N>B?N:B}return E}}}function St(n,e,t,r,i){let s,a,o,c,l,h;const u=1/t.direction.x,d=1/t.direction.y,p=1/t.direction.z,y=t.origin.x,g=t.origin.y,f=t.origin.z;let m=e[n],v=e[n+3],_=e[n+1],b=e[n+3+1],x=e[n+2],S=e[n+3+2];return u>=0?(s=(m-y)*u,a=(v-y)*u):(s=(v-y)*u,a=(m-y)*u),d>=0?(o=(_-g)*d,c=(b-g)*d):(o=(b-g)*d,c=(_-g)*d),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),p>=0?(l=(x-f)*p,h=(S-f)*p):(l=(S-f)*p,h=(x-f)*p),s>h||l>a)?!1:((l>s||s!==s)&&(s=l),(h<a||a!==a)&&(a=h),s<=i&&a>=r)}function Lh(n,e,t,r,i,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let h=r,u=r+i;h<u;h++){let d=l?l[h]:h;Vi(c,e,t,d,s,a,o)}}function Vh(n,e,t,r,i,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,h=null;for(let u=r,d=r+i;u<d;u++){let p;p=Vi(o,e,t,c?c[u]:u,null,s,a),p&&p.distance<l&&(h=p,l=p.distance)}return h}function jh(n,e,t,r,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let h=n,u=e+n;h<u;h++){let d;if(d=t.resolveTriangleIndex(h),te(a,d*3,c,l),a.needsUpdate=!0,r(a,d,i,s))return!0}return!1}function Jh(n,e,t,r,i,s,a){X.setBuffer(n._roots[e]),rs(0,n,t,r,i,s,a),X.clearBuffer()}function rs(n,e,t,r,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=X,h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);Uh(e,t,r,u,d,i,s,a)}else{const u=ke(n);St(u,o,r,s,a)&&rs(u,e,t,r,i,s,a);const d=Ae(n,l);St(d,o,r,s,a)&&rs(d,e,t,r,i,s,a)}}const Gh=["x","y","z"];function Wh(n,e,t,r,i,s){X.setBuffer(n._roots[e]);const a=is(0,n,t,r,i,s);return X.clearBuffer(),a}function is(n,e,t,r,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=X;let l=n*2;if(we(l,o)){const h=Pe(n,c),u=Ee(l,o);return Nh(e,t,r,h,u,i,s)}else{const h=ba(n,c),u=Gh[h],d=r.direction[u]>=0;let p,y;d?(p=ke(n),y=Ae(n,c)):(p=Ae(n,c),y=ke(n));const g=St(p,a,r,i,s)?is(p,e,t,r,i,s):null;if(g){const m=g.point[u];if(d?m<=a[y+h]:m>=a[y+h+3])return g}const f=St(y,a,r,i,s)?is(y,e,t,r,i,s):null;return g&&f?g.distance<=f.distance?g:f:g||f||null}}const ji=new Ye,Yt=new Re,Zt=new Re,Tr=new Ve,Ca=new fe,Ji=new fe;function Xh(n,e,t,r){X.setBuffer(n._roots[e]);const i=ns(0,n,t,r);return X.clearBuffer(),i}function ns(n,e,t,r,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=X;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Ca.set(t.boundingBox.min,t.boundingBox.max,r),i=Ca),we(c,a)){const l=e.geometry,h=l.index,u=l.attributes.position,d=t.index,p=t.attributes.position,y=Pe(n,o),g=Ee(c,a);if(Tr.copy(r).invert(),t.boundsTree)return Z(n,s,Ji),Ji.matrix.copy(Tr),Ji.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:f=>Ji.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(r),f.b.applyMatrix4(r),f.c.applyMatrix4(r),f.needsUpdate=!0;for(let m=y*3,v=(g+y)*3;m<v;m+=3)if(te(Zt,m,h,u),Zt.needsUpdate=!0,f.intersectsTriangle(Zt))return!0;return!1}});for(let f=y*3,m=(g+y)*3;f<m;f+=3){te(Yt,f,h,u),Yt.a.applyMatrix4(Tr),Yt.b.applyMatrix4(Tr),Yt.c.applyMatrix4(Tr),Yt.needsUpdate=!0;for(let v=0,_=d.count;v<_;v+=3)if(te(Zt,v,d,p),Zt.needsUpdate=!0,Yt.intersectsTriangle(Zt))return!0}}else{const l=n+8,h=o[n+6];return Z(l,s,ji),!!(i.intersectsBox(ji)&&ns(l,e,t,r,i)||(Z(h,s,ji),i.intersectsBox(ji)&&ns(h,e,t,r,i)))}}const Gi=new Ve,ss=new fe,Cr=new fe,qh=new I,Hh=new I,Yh=new I,Zh=new I;function Qh(n,e,t,r={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),ss.set(e.boundingBox.min,e.boundingBox.max,t),ss.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,h=e.attributes.position,u=e.index,d=Oe.getPrimitive(),p=Oe.getPrimitive();let y=qh,g=Hh,f=null,m=null;i&&(f=Yh,m=Zh);let v=1/0,_=null,b=null;return Gi.copy(t).invert(),Cr.matrix.copy(Gi),n.shapecast({boundsTraverseOrder:x=>ss.distanceToBox(x),intersectsBounds:(x,S,w)=>w<v&&w<a?(S&&(Cr.min.copy(x.min),Cr.max.copy(x.max),Cr.needsUpdate=!0),!0):!1,intersectsRange:(x,S)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:w=>Cr.distanceToBox(w),intersectsBounds:(w,C,M)=>M<v&&M<a,intersectsRange:(w,C)=>{for(let M=w,T=w+C;M<T;M++){te(p,3*M,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let E=x,P=x+S;E<P;E++){te(d,3*E,l,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,y,f);if(k<v&&(g.copy(y),m&&m.copy(f),v=k,_=E,b=M),k<s)return!0}}}});{const w=Xt(e);for(let C=0,M=w;C<M;C++){te(p,3*C,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let T=x,E=x+S;T<E;T++){te(d,3*T,l,c),d.needsUpdate=!0;const P=d.distanceToTriangle(p,y,f);if(P<v&&(g.copy(y),m&&m.copy(f),v=P,_=T,b=C),P<s)return!0}}}}}),Oe.releasePrimitive(d),Oe.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(g):r.point=g.clone(),r.distance=v,r.faceIndex=_,i&&(i.point?i.point.copy(m):i.point=m.clone(),i.point.applyMatrix4(Gi),g.applyMatrix4(Gi),i.distance=g.sub(i.point).length(),i.faceIndex=b),r)}function Kh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,r=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const h=n._roots;for(let d=0,p=h.length;d<p;d++)s=h[d],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),u(0,l),l+=s.byteLength;function u(d,p,y=!1){const g=d*2;if(o[g+15]===zi){const f=a[d+6],m=o[g+14];let v=1/0,_=1/0,b=1/0,x=-1/0,S=-1/0,w=-1/0;for(let C=f,M=f+m;C<M;C++){const T=3*n.resolveTriangleIndex(C);for(let E=0;E<3;E++){let P=T+E;P=r?r[P]:P;const k=i.getX(P),R=i.getY(P),U=i.getZ(P);k<v&&(v=k),k>x&&(x=k),R<_&&(_=R),R>S&&(S=R),U<b&&(b=U),U>w&&(w=U)}}return c[d+0]!==v||c[d+1]!==_||c[d+2]!==b||c[d+3]!==x||c[d+4]!==S||c[d+5]!==w?(c[d+0]=v,c[d+1]=_,c[d+2]=b,c[d+3]=x,c[d+4]=S,c[d+5]=w,!0):!1}else{const f=d+8,m=a[d+6],v=f+p,_=m+p;let b=y,x=!1,S=!1;e?b||(x=e.has(v),S=e.has(_),b=!x&&!S):(x=!0,S=!0);const w=b||x,C=b||S;let M=!1;w&&(M=u(f,p,b));let T=!1;C&&(T=u(m,p,b));const E=M||T;if(E)for(let P=0;P<3;P++){const k=f+P,R=m+P,U=c[k],N=c[k+3],G=c[R],B=c[R+3];c[d+P]=U<G?U:G,c[d+P+3]=N>B?N:B}return E}}}function $h(n,e,t,r,i,s,a){X.setBuffer(n._roots[e]),os(0,n,t,r,i,s,a),X.clearBuffer()}function os(n,e,t,r,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=X,h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);Lh(e,t,r,u,d,i,s,a)}else{const u=ke(n);St(u,o,r,s,a)&&os(u,e,t,r,i,s,a);const d=Ae(n,l);St(d,o,r,s,a)&&os(d,e,t,r,i,s,a)}}const eu=["x","y","z"];function tu(n,e,t,r,i,s){X.setBuffer(n._roots[e]);const a=as(0,n,t,r,i,s);return X.clearBuffer(),a}function as(n,e,t,r,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=X;let l=n*2;if(we(l,o)){const h=Pe(n,c),u=Ee(l,o);return Vh(e,t,r,h,u,i,s)}else{const h=ba(n,c),u=eu[h],d=r.direction[u]>=0;let p,y;d?(p=ke(n),y=Ae(n,c)):(p=Ae(n,c),y=ke(n));const g=St(p,a,r,i,s)?as(p,e,t,r,i,s):null;if(g){const m=g.point[u];if(d?m<=a[y+h]:m>=a[y+h+3])return g}const f=St(y,a,r,i,s)?as(y,e,t,r,i,s):null;return g&&f?g.distance<=f.distance?g:f:g||f||null}}const Wi=new Ye,Qt=new Re,Kt=new Re,Pr=new Ve,Pa=new fe,Xi=new fe;function ru(n,e,t,r){X.setBuffer(n._roots[e]);const i=cs(0,n,t,r);return X.clearBuffer(),i}function cs(n,e,t,r,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=X;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Pa.set(t.boundingBox.min,t.boundingBox.max,r),i=Pa),we(c,a)){const l=e.geometry,h=l.index,u=l.attributes.position,d=t.index,p=t.attributes.position,y=Pe(n,o),g=Ee(c,a);if(Pr.copy(r).invert(),t.boundsTree)return Z(n,s,Xi),Xi.matrix.copy(Pr),Xi.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:f=>Xi.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(r),f.b.applyMatrix4(r),f.c.applyMatrix4(r),f.needsUpdate=!0;for(let m=y,v=g+y;m<v;m++)if(te(Kt,3*e.resolveTriangleIndex(m),h,u),Kt.needsUpdate=!0,f.intersectsTriangle(Kt))return!0;return!1}});for(let f=y,m=g+y;f<m;f++){const v=e.resolveTriangleIndex(f);te(Qt,3*v,h,u),Qt.a.applyMatrix4(Pr),Qt.b.applyMatrix4(Pr),Qt.c.applyMatrix4(Pr),Qt.needsUpdate=!0;for(let _=0,b=d.count;_<b;_+=3)if(te(Kt,_,d,p),Kt.needsUpdate=!0,Qt.intersectsTriangle(Kt))return!0}}else{const l=n+8,h=o[n+6];return Z(l,s,Wi),!!(i.intersectsBox(Wi)&&cs(l,e,t,r,i)||(Z(h,s,Wi),i.intersectsBox(Wi)&&cs(h,e,t,r,i)))}}const qi=new Ve,ls=new fe,Er=new fe,iu=new I,nu=new I,su=new I,ou=new I;function au(n,e,t,r={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),ls.set(e.boundingBox.min,e.boundingBox.max,t),ls.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,h=e.attributes.position,u=e.index,d=Oe.getPrimitive(),p=Oe.getPrimitive();let y=iu,g=nu,f=null,m=null;i&&(f=su,m=ou);let v=1/0,_=null,b=null;return qi.copy(t).invert(),Er.matrix.copy(qi),n.shapecast({boundsTraverseOrder:x=>ls.distanceToBox(x),intersectsBounds:(x,S,w)=>w<v&&w<a?(S&&(Er.min.copy(x.min),Er.max.copy(x.max),Er.needsUpdate=!0),!0):!1,intersectsRange:(x,S)=>{if(e.boundsTree){const w=e.boundsTree;return w.shapecast({boundsTraverseOrder:C=>Er.distanceToBox(C),intersectsBounds:(C,M,T)=>T<v&&T<a,intersectsRange:(C,M)=>{for(let T=C,E=C+M;T<E;T++){const P=w.resolveTriangleIndex(T);te(p,3*P,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let k=x,R=x+S;k<R;k++){const U=n.resolveTriangleIndex(k);te(d,3*U,l,c),d.needsUpdate=!0;const N=d.distanceToTriangle(p,y,f);if(N<v&&(g.copy(y),m&&m.copy(f),v=N,_=k,b=T),N<s)return!0}}}})}else{const w=Xt(e);for(let C=0,M=w;C<M;C++){te(p,3*C,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let T=x,E=x+S;T<E;T++){const P=n.resolveTriangleIndex(T);te(d,3*P,l,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,y,f);if(k<v&&(g.copy(y),m&&m.copy(f),v=k,_=T,b=C),k<s)return!0}}}}}),Oe.releasePrimitive(d),Oe.releasePrimitive(p),v===1/0?null:(r.point?r.point.copy(g):r.point=g.clone(),r.distance=v,r.faceIndex=_,i&&(i.point?i.point.copy(m):i.point=m.clone(),i.point.applyMatrix4(qi),g.applyMatrix4(qi),i.distance=g.sub(i.point).length(),i.faceIndex=b),r)}function cu(){return typeof SharedArrayBuffer<"u"}const kr=new X.constructor,Hi=new X.constructor,wt=new $n(()=>new Ye),$t=new Ye,er=new Ye,hs=new Ye,us=new Ye;let ds=!1;function lu(n,e,t,r){if(ds)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");ds=!0;const i=n._roots,s=e._roots;let a,o=0,c=0;const l=new Ve().copy(t).invert();for(let h=0,u=i.length;h<u;h++){kr.setBuffer(i[h]),c=0;const d=wt.getPrimitive();Z(0,kr.float32Array,d),d.applyMatrix4(l);for(let p=0,y=s.length;p<y&&(Hi.setBuffer(s[p]),a=Ge(0,0,t,l,r,o,c,0,0,d),Hi.clearBuffer(),c+=s[p].length,!a);p++);if(wt.releasePrimitive(d),kr.clearBuffer(),o+=i[h].length,a)break}return ds=!1,a}function Ge(n,e,t,r,i,s=0,a=0,o=0,c=0,l=null,h=!1){let u,d;h?(u=Hi,d=kr):(u=kr,d=Hi);const p=u.float32Array,y=u.uint32Array,g=u.uint16Array,f=d.float32Array,m=d.uint32Array,v=d.uint16Array,_=n*2,b=e*2,x=we(_,g),S=we(b,v);let w=!1;if(S&&x)h?w=i(Pe(e,m),Ee(e*2,v),Pe(n,y),Ee(n*2,g),c,a+e,o,s+n):w=i(Pe(n,y),Ee(n*2,g),Pe(e,m),Ee(e*2,v),o,s+n,c,a+e);else if(S){const C=wt.getPrimitive();Z(e,f,C),C.applyMatrix4(t);const M=ke(n),T=Ae(n,y);Z(M,p,$t),Z(T,p,er);const E=C.intersectsBox($t),P=C.intersectsBox(er);w=E&&Ge(e,M,r,t,i,a,s,c,o+1,C,!h)||P&&Ge(e,T,r,t,i,a,s,c,o+1,C,!h),wt.releasePrimitive(C)}else{const C=ke(e),M=Ae(e,m);Z(C,f,hs),Z(M,f,us);const T=l.intersectsBox(hs),E=l.intersectsBox(us);if(T&&E)w=Ge(n,C,t,r,i,s,a,o,c+1,l,h)||Ge(n,M,t,r,i,s,a,o,c+1,l,h);else if(T)if(x)w=Ge(n,C,t,r,i,s,a,o,c+1,l,h);else{const P=wt.getPrimitive();P.copy(hs).applyMatrix4(t);const k=ke(n),R=Ae(n,y);Z(k,p,$t),Z(R,p,er);const U=P.intersectsBox($t),N=P.intersectsBox(er);w=U&&Ge(C,k,r,t,i,a,s,c,o+1,P,!h)||N&&Ge(C,R,r,t,i,a,s,c,o+1,P,!h),wt.releasePrimitive(P)}else if(E)if(x)w=Ge(n,M,t,r,i,s,a,o,c+1,l,h);else{const P=wt.getPrimitive();P.copy(us).applyMatrix4(t);const k=ke(n),R=Ae(n,y);Z(k,p,$t),Z(R,p,er);const U=P.intersectsBox($t),N=P.intersectsBox(er);w=U&&Ge(M,k,r,t,i,a,s,c,o+1,P,!h)||N&&Ge(M,R,r,t,i,a,s,c,o+1,P,!h),wt.releasePrimitive(P)}}return w}const Yi=new fe,Ea=new Ye,hu={strategy:Jn,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class zr{static serialize(e,t={}){t={cloneBuffers:!0,...t};const r=e.geometry,i=e._roots,s=e._indirectBuffer,a=r.getIndex();let o;return t.cloneBuffers?o={roots:i.map(c=>c.slice()),index:a?a.array.slice():null,indirectBuffer:s?s.slice():null}:o={roots:i,index:a?a.array:null,indirectBuffer:s},o}static deserialize(e,t,r={}){r={setIndex:!0,indirect:!!e.indirectBuffer,...r};const{index:i,roots:s,indirectBuffer:a}=e,o=new zr(t,{...r,[Xn]:!0});if(o._roots=s,o._indirectBuffer=a||null,r.setIndex){const c=t.getIndex();if(c===null){const l=new Te(e.index,1,!1);t.setIndex(l)}else c.array!==i&&(c.array.set(i),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...hu,[Xn]:!1},t),t.useSharedArrayBuffer&&!cu())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[Xn]||(Th(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Ye))),this.resolveTriangleIndex=t.indirect?r=>this._indirectBuffer[r]:r=>r}refit(e=null){return(this.indirect?Kh:Fh)(this,e)}traverse(e,t=0){const r=this._roots[t],i=new Uint32Array(r),s=new Uint16Array(r);a(0);function a(o,c=0){const l=o*2,h=s[l+15]===zi;if(h){const u=i[o+6],d=s[l+14];e(c,h,new Float32Array(r,o*4,6),u,d)}else{const u=o+br/4,d=i[o+6],p=i[o+7];e(c,h,new Float32Array(r,o*4,6),p)||(a(u,c+1),a(d,c+1))}}}raycast(e,t=ws,r=0,i=1/0){const s=this._roots,a=this.geometry,o=[],c=t.isMaterial,l=Array.isArray(t),h=a.groups,u=c?t.side:t,d=this.indirect?$h:Jh;for(let p=0,y=s.length;p<y;p++){const g=l?t[h[p].materialIndex].side:u,f=o.length;if(d(this,p,g,e,o,r,i),l){const m=h[p].materialIndex;for(let v=f,_=o.length;v<_;v++)o[v].face.materialIndex=m}}return o}raycastFirst(e,t=ws,r=0,i=1/0){const s=this._roots,a=this.geometry,o=t.isMaterial,c=Array.isArray(t);let l=null;const h=a.groups,u=o?t.side:t,d=this.indirect?tu:Wh;for(let p=0,y=s.length;p<y;p++){const g=c?t[h[p].materialIndex].side:u,f=d(this,p,g,e,r,i);f!=null&&(l==null||f.distance<l.distance)&&(l=f,c&&(f.face.materialIndex=h[p].materialIndex))}return l}intersectsGeometry(e,t){let r=!1;const i=this._roots,s=this.indirect?ru:Xh;for(let a=0,o=i.length;a<o&&(r=s(this,a,e,t),!r);a++);return r}shapecast(e){const t=Oe.getPrimitive(),r=this.indirect?jh:Dh;let{boundsTraverseOrder:i,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=e;if(a&&o){const u=a;a=(d,p,y,g,f)=>u(d,p,y,g,f)?!0:r(d,p,this,o,y,g,t)}else a||(o?a=(u,d,p,y)=>r(u,d,this,o,p,y,t):a=(u,d,p)=>p);let c=!1,l=0;const h=this._roots;for(let u=0,d=h.length;u<d;u++){const p=h[u];if(c=Rh(this,u,s,a,i,l),c)break;l+=p.byteLength}return Oe.releasePrimitive(t),c}bvhcast(e,t,r){let{intersectsRanges:i,intersectsTriangles:s}=r;const a=Oe.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const g=this.resolveTriangleIndex(y);te(a,g*3,o,c)}:y=>{te(a,y*3,o,c)},h=Oe.getPrimitive(),u=e.geometry.index,d=e.geometry.attributes.position,p=e.indirect?y=>{const g=e.resolveTriangleIndex(y);te(h,g*3,u,d)}:y=>{te(h,y*3,u,d)};if(s){const y=(g,f,m,v,_,b,x,S)=>{for(let w=m,C=m+v;w<C;w++){p(w),h.a.applyMatrix4(t),h.b.applyMatrix4(t),h.c.applyMatrix4(t),h.needsUpdate=!0;for(let M=g,T=g+f;M<T;M++)if(l(M),a.needsUpdate=!0,s(a,h,M,w,_,b,x,S))return!0}return!1};if(i){const g=i;i=function(f,m,v,_,b,x,S,w){return g(f,m,v,_,b,x,S,w)?!0:y(f,m,v,_,b,x,S,w)}}else i=y}return lu(this,e,t,i)}intersectsBox(e,t){return Yi.set(e.min,e.max,t),Yi.needsUpdate=!0,this.shapecast({intersectsBounds:r=>Yi.intersectsBox(r),intersectsTriangle:r=>Yi.intersectsTriangle(r)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,r={},i={},s=0,a=1/0){return(this.indirect?au:Qh)(this,e,t,r,i,s,a)}closestPointToPoint(e,t={},r=0,i=1/0){return Oh(this,e,t,r,i)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Z(0,new Float32Array(t),Ea),e.union(Ea)}),e}}function ka(n,e,t){return n===null?null:(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n)}const Zi=new Xa,Aa=new I,Ra=new Ve,uu=an.prototype.raycast,du=Wa.prototype.raycast,Oa=new I,ue=new an,Qi=[];function pu(n,e){this.isBatchedMesh?fu.call(this,n,e):mu.call(this,n,e)}function fu(n,e){if(this.boundsTrees){const t=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ue.material=this.material,ue.geometry=this.geometry;const a=ue.geometry.boundsTree,o=ue.geometry.drawRange;ue.geometry.boundingSphere===null&&(ue.geometry.boundingSphere=new Ss);for(let c=0,l=r.length;c<l;c++){if(!this.getVisibleAt(c))continue;const h=r[c].geometryIndex;if(ue.geometry.boundsTree=t[h],this.getMatrixAt(c,ue.matrixWorld).premultiply(s),!ue.geometry.boundsTree){this.getBoundingBoxAt(h,ue.geometry.boundingBox),this.getBoundingSphereAt(h,ue.geometry.boundingSphere);const u=i[h];ue.geometry.setDrawRange(u.start,u.count)}ue.raycast(n,Qi);for(let u=0,d=Qi.length;u<d;u++){const p=Qi[u];p.object=this,p.batchId=c,e.push(p)}Qi.length=0}ue.geometry.boundsTree=a,ue.geometry.drawRange=o,ue.material=null,ue.geometry=null}else du.call(this,n,e)}function mu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;Ra.copy(this.matrixWorld).invert(),Zi.copy(n.ray).applyMatrix4(Ra),Oa.setFromMatrixScale(this.matrixWorld),Aa.copy(Zi.direction).multiply(Oa);const t=Aa.length(),r=n.near/t,i=n.far/t,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=ka(s.raycastFirst(Zi,this.material,r,i),this,n);a&&e.push(a)}else{const a=s.raycast(Zi,this.material,r,i);for(let o=0,c=a.length;o<c;o++){const l=ka(a[o],this,n);l&&e.push(l)}}}else uu.call(this,n,e)}function yu(n={}){return this.boundsTree=new zr(this,n),this.boundsTree}const zt=new I,Bt=new I,It=new I,za=new cn,Ki=new I,ps=new I,Ba=new cn,Ia=new cn,$i=new Ve,Ua=new Ve;function Ar(n,e){if(!n&&!e)return;const t=n.count===e.count,r=n.normalized===e.normalized,i=n.array.constructor===e.array.constructor,s=n.itemSize===e.itemSize;if(!t||!r||!i||!s)throw new Error}function Rr(n,e=null){const t=n.array.constructor,r=n.normalized,i=n.itemSize,s=e===null?n.count:e;return new Te(new t(i*s),i,r)}function Na(n,e,t=0){if(n.isInterleavedBufferAttribute){const r=n.itemSize;for(let i=0,s=n.count;i<s;i++){const a=i+t;e.setX(a,n.getX(i)),r>=2&&e.setY(a,n.getY(i)),r>=3&&e.setZ(a,n.getZ(i)),r>=4&&e.setW(a,n.getW(i))}}else{const r=e.array,i=r.constructor,s=r.BYTES_PER_ELEMENT*n.itemSize*t;new i(r.buffer,s,n.array.length).set(n.array)}}function gu(n,e,t){const r=n.elements,i=e.elements;for(let s=0,a=i.length;s<a;s++)r[s]+=i[s]*t}function Da(n,e,t){const r=n.skeleton,i=n.geometry,s=r.bones,a=r.boneInverses;Ba.fromBufferAttribute(i.attributes.skinIndex,e),Ia.fromBufferAttribute(i.attributes.skinWeight,e),$i.elements.fill(0);for(let o=0;o<4;o++){const c=Ia.getComponent(o);if(c!==0){const l=Ba.getComponent(o);Ua.multiplyMatrices(s[l].matrixWorld,a[l]),gu($i,Ua,c)}}return $i.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection($i),t}function fs(n,e,t,r,i){Ki.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=e[s],c=n[s];o!==0&&(ps.fromBufferAttribute(c,r),t?Ki.addScaledVector(ps,o):Ki.addScaledVector(ps.sub(i),o))}i.add(Ki)}function vu(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new ar){const r=n[0].index!==null,{useGroups:i=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;t.clearGroups();for(let h=0;h<n.length;++h){const u=n[h];let d=0;if(r!==(u.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 p in u.attributes){if(!o.has(p))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.');c[p]===void 0&&(c[p]=[]),c[p].push(u.attributes[p]),d++}if(d!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(i){let p;if(r)p=u.index.count;else if(u.attributes.position!==void 0)p=u.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,p,h),l+=p}}if(r){let h=!1;if(!t.index){let u=0;for(let d=0;d<n.length;++d)u+=n[d].index.count;t.setIndex(new Te(new Uint32Array(u),1,!1)),h=!0}if(s||h){const u=t.index;let d=0,p=0;for(let y=0;y<n.length;++y){const g=n[y],f=g.index;if(a[y]!==!0)for(let m=0;m<f.count;++m)u.setX(d,f.getX(m)+p),d++;p+=g.attributes.position.count}}}for(const h in c){const u=c[h];if(!(h in t.attributes)){let y=0;for(const g in u)y+=u[g].count;t.setAttribute(h,Rr(c[h][0],y))}const d=t.attributes[h];let p=0;for(let y=0,g=u.length;y<g;y++){const f=u[y];a[y]!==!0&&Na(f,d,p),p+=f.count}}return t}function _u(n,e){if(n===null||e===null)return n===e;if(n.length!==e.length)return!1;for(let t=0,r=n.length;t<r;t++)if(n[t]!==e[t])return!1;return!0}function bu(n){const{index:e,attributes:t}=n;if(e)for(let r=0,i=e.count;r<i;r+=3){const s=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,s)}else for(const r in t){const i=t[r],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),h=i.getComponent(a+2,c);i.setComponent(a,c,h),i.setComponent(a+2,c,l)}}return n}class xu{constructor(e){this.matrixWorld=new Ve,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,r=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,r){r.boneTexture||r.computeBoneTexture(),r.update();const s=r.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,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&_u(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===r)}}class Su{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(r=>{r.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 ar),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 ar){let t=[];const{meshes:r,useGroups:i,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=r.length;o<c;o++){const l=r[o],h=s[o],u=a.get(l);!u||u.didChange(l)?(this._convertToStaticGeometry(l,h),t.push(!1),u?u.update():a.set(l,new xu(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 Te(new Float32Array(0),4,!1))}else vu(s,{useGroups:i,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new ar){const r=e.geometry,i=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=r.attributes,c=t.attributes;!t.index&&r.index&&(t.index=r.index.clone()),c.position||t.setAttribute("position",Rr(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",Rr(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",Rr(o.tangent)),Ar(r.index,t.index),Ar(o.position,c.position),s&&Ar(o.normal,c.normal),a&&Ar(o.tangent,c.tangent);const l=o.position,h=s?o.normal:null,u=a?o.tangent:null,d=r.morphAttributes.position,p=r.morphAttributes.normal,y=r.morphAttributes.tangent,g=r.morphTargetsRelative,f=e.morphTargetInfluences,m=new qa;m.getNormalMatrix(e.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let v=0,_=o.position.count;v<_;v++)zt.fromBufferAttribute(l,v),h&&Bt.fromBufferAttribute(h,v),u&&(za.fromBufferAttribute(u,v),It.fromBufferAttribute(u,v)),f&&(d&&fs(d,f,g,v,zt),p&&fs(p,f,g,v,Bt),y&&fs(y,f,g,v,It)),e.isSkinnedMesh&&(e.applyBoneTransform(v,zt),h&&Da(e,v,Bt),u&&Da(e,v,It)),i&&zt.applyMatrix4(e.matrixWorld),c.position.setXYZ(v,zt.x,zt.y,zt.z),h&&(i&&Bt.applyNormalMatrix(m),c.normal.setXYZ(v,Bt.x,Bt.y,Bt.z)),u&&(i&&It.transformDirection(e.matrixWorld),c.tangent.setXYZW(v,It.x,It.y,It.z,za.w));for(const v in this.attributes){const _=this.attributes[v];_==="position"||_==="tangent"||_==="normal"||!(_ in o)||(c[_]||t.setAttribute(_,Rr(o[_])),Ar(o[_],c[_]),Na(o[_],c[_]))}return e.matrixWorld.determinant()<0&&bu(t),t}}const wu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:da,CENTER:Jn,CONTAINED:Gn,ExtendedTriangle:Re,MeshBVH:zr,OrientedBox:fe,SAH:pa,StaticGeometryGenerator:Su,acceleratedRaycast:pu,computeBoundsTree:yu},Symbol.toStringTag,{value:"Module"}));class Mu{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}}export{jo as $70d766613f57b014$export$2e2bcd8739ae039,ih as BatchedParticleRenderer,ms as Builder,Or as ByteBuffer,Nt as ConstantColor,L as ConstantValue,We as Matrix4,zr as MeshBVH,ec as MotionController,nn as ParticleSystem,A as RenderMode,Ts as SIZE_PREFIX_LENGTH,ki as TrailParticle,Me as Vector4,Mu as WorkerBase,Oc as bundler,sh as createNoise4D,Ya as fetchProfile,lh as index,wu as index$1,Hc as md5,Jc as v5};
|
|
1121
|
+
}`;class fh extends da{constructor(e){super(e),this.vector_=new z,this.vector2_=new z,this.vector3_=new z,this.quaternion_=new j,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new lr,this.indexBuffer=new Te(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(ge),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(ge),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(ge),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new Te(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(ge),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new Te(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(ge),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new Te(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(ge),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new Te(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(ge),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new Te(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(ge),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 ir(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=Gn(this.settings.material.map.channel),e.map=new Ve(this.settings.material.map),e.mapTransform=new Ve(new rt().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===R.Trail)this.material=new cn({uniforms:e,defines:t,vertexShader:ph,fragmentShader:dh,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||Ss,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,r=0;this.systems.forEach(i=>{for(let s=0;s<i.particleNum;s++)r+=i.particles[s].previous.length*2}),r>this.maxParticles&&this.expandBuffers(r),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,h=this.settings.uTileCount,u=this.settings.vTileCount,d=1/h,p=1/u;for(let y=0;y<l;y++){const g=c[y],f=g.uvTile%u,m=Math.floor(g.uvTile/u+.001),b=g.previous.values();let v=b.next(),x=v.value,_=x;v.done||(v=b.next());let S;v.value!==void 0?S=v.value:S=_;for(let w=0;w<g.previous.length;w++,e+=2){if(this.positionBuffer.setXYZ(e,_.position.x,_.position.y,_.position.z),this.positionBuffer.setXYZ(e+1,_.position.x,_.position.y,_.position.z),i.worldSpace?(this.positionBuffer.setXYZ(e,_.position.x,_.position.y,_.position.z),this.positionBuffer.setXYZ(e+1,_.position.x,_.position.y,_.position.z)):(g.parentMatrix?this.vector_.copy(_.position).applyMatrix4(g.parentMatrix):this.vector_.copy(_.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,x.position.x,x.position.y,x.position.z),this.previousBuffer.setXYZ(e+1,x.position.x,x.position.y,x.position.z)):(g.parentMatrix?this.vector_.copy(x.position).applyMatrix4(g.parentMatrix):this.vector_.copy(x.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,S.position.x,S.position.y,S.position.z),this.nextBuffer.setXYZ(e+1,S.position.x,S.position.y,S.position.z)):(g.parentMatrix?this.vector_.copy(S.position).applyMatrix4(g.parentMatrix):this.vector_.copy(S.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,_.size),this.widthBuffer.setX(e+1,_.size);else if(g.parentMatrix)this.widthBuffer.setX(e,_.size),this.widthBuffer.setX(e+1,_.size);else{const C=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(e,_.size*C),this.widthBuffer.setX(e+1,_.size*C)}this.uvBuffer.setXY(e,(w/g.previous.length+f)*d,(u-m-1)*p),this.uvBuffer.setXY(e+1,(w/g.previous.length+f)*d,(u-m)*p),this.colorBuffer.setXYZW(e,_.color.x,_.color.y,_.color.z,_.color.w),this.colorBuffer.setXYZW(e+1,_.color.x,_.color.y,_.color.z,_.color.w),w+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++),x=_,_=S,v.done||(v=b.next(),v.value!==void 0&&(S=v.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 ui{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new Et;this._triangleIndexToArea.length=0;let r=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]),r+=t.getArea(),this._triangleIndexToArea.push(r);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new I,this._tempB=new I,this._tempC=new I,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 r=this._triangleIndexToArea.length-1;let i=0,s=r;const a=Math.random()*this._triangleIndexToArea[r];for(;i+1<s;){const p=Math.floor((i+s)/2);a<this._triangleIndexToArea[p]?s=p:i=p}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=t.getIndex().array[i*3],h=t.getIndex().array[i*3+1],u=t.getIndex().array[i*3+2],d=t.getAttribute("position");this._tempA.fromBufferAttribute(d,l),this._tempB.fromBufferAttribute(d,h),this._tempC.fromBufferAttribute(d,u),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 ui(t.geometries[e.geometry])}clone(){return new ui(this._geometry)}update(e,t){}}Wl({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:ui,loadJSON:ui.fromJSON}],behaviors:[]});class vs extends _s{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(vs.equals(this.batches[i].settings,t)){this.batches[i].addSystem(e),this.systemToBatchIndex.set(e,i);return}let r;switch(t.renderMode){case R.Trail:r=new fh(t);break;case R.Mesh:case R.BillBoard:case R.VerticalBillBoard:case R.HorizontalBillBoard:case R.StretchedBillBoard:r=new uh(t);break}this.depthTexture&&r.applyDepthTexture(this.depthTexture),r.addSystem(e),this.batches.push(r),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(r)}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,r)=>{r.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const mh=vs;eh(),console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const fa=Math.sqrt(5),yh=(fa-1)/4,he=(5-fa)/20,zi=n=>Math.floor(n)|0,Bi=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 gh(n=Math.random){const e=vh(n),t=new Float64Array(e).map(a=>Bi[a%32*4]),r=new Float64Array(e).map(a=>Bi[a%32*4+1]),i=new Float64Array(e).map(a=>Bi[a%32*4+2]),s=new Float64Array(e).map(a=>Bi[a%32*4+3]);return function(a,o,c,l){let h,u,d,p,y;const g=(a+o+c+l)*yh,f=zi(a+g),m=zi(o+g),b=zi(c+g),v=zi(l+g),x=(f+m+b+v)*he,_=f-x,S=m-x,w=b-x,C=v-x,M=a-_,T=o-S,E=c-w,P=l-C;let k=0,A=0,N=0,U=0;M>T?k++:A++,M>E?k++:N++,M>P?k++:U++,T>E?A++:N++,T>P?A++:U++,E>P?N++:U++;const G=k>=3?1:0,B=A>=3?1:0,oe=N>=3?1:0,K=U>=3?1:0,re=k>=2?1:0,$=A>=2?1:0,me=N>=2?1:0,ye=U>=2?1:0,ie=k>=1?1:0,q=A>=1?1:0,W=N>=1?1:0,it=U>=1?1:0,Be=M-G+he,Xe=T-B+he,qe=E-oe+he,_e=P-K+he,Ie=M-re+2*he,xe=T-$+2*he,nt=E-me+2*he,st=P-ye+2*he,Y=M-ie+3*he,Ye=T-q+3*he,ot=E-W+3*he,Ct=P-it+3*he,at=M-1+4*he,ct=T-1+4*he,lt=E-1+4*he,ht=P-1+4*he,Ne=f&255,Ue=m&255,De=b&255,Fe=v&255;let Le=.6-M*M-T*T-E*E-P*P;if(Le<0)h=0;else{const X=Ne+e[Ue+e[De+e[Fe]]];Le*=Le,h=Le*Le*(t[X]*M+r[X]*T+i[X]*E+s[X]*P)}let V=.6-Be*Be-Xe*Xe-qe*qe-_e*_e;if(V<0)u=0;else{const X=Ne+G+e[Ue+B+e[De+oe+e[Fe+K]]];V*=V,u=V*V*(t[X]*Be+r[X]*Xe+i[X]*qe+s[X]*_e)}let or=.6-Ie*Ie-xe*xe-nt*nt-st*st;if(or<0)d=0;else{const X=Ne+re+e[Ue+$+e[De+me+e[Fe+ye]]];or*=or,d=or*or*(t[X]*Ie+r[X]*xe+i[X]*nt+s[X]*st)}let ar=.6-Y*Y-Ye*Ye-ot*ot-Ct*Ct;if(ar<0)p=0;else{const X=Ne+ie+e[Ue+q+e[De+W+e[Fe+it]]];ar*=ar,p=ar*ar*(t[X]*Y+r[X]*Ye+i[X]*ot+s[X]*Ct)}let cr=.6-at*at-ct*ct-lt*lt-ht*ht;if(cr<0)y=0;else{const X=Ne+1+e[Ue+1+e[De+1+e[Fe+1]]];cr*=cr,y=cr*cr*(t[X]*at+r[X]*ct+i[X]*lt+s[X]*ht)}return 27*(h+u+d+p+y)}}function vh(n){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 r=t+~~(n()*(256-t)),i=e[t];e[t]=e[r],e[r]=i}for(let t=256;t<512;t++)e[t]=e[t-256];return e}class bh{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 J;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(J||(J={}));class ma{constructor(e,t,r){var i,s,a,o,c,l,h,u,d,p,y,g,f,m,b;this._closedByUser=!1,this.handleOpenEvent=v=>this.handleEvent(J.open,v),this.handleErrorEvent=v=>this.handleEvent(J.error,v),this.handleCloseEvent=v=>this.handleEvent(J.close,v),this.handleMessageEvent=v=>this.handleEvent(J.message,v),this._url=e,this._protocols=t,this._options={buffer:r?.buffer,retry:{maxRetries:(i=r?.retry)===null||i===void 0?void 0:i.maxRetries,instantReconnect:(s=r?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=r?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=r?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(h=(l=r?.listeners)===null||l===void 0?void 0:l.close)!==null&&h!==void 0?h:[]],error:[...(d=(u=r?.listeners)===null||u===void 0?void 0:u.error)!==null&&d!==void 0?d:[]],message:[...(y=(p=r?.listeners)===null||p===void 0?void 0:p.message)!==null&&y!==void 0?y:[]],retry:[...(f=(g=r?.listeners)===null||g===void 0?void 0:g.retry)!==null&&f!==void 0?f:[]],reconnect:[...(b=(m=r?.listeners)===null||m===void 0?void 0:m.reconnect)!==null&&b!==void 0?b:[]]}},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,r){this._options.listeners[e].push({listener:t,options:r})}removeEventListener(e,t,r){const i=s=>s.listener!==t||s.options!==r;this._options.listeners[e]=this._options.listeners[e].filter(i)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(J.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(J.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(J.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(J.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(J.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(J.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(J.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(J.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const r=this._options.listeners[e],i=[];r.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 J.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case J.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const r={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},i=new CustomEvent(J.reconnect,{detail:r});this.dispatchEvent(J.reconnect,i),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case J.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=r=>{const i=new CustomEvent(J.retry,{detail:r});this.handleEvent(J.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 _h{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(J.open,e,t),this}onClose(e,t){return this.addListener(J.close,e,t),this}onError(e,t){return this.addListener(J.error,e,t),this}onMessage(e,t){return this.addListener(J.message,e,t),this}onRetry(e,t){return this.addListener(J.retry,e,t),this}onReconnect(e,t){return this.addListener(J.reconnect,e,t),this}build(){return new ma(this._url,this._protocols,this._options)}addListener(e,t,r){var i,s,a,o,c,l,h,u,d,p,y,g,f,m,b,v,x,_,S,w,C;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:(d=(u=(h=this._options)===null||h===void 0?void 0:h.listeners)===null||u===void 0?void 0:u.error)!==null&&d!==void 0?d:[],message:(g=(y=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||y===void 0?void 0:y.message)!==null&&g!==void 0?g:[],retry:(b=(m=(f=this._options)===null||f===void 0?void 0:f.listeners)===null||m===void 0?void 0:m.retry)!==null&&b!==void 0?b:[],reconnect:(_=(x=(v=this._options)===null||v===void 0?void 0:v.listeners)===null||x===void 0?void 0:x.reconnect)!==null&&_!==void 0?_:[],[e]:[...(C=(w=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||w===void 0?void 0:w[e])!==null&&C!==void 0?C:[],{listener:t,options:r}]}}),this}}const xh=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:bh,Websocket:ma,WebsocketBuilder:_h,get WebsocketEvent(){return J}},Symbol.toStringTag,{value:"Module"})),Wn=0,ya=1,ga=2,Hn=2,Xn=1.25,va=1,Sr=32,Ii=65535,Sh=Math.pow(2,-24),qn=Symbol("SKIP_GENERATION");function wh(n){return n.index?n.index.count:n.attributes.position.count}function qt(n){return wh(n)/3}function Mh(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function Th(n,e){if(!n.index){const t=n.attributes.position.count,r=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Mh(t,r);n.setIndex(new Te(i,1));for(let s=0;s<t;s++)i[s]=s}}function ba(n,e){const t=qt(n),r=e||n.drawRange,i=r.start/3,s=(r.start+r.count)/3,a=Math.max(0,i),o=Math.min(t,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function _a(n,e){if(!n.groups||!n.groups.length)return ba(n,e);const t=[],r=new Set,i=e||n.drawRange,s=i.start/3,a=(i.start+i.count)/3;for(const c of n.groups){const l=c.start/3,h=(c.start+c.count)/3;r.add(Math.max(s,l)),r.add(Math.min(a,h))}const o=Array.from(r.values()).sort((c,l)=>c-l);for(let c=0;c<o.length-1;c++){const l=o[c],h=o[c+1];t.push({offset:Math.floor(l),count:Math.floor(h-l)})}return t}function Ch(n,e){const t=qt(n),r=_a(n,e).sort((a,o)=>a.offset-o.offset),i=r[r.length-1];i.count=Math.min(t-i.offset,i.count);let s=0;return r.forEach(({count:a})=>s+=a),t!==s}function Yn(n,e,t,r,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,h=-1/0,u=1/0,d=1/0,p=1/0,y=-1/0,g=-1/0,f=-1/0;for(let m=e*6,b=(e+t)*6;m<b;m+=6){const v=n[m+0],x=n[m+1],_=v-x,S=v+x;_<s&&(s=_),S>c&&(c=S),v<u&&(u=v),v>y&&(y=v);const w=n[m+2],C=n[m+3],M=w-C,T=w+C;M<a&&(a=M),T>l&&(l=T),w<d&&(d=w),w>g&&(g=w);const E=n[m+4],P=n[m+5],k=E-P,A=E+P;k<o&&(o=k),A>h&&(h=A),E<p&&(p=E),E>f&&(f=E)}r[0]=s,r[1]=a,r[2]=o,r[3]=c,r[4]=l,r[5]=h,i[0]=u,i[1]=d,i[2]=p,i[3]=y,i[4]=g,i[5]=f}function Ph(n,e=null,t=null,r=null){const i=n.attributes.position,s=n.index?n.index.array:null,a=qt(n),o=i.normalized;let c;e===null?(c=new Float32Array(a*6),t=0,r=a):(c=e,t=t||0,r=r||a);const l=i.array,h=i.offset||0;let u=3;i.isInterleavedBufferAttribute&&(u=i.data.stride);const d=["getX","getY","getZ"];for(let p=t;p<t+r;p++){const y=p*3,g=p*6;let f=y+0,m=y+1,b=y+2;s&&(f=s[f],m=s[m],b=s[b]),o||(f=f*u+h,m=m*u+h,b=b*u+h);for(let v=0;v<3;v++){let x,_,S;o?(x=i[d[v]](f),_=i[d[v]](m),S=i[d[v]](b)):(x=l[f+v],_=l[m+v],S=l[b+v]);let w=x;_<w&&(w=_),S<w&&(w=S);let C=x;_>C&&(C=_),S>C&&(C=S);const M=(C-w)/2,T=v*2;c[g+T+0]=w+M,c[g+T+1]=M+(Math.abs(w)+M)*Sh}}return c}function Z(n,e,t){return t.min.x=e[n],t.min.y=e[n+1],t.min.z=e[n+2],t.max.x=e[n+3],t.max.y=e[n+4],t.max.z=e[n+5],t}function xa(n){let e=-1,t=-1/0;for(let r=0;r<3;r++){const i=n[r+3]-n[r];i>t&&(t=i,e=r)}return e}function Sa(n,e){e.set(n)}function wa(n,e,t){let r,i;for(let s=0;s<3;s++){const a=s+3;r=n[s],i=e[s],t[s]=r<i?r:i,r=n[a],i=e[a],t[a]=r>i?r:i}}function Ni(n,e,t){for(let r=0;r<3;r++){const i=e[n+2*r],s=e[n+2*r+1],a=i-s,o=i+s;a<t[r]&&(t[r]=a),o>t[r+3]&&(t[r+3]=o)}}function wr(n){const e=n[3]-n[0],t=n[4]-n[1],r=n[5]-n[2];return 2*(e*t+t*r+r*e)}const mt=32,Eh=(n,e)=>n.candidate-e.candidate,xt=new Array(mt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),Ui=new Float32Array(6);function kh(n,e,t,r,i,s){let a=-1,o=0;if(s===Wn)a=xa(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===ya)a=xa(n),a!==-1&&(o=Rh(t,r,i,a));else if(s===ga){const c=wr(n);let l=Xn*i;const h=r*6,u=(r+i)*6;for(let d=0;d<3;d++){const p=e[d],y=(e[d+3]-p)/mt;if(i<mt/4){const g=[...xt];g.length=i;let f=0;for(let b=h;b<u;b+=6,f++){const v=g[f];v.candidate=t[b+2*d],v.count=0;const{bounds:x,leftCacheBounds:_,rightCacheBounds:S}=v;for(let w=0;w<3;w++)S[w]=1/0,S[w+3]=-1/0,_[w]=1/0,_[w+3]=-1/0,x[w]=1/0,x[w+3]=-1/0;Ni(b,t,x)}g.sort(Eh);let m=i;for(let b=0;b<m;b++){const v=g[b];for(;b+1<m&&g[b+1].candidate===v.candidate;)g.splice(b+1,1),m--}for(let b=h;b<u;b+=6){const v=t[b+2*d];for(let x=0;x<m;x++){const _=g[x];v>=_.candidate?Ni(b,t,_.rightCacheBounds):(Ni(b,t,_.leftCacheBounds),_.count++)}}for(let b=0;b<m;b++){const v=g[b],x=v.count,_=i-v.count,S=v.leftCacheBounds,w=v.rightCacheBounds;let C=0;x!==0&&(C=wr(S)/c);let M=0;_!==0&&(M=wr(w)/c);const T=va+Xn*(C*x+M*_);T<l&&(a=d,l=T,o=v.candidate)}}else{for(let m=0;m<mt;m++){const b=xt[m];b.count=0,b.candidate=p+y+m*y;const v=b.bounds;for(let x=0;x<3;x++)v[x]=1/0,v[x+3]=-1/0}for(let m=h;m<u;m+=6){let b=~~((t[m+2*d]-p)/y);b>=mt&&(b=mt-1);const v=xt[b];v.count++,Ni(m,t,v.bounds)}const g=xt[mt-1];Sa(g.bounds,g.rightCacheBounds);for(let m=mt-2;m>=0;m--){const b=xt[m],v=xt[m+1];wa(b.bounds,v.rightCacheBounds,b.rightCacheBounds)}let f=0;for(let m=0;m<mt-1;m++){const b=xt[m],v=b.count,x=b.bounds,_=xt[m+1].rightCacheBounds;v!==0&&(f===0?Sa(x,Ui):wa(x,Ui,Ui)),f+=v;let S=0,w=0;f!==0&&(S=wr(Ui)/c);const C=i-f;C!==0&&(w=wr(_)/c);const M=va+Xn*(S*f+w*C);M<l&&(a=d,l=M,o=b.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function Rh(n,e,t,r){let i=0;for(let s=e,a=e+t;s<a;s++)i+=n[s*6+r*2];return i/t}class Zn{constructor(){this.boundingData=new Float32Array(6)}}function Ah(n,e,t,r,i,s){let a=r,o=r+i-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){for(let h=0;h<3;h++){let u=e[a*3+h];e[a*3+h]=e[o*3+h],e[o*3+h]=u}for(let h=0;h<6;h++){let u=t[a*6+h];t[a*6+h]=t[o*6+h],t[o*6+h]=u}a++,o--}else return a}}function Oh(n,e,t,r,i,s){let a=r,o=r+i-1;const c=s.pos,l=s.axis*2;for(;;){for(;a<=o&&t[a*6+l]<c;)a++;for(;a<=o&&t[o*6+l]>=c;)o--;if(a<o){let h=n[a];n[a]=n[o],n[o]=h;for(let u=0;u<6;u++){let d=t[a*6+u];t[a*6+u]=t[o*6+u],t[o*6+u]=d}a++,o--}else return a}}function we(n,e){return e[n+15]===65535}function Pe(n,e){return e[n+6]}function Ee(n,e){return e[n+14]}function ke(n){return n+8}function Re(n,e){return e[n+6]}function Ma(n,e){return e[n+7]}let Ta,Mr,Di,Ca;const zh=Math.pow(2,32);function Kn(n){return"count"in n?1:1+Kn(n.left)+Kn(n.right)}function Bh(n,e,t){return Ta=new Float32Array(t),Mr=new Uint32Array(t),Di=new Uint16Array(t),Ca=new Uint8Array(t),Qn(n,e)}function Qn(n,e){const t=n/4,r=n/2,i="count"in e,s=e.boundingData;for(let a=0;a<6;a++)Ta[t+a]=s[a];if(i)if(e.buffer){const a=e.buffer;Ca.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=Sr){const l=o/2;we(l,Di)||(Mr[o/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,o=e.count;return Mr[t+6]=a,Di[r+14]=o,Di[r+15]=Ii,n+Sr}else{const a=e.left,o=e.right,c=e.splitAxis;let l;if(l=Qn(n+Sr,a),l/4>zh)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return Mr[t+6]=l/4,l=Qn(l,o),Mr[t+7]=c,l}}function Ih(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,r=t>2**16,i=r?4:2,s=e?new SharedArrayBuffer(t*i):new ArrayBuffer(t*i),a=r?new Uint32Array(s):new Uint16Array(s);for(let o=0,c=a.length;o<c;o++)a[o]=o;return a}function Nh(n,e,t,r,i){const{maxDepth:s,verbose:a,maxLeafTris:o,strategy:c,onProgress:l,indirect:h}=i,u=n._indirectBuffer,d=n.geometry,p=d.index?d.index.array:null,y=h?Oh:Ah,g=qt(d),f=new Float32Array(6);let m=!1;const b=new Zn;return Yn(e,t,r,b.boundingData,f),x(b,t,r,f),b;function v(_){l&&l(_/g)}function x(_,S,w,C=null,M=0){if(!m&&M>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(d))),w<=o||M>=s)return v(S+w),_.offset=S,_.count=w,_;const T=kh(_.boundingData,C,e,S,w,c);if(T.axis===-1)return v(S+w),_.offset=S,_.count=w,_;const E=y(u,p,e,S,w,T);if(E===S||E===S+w)v(S+w),_.offset=S,_.count=w;else{_.splitAxis=T.axis;const P=new Zn,k=S,A=E-S;_.left=P,Yn(e,k,A,P.boundingData,f),x(P,k,A,f,M+1);const N=new Zn,U=E,G=w-A;_.right=N,Yn(e,U,G,N.boundingData,f),x(N,U,G,f,M+1)}return _}}function Uh(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Ih(t,e.useSharedArrayBuffer),Ch(t,e.range)&&!e.verbose&&console.warn('MeshBVH: Provided geometry contains groups or a range that do not fully span the vertex contents while using the "indirect" option. BVH may incorrectly report intersections on unrendered portions of the geometry.')),n._indirectBuffer||Th(t,e);const r=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=Ph(t),s=e.indirect?ba(t,e.range):_a(t,e.range);n._roots=s.map(a=>{const o=Nh(n,i,a.offset,a.count,e),c=Kn(o),l=new r(Sr*c);return Bh(0,o,l),l})}class yt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let r=1/0,i=-1/0;for(let s=0,a=e.length;s<a;s++){const o=e[s][t];r=o<r?o:r,i=o>i?o:i}this.min=r,this.max=i}setFromPoints(e,t){let r=1/0,i=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);r=c<r?c:r,i=c>i?c:i}this.min=r,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}yt.prototype.setFromBox=function(){const n=new I;return function(e,t){const r=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++){n.x=r.x*o+i.x*(1-o),n.y=r.y*c+i.y*(1-c),n.z=r.z*l+i.z*(1-l);const h=e.dot(n);s=Math.min(h,s),a=Math.max(h,a)}this.min=s,this.max=a}}();const Dh=function(){const n=new I,e=new I,t=new I;return function(r,i,s){const a=r.start,o=n,c=i.start,l=e;t.subVectors(a,c),n.subVectors(r.end,r.start),e.subVectors(i.end,i.start);const h=t.dot(l),u=l.dot(o),d=l.dot(l),p=t.dot(o),y=o.dot(o)*d-u*u;let g,f;y!==0?g=(h*u-p*d)/y:g=0,f=(h+g*u)/d,s.x=g,s.y=f}}(),$n=function(){const n=new Jt,e=new I,t=new I;return function(r,i,s,a){Dh(r,i,n);let o=n.x,c=n.y;if(o>=0&&o<=1&&c>=0&&c<=1){r.at(o,s),i.at(c,a);return}else if(o>=0&&o<=1){c<0?i.at(0,a):i.at(1,a),r.closestPointToPoint(a,!0,s);return}else if(c>=0&&c<=1){o<0?r.at(0,s):r.at(1,s),i.closestPointToPoint(s,!0,a);return}else{let l;o<0?l=r.start:l=r.end;let h;c<0?h=i.start:h=i.end;const u=e,d=t;if(r.closestPointToPoint(h,!0,e),i.closestPointToPoint(l,!0,t),u.distanceToSquared(h)<=d.distanceToSquared(l)){s.copy(u),a.copy(h);return}else{s.copy(l),a.copy(d);return}}}}(),Fh=function(){const n=new I,e=new I,t=new ws,r=new ut;return function(i,s){const{radius:a,center:o}=i,{a:c,b:l,c:h}=s;if(r.start=c,r.end=l,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a||(r.start=c,r.end=h,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a)||(r.start=l,r.end=h,r.closestPointToPoint(o,!0,n).distanceTo(o)<=a))return!0;const u=s.getPlane(t);if(Math.abs(u.distanceToPoint(o))<=a){const d=u.projectPoint(o,e);if(s.containsPoint(d))return!0}return!1}}(),Lh=1e-15;function es(n){return Math.abs(n)<Lh}class Ae extends Et{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new I),this.satBounds=new Array(4).fill().map(()=>new yt),this.points=[this.a,this.b,this.c],this.sphere=new Ms,this.plane=new ws,this.needsUpdate=!0}intersectsSphere(e){return Fh(e,this)}update(){const e=this.a,t=this.b,r=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],h=a[1];l.subVectors(e,t),h.setFromPoints(l,i);const u=s[2],d=a[2];u.subVectors(t,r),d.setFromPoints(u,i);const p=s[3],y=a[3];p.subVectors(r,e),y.setFromPoints(p,i),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}Ae.prototype.closestPointToSegment=function(){const n=new I,e=new I,t=new ut;return function(r,i=null,s=null){const{start:a,end:o}=r,c=this.points;let l,h=1/0;for(let u=0;u<3;u++){const d=(u+1)%3;t.start.copy(c[u]),t.end.copy(c[d]),$n(t,r,n,e),l=n.distanceToSquared(e),l<h&&(h=l,i&&i.copy(n),s&&s.copy(e))}return this.closestPointToPoint(a,n),l=a.distanceToSquared(n),l<h&&(h=l,i&&i.copy(n),s&&s.copy(a)),this.closestPointToPoint(o,n),l=o.distanceToSquared(n),l<h&&(h=l,i&&i.copy(n),s&&s.copy(o)),Math.sqrt(h)}}(),Ae.prototype.intersectsTriangle=function(){const n=new Ae,e=new Array(3),t=new Array(3),r=new yt,i=new yt,s=new I,a=new I,o=new I,c=new I,l=new I,h=new ut,u=new ut,d=new ut,p=new I;function y(g,f,m){const b=g.points;let v=0,x=-1;for(let _=0;_<3;_++){const{start:S,end:w}=h;S.copy(b[_]),w.copy(b[(_+1)%3]),h.delta(a);const C=es(f.distanceToPoint(S));if(es(f.normal.dot(a))&&C){m.copy(h),v=2;break}const M=f.intersectLine(h,p);if(!M&&C&&p.copy(S),(M||C)&&!es(p.distanceTo(w))){if(v<=1)(v===1?m.start:m.end).copy(p),C&&(x=v);else if(v>=2){(x===1?m.start:m.end).copy(p),v=2;break}if(v++,v===2&&x===-1)break}}return v}return function(g,f=null,m=!1){this.needsUpdate&&this.update(),g.isExtendedTriangle?g.needsUpdate&&g.update():(n.copy(g),n.update(),g=n);const b=this.plane,v=g.plane;if(Math.abs(b.normal.dot(v.normal))>1-1e-10){const x=this.satBounds,_=this.satAxes;t[0]=g.a,t[1]=g.b,t[2]=g.c;for(let C=0;C<4;C++){const M=x[C],T=_[C];if(r.setFromPoints(T,t),M.isSeparated(r))return!1}const S=g.satBounds,w=g.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let C=0;C<4;C++){const M=S[C],T=w[C];if(r.setFromPoints(T,e),M.isSeparated(r))return!1}for(let C=0;C<4;C++){const M=_[C];for(let T=0;T<4;T++){const E=w[T];if(s.crossVectors(M,E),r.setFromPoints(s,e),i.setFromPoints(s,t),r.isSeparated(i))return!1}}return f&&(m||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),f.start.set(0,0,0),f.end.set(0,0,0)),!0}else{const x=y(this,v,u);if(x===1&&g.containsPoint(u.end))return f&&(f.start.copy(u.end),f.end.copy(u.end)),!0;if(x!==2)return!1;const _=y(g,b,d);if(_===1&&this.containsPoint(d.end))return f&&(f.start.copy(d.end),f.end.copy(d.end)),!0;if(_!==2)return!1;if(u.delta(o),d.delta(c),o.dot(c)<0){let P=d.start;d.start=d.end,d.end=P}const S=u.start.dot(o),w=u.end.dot(o),C=d.start.dot(o),M=d.end.dot(o),T=w<C,E=S<M;return S!==M&&C!==w&&T===E?!1:(f&&(l.subVectors(u.start,d.start),l.dot(o)>0?f.start.copy(u.start):f.start.copy(d.start),l.subVectors(u.end,d.end),l.dot(o)<0?f.end.copy(u.end):f.end.copy(d.end)),!0)}}}(),Ae.prototype.distanceToPoint=function(){const n=new I;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),Ae.prototype.distanceToTriangle=function(){const n=new I,e=new I,t=["a","b","c"],r=new ut,i=new ut;return function(s,a=null,o=null){const c=a||o?r:null;if(this.intersectsTriangle(s,c))return(a||o)&&(a&&c.getCenter(a),o&&c.getCenter(o)),0;let l=1/0;for(let h=0;h<3;h++){let u;const d=t[h],p=s[d];this.closestPointToPoint(p,n),u=p.distanceToSquared(n),u<l&&(l=u,a&&a.copy(n),o&&o.copy(p));const y=this[d];s.closestPointToPoint(y,n),u=y.distanceToSquared(n),u<l&&(l=u,a&&a.copy(y),o&&o.copy(n))}for(let h=0;h<3;h++){const u=t[h],d=t[(h+1)%3];r.set(this[u],this[d]);for(let p=0;p<3;p++){const y=t[p],g=t[(p+1)%3];i.set(s[y],s[g]),$n(r,i,n,e);const f=n.distanceToSquared(e);f<l&&(l=f,a&&a.copy(n),o&&o.copy(e))}}return Math.sqrt(l)}}();class fe{constructor(e,t,r){this.isOrientedBox=!0,this.min=new I,this.max=new I,this.matrix=new je,this.invMatrix=new je,this.points=new Array(8).fill().map(()=>new I),this.satAxes=new Array(3).fill().map(()=>new I),this.satBounds=new Array(3).fill().map(()=>new yt),this.alignedSatBounds=new Array(3).fill().map(()=>new yt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),r&&this.matrix.copy(r)}set(e,t,r){this.min.copy(e),this.max.copy(t),this.matrix.copy(r),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}fe.prototype.update=function(){return function(){const n=this.matrix,e=this.min,t=this.max,r=this.points;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let h=0;h<=1;h++){const u=1*c|2*l|4*h,d=r[u];d.x=c?t.x:e.x,d.y=l?t.y:e.y,d.z=h?t.z:e.z,d.applyMatrix4(n)}const i=this.satBounds,s=this.satAxes,a=r[0];for(let c=0;c<3;c++){const l=s[c],h=i[c],u=1<<c,d=r[u];l.subVectors(a,d),h.setFromPoints(l,r)}const o=this.alignedSatBounds;o[0].setFromPointsField(r,"x"),o[1].setFromPointsField(r,"y"),o[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}}(),fe.prototype.intersectsBox=function(){const n=new yt;return function(e){this.needsUpdate&&this.update();const t=e.min,r=e.max,i=this.satBounds,s=this.satAxes,a=this.alignedSatBounds;if(n.min=t.x,n.max=r.x,a[0].isSeparated(n)||(n.min=t.y,n.max=r.y,a[1].isSeparated(n))||(n.min=t.z,n.max=r.z,a[2].isSeparated(n)))return!1;for(let o=0;o<3;o++){const c=s[o],l=i[o];if(n.setFromBox(c,e),l.isSeparated(n))return!1}return!0}}(),fe.prototype.intersectsTriangle=function(){const n=new Ae,e=new Array(3),t=new yt,r=new yt,i=new I;return function(s){this.needsUpdate&&this.update(),s.isExtendedTriangle?s.needsUpdate&&s.update():(n.copy(s),n.update(),s=n);const a=this.satBounds,o=this.satAxes;e[0]=s.a,e[1]=s.b,e[2]=s.c;for(let u=0;u<3;u++){const d=a[u],p=o[u];if(t.setFromPoints(p,e),d.isSeparated(t))return!1}const c=s.satBounds,l=s.satAxes,h=this.points;for(let u=0;u<3;u++){const d=c[u],p=l[u];if(t.setFromPoints(p,h),d.isSeparated(t))return!1}for(let u=0;u<3;u++){const d=o[u];for(let p=0;p<4;p++){const y=l[p];if(i.crossVectors(d,y),t.setFromPoints(i,e),r.setFromPoints(i,h),t.isSeparated(r))return!1}}return!0}}(),fe.prototype.closestPointToPoint=function(){return function(n,e){return this.needsUpdate&&this.update(),e.copy(n).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),e}}(),fe.prototype.distanceToPoint=function(){const n=new I;return function(e){return this.closestPointToPoint(e,n),e.distanceTo(n)}}(),fe.prototype.distanceToBox=function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new ut),t=new Array(12).fill().map(()=>new ut),r=new I,i=new I;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,r),s.closestPointToPoint(r,i),o&&o.copy(r),c&&c.copy(i)),0;const l=a*a,h=s.min,u=s.max,d=this.points;let p=1/0;for(let g=0;g<8;g++){const f=d[g];i.copy(f).clamp(h,u);const m=f.distanceToSquared(i);if(m<p&&(p=m,o&&o.copy(f),c&&c.copy(i),m<l))return Math.sqrt(m)}let y=0;for(let g=0;g<3;g++)for(let f=0;f<=1;f++)for(let m=0;m<=1;m++){const b=(g+1)%3,v=(g+2)%3,x=f<<b|m<<v,_=1<<g|f<<b|m<<v,S=d[x],w=d[_];e[y].set(S,w);const C=n[g],M=n[b],T=n[v],E=t[y],P=E.start,k=E.end;P[C]=h[C],P[M]=f?h[M]:u[M],P[T]=m?h[T]:u[M],k[C]=u[C],k[M]=f?h[M]:u[M],k[T]=m?h[T]:u[M],y++}for(let g=0;g<=1;g++)for(let f=0;f<=1;f++)for(let m=0;m<=1;m++){i.x=g?u.x:h.x,i.y=f?u.y:h.y,i.z=m?u.z:h.z,this.closestPointToPoint(i,r);const b=i.distanceToSquared(r);if(b<p&&(p=b,o&&o.copy(r),c&&c.copy(i),b<l))return Math.sqrt(b)}for(let g=0;g<12;g++){const f=e[g];for(let m=0;m<12;m++){const b=t[m];$n(f,b,r,i);const v=r.distanceToSquared(i);if(v<p&&(p=v,o&&o.copy(r),c&&c.copy(i),v<l))return Math.sqrt(v)}}return Math.sqrt(p)}}();class ts{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 Vh extends ts{constructor(){super(()=>new Ae)}}const Oe=new Vh;class jh{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=r=>{t&&e.push(t),t=r,this.float32Array=new Float32Array(r),this.uint16Array=new Uint16Array(r),this.uint32Array=new Uint32Array(r)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const H=new jh;let St,Yt;const Zt=[],Fi=new ts(()=>new Ze);function Jh(n,e,t,r,i,s){St=Fi.getPrimitive(),Yt=Fi.getPrimitive(),Zt.push(St,Yt),H.setBuffer(n._roots[e]);const a=rs(0,n.geometry,t,r,i,s);H.clearBuffer(),Fi.releasePrimitive(St),Fi.releasePrimitive(Yt),Zt.pop(),Zt.pop();const o=Zt.length;return o>0&&(Yt=Zt[o-1],St=Zt[o-2]),a}function rs(n,e,t,r,i=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=H;let h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);return Z(n,o,St),r(u,d,!1,a,s+n,St)}else{let u=function(E){const{uint16Array:P,uint32Array:k}=H;let A=E*2;for(;!we(A,P);)E=ke(E),A=E*2;return Pe(E,k)},d=function(E){const{uint16Array:P,uint32Array:k}=H;let A=E*2;for(;!we(A,P);)E=Re(E,k),A=E*2;return Pe(E,k)+Ee(A,P)};const p=ke(n),y=Re(n,l);let g=p,f=y,m,b,v,x;if(i&&(v=St,x=Yt,Z(g,o,v),Z(f,o,x),m=i(v),b=i(x),b<m)){g=y,f=p;const E=m;m=b,b=E,v=x}v||(v=St,Z(g,o,v));const _=we(g*2,c),S=t(v,_,m,a+1,s+g);let w;if(S===Hn){const E=u(g),P=d(g)-E;w=r(E,P,!0,a+1,s+g,v)}else w=S&&rs(g,e,t,r,i,s,a+1);if(w)return!0;x=Yt,Z(f,o,x);const C=we(f*2,c),M=t(x,C,b,a+1,s+f);let T;if(M===Hn){const E=u(f),P=d(f)-E;T=r(E,P,!0,a+1,s+f,x)}else T=M&&rs(f,e,t,r,i,s,a+1);return!!T}}const Tr=new I,is=new I;function Gh(n,e,t={},r=0,i=1/0){const s=r*r,a=i*i;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:h=>(Tr.copy(e).clamp(h.min,h.max),Tr.distanceToSquared(e)),intersectsBounds:(h,u,d)=>d<o&&d<a,intersectsTriangle:(h,u)=>{h.closestPointToPoint(e,Tr);const d=e.distanceToSquared(Tr);return d<o&&(is.copy(Tr),o=d,c=u),d<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(is):t.point=is.clone(),t.distance=l,t.faceIndex=c,t}const Wh=parseInt(Ya)>=169,At=new I,Ot=new I,zt=new I,Li=new Jt,Vi=new Jt,ji=new Jt,Pa=new I,Ea=new I,ka=new I,Cr=new I;function Hh(n,e,t,r,i,s,a,o){let c;if(s===qa?c=n.intersectTriangle(r,t,e,!0,i):c=n.intersectTriangle(e,t,r,s!==an,i),c===null)return null;const l=n.origin.distanceTo(i);return l<a||l>o?null:{distance:l,point:i.clone()}}function Xh(n,e,t,r,i,s,a,o,c,l,h){At.fromBufferAttribute(e,s),Ot.fromBufferAttribute(e,a),zt.fromBufferAttribute(e,o);const u=Hh(n,At,Ot,zt,Cr,c,l,h);if(u){const d=new I;Et.getBarycoord(Cr,At,Ot,zt,d),r&&(Li.fromBufferAttribute(r,s),Vi.fromBufferAttribute(r,a),ji.fromBufferAttribute(r,o),u.uv=Et.getInterpolation(Cr,At,Ot,zt,Li,Vi,ji,new Jt)),i&&(Li.fromBufferAttribute(i,s),Vi.fromBufferAttribute(i,a),ji.fromBufferAttribute(i,o),u.uv1=Et.getInterpolation(Cr,At,Ot,zt,Li,Vi,ji,new Jt)),t&&(Pa.fromBufferAttribute(t,s),Ea.fromBufferAttribute(t,a),ka.fromBufferAttribute(t,o),u.normal=Et.getInterpolation(Cr,At,Ot,zt,Pa,Ea,ka,new I),u.normal.dot(n.direction)>0&&u.normal.multiplyScalar(-1));const p={a:s,b:a,c:o,normal:new I,materialIndex:0};Et.getNormal(At,Ot,zt,p.normal),u.face=p,u.faceIndex=s,Wh&&(u.barycoord=d)}return u}function Ji(n,e,t,r,i,s,a){const o=r*3;let c=o+0,l=o+1,h=o+2;const u=n.index;n.index&&(c=u.getX(c),l=u.getX(l),h=u.getX(h));const{position:d,normal:p,uv:y,uv1:g}=n.attributes,f=Xh(t,d,p,y,g,c,l,h,e,s,a);return f?(f.faceIndex=r,i&&i.push(f),f):null}function te(n,e,t,r){const i=n.a,s=n.b,a=n.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=r.getX(o),i.y=r.getY(o),i.z=r.getZ(o),s.x=r.getX(c),s.y=r.getY(c),s.z=r.getZ(c),a.x=r.getX(l),a.y=r.getY(l),a.z=r.getZ(l)}function qh(n,e,t,r,i,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let h=r,u=r+i;h<u;h++)Ji(c,e,t,h,s,a,o)}function Yh(n,e,t,r,i,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,h=null;for(let u=r,d=r+i;u<d;u++){let p;p=Ji(o,e,t,u,null,s,a),p&&p.distance<l&&(h=p,l=p.distance)}return h}function Zh(n,e,t,r,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let h=n,u=e+n;h<u;h++){let d;if(d=h,te(a,d*3,c,l),a.needsUpdate=!0,r(a,d,i,s))return!0}return!1}function Kh(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,r=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const h=n._roots;for(let d=0,p=h.length;d<p;d++)s=h[d],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),u(0,l),l+=s.byteLength;function u(d,p,y=!1){const g=d*2;if(o[g+15]===Ii){const f=a[d+6],m=o[g+14];let b=1/0,v=1/0,x=1/0,_=-1/0,S=-1/0,w=-1/0;for(let C=3*f,M=3*(f+m);C<M;C++){let T=r[C];const E=i.getX(T),P=i.getY(T),k=i.getZ(T);E<b&&(b=E),E>_&&(_=E),P<v&&(v=P),P>S&&(S=P),k<x&&(x=k),k>w&&(w=k)}return c[d+0]!==b||c[d+1]!==v||c[d+2]!==x||c[d+3]!==_||c[d+4]!==S||c[d+5]!==w?(c[d+0]=b,c[d+1]=v,c[d+2]=x,c[d+3]=_,c[d+4]=S,c[d+5]=w,!0):!1}else{const f=d+8,m=a[d+6],b=f+p,v=m+p;let x=y,_=!1,S=!1;e?x||(_=e.has(b),S=e.has(v),x=!_&&!S):(_=!0,S=!0);const w=x||_,C=x||S;let M=!1;w&&(M=u(f,p,x));let T=!1;C&&(T=u(m,p,x));const E=M||T;if(E)for(let P=0;P<3;P++){const k=f+P,A=m+P,N=c[k],U=c[k+3],G=c[A],B=c[A+3];c[d+P]=N<G?N:G,c[d+P+3]=U>B?U:B}return E}}}function wt(n,e,t,r,i){let s,a,o,c,l,h;const u=1/t.direction.x,d=1/t.direction.y,p=1/t.direction.z,y=t.origin.x,g=t.origin.y,f=t.origin.z;let m=e[n],b=e[n+3],v=e[n+1],x=e[n+3+1],_=e[n+2],S=e[n+3+2];return u>=0?(s=(m-y)*u,a=(b-y)*u):(s=(b-y)*u,a=(m-y)*u),d>=0?(o=(v-g)*d,c=(x-g)*d):(o=(x-g)*d,c=(v-g)*d),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),p>=0?(l=(_-f)*p,h=(S-f)*p):(l=(S-f)*p,h=(_-f)*p),s>h||l>a)?!1:((l>s||s!==s)&&(s=l),(h<a||a!==a)&&(a=h),s<=i&&a>=r)}function Qh(n,e,t,r,i,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let h=r,u=r+i;h<u;h++){let d=l?l[h]:h;Ji(c,e,t,d,s,a,o)}}function $h(n,e,t,r,i,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,h=null;for(let u=r,d=r+i;u<d;u++){let p;p=Ji(o,e,t,c?c[u]:u,null,s,a),p&&p.distance<l&&(h=p,l=p.distance)}return h}function eu(n,e,t,r,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let h=n,u=e+n;h<u;h++){let d;if(d=t.resolveTriangleIndex(h),te(a,d*3,c,l),a.needsUpdate=!0,r(a,d,i,s))return!0}return!1}function tu(n,e,t,r,i,s,a){H.setBuffer(n._roots[e]),ns(0,n,t,r,i,s,a),H.clearBuffer()}function ns(n,e,t,r,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=H,h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);qh(e,t,r,u,d,i,s,a)}else{const u=ke(n);wt(u,o,r,s,a)&&ns(u,e,t,r,i,s,a);const d=Re(n,l);wt(d,o,r,s,a)&&ns(d,e,t,r,i,s,a)}}const ru=["x","y","z"];function iu(n,e,t,r,i,s){H.setBuffer(n._roots[e]);const a=ss(0,n,t,r,i,s);return H.clearBuffer(),a}function ss(n,e,t,r,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=H;let l=n*2;if(we(l,o)){const h=Pe(n,c),u=Ee(l,o);return Yh(e,t,r,h,u,i,s)}else{const h=Ma(n,c),u=ru[h],d=r.direction[u]>=0;let p,y;d?(p=ke(n),y=Re(n,c)):(p=Re(n,c),y=ke(n));const g=wt(p,a,r,i,s)?ss(p,e,t,r,i,s):null;if(g){const m=g.point[u];if(d?m<=a[y+h]:m>=a[y+h+3])return g}const f=wt(y,a,r,i,s)?ss(y,e,t,r,i,s):null;return g&&f?g.distance<=f.distance?g:f:g||f||null}}const Gi=new Ze,Kt=new Ae,Qt=new Ae,Pr=new je,Ra=new fe,Wi=new fe;function nu(n,e,t,r){H.setBuffer(n._roots[e]);const i=os(0,n,t,r);return H.clearBuffer(),i}function os(n,e,t,r,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=H;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Ra.set(t.boundingBox.min,t.boundingBox.max,r),i=Ra),we(c,a)){const l=e.geometry,h=l.index,u=l.attributes.position,d=t.index,p=t.attributes.position,y=Pe(n,o),g=Ee(c,a);if(Pr.copy(r).invert(),t.boundsTree)return Z(n,s,Wi),Wi.matrix.copy(Pr),Wi.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:f=>Wi.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(r),f.b.applyMatrix4(r),f.c.applyMatrix4(r),f.needsUpdate=!0;for(let m=y*3,b=(g+y)*3;m<b;m+=3)if(te(Qt,m,h,u),Qt.needsUpdate=!0,f.intersectsTriangle(Qt))return!0;return!1}});for(let f=y*3,m=(g+y)*3;f<m;f+=3){te(Kt,f,h,u),Kt.a.applyMatrix4(Pr),Kt.b.applyMatrix4(Pr),Kt.c.applyMatrix4(Pr),Kt.needsUpdate=!0;for(let b=0,v=d.count;b<v;b+=3)if(te(Qt,b,d,p),Qt.needsUpdate=!0,Kt.intersectsTriangle(Qt))return!0}}else{const l=n+8,h=o[n+6];return Z(l,s,Gi),!!(i.intersectsBox(Gi)&&os(l,e,t,r,i)||(Z(h,s,Gi),i.intersectsBox(Gi)&&os(h,e,t,r,i)))}}const Hi=new je,as=new fe,Er=new fe,su=new I,ou=new I,au=new I,cu=new I;function lu(n,e,t,r={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),as.set(e.boundingBox.min,e.boundingBox.max,t),as.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,h=e.attributes.position,u=e.index,d=Oe.getPrimitive(),p=Oe.getPrimitive();let y=su,g=ou,f=null,m=null;i&&(f=au,m=cu);let b=1/0,v=null,x=null;return Hi.copy(t).invert(),Er.matrix.copy(Hi),n.shapecast({boundsTraverseOrder:_=>as.distanceToBox(_),intersectsBounds:(_,S,w)=>w<b&&w<a?(S&&(Er.min.copy(_.min),Er.max.copy(_.max),Er.needsUpdate=!0),!0):!1,intersectsRange:(_,S)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:w=>Er.distanceToBox(w),intersectsBounds:(w,C,M)=>M<b&&M<a,intersectsRange:(w,C)=>{for(let M=w,T=w+C;M<T;M++){te(p,3*M,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let E=_,P=_+S;E<P;E++){te(d,3*E,l,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,y,f);if(k<b&&(g.copy(y),m&&m.copy(f),b=k,v=E,x=M),k<s)return!0}}}});{const w=qt(e);for(let C=0,M=w;C<M;C++){te(p,3*C,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let T=_,E=_+S;T<E;T++){te(d,3*T,l,c),d.needsUpdate=!0;const P=d.distanceToTriangle(p,y,f);if(P<b&&(g.copy(y),m&&m.copy(f),b=P,v=T,x=C),P<s)return!0}}}}}),Oe.releasePrimitive(d),Oe.releasePrimitive(p),b===1/0?null:(r.point?r.point.copy(g):r.point=g.clone(),r.distance=b,r.faceIndex=v,i&&(i.point?i.point.copy(m):i.point=m.clone(),i.point.applyMatrix4(Hi),g.applyMatrix4(Hi),i.distance=g.sub(i.point).length(),i.faceIndex=x),r)}function hu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,r=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const h=n._roots;for(let d=0,p=h.length;d<p;d++)s=h[d],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),u(0,l),l+=s.byteLength;function u(d,p,y=!1){const g=d*2;if(o[g+15]===Ii){const f=a[d+6],m=o[g+14];let b=1/0,v=1/0,x=1/0,_=-1/0,S=-1/0,w=-1/0;for(let C=f,M=f+m;C<M;C++){const T=3*n.resolveTriangleIndex(C);for(let E=0;E<3;E++){let P=T+E;P=r?r[P]:P;const k=i.getX(P),A=i.getY(P),N=i.getZ(P);k<b&&(b=k),k>_&&(_=k),A<v&&(v=A),A>S&&(S=A),N<x&&(x=N),N>w&&(w=N)}}return c[d+0]!==b||c[d+1]!==v||c[d+2]!==x||c[d+3]!==_||c[d+4]!==S||c[d+5]!==w?(c[d+0]=b,c[d+1]=v,c[d+2]=x,c[d+3]=_,c[d+4]=S,c[d+5]=w,!0):!1}else{const f=d+8,m=a[d+6],b=f+p,v=m+p;let x=y,_=!1,S=!1;e?x||(_=e.has(b),S=e.has(v),x=!_&&!S):(_=!0,S=!0);const w=x||_,C=x||S;let M=!1;w&&(M=u(f,p,x));let T=!1;C&&(T=u(m,p,x));const E=M||T;if(E)for(let P=0;P<3;P++){const k=f+P,A=m+P,N=c[k],U=c[k+3],G=c[A],B=c[A+3];c[d+P]=N<G?N:G,c[d+P+3]=U>B?U:B}return E}}}function uu(n,e,t,r,i,s,a){H.setBuffer(n._roots[e]),cs(0,n,t,r,i,s,a),H.clearBuffer()}function cs(n,e,t,r,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=H,h=n*2;if(we(h,c)){const u=Pe(n,l),d=Ee(h,c);Qh(e,t,r,u,d,i,s,a)}else{const u=ke(n);wt(u,o,r,s,a)&&cs(u,e,t,r,i,s,a);const d=Re(n,l);wt(d,o,r,s,a)&&cs(d,e,t,r,i,s,a)}}const du=["x","y","z"];function pu(n,e,t,r,i,s){H.setBuffer(n._roots[e]);const a=ls(0,n,t,r,i,s);return H.clearBuffer(),a}function ls(n,e,t,r,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=H;let l=n*2;if(we(l,o)){const h=Pe(n,c),u=Ee(l,o);return $h(e,t,r,h,u,i,s)}else{const h=Ma(n,c),u=du[h],d=r.direction[u]>=0;let p,y;d?(p=ke(n),y=Re(n,c)):(p=Re(n,c),y=ke(n));const g=wt(p,a,r,i,s)?ls(p,e,t,r,i,s):null;if(g){const m=g.point[u];if(d?m<=a[y+h]:m>=a[y+h+3])return g}const f=wt(y,a,r,i,s)?ls(y,e,t,r,i,s):null;return g&&f?g.distance<=f.distance?g:f:g||f||null}}const Xi=new Ze,$t=new Ae,er=new Ae,kr=new je,Aa=new fe,qi=new fe;function fu(n,e,t,r){H.setBuffer(n._roots[e]);const i=hs(0,n,t,r);return H.clearBuffer(),i}function hs(n,e,t,r,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=H;let c=n*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Aa.set(t.boundingBox.min,t.boundingBox.max,r),i=Aa),we(c,a)){const l=e.geometry,h=l.index,u=l.attributes.position,d=t.index,p=t.attributes.position,y=Pe(n,o),g=Ee(c,a);if(kr.copy(r).invert(),t.boundsTree)return Z(n,s,qi),qi.matrix.copy(kr),qi.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:f=>qi.intersectsBox(f),intersectsTriangle:f=>{f.a.applyMatrix4(r),f.b.applyMatrix4(r),f.c.applyMatrix4(r),f.needsUpdate=!0;for(let m=y,b=g+y;m<b;m++)if(te(er,3*e.resolveTriangleIndex(m),h,u),er.needsUpdate=!0,f.intersectsTriangle(er))return!0;return!1}});for(let f=y,m=g+y;f<m;f++){const b=e.resolveTriangleIndex(f);te($t,3*b,h,u),$t.a.applyMatrix4(kr),$t.b.applyMatrix4(kr),$t.c.applyMatrix4(kr),$t.needsUpdate=!0;for(let v=0,x=d.count;v<x;v+=3)if(te(er,v,d,p),er.needsUpdate=!0,$t.intersectsTriangle(er))return!0}}else{const l=n+8,h=o[n+6];return Z(l,s,Xi),!!(i.intersectsBox(Xi)&&hs(l,e,t,r,i)||(Z(h,s,Xi),i.intersectsBox(Xi)&&hs(h,e,t,r,i)))}}const Yi=new je,us=new fe,Rr=new fe,mu=new I,yu=new I,gu=new I,vu=new I;function bu(n,e,t,r={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),us.set(e.boundingBox.min,e.boundingBox.max,t),us.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,h=e.attributes.position,u=e.index,d=Oe.getPrimitive(),p=Oe.getPrimitive();let y=mu,g=yu,f=null,m=null;i&&(f=gu,m=vu);let b=1/0,v=null,x=null;return Yi.copy(t).invert(),Rr.matrix.copy(Yi),n.shapecast({boundsTraverseOrder:_=>us.distanceToBox(_),intersectsBounds:(_,S,w)=>w<b&&w<a?(S&&(Rr.min.copy(_.min),Rr.max.copy(_.max),Rr.needsUpdate=!0),!0):!1,intersectsRange:(_,S)=>{if(e.boundsTree){const w=e.boundsTree;return w.shapecast({boundsTraverseOrder:C=>Rr.distanceToBox(C),intersectsBounds:(C,M,T)=>T<b&&T<a,intersectsRange:(C,M)=>{for(let T=C,E=C+M;T<E;T++){const P=w.resolveTriangleIndex(T);te(p,3*P,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let k=_,A=_+S;k<A;k++){const N=n.resolveTriangleIndex(k);te(d,3*N,l,c),d.needsUpdate=!0;const U=d.distanceToTriangle(p,y,f);if(U<b&&(g.copy(y),m&&m.copy(f),b=U,v=k,x=T),U<s)return!0}}}})}else{const w=qt(e);for(let C=0,M=w;C<M;C++){te(p,3*C,u,h),p.a.applyMatrix4(t),p.b.applyMatrix4(t),p.c.applyMatrix4(t),p.needsUpdate=!0;for(let T=_,E=_+S;T<E;T++){const P=n.resolveTriangleIndex(T);te(d,3*P,l,c),d.needsUpdate=!0;const k=d.distanceToTriangle(p,y,f);if(k<b&&(g.copy(y),m&&m.copy(f),b=k,v=T,x=C),k<s)return!0}}}}}),Oe.releasePrimitive(d),Oe.releasePrimitive(p),b===1/0?null:(r.point?r.point.copy(g):r.point=g.clone(),r.distance=b,r.faceIndex=v,i&&(i.point?i.point.copy(m):i.point=m.clone(),i.point.applyMatrix4(Yi),g.applyMatrix4(Yi),i.distance=g.sub(i.point).length(),i.faceIndex=x),r)}function _u(){return typeof SharedArrayBuffer<"u"}const Ar=new H.constructor,Zi=new H.constructor,Mt=new ts(()=>new Ze),tr=new Ze,rr=new Ze,ds=new Ze,ps=new Ze;let fs=!1;function xu(n,e,t,r){if(fs)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");fs=!0;const i=n._roots,s=e._roots;let a,o=0,c=0;const l=new je().copy(t).invert();for(let h=0,u=i.length;h<u;h++){Ar.setBuffer(i[h]),c=0;const d=Mt.getPrimitive();Z(0,Ar.float32Array,d),d.applyMatrix4(l);for(let p=0,y=s.length;p<y&&(Zi.setBuffer(s[p]),a=We(0,0,t,l,r,o,c,0,0,d),Zi.clearBuffer(),c+=s[p].length,!a);p++);if(Mt.releasePrimitive(d),Ar.clearBuffer(),o+=i[h].length,a)break}return fs=!1,a}function We(n,e,t,r,i,s=0,a=0,o=0,c=0,l=null,h=!1){let u,d;h?(u=Zi,d=Ar):(u=Ar,d=Zi);const p=u.float32Array,y=u.uint32Array,g=u.uint16Array,f=d.float32Array,m=d.uint32Array,b=d.uint16Array,v=n*2,x=e*2,_=we(v,g),S=we(x,b);let w=!1;if(S&&_)h?w=i(Pe(e,m),Ee(e*2,b),Pe(n,y),Ee(n*2,g),c,a+e,o,s+n):w=i(Pe(n,y),Ee(n*2,g),Pe(e,m),Ee(e*2,b),o,s+n,c,a+e);else if(S){const C=Mt.getPrimitive();Z(e,f,C),C.applyMatrix4(t);const M=ke(n),T=Re(n,y);Z(M,p,tr),Z(T,p,rr);const E=C.intersectsBox(tr),P=C.intersectsBox(rr);w=E&&We(e,M,r,t,i,a,s,c,o+1,C,!h)||P&&We(e,T,r,t,i,a,s,c,o+1,C,!h),Mt.releasePrimitive(C)}else{const C=ke(e),M=Re(e,m);Z(C,f,ds),Z(M,f,ps);const T=l.intersectsBox(ds),E=l.intersectsBox(ps);if(T&&E)w=We(n,C,t,r,i,s,a,o,c+1,l,h)||We(n,M,t,r,i,s,a,o,c+1,l,h);else if(T)if(_)w=We(n,C,t,r,i,s,a,o,c+1,l,h);else{const P=Mt.getPrimitive();P.copy(ds).applyMatrix4(t);const k=ke(n),A=Re(n,y);Z(k,p,tr),Z(A,p,rr);const N=P.intersectsBox(tr),U=P.intersectsBox(rr);w=N&&We(C,k,r,t,i,a,s,c,o+1,P,!h)||U&&We(C,A,r,t,i,a,s,c,o+1,P,!h),Mt.releasePrimitive(P)}else if(E)if(_)w=We(n,M,t,r,i,s,a,o,c+1,l,h);else{const P=Mt.getPrimitive();P.copy(ps).applyMatrix4(t);const k=ke(n),A=Re(n,y);Z(k,p,tr),Z(A,p,rr);const N=P.intersectsBox(tr),U=P.intersectsBox(rr);w=N&&We(M,k,r,t,i,a,s,c,o+1,P,!h)||U&&We(M,A,r,t,i,a,s,c,o+1,P,!h),Mt.releasePrimitive(P)}}return w}const Ki=new fe,Oa=new Ze,Su={strategy:Wn,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class Ir{static serialize(e,t={}){t={cloneBuffers:!0,...t};const r=e.geometry,i=e._roots,s=e._indirectBuffer,a=r.getIndex();let o;return t.cloneBuffers?o={roots:i.map(c=>c.slice()),index:a?a.array.slice():null,indirectBuffer:s?s.slice():null}:o={roots:i,index:a?a.array:null,indirectBuffer:s},o}static deserialize(e,t,r={}){r={setIndex:!0,indirect:!!e.indirectBuffer,...r};const{index:i,roots:s,indirectBuffer:a}=e,o=new Ir(t,{...r,[qn]:!0});if(o._roots=s,o._indirectBuffer=a||null,r.setIndex){const c=t.getIndex();if(c===null){const l=new Te(e.index,1,!1);t.setIndex(l)}else c.array!==i&&(c.array.set(i),c.needsUpdate=!0)}return o}get indirect(){return!!this._indirectBuffer}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("MeshBVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("MeshBVH: Only BufferGeometries are supported.");if(t=Object.assign({...Su,[qn]:!1},t),t.useSharedArrayBuffer&&!_u())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[qn]||(Uh(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new Ze))),this.resolveTriangleIndex=t.indirect?r=>this._indirectBuffer[r]:r=>r}refit(e=null){return(this.indirect?hu:Kh)(this,e)}traverse(e,t=0){const r=this._roots[t],i=new Uint32Array(r),s=new Uint16Array(r);a(0);function a(o,c=0){const l=o*2,h=s[l+15]===Ii;if(h){const u=i[o+6],d=s[l+14];e(c,h,new Float32Array(r,o*4,6),u,d)}else{const u=o+Sr/4,d=i[o+6],p=i[o+7];e(c,h,new Float32Array(r,o*4,6),p)||(a(u,c+1),a(d,c+1))}}}raycast(e,t=Ts,r=0,i=1/0){const s=this._roots,a=this.geometry,o=[],c=t.isMaterial,l=Array.isArray(t),h=a.groups,u=c?t.side:t,d=this.indirect?uu:tu;for(let p=0,y=s.length;p<y;p++){const g=l?t[h[p].materialIndex].side:u,f=o.length;if(d(this,p,g,e,o,r,i),l){const m=h[p].materialIndex;for(let b=f,v=o.length;b<v;b++)o[b].face.materialIndex=m}}return o}raycastFirst(e,t=Ts,r=0,i=1/0){const s=this._roots,a=this.geometry,o=t.isMaterial,c=Array.isArray(t);let l=null;const h=a.groups,u=o?t.side:t,d=this.indirect?pu:iu;for(let p=0,y=s.length;p<y;p++){const g=c?t[h[p].materialIndex].side:u,f=d(this,p,g,e,r,i);f!=null&&(l==null||f.distance<l.distance)&&(l=f,c&&(f.face.materialIndex=h[p].materialIndex))}return l}intersectsGeometry(e,t){let r=!1;const i=this._roots,s=this.indirect?fu:nu;for(let a=0,o=i.length;a<o&&(r=s(this,a,e,t),!r);a++);return r}shapecast(e){const t=Oe.getPrimitive(),r=this.indirect?eu:Zh;let{boundsTraverseOrder:i,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=e;if(a&&o){const u=a;a=(d,p,y,g,f)=>u(d,p,y,g,f)?!0:r(d,p,this,o,y,g,t)}else a||(o?a=(u,d,p,y)=>r(u,d,this,o,p,y,t):a=(u,d,p)=>p);let c=!1,l=0;const h=this._roots;for(let u=0,d=h.length;u<d;u++){const p=h[u];if(c=Jh(this,u,s,a,i,l),c)break;l+=p.byteLength}return Oe.releasePrimitive(t),c}bvhcast(e,t,r){let{intersectsRanges:i,intersectsTriangles:s}=r;const a=Oe.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const g=this.resolveTriangleIndex(y);te(a,g*3,o,c)}:y=>{te(a,y*3,o,c)},h=Oe.getPrimitive(),u=e.geometry.index,d=e.geometry.attributes.position,p=e.indirect?y=>{const g=e.resolveTriangleIndex(y);te(h,g*3,u,d)}:y=>{te(h,y*3,u,d)};if(s){const y=(g,f,m,b,v,x,_,S)=>{for(let w=m,C=m+b;w<C;w++){p(w),h.a.applyMatrix4(t),h.b.applyMatrix4(t),h.c.applyMatrix4(t),h.needsUpdate=!0;for(let M=g,T=g+f;M<T;M++)if(l(M),a.needsUpdate=!0,s(a,h,M,w,v,x,_,S))return!0}return!1};if(i){const g=i;i=function(f,m,b,v,x,_,S,w){return g(f,m,b,v,x,_,S,w)?!0:y(f,m,b,v,x,_,S,w)}}else i=y}return xu(this,e,t,i)}intersectsBox(e,t){return Ki.set(e.min,e.max,t),Ki.needsUpdate=!0,this.shapecast({intersectsBounds:r=>Ki.intersectsBox(r),intersectsTriangle:r=>Ki.intersectsTriangle(r)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,r={},i={},s=0,a=1/0){return(this.indirect?bu:lu)(this,e,t,r,i,s,a)}closestPointToPoint(e,t={},r=0,i=1/0){return Gh(this,e,t,r,i)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(t=>{Z(0,new Float32Array(t),Oa),e.union(Oa)}),e}}function za(n,e,t){return n===null?null:(n.point.applyMatrix4(e.matrixWorld),n.distance=n.point.distanceTo(t.ray.origin),n.object=e,n)}const Qi=new Ka,Ba=new I,Ia=new je,wu=ln.prototype.raycast,Mu=Za.prototype.raycast,Na=new I,ue=new ln,$i=[];function Tu(n,e){this.isBatchedMesh?Cu.call(this,n,e):Pu.call(this,n,e)}function Cu(n,e){if(this.boundsTrees){const t=this.boundsTrees,r=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ue.material=this.material,ue.geometry=this.geometry;const a=ue.geometry.boundsTree,o=ue.geometry.drawRange;ue.geometry.boundingSphere===null&&(ue.geometry.boundingSphere=new Ms);for(let c=0,l=r.length;c<l;c++){if(!this.getVisibleAt(c))continue;const h=r[c].geometryIndex;if(ue.geometry.boundsTree=t[h],this.getMatrixAt(c,ue.matrixWorld).premultiply(s),!ue.geometry.boundsTree){this.getBoundingBoxAt(h,ue.geometry.boundingBox),this.getBoundingSphereAt(h,ue.geometry.boundingSphere);const u=i[h];ue.geometry.setDrawRange(u.start,u.count)}ue.raycast(n,$i);for(let u=0,d=$i.length;u<d;u++){const p=$i[u];p.object=this,p.batchId=c,e.push(p)}$i.length=0}ue.geometry.boundsTree=a,ue.geometry.drawRange=o,ue.material=null,ue.geometry=null}else Mu.call(this,n,e)}function Pu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;Ia.copy(this.matrixWorld).invert(),Qi.copy(n.ray).applyMatrix4(Ia),Na.setFromMatrixScale(this.matrixWorld),Ba.copy(Qi.direction).multiply(Na);const t=Ba.length(),r=n.near/t,i=n.far/t,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=za(s.raycastFirst(Qi,this.material,r,i),this,n);a&&e.push(a)}else{const a=s.raycast(Qi,this.material,r,i);for(let o=0,c=a.length;o<c;o++){const l=za(a[o],this,n);l&&e.push(l)}}}else wu.call(this,n,e)}function Eu(n={}){return this.boundsTree=new Ir(this,n),this.boundsTree}const Bt=new I,It=new I,Nt=new I,Ua=new hn,en=new I,ms=new I,Da=new hn,Fa=new hn,tn=new je,La=new je;function Or(n,e){if(!n&&!e)return;const t=n.count===e.count,r=n.normalized===e.normalized,i=n.array.constructor===e.array.constructor,s=n.itemSize===e.itemSize;if(!t||!r||!i||!s)throw new Error}function zr(n,e=null){const t=n.array.constructor,r=n.normalized,i=n.itemSize,s=e===null?n.count:e;return new Te(new t(i*s),i,r)}function Va(n,e,t=0){if(n.isInterleavedBufferAttribute){const r=n.itemSize;for(let i=0,s=n.count;i<s;i++){const a=i+t;e.setX(a,n.getX(i)),r>=2&&e.setY(a,n.getY(i)),r>=3&&e.setZ(a,n.getZ(i)),r>=4&&e.setW(a,n.getW(i))}}else{const r=e.array,i=r.constructor,s=r.BYTES_PER_ELEMENT*n.itemSize*t;new i(r.buffer,s,n.array.length).set(n.array)}}function ku(n,e,t){const r=n.elements,i=e.elements;for(let s=0,a=i.length;s<a;s++)r[s]+=i[s]*t}function ja(n,e,t){const r=n.skeleton,i=n.geometry,s=r.bones,a=r.boneInverses;Da.fromBufferAttribute(i.attributes.skinIndex,e),Fa.fromBufferAttribute(i.attributes.skinWeight,e),tn.elements.fill(0);for(let o=0;o<4;o++){const c=Fa.getComponent(o);if(c!==0){const l=Da.getComponent(o);La.multiplyMatrices(s[l].matrixWorld,a[l]),ku(tn,La,c)}}return tn.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection(tn),t}function ys(n,e,t,r,i){en.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=e[s],c=n[s];o!==0&&(ms.fromBufferAttribute(c,r),t?en.addScaledVector(ms,o):en.addScaledVector(ms.sub(i),o))}i.add(en)}function Ru(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new lr){const r=n[0].index!==null,{useGroups:i=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;t.clearGroups();for(let h=0;h<n.length;++h){const u=n[h];let d=0;if(r!==(u.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 p in u.attributes){if(!o.has(p))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.');c[p]===void 0&&(c[p]=[]),c[p].push(u.attributes[p]),d++}if(d!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(i){let p;if(r)p=u.index.count;else if(u.attributes.position!==void 0)p=u.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,p,h),l+=p}}if(r){let h=!1;if(!t.index){let u=0;for(let d=0;d<n.length;++d)u+=n[d].index.count;t.setIndex(new Te(new Uint32Array(u),1,!1)),h=!0}if(s||h){const u=t.index;let d=0,p=0;for(let y=0;y<n.length;++y){const g=n[y],f=g.index;if(a[y]!==!0)for(let m=0;m<f.count;++m)u.setX(d,f.getX(m)+p),d++;p+=g.attributes.position.count}}}for(const h in c){const u=c[h];if(!(h in t.attributes)){let y=0;for(const g in u)y+=u[g].count;t.setAttribute(h,zr(c[h][0],y))}const d=t.attributes[h];let p=0;for(let y=0,g=u.length;y<g;y++){const f=u[y];a[y]!==!0&&Va(f,d,p),p+=f.count}}return t}function Au(n,e){if(n===null||e===null)return n===e;if(n.length!==e.length)return!1;for(let t=0,r=n.length;t<r;t++)if(n[t]!==e[t])return!1;return!0}function Ou(n){const{index:e,attributes:t}=n;if(e)for(let r=0,i=e.count;r<i;r+=3){const s=e.getX(r),a=e.getX(r+2);e.setX(r,a),e.setX(r+2,s)}else for(const r in t){const i=t[r],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),h=i.getComponent(a+2,c);i.setComponent(a,c,h),i.setComponent(a+2,c,l)}}return n}class zu{constructor(e){this.matrixWorld=new je,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,r=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,r){r.boneTexture||r.computeBoneTexture(),r.update();const s=r.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,r=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&Au(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===r)}}class Bu{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(r=>{r.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 lr),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 lr){let t=[];const{meshes:r,useGroups:i,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=r.length;o<c;o++){const l=r[o],h=s[o],u=a.get(l);!u||u.didChange(l)?(this._convertToStaticGeometry(l,h),t.push(!1),u?u.update():a.set(l,new zu(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 Te(new Float32Array(0),4,!1))}else Ru(s,{useGroups:i,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new lr){const r=e.geometry,i=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=r.attributes,c=t.attributes;!t.index&&r.index&&(t.index=r.index.clone()),c.position||t.setAttribute("position",zr(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",zr(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",zr(o.tangent)),Or(r.index,t.index),Or(o.position,c.position),s&&Or(o.normal,c.normal),a&&Or(o.tangent,c.tangent);const l=o.position,h=s?o.normal:null,u=a?o.tangent:null,d=r.morphAttributes.position,p=r.morphAttributes.normal,y=r.morphAttributes.tangent,g=r.morphTargetsRelative,f=e.morphTargetInfluences,m=new Qa;m.getNormalMatrix(e.matrixWorld),r.index&&t.index.array.set(r.index.array);for(let b=0,v=o.position.count;b<v;b++)Bt.fromBufferAttribute(l,b),h&&It.fromBufferAttribute(h,b),u&&(Ua.fromBufferAttribute(u,b),Nt.fromBufferAttribute(u,b)),f&&(d&&ys(d,f,g,b,Bt),p&&ys(p,f,g,b,It),y&&ys(y,f,g,b,Nt)),e.isSkinnedMesh&&(e.applyBoneTransform(b,Bt),h&&ja(e,b,It),u&&ja(e,b,Nt)),i&&Bt.applyMatrix4(e.matrixWorld),c.position.setXYZ(b,Bt.x,Bt.y,Bt.z),h&&(i&&It.applyNormalMatrix(m),c.normal.setXYZ(b,It.x,It.y,It.z)),u&&(i&&Nt.transformDirection(e.matrixWorld),c.tangent.setXYZW(b,Nt.x,Nt.y,Nt.z,Ua.w));for(const b in this.attributes){const v=this.attributes[b];v==="position"||v==="tangent"||v==="normal"||!(v in o)||(c[v]||t.setAttribute(v,zr(o[v])),Or(o[v],c[v]),Va(o[v],c[v]))}return e.matrixWorld.determinant()<0&&Ou(t),t}}const Iu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:ya,CENTER:Wn,CONTAINED:Hn,ExtendedTriangle:Ae,MeshBVH:Ir,OrientedBox:fe,SAH:ga,StaticGeometryGenerator:Bu,acceleratedRaycast:Tu,computeBoundsTree:Eu},Symbol.toStringTag,{value:"Module"}));class Nu{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 ze={node:"node",material:"material",camera:"camera",light:"light"},Ut="KHR_animation_pointer",Uu={CUBICSPLINE:void 0,LINEAR:Cs,STEP:ec};class Du{constructor(e){this.name=Ut,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,r=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",r)}loadAnimationTargetFromChannelWithAnimationPointer(e){Lu();const t=e.target,r=t.extensions&&t.extensions[Ut]&&t.path&&t.path==="pointer";if(!r)return null;let i,s=ze.node,a;if(r){const c=t.extensions[Ut];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=ze.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=ze.light:l.startsWith("/cameras/")&&(s=ze.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case ze.material:const h=("/materials/"+a.toString()+"/").length,u=l.substring(0,h);switch(i=l.substring(h),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=u+i;break;case ze.node:const d=("/nodes/"+a.toString()+"/").length,p=l.substring(0,d);switch(i=l.substring(d),i){case"translation":i="position";break;case"rotation":i="quaternion";break;case"scale":i="scale";break;case"weights":i="morphTargetInfluences";break}l=p+i;break;case ze.light:const y=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(i=l.substring(y),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 ze.camera:const g=("/cameras/"+a.toString()+"/").length,f=l.substring(0,g);switch(i=l.substring(g),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=f+i;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[Ut].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===ze.node?o=this.parser.getDependency("node",a):s===ze.material?o=this.parser.getDependency("material",a):s===ze.light?o=this.parser.getDependency("light",a):s===ze.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,r,i,s){if(!(s.extensions&&s.extensions[Ut]&&s.path&&s.path==="pointer"))return null;let a=s.extensions[Ut].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 u of e.children)u instanceof $a&&u.morphTargetInfluences&&(c[3]=u.name,c[4]="morphTargetInfluences",h(this.parser));return o}h(this.parser);function h(u){a=c.join(".");let d;switch(r.itemSize){case 1:d=sc;break;case 2:case 3:d=nc;break;case 4:a.endsWith(".quaternion")?d=rc:d=ic;break}if(!d){console.warn("Unsupported output accessor format",r);return}const p=i.interpolation!==void 0?Uu[i.interpolation]:Cs;let y=u._getArrayFromAccessor(r);a.endsWith(".fov")&&(y=y.map(f=>f/Math.PI*180));const g=new d(a,t.array,y,p);if(p==="CUBICSPLINE"&&u._createCubicSplineTrackInterpolant(g),o.push(g),a&&r.itemSize===4&&a.startsWith(".materials.")&&a.endsWith(".color")){const f=new Float32Array(y.length/4);for(let b=0,v=y.length/4;b<v;b+=1)f[b]=y[b*4+3];const m=new d(a.replace(".color",".opacity"),t.array,f,p);p==="CUBICSPLINE"&&u._createCubicSplineTrackInterpolant(g),o.push(m)}}return o}_tryResolveTargetId(e,t){let r="";return t==="node"?r=e.substring(7):t==="material"?r=e.substring(11):t==="light"?r=e.substring(39):t==="camera"&&(r=e.substring(9)),r=r.substring(0,r.indexOf("/")),Number.parseInt(r)}loadAnimation(e){const t=this,r=this.parser.json,i=this.parser,s=r.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],h=[],u=[];for(let d=0,p=s.channels.length;d<p;d++){const y=s.channels[d],g=s.samplers[y.sampler],f=y.target,m=s.parameters!==void 0?s.parameters[g.input]:g.input,b=s.parameters!==void 0?s.parameters[g.output]:g.output;let v=t.loadAnimationTargetFromChannelWithAnimationPointer(y);v||(v=t.loadAnimationTargetFromChannel(y)),o.push(v),c.push(i.getDependency("accessor",m)),l.push(i.getDependency("accessor",b)),h.push(g),u.push(f)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(h),Promise.all(u)]).then(function(d){const p=d[0],y=d[1],g=d[2],f=d[3],m=d[4],b=[];for(let v=0,x=p.length;v<x;v++){const _=p[v],S=y[v],w=g[v],C=f[v],M=m[v];if(_===void 0)continue;_.updateMatrix&&(_.updateMatrix(),_.matrixAutoUpdate=!0);let T=t.createAnimationTracksWithAnimationPointer(_,S,w,C,M);if(T||(T=i._createAnimationTracks(_,S,w,C,M)),T)for(let E=0;E<T.length;E++)b.push(T[E])}return new tc(a,void 0,b)})}}let Ja=!1,Fu=null;function Lu(){if(Ja)return;Ja=!0;const n=Fu||=Ps.findNode;Ps.findNode=function(e,t){if(t.startsWith(".materials.")){const r=t.substring(11).substring(t.indexOf(".")),i=r.indexOf("."),s=i<0?r:r.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&&(r.endsWith(".map")?a=a.map:r.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const r=t.split(".");let i;for(let s=1;s<r.length;s++){const a=r[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=n(e,r[2]);return s||console.warn(Ut+": Property binding not found",t,e,e.name,r),s}return i}return n(e,t)}}const Vu=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Du},Symbol.toStringTag,{value:"Module"}));export{Ho as $70d766613f57b014$export$2e2bcd8739ae039,mh as BatchedParticleRenderer,gs as Builder,Br as ByteBuffer,Ft as ConstantColor,L as ConstantValue,He as Matrix4,Ir as MeshBVH,dc as MotionController,on as ParticleSystem,R as RenderMode,ks as SIZE_PREFIX_LENGTH,Ai as TrailParticle,Me as Vector4,Nu as WorkerBase,Gc as bundler,gh as createNoise4D,ac as fetchProfile,xh as index,Iu as index$1,Vu as index$2,ol as md5,tl as v5};
|