@needle-tools/engine 4.10.0-beta.5 → 4.10.0-beta.9

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 (35) hide show
  1. package/CHANGELOG.md +6 -1
  2. package/README.md +2 -1
  3. package/dist/{needle-engine.bundle-DcvMQ1Nq.js → needle-engine.bundle-B_wUQWD9.js} +19 -18
  4. package/dist/{needle-engine.bundle-DzVytSSo.umd.cjs → needle-engine.bundle-CrO5PE4u.umd.cjs} +11 -11
  5. package/dist/{needle-engine.bundle-BGVvfSfQ.min.js → needle-engine.bundle-DjiUOI9O.min.js} +11 -11
  6. package/dist/needle-engine.js +331 -332
  7. package/dist/needle-engine.min.js +1 -1
  8. package/dist/needle-engine.umd.cjs +1 -1
  9. package/dist/vendor-CPuBPspY.umd.cjs +1121 -0
  10. package/dist/vendor-DPCU8cUF.min.js +1121 -0
  11. package/dist/vendor-MBoqSyFm.js +16240 -0
  12. package/lib/engine/codegen/register_types.js +1 -1
  13. package/lib/engine/codegen/register_types.js.map +1 -1
  14. package/lib/engine/engine_license.js +1 -1
  15. package/lib/engine/engine_license.js.map +1 -1
  16. package/lib/engine-components/codegen/components.d.ts +1 -1
  17. package/lib/engine-components/codegen/components.js +1 -1
  18. package/lib/engine-components/codegen/components.js.map +1 -1
  19. package/lib/engine-components/timeline/TimelineTracks.js +2 -4
  20. package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
  21. package/lib/engine-components/web/ScrollFollow.d.ts +1 -0
  22. package/lib/engine-components/web/ScrollFollow.js +2 -0
  23. package/lib/engine-components/web/ScrollFollow.js.map +1 -1
  24. package/lib/engine-components/web/ViewBox.js +1 -1
  25. package/lib/engine-components/web/ViewBox.js.map +1 -1
  26. package/package.json +2 -1
  27. package/src/engine/codegen/register_types.ts +1 -1
  28. package/src/engine/engine_license.ts +1 -1
  29. package/src/engine-components/codegen/components.ts +1 -1
  30. package/src/engine-components/timeline/TimelineTracks.ts +2 -4
  31. package/src/engine-components/web/ScrollFollow.ts +3 -2
  32. package/src/engine-components/web/ViewBox.ts +1 -1
  33. package/dist/vendor-D0Yvltn9.umd.cjs +0 -1121
  34. package/dist/vendor-DU8tJyl_.js +0 -14366
  35. package/dist/vendor-JyrX4DVM.min.js +0 -1121
