@needle-tools/engine 4.5.5-next.f053174 → 4.5.6-next.1d4dc79

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/{needle-engine.bundle-DvRTYg0j.js → needle-engine.bundle-BgKkDMl2.js} +3 -3
  3. package/dist/{needle-engine.bundle-DFfLpZpn.min.js → needle-engine.bundle-D9kyS8Tj.min.js} +1 -1
  4. package/dist/{needle-engine.bundle-Dx2hV9Bu.umd.cjs → needle-engine.bundle-DqD4rb6x.umd.cjs} +2 -2
  5. package/dist/needle-engine.js +2 -2
  6. package/dist/needle-engine.min.js +1 -1
  7. package/dist/needle-engine.umd.cjs +1 -1
  8. package/package.json +2 -3
  9. package/plugins/common/license.js +12 -2
  10. package/dist/gltf-progressive-BEgFkNGc.light.min.js +0 -8
  11. package/dist/gltf-progressive-C9Dguupm.light.umd.cjs +0 -8
  12. package/dist/gltf-progressive-ZWp05WqX.light.js +0 -1054
  13. package/dist/needle-engine.bundle-5YrltOTW.light.umd.cjs +0 -1559
  14. package/dist/needle-engine.bundle-Bjtl-M4D.light.js +0 -43245
  15. package/dist/needle-engine.bundle-BxW8rOic.light.min.js +0 -1559
  16. package/dist/needle-engine.light.d.ts +0 -132
  17. package/dist/needle-engine.light.js +0 -617
  18. package/dist/needle-engine.light.min.js +0 -1
  19. package/dist/needle-engine.light.umd.cjs +0 -1
  20. package/dist/postprocessing-FosLwPQS.light.min.js +0 -1637
  21. package/dist/postprocessing-WrSov-2f.light.umd.cjs +0 -1637
  22. package/dist/postprocessing-hAt4uO_H.light.js +0 -14814
  23. package/dist/rapier-CU5cp-KB.light.js +0 -5142
  24. package/dist/rapier-CUe6_xwE.light.umd.cjs +0 -1
  25. package/dist/rapier-CyWhltHY.light.min.js +0 -1
  26. package/dist/three-1JG7vpNC.light.js +0 -32110
  27. package/dist/three-CFtLGNtV.light.min.js +0 -3874
  28. package/dist/three-Cn7l9Zcu.light.umd.cjs +0 -3874
  29. package/dist/three-examples-BEj-FSbn.light.umd.cjs +0 -501
  30. package/dist/three-examples-BnHP6TJv.light.min.js +0 -501
  31. package/dist/three-examples-D7sODHUy.light.js +0 -10800
  32. package/dist/three-mesh-ui-455xHppU.light.umd.cjs +0 -406
  33. package/dist/three-mesh-ui-d5QV--Fw.light.js +0 -6230
  34. package/dist/three-mesh-ui-d9DMm4Vu.light.min.js +0 -406
  35. package/dist/vendor-C6uo3n0R.light.js +0 -14010
  36. package/dist/vendor-Chn-TYVI.light.umd.cjs +0 -1121
  37. package/dist/vendor-D_SttDVr.light.min.js +0 -1121