@@ -1,1121 +0,0 @@
1
- "use strict";const M=require("./three-B-jwTHao.umd.cjs"),se={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 po(n){const e=await fetch(n);if(e.ok)return e.json();throw new Error(e.statusText)}async function xa(n){return await po(`${n}/profilesList.json`)}async function ba(n,e,t=null,i=!0){if(!n)throw new Error("No xrInputSource supplied");const r=await xa(e);let s;if(n.profiles.some(c=>{const l=r[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=r[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 po(s.profilePath);let o;if(i){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 Sa={xAxis:0,yAxis:0,button:0,state:se.ComponentState.DEFAULT};function Ta(n=0,e=0){let t=n,i=e;if(Math.sqrt(n*n+e*e)>1){const a=Math.atan2(e,n);t=Math.cos(a),i=Math.sin(a)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:i*.5+.5}}class Ma{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===se.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(Sa)}updateFromComponent({xAxis:e,yAxis:t,button:i,state:r}){const{normalizedXAxis:s,normalizedYAxis:a}=Ta(e,t);switch(this.componentProperty){case se.ComponentProperty.X_AXIS:this.value=this.states.includes(r)?s:.5;break;case se.ComponentProperty.Y_AXIS:this.value=this.states.includes(r)?a:.5;break;case se.ComponentProperty.BUTTON:this.value=this.states.includes(r)?i:0;break;case se.ComponentProperty.STATE:this.valueNodeProperty===se.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(r):this.value=this.states.includes(r)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class Ca{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(i=>{const r=new Ma(t.visualResponses[i]);this.visualResponses[i]=r}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:se.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=se.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=se.ComponentState.PRESSED:(t.touched||this.values.button>se.ButtonTouchThreshold)&&(this.values.state=se.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===se.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>se.AxisTouchThreshold&&(this.values.state=se.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===se.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>se.AxisTouchThreshold&&(this.values.state=se.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class Pa{constructor(e,t,i){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=i,this.id=t.profileId,this.layoutDescription=t.layouts[e.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(r=>{const s=this.layoutDescription.components[r];this.components[r]=new Ca(r,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 Wr=2,Xe=4,at=4,mo=4,pt=new Int32Array(2),cs=new Float32Array(pt.buffer),ls=new Float64Array(pt.buffer),ir=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;class lt{constructor(e,t){this.low=e|0,this.high=t|0}static create(e,t){return e==0&&t==0?lt.ZERO:new lt(e,t)}toFloat64(){return(this.low>>>0)+this.high*4294967296}equals(e){return this.low==e.low&&this.high==e.high}}lt.ZERO=new lt(0,0);var En;(function(n){n[n.UTF8_BYTES=1]="UTF8_BYTES",n[n.UTF16_STRING=2]="UTF16_STRING"})(En||(En={}));class _i{constructor(e){this.bytes_=e,this.position_=0}static allocate(e){return new _i(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 lt(this.readInt32(e),this.readInt32(e+4))}readUint64(e){return new lt(this.readUint32(e),this.readUint32(e+4))}readFloat32(e){return pt[0]=this.readInt32(e),cs[0]}readFloat64(e){return pt[ir?0:1]=this.readInt32(e),pt[ir?1:0]=this.readInt32(e+4),ls[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,pt[0])}writeFloat64(e,t){ls[0]=t,this.writeInt32(e,pt[ir?0:1]),this.writeInt32(e+4,pt[ir?1:0])}getBufferIdentifier(){if(this.bytes_.length<this.position_+Xe+at)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");let e="";for(let t=0;t<at;t++)e+=String.fromCharCode(this.readInt8(this.position_+Xe+t));return e}__offset(e,t){const i=e-this.readInt32(e);return t<this.readInt16(i)?this.readInt16(i+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 i=this.readInt32(e);let r="",s=0;if(e+=Xe,t===En.UTF8_BYTES)return this.bytes_.subarray(e,e+i);for(;s<i;){let a;const o=this.readUint8(e+s++);if(o<192)a=o;else{const c=this.readUint8(e+s++);if(o<224)a=(o&31)<<6|c&63;else{const l=this.readUint8(e+s++);if(o<240)a=(o&15)<<12|(c&63)<<6|l&63;else{const u=this.readUint8(e+s++);a=(o&7)<<18|(c&63)<<12|(l&63)<<6|u&63}}}a<65536?r+=String.fromCharCode(a):(a-=65536,r+=String.fromCharCode((a>>10)+55296,(a&1023)+56320))}return r}__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)+Xe}__vector_len(e){return this.readInt32(e+this.readInt32(e))}__has_identifier(e){if(e.length!=at)throw new Error("FlatBuffers: file identifier must be length "+at);for(let t=0;t<at;t++)if(e.charCodeAt(t)!=this.readInt8(this.position()+Xe+t))return!1;return!0}createLong(e,t){return lt.create(e,t)}createScalarList(e,t){const i=[];for(let r=0;r<t;++r)e(r)!==null&&i.push(e(r));return i}createObjList(e,t){const i=[];for(let r=0;r<t;++r){const s=e(r);s!==null&&i.push(s.unpack())}return i}}class Yn{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=_i.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 i=~(this.bb.capacity()-this.space+t)+1&e-1;for(;this.space<i+e+t;){const r=this.bb.capacity();this.bb=Yn.growByteBuffer(this.bb),this.space+=this.bb.capacity()-r}this.pad(i)}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,i){(this.force_defaults||t!=i)&&(this.addInt8(t),this.slot(e))}addFieldInt16(e,t,i){(this.force_defaults||t!=i)&&(this.addInt16(t),this.slot(e))}addFieldInt32(e,t,i){(this.force_defaults||t!=i)&&(this.addInt32(t),this.slot(e))}addFieldInt64(e,t,i){(this.force_defaults||!t.equals(i))&&(this.addInt64(t),this.slot(e))}addFieldFloat32(e,t,i){(this.force_defaults||t!=i)&&(this.addFloat32(t),this.slot(e))}addFieldFloat64(e,t,i){(this.force_defaults||t!=i)&&(this.addFloat64(t),this.slot(e))}addFieldOffset(e,t,i){(this.force_defaults||t!=i)&&(this.addOffset(t),this.slot(e))}addFieldStruct(e,t,i){t!=i&&(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 i=t<<1,r=_i.allocate(i);return r.setPosition(i-t),r.bytes().set(e.bytes(),i-t),r}addOffset(e){this.prep(Xe,0),this.writeInt32(this.offset()-e+Xe)}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 i=t+1;for(;t>=0;t--)this.addInt16(this.vtable[t]!=0?e-this.vtable[t]:0);const r=2;this.addInt16(e-this.object_start);const s=(i+r)*Wr;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=Wr;l<s;l+=Wr)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,i){const r=i?mo:0;if(t){const s=t;if(this.prep(this.minalign,Xe+at+r),s.length!=at)throw new Error("FlatBuffers: file identifier must be length "+at);for(let a=at-1;a>=0;a--)this.writeInt8(s.charCodeAt(a))}this.prep(this.minalign,Xe+r),this.addOffset(e),r&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(e,t){this.finish(e,t,!0)}requiredField(e,t){const i=this.bb.capacity()-e,r=i-this.bb.readInt32(i);if(!(this.bb.readInt16(r+t)!=0))throw new Error("FlatBuffers: field "+t+" must be set")}startVector(e,t,i){this.notNested(),this.vector_num_elems=t,this.prep(Xe,e*t),this.prep(i,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 i=0;for(;i<e.length;){let r;const s=e.charCodeAt(i++);if(s<55296||s>=56320)r=s;else{const a=e.charCodeAt(i++);r=(s<<10)+a+-56613888}r<128?t.push(r):(r<2048?t.push(r>>6&31|192):(r<65536?t.push(r>>12&15|224):t.push(r>>18&7|240,r>>12&63|128),t.push(r>>6&63|128)),t.push(r&63|128))}}this.addInt8(0),this.startVector(1,t.length,1),this.bb.setPosition(this.space-=t.length);for(let i=0,r=this.space,s=this.bb.bytes();i<t.length;i++)s[r++]=t[i];return this.endVector()}createLong(e,t){return lt.create(e,t)}createObjectOffset(e){return e===null?0:typeof e=="string"?this.createString(e):e.pack(this)}createObjectOffsetList(e){const t=[];for(let i=0;i<e.length;++i){const r=e[i];if(r!==null)t.push(this.createObjectOffset(r));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 Gr(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var Yr={exports:{}},us;function hs(){return us||(us=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 i(){this._pieces=[],this._parts=[]}i.prototype.append=function(r){typeof r=="number"?this._pieces.push(r):(this.flush(),this._parts.push(r))},i.prototype.flush=function(){if(this._pieces.length>0){var r=new Uint8Array(this._pieces);e.useArrayBufferView||(r=r.buffer),this._parts.push(r),this._pieces=[]}},i.prototype.getBuffer=function(){if(this.flush(),e.useBlobBuilder){for(var r=new t,s=0,a=this._parts.length;s<a;s++)r.append(this._parts[s]);return r.getBlob()}else return new Blob(this._parts)},n.exports.BufferBuilder=i})(Yr)),Yr.exports}var Zr,fs;function wa(){if(fs)return Zr;fs=1;var n=hs().BufferBuilder,e=hs().binaryFeatures,t={unpack:function(o){var c=new i(o);return c.unpack()},pack:function(o){var c=new r;c.pack(o);var l=c.getBuffer();return l}};Zr=t;function i(o){this.index=0,this.dataBuffer=o,this.dataView=new Uint8Array(this.dataBuffer),this.length=this.dataBuffer.byteLength}i.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)}},i.prototype.unpack_uint8=function(){var o=this.dataView[this.index]&255;return this.index++,o},i.prototype.unpack_uint16=function(){var o=this.read(2),c=(o[0]&255)*256+(o[1]&255);return this.index+=2,c},i.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},i.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},i.prototype.unpack_int8=function(){var o=this.unpack_uint8();return o<128?o:o-256},i.prototype.unpack_int16=function(){var o=this.unpack_uint16();return o<32768?o:o-65536},i.prototype.unpack_int32=function(){var o=this.unpack_uint32();return o<Math.pow(2,31)?o:o-Math.pow(2,32)},i.prototype.unpack_int64=function(){var o=this.unpack_uint64();return o<Math.pow(2,63)?o:o-Math.pow(2,64)},i.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},i.prototype.unpack_string=function(o){for(var c=this.read(o),l=0,u="",h,f;l<o;)h=c[l],h<128?(u+=String.fromCharCode(h),l++):(h^192)<32?(f=(h^192)<<6|c[l+1]&63,u+=String.fromCharCode(f),l+=2):(f=(h&15)<<12|(c[l+1]&63)<<6|c[l+2]&63,u+=String.fromCharCode(f),l+=3);return this.index+=o,u},i.prototype.unpack_array=function(o){for(var c=new Array(o),l=0;l<o;l++)c[l]=this.unpack();return c},i.prototype.unpack_map=function(o){for(var c={},l=0;l<o;l++){var u=this.unpack(),h=this.unpack();c[u]=h}return c},i.prototype.unpack_float=function(){var o=this.unpack_uint32(),c=o>>31,l=(o>>23&255)-127,u=o&8388607|8388608;return(c===0?1:-1)*u*Math.pow(2,l-23)},i.prototype.unpack_double=function(){var o=this.unpack_uint32(),c=this.unpack_uint32(),l=o>>31,u=(o>>20&2047)-1023,h=o&1048575|1048576,f=h*Math.pow(2,u-20)+c*Math.pow(2,u-52);return(l===0?1:-1)*f},i.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 r(){this.bufferBuilder=new n}r.prototype.getBuffer=function(){return this.bufferBuilder.getBuffer()},r.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()},r.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)},r.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)},r.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])},r.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")},r.prototype.pack_double=function(o){var c=0;o<0&&(c=1,o=-o);var l=Math.floor(Math.log(o)/Math.LN2),u=o/Math.pow(2,l)-1,h=Math.floor(u*Math.pow(2,52)),f=Math.pow(2,32),d=c<<31|l+1023<<20|h/f&1048575,y=h%f;this.bufferBuilder.append(203),this.pack_int32(d),this.pack_int32(y)},r.prototype.pack_object=function(o){var c=Object.keys(o),l=c.length;if(l<=15)this.pack_uint8(128+l);else if(l<=65535)this.bufferBuilder.append(222),this.pack_uint16(l);else if(l<=4294967295)this.bufferBuilder.append(223),this.pack_uint32(l);else throw new Error("Invalid length");for(var u in o)o.hasOwnProperty(u)&&(this.pack(u),this.pack(o[u]))},r.prototype.pack_uint8=function(o){this.bufferBuilder.append(o)},r.prototype.pack_uint16=function(o){this.bufferBuilder.append(o>>8),this.bufferBuilder.append(o&255)},r.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)},r.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)},r.prototype.pack_int8=function(o){this.bufferBuilder.append(o&255)},r.prototype.pack_int16=function(o){this.bufferBuilder.append((o&65280)>>8),this.bufferBuilder.append(o&255)},r.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)},r.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 Zr}var Ea=wa();const ds=Gr(Ea);let yo=!0,go=!0;function hi(n,e,t){const i=n.match(e);return i&&i.length>=t&&parseInt(i[t],10)}function Xt(n,e,t){if(!n.RTCPeerConnection)return;const i=n.RTCPeerConnection.prototype,r=i.addEventListener;i.addEventListener=function(a,o){if(a!==e)return r.apply(this,arguments);const c=l=>{const u=t(l);u&&(o.handleEvent?o.handleEvent(u):o(u))};return this._eventMap=this._eventMap||{},this._eventMap[e]||(this._eventMap[e]=new Map),this._eventMap[e].set(o,c),r.apply(this,[a,c])};const s=i.removeEventListener;i.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(i,"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 Ra(n){return typeof n!="boolean"?new Error("Argument type: "+typeof n+". Please use a boolean."):(yo=n,n?"adapter.js logging disabled":"adapter.js logging enabled")}function ka(n){return typeof n!="boolean"?new Error("Argument type: "+typeof n+". Please use a boolean."):(go=!n,"adapter.js deprecation warnings "+(n?"disabled":"enabled"))}function Zn(){if(typeof window=="object"){if(yo)return;typeof console<"u"&&typeof console.log=="function"&&console.log.apply(console,arguments)}}function jr(n,e){go&&console.warn(n+" is deprecated, please use "+e+" instead.")}function Aa(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=hi(t.userAgent,/Firefox\/(\d+)\./,1);else if(t.webkitGetUserMedia||n.isSecureContext===!1&&n.webkitRTCPeerConnection&&!n.RTCIceGatherer)e.browser="chrome",e.version=hi(t.userAgent,/Chrom(e|ium)\/(\d+)\./,2);else if(t.mediaDevices&&t.userAgent.match(/Edge\/(\d+).(\d+)$/))e.browser="edge",e.version=hi(t.userAgent,/Edge\/(\d+).(\d+)$/,2);else if(n.RTCPeerConnection&&t.userAgent.match(/AppleWebKit\/(\d+)\./))e.browser="safari",e.version=hi(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 ps(n){return Object.prototype.toString.call(n)==="[object Object]"}function vo(n){return ps(n)?Object.keys(n).reduce(function(e,t){const i=ps(n[t]),r=i?vo(n[t]):n[t],s=i&&!Object.keys(r).length;return r===void 0||s?e:Object.assign(e,{[t]:r})},{}):n}function Rn(n,e,t){!e||t.has(e.id)||(t.set(e.id,e),Object.keys(e).forEach(i=>{i.endsWith("Id")?Rn(n,n.get(e[i]),t):i.endsWith("Ids")&&e[i].forEach(r=>{Rn(n,n.get(r),t)})}))}function ms(n,e,t){const i=t?"outbound-rtp":"inbound-rtp",r=new Map;if(e===null)return r;const s=[];return n.forEach(a=>{a.type==="track"&&a.trackIdentifier===e.id&&s.push(a)}),s.forEach(a=>{n.forEach(o=>{o.type===i&&o.trackId===a.id&&Rn(n,o,r)})}),r}const ys=Zn;function _o(n,e){const t=n&&n.navigator;if(!t.mediaDevices)return;const i=function(o){if(typeof o!="object"||o.mandatory||o.optional)return o;const c={};return Object.keys(o).forEach(l=>{if(l==="require"||l==="advanced"||l==="mediaSource")return;const u=typeof o[l]=="object"?o[l]:{ideal:o[l]};u.exact!==void 0&&typeof u.exact=="number"&&(u.min=u.max=u.exact);const h=function(f,d){return f?f+d.charAt(0).toUpperCase()+d.slice(1):d==="deviceId"?"sourceId":d};if(u.ideal!==void 0){c.optional=c.optional||[];let f={};typeof u.ideal=="number"?(f[h("min",l)]=u.ideal,c.optional.push(f),f={},f[h("max",l)]=u.ideal,c.optional.push(f)):(f[h("",l)]=u.ideal,c.optional.push(f))}u.exact!==void 0&&typeof u.exact!="number"?(c.mandatory=c.mandatory||{},c.mandatory[h("",l)]=u.exact):["min","max"].forEach(f=>{u[f]!==void 0&&(c.mandatory=c.mandatory||{},c.mandatory[h(f,l)]=u[f])})}),o.advanced&&(c.optional=(c.optional||[]).concat(o.advanced)),c},r=function(o,c){if(e.version>=61)return c(o);if(o=JSON.parse(JSON.stringify(o)),o&&typeof o.audio=="object"){const l=function(u,h,f){h in u&&!(f in u)&&(u[f]=u[h],delete u[h])};o=JSON.parse(JSON.stringify(o)),l(o.audio,"autoGainControl","googAutoGainControl"),l(o.audio,"noiseSuppression","googNoiseSuppression"),o.audio=i(o.audio)}if(o&&typeof o.video=="object"){let l=o.video.facingMode;l=l&&(typeof l=="object"?l:{ideal:l});const u=e.version<66;if(l&&(l.exact==="user"||l.exact==="environment"||l.ideal==="user"||l.ideal==="environment")&&!(t.mediaDevices.getSupportedConstraints&&t.mediaDevices.getSupportedConstraints().facingMode&&!u)){delete o.video.facingMode;let h;if(l.exact==="environment"||l.ideal==="environment"?h=["back","rear"]:(l.exact==="user"||l.ideal==="user")&&(h=["front"]),h)return t.mediaDevices.enumerateDevices().then(f=>{f=f.filter(y=>y.kind==="videoinput");let d=f.find(y=>h.some(_=>y.label.toLowerCase().includes(_)));return!d&&f.length&&h.includes("back")&&(d=f[f.length-1]),d&&(o.video.deviceId=l.exact?{exact:d.deviceId}:{ideal:d.deviceId}),o.video=i(o.video),ys("chrome: "+JSON.stringify(o)),c(o)})}o.video=i(o.video)}return ys("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){r(o,u=>{t.webkitGetUserMedia(u,c,h=>{l&&l(s(h))})})};if(t.getUserMedia=a.bind(t),t.mediaDevices.getUserMedia){const o=t.mediaDevices.getUserMedia.bind(t.mediaDevices);Object.getOwnPropertyDescriptor(t.mediaDevices,"getUserMedia")?.writable&&(t.mediaDevices.getUserMedia=function(c){return r(c,l=>o(l).then(u=>{if(l.audio&&!u.getAudioTracks().length||l.video&&!u.getVideoTracks().length)throw u.getTracks().forEach(h=>{h.stop()}),new DOMException("","NotFoundError");return u},u=>Promise.reject(s(u))))})}}function za(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(i){return e(i).then(r=>{const s=i.video&&i.video.width,a=i.video&&i.video.height,o=i.video&&i.video.frameRate;return i.video={mandatory:{chromeMediaSource:"desktop",chromeMediaSourceId:r,maxFrameRate:o||3}},s&&(i.video.mandatory.maxWidth=s),a&&(i.video.mandatory.maxHeight=a),n.navigator.mediaDevices.getUserMedia(i)})}}}function xo(n){n.MediaStream=n.MediaStream||n.webkitMediaStream}function bo(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=i=>{i.stream.addEventListener("addtrack",r=>{let s;n.RTCPeerConnection.prototype.getReceivers?s=this.getReceivers().find(o=>o.track&&o.track.id===r.track.id):s={track:r.track};const a=new Event("track");a.track=r.track,a.receiver=s,a.transceiver={receiver:s},a.streams=[i.stream],this.dispatchEvent(a)}),i.stream.getTracks().forEach(r=>{let s;n.RTCPeerConnection.prototype.getReceivers?s=this.getReceivers().find(o=>o.track&&o.track.id===r.id):s={track:r};const a=new Event("track");a.track=r,a.receiver=s,a.transceiver={receiver:s},a.streams=[i.stream],this.dispatchEvent(a)})},this.addEventListener("addstream",this._ontrackpoly)),e.apply(this,arguments)}}else Xt(n,"track",e=>(e.transceiver||Object.defineProperty(e,"transceiver",{value:{receiver:e.receiver}}),e))}function So(n){if(typeof n=="object"&&n.RTCPeerConnection&&!("getSenders"in n.RTCPeerConnection.prototype)&&"createDTMFSender"in n.RTCPeerConnection.prototype){const e=function(r,s){return{track:s,get dtmf(){return this._dtmf===void 0&&(s.kind==="audio"?this._dtmf=r.createDTMFSender(s):this._dtmf=null),this._dtmf},_pc:r}};if(!n.RTCPeerConnection.prototype.getSenders){n.RTCPeerConnection.prototype.getSenders=function(){return this._senders=this._senders||[],this._senders.slice()};const r=n.RTCPeerConnection.prototype.addTrack;n.RTCPeerConnection.prototype.addTrack=function(o,c){let l=r.apply(this,arguments);return l||(l=e(this,o),this._senders.push(l)),l};const s=n.RTCPeerConnection.prototype.removeTrack;n.RTCPeerConnection.prototype.removeTrack=function(o){s.apply(this,arguments);const c=this._senders.indexOf(o);c!==-1&&this._senders.splice(c,1)}}const t=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(s){this._senders=this._senders||[],t.apply(this,[s]),s.getTracks().forEach(a=>{this._senders.push(e(this,a))})};const i=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(s){this._senders=this._senders||[],i.apply(this,[s]),s.getTracks().forEach(a=>{const o=this._senders.find(c=>c.track===a);o&&this._senders.splice(this._senders.indexOf(o),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 i=e.apply(this,[]);return i.forEach(r=>r._pc=this),i},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 To(n){if(!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){const[i,r,s]=arguments;if(arguments.length>0&&typeof i=="function")return e.apply(this,arguments);if(e.length===0&&(arguments.length===0||typeof i!="function"))return e.apply(this,[]);const a=function(c){const l={};return c.result().forEach(h=>{const f={id:h.id,timestamp:h.timestamp,type:{localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[h.type]||h.type};h.names().forEach(d=>{f[d]=h.stat(d)}),l[f.id]=f}),l},o=function(c){return new Map(Object.keys(c).map(l=>[l,c[l]]))};if(arguments.length>=2){const c=function(l){r(o(a(l)))};return e.apply(this,[c,i])}return new Promise((c,l)=>{e.apply(this,[function(u){c(o(a(u)))},l])}).then(r,s)}}function Mo(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 s=t.apply(this,[]);return s.forEach(a=>a._pc=this),s});const i=n.RTCPeerConnection.prototype.addTrack;i&&(n.RTCPeerConnection.prototype.addTrack=function(){const s=i.apply(this,arguments);return s._pc=this,s}),n.RTCRtpSender.prototype.getStats=function(){const s=this;return this._pc.getStats().then(a=>ms(a,s.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(s=>s._pc=this),r}),Xt(n,"track",i=>(i.receiver._pc=i.srcElement,i)),n.RTCRtpReceiver.prototype.getStats=function(){const r=this;return this._pc.getStats().then(s=>ms(s,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 i=arguments[0];let r,s,a;return this.getSenders().forEach(o=>{o.track===i&&(r?a=!0:r=o)}),this.getReceivers().forEach(o=>(o.track===i&&(s?a=!0:s=o),o.track===i)),a||r&&s?Promise.reject(new DOMException("There are more than one sender or receiver for the track.","InvalidAccessError")):r?r.getStats():s?s.getStats():Promise.reject(new DOMException("There is no sender or receiver for the track.","InvalidAccessError"))}return e.apply(this,arguments)}}function Co(n){n.RTCPeerConnection.prototype.getLocalStreams=function(){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},Object.keys(this._shimmedLocalStreams).map(a=>this._shimmedLocalStreams[a][0])};const e=n.RTCPeerConnection.prototype.addTrack;n.RTCPeerConnection.prototype.addTrack=function(a,o){if(!o)return e.apply(this,arguments);this._shimmedLocalStreams=this._shimmedLocalStreams||{};const c=e.apply(this,arguments);return this._shimmedLocalStreams[o.id]?this._shimmedLocalStreams[o.id].indexOf(c)===-1&&this._shimmedLocalStreams[o.id].push(c):this._shimmedLocalStreams[o.id]=[o,c],c};const t=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(a){this._shimmedLocalStreams=this._shimmedLocalStreams||{},a.getTracks().forEach(l=>{if(this.getSenders().find(h=>h.track===l))throw new DOMException("Track already exists.","InvalidAccessError")});const o=this.getSenders();t.apply(this,arguments);const c=this.getSenders().filter(l=>o.indexOf(l)===-1);this._shimmedLocalStreams[a.id]=[a].concat(c)};const i=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(a){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},delete this._shimmedLocalStreams[a.id],i.apply(this,arguments)};const r=n.RTCPeerConnection.prototype.removeTrack;n.RTCPeerConnection.prototype.removeTrack=function(a){return this._shimmedLocalStreams=this._shimmedLocalStreams||{},a&&Object.keys(this._shimmedLocalStreams).forEach(o=>{const c=this._shimmedLocalStreams[o].indexOf(a);c!==-1&&this._shimmedLocalStreams[o].splice(c,1),this._shimmedLocalStreams[o].length===1&&delete this._shimmedLocalStreams[o]}),r.apply(this,arguments)}}function Po(n,e){if(!n.RTCPeerConnection)return;if(n.RTCPeerConnection.prototype.addTrack&&e.version>=65)return Co(n);const t=n.RTCPeerConnection.prototype.getLocalStreams;n.RTCPeerConnection.prototype.getLocalStreams=function(){const u=t.apply(this);return this._reverseStreams=this._reverseStreams||{},u.map(h=>this._reverseStreams[h.id])};const i=n.RTCPeerConnection.prototype.addStream;n.RTCPeerConnection.prototype.addStream=function(u){if(this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},u.getTracks().forEach(h=>{if(this.getSenders().find(d=>d.track===h))throw new DOMException("Track already exists.","InvalidAccessError")}),!this._reverseStreams[u.id]){const h=new n.MediaStream(u.getTracks());this._streams[u.id]=h,this._reverseStreams[h.id]=u,u=h}i.apply(this,[u])};const r=n.RTCPeerConnection.prototype.removeStream;n.RTCPeerConnection.prototype.removeStream=function(u){this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{},r.apply(this,[this._streams[u.id]||u]),delete this._reverseStreams[this._streams[u.id]?this._streams[u.id].id:u.id],delete this._streams[u.id]},n.RTCPeerConnection.prototype.addTrack=function(u,h){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");const f=[].slice.call(arguments,1);if(f.length!==1||!f[0].getTracks().find(_=>_===u))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(_=>_.track===u))throw new DOMException("Track already exists.","InvalidAccessError");this._streams=this._streams||{},this._reverseStreams=this._reverseStreams||{};const y=this._streams[h.id];if(y)y.addTrack(u),Promise.resolve().then(()=>{this.dispatchEvent(new Event("negotiationneeded"))});else{const _=new n.MediaStream([u]);this._streams[h.id]=_,this._reverseStreams[_.id]=h,this.addStream(_)}return this.getSenders().find(_=>_.track===u)};function s(l,u){let h=u.sdp;return Object.keys(l._reverseStreams||[]).forEach(f=>{const d=l._reverseStreams[f],y=l._streams[d.id];h=h.replace(new RegExp(y.id,"g"),d.id)}),new RTCSessionDescription({type:u.type,sdp:h})}function a(l,u){let h=u.sdp;return Object.keys(l._reverseStreams||[]).forEach(f=>{const d=l._reverseStreams[f],y=l._streams[d.id];h=h.replace(new RegExp(d.id,"g"),y.id)}),new RTCSessionDescription({type:u.type,sdp:h})}["createOffer","createAnswer"].forEach(function(l){const u=n.RTCPeerConnection.prototype[l],h={[l](){const f=arguments;return arguments.length&&typeof arguments[0]=="function"?u.apply(this,[y=>{const _=s(this,y);f[0].apply(null,[_])},y=>{f[1]&&f[1].apply(null,y)},arguments[2]]):u.apply(this,arguments).then(y=>s(this,y))}};n.RTCPeerConnection.prototype[l]=h[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(u){if(this.signalingState==="closed")throw new DOMException("The RTCPeerConnection's signalingState is 'closed'.","InvalidStateError");if(!u._pc)throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.","TypeError");if(!(u._pc===this))throw new DOMException("Sender was not created by this connection.","InvalidAccessError");this._streams=this._streams||{};let f;Object.keys(this._streams).forEach(d=>{this._streams[d].getTracks().find(_=>u.track===_)&&(f=this._streams[d])}),f&&(f.getTracks().length===1?this.removeStream(this._reverseStreams[f.id]):f.removeTrack(u.track),this.dispatchEvent(new Event("negotiationneeded")))}}function kn(n,e){!n.RTCPeerConnection&&n.webkitRTCPeerConnection&&(n.RTCPeerConnection=n.webkitRTCPeerConnection),n.RTCPeerConnection&&e.version<53&&["setLocalDescription","setRemoteDescription","addIceCandidate"].forEach(function(t){const i=n.RTCPeerConnection.prototype[t],r={[t](){return arguments[0]=new(t==="addIceCandidate"?n.RTCIceCandidate:n.RTCSessionDescription)(arguments[0]),i.apply(this,arguments)}};n.RTCPeerConnection.prototype[t]=r[t]})}function wo(n,e){Xt(n,"negotiationneeded",t=>{const i=t.target;if(!((e.version<72||i.getConfiguration&&i.getConfiguration().sdpSemantics==="plan-b")&&i.signalingState!=="stable"))return t})}const gs=Object.freeze(Object.defineProperty({__proto__:null,fixNegotiationNeeded:wo,shimAddTrackRemoveTrack:Po,shimAddTrackRemoveTrackWithNative:Co,shimGetDisplayMedia:za,shimGetSendersWithDtmf:So,shimGetStats:To,shimGetUserMedia:_o,shimMediaStream:xo,shimOnTrack:bo,shimPeerConnection:kn,shimSenderReceiverGetStats:Mo},Symbol.toStringTag,{value:"Module"}));function Oa(n,e){let t=!1;return n=JSON.parse(JSON.stringify(n)),n.filter(i=>{if(i&&(i.urls||i.url)){let r=i.urls||i.url;i.url&&!i.urls&&jr("RTCIceServer.url","RTCIceServer.urls");const s=typeof r=="string";return s&&(r=[r]),r=r.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 i.url,i.urls=s?r[0]:r,!!r.length}})}var Kr={exports:{}},vs;function Eo(){return vs||(vs=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(i){return i.trim()})},e.splitSections=function(t){var i=t.split(`
3
- m=`);return i.map(function(r,s){return(s>0?"m="+r:r).trim()+`\r
4
- `})},e.getDescription=function(t){var i=e.splitSections(t);return i&&i[0]},e.getMediaSections=function(t){var i=e.splitSections(t);return i.shift(),i},e.matchPrefix=function(t,i){return e.splitLines(t).filter(function(r){return r.indexOf(i)===0})},e.parseCandidate=function(t){var i;t.indexOf("a=candidate:")===0?i=t.substring(12).split(" "):i=t.substring(10).split(" ");for(var r={foundation:i[0],component:parseInt(i[1],10),protocol:i[2].toLowerCase(),priority:parseInt(i[3],10),ip:i[4],address:i[4],port:parseInt(i[5],10),type:i[7]},s=8;s<i.length;s+=2)switch(i[s]){case"raddr":r.relatedAddress=i[s+1];break;case"rport":r.relatedPort=parseInt(i[s+1],10);break;case"tcptype":r.tcpType=i[s+1];break;case"ufrag":r.ufrag=i[s+1],r.usernameFragment=i[s+1];break;default:r[i[s]]=i[s+1];break}return r},e.writeCandidate=function(t){var i=[];i.push(t.foundation),i.push(t.component),i.push(t.protocol.toUpperCase()),i.push(t.priority),i.push(t.address||t.ip),i.push(t.port);var r=t.type;return i.push("typ"),i.push(r),r!=="host"&&t.relatedAddress&&t.relatedPort&&(i.push("raddr"),i.push(t.relatedAddress),i.push("rport"),i.push(t.relatedPort)),t.tcpType&&t.protocol.toLowerCase()==="tcp"&&(i.push("tcptype"),i.push(t.tcpType)),(t.usernameFragment||t.ufrag)&&(i.push("ufrag"),i.push(t.usernameFragment||t.ufrag)),"candidate:"+i.join(" ")},e.parseIceOptions=function(t){return t.substr(14).split(" ")},e.parseRtpMap=function(t){var i=t.substr(9).split(" "),r={payloadType:parseInt(i.shift(),10)};return i=i[0].split("/"),r.name=i[0],r.clockRate=parseInt(i[1],10),r.channels=i.length===3?parseInt(i[2],10):1,r.numChannels=r.channels,r},e.writeRtpMap=function(t){var i=t.payloadType;t.preferredPayloadType!==void 0&&(i=t.preferredPayloadType);var r=t.channels||t.numChannels||1;return"a=rtpmap:"+i+" "+t.name+"/"+t.clockRate+(r!==1?"/"+r:"")+`\r
5
- `},e.parseExtmap=function(t){var i=t.substr(9).split(" ");return{id:parseInt(i[0],10),direction:i[0].indexOf("/")>0?i[0].split("/")[1]:"sendrecv",uri:i[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 i={},r,s=t.substr(t.indexOf(" ")+1).split(";"),a=0;a<s.length;a++)r=s[a].trim().split("="),i[r[0].trim()]=r[1];return i},e.writeFmtp=function(t){var i="",r=t.payloadType;if(t.preferredPayloadType!==void 0&&(r=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)}),i+="a=fmtp:"+r+" "+s.join(";")+`\r
7
- `}return i},e.parseRtcpFb=function(t){var i=t.substr(t.indexOf(" ")+1).split(" ");return{type:i.shift(),parameter:i.join(" ")}},e.writeRtcpFb=function(t){var i="",r=t.payloadType;return t.preferredPayloadType!==void 0&&(r=t.preferredPayloadType),t.rtcpFeedback&&t.rtcpFeedback.length&&t.rtcpFeedback.forEach(function(s){i+="a=rtcp-fb:"+r+" "+s.type+(s.parameter&&s.parameter.length?" "+s.parameter:"")+`\r
8
- `}),i},e.parseSsrcMedia=function(t){var i=t.indexOf(" "),r={ssrc:parseInt(t.substr(7,i-7),10)},s=t.indexOf(":",i);return s>-1?(r.attribute=t.substr(i+1,s-i-1),r.value=t.substr(s+1)):r.attribute=t.substr(i+1),r},e.parseSsrcGroup=function(t){var i=t.substr(13).split(" ");return{semantics:i.shift(),ssrcs:i.map(function(r){return parseInt(r,10)})}},e.getMid=function(t){var i=e.matchPrefix(t,"a=mid:")[0];if(i)return i.substr(6)},e.parseFingerprint=function(t){var i=t.substr(14).split(" ");return{algorithm:i[0].toLowerCase(),value:i[1]}},e.getDtlsParameters=function(t,i){var r=e.matchPrefix(t+i,"a=fingerprint:");return{role:"auto",fingerprints:r.map(e.parseFingerprint)}},e.writeDtlsParameters=function(t,i){var r="a=setup:"+i+`\r
9
- `;return t.fingerprints.forEach(function(s){r+="a=fingerprint:"+s.algorithm+" "+s.value+`\r
10
- `}),r},e.parseCryptoLine=function(t){var i=t.substr(9).split(" ");return{tag:parseInt(i[0],10),cryptoSuite:i[1],keyParams:i[2],sessionParams:i.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 i=t.substr(7).split("|");return{keyMethod:"inline",keySalt:i[0],lifeTime:i[1],mkiValue:i[2]?i[2].split(":")[0]:void 0,mkiLength:i[2]?i[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,i){var r=e.matchPrefix(t+i,"a=crypto:");return r.map(e.parseCryptoLine)},e.getIceParameters=function(t,i){var r=e.matchPrefix(t+i,"a=ice-ufrag:")[0],s=e.matchPrefix(t+i,"a=ice-pwd:")[0];return r&&s?{usernameFragment:r.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 i={codecs:[],headerExtensions:[],fecMechanisms:[],rtcp:[]},r=e.splitLines(t),s=r[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),u=e.matchPrefix(t,"a=fmtp:"+o+" ");switch(l.parameters=u.length?e.parseFmtp(u[0]):{},l.rtcpFeedback=e.matchPrefix(t,"a=rtcp-fb:"+o+" ").map(e.parseRtcpFb),i.codecs.push(l),l.name.toUpperCase()){case"RED":case"ULPFEC":i.fecMechanisms.push(l.name.toUpperCase());break}}}return e.matchPrefix(t,"a=extmap:").forEach(function(h){i.headerExtensions.push(e.parseExtmap(h))}),i},e.writeRtpDescription=function(t,i){var r="";r+="m="+t+" ",r+=i.codecs.length>0?"9":"0",r+=" UDP/TLS/RTP/SAVPF ",r+=i.codecs.map(function(a){return a.preferredPayloadType!==void 0?a.preferredPayloadType:a.payloadType}).join(" ")+`\r
14
- `,r+=`c=IN IP4 0.0.0.0\r
15
- `,r+=`a=rtcp:9 IN IP4 0.0.0.0\r
16
- `,i.codecs.forEach(function(a){r+=e.writeRtpMap(a),r+=e.writeFmtp(a),r+=e.writeRtcpFb(a)});var s=0;return i.codecs.forEach(function(a){a.maxptime>s&&(s=a.maxptime)}),s>0&&(r+="a=maxptime:"+s+`\r
17
- `),r+=`a=rtcp-mux\r
18
- `,i.headerExtensions&&i.headerExtensions.forEach(function(a){r+=e.writeExtmap(a)}),r},e.parseRtpEncodingParameters=function(t){var i=[],r=e.parseRtpParameters(t),s=r.fecMechanisms.indexOf("RED")!==-1,a=r.fecMechanisms.indexOf("ULPFEC")!==-1,o=e.matchPrefix(t,"a=ssrc:").map(function(f){return e.parseSsrcMedia(f)}).filter(function(f){return f.attribute==="cname"}),c=o.length>0&&o[0].ssrc,l,u=e.matchPrefix(t,"a=ssrc-group:FID").map(function(f){var d=f.substr(17).split(" ");return d.map(function(y){return parseInt(y,10)})});u.length>0&&u[0].length>1&&u[0][0]===c&&(l=u[0][1]),r.codecs.forEach(function(f){if(f.name.toUpperCase()==="RTX"&&f.parameters.apt){var d={ssrc:c,codecPayloadType:parseInt(f.parameters.apt,10)};c&&l&&(d.rtx={ssrc:l}),i.push(d),s&&(d=JSON.parse(JSON.stringify(d)),d.fec={ssrc:c,mechanism:a?"red+ulpfec":"red"},i.push(d))}}),i.length===0&&c&&i.push({ssrc:c});var h=e.matchPrefix(t,"b=");return h.length&&(h[0].indexOf("b=TIAS:")===0?h=parseInt(h[0].substr(7),10):h[0].indexOf("b=AS:")===0?h=parseInt(h[0].substr(5),10)*1e3*.95-2e3*8:h=void 0,i.forEach(function(f){f.maxBitrate=h})),i},e.parseRtcpParameters=function(t){var i={},r=e.matchPrefix(t,"a=ssrc:").map(function(o){return e.parseSsrcMedia(o)}).filter(function(o){return o.attribute==="cname"})[0];r&&(i.cname=r.value,i.ssrc=r.ssrc);var s=e.matchPrefix(t,"a=rtcp-rsize");i.reducedSize=s.length>0,i.compound=s.length===0;var a=e.matchPrefix(t,"a=rtcp-mux");return i.mux=a.length>0,i},e.parseMsid=function(t){var i,r=e.matchPrefix(t,"a=msid:");if(r.length===1)return i=r[0].substr(7).split(" "),{stream:i[0],track:i[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 i=s[0].value.split(" "),{stream:i[0],track:i[1]}},e.parseSctpDescription=function(t){var i=e.parseMLine(t),r=e.matchPrefix(t,"a=max-message-size:"),s;r.length>0&&(s=parseInt(r[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:i.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,i){var r=[];return t.protocol!=="DTLS/SCTP"?r=["m="+t.kind+" 9 "+t.protocol+" "+i.protocol+`\r
19
- `,`c=IN IP4 0.0.0.0\r
20
- `,"a=sctp-port:"+i.port+`\r
21
- `]:r=["m="+t.kind+" 9 "+t.protocol+" "+i.port+`\r
22
- `,`c=IN IP4 0.0.0.0\r
23
- `,"a=sctpmap:"+i.port+" "+i.protocol+` 65535\r
24
- `],i.maxMessageSize!==void 0&&r.push("a=max-message-size:"+i.maxMessageSize+`\r
25
- `),r.join("")},e.generateSessionId=function(){return Math.random().toString().substr(2,21)},e.writeSessionBoilerplate=function(t,i,r){var s,a=i!==void 0?i:2;t?s=t:s=e.generateSessionId();var o=r||"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,i,r,s){var a=e.writeRtpDescription(t.kind,i);if(a+=e.writeIceParameters(t.iceGatherer.getLocalParameters()),a+=e.writeDtlsParameters(t.dtlsTransport.getLocalParameters(),r==="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,i){for(var r=e.splitLines(t),s=0;s<r.length;s++)switch(r[s]){case"a=sendrecv":case"a=sendonly":case"a=recvonly":case"a=inactive":return r[s].substr(2)}return i?e.getDirection(i):"sendrecv"},e.getKind=function(t){var i=e.splitLines(t),r=i[0].split(" ");return r[0].substr(2)},e.isRejected=function(t){return t.split(" ",2)[1]==="0"},e.parseMLine=function(t){var i=e.splitLines(t),r=i[0].substr(2).split(" ");return{kind:r[0],port:parseInt(r[1],10),protocol:r[2],fmt:r.slice(3).join(" ")}},e.parseOLine=function(t){var i=e.matchPrefix(t,"o=")[0],r=i.substr(2).split(" ");return{username:r[0],sessionId:r[1],sessionVersion:parseInt(r[2],10),netType:r[3],addressType:r[4],address:r[5]}},e.isValidSDP=function(t){if(typeof t!="string"||t.length===0)return!1;for(var i=e.splitLines(t),r=0;r<i.length;r++)if(i[r].length<2||i[r].charAt(1)!=="=")return!1;return!0},n.exports=e})(Kr)),Kr.exports}var Qr,_s;function Ba(){if(_s)return Qr;_s=1;var n=Eo();function e(c){return{inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"}[c.type]||c.type}function t(c,l,u,h,f){var d=n.writeRtpDescription(c.kind,l);if(d+=n.writeIceParameters(c.iceGatherer.getLocalParameters()),d+=n.writeDtlsParameters(c.dtlsTransport.getLocalParameters(),u==="offer"?"actpass":f||"active"),d+="a=mid:"+c.mid+`\r
40
- `,c.rtpSender&&c.rtpReceiver?d+=`a=sendrecv\r
41
- `:c.rtpSender?d+=`a=sendonly\r
42
- `:c.rtpReceiver?d+=`a=recvonly\r
43
- `:d+=`a=inactive\r
44
- `,c.rtpSender){var y=c.rtpSender._initialTrackId||c.rtpSender.track.id;c.rtpSender._initialTrackId=y;var _="msid:"+(h?h.id:"-")+" "+y+`\r
45
- `;d+="a="+_,d+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" "+_,c.sendEncodingParameters[0].rtx&&(d+="a=ssrc:"+c.sendEncodingParameters[0].rtx.ssrc+" "+_,d+="a=ssrc-group:FID "+c.sendEncodingParameters[0].ssrc+" "+c.sendEncodingParameters[0].rtx.ssrc+`\r
46
- `)}return d+="a=ssrc:"+c.sendEncodingParameters[0].ssrc+" cname:"+n.localCName+`\r
47
- `,c.rtpSender&&c.sendEncodingParameters[0].rtx&&(d+="a=ssrc:"+c.sendEncodingParameters[0].rtx.ssrc+" cname:"+n.localCName+`\r
48
- `),d}function i(c,l){var u=!1;return c=JSON.parse(JSON.stringify(c)),c.filter(function(h){if(h&&(h.urls||h.url)){var f=h.urls||h.url;h.url&&!h.urls&&console.warn("RTCIceServer.url is deprecated! Use urls instead.");var d=typeof f=="string";return d&&(f=[f]),f=f.filter(function(y){var _=y.indexOf("turn:")===0&&y.indexOf("transport=udp")!==-1&&y.indexOf("turn:[")===-1&&!u;return _?(u=!0,!0):y.indexOf("stun:")===0&&l>=14393&&y.indexOf("?transport=udp")===-1}),delete h.url,h.urls=d?f[0]:f,!!f.length}})}function r(c,l){var u={codecs:[],headerExtensions:[],fecMechanisms:[]},h=function(d,y){d=parseInt(d,10);for(var _=0;_<y.length;_++)if(y[_].payloadType===d||y[_].preferredPayloadType===d)return y[_]},f=function(d,y,_,p){var m=h(d.parameters.apt,_),v=h(y.parameters.apt,p);return m&&v&&m.name.toLowerCase()===v.name.toLowerCase()};return c.codecs.forEach(function(d){for(var y=0;y<l.codecs.length;y++){var _=l.codecs[y];if(d.name.toLowerCase()===_.name.toLowerCase()&&d.clockRate===_.clockRate){if(d.name.toLowerCase()==="rtx"&&d.parameters&&_.parameters.apt&&!f(d,_,c.codecs,l.codecs))continue;_=JSON.parse(JSON.stringify(_)),_.numChannels=Math.min(d.numChannels,_.numChannels),u.codecs.push(_),_.rtcpFeedback=_.rtcpFeedback.filter(function(p){for(var m=0;m<d.rtcpFeedback.length;m++)if(d.rtcpFeedback[m].type===p.type&&d.rtcpFeedback[m].parameter===p.parameter)return!0;return!1});break}}}),c.headerExtensions.forEach(function(d){for(var y=0;y<l.headerExtensions.length;y++){var _=l.headerExtensions[y];if(d.uri===_.uri){u.headerExtensions.push(_);break}}}),u}function s(c,l,u){return{offer:{setLocalDescription:["stable","have-local-offer"],setRemoteDescription:["stable","have-remote-offer"]},answer:{setLocalDescription:["have-remote-offer","have-local-pranswer"],setRemoteDescription:["have-local-offer","have-remote-pranswer"]}}[l][c].indexOf(u)!==-1}function a(c,l){var u=c.getRemoteCandidates().find(function(h){return l.foundation===h.foundation&&l.ip===h.ip&&l.port===h.port&&l.priority===h.priority&&l.protocol===h.protocol&&l.type===h.type});return u||c.addRemoteCandidate(l),!u}function o(c,l){var u=new Error(l);return u.name=c,u.code={NotSupportedError:9,InvalidStateError:11,InvalidAccessError:15,TypeError:void 0,OperationError:void 0}[c],u}return Qr=function(c,l){function u(p,m){m.addTrack(p),m.dispatchEvent(new c.MediaStreamTrackEvent("addtrack",{track:p}))}function h(p,m){m.removeTrack(p),m.dispatchEvent(new c.MediaStreamTrackEvent("removetrack",{track:p}))}function f(p,m,v,g){var b=new Event("track");b.track=m,b.receiver=v,b.transceiver={receiver:v},b.streams=g,c.setTimeout(function(){p._dispatchEvent("track",b)})}var d=function(p){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",p=JSON.parse(JSON.stringify(p||{})),this.usingBundle=p.bundlePolicy==="max-bundle",p.rtcpMuxPolicy==="negotiate")throw o("NotSupportedError","rtcpMuxPolicy 'negotiate' is not supported");switch(p.rtcpMuxPolicy||(p.rtcpMuxPolicy="require"),p.iceTransportPolicy){case"all":case"relay":break;default:p.iceTransportPolicy="all";break}switch(p.bundlePolicy){case"balanced":case"max-compat":case"max-bundle":break;default:p.bundlePolicy="balanced";break}if(p.iceServers=i(p.iceServers||[],l),this._iceGatherers=[],p.iceCandidatePoolSize)for(var g=p.iceCandidatePoolSize;g>0;g--)this._iceGatherers.push(new c.RTCIceGatherer({iceServers:p.iceServers,gatherPolicy:p.iceTransportPolicy}));else p.iceCandidatePoolSize=0;this._config=p,this.transceivers=[],this._sdpSessionId=n.generateSessionId(),this._sdpSessionVersion=0,this._dtlsRole=void 0,this._isClosed=!1};Object.defineProperty(d.prototype,"localDescription",{configurable:!0,get:function(){return this._localDescription}}),Object.defineProperty(d.prototype,"remoteDescription",{configurable:!0,get:function(){return this._remoteDescription}}),d.prototype.onicecandidate=null,d.prototype.onaddstream=null,d.prototype.ontrack=null,d.prototype.onremovestream=null,d.prototype.onsignalingstatechange=null,d.prototype.oniceconnectionstatechange=null,d.prototype.onconnectionstatechange=null,d.prototype.onicegatheringstatechange=null,d.prototype.onnegotiationneeded=null,d.prototype.ondatachannel=null,d.prototype._dispatchEvent=function(p,m){this._isClosed||(this.dispatchEvent(m),typeof this["on"+p]=="function"&&this["on"+p](m))},d.prototype._emitGatheringStateChange=function(){var p=new Event("icegatheringstatechange");this._dispatchEvent("icegatheringstatechange",p)},d.prototype.getConfiguration=function(){return this._config},d.prototype.getLocalStreams=function(){return this.localStreams},d.prototype.getRemoteStreams=function(){return this.remoteStreams},d.prototype._createTransceiver=function(p,m){var v=this.transceivers.length>0,g={track:null,iceGatherer:null,iceTransport:null,dtlsTransport:null,localCapabilities:null,remoteCapabilities:null,rtpSender:null,rtpReceiver:null,kind:p,mid:null,sendEncodingParameters:null,recvEncodingParameters:null,stream:null,associatedRemoteMediaStreams:[],wantReceive:!0};if(this.usingBundle&&v)g.iceTransport=this.transceivers[0].iceTransport,g.dtlsTransport=this.transceivers[0].dtlsTransport;else{var b=this._createIceAndDtlsTransports();g.iceTransport=b.iceTransport,g.dtlsTransport=b.dtlsTransport}return m||this.transceivers.push(g),g},d.prototype.addTrack=function(p,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===p});if(v)throw o("InvalidAccessError","Track already exists.");for(var g,b=0;b<this.transceivers.length;b++)!this.transceivers[b].track&&this.transceivers[b].kind===p.kind&&(g=this.transceivers[b]);return g||(g=this._createTransceiver(p.kind)),this._maybeFireNegotiationNeeded(),this.localStreams.indexOf(m)===-1&&this.localStreams.push(m),g.track=p,g.stream=m,g.rtpSender=new c.RTCRtpSender(p,g.dtlsTransport),g.rtpSender},d.prototype.addStream=function(p){var m=this;if(l>=15025)p.getTracks().forEach(function(g){m.addTrack(g,p)});else{var v=p.clone();p.getTracks().forEach(function(g,b){var x=v.getTracks()[b];g.addEventListener("enabled",function(S){x.enabled=S.enabled})}),v.getTracks().forEach(function(g){m.addTrack(g,v)})}},d.prototype.removeTrack=function(p){if(this._isClosed)throw o("InvalidStateError","Attempted to call removeTrack on a closed peerconnection.");if(!(p 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===p});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 g=this.transceivers.map(function(b){return b.stream});g.indexOf(v)===-1&&this.localStreams.indexOf(v)>-1&&this.localStreams.splice(this.localStreams.indexOf(v),1),this._maybeFireNegotiationNeeded()},d.prototype.removeStream=function(p){var m=this;p.getTracks().forEach(function(v){var g=m.getSenders().find(function(b){return b.track===v});g&&m.removeTrack(g)})},d.prototype.getSenders=function(){return this.transceivers.filter(function(p){return!!p.rtpSender}).map(function(p){return p.rtpSender})},d.prototype.getReceivers=function(){return this.transceivers.filter(function(p){return!!p.rtpReceiver}).map(function(p){return p.rtpReceiver})},d.prototype._createIceGatherer=function(p,m){var v=this;if(m&&p>0)return this.transceivers[0].iceGatherer;if(this._iceGatherers.length)return this._iceGatherers.shift();var g=new c.RTCIceGatherer({iceServers:this._config.iceServers,gatherPolicy:this._config.iceTransportPolicy});return Object.defineProperty(g,"state",{value:"new",writable:!0}),this.transceivers[p].bufferedCandidateEvents=[],this.transceivers[p].bufferCandidates=function(b){var x=!b.candidate||Object.keys(b.candidate).length===0;g.state=x?"completed":"gathering",v.transceivers[p].bufferedCandidateEvents!==null&&v.transceivers[p].bufferedCandidateEvents.push(b)},g.addEventListener("localcandidate",this.transceivers[p].bufferCandidates),g},d.prototype._gather=function(p,m){var v=this,g=this.transceivers[m].iceGatherer;if(!g.onlocalcandidate){var b=this.transceivers[m].bufferedCandidateEvents;this.transceivers[m].bufferedCandidateEvents=null,g.removeEventListener("localcandidate",this.transceivers[m].bufferCandidates),g.onlocalcandidate=function(x){if(!(v.usingBundle&&m>0)){var S=new Event("icecandidate");S.candidate={sdpMid:p,sdpMLineIndex:m};var T=x.candidate,w=!T||Object.keys(T).length===0;if(w)(g.state==="new"||g.state==="gathering")&&(g.state="completed");else{g.state==="new"&&(g.state="gathering"),T.component=1,T.ufrag=g.getLocalParameters().usernameFragment;var P=n.writeCandidate(T);S.candidate=Object.assign(S.candidate,n.parseCandidate(P)),S.candidate.candidate=P,S.candidate.toJSON=function(){return{candidate:S.candidate.candidate,sdpMid:S.candidate.sdpMid,sdpMLineIndex:S.candidate.sdpMLineIndex,usernameFragment:S.candidate.usernameFragment}}}var C=n.getMediaSections(v._localDescription.sdp);w?C[S.candidate.sdpMLineIndex]+=`a=end-of-candidates\r
49
- `:C[S.candidate.sdpMLineIndex]+="a="+S.candidate.candidate+`\r
50
- `,v._localDescription.sdp=n.getDescription(v._localDescription.sdp)+C.join("");var R=v.transceivers.every(function(E){return E.iceGatherer&&E.iceGatherer.state==="completed"});v.iceGatheringState!=="gathering"&&(v.iceGatheringState="gathering",v._emitGatheringStateChange()),w||v._dispatchEvent("icecandidate",S),R&&(v._dispatchEvent("icecandidate",new Event("icecandidate")),v.iceGatheringState="complete",v._emitGatheringStateChange())}},c.setTimeout(function(){b.forEach(function(x){g.onlocalcandidate(x)})},0)}},d.prototype._createIceAndDtlsTransports=function(){var p=this,m=new c.RTCIceTransport(null);m.onicestatechange=function(){p._updateIceConnectionState(),p._updateConnectionState()};var v=new c.RTCDtlsTransport(m);return v.ondtlsstatechange=function(){p._updateConnectionState()},v.onerror=function(){Object.defineProperty(v,"state",{value:"failed",writable:!0}),p._updateConnectionState()},{iceTransport:m,dtlsTransport:v}},d.prototype._disposeIceAndDtlsTransports=function(p){var m=this.transceivers[p].iceGatherer;m&&(delete m.onlocalcandidate,delete this.transceivers[p].iceGatherer);var v=this.transceivers[p].iceTransport;v&&(delete v.onicestatechange,delete this.transceivers[p].iceTransport);var g=this.transceivers[p].dtlsTransport;g&&(delete g.ondtlsstatechange,delete g.onerror,delete this.transceivers[p].dtlsTransport)},d.prototype._transceive=function(p,m,v){var g=r(p.localCapabilities,p.remoteCapabilities);m&&p.rtpSender&&(g.encodings=p.sendEncodingParameters,g.rtcp={cname:n.localCName,compound:p.rtcpParameters.compound},p.recvEncodingParameters.length&&(g.rtcp.ssrc=p.recvEncodingParameters[0].ssrc),p.rtpSender.send(g)),v&&p.rtpReceiver&&g.codecs.length>0&&(p.kind==="video"&&p.recvEncodingParameters&&l<15019&&p.recvEncodingParameters.forEach(function(b){delete b.rtx}),p.recvEncodingParameters.length?g.encodings=p.recvEncodingParameters:g.encodings=[{}],g.rtcp={compound:p.rtcpParameters.compound},p.rtcpParameters.cname&&(g.rtcp.cname=p.rtcpParameters.cname),p.sendEncodingParameters.length&&(g.rtcp.ssrc=p.sendEncodingParameters[0].ssrc),p.rtpReceiver.receive(g))},d.prototype.setLocalDescription=function(p){var m=this;if(["offer","answer"].indexOf(p.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+p.type+'"'));if(!s("setLocalDescription",p.type,m.signalingState)||m._isClosed)return Promise.reject(o("InvalidStateError","Can not set local "+p.type+" in state "+m.signalingState));var v,g;if(p.type==="offer")v=n.splitSections(p.sdp),g=v.shift(),v.forEach(function(x,S){var T=n.parseRtpParameters(x);m.transceivers[S].localCapabilities=T}),m.transceivers.forEach(function(x,S){m._gather(x.mid,S)});else if(p.type==="answer"){v=n.splitSections(m._remoteDescription.sdp),g=v.shift();var b=n.matchPrefix(g,"a=ice-lite").length>0;v.forEach(function(x,S){var T=m.transceivers[S],w=T.iceGatherer,P=T.iceTransport,C=T.dtlsTransport,R=T.localCapabilities,E=T.remoteCapabilities,k=n.isRejected(x)&&n.matchPrefix(x,"a=bundle-only").length===0;if(!k&&!T.rejected){var A=n.getIceParameters(x,g),z=n.getDtlsParameters(x,g);b&&(z.role="server"),(!m.usingBundle||S===0)&&(m._gather(T.mid,S),P.state==="new"&&P.start(w,A,b?"controlling":"controlled"),C.state==="new"&&C.start(z));var N=r(R,E);m._transceive(T,N.codecs.length>0,!1)}})}return m._localDescription={type:p.type,sdp:p.sdp},p.type==="offer"?m._updateSignalingState("have-local-offer"):m._updateSignalingState("stable"),Promise.resolve()},d.prototype.setRemoteDescription=function(p){var m=this;if(["offer","answer"].indexOf(p.type)===-1)return Promise.reject(o("TypeError",'Unsupported type "'+p.type+'"'));if(!s("setRemoteDescription",p.type,m.signalingState)||m._isClosed)return Promise.reject(o("InvalidStateError","Can not set remote "+p.type+" in state "+m.signalingState));var v={};m.remoteStreams.forEach(function(P){v[P.id]=P});var g=[],b=n.splitSections(p.sdp),x=b.shift(),S=n.matchPrefix(x,"a=ice-lite").length>0,T=n.matchPrefix(x,"a=group:BUNDLE ").length>0;m.usingBundle=T;var w=n.matchPrefix(x,"a=ice-options:")[0];return w?m.canTrickleIceCandidates=w.substr(14).split(" ").indexOf("trickle")>=0:m.canTrickleIceCandidates=!1,b.forEach(function(P,C){var R=n.splitLines(P),E=n.getKind(P),k=n.isRejected(P)&&n.matchPrefix(P,"a=bundle-only").length===0,A=R[0].substr(2).split(" ")[2],z=n.getDirection(P,x),N=n.parseMsid(P),L=n.getMid(P)||n.generateIdentifier();if(k||E==="application"&&(A==="DTLS/SCTP"||A==="UDP/DTLS/SCTP")){m.transceivers[C]={mid:L,kind:E,protocol:A,rejected:!0};return}!k&&m.transceivers[C]&&m.transceivers[C].rejected&&(m.transceivers[C]=m._createTransceiver(E,!0));var I,X,Z,ie,Q,pe,me,re,H,j=n.parseRtpParameters(P),Ye,Le;k||(Ye=n.getIceParameters(P,x),Le=n.getDtlsParameters(P,x),Le.role="client"),me=n.parseRtpEncodingParameters(P);var Ve=n.parseRtcpParameters(P),Je=n.matchPrefix(P,"a=end-of-candidates",x).length>0,ve=n.matchPrefix(P,"a=candidate:").map(function(W){return n.parseCandidate(W)}).filter(function(W){return W.component===1});if((p.type==="offer"||p.type==="answer")&&!k&&T&&C>0&&m.transceivers[C]&&(m._disposeIceAndDtlsTransports(C),m.transceivers[C].iceGatherer=m.transceivers[0].iceGatherer,m.transceivers[C].iceTransport=m.transceivers[0].iceTransport,m.transceivers[C].dtlsTransport=m.transceivers[0].dtlsTransport,m.transceivers[C].rtpSender&&m.transceivers[C].rtpSender.setTransport(m.transceivers[0].dtlsTransport),m.transceivers[C].rtpReceiver&&m.transceivers[C].rtpReceiver.setTransport(m.transceivers[0].dtlsTransport)),p.type==="offer"&&!k){I=m.transceivers[C]||m._createTransceiver(E),I.mid=L,I.iceGatherer||(I.iceGatherer=m._createIceGatherer(C,T)),ve.length&&I.iceTransport.state==="new"&&(Je&&(!T||C===0)?I.iceTransport.setRemoteCandidates(ve):ve.forEach(function(W){a(I.iceTransport,W)})),re=c.RTCRtpReceiver.getCapabilities(E),l<15019&&(re.codecs=re.codecs.filter(function(W){return W.name!=="rtx"})),pe=I.sendEncodingParameters||[{ssrc:(2*C+2)*1001}];var Ae=!1;if(z==="sendrecv"||z==="sendonly"){if(Ae=!I.rtpReceiver,Q=I.rtpReceiver||new c.RTCRtpReceiver(I.dtlsTransport,E),Ae){var _e;H=Q.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}}),_e=v[N.stream]):(v.default||(v.default=new c.MediaStream),_e=v.default)),_e&&(u(H,_e),I.associatedRemoteMediaStreams.push(_e)),g.push([H,Q,_e])}}else I.rtpReceiver&&I.rtpReceiver.track&&(I.associatedRemoteMediaStreams.forEach(function(W){var Ge=W.getTracks().find(function(Qe){return Qe.id===I.rtpReceiver.track.id});Ge&&h(Ge,W)}),I.associatedRemoteMediaStreams=[]);I.localCapabilities=re,I.remoteCapabilities=j,I.rtpReceiver=Q,I.rtcpParameters=Ve,I.sendEncodingParameters=pe,I.recvEncodingParameters=me,m._transceive(m.transceivers[C],!1,Ae)}else if(p.type==="answer"&&!k){I=m.transceivers[C],X=I.iceGatherer,Z=I.iceTransport,ie=I.dtlsTransport,Q=I.rtpReceiver,pe=I.sendEncodingParameters,re=I.localCapabilities,m.transceivers[C].recvEncodingParameters=me,m.transceivers[C].remoteCapabilities=j,m.transceivers[C].rtcpParameters=Ve,ve.length&&Z.state==="new"&&((S||Je)&&(!T||C===0)?Z.setRemoteCandidates(ve):ve.forEach(function(W){a(I.iceTransport,W)})),(!T||C===0)&&(Z.state==="new"&&Z.start(X,Ye,"controlling"),ie.state==="new"&&ie.start(Le));var Ze=r(I.localCapabilities,I.remoteCapabilities),Ke=Ze.codecs.filter(function(W){return W.name.toLowerCase()==="rtx"}).length;!Ke&&I.sendEncodingParameters[0].rtx&&delete I.sendEncodingParameters[0].rtx,m._transceive(I,z==="sendrecv"||z==="recvonly",z==="sendrecv"||z==="sendonly"),Q&&(z==="sendrecv"||z==="sendonly")?(H=Q.track,N?(v[N.stream]||(v[N.stream]=new c.MediaStream),u(H,v[N.stream]),g.push([H,Q,v[N.stream]])):(v.default||(v.default=new c.MediaStream),u(H,v.default),g.push([H,Q,v.default]))):delete I.rtpReceiver}}),m._dtlsRole===void 0&&(m._dtlsRole=p.type==="offer"?"active":"passive"),m._remoteDescription={type:p.type,sdp:p.sdp},p.type==="offer"?m._updateSignalingState("have-remote-offer"):m._updateSignalingState("stable"),Object.keys(v).forEach(function(P){var C=v[P];if(C.getTracks().length){if(m.remoteStreams.indexOf(C)===-1){m.remoteStreams.push(C);var R=new Event("addstream");R.stream=C,c.setTimeout(function(){m._dispatchEvent("addstream",R)})}g.forEach(function(E){var k=E[0],A=E[1];C.id===E[2].id&&f(m,k,A,[C])})}}),g.forEach(function(P){P[2]||f(m,P[0],P[1],[])}),c.setTimeout(function(){m&&m.transceivers&&m.transceivers.forEach(function(P){P.iceTransport&&P.iceTransport.state==="new"&&P.iceTransport.getRemoteCandidates().length>0&&(console.warn("Timeout for addRemoteCandidate. Consider sending an end-of-candidates notification"),P.iceTransport.addRemoteCandidate({}))})},4e3),Promise.resolve()},d.prototype.close=function(){this.transceivers.forEach(function(p){p.iceTransport&&p.iceTransport.stop(),p.dtlsTransport&&p.dtlsTransport.stop(),p.rtpSender&&p.rtpSender.stop(),p.rtpReceiver&&p.rtpReceiver.stop()}),this._isClosed=!0,this._updateSignalingState("closed")},d.prototype._updateSignalingState=function(p){this.signalingState=p;var m=new Event("signalingstatechange");this._dispatchEvent("signalingstatechange",m)},d.prototype._maybeFireNegotiationNeeded=function(){var p=this;this.signalingState!=="stable"||this.needNegotiation===!0||(this.needNegotiation=!0,c.setTimeout(function(){if(p.needNegotiation){p.needNegotiation=!1;var m=new Event("negotiationneeded");p._dispatchEvent("negotiationneeded",m)}},0))},d.prototype._updateIceConnectionState=function(){var p,m={new:0,closed:0,checking:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(g){g.iceTransport&&!g.rejected&&m[g.iceTransport.state]++}),p="new",m.failed>0?p="failed":m.checking>0?p="checking":m.disconnected>0?p="disconnected":m.new>0?p="new":m.connected>0?p="connected":m.completed>0&&(p="completed"),p!==this.iceConnectionState){this.iceConnectionState=p;var v=new Event("iceconnectionstatechange");this._dispatchEvent("iceconnectionstatechange",v)}},d.prototype._updateConnectionState=function(){var p,m={new:0,closed:0,connecting:0,connected:0,completed:0,disconnected:0,failed:0};if(this.transceivers.forEach(function(g){g.iceTransport&&g.dtlsTransport&&!g.rejected&&(m[g.iceTransport.state]++,m[g.dtlsTransport.state]++)}),m.connected+=m.completed,p="new",m.failed>0?p="failed":m.connecting>0?p="connecting":m.disconnected>0?p="disconnected":m.new>0?p="new":m.connected>0&&(p="connected"),p!==this.connectionState){this.connectionState=p;var v=new Event("connectionstatechange");this._dispatchEvent("connectionstatechange",v)}},d.prototype.createOffer=function(){var p=this;if(p._isClosed)return Promise.reject(o("InvalidStateError","Can not call createOffer after close"));var m=p.transceivers.filter(function(S){return S.kind==="audio"}).length,v=p.transceivers.filter(function(S){return S.kind==="video"}).length,g=arguments[0];if(g){if(g.mandatory||g.optional)throw new TypeError("Legacy mandatory/optional constraints not supported.");g.offerToReceiveAudio!==void 0&&(g.offerToReceiveAudio===!0?m=1:g.offerToReceiveAudio===!1?m=0:m=g.offerToReceiveAudio),g.offerToReceiveVideo!==void 0&&(g.offerToReceiveVideo===!0?v=1:g.offerToReceiveVideo===!1?v=0:v=g.offerToReceiveVideo)}for(p.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&&(p._createTransceiver("audio"),m--),v>0&&(p._createTransceiver("video"),v--);var b=n.writeSessionBoilerplate(p._sdpSessionId,p._sdpSessionVersion++);p.transceivers.forEach(function(S,T){var w=S.track,P=S.kind,C=S.mid||n.generateIdentifier();S.mid=C,S.iceGatherer||(S.iceGatherer=p._createIceGatherer(T,p.usingBundle));var R=c.RTCRtpSender.getCapabilities(P);l<15019&&(R.codecs=R.codecs.filter(function(k){return k.name!=="rtx"})),R.codecs.forEach(function(k){k.name==="H264"&&k.parameters["level-asymmetry-allowed"]===void 0&&(k.parameters["level-asymmetry-allowed"]="1"),S.remoteCapabilities&&S.remoteCapabilities.codecs&&S.remoteCapabilities.codecs.forEach(function(A){k.name.toLowerCase()===A.name.toLowerCase()&&k.clockRate===A.clockRate&&(k.preferredPayloadType=A.payloadType)})}),R.headerExtensions.forEach(function(k){var A=S.remoteCapabilities&&S.remoteCapabilities.headerExtensions||[];A.forEach(function(z){k.uri===z.uri&&(k.id=z.id)})});var E=S.sendEncodingParameters||[{ssrc:(2*T+1)*1001}];w&&l>=15019&&P==="video"&&!E[0].rtx&&(E[0].rtx={ssrc:E[0].ssrc+1}),S.wantReceive&&(S.rtpReceiver=new c.RTCRtpReceiver(S.dtlsTransport,P)),S.localCapabilities=R,S.sendEncodingParameters=E}),p._config.bundlePolicy!=="max-compat"&&(b+="a=group:BUNDLE "+p.transceivers.map(function(S){return S.mid}).join(" ")+`\r
51
- `),b+=`a=ice-options:trickle\r
52
- `,p.transceivers.forEach(function(S,T){b+=t(S,S.localCapabilities,"offer",S.stream,p._dtlsRole),b+=`a=rtcp-rsize\r
53
- `,S.iceGatherer&&p.iceGatheringState!=="new"&&(T===0||!p.usingBundle)&&(S.iceGatherer.getLocalCandidates().forEach(function(w){w.component=1,b+="a="+n.writeCandidate(w)+`\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)},d.prototype.createAnswer=function(){var p=this;if(p._isClosed)return Promise.reject(o("InvalidStateError","Can not call createAnswer after close"));if(!(p.signalingState==="have-remote-offer"||p.signalingState==="have-local-pranswer"))return Promise.reject(o("InvalidStateError","Can not call createAnswer in signalingState "+p.signalingState));var m=n.writeSessionBoilerplate(p._sdpSessionId,p._sdpSessionVersion++);p.usingBundle&&(m+="a=group:BUNDLE "+p.transceivers.map(function(b){return b.mid}).join(" ")+`\r
56
- `),m+=`a=ice-options:trickle\r
57
- `;var v=n.getMediaSections(p._remoteDescription.sdp).length;p.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 T=r(b.localCapabilities,b.remoteCapabilities),w=T.codecs.filter(function(P){return P.name.toLowerCase()==="rtx"}).length;!w&&b.sendEncodingParameters[0].rtx&&delete b.sendEncodingParameters[0].rtx,m+=t(b,T,"answer",b.stream,p._dtlsRole),b.rtcpParameters&&b.rtcpParameters.reducedSize&&(m+=`a=rtcp-rsize\r
67
- `)}});var g=new c.RTCSessionDescription({type:"answer",sdp:m});return Promise.resolve(g)},d.prototype.addIceCandidate=function(p){var m=this,v;return p&&!(p.sdpMLineIndex!==void 0||p.sdpMid)?Promise.reject(new TypeError("sdpMLineIndex or sdpMid required")):new Promise(function(g,b){if(m._remoteDescription)if(!p||p.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=p.sdpMLineIndex;if(p.sdpMid){for(var T=0;T<m.transceivers.length;T++)if(m.transceivers[T].mid===p.sdpMid){S=T;break}}var w=m.transceivers[S];if(w){if(w.rejected)return g();var P=Object.keys(p.candidate).length>0?n.parseCandidate(p.candidate):{};if(P.protocol==="tcp"&&(P.port===0||P.port===9)||P.component&&P.component!==1)return g();if((S===0||S>0&&w.iceTransport!==m.transceivers[0].iceTransport)&&!a(w.iceTransport,P))return b(o("OperationError","Can not add ICE candidate"));var C=p.candidate.trim();C.indexOf("a=")===0&&(C=C.substr(2)),v=n.getMediaSections(m._remoteDescription.sdp),v[S]+="a="+(P.type?C:"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"));g()})},d.prototype.getStats=function(p){if(p&&p instanceof c.MediaStreamTrack){var m=null;if(this.transceivers.forEach(function(g){g.rtpSender&&g.rtpSender.track===p?m=g.rtpSender:g.rtpReceiver&&g.rtpReceiver.track===p&&(m=g.rtpReceiver)}),!m)throw o("InvalidAccessError","Invalid selector.");return m.getStats()}var v=[];return this.transceivers.forEach(function(g){["rtpSender","rtpReceiver","iceGatherer","iceTransport","dtlsTransport"].forEach(function(b){g[b]&&v.push(g[b].getStats())})}),Promise.all(v).then(function(g){var b=new Map;return g.forEach(function(x){x.forEach(function(S){b.set(S.id,S)})}),b})};var y=["RTCRtpSender","RTCRtpReceiver","RTCIceGatherer","RTCIceTransport","RTCDtlsTransport"];y.forEach(function(p){var m=c[p];if(m&&m.prototype&&m.prototype.getStats){var v=m.prototype.getStats;m.prototype.getStats=function(){return v.apply(this).then(function(g){var b=new Map;return Object.keys(g).forEach(function(x){g[x].type=e(g[x]),b.set(x,g[x])}),b})}}});var _=["createOffer","createAnswer"];return _.forEach(function(p){var m=d.prototype[p];d.prototype[p]=function(){var v=arguments;return typeof v[0]=="function"||typeof v[1]=="function"?m.apply(this,[arguments[2]]).then(function(g){typeof v[0]=="function"&&v[0].apply(null,[g])},function(g){typeof v[1]=="function"&&v[1].apply(null,[g])}):m.apply(this,arguments)}}),_=["setLocalDescription","setRemoteDescription","addIceCandidate"],_.forEach(function(p){var m=d.prototype[p];d.prototype[p]=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(g){typeof v[2]=="function"&&v[2].apply(null,[g])}):m.apply(this,arguments)}}),["getStats"].forEach(function(p){var m=d.prototype[p];d.prototype[p]=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)}}),d},Qr}var Ia=Ba();const Na=Gr(Ia);function Ro(n){const e=n&&n.navigator,t=function(r){return{name:{PermissionDeniedError:"NotAllowedError"}[r.name]||r.name,message:r.message,constraint:r.constraint,toString(){return this.name}}},i=e.mediaDevices.getUserMedia.bind(e.mediaDevices);Object.getOwnPropertyDescriptor(e.mediaDevices,"getUserMedia")?.writable&&(e.mediaDevices.getUserMedia=function(r){return i(r).catch(s=>Promise.reject(t(s)))})}function ko(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 An(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 i=Object.getOwnPropertyDescriptor(n.MediaStreamTrack.prototype,"enabled");Object.defineProperty(n.MediaStreamTrack.prototype,"enabled",{set(r){i.set.call(this,r);const s=new Event("enabled");s.enabled=r,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=Na(n,e.version);n.RTCPeerConnection=function(r){return r&&r.iceServers&&(r.iceServers=Oa(r.iceServers,e.version),Zn("ICE servers after filtering:",r.iceServers)),new t(r)},n.RTCPeerConnection.prototype=t.prototype}function Ao(n){n.RTCRtpSender&&!("replaceTrack"in n.RTCRtpSender.prototype)&&(n.RTCRtpSender.prototype.replaceTrack=n.RTCRtpSender.prototype.setTrack)}const xs=Object.freeze(Object.defineProperty({__proto__:null,shimGetDisplayMedia:ko,shimGetUserMedia:Ro,shimPeerConnection:An,shimReplaceTrack:Ao},Symbol.toStringTag,{value:"Module"}));function zo(n,e){const t=n&&n.navigator,i=n&&n.MediaStreamTrack;if(t.getUserMedia=function(r,s,a){jr("navigator.getUserMedia","navigator.mediaDevices.getUserMedia"),t.mediaDevices.getUserMedia(r).then(s,a)},!(e.version>55&&"autoGainControl"in t.mediaDevices.getSupportedConstraints())){const r=function(a,o,c){o in a&&!(c in a)&&(a[c]=a[o],delete a[o])},s=t.mediaDevices.getUserMedia.bind(t.mediaDevices);if(Object.getOwnPropertyDescriptor(t.mediaDevices,"getUserMedia")?.writable&&(t.mediaDevices.getUserMedia=function(a){return typeof a=="object"&&typeof a.audio=="object"&&(a=JSON.parse(JSON.stringify(a)),r(a.audio,"autoGainControl","mozAutoGainControl"),r(a.audio,"noiseSuppression","mozNoiseSuppression")),s(a)}),i&&i.prototype.getSettings){const a=i.prototype.getSettings;i.prototype.getSettings=function(){const o=a.apply(this,arguments);return r(o,"mozAutoGainControl","autoGainControl"),r(o,"mozNoiseSuppression","noiseSuppression"),o}}if(i&&i.prototype.applyConstraints){const a=i.prototype.applyConstraints;i.prototype.applyConstraints=function(o){return this.kind==="audio"&&typeof o=="object"&&(o=JSON.parse(JSON.stringify(o)),r(o,"autoGainControl","mozAutoGainControl"),r(o,"noiseSuppression","mozNoiseSuppression")),a.apply(this,[o])}}}}function Ua(n,e){n.navigator.mediaDevices&&"getDisplayMedia"in n.navigator.mediaDevices||n.navigator.mediaDevices&&(n.navigator.mediaDevices.getDisplayMedia=function(i){if(!(i&&i.video)){const r=new DOMException("getDisplayMedia without video constraints is undefined");return r.name="NotFoundError",r.code=8,Promise.reject(r)}return i.video===!0?i.video={mediaSource:e}:i.video.mediaSource=e,n.navigator.mediaDevices.getUserMedia(i)})}function Oo(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 zn(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(r){const s=n.RTCPeerConnection.prototype[r],a={[r](){return arguments[0]=new(r==="addIceCandidate"?n.RTCIceCandidate:n.RTCSessionDescription)(arguments[0]),s.apply(this,arguments)}};n.RTCPeerConnection.prototype[r]=a[r]});const t={inboundrtp:"inbound-rtp",outboundrtp:"outbound-rtp",candidatepair:"candidate-pair",localcandidate:"local-candidate",remotecandidate:"remote-candidate"},i=n.RTCPeerConnection.prototype.getStats;n.RTCPeerConnection.prototype.getStats=function(){const[s,a,o]=arguments;return i.apply(this,[s||null]).then(c=>{if(e.version<53&&!a)try{c.forEach(l=>{l.type=t[l.type]||l.type})}catch(l){if(l.name!=="TypeError")throw l;c.forEach((u,h)=>{c.set(h,Object.assign({},u,{type:t[u.type]||u.type}))})}return c}).then(a,o)}}function Bo(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(s=>s._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 Io(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 i=e.apply(this,[]);return i.forEach(r=>r._pc=this),i}),Xt(n,"track",t=>(t.receiver._pc=t.srcElement,t)),n.RTCRtpReceiver.prototype.getStats=function(){return this._pc.getStats(this.track)}}function No(n){!n.RTCPeerConnection||"removeStream"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.removeStream=function(t){jr("removeStream","removeTrack"),this.getSenders().forEach(i=>{i.track&&t.getTracks().includes(i.track)&&this.removeTrack(i)})})}function Uo(n){n.DataChannel&&!n.RTCDataChannel&&(n.RTCDataChannel=n.DataChannel)}function Fo(n){if(!(typeof n=="object"&&n.RTCPeerConnection))return;const e=n.RTCPeerConnection.prototype.addTransceiver;e&&(n.RTCPeerConnection.prototype.addTransceiver=function(){this.setParametersPromises=[];const i=arguments[1],r=i&&"sendEncodings"in i;r&&i.sendEncodings.forEach(a=>{if("rid"in a&&!/^[a-z0-9]{0,16}$/i.test(a.rid))throw new TypeError("Invalid RID value provided.");if("scaleResolutionDownBy"in a&&!(parseFloat(a.scaleResolutionDownBy)>=1))throw new RangeError("scale_resolution_down_by must be >= 1.0");if("maxFramerate"in a&&!(parseFloat(a.maxFramerate)>=0))throw new RangeError("max_framerate must be >= 0.0")});const s=e.apply(this,arguments);if(r){const{sender:a}=s,o=a.getParameters();(!("encodings"in o)||o.encodings.length===1&&Object.keys(o.encodings[0]).length===0)&&(o.encodings=i.sendEncodings,a.sendEncodings=i.sendEncodings,this.setParametersPromises.push(a.setParameters(o).then(()=>{delete a.sendEncodings}).catch(()=>{delete a.sendEncodings})))}return s})}function Do(n){if(!(typeof n=="object"&&n.RTCRtpSender))return;const e=n.RTCRtpSender.prototype.getParameters;e&&(n.RTCRtpSender.prototype.getParameters=function(){const i=e.apply(this,arguments);return"encodings"in i||(i.encodings=[].concat(this.sendEncodings||[{}])),i})}function Lo(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 Vo(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 bs=Object.freeze(Object.defineProperty({__proto__:null,shimAddTransceiver:Fo,shimCreateAnswer:Vo,shimCreateOffer:Lo,shimGetDisplayMedia:Ua,shimGetParameters:Do,shimGetUserMedia:zo,shimOnTrack:Oo,shimPeerConnection:zn,shimRTCDataChannel:Uo,shimReceiverGetStats:Io,shimRemoveStream:No,shimSenderGetStats:Bo},Symbol.toStringTag,{value:"Module"}));function Jo(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(i){this._localStreams||(this._localStreams=[]),this._localStreams.includes(i)||this._localStreams.push(i),i.getAudioTracks().forEach(r=>e.call(this,r,i)),i.getVideoTracks().forEach(r=>e.call(this,r,i))},n.RTCPeerConnection.prototype.addTrack=function(i,...r){return r&&r.forEach(s=>{this._localStreams?this._localStreams.includes(s)||this._localStreams.push(s):this._localStreams=[s]}),e.apply(this,arguments)}}"removeStream"in n.RTCPeerConnection.prototype||(n.RTCPeerConnection.prototype.removeStream=function(t){this._localStreams||(this._localStreams=[]);const i=this._localStreams.indexOf(t);if(i===-1)return;this._localStreams.splice(i,1);const r=t.getTracks();this.getSenders().forEach(s=>{r.includes(s.track)&&this.removeTrack(s)})})}}function Go(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=i=>{i.streams.forEach(r=>{if(this._remoteStreams||(this._remoteStreams=[]),this._remoteStreams.includes(r))return;this._remoteStreams.push(r);const s=new Event("addstream");s.stream=r,this.dispatchEvent(s)})})}});const e=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){const i=this;return this._onaddstreampoly||this.addEventListener("track",this._onaddstreampoly=function(r){r.streams.forEach(s=>{if(i._remoteStreams||(i._remoteStreams=[]),i._remoteStreams.indexOf(s)>=0)return;i._remoteStreams.push(s);const a=new Event("addstream");a.stream=s,i.dispatchEvent(a)})}),e.apply(i,arguments)}}}function jo(n){if(typeof n!="object"||!n.RTCPeerConnection)return;const e=n.RTCPeerConnection.prototype,t=e.createOffer,i=e.createAnswer,r=e.setLocalDescription,s=e.setRemoteDescription,a=e.addIceCandidate;e.createOffer=function(l,u){const h=arguments.length>=2?arguments[2]:arguments[0],f=t.apply(this,[h]);return u?(f.then(l,u),Promise.resolve()):f},e.createAnswer=function(l,u){const h=arguments.length>=2?arguments[2]:arguments[0],f=i.apply(this,[h]);return u?(f.then(l,u),Promise.resolve()):f};let o=function(c,l,u){const h=r.apply(this,[c]);return u?(h.then(l,u),Promise.resolve()):h};e.setLocalDescription=o,o=function(c,l,u){const h=s.apply(this,[c]);return u?(h.then(l,u),Promise.resolve()):h},e.setRemoteDescription=o,o=function(c,l,u){const h=a.apply(this,[c]);return u?(h.then(l,u),Promise.resolve()):h},e.addIceCandidate=o}function $o(n){const e=n&&n.navigator;if(e.mediaDevices&&e.mediaDevices.getUserMedia){const t=e.mediaDevices,i=t.getUserMedia.bind(t);e.mediaDevices.getUserMedia=r=>i(qo(r))}!e.getUserMedia&&e.mediaDevices&&e.mediaDevices.getUserMedia&&(e.getUserMedia=(function(i,r,s){e.mediaDevices.getUserMedia(i).then(r,s)}).bind(e))}function qo(n){return n&&n.video!==void 0?Object.assign({},n,{video:vo(n.video)}):n}function Xo(n){if(!n.RTCPeerConnection)return;const e=n.RTCPeerConnection;n.RTCPeerConnection=function(i,r){if(i&&i.iceServers){const s=[];for(let a=0;a<i.iceServers.length;a++){let o=i.iceServers[a];!o.hasOwnProperty("urls")&&o.hasOwnProperty("url")?(jr("RTCIceServer.url","RTCIceServer.urls"),o=JSON.parse(JSON.stringify(o)),o.urls=o.url,delete o.url,s.push(o)):s.push(i.iceServers[a])}i.iceServers=s}return new e(i,r)},n.RTCPeerConnection.prototype=e.prototype,"generateCertificate"in e&&Object.defineProperty(n.RTCPeerConnection,"generateCertificate",{get(){return e.generateCertificate}})}function Ho(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 Wo(n){const e=n.RTCPeerConnection.prototype.createOffer;n.RTCPeerConnection.prototype.createOffer=function(i){if(i){typeof i.offerToReceiveAudio<"u"&&(i.offerToReceiveAudio=!!i.offerToReceiveAudio);const r=this.getTransceivers().find(a=>a.receiver.track.kind==="audio");i.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"):i.offerToReceiveAudio===!0&&!r&&this.addTransceiver("audio"),typeof i.offerToReceiveVideo<"u"&&(i.offerToReceiveVideo=!!i.offerToReceiveVideo);const s=this.getTransceivers().find(a=>a.receiver.track.kind==="video");i.offerToReceiveVideo===!1&&s?s.direction==="sendrecv"?s.setDirection?s.setDirection("sendonly"):s.direction="sendonly":s.direction==="recvonly"&&(s.setDirection?s.setDirection("inactive"):s.direction="inactive"):i.offerToReceiveVideo===!0&&!s&&this.addTransceiver("video")}return e.apply(this,arguments)}}function Yo(n){typeof n!="object"||n.AudioContext||(n.AudioContext=n.webkitAudioContext)}const Ss=Object.freeze(Object.defineProperty({__proto__:null,shimAudioContext:Yo,shimCallbacksAPI:jo,shimConstraints:qo,shimCreateOfferLegacy:Wo,shimGetUserMedia:$o,shimLocalStreamsAPI:Jo,shimRTCIceServerUrls:Xo,shimRemoteStreamsAPI:Go,shimTrackEventTransceiver:Ho},Symbol.toStringTag,{value:"Module"}));var Fa=Eo();const Er=Gr(Fa);function Rr(n){if(!n.RTCIceCandidate||n.RTCIceCandidate&&"foundation"in n.RTCIceCandidate.prototype)return;const e=n.RTCIceCandidate;n.RTCIceCandidate=function(i){if(typeof i=="object"&&i.candidate&&i.candidate.indexOf("a=")===0&&(i=JSON.parse(JSON.stringify(i)),i.candidate=i.candidate.substr(2)),i.candidate&&i.candidate.length){const r=new e(i),s=Er.parseCandidate(i.candidate),a=Object.assign(r,s);return a.toJSON=function(){return{candidate:a.candidate,sdpMid:a.sdpMid,sdpMLineIndex:a.sdpMLineIndex,usernameFragment:a.usernameFragment}},a}return new e(i)},n.RTCIceCandidate.prototype=e.prototype,Xt(n,"icecandidate",t=>(t.candidate&&Object.defineProperty(t,"candidate",{value:new n.RTCIceCandidate(t.candidate),writable:"false"}),t))}function fi(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=Er.splitSections(o.sdp);return c.shift(),c.some(l=>{const u=Er.parseMLine(l);return u&&u.kind==="application"&&u.protocol.indexOf("SCTP")!==-1})},i=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},r=function(o){let c=65536;return e.browser==="firefox"&&(e.version<57?o===-1?c=16384:c=2147483637:e.version<60?c=e.version===57?65535:65536:c=2147483637),c},s=function(o,c){let l=65536;e.browser==="firefox"&&e.version===57&&(l=65535);const u=Er.matchPrefix(o.sdp,"a=max-message-size:");return u.length>0?l=parseInt(u[0].substr(19),10):e.browser==="firefox"&&c!==-1&&(l=2147483637),l},a=n.RTCPeerConnection.prototype.setRemoteDescription;n.RTCPeerConnection.prototype.setRemoteDescription=function(){if(this._sctp=null,e.browser==="chrome"&&e.version>=76){const{sdpSemantics:c}=this.getConfiguration();c==="plan-b"&&Object.defineProperty(this,"sctp",{get(){return typeof this._sctp>"u"?null:this._sctp},enumerable:!0,configurable:!0})}if(t(arguments[0])){const c=i(arguments[0]),l=r(c),u=s(arguments[0],c);let h;l===0&&u===0?h=Number.POSITIVE_INFINITY:l===0||u===0?h=Math.max(l,u):h=Math.min(l,u);const f={};Object.defineProperty(f,"maxMessageSize",{get(){return h}}),this._sctp=f}return a.apply(this,arguments)}}function di(n){if(!(n.RTCPeerConnection&&"createDataChannel"in n.RTCPeerConnection.prototype))return;function e(i,r){const s=i.send;i.send=function(){const o=arguments[0],c=o.length||o.size||o.byteLength;if(i.readyState==="open"&&r.sctp&&c>r.sctp.maxMessageSize)throw new TypeError("Message too large (can send a maximum of "+r.sctp.maxMessageSize+" bytes)");return s.apply(i,arguments)}}const t=n.RTCPeerConnection.prototype.createDataChannel;n.RTCPeerConnection.prototype.createDataChannel=function(){const r=t.apply(this,arguments);return e(r,this),r},Xt(n,"datachannel",i=>(e(i.channel,i.target),i))}function On(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 i=e[t];e[t]=function(){return this._connectionstatechangepoly||(this._connectionstatechangepoly=r=>{const s=r.target;if(s._lastConnectionState!==s.connectionState){s._lastConnectionState=s.connectionState;const a=new Event("connectionstatechange",r);s.dispatchEvent(a)}return r},this.addEventListener("iceconnectionstatechange",this._connectionstatechangepoly)),i.apply(this,arguments)}})}function Bn(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 s=r.sdp.split(`
71
- `).filter(a=>a.trim()!=="a=extmap-allow-mixed").join(`
72
- `);n.RTCSessionDescription&&r instanceof n.RTCSessionDescription?arguments[0]=new n.RTCSessionDescription({type:r.type,sdp:s}):r.sdp=s}return t.apply(this,arguments)}}function kr(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 Da=Object.freeze(Object.defineProperty({__proto__:null,removeExtmapAllowMixed:Bn,shimAddIceCandidateNullOrEmpty:kr,shimConnectionState:On,shimMaxMessageSize:fi,shimRTCIceCandidate:Rr,shimSendThrowTypeError:di},Symbol.toStringTag,{value:"Module"}));function La({window:n}={},e={shimChrome:!0,shimFirefox:!0,shimEdge:!0,shimSafari:!0}){const t=Zn,i=Aa(n),r={browserDetails:i,commonShim:Da,extractVersion:hi,disableLog:Ra,disableWarnings:ka};switch(i.browser){case"chrome":if(!gs||!kn||!e.shimChrome)return t("Chrome shim is not included in this adapter release."),r;if(i.version===null)return t("Chrome shim can not determine version, not shimming."),r;t("adapter.js shimming chrome."),r.browserShim=gs,kr(n,i),_o(n,i),xo(n),kn(n,i),bo(n),Po(n,i),So(n),To(n),Mo(n),wo(n,i),Rr(n),On(n),fi(n,i),di(n),Bn(n,i);break;case"firefox":if(!bs||!zn||!e.shimFirefox)return t("Firefox shim is not included in this adapter release."),r;t("adapter.js shimming firefox."),r.browserShim=bs,kr(n,i),zo(n,i),zn(n,i),Oo(n),No(n),Bo(n),Io(n),Uo(n),Fo(n),Do(n),Lo(n),Vo(n),Rr(n),On(n),fi(n,i),di(n);break;case"edge":if(!xs||!An||!e.shimEdge)return t("MS edge shim is not included in this adapter release."),r;t("adapter.js shimming edge."),r.browserShim=xs,Ro(n),ko(n),An(n,i),Ao(n),fi(n,i),di(n);break;case"safari":if(!Ss||!e.shimSafari)return t("Safari shim is not included in this adapter release."),r;t("adapter.js shimming safari."),r.browserShim=Ss,kr(n,i),Xo(n),Wo(n),jo(n),Jo(n),Go(n),Ho(n),$o(n),Yo(n),Rr(n),fi(n,i),di(n),Bn(n,i);break;default:t("Unsupported browser!");break}return r}const Ts=La({window:typeof window>"u"?void 0:window});function We(n,e,t,i){Object.defineProperty(n,e,{get:t,set:i,enumerable:!0,configurable:!0})}var en=Ts.default||Ts,ei=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(),i=this.supportedBrowsers.includes(e);return i?e==="chrome"?t>=this.minChromeVersion:e==="firefox"?t>=this.minFirefoxVersion:e==="safari"?!this.isIOS&&t>=this.minSafariVersion:!1:!1},n.prototype.getBrowser=function(){return en.browserDetails.browser},n.prototype.getVersion=function(){return en.browserDetails.version||0},n.prototype.isUnifiedPlanSupported=function(){var e=this.getBrowser(),t=en.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 i,r=!1;try{i=new RTCPeerConnection,i.addTransceiver("audio"),r=!0}catch{}finally{i&&i.close()}return r},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})()),Ms={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"},Va=(function(){function n(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=Ms,this.browser=ei.getBrowser(),this.browserVersion=ei.getVersion(),this.supports=(function(){var e={browser:ei.isBrowserSupported(),webRTC:ei.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(Ms),e.audioVideo=!0;var i=void 0;try{i=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!i.ordered;try{i.binaryType="blob",e.binaryBlob=!ei.isIOS}catch{}}catch{}finally{i&&i.close()}}catch{}finally{t&&t.close()}return e})(),this.pack=ds.pack,this.unpack=ds.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=[],i=e.size,r=Math.ceil(i/D.chunkedMTU),s=0,a=0;a<i;){var o=Math.min(i,a+D.chunkedMTU),c=e.slice(a,o),l={__peerData:this._dataCount,n:s,data:c,total:r};t.push(l),a=o,s++}return this._dataCount++,t},n.prototype.blobToArrayBuffer=function(e,t){var i=new FileReader;return i.onload=function(r){r.target&&t(r.target.result)},i.readAsArrayBuffer(e),i},n.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),i=0;i<e.length;i++)t[i]=e.charCodeAt(i)&255;return t.buffer},n.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},n.prototype.isSecure=function(){return location.protocol==="https:"},n})(),D=new Va,Zo={};We(Zo,"Peer",()=>Un,n=>Un=n);var Qi={},Ja=Object.prototype.hasOwnProperty,ge="~";function xi(){}Object.create&&(xi.prototype=Object.create(null),new xi().__proto__||(ge=!1));function Ga(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function Ko(n,e,t,i,r){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new Ga(t,i||n,r),a=ge?ge+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 Ar(n,e){--n._eventsCount===0?n._events=new xi:delete n._events[e]}function fe(){this._events=new xi,this._eventsCount=0}fe.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)Ja.call(t,i)&&e.push(ge?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};fe.prototype.listeners=function(e){var t=ge?ge+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var r=0,s=i.length,a=new Array(s);r<s;r++)a[r]=i[r].fn;return a};fe.prototype.listenerCount=function(e){var t=ge?ge+e:e,i=this._events[t];return i?i.fn?1:i.length:0};fe.prototype.emit=function(e,t,i,r,s,a){var o=ge?ge+e:e;if(!this._events[o])return!1;var c=this._events[o],l=arguments.length,u,h;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,i),!0;case 4:return c.fn.call(c.context,t,i,r),!0;case 5:return c.fn.call(c.context,t,i,r,s),!0;case 6:return c.fn.call(c.context,t,i,r,s,a),!0}for(h=1,u=new Array(l-1);h<l;h++)u[h-1]=arguments[h];c.fn.apply(c.context,u)}else{var f=c.length,d;for(h=0;h<f;h++)switch(c[h].once&&this.removeListener(e,c[h].fn,void 0,!0),l){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,t);break;case 3:c[h].fn.call(c[h].context,t,i);break;case 4:c[h].fn.call(c[h].context,t,i,r);break;default:if(!u)for(d=1,u=new Array(l-1);d<l;d++)u[d-1]=arguments[d];c[h].fn.apply(c[h].context,u)}}return!0};fe.prototype.on=function(e,t,i){return Ko(this,e,t,i,!1)};fe.prototype.once=function(e,t,i){return Ko(this,e,t,i,!0)};fe.prototype.removeListener=function(e,t,i,r){var s=ge?ge+e:e;if(!this._events[s])return this;if(!t)return Ar(this,s),this;var a=this._events[s];if(a.fn)a.fn===t&&(!r||a.once)&&(!i||a.context===i)&&Ar(this,s);else{for(var o=0,c=[],l=a.length;o<l;o++)(a[o].fn!==t||r&&!a[o].once||i&&a[o].context!==i)&&c.push(a[o]);c.length?this._events[s]=c.length===1?c[0]:c:Ar(this,s)}return this};fe.prototype.removeAllListeners=function(e){var t;return e?(t=ge?ge+e:e,this._events[t]&&Ar(this,t)):(this._events=new xi,this._eventsCount=0),this};fe.prototype.off=fe.prototype.removeListener;fe.prototype.addListener=fe.prototype.on;fe.prefixed=ge;fe.EventEmitter=fe;Qi=fe;var O={};We(O,"LogLevel",()=>xe,n=>xe=n);We(O,"default",()=>Cs,n=>Cs=n);var xt=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var i=t.call(n),r,s=[],a;try{for(;(e===void 0||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(o){a={error:o}}finally{try{r&&!r.done&&(t=i.return)&&t.call(i)}finally{if(a)throw a.error}}return s},bt=function(n,e,t){if(t||arguments.length===2)for(var i=0,r=e.length,s;i<r;i++)(s||!(i in e))&&(s||(s=Array.prototype.slice.call(e,0,i)),s[i]=e[i]);return n.concat(s||Array.prototype.slice.call(e))},ja="PeerJS: ",xe;(function(n){n[n.Disabled=0]="Disabled",n[n.Errors=1]="Errors",n[n.Warnings=2]="Warnings",n[n.All=3]="All"})(xe||(xe={}));var $a=(function(){function n(){this._logLevel=xe.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>=xe.All&&this._print.apply(this,bt([xe.All],xt(e),!1))},n.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=xe.Warnings&&this._print.apply(this,bt([xe.Warnings],xt(e),!1))},n.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=xe.Errors&&this._print.apply(this,bt([xe.Errors],xt(e),!1))},n.prototype.setLogFunction=function(e){this._print=e},n.prototype._print=function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];var r=bt([ja],xt(t),!1);for(var s in r)r[s]instanceof Error&&(r[s]="("+r[s].name+") "+r[s].message);e>=xe.All?console.log.apply(console,bt([],xt(r),!1)):e>=xe.Warnings?console.warn.apply(console,bt(["WARNING"],xt(r),!1)):e>=xe.Errors&&console.error.apply(console,bt(["ERROR"],xt(r),!1))},n})(),Cs=new $a,Qo={};We(Qo,"Socket",()=>Ps,n=>Ps=n);var Fe;(function(n){n.Data="data",n.Media="media"})(Fe||(Fe={}));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 ot;(function(n){n.Binary="binary",n.BinaryUTF8="binary-utf8",n.JSON="json"})(ot||(ot={}));var ct;(function(n){n.Message="message",n.Disconnected="disconnected",n.Error="error",n.Close="close"})(ct||(ct={}));var ue;(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"})(ue||(ue={}));var Kn={};Kn=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ückler <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>","Sören 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 qa=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,r){i.__proto__=r}||function(i,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[s]=r[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 i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}})(),Xa=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var i=t.call(n),r,s=[],a;try{for(;(e===void 0||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(o){a={error:o}}finally{try{r&&!r.done&&(t=i.return)&&t.call(i)}finally{if(a)throw a.error}}return s},Ha=function(n,e,t){if(t||arguments.length===2)for(var i=0,r=e.length,s;i<r;i++)(s||!(i in e))&&(s||(s=Array.prototype.slice.call(e,0,i)),s[i]=e[i]);return n.concat(s||Array.prototype.slice.call(e))},Wa=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ps=(function(n){qa(e,n);function e(t,i,r,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+i+":"+r+s+"peerjs?key="+a,c}return e.prototype.start=function(t,i){var r=this;this._id=t;var s="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(i);this._socket||!this._disconnected||(this._socket=new WebSocket(s+"&version="+Kn.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}r.emit(ct.Message,o)},this._socket.onclose=function(a){r._disconnected||(O.default.log("Socket closed.",a),r._cleanup(),r._disconnected=!0,r.emit(ct.Disconnected))},this._socket.onopen=function(){r._disconnected||(r._sendQueuedMessages(),O.default.log("Socket open"),r._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:ue.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,i,r=Ha([],Xa(this._messagesQueue),!1);this._messagesQueue=[];try{for(var s=Wa(r),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&&(i=s.return)&&i.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(ct.Error,"Invalid message");return}if(this._wsOpen()){var i=JSON.stringify(t);this._socket.send(i)}}},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})(Qi.EventEmitter),In={};We(In,"MediaConnection",()=>Rs,n=>Rs=n);var Qn={};We(Qn,"Negotiator",()=>ws,n=>ws=n);var Or=function(){return Or=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},Or.apply(this,arguments)},rr=function(n,e,t,i){function r(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(i.next(u))}catch(h){a(h)}}function c(u){try{l(i.throw(u))}catch(h){a(h)}}function l(u){u.done?s(u.value):r(u.value).then(o,c)}l((i=i.apply(n,e||[])).next())})},nr=function(n,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},i,r,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,r&&(s=l[0]&2?r.return:l[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,l[1])).done)return s;switch(r=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++,r=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(u){l=[6,u],r=0}finally{i=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},ws=(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===Fe.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===Fe.Data){var i=this.connection,r={ordered:!!e.reliable},s=t.createDataChannel(i.label,r);i.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,i=this.connection.peer,r=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(i,":"),o.candidate),a.socket.send({type:ue.Candidate,payload:{candidate:o.candidate,type:s,connectionId:r},dst:i}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":O.default.log("iceConnectionState is failed, closing connections to "+i),t.connection.emit("error",new Error("Negotiation of connection to "+i+" failed.")),t.connection.close();break;case"closed":O.default.log("iceConnectionState is closed, closing connections to "+i),t.connection.emit("error",new Error("Connection to "+i+" closed.")),t.connection.close();break;case"disconnected":O.default.log("iceConnectionState changed to disconnected on the connection with "+i);break;case"completed":e.onicecandidate=D.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(i,r);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(i,r);if(l.type===Fe.Media){var u=l;t._addStreamToMediaConnection(c,u)}}},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",i=!1;if(this.connection.type===Fe.Data){var r=this.connection,s=r.dataChannel;s&&(i=!!s.readyState&&s.readyState!=="closed")}(t||i)&&e.close()}},n.prototype._makeOffer=function(){return rr(this,void 0,Promise,function(){var e,t,i,r,s,a,o;return nr(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:i=c.sent(),O.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(i.sdp=this.connection.options.sdpTransform(i.sdp)||i.sdp),c.label=3;case 3:return c.trys.push([3,5,,6]),[4,e.setLocalDescription(i)];case 4:return c.sent(),O.default.log("Set localDescription:",i,"for:".concat(this.connection.peer)),r={sdp:i,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:D.browser},this.connection.type===Fe.Data&&(s=this.connection,r=Or(Or({},r),{label:s.label,reliable:s.reliable,serialization:s.serialization})),t.socket.send({type:ue.Offer,payload:r,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 rr(this,void 0,Promise,function(){var e,t,i,r,s;return nr(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:i=a.sent(),O.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(i.sdp=this.connection.options.sdpTransform(i.sdp)||i.sdp),a.label=3;case 3:return a.trys.push([3,5,,6]),[4,e.setLocalDescription(i)];case 4:return a.sent(),O.default.log("Set localDescription:",i,"for:".concat(this.connection.peer)),t.socket.send({type:ue.Answer,payload:{sdp:i,type:this.connection.type,connectionId:this.connection.connectionId,browser:D.browser},dst:this.connection.peer}),[3,6];case 5:return r=a.sent(),t.emitError(K.WebRTC,r),O.default.log("Failed to setLocalDescription, ",r),[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 rr(this,void 0,Promise,function(){var i,r,s,a;return nr(this,function(o){switch(o.label){case 0:t=new RTCSessionDescription(t),i=this.connection.peerConnection,r=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,i.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(),r.emitError(K.WebRTC,a),O.default.log("Failed to setRemoteDescription, ",a),[3,6];case 6:return[2]}})})},n.prototype.handleCandidate=function(e){return rr(this,void 0,Promise,function(){var t,i,r,s,a,o;return nr(this,function(c){switch(c.label){case 0:O.default.log("handleCandidate:",e),t=e.candidate,i=e.sdpMLineIndex,r=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:r,sdpMLineIndex:i,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(i){t.addTrack(i,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})(),es={};We(es,"BaseConnection",()=>Es,n=>Es=n);var Ya=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,r){i.__proto__=r}||function(i,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[s]=r[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 i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}})(),Es=(function(n){Ya(e,n);function e(t,i,r){var s=n.call(this)||this;return s.peer=t,s.provider=i,s.options=r,s._open=!1,s.metadata=r.metadata,s}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e})(Qi.EventEmitter),Za=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,r){i.__proto__=r}||function(i,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[s]=r[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 i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}})(),Br=function(){return Br=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},Br.apply(this,arguments)},Ka=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Rs=(function(n){Za(e,n);function e(t,i,r){var s=n.call(this,t,i,r)||this;return s._localStream=s.options._stream,s.connectionId=s.options.connectionId||e.ID_PREFIX+D.randomToken(),s._negotiator=new Qn.Negotiator(s),s._localStream&&s._negotiator.startConnection({_stream:s._localStream,originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return Fe.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 i=t.type,r=t.payload;switch(t.type){case ue.Answer:this._negotiator.handleSDP(i,r.sdp),this._open=!0;break;case ue.Candidate:this._negotiator.handleCandidate(r.candidate);break;default:O.default.warn("Unrecognized message type:".concat(i," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,i){var r,s;if(i===void 0&&(i={}),this._localStream){O.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,i&&i.sdpTransform&&(this.options.sdpTransform=i.sdpTransform),this._negotiator.startConnection(Br(Br({},this.options._payload),{_stream:t}));var a=this.provider._getMessages(this.connectionId);try{for(var o=Ka(a),c=o.next();!c.done;c=o.next()){var l=c.value;this.handleMessage(l)}}catch(u){r={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(r)throw r.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})(es.BaseConnection),Nn={};We(Nn,"DataConnection",()=>As,n=>As=n);var ea={};We(ea,"EncodingQueue",()=>ks,n=>ks=n);var Qa=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,r){i.__proto__=r}||function(i,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[s]=r[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 i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}})(),ks=(function(n){Qa(e,n);function e(){var t=n.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(i){t._processing=!1,i.target&&t.emit("done",i.target.result),t.doNextTask()},t.fileReader.onerror=function(i){O.default.error("EncodingQueue error:",i),t._processing=!1,t.destroy(),t.emit("error",i)},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})(Qi.EventEmitter),ec=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,r){i.__proto__=r}||function(i,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[s]=r[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 i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}})(),tc=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},As=(function(n){ec(e,n);function e(t,i,r){var s=n.call(this,t,i,r)||this;return s.stringify=JSON.stringify,s.parse=JSON.parse,s._buffer=[],s._bufferSize=0,s._buffering=!1,s._chunkedData={},s._encodingQueue=new ea.EncodingQueue,s.connectionId=s.options.connectionId||e.ID_PREFIX+D.randomToken(),s.label=s.options.label||s.connectionId,s.serialization=s.options.serialization||ot.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 Qn.Negotiator(s),s._negotiator.startConnection(s.options._payload||{originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return Fe.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;(!D.supports.binaryBlob||D.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(i){O.default.log("DC#".concat(t.connectionId," dc onmessage:"),i.data),t._handleDataMessage(i)},this.dataChannel.onclose=function(){O.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var i=this,r=t.data,s=r.constructor,a=this.serialization===ot.Binary||this.serialization===ot.BinaryUTF8,o=r;if(a){if(s===Blob){D.blobToArrayBuffer(r,function(l){var u=D.unpack(l);i.emit("data",u)});return}else if(s===ArrayBuffer)o=D.unpack(r);else if(s===String){var c=D.binaryStringToArrayBuffer(r);o=D.unpack(c)}}else this.serialization===ot.JSON&&(o=this.parse(r));if(o.__peerData){this._handleChunk(o);return}n.prototype.emit.call(this,"data",o)},e.prototype._handleChunk=function(t){var i=t.__peerData,r=this._chunkedData[i]||{data:[],count:0,total:t.total};if(r.data[t.n]=t.data,r.count++,this._chunkedData[i]=r,r.total===r.count){delete this._chunkedData[i];var s=new Blob(r.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,i){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===ot.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===ot.Binary||this.serialization===ot.BinaryUTF8){var r=D.pack(t);if(!i&&r.size>D.chunkedMTU){this._sendChunks(r);return}D.supports.binaryBlob?this._bufferedSend(r):this._encodingQueue.enque(r)}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 i=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){i._buffering=!1,i._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(r){return O.default.error("DC#:".concat(this.connectionId," Error when sending:"),r),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 i,r,s=D.chunk(t);O.default.log("DC#".concat(this.connectionId," Try to send ").concat(s.length," chunks..."));try{for(var a=tc(s),o=a.next();!o.done;o=a.next()){var c=o.value;this.send(c,!0)}}catch(l){i={error:l}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}},e.prototype.handleMessage=function(t){var i=t.payload;switch(t.type){case ue.Answer:this._negotiator.handleSDP(t.type,i.sdp);break;case ue.Candidate:this._negotiator.handleCandidate(i.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})(es.BaseConnection),ta={};We(ta,"API",()=>Bs,n=>Bs=n);var zs=function(n,e,t,i){function r(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(i.next(u))}catch(h){a(h)}}function c(u){try{l(i.throw(u))}catch(h){a(h)}}function l(u){u.done?s(u.value):r(u.value).then(o,c)}l((i=i.apply(n,e||[])).next())})},Os=function(n,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},i,r,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,r&&(s=l[0]&2?r.return:l[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,l[1])).done)return s;switch(r=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++,r=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(u){l=[6,u],r=0}finally{i=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},Bs=(function(){function n(e){this._options=e}return n.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",i=this._options,r=i.host,s=i.port,a=i.path,o=i.key,c=new URL("".concat(t,"://").concat(r,":").concat(s).concat(a).concat(o,"/").concat(e));return c.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),c.searchParams.set("version",Kn.version),fetch(c.href,{referrerPolicy:this._options.referrerPolicy})},n.prototype.retrieveId=function(){return zs(this,void 0,Promise,function(){var e,t,i;return Os(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=r.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=r.sent(),O.default.error("Error retrieving ID",t),i="",this._options.path==="/"&&this._options.host!==D.CLOUD_HOST&&(i=" 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."+i);case 3:return[2]}})})},n.prototype.listAllPeers=function(){return zs(this,void 0,Promise,function(){var e,t,i;return Os(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=r.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===D.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 i=r.sent(),O.default.error("Error retrieving list peers",i),new Error("Could not get list peers from the server."+i);case 3:return[2]}})})},n})(),ic=(function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,r){i.__proto__=r}||function(i,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[s]=r[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 i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}})(),yi=function(){return yi=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},yi.apply(this,arguments)},ti=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],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 i=t.call(n),r,s=[],a;try{for(;(e===void 0||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(o){a={error:o}}finally{try{r&&!r.done&&(t=i.return)&&t.call(i)}finally{if(a)throw a.error}}return s},Un=(function(n){ic(e,n);function e(t,i){var r=n.call(this)||this;r._id=null,r._lastServerId=null,r._destroyed=!1,r._disconnected=!1,r._open=!1,r._connections=new Map,r._lostMessages=new Map;var s;return t&&t.constructor==Object?i=t:t&&(s=t.toString()),i=yi({debug:0,host:D.CLOUD_HOST,port:D.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:D.randomToken(),config:D.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},i),r._options=i,r._options.host==="/"&&(r._options.host=window.location.hostname),r._options.path&&(r._options.path[0]!=="/"&&(r._options.path="/"+r._options.path),r._options.path[r._options.path.length-1]!=="/"&&(r._options.path+="/")),r._options.secure===void 0&&r._options.host!==D.CLOUD_HOST?r._options.secure=D.isSecure():r._options.host==D.CLOUD_HOST&&(r._options.secure=!0),r._options.logFunction&&O.default.setLogFunction(r._options.logFunction),O.default.logLevel=r._options.debug||0,r._api=new ta.API(i),r._socket=r._createServerConnection(),!D.supports.audioVideo&&!D.supports.data?(r._delayedAbort(K.BrowserIncompatible,"The current browser does not support WebRTC"),r):s&&!D.validateId(s)?(r._delayedAbort(K.InvalidID,'ID "'.concat(s,'" is invalid')),r):(s?r._initialize(s):r._api.retrieveId().then(function(a){return r._initialize(a)}).catch(function(a){return r._abort(K.ServerError,a)}),r)}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,i,r=Object.create(null);try{for(var s=ti(this._connections),a=s.next();!a.done;a=s.next()){var o=rc(a.value,2),c=o[0],l=o[1];r[c]=l}}catch(u){t={error:u}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(t)throw t.error}}return r},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,i=new Qo.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return i.on(ct.Message,function(r){t._handleMessage(r)}),i.on(ct.Error,function(r){t._abort(K.SocketError,r)}),i.on(ct.Disconnected,function(){t.disconnected||(t.emitError(K.Network,"Lost connection to server."),t.disconnect())}),i.on(ct.Close,function(){t.disconnected||t._abort(K.SocketClosed,"Underlying socket is already closed.")}),i},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var i,r,s=t.type,a=t.payload,o=t.src;switch(s){case ue.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case ue.Error:this._abort(K.ServerError,a.msg);break;case ue.IdTaken:this._abort(K.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case ue.InvalidKey:this._abort(K.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case ue.Leave:O.default.log("Received leave message from ".concat(o)),this._cleanupPeer(o),this._connections.delete(o);break;case ue.Expire:this.emitError(K.PeerUnavailable,"Could not connect to peer ".concat(o));break;case ue.Offer:var y=a.connectionId,_=this.getConnection(o,y);if(_&&(_.close(),O.default.warn("Offer received for existing Connection ID:".concat(y))),a.type===Fe.Media){var c=new In.MediaConnection(o,this,{connectionId:y,_payload:a,metadata:a.metadata});_=c,this._addConnection(o,_),this.emit("call",c)}else if(a.type===Fe.Data){var l=new Nn.DataConnection(o,this,{connectionId:y,_payload:a,metadata:a.metadata,label:a.label,serialization:a.serialization,reliable:a.reliable});_=l,this._addConnection(o,_),this.emit("connection",l)}else{O.default.warn("Received malformed connection type:".concat(a.type));return}var u=this._getMessages(y);try{for(var h=ti(u),f=h.next();!f.done;f=h.next()){var d=f.value;_.handleMessage(d)}}catch(p){i={error:p}}finally{try{f&&!f.done&&(r=h.return)&&r.call(h)}finally{if(i)throw i.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,_=this.getConnection(o,y);_&&_.peerConnection?_.handleMessage(t):y?this._storeMessage(y,t):O.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,i){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(i)},e.prototype._getMessages=function(t){var i=this._lostMessages.get(t);return i?(this._lostMessages.delete(t),i):[]},e.prototype.connect=function(t,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, 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 r=new Nn.DataConnection(t,this,i);return this._addConnection(t,r),r},e.prototype.call=function(t,i,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."),this.emitError(K.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!i){O.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var s=new In.MediaConnection(t,this,yi(yi({},r),{_stream:i}));return this._addConnection(t,s),s},e.prototype._addConnection=function(t,i){O.default.log("add connection ".concat(i.type,":").concat(i.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(i)},e.prototype._removeConnection=function(t){var i=this._connections.get(t.peer);if(i){var r=i.indexOf(t);r!==-1&&i.splice(r,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,i){var r,s,a=this._connections.get(t);if(!a)return null;try{for(var o=ti(a),c=o.next();!c.done;c=o.next()){var l=c.value;if(l.connectionId===i)return l}}catch(u){r={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(r)throw r.error}}return null},e.prototype._delayedAbort=function(t,i){var r=this;setTimeout(function(){r._abort(t,i)},0)},e.prototype._abort=function(t,i){O.default.error("Aborting!"),this.emitError(t,i),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,i){O.default.error("Error:",i);var r;typeof i=="string"?r=new Error(i):r=i,r.type=t,this.emit("error",r)},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,i;try{for(var r=ti(this._connections.keys()),s=r.next();!s.done;s=r.next()){var a=s.value;this._cleanupPeer(a),this._connections.delete(a)}}catch(o){t={error:o}}finally{try{s&&!s.done&&(i=r.return)&&i.call(r)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var i,r,s=this._connections.get(t);if(s)try{for(var a=ti(s),o=a.next();!o.done;o=a.next()){var c=o.value;c.close()}}catch(l){i={error:l}}finally{try{o&&!o.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.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 i=this;t===void 0&&(t=function(r){}),this._api.listAllPeers().then(function(r){return t(r)}).catch(function(r){return i._abort(K.ServerError,r)})},e.DEFAULT_KEY="peerjs",e})(Qi.EventEmitter),ia=Zo.Peer;const nc=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return Un},default:ia,util:D},Symbol.toStringTag,{value:"Module"})),sc=/^(?:[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 oc(n){return typeof n=="string"&&sc.test(n)}const le=[];for(let n=0;n<256;++n)le.push((n+256).toString(16).slice(1));function ac(n,e=0){return le[n[e+0]]+le[n[e+1]]+le[n[e+2]]+le[n[e+3]]+"-"+le[n[e+4]]+le[n[e+5]]+"-"+le[n[e+6]]+le[n[e+7]]+"-"+le[n[e+8]]+le[n[e+9]]+"-"+le[n[e+10]]+le[n[e+11]]+le[n[e+12]]+le[n[e+13]]+le[n[e+14]]+le[n[e+15]]}function cc(n){if(!oc(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 lc(n){n=unescape(encodeURIComponent(n));const e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}const uc="6ba7b810-9dad-11d1-80b4-00c04fd430c8",hc="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function fc(n,e,t){function i(r,s,a,o){var c;if(typeof r=="string"&&(r=lc(r)),typeof s=="string"&&(s=cc(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+r.length);if(l.set(s),l.set(r,s.length),l=t(l),l[6]=l[6]&15|e,l[8]=l[8]&63|128,a){o=o||0;for(let u=0;u<16;++u)a[o+u]=l[u];return a}return ac(l)}try{i.name=n}catch{}return i.DNS=uc,i.URL=hc,i}function dc(n,e,t,i){switch(n){case 0:return e&t^~e&i;case 1:return e^t^i;case 2:return e&t^e&i^t&i;case 3:return e^t^i}}function tn(n,e){return n<<e|n>>>32-e}function pc(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 i=n.length/4+2,r=Math.ceil(i/16),s=new Array(r);for(let a=0;a<r;++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[r-1][14]=(n.length-1)*8/Math.pow(2,32),s[r-1][14]=Math.floor(s[r-1][14]),s[r-1][15]=(n.length-1)*8&4294967295;for(let a=0;a<r;++a){const o=new Uint32Array(80);for(let d=0;d<16;++d)o[d]=s[a][d];for(let d=16;d<80;++d)o[d]=tn(o[d-3]^o[d-8]^o[d-14]^o[d-16],1);let c=t[0],l=t[1],u=t[2],h=t[3],f=t[4];for(let d=0;d<80;++d){const y=Math.floor(d/20),_=tn(c,5)+dc(y,l,u,h)+f+e[y]+o[d]>>>0;f=h,h=u,u=tn(l,30)>>>0,l=c,c=_}t[0]=t[0]+c>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+h>>>0,t[4]=t[4]+f>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const mc=fc("v5",80,pc);var rn={exports:{}},nn={exports:{}},Is;function yc(){return Is||(Is=1,(function(){var n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e={rotl:function(t,i){return t<<i|t>>>32-i},rotr:function(t,i){return t<<32-i|t>>>i},endian:function(t){if(t.constructor==Number)return e.rotl(t,8)&16711935|e.rotl(t,24)&4278255360;for(var i=0;i<t.length;i++)t[i]=e.endian(t[i]);return t},randomBytes:function(t){for(var i=[];t>0;t--)i.push(Math.floor(Math.random()*256));return i},bytesToWords:function(t){for(var i=[],r=0,s=0;r<t.length;r++,s+=8)i[s>>>5]|=t[r]<<24-s%32;return i},wordsToBytes:function(t){for(var i=[],r=0;r<t.length*32;r+=8)i.push(t[r>>>5]>>>24-r%32&255);return i},bytesToHex:function(t){for(var i=[],r=0;r<t.length;r++)i.push((t[r]>>>4).toString(16)),i.push((t[r]&15).toString(16));return i.join("")},hexToBytes:function(t){for(var i=[],r=0;r<t.length;r+=2)i.push(parseInt(t.substr(r,2),16));return i},bytesToBase64:function(t){for(var i=[],r=0;r<t.length;r+=3)for(var s=t[r]<<16|t[r+1]<<8|t[r+2],a=0;a<4;a++)r*8+a*6<=t.length*8?i.push(n.charAt(s>>>6*(3-a)&63)):i.push("=");return i.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/ig,"");for(var i=[],r=0,s=0;r<t.length;s=++r%4)s!=0&&i.push((n.indexOf(t.charAt(r-1))&Math.pow(2,-2*s+8)-1)<<s*2|n.indexOf(t.charAt(r))>>>6-s*2);return i}};nn.exports=e})()),nn.exports}var sn,Ns;function Us(){if(Ns)return sn;Ns=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=[],i=0;i<e.length;i++)t.push(e.charCodeAt(i)&255);return t},bytesToString:function(e){for(var t=[],i=0;i<e.length;i++)t.push(String.fromCharCode(e[i]));return t.join("")}}};return sn=n,sn}/*!
79
- * Determine if an object is a Buffer
80
- *
81
- * @author Feross Aboukhadijeh <https://feross.org>
82
- * @license MIT
83
- */var on,Fs;function gc(){if(Fs)return on;Fs=1,on=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 on}var Ds;function vc(){return Ds||(Ds=1,(function(){var n=yc(),e=Us().utf8,t=gc(),i=Us().bin,r=function(s,a){s.constructor==String?a&&a.encoding==="binary"?s=i.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,u=-271733879,h=-1732584194,f=271733878,d=0;d<o.length;d++)o[d]=(o[d]<<8|o[d]>>>24)&16711935|(o[d]<<24|o[d]>>>8)&4278255360;o[c>>>5]|=128<<c%32,o[(c+64>>>9<<4)+14]=c;for(var y=r._ff,_=r._gg,p=r._hh,m=r._ii,d=0;d<o.length;d+=16){var v=l,g=u,b=h,x=f;l=y(l,u,h,f,o[d+0],7,-680876936),f=y(f,l,u,h,o[d+1],12,-389564586),h=y(h,f,l,u,o[d+2],17,606105819),u=y(u,h,f,l,o[d+3],22,-1044525330),l=y(l,u,h,f,o[d+4],7,-176418897),f=y(f,l,u,h,o[d+5],12,1200080426),h=y(h,f,l,u,o[d+6],17,-1473231341),u=y(u,h,f,l,o[d+7],22,-45705983),l=y(l,u,h,f,o[d+8],7,1770035416),f=y(f,l,u,h,o[d+9],12,-1958414417),h=y(h,f,l,u,o[d+10],17,-42063),u=y(u,h,f,l,o[d+11],22,-1990404162),l=y(l,u,h,f,o[d+12],7,1804603682),f=y(f,l,u,h,o[d+13],12,-40341101),h=y(h,f,l,u,o[d+14],17,-1502002290),u=y(u,h,f,l,o[d+15],22,1236535329),l=_(l,u,h,f,o[d+1],5,-165796510),f=_(f,l,u,h,o[d+6],9,-1069501632),h=_(h,f,l,u,o[d+11],14,643717713),u=_(u,h,f,l,o[d+0],20,-373897302),l=_(l,u,h,f,o[d+5],5,-701558691),f=_(f,l,u,h,o[d+10],9,38016083),h=_(h,f,l,u,o[d+15],14,-660478335),u=_(u,h,f,l,o[d+4],20,-405537848),l=_(l,u,h,f,o[d+9],5,568446438),f=_(f,l,u,h,o[d+14],9,-1019803690),h=_(h,f,l,u,o[d+3],14,-187363961),u=_(u,h,f,l,o[d+8],20,1163531501),l=_(l,u,h,f,o[d+13],5,-1444681467),f=_(f,l,u,h,o[d+2],9,-51403784),h=_(h,f,l,u,o[d+7],14,1735328473),u=_(u,h,f,l,o[d+12],20,-1926607734),l=p(l,u,h,f,o[d+5],4,-378558),f=p(f,l,u,h,o[d+8],11,-2022574463),h=p(h,f,l,u,o[d+11],16,1839030562),u=p(u,h,f,l,o[d+14],23,-35309556),l=p(l,u,h,f,o[d+1],4,-1530992060),f=p(f,l,u,h,o[d+4],11,1272893353),h=p(h,f,l,u,o[d+7],16,-155497632),u=p(u,h,f,l,o[d+10],23,-1094730640),l=p(l,u,h,f,o[d+13],4,681279174),f=p(f,l,u,h,o[d+0],11,-358537222),h=p(h,f,l,u,o[d+3],16,-722521979),u=p(u,h,f,l,o[d+6],23,76029189),l=p(l,u,h,f,o[d+9],4,-640364487),f=p(f,l,u,h,o[d+12],11,-421815835),h=p(h,f,l,u,o[d+15],16,530742520),u=p(u,h,f,l,o[d+2],23,-995338651),l=m(l,u,h,f,o[d+0],6,-198630844),f=m(f,l,u,h,o[d+7],10,1126891415),h=m(h,f,l,u,o[d+14],15,-1416354905),u=m(u,h,f,l,o[d+5],21,-57434055),l=m(l,u,h,f,o[d+12],6,1700485571),f=m(f,l,u,h,o[d+3],10,-1894986606),h=m(h,f,l,u,o[d+10],15,-1051523),u=m(u,h,f,l,o[d+1],21,-2054922799),l=m(l,u,h,f,o[d+8],6,1873313359),f=m(f,l,u,h,o[d+15],10,-30611744),h=m(h,f,l,u,o[d+6],15,-1560198380),u=m(u,h,f,l,o[d+13],21,1309151649),l=m(l,u,h,f,o[d+4],6,-145523070),f=m(f,l,u,h,o[d+11],10,-1120210379),h=m(h,f,l,u,o[d+2],15,718787259),u=m(u,h,f,l,o[d+9],21,-343485551),l=l+v>>>0,u=u+g>>>0,h=h+b>>>0,f=f+x>>>0}return n.endian([l,u,h,f])};r._ff=function(s,a,o,c,l,u,h){var f=s+(a&o|~a&c)+(l>>>0)+h;return(f<<u|f>>>32-u)+a},r._gg=function(s,a,o,c,l,u,h){var f=s+(a&c|o&~c)+(l>>>0)+h;return(f<<u|f>>>32-u)+a},r._hh=function(s,a,o,c,l,u,h){var f=s+(a^o^c)+(l>>>0)+h;return(f<<u|f>>>32-u)+a},r._ii=function(s,a,o,c,l,u,h){var f=s+(o^(a|~c))+(l>>>0)+h;return(f<<u|f>>>32-u)+a},r._blocksize=16,r._digestsize=16,rn.exports=function(s,a){if(s==null)throw new Error("Illegal argument "+s);var o=n.wordsToBytes(r(s,a));return a&&a.asBytes?o:a&&a.asString?i.bytesToString(o):n.bytesToHex(o)}})()),rn.exports}var _c=vc();const xc=Gr(_c),he=["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 Ls=1234567;const ra=Math.PI/180,na=180/Math.PI;function bc(){const n=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,i=Math.random()*4294967295|0;return(he[n&255]+he[n>>8&255]+he[n>>16&255]+he[n>>24&255]+"-"+he[e&255]+he[e>>8&255]+"-"+he[e>>16&15|64]+he[e>>24&255]+"-"+he[t&63|128]+he[t>>8&255]+"-"+he[t>>16&255]+he[t>>24&255]+he[i&255]+he[i>>8&255]+he[i>>16&255]+he[i>>24&255]).toLowerCase()}function qe(n,e,t){return Math.max(e,Math.min(t,n))}function sa(n,e){return(n%e+e)%e}function Sc(n,e,t,i,r){return i+(n-e)*(r-i)/(t-e)}function Tc(n,e,t){return n!==e?(t-n)/(e-n):0}function oa(n,e,t){return(1-t)*n+t*e}function Mc(n,e,t,i){return oa(n,e,1-Math.exp(-t*i))}function Cc(n,e=1){return e-Math.abs(sa(n,e*2)-e)}function Pc(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*(3-2*n))}function wc(n,e,t){return n<=e?0:n>=t?1:(n=(n-e)/(t-e),n*n*n*(n*(n*6-15)+10))}function Ec(n,e){return n+Math.floor(Math.random()*(e-n+1))}function Rc(n,e){return n+Math.random()*(e-n)}function kc(n){return n*(.5-Math.random())}function Ac(n){n!==void 0&&(Ls=n);let e=Ls+=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 zc(n){return n*ra}function Oc(n){return n*na}function Bc(n){return(n&n-1)===0&&n!==0}function Ic(n){return Math.pow(2,Math.ceil(Math.log(n)/Math.LN2))}function Nc(n){return Math.pow(2,Math.floor(Math.log(n)/Math.LN2))}function Uc(n,e,t,i,r){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+i)/2),u=a((e+i)/2),h=s((e-i)/2),f=a((e-i)/2),d=s((i-e)/2),y=a((i-e)/2);switch(r){case"XYX":n.set(o*u,c*h,c*f,o*l);break;case"YZY":n.set(c*f,o*u,c*h,o*l);break;case"ZXZ":n.set(c*h,c*f,o*u,o*l);break;case"XZX":n.set(o*u,c*y,c*d,o*l);break;case"YXY":n.set(c*d,o*u,c*y,o*l);break;case"ZYZ":n.set(c*y,c*d,o*u,o*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}function Fc(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 Dc(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 Ht={DEG2RAD:ra,RAD2DEG:na,generateUUID:bc,clamp:qe,euclideanModulo:sa,mapLinear:Sc,inverseLerp:Tc,lerp:oa,damp:Mc,pingpong:Cc,smoothstep:Pc,smootherstep:wc,randInt:Ec,randFloat:Rc,randFloatSpread:kc,seededRandom:Ac,degToRad:zc,radToDeg:Oc,isPowerOfTwo:Bc,ceilPowerOfTwo:Ic,floorPowerOfTwo:Nc,setQuaternionFromProperEuler:Uc,normalize:Dc,denormalize:Fc};class J{constructor(e=0,t=0,i=0,r=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=i,this._w=r}static slerpFlat(e,t,i,r,s,a,o){let c=i[r+0],l=i[r+1],u=i[r+2],h=i[r+3];const f=s[a+0],d=s[a+1],y=s[a+2],_=s[a+3];if(o===0){e[t+0]=c,e[t+1]=l,e[t+2]=u,e[t+3]=h;return}if(o===1){e[t+0]=f,e[t+1]=d,e[t+2]=y,e[t+3]=_;return}if(h!==_||c!==f||l!==d||u!==y){let p=1-o;const m=c*f+l*d+u*y+h*_,v=m>=0?1:-1,g=1-m*m;if(g>Number.EPSILON){const x=Math.sqrt(g),S=Math.atan2(x,m*v);p=Math.sin(p*S)/x,o=Math.sin(o*S)/x}const b=o*v;if(c=c*p+f*b,l=l*p+d*b,u=u*p+y*b,h=h*p+_*b,p===1-o){const x=1/Math.sqrt(c*c+l*l+u*u+h*h);c*=x,l*=x,u*=x,h*=x}}e[t]=c,e[t+1]=l,e[t+2]=u,e[t+3]=h}static multiplyQuaternionsFlat(e,t,i,r,s,a){const o=i[r],c=i[r+1],l=i[r+2],u=i[r+3],h=s[a],f=s[a+1],d=s[a+2],y=s[a+3];return e[t]=o*y+u*h+c*d-l*f,e[t+1]=c*y+u*f+l*h-o*d,e[t+2]=l*y+u*d+o*f-c*h,e[t+3]=u*y-o*h-c*f-l*d,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,i,r){return this._x=e,this._y=t,this._z=i,this._w=r,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 i=e._x,r=e._y,s=e._z,a=e._order,o=Math.cos,c=Math.sin,l=o(i/2),u=o(r/2),h=o(s/2),f=c(i/2),d=c(r/2),y=c(s/2);switch(a){case"XYZ":this._x=f*u*h+l*d*y,this._y=l*d*h-f*u*y,this._z=l*u*y+f*d*h,this._w=l*u*h-f*d*y;break;case"YXZ":this._x=f*u*h+l*d*y,this._y=l*d*h-f*u*y,this._z=l*u*y-f*d*h,this._w=l*u*h+f*d*y;break;case"ZXY":this._x=f*u*h-l*d*y,this._y=l*d*h+f*u*y,this._z=l*u*y+f*d*h,this._w=l*u*h-f*d*y;break;case"ZYX":this._x=f*u*h-l*d*y,this._y=l*d*h+f*u*y,this._z=l*u*y-f*d*h,this._w=l*u*h+f*d*y;break;case"YZX":this._x=f*u*h+l*d*y,this._y=l*d*h+f*u*y,this._z=l*u*y-f*d*h,this._w=l*u*h-f*d*y;break;case"XZY":this._x=f*u*h-l*d*y,this._y=l*d*h-f*u*y,this._z=l*u*y+f*d*h,this._w=l*u*h+f*d*y;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const i=t/2,r=Math.sin(i);return this._x=e.x*r,this._y=e.y*r,this._z=e.z*r,this._w=Math.cos(i),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,i=t[0],r=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],u=t[6],h=t[10],f=i+o+h;if(f>0){const d=.5/Math.sqrt(f+1);this._w=.25/d,this._x=(u-c)*d,this._y=(s-l)*d,this._z=(a-r)*d}else if(i>o&&i>h){const d=2*Math.sqrt(1+i-o-h);this._w=(u-c)/d,this._x=.25*d,this._y=(r+a)/d,this._z=(s+l)/d}else if(o>h){const d=2*Math.sqrt(1+o-i-h);this._w=(s-l)/d,this._x=(r+a)/d,this._y=.25*d,this._z=(c+u)/d}else{const d=2*Math.sqrt(1+h-i-o);this._w=(a-r)/d,this._x=(s+l)/d,this._y=(c+u)/d,this._z=.25*d}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let i=e.dot(t)+1;return i<Number.EPSILON?(i=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=i):(this._x=0,this._y=-e.z,this._z=e.y,this._w=i)):(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=i),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(qe(this.dot(e),-1,1)))}rotateTowards(e,t){const i=this.angleTo(e);if(i===0)return this;const r=Math.min(1,t/i);return this.slerp(e,r),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 i=e._x,r=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,u=t._w;return this._x=i*u+a*o+r*l-s*c,this._y=r*u+a*c+s*o-i*l,this._z=s*u+a*l+i*c-r*o,this._w=a*u-i*o-r*c-s*l,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const i=this._x,r=this._y,s=this._z,a=this._w;let o=a*e._w+i*e._x+r*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=i,this._y=r,this._z=s,this;const c=1-o*o;if(c<=Number.EPSILON){const d=1-t;return this._w=d*a+t*this._w,this._x=d*i+t*this._x,this._y=d*r+t*this._y,this._z=d*s+t*this._z,this.normalize(),this}const l=Math.sqrt(c),u=Math.atan2(l,o),h=Math.sin((1-t)*u)/l,f=Math.sin(t*u)/l;return this._w=a*h+this._w*f,this._x=i*h+this._x*f,this._y=r*h+this._y*f,this._z=s*h+this._z*f,this._onChangeCallback(),this}slerpQuaternions(e,t,i){return this.copy(e).slerp(t,i)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),i=Math.random(),r=Math.sqrt(1-i),s=Math.sqrt(i);return this.set(r*Math.sin(e),r*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 B{constructor(e=0,t=0,i=0){this.isVector3=!0,B.prototype.isVector3=!0,this.x=e,this.y=t,this.z=i}set(e,t,i){return i===void 0&&(i=this.z),this.x=e,this.y=t,this.z=i,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 B(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(Vs.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Vs.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,i=this.y,r=this.z,s=e.elements;return this.x=s[0]*t+s[3]*i+s[6]*r,this.y=s[1]*t+s[4]*i+s[7]*r,this.z=s[2]*t+s[5]*i+s[8]*r,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,i=this.y,r=this.z,s=e.elements,a=1/(s[3]*t+s[7]*i+s[11]*r+s[15]);return this.x=(s[0]*t+s[4]*i+s[8]*r+s[12])*a,this.y=(s[1]*t+s[5]*i+s[9]*r+s[13])*a,this.z=(s[2]*t+s[6]*i+s[10]*r+s[14])*a,this}applyQuaternion(e){const t=this.x,i=this.y,r=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*r-o*i),u=2*(o*t-s*r),h=2*(s*i-a*t);return this.x=t+c*l+a*h-o*u,this.y=i+c*u+o*l-s*h,this.z=r+c*h+s*u-a*l,this}transformDirection(e){const t=this.x,i=this.y,r=this.z,s=e.elements;return this.x=s[0]*t+s[4]*i+s[8]*r,this.y=s[1]*t+s[5]*i+s[9]*r,this.z=s[2]*t+s[6]*i+s[10]*r,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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}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,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const i=e.x,r=e.y,s=e.z,a=t.x,o=t.y,c=t.z;return this.x=r*c-s*o,this.y=s*a-i*c,this.z=i*o-r*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const i=e.dot(this)/t;return this.copy(e).multiplyScalar(i)}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 i=this.dot(e)/t;return Math.acos(qe(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y,r=this.z-e.z;return t*t+i*i+r*r}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSphericalCoords(e,t,i){const r=Math.sin(t)*e;return this.x=r*Math.sin(i),this.y=Math.cos(t)*e,this.z=r*Math.cos(i),this}setFromCylindricalCoords(e,t,i){return this.x=e*Math.sin(t),this.y=i,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(),i=this.setFromMatrixColumn(e,1).length(),r=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=i,this.z=r,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,i=Math.sqrt(1-t*t);return this.x=i*Math.cos(e),this.y=t,this.z=i*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 B,Vs=new J,sr=2e3,Js=2001;class De{constructor(e,t,i,r,s,a,o,c,l,u,h,f,d,y,_,p){this.isMatrix4=!0,De.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,i,r,s,a,o,c,l,u,h,f,d,y,_,p)}extractPosition(e){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(e)}multiplyToArray(e,t,i){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(e){return this.makeRotationFromQuaternion(e)}set(e,t,i,r,s,a,o,c,l,u,h,f,d,y,_,p){const m=this.elements;return m[0]=e,m[4]=t,m[8]=i,m[12]=r,m[1]=s,m[5]=a,m[9]=o,m[13]=c,m[2]=l,m[6]=u,m[10]=h,m[14]=f,m[3]=d,m[7]=y,m[11]=_,m[15]=p,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 De().fromArray(this.elements)}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],this}copyPosition(e){const t=this.elements,i=e.elements;return t[12]=i[12],t[13]=i[13],t[14]=i[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,i){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),i.setFromMatrixColumn(this,2),this}makeBasis(e,t,i){return this.set(e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,i=e.elements,r=1/Bt.setFromMatrixColumn(e,0).length(),s=1/Bt.setFromMatrixColumn(e,1).length(),a=1/Bt.setFromMatrixColumn(e,2).length();return t[0]=i[0]*r,t[1]=i[1]*r,t[2]=i[2]*r,t[3]=0,t[4]=i[4]*s,t[5]=i[5]*s,t[6]=i[6]*s,t[7]=0,t[8]=i[8]*a,t[9]=i[9]*a,t[10]=i[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,i=e.x,r=e.y,s=e.z,a=Math.cos(i),o=Math.sin(i),c=Math.cos(r),l=Math.sin(r),u=Math.cos(s),h=Math.sin(s);if(e.order==="XYZ"){const f=a*u,d=a*h,y=o*u,_=o*h;t[0]=c*u,t[4]=-c*h,t[8]=l,t[1]=d+y*l,t[5]=f-_*l,t[9]=-o*c,t[2]=_-f*l,t[6]=y+d*l,t[10]=a*c}else if(e.order==="YXZ"){const f=c*u,d=c*h,y=l*u,_=l*h;t[0]=f+_*o,t[4]=y*o-d,t[8]=a*l,t[1]=a*h,t[5]=a*u,t[9]=-o,t[2]=d*o-y,t[6]=_+f*o,t[10]=a*c}else if(e.order==="ZXY"){const f=c*u,d=c*h,y=l*u,_=l*h;t[0]=f-_*o,t[4]=-a*h,t[8]=y+d*o,t[1]=d+y*o,t[5]=a*u,t[9]=_-f*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const f=a*u,d=a*h,y=o*u,_=o*h;t[0]=c*u,t[4]=y*l-d,t[8]=f*l+_,t[1]=c*h,t[5]=_*l+f,t[9]=d*l-y,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const f=a*c,d=a*l,y=o*c,_=o*l;t[0]=c*u,t[4]=_-f*h,t[8]=y*h+d,t[1]=h,t[5]=a*u,t[9]=-o*u,t[2]=-l*u,t[6]=d*h+y,t[10]=f-_*h}else if(e.order==="XZY"){const f=a*c,d=a*l,y=o*c,_=o*l;t[0]=c*u,t[4]=-h,t[8]=l*u,t[1]=f*h+_,t[5]=a*u,t[9]=d*h-y,t[2]=y*h-d,t[6]=o*u,t[10]=_*h+f}return t[3]=0,t[7]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromQuaternion(e){return this.compose(Lc,e,Vc)}lookAt(e,t,i){const r=this.elements;return Te.subVectors(e,t),Te.lengthSq()===0&&(Te.z=1),Te.normalize(),ht.crossVectors(i,Te),ht.lengthSq()===0&&(Math.abs(i.z)===1?Te.x+=1e-4:Te.z+=1e-4,Te.normalize(),ht.crossVectors(i,Te)),ht.normalize(),or.crossVectors(Te,ht),r[0]=ht.x,r[4]=or.x,r[8]=Te.x,r[1]=ht.y,r[5]=or.y,r[9]=Te.y,r[2]=ht.z,r[6]=or.z,r[10]=Te.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const i=e.elements,r=t.elements,s=this.elements,a=i[0],o=i[4],c=i[8],l=i[12],u=i[1],h=i[5],f=i[9],d=i[13],y=i[2],_=i[6],p=i[10],m=i[14],v=i[3],g=i[7],b=i[11],x=i[15],S=r[0],T=r[4],w=r[8],P=r[12],C=r[1],R=r[5],E=r[9],k=r[13],A=r[2],z=r[6],N=r[10],L=r[14],I=r[3],X=r[7],Z=r[11],ie=r[15];return s[0]=a*S+o*C+c*A+l*I,s[4]=a*T+o*R+c*z+l*X,s[8]=a*w+o*E+c*N+l*Z,s[12]=a*P+o*k+c*L+l*ie,s[1]=u*S+h*C+f*A+d*I,s[5]=u*T+h*R+f*z+d*X,s[9]=u*w+h*E+f*N+d*Z,s[13]=u*P+h*k+f*L+d*ie,s[2]=y*S+_*C+p*A+m*I,s[6]=y*T+_*R+p*z+m*X,s[10]=y*w+_*E+p*N+m*Z,s[14]=y*P+_*k+p*L+m*ie,s[3]=v*S+g*C+b*A+x*I,s[7]=v*T+g*R+b*z+x*X,s[11]=v*w+g*E+b*N+x*Z,s[15]=v*P+g*k+b*L+x*ie,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],i=e[4],r=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],u=e[2],h=e[6],f=e[10],d=e[14],y=e[3],_=e[7],p=e[11],m=e[15];return y*(+s*c*h-r*l*h-s*o*f+i*l*f+r*o*d-i*c*d)+_*(+t*c*d-t*l*f+s*a*f-r*a*d+r*l*u-s*c*u)+p*(+t*l*h-t*o*d-s*a*h+i*a*d+s*o*u-i*l*u)+m*(-r*o*u-t*c*h+t*o*f+r*a*h-i*a*f+i*c*u)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,i){const r=this.elements;return e.isVector3?(r[12]=e.x,r[13]=e.y,r[14]=e.z):(r[12]=e,r[13]=t,r[14]=i),this}invert(){const e=this.elements,t=e[0],i=e[1],r=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],h=e[9],f=e[10],d=e[11],y=e[12],_=e[13],p=e[14],m=e[15],v=h*p*l-_*f*l+_*c*d-o*p*d-h*c*m+o*f*m,g=y*f*l-u*p*l-y*c*d+a*p*d+u*c*m-a*f*m,b=u*_*l-y*h*l+y*o*d-a*_*d-u*o*m+a*h*m,x=y*h*c-u*_*c-y*o*f+a*_*f+u*o*p-a*h*p,S=t*v+i*g+r*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 T=1/S;return e[0]=v*T,e[1]=(_*f*s-h*p*s-_*r*d+i*p*d+h*r*m-i*f*m)*T,e[2]=(o*p*s-_*c*s+_*r*l-i*p*l-o*r*m+i*c*m)*T,e[3]=(h*c*s-o*f*s-h*r*l+i*f*l+o*r*d-i*c*d)*T,e[4]=g*T,e[5]=(u*p*s-y*f*s+y*r*d-t*p*d-u*r*m+t*f*m)*T,e[6]=(y*c*s-a*p*s-y*r*l+t*p*l+a*r*m-t*c*m)*T,e[7]=(a*f*s-u*c*s+u*r*l-t*f*l-a*r*d+t*c*d)*T,e[8]=b*T,e[9]=(y*h*s-u*_*s-y*i*d+t*_*d+u*i*m-t*h*m)*T,e[10]=(a*_*s-y*o*s+y*i*l-t*_*l-a*i*m+t*o*m)*T,e[11]=(u*o*s-a*h*s-u*i*l+t*h*l+a*i*d-t*o*d)*T,e[12]=x*T,e[13]=(u*_*r-y*h*r+y*i*f-t*_*f-u*i*p+t*h*p)*T,e[14]=(y*o*r-a*_*r-y*i*c+t*_*c+a*i*p-t*o*p)*T,e[15]=(a*h*r-u*o*r+u*i*c-t*h*c-a*i*f+t*o*f)*T,this}scale(e){const t=this.elements,i=e.x,r=e.y,s=e.z;return t[0]*=i,t[4]*=r,t[8]*=s,t[1]*=i,t[5]*=r,t[9]*=s,t[2]*=i,t[6]*=r,t[10]*=s,t[3]*=i,t[7]*=r,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],i=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],r=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,i,r))}makeTranslation(e,t,i){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,i,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),i=Math.sin(e);return this.set(1,0,0,0,0,t,-i,0,0,i,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,0,i,0,0,1,0,0,-i,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),i=Math.sin(e);return this.set(t,-i,0,0,i,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const i=Math.cos(t),r=Math.sin(t),s=1-i,a=e.x,o=e.y,c=e.z,l=s*a,u=s*o;return this.set(l*a+i,l*o-r*c,l*c+r*o,0,l*o+r*c,u*o+i,u*c-r*a,0,l*c-r*o,u*c+r*a,s*c*c+i,0,0,0,0,1),this}makeScale(e,t,i){return this.set(e,0,0,0,0,t,0,0,0,0,i,0,0,0,0,1),this}makeShear(e,t,i,r,s,a){return this.set(1,i,s,0,e,1,a,0,t,r,1,0,0,0,0,1),this}compose(e,t,i){const r=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,u=a+a,h=o+o,f=s*l,d=s*u,y=s*h,_=a*u,p=a*h,m=o*h,v=c*l,g=c*u,b=c*h,x=i.x,S=i.y,T=i.z;return r[0]=(1-(_+m))*x,r[1]=(d+b)*x,r[2]=(y-g)*x,r[3]=0,r[4]=(d-b)*S,r[5]=(1-(f+m))*S,r[6]=(p+v)*S,r[7]=0,r[8]=(y+g)*T,r[9]=(p-v)*T,r[10]=(1-(f+_))*T,r[11]=0,r[12]=e.x,r[13]=e.y,r[14]=e.z,r[15]=1,this}decompose(e,t,i){const r=this.elements;let s=Bt.set(r[0],r[1],r[2]).length();const a=Bt.set(r[4],r[5],r[6]).length(),o=Bt.set(r[8],r[9],r[10]).length();this.determinant()<0&&(s=-s),e.x=r[12],e.y=r[13],e.z=r[14],Ne.copy(this);const l=1/s,u=1/a,h=1/o;return Ne.elements[0]*=l,Ne.elements[1]*=l,Ne.elements[2]*=l,Ne.elements[4]*=u,Ne.elements[5]*=u,Ne.elements[6]*=u,Ne.elements[8]*=h,Ne.elements[9]*=h,Ne.elements[10]*=h,t.setFromRotationMatrix(Ne),i.x=s,i.y=a,i.z=o,this}makePerspective(e,t,i,r,s,a,o=sr){const c=this.elements,l=2*s/(t-e),u=2*s/(i-r),h=(t+e)/(t-e),f=(i+r)/(i-r);let d,y;if(o===sr)d=-(a+s)/(a-s),y=-2*a*s/(a-s);else if(o===Js)d=-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]=h,c[12]=0,c[1]=0,c[5]=u,c[9]=f,c[13]=0,c[2]=0,c[6]=0,c[10]=d,c[14]=y,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,i,r,s,a,o=sr){const c=this.elements,l=1/(t-e),u=1/(i-r),h=1/(a-s),f=(t+e)*l,d=(i+r)*u;let y,_;if(o===sr)y=(a+s)*h,_=-2*h;else if(o===Js)y=s*h,_=-1*h;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-f,c[1]=0,c[5]=2*u,c[9]=0,c[13]=-d,c[2]=0,c[6]=0,c[10]=_,c[14]=-y,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,i=e.elements;for(let r=0;r<16;r++)if(t[r]!==i[r])return!1;return!0}fromArray(e,t=0){for(let i=0;i<16;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e[t+9]=i[9],e[t+10]=i[10],e[t+11]=i[11],e[t+12]=i[12],e[t+13]=i[13],e[t+14]=i[14],e[t+15]=i[15],e}}const Bt=new B,Ne=new De,Lc=new B(0,0,0),Vc=new B(1,1,1),ht=new B,or=new B,Te=new B,Gs=new De,js=new J;class bi{constructor(e=0,t=0,i=0,r=bi.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=i,this._order=r}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,i,r=this._order){return this._x=e,this._y=t,this._z=i,this._order=r,this._onChangeCallback(),this}clone(){return new bi(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,i=!0){const r=e.elements,s=r[0],a=r[4],o=r[8],c=r[1],l=r[5],u=r[9],h=r[2],f=r[6],d=r[10];switch(t){case"XYZ":this._y=Math.asin(qe(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,d),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(f,l),this._z=0);break;case"YXZ":this._x=Math.asin(-qe(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,d),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-h,s),this._z=0);break;case"ZXY":this._x=Math.asin(qe(f,-1,1)),Math.abs(f)<.9999999?(this._y=Math.atan2(-h,d),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-qe(h,-1,1)),Math.abs(h)<.9999999?(this._x=Math.atan2(f,d),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin(qe(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-u,l),this._y=Math.atan2(-h,s)):(this._x=0,this._y=Math.atan2(o,d));break;case"XZY":this._z=Math.asin(-qe(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(f,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-u,d),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,i===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,i){return Gs.makeRotationFromQuaternion(e),this.setFromRotationMatrix(Gs,t,i)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return js.setFromEuler(this),this.setFromQuaternion(js,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}}bi.DEFAULT_ORDER="XYZ";class jt{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 jt(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,i=this.y,r=e.elements;return this.x=r[0]*t+r[3]*i+r[6],this.y=r[1]*t+r[4]*i+r[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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}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 i=this.dot(e)/t;return Math.acos(qe(i,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,i=this.y-e.y;return t*t+i*i}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,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,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 i=Math.cos(t),r=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*i-a*r+e.x,this.y=s*r+a*i+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}jt.isVector2=!0;class Se{constructor(e=0,t=0,i=0,r=1){Se.prototype.isVector4=!0,this.x=e,this.y=t,this.z=i,this.w=r}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,i,r){return this.x=e,this.y=t,this.z=i,this.w=r,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 Se(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,i=this.y,r=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*i+a[8]*r+a[12]*s,this.y=a[1]*t+a[5]*i+a[9]*r+a[13]*s,this.z=a[2]*t+a[6]*i+a[10]*r+a[14]*s,this.w=a[3]*t+a[7]*i+a[11]*r+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,i,r,s;const c=e.elements,l=c[0],u=c[4],h=c[8],f=c[1],d=c[5],y=c[9],_=c[2],p=c[6],m=c[10];if(Math.abs(u-f)<.01&&Math.abs(h-_)<.01&&Math.abs(y-p)<.01){if(Math.abs(u+f)<.1&&Math.abs(h+_)<.1&&Math.abs(y+p)<.1&&Math.abs(l+d+m-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const g=(l+1)/2,b=(d+1)/2,x=(m+1)/2,S=(u+f)/4,T=(h+_)/4,w=(y+p)/4;return g>b&&g>x?g<.01?(i=0,r=.707106781,s=.707106781):(i=Math.sqrt(g),r=S/i,s=T/i):b>x?b<.01?(i=.707106781,r=0,s=.707106781):(r=Math.sqrt(b),i=S/r,s=w/r):x<.01?(i=.707106781,r=.707106781,s=0):(s=Math.sqrt(x),i=T/s,r=w/s),this.set(i,r,s,t),this}let v=Math.sqrt((p-y)*(p-y)+(h-_)*(h-_)+(f-u)*(f-u));return Math.abs(v)<.001&&(v=1),this.x=(p-y)/v,this.y=(h-_)/v,this.z=(f-u)/v,this.w=Math.acos((l+d+m-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 i=this.length();return this.divideScalar(i||1).multiplyScalar(Math.max(e,Math.min(t,i)))}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,i){return this.x=e.x+(t.x-e.x)*i,this.y=e.y+(t.y-e.y)*i,this.z=e.z+(t.z-e.z)*i,this.w=e.w+(t.w-e.w)*i,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 He{constructor(e,t,i,r,s,a,o,c,l){He.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,i,r,s,a,o,c,l)}set(e,t,i,r,s,a,o,c,l){const u=this.elements;return u[0]=e,u[1]=r,u[2]=o,u[3]=t,u[4]=s,u[5]=c,u[6]=i,u[7]=a,u[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,i=e.elements;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],this}extractBasis(e,t,i){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),i.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 i=e.elements,r=t.elements,s=this.elements,a=i[0],o=i[3],c=i[6],l=i[1],u=i[4],h=i[7],f=i[2],d=i[5],y=i[8],_=r[0],p=r[3],m=r[6],v=r[1],g=r[4],b=r[7],x=r[2],S=r[5],T=r[8];return s[0]=a*_+o*v+c*x,s[3]=a*p+o*g+c*S,s[6]=a*m+o*b+c*T,s[1]=l*_+u*v+h*x,s[4]=l*p+u*g+h*S,s[7]=l*m+u*b+h*T,s[2]=f*_+d*v+y*x,s[5]=f*p+d*g+y*S,s[8]=f*m+d*b+y*T,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],i=e[1],r=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8];return t*a*u-t*o*l-i*s*u+i*o*c+r*s*l-r*a*c}invert(){const e=this.elements,t=e[0],i=e[1],r=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],h=u*a-o*l,f=o*c-u*s,d=l*s-a*c,y=t*h+i*f+r*d;if(y===0)return this.set(0,0,0,0,0,0,0,0,0);const _=1/y;return e[0]=h*_,e[1]=(r*l-u*i)*_,e[2]=(o*i-r*a)*_,e[3]=f*_,e[4]=(u*t-r*c)*_,e[5]=(r*s-o*t)*_,e[6]=d*_,e[7]=(i*c-l*t)*_,e[8]=(a*t-i*s)*_,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,i,r,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(i*c,i*l,-i*(c*a+l*o)+a+e,-r*l,r*c,-r*(-l*a+c*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(cn.makeScale(e,t)),this}rotate(e){return this.premultiply(cn.makeRotation(-e)),this}translate(e,t){return this.premultiply(cn.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),i=Math.sin(e);return this.set(t,-i,0,i,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,i=e.elements;for(let r=0;r<9;r++)if(t[r]!==i[r])return!1;return!0}fromArray(e,t=0){for(let i=0;i<9;i++)this.elements[i]=e[i+t];return this}toArray(e=[],t=0){const i=this.elements;return e[t]=i[0],e[t+1]=i[1],e[t+2]=i[2],e[t+3]=i[3],e[t+4]=i[4],e[t+5]=i[5],e[t+6]=i[6],e[t+7]=i[7],e[t+8]=i[8],e}clone(){return new He().fromArray(this.elements)}}const cn=new He;var ye;(function(n){n[n.Random=0]="Random",n[n.Loop=1]="Loop",n[n.PingPong=2]="PingPong",n[n.Burst=3]="Burst"})(ye||(ye={}));function er(n,e,t,i){let r;switch(ye.Random===n?e=Math.random():ye.Burst===n&&i.isBursting&&(e=i.burstParticleIndex/i.burstParticleCount),t>0?r=Math.floor(e/t)*t:r=e,n){case ye.Loop:r=r%1;break;case ye.PingPong:r=Math.abs(r%2-1);break}return r}class Rt{constructor(e,t,i,r){this.p=[e,t,i,r]}genValue(e){const t=e*e,i=e*e*e,r=1-e,s=r*r,a=s*r;return this.p[0]*a+this.p[1]*s*e*3+this.p[2]*r*t*3+this.p[3]*i}derivativeCoefficients(e){const t=[];for(let i=e,r=i.length-1;r>0;r--){const s=[];for(let a=0;a<r;a++){const o=r*(i[a+1]-i[a]);s.push(o)}t.push(s),i=s}return t}getSlope(e){const t=this.derivativeCoefficients(this.p)[0],i=1-e,r=i*i,s=i*e*2,a=e*e;return r*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,i=[],r,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(i=[],a=0,o=t.length-1;a<o;a++)r=e*t[a]+(1-e)*t[a+1],c[s++]=r,i.push(r);t=i}return c}split(e){const t=this.hull(e);return{left:new Rt(t[0],t[4],t[7],t[9]),right:new Rt(t[9],t[8],t[6],t[3]),span:t}}clone(){return new Rt(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 Rt(e.p0,e.p1,e.p2,e.p3)}}const Si=n=>({r:n.x,g:n.y,b:n.z,a:n.w}),Ti=n=>new Se(n.r,n.g,n.b,n.a),Jc=(n,e)=>{switch(e){case"Vector3":return new B(n.x,n.y,n.z);case"Vector4":return new Se(n.x,n.y,n.z,n.w);case"Color":return new B(n.r,n.g,n.b);case"Number":return n;default:return n}},Gc=(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 Ir{constructor(e,t){this.a=e,this.b=t,this.type="value"}startGen(e){}genColor(e,t){const i=Math.random();return t.copy(this.a).lerp(this.b,i)}toJSON(){return{type:"RandomColor",a:Si(this.a),b:Si(this.b)}}static fromJSON(e){return new Ir(Ti(e.a),Ti(e.b))}clone(){return new Ir(this.a.clone(),this.b.clone())}}class $t{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:Si(this.a),b:Si(this.b)}}static fromJSON(e){return new $t(Ti(e.a),Ti(e.b))}clone(){return new $t(this.a.clone(),this.b.clone())}}class yt{constructor(e,t){this.subType=t,this.type="function",this.keys=e}findKey(e){let t=0,i=0,r=this.keys.length-1;for(;i+1<r;)if(t=Math.floor((i+r)/2),e<this.getStartX(t))r=t-1;else if(e>this.getEndX(t))i=t+1;else return t;for(let s=i;s<=r;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 i=this.findKey(t);return this.subType==="Number"?i===-1?this.keys[0][0]:i+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[i+1][0]-this.keys[i][0])*((t-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))+this.keys[i][0]:i===-1?e.copy(this.keys[0][0]):i+1>=this.keys.length?e.copy(this.keys[this.keys.length-1][0]):e.copy(this.keys[i][0]).lerp(this.keys[i+1][0],(t-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([e,t])=>({value:Gc(e,this.subType),pos:t}))}}static fromJSON(e){return new yt(e.keys.map(t=>[Jc(t.value,e.subType),t.pos]),e.subType)}clone(){return this.subType==="Number"?new yt(this.keys.map(([e,t])=>[e,t]),this.subType):new yt(this.keys.map(([e,t])=>[e.clone(),t]),this.subType)}}const ar=new B;class kt{constructor(e=[[new B(0,0,0),0],[new B(1,1,1),0]],t=[[1,0],[1,1]]){this.type="function",this.color=new yt(e,"Color"),this.alpha=new yt(t,"Number")}genColor(e,t,i){return this.color.genValue(ar,i),t.set(ar.x,ar.y,ar.z,this.alpha.genValue(1,i))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(e){if(e.functions){const t=e.functions.map(i=>[$t.fromJSON(i.function).a,i.start]);return e.functions.length>0&&t.push([$t.fromJSON(e.functions[e.functions.length-1].function).b,1]),new kt(t.map(i=>[new B(i[0].x,i[0].y,i[0].z),i[1]]),t.map(i=>[i[0].w,i[1]]))}else{const t=new kt;return t.alpha=yt.fromJSON(e.alpha),t.color=yt.fromJSON(e.color),t}}clone(){const e=new kt;return e.alpha=this.alpha.clone(),e.color=this.color.clone(),e}startGen(e){}}const ln=new Se;class Nr{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,i){return this.gradient1.genColor(e,t,i),this.gradient2.genColor(e,ln,i),e&&e[this.indexCount]!==void 0?t.lerp(ln,e[this.indexCount]):t.lerp(ln,Math.random()),t}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(e){return new Nr(kt.fromJSON(e.gradient1),kt.fromJSON(e.gradient2))}clone(){return new Nr(this.gradient1.clone(),this.gradient2.clone())}}class At{constructor(e){this.color=e,this.type="value"}startGen(e){}genColor(e,t){return t.copy(this.color)}toJSON(){return{type:"ConstantColor",color:Si(this.color)}}static fromJSON(e){return new At(Ti(e.color))}clone(){return new At(this.color.clone())}}function ts(n){switch(n.type){case"ConstantColor":return At.fromJSON(n);case"ColorRange":return $t.fromJSON(n);case"RandomColor":return Ir.fromJSON(n);case"Gradient":return kt.fromJSON(n);case"RandomColorBetweenGradient":return Nr.fromJSON(n);default:return new At(new Se(1,1,1,1))}}class F{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 F(e.value)}clone(){return new F(this.value)}}class zt{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),Ht.lerp(this.a,this.b,e[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(e){return new zt(e.a,e.b)}clone(){return new zt(this.a,this.b)}}class jc{constructor(){this.functions=new Array}findFunction(e){let t=0,i=0,r=this.functions.length-1;for(;i+1<r;)if(t=Math.floor((i+r)/2),e<this.getStartX(t))r=t-1;else if(e>this.getEndX(t))i=t+1;else return t;for(let s=i;s<=r;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 i=this.findFunction(e);this.functions.splice(i+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 Mi extends jc{constructor(e=[[new Rt(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=e}genValue(e,t=0){const i=this.findFunction(t);return i===-1?0:this.functions[i][0].genValue((t-this.getStartX(i))/(this.getEndX(i)-this.getStartX(i)))}toSVG(e,t){if(t<1)return"";let i=["M",0,this.functions[0][0].p[0]].join(" ");for(let r=1/t;r<=1;r+=1/t)i=[i,"L",r*e,this.genValue(void 0,r)].join(" ");return i}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([e,t])=>({function:e.toJSON(),start:t}))}}static fromJSON(e){return new Mi(e.functions.map(t=>[Rt.fromJSON(t.function),t.start]))}clone(){return new Mi(this.functions.map(([e,t])=>[e.clone(),t]))}startGen(e){}}function U(n){switch(n.type){case"ConstantValue":return F.fromJSON(n);case"IntervalValue":return zt.fromJSON(n);case"PiecewiseBezier":return Mi.fromJSON(n);default:return new F(0)}}class Ci{constructor(){this.indexCount=0,this.type="rotation"}startGen(e){this.indexCount=e.length,e.push(new J);let t,i,r,s,a,o;do t=Math.random()*2-1,i=Math.random()*2-1,r=t*t+i*i;while(r>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-r)/o);e[this.indexCount].set(t,i,c*s,c*a)}genValue(e,t,i,r){return this.indexCount===-1&&this.startGen(e),t.copy(e[this.indexCount]),t}toJSON(){return{type:"RandomQuat"}}static fromJSON(e){return new Ci}clone(){return new Ci}}class Pi{constructor(e,t){this.axis=e,this.angle=t,this.type="rotation"}startGen(e){this.angle.startGen(e)}genValue(e,t,i,r){return t.setFromAxisAngle(this.axis,this.angle.genValue(e,r)*i)}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 Pi(new B(e.axis.x,e.axis.y,e.axis.z),U(e.angle))}clone(){return new Pi(this.axis.clone(),this.angle.clone())}}class Ur{constructor(e,t,i,r){this.angleX=e,this.angleY=t,this.angleZ=i,this.type="rotation",this.eular=new bi(0,0,0,r)}startGen(e){this.angleX.startGen(e),this.angleY.startGen(e),this.angleZ.startGen(e)}genValue(e,t,i,r){return this.eular.set(this.angleX.genValue(e,r)*i,this.angleY.genValue(e,r)*i,this.angleZ.genValue(e,r)*i),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 Ur(U(e.angleX),U(e.angleY),U(e.angleZ),e.eulerOrder)}clone(){return new Ur(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function aa(n){switch(n.type){case"AxisAngle":return Pi.fromJSON(n);case"Euler":return Ur.fromJSON(n);case"RandomQuat":return Ci.fromJSON(n);default:return new Ci}}class Ot{constructor(e,t,i){this.x=e,this.y=t,this.z=i,this.type="vec3function"}startGen(e){this.x.startGen(e),this.y.startGen(e),this.z.startGen(e)}genValue(e,t,i){return t.set(this.x.genValue(e,i),this.y.genValue(e,i),this.z.genValue(e,i))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new Ot(U(e.x),U(e.y),U(e.z))}clone(){return new Ot(this.x,this.y,this.z)}}function $c(n){switch(n.type){case"Vector3Function":return Ot.fromJSON(n);default:return new Ot(new F(0),new F(0),new F(0))}}function Fr(n){switch(n.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return U(n);case"AxisAngle":case"RandomQuat":case"Euler":return aa(n);case"Vector3Function":return $c(n);default:return new F(0)}}class wi{constructor(e={}){var t,i,r,s,a,o,c;this.type="cone",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(i=e.arc)!==null&&i!==void 0?i:2*Math.PI,this.thickness=(r=e.thickness)!==null&&r!==void 0?r:1,this.angle=(s=e.angle)!==null&&s!==void 0?s:Math.PI/6,this.mode=(a=e.mode)!==null&&a!==void 0?a:ye.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new F(1),this.memory=[]}update(e,t){ye.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const i=er(this.mode,this.currentValue,this.spread,t),r=Ht.lerp(1-this.thickness,1,Math.random()),s=i*this.arc,a=Math.sqrt(r),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 wi({radius:e.radius,arc:e.arc,thickness:e.thickness,angle:e.angle,mode:e.mode,speed:e.speed?U(e.speed):void 0,spread:e.spread})}clone(){return new wi({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ei{constructor(e={}){var t,i,r,s,a,o;this.type="circle",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(i=e.arc)!==null&&i!==void 0?i:2*Math.PI,this.thickness=(r=e.thickness)!==null&&r!==void 0?r:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:ye.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new F(1),this.memory=[]}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const i=er(this.mode,this.currentValue,this.spread,t),r=Ht.lerp(1-this.thickness,1,Math.random()),s=i*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*r)}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 Ei({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?U(e.speed):void 0,spread:e.spread})}clone(){return new Ei({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function cr(n,e){return Math.floor(Math.random()*(e-n))+n}const $r=new B(0,1,0),qr=new B(0,0,0),qc=new B(1,1,1),$s=new B(0,0,1);class Ri{constructor(e={}){var t,i,r,s,a,o,c;this.type="donut",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(i=e.arc)!==null&&i!==void 0?i:2*Math.PI,this.thickness=(r=e.thickness)!==null&&r!==void 0?r:1,this.donutRadius=(s=e.donutRadius)!==null&&s!==void 0?s:this.radius*.2,this.mode=(a=e.mode)!==null&&a!==void 0?a:ye.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new F(1),this.memory=[],this._m1=new De}update(e,t){ye.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const i=er(this.mode,this.currentValue,this.spread,t),r=Math.random(),s=Ht.lerp(1-this.thickness,1,Math.random()),a=i*this.arc,o=r*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(qr,e.velocity,$r),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 Ri({radius:e.radius,arc:e.arc,thickness:e.thickness,donutRadius:e.donutRadius,mode:e.mode,speed:e.speed?U(e.speed):void 0,spread:e.spread})}clone(){return new Ri({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class ki{constructor(){this.type="point",this._m1=new De}update(e,t){}initialize(e){const t=Math.random(),i=Math.random(),r=t*Math.PI*2,s=Math.acos(2*i-1),a=Math.cbrt(Math.random()),o=Math.sin(r),c=Math.cos(r),l=Math.sin(s),u=Math.cos(s);e.velocity.x=a*l*c,e.velocity.y=a*l*o,e.velocity.z=a*u,e.velocity.multiplyScalar(e.startSpeed),e.position.setScalar(0),e.rotation instanceof J&&(this._m1.lookAt(qr,e.position,$r),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(e){return new ki}clone(){return new ki}}class qt{constructor(e={}){var t,i,r,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(i=e.arc)!==null&&i!==void 0?i:2*Math.PI,this.thickness=(r=e.thickness)!==null&&r!==void 0?r:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:ye.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new F(1),this.memory=[],this._m1=new De}update(e,t){ye.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const i=er(this.mode,this.currentValue,this.spread,t),r=Math.random(),s=Ht.lerp(1-this.thickness,1,Math.random()),a=i*this.arc,o=Math.acos(2*r-1),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),h=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=h,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof J&&(this._m1.lookAt(qr,e.position,$r),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 qt({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?U(e.speed):void 0,spread:e.spread})}clone(){return new qt({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Ai{constructor(e={}){var t,i,r,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(i=e.arc)!==null&&i!==void 0?i:2*Math.PI,this.thickness=(r=e.thickness)!==null&&r!==void 0?r:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:ye.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new F(1),this.memory=[],this._m1=new De}update(e,t){ye.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const i=er(this.mode,this.currentValue,this.spread,t),r=Math.random(),s=Ht.lerp(1-this.thickness,1,Math.random()),a=i*this.arc,o=Math.acos(r),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),h=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=h,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof J&&(this._m1.lookAt(qr,e.position,$r),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 Ai({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?U(e.speed):void 0,spread:e.spread})}clone(){return new Ai({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class zi{constructor(e={}){var t,i,r,s;this.type="grid",this.width=(t=e.width)!==null&&t!==void 0?t:1,this.height=(i=e.height)!==null&&i!==void 0?i:1,this.column=(r=e.column)!==null&&r!==void 0?r:10,this.row=(s=e.row)!==null&&s!==void 0?s:10}initialize(e){const t=Math.floor(Math.random()*this.row),i=Math.floor(Math.random()*this.column);e.position.x=i*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 zi(e)}clone(){return new zi({width:this.width,height:this.height,column:this.column,row:this.row})}update(e,t){}}const Fn={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ei,loadJSON:Ei.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:wi,loadJSON:wi.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ri,loadJSON:Ri.fromJSON},point:{type:"point",params:[],constructor:ki,loadJSON:ki.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:qt,loadJSON:qt.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ai,loadJSON:Ai.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:zi,loadJSON:zi.fromJSON}};function Xc(n,e){return Fn[n.type].loadJSON(n,e)}class Oi{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 Oi(ts(e.color))}clone(){return new Oi(this.color.clone())}reset(){}}class Bi{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 Bi(U(e.angularVelocity))}frameUpdate(e){}clone(){return new Bi(this.angularVelocity.clone())}reset(){}}class Ii{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 Ii(aa(e.angularVelocity))}frameUpdate(e){}clone(){return new Ii(this.angularVelocity.clone())}reset(){}}class Ni{initialize(e,t){this.ps=t,this.x.startGen(e.memory),this.y.startGen(e.memory),this.z.startGen(e.memory)}constructor(e,t,i){this.x=e,this.y=t,this.z=i,this.type="ForceOverLife",this._temp=new B,this._tempScale=new B,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 Ni(U(e.x),U(e.y),U(e.z))}frameUpdate(e){if(this.ps&&!this.ps.worldSpace){const t=this._temp,i=this._tempQ,r=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,i,r),i.invert(),r.set(1/r.x,1/r.y,1/r.z)}}clone(){return new Ni(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class Ui{initialize(e){this.size.startGen(e.memory)}constructor(e){this.size=e,this.type="SizeOverLife"}update(e){this.size instanceof Ot?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 Ui(Fr(e.size))}frameUpdate(e){}clone(){return new Ui(this.size.clone())}reset(){}}class Fi{initialize(e){this.speed.startGen(e.memory)}constructor(e){this.speed=e,this.type="SpeedOverLife"}update(e){e.speedModifier=this.speed.genValue(e.memory,e.age/e.life)}toJSON(){return{type:this.type,speed:this.speed.toJSON()}}static fromJSON(e){return new Fi(U(e.speed))}frameUpdate(e){}clone(){return new Fi(this.speed.clone())}reset(){}}class Di{constructor(e){this.frame=e,this.type="FrameOverLife"}initialize(e){this.frame.startGen(e.memory)}update(e,t){this.frame instanceof Mi&&(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 Di(U(e.frame))}clone(){return new Di(this.frame.clone())}reset(){}}class Li{constructor(e,t=new B(0,1,0)){this.orbitSpeed=e,this.axis=t,this.type="OrbitOverLife",this.temp=new B,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 Li(U(e.orbitSpeed),e.axis?new B(e.axis[0],e.axis[1],e.axis[2]):void 0)}clone(){return new Li(this.orbitSpeed.clone())}reset(){}}class un{constructor(e){this.data=e,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class Hc{constructor(){this.length=0,this.head=this.tail=null}isEmpty(){return this.head===null}clear(){this.length=0,this.head=this.tail=null}front(){return this.head===null?null:this.head.data}back(){return this.tail===null?null:this.tail.data}dequeue(){if(this.head){const e=this.head.data;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,e}}pop(){if(this.tail){const e=this.tail.data;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,e}}queue(e){const t=new un(e);this.tail||(this.tail=t),this.head&&(this.head.prev=t,t.next=this.head),this.head=t,this.length++}push(e){const t=new un(e);this.head||(this.head=t),this.tail&&(this.tail.next=t,t.prev=this.tail),this.tail=t,this.length++}insertBefore(e,t){const i=new un(t);i.next=e,i.prev=e.prev,i.prev!==null&&(i.prev.next=i),i.next.prev=i,e==this.head&&(this.head=i),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 Wc{constructor(){this.startSpeed=0,this.startColor=new Se,this.startSize=new B(1,1,1),this.position=new B,this.velocity=new B,this.age=0,this.life=1,this.size=new B(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new Se,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class Yc{constructor(e,t,i){this.position=e,this.size=t,this.color=i}}class Dr{constructor(){this.startSpeed=0,this.startColor=new Se,this.startSize=new B(1,1,1),this.position=new B,this.velocity=new B,this.age=0,this.life=1,this.size=new B(1,1,1),this.length=100,this.speedModifier=1,this.color=new Se,this.previous=new Hc,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new Yc(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 Vi{initialize(e){this.width.startGen(e.memory)}constructor(e){this.width=e,this.type="WidthOverLength"}update(e){if(e instanceof Dr){const t=e.previous.values();for(let i=0;i<e.previous.length;i++){const r=t.next();r.value.size=this.width.genValue(e.memory,(e.previous.length-i)/e.length)}}}frameUpdate(e){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(e){return new Vi(U(e.width))}clone(){return new Vi(this.width.clone())}reset(){}}class Ji{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 Ji(new B(e.direction[0],e.direction[1],e.direction[2]),U((t=e.magnitude)!==null&&t!==void 0?t:e.force))}clone(){return new Ji(this.direction.clone(),this.magnitude.clone())}reset(){}}class Gi{constructor(e,t){this.center=e,this.magnitude=t,this.type="GravityForce",this.temp=new B}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 Gi(new B(e.center[0],e.center[1],e.center[2]),e.magnitude)}clone(){return new Gi(this.center.clone(),this.magnitude)}reset(){}}class ji{constructor(e){this.angle=e,this.type="ChangeEmitDirection",this._temp=new B,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 ji(U(e.angle))}clone(){return new ji(this.angle)}reset(){}}var Jt;(function(n){n[n.Death=0]="Death",n[n.Birth=1]="Birth",n[n.Frame=2]="Frame"})(Jt||(Jt={}));class $i{constructor(e,t,i,r=Jt.Frame,s=1){this.particleSystem=e,this.useVelocityAsBasis=t,this.subParticleSystem=i,this.mode=r,this.emitProbability=s,this.type="EmitSubParticleSystem",this.q_=new J,this.v_=new B,this.v2_=new B,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(e){}update(e,t){this.mode===Jt.Frame?this.emit(e,t):this.mode===Jt.Birth&&e.age===0?this.emit(e,t):this.mode===Jt.Death&&e.age+t>=e.life&&this.emit(e,t)}emit(e,t){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const i=new De;this.setMatrixFromParticle(i,e),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:i,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 i=this.subEmissions[t];i.particle&&i.particle.age<i.particle.life?this.setMatrixFromParticle(i.matrix,i.particle):i.particle=void 0,this.subParticleSystem.system.emit(e,i,i.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 $i(t,e.useVelocityAsBasis,e.subParticleSystem,e.mode,e.emitProbability)}clone(){return new $i(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(e,t){let i;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($s).cross(t.velocity),this.v2_.copy(t.velocity).cross(this.v_);const r=this.v_.length(),s=this.v2_.length();e.set(this.v_.x/r,this.v2_.x/s,t.velocity.x,t.position.x,this.v_.y/r,this.v2_.y/s,t.velocity.y,t.position.y,this.v_.z/r,this.v2_.z/s,t.velocity.z,t.position.z,0,0,0,1)}else t.rotation instanceof J?i=t.rotation:(this.q_.setFromAxisAngle($s,t.rotation),i=this.q_),e.compose(t.position,i,qc);this.particleSystem.worldSpace||e.multiplyMatrices(this.particleSystem.emitter.matrixWorld,e)}}const Zc=.5*(Math.sqrt(3)-1),ii=(3-Math.sqrt(3))/6,Kc=1/3,je=1/6,Qc=(Math.sqrt(5)-1)/4,oe=(5-Math.sqrt(5))/20,ne=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 ca{constructor(e=Math.random){const t=typeof e=="function"?e:tl(e);this.p=el(t),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let i=0;i<512;i++)this.perm[i]=this.p[i&255],this.permMod12[i]=this.perm[i]%12}noise2D(e,t){const i=this.permMod12,r=this.perm;let s=0,a=0,o=0;const c=(e+t)*Zc,l=Math.floor(e+c),u=Math.floor(t+c),h=(l+u)*ii,f=l-h,d=u-h,y=e-f,_=t-d;let p,m;y>_?(p=1,m=0):(p=0,m=1);const v=y-p+ii,g=_-m+ii,b=y-1+2*ii,x=_-1+2*ii,S=l&255,T=u&255;let w=.5-y*y-_*_;if(w>=0){const R=i[S+r[T]]*3;w*=w,s=w*w*(ne[R]*y+ne[R+1]*_)}let P=.5-v*v-g*g;if(P>=0){const R=i[S+p+r[T+m]]*3;P*=P,a=P*P*(ne[R]*v+ne[R+1]*g)}let C=.5-b*b-x*x;if(C>=0){const R=i[S+1+r[T+1]]*3;C*=C,o=C*C*(ne[R]*b+ne[R+1]*x)}return 70*(s+a+o)}noise3D(e,t,i){const r=this.permMod12,s=this.perm;let a,o,c,l;const u=(e+t+i)*Kc,h=Math.floor(e+u),f=Math.floor(t+u),d=Math.floor(i+u),y=(h+f+d)*je,_=h-y,p=f-y,m=d-y,v=e-_,g=t-p,b=i-m;let x,S,T,w,P,C;v>=g?g>=b?(x=1,S=0,T=0,w=1,P=1,C=0):v>=b?(x=1,S=0,T=0,w=1,P=0,C=1):(x=0,S=0,T=1,w=1,P=0,C=1):g<b?(x=0,S=0,T=1,w=0,P=1,C=1):v<b?(x=0,S=1,T=0,w=0,P=1,C=1):(x=0,S=1,T=0,w=1,P=1,C=0);const R=v-x+je,E=g-S+je,k=b-T+je,A=v-w+2*je,z=g-P+2*je,N=b-C+2*je,L=v-1+3*je,I=g-1+3*je,X=b-1+3*je,Z=h&255,ie=f&255,Q=d&255;let pe=.6-v*v-g*g-b*b;if(pe<0)a=0;else{const j=r[Z+s[ie+s[Q]]]*3;pe*=pe,a=pe*pe*(ne[j]*v+ne[j+1]*g+ne[j+2]*b)}let me=.6-R*R-E*E-k*k;if(me<0)o=0;else{const j=r[Z+x+s[ie+S+s[Q+T]]]*3;me*=me,o=me*me*(ne[j]*R+ne[j+1]*E+ne[j+2]*k)}let re=.6-A*A-z*z-N*N;if(re<0)c=0;else{const j=r[Z+w+s[ie+P+s[Q+C]]]*3;re*=re,c=re*re*(ne[j]*A+ne[j+1]*z+ne[j+2]*N)}let H=.6-L*L-I*I-X*X;if(H<0)l=0;else{const j=r[Z+1+s[ie+1+s[Q+1]]]*3;H*=H,l=H*H*(ne[j]*L+ne[j+1]*I+ne[j+2]*X)}return 32*(a+o+c+l)}noise4D(e,t,i,r){const s=this.perm;let a,o,c,l,u;const h=(e+t+i+r)*Qc,f=Math.floor(e+h),d=Math.floor(t+h),y=Math.floor(i+h),_=Math.floor(r+h),p=(f+d+y+_)*oe,m=f-p,v=d-p,g=y-p,b=_-p,x=e-m,S=t-v,T=i-g,w=r-b;let P=0,C=0,R=0,E=0;x>S?P++:C++,x>T?P++:R++,x>w?P++:E++,S>T?C++:R++,S>w?C++:E++,T>w?R++:E++;const k=P>=3?1:0,A=C>=3?1:0,z=R>=3?1:0,N=E>=3?1:0,L=P>=2?1:0,I=C>=2?1:0,X=R>=2?1:0,Z=E>=2?1:0,ie=P>=1?1:0,Q=C>=1?1:0,pe=R>=1?1:0,me=E>=1?1:0,re=x-k+oe,H=S-A+oe,j=T-z+oe,Ye=w-N+oe,Le=x-L+2*oe,Ve=S-I+2*oe,Je=T-X+2*oe,ve=w-Z+2*oe,Ae=x-ie+3*oe,_e=S-Q+3*oe,Ze=T-pe+3*oe,Ke=w-me+3*oe,W=x-1+4*oe,Ge=S-1+4*oe,Qe=T-1+4*oe,_t=w-1+4*oe,et=f&255,tt=d&255,it=y&255,rt=_&255;let nt=.6-x*x-S*S-T*T-w*w;if(nt<0)a=0;else{const V=s[et+s[tt+s[it+s[rt]]]]%32*4;nt*=nt,a=nt*nt*(ee[V]*x+ee[V+1]*S+ee[V+2]*T+ee[V+3]*w)}let ze=.6-re*re-H*H-j*j-Ye*Ye;if(ze<0)o=0;else{const V=s[et+k+s[tt+A+s[it+z+s[rt+N]]]]%32*4;ze*=ze,o=ze*ze*(ee[V]*re+ee[V+1]*H+ee[V+2]*j+ee[V+3]*Ye)}let Oe=.6-Le*Le-Ve*Ve-Je*Je-ve*ve;if(Oe<0)c=0;else{const V=s[et+L+s[tt+I+s[it+X+s[rt+Z]]]]%32*4;Oe*=Oe,c=Oe*Oe*(ee[V]*Le+ee[V+1]*Ve+ee[V+2]*Je+ee[V+3]*ve)}let Be=.6-Ae*Ae-_e*_e-Ze*Ze-Ke*Ke;if(Be<0)l=0;else{const V=s[et+ie+s[tt+Q+s[it+pe+s[rt+me]]]]%32*4;Be*=Be,l=Be*Be*(ee[V]*Ae+ee[V+1]*_e+ee[V+2]*Ze+ee[V+3]*Ke)}let Ie=.6-W*W-Ge*Ge-Qe*Qe-_t*_t;if(Ie<0)u=0;else{const V=s[et+1+s[tt+1+s[it+1+s[rt+1]]]]%32*4;Ie*=Ie,u=Ie*Ie*(ee[V]*W+ee[V+1]*Ge+ee[V+2]*Qe+ee[V+3]*_t)}return 27*(a+o+c+l+u)}}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 i=t+~~(n()*(256-t)),r=e[t];e[t]=e[i],e[i]=r}return e}function tl(n){let e=0,t=0,i=0,r=1;const s=il();return e=s(" "),t=s(" "),i=s(" "),e-=s(n),e<0&&(e+=1),t-=s(n),t<0&&(t+=1),i-=s(n),i<0&&(i+=1),function(){const a=2091639*e+r*23283064365386963e-26;return e=t,t=i,i=a-(r=a|0)}}function il(){let n=4022871197;return function(e){e=e.toString();for(let t=0;t<e.length;t++){n+=e.charCodeAt(t);let i=.02519603282416938*n;n=i>>>0,i-=n,i*=n,n=i>>>0,i-=n,n+=i*4294967296}return(n>>>0)*23283064365386963e-26}}class qi{constructor(e,t,i,r){this.scale=e,this.octaves=t,this.velocityMultiplier=i,this.timeScale=r,this.type="TurbulenceField",this.generator=new ca,this.timeOffset=new B,this.temp=new B,this.temp2=new B,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 i=e.position.x/this.scale.x,r=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(i*a,r*a,s*a,this.timeOffset.x*a)/a,this.generator.noise4D(i*a,r*a,s*a,this.timeOffset.y*a)/a,this.generator.noise4D(i*a,r*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 qi(new B(e.scale[0],e.scale[1],e.scale[2]),e.octaves,new B(e.velocityMultiplier[0],e.velocityMultiplier[1],e.velocityMultiplier[2]),new B(e.timeScale[0],e.timeScale[1],e.timeScale[2]))}clone(){return new qi(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const $e=[],hn=new B,fn=new J;class Xi{constructor(e,t,i=new F(1),r=new F(0)){if(this.frequency=e,this.power=t,this.positionAmount=i,this.rotationAmount=r,this.type="Noise",this.duration=0,$e.length===0)for(let s=0;s<100;s++)$e.push(new ca)}initialize(e){e.lastPosNoise=new B,typeof e.rotation=="number"?e.lastRotNoise=0:e.lastRotNoise=new J,e.generatorIndex=[cr(0,100),cr(0,100),cr(0,100),cr(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 i=this.frequency.genValue(e.memory,e.age/e.life),r=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),hn.set($e[e.generatorIndex[0]].noise2D(0,e.age*i)*r*s,$e[e.generatorIndex[1]].noise2D(0,e.age*i)*r*s,$e[e.generatorIndex[2]].noise2D(0,e.age*i)*r*s),e.position.add(hn),e.lastPosNoise.copy(hn)),a>0&&e.lastRotNoise!==void 0&&(typeof e.rotation=="number"?(e.rotation-=e.lastRotNoise,e.rotation+=$e[e.generatorIndex[3]].noise2D(0,e.age*i)*Math.PI*r*a):(e.lastRotNoise.invert(),e.rotation.multiply(e.lastRotNoise),fn.set($e[e.generatorIndex[0]].noise2D(0,e.age*i)*r*a,$e[e.generatorIndex[1]].noise2D(0,e.age*i)*r*a,$e[e.generatorIndex[2]].noise2D(0,e.age*i)*r*a,$e[e.generatorIndex[3]].noise2D(0,e.age*i)*r*a).normalize(),e.rotation.multiply(fn),e.lastRotNoise.copy(fn)))}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON()}}frameUpdate(e){this.duration+=e}static fromJSON(e){return new Xi(U(e.frequency),U(e.power),U(e.positionAmount),U(e.rotationAmount))}clone(){return new Xi(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Hi{constructor(e,t){this.color=e,this.speedRange=t,this.type="ColorBySpeed"}initialize(e){this.color.startGen(e.memory)}update(e,t){const i=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(e.memory,e.color,i),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 Hi(ts(e.color),zt.fromJSON(e.speedRange))}clone(){return new Hi(this.color.clone(),this.speedRange.clone())}reset(){}}class Wi{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 Ot?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 Wi(Fr(e.size),zt.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Wi(this.size.clone(),this.speedRange.clone())}reset(){}}class Yi{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 i=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);e.rotation+=t*this.angularVelocity.genValue(e.memory,i)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Yi(U(e.angularVelocity),zt.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Yi(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class Zi{initialize(e){this.speed.startGen(e.memory)}constructor(e,t){this.speed=e,this.dampen=t,this.type="LimitSpeedOverLife"}update(e,t){let i=e.velocity.length(),r=this.speed.genValue(e.memory,e.age/e.life);if(i>r){const s=(i-r)/i;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 Zi(U(e.speed),e.dampen)}frameUpdate(e){}clone(){return new Zi(this.speed.clone(),this.dampen)}reset(){}}const Lr={ApplyForce:{type:"ApplyForce",constructor:Ji,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Ji.fromJSON},Noise:{type:"Noise",constructor:Xi,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Xi.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:qi,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:qi.fromJSON},GravityForce:{type:"GravityForce",constructor:Gi,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:Gi.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:Oi,params:[["color",["colorFunc"]]],loadJSON:Oi.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Bi,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Bi.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Ii,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Ii.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:Ui,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:Ui.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:Hi,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:Hi.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Yi,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Yi.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:Wi,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:Wi.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Fi,params:[["speed",["value","valueFunc"]]],loadJSON:Fi.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:Di,params:[["frame",["value","valueFunc"]]],loadJSON:Di.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:Ni,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:Ni.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:Li,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:Li.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Vi,params:[["width",["value","valueFunc"]]],loadJSON:Vi.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:ji,params:[["angle",["value"]]],loadJSON:ji.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:$i,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:$i.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:Zi,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:Zi.fromJSON}};function rl(n,e){return Lr[n.type]?Lr[n.type].loadJSON(n,e):null}const nl=[];function sl(n){if(!nl.find(t=>t.id===n.id)){for(const t of n.emitterShapes)Fn[t.type]||(Fn[t.type]=t);for(const t of n.behaviors)Lr[t.type]||(Lr[t.type]=t)}}var ol=`
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
- `,al=`
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
- `,cl=`
128
- #ifdef SOFT_PARTICLES
129
- varying vec4 projPosition;
130
- varying float linearDepth;
131
- #endif
132
- `,ll=`
133
- #ifdef SOFT_PARTICLES
134
- projPosition = gl_Position;
135
- linearDepth = -mvPosition.z;
136
- #endif
137
- `,ul=`
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
- `,hl=`
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
- `,fl=`
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
- `,dl=`
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 ft=M.ShaderChunk;function pl(){ft.tile_pars_vertex=fl,ft.tile_vertex=dl,ft.tile_pars_fragment=hl,ft.tile_fragment=ul,ft.soft_pars_vertex=cl,ft.soft_vertex=ll,ft.soft_pars_fragment=al,ft.soft_fragment=ol}class ml extends M.Object3D{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 i in e){const r=e[i];delete r.metadata,t.push(r)}return t}toJSON(e,t={}){const i=this.children;this.children=this.children.filter(s=>s.type!=="ParticleSystemPreview");const r=super.toJSON(e);return this.children=i,this.system!==null&&(r.object.ps=this.system.toJSON(e,t)),r}}exports.RenderMode=void 0;(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"})(exports.RenderMode||(exports.RenderMode={}));class la extends M.Mesh{constructor(e){super(),this.type="VFXBatch",this.maxParticles=1e3,this.systems=new Set;const t=new M.Layers;t.mask=e.layers.mask;const i=e.material.clone();i.defines={},Object.assign(i.defines,e.material.defines),this.settings={instancingGeometry:e.instancingGeometry,renderMode:e.renderMode,renderOrder:e.renderOrder,material:i,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 yl=new B(0,0,1),dn=new J,gl=new B,vl=new B;new B;const qs=60,_l=new M.PlaneGeometry(1,1,1,1);class Vr{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!=exports.RenderMode.Trail&&e===exports.RenderMode.Trail||this.rendererSettings.renderMode==exports.RenderMode.Trail&&e!==exports.RenderMode.Trail)&&(this.restart(),this.particles.length=0),this.rendererSettings.renderMode!==e)switch(e){case exports.RenderMode.Trail:this.rendererEmitterSettings={startLength:new F(30),followLocalOrigin:!1};break;case exports.RenderMode.Mesh:this.rendererEmitterSettings={geometry:new M.PlaneGeometry(1,1)},this.startRotation=new Pi(new B(0,1,0),new F(0));break;case exports.RenderMode.StretchedBillBoard:this.rendererEmitterSettings={speedFactor:0,lengthFactor:2},this.rendererSettings.renderMode===exports.RenderMode.Mesh&&(this.startRotation=new F(0));break;case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:this.rendererEmitterSettings={},this.rendererSettings.renderMode===exports.RenderMode.Mesh&&(this.startRotation=new F(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,i,r,s,a,o,c,l,u,h,f,d,y,_,p,m,v,g,b,x,S,T,w,P,C,R;if(this.temp=new B,this.travelDistance=0,this.normalMatrix=new He,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=(i=e.startLife)!==null&&i!==void 0?i:new F(5),this.startSpeed=(r=e.startSpeed)!==null&&r!==void 0?r:new F(0),this.startRotation=(s=e.startRotation)!==null&&s!==void 0?s:new F(0),this.startSize=(a=e.startSize)!==null&&a!==void 0?a:new F(1),this.startColor=(o=e.startColor)!==null&&o!==void 0?o:new At(new Se(1,1,1,1)),this.emissionOverTime=(c=e.emissionOverTime)!==null&&c!==void 0?c:new F(10),this.emissionOverDistance=(l=e.emissionOverDistance)!==null&&l!==void 0?l:new F(0),this.emissionBursts=(u=e.emissionBursts)!==null&&u!==void 0?u:[],this.onlyUsedByOther=(h=e.onlyUsedByOther)!==null&&h!==void 0?h:!1,this.emitterShape=(f=e.shape)!==null&&f!==void 0?f:new qt,this.behaviors=(d=e.behaviors)!==null&&d!==void 0?d:new Array,this.worldSpace=(y=e.worldSpace)!==null&&y!==void 0?y:!1,this.rendererEmitterSettings=(_=e.rendererEmitterSettings)!==null&&_!==void 0?_:{},e.renderMode===exports.RenderMode.StretchedBillBoard){const E=this.rendererEmitterSettings;e.speedFactor!==void 0&&(E.speedFactor=e.speedFactor),E.speedFactor=(p=E.speedFactor)!==null&&p!==void 0?p:0,E.lengthFactor=(m=E.lengthFactor)!==null&&m!==void 0?m:0}this.rendererSettings={instancingGeometry:(v=e.instancingGeometry)!==null&&v!==void 0?v:_l,renderMode:(g=e.renderMode)!==null&&g!==void 0?g:exports.RenderMode.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:(T=e.blendTiles)!==null&&T!==void 0?T:!1,softParticles:(w=e.softParticles)!==null&&w!==void 0?w:!1,softNearFade:(P=e.softNearFade)!==null&&P!==void 0?P:0,softFarFade:(C=e.softFarFade)!==null&&C!==void 0?C:0,layers:(R=e.layers)!==null&&R!==void 0?R:new M.Layers},this.neededToUpdateRender=!0,this.particles=new Array,this.startTileIndex=e.startTileIndex||new F(0),this.emitter=new ml(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(E=>E.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,i){dn.setFromRotationMatrix(i);const r=gl,s=dn,a=vl;i.decompose(r,s,a);for(let o=0;o<e;o++){for(t.burstParticleIndex=o,this.particleNum++;this.particles.length<this.particleNum;)this.rendererSettings.renderMode===exports.RenderMode.Trail?this.particles.push(new Dr):this.particles.push(new Wc);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===exports.RenderMode.Mesh||this.rendererSettings.renderMode===exports.RenderMode.BillBoard||this.rendererSettings.renderMode===exports.RenderMode.VerticalBillBoard||this.rendererSettings.renderMode===exports.RenderMode.HorizontalBillBoard||this.rendererSettings.renderMode===exports.RenderMode.StretchedBillBoard){const l=c;this.startRotation.startGen(c.memory),this.rendererSettings.renderMode===exports.RenderMode.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(yl,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===exports.RenderMode.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===exports.RenderMode.Trail&&this.rendererEmitterSettings.followLocalOrigin){const l=c;l.localPosition=new B().copy(l.position)}this.worldSpace?(c.position.applyMatrix4(i),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=i);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 i=0;i<this.duration*qs;i++)this.update(1/qs)}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 i=0;i<this.behaviors.length;i++){this.behaviors[i].frameUpdate(e);for(let r=0;r<this.particleNum;r++)this.particles[r].died||this.behaviors[i].update(this.particles[r],e)}for(let i=0;i<this.particleNum;i++)this.rendererEmitterSettings.followLocalOrigin&&this.particles[i].localPosition?(this.particles[i].position.copy(this.particles[i].localPosition),this.particles[i].parentMatrix?this.particles[i].position.applyMatrix4(this.particles[i].parentMatrix):this.particles[i].position.applyMatrix4(this.emitter.matrixWorld)):this.particles[i].position.addScaledVector(this.particles[i].velocity,e*this.particles[i].speedModifier),this.particles[i].age+=e;if(this.rendererSettings.renderMode===exports.RenderMode.Trail)for(let i=0;i<this.particleNum;i++)this.particles[i].update();for(let i=0;i<this.particleNum;i++){const r=this.particles[i];r.died&&(!(r instanceof Dr)||r.previous.length===0)&&(this.particles[i]=this.particles[this.particleNum-1],this.particles[this.particleNum-1]=r,this.particleNum--,i--,this.fire({type:"particleDied",particleSystem:this,particle:r}))}}emit(e,t,i){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(i);const r=Math.ceil(t.waitEmiting);for(this.spawn(r,t,i),t.waitEmiting-=r;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,i),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(i.elements[12],i.elements[13],i.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 B),t.previousWorldPos.set(i.elements[12],i.elements[13],i.elements[14]),t.time+=e}toJSON(e,t={}){var i;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&&((i=this.texture)===null||i===void 0?void 0:i.source)!==void 0){const o=this.texture.source;e.images[o.uuid]={uuid:o.uuid,url:this.texture.image.url}}let s;this.renderMode===exports.RenderMode.Trail?s={startLength:this.rendererEmitterSettings.startLength.toJSON(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===exports.RenderMode.Mesh?s={}:this.renderMode===exports.RenderMode.StretchedBillBoard?s={speedFactor:this.rendererEmitterSettings.speedFactor,lengthFactor:this.rendererEmitterSettings.lengthFactor}:s={};const a=this.rendererSettings.instancingGeometry;return e.geometries&&!e.geometries[a.uuid]&&(e.geometries[a.uuid]=a.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(o=>({time:o.time,count:o.count.toJSON(),probability:o.probability,interval:o.interval,cycle:o.cycle})),onlyUsedByOther:this.onlyUsedByOther,instancingGeometry:this.rendererSettings.instancingGeometry.uuid,renderOrder:this.renderOrder,renderMode:this.renderMode,rendererEmitterSettings:s,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(o=>o.toJSON()),worldSpace:this.worldSpace}}static fromJSON(e,t,i){var r,s;const a=Xc(e.shape,t);let o;if(e.renderMode===exports.RenderMode.Trail){const u=e.rendererEmitterSettings;o={startLength:u.startLength!=null?U(u.startLength):new F(30),followLocalOrigin:u.followLocalOrigin}}else e.renderMode===exports.RenderMode.Mesh?o={}:e.renderMode===exports.RenderMode.StretchedBillBoard?(o=e.rendererEmitterSettings,e.speedFactor!=null&&(o.speedFactor=e.speedFactor)):o={};const c=new M.Layers;e.layers&&(c.mask=e.layers);const l=new Vr({autoDestroy:e.autoDestroy,looping:e.looping,prewarm:e.prewarm,duration:e.duration,shape:a,startLife:U(e.startLife),startSpeed:U(e.startSpeed),startRotation:Fr(e.startRotation),startSize:Fr(e.startSize),startColor:ts(e.startColor),emissionOverTime:U(e.emissionOverTime),emissionOverDistance:U(e.emissionOverDistance),emissionBursts:(r=e.emissionBursts)===null||r===void 0?void 0:r.map(u=>{var h,f,d;return{time:u.time,count:typeof u.count=="number"?new F(u.count):U(u.count),probability:(h=u.probability)!==null&&h!==void 0?h:1,interval:(f=u.interval)!==null&&f!==void 0?f:.1,cycle:(d=u.cycle)!==null&&d!==void 0?d: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 M.MeshBasicMaterial({map:t.textures[e.texture],transparent:(s=e.transparent)!==null&&s!==void 0?s:!0,blending:e.blending,side:M.DoubleSide}):new M.MeshBasicMaterial({color:16777215,transparent:!0,blending:M.AdditiveBlending,side:M.DoubleSide}),startTileIndex:typeof e.startTileIndex=="number"?new F(e.startTileIndex):U(e.startTileIndex),uTileCount:e.uTileCount,vTileCount:e.vTileCount,blendTiles:e.blendTiles,softParticles:e.softParticles,softFarFade:e.softFarFade,softNearFade:e.softNearFade,behaviors:[],worldSpace:e.worldSpace});return l.behaviors=e.behaviors.map(u=>{const h=rl(u,l);return h.type==="EmitSubParticleSystem"&&(i[u.subParticleSystem]=h),h}),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 i=this.listeners[e].indexOf(t);i!==-1&&this.listeners[e].splice(i,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 i;this.renderMode===exports.RenderMode.Trail?i={startLength:this.rendererEmitterSettings.startLength.clone(),followLocalOrigin:this.rendererEmitterSettings.followLocalOrigin}:this.renderMode===exports.RenderMode.StretchedBillBoard?i={lengthFactor:this.rendererEmitterSettings.lengthFactor,speedFactor:this.rendererEmitterSettings.speedFactor}:i={};const r=new M.Layers;return r.mask=this.layers.mask,new Vr({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:i,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:r})}}var pn=`
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
- `,is=`
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
- }`,xl=`
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
- `,bl=`
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
- `,rs=`
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
- `,Sl=`
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 Dn(n){return n===0?"uv":`uv${n}`}class Tl extends M.MeshStandardMaterial{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=rs,e.fragmentShader=is}}class Ml extends M.MeshPhysicalMaterial{constructor(e){super(e)}onBeforeCompile(e,t){super.onBeforeCompile(e,t),e.vertexShader=rs,e.fragmentShader=is}}class Cl extends la{constructor(e){super(e),this.vector_=new B,this.vector2_=new B,this.vector3_=new B,this.quaternion_=new J,this.quaternion2_=new J,this.quaternion3_=new J,this.rotationMat_=new He,this.rotationMat2_=new He,this.maxParticles=1e3,this.setupBuffers(),this.rebuildMaterial()}buildExpandableBuffers(){this.offsetBuffer=new M.InstancedBufferAttribute(new Float32Array(this.maxParticles*3),3),this.offsetBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("offset",this.offsetBuffer),this.colorBuffer=new M.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.colorBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("color",this.colorBuffer),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer=new M.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.rotationBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("rotation",this.rotationBuffer)):(this.settings.renderMode===exports.RenderMode.BillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.StretchedBillBoard)&&(this.rotationBuffer=new M.InstancedBufferAttribute(new Float32Array(this.maxParticles),1),this.rotationBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("rotation",this.rotationBuffer)),this.sizeBuffer=new M.InstancedBufferAttribute(new Float32Array(this.maxParticles*3),3),this.sizeBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("size",this.sizeBuffer),this.uvTileBuffer=new M.InstancedBufferAttribute(new Float32Array(this.maxParticles),1),this.uvTileBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("uvTile",this.uvTileBuffer),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&(this.velocityBuffer=new M.InstancedBufferAttribute(new Float32Array(this.maxParticles*4),4),this.velocityBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("velocity",this.velocityBuffer))}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new M.InstancedBufferGeometry,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 M.Uniform$1(this.settings.material.map)),this.settings.material.alphaTest&&(t.USE_ALPHATEST="",e.alphaTest=new M.Uniform$1(this.settings.material.alphaTest)),t.USE_UV="";const i=this.settings.uTileCount,r=this.settings.vTileCount;(i>1||r>1)&&(t.UV_TILE="",e.tileCount=new M.Uniform$1(new jt(i,r))),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=Dn(this.settings.material.normalMap.channel),e.normalMapTransform=new M.Uniform$1(new He().copy(this.settings.material.normalMap.matrix))),this.settings.material.map&&(t.USE_MAP="",this.settings.blendTiles&&(t.TILE_BLEND=""),t.MAP_UV=Dn(this.settings.material.map.channel),e.mapTransform=new M.Uniform$1(new He().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 M.Uniform$1(new jt(o,c)),e.depthTexture=new M.Uniform$1(null);const l=e.projParams=new M.Uniform$1(new Se);s=(u,h,f)=>{l.value.set(f.near,f.far,0,0)}}let a=!1;if(this.settings.renderMode===exports.RenderMode.BillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.Mesh){let o,c;this.settings.renderMode===exports.RenderMode.Mesh?this.settings.material.type==="MeshStandardMaterial"||this.settings.material.type==="MeshPhysicalMaterial"?(t.USE_COLOR="",o=rs,c=is,a=!0):(o=bl,c=pn):(o=xl,c=pn),this.settings.renderMode===exports.RenderMode.VerticalBillBoard?t.VERTICAL="":this.settings.renderMode===exports.RenderMode.HorizontalBillBoard&&(t.HORIZONTAL="");let l=!1;this.settings.renderMode===exports.RenderMode.Mesh&&(this.settings.material.type==="MeshStandardMaterial"?(this.material=new Tl({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0):this.settings.material.type==="MeshPhysicalMaterial"&&(this.material=new Ml({}),this.material.copy(this.settings.material),this.material.uniforms=e,this.material.defines=t,l=!0)),l||(this.material=new M.ShaderMaterial({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===exports.RenderMode.StretchedBillBoard)e.speedFactor=new M.Uniform$1(1),this.material=new M.ShaderMaterial({uniforms:e,defines:t,vertexShader:Sl,fragmentShader:pn,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(i=>{t+=i.particleNum}),t>this.maxParticles&&this.expandBuffers(t),this.systems.forEach(i=>{i.emitter.updateMatrixWorld&&(i.emitter.updateWorldMatrix(!0,!1),i.emitter.updateMatrixWorld(!0));const r=i.particles,s=i.particleNum,a=this.quaternion2_,o=this.vector2_,c=this.vector3_;i.emitter.matrixWorld.decompose(o,a,c),this.rotationMat_.setFromMatrix4(i.emitter.matrixWorld);for(let l=0;l<s;l++,e++){const u=r[l];if(this.settings.renderMode===exports.RenderMode.Mesh){let f;if(i.worldSpace)f=u.rotation;else{let d;u.parentMatrix?d=this.quaternion3_.setFromRotationMatrix(u.parentMatrix):d=a,f=this.quaternion_,f.copy(d).multiply(u.rotation)}this.rotationBuffer.setXYZW(e,f.x,f.y,f.z,f.w)}else(this.settings.renderMode===exports.RenderMode.StretchedBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.BillBoard)&&this.rotationBuffer.setX(e,u.rotation);let h;if(i.worldSpace?h=u.position:(h=this.vector_,u.parentMatrix?h.copy(u.position).applyMatrix4(u.parentMatrix):h.copy(u.position).applyMatrix4(i.emitter.matrixWorld)),this.offsetBuffer.setXYZ(e,h.x,h.y,h.z),this.colorBuffer.setXYZW(e,u.color.x,u.color.y,u.color.z,u.color.w),i.worldSpace?this.sizeBuffer.setXYZ(e,u.size.x,u.size.y,u.size.z):u.parentMatrix?this.sizeBuffer.setXYZ(e,u.size.x,u.size.y,u.size.z):this.sizeBuffer.setXYZ(e,u.size.x*Math.abs(c.x),u.size.y*Math.abs(c.y),u.size.z*Math.abs(c.z)),this.uvTileBuffer.setX(e,u.uvTile),this.settings.renderMode===exports.RenderMode.StretchedBillBoard&&this.velocityBuffer){let f=i.rendererEmitterSettings.speedFactor;f===0&&(f=.001);const d=i.rendererEmitterSettings.lengthFactor;let y;i.worldSpace?y=u.velocity:(y=this.vector_,u.parentMatrix?(this.rotationMat2_.setFromMatrix4(u.parentMatrix),y.copy(u.velocity).applyMatrix3(this.rotationMat2_)):y.copy(u.velocity).applyMatrix3(this.rotationMat_)),this.velocityBuffer.setXYZW(e,y.x*f,y.y*f,y.z*f,d)}}}),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===exports.RenderMode.StretchedBillBoard&&this.velocityBuffer&&(this.velocityBuffer.clearUpdateRanges(),this.velocityBuffer.addUpdateRange(0,e*4),this.velocityBuffer.needsUpdate=!0),this.settings.renderMode===exports.RenderMode.Mesh?(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e*4),this.rotationBuffer.needsUpdate=!0):(this.settings.renderMode===exports.RenderMode.StretchedBillBoard||this.settings.renderMode===exports.RenderMode.HorizontalBillBoard||this.settings.renderMode===exports.RenderMode.VerticalBillBoard||this.settings.renderMode===exports.RenderMode.BillBoard)&&(this.rotationBuffer.clearUpdateRanges(),this.rotationBuffer.addUpdateRange(0,e),this.rotationBuffer.needsUpdate=!0))}dispose(){this.geometry.dispose()}}var Pl=`
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
- }`,wl=`
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 El extends la{constructor(e){super(e),this.vector_=new B,this.vector2_=new B,this.vector3_=new B,this.quaternion_=new J,this.maxParticles=1e4,this.setupBuffers(),this.rebuildMaterial()}setupBuffers(){this.geometry&&this.geometry.dispose(),this.geometry=new M.BufferGeometry,this.indexBuffer=new M.BufferAttribute(new Uint32Array(this.maxParticles*6),1),this.indexBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setIndex(this.indexBuffer),this.positionBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.positionBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("position",this.positionBuffer),this.previousBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.previousBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("previous",this.previousBuffer),this.nextBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*6),3),this.nextBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("next",this.nextBuffer),this.widthBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.widthBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("width",this.widthBuffer),this.sideBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*2),1),this.sideBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("side",this.sideBuffer),this.uvBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*4),2),this.uvBuffer.setUsage(M.DynamicDrawUsage),this.geometry.setAttribute("uv",this.uvBuffer),this.colorBuffer=new M.BufferAttribute(new Float32Array(this.maxParticles*8),4),this.colorBuffer.setUsage(M.DynamicDrawUsage),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 jt(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=Dn(this.settings.material.map.channel),e.map=new M.Uniform$1(this.settings.material.map),e.mapTransform=new M.Uniform$1(new He().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===exports.RenderMode.Trail)this.material=new M.ShaderMaterial({uniforms:e,defines:t,vertexShader:wl,fragmentShader:Pl,transparent:this.settings.material.transparent,depthWrite:!this.settings.material.transparent,side:this.settings.material.side,blending:this.settings.material.blending||M.AdditiveBlending,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,i=0;this.systems.forEach(r=>{for(let s=0;s<r.particleNum;s++)i+=r.particles[s].previous.length*2}),i>this.maxParticles&&this.expandBuffers(i),this.systems.forEach(r=>{r.emitter.updateMatrixWorld&&(r.emitter.updateWorldMatrix(!0,!1),r.emitter.updateMatrixWorld(!0));const s=this.quaternion_,a=this.vector2_,o=this.vector3_;r.emitter.matrixWorld.decompose(a,s,o);const c=r.particles,l=r.particleNum,u=this.settings.uTileCount,h=this.settings.vTileCount,f=1/u,d=1/h;for(let y=0;y<l;y++){const _=c[y],p=_.uvTile%h,m=Math.floor(_.uvTile/h+.001),v=_.previous.values();let g=v.next(),b=g.value,x=b;g.done||(g=v.next());let S;g.value!==void 0?S=g.value:S=x;for(let T=0;T<_.previous.length;T++,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),r.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)):(_.parentMatrix?this.vector_.copy(x.position).applyMatrix4(_.parentMatrix):this.vector_.copy(x.position).applyMatrix4(r.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)),r.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)):(_.parentMatrix?this.vector_.copy(b.position).applyMatrix4(_.parentMatrix):this.vector_.copy(b.position).applyMatrix4(r.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)),r.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)):(_.parentMatrix?this.vector_.copy(S.position).applyMatrix4(_.parentMatrix):this.vector_.copy(S.position).applyMatrix4(r.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),r.worldSpace)this.widthBuffer.setX(e,x.size),this.widthBuffer.setX(e+1,x.size);else if(_.parentMatrix)this.widthBuffer.setX(e,x.size),this.widthBuffer.setX(e+1,x.size);else{const w=(Math.abs(o.x)+Math.abs(o.y)+Math.abs(o.z))/3;this.widthBuffer.setX(e,x.size*w),this.widthBuffer.setX(e+1,x.size*w)}this.uvBuffer.setXY(e,(T/_.previous.length+p)*f,(h-m-1)*d),this.uvBuffer.setXY(e+1,(T/_.previous.length+p)*f,(h-m)*d),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),T+1<_.previous.length&&(this.indexBuffer.setX(t*3,e),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+2),t++,this.indexBuffer.setX(t*3,e+2),this.indexBuffer.setX(t*3+1,e+1),this.indexBuffer.setX(t*3+2,e+3),t++),b=x,x=S,g.done||(g=v.next(),g.value!==void 0&&(S=g.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 Ki{get geometry(){return this._geometry}set geometry(e){if(this._geometry=e,e===void 0||typeof e=="string")return;const t=new M.Triangle;this._triangleIndexToArea.length=0;let i=0;if(!e.getIndex())return;const r=e.getIndex().array,s=r.length/3;this._triangleIndexToArea.push(0);for(let a=0;a<s;a++)t.setFromAttributeAndIndices(e.getAttribute("position"),r[a*3],r[a*3+1],r[a*3+2]),i+=t.getArea(),this._triangleIndexToArea.push(i);e.userData.triangleIndexToArea=this._triangleIndexToArea}constructor(e){this.type="mesh_surface",this._triangleIndexToArea=[],this._tempA=new M.Vector3,this._tempB=new M.Vector3,this._tempC=new M.Vector3,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 i=this._triangleIndexToArea.length-1;let r=0,s=i;const a=Math.random()*this._triangleIndexToArea[i];for(;r+1<s;){const d=Math.floor((r+s)/2);a<this._triangleIndexToArea[d]?s=d:r=d}let o=Math.random(),c=Math.random();o+c>1&&(o=1-o,c=1-c);const l=t.getIndex().array[r*3],u=t.getIndex().array[r*3+1],h=t.getIndex().array[r*3+2],f=t.getAttribute("position");this._tempA.fromBufferAttribute(f,l),this._tempB.fromBufferAttribute(f,u),this._tempC.fromBufferAttribute(f,h),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 Ki(t.geometries[e.geometry])}clone(){return new Ki(this._geometry)}update(e,t){}}sl({id:"three.quarks",emitterShapes:[{type:"mesh_surface",params:[["geometry",["geometry"]]],constructor:Ki,loadJSON:Ki.fromJSON}],behaviors:[]});class ns extends M.Object3D{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 r=0;r<this.batches.length;r++)if(ns.equals(this.batches[r].settings,t)){this.batches[r].addSystem(e),this.systemToBatchIndex.set(e,r);return}let i;switch(t.renderMode){case exports.RenderMode.Trail:i=new El(t);break;case exports.RenderMode.Mesh:case exports.RenderMode.BillBoard:case exports.RenderMode.VerticalBillBoard:case exports.RenderMode.HorizontalBillBoard:case exports.RenderMode.StretchedBillBoard:i=new Cl(t);break}this.depthTexture&&i.applyDepthTexture(this.depthTexture),i.addSystem(e),this.batches.push(i),this.systemToBatchIndex.set(e,this.batches.length-1),this.add(i)}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,i)=>{i.update(e)});for(let t=0;t<this.batches.length;t++)this.batches[t].update()}}const Rl=ns;pl();console.log("%c Particle system powered by three.quarks. https://quarks.art/","font-size: 14px; font-weight: bold;");const ua=Math.sqrt(5),kl=(ua-1)/4,ae=(5-ua)/20,lr=n=>Math.floor(n)|0,ur=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 Al(n=Math.random){const e=zl(n),t=new Float64Array(e).map(a=>ur[a%32*4]),i=new Float64Array(e).map(a=>ur[a%32*4+1]),r=new Float64Array(e).map(a=>ur[a%32*4+2]),s=new Float64Array(e).map(a=>ur[a%32*4+3]);return function(o,c,l,u){let h,f,d,y,_;const p=(o+c+l+u)*kl,m=lr(o+p),v=lr(c+p),g=lr(l+p),b=lr(u+p),x=(m+v+g+b)*ae,S=m-x,T=v-x,w=g-x,P=b-x,C=o-S,R=c-T,E=l-w,k=u-P;let A=0,z=0,N=0,L=0;C>R?A++:z++,C>E?A++:N++,C>k?A++:L++,R>E?z++:N++,R>k?z++:L++,E>k?N++:L++;const I=A>=3?1:0,X=z>=3?1:0,Z=N>=3?1:0,ie=L>=3?1:0,Q=A>=2?1:0,pe=z>=2?1:0,me=N>=2?1:0,re=L>=2?1:0,H=A>=1?1:0,j=z>=1?1:0,Ye=N>=1?1:0,Le=L>=1?1:0,Ve=C-I+ae,Je=R-X+ae,ve=E-Z+ae,Ae=k-ie+ae,_e=C-Q+2*ae,Ze=R-pe+2*ae,Ke=E-me+2*ae,W=k-re+2*ae,Ge=C-H+3*ae,Qe=R-j+3*ae,_t=E-Ye+3*ae,et=k-Le+3*ae,tt=C-1+4*ae,it=R-1+4*ae,rt=E-1+4*ae,nt=k-1+4*ae,ze=m&255,Oe=v&255,Be=g&255,Ie=b&255;let V=.6-C*C-R*R-E*E-k*k;if(V<0)h=0;else{const q=ze+e[Oe+e[Be+e[Ie]]];V*=V,h=V*V*(t[q]*C+i[q]*R+r[q]*E+s[q]*k)}let Yt=.6-Ve*Ve-Je*Je-ve*ve-Ae*Ae;if(Yt<0)f=0;else{const q=ze+I+e[Oe+X+e[Be+Z+e[Ie+ie]]];Yt*=Yt,f=Yt*Yt*(t[q]*Ve+i[q]*Je+r[q]*ve+s[q]*Ae)}let Zt=.6-_e*_e-Ze*Ze-Ke*Ke-W*W;if(Zt<0)d=0;else{const q=ze+Q+e[Oe+pe+e[Be+me+e[Ie+re]]];Zt*=Zt,d=Zt*Zt*(t[q]*_e+i[q]*Ze+r[q]*Ke+s[q]*W)}let Kt=.6-Ge*Ge-Qe*Qe-_t*_t-et*et;if(Kt<0)y=0;else{const q=ze+H+e[Oe+j+e[Be+Ye+e[Ie+Le]]];Kt*=Kt,y=Kt*Kt*(t[q]*Ge+i[q]*Qe+r[q]*_t+s[q]*et)}let Qt=.6-tt*tt-it*it-rt*rt-nt*nt;if(Qt<0)_=0;else{const q=ze+1+e[Oe+1+e[Be+1+e[Ie+1]]];Qt*=Qt,_=Qt*Qt*(t[q]*tt+i[q]*it+r[q]*rt+s[q]*nt)}return 27*(h+f+d+y+_)}}function zl(n){const t=new Uint8Array(512);for(let i=0;i<512/2;i++)t[i]=i;for(let i=0;i<512/2-1;i++){const r=i+~~(n()*(256-i)),s=t[i];t[i]=t[r],t[r]=s}for(let i=256;i<512;i++)t[i]=t[i-256];return t}class Ol{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 G;(function(n){n.open="open",n.close="close",n.error="error",n.message="message",n.retry="retry",n.reconnect="reconnect"})(G||(G={}));class ha{constructor(e,t,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,v;this._closedByUser=!1,this.handleOpenEvent=g=>this.handleEvent(G.open,g),this.handleErrorEvent=g=>this.handleEvent(G.error,g),this.handleCloseEvent=g=>this.handleEvent(G.close,g),this.handleMessageEvent=g=>this.handleEvent(G.message,g),this._url=e,this._protocols=t,this._options={buffer:i?.buffer,retry:{maxRetries:(r=i?.retry)===null||r===void 0?void 0:r.maxRetries,instantReconnect:(s=i?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=i?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=i?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(u=(l=i?.listeners)===null||l===void 0?void 0:l.close)!==null&&u!==void 0?u:[]],error:[...(f=(h=i?.listeners)===null||h===void 0?void 0:h.error)!==null&&f!==void 0?f:[]],message:[...(y=(d=i?.listeners)===null||d===void 0?void 0:d.message)!==null&&y!==void 0?y:[]],retry:[...(p=(_=i?.listeners)===null||_===void 0?void 0:_.retry)!==null&&p!==void 0?p:[]],reconnect:[...(v=(m=i?.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,i){this._options.listeners[e].push({listener:t,options:i})}removeEventListener(e,t,i){const r=s=>s.listener!==t||s.options!==i;this._options.listeners[e]=this._options.listeners[e].filter(r)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(G.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(G.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(G.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(G.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(G.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(G.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(G.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(G.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const i=this._options.listeners[e],r=[];i.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&r.push({listener:s,options:a})}),this._options.listeners[e]=r}handleEvent(e,t){switch(e){case G.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case G.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const i={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},r=new CustomEvent(G.reconnect,{detail:i});this.dispatchEvent(G.reconnect,r),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case G.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=i=>{const r=new CustomEvent(G.retry,{detail:i});this.handleEvent(G.retry,r)},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 Bl{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(G.open,e,t),this}onClose(e,t){return this.addListener(G.close,e,t),this}onError(e,t){return this.addListener(G.error,e,t),this}onMessage(e,t){return this.addListener(G.message,e,t),this}onRetry(e,t){return this.addListener(G.retry,e,t),this}onReconnect(e,t){return this.addListener(G.reconnect,e,t),this}build(){return new ha(this._url,this._protocols,this._options)}addListener(e,t,i){var r,s,a,o,c,l,u,h,f,d,y,_,p,m,v,g,b,x,S,T,w;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(r=this._options)===null||r===void 0?void 0:r.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(f=(h=(u=this._options)===null||u===void 0?void 0:u.listeners)===null||h===void 0?void 0:h.error)!==null&&f!==void 0?f:[],message:(_=(y=(d=this._options)===null||d===void 0?void 0:d.listeners)===null||y===void 0?void 0:y.message)!==null&&_!==void 0?_:[],retry:(v=(m=(p=this._options)===null||p===void 0?void 0:p.listeners)===null||m===void 0?void 0:m.retry)!==null&&v!==void 0?v:[],reconnect:(x=(b=(g=this._options)===null||g===void 0?void 0:g.listeners)===null||b===void 0?void 0:b.reconnect)!==null&&x!==void 0?x:[],[e]:[...(w=(T=(S=this._options)===null||S===void 0?void 0:S.listeners)===null||T===void 0?void 0:T[e])!==null&&w!==void 0?w:[],{listener:t,options:i}]}}),this}}const Il=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Ol,Websocket:ha,WebsocketBuilder:Bl,get WebsocketEvent(){return G}},Symbol.toStringTag,{value:"Module"})),ss=0,fa=1,da=2,Ln=2,mn=1.25,Xs=1,gi=32,Xr=65535,Nl=Math.pow(2,-24),yn=Symbol("SKIP_GENERATION");function Ul(n){return n.index?n.index.count:n.attributes.position.count}function Wt(n){return Ul(n)/3}function Fl(n,e=ArrayBuffer){return n>65535?new Uint32Array(new e(4*n)):new Uint16Array(new e(2*n))}function Dl(n,e){if(!n.index){const t=n.attributes.position.count,i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Fl(t,i);n.setIndex(new M.BufferAttribute(r,1));for(let s=0;s<t;s++)r[s]=s}}function pa(n,e){const t=Wt(n),i=e||n.drawRange,r=i.start/3,s=(i.start+i.count)/3,a=Math.max(0,r),o=Math.min(t,s)-a;return[{offset:Math.floor(a),count:Math.floor(o)}]}function ma(n,e){if(!n.groups||!n.groups.length)return pa(n,e);const t=[],i=new Set,r=e||n.drawRange,s=r.start/3,a=(r.start+r.count)/3;for(const c of n.groups){const l=c.start/3,u=(c.start+c.count)/3;i.add(Math.max(s,l)),i.add(Math.min(a,u))}const o=Array.from(i.values()).sort((c,l)=>c-l);for(let c=0;c<o.length-1;c++){const l=o[c],u=o[c+1];t.push({offset:Math.floor(l),count:Math.floor(u-l)})}return t}function Ll(n,e){const t=Wt(n),i=ma(n,e).sort((a,o)=>a.offset-o.offset),r=i[i.length-1];r.count=Math.min(t-r.offset,r.count);let s=0;return i.forEach(({count:a})=>s+=a),t!==s}function gn(n,e,t,i,r){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0,h=1/0,f=1/0,d=1/0,y=-1/0,_=-1/0,p=-1/0;for(let m=e*6,v=(e+t)*6;m<v;m+=6){const g=n[m+0],b=n[m+1],x=g-b,S=g+b;x<s&&(s=x),S>c&&(c=S),g<h&&(h=g),g>y&&(y=g);const T=n[m+2],w=n[m+3],P=T-w,C=T+w;P<a&&(a=P),C>l&&(l=C),T<f&&(f=T),T>_&&(_=T);const R=n[m+4],E=n[m+5],k=R-E,A=R+E;k<o&&(o=k),A>u&&(u=A),R<d&&(d=R),R>p&&(p=R)}i[0]=s,i[1]=a,i[2]=o,i[3]=c,i[4]=l,i[5]=u,r[0]=h,r[1]=f,r[2]=d,r[3]=y,r[4]=_,r[5]=p}function Vl(n,e=null,t=null,i=null){const r=n.attributes.position,s=n.index?n.index.array:null,a=Wt(n),o=r.normalized;let c;e===null?(c=new Float32Array(a*6),t=0,i=a):(c=e,t=t||0,i=i||a);const l=r.array,u=r.offset||0;let h=3;r.isInterleavedBufferAttribute&&(h=r.data.stride);const f=["getX","getY","getZ"];for(let d=t;d<t+i;d++){const y=d*3,_=d*6;let p=y+0,m=y+1,v=y+2;s&&(p=s[p],m=s[m],v=s[v]),o||(p=p*h+u,m=m*h+u,v=v*h+u);for(let g=0;g<3;g++){let b,x,S;o?(b=r[f[g]](p),x=r[f[g]](m),S=r[f[g]](v)):(b=l[p+g],x=l[m+g],S=l[v+g]);let T=b;x<T&&(T=x),S<T&&(T=S);let w=b;x>w&&(w=x),S>w&&(w=S);const P=(w-T)/2,C=g*2;c[_+C+0]=T+P,c[_+C+1]=P+(Math.abs(T)+P)*Nl}}return c}function Y(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 Hs(n){let e=-1,t=-1/0;for(let i=0;i<3;i++){const r=n[i+3]-n[i];r>t&&(t=r,e=i)}return e}function Ws(n,e){e.set(n)}function Ys(n,e,t){let i,r;for(let s=0;s<3;s++){const a=s+3;i=n[s],r=e[s],t[s]=i<r?i:r,i=n[a],r=e[a],t[a]=i>r?i:r}}function hr(n,e,t){for(let i=0;i<3;i++){const r=e[n+2*i],s=e[n+2*i+1],a=r-s,o=r+s;a<t[i]&&(t[i]=a),o>t[i+3]&&(t[i+3]=o)}}function ri(n){const e=n[3]-n[0],t=n[4]-n[1],i=n[5]-n[2];return 2*(e*t+t*i+i*e)}const st=32,Jl=(n,e)=>n.candidate-e.candidate,dt=new Array(st).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),fr=new Float32Array(6);function Gl(n,e,t,i,r,s){let a=-1,o=0;if(s===ss)a=Hs(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===fa)a=Hs(n),a!==-1&&(o=jl(t,i,r,a));else if(s===da){const c=ri(n);let l=mn*r;const u=i*6,h=(i+r)*6;for(let f=0;f<3;f++){const d=e[f],p=(e[f+3]-d)/st;if(r<st/4){const m=[...dt];m.length=r;let v=0;for(let b=u;b<h;b+=6,v++){const x=m[v];x.candidate=t[b+2*f],x.count=0;const{bounds:S,leftCacheBounds:T,rightCacheBounds:w}=x;for(let P=0;P<3;P++)w[P]=1/0,w[P+3]=-1/0,T[P]=1/0,T[P+3]=-1/0,S[P]=1/0,S[P+3]=-1/0;hr(b,t,S)}m.sort(Jl);let g=r;for(let b=0;b<g;b++){const x=m[b];for(;b+1<g&&m[b+1].candidate===x.candidate;)m.splice(b+1,1),g--}for(let b=u;b<h;b+=6){const x=t[b+2*f];for(let S=0;S<g;S++){const T=m[S];x>=T.candidate?hr(b,t,T.rightCacheBounds):(hr(b,t,T.leftCacheBounds),T.count++)}}for(let b=0;b<g;b++){const x=m[b],S=x.count,T=r-x.count,w=x.leftCacheBounds,P=x.rightCacheBounds;let C=0;S!==0&&(C=ri(w)/c);let R=0;T!==0&&(R=ri(P)/c);const E=Xs+mn*(C*S+R*T);E<l&&(a=f,l=E,o=x.candidate)}}else{for(let g=0;g<st;g++){const b=dt[g];b.count=0,b.candidate=d+p+g*p;const x=b.bounds;for(let S=0;S<3;S++)x[S]=1/0,x[S+3]=-1/0}for(let g=u;g<h;g+=6){let S=~~((t[g+2*f]-d)/p);S>=st&&(S=st-1);const T=dt[S];T.count++,hr(g,t,T.bounds)}const m=dt[st-1];Ws(m.bounds,m.rightCacheBounds);for(let g=st-2;g>=0;g--){const b=dt[g],x=dt[g+1];Ys(b.bounds,x.rightCacheBounds,b.rightCacheBounds)}let v=0;for(let g=0;g<st-1;g++){const b=dt[g],x=b.count,S=b.bounds,w=dt[g+1].rightCacheBounds;x!==0&&(v===0?Ws(S,fr):Ys(S,fr,fr)),v+=x;let P=0,C=0;v!==0&&(P=ri(fr)/c);const R=r-v;R!==0&&(C=ri(w)/c);const E=Xs+mn*(P*v+C*R);E<l&&(a=f,l=E,o=b.candidate)}}}}else console.warn(`MeshBVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function jl(n,e,t,i){let r=0;for(let s=e,a=e+t;s<a;s++)r+=n[s*6+i*2];return r/t}class vn{constructor(){this.boundingData=new Float32Array(6)}}function $l(n,e,t,i,r,s){let a=i,o=i+r-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 u=0;u<3;u++){let h=e[a*3+u];e[a*3+u]=e[o*3+u],e[o*3+u]=h}for(let u=0;u<6;u++){let h=t[a*6+u];t[a*6+u]=t[o*6+u],t[o*6+u]=h}a++,o--}else return a}}function ql(n,e,t,i,r,s){let a=i,o=i+r-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 u=n[a];n[a]=n[o],n[o]=u;for(let h=0;h<6;h++){let f=t[a*6+h];t[a*6+h]=t[o*6+h],t[o*6+h]=f}a++,o--}else return a}}function be(n,e){return e[n+15]===65535}function Me(n,e){return e[n+6]}function Pe(n,e){return e[n+14]}function we(n){return n+8}function Ee(n,e){return e[n+6]}function ya(n,e){return e[n+7]}let ga,pi,zr,va;const Xl=Math.pow(2,32);function Vn(n){return"count"in n?1:1+Vn(n.left)+Vn(n.right)}function Hl(n,e,t){return ga=new Float32Array(t),pi=new Uint32Array(t),zr=new Uint16Array(t),va=new Uint8Array(t),Jn(n,e)}function Jn(n,e){const t=n/4,i=n/2,r="count"in e,s=e.boundingData;for(let a=0;a<6;a++)ga[t+a]=s[a];if(r)if(e.buffer){const a=e.buffer;va.set(new Uint8Array(a),n);for(let o=n,c=n+a.byteLength;o<c;o+=gi){const l=o/2;be(l,zr)||(pi[o/4+6]+=t)}return n+a.byteLength}else{const a=e.offset,o=e.count;return pi[t+6]=a,zr[i+14]=o,zr[i+15]=Xr,n+gi}else{const a=e.left,o=e.right,c=e.splitAxis;let l;if(l=Jn(n+gi,a),l/4>Xl)throw new Error("MeshBVH: Cannot store child pointer greater than 32 bits.");return pi[t+6]=l/4,l=Jn(l,o),pi[t+7]=c,l}}function Wl(n,e){const t=(n.index?n.index.count:n.attributes.position.count)/3,i=t>2**16,r=i?4:2,s=e?new SharedArrayBuffer(t*r):new ArrayBuffer(t*r),a=i?new Uint32Array(s):new Uint16Array(s);for(let o=0,c=a.length;o<c;o++)a[o]=o;return a}function Yl(n,e,t,i,r){const{maxDepth:s,verbose:a,maxLeafTris:o,strategy:c,onProgress:l,indirect:u}=r,h=n._indirectBuffer,f=n.geometry,d=f.index?f.index.array:null,y=u?ql:$l,_=Wt(f),p=new Float32Array(6);let m=!1;const v=new vn;return gn(e,t,i,v.boundingData,p),b(v,t,i,p),v;function g(x){l&&l(x/_)}function b(x,S,T,w=null,P=0){if(!m&&P>=s&&(m=!0,a&&(console.warn(`MeshBVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`),console.warn(f))),T<=o||P>=s)return g(S+T),x.offset=S,x.count=T,x;const C=Gl(x.boundingData,w,e,S,T,c);if(C.axis===-1)return g(S+T),x.offset=S,x.count=T,x;const R=y(h,d,e,S,T,C);if(R===S||R===S+T)g(S+T),x.offset=S,x.count=T;else{x.splitAxis=C.axis;const E=new vn,k=S,A=R-S;x.left=E,gn(e,k,A,E.boundingData,p),b(E,k,A,p,P+1);const z=new vn,N=R,L=T-A;x.right=z,gn(e,N,L,z.boundingData,p),b(z,N,L,p,P+1)}return x}}function Zl(n,e){const t=n.geometry;e.indirect&&(n._indirectBuffer=Wl(t,e.useSharedArrayBuffer),Ll(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||Dl(t,e);const i=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,r=Vl(t),s=e.indirect?pa(t,e.range):ma(t,e.range);n._roots=s.map(a=>{const o=Yl(n,r,a.offset,a.count,e),c=Vn(o),l=new i(gi*c);return Hl(0,o,l),l})}class ut{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let i=1/0,r=-1/0;for(let s=0,a=e.length;s<a;s++){const c=e[s][t];i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}setFromPoints(e,t){let i=1/0,r=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);i=c<i?c:i,r=c>r?c:r}this.min=i,this.max=r}isSeparated(e){return this.min>e.max||e.min>this.max}}ut.prototype.setFromBox=(function(){const n=new M.Vector3;return function(t,i){const r=i.min,s=i.max;let a=1/0,o=-1/0;for(let c=0;c<=1;c++)for(let l=0;l<=1;l++)for(let u=0;u<=1;u++){n.x=r.x*c+s.x*(1-c),n.y=r.y*l+s.y*(1-l),n.z=r.z*u+s.z*(1-u);const h=t.dot(n);a=Math.min(h,a),o=Math.max(h,o)}this.min=a,this.max=o}})();const Kl=(function(){const n=new M.Vector3,e=new M.Vector3,t=new M.Vector3;return function(r,s,a){const o=r.start,c=n,l=s.start,u=e;t.subVectors(o,l),n.subVectors(r.end,r.start),e.subVectors(s.end,s.start);const h=t.dot(u),f=u.dot(c),d=u.dot(u),y=t.dot(c),p=c.dot(c)*d-f*f;let m,v;p!==0?m=(h*f-y*d)/p:m=0,v=(h+m*f)/d,a.x=m,a.y=v}})(),os=(function(){const n=new M.Vector2,e=new M.Vector3,t=new M.Vector3;return function(r,s,a,o){Kl(r,s,n);let c=n.x,l=n.y;if(c>=0&&c<=1&&l>=0&&l<=1){r.at(c,a),s.at(l,o);return}else if(c>=0&&c<=1){l<0?s.at(0,o):s.at(1,o),r.closestPointToPoint(o,!0,a);return}else if(l>=0&&l<=1){c<0?r.at(0,a):r.at(1,a),s.closestPointToPoint(a,!0,o);return}else{let u;c<0?u=r.start:u=r.end;let h;l<0?h=s.start:h=s.end;const f=e,d=t;if(r.closestPointToPoint(h,!0,e),s.closestPointToPoint(u,!0,t),f.distanceToSquared(h)<=d.distanceToSquared(u)){a.copy(f),o.copy(h);return}else{a.copy(u),o.copy(d);return}}}})(),Ql=(function(){const n=new M.Vector3,e=new M.Vector3,t=new M.Plane,i=new M.Line3;return function(s,a){const{radius:o,center:c}=s,{a:l,b:u,c:h}=a;if(i.start=l,i.end=u,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o||(i.start=l,i.end=h,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o)||(i.start=u,i.end=h,i.closestPointToPoint(c,!0,n).distanceTo(c)<=o))return!0;const _=a.getPlane(t);if(Math.abs(_.distanceToPoint(c))<=o){const m=_.projectPoint(c,e);if(a.containsPoint(m))return!0}return!1}})(),eu=1e-15;function _n(n){return Math.abs(n)<eu}class ke extends M.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new M.Vector3),this.satBounds=new Array(4).fill().map(()=>new ut),this.points=[this.a,this.b,this.c],this.sphere=new M.Sphere,this.plane=new M.Plane,this.needsUpdate=!0}intersectsSphere(e){return Ql(e,this)}update(){const e=this.a,t=this.b,i=this.c,r=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,r);const l=s[1],u=a[1];l.subVectors(e,t),u.setFromPoints(l,r);const h=s[2],f=a[2];h.subVectors(t,i),f.setFromPoints(h,r);const d=s[3],y=a[3];d.subVectors(i,e),y.setFromPoints(d,r),this.sphere.setFromPoints(this.points),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}ke.prototype.closestPointToSegment=(function(){const n=new M.Vector3,e=new M.Vector3,t=new M.Line3;return function(r,s=null,a=null){const{start:o,end:c}=r,l=this.points;let u,h=1/0;for(let f=0;f<3;f++){const d=(f+1)%3;t.start.copy(l[f]),t.end.copy(l[d]),os(t,r,n,e),u=n.distanceToSquared(e),u<h&&(h=u,s&&s.copy(n),a&&a.copy(e))}return this.closestPointToPoint(o,n),u=o.distanceToSquared(n),u<h&&(h=u,s&&s.copy(n),a&&a.copy(o)),this.closestPointToPoint(c,n),u=c.distanceToSquared(n),u<h&&(h=u,s&&s.copy(n),a&&a.copy(c)),Math.sqrt(h)}})();ke.prototype.intersectsTriangle=(function(){const n=new ke,e=new Array(3),t=new Array(3),i=new ut,r=new ut,s=new M.Vector3,a=new M.Vector3,o=new M.Vector3,c=new M.Vector3,l=new M.Vector3,u=new M.Line3,h=new M.Line3,f=new M.Line3,d=new M.Vector3;function y(_,p,m){const v=_.points;let g=0,b=-1;for(let x=0;x<3;x++){const{start:S,end:T}=u;S.copy(v[x]),T.copy(v[(x+1)%3]),u.delta(a);const w=_n(p.distanceToPoint(S));if(_n(p.normal.dot(a))&&w){m.copy(u),g=2;break}const P=p.intersectLine(u,d);if(!P&&w&&d.copy(S),(P||w)&&!_n(d.distanceTo(T))){if(g<=1)(g===1?m.start:m.end).copy(d),w&&(b=g);else if(g>=2){(b===1?m.start:m.end).copy(d),g=2;break}if(g++,g===2&&b===-1)break}}return g}return function(p,m=null,v=!1){this.needsUpdate&&this.update(),p.isExtendedTriangle?p.needsUpdate&&p.update():(n.copy(p),n.update(),p=n);const g=this.plane,b=p.plane;if(Math.abs(g.normal.dot(b.normal))>1-1e-10){const x=this.satBounds,S=this.satAxes;t[0]=p.a,t[1]=p.b,t[2]=p.c;for(let P=0;P<4;P++){const C=x[P],R=S[P];if(i.setFromPoints(R,t),C.isSeparated(i))return!1}const T=p.satBounds,w=p.satAxes;e[0]=this.a,e[1]=this.b,e[2]=this.c;for(let P=0;P<4;P++){const C=T[P],R=w[P];if(i.setFromPoints(R,e),C.isSeparated(i))return!1}for(let P=0;P<4;P++){const C=S[P];for(let R=0;R<4;R++){const E=w[R];if(s.crossVectors(C,E),i.setFromPoints(s,e),r.setFromPoints(s,t),i.isSeparated(r))return!1}}return m&&(v||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),m.start.set(0,0,0),m.end.set(0,0,0)),!0}else{const x=y(this,b,h);if(x===1&&p.containsPoint(h.end))return m&&(m.start.copy(h.end),m.end.copy(h.end)),!0;if(x!==2)return!1;const S=y(p,g,f);if(S===1&&this.containsPoint(f.end))return m&&(m.start.copy(f.end),m.end.copy(f.end)),!0;if(S!==2)return!1;if(h.delta(o),f.delta(c),o.dot(c)<0){let k=f.start;f.start=f.end,f.end=k}const T=h.start.dot(o),w=h.end.dot(o),P=f.start.dot(o),C=f.end.dot(o),R=w<P,E=T<C;return T!==C&&P!==w&&R===E?!1:(m&&(l.subVectors(h.start,f.start),l.dot(o)>0?m.start.copy(h.start):m.start.copy(f.start),l.subVectors(h.end,f.end),l.dot(o)<0?m.end.copy(h.end):m.end.copy(f.end)),!0)}}})();ke.prototype.distanceToPoint=(function(){const n=new M.Vector3;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();ke.prototype.distanceToTriangle=(function(){const n=new M.Vector3,e=new M.Vector3,t=["a","b","c"],i=new M.Line3,r=new M.Line3;return function(a,o=null,c=null){const l=o||c?i:null;if(this.intersectsTriangle(a,l))return(o||c)&&(o&&l.getCenter(o),c&&l.getCenter(c)),0;let u=1/0;for(let h=0;h<3;h++){let f;const d=t[h],y=a[d];this.closestPointToPoint(y,n),f=y.distanceToSquared(n),f<u&&(u=f,o&&o.copy(n),c&&c.copy(y));const _=this[d];a.closestPointToPoint(_,n),f=_.distanceToSquared(n),f<u&&(u=f,o&&o.copy(_),c&&c.copy(n))}for(let h=0;h<3;h++){const f=t[h],d=t[(h+1)%3];i.set(this[f],this[d]);for(let y=0;y<3;y++){const _=t[y],p=t[(y+1)%3];r.set(a[_],a[p]),os(i,r,n,e);const m=n.distanceToSquared(e);m<u&&(u=m,o&&o.copy(n),c&&c.copy(e))}}return Math.sqrt(u)}})();class de{constructor(e,t,i){this.isOrientedBox=!0,this.min=new M.Vector3,this.max=new M.Vector3,this.matrix=new M.Matrix4,this.invMatrix=new M.Matrix4,this.points=new Array(8).fill().map(()=>new M.Vector3),this.satAxes=new Array(3).fill().map(()=>new M.Vector3),this.satBounds=new Array(3).fill().map(()=>new ut),this.alignedSatBounds=new Array(3).fill().map(()=>new ut),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),i&&this.matrix.copy(i)}set(e,t,i){this.min.copy(e),this.max.copy(t),this.matrix.copy(i),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}de.prototype.update=(function(){return function(){const e=this.matrix,t=this.min,i=this.max,r=this.points;for(let l=0;l<=1;l++)for(let u=0;u<=1;u++)for(let h=0;h<=1;h++){const f=1*l|2*u|4*h,d=r[f];d.x=l?i.x:t.x,d.y=u?i.y:t.y,d.z=h?i.z:t.z,d.applyMatrix4(e)}const s=this.satBounds,a=this.satAxes,o=r[0];for(let l=0;l<3;l++){const u=a[l],h=s[l],f=1<<l,d=r[f];u.subVectors(o,d),h.setFromPoints(u,r)}const c=this.alignedSatBounds;c[0].setFromPointsField(r,"x"),c[1].setFromPointsField(r,"y"),c[2].setFromPointsField(r,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})();de.prototype.intersectsBox=(function(){const n=new ut;return function(t){this.needsUpdate&&this.update();const i=t.min,r=t.max,s=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(n.min=i.x,n.max=r.x,o[0].isSeparated(n)||(n.min=i.y,n.max=r.y,o[1].isSeparated(n))||(n.min=i.z,n.max=r.z,o[2].isSeparated(n)))return!1;for(let c=0;c<3;c++){const l=a[c],u=s[c];if(n.setFromBox(l,t),u.isSeparated(n))return!1}return!0}})();de.prototype.intersectsTriangle=(function(){const n=new ke,e=new Array(3),t=new ut,i=new ut,r=new M.Vector3;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(n.copy(a),n.update(),a=n);const o=this.satBounds,c=this.satAxes;e[0]=a.a,e[1]=a.b,e[2]=a.c;for(let f=0;f<3;f++){const d=o[f],y=c[f];if(t.setFromPoints(y,e),d.isSeparated(t))return!1}const l=a.satBounds,u=a.satAxes,h=this.points;for(let f=0;f<3;f++){const d=l[f],y=u[f];if(t.setFromPoints(y,h),d.isSeparated(t))return!1}for(let f=0;f<3;f++){const d=c[f];for(let y=0;y<4;y++){const _=u[y];if(r.crossVectors(d,_),t.setFromPoints(r,e),i.setFromPoints(r,h),t.isSeparated(i))return!1}}return!0}})();de.prototype.closestPointToPoint=(function(){return function(e,t){return this.needsUpdate&&this.update(),t.copy(e).applyMatrix4(this.invMatrix).clamp(this.min,this.max).applyMatrix4(this.matrix),t}})();de.prototype.distanceToPoint=(function(){const n=new M.Vector3;return function(t){return this.closestPointToPoint(t,n),t.distanceTo(n)}})();de.prototype.distanceToBox=(function(){const n=["x","y","z"],e=new Array(12).fill().map(()=>new M.Line3),t=new Array(12).fill().map(()=>new M.Line3),i=new M.Vector3,r=new M.Vector3;return function(a,o=0,c=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(c||l)&&(a.getCenter(r),this.closestPointToPoint(r,i),a.closestPointToPoint(i,r),c&&c.copy(i),l&&l.copy(r)),0;const u=o*o,h=a.min,f=a.max,d=this.points;let y=1/0;for(let p=0;p<8;p++){const m=d[p];r.copy(m).clamp(h,f);const v=m.distanceToSquared(r);if(v<y&&(y=v,c&&c.copy(m),l&&l.copy(r),v<u))return Math.sqrt(v)}let _=0;for(let p=0;p<3;p++)for(let m=0;m<=1;m++)for(let v=0;v<=1;v++){const g=(p+1)%3,b=(p+2)%3,x=m<<g|v<<b,S=1<<p|m<<g|v<<b,T=d[x],w=d[S];e[_].set(T,w);const C=n[p],R=n[g],E=n[b],k=t[_],A=k.start,z=k.end;A[C]=h[C],A[R]=m?h[R]:f[R],A[E]=v?h[E]:f[R],z[C]=f[C],z[R]=m?h[R]:f[R],z[E]=v?h[E]:f[R],_++}for(let p=0;p<=1;p++)for(let m=0;m<=1;m++)for(let v=0;v<=1;v++){r.x=p?f.x:h.x,r.y=m?f.y:h.y,r.z=v?f.z:h.z,this.closestPointToPoint(r,i);const g=r.distanceToSquared(i);if(g<y&&(y=g,c&&c.copy(i),l&&l.copy(r),g<u))return Math.sqrt(g)}for(let p=0;p<12;p++){const m=e[p];for(let v=0;v<12;v++){const g=t[v];os(m,g,i,r);const b=i.distanceToSquared(r);if(b<y&&(y=b,c&&c.copy(i),l&&l.copy(r),b<u))return Math.sqrt(b)}}return Math.sqrt(y)}})();class as{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 tu extends as{constructor(){super(()=>new ke)}}const Re=new tu;class iu{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=i=>{t&&e.push(t),t=i,this.float32Array=new Float32Array(i),this.uint16Array=new Uint16Array(i),this.uint32Array=new Uint32Array(i)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const $=new iu;let gt,Gt;const It=[],dr=new as(()=>new M.Box3);function ru(n,e,t,i,r,s){gt=dr.getPrimitive(),Gt=dr.getPrimitive(),It.push(gt,Gt),$.setBuffer(n._roots[e]);const a=Gn(0,n.geometry,t,i,r,s);$.clearBuffer(),dr.releasePrimitive(gt),dr.releasePrimitive(Gt),It.pop(),It.pop();const o=It.length;return o>0&&(Gt=It[o-1],gt=It[o-2]),a}function Gn(n,e,t,i,r=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=$;let u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);return Y(n,o,gt),i(f,d,!1,a,s+n,gt)}else{let C=function(E){const{uint16Array:k,uint32Array:A}=$;let z=E*2;for(;!be(z,k);)E=we(E),z=E*2;return Me(E,A)},R=function(E){const{uint16Array:k,uint32Array:A}=$;let z=E*2;for(;!be(z,k);)E=Ee(E,A),z=E*2;return Me(E,A)+Pe(z,k)};const f=we(n),d=Ee(n,l);let y=f,_=d,p,m,v,g;if(r&&(v=gt,g=Gt,Y(y,o,v),Y(_,o,g),p=r(v),m=r(g),m<p)){y=d,_=f;const E=p;p=m,m=E,v=g}v||(v=gt,Y(y,o,v));const b=be(y*2,c),x=t(v,b,p,a+1,s+y);let S;if(x===Ln){const E=C(y),A=R(y)-E;S=i(E,A,!0,a+1,s+y,v)}else S=x&&Gn(y,e,t,i,r,s,a+1);if(S)return!0;g=Gt,Y(_,o,g);const T=be(_*2,c),w=t(g,T,m,a+1,s+_);let P;if(w===Ln){const E=C(_),A=R(_)-E;P=i(E,A,!0,a+1,s+_,g)}else P=w&&Gn(_,e,t,i,r,s,a+1);return!!P}}const ni=new M.Vector3,xn=new M.Vector3;function nu(n,e,t={},i=0,r=1/0){const s=i*i,a=r*r;let o=1/0,c=null;if(n.shapecast({boundsTraverseOrder:u=>(ni.copy(e).clamp(u.min,u.max),ni.distanceToSquared(e)),intersectsBounds:(u,h,f)=>f<o&&f<a,intersectsTriangle:(u,h)=>{u.closestPointToPoint(e,ni);const f=e.distanceToSquared(ni);return f<o&&(xn.copy(ni),o=f,c=h),f<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(xn):t.point=xn.clone(),t.distance=l,t.faceIndex=c,t}const su=parseInt(M.REVISION)>=169,St=new M.Vector3,Tt=new M.Vector3,Mt=new M.Vector3,pr=new M.Vector2,mr=new M.Vector2,yr=new M.Vector2,Zs=new M.Vector3,Ks=new M.Vector3,Qs=new M.Vector3,si=new M.Vector3;function ou(n,e,t,i,r,s,a,o){let c;if(s===M.BackSide?c=n.intersectTriangle(i,t,e,!0,r):c=n.intersectTriangle(e,t,i,s!==M.DoubleSide,r),c===null)return null;const l=n.origin.distanceTo(r);return l<a||l>o?null:{distance:l,point:r.clone()}}function au(n,e,t,i,r,s,a,o,c,l,u){St.fromBufferAttribute(e,s),Tt.fromBufferAttribute(e,a),Mt.fromBufferAttribute(e,o);const h=ou(n,St,Tt,Mt,si,c,l,u);if(h){const f=new M.Vector3;M.Triangle.getBarycoord(si,St,Tt,Mt,f),i&&(pr.fromBufferAttribute(i,s),mr.fromBufferAttribute(i,a),yr.fromBufferAttribute(i,o),h.uv=M.Triangle.getInterpolation(si,St,Tt,Mt,pr,mr,yr,new M.Vector2)),r&&(pr.fromBufferAttribute(r,s),mr.fromBufferAttribute(r,a),yr.fromBufferAttribute(r,o),h.uv1=M.Triangle.getInterpolation(si,St,Tt,Mt,pr,mr,yr,new M.Vector2)),t&&(Zs.fromBufferAttribute(t,s),Ks.fromBufferAttribute(t,a),Qs.fromBufferAttribute(t,o),h.normal=M.Triangle.getInterpolation(si,St,Tt,Mt,Zs,Ks,Qs,new M.Vector3),h.normal.dot(n.direction)>0&&h.normal.multiplyScalar(-1));const d={a:s,b:a,c:o,normal:new M.Vector3,materialIndex:0};M.Triangle.getNormal(St,Tt,Mt,d.normal),h.face=d,h.faceIndex=s,su&&(h.barycoord=f)}return h}function Hr(n,e,t,i,r,s,a){const o=i*3;let c=o+0,l=o+1,u=o+2;const h=n.index;n.index&&(c=h.getX(c),l=h.getX(l),u=h.getX(u));const{position:f,normal:d,uv:y,uv1:_}=n.attributes,p=au(t,f,d,y,_,c,l,u,e,s,a);return p?(p.faceIndex=i,r&&r.push(p),p):null}function te(n,e,t,i){const r=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)),r.x=i.getX(o),r.y=i.getY(o),r.z=i.getZ(o),s.x=i.getX(c),s.y=i.getY(c),s.z=i.getZ(c),a.x=i.getX(l),a.y=i.getY(l),a.z=i.getZ(l)}function cu(n,e,t,i,r,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let u=i,h=i+r;u<h;u++)Hr(c,e,t,u,s,a,o)}function lu(n,e,t,i,r,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,u=null;for(let h=i,f=i+r;h<f;h++){let d;d=Hr(o,e,t,h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function uu(n,e,t,i,r,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=n,h=e+n;u<h;u++){let f;if(f=u,te(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function hu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,r=t.attributes.position;let s,a,o,c,l=0;const u=n._roots;for(let f=0,d=u.length;f<d;f++)s=u[f],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),h(0,l),l+=s.byteLength;function h(f,d,y=!1){const _=f*2;if(o[_+15]===Xr){const m=a[f+6],v=o[_+14];let g=1/0,b=1/0,x=1/0,S=-1/0,T=-1/0,w=-1/0;for(let P=3*m,C=3*(m+v);P<C;P++){let R=i[P];const E=r.getX(R),k=r.getY(R),A=r.getZ(R);E<g&&(g=E),E>S&&(S=E),k<b&&(b=k),k>T&&(T=k),A<x&&(x=A),A>w&&(w=A)}return c[f+0]!==g||c[f+1]!==b||c[f+2]!==x||c[f+3]!==S||c[f+4]!==T||c[f+5]!==w?(c[f+0]=g,c[f+1]=b,c[f+2]=x,c[f+3]=S,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,v=a[f+6],g=m+d,b=v+d;let x=y,S=!1,T=!1;e?x||(S=e.has(g),T=e.has(b),x=!S&&!T):(S=!0,T=!0);const w=x||S,P=x||T;let C=!1;w&&(C=h(m,d,x));let R=!1;P&&(R=h(v,d,x));const E=C||R;if(E)for(let k=0;k<3;k++){const A=m+k,z=v+k,N=c[A],L=c[A+3],I=c[z],X=c[z+3];c[f+k]=N<I?N:I,c[f+k+3]=L>X?L:X}return E}}}function vt(n,e,t,i,r){let s,a,o,c,l,u;const h=1/t.direction.x,f=1/t.direction.y,d=1/t.direction.z,y=t.origin.x,_=t.origin.y,p=t.origin.z;let m=e[n],v=e[n+3],g=e[n+1],b=e[n+3+1],x=e[n+2],S=e[n+3+2];return h>=0?(s=(m-y)*h,a=(v-y)*h):(s=(v-y)*h,a=(m-y)*h),f>=0?(o=(g-_)*f,c=(b-_)*f):(o=(b-_)*f,c=(g-_)*f),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),d>=0?(l=(x-p)*d,u=(S-p)*d):(l=(S-p)*d,u=(x-p)*d),s>u||l>a)?!1:((l>s||s!==s)&&(s=l),(u<a||a!==a)&&(a=u),s<=r&&a>=i)}function fu(n,e,t,i,r,s,a,o){const{geometry:c,_indirectBuffer:l}=n;for(let u=i,h=i+r;u<h;u++){let f=l?l[u]:u;Hr(c,e,t,f,s,a,o)}}function du(n,e,t,i,r,s,a){const{geometry:o,_indirectBuffer:c}=n;let l=1/0,u=null;for(let h=i,f=i+r;h<f;h++){let d;d=Hr(o,e,t,c?c[h]:h,null,s,a),d&&d.distance<l&&(u=d,l=d.distance)}return u}function pu(n,e,t,i,r,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=n,h=e+n;u<h;u++){let f;if(f=t.resolveTriangleIndex(u),te(a,f*3,c,l),a.needsUpdate=!0,i(a,f,r,s))return!0}return!1}function mu(n,e,t,i,r,s,a){$.setBuffer(n._roots[e]),jn(0,n,t,i,r,s,a),$.clearBuffer()}function jn(n,e,t,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);cu(e,t,i,f,d,r,s,a)}else{const f=we(n);vt(f,o,i,s,a)&&jn(f,e,t,i,r,s,a);const d=Ee(n,l);vt(d,o,i,s,a)&&jn(d,e,t,i,r,s,a)}}const yu=["x","y","z"];function gu(n,e,t,i,r,s){$.setBuffer(n._roots[e]);const a=$n(0,n,t,i,r,s);return $.clearBuffer(),a}function $n(n,e,t,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(be(l,o)){const h=Me(n,c),f=Pe(l,o);return lu(e,t,i,h,f,r,s)}else{const h=ya(n,c),f=yu[h],y=i.direction[f]>=0;let _,p;y?(_=we(n),p=Ee(n,c)):(_=Ee(n,c),p=we(n));const v=vt(_,a,i,r,s)?$n(_,e,t,i,r,s):null;if(v){const x=v.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return v}const b=vt(p,a,i,r,s)?$n(p,e,t,i,r,s):null;return v&&b?v.distance<=b.distance?v:b:v||b||null}}const gr=new M.Box3,Nt=new ke,Ut=new ke,oi=new M.Matrix4,eo=new de,vr=new de;function vu(n,e,t,i){$.setBuffer(n._roots[e]);const r=qn(0,n,t,i);return $.clearBuffer(),r}function qn(n,e,t,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(t.boundingBox||t.computeBoundingBox(),eo.set(t.boundingBox.min,t.boundingBox.max,i),r=eo),be(c,a)){const u=e.geometry,h=u.index,f=u.attributes.position,d=t.index,y=t.attributes.position,_=Me(n,o),p=Pe(c,a);if(oi.copy(i).invert(),t.boundsTree)return Y(n,s,vr),vr.matrix.copy(oi),vr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:v=>vr.intersectsBox(v),intersectsTriangle:v=>{v.a.applyMatrix4(i),v.b.applyMatrix4(i),v.c.applyMatrix4(i),v.needsUpdate=!0;for(let g=_*3,b=(p+_)*3;g<b;g+=3)if(te(Ut,g,h,f),Ut.needsUpdate=!0,v.intersectsTriangle(Ut))return!0;return!1}});for(let m=_*3,v=(p+_)*3;m<v;m+=3){te(Nt,m,h,f),Nt.a.applyMatrix4(oi),Nt.b.applyMatrix4(oi),Nt.c.applyMatrix4(oi),Nt.needsUpdate=!0;for(let g=0,b=d.count;g<b;g+=3)if(te(Ut,g,d,y),Ut.needsUpdate=!0,Nt.intersectsTriangle(Ut))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,gr),!!(r.intersectsBox(gr)&&qn(u,e,t,i,r)||(Y(h,s,gr),r.intersectsBox(gr)&&qn(h,e,t,i,r)))}}const _r=new M.Matrix4,bn=new de,ai=new de,_u=new M.Vector3,xu=new M.Vector3,bu=new M.Vector3,Su=new M.Vector3;function Tu(n,e,t,i={},r={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),bn.set(e.boundingBox.min,e.boundingBox.max,t),bn.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,h=e.index,f=Re.getPrimitive(),d=Re.getPrimitive();let y=_u,_=xu,p=null,m=null;r&&(p=bu,m=Su);let v=1/0,g=null,b=null;return _r.copy(t).invert(),ai.matrix.copy(_r),n.shapecast({boundsTraverseOrder:x=>bn.distanceToBox(x),intersectsBounds:(x,S,T)=>T<v&&T<a?(S&&(ai.min.copy(x.min),ai.max.copy(x.max),ai.needsUpdate=!0),!0):!1,intersectsRange:(x,S)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:w=>ai.distanceToBox(w),intersectsBounds:(w,P,C)=>C<v&&C<a,intersectsRange:(w,P)=>{for(let C=w,R=w+P;C<R;C++){te(d,3*C,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let E=x,k=x+S;E<k;E++){te(f,3*E,l,c),f.needsUpdate=!0;const A=f.distanceToTriangle(d,y,p);if(A<v&&(_.copy(y),m&&m.copy(p),v=A,g=E,b=C),A<s)return!0}}}});{const T=Wt(e);for(let w=0,P=T;w<P;w++){te(d,3*w,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let C=x,R=x+S;C<R;C++){te(f,3*C,l,c),f.needsUpdate=!0;const E=f.distanceToTriangle(d,y,p);if(E<v&&(_.copy(y),m&&m.copy(p),v=E,g=C,b=w),E<s)return!0}}}}}),Re.releasePrimitive(f),Re.releasePrimitive(d),v===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=v,i.faceIndex=g,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(_r),_.applyMatrix4(_r),r.distance=_.sub(r.point).length(),r.faceIndex=b),i)}function Mu(n,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=n.geometry,i=t.index?t.index.array:null,r=t.attributes.position;let s,a,o,c,l=0;const u=n._roots;for(let f=0,d=u.length;f<d;f++)s=u[f],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),h(0,l),l+=s.byteLength;function h(f,d,y=!1){const _=f*2;if(o[_+15]===Xr){const m=a[f+6],v=o[_+14];let g=1/0,b=1/0,x=1/0,S=-1/0,T=-1/0,w=-1/0;for(let P=m,C=m+v;P<C;P++){const R=3*n.resolveTriangleIndex(P);for(let E=0;E<3;E++){let k=R+E;k=i?i[k]:k;const A=r.getX(k),z=r.getY(k),N=r.getZ(k);A<g&&(g=A),A>S&&(S=A),z<b&&(b=z),z>T&&(T=z),N<x&&(x=N),N>w&&(w=N)}}return c[f+0]!==g||c[f+1]!==b||c[f+2]!==x||c[f+3]!==S||c[f+4]!==T||c[f+5]!==w?(c[f+0]=g,c[f+1]=b,c[f+2]=x,c[f+3]=S,c[f+4]=T,c[f+5]=w,!0):!1}else{const m=f+8,v=a[f+6],g=m+d,b=v+d;let x=y,S=!1,T=!1;e?x||(S=e.has(g),T=e.has(b),x=!S&&!T):(S=!0,T=!0);const w=x||S,P=x||T;let C=!1;w&&(C=h(m,d,x));let R=!1;P&&(R=h(v,d,x));const E=C||R;if(E)for(let k=0;k<3;k++){const A=m+k,z=v+k,N=c[A],L=c[A+3],I=c[z],X=c[z+3];c[f+k]=N<I?N:I,c[f+k+3]=L>X?L:X}return E}}}function Cu(n,e,t,i,r,s,a){$.setBuffer(n._roots[e]),Xn(0,n,t,i,r,s,a),$.clearBuffer()}function Xn(n,e,t,i,r,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=$,u=n*2;if(be(u,c)){const f=Me(n,l),d=Pe(u,c);fu(e,t,i,f,d,r,s,a)}else{const f=we(n);vt(f,o,i,s,a)&&Xn(f,e,t,i,r,s,a);const d=Ee(n,l);vt(d,o,i,s,a)&&Xn(d,e,t,i,r,s,a)}}const Pu=["x","y","z"];function wu(n,e,t,i,r,s){$.setBuffer(n._roots[e]);const a=Hn(0,n,t,i,r,s);return $.clearBuffer(),a}function Hn(n,e,t,i,r,s){const{float32Array:a,uint16Array:o,uint32Array:c}=$;let l=n*2;if(be(l,o)){const h=Me(n,c),f=Pe(l,o);return du(e,t,i,h,f,r,s)}else{const h=ya(n,c),f=Pu[h],y=i.direction[f]>=0;let _,p;y?(_=we(n),p=Ee(n,c)):(_=Ee(n,c),p=we(n));const v=vt(_,a,i,r,s)?Hn(_,e,t,i,r,s):null;if(v){const x=v.point[f];if(y?x<=a[p+h]:x>=a[p+h+3])return v}const b=vt(p,a,i,r,s)?Hn(p,e,t,i,r,s):null;return v&&b?v.distance<=b.distance?v:b:v||b||null}}const xr=new M.Box3,Ft=new ke,Dt=new ke,ci=new M.Matrix4,to=new de,br=new de;function Eu(n,e,t,i){$.setBuffer(n._roots[e]);const r=Wn(0,n,t,i);return $.clearBuffer(),r}function Wn(n,e,t,i,r=null){const{float32Array:s,uint16Array:a,uint32Array:o}=$;let c=n*2;if(r===null&&(t.boundingBox||t.computeBoundingBox(),to.set(t.boundingBox.min,t.boundingBox.max,i),r=to),be(c,a)){const u=e.geometry,h=u.index,f=u.attributes.position,d=t.index,y=t.attributes.position,_=Me(n,o),p=Pe(c,a);if(ci.copy(i).invert(),t.boundsTree)return Y(n,s,br),br.matrix.copy(ci),br.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:v=>br.intersectsBox(v),intersectsTriangle:v=>{v.a.applyMatrix4(i),v.b.applyMatrix4(i),v.c.applyMatrix4(i),v.needsUpdate=!0;for(let g=_,b=p+_;g<b;g++)if(te(Dt,3*e.resolveTriangleIndex(g),h,f),Dt.needsUpdate=!0,v.intersectsTriangle(Dt))return!0;return!1}});for(let m=_,v=p+_;m<v;m++){const g=e.resolveTriangleIndex(m);te(Ft,3*g,h,f),Ft.a.applyMatrix4(ci),Ft.b.applyMatrix4(ci),Ft.c.applyMatrix4(ci),Ft.needsUpdate=!0;for(let b=0,x=d.count;b<x;b+=3)if(te(Dt,b,d,y),Dt.needsUpdate=!0,Ft.intersectsTriangle(Dt))return!0}}else{const u=n+8,h=o[n+6];return Y(u,s,xr),!!(r.intersectsBox(xr)&&Wn(u,e,t,i,r)||(Y(h,s,xr),r.intersectsBox(xr)&&Wn(h,e,t,i,r)))}}const Sr=new M.Matrix4,Sn=new de,li=new de,Ru=new M.Vector3,ku=new M.Vector3,Au=new M.Vector3,zu=new M.Vector3;function Ou(n,e,t,i={},r={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Sn.set(e.boundingBox.min,e.boundingBox.max,t),Sn.needsUpdate=!0;const o=n.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,h=e.index,f=Re.getPrimitive(),d=Re.getPrimitive();let y=Ru,_=ku,p=null,m=null;r&&(p=Au,m=zu);let v=1/0,g=null,b=null;return Sr.copy(t).invert(),li.matrix.copy(Sr),n.shapecast({boundsTraverseOrder:x=>Sn.distanceToBox(x),intersectsBounds:(x,S,T)=>T<v&&T<a?(S&&(li.min.copy(x.min),li.max.copy(x.max),li.needsUpdate=!0),!0):!1,intersectsRange:(x,S)=>{if(e.boundsTree){const T=e.boundsTree;return T.shapecast({boundsTraverseOrder:w=>li.distanceToBox(w),intersectsBounds:(w,P,C)=>C<v&&C<a,intersectsRange:(w,P)=>{for(let C=w,R=w+P;C<R;C++){const E=T.resolveTriangleIndex(C);te(d,3*E,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let k=x,A=x+S;k<A;k++){const z=n.resolveTriangleIndex(k);te(f,3*z,l,c),f.needsUpdate=!0;const N=f.distanceToTriangle(d,y,p);if(N<v&&(_.copy(y),m&&m.copy(p),v=N,g=k,b=C),N<s)return!0}}}})}else{const T=Wt(e);for(let w=0,P=T;w<P;w++){te(d,3*w,h,u),d.a.applyMatrix4(t),d.b.applyMatrix4(t),d.c.applyMatrix4(t),d.needsUpdate=!0;for(let C=x,R=x+S;C<R;C++){const E=n.resolveTriangleIndex(C);te(f,3*E,l,c),f.needsUpdate=!0;const k=f.distanceToTriangle(d,y,p);if(k<v&&(_.copy(y),m&&m.copy(p),v=k,g=C,b=w),k<s)return!0}}}}}),Re.releasePrimitive(f),Re.releasePrimitive(d),v===1/0?null:(i.point?i.point.copy(_):i.point=_.clone(),i.distance=v,i.faceIndex=g,r&&(r.point?r.point.copy(m):r.point=m.clone(),r.point.applyMatrix4(Sr),_.applyMatrix4(Sr),r.distance=_.sub(r.point).length(),r.faceIndex=b),i)}function Bu(){return typeof SharedArrayBuffer<"u"}const vi=new $.constructor,Jr=new $.constructor,mt=new as(()=>new M.Box3),Lt=new M.Box3,Vt=new M.Box3,Tn=new M.Box3,Mn=new M.Box3;let Cn=!1;function Iu(n,e,t,i){if(Cn)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");Cn=!0;const r=n._roots,s=e._roots;let a,o=0,c=0;const l=new M.Matrix4().copy(t).invert();for(let u=0,h=r.length;u<h;u++){vi.setBuffer(r[u]),c=0;const f=mt.getPrimitive();Y(0,vi.float32Array,f),f.applyMatrix4(l);for(let d=0,y=s.length;d<y&&(Jr.setBuffer(s[d]),a=Ue(0,0,t,l,i,o,c,0,0,f),Jr.clearBuffer(),c+=s[d].length,!a);d++);if(mt.releasePrimitive(f),vi.clearBuffer(),o+=r[u].length,a)break}return Cn=!1,a}function Ue(n,e,t,i,r,s=0,a=0,o=0,c=0,l=null,u=!1){let h,f;u?(h=Jr,f=vi):(h=vi,f=Jr);const d=h.float32Array,y=h.uint32Array,_=h.uint16Array,p=f.float32Array,m=f.uint32Array,v=f.uint16Array,g=n*2,b=e*2,x=be(g,_),S=be(b,v);let T=!1;if(S&&x)u?T=r(Me(e,m),Pe(e*2,v),Me(n,y),Pe(n*2,_),c,a+e,o,s+n):T=r(Me(n,y),Pe(n*2,_),Me(e,m),Pe(e*2,v),o,s+n,c,a+e);else if(S){const w=mt.getPrimitive();Y(e,p,w),w.applyMatrix4(t);const P=we(n),C=Ee(n,y);Y(P,d,Lt),Y(C,d,Vt);const R=w.intersectsBox(Lt),E=w.intersectsBox(Vt);T=R&&Ue(e,P,i,t,r,a,s,c,o+1,w,!u)||E&&Ue(e,C,i,t,r,a,s,c,o+1,w,!u),mt.releasePrimitive(w)}else{const w=we(e),P=Ee(e,m);Y(w,p,Tn),Y(P,p,Mn);const C=l.intersectsBox(Tn),R=l.intersectsBox(Mn);if(C&&R)T=Ue(n,w,t,i,r,s,a,o,c+1,l,u)||Ue(n,P,t,i,r,s,a,o,c+1,l,u);else if(C)if(x)T=Ue(n,w,t,i,r,s,a,o,c+1,l,u);else{const E=mt.getPrimitive();E.copy(Tn).applyMatrix4(t);const k=we(n),A=Ee(n,y);Y(k,d,Lt),Y(A,d,Vt);const z=E.intersectsBox(Lt),N=E.intersectsBox(Vt);T=z&&Ue(w,k,i,t,r,a,s,c,o+1,E,!u)||N&&Ue(w,A,i,t,r,a,s,c,o+1,E,!u),mt.releasePrimitive(E)}else if(R)if(x)T=Ue(n,P,t,i,r,s,a,o,c+1,l,u);else{const E=mt.getPrimitive();E.copy(Mn).applyMatrix4(t);const k=we(n),A=Ee(n,y);Y(k,d,Lt),Y(A,d,Vt);const z=E.intersectsBox(Lt),N=E.intersectsBox(Vt);T=z&&Ue(P,k,i,t,r,a,s,c,o+1,E,!u)||N&&Ue(P,A,i,t,r,a,s,c,o+1,E,!u),mt.releasePrimitive(E)}}return T}const Tr=new de,io=new M.Box3,Nu={strategy:ss,maxDepth:40,maxLeafTris:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null};class tr{static serialize(e,t={}){t={cloneBuffers:!0,...t};const i=e.geometry,r=e._roots,s=e._indirectBuffer,a=i.getIndex();let o;return t.cloneBuffers?o={roots:r.map(c=>c.slice()),index:a?a.array.slice():null,indirectBuffer:s?s.slice():null}:o={roots:r,index:a?a.array:null,indirectBuffer:s},o}static deserialize(e,t,i={}){i={setIndex:!0,indirect:!!e.indirectBuffer,...i};const{index:r,roots:s,indirectBuffer:a}=e,o=new tr(t,{...i,[yn]:!0});if(o._roots=s,o._indirectBuffer=a||null,i.setIndex){const c=t.getIndex();if(c===null){const l=new M.BufferAttribute(e.index,1,!1);t.setIndex(l)}else c.array!==r&&(c.array.set(r),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({...Nu,[yn]:!1},t),t.useSharedArrayBuffer&&!Bu())throw new Error("MeshBVH: SharedArrayBuffer is not available.");this.geometry=e,this._roots=null,this._indirectBuffer=null,t[yn]||(Zl(this,t),!e.boundingBox&&t.setBoundingBox&&(e.boundingBox=this.getBoundingBox(new M.Box3))),this.resolveTriangleIndex=t.indirect?i=>this._indirectBuffer[i]:i=>i}refit(e=null){return(this.indirect?Mu:hu)(this,e)}traverse(e,t=0){const i=this._roots[t],r=new Uint32Array(i),s=new Uint16Array(i);a(0);function a(o,c=0){const l=o*2,u=s[l+15]===Xr;if(u){const h=r[o+6],f=s[l+14];e(c,u,new Float32Array(i,o*4,6),h,f)}else{const h=o+gi/4,f=r[o+6],d=r[o+7];e(c,u,new Float32Array(i,o*4,6),d)||(a(h,c+1),a(f,c+1))}}}raycast(e,t=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=[],c=t.isMaterial,l=Array.isArray(t),u=a.groups,h=c?t.side:t,f=this.indirect?Cu:mu;for(let d=0,y=s.length;d<y;d++){const _=l?t[u[d].materialIndex].side:h,p=o.length;if(f(this,d,_,e,o,i,r),l){const m=u[d].materialIndex;for(let v=p,g=o.length;v<g;v++)o[v].face.materialIndex=m}}return o}raycastFirst(e,t=M.FrontSide,i=0,r=1/0){const s=this._roots,a=this.geometry,o=t.isMaterial,c=Array.isArray(t);let l=null;const u=a.groups,h=o?t.side:t,f=this.indirect?wu:gu;for(let d=0,y=s.length;d<y;d++){const _=c?t[u[d].materialIndex].side:h,p=f(this,d,_,e,i,r);p!=null&&(l==null||p.distance<l.distance)&&(l=p,c&&(p.face.materialIndex=u[d].materialIndex))}return l}intersectsGeometry(e,t){let i=!1;const r=this._roots,s=this.indirect?Eu:vu;for(let a=0,o=r.length;a<o&&(i=s(this,a,e,t),!i);a++);return i}shapecast(e){const t=Re.getPrimitive(),i=this.indirect?pu:uu;let{boundsTraverseOrder:r,intersectsBounds:s,intersectsRange:a,intersectsTriangle:o}=e;if(a&&o){const h=a;a=(f,d,y,_,p)=>h(f,d,y,_,p)?!0:i(f,d,this,o,y,_,t)}else a||(o?a=(h,f,d,y)=>i(h,f,this,o,d,y,t):a=(h,f,d)=>d);let c=!1,l=0;const u=this._roots;for(let h=0,f=u.length;h<f;h++){const d=u[h];if(c=ru(this,h,s,a,r,l),c)break;l+=d.byteLength}return Re.releasePrimitive(t),c}bvhcast(e,t,i){let{intersectsRanges:r,intersectsTriangles:s}=i;const a=Re.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?y=>{const _=this.resolveTriangleIndex(y);te(a,_*3,o,c)}:y=>{te(a,y*3,o,c)},u=Re.getPrimitive(),h=e.geometry.index,f=e.geometry.attributes.position,d=e.indirect?y=>{const _=e.resolveTriangleIndex(y);te(u,_*3,h,f)}:y=>{te(u,y*3,h,f)};if(s){const y=(_,p,m,v,g,b,x,S)=>{for(let T=m,w=m+v;T<w;T++){d(T),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let P=_,C=_+p;P<C;P++)if(l(P),a.needsUpdate=!0,s(a,u,P,T,g,b,x,S))return!0}return!1};if(r){const _=r;r=function(p,m,v,g,b,x,S,T){return _(p,m,v,g,b,x,S,T)?!0:y(p,m,v,g,b,x,S,T)}}else r=y}return Iu(this,e,t,r)}intersectsBox(e,t){return Tr.set(e.min,e.max,t),Tr.needsUpdate=!0,this.shapecast({intersectsBounds:i=>Tr.intersectsBox(i),intersectsTriangle:i=>Tr.intersectsTriangle(i)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,i={},r={},s=0,a=1/0){return(this.indirect?Ou:Tu)(this,e,t,i,r,s,a)}closestPointToPoint(e,t={},i=0,r=1/0){return nu(this,e,t,i,r)}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(i=>{Y(0,new Float32Array(i),io),e.union(io)}),e}}function ro(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 Mr=new M.Ray,no=new M.Vector3,so=new M.Matrix4,Uu=M.Mesh.prototype.raycast,Fu=M.BatchedMesh.prototype.raycast,oo=new M.Vector3,ce=new M.Mesh,Cr=[];function Du(n,e){this.isBatchedMesh?Lu.call(this,n,e):Vu.call(this,n,e)}function Lu(n,e){if(this.boundsTrees){const t=this.boundsTrees,i=this._drawInfo||this._instanceInfo,r=this._drawRanges||this._geometryInfo,s=this.matrixWorld;ce.material=this.material,ce.geometry=this.geometry;const a=ce.geometry.boundsTree,o=ce.geometry.drawRange;ce.geometry.boundingSphere===null&&(ce.geometry.boundingSphere=new M.Sphere);for(let c=0,l=i.length;c<l;c++){if(!this.getVisibleAt(c))continue;const u=i[c].geometryIndex;if(ce.geometry.boundsTree=t[u],this.getMatrixAt(c,ce.matrixWorld).premultiply(s),!ce.geometry.boundsTree){this.getBoundingBoxAt(u,ce.geometry.boundingBox),this.getBoundingSphereAt(u,ce.geometry.boundingSphere);const h=r[u];ce.geometry.setDrawRange(h.start,h.count)}ce.raycast(n,Cr);for(let h=0,f=Cr.length;h<f;h++){const d=Cr[h];d.object=this,d.batchId=c,e.push(d)}Cr.length=0}ce.geometry.boundsTree=a,ce.geometry.drawRange=o,ce.material=null,ce.geometry=null}else Fu.call(this,n,e)}function Vu(n,e){if(this.geometry.boundsTree){if(this.material===void 0)return;so.copy(this.matrixWorld).invert(),Mr.copy(n.ray).applyMatrix4(so),oo.setFromMatrixScale(this.matrixWorld),no.copy(Mr.direction).multiply(oo);const t=no.length(),i=n.near/t,r=n.far/t,s=this.geometry.boundsTree;if(n.firstHitOnly===!0){const a=ro(s.raycastFirst(Mr,this.material,i,r),this,n);a&&e.push(a)}else{const a=s.raycast(Mr,this.material,i,r);for(let o=0,c=a.length;o<c;o++){const l=ro(a[o],this,n);l&&e.push(l)}}}else Uu.call(this,n,e)}function Ju(n={}){return this.boundsTree=new tr(this,n),this.boundsTree}const Ct=new M.Vector3,Pt=new M.Vector3,wt=new M.Vector3,ao=new M.Vector4,Pr=new M.Vector3,Pn=new M.Vector3,co=new M.Vector4,lo=new M.Vector4,wr=new M.Matrix4,uo=new M.Matrix4;function ui(n,e){if(!n&&!e)return;const t=n.count===e.count,i=n.normalized===e.normalized,r=n.array.constructor===e.array.constructor,s=n.itemSize===e.itemSize;if(!t||!i||!r||!s)throw new Error}function mi(n,e=null){const t=n.array.constructor,i=n.normalized,r=n.itemSize,s=e===null?n.count:e;return new M.BufferAttribute(new t(r*s),r,i)}function _a(n,e,t=0){if(n.isInterleavedBufferAttribute){const i=n.itemSize;for(let r=0,s=n.count;r<s;r++){const a=r+t;e.setX(a,n.getX(r)),i>=2&&e.setY(a,n.getY(r)),i>=3&&e.setZ(a,n.getZ(r)),i>=4&&e.setW(a,n.getW(r))}}else{const i=e.array,r=i.constructor,s=i.BYTES_PER_ELEMENT*n.itemSize*t;new r(i.buffer,s,n.array.length).set(n.array)}}function Gu(n,e,t){const i=n.elements,r=e.elements;for(let s=0,a=r.length;s<a;s++)i[s]+=r[s]*t}function ho(n,e,t){const i=n.skeleton,r=n.geometry,s=i.bones,a=i.boneInverses;co.fromBufferAttribute(r.attributes.skinIndex,e),lo.fromBufferAttribute(r.attributes.skinWeight,e),wr.elements.fill(0);for(let o=0;o<4;o++){const c=lo.getComponent(o);if(c!==0){const l=co.getComponent(o);uo.multiplyMatrices(s[l].matrixWorld,a[l]),Gu(wr,uo,c)}}return wr.multiply(n.bindMatrix).premultiply(n.bindMatrixInverse),t.transformDirection(wr),t}function wn(n,e,t,i,r){Pr.set(0,0,0);for(let s=0,a=n.length;s<a;s++){const o=e[s],c=n[s];o!==0&&(Pn.fromBufferAttribute(c,i),t?Pr.addScaledVector(Pn,o):Pr.addScaledVector(Pn.sub(r),o))}r.add(Pr)}function ju(n,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new M.BufferGeometry){const i=n[0].index!==null,{useGroups:r=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(n[0].attributes)),c={};let l=0;t.clearGroups();for(let u=0;u<n.length;++u){const h=n[u];let f=0;if(i!==(h.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 d in h.attributes){if(!o.has(d))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+d+'" attribute exists among all geometries, or in none of them.');c[d]===void 0&&(c[d]=[]),c[d].push(h.attributes[d]),f++}if(f!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(r){let d;if(i)d=h.index.count;else if(h.attributes.position!==void 0)d=h.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,d,u),l+=d}}if(i){let u=!1;if(!t.index){let h=0;for(let f=0;f<n.length;++f)h+=n[f].index.count;t.setIndex(new M.BufferAttribute(new Uint32Array(h),1,!1)),u=!0}if(s||u){const h=t.index;let f=0,d=0;for(let y=0;y<n.length;++y){const _=n[y],p=_.index;if(a[y]!==!0)for(let m=0;m<p.count;++m)h.setX(f,p.getX(m)+d),f++;d+=_.attributes.position.count}}}for(const u in c){const h=c[u];if(!(u in t.attributes)){let y=0;for(const _ in h)y+=h[_].count;t.setAttribute(u,mi(c[u][0],y))}const f=t.attributes[u];let d=0;for(let y=0,_=h.length;y<_;y++){const p=h[y];a[y]!==!0&&_a(p,f,d),d+=p.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,i=n.length;t<i;t++)if(n[t]!==e[t])return!1;return!0}function qu(n){const{index:e,attributes:t}=n;if(e)for(let i=0,r=e.count;i<r;i+=3){const s=e.getX(i),a=e.getX(i+2);e.setX(i,a),e.setX(i+2,s)}else for(const i in t){const r=t[i],s=r.itemSize;for(let a=0,o=r.count;a<o;a+=3)for(let c=0;c<s;c++){const l=r.getComponent(a,c),u=r.getComponent(a+2,c);r.setComponent(a,c,u),r.setComponent(a+2,c,l)}}return n}class Xu{constructor(e){this.matrixWorld=new M.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,i=e.skeleton,r=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=r,i){i.boneTexture||i.computeBoneTexture(),i.update();const s=i.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,i=(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===i)}}class Hu{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(i=>{i.traverseVisible(r=>{r.isMesh&&t.push(r)})}),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 M.BufferGeometry),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 M.BufferGeometry){let t=[];const{meshes:i,useGroups:r,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=i.length;o<c;o++){const l=i[o],u=s[o],h=a.get(l);!h||h.didChange(l)?(this._convertToStaticGeometry(l,u),t.push(!1),h?h.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 M.BufferAttribute(new Float32Array(0),4,!1))}else ju(s,{useGroups:r,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new M.BufferGeometry){const i=e.geometry,r=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=i.attributes,c=t.attributes;!t.index&&i.index&&(t.index=i.index.clone()),c.position||t.setAttribute("position",mi(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",mi(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",mi(o.tangent)),ui(i.index,t.index),ui(o.position,c.position),s&&ui(o.normal,c.normal),a&&ui(o.tangent,c.tangent);const l=o.position,u=s?o.normal:null,h=a?o.tangent:null,f=i.morphAttributes.position,d=i.morphAttributes.normal,y=i.morphAttributes.tangent,_=i.morphTargetsRelative,p=e.morphTargetInfluences,m=new M.Matrix3;m.getNormalMatrix(e.matrixWorld),i.index&&t.index.array.set(i.index.array);for(let v=0,g=o.position.count;v<g;v++)Ct.fromBufferAttribute(l,v),u&&Pt.fromBufferAttribute(u,v),h&&(ao.fromBufferAttribute(h,v),wt.fromBufferAttribute(h,v)),p&&(f&&wn(f,p,_,v,Ct),d&&wn(d,p,_,v,Pt),y&&wn(y,p,_,v,wt)),e.isSkinnedMesh&&(e.applyBoneTransform(v,Ct),u&&ho(e,v,Pt),h&&ho(e,v,wt)),r&&Ct.applyMatrix4(e.matrixWorld),c.position.setXYZ(v,Ct.x,Ct.y,Ct.z),u&&(r&&Pt.applyNormalMatrix(m),c.normal.setXYZ(v,Pt.x,Pt.y,Pt.z)),h&&(r&&wt.transformDirection(e.matrixWorld),c.tangent.setXYZW(v,wt.x,wt.y,wt.z,ao.w));for(const v in this.attributes){const g=this.attributes[v];g==="position"||g==="tangent"||g==="normal"||!(g in o)||(c[g]||t.setAttribute(g,mi(o[g])),ui(o[g],c[g]),_a(o[g],c[g]))}return e.matrixWorld.determinant()<0&&qu(t),t}}const Wu=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:fa,CENTER:ss,CONTAINED:Ln,ExtendedTriangle:ke,MeshBVH:tr,OrientedBox:de,SAH:da,StaticGeometryGenerator:Hu,acceleratedRaycast:Du,computeBoundsTree:Ju},Symbol.toStringTag,{value:"Module"}));class Yu{constructor(e){this.name="WorkerBase",this.running=!1,this.worker=e,this.worker.onerror=t=>{throw t.message?new Error(`${this.name}: Could not create Web Worker with error "${t.message}"`):new Error(`${this.name}: Could not create Web Worker.`)}}runTask(){}generate(...e){if(this.running)throw new Error("GenerateMeshBVHWorker: Already running job.");if(this.worker===null)throw new Error("GenerateMeshBVHWorker: Worker has been disposed.");this.running=!0;const t=this.runTask(this.worker,...e);return t.finally(()=>{this.running=!1}),t}dispose(){this.worker.terminate(),this.worker=null}}const Ce={node:"node",material:"material",camera:"camera",light:"light"},Et="KHR_animation_pointer",Zu={CUBICSPLINE:void 0,LINEAR:M.InterpolateLinear,STEP:M.InterpolateDiscrete};class Ku{constructor(e){this.name=Et,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,i=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",i)}loadAnimationTargetFromChannelWithAnimationPointer(e){eh();const t=e.target,i=t.extensions&&t.extensions[Et]&&t.path&&t.path==="pointer";if(!i)return null;let r,s=Ce.node,a;if(i){const c=t.extensions[Et];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=Ce.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=Ce.light:l.startsWith("/cameras/")&&(s=Ce.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case Ce.material:const u=("/materials/"+a.toString()+"/").length,h=l.substring(0,u);switch(r=l.substring(u),r){case"pbrMetallicRoughness/baseColorFactor":r="color";break;case"pbrMetallicRoughness/roughnessFactor":r="roughness";break;case"pbrMetallicRoughness/metallicFactor":r="metalness";break;case"emissiveFactor":r="emissive";break;case"alphaCutoff":r="alphaTest";break;case"occlusionTexture/strength":r="aoMapIntensity";break;case"normalTexture/scale":r="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":r="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":r="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":r="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":r="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":r="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":r="transmission";break;case"extensions/KHR_materials_ior/ior":r="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":r="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":r="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":r="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":r="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":r="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":r="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":r="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":r="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":r="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":r="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":r="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":r="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":r="specularColor";break}l=h+r;break;case Ce.node:const f=("/nodes/"+a.toString()+"/").length,d=l.substring(0,f);switch(r=l.substring(f),r){case"translation":r="position";break;case"rotation":r="quaternion";break;case"scale":r="scale";break;case"weights":r="morphTargetInfluences";break}l=d+r;break;case Ce.light:const y=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(r=l.substring(y),r){case"color":break;case"intensity":break;case"spot/innerConeAngle":r="penumbra";break;case"spot/outerConeAngle":r="angle";break;case"range":r="distance";break}l="/lights/"+a.toString()+"/"+r;break;case Ce.camera:const _=("/cameras/"+a.toString()+"/").length,p=l.substring(0,_);switch(r=l.substring(_),r){case"perspective/yfov":r="fov";break;case"perspective/znear":case"orthographic/znear":r="near";break;case"perspective/zfar":case"orthographic/zfar":r="far";break;case"perspective/aspect":r="aspect";break;case"orthographic/xmag":r="zoom";break;case"orthographic/ymag":r="zoom";break}l=p+r;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[Et].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===Ce.node?o=this.parser.getDependency("node",a):s===Ce.material?o=this.parser.getDependency("material",a):s===Ce.light?o=this.parser.getDependency("light",a):s===Ce.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,i,r,s){if(!(s.extensions&&s.extensions[Et]&&s.path&&s.path==="pointer"))return null;let o=s.extensions[Et].pointer;if(!o)return null;const c=[];o=o.replaceAll("/",".");const l=o.split(".");var h=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(l[2]=h,l[3]==="morphTargetInfluences"&&e.type==="Group"){for(const d of e.children)d instanceof M.SkinnedMesh&&d.morphTargetInfluences&&(l[3]=d.name,l[4]="morphTargetInfluences",f(this.parser));return c}f(this.parser);function f(d){o=l.join(".");let y;switch(i.itemSize){case 1:y=M.NumberKeyframeTrack;break;case 2:case 3:y=M.VectorKeyframeTrack;break;case 4:o.endsWith(".quaternion")?y=M.QuaternionKeyframeTrack:y=M.ColorKeyframeTrack;break}if(!y){console.warn("Unsupported output accessor format",i);return}const _=r.interpolation!==void 0?Zu[r.interpolation]:M.InterpolateLinear;let p=d._getArrayFromAccessor(i);o.endsWith(".fov")&&(p=p.map(v=>v/Math.PI*180));const m=new y(o,t.array,p,_);if(_==="CUBICSPLINE"&&d._createCubicSplineTrackInterpolant(m),c.push(m),o&&i.itemSize===4&&o.startsWith(".materials.")&&o.endsWith(".color")){const v=new Float32Array(p.length/4);for(let b=0,x=p.length/4;b<x;b+=1)v[b]=p[b*4+3];const g=new y(o.replace(".color",".opacity"),t.array,v,_);_==="CUBICSPLINE"&&d._createCubicSplineTrackInterpolant(m),c.push(g)}}return c}_tryResolveTargetId(e,t){let i="";return t==="node"?i=e.substring(7):t==="material"?i=e.substring(11):t==="light"?i=e.substring(39):t==="camera"&&(i=e.substring(9)),i=i.substring(0,i.indexOf("/")),Number.parseInt(i)}loadAnimation(e){const t=this,i=this.parser.json,r=this.parser,s=i.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],u=[],h=[];for(let f=0,d=s.channels.length;f<d;f++){const y=s.channels[f],_=s.samplers[y.sampler],p=y.target,m=s.parameters!==void 0?s.parameters[_.input]:_.input,v=s.parameters!==void 0?s.parameters[_.output]:_.output;let g=t.loadAnimationTargetFromChannelWithAnimationPointer(y);g||(g=t.loadAnimationTargetFromChannel(y)),o.push(g),c.push(r.getDependency("accessor",m)),l.push(r.getDependency("accessor",v)),u.push(_),h.push(p)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(u),Promise.all(h)]).then(function(f){const d=f[0],y=f[1],_=f[2],p=f[3],m=f[4],v=[];for(let g=0,b=d.length;g<b;g++){const x=d[g],S=y[g],T=_[g],w=p[g],P=m[g];if(x===void 0)continue;x.updateMatrix&&(x.updateMatrix(),x.matrixAutoUpdate=!0);let C=t.createAnimationTracksWithAnimationPointer(x,S,T,w,P);if(C||(C=r._createAnimationTracks(x,S,T,w,P)),C)for(let R=0;R<C.length;R++)v.push(C[R])}return new M.AnimationClip(a,void 0,v)})}}let fo=!1,Qu=null;function eh(){if(fo)return;fo=!0;const n=Qu||=M.PropertyBinding.findNode;M.PropertyBinding.findNode=function(e,t){if(!t)return n(e,t);if(t.startsWith(".materials.")){const i=t.substring(11).substring(t.indexOf(".")),r=i.indexOf("."),s=r<0?i:i.substring(0,r);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(i.endsWith(".map")?a=a.map:i.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const i=t.split(".");let r;for(let s=1;s<i.length;s++){const a=i[s];if(a.length==36)r=e.getObjectByProperty("uuid",a);else if(r&&r[a]){const c=Number.parseInt(a);let l=a;c>=0&&(l=c),r=r[l]}else{const c=e.getObjectByName(a);c&&(r=c)}}if(!r){const s=n(e,i[2]);return s||console.warn(Et+": Property binding not found",t,e,e.name,i),s}return r}return n(e,t)}}const th=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Ku},Symbol.toStringTag,{value:"Module"}));exports.$70d766613f57b014$export$2e2bcd8739ae039=ia;exports.BatchedParticleRenderer=Rl;exports.Builder=Yn;exports.ByteBuffer=_i;exports.ConstantColor=At;exports.ConstantValue=F;exports.Matrix4=De;exports.MeshBVH=tr;exports.MotionController=Pa;exports.ParticleSystem=Vr;exports.SIZE_PREFIX_LENGTH=mo;exports.TrailParticle=Dr;exports.Vector4=Se;exports.WorkerBase=Yu;exports.bundler=nc;exports.createNoise4D=Al;exports.fetchProfile=ba;exports.index=Il;exports.index$1=Wu;exports.index$2=th;exports.md5=xc;exports.v5=mc;