@@ -1,1121 +0,0 @@
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-CFtLGNtV.light.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);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(`
2
- `).map(function(r){return r.trim()})},e.splitSections=function(t){var r=t.split(`
3
- m=`);return r.map(function(i,s){return(s>0?"m="+i:i).trim()+`\r
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
5
- `},e.parseExtmap=function(t){var r=t.substr(9).split(" ");return{id:parseInt(r[0],10),direction:r[0].indexOf("/")>0?r[0].split("/")[1]:"sendrecv",uri:r[1]}},e.writeExtmap=function(t){return"a=extmap:"+(t.id||t.preferredId)+(t.direction&&t.direction!=="sendrecv"?"/"+t.direction:"")+" "+t.uri+`\r
6
- `},e.parseFmtp=function(t){for(var r={},i,s=t.substr(t.indexOf(" ")+1).split(";"),a=0;a<s.length;a++)i=s[a].trim().split("="),r[i[0].trim()]=i[1];return r},e.writeFmtp=function(t){var r="",i=t.payloadType;if(t.preferredPayloadType!==void 0&&(i=t.preferredPayloadType),t.parameters&&Object.keys(t.parameters).length){var s=[];Object.keys(t.parameters).forEach(function(a){t.parameters[a]?s.push(a+"="+t.parameters[a]):s.push(a)}),r+="a=fmtp:"+i+" "+s.join(";")+`\r
7
- `}return r},e.parseRtcpFb=function(t){var r=t.substr(t.indexOf(" ")+1).split(" ");return{type:r.shift(),parameter:r.join(" ")}},e.writeRtcpFb=function(t){var r="",i=t.payloadType;return t.preferredPayloadType!==void 0&&(i=t.preferredPayloadType),t.rtcpFeedback&&t.rtcpFeedback.length&&t.rtcpFeedback.forEach(function(s){r+="a=rtcp-fb:"+i+" "+s.type+(s.parameter&&s.parameter.length?" "+s.parameter:"")+`\r
8
- `}),r},e.parseSsrcMedia=function(t){var r=t.indexOf(" "),i={ssrc:parseInt(t.substr(7,r-7),10)},s=t.indexOf(":",r);return s>-1?(i.attribute=t.substr(r+1,s-r-1),i.value=t.substr(s+1)):i.attribute=t.substr(r+1),i},e.parseSsrcGroup=function(t){var r=t.substr(13).split(" ");return{semantics:r.shift(),ssrcs:r.map(function(i){return parseInt(i,10)})}},e.getMid=function(t){var r=e.matchPrefix(t,"a=mid:")[0];if(r)return r.substr(6)},e.parseFingerprint=function(t){var r=t.substr(14).split(" ");return{algorithm:r[0].toLowerCase(),value:r[1]}},e.getDtlsParameters=function(t,r){var i=e.matchPrefix(t+r,"a=fingerprint:");return{role:"auto",fingerprints:i.map(e.parseFingerprint)}},e.writeDtlsParameters=function(t,r){var i="a=setup:"+r+`\r
9
- `;return t.fingerprints.forEach(function(s){i+="a=fingerprint:"+s.algorithm+" "+s.value+`\r
10
- `}),i},e.parseCryptoLine=function(t){var r=t.substr(9).split(" ");return{tag:parseInt(r[0],10),cryptoSuite:r[1],keyParams:r[2],sessionParams:r.slice(3)}},e.writeCryptoLine=function(t){return"a=crypto:"+t.tag+" "+t.cryptoSuite+" "+(typeof t.keyParams=="object"?e.writeCryptoKeyParams(t.keyParams):t.keyParams)+(t.sessionParams?" "+t.sessionParams.join(" "):"")+`\r
11
- `},e.parseCryptoKeyParams=function(t){if(t.indexOf("inline:")!==0)return null;var r=t.substr(7).split("|");return{keyMethod:"inline",keySalt:r[0],lifeTime:r[1],mkiValue:r[2]?r[2].split(":")[0]:void 0,mkiLength:r[2]?r[2].split(":")[1]:void 0}},e.writeCryptoKeyParams=function(t){return t.keyMethod+":"+t.keySalt+(t.lifeTime?"|"+t.lifeTime:"")+(t.mkiValue&&t.mkiLength?"|"+t.mkiValue+":"+t.mkiLength:"")},e.getCryptoParameters=function(t,r){var i=e.matchPrefix(t+r,"a=crypto:");return i.map(e.parseCryptoLine)},e.getIceParameters=function(t,r){var i=e.matchPrefix(t+r,"a=ice-ufrag:")[0],s=e.matchPrefix(t+r,"a=ice-pwd:")[0];return i&&s?{usernameFragment:i.substr(12),password:s.substr(10)}:null},e.writeIceParameters=function(t){return"a=ice-ufrag:"+t.usernameFragment+`\r
12
- a=ice-pwd:`+t.password+`\r
13
- `},e.parseRtpParameters=function(t){for(var r={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},i=e.splitLines(t),s=i[0].split(" "),a=3;a<s.length;a++){var o=s[a],c=e.matchPrefix(t,"a=rtpmap:"+o+" ")[0];if(c){var l=e.parseRtpMap(c),h=e.matchPrefix(t,"a=fmtp:"+o+" ");switch(l.parameters=h.length?e.parseFmtp(h[0]):{},l.rtcpFeedback=e.matchPrefix(t,"a=rtcp-fb:"+o+" ").map(e.parseRtcpFb),r.codecs.push(l),l.name.toUpperCase()){case"RED":case"ULPFEC":r.fecMechanisms.push(l.name.toUpperCase());break}}}return e.matchPrefix(t,"a=extmap:").forEach(function(u){r.headerExtensions.push(e.parseExtmap(u))}),r},e.writeRtpDescription=function(t,r){var i="";i+="m="+t+" ",i+=r.codecs.length>0?"9":"0",i+=" UDP/TLS/RTP/SAVPF ",i+=r.codecs.map(function(a){return a.preferredPayloadType!==void 0?a.preferredPayloadType:a.payloadType}).join(" ")+`\r
14
- `,i+=`c=IN IP4 0.0.0.0\r
15
- `,i+=`a=rtcp:9 IN IP4 0.0.0.0\r
16
- `,r.codecs.forEach(function(a){i+=e.writeRtpMap(a),i+=e.writeFmtp(a),i+=e.writeRtcpFb(a)});var s=0;return r.codecs.forEach(function(a){a.maxptime>s&&(s=a.maxptime)}),s>0&&(i+="a=maxptime:"+s+`\r
17
- `),i+=`a=rtcp-mux\r
18
- `,r.headerExtensions&&r.headerExtensions.forEach(function(a){i+=e.writeExtmap(a)}),i},e.parseRtpEncodingParameters=function(t){var r=[],i=e.parseRtpParameters(t),s=i.fecMechanisms.indexOf("RED")!==-1,a=i.fecMechanisms.indexOf("ULPFEC")!==-1,o=e.matchPrefix(t,"a=ssrc:").map(function(d){return e.parseSsrcMedia(d)}).filter(function(d){return d.attribute==="cname"}),c=o.length>0&&o[0].ssrc,l,h=e.matchPrefix(t,"a=ssrc-group:FID").map(function(d){var p=d.substr(17).split(" ");return p.map(function(y){return parseInt(y,10)})});h.length>0&&h[0].length>1&&h[0][0]===c&&(l=h[0][1]),i.codecs.forEach(function(d){if(d.name.toUpperCase()==="RTX"&&d.parameters.apt){var p={ssrc:c,codecPayloadType:parseInt(d.parameters.apt,10)};c&&l&&(p.rtx={ssrc:l}),r.push(p),s&&(p=JSON.parse(JSON.stringify(p)),p.fec={ssrc:c,mechanism:a?"red+ulpfec":"red"},r.push(p))}}),r.length===0&&c&&r.push({ssrc:c});var u=e.matchPrefix(t,"b=");return u.length&&(u[0].indexOf("b=TIAS:")===0?u=parseInt(u[0].substr(7),10):u[0].indexOf("b=AS:")===0?u=parseInt(u[0].substr(5),10)*1e3*.95-50*40*8:u=void 0,r.forEach(function(d){d.maxBitrate=u})),r},e.parseRtcpParameters=function(t){var r={},i=e.matchPrefix(t,"a=ssrc:").map(function(o){return e.parseSsrcMedia(o)}).filter(function(o){return o.attribute==="cname"})[0];i&&(r.cname=i.value,r.ssrc=i.ssrc);var s=e.matchPrefix(t,"a=rtcp-rsize");r.reducedSize=s.length>0,r.compound=s.length===0;var a=e.matchPrefix(t,"a=rtcp-mux");return r.mux=a.length>0,r},e.parseMsid=function(t){var r,i=e.matchPrefix(t,"a=msid:");if(i.length===1)return r=i[0].substr(7).split(" "),{stream:r[0],track:r[1]};var s=e.matchPrefix(t,"a=ssrc:").map(function(a){return e.parseSsrcMedia(a)}).filter(function(a){return a.attribute==="msid"});if(s.length>0)return r=s[0].value.split(" "),{stream:r[0],track:r[1]}},e.parseSctpDescription=function(t){var r=e.parseMLine(t),i=e.matchPrefix(t,"a=max-message-size:"),s;i.length>0&&(s=parseInt(i[0].substr(19),10)),isNaN(s)&&(s=65536);var a=e.matchPrefix(t,"a=sctp-port:");if(a.length>0)return{port:parseInt(a[0].substr(12),10),protocol:r.fmt,maxMessageSize:s};var o=e.matchPrefix(t,"a=sctpmap:");if(o.length>0){var c=e.matchPrefix(t,"a=sctpmap:")[0].substr(10).split(" ");return{port:parseInt(c[0],10),protocol:c[1],maxMessageSize:s}}},e.writeSctpDescription=function(t,r){var i=[];return t.protocol!=="DTLS/SCTP"?i=["m="+t.kind+" 9 "+t.protocol+" "+r.protocol+`\r
19
- `,`c=IN IP4 0.0.0.0\r
20
- `,"a=sctp-port:"+r.port+`\r
21
- `]:i=["m="+t.kind+" 9 "+t.protocol+" "+r.port+`\r
22
- `,`c=IN IP4 0.0.0.0\r
23
- `,"a=sctpmap:"+r.port+" "+r.protocol+` 65535\r
24
- `],r.maxMessageSize!==void 0&&i.push("a=max-message-size:"+r.maxMessageSize+`\r
25
- `),i.join("")},e.generateSessionId=function(){return Math.random().toString().substr(2,21)},e.writeSessionBoilerplate=function(t,r,i){var s,a=r!==void 0?r:2;t?s=t:s=e.generateSessionId();var o=i||"thisisadapterortc";return`v=0\r
26
- o=`+o+" "+s+" "+a+` IN IP4 127.0.0.1\r
27
- s=-\r
28
- t=0 0\r
29
- `},e.writeMediaSection=function(t,r,i,s){var a=e.writeRtpDescription(t.kind,r);if(a+=e.writeIceParameters(t.iceGatherer.getLocalParameters()),a+=e.writeDtlsParameters(t.dtlsTransport.getLocalParameters(),i==="offer"?"actpass":"active"),a+="a=mid:"+t.mid+`\r
30
- `,t.direction?a+="a="+t.direction+`\r
31
- `:t.rtpSender&&t.rtpReceiver?a+=`a=sendrecv\r
32
- `:t.rtpSender?a+=`a=sendonly\r
33
- `:t.rtpReceiver?a+=`a=recvonly\r
34
- `:a+=`a=inactive\r
35
- `,t.rtpSender){var o="msid:"+s.id+" "+t.rtpSender.track.id+`\r
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
- `)}return a+="a=ssrc:"+t.sendEncodingParameters[0].ssrc+" cname:"+e.localCName+`\r
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}(Ys)),Ys.exports}var mn,Ks;function cc(){if(Ks)return mn;Ks=1;var n=Qs();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
- `,c.rtpSender&&c.rtpReceiver?p+=`a=sendrecv\r
41
- `:c.rtpSender?p+=`a=sendonly\r
42
- `:c.rtpReceiver?p+=`a=recvonly\r
43
- `:p+=`a=inactive\r
44
- `,c.rtpSender){var y=c.rtpSender._initialTrackId||c.rtpSender.track.id;c.rtpSender._initialTrackId=y;var g="msid:"+(u?u.id:"-")+" "+y+`\r
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
- `)}return p+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" cname:"+n.localCName+`\r
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),v=u(y.parameters.apt,f);return m&&v&&m.name.toLowerCase()===v.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 mn=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,v,_){var b=new Event("track");b.track=m,b.receiver=v,b.transceiver={receiver:v},b.streams=_,c.setTimeout(function(){f._dispatchEvent("track",b)})}var p=function(f){var m=this,v=document.createDocumentFragment();if(["addEventListener","removeEventListener","dispatchEvent"].forEach(function(b){m[b]=v[b].bind(v)}),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 _=f.iceCandidatePoolSize;_>0;_--)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 v=this.transceivers.length>0,_={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&&v)_.iceTransport=this.transceivers[0].iceTransport,_.dtlsTransport=this.transceivers[0].dtlsTransport;else{var b=this._createIceAndDtlsTransports();_.iceTransport=b.iceTransport,_.dtlsTransport=b.dtlsTransport}return m||this.transceivers.push(_),_},p.prototype.addTrack=function(f,m){if(this._isClosed)throw o("InvalidStateError","Attempted to call addTrack on a closed peerconnection.");var v=this.transceivers.find(function(x){return x.track===f});if(v)throw o("InvalidAccessError","Track already exists.");for(var _,b=0;b<this.transceivers.length;b++)!this.transceivers[b].track&&this.transceivers[b].kind===f.kind&&(_=this.transceivers[b]);return _||(_=this._createTransceiver(f.kind)),this._maybeFireNegotiationNeeded(),this.localStreams.indexOf(m)===-1&&this.localStreams.push(m),_.track=f,_.stream=m,_.rtpSender=new c.RTCRtpSender(f,_.dtlsTransport),_.rtpSender},p.prototype.addStream=function(f){var m=this;if(l>=15025)f.getTracks().forEach(function(_){m.addTrack(_,f)});else{var v=f.clone();f.getTracks().forEach(function(_,b){var x=v.getTracks()[b];_.addEventListener("enabled",function(S){x.enabled=S.enabled})}),v.getTracks().forEach(function(_){m.addTrack(_,v)})}},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(b){return b.rtpSender===f});if(!m)throw o("InvalidAccessError","Sender was not created by this connection.");var v=m.stream;m.rtpSender.stop(),m.rtpSender=null,m.track=null,m.stream=null;var _=this.transceivers.map(function(b){return b.stream});_.indexOf(v)===-1&&this.localStreams.indexOf(v)>-1&&this.localStreams.splice(this.localStreams.indexOf(v),1),this._maybeFireNegotiationNeeded()},p.prototype.removeStream=function(f){var m=this;f.getTracks().forEach(function(v){var _=m.getSenders().find(function(b){return b.track===v});_&&m.removeTrack(_)})},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 v=this;if(m&&f>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var _=new c.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(_,"state",{value:"new",writable:!0}),this.transceivers[f].bufferedCandidateEvents=[],this.transceivers[f].bufferCandidates=function(b){var x=!b.candidate||Object.keys(b.candidate).length===0;_.state=x?"completed":"gathering",v.transceivers[f].bufferedCandidateEvents!==null&&v.transceivers[f].bufferedCandidateEvents.push(b)},_.addEventListener("localcandidate",this.transceivers[f].bufferCandidates),_},p.prototype._gather=function(f,m){var v=this,_=this.transceivers[m].iceGatherer;if(!_.onlocalcandidate){var b=this.transceivers[m].bufferedCandidateEvents;this.transceivers[m].bufferedCandidateEvents=null,_.removeEventListener("localcandidate",this.transceivers[m].bufferCandidates),_.onlocalcandidate=function(x){if(!(v.usingBundle&&m>0)){var S=new Event("icecandidate");S.candidate={sdpMid:f,sdpMLineIndex:m};var w=x.candidate,C=!w||Object.keys(w).length===0;if(C)(_.state==="new"||_.state==="gathering")&&(_.state="completed");else{_.state==="new"&&(_.state="gathering"),w.component=1,w.ufrag=_.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(v._localDescription.sdp);C?T[S.candidate.sdpMLineIndex]+=`a=end-of-candidates\r
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
- `),b+=`a=ice-options:trickle\r
52
- `,f.transceivers.forEach(function(S,w){b+=t(S,S.localCapabilities,"offer",S.stream,f._dtlsRole),b+=`a=rtcp-rsize\r
53
- `,S.iceGatherer&&f.iceGatheringState!=="new"&&(w===0||!f.usingBundle)&&(S.iceGatherer.getLocalCandidates().forEach(function(C){C.component=1,b+="a="+n.writeCandidate(C)+`\r
54
- `}),S.iceGatherer.state==="completed"&&(b+=`a=end-of-candidates\r
55
- `))});var x=new c.RTCSessionDescription({type:"offer",sdp:b});return Promise.resolve(x)},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(b){return b.mid}).join(" ")+`\r
56
- `),m+=`a=ice-options:trickle\r
57
- `;var v=n.getMediaSections(f._remoteDescription.sdp).length;f.transceivers.forEach(function(b,x){if(!(x+1>v)){if(b.rejected){b.kind==="application"?b.protocol==="DTLS/SCTP"?m+=`m=application 0 DTLS/SCTP 5000\r
58
- `:m+="m=application 0 "+b.protocol+` webrtc-datachannel\r
59
- `:b.kind==="audio"?m+=`m=audio 0 UDP/TLS/RTP/SAVPF 0\r
60
- a=rtpmap:0 PCMU/8000\r
61
- `:b.kind==="video"&&(m+=`m=video 0 UDP/TLS/RTP/SAVPF 120\r
62
- a=rtpmap:120 VP8/90000\r
63
- `),m+=`c=IN IP4 0.0.0.0\r
64
- a=inactive\r
65
- a=mid:`+b.mid+`\r
66
- `;return}if(b.stream){var S;b.kind==="audio"?S=b.stream.getAudioTracks()[0]:b.kind==="video"&&(S=b.stream.getVideoTracks()[0]),S&&l>=15019&&b.kind==="video"&&!b.sendEncodingParameters[0].rtx&&(b.sendEncodingParameters[0].rtx={ssrc:b.sendEncodingParameters[0].ssrc+1})}var w=i(b.localCapabilities,b.remoteCapabilities),C=w.codecs.filter(function(M){return M.name.toLowerCase()==="rtx"}).length;!C&&b.sendEncodingParameters[0].rtx&&delete b.sendEncodingParameters[0].rtx,m+=t(b,w,"answer",b.stream,f._dtlsRole),b.rtcpParameters&&b.rtcpParameters.reducedSize&&(m+=`a=rtcp-rsize\r
67
- `)}});var _=new c.RTCSessionDescription({type:"answer",sdp:m});return Promise.resolve(_)},p.prototype.addIceCandidate=function(f){var m=this,v;return f&&!(f.sdpMLineIndex!==void 0||f.sdpMid)?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise(function(_,b){if(m._remoteDescription)if(!f||f.candidate==="")for(var x=0;x<m.transceivers.length&&!(!m.transceivers[x].rejected&&(m.transceivers[x].iceTransport.addRemoteCandidate({}),v=n.getMediaSections(m._remoteDescription.sdp),v[x]+=`a=end-of-candidates\r
68
- `,m._remoteDescription.sdp=n.getDescription(m._remoteDescription.sdp)+v.join(""),m.usingBundle));x++);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 _();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 _();if((S===0||S>0&&C.iceTransport!==m.transceivers[0].iceTransport)&&!a(C.iceTransport,M))return b(o("OperationError","Can not add ICE candidate"));var T=f.candidate.trim();T.indexOf("a=")===0&&(T=T.substr(2)),v=n.getMediaSections(m._remoteDescription.sdp),v[S]+="a="+(M.type?T:"end-of-candidates")+`\r
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);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(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(`
70
- a=extmap-allow-mixed`)!==-1){const i=r.sdp.split(`
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 yi(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 pc=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:_n,shimAddIceCandidateNullOrEmpty:yi,shimConnectionState:vn,shimMaxMessageSize:lr,shimRTCIceCandidate:mi,shimSendThrowTypeError:hr},Symbol.toStringTag,{value:"Module"}));function fc({window:n}={},e={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const t=dn,r=sc(n),i={browserDetails:r,commonShim:pc,extractVersion:cr,disableLog:ic,disableWarnings:nc};switch(r.browser){case"chrome":if(!Hs||!fn||!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=Hs,yi(n,r),Fs(n,r),Ls(n),fn(n,r),Vs(n),Xs(n,r),js(n),Js(n),Gs(n),qs(n,r),mi(n),vn(n),lr(n,r),hr(n),_n(n,r);break;case"firefox":if(!fo||!gn||!e.shimFirefox)return t("Firefox shim is not included in this adapter release."),i;t("adapter.js shimming firefox."),i.browserShim=fo,yi(n,r),io(n,r),gn(n,r),no(n),ao(n),so(n),oo(n),co(n),lo(n),ho(n),uo(n),po(n),mi(n),vn(n),lr(n,r),hr(n);break;case"edge":if(!ro||!yn||!e.shimEdge)return t("MS edge shim is not included in this adapter release."),i;t("adapter.js shimming edge."),i.browserShim=ro,$s(n),eo(n),yn(n,r),to(n),lr(n,r),hr(n);break;case"safari":if(!Mo||!e.shimSafari)return t("Safari shim is not included in this adapter release."),i;t("adapter.js shimming safari."),i.browserShim=Mo,yi(n,r),bo(n),So(n),go(n),mo(n),yo(n),xo(n),vo(n),wo(n),mi(n),lr(n,r),hr(n),_n(n,r);break;default:t("Unsupported browser!");break}return i}const To=fc({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 bn=To.default||To,ur=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 bn.browserDetails.browser},n.prototype.getVersion=function(){return bn.browserDetails.version||0},n.prototype.isUnifiedPlanSupported=function(){var e=this.getBrowser(),t=bn.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
- browser:`.concat(this.getBrowser(),`
74
- version:`).concat(this.getVersion(),`
75
- isIOS:`).concat(this.isIOS,`
76
- isWebRTCSupported:`).concat(this.isWebRTCSupported(),`
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}/*!
79
- * Determine if an object is a Buffer
80
- *
81
- * @author Feross Aboukhadijeh <https://feross.org>
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=`
84
- #ifdef SOFT_PARTICLES
85
-
86
- /* #ifdef LOGDEPTH
87
- float distSample = linearize_depth_log(sampleDepth, near, far);
88
- #else
89
- float distSample = ortho ? linearize_depth_ortho(sampleDepth, near, far) : linearize_depth(sampleDepth, near, far);
90
- #endif */
91
-
92
- vec2 p2 = projPosition.xy / projPosition.w;
93
-
94
- p2 = 0.5 * p2 + 0.5;
95
-
96
- float readDepth = texture2D(depthTexture, p2.xy).r;
97
- float viewDepth = linearize_depth(readDepth);
98
-
99
- float softParticlesFade = saturate(SOFT_INV_FADE_DISTANCE * ((viewDepth - SOFT_NEAR_FADE) - linearDepth));
100
-
101
- gl_FragColor *= softParticlesFade;
102
-
103
- //gl_FragColor = vec4(softParticlesFade , 0, 0, 1);
104
- #endif
105
- `,Il=`
106
- #ifdef SOFT_PARTICLES
107
-
108
- uniform sampler2D depthTexture;
109
- uniform vec4 projParams;
110
- uniform vec2 softParams;
111
-
112
- varying vec4 projPosition;
113
- varying float linearDepth;
114
-
115
- #define SOFT_NEAR_FADE softParams.x
116
- #define SOFT_INV_FADE_DISTANCE softParams.y
117
-
118
- #define zNear projParams.x
119
- #define zFar projParams.y
120
-
121
- float linearize_depth(float d)
122
- {
123
- return (zFar * zNear) / (zFar - d * (zFar - zNear));
124
- }
125
-
126
- #endif
127
- `,Ul=`
128
- #ifdef SOFT_PARTICLES
129
- varying vec4 projPosition;
130
- varying float linearDepth;
131
- #endif
132
- `,Nl=`
133
- #ifdef SOFT_PARTICLES
134
- projPosition = gl_Position;
135
- linearDepth = -mvPosition.z;
136
- #endif
137
- `,Dl=`
138
- #ifdef USE_MAP
139
- vec4 texelColor = texture2D( map, vUv);
140
- #ifdef TILE_BLEND
141
- texelColor = mix( texelColor, texture2D( map, vUvNext ), vUvBlend );
142
- #endif
143
- diffuseColor *= texelColor;
144
- #endif
145
- `,Fl=`
146
- #if defined( USE_UV ) || defined( USE_ANISOTROPY )
147
-
148
- varying vec2 vUv;
149
- #ifdef TILE_BLEND
150
- varying vec2 vUvNext;
151
- varying float vUvBlend;
152
- #endif
153
-
154
- #endif
155
- #ifdef USE_MAP
156
-
157
- uniform mat3 mapTransform;
158
- varying vec2 vMapUv;
159
- #ifdef TILE_BLEND
160
- varying vec2 vMapUvNext;
161
- #endif
162
-
163
- #endif
164
- #ifdef USE_ALPHAMAP
165
-
166
- uniform mat3 alphaMapTransform;
167
- varying vec2 vAlphaMapUv;
168
-
169
- #endif
170
- #ifdef USE_LIGHTMAP
171
-
172
- uniform mat3 lightMapTransform;
173
- varying vec2 vLightMapUv;
174
-
175
- #endif
176
- #ifdef USE_AOMAP
177
-
178
- uniform mat3 aoMapTransform;
179
- varying vec2 vAoMapUv;
180
-
181
- #endif
182
- #ifdef USE_BUMPMAP
183
-
184
- uniform mat3 bumpMapTransform;
185
- varying vec2 vBumpMapUv;
186
-
187
- #endif
188
- #ifdef USE_NORMALMAP
189
-
190
- uniform mat3 normalMapTransform;
191
- varying vec2 vNormalMapUv;
192
-
193
- #endif
194
- #ifdef USE_DISPLACEMENTMAP
195
-
196
- uniform mat3 displacementMapTransform;
197
- varying vec2 vDisplacementMapUv;
198
-
199
- #endif
200
- #ifdef USE_EMISSIVEMAP
201
-
202
- uniform mat3 emissiveMapTransform;
203
- varying vec2 vEmissiveMapUv;
204
-
205
- #endif
206
- #ifdef USE_METALNESSMAP
207
-
208
- uniform mat3 metalnessMapTransform;
209
- varying vec2 vMetalnessMapUv;
210
-
211
- #endif
212
- #ifdef USE_ROUGHNESSMAP
213
-
214
- uniform mat3 roughnessMapTransform;
215
- varying vec2 vRoughnessMapUv;
216
-
217
- #endif
218
- #ifdef USE_ANISOTROPYMAP
219
-
220
- uniform mat3 anisotropyMapTransform;
221
- varying vec2 vAnisotropyMapUv;
222
-
223
- #endif
224
- #ifdef USE_CLEARCOATMAP
225
-
226
- uniform mat3 clearcoatMapTransform;
227
- varying vec2 vClearcoatMapUv;
228
-
229
- #endif
230
- #ifdef USE_CLEARCOAT_NORMALMAP
231
-
232
- uniform mat3 clearcoatNormalMapTransform;
233
- varying vec2 vClearcoatNormalMapUv;
234
-
235
- #endif
236
- #ifdef USE_CLEARCOAT_ROUGHNESSMAP
237
-
238
- uniform mat3 clearcoatRoughnessMapTransform;
239
- varying vec2 vClearcoatRoughnessMapUv;
240
-
241
- #endif
242
- #ifdef USE_SHEEN_COLORMAP
243
-
244
- uniform mat3 sheenColorMapTransform;
245
- varying vec2 vSheenColorMapUv;
246
-
247
- #endif
248
- #ifdef USE_SHEEN_ROUGHNESSMAP
249
-
250
- uniform mat3 sheenRoughnessMapTransform;
251
- varying vec2 vSheenRoughnessMapUv;
252
-
253
- #endif
254
- #ifdef USE_IRIDESCENCEMAP
255
-
256
- uniform mat3 iridescenceMapTransform;
257
- varying vec2 vIridescenceMapUv;
258
-
259
- #endif
260
- #ifdef USE_IRIDESCENCE_THICKNESSMAP
261
-
262
- uniform mat3 iridescenceThicknessMapTransform;
263
- varying vec2 vIridescenceThicknessMapUv;
264
-
265
- #endif
266
- #ifdef USE_SPECULARMAP
267
-
268
- uniform mat3 specularMapTransform;
269
- varying vec2 vSpecularMapUv;
270
-
271
- #endif
272
- #ifdef USE_SPECULAR_COLORMAP
273
-
274
- uniform mat3 specularColorMapTransform;
275
- varying vec2 vSpecularColorMapUv;
276
-
277
- #endif
278
- #ifdef USE_SPECULAR_INTENSITYMAP
279
-
280
- uniform mat3 specularIntensityMapTransform;
281
- varying vec2 vSpecularIntensityMapUv;
282
-
283
- #endif
284
- #ifdef USE_TRANSMISSIONMAP
285
-
286
- uniform mat3 transmissionMapTransform;
287
- varying vec2 vTransmissionMapUv;
288
-
289
- #endif
290
- #ifdef USE_THICKNESSMAP
291
-
292
- uniform mat3 thicknessMapTransform;
293
- varying vec2 vThicknessMapUv;
294
-
295
- #endif
296
- `,Ll=`
297
- #ifdef UV_TILE
298
- attribute float uvTile;
299
- uniform vec2 tileCount;
300
-
301
- mat3 makeTileTransform(float uvTile) {
302
- float col = mod(uvTile, tileCount.x);
303
- float row = (tileCount.y - floor(uvTile / tileCount.x) - 1.0);
304
-
305
- return mat3(
306
- 1.0 / tileCount.x, 0.0, 0.0,
307
- 0.0, 1.0 / tileCount.y, 0.0,
308
- col / tileCount.x, row / tileCount.y, 1.0);
309
- }
310
- #else
311
- mat3 makeTileTransform(float uvTile) {
312
- return mat3(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
313
- }
314
- #endif
315
-
316
- #if defined( USE_UV ) || defined( USE_ANISOTROPY )
317
-
318
- varying vec2 vUv;
319
- #ifdef TILE_BLEND
320
- varying vec2 vUvNext;
321
- varying float vUvBlend;
322
- #endif
323
-
324
- #endif
325
- #ifdef USE_MAP
326
-
327
- uniform mat3 mapTransform;
328
- varying vec2 vMapUv;
329
- #ifdef TILE_BLEND
330
- varying vec2 vMapUvNext;
331
- #endif
332
-
333
- #endif
334
- #ifdef USE_ALPHAMAP
335
-
336
- uniform mat3 alphaMapTransform;
337
- varying vec2 vAlphaMapUv;
338
-
339
- #endif
340
- #ifdef USE_LIGHTMAP
341
-
342
- uniform mat3 lightMapTransform;
343
- varying vec2 vLightMapUv;
344
-
345
- #endif
346
- #ifdef USE_AOMAP
347
-
348
- uniform mat3 aoMapTransform;
349
- varying vec2 vAoMapUv;
350
-
351
- #endif
352
- #ifdef USE_BUMPMAP
353
-
354
- uniform mat3 bumpMapTransform;
355
- varying vec2 vBumpMapUv;
356
-
357
- #endif
358
- #ifdef USE_NORMALMAP
359
-
360
- uniform mat3 normalMapTransform;
361
- varying vec2 vNormalMapUv;
362
-
363
- #endif
364
- #ifdef USE_DISPLACEMENTMAP
365
-
366
- uniform mat3 displacementMapTransform;
367
- varying vec2 vDisplacementMapUv;
368
-
369
- #endif
370
- #ifdef USE_EMISSIVEMAP
371
-
372
- uniform mat3 emissiveMapTransform;
373
- varying vec2 vEmissiveMapUv;
374
-
375
- #endif
376
- #ifdef USE_METALNESSMAP
377
-
378
- uniform mat3 metalnessMapTransform;
379
- varying vec2 vMetalnessMapUv;
380
-
381
- #endif
382
- #ifdef USE_ROUGHNESSMAP
383
-
384
- uniform mat3 roughnessMapTransform;
385
- varying vec2 vRoughnessMapUv;
386
-
387
- #endif
388
- #ifdef USE_ANISOTROPYMAP
389
-
390
- uniform mat3 anisotropyMapTransform;
391
- varying vec2 vAnisotropyMapUv;
392
-
393
- #endif
394
- #ifdef USE_CLEARCOATMAP
395
-
396
- uniform mat3 clearcoatMapTransform;
397
- varying vec2 vClearcoatMapUv;
398
-
399
- #endif
400
- #ifdef USE_CLEARCOAT_NORMALMAP
401
-
402
- uniform mat3 clearcoatNormalMapTransform;
403
- varying vec2 vClearcoatNormalMapUv;
404
-
405
- #endif
406
- #ifdef USE_CLEARCOAT_ROUGHNESSMAP
407
-
408
- uniform mat3 clearcoatRoughnessMapTransform;
409
- varying vec2 vClearcoatRoughnessMapUv;
410
-
411
- #endif
412
- #ifdef USE_SHEEN_COLORMAP
413
-
414
- uniform mat3 sheenColorMapTransform;
415
- varying vec2 vSheenColorMapUv;
416
-
417
- #endif
418
- #ifdef USE_SHEEN_ROUGHNESSMAP
419
-
420
- uniform mat3 sheenRoughnessMapTransform;
421
- varying vec2 vSheenRoughnessMapUv;
422
-
423
- #endif
424
- #ifdef USE_IRIDESCENCEMAP
425
-
426
- uniform mat3 iridescenceMapTransform;
427
- varying vec2 vIridescenceMapUv;
428
-
429
- #endif
430
- #ifdef USE_IRIDESCENCE_THICKNESSMAP
431
-
432
- uniform mat3 iridescenceThicknessMapTransform;
433
- varying vec2 vIridescenceThicknessMapUv;
434
-
435
- #endif
436
- #ifdef USE_SPECULARMAP
437
-
438
- uniform mat3 specularMapTransform;
439
- varying vec2 vSpecularMapUv;
440
-
441
- #endif
442
- #ifdef USE_SPECULAR_COLORMAP
443
-
444
- uniform mat3 specularColorMapTransform;
445
- varying vec2 vSpecularColorMapUv;
446
-
447
- #endif
448
- #ifdef USE_SPECULAR_INTENSITYMAP
449
-
450
- uniform mat3 specularIntensityMapTransform;
451
- varying vec2 vSpecularIntensityMapUv;
452
-
453
- #endif
454
- #ifdef USE_TRANSMISSIONMAP
455
-
456
- uniform mat3 transmissionMapTransform;
457
- varying vec2 vTransmissionMapUv;
458
-
459
- #endif
460
- #ifdef USE_THICKNESSMAP
461
-
462
- uniform mat3 thicknessMapTransform;
463
- varying vec2 vThicknessMapUv;
464
-
465
- #endif
466
- `,Vl=`
467
- #ifdef UV_TILE
468
- mat3 tileTransform = makeTileTransform(floor(uvTile));
469
- #ifdef TILE_BLEND
470
- mat3 nextTileTransform = makeTileTransform(ceil(uvTile));
471
- vUvBlend = fract(uvTile);
472
- #endif
473
- #else
474
- mat3 tileTransform = makeTileTransform(0.0);
475
- #endif
476
-
477
- #if defined( USE_UV ) || defined( USE_ANISOTROPY )
478
-
479
- vUv = (tileTransform *vec3( uv, 1 )).xy;
480
- #if defined( TILE_BLEND ) && defined( UV_TILE )
481
- vUvNext = (nextTileTransform *vec3( uv, 1 )).xy;
482
- #endif
483
-
484
- #endif
485
- #ifdef USE_MAP
486
-
487
- vMapUv = ( tileTransform * (mapTransform * vec3( MAP_UV, 1 ) )).xy;
488
- #if defined( TILE_BLEND ) && defined( UV_TILE )
489
- vMapUvNext = (nextTileTransform * (mapTransform * vec3( MAP_UV, 1 ))).xy;
490
- #endif
491
-
492
- #endif
493
- #ifdef USE_ALPHAMAP
494
-
495
- vAlphaMapUv = ( tileTransform * (alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) )).xy;
496
-
497
- #endif
498
- #ifdef USE_LIGHTMAP
499
-
500
- vLightMapUv = ( tileTransform * (lightMapTransform * vec3( LIGHTMAP_UV, 1 ) )).xy;
501
-
502
- #endif
503
- #ifdef USE_AOMAP
504
-
505
- vAoMapUv = ( tileTransform * (aoMapTransform * vec3( AOMAP_UV, 1 ) )).xy;
506
-
507
- #endif
508
- #ifdef USE_BUMPMAP
509
-
510
- vBumpMapUv = ( tileTransform * (bumpMapTransform * vec3( BUMPMAP_UV, 1 ) )).xy;
511
-
512
- #endif
513
- #ifdef USE_NORMALMAP
514
-
515
- vNormalMapUv = ( tileTransform * (normalMapTransform * vec3( NORMALMAP_UV, 1 ) )).xy;
516
-
517
- #endif
518
- #ifdef USE_DISPLACEMENTMAP
519
-
520
- vDisplacementMapUv = ( tileTransform * (displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) )).xy;
521
-
522
- #endif
523
- #ifdef USE_EMISSIVEMAP
524
-
525
- vEmissiveMapUv = ( tileTransform * (emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) )).xy;
526
-
527
- #endif
528
- #ifdef USE_METALNESSMAP
529
-
530
- vMetalnessMapUv = ( tileTransform * (metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) )).xy;
531
-
532
- #endif
533
- #ifdef USE_ROUGHNESSMAP
534
-
535
- vRoughnessMapUv = ( tileTransform * (roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) )).xy;
536
-
537
- #endif
538
- #ifdef USE_ANISOTROPYMAP
539
-
540
- vAnisotropyMapUv = ( tileTransform * (anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) )).xy;
541
-
542
- #endif
543
- #ifdef USE_CLEARCOATMAP
544
-
545
- vClearcoatMapUv = ( tileTransform * (clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) )).xy;
546
-
547
- #endif
548
- #ifdef USE_CLEARCOAT_NORMALMAP
549
-
550
- vClearcoatNormalMapUv = ( tileTransform * (clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) )).xy;
551
-
552
- #endif
553
- #ifdef USE_CLEARCOAT_ROUGHNESSMAP
554
-
555
- vClearcoatRoughnessMapUv = ( tileTransform * (clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) )).xy;
556
-
557
- #endif
558
- #ifdef USE_IRIDESCENCEMAP
559
-
560
- vIridescenceMapUv = ( tileTransform * (iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) )).xy;
561
-
562
- #endif
563
- #ifdef USE_IRIDESCENCE_THICKNESSMAP
564
-
565
- vIridescenceThicknessMapUv = ( tileTransform * (iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) )).xy;
566
-
567
- #endif
568
- #ifdef USE_SHEEN_COLORMAP
569
-
570
- vSheenColorMapUv = ( tileTransform * (sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) )).xy;
571
-
572
- #endif
573
- #ifdef USE_SHEEN_ROUGHNESSMAP
574
-
575
- vSheenRoughnessMapUv = ( tileTransform * (sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) )).xy;
576
-
577
- #endif
578
- #ifdef USE_SPECULARMAP
579
-
580
- vSpecularMapUv = ( tileTransform * (specularMapTransform * vec3( SPECULARMAP_UV, 1 ) )).xy;
581
-
582
- #endif
583
- #ifdef USE_SPECULAR_COLORMAP
584
-
585
- vSpecularColorMapUv = ( tileTransform * (specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) )).xy;
586
-
587
- #endif
588
- #ifdef USE_SPECULAR_INTENSITYMAP
589
-
590
- vSpecularIntensityMapUv = ( tileTransform * (specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) )).xy;
591
-
592
- #endif
593
- #ifdef USE_TRANSMISSIONMAP
594
-
595
- vTransmissionMapUv = ( tileTransform * transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) )).xy;
596
-
597
- #endif
598
- #ifdef USE_THICKNESSMAP
599
-
600
- vThicknessMapUv = ( tileTransform * thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) )).xy;
601
-
602
- #endif
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=`
605
-
606
- #include <common>
607
- #include <color_pars_fragment>
608
- #include <map_pars_fragment>
609
- #include <logdepthbuf_pars_fragment>
610
- #include <clipping_planes_pars_fragment>
611
- #include <alphatest_pars_fragment>
612
-
613
- #include <tile_pars_fragment>
614
- #include <soft_pars_fragment>
615
-
616
- void main() {
617
-
618
- #include <clipping_planes_fragment>
619
-
620
- vec3 outgoingLight = vec3( 0.0 );
621
- vec4 diffuseColor = vColor;
622
-
623
- #include <logdepthbuf_fragment>
624
-
625
- #include <tile_fragment>
626
- #include <alphatest_fragment>
627
-
628
- outgoingLight = diffuseColor.rgb;
629
-
630
- #ifdef USE_COLOR_AS_ALPHA
631
- gl_FragColor = vec4( outgoingLight, diffuseColor.r );
632
- #else
633
- gl_FragColor = vec4( outgoingLight, diffuseColor.a );
634
- #endif
635
-
636
- #include <soft_fragment>
637
- #include <tonemapping_fragment>
638
- }
639
- `,Ln=`
640
- #define STANDARD
641
-
642
- #ifdef PHYSICAL
643
- #define IOR
644
- #define USE_SPECULAR
645
- #endif
646
-
647
- uniform vec3 diffuse;
648
- uniform vec3 emissive;
649
- uniform float roughness;
650
- uniform float metalness;
651
- uniform float opacity;
652
-
653
- #ifdef IOR
654
- uniform float ior;
655
- #endif
656
-
657
- #ifdef USE_SPECULAR
658
- uniform float specularIntensity;
659
- uniform vec3 specularColor;
660
-
661
- #ifdef USE_SPECULAR_COLORMAP
662
- uniform sampler2D specularColorMap;
663
- #endif
664
-
665
- #ifdef USE_SPECULAR_INTENSITYMAP
666
- uniform sampler2D specularIntensityMap;
667
- #endif
668
- #endif
669
-
670
- #ifdef USE_CLEARCOAT
671
- uniform float clearcoat;
672
- uniform float clearcoatRoughness;
673
- #endif
674
-
675
- #ifdef USE_DISPERSION
676
- uniform float dispersion;
677
- #endif
678
-
679
- #ifdef USE_IRIDESCENCE
680
- uniform float iridescence;
681
- uniform float iridescenceIOR;
682
- uniform float iridescenceThicknessMinimum;
683
- uniform float iridescenceThicknessMaximum;
684
- #endif
685
-
686
- #ifdef USE_SHEEN
687
- uniform vec3 sheenColor;
688
- uniform float sheenRoughness;
689
-
690
- #ifdef USE_SHEEN_COLORMAP
691
- uniform sampler2D sheenColorMap;
692
- #endif
693
-
694
- #ifdef USE_SHEEN_ROUGHNESSMAP
695
- uniform sampler2D sheenRoughnessMap;
696
- #endif
697
- #endif
698
-
699
- #ifdef USE_ANISOTROPY
700
- uniform vec2 anisotropyVector;
701
-
702
- #ifdef USE_ANISOTROPYMAP
703
- uniform sampler2D anisotropyMap;
704
- #endif
705
- #endif
706
-
707
- varying vec3 vViewPosition;
708
-
709
- #include <common>
710
- #include <packing>
711
- #include <dithering_pars_fragment>
712
- #include <color_pars_fragment>
713
- #include <uv_pars_fragment>
714
- #include <map_pars_fragment>
715
- #include <alphamap_pars_fragment>
716
- #include <alphatest_pars_fragment>
717
- #include <alphahash_pars_fragment>
718
- #include <aomap_pars_fragment>
719
- #include <lightmap_pars_fragment>
720
- #include <emissivemap_pars_fragment>
721
- #include <iridescence_fragment>
722
- #include <cube_uv_reflection_fragment>
723
- #include <envmap_common_pars_fragment>
724
- #include <envmap_physical_pars_fragment>
725
- #include <fog_pars_fragment>
726
- #include <lights_pars_begin>
727
- #include <normal_pars_fragment>
728
- #include <lights_physical_pars_fragment>
729
- #include <transmission_pars_fragment>
730
- #include <shadowmap_pars_fragment>
731
- #include <bumpmap_pars_fragment>
732
- #include <normalmap_pars_fragment>
733
- #include <clearcoat_pars_fragment>
734
- #include <iridescence_pars_fragment>
735
- #include <roughnessmap_pars_fragment>
736
- #include <metalnessmap_pars_fragment>
737
- #include <logdepthbuf_pars_fragment>
738
- #include <clipping_planes_pars_fragment>
739
-
740
- void main() {
741
-
742
- vec4 diffuseColor = vec4( diffuse, opacity );
743
- #include <clipping_planes_fragment>
744
-
745
- ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
746
- vec3 totalEmissiveRadiance = emissive;
747
-
748
- #include <logdepthbuf_fragment>
749
- #include <map_fragment>
750
- #include <color_fragment>
751
- #include <alphamap_fragment>
752
- #include <alphatest_fragment>
753
- #include <alphahash_fragment>
754
- #include <roughnessmap_fragment>
755
- #include <metalnessmap_fragment>
756
- #include <normal_fragment_begin>
757
- #include <normal_fragment_maps>
758
- #include <clearcoat_normal_fragment_begin>
759
- #include <clearcoat_normal_fragment_maps>
760
- #include <emissivemap_fragment>
761
-
762
- // accumulation
763
- #include <lights_physical_fragment>
764
- #include <lights_fragment_begin>
765
- #include <lights_fragment_maps>
766
- #include <lights_fragment_end>
767
-
768
- // modulation
769
- #include <aomap_fragment>
770
-
771
- vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
772
- vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
773
-
774
- #include <transmission_fragment>
775
-
776
- vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
777
-
778
- #ifdef USE_SHEEN
779
-
780
- // Sheen energy compensation approximation calculation can be found at the end of
781
- // https://drive.google.com/file/d/1T0D1VSyR4AllqIJTQAraEIzjlb5h4FKH/view?usp=sharing
782
- float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );
783
-
784
- outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;
785
-
786
- #endif
787
-
788
- #ifdef USE_CLEARCOAT
789
-
790
- float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
791
-
792
- vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
793
-
794
- outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
795
-
796
- #endif
797
-
798
- #include <opaque_fragment>
799
- #include <tonemapping_fragment>
800
- #include <colorspace_fragment>
801
- #include <fog_fragment>
802
- #include <premultiplied_alpha_fragment>
803
- #include <dithering_fragment>
804
- }`,Hl=`
805
- #include <common>
806
- #include <color_pars_vertex>
807
- #include <logdepthbuf_pars_vertex>
808
- #include <clipping_planes_pars_vertex>
809
-
810
- #include <tile_pars_vertex>
811
- #include <soft_pars_vertex>
812
-
813
- attribute vec3 offset;
814
- attribute float rotation;
815
- attribute vec3 size;
816
-
817
- void main() {
818
-
819
- vec2 alignedPosition = position.xy * size.xy;
820
-
821
- vec2 rotatedPosition;
822
- rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
823
- rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
824
- #ifdef HORIZONTAL
825
- vec4 mvPosition = modelMatrix * vec4( offset, 1.0 );
826
- mvPosition.x += rotatedPosition.x;
827
- mvPosition.z -= rotatedPosition.y;
828
- mvPosition = viewMatrix * mvPosition;
829
- #elif defined(VERTICAL)
830
- vec4 mvPosition = modelMatrix * vec4( offset, 1.0 );
831
- mvPosition.y += rotatedPosition.y;
832
- mvPosition = viewMatrix * mvPosition;
833
- mvPosition.x += rotatedPosition.x;
834
- #else
835
- vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
836
- mvPosition.xy += rotatedPosition;
837
- #endif
838
-
839
- vColor = color;
840
-
841
- gl_Position = projectionMatrix * mvPosition;
842
-
843
- #include <logdepthbuf_vertex>
844
-
845
- #include <clipping_planes_vertex>
846
-
847
- #include <tile_vertex>
848
- #include <soft_vertex>
849
- }
850
- `,Yl=`
851
- #include <common>
852
- #include <color_pars_vertex>
853
- #include <logdepthbuf_pars_vertex>
854
- #include <clipping_planes_pars_vertex>
855
- #include <tile_pars_vertex>
856
- #include <soft_pars_vertex>
857
-
858
- attribute vec3 offset;
859
- attribute vec4 rotation;
860
- attribute vec3 size;
861
- // attribute vec4 color;
862
-
863
- void main() {
864
-
865
- float x2 = rotation.x + rotation.x, y2 = rotation.y + rotation.y, z2 = rotation.z + rotation.z;
866
- float xx = rotation.x * x2, xy = rotation.x * y2, xz = rotation.x * z2;
867
- float yy = rotation.y * y2, yz = rotation.y * z2, zz = rotation.z * z2;
868
- float wx = rotation.w * x2, wy = rotation.w * y2, wz = rotation.w * z2;
869
- float sx = size.x, sy = size.y, sz = size.z;
870
-
871
- mat4 matrix = mat4(( 1.0 - ( yy + zz ) ) * sx, ( xy + wz ) * sx, ( xz - wy ) * sx, 0.0, // 1. column
872
- ( xy - wz ) * sy, ( 1.0 - ( xx + zz ) ) * sy, ( yz + wx ) * sy, 0.0, // 2. column
873
- ( xz + wy ) * sz, ( yz - wx ) * sz, ( 1.0 - ( xx + yy ) ) * sz, 0.0, // 3. column
874
- offset.x, offset.y, offset.z, 1.0);
875
-
876
- vec4 mvPosition = modelViewMatrix * (matrix * vec4( position, 1.0 ));
877
-
878
- vColor = color;
879
-
880
- gl_Position = projectionMatrix * mvPosition;
881
-
882
- #include <logdepthbuf_vertex>
883
- #include <clipping_planes_vertex>
884
- #include <tile_vertex>
885
- #include <soft_vertex>
886
- }
887
- `,Vn=`
888
- #define STANDARD
889
- varying vec3 vViewPosition;
890
- #ifdef USE_TRANSMISSION
891
- varying vec3 vWorldPosition;
892
- #endif
893
- #include <common>
894
-
895
- attribute vec3 offset;
896
- attribute vec4 rotation;
897
- attribute vec3 size;
898
- #include <tile_pars_vertex>
899
- #include <displacementmap_pars_vertex>
900
- #include <color_pars_vertex>
901
- #include <fog_pars_vertex>
902
- #include <normal_pars_vertex>
903
- #include <morphtarget_pars_vertex>
904
- #include <skinning_pars_vertex>
905
- #include <shadowmap_pars_vertex>
906
- #include <logdepthbuf_pars_vertex>
907
- #include <clipping_planes_pars_vertex>
908
-
909
- void main() {
910
-
911
- #include <tile_vertex>
912
- float x2 = rotation.x + rotation.x, y2 = rotation.y + rotation.y, z2 = rotation.z + rotation.z;
913
- float xx = rotation.x * x2, xy = rotation.x * y2, xz = rotation.x * z2;
914
- float yy = rotation.y * y2, yz = rotation.y * z2, zz = rotation.z * z2;
915
- float wx = rotation.w * x2, wy = rotation.w * y2, wz = rotation.w * z2;
916
- float sx = size.x, sy = size.y, sz = size.z;
917
-
918
- mat4 particleMatrix = mat4(( 1.0 - ( yy + zz ) ) * sx, ( xy + wz ) * sx, ( xz - wy ) * sx, 0.0, // 1. column
919
- ( xy - wz ) * sy, ( 1.0 - ( xx + zz ) ) * sy, ( yz + wx ) * sy, 0.0, // 2. column
920
- ( xz + wy ) * sz, ( yz - wx ) * sz, ( 1.0 - ( xx + yy ) ) * sz, 0.0, // 3. column
921
- offset.x, offset.y, offset.z, 1.0);
922
-
923
- #include <color_vertex>
924
- #include <morphinstance_vertex>
925
- #include <morphcolor_vertex>
926
- #include <batching_vertex>
927
-
928
- #include <beginnormal_vertex>
929
- #include <morphnormal_vertex>
930
- #include <skinbase_vertex>
931
- #include <skinnormal_vertex>
932
-
933
- // replace defaultnormal_vertex
934
- vec3 transformedNormal = objectNormal;
935
- mat3 m = mat3( particleMatrix );
936
- transformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );
937
- transformedNormal = m * transformedNormal;
938
- transformedNormal = normalMatrix * transformedNormal;
939
- #ifdef FLIP_SIDED
940
- transformedNormal = - transformedNormal;
941
- #endif
942
- #ifdef USE_TANGENT
943
- vec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;
944
- #ifdef FLIP_SIDED
945
- transformedTangent = - transformedTangent;
946
- #endif
947
- #endif
948
-
949
- #include <normal_vertex>
950
- #include <begin_vertex>
951
- #include <morphtarget_vertex>
952
- #include <skinning_vertex>
953
- #include <displacementmap_vertex>
954
-
955
- // replace include <project_vertex>
956
- vec4 mvPosition = vec4( transformed, 1.0 );
957
- mvPosition = modelViewMatrix * (particleMatrix * mvPosition);
958
- gl_Position = projectionMatrix * mvPosition;
959
-
960
- #include <logdepthbuf_vertex>
961
- #include <clipping_planes_vertex>
962
-
963
- vViewPosition = - mvPosition.xyz;
964
-
965
- #include <worldpos_vertex>
966
- #include <shadowmap_vertex>
967
- #include <fog_vertex>
968
- #ifdef USE_TRANSMISSION
969
- vWorldPosition = worldPosition.xyz;
970
- #endif
971
- }
972
- `,Zl=`
973
- #include <common>
974
- #include <color_pars_vertex>
975
- #include <logdepthbuf_pars_vertex>
976
- #include <clipping_planes_pars_vertex>
977
-
978
- #include <tile_pars_vertex>
979
- #include <soft_pars_vertex>
980
-
981
- attribute vec3 offset;
982
- attribute float rotation;
983
- attribute vec3 size;
984
- attribute vec4 velocity;
985
-
986
- uniform float speedFactor;
987
-
988
- void main() {
989
- float lengthFactor = velocity.w;
990
- float avgSize = (size.x + size.y) * 0.5;
991
- #ifdef USE_SKEW
992
- vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
993
- vec3 viewVelocity = normalMatrix * velocity.xyz;
994
-
995
- vec3 scaledPos = vec3(position.xy * size.xy, position.z);
996
- float vlength = length(viewVelocity);
997
- vec3 projVelocity = dot(scaledPos, viewVelocity) * viewVelocity / vlength;
998
- mvPosition.xyz += scaledPos + projVelocity * (speedFactor / avgSize + lengthFactor / vlength);
999
- #else
1000
- vec4 mvPosition = modelViewMatrix * vec4( offset, 1.0 );
1001
- vec3 viewVelocity = normalMatrix * velocity.xyz;
1002
- float vlength = length(viewVelocity);
1003
- mvPosition.xyz += position.y * normalize(cross(mvPosition.xyz, viewVelocity)) * avgSize; // switch the cross to match unity implementation
1004
- mvPosition.xyz -= (position.x + 0.5) * viewVelocity * (1.0 + lengthFactor / vlength) * avgSize; // minus position.x to match unity implementation
1005
- #endif
1006
- vColor = color;
1007
- gl_Position = projectionMatrix * mvPosition;
1008
- #include <logdepthbuf_vertex>
1009
- #include <clipping_planes_vertex>
1010
- #include <tile_vertex>
1011
- #include <soft_vertex>
1012
- }
1013
- `;function jn(n){return n===0?"uv":`uv${n}`}class Ql extends Va{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=Vn,e.fragmentShader=Ln}}class Kl extends ja{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=Vn,e.fragmentShader=Ln}}class $l extends ca{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 tt,this.rotationMat2_=new tt,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new Ct(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(ge),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new Ct(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(ge),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===A.Mesh?(this.rotationBuffer=new Ct(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(ge),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===A.BillBoard||this.settings.renderMode===A.HorizontalBillBoard||this.settings.renderMode===A.VerticalBillBoard||this.settings.renderMode===A.StretchedBillBoard)&&(this.rotationBuffer=new Ct(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(ge),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new Ct(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(ge),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new Ct(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(ge),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===A.StretchedBillBoard&&(this.velocityBuffer=new Ct(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 La,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 Le(this.settings.material.map)),this.settings.material.alphaTest&&(t.USE_ALPHATEST="",e.alphaTest=new Le(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 Le(new tr(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=jn(this.settings.material.normalMap.channel),e.normalMapTransform=new Le(new tt().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(t.USE_MAP="",this.settings.blendTiles&&(t.TILE_BLEND=""),t.MAP_UV=jn(this.settings.material.map.channel),e.mapTransform=new Le(new tt().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 Le(new tr(o,c)),e.depthTexture=new Le(null);const l=e.projParams=new Le(new Me);s=(h,u,d)=>{l.value.set(d.near,d.far,0,0)}}let a=!1;if(this.settings.renderMode===A.BillBoard||this.settings.renderMode===A.VerticalBillBoard||this.settings.renderMode===A.HorizontalBillBoard||this.settings.renderMode===A.Mesh){let o,c;this.settings.renderMode===A.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(t.USE_COLOR="",o=Vn,c=Ln,a=!0):(o=Yl,c=Fn):(o=Hl,c=Fn),this.settings.renderMode===A.VerticalBillBoard?t.VERTICAL="":this.settings.renderMode===A.HorizontalBillBoard&&(t.HORIZONTAL="");let l=!1;this.settings.renderMode===A.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new Ql({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new Kl({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0)),l||(this.material=new on({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===A.StretchedBillBoard)e.speedFactor=new Le(1),this.material=new on({uniforms:e,defines:t,vertexShader:Zl,fragmentShader:Fn,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===A.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===A.StretchedBillBoard||this.settings.renderMode===A.VerticalBillBoard||this.settings.renderMode===A.HorizontalBillBoard||this.settings.renderMode===A.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===A.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===A.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,e*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===A.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===A.StretchedBillBoard||this.settings.renderMode===A.HorizontalBillBoard||this.settings.renderMode===A.VerticalBillBoard||this.settings.renderMode===A.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var eh=`
1014
-
1015
- #include <common>
1016
- #include <tile_pars_fragment>
1017
- #include <map_pars_fragment>
1018
- #include <fog_pars_fragment>
1019
- #include <logdepthbuf_pars_fragment>
1020
- #include <clipping_planes_pars_fragment>
1021
-
1022
- uniform sampler2D alphaMap;
1023
- uniform float useAlphaMap;
1024
- uniform float visibility;
1025
- uniform float alphaTest;
1026
-
1027
- varying vec4 vColor;
1028
-
1029
- void main() {
1030
- #include <clipping_planes_fragment>
1031
- #include <logdepthbuf_fragment>
1032
-
1033
- vec4 diffuseColor = vColor;
1034
-
1035
- #ifdef USE_MAP
1036
- #include <tile_fragment>
1037
- #ifndef USE_COLOR_AS_ALPHA
1038
- #endif
1039
- #endif
1040
- if( useAlphaMap == 1. ) diffuseColor.a *= texture2D( alphaMap, vUv).a;
1041
- if( diffuseColor.a < alphaTest ) discard;
1042
- gl_FragColor = diffuseColor;
1043
-
1044
- #include <fog_fragment>
1045
- #include <tonemapping_fragment>
1046
- }`,th=`
1047
- #include <common>
1048
- #include <tile_pars_vertex>
1049
- #include <color_pars_vertex>
1050
- #include <clipping_planes_pars_vertex>
1051
- #include <logdepthbuf_pars_vertex>
1052
- #include <fog_pars_vertex>
1053
-
1054
- attribute vec3 previous;
1055
- attribute vec3 next;
1056
- attribute float side;
1057
- attribute float width;
1058
-
1059
- uniform vec2 resolution;
1060
- uniform float lineWidth;
1061
- uniform float sizeAttenuation;
1062
-
1063
- vec2 fix(vec4 i, float aspect) {
1064
- vec2 res = i.xy / i.w;
1065
- res.x *= aspect;
1066
- return res;
1067
- }
1068
-
1069
- void main() {
1070
-
1071
- #include <tile_vertex>
1072
-
1073
- float aspect = resolution.x / resolution.y;
1074
-
1075
- vColor = color;
1076
-
1077
- mat4 m = projectionMatrix * modelViewMatrix;
1078
- vec4 finalPosition = m * vec4( position, 1.0 );
1079
- vec4 prevPos = m * vec4( previous, 1.0 );
1080
- vec4 nextPos = m * vec4( next, 1.0 );
1081
-
1082
- vec2 currentP = fix( finalPosition, aspect );
1083
- vec2 prevP = fix( prevPos, aspect );
1084
- vec2 nextP = fix( nextPos, aspect );
1085
-
1086
- float w = lineWidth * width;
1087
-
1088
- vec2 dir;
1089
- if( nextP == currentP ) dir = normalize( currentP - prevP );
1090
- else if( prevP == currentP ) dir = normalize( nextP - currentP );
1091
- else {
1092
- vec2 dir1 = normalize( currentP - prevP );
1093
- vec2 dir2 = normalize( nextP - currentP );
1094
- dir = normalize( dir1 + dir2 );
1095
-
1096
- vec2 perp = vec2( -dir1.y, dir1.x );
1097
- vec2 miter = vec2( -dir.y, dir.x );
1098
- //w = clamp( w / dot( miter, perp ), 0., 4., * lineWidth * width );
1099
-
1100
- }
1101
-
1102
- //vec2 normal = ( cross( vec3( dir, 0. ) vec3( 0., 0., 1. ) ) ).xy;
1103
- vec4 normal = vec4( -dir.y, dir.x, 0., 1. );
1104
- normal.xy *= .5 * w;
1105
- normal *= projectionMatrix;
1106
- if( sizeAttenuation == 0. ) {
1107
- normal.xy *= finalPosition.w;
1108
- normal.xy /= ( vec4( resolution, 0., 1. ) * projectionMatrix ).xy;
1109
- }
1110
-
1111
- finalPosition.xy += normal.xy * side;
1112
-
1113
- gl_Position = finalPosition;
1114
-
1115
- #include <logdepthbuf_vertex>
1116
- #include <clipping_planes_vertex>
1117
-
1118
- vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
1119
-
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=6*4+4+4,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};