@needle-tools/engine 5.0.2 → 5.1.0-canary.525aa82

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 (176) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +6 -7
  3. package/SKILL.md +39 -21
  4. package/components.needle.json +1 -1
  5. package/dist/needle-engine.bundle-DPag02s9.min.js +1732 -0
  6. package/dist/needle-engine.bundle-IPMzQpe1.umd.cjs +1732 -0
  7. package/dist/{needle-engine.bundle-BoTyA-Le.js → needle-engine.bundle-qa_NEunk.js} +8881 -8148
  8. package/dist/needle-engine.d.ts +633 -61
  9. package/dist/needle-engine.js +576 -565
  10. package/dist/needle-engine.min.js +1 -1
  11. package/dist/needle-engine.umd.cjs +1 -1
  12. package/dist/{vendor-vHLk8sXu.js → vendor-CAcsI0eU.js} +116 -115
  13. package/dist/{vendor-CntUvmJu.umd.cjs → vendor-CEM38hLE.umd.cjs} +2 -2
  14. package/dist/{vendor-DPbfJJ4d.min.js → vendor-HRlxIBga.min.js} +2 -2
  15. package/lib/engine/api.d.ts +2 -0
  16. package/lib/engine/api.js +2 -0
  17. package/lib/engine/api.js.map +1 -1
  18. package/lib/engine/engine_addressables.js +5 -1
  19. package/lib/engine/engine_addressables.js.map +1 -1
  20. package/lib/engine/engine_animation.d.ts +14 -7
  21. package/lib/engine/engine_animation.js +49 -9
  22. package/lib/engine/engine_animation.js.map +1 -1
  23. package/lib/engine/engine_components.js +33 -4
  24. package/lib/engine/engine_components.js.map +1 -1
  25. package/lib/engine/engine_context.d.ts +7 -2
  26. package/lib/engine/engine_context.js +10 -2
  27. package/lib/engine/engine_context.js.map +1 -1
  28. package/lib/engine/engine_gameobject.d.ts +4 -0
  29. package/lib/engine/engine_gameobject.js.map +1 -1
  30. package/lib/engine/engine_init.js +4 -0
  31. package/lib/engine/engine_init.js.map +1 -1
  32. package/lib/engine/engine_input.js +4 -1
  33. package/lib/engine/engine_input.js.map +1 -1
  34. package/lib/engine/engine_materialpropertyblock.js +1 -20
  35. package/lib/engine/engine_materialpropertyblock.js.map +1 -1
  36. package/lib/engine/engine_networking.d.ts +11 -8
  37. package/lib/engine/engine_networking.js +43 -26
  38. package/lib/engine/engine_networking.js.map +1 -1
  39. package/lib/engine/engine_networking_instantiate.d.ts +100 -5
  40. package/lib/engine/engine_networking_instantiate.js +150 -16
  41. package/lib/engine/engine_networking_instantiate.js.map +1 -1
  42. package/lib/engine/engine_networking_prefabs.d.ts +59 -0
  43. package/lib/engine/engine_networking_prefabs.js +67 -0
  44. package/lib/engine/engine_networking_prefabs.js.map +1 -0
  45. package/lib/engine/engine_physics_rapier.d.ts +3 -0
  46. package/lib/engine/engine_physics_rapier.js +13 -9
  47. package/lib/engine/engine_physics_rapier.js.map +1 -1
  48. package/lib/engine/postprocessing/api.d.ts +2 -0
  49. package/lib/engine/postprocessing/api.js +2 -0
  50. package/lib/engine/postprocessing/api.js.map +1 -0
  51. package/lib/engine/postprocessing/index.d.ts +2 -0
  52. package/lib/engine/postprocessing/index.js +2 -0
  53. package/lib/engine/postprocessing/index.js.map +1 -0
  54. package/lib/engine/postprocessing/postprocessing.d.ts +83 -0
  55. package/lib/engine/postprocessing/postprocessing.js +280 -0
  56. package/lib/engine/postprocessing/postprocessing.js.map +1 -0
  57. package/lib/engine/postprocessing/types.d.ts +39 -0
  58. package/lib/engine/postprocessing/types.js +2 -0
  59. package/lib/engine/postprocessing/types.js.map +1 -0
  60. package/lib/engine/webcomponents/WebXRButtons.js +17 -3
  61. package/lib/engine/webcomponents/WebXRButtons.js.map +1 -1
  62. package/lib/engine/webcomponents/icons.js +3 -1
  63. package/lib/engine/webcomponents/icons.js.map +1 -1
  64. package/lib/engine/xr/NeedleXRSession.d.ts +1 -0
  65. package/lib/engine/xr/NeedleXRSession.js +43 -10
  66. package/lib/engine/xr/NeedleXRSession.js.map +1 -1
  67. package/lib/engine/xr/init.d.ts +4 -0
  68. package/lib/engine/xr/init.js +49 -0
  69. package/lib/engine/xr/init.js.map +1 -0
  70. package/lib/engine-components/AnimationUtils.d.ts +4 -1
  71. package/lib/engine-components/AnimationUtils.js +7 -19
  72. package/lib/engine-components/AnimationUtils.js.map +1 -1
  73. package/lib/engine-components/AnimatorController.d.ts +135 -2
  74. package/lib/engine-components/AnimatorController.js +216 -13
  75. package/lib/engine-components/AnimatorController.js.map +1 -1
  76. package/lib/engine-components/GroundProjection.d.ts +1 -0
  77. package/lib/engine-components/GroundProjection.js +184 -48
  78. package/lib/engine-components/GroundProjection.js.map +1 -1
  79. package/lib/engine-components/OrbitControls.d.ts +4 -0
  80. package/lib/engine-components/OrbitControls.js +5 -1
  81. package/lib/engine-components/OrbitControls.js.map +1 -1
  82. package/lib/engine-components/SeeThrough.d.ts +0 -2
  83. package/lib/engine-components/SeeThrough.js +0 -89
  84. package/lib/engine-components/SeeThrough.js.map +1 -1
  85. package/lib/engine-components/SyncedRoom.d.ts +4 -0
  86. package/lib/engine-components/SyncedRoom.js +23 -8
  87. package/lib/engine-components/SyncedRoom.js.map +1 -1
  88. package/lib/engine-components/SyncedTransform.js +5 -5
  89. package/lib/engine-components/SyncedTransform.js.map +1 -1
  90. package/lib/engine-components/Voip.d.ts +46 -0
  91. package/lib/engine-components/Voip.js +126 -2
  92. package/lib/engine-components/Voip.js.map +1 -1
  93. package/lib/engine-components/api.d.ts +1 -0
  94. package/lib/engine-components/api.js +1 -0
  95. package/lib/engine-components/api.js.map +1 -1
  96. package/lib/engine-components/codegen/components.d.ts +1 -0
  97. package/lib/engine-components/codegen/components.js +1 -0
  98. package/lib/engine-components/codegen/components.js.map +1 -1
  99. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +5 -2
  100. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +11 -18
  101. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
  102. package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +3 -4
  103. package/lib/engine-components/postprocessing/PostProcessingEffect.js +6 -15
  104. package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
  105. package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +2 -1
  106. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  107. package/lib/engine-components/postprocessing/Volume.d.ts +18 -11
  108. package/lib/engine-components/postprocessing/Volume.js +61 -140
  109. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  110. package/lib/engine-components/postprocessing/index.d.ts +1 -0
  111. package/lib/engine-components/postprocessing/index.js +1 -0
  112. package/lib/engine-components/postprocessing/index.js.map +1 -1
  113. package/lib/engine-components/postprocessing/utils.d.ts +2 -0
  114. package/lib/engine-components/postprocessing/utils.js +2 -0
  115. package/lib/engine-components/postprocessing/utils.js.map +1 -1
  116. package/lib/engine-components/ui/Canvas.js +2 -2
  117. package/lib/engine-components/ui/Canvas.js.map +1 -1
  118. package/lib/engine-components/ui/Graphic.d.ts +3 -3
  119. package/lib/engine-components/ui/Graphic.js +6 -2
  120. package/lib/engine-components/ui/Graphic.js.map +1 -1
  121. package/lib/engine-components/ui/Text.d.ts +64 -11
  122. package/lib/engine-components/ui/Text.js +154 -45
  123. package/lib/engine-components/ui/Text.js.map +1 -1
  124. package/lib/engine-components/ui/index.d.ts +1 -0
  125. package/lib/engine-components/ui/index.js +1 -0
  126. package/lib/engine-components/ui/index.js.map +1 -1
  127. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +25 -3
  128. package/lib/engine-components-experimental/networking/PlayerSync.js +60 -11
  129. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  130. package/package.json +6 -5
  131. package/plugins/vite/ai.d.ts +11 -10
  132. package/plugins/vite/ai.js +305 -31
  133. package/src/engine/api.ts +3 -0
  134. package/src/engine/engine_addressables.ts +4 -1
  135. package/src/engine/engine_animation.ts +47 -9
  136. package/src/engine/engine_components.ts +36 -7
  137. package/src/engine/engine_context.ts +11 -2
  138. package/src/engine/engine_gameobject.ts +5 -0
  139. package/src/engine/engine_init.ts +4 -0
  140. package/src/engine/engine_input.ts +2 -1
  141. package/src/engine/engine_materialpropertyblock.ts +1 -20
  142. package/src/engine/engine_networking.ts +46 -23
  143. package/src/engine/engine_networking_instantiate.ts +160 -18
  144. package/src/engine/engine_networking_prefabs.ts +80 -0
  145. package/src/engine/engine_physics_rapier.ts +14 -9
  146. package/src/engine/postprocessing/api.ts +2 -0
  147. package/src/engine/postprocessing/index.ts +2 -0
  148. package/src/engine/postprocessing/postprocessing.ts +322 -0
  149. package/src/engine/postprocessing/types.ts +43 -0
  150. package/src/engine/webcomponents/WebXRButtons.ts +21 -4
  151. package/src/engine/webcomponents/icons.ts +5 -3
  152. package/src/engine/xr/NeedleXRSession.ts +50 -15
  153. package/src/engine/xr/init.ts +56 -0
  154. package/src/engine-components/AnimationUtils.ts +7 -17
  155. package/src/engine-components/AnimatorController.ts +288 -18
  156. package/src/engine-components/GroundProjection.ts +226 -52
  157. package/src/engine-components/OrbitControls.ts +5 -1
  158. package/src/engine-components/SeeThrough.ts +0 -116
  159. package/src/engine-components/SyncedRoom.ts +28 -9
  160. package/src/engine-components/SyncedTransform.ts +5 -5
  161. package/src/engine-components/Voip.ts +129 -2
  162. package/src/engine-components/api.ts +1 -0
  163. package/src/engine-components/codegen/components.ts +1 -0
  164. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +16 -24
  165. package/src/engine-components/postprocessing/PostProcessingEffect.ts +9 -16
  166. package/src/engine-components/postprocessing/PostProcessingHandler.ts +2 -1
  167. package/src/engine-components/postprocessing/Volume.ts +72 -163
  168. package/src/engine-components/postprocessing/index.ts +1 -0
  169. package/src/engine-components/postprocessing/utils.ts +2 -0
  170. package/src/engine-components/ui/Canvas.ts +2 -2
  171. package/src/engine-components/ui/Graphic.ts +7 -3
  172. package/src/engine-components/ui/Text.ts +170 -52
  173. package/src/engine-components/ui/index.ts +2 -1
  174. package/src/engine-components-experimental/networking/PlayerSync.ts +64 -11
  175. package/dist/needle-engine.bundle-B3ywqx5o.min.js +0 -1654
  176. package/dist/needle-engine.bundle-CzOPcOui.umd.cjs +0 -1654
@@ -1,4 +1,4 @@
1
- "use strict";const A=require("./three.umd.cjs");function Vr(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var as={exports:{}},cs={exports:{}},Go;function Cl(){return Go||(Go=1,(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e={rotl:function(t,n){return t<<n|t>>>32-n},rotr:function(t,n){return t<<32-n|t>>>n},endian:function(t){if(t.constructor==Number)return e.rotl(t,8)&16711935|e.rotl(t,24)&4278255360;for(var n=0;n<t.length;n++)t[n]=e.endian(t[n]);return t},randomBytes:function(t){for(var n=[];t>0;t--)n.push(Math.floor(Math.random()*256));return n},bytesToWords:function(t){for(var n=[],i=0,s=0;i<t.length;i++,s+=8)n[s>>>5]|=t[i]<<24-s%32;return n},wordsToBytes:function(t){for(var n=[],i=0;i<t.length*32;i+=8)n.push(t[i>>>5]>>>24-i%32&255);return n},bytesToHex:function(t){for(var n=[],i=0;i<t.length;i++)n.push((t[i]>>>4).toString(16)),n.push((t[i]&15).toString(16));return n.join("")},hexToBytes:function(t){for(var n=[],i=0;i<t.length;i+=2)n.push(parseInt(t.substr(i,2),16));return n},bytesToBase64:function(t){for(var n=[],i=0;i<t.length;i+=3)for(var s=t[i]<<16|t[i+1]<<8|t[i+2],a=0;a<4;a++)i*8+a*6<=t.length*8?n.push(r.charAt(s>>>6*(3-a)&63)):n.push("=");return n.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/ig,"");for(var n=[],i=0,s=0;i<t.length;s=++i%4)s!=0&&n.push((r.indexOf(t.charAt(i-1))&Math.pow(2,-2*s+8)-1)<<s*2|r.indexOf(t.charAt(i))>>>6-s*2);return n}};cs.exports=e})()),cs.exports}var ls,Wo;function $o(){if(Wo)return ls;Wo=1;var r={utf8:{stringToBytes:function(e){return r.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(r.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n)&255);return t},bytesToString:function(e){for(var t=[],n=0;n<e.length;n++)t.push(String.fromCharCode(e[n]));return t.join("")}}};return ls=r,ls}var us,Ho;function wl(){if(Ho)return us;Ho=1,us=function(t){return t!=null&&(r(t)||e(t)||!!t._isBuffer)};function r(t){return!!t.constructor&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}function e(t){return typeof t.readFloatLE=="function"&&typeof t.slice=="function"&&r(t.slice(0,0))}return us}var qo;function Pl(){return qo||(qo=1,(function(){var r=Cl(),e=$o().utf8,t=wl(),n=$o().bin,i=function(s,a){s.constructor==String?a&&a.encoding==="binary"?s=n.stringToBytes(s):s=e.stringToBytes(s):t(s)?s=Array.prototype.slice.call(s,0):!Array.isArray(s)&&s.constructor!==Uint8Array&&(s=s.toString());for(var o=r.bytesToWords(s),c=s.length*8,l=1732584193,u=-271733879,f=-1732584194,p=271733878,m=0;m<o.length;m++)o[m]=(o[m]<<8|o[m]>>>24)&16711935|(o[m]<<24|o[m]>>>8)&4278255360;o[c>>>5]|=128<<c%32,o[(c+64>>>9<<4)+14]=c;for(var x=i._ff,T=i._gg,g=i._hh,v=i._ii,m=0;m<o.length;m+=16){var _=l,b=u,M=f,C=p;l=x(l,u,f,p,o[m+0],7,-680876936),p=x(p,l,u,f,o[m+1],12,-389564586),f=x(f,p,l,u,o[m+2],17,606105819),u=x(u,f,p,l,o[m+3],22,-1044525330),l=x(l,u,f,p,o[m+4],7,-176418897),p=x(p,l,u,f,o[m+5],12,1200080426),f=x(f,p,l,u,o[m+6],17,-1473231341),u=x(u,f,p,l,o[m+7],22,-45705983),l=x(l,u,f,p,o[m+8],7,1770035416),p=x(p,l,u,f,o[m+9],12,-1958414417),f=x(f,p,l,u,o[m+10],17,-42063),u=x(u,f,p,l,o[m+11],22,-1990404162),l=x(l,u,f,p,o[m+12],7,1804603682),p=x(p,l,u,f,o[m+13],12,-40341101),f=x(f,p,l,u,o[m+14],17,-1502002290),u=x(u,f,p,l,o[m+15],22,1236535329),l=T(l,u,f,p,o[m+1],5,-165796510),p=T(p,l,u,f,o[m+6],9,-1069501632),f=T(f,p,l,u,o[m+11],14,643717713),u=T(u,f,p,l,o[m+0],20,-373897302),l=T(l,u,f,p,o[m+5],5,-701558691),p=T(p,l,u,f,o[m+10],9,38016083),f=T(f,p,l,u,o[m+15],14,-660478335),u=T(u,f,p,l,o[m+4],20,-405537848),l=T(l,u,f,p,o[m+9],5,568446438),p=T(p,l,u,f,o[m+14],9,-1019803690),f=T(f,p,l,u,o[m+3],14,-187363961),u=T(u,f,p,l,o[m+8],20,1163531501),l=T(l,u,f,p,o[m+13],5,-1444681467),p=T(p,l,u,f,o[m+2],9,-51403784),f=T(f,p,l,u,o[m+7],14,1735328473),u=T(u,f,p,l,o[m+12],20,-1926607734),l=g(l,u,f,p,o[m+5],4,-378558),p=g(p,l,u,f,o[m+8],11,-2022574463),f=g(f,p,l,u,o[m+11],16,1839030562),u=g(u,f,p,l,o[m+14],23,-35309556),l=g(l,u,f,p,o[m+1],4,-1530992060),p=g(p,l,u,f,o[m+4],11,1272893353),f=g(f,p,l,u,o[m+7],16,-155497632),u=g(u,f,p,l,o[m+10],23,-1094730640),l=g(l,u,f,p,o[m+13],4,681279174),p=g(p,l,u,f,o[m+0],11,-358537222),f=g(f,p,l,u,o[m+3],16,-722521979),u=g(u,f,p,l,o[m+6],23,76029189),l=g(l,u,f,p,o[m+9],4,-640364487),p=g(p,l,u,f,o[m+12],11,-421815835),f=g(f,p,l,u,o[m+15],16,530742520),u=g(u,f,p,l,o[m+2],23,-995338651),l=v(l,u,f,p,o[m+0],6,-198630844),p=v(p,l,u,f,o[m+7],10,1126891415),f=v(f,p,l,u,o[m+14],15,-1416354905),u=v(u,f,p,l,o[m+5],21,-57434055),l=v(l,u,f,p,o[m+12],6,1700485571),p=v(p,l,u,f,o[m+3],10,-1894986606),f=v(f,p,l,u,o[m+10],15,-1051523),u=v(u,f,p,l,o[m+1],21,-2054922799),l=v(l,u,f,p,o[m+8],6,1873313359),p=v(p,l,u,f,o[m+15],10,-30611744),f=v(f,p,l,u,o[m+6],15,-1560198380),u=v(u,f,p,l,o[m+13],21,1309151649),l=v(l,u,f,p,o[m+4],6,-145523070),p=v(p,l,u,f,o[m+11],10,-1120210379),f=v(f,p,l,u,o[m+2],15,718787259),u=v(u,f,p,l,o[m+9],21,-343485551),l=l+_>>>0,u=u+b>>>0,f=f+M>>>0,p=p+C>>>0}return r.endian([l,u,f,p])};i._ff=function(s,a,o,c,l,u,f){var p=s+(a&o|~a&c)+(l>>>0)+f;return(p<<u|p>>>32-u)+a},i._gg=function(s,a,o,c,l,u,f){var p=s+(a&c|o&~c)+(l>>>0)+f;return(p<<u|p>>>32-u)+a},i._hh=function(s,a,o,c,l,u,f){var p=s+(a^o^c)+(l>>>0)+f;return(p<<u|p>>>32-u)+a},i._ii=function(s,a,o,c,l,u,f){var p=s+(o^(a|~c))+(l>>>0)+f;return(p<<u|p>>>32-u)+a},i._blocksize=16,i._digestsize=16,as.exports=function(s,a){if(s==null)throw new Error("Illegal argument "+s);var o=r.wordsToBytes(i(s,a));return a&&a.asBytes?o:a&&a.asString?n.bytesToString(o):r.bytesToHex(o)}})()),as.exports}var El=Pl();const Qa=Vr(El),kl=Object.freeze(Object.defineProperty({__proto__:null,default:Qa},Symbol.toStringTag,{value:"Module"})),Rl=/^(?:[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 Al(r){return typeof r=="string"&&Rl.test(r)}const Fe=[];for(let r=0;r<256;++r)Fe.push((r+256).toString(16).slice(1));function Ol(r,e=0){return Fe[r[e+0]]+Fe[r[e+1]]+Fe[r[e+2]]+Fe[r[e+3]]+"-"+Fe[r[e+4]]+Fe[r[e+5]]+"-"+Fe[r[e+6]]+Fe[r[e+7]]+"-"+Fe[r[e+8]]+Fe[r[e+9]]+"-"+Fe[r[e+10]]+Fe[r[e+11]]+Fe[r[e+12]]+Fe[r[e+13]]+Fe[r[e+14]]+Fe[r[e+15]]}function zl(r){if(!Al(r))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(r.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(r.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(r.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(r.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(r.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function Il(r){r=unescape(encodeURIComponent(r));const e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t));return e}const Bl="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Nl="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function Ul(r,e,t){function n(i,s,a,o){var c;if(typeof i=="string"&&(i=Il(i)),typeof s=="string"&&(s=zl(s)),((c=s)===null||c===void 0?void 0:c.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(s),l.set(i,s.length),l=t(l),l[6]=l[6]&15|e,l[8]=l[8]&63|128,a){o=o||0;for(let u=0;u<16;++u)a[o+u]=l[u];return a}return Ol(l)}try{n.name=r}catch{}return n.DNS=Bl,n.URL=Nl,n}function Dl(r,e,t,n){switch(r){case 0:return e&t^~e&n;case 1:return e^t^n;case 2:return e&t^e&n^t&n;case 3:return e^t^n}}function hs(r,e){return r<<e|r>>>32-e}function Fl(r){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof r=="string"){const a=unescape(encodeURIComponent(r));r=[];for(let o=0;o<a.length;++o)r.push(a.charCodeAt(o))}else Array.isArray(r)||(r=Array.prototype.slice.call(r));r.push(128);const n=r.length/4+2,i=Math.ceil(n/16),s=new Array(i);for(let a=0;a<i;++a){const o=new Uint32Array(16);for(let c=0;c<16;++c)o[c]=r[a*64+c*4]<<24|r[a*64+c*4+1]<<16|r[a*64+c*4+2]<<8|r[a*64+c*4+3];s[a]=o}s[i-1][14]=(r.length-1)*8/Math.pow(2,32),s[i-1][14]=Math.floor(s[i-1][14]),s[i-1][15]=(r.length-1)*8&4294967295;for(let a=0;a<i;++a){const o=new Uint32Array(80);for(let m=0;m<16;++m)o[m]=s[a][m];for(let m=16;m<80;++m)o[m]=hs(o[m-3]^o[m-8]^o[m-14]^o[m-16],1);let c=t[0],l=t[1],u=t[2],f=t[3],p=t[4];for(let m=0;m<80;++m){const x=Math.floor(m/20),T=hs(c,5)+Dl(x,l,u,f)+p+e[x]+o[m]>>>0;p=f,f=u,u=hs(l,30)>>>0,l=c,c=T}t[0]=t[0]+c>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+f>>>0,t[4]=t[4]+p>>>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 Ll=Ul("v5",80,Fl),fs=2,zt=4,Wt=4,ec=4,Qt=new Int32Array(2),Xo=new Float32Array(Qt.buffer),Yo=new Float64Array(Qt.buffer),Ki=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;class Ht{constructor(e,t){this.low=e|0,this.high=t|0}static create(e,t){return e==0&&t==0?Ht.ZERO:new Ht(e,t)}toFloat64(){return(this.low>>>0)+this.high*4294967296}equals(e){return this.low==e.low&&this.high==e.high}}Ht.ZERO=new Ht(0,0);var Ds;(function(r){r[r.UTF8_BYTES=1]="UTF8_BYTES",r[r.UTF16_STRING=2]="UTF16_STRING"})(Ds||(Ds={}));class li{constructor(e){this.bytes_=e,this.position_=0}static allocate(e){return new li(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 Ht(this.readInt32(e),this.readInt32(e+4))}readUint64(e){return new Ht(this.readUint32(e),this.readUint32(e+4))}readFloat32(e){return Qt[0]=this.readInt32(e),Xo[0]}readFloat64(e){return Qt[Ki?0:1]=this.readInt32(e),Qt[Ki?1:0]=this.readInt32(e+4),Yo[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){Xo[0]=t,this.writeInt32(e,Qt[0])}writeFloat64(e,t){Yo[0]=t,this.writeInt32(e,Qt[Ki?0:1]),this.writeInt32(e+4,Qt[Ki?1:0])}getBufferIdentifier(){if(this.bytes_.length<this.position_+zt+Wt)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");let e="";for(let t=0;t<Wt;t++)e+=String.fromCharCode(this.readInt8(this.position_+zt+t));return e}__offset(e,t){const n=e-this.readInt32(e);return t<this.readInt16(n)?this.readInt16(n+t):0}__union(e,t){return e.bb_pos=t+this.readInt32(t),e.bb=this,e}__string(e,t){e+=this.readInt32(e);const n=this.readInt32(e);let i="",s=0;if(e+=zt,t===Ds.UTF8_BYTES)return this.bytes_.subarray(e,e+n);for(;s<n;){let a;const o=this.readUint8(e+s++);if(o<192)a=o;else{const c=this.readUint8(e+s++);if(o<224)a=(o&31)<<6|c&63;else{const l=this.readUint8(e+s++);if(o<240)a=(o&15)<<12|(c&63)<<6|l&63;else{const u=this.readUint8(e+s++);a=(o&7)<<18|(c&63)<<12|(l&63)<<6|u&63}}}a<65536?i+=String.fromCharCode(a):(a-=65536,i+=String.fromCharCode((a>>10)+55296,(a&1023)+56320))}return i}__union_with_string(e,t){return typeof e=="string"?this.__string(t):this.__union(e,t)}__indirect(e){return e+this.readInt32(e)}__vector(e){return e+this.readInt32(e)+zt}__vector_len(e){return this.readInt32(e+this.readInt32(e))}__has_identifier(e){if(e.length!=Wt)throw new Error("FlatBuffers: file identifier must be length "+Wt);for(let t=0;t<Wt;t++)if(e.charCodeAt(t)!=this.readInt8(this.position()+zt+t))return!1;return!0}createLong(e,t){return Ht.create(e,t)}createScalarList(e,t){const n=[];for(let i=0;i<t;++i)e(i)!==null&&n.push(e(i));return n}createObjList(e,t){const n=[];for(let i=0;i<t;++i){const s=e(i);s!==null&&n.push(s.unpack())}return n}}class ao{constructor(e){this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null;let t;e?t=e:t=1024,this.bb=li.allocate(t),this.space=t}clear(){this.bb.clear(),this.space=this.bb.capacity(),this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null}forceDefaults(e){this.force_defaults=e}dataBuffer(){return this.bb}asUint8Array(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())}prep(e,t){e>this.minalign&&(this.minalign=e);const n=~(this.bb.capacity()-this.space+t)+1&e-1;for(;this.space<n+e+t;){const i=this.bb.capacity();this.bb=ao.growByteBuffer(this.bb),this.space+=this.bb.capacity()-i}this.pad(n)}pad(e){for(let t=0;t<e;t++)this.bb.writeInt8(--this.space,0)}writeInt8(e){this.bb.writeInt8(this.space-=1,e)}writeInt16(e){this.bb.writeInt16(this.space-=2,e)}writeInt32(e){this.bb.writeInt32(this.space-=4,e)}writeInt64(e){this.bb.writeInt64(this.space-=8,e)}writeFloat32(e){this.bb.writeFloat32(this.space-=4,e)}writeFloat64(e){this.bb.writeFloat64(this.space-=8,e)}addInt8(e){this.prep(1,0),this.writeInt8(e)}addInt16(e){this.prep(2,0),this.writeInt16(e)}addInt32(e){this.prep(4,0),this.writeInt32(e)}addInt64(e){this.prep(8,0),this.writeInt64(e)}addFloat32(e){this.prep(4,0),this.writeFloat32(e)}addFloat64(e){this.prep(8,0),this.writeFloat64(e)}addFieldInt8(e,t,n){(this.force_defaults||t!=n)&&(this.addInt8(t),this.slot(e))}addFieldInt16(e,t,n){(this.force_defaults||t!=n)&&(this.addInt16(t),this.slot(e))}addFieldInt32(e,t,n){(this.force_defaults||t!=n)&&(this.addInt32(t),this.slot(e))}addFieldInt64(e,t,n){(this.force_defaults||!t.equals(n))&&(this.addInt64(t),this.slot(e))}addFieldFloat32(e,t,n){(this.force_defaults||t!=n)&&(this.addFloat32(t),this.slot(e))}addFieldFloat64(e,t,n){(this.force_defaults||t!=n)&&(this.addFloat64(t),this.slot(e))}addFieldOffset(e,t,n){(this.force_defaults||t!=n)&&(this.addOffset(t),this.slot(e))}addFieldStruct(e,t,n){t!=n&&(this.nested(t),this.slot(e))}nested(e){if(e!=this.offset())throw new Error("FlatBuffers: struct must be serialized inline.")}notNested(){if(this.isNested)throw new Error("FlatBuffers: object serialization must not be nested.")}slot(e){this.vtable!==null&&(this.vtable[e]=this.offset())}offset(){return this.bb.capacity()-this.space}static growByteBuffer(e){const t=e.capacity();if(t&3221225472)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");const n=t<<1,i=li.allocate(n);return i.setPosition(n-t),i.bytes().set(e.bytes(),n-t),i}addOffset(e){this.prep(zt,0),this.writeInt32(this.offset()-e+zt)}startObject(e){this.notNested(),this.vtable==null&&(this.vtable=[]),this.vtable_in_use=e;for(let t=0;t<e;t++)this.vtable[t]=0;this.isNested=!0,this.object_start=this.offset()}endObject(){if(this.vtable==null||!this.isNested)throw new Error("FlatBuffers: endObject called without startObject");this.addInt32(0);const e=this.offset();let t=this.vtable_in_use-1;for(;t>=0&&this.vtable[t]==0;t--);const n=t+1;for(;t>=0;t--)this.addInt16(this.vtable[t]!=0?e-this.vtable[t]:0);const i=2;this.addInt16(e-this.object_start);const s=(n+i)*fs;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=fs;l<s;l+=fs)if(this.bb.readInt16(o+l)!=this.bb.readInt16(c+l))continue e;a=this.vtables[t];break}}return a?(this.space=this.bb.capacity()-e,this.bb.writeInt32(this.space,a-e)):(this.vtables.push(this.offset()),this.bb.writeInt32(this.bb.capacity()-e,this.offset()-e)),this.isNested=!1,e}finish(e,t,n){const i=n?ec:0;if(t){const s=t;if(this.prep(this.minalign,zt+Wt+i),s.length!=Wt)throw new Error("FlatBuffers: file identifier must be length "+Wt);for(let a=Wt-1;a>=0;a--)this.writeInt8(s.charCodeAt(a))}this.prep(this.minalign,zt+i),this.addOffset(e),i&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(e,t){this.finish(e,t,!0)}requiredField(e,t){const n=this.bb.capacity()-e,i=n-this.bb.readInt32(n);if(!(this.bb.readInt16(i+t)!=0))throw new Error("FlatBuffers: field "+t+" must be set")}startVector(e,t,n){this.notNested(),this.vector_num_elems=t,this.prep(zt,e*t),this.prep(n,e*t)}endVector(){return this.writeInt32(this.vector_num_elems),this.offset()}createSharedString(e){if(!e)return 0;if(this.string_maps||(this.string_maps=new Map),this.string_maps.has(e))return this.string_maps.get(e);const t=this.createString(e);return this.string_maps.set(e,t),t}createString(e){if(!e)return 0;let t;if(e instanceof Uint8Array)t=e;else{t=[];let n=0;for(;n<e.length;){let i;const s=e.charCodeAt(n++);if(s<55296||s>=56320)i=s;else{const a=e.charCodeAt(n++);i=(s<<10)+a+-56613888}i<128?t.push(i):(i<2048?t.push(i>>6&31|192):(i<65536?t.push(i>>12&15|224):t.push(i>>18&7|240,i>>12&63|128),t.push(i>>6&63|128)),t.push(i&63|128))}}this.addInt8(0),this.startVector(1,t.length,1),this.bb.setPosition(this.space-=t.length);for(let n=0,i=this.space,s=this.bb.bytes();n<t.length;n++)s[i++]=t[n];return this.endVector()}createLong(e,t){return Ht.create(e,t)}createObjectOffset(e){return e===null?0:typeof e=="string"?this.createString(e):e.pack(this)}createObjectOffsetList(e){const t=[];for(let n=0;n<e.length;++n){const i=e[n];if(i!==null)t.push(this.createObjectOffset(i));else throw new Error("FlatBuffers: Argument for createObjectOffsetList cannot contain null.")}return t}createStructOffsetList(e,t){return t(this,e.length),this.createObjectOffsetList(e),this.endVector()}}const ze={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 tc(r){const e=await fetch(r);if(e.ok)return e.json();throw new Error(e.statusText)}async function Vl(r){return await tc(`${r}/profilesList.json`)}async function Jl(r,e,t=null,n=!0){if(!r)throw new Error("No xrInputSource supplied");const i=await Vl(e);let s;if(r.profiles.some(c=>{const l=i[c];return l&&(s={profileId:c,profilePath:`${e}/${l.path}`,deprecated:!!l.deprecated}),!!s}),!s){if(!t)throw new Error("No matching profile name found");const c=i[t];if(!c)throw new Error(`No matching profile name found and default profile "${t}" missing.`);s={profileId:t,profilePath:`${e}/${c.path}`,deprecated:!!c.deprecated}}const a=await tc(s.profilePath);let o;if(n){let c;if(r.handedness==="any"?c=a.layouts[Object.keys(a.layouts)[0]]:c=a.layouts[r.handedness],!c)throw new Error(`No matching handedness, ${r.handedness}, in profile ${s.profileId}`);c.assetPath&&(o=s.profilePath.replace("profile.json",c.assetPath))}return{profile:a,assetPath:o}}const jl={xAxis:0,yAxis:0,button:0,state:ze.ComponentState.DEFAULT};function Gl(r=0,e=0){let t=r,n=e;if(Math.sqrt(r*r+e*e)>1){const a=Math.atan2(e,r);t=Math.cos(a),n=Math.sin(a)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:n*.5+.5}}class Wl{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===ze.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(jl)}updateFromComponent({xAxis:e,yAxis:t,button:n,state:i}){const{normalizedXAxis:s,normalizedYAxis:a}=Gl(e,t);switch(this.componentProperty){case ze.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?s:.5;break;case ze.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?a:.5;break;case ze.ComponentProperty.BUTTON:this.value=this.states.includes(i)?n:0;break;case ze.ComponentProperty.STATE:this.valueNodeProperty===ze.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(i):this.value=this.states.includes(i)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class $l{constructor(e,t){if(!e||!t||!t.visualResponses||!t.gamepadIndices||Object.keys(t.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=e,this.type=t.type,this.rootNodeName=t.rootNodeName,this.touchPointNodeName=t.touchPointNodeName,this.visualResponses={},Object.keys(t.visualResponses).forEach(n=>{const i=new Wl(t.visualResponses[n]);this.visualResponses[n]=i}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:ze.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=ze.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=ze.ComponentState.PRESSED:(t.touched||this.values.button>ze.ButtonTouchThreshold)&&(this.values.state=ze.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===ze.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>ze.AxisTouchThreshold&&(this.values.state=ze.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===ze.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>ze.AxisTouchThreshold&&(this.values.state=ze.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class Hl{constructor(e,t,n){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=n,this.id=t.profileId,this.layoutDescription=t.layouts[e.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(i=>{const s=this.layoutDescription.components[i];this.components[i]=new $l(i,s)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const e=[];return Object.values(this.components).forEach(t=>{e.push(t.data)}),e}updateFromGamepad(){Object.values(this.components).forEach(e=>{e.updateFromGamepad(this.xrInputSource.gamepad)})}}const Ge=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Zo=1234567;const nc=Math.PI/180,ic=180/Math.PI;function ql(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(Ge[r&255]+Ge[r>>8&255]+Ge[r>>16&255]+Ge[r>>24&255]+"-"+Ge[e&255]+Ge[e>>8&255]+"-"+Ge[e>>16&15|64]+Ge[e>>24&255]+"-"+Ge[t&63|128]+Ge[t>>8&255]+"-"+Ge[t>>16&255]+Ge[t>>24&255]+Ge[n&255]+Ge[n>>8&255]+Ge[n>>16&255]+Ge[n>>24&255]).toLowerCase()}function Ot(r,e,t){return Math.max(e,Math.min(t,r))}function rc(r,e){return(r%e+e)%e}function Xl(r,e,t,n,i){return n+(r-e)*(i-n)/(t-e)}function Yl(r,e,t){return r!==e?(t-r)/(e-r):0}function sc(r,e,t){return(1-t)*r+t*e}function Zl(r,e,t,n){return sc(r,e,1-Math.exp(-t*n))}function Kl(r,e=1){return e-Math.abs(rc(r,e*2)-e)}function Ql(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function eu(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function tu(r,e){return r+Math.floor(Math.random()*(e-r+1))}function nu(r,e){return r+Math.random()*(e-r)}function iu(r){return r*(.5-Math.random())}function ru(r){r!==void 0&&(Zo=r);let e=Zo+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function su(r){return r*nc}function ou(r){return r*ic}function au(r){return(r&r-1)===0&&r!==0}function cu(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function lu(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function uu(r,e,t,n,i){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+n)/2),u=a((e+n)/2),f=s((e-n)/2),p=a((e-n)/2),m=s((n-e)/2),x=a((n-e)/2);switch(i){case"XYX":r.set(o*u,c*f,c*p,o*l);break;case"YZY":r.set(c*p,o*u,c*f,o*l);break;case"ZXZ":r.set(c*f,c*p,o*u,o*l);break;case"XZX":r.set(o*u,c*x,c*m,o*l);break;case"YXY":r.set(c*m,o*u,c*x,o*l);break;case"ZYZ":r.set(c*x,c*m,o*u,o*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function hu(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function fu(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}const Jn={DEG2RAD:nc,RAD2DEG:ic,generateUUID:ql,clamp:Ot,euclideanModulo:rc,mapLinear:Xl,inverseLerp:Yl,lerp:sc,damp:Zl,pingpong:Kl,smoothstep:Ql,smootherstep:eu,randInt:tu,randFloat:nu,randFloatSpread:iu,seededRandom:ru,degToRad:su,radToDeg:ou,isPowerOfTwo:au,ceilPowerOfTwo:cu,floorPowerOfTwo:lu,setQuaternionFromProperEuler:uu,normalize:fu,denormalize:hu};class ie{constructor(e=0,t=0,n=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,s,a,o){let c=n[i+0],l=n[i+1],u=n[i+2],f=n[i+3];const p=s[a+0],m=s[a+1],x=s[a+2],T=s[a+3];if(o===0){e[t+0]=c,e[t+1]=l,e[t+2]=u,e[t+3]=f;return}if(o===1){e[t+0]=p,e[t+1]=m,e[t+2]=x,e[t+3]=T;return}if(f!==T||c!==p||l!==m||u!==x){let g=1-o;const v=c*p+l*m+u*x+f*T,_=v>=0?1:-1,b=1-v*v;if(b>Number.EPSILON){const C=Math.sqrt(b),P=Math.atan2(C,v*_);g=Math.sin(g*P)/C,o=Math.sin(o*P)/C}const M=o*_;if(c=c*g+p*M,l=l*g+m*M,u=u*g+x*M,f=f*g+T*M,g===1-o){const C=1/Math.sqrt(c*c+l*l+u*u+f*f);c*=C,l*=C,u*=C,f*=C}}e[t]=c,e[t+1]=l,e[t+2]=u,e[t+3]=f}static multiplyQuaternionsFlat(e,t,n,i,s,a){const o=n[i],c=n[i+1],l=n[i+2],u=n[i+3],f=s[a],p=s[a+1],m=s[a+2],x=s[a+3];return e[t]=o*x+u*f+c*m-l*p,e[t+1]=c*x+u*p+l*f-o*m,e[t+2]=l*x+u*m+o*p-c*f,e[t+3]=u*x-o*f-c*p-l*m,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new ie(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const n=e._x,i=e._y,s=e._z,a=e._order,o=Math.cos,c=Math.sin,l=o(n/2),u=o(i/2),f=o(s/2),p=c(n/2),m=c(i/2),x=c(s/2);switch(a){case"XYZ":this._x=p*u*f+l*m*x,this._y=l*m*f-p*u*x,this._z=l*u*x+p*m*f,this._w=l*u*f-p*m*x;break;case"YXZ":this._x=p*u*f+l*m*x,this._y=l*m*f-p*u*x,this._z=l*u*x-p*m*f,this._w=l*u*f+p*m*x;break;case"ZXY":this._x=p*u*f-l*m*x,this._y=l*m*f+p*u*x,this._z=l*u*x+p*m*f,this._w=l*u*f-p*m*x;break;case"ZYX":this._x=p*u*f-l*m*x,this._y=l*m*f+p*u*x,this._z=l*u*x-p*m*f,this._w=l*u*f+p*m*x;break;case"YZX":this._x=p*u*f+l*m*x,this._y=l*m*f+p*u*x,this._z=l*u*x-p*m*f,this._w=l*u*f-p*m*x;break;case"XZY":this._x=p*u*f-l*m*x,this._y=l*m*f-p*u*x,this._z=l*u*x+p*m*f,this._w=l*u*f+p*m*x;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,n=t[0],i=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],u=t[6],f=t[10],p=n+o+f;if(p>0){const m=.5/Math.sqrt(p+1);this._w=.25/m,this._x=(u-c)*m,this._y=(s-l)*m,this._z=(a-i)*m}else if(n>o&&n>f){const m=2*Math.sqrt(1+n-o-f);this._w=(u-c)/m,this._x=.25*m,this._y=(i+a)/m,this._z=(s+l)/m}else if(o>f){const m=2*Math.sqrt(1+o-n-f);this._w=(s-l)/m,this._x=(i+a)/m,this._y=.25*m,this._z=(c+u)/m}else{const m=2*Math.sqrt(1+f-n-o);this._w=(a-i)/m,this._x=(s+l)/m,this._y=(c+u)/m,this._z=.25*m}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<Number.EPSILON?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Ot(this.dot(e),-1,1)))}rotateTowards(e,t){const n=this.angleTo(e);if(n===0)return this;const i=Math.min(1,t/n);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const n=e._x,i=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,u=t._w;return this._x=n*u+a*o+i*l-s*c,this._y=i*u+a*c+s*o-n*l,this._z=s*u+a*l+n*c-i*o,this._w=a*u-n*o-i*c-s*l,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const n=this._x,i=this._y,s=this._z,a=this._w;let o=a*e._w+n*e._x+i*e._y+s*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=a,this._x=n,this._y=i,this._z=s,this;const c=1-o*o;if(c<=Number.EPSILON){const m=1-t;return this._w=m*a+t*this._w,this._x=m*n+t*this._x,this._y=m*i+t*this._y,this._z=m*s+t*this._z,this.normalize(),this}const l=Math.sqrt(c),u=Math.atan2(l,o),f=Math.sin((1-t)*u)/l,p=Math.sin(t*u)/l;return this._w=a*f+this._w*p,this._x=n*f+this._x*p,this._y=i*f+this._y*p,this._z=s*f+this._z*p,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class G{constructor(e=0,t=0,n=0){this.isVector3=!0,G.prototype.isVector3=!0,this.x=e,this.y=t,this.z=n}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new G(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Ko.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Ko.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*i,this.y=s[1]*t+s[4]*n+s[7]*i,this.z=s[2]*t+s[5]*n+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=e.elements,a=1/(s[3]*t+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*i+s[12])*a,this.y=(s[1]*t+s[5]*n+s[9]*i+s[13])*a,this.z=(s[2]*t+s[6]*n+s[10]*i+s[14])*a,this}applyQuaternion(e){const t=this.x,n=this.y,i=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*i-o*n),u=2*(o*t-s*i),f=2*(s*n-a*t);return this.x=t+c*l+a*f-o*u,this.y=n+c*u+o*l-s*f,this.z=i+c*f+s*u-a*l,this}transformDirection(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*i,this.y=s[1]*t+s[5]*n+s[9]*i,this.z=s[2]*t+s[6]*n+s[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const n=e.x,i=e.y,s=e.z,a=t.x,o=t.y,c=t.z;return this.x=i*c-s*o,this.y=s*a-n*c,this.z=n*o-i*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return ds.copy(this).projectOnVector(e),this.sub(ds)}reflect(e){return this.sub(ds.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(Ot(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSphericalCoords(e,t,n){const i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const ds=new G,Ko=new ie,Qi=2e3,Qo=2001;class Et{constructor(e,t,n,i,s,a,o,c,l,u,f,p,m,x,T,g){this.isMatrix4=!0,Et.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,a,o,c,l,u,f,p,m,x,T,g)}extractPosition(e){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(e)}multiplyToArray(e,t,n){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(e){return this.makeRotationFromQuaternion(e)}set(e,t,n,i,s,a,o,c,l,u,f,p,m,x,T,g){const v=this.elements;return v[0]=e,v[4]=t,v[8]=n,v[12]=i,v[1]=s,v[5]=a,v[9]=o,v[13]=c,v[2]=l,v[6]=u,v[10]=f,v[14]=p,v[3]=m,v[7]=x,v[11]=T,v[15]=g,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new Et().fromArray(this.elements)}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){const t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,n=e.elements,i=1/wn.setFromMatrixColumn(e,0).length(),s=1/wn.setFromMatrixColumn(e,1).length(),a=1/wn.setFromMatrixColumn(e,2).length();return t[0]=n[0]*i,t[1]=n[1]*i,t[2]=n[2]*i,t[3]=0,t[4]=n[4]*s,t[5]=n[5]*s,t[6]=n[6]*s,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,n=e.x,i=e.y,s=e.z,a=Math.cos(n),o=Math.sin(n),c=Math.cos(i),l=Math.sin(i),u=Math.cos(s),f=Math.sin(s);if(e.order==="XYZ"){const p=a*u,m=a*f,x=o*u,T=o*f;t[0]=c*u,t[4]=-c*f,t[8]=l,t[1]=m+x*l,t[5]=p-T*l,t[9]=-o*c,t[2]=T-p*l,t[6]=x+m*l,t[10]=a*c}else if(e.order==="YXZ"){const p=c*u,m=c*f,x=l*u,T=l*f;t[0]=p+T*o,t[4]=x*o-m,t[8]=a*l,t[1]=a*f,t[5]=a*u,t[9]=-o,t[2]=m*o-x,t[6]=T+p*o,t[10]=a*c}else if(e.order==="ZXY"){const p=c*u,m=c*f,x=l*u,T=l*f;t[0]=p-T*o,t[4]=-a*f,t[8]=x+m*o,t[1]=m+x*o,t[5]=a*u,t[9]=T-p*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const p=a*u,m=a*f,x=o*u,T=o*f;t[0]=c*u,t[4]=x*l-m,t[8]=p*l+T,t[1]=c*f,t[5]=T*l+p,t[9]=m*l-x,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const p=a*c,m=a*l,x=o*c,T=o*l;t[0]=c*u,t[4]=T-p*f,t[8]=x*f+m,t[1]=f,t[5]=a*u,t[9]=-o*u,t[2]=-l*u,t[6]=m*f+x,t[10]=p-T*f}else if(e.order==="XZY"){const p=a*c,m=a*l,x=o*c,T=o*l;t[0]=c*u,t[4]=-f,t[8]=l*u,t[1]=p*f+T,t[5]=a*u,t[9]=m*f-x,t[2]=x*f-m,t[6]=o*u,t[10]=T*f+p}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(du,e,pu)}lookAt(e,t,n){const i=this.elements;return lt.subVectors(e,t),lt.lengthSq()===0&&(lt.z=1),lt.normalize(),Yt.crossVectors(n,lt),Yt.lengthSq()===0&&(Math.abs(n.z)===1?lt.x+=1e-4:lt.z+=1e-4,lt.normalize(),Yt.crossVectors(n,lt)),Yt.normalize(),er.crossVectors(lt,Yt),i[0]=Yt.x,i[4]=er.x,i[8]=lt.x,i[1]=Yt.y,i[5]=er.y,i[9]=lt.y,i[2]=Yt.z,i[6]=er.z,i[10]=lt.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,a=n[0],o=n[4],c=n[8],l=n[12],u=n[1],f=n[5],p=n[9],m=n[13],x=n[2],T=n[6],g=n[10],v=n[14],_=n[3],b=n[7],M=n[11],C=n[15],P=i[0],E=i[4],z=i[8],I=i[12],R=i[1],N=i[5],O=i[9],U=i[13],L=i[2],J=i[6],$=i[10],K=i[14],W=i[3],me=i[7],ne=i[11],ue=i[15];return s[0]=a*P+o*R+c*L+l*W,s[4]=a*E+o*N+c*J+l*me,s[8]=a*z+o*O+c*$+l*ne,s[12]=a*I+o*U+c*K+l*ue,s[1]=u*P+f*R+p*L+m*W,s[5]=u*E+f*N+p*J+m*me,s[9]=u*z+f*O+p*$+m*ne,s[13]=u*I+f*U+p*K+m*ue,s[2]=x*P+T*R+g*L+v*W,s[6]=x*E+T*N+g*J+v*me,s[10]=x*z+T*O+g*$+v*ne,s[14]=x*I+T*U+g*K+v*ue,s[3]=_*P+b*R+M*L+C*W,s[7]=_*E+b*N+M*J+C*me,s[11]=_*z+b*O+M*$+C*ne,s[15]=_*I+b*U+M*K+C*ue,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[4],i=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],u=e[2],f=e[6],p=e[10],m=e[14],x=e[3],T=e[7],g=e[11],v=e[15];return x*(+s*c*f-i*l*f-s*o*p+n*l*p+i*o*m-n*c*m)+T*(+t*c*m-t*l*p+s*a*p-i*a*m+i*l*u-s*c*u)+g*(+t*l*f-t*o*m-s*a*f+n*a*m+s*o*u-n*l*u)+v*(-i*o*u-t*c*f+t*o*p+i*a*f-n*a*p+n*c*u)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=n),this}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],f=e[9],p=e[10],m=e[11],x=e[12],T=e[13],g=e[14],v=e[15],_=f*g*l-T*p*l+T*c*m-o*g*m-f*c*v+o*p*v,b=x*p*l-u*g*l-x*c*m+a*g*m+u*c*v-a*p*v,M=u*T*l-x*f*l+x*o*m-a*T*m-u*o*v+a*f*v,C=x*f*c-u*T*c-x*o*p+a*T*p+u*o*g-a*f*g,P=t*_+n*b+i*M+s*C;if(P===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/P;return e[0]=_*E,e[1]=(T*p*s-f*g*s-T*i*m+n*g*m+f*i*v-n*p*v)*E,e[2]=(o*g*s-T*c*s+T*i*l-n*g*l-o*i*v+n*c*v)*E,e[3]=(f*c*s-o*p*s-f*i*l+n*p*l+o*i*m-n*c*m)*E,e[4]=b*E,e[5]=(u*g*s-x*p*s+x*i*m-t*g*m-u*i*v+t*p*v)*E,e[6]=(x*c*s-a*g*s-x*i*l+t*g*l+a*i*v-t*c*v)*E,e[7]=(a*p*s-u*c*s+u*i*l-t*p*l-a*i*m+t*c*m)*E,e[8]=M*E,e[9]=(x*f*s-u*T*s-x*n*m+t*T*m+u*n*v-t*f*v)*E,e[10]=(a*T*s-x*o*s+x*n*l-t*T*l-a*n*v+t*o*v)*E,e[11]=(u*o*s-a*f*s-u*n*l+t*f*l+a*n*m-t*o*m)*E,e[12]=C*E,e[13]=(u*T*i-x*f*i+x*n*p-t*T*p-u*n*g+t*f*g)*E,e[14]=(x*o*i-a*T*i-x*n*c+t*T*c+a*n*g-t*o*g)*E,e[15]=(a*f*i-u*o*i+u*n*c-t*f*c-a*n*p+t*o*p)*E,this}scale(e){const t=this.elements,n=e.x,i=e.y,s=e.z;return t[0]*=n,t[4]*=i,t[8]*=s,t[1]*=n,t[5]*=i,t[9]*=s,t[2]*=n,t[6]*=i,t[10]*=s,t[3]*=n,t[7]*=i,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,i))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const n=Math.cos(t),i=Math.sin(t),s=1-n,a=e.x,o=e.y,c=e.z,l=s*a,u=s*o;return this.set(l*a+n,l*o-i*c,l*c+i*o,0,l*o+i*c,u*o+n,u*c-i*a,0,l*c-i*o,u*c+i*a,s*c*c+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,i,s,a){return this.set(1,n,s,0,e,1,a,0,t,i,1,0,0,0,0,1),this}compose(e,t,n){const i=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,u=a+a,f=o+o,p=s*l,m=s*u,x=s*f,T=a*u,g=a*f,v=o*f,_=c*l,b=c*u,M=c*f,C=n.x,P=n.y,E=n.z;return i[0]=(1-(T+v))*C,i[1]=(m+M)*C,i[2]=(x-b)*C,i[3]=0,i[4]=(m-M)*P,i[5]=(1-(p+v))*P,i[6]=(g+_)*P,i[7]=0,i[8]=(x+b)*E,i[9]=(g-_)*E,i[10]=(1-(p+T))*E,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,n){const i=this.elements;let s=wn.set(i[0],i[1],i[2]).length();const a=wn.set(i[4],i[5],i[6]).length(),o=wn.set(i[8],i[9],i[10]).length();this.determinant()<0&&(s=-s),e.x=i[12],e.y=i[13],e.z=i[14],Ct.copy(this);const l=1/s,u=1/a,f=1/o;return Ct.elements[0]*=l,Ct.elements[1]*=l,Ct.elements[2]*=l,Ct.elements[4]*=u,Ct.elements[5]*=u,Ct.elements[6]*=u,Ct.elements[8]*=f,Ct.elements[9]*=f,Ct.elements[10]*=f,t.setFromRotationMatrix(Ct),n.x=s,n.y=a,n.z=o,this}makePerspective(e,t,n,i,s,a,o=Qi){const c=this.elements,l=2*s/(t-e),u=2*s/(n-i),f=(t+e)/(t-e),p=(n+i)/(n-i);let m,x;if(o===Qi)m=-(a+s)/(a-s),x=-2*a*s/(a-s);else if(o===Qo)m=-a/(a-s),x=-a*s/(a-s);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=l,c[4]=0,c[8]=f,c[12]=0,c[1]=0,c[5]=u,c[9]=p,c[13]=0,c[2]=0,c[6]=0,c[10]=m,c[14]=x,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,i,s,a,o=Qi){const c=this.elements,l=1/(t-e),u=1/(n-i),f=1/(a-s),p=(t+e)*l,m=(n+i)*u;let x,T;if(o===Qi)x=(a+s)*f,T=-2*f;else if(o===Qo)x=s*f,T=-1*f;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-p,c[1]=0,c[5]=2*u,c[9]=0,c[13]=-m,c[2]=0,c[6]=0,c[10]=T,c[14]=-x,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<16;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}}const wn=new G,Ct=new Et,du=new G(0,0,0),pu=new G(1,1,1),Yt=new G,er=new G,lt=new G,ea=new Et,ta=new ie;class ui{constructor(e=0,t=0,n=0,i=ui.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,i=this._order){return this._x=e,this._y=t,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new ui(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){const i=e.elements,s=i[0],a=i[4],o=i[8],c=i[1],l=i[5],u=i[9],f=i[2],p=i[6],m=i[10];switch(t){case"XYZ":this._y=Math.asin(Ot(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,m),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(p,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Ot(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,m),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-f,s),this._z=0);break;case"ZXY":this._x=Math.asin(Ot(p,-1,1)),Math.abs(p)<.9999999?(this._y=Math.atan2(-f,m),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Ot(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(p,m),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin(Ot(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-u,l),this._y=Math.atan2(-f,s)):(this._x=0,this._y=Math.atan2(o,m));break;case"XZY":this._z=Math.asin(-Ot(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(p,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-u,m),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return ea.makeRotationFromQuaternion(e),this.setFromRotationMatrix(ea,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return ta.setFromEuler(this),this.setFromQuaternion(ta,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}}ui.DEFAULT_ORDER="XYZ";class Dn{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 Dn(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(Ot(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}rotateAround(e,t){const n=Math.cos(t),i=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*n-a*i+e.x,this.y=s*i+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}Dn.isVector2=!0;class at{constructor(e=0,t=0,n=0,i=1){at.prototype.isVector4=!0,this.x=e,this.y=t,this.z=n,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new at(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*i+a[12]*s,this.y=a[1]*t+a[5]*n+a[9]*i+a[13]*s,this.z=a[2]*t+a[6]*n+a[10]*i+a[14]*s,this.w=a[3]*t+a[7]*n+a[11]*i+a[15]*s,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,i,s;const c=e.elements,l=c[0],u=c[4],f=c[8],p=c[1],m=c[5],x=c[9],T=c[2],g=c[6],v=c[10];if(Math.abs(u-p)<.01&&Math.abs(f-T)<.01&&Math.abs(x-g)<.01){if(Math.abs(u+p)<.1&&Math.abs(f+T)<.1&&Math.abs(x+g)<.1&&Math.abs(l+m+v-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const b=(l+1)/2,M=(m+1)/2,C=(v+1)/2,P=(u+p)/4,E=(f+T)/4,z=(x+g)/4;return b>M&&b>C?b<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(b),i=P/n,s=E/n):M>C?M<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(M),n=P/i,s=z/i):C<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(C),n=E/s,i=z/s),this.set(n,i,s,t),this}let _=Math.sqrt((g-x)*(g-x)+(f-T)*(f-T)+(p-u)*(p-u));return Math.abs(_)<.001&&(_=1),this.x=(g-x)/_,this.y=(f-T)/_,this.z=(p-u)/_,this.w=Math.acos((l+m+v-1)/2),this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class It{constructor(e,t,n,i,s,a,o,c,l){It.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,a,o,c,l)}set(e,t,n,i,s,a,o,c,l){const u=this.elements;return u[0]=e,u[1]=i,u[2]=o,u[3]=t,u[4]=s,u[5]=c,u[6]=n,u[7]=a,u[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,a=n[0],o=n[3],c=n[6],l=n[1],u=n[4],f=n[7],p=n[2],m=n[5],x=n[8],T=i[0],g=i[3],v=i[6],_=i[1],b=i[4],M=i[7],C=i[2],P=i[5],E=i[8];return s[0]=a*T+o*_+c*C,s[3]=a*g+o*b+c*P,s[6]=a*v+o*M+c*E,s[1]=l*T+u*_+f*C,s[4]=l*g+u*b+f*P,s[7]=l*v+u*M+f*E,s[2]=p*T+m*_+x*C,s[5]=p*g+m*b+x*P,s[8]=p*v+m*M+x*E,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8];return t*a*u-t*o*l-n*s*u+n*o*c+i*s*l-i*a*c}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],f=u*a-o*l,p=o*c-u*s,m=l*s-a*c,x=t*f+n*p+i*m;if(x===0)return this.set(0,0,0,0,0,0,0,0,0);const T=1/x;return e[0]=f*T,e[1]=(i*l-u*n)*T,e[2]=(o*n-i*a)*T,e[3]=p*T,e[4]=(u*t-i*c)*T,e[5]=(i*s-o*t)*T,e[6]=m*T,e[7]=(n*c-l*t)*T,e[8]=(a*t-n*s)*T,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,i,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(n*c,n*l,-n*(c*a+l*o)+a+e,-i*l,i*c,-i*(-l*a+c*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(ps.makeScale(e,t)),this}rotate(e){return this.premultiply(ps.makeRotation(-e)),this}translate(e,t){return this.premultiply(ps.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<9;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new It().fromArray(this.elements)}}const ps=new It;var et;(function(r){r[r.Random=0]="Random",r[r.Loop=1]="Loop",r[r.PingPong=2]="PingPong",r[r.Burst=3]="Burst"})(et||(et={}));function ji(r,e,t,n){let i;switch(et.Random===r?e=Math.random():et.Burst===r&&n.isBursting&&(e=n.burstParticleIndex/n.burstParticleCount),t>0?i=Math.floor(e/t)*t:i=e,r){case et.Loop:i=i%1;break;case et.PingPong:i=Math.abs(i%2-1);break}return i}class yn{constructor(e,t,n,i){this.p=[e,t,n,i]}genValue(e){const t=e*e,n=e*e*e,i=1-e,s=i*i,a=s*i;return this.p[0]*a+this.p[1]*s*e*3+this.p[2]*i*t*3+this.p[3]*n}derivativeCoefficients(e){const t=[];for(let n=e,i=n.length-1;i>0;i--){const s=[];for(let a=0;a<i;a++){const o=i*(n[a+1]-n[a]);s.push(o)}t.push(s),n=s}return t}getSlope(e){const t=this.derivativeCoefficients(this.p)[0],n=1-e,i=n*n,s=n*e*2,a=e*e;return i*t[0]+s*t[1]+a*t[2]}controlCurve(e,t){this.p[1]=e/3+this.p[0],this.p[2]=this.p[3]-t/3}hull(e){let t=this.p,n=[],i,s=0,a=0,o=0;const c=[];for(c[s++]=t[0],c[s++]=t[1],c[s++]=t[2],c[s++]=t[3];t.length>1;){for(n=[],a=0,o=t.length-1;a<o;a++)i=e*t[a]+(1-e)*t[a+1],c[s++]=i,n.push(i);t=n}return c}split(e){const t=this.hull(e);return{left:new yn(t[0],t[4],t[7],t[9]),right:new yn(t[9],t[8],t[6],t[3]),span:t}}clone(){return new yn(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 yn(e.p0,e.p1,e.p2,e.p3)}}const hi=r=>({r:r.x,g:r.y,b:r.z,a:r.w}),fi=r=>new at(r.r,r.g,r.b,r.a),mu=(r,e)=>{switch(e){case"Vector3":return new G(r.x,r.y,r.z);case"Vector4":return new at(r.x,r.y,r.z,r.w);case"Color":return new G(r.r,r.g,r.b);case"Number":return r;default:return r}},yu=(r,e)=>{switch(e){case"Vector3":return{x:r.x,y:r.y,z:r.z};case"Vector4":return{x:r.x,y:r.y,z:r.z,w:r.w};case"Color":return{r:r.x,g:r.y,b:r.z};case"Number":return r;default:return r}};class Ar{constructor(e,t){this.a=e,this.b=t,this.type="value"}startGen(e){}genColor(e,t){const n=Math.random();return t.copy(this.a).lerp(this.b,n)}toJSON(){return{type:"RandomColor",a:hi(this.a),b:hi(this.b)}}static fromJSON(e){return new Ar(fi(e.a),fi(e.b))}clone(){return new Ar(this.a.clone(),this.b.clone())}}class Fn{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:hi(this.a),b:hi(this.b)}}static fromJSON(e){return new Fn(fi(e.a),fi(e.b))}clone(){return new Fn(this.a.clone(),this.b.clone())}}class tn{constructor(e,t){this.subType=t,this.type="function",this.keys=e}findKey(e){let t=0,n=0,i=this.keys.length-1;for(;n+1<i;)if(t=Math.floor((n+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))n=t+1;else return t;for(let s=n;s<=i;s++)if(e>=this.getStartX(s)&&e<=this.getEndX(s))return s;return-1}getStartX(e){return this.keys[e][1]}getEndX(e){return e+1<this.keys.length?this.keys[e+1][1]:1}genValue(e,t){const n=this.findKey(t);return this.subType==="Number"?n===-1?this.keys[0][0]:n+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[n+1][0]-this.keys[n][0])*((t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))+this.keys[n][0]:n===-1?e.copy(this.keys[0][0]):n+1>=this.keys.length?e.copy(this.keys[this.keys.length-1][0]):e.copy(this.keys[n][0]).lerp(this.keys[n+1][0],(t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([e,t])=>({value:yu(e,this.subType),pos:t}))}}static fromJSON(e){return new tn(e.keys.map(t=>[mu(t.value,e.subType),t.pos]),e.subType)}clone(){return this.subType==="Number"?new tn(this.keys.map(([e,t])=>[e,t]),this.subType):new tn(this.keys.map(([e,t])=>[e.clone(),t]),this.subType)}}const tr=new G;class gn{constructor(e=[[new G(0,0,0),0],[new G(1,1,1),0]],t=[[1,0],[1,1]]){this.type="function",this.color=new tn(e,"Color"),this.alpha=new tn(t,"Number")}genColor(e,t,n){return this.color.genValue(tr,n),t.set(tr.x,tr.y,tr.z,this.alpha.genValue(1,n))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(e){if(e.functions){const t=e.functions.map(n=>[Fn.fromJSON(n.function).a,n.start]);return e.functions.length>0&&t.push([Fn.fromJSON(e.functions[e.functions.length-1].function).b,1]),new gn(t.map(n=>[new G(n[0].x,n[0].y,n[0].z),n[1]]),t.map(n=>[n[0].w,n[1]]))}else{const t=new gn;return t.alpha=tn.fromJSON(e.alpha),t.color=tn.fromJSON(e.color),t}}clone(){const e=new gn;return e.alpha=this.alpha.clone(),e.color=this.color.clone(),e}startGen(e){}}const ms=new at;class Or{constructor(e,t){this.indexCount=0,this.type="function",this.gradient1=e,this.gradient2=t}startGen(e){this.indexCount=e.length,e.push(Math.random())}genColor(e,t,n){return this.gradient1.genColor(e,t,n),this.gradient2.genColor(e,ms,n),e&&e[this.indexCount]!==void 0?t.lerp(ms,e[this.indexCount]):t.lerp(ms,Math.random()),t}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(e){return new Or(gn.fromJSON(e.gradient1),gn.fromJSON(e.gradient2))}clone(){return new Or(this.gradient1.clone(),this.gradient2.clone())}}class vn{constructor(e){this.color=e,this.type="value"}startGen(e){}genColor(e,t){return t.copy(this.color)}toJSON(){return{type:"ConstantColor",color:hi(this.color)}}static fromJSON(e){return new vn(fi(e.color))}clone(){return new vn(this.color.clone())}}function co(r){switch(r.type){case"ConstantColor":return vn.fromJSON(r);case"ColorRange":return Fn.fromJSON(r);case"RandomColor":return Ar.fromJSON(r);case"Gradient":return gn.fromJSON(r);case"RandomColorBetweenGradient":return Or.fromJSON(r);default:return new vn(new at(1,1,1,1))}}class ee{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 ee(e.value)}clone(){return new ee(this.value)}}class Sn{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),Jn.lerp(this.a,this.b,e[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(e){return new Sn(e.a,e.b)}clone(){return new Sn(this.a,this.b)}}class gu{constructor(){this.functions=new Array}findFunction(e){let t=0,n=0,i=this.functions.length-1;for(;n+1<i;)if(t=Math.floor((n+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))n=t+1;else return t;for(let s=n;s<=i;s++)if(e>=this.functions[s][1]&&e<=this.getEndX(s))return s;return-1}getStartX(e){return this.functions[e][1]}setStartX(e,t){e>0&&(this.functions[e][1]=t)}getEndX(e){return e+1<this.functions.length?this.functions[e+1][1]:1}setEndX(e,t){e+1<this.functions.length&&(this.functions[e+1][1]=t)}insertFunction(e,t){const n=this.findFunction(e);this.functions.splice(n+1,0,[t,e])}removeFunction(e){return this.functions.splice(e,1)[0][0]}getFunction(e){return this.functions[e][0]}setFunction(e,t){this.functions[e][0]=t}get numOfFunctions(){return this.functions.length}}class di extends gu{constructor(e=[[new yn(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=e}genValue(e,t=0){const n=this.findFunction(t);return n===-1?0:this.functions[n][0].genValue((t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))}toSVG(e,t){if(t<1)return"";let n=["M",0,this.functions[0][0].p[0]].join(" ");for(let i=1/t;i<=1;i+=1/t)n=[n,"L",i*e,this.genValue(void 0,i)].join(" ");return n}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([e,t])=>({function:e.toJSON(),start:t}))}}static fromJSON(e){return new di(e.functions.map(t=>[yn.fromJSON(t.function),t.start]))}clone(){return new di(this.functions.map(([e,t])=>[e.clone(),t]))}startGen(e){}}function Z(r){switch(r.type){case"ConstantValue":return ee.fromJSON(r);case"IntervalValue":return Sn.fromJSON(r);case"PiecewiseBezier":return di.fromJSON(r);default:return new ee(0)}}class pi{constructor(){this.indexCount=0,this.type="rotation"}startGen(e){this.indexCount=e.length,e.push(new ie);let t,n,i,s,a,o;do t=Math.random()*2-1,n=Math.random()*2-1,i=t*t+n*n;while(i>1);do s=Math.random()*2-1,a=Math.random()*2-1,o=s*s+a*a;while(o>1);const c=Math.sqrt((1-i)/o);e[this.indexCount].set(t,n,c*s,c*a)}genValue(e,t,n,i){return this.indexCount===-1&&this.startGen(e),t.copy(e[this.indexCount]),t}toJSON(){return{type:"RandomQuat"}}static fromJSON(e){return new pi}clone(){return new pi}}class mi{constructor(e,t){this.axis=e,this.angle=t,this.type="rotation"}startGen(e){this.angle.startGen(e)}genValue(e,t,n,i){return t.setFromAxisAngle(this.axis,this.angle.genValue(e,i)*n)}toJSON(){return{type:"AxisAngle",axis:{x:this.axis.x,y:this.axis.y,z:this.axis.z},angle:this.angle.toJSON()}}static fromJSON(e){return new mi(new G(e.axis.x,e.axis.y,e.axis.z),Z(e.angle))}clone(){return new mi(this.axis.clone(),this.angle.clone())}}class zr{constructor(e,t,n,i){this.angleX=e,this.angleY=t,this.angleZ=n,this.type="rotation",this.eular=new ui(0,0,0,i)}startGen(e){this.angleX.startGen(e),this.angleY.startGen(e),this.angleZ.startGen(e)}genValue(e,t,n,i){return this.eular.set(this.angleX.genValue(e,i)*n,this.angleY.genValue(e,i)*n,this.angleZ.genValue(e,i)*n),t.setFromEuler(this.eular)}toJSON(){return{type:"Euler",angleX:this.angleX.toJSON(),angleY:this.angleY.toJSON(),angleZ:this.angleZ.toJSON(),eulerOrder:this.eular.order}}static fromJSON(e){return new zr(Z(e.angleX),Z(e.angleY),Z(e.angleZ),e.eulerOrder)}clone(){return new zr(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function oc(r){switch(r.type){case"AxisAngle":return mi.fromJSON(r);case"Euler":return zr.fromJSON(r);case"RandomQuat":return pi.fromJSON(r);default:return new pi}}class xn{constructor(e,t,n){this.x=e,this.y=t,this.z=n,this.type="vec3function"}startGen(e){this.x.startGen(e),this.y.startGen(e),this.z.startGen(e)}genValue(e,t,n){return t.set(this.x.genValue(e,n),this.y.genValue(e,n),this.z.genValue(e,n))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new xn(Z(e.x),Z(e.y),Z(e.z))}clone(){return new xn(this.x,this.y,this.z)}}function vu(r){return r.type==="Vector3Function"?xn.fromJSON(r):new xn(new ee(0),new ee(0),new ee(0))}function Ir(r){switch(r.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return Z(r);case"AxisAngle":case"RandomQuat":case"Euler":return oc(r);case"Vector3Function":return vu(r);default:return new ee(0)}}class yi{constructor(e={}){var t,n,i,s,a,o,c;this.type="cone",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.angle=(s=e.angle)!==null&&s!==void 0?s:Math.PI/6,this.mode=(a=e.mode)!==null&&a!==void 0?a:et.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new ee(1),this.memory=[]}update(e,t){et.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Jn.lerp(1-this.thickness,1,Math.random()),s=n*this.arc,a=Math.sqrt(i),o=Math.sin(s),c=Math.cos(s);e.position.x=a*c,e.position.y=a*o,e.position.z=0;const l=this.angle*a;e.velocity.set(0,0,Math.cos(l)).addScaledVector(e.position,Math.sin(l)).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius)}toJSON(){return{type:"cone",radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new yi({radius:e.radius,arc:e.arc,thickness:e.thickness,angle:e.angle,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new yi({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class gi{constructor(e={}){var t,n,i,s,a,o;this.type="circle",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:et.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ee(1),this.memory=[]}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Jn.lerp(1-this.thickness,1,Math.random()),s=n*this.arc;e.position.x=Math.cos(s),e.position.y=Math.sin(s),e.position.z=0,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*i)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new gi({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new gi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function nr(r,e){return Math.floor(Math.random()*(e-r))+r}const Jr=new G(0,1,0),jr=new G(0,0,0),Su=new G(1,1,1),na=new G(0,0,1);class vi{constructor(e={}){var t,n,i,s,a,o,c;this.type="donut",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.donutRadius=(s=e.donutRadius)!==null&&s!==void 0?s:this.radius*.2,this.mode=(a=e.mode)!==null&&a!==void 0?a:et.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new ee(1),this.memory=[],this._m1=new Et}update(e,t){et.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=i*Math.PI*2,c=Math.sin(a),l=Math.cos(a);e.position.x=this.radius*l,e.position.y=this.radius*c,e.position.z=0,e.velocity.z=this.donutRadius*s*Math.sin(o),e.velocity.x=this.donutRadius*s*Math.cos(o)*l,e.velocity.y=this.donutRadius*s*Math.cos(o)*c,e.position.add(e.velocity),e.velocity.normalize().multiplyScalar(e.startSpeed),e.rotation instanceof ie&&(this._m1.lookAt(jr,e.velocity,Jr),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 vi({radius:e.radius,arc:e.arc,thickness:e.thickness,donutRadius:e.donutRadius,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new vi({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Si{constructor(){this.type="point",this._m1=new Et}update(e,t){}initialize(e){const t=Math.random(),n=Math.random(),i=t*Math.PI*2,s=Math.acos(2*n-1),a=Math.cbrt(Math.random()),o=Math.sin(i),c=Math.cos(i),l=Math.sin(s),u=Math.cos(s);e.velocity.x=a*l*c,e.velocity.y=a*l*o,e.velocity.z=a*u,e.velocity.multiplyScalar(e.startSpeed),e.position.setScalar(0),e.rotation instanceof ie&&(this._m1.lookAt(jr,e.position,Jr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(e){return new Si}clone(){return new Si}}class Ln{constructor(e={}){var t,n,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:et.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ee(1),this.memory=[],this._m1=new Et}update(e,t){et.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=Math.acos(2*i-1),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),f=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=f,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof ie&&(this._m1.lookAt(jr,e.position,Jr),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 Ln({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new Ln({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class xi{constructor(e={}){var t,n,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:et.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ee(1),this.memory=[],this._m1=new Et}update(e,t){et.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=Math.acos(i),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),f=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=f,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof ie&&(this._m1.lookAt(jr,e.position,Jr),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 xi({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new xi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class _i{constructor(e={}){var t,n,i,s;this.type="grid",this.width=(t=e.width)!==null&&t!==void 0?t:1,this.height=(n=e.height)!==null&&n!==void 0?n:1,this.column=(i=e.column)!==null&&i!==void 0?i:10,this.row=(s=e.row)!==null&&s!==void 0?s:10}initialize(e){const t=Math.floor(Math.random()*this.row),n=Math.floor(Math.random()*this.column);e.position.x=n*this.width/this.column-this.width/2,e.position.y=t*this.height/this.row-this.height/2,e.position.z=0,e.velocity.set(0,0,e.startSpeed)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row}}static fromJSON(e){return new _i(e)}clone(){return new _i({width:this.width,height:this.height,column:this.column,row:this.row})}update(e,t){}}const Fs={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:gi,loadJSON:gi.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:yi,loadJSON:yi.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:vi,loadJSON:vi.fromJSON},point:{type:"point",params:[],constructor:Si,loadJSON:Si.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ln,loadJSON:Ln.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:xi,loadJSON:xi.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:_i,loadJSON:_i.fromJSON}};function xu(r,e){return Fs[r.type].loadJSON(r,e)}class bi{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 bi(co(e.color))}clone(){return new bi(this.color.clone())}reset(){}}class Ti{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 Ti(Z(e.angularVelocity))}frameUpdate(e){}clone(){return new Ti(this.angularVelocity.clone())}reset(){}}class Mi{constructor(e){this.angularVelocity=e,this.type="Rotation3DOverLife",this.tempQuat=new ie,this.tempQuat2=new ie}initialize(e){e.rotation instanceof ie&&(e.angularVelocity=new ie,this.angularVelocity.startGen(e.memory))}update(e,t){e.rotation instanceof ie&&(this.angularVelocity.genValue(e.memory,this.tempQuat,t,e.age/e.life),e.rotation.multiply(this.tempQuat))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(e){return new Mi(oc(e.angularVelocity))}frameUpdate(e){}clone(){return new Mi(this.angularVelocity.clone())}reset(){}}class Ci{initialize(e,t){this.ps=t,this.x.startGen(e.memory),this.y.startGen(e.memory),this.z.startGen(e.memory)}constructor(e,t,n){this.x=e,this.y=t,this.z=n,this.type="ForceOverLife",this._temp=new G,this._tempScale=new G,this._tempQ=new ie}update(e,t){this._temp.set(this.x.genValue(e.memory,e.age/e.life),this.y.genValue(e.memory,e.age/e.life),this.z.genValue(e.memory,e.age/e.life)),this.ps.worldSpace?e.velocity.addScaledVector(this._temp,t):(this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ),e.velocity.addScaledVector(this._temp,t))}toJSON(){return{type:this.type,x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new Ci(Z(e.x),Z(e.y),Z(e.z))}frameUpdate(e){if(this.ps&&!this.ps.worldSpace){const t=this._temp,n=this._tempQ,i=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,n,i),n.invert(),i.set(1/i.x,1/i.y,1/i.z)}}clone(){return new Ci(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class wi{initialize(e){this.size.startGen(e.memory)}constructor(e){this.size=e,this.type="SizeOverLife"}update(e){this.size instanceof xn?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 wi(Ir(e.size))}frameUpdate(e){}clone(){return new wi(this.size.clone())}reset(){}}class Pi{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 Pi(Z(e.speed))}frameUpdate(e){}clone(){return new Pi(this.speed.clone())}reset(){}}class Ei{constructor(e){this.frame=e,this.type="FrameOverLife"}initialize(e){this.frame.startGen(e.memory)}update(e,t){this.frame instanceof di&&(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 Ei(Z(e.frame))}clone(){return new Ei(this.frame.clone())}reset(){}}class ki{constructor(e,t=new G(0,1,0)){this.orbitSpeed=e,this.axis=t,this.type="OrbitOverLife",this.temp=new G,this.rotation=new ie}initialize(e){this.orbitSpeed.startGen(e.memory)}update(e,t){this.temp.copy(e.position).projectOnVector(this.axis),this.rotation.setFromAxisAngle(this.axis,this.orbitSpeed.genValue(e.memory,e.age/e.life)*t),e.position.sub(this.temp),e.position.applyQuaternion(this.rotation),e.position.add(this.temp)}frameUpdate(e){}toJSON(){return{type:this.type,orbitSpeed:this.orbitSpeed.toJSON(),axis:[this.axis.x,this.axis.y,this.axis.z]}}static fromJSON(e){return new ki(Z(e.orbitSpeed),e.axis?new G(e.axis[0],e.axis[1],e.axis[2]):void 0)}clone(){return new ki(this.orbitSpeed.clone())}reset(){}}class ys{constructor(e){this.data=e,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class _u{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 ys(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 ys(e);this.head||(this.head=t),this.tail&&(this.tail.next=t,t.prev=this.tail),this.tail=t,this.length++}insertBefore(e,t){const n=new ys(t);n.next=e,n.prev=e.prev,n.prev!==null&&(n.prev.next=n),n.next.prev=n,e==this.head&&(this.head=n),this.length++}remove(e){if(this.head===null||this.tail===null)return;let t=this.head;for(e===this.head.data&&(this.head=this.head.next),e===this.tail.data&&(this.tail=this.tail.prev);t.next!==null&&t.data!==e;)t=t.next;t.data===e&&(t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.length--)}*values(){let e=this.head;for(;e!==null;)yield e.data,e=e.next}}class bu{constructor(){this.startSpeed=0,this.startColor=new at,this.startSize=new G(1,1,1),this.position=new G,this.velocity=new G,this.age=0,this.life=1,this.size=new G(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new at,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class Tu{constructor(e,t,n){this.position=e,this.size=t,this.color=n}}class Br{constructor(){this.startSpeed=0,this.startColor=new at,this.startSize=new G(1,1,1),this.position=new G,this.velocity=new G,this.age=0,this.life=1,this.size=new G(1,1,1),this.length=100,this.speedModifier=1,this.color=new at,this.previous=new _u,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new Tu(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 Ri{initialize(e){this.width.startGen(e.memory)}constructor(e){this.width=e,this.type="WidthOverLength"}update(e){if(e instanceof Br){const t=e.previous.values();for(let n=0;n<e.previous.length;n++){const i=t.next();i.value.size=this.width.genValue(e.memory,(e.previous.length-n)/e.length)}}}frameUpdate(e){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(e){return new Ri(Z(e.width))}clone(){return new Ri(this.width.clone())}reset(){}}class Ai{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 Ai(new G(e.direction[0],e.direction[1],e.direction[2]),Z((t=e.magnitude)!==null&&t!==void 0?t:e.force))}clone(){return new Ai(this.direction.clone(),this.magnitude.clone())}reset(){}}class Oi{constructor(e,t){this.center=e,this.magnitude=t,this.type="GravityForce",this.temp=new G}initialize(e){}update(e,t){this.temp.copy(this.center).sub(e.position).normalize(),e.velocity.addScaledVector(this.temp,this.magnitude/e.position.distanceToSquared(this.center)*t)}frameUpdate(e){}toJSON(){return{type:this.type,center:[this.center.x,this.center.y,this.center.z],magnitude:this.magnitude}}static fromJSON(e){return new Oi(new G(e.center[0],e.center[1],e.center[2]),e.magnitude)}clone(){return new Oi(this.center.clone(),this.magnitude)}reset(){}}class zi{constructor(e){this.angle=e,this.type="ChangeEmitDirection",this._temp=new G,this._q=new ie,this.memory={data:[],dataCount:0}}initialize(e){const t=e.velocity.length();t!=0&&(e.velocity.normalize(),e.velocity.x===0&&e.velocity.y===0?this._temp.set(0,e.velocity.z,0):this._temp.set(-e.velocity.y,e.velocity.x,0),this.angle.startGen(this.memory),this._q.setFromAxisAngle(this._temp.normalize(),this.angle.genValue(this.memory)),this._temp.copy(e.velocity),e.velocity.applyQuaternion(this._q),this._q.setFromAxisAngle(this._temp,Math.random()*Math.PI*2),e.velocity.applyQuaternion(this._q),e.velocity.setLength(t))}update(e,t){}frameUpdate(e){}toJSON(){return{type:this.type,angle:this.angle.toJSON()}}static fromJSON(e){return new zi(Z(e.angle))}clone(){return new zi(this.angle)}reset(){}}var Nn;(function(r){r[r.Death=0]="Death",r[r.Birth=1]="Birth",r[r.Frame=2]="Frame"})(Nn||(Nn={}));class Ii{constructor(e,t,n,i=Nn.Frame,s=1){this.particleSystem=e,this.useVelocityAsBasis=t,this.subParticleSystem=n,this.mode=i,this.emitProbability=s,this.type="EmitSubParticleSystem",this.q_=new ie,this.v_=new G,this.v2_=new G,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(e){}update(e,t){this.mode===Nn.Frame?this.emit(e,t):this.mode===Nn.Birth&&e.age===0?this.emit(e,t):this.mode===Nn.Death&&e.age+t>=e.life&&this.emit(e,t)}emit(e,t){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const n=new Et;this.setMatrixFromParticle(n,e),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:n,travelDistance:0,particle:e})}frameUpdate(e){if(this.subParticleSystem)for(let t=0;t<this.subEmissions.length;t++)if(this.subEmissions[t].time>=this.subParticleSystem.system.duration)this.subEmissions[t]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,t--;else{const n=this.subEmissions[t];n.particle&&n.particle.age<n.particle.life?this.setMatrixFromParticle(n.matrix,n.particle):n.particle=void 0,this.subParticleSystem.system.emit(e,n,n.matrix)}}toJSON(){return{type:this.type,subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(e,t){return new Ii(t,e.useVelocityAsBasis,e.subParticleSystem,e.mode,e.emitProbability)}clone(){return new Ii(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(e,t){let n;if(t.rotation===void 0||this.useVelocityAsBasis)if(t.velocity.x===0&&t.velocity.y===0&&(t.velocity.z===1||t.velocity.z===0))e.set(1,0,0,t.position.x,0,1,0,t.position.y,0,0,1,t.position.z,0,0,0,1);else{this.v_.copy(na).cross(t.velocity),this.v2_.copy(t.velocity).cross(this.v_);const i=this.v_.length(),s=this.v2_.length();e.set(this.v_.x/i,this.v2_.x/s,t.velocity.x,t.position.x,this.v_.y/i,this.v2_.y/s,t.velocity.y,t.position.y,this.v_.z/i,this.v2_.z/s,t.velocity.z,t.position.z,0,0,0,1)}else t.rotation instanceof ie?n=t.rotation:(this.q_.setFromAxisAngle(na,t.rotation),n=this.q_),e.compose(t.position,n,Su);this.particleSystem.worldSpace||e.multiplyMatrices(this.particleSystem.emitter.matrixWorld,e)}}const Mu=.5*(Math.sqrt(3)-1),$n=(3-Math.sqrt(3))/6,Cu=1/3,Rt=1/6,wu=(Math.sqrt(5)-1)/4,Ne=(5-Math.sqrt(5))/20,Oe=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]),Me=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 ac{constructor(e=Math.random){const t=typeof e=="function"?e:Eu(e);this.p=Pu(t),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let n=0;n<512;n++)this.perm[n]=this.p[n&255],this.permMod12[n]=this.perm[n]%12}noise2D(e,t){const n=this.permMod12,i=this.perm;let s=0,a=0,o=0;const c=(e+t)*Mu,l=Math.floor(e+c),u=Math.floor(t+c),f=(l+u)*$n,p=l-f,m=u-f,x=e-p,T=t-m;let g,v;x>T?(g=1,v=0):(g=0,v=1);const _=x-g+$n,b=T-v+$n,M=x-1+2*$n,C=T-1+2*$n,P=l&255,E=u&255;let z=.5-x*x-T*T;if(z>=0){const N=n[P+i[E]]*3;z*=z,s=z*z*(Oe[N]*x+Oe[N+1]*T)}let I=.5-_*_-b*b;if(I>=0){const N=n[P+g+i[E+v]]*3;I*=I,a=I*I*(Oe[N]*_+Oe[N+1]*b)}let R=.5-M*M-C*C;if(R>=0){const N=n[P+1+i[E+1]]*3;R*=R,o=R*R*(Oe[N]*M+Oe[N+1]*C)}return 70*(s+a+o)}noise3D(e,t,n){const i=this.permMod12,s=this.perm;let a,o,c,l;const u=(e+t+n)*Cu,f=Math.floor(e+u),p=Math.floor(t+u),m=Math.floor(n+u),x=(f+p+m)*Rt,T=f-x,g=p-x,v=m-x,_=e-T,b=t-g,M=n-v;let C,P,E,z,I,R;_>=b?b>=M?(C=1,P=0,E=0,z=1,I=1,R=0):_>=M?(C=1,P=0,E=0,z=1,I=0,R=1):(C=0,P=0,E=1,z=1,I=0,R=1):b<M?(C=0,P=0,E=1,z=0,I=1,R=1):_<M?(C=0,P=1,E=0,z=0,I=1,R=1):(C=0,P=1,E=0,z=1,I=1,R=0);const N=_-C+Rt,O=b-P+Rt,U=M-E+Rt,L=_-z+2*Rt,J=b-I+2*Rt,$=M-R+2*Rt,K=_-1+3*Rt,W=b-1+3*Rt,me=M-1+3*Rt,ne=f&255,ue=p&255,re=m&255;let ge=.6-_*_-b*b-M*M;if(ge<0)a=0;else{const oe=i[ne+s[ue+s[re]]]*3;ge*=ge,a=ge*ge*(Oe[oe]*_+Oe[oe+1]*b+Oe[oe+2]*M)}let be=.6-N*N-O*O-U*U;if(be<0)o=0;else{const oe=i[ne+C+s[ue+P+s[re+E]]]*3;be*=be,o=be*be*(Oe[oe]*N+Oe[oe+1]*O+Oe[oe+2]*U)}let se=.6-L*L-J*J-$*$;if(se<0)c=0;else{const oe=i[ne+z+s[ue+I+s[re+R]]]*3;se*=se,c=se*se*(Oe[oe]*L+Oe[oe+1]*J+Oe[oe+2]*$)}let he=.6-K*K-W*W-me*me;if(he<0)l=0;else{const oe=i[ne+1+s[ue+1+s[re+1]]]*3;he*=he,l=he*he*(Oe[oe]*K+Oe[oe+1]*W+Oe[oe+2]*me)}return 32*(a+o+c+l)}noise4D(e,t,n,i){const s=this.perm;let a,o,c,l,u;const f=(e+t+n+i)*wu,p=Math.floor(e+f),m=Math.floor(t+f),x=Math.floor(n+f),T=Math.floor(i+f),g=(p+m+x+T)*Ne,v=p-g,_=m-g,b=x-g,M=T-g,C=e-v,P=t-_,E=n-b,z=i-M;let I=0,R=0,N=0,O=0;C>P?I++:R++,C>E?I++:N++,C>z?I++:O++,P>E?R++:N++,P>z?R++:O++,E>z?N++:O++;const U=I>=3?1:0,L=R>=3?1:0,J=N>=3?1:0,$=O>=3?1:0,K=I>=2?1:0,W=R>=2?1:0,me=N>=2?1:0,ne=O>=2?1:0,ue=I>=1?1:0,re=R>=1?1:0,ge=N>=1?1:0,be=O>=1?1:0,se=C-U+Ne,he=P-L+Ne,oe=E-J+Ne,Xe=z-$+Ne,Ve=C-K+2*Ne,Je=P-W+2*Ne,Ye=E-me+2*Ne,xe=z-ne+2*Ne,ye=C-ue+3*Ne,ae=P-re+3*Ne,ut=E-ge+3*Ne,ke=z-be+3*Ne,fe=C-1+4*Ne,it=P-1+4*Ne,vt=E-1+4*Ne,St=z-1+4*Ne,rt=p&255,xt=m&255,ht=x&255,ft=T&255;let _t=.6-C*C-P*P-E*E-z*z;if(_t<0)a=0;else{const Q=s[rt+s[xt+s[ht+s[ft]]]]%32*4;_t*=_t,a=_t*_t*(Me[Q]*C+Me[Q+1]*P+Me[Q+2]*E+Me[Q+3]*z)}let Re=.6-se*se-he*he-oe*oe-Xe*Xe;if(Re<0)o=0;else{const Q=s[rt+U+s[xt+L+s[ht+J+s[ft+$]]]]%32*4;Re*=Re,o=Re*Re*(Me[Q]*se+Me[Q+1]*he+Me[Q+2]*oe+Me[Q+3]*Xe)}let Ze=.6-Ve*Ve-Je*Je-Ye*Ye-xe*xe;if(Ze<0)c=0;else{const Q=s[rt+K+s[xt+W+s[ht+me+s[ft+ne]]]]%32*4;Ze*=Ze,c=Ze*Ze*(Me[Q]*Ve+Me[Q+1]*Je+Me[Q+2]*Ye+Me[Q+3]*xe)}let ct=.6-ye*ye-ae*ae-ut*ut-ke*ke;if(ct<0)l=0;else{const Q=s[rt+ue+s[xt+re+s[ht+ge+s[ft+be]]]]%32*4;ct*=ct,l=ct*ct*(Me[Q]*ye+Me[Q+1]*ae+Me[Q+2]*ut+Me[Q+3]*ke)}let Ke=.6-fe*fe-it*it-vt*vt-St*St;if(Ke<0)u=0;else{const Q=s[rt+1+s[xt+1+s[ht+1+s[ft+1]]]]%32*4;Ke*=Ke,u=Ke*Ke*(Me[Q]*fe+Me[Q+1]*it+Me[Q+2]*vt+Me[Q+3]*St)}return 27*(a+o+c+l+u)}}function Pu(r){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let t=0;t<255;t++){const n=t+~~(r()*(256-t)),i=e[t];e[t]=e[n],e[n]=i}return e}function Eu(r){let e=0,t=0,n=0,i=1;const s=ku();return e=s(" "),t=s(" "),n=s(" "),e-=s(r),e<0&&(e+=1),t-=s(r),t<0&&(t+=1),n-=s(r),n<0&&(n+=1),function(){const a=2091639*e+i*23283064365386963e-26;return e=t,t=n,n=a-(i=a|0)}}function ku(){let r=4022871197;return function(e){e=e.toString();for(let t=0;t<e.length;t++){r+=e.charCodeAt(t);let n=.02519603282416938*r;r=n>>>0,n-=r,n*=r,r=n>>>0,n-=r,r+=n*4294967296}return(r>>>0)*23283064365386963e-26}}class Bi{constructor(e,t,n,i){this.scale=e,this.octaves=t,this.velocityMultiplier=n,this.timeScale=i,this.type="TurbulenceField",this.generator=new ac,this.timeOffset=new G,this.temp=new G,this.temp2=new G,this.timeOffset.x=Math.random()/this.scale.x*this.timeScale.x,this.timeOffset.y=Math.random()/this.scale.y*this.timeScale.y,this.timeOffset.z=Math.random()/this.scale.z*this.timeScale.z}initialize(e){}update(e,t){const n=e.position.x/this.scale.x,i=e.position.y/this.scale.y,s=e.position.z/this.scale.z;this.temp.set(0,0,0);let a=1;for(let o=0;o<this.octaves;o++)this.temp2.set(this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.x*a)/a,this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.y*a)/a,this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.z*a)/a),this.temp.add(this.temp2),a*=2;this.temp.multiply(this.velocityMultiplier),e.velocity.addScaledVector(this.temp,t)}toJSON(){return{type:this.type,scale:[this.scale.x,this.scale.y,this.scale.z],octaves:this.octaves,velocityMultiplier:[this.velocityMultiplier.x,this.velocityMultiplier.y,this.velocityMultiplier.z],timeScale:[this.timeScale.x,this.timeScale.y,this.timeScale.z]}}frameUpdate(e){this.timeOffset.x+=e*this.timeScale.x,this.timeOffset.y+=e*this.timeScale.y,this.timeOffset.z+=e*this.timeScale.z}static fromJSON(e){return new Bi(new G(e.scale[0],e.scale[1],e.scale[2]),e.octaves,new G(e.velocityMultiplier[0],e.velocityMultiplier[1],e.velocityMultiplier[2]),new G(e.timeScale[0],e.timeScale[1],e.timeScale[2]))}clone(){return new Bi(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const At=[],gs=new G,vs=new ie;class Ni{constructor(e,t,n=new ee(1),i=new ee(0)){if(this.frequency=e,this.power=t,this.positionAmount=n,this.rotationAmount=i,this.type="Noise",this.duration=0,At.length===0)for(let s=0;s<100;s++)At.push(new ac)}initialize(e){e.lastPosNoise=new G,typeof e.rotation=="number"?e.lastRotNoise=0:e.lastRotNoise=new ie,e.generatorIndex=[nr(0,100),nr(0,100),nr(0,100),nr(0,100)],this.positionAmount.startGen(e.memory),this.rotationAmount.startGen(e.memory),this.frequency.startGen(e.memory),this.power.startGen(e.memory)}update(e,t){let n=this.frequency.genValue(e.memory,e.age/e.life),i=this.power.genValue(e.memory,e.age/e.life),s=this.positionAmount.genValue(e.memory,e.age/e.life),a=this.rotationAmount.genValue(e.memory,e.age/e.life);s>0&&e.lastPosNoise!==void 0&&(e.position.sub(e.lastPosNoise),gs.set(At[e.generatorIndex[0]].noise2D(0,e.age*n)*i*s,At[e.generatorIndex[1]].noise2D(0,e.age*n)*i*s,At[e.generatorIndex[2]].noise2D(0,e.age*n)*i*s),e.position.add(gs),e.lastPosNoise.copy(gs)),a>0&&e.lastRotNoise!==void 0&&(typeof e.rotation=="number"?(e.rotation-=e.lastRotNoise,e.rotation+=At[e.generatorIndex[3]].noise2D(0,e.age*n)*Math.PI*i*a):(e.lastRotNoise.invert(),e.rotation.multiply(e.lastRotNoise),vs.set(At[e.generatorIndex[0]].noise2D(0,e.age*n)*i*a,At[e.generatorIndex[1]].noise2D(0,e.age*n)*i*a,At[e.generatorIndex[2]].noise2D(0,e.age*n)*i*a,At[e.generatorIndex[3]].noise2D(0,e.age*n)*i*a).normalize(),e.rotation.multiply(vs),e.lastRotNoise.copy(vs)))}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON()}}frameUpdate(e){this.duration+=e}static fromJSON(e){return new Ni(Z(e.frequency),Z(e.power),Z(e.positionAmount),Z(e.rotationAmount))}clone(){return new Ni(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Ui{constructor(e,t){this.color=e,this.speedRange=t,this.type="ColorBySpeed"}initialize(e){this.color.startGen(e.memory)}update(e,t){const n=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(e.memory,e.color,n),e.color.x*=e.startColor.x,e.color.y*=e.startColor.y,e.color.z*=e.startColor.z,e.color.w*=e.startColor.w}frameUpdate(e){}toJSON(){return{type:this.type,color:this.color.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Ui(co(e.color),Sn.fromJSON(e.speedRange))}clone(){return new Ui(this.color.clone(),this.speedRange.clone())}reset(){}}class Di{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 xn?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 Di(Ir(e.size),Sn.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Di(this.size.clone(),this.speedRange.clone())}reset(){}}class Fi{constructor(e,t){this.angularVelocity=e,this.speedRange=t,this.type="RotationBySpeed",this.tempQuat=new ie}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){if(typeof e.rotation=="number"){const n=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);e.rotation+=t*this.angularVelocity.genValue(e.memory,n)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Fi(Z(e.angularVelocity),Sn.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Fi(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class Li{initialize(e){this.speed.startGen(e.memory)}constructor(e,t){this.speed=e,this.dampen=t,this.type="LimitSpeedOverLife"}update(e,t){let n=e.velocity.length(),i=this.speed.genValue(e.memory,e.age/e.life);if(n>i){const s=(n-i)/n;e.velocity.multiplyScalar(1-s*this.dampen*t*20)}}toJSON(){return{type:this.type,speed:this.speed.toJSON(),dampen:this.dampen}}static fromJSON(e){return new Li(Z(e.speed),e.dampen)}frameUpdate(e){}clone(){return new Li(this.speed.clone(),this.dampen)}reset(){}}const Nr={ApplyForce:{type:"ApplyForce",constructor:Ai,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Ai.fromJSON},Noise:{type:"Noise",constructor:Ni,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Ni.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Bi,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Bi.fromJSON},GravityForce:{type:"GravityForce",constructor:Oi,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:Oi.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:bi,params:[["color",["colorFunc"]]],loadJSON:bi.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Ti,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Ti.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Mi,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Mi.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:wi,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:wi.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:Ui,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:Ui.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Fi,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Fi.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:Di,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:Di.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Pi,params:[["speed",["value","valueFunc"]]],loadJSON:Pi.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:Ei,params:[["frame",["value","valueFunc"]]],loadJSON:Ei.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:Ci,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:Ci.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:ki,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:ki.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Ri,params:[["width",["value","valueFunc"]]],loadJSON:Ri.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:zi,params:[["angle",["value"]]],loadJSON:zi.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:Ii,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:Ii.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:Li,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:Li.fromJSON}};function Ru(r,e){return Nr[r.type]?Nr[r.type].loadJSON(r,e):null}const Au=[];function Ou(r){if(!Au.find(t=>t.id===r.id)){for(const t of r.emitterShapes)Fs[t.type]||(Fs[t.type]=t);for(const t of r.behaviors)Nr[t.type]||(Nr[t.type]=t)}}var zu=`
1
+ "use strict";const A=require("./three.umd.cjs"),Cl=/^(?:[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 wl(r){return typeof r=="string"&&Cl.test(r)}const Fe=[];for(let r=0;r<256;++r)Fe.push((r+256).toString(16).slice(1));function Pl(r,e=0){return Fe[r[e+0]]+Fe[r[e+1]]+Fe[r[e+2]]+Fe[r[e+3]]+"-"+Fe[r[e+4]]+Fe[r[e+5]]+"-"+Fe[r[e+6]]+Fe[r[e+7]]+"-"+Fe[r[e+8]]+Fe[r[e+9]]+"-"+Fe[r[e+10]]+Fe[r[e+11]]+Fe[r[e+12]]+Fe[r[e+13]]+Fe[r[e+14]]+Fe[r[e+15]]}function El(r){if(!wl(r))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(r.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(r.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(r.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(r.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(r.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function kl(r){r=unescape(encodeURIComponent(r));const e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t));return e}const Rl="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Al="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function Ol(r,e,t){function n(i,s,a,o){var c;if(typeof i=="string"&&(i=kl(i)),typeof s=="string"&&(s=El(s)),((c=s)===null||c===void 0?void 0:c.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(s),l.set(i,s.length),l=t(l),l[6]=l[6]&15|e,l[8]=l[8]&63|128,a){o=o||0;for(let u=0;u<16;++u)a[o+u]=l[u];return a}return Pl(l)}try{n.name=r}catch{}return n.DNS=Rl,n.URL=Al,n}function zl(r,e,t,n){switch(r){case 0:return e&t^~e&n;case 1:return e^t^n;case 2:return e&t^e&n^t&n;case 3:return e^t^n}}function as(r,e){return r<<e|r>>>32-e}function Il(r){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof r=="string"){const a=unescape(encodeURIComponent(r));r=[];for(let o=0;o<a.length;++o)r.push(a.charCodeAt(o))}else Array.isArray(r)||(r=Array.prototype.slice.call(r));r.push(128);const n=r.length/4+2,i=Math.ceil(n/16),s=new Array(i);for(let a=0;a<i;++a){const o=new Uint32Array(16);for(let c=0;c<16;++c)o[c]=r[a*64+c*4]<<24|r[a*64+c*4+1]<<16|r[a*64+c*4+2]<<8|r[a*64+c*4+3];s[a]=o}s[i-1][14]=(r.length-1)*8/Math.pow(2,32),s[i-1][14]=Math.floor(s[i-1][14]),s[i-1][15]=(r.length-1)*8&4294967295;for(let a=0;a<i;++a){const o=new Uint32Array(80);for(let m=0;m<16;++m)o[m]=s[a][m];for(let m=16;m<80;++m)o[m]=as(o[m-3]^o[m-8]^o[m-14]^o[m-16],1);let c=t[0],l=t[1],u=t[2],f=t[3],p=t[4];for(let m=0;m<80;++m){const x=Math.floor(m/20),T=as(c,5)+zl(x,l,u,f)+p+e[x]+o[m]>>>0;p=f,f=u,u=as(l,30)>>>0,l=c,c=T}t[0]=t[0]+c>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+f>>>0,t[4]=t[4]+p>>>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 Bl=Ol("v5",80,Il);function Vr(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var cs={exports:{}},ls={exports:{}},Go;function Nl(){return Go||(Go=1,(function(){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e={rotl:function(t,n){return t<<n|t>>>32-n},rotr:function(t,n){return t<<32-n|t>>>n},endian:function(t){if(t.constructor==Number)return e.rotl(t,8)&16711935|e.rotl(t,24)&4278255360;for(var n=0;n<t.length;n++)t[n]=e.endian(t[n]);return t},randomBytes:function(t){for(var n=[];t>0;t--)n.push(Math.floor(Math.random()*256));return n},bytesToWords:function(t){for(var n=[],i=0,s=0;i<t.length;i++,s+=8)n[s>>>5]|=t[i]<<24-s%32;return n},wordsToBytes:function(t){for(var n=[],i=0;i<t.length*32;i+=8)n.push(t[i>>>5]>>>24-i%32&255);return n},bytesToHex:function(t){for(var n=[],i=0;i<t.length;i++)n.push((t[i]>>>4).toString(16)),n.push((t[i]&15).toString(16));return n.join("")},hexToBytes:function(t){for(var n=[],i=0;i<t.length;i+=2)n.push(parseInt(t.substr(i,2),16));return n},bytesToBase64:function(t){for(var n=[],i=0;i<t.length;i+=3)for(var s=t[i]<<16|t[i+1]<<8|t[i+2],a=0;a<4;a++)i*8+a*6<=t.length*8?n.push(r.charAt(s>>>6*(3-a)&63)):n.push("=");return n.join("")},base64ToBytes:function(t){t=t.replace(/[^A-Z0-9+\/]/ig,"");for(var n=[],i=0,s=0;i<t.length;s=++i%4)s!=0&&n.push((r.indexOf(t.charAt(i-1))&Math.pow(2,-2*s+8)-1)<<s*2|r.indexOf(t.charAt(i))>>>6-s*2);return n}};ls.exports=e})()),ls.exports}var us,Wo;function $o(){if(Wo)return us;Wo=1;var r={utf8:{stringToBytes:function(e){return r.bin.stringToBytes(unescape(encodeURIComponent(e)))},bytesToString:function(e){return decodeURIComponent(escape(r.bin.bytesToString(e)))}},bin:{stringToBytes:function(e){for(var t=[],n=0;n<e.length;n++)t.push(e.charCodeAt(n)&255);return t},bytesToString:function(e){for(var t=[],n=0;n<e.length;n++)t.push(String.fromCharCode(e[n]));return t.join("")}}};return us=r,us}var hs,Ho;function Ul(){if(Ho)return hs;Ho=1,hs=function(t){return t!=null&&(r(t)||e(t)||!!t._isBuffer)};function r(t){return!!t.constructor&&typeof t.constructor.isBuffer=="function"&&t.constructor.isBuffer(t)}function e(t){return typeof t.readFloatLE=="function"&&typeof t.slice=="function"&&r(t.slice(0,0))}return hs}var qo;function Dl(){return qo||(qo=1,(function(){var r=Nl(),e=$o().utf8,t=Ul(),n=$o().bin,i=function(s,a){s.constructor==String?a&&a.encoding==="binary"?s=n.stringToBytes(s):s=e.stringToBytes(s):t(s)?s=Array.prototype.slice.call(s,0):!Array.isArray(s)&&s.constructor!==Uint8Array&&(s=s.toString());for(var o=r.bytesToWords(s),c=s.length*8,l=1732584193,u=-271733879,f=-1732584194,p=271733878,m=0;m<o.length;m++)o[m]=(o[m]<<8|o[m]>>>24)&16711935|(o[m]<<24|o[m]>>>8)&4278255360;o[c>>>5]|=128<<c%32,o[(c+64>>>9<<4)+14]=c;for(var x=i._ff,T=i._gg,g=i._hh,v=i._ii,m=0;m<o.length;m+=16){var _=l,b=u,M=f,C=p;l=x(l,u,f,p,o[m+0],7,-680876936),p=x(p,l,u,f,o[m+1],12,-389564586),f=x(f,p,l,u,o[m+2],17,606105819),u=x(u,f,p,l,o[m+3],22,-1044525330),l=x(l,u,f,p,o[m+4],7,-176418897),p=x(p,l,u,f,o[m+5],12,1200080426),f=x(f,p,l,u,o[m+6],17,-1473231341),u=x(u,f,p,l,o[m+7],22,-45705983),l=x(l,u,f,p,o[m+8],7,1770035416),p=x(p,l,u,f,o[m+9],12,-1958414417),f=x(f,p,l,u,o[m+10],17,-42063),u=x(u,f,p,l,o[m+11],22,-1990404162),l=x(l,u,f,p,o[m+12],7,1804603682),p=x(p,l,u,f,o[m+13],12,-40341101),f=x(f,p,l,u,o[m+14],17,-1502002290),u=x(u,f,p,l,o[m+15],22,1236535329),l=T(l,u,f,p,o[m+1],5,-165796510),p=T(p,l,u,f,o[m+6],9,-1069501632),f=T(f,p,l,u,o[m+11],14,643717713),u=T(u,f,p,l,o[m+0],20,-373897302),l=T(l,u,f,p,o[m+5],5,-701558691),p=T(p,l,u,f,o[m+10],9,38016083),f=T(f,p,l,u,o[m+15],14,-660478335),u=T(u,f,p,l,o[m+4],20,-405537848),l=T(l,u,f,p,o[m+9],5,568446438),p=T(p,l,u,f,o[m+14],9,-1019803690),f=T(f,p,l,u,o[m+3],14,-187363961),u=T(u,f,p,l,o[m+8],20,1163531501),l=T(l,u,f,p,o[m+13],5,-1444681467),p=T(p,l,u,f,o[m+2],9,-51403784),f=T(f,p,l,u,o[m+7],14,1735328473),u=T(u,f,p,l,o[m+12],20,-1926607734),l=g(l,u,f,p,o[m+5],4,-378558),p=g(p,l,u,f,o[m+8],11,-2022574463),f=g(f,p,l,u,o[m+11],16,1839030562),u=g(u,f,p,l,o[m+14],23,-35309556),l=g(l,u,f,p,o[m+1],4,-1530992060),p=g(p,l,u,f,o[m+4],11,1272893353),f=g(f,p,l,u,o[m+7],16,-155497632),u=g(u,f,p,l,o[m+10],23,-1094730640),l=g(l,u,f,p,o[m+13],4,681279174),p=g(p,l,u,f,o[m+0],11,-358537222),f=g(f,p,l,u,o[m+3],16,-722521979),u=g(u,f,p,l,o[m+6],23,76029189),l=g(l,u,f,p,o[m+9],4,-640364487),p=g(p,l,u,f,o[m+12],11,-421815835),f=g(f,p,l,u,o[m+15],16,530742520),u=g(u,f,p,l,o[m+2],23,-995338651),l=v(l,u,f,p,o[m+0],6,-198630844),p=v(p,l,u,f,o[m+7],10,1126891415),f=v(f,p,l,u,o[m+14],15,-1416354905),u=v(u,f,p,l,o[m+5],21,-57434055),l=v(l,u,f,p,o[m+12],6,1700485571),p=v(p,l,u,f,o[m+3],10,-1894986606),f=v(f,p,l,u,o[m+10],15,-1051523),u=v(u,f,p,l,o[m+1],21,-2054922799),l=v(l,u,f,p,o[m+8],6,1873313359),p=v(p,l,u,f,o[m+15],10,-30611744),f=v(f,p,l,u,o[m+6],15,-1560198380),u=v(u,f,p,l,o[m+13],21,1309151649),l=v(l,u,f,p,o[m+4],6,-145523070),p=v(p,l,u,f,o[m+11],10,-1120210379),f=v(f,p,l,u,o[m+2],15,718787259),u=v(u,f,p,l,o[m+9],21,-343485551),l=l+_>>>0,u=u+b>>>0,f=f+M>>>0,p=p+C>>>0}return r.endian([l,u,f,p])};i._ff=function(s,a,o,c,l,u,f){var p=s+(a&o|~a&c)+(l>>>0)+f;return(p<<u|p>>>32-u)+a},i._gg=function(s,a,o,c,l,u,f){var p=s+(a&c|o&~c)+(l>>>0)+f;return(p<<u|p>>>32-u)+a},i._hh=function(s,a,o,c,l,u,f){var p=s+(a^o^c)+(l>>>0)+f;return(p<<u|p>>>32-u)+a},i._ii=function(s,a,o,c,l,u,f){var p=s+(o^(a|~c))+(l>>>0)+f;return(p<<u|p>>>32-u)+a},i._blocksize=16,i._digestsize=16,cs.exports=function(s,a){if(s==null)throw new Error("Illegal argument "+s);var o=r.wordsToBytes(i(s,a));return a&&a.asBytes?o:a&&a.asString?n.bytesToString(o):r.bytesToHex(o)}})()),cs.exports}var Fl=Dl();const Qa=Vr(Fl),Ll=Object.freeze(Object.defineProperty({__proto__:null,default:Qa},Symbol.toStringTag,{value:"Module"})),fs=2,zt=4,Wt=4,ec=4,Qt=new Int32Array(2),Xo=new Float32Array(Qt.buffer),Yo=new Float64Array(Qt.buffer),Ki=new Uint16Array(new Uint8Array([1,0]).buffer)[0]===1;class Ht{constructor(e,t){this.low=e|0,this.high=t|0}static create(e,t){return e==0&&t==0?Ht.ZERO:new Ht(e,t)}toFloat64(){return(this.low>>>0)+this.high*4294967296}equals(e){return this.low==e.low&&this.high==e.high}}Ht.ZERO=new Ht(0,0);var Ds;(function(r){r[r.UTF8_BYTES=1]="UTF8_BYTES",r[r.UTF16_STRING=2]="UTF16_STRING"})(Ds||(Ds={}));class li{constructor(e){this.bytes_=e,this.position_=0}static allocate(e){return new li(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 Ht(this.readInt32(e),this.readInt32(e+4))}readUint64(e){return new Ht(this.readUint32(e),this.readUint32(e+4))}readFloat32(e){return Qt[0]=this.readInt32(e),Xo[0]}readFloat64(e){return Qt[Ki?0:1]=this.readInt32(e),Qt[Ki?1:0]=this.readInt32(e+4),Yo[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){Xo[0]=t,this.writeInt32(e,Qt[0])}writeFloat64(e,t){Yo[0]=t,this.writeInt32(e,Qt[Ki?0:1]),this.writeInt32(e+4,Qt[Ki?1:0])}getBufferIdentifier(){if(this.bytes_.length<this.position_+zt+Wt)throw new Error("FlatBuffers: ByteBuffer is too short to contain an identifier.");let e="";for(let t=0;t<Wt;t++)e+=String.fromCharCode(this.readInt8(this.position_+zt+t));return e}__offset(e,t){const n=e-this.readInt32(e);return t<this.readInt16(n)?this.readInt16(n+t):0}__union(e,t){return e.bb_pos=t+this.readInt32(t),e.bb=this,e}__string(e,t){e+=this.readInt32(e);const n=this.readInt32(e);let i="",s=0;if(e+=zt,t===Ds.UTF8_BYTES)return this.bytes_.subarray(e,e+n);for(;s<n;){let a;const o=this.readUint8(e+s++);if(o<192)a=o;else{const c=this.readUint8(e+s++);if(o<224)a=(o&31)<<6|c&63;else{const l=this.readUint8(e+s++);if(o<240)a=(o&15)<<12|(c&63)<<6|l&63;else{const u=this.readUint8(e+s++);a=(o&7)<<18|(c&63)<<12|(l&63)<<6|u&63}}}a<65536?i+=String.fromCharCode(a):(a-=65536,i+=String.fromCharCode((a>>10)+55296,(a&1023)+56320))}return i}__union_with_string(e,t){return typeof e=="string"?this.__string(t):this.__union(e,t)}__indirect(e){return e+this.readInt32(e)}__vector(e){return e+this.readInt32(e)+zt}__vector_len(e){return this.readInt32(e+this.readInt32(e))}__has_identifier(e){if(e.length!=Wt)throw new Error("FlatBuffers: file identifier must be length "+Wt);for(let t=0;t<Wt;t++)if(e.charCodeAt(t)!=this.readInt8(this.position()+zt+t))return!1;return!0}createLong(e,t){return Ht.create(e,t)}createScalarList(e,t){const n=[];for(let i=0;i<t;++i)e(i)!==null&&n.push(e(i));return n}createObjList(e,t){const n=[];for(let i=0;i<t;++i){const s=e(i);s!==null&&n.push(s.unpack())}return n}}class ao{constructor(e){this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null;let t;e?t=e:t=1024,this.bb=li.allocate(t),this.space=t}clear(){this.bb.clear(),this.space=this.bb.capacity(),this.minalign=1,this.vtable=null,this.vtable_in_use=0,this.isNested=!1,this.object_start=0,this.vtables=[],this.vector_num_elems=0,this.force_defaults=!1,this.string_maps=null}forceDefaults(e){this.force_defaults=e}dataBuffer(){return this.bb}asUint8Array(){return this.bb.bytes().subarray(this.bb.position(),this.bb.position()+this.offset())}prep(e,t){e>this.minalign&&(this.minalign=e);const n=~(this.bb.capacity()-this.space+t)+1&e-1;for(;this.space<n+e+t;){const i=this.bb.capacity();this.bb=ao.growByteBuffer(this.bb),this.space+=this.bb.capacity()-i}this.pad(n)}pad(e){for(let t=0;t<e;t++)this.bb.writeInt8(--this.space,0)}writeInt8(e){this.bb.writeInt8(this.space-=1,e)}writeInt16(e){this.bb.writeInt16(this.space-=2,e)}writeInt32(e){this.bb.writeInt32(this.space-=4,e)}writeInt64(e){this.bb.writeInt64(this.space-=8,e)}writeFloat32(e){this.bb.writeFloat32(this.space-=4,e)}writeFloat64(e){this.bb.writeFloat64(this.space-=8,e)}addInt8(e){this.prep(1,0),this.writeInt8(e)}addInt16(e){this.prep(2,0),this.writeInt16(e)}addInt32(e){this.prep(4,0),this.writeInt32(e)}addInt64(e){this.prep(8,0),this.writeInt64(e)}addFloat32(e){this.prep(4,0),this.writeFloat32(e)}addFloat64(e){this.prep(8,0),this.writeFloat64(e)}addFieldInt8(e,t,n){(this.force_defaults||t!=n)&&(this.addInt8(t),this.slot(e))}addFieldInt16(e,t,n){(this.force_defaults||t!=n)&&(this.addInt16(t),this.slot(e))}addFieldInt32(e,t,n){(this.force_defaults||t!=n)&&(this.addInt32(t),this.slot(e))}addFieldInt64(e,t,n){(this.force_defaults||!t.equals(n))&&(this.addInt64(t),this.slot(e))}addFieldFloat32(e,t,n){(this.force_defaults||t!=n)&&(this.addFloat32(t),this.slot(e))}addFieldFloat64(e,t,n){(this.force_defaults||t!=n)&&(this.addFloat64(t),this.slot(e))}addFieldOffset(e,t,n){(this.force_defaults||t!=n)&&(this.addOffset(t),this.slot(e))}addFieldStruct(e,t,n){t!=n&&(this.nested(t),this.slot(e))}nested(e){if(e!=this.offset())throw new Error("FlatBuffers: struct must be serialized inline.")}notNested(){if(this.isNested)throw new Error("FlatBuffers: object serialization must not be nested.")}slot(e){this.vtable!==null&&(this.vtable[e]=this.offset())}offset(){return this.bb.capacity()-this.space}static growByteBuffer(e){const t=e.capacity();if(t&3221225472)throw new Error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.");const n=t<<1,i=li.allocate(n);return i.setPosition(n-t),i.bytes().set(e.bytes(),n-t),i}addOffset(e){this.prep(zt,0),this.writeInt32(this.offset()-e+zt)}startObject(e){this.notNested(),this.vtable==null&&(this.vtable=[]),this.vtable_in_use=e;for(let t=0;t<e;t++)this.vtable[t]=0;this.isNested=!0,this.object_start=this.offset()}endObject(){if(this.vtable==null||!this.isNested)throw new Error("FlatBuffers: endObject called without startObject");this.addInt32(0);const e=this.offset();let t=this.vtable_in_use-1;for(;t>=0&&this.vtable[t]==0;t--);const n=t+1;for(;t>=0;t--)this.addInt16(this.vtable[t]!=0?e-this.vtable[t]:0);const i=2;this.addInt16(e-this.object_start);const s=(n+i)*fs;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=fs;l<s;l+=fs)if(this.bb.readInt16(o+l)!=this.bb.readInt16(c+l))continue e;a=this.vtables[t];break}}return a?(this.space=this.bb.capacity()-e,this.bb.writeInt32(this.space,a-e)):(this.vtables.push(this.offset()),this.bb.writeInt32(this.bb.capacity()-e,this.offset()-e)),this.isNested=!1,e}finish(e,t,n){const i=n?ec:0;if(t){const s=t;if(this.prep(this.minalign,zt+Wt+i),s.length!=Wt)throw new Error("FlatBuffers: file identifier must be length "+Wt);for(let a=Wt-1;a>=0;a--)this.writeInt8(s.charCodeAt(a))}this.prep(this.minalign,zt+i),this.addOffset(e),i&&this.addInt32(this.bb.capacity()-this.space),this.bb.setPosition(this.space)}finishSizePrefixed(e,t){this.finish(e,t,!0)}requiredField(e,t){const n=this.bb.capacity()-e,i=n-this.bb.readInt32(n);if(!(this.bb.readInt16(i+t)!=0))throw new Error("FlatBuffers: field "+t+" must be set")}startVector(e,t,n){this.notNested(),this.vector_num_elems=t,this.prep(zt,e*t),this.prep(n,e*t)}endVector(){return this.writeInt32(this.vector_num_elems),this.offset()}createSharedString(e){if(!e)return 0;if(this.string_maps||(this.string_maps=new Map),this.string_maps.has(e))return this.string_maps.get(e);const t=this.createString(e);return this.string_maps.set(e,t),t}createString(e){if(!e)return 0;let t;if(e instanceof Uint8Array)t=e;else{t=[];let n=0;for(;n<e.length;){let i;const s=e.charCodeAt(n++);if(s<55296||s>=56320)i=s;else{const a=e.charCodeAt(n++);i=(s<<10)+a+-56613888}i<128?t.push(i):(i<2048?t.push(i>>6&31|192):(i<65536?t.push(i>>12&15|224):t.push(i>>18&7|240,i>>12&63|128),t.push(i>>6&63|128)),t.push(i&63|128))}}this.addInt8(0),this.startVector(1,t.length,1),this.bb.setPosition(this.space-=t.length);for(let n=0,i=this.space,s=this.bb.bytes();n<t.length;n++)s[i++]=t[n];return this.endVector()}createLong(e,t){return Ht.create(e,t)}createObjectOffset(e){return e===null?0:typeof e=="string"?this.createString(e):e.pack(this)}createObjectOffsetList(e){const t=[];for(let n=0;n<e.length;++n){const i=e[n];if(i!==null)t.push(this.createObjectOffset(i));else throw new Error("FlatBuffers: Argument for createObjectOffsetList cannot contain null.")}return t}createStructOffsetList(e,t){return t(this,e.length),this.createObjectOffsetList(e),this.endVector()}}const ze={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 tc(r){const e=await fetch(r);if(e.ok)return e.json();throw new Error(e.statusText)}async function Vl(r){return await tc(`${r}/profilesList.json`)}async function Jl(r,e,t=null,n=!0){if(!r)throw new Error("No xrInputSource supplied");const i=await Vl(e);let s;if(r.profiles.some(c=>{const l=i[c];return l&&(s={profileId:c,profilePath:`${e}/${l.path}`,deprecated:!!l.deprecated}),!!s}),!s){if(!t)throw new Error("No matching profile name found");const c=i[t];if(!c)throw new Error(`No matching profile name found and default profile "${t}" missing.`);s={profileId:t,profilePath:`${e}/${c.path}`,deprecated:!!c.deprecated}}const a=await tc(s.profilePath);let o;if(n){let c;if(r.handedness==="any"?c=a.layouts[Object.keys(a.layouts)[0]]:c=a.layouts[r.handedness],!c)throw new Error(`No matching handedness, ${r.handedness}, in profile ${s.profileId}`);c.assetPath&&(o=s.profilePath.replace("profile.json",c.assetPath))}return{profile:a,assetPath:o}}const jl={xAxis:0,yAxis:0,button:0,state:ze.ComponentState.DEFAULT};function Gl(r=0,e=0){let t=r,n=e;if(Math.sqrt(r*r+e*e)>1){const a=Math.atan2(e,r);t=Math.cos(a),n=Math.sin(a)}return{normalizedXAxis:t*.5+.5,normalizedYAxis:n*.5+.5}}class Wl{constructor(e){this.componentProperty=e.componentProperty,this.states=e.states,this.valueNodeName=e.valueNodeName,this.valueNodeProperty=e.valueNodeProperty,this.valueNodeProperty===ze.VisualResponseProperty.TRANSFORM&&(this.minNodeName=e.minNodeName,this.maxNodeName=e.maxNodeName),this.value=0,this.updateFromComponent(jl)}updateFromComponent({xAxis:e,yAxis:t,button:n,state:i}){const{normalizedXAxis:s,normalizedYAxis:a}=Gl(e,t);switch(this.componentProperty){case ze.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?s:.5;break;case ze.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?a:.5;break;case ze.ComponentProperty.BUTTON:this.value=this.states.includes(i)?n:0;break;case ze.ComponentProperty.STATE:this.valueNodeProperty===ze.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(i):this.value=this.states.includes(i)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}}class $l{constructor(e,t){if(!e||!t||!t.visualResponses||!t.gamepadIndices||Object.keys(t.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=e,this.type=t.type,this.rootNodeName=t.rootNodeName,this.touchPointNodeName=t.touchPointNodeName,this.visualResponses={},Object.keys(t.visualResponses).forEach(n=>{const i=new Wl(t.visualResponses[n]);this.visualResponses[n]=i}),this.gamepadIndices=Object.assign({},t.gamepadIndices),this.values={state:ze.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=ze.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=ze.ComponentState.PRESSED:(t.touched||this.values.button>ze.ButtonTouchThreshold)&&(this.values.state=ze.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===ze.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>ze.AxisTouchThreshold&&(this.values.state=ze.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===ze.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>ze.AxisTouchThreshold&&(this.values.state=ze.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(t=>{t.updateFromComponent(this.values)})}}class Hl{constructor(e,t,n){if(!e)throw new Error("No xrInputSource supplied");if(!t)throw new Error("No profile supplied");this.xrInputSource=e,this.assetUrl=n,this.id=t.profileId,this.layoutDescription=t.layouts[e.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(i=>{const s=this.layoutDescription.components[i];this.components[i]=new $l(i,s)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const e=[];return Object.values(this.components).forEach(t=>{e.push(t.data)}),e}updateFromGamepad(){Object.values(this.components).forEach(e=>{e.updateFromGamepad(this.xrInputSource.gamepad)})}}const Ge=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let Zo=1234567;const nc=Math.PI/180,ic=180/Math.PI;function ql(){const r=Math.random()*4294967295|0,e=Math.random()*4294967295|0,t=Math.random()*4294967295|0,n=Math.random()*4294967295|0;return(Ge[r&255]+Ge[r>>8&255]+Ge[r>>16&255]+Ge[r>>24&255]+"-"+Ge[e&255]+Ge[e>>8&255]+"-"+Ge[e>>16&15|64]+Ge[e>>24&255]+"-"+Ge[t&63|128]+Ge[t>>8&255]+"-"+Ge[t>>16&255]+Ge[t>>24&255]+Ge[n&255]+Ge[n>>8&255]+Ge[n>>16&255]+Ge[n>>24&255]).toLowerCase()}function Ot(r,e,t){return Math.max(e,Math.min(t,r))}function rc(r,e){return(r%e+e)%e}function Xl(r,e,t,n,i){return n+(r-e)*(i-n)/(t-e)}function Yl(r,e,t){return r!==e?(t-r)/(e-r):0}function sc(r,e,t){return(1-t)*r+t*e}function Zl(r,e,t,n){return sc(r,e,1-Math.exp(-t*n))}function Kl(r,e=1){return e-Math.abs(rc(r,e*2)-e)}function Ql(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*(3-2*r))}function eu(r,e,t){return r<=e?0:r>=t?1:(r=(r-e)/(t-e),r*r*r*(r*(r*6-15)+10))}function tu(r,e){return r+Math.floor(Math.random()*(e-r+1))}function nu(r,e){return r+Math.random()*(e-r)}function iu(r){return r*(.5-Math.random())}function ru(r){r!==void 0&&(Zo=r);let e=Zo+=1831565813;return e=Math.imul(e^e>>>15,e|1),e^=e+Math.imul(e^e>>>7,e|61),((e^e>>>14)>>>0)/4294967296}function su(r){return r*nc}function ou(r){return r*ic}function au(r){return(r&r-1)===0&&r!==0}function cu(r){return Math.pow(2,Math.ceil(Math.log(r)/Math.LN2))}function lu(r){return Math.pow(2,Math.floor(Math.log(r)/Math.LN2))}function uu(r,e,t,n,i){const s=Math.cos,a=Math.sin,o=s(t/2),c=a(t/2),l=s((e+n)/2),u=a((e+n)/2),f=s((e-n)/2),p=a((e-n)/2),m=s((n-e)/2),x=a((n-e)/2);switch(i){case"XYX":r.set(o*u,c*f,c*p,o*l);break;case"YZY":r.set(c*p,o*u,c*f,o*l);break;case"ZXZ":r.set(c*f,c*p,o*u,o*l);break;case"XZX":r.set(o*u,c*x,c*m,o*l);break;case"YXY":r.set(c*m,o*u,c*x,o*l);break;case"ZYZ":r.set(c*x,c*m,o*u,o*l);break;default:console.warn("../math.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+i)}}function hu(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return r/4294967295;case Uint16Array:return r/65535;case Uint8Array:return r/255;case Int32Array:return Math.max(r/2147483647,-1);case Int16Array:return Math.max(r/32767,-1);case Int8Array:return Math.max(r/127,-1);default:throw new Error("Invalid component type.")}}function fu(r,e){switch(e.constructor){case Float32Array:return r;case Uint32Array:return Math.round(r*4294967295);case Uint16Array:return Math.round(r*65535);case Uint8Array:return Math.round(r*255);case Int32Array:return Math.round(r*2147483647);case Int16Array:return Math.round(r*32767);case Int8Array:return Math.round(r*127);default:throw new Error("Invalid component type.")}}const Jn={DEG2RAD:nc,RAD2DEG:ic,generateUUID:ql,clamp:Ot,euclideanModulo:rc,mapLinear:Xl,inverseLerp:Yl,lerp:sc,damp:Zl,pingpong:Kl,smoothstep:Ql,smootherstep:eu,randInt:tu,randFloat:nu,randFloatSpread:iu,seededRandom:ru,degToRad:su,radToDeg:ou,isPowerOfTwo:au,ceilPowerOfTwo:cu,floorPowerOfTwo:lu,setQuaternionFromProperEuler:uu,normalize:fu,denormalize:hu};class ie{constructor(e=0,t=0,n=0,i=1){this.isQuaternion=!0,this._x=e,this._y=t,this._z=n,this._w=i}static slerpFlat(e,t,n,i,s,a,o){let c=n[i+0],l=n[i+1],u=n[i+2],f=n[i+3];const p=s[a+0],m=s[a+1],x=s[a+2],T=s[a+3];if(o===0){e[t+0]=c,e[t+1]=l,e[t+2]=u,e[t+3]=f;return}if(o===1){e[t+0]=p,e[t+1]=m,e[t+2]=x,e[t+3]=T;return}if(f!==T||c!==p||l!==m||u!==x){let g=1-o;const v=c*p+l*m+u*x+f*T,_=v>=0?1:-1,b=1-v*v;if(b>Number.EPSILON){const C=Math.sqrt(b),P=Math.atan2(C,v*_);g=Math.sin(g*P)/C,o=Math.sin(o*P)/C}const M=o*_;if(c=c*g+p*M,l=l*g+m*M,u=u*g+x*M,f=f*g+T*M,g===1-o){const C=1/Math.sqrt(c*c+l*l+u*u+f*f);c*=C,l*=C,u*=C,f*=C}}e[t]=c,e[t+1]=l,e[t+2]=u,e[t+3]=f}static multiplyQuaternionsFlat(e,t,n,i,s,a){const o=n[i],c=n[i+1],l=n[i+2],u=n[i+3],f=s[a],p=s[a+1],m=s[a+2],x=s[a+3];return e[t]=o*x+u*f+c*m-l*p,e[t+1]=c*x+u*p+l*f-o*m,e[t+2]=l*x+u*m+o*p-c*f,e[t+3]=u*x-o*f-c*p-l*m,e}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get w(){return this._w}set w(e){this._w=e,this._onChangeCallback()}set(e,t,n,i){return this._x=e,this._y=t,this._z=n,this._w=i,this._onChangeCallback(),this}clone(){return new ie(this._x,this._y,this._z,this._w)}copy(e){return this._x=e.x,this._y=e.y,this._z=e.z,this._w=e.w,this._onChangeCallback(),this}setFromEuler(e,t=!0){const n=e._x,i=e._y,s=e._z,a=e._order,o=Math.cos,c=Math.sin,l=o(n/2),u=o(i/2),f=o(s/2),p=c(n/2),m=c(i/2),x=c(s/2);switch(a){case"XYZ":this._x=p*u*f+l*m*x,this._y=l*m*f-p*u*x,this._z=l*u*x+p*m*f,this._w=l*u*f-p*m*x;break;case"YXZ":this._x=p*u*f+l*m*x,this._y=l*m*f-p*u*x,this._z=l*u*x-p*m*f,this._w=l*u*f+p*m*x;break;case"ZXY":this._x=p*u*f-l*m*x,this._y=l*m*f+p*u*x,this._z=l*u*x+p*m*f,this._w=l*u*f-p*m*x;break;case"ZYX":this._x=p*u*f-l*m*x,this._y=l*m*f+p*u*x,this._z=l*u*x-p*m*f,this._w=l*u*f+p*m*x;break;case"YZX":this._x=p*u*f+l*m*x,this._y=l*m*f+p*u*x,this._z=l*u*x-p*m*f,this._w=l*u*f-p*m*x;break;case"XZY":this._x=p*u*f-l*m*x,this._y=l*m*f-p*u*x,this._z=l*u*x+p*m*f,this._w=l*u*f+p*m*x;break;default:console.warn("../math.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return t===!0&&this._onChangeCallback(),this}setFromAxisAngle(e,t){const n=t/2,i=Math.sin(n);return this._x=e.x*i,this._y=e.y*i,this._z=e.z*i,this._w=Math.cos(n),this._onChangeCallback(),this}setFromRotationMatrix(e){const t=e.elements,n=t[0],i=t[4],s=t[8],a=t[1],o=t[5],c=t[9],l=t[2],u=t[6],f=t[10],p=n+o+f;if(p>0){const m=.5/Math.sqrt(p+1);this._w=.25/m,this._x=(u-c)*m,this._y=(s-l)*m,this._z=(a-i)*m}else if(n>o&&n>f){const m=2*Math.sqrt(1+n-o-f);this._w=(u-c)/m,this._x=.25*m,this._y=(i+a)/m,this._z=(s+l)/m}else if(o>f){const m=2*Math.sqrt(1+o-n-f);this._w=(s-l)/m,this._x=(i+a)/m,this._y=.25*m,this._z=(c+u)/m}else{const m=2*Math.sqrt(1+f-n-o);this._w=(a-i)/m,this._x=(s+l)/m,this._y=(c+u)/m,this._z=.25*m}return this._onChangeCallback(),this}setFromUnitVectors(e,t){let n=e.dot(t)+1;return n<Number.EPSILON?(n=0,Math.abs(e.x)>Math.abs(e.z)?(this._x=-e.y,this._y=e.x,this._z=0,this._w=n):(this._x=0,this._y=-e.z,this._z=e.y,this._w=n)):(this._x=e.y*t.z-e.z*t.y,this._y=e.z*t.x-e.x*t.z,this._z=e.x*t.y-e.y*t.x,this._w=n),this.normalize()}angleTo(e){return 2*Math.acos(Math.abs(Ot(this.dot(e),-1,1)))}rotateTowards(e,t){const n=this.angleTo(e);if(n===0)return this;const i=Math.min(1,t/n);return this.slerp(e,i),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(e){return this._x*e._x+this._y*e._y+this._z*e._z+this._w*e._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let e=this.length();return e===0?(this._x=0,this._y=0,this._z=0,this._w=1):(e=1/e,this._x=this._x*e,this._y=this._y*e,this._z=this._z*e,this._w=this._w*e),this._onChangeCallback(),this}multiply(e){return this.multiplyQuaternions(this,e)}premultiply(e){return this.multiplyQuaternions(e,this)}multiplyQuaternions(e,t){const n=e._x,i=e._y,s=e._z,a=e._w,o=t._x,c=t._y,l=t._z,u=t._w;return this._x=n*u+a*o+i*l-s*c,this._y=i*u+a*c+s*o-n*l,this._z=s*u+a*l+n*c-i*o,this._w=a*u-n*o-i*c-s*l,this._onChangeCallback(),this}slerp(e,t){if(t===0)return this;if(t===1)return this.copy(e);const n=this._x,i=this._y,s=this._z,a=this._w;let o=a*e._w+n*e._x+i*e._y+s*e._z;if(o<0?(this._w=-e._w,this._x=-e._x,this._y=-e._y,this._z=-e._z,o=-o):this.copy(e),o>=1)return this._w=a,this._x=n,this._y=i,this._z=s,this;const c=1-o*o;if(c<=Number.EPSILON){const m=1-t;return this._w=m*a+t*this._w,this._x=m*n+t*this._x,this._y=m*i+t*this._y,this._z=m*s+t*this._z,this.normalize(),this}const l=Math.sqrt(c),u=Math.atan2(l,o),f=Math.sin((1-t)*u)/l,p=Math.sin(t*u)/l;return this._w=a*f+this._w*p,this._x=n*f+this._x*p,this._y=i*f+this._y*p,this._z=s*f+this._z*p,this._onChangeCallback(),this}slerpQuaternions(e,t,n){return this.copy(e).slerp(t,n)}random(){const e=2*Math.PI*Math.random(),t=2*Math.PI*Math.random(),n=Math.random(),i=Math.sqrt(1-n),s=Math.sqrt(n);return this.set(i*Math.sin(e),i*Math.cos(e),s*Math.sin(t),s*Math.cos(t))}equals(e){return e._x===this._x&&e._y===this._y&&e._z===this._z&&e._w===this._w}fromArray(e,t=0){return this._x=e[t],this._y=e[t+1],this._z=e[t+2],this._w=e[t+3],this._onChangeCallback(),this}toArray(e=[],t=0){return e[t]=this._x,e[t+1]=this._y,e[t+2]=this._z,e[t+3]=this._w,e}toJSON(){return this.toArray()}_onChange(e){return this._onChangeCallback=e,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class G{constructor(e=0,t=0,n=0){this.isVector3=!0,G.prototype.isVector3=!0,this.x=e,this.y=t,this.z=n}set(e,t,n){return n===void 0&&(n=this.z),this.x=e,this.y=t,this.z=n,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+e)}}clone(){return new G(this.x,this.y,this.z)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this}multiplyVectors(e,t){return this.x=e.x*t.x,this.y=e.y*t.y,this.z=e.z*t.z,this}applyEuler(e){return this.applyQuaternion(Ko.setFromEuler(e))}applyAxisAngle(e,t){return this.applyQuaternion(Ko.setFromAxisAngle(e,t))}applyMatrix3(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[3]*n+s[6]*i,this.y=s[1]*t+s[4]*n+s[7]*i,this.z=s[2]*t+s[5]*n+s[8]*i,this}applyNormalMatrix(e){return this.applyMatrix3(e).normalize()}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=e.elements,a=1/(s[3]*t+s[7]*n+s[11]*i+s[15]);return this.x=(s[0]*t+s[4]*n+s[8]*i+s[12])*a,this.y=(s[1]*t+s[5]*n+s[9]*i+s[13])*a,this.z=(s[2]*t+s[6]*n+s[10]*i+s[14])*a,this}applyQuaternion(e){const t=this.x,n=this.y,i=this.z,s=e.x,a=e.y,o=e.z,c=e.w,l=2*(a*i-o*n),u=2*(o*t-s*i),f=2*(s*n-a*t);return this.x=t+c*l+a*f-o*u,this.y=n+c*u+o*l-s*f,this.z=i+c*f+s*u-a*l,this}transformDirection(e){const t=this.x,n=this.y,i=this.z,s=e.elements;return this.x=s[0]*t+s[4]*n+s[8]*i,this.y=s[1]*t+s[5]*n+s[9]*i,this.z=s[2]*t+s[6]*n+s[10]*i,this.normalize()}divide(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}divideScalar(e){return this.multiplyScalar(1/e)}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this}cross(e){return this.crossVectors(this,e)}crossVectors(e,t){const n=e.x,i=e.y,s=e.z,a=t.x,o=t.y,c=t.z;return this.x=i*c-s*o,this.y=s*a-n*c,this.z=n*o-i*a,this}projectOnVector(e){const t=e.lengthSq();if(t===0)return this.set(0,0,0);const n=e.dot(this)/t;return this.copy(e).multiplyScalar(n)}projectOnPlane(e){return ds.copy(this).projectOnVector(e),this.sub(ds)}reflect(e){return this.sub(ds.copy(e).multiplyScalar(2*this.dot(e)))}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(Ot(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y,i=this.z-e.z;return t*t+n*n+i*i}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)+Math.abs(this.z-e.z)}setFromSphericalCoords(e,t,n){const i=Math.sin(t)*e;return this.x=i*Math.sin(n),this.y=Math.cos(t)*e,this.z=i*Math.cos(n),this}setFromCylindricalCoords(e,t,n){return this.x=e*Math.sin(t),this.y=n,this.z=e*Math.cos(t),this}setFromMatrixPosition(e){const t=e.elements;return this.x=t[12],this.y=t[13],this.z=t[14],this}setFromMatrixScale(e){const t=this.setFromMatrixColumn(e,0).length(),n=this.setFromMatrixColumn(e,1).length(),i=this.setFromMatrixColumn(e,2).length();return this.x=t,this.y=n,this.z=i,this}setFromMatrixColumn(e,t){return this.fromArray(e.elements,t*4)}setFromMatrix3Column(e,t){return this.fromArray(e.elements,t*3)}setFromEuler(e){return this.x=e._x,this.y=e._y,this.z=e._z,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const e=Math.random()*Math.PI*2,t=Math.random()*2-1,n=Math.sqrt(1-t*t);return this.x=n*Math.cos(e),this.y=t,this.z=n*Math.sin(e),this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this.z=Math.abs(this.z),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const ds=new G,Ko=new ie,Qi=2e3,Qo=2001;class Et{constructor(e,t,n,i,s,a,o,c,l,u,f,p,m,x,T,g){this.isMatrix4=!0,Et.prototype.isMatrix4=!0,this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,a,o,c,l,u,f,p,m,x,T,g)}extractPosition(e){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(e)}multiplyToArray(e,t,n){return console.error("THREE.Matrix4: .multiplyToArray() has been removed."),this}setRotationFromQuaternion(e){return this.makeRotationFromQuaternion(e)}set(e,t,n,i,s,a,o,c,l,u,f,p,m,x,T,g){const v=this.elements;return v[0]=e,v[4]=t,v[8]=n,v[12]=i,v[1]=s,v[5]=a,v[9]=o,v[13]=c,v[2]=l,v[6]=u,v[10]=f,v[14]=p,v[3]=m,v[7]=x,v[11]=T,v[15]=g,this}identity(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}clone(){return new Et().fromArray(this.elements)}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],t[9]=n[9],t[10]=n[10],t[11]=n[11],t[12]=n[12],t[13]=n[13],t[14]=n[14],t[15]=n[15],this}copyPosition(e){const t=this.elements,n=e.elements;return t[12]=n[12],t[13]=n[13],t[14]=n[14],this}setFromMatrix3(e){const t=e.elements;return this.set(t[0],t[3],t[6],0,t[1],t[4],t[7],0,t[2],t[5],t[8],0,0,0,0,1),this}extractBasis(e,t,n){return e.setFromMatrixColumn(this,0),t.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}makeBasis(e,t,n){return this.set(e.x,t.x,n.x,0,e.y,t.y,n.y,0,e.z,t.z,n.z,0,0,0,0,1),this}extractRotation(e){const t=this.elements,n=e.elements,i=1/wn.setFromMatrixColumn(e,0).length(),s=1/wn.setFromMatrixColumn(e,1).length(),a=1/wn.setFromMatrixColumn(e,2).length();return t[0]=n[0]*i,t[1]=n[1]*i,t[2]=n[2]*i,t[3]=0,t[4]=n[4]*s,t[5]=n[5]*s,t[6]=n[6]*s,t[7]=0,t[8]=n[8]*a,t[9]=n[9]*a,t[10]=n[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,this}makeRotationFromEuler(e){const t=this.elements,n=e.x,i=e.y,s=e.z,a=Math.cos(n),o=Math.sin(n),c=Math.cos(i),l=Math.sin(i),u=Math.cos(s),f=Math.sin(s);if(e.order==="XYZ"){const p=a*u,m=a*f,x=o*u,T=o*f;t[0]=c*u,t[4]=-c*f,t[8]=l,t[1]=m+x*l,t[5]=p-T*l,t[9]=-o*c,t[2]=T-p*l,t[6]=x+m*l,t[10]=a*c}else if(e.order==="YXZ"){const p=c*u,m=c*f,x=l*u,T=l*f;t[0]=p+T*o,t[4]=x*o-m,t[8]=a*l,t[1]=a*f,t[5]=a*u,t[9]=-o,t[2]=m*o-x,t[6]=T+p*o,t[10]=a*c}else if(e.order==="ZXY"){const p=c*u,m=c*f,x=l*u,T=l*f;t[0]=p-T*o,t[4]=-a*f,t[8]=x+m*o,t[1]=m+x*o,t[5]=a*u,t[9]=T-p*o,t[2]=-a*l,t[6]=o,t[10]=a*c}else if(e.order==="ZYX"){const p=a*u,m=a*f,x=o*u,T=o*f;t[0]=c*u,t[4]=x*l-m,t[8]=p*l+T,t[1]=c*f,t[5]=T*l+p,t[9]=m*l-x,t[2]=-l,t[6]=o*c,t[10]=a*c}else if(e.order==="YZX"){const p=a*c,m=a*l,x=o*c,T=o*l;t[0]=c*u,t[4]=T-p*f,t[8]=x*f+m,t[1]=f,t[5]=a*u,t[9]=-o*u,t[2]=-l*u,t[6]=m*f+x,t[10]=p-T*f}else if(e.order==="XZY"){const p=a*c,m=a*l,x=o*c,T=o*l;t[0]=c*u,t[4]=-f,t[8]=l*u,t[1]=p*f+T,t[5]=a*u,t[9]=m*f-x,t[2]=x*f-m,t[6]=o*u,t[10]=T*f+p}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(du,e,pu)}lookAt(e,t,n){const i=this.elements;return lt.subVectors(e,t),lt.lengthSq()===0&&(lt.z=1),lt.normalize(),Yt.crossVectors(n,lt),Yt.lengthSq()===0&&(Math.abs(n.z)===1?lt.x+=1e-4:lt.z+=1e-4,lt.normalize(),Yt.crossVectors(n,lt)),Yt.normalize(),er.crossVectors(lt,Yt),i[0]=Yt.x,i[4]=er.x,i[8]=lt.x,i[1]=Yt.y,i[5]=er.y,i[9]=lt.y,i[2]=Yt.z,i[6]=er.z,i[10]=lt.z,this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,a=n[0],o=n[4],c=n[8],l=n[12],u=n[1],f=n[5],p=n[9],m=n[13],x=n[2],T=n[6],g=n[10],v=n[14],_=n[3],b=n[7],M=n[11],C=n[15],P=i[0],E=i[4],z=i[8],I=i[12],R=i[1],N=i[5],O=i[9],U=i[13],L=i[2],J=i[6],$=i[10],K=i[14],W=i[3],me=i[7],ne=i[11],ue=i[15];return s[0]=a*P+o*R+c*L+l*W,s[4]=a*E+o*N+c*J+l*me,s[8]=a*z+o*O+c*$+l*ne,s[12]=a*I+o*U+c*K+l*ue,s[1]=u*P+f*R+p*L+m*W,s[5]=u*E+f*N+p*J+m*me,s[9]=u*z+f*O+p*$+m*ne,s[13]=u*I+f*U+p*K+m*ue,s[2]=x*P+T*R+g*L+v*W,s[6]=x*E+T*N+g*J+v*me,s[10]=x*z+T*O+g*$+v*ne,s[14]=x*I+T*U+g*K+v*ue,s[3]=_*P+b*R+M*L+C*W,s[7]=_*E+b*N+M*J+C*me,s[11]=_*z+b*O+M*$+C*ne,s[15]=_*I+b*U+M*K+C*ue,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[4]*=e,t[8]*=e,t[12]*=e,t[1]*=e,t[5]*=e,t[9]*=e,t[13]*=e,t[2]*=e,t[6]*=e,t[10]*=e,t[14]*=e,t[3]*=e,t[7]*=e,t[11]*=e,t[15]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[4],i=e[8],s=e[12],a=e[1],o=e[5],c=e[9],l=e[13],u=e[2],f=e[6],p=e[10],m=e[14],x=e[3],T=e[7],g=e[11],v=e[15];return x*(+s*c*f-i*l*f-s*o*p+n*l*p+i*o*m-n*c*m)+T*(+t*c*m-t*l*p+s*a*p-i*a*m+i*l*u-s*c*u)+g*(+t*l*f-t*o*m-s*a*f+n*a*m+s*o*u-n*l*u)+v*(-i*o*u-t*c*f+t*o*p+i*a*f-n*a*p+n*c*u)}transpose(){const e=this.elements;let t;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}setPosition(e,t,n){const i=this.elements;return e.isVector3?(i[12]=e.x,i[13]=e.y,i[14]=e.z):(i[12]=e,i[13]=t,i[14]=n),this}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],f=e[9],p=e[10],m=e[11],x=e[12],T=e[13],g=e[14],v=e[15],_=f*g*l-T*p*l+T*c*m-o*g*m-f*c*v+o*p*v,b=x*p*l-u*g*l-x*c*m+a*g*m+u*c*v-a*p*v,M=u*T*l-x*f*l+x*o*m-a*T*m-u*o*v+a*f*v,C=x*f*c-u*T*c-x*o*p+a*T*p+u*o*g-a*f*g,P=t*_+n*b+i*M+s*C;if(P===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);const E=1/P;return e[0]=_*E,e[1]=(T*p*s-f*g*s-T*i*m+n*g*m+f*i*v-n*p*v)*E,e[2]=(o*g*s-T*c*s+T*i*l-n*g*l-o*i*v+n*c*v)*E,e[3]=(f*c*s-o*p*s-f*i*l+n*p*l+o*i*m-n*c*m)*E,e[4]=b*E,e[5]=(u*g*s-x*p*s+x*i*m-t*g*m-u*i*v+t*p*v)*E,e[6]=(x*c*s-a*g*s-x*i*l+t*g*l+a*i*v-t*c*v)*E,e[7]=(a*p*s-u*c*s+u*i*l-t*p*l-a*i*m+t*c*m)*E,e[8]=M*E,e[9]=(x*f*s-u*T*s-x*n*m+t*T*m+u*n*v-t*f*v)*E,e[10]=(a*T*s-x*o*s+x*n*l-t*T*l-a*n*v+t*o*v)*E,e[11]=(u*o*s-a*f*s-u*n*l+t*f*l+a*n*m-t*o*m)*E,e[12]=C*E,e[13]=(u*T*i-x*f*i+x*n*p-t*T*p-u*n*g+t*f*g)*E,e[14]=(x*o*i-a*T*i-x*n*c+t*T*c+a*n*g-t*o*g)*E,e[15]=(a*f*i-u*o*i+u*n*c-t*f*c-a*n*p+t*o*p)*E,this}scale(e){const t=this.elements,n=e.x,i=e.y,s=e.z;return t[0]*=n,t[4]*=i,t[8]*=s,t[1]*=n,t[5]*=i,t[9]*=s,t[2]*=n,t[6]*=i,t[10]*=s,t[3]*=n,t[7]*=i,t[11]*=s,this}getMaxScaleOnAxis(){const e=this.elements,t=e[0]*e[0]+e[1]*e[1]+e[2]*e[2],n=e[4]*e[4]+e[5]*e[5]+e[6]*e[6],i=e[8]*e[8]+e[9]*e[9]+e[10]*e[10];return Math.sqrt(Math.max(t,n,i))}makeTranslation(e,t,n){return e.isVector3?this.set(1,0,0,e.x,0,1,0,e.y,0,0,1,e.z,0,0,0,1):this.set(1,0,0,e,0,1,0,t,0,0,1,n,0,0,0,1),this}makeRotationX(e){const t=Math.cos(e),n=Math.sin(e);return this.set(1,0,0,0,0,t,-n,0,0,n,t,0,0,0,0,1),this}makeRotationY(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,0,n,0,0,1,0,0,-n,0,t,0,0,0,0,1),this}makeRotationZ(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,0,n,t,0,0,0,0,1,0,0,0,0,1),this}makeRotationAxis(e,t){const n=Math.cos(t),i=Math.sin(t),s=1-n,a=e.x,o=e.y,c=e.z,l=s*a,u=s*o;return this.set(l*a+n,l*o-i*c,l*c+i*o,0,l*o+i*c,u*o+n,u*c-i*a,0,l*c-i*o,u*c+i*a,s*c*c+n,0,0,0,0,1),this}makeScale(e,t,n){return this.set(e,0,0,0,0,t,0,0,0,0,n,0,0,0,0,1),this}makeShear(e,t,n,i,s,a){return this.set(1,n,s,0,e,1,a,0,t,i,1,0,0,0,0,1),this}compose(e,t,n){const i=this.elements,s=t._x,a=t._y,o=t._z,c=t._w,l=s+s,u=a+a,f=o+o,p=s*l,m=s*u,x=s*f,T=a*u,g=a*f,v=o*f,_=c*l,b=c*u,M=c*f,C=n.x,P=n.y,E=n.z;return i[0]=(1-(T+v))*C,i[1]=(m+M)*C,i[2]=(x-b)*C,i[3]=0,i[4]=(m-M)*P,i[5]=(1-(p+v))*P,i[6]=(g+_)*P,i[7]=0,i[8]=(x+b)*E,i[9]=(g-_)*E,i[10]=(1-(p+T))*E,i[11]=0,i[12]=e.x,i[13]=e.y,i[14]=e.z,i[15]=1,this}decompose(e,t,n){const i=this.elements;let s=wn.set(i[0],i[1],i[2]).length();const a=wn.set(i[4],i[5],i[6]).length(),o=wn.set(i[8],i[9],i[10]).length();this.determinant()<0&&(s=-s),e.x=i[12],e.y=i[13],e.z=i[14],Ct.copy(this);const l=1/s,u=1/a,f=1/o;return Ct.elements[0]*=l,Ct.elements[1]*=l,Ct.elements[2]*=l,Ct.elements[4]*=u,Ct.elements[5]*=u,Ct.elements[6]*=u,Ct.elements[8]*=f,Ct.elements[9]*=f,Ct.elements[10]*=f,t.setFromRotationMatrix(Ct),n.x=s,n.y=a,n.z=o,this}makePerspective(e,t,n,i,s,a,o=Qi){const c=this.elements,l=2*s/(t-e),u=2*s/(n-i),f=(t+e)/(t-e),p=(n+i)/(n-i);let m,x;if(o===Qi)m=-(a+s)/(a-s),x=-2*a*s/(a-s);else if(o===Qo)m=-a/(a-s),x=-a*s/(a-s);else throw new Error("Matrix4.makePerspective(): Invalid coordinate system: "+o);return c[0]=l,c[4]=0,c[8]=f,c[12]=0,c[1]=0,c[5]=u,c[9]=p,c[13]=0,c[2]=0,c[6]=0,c[10]=m,c[14]=x,c[3]=0,c[7]=0,c[11]=-1,c[15]=0,this}makeOrthographic(e,t,n,i,s,a,o=Qi){const c=this.elements,l=1/(t-e),u=1/(n-i),f=1/(a-s),p=(t+e)*l,m=(n+i)*u;let x,T;if(o===Qi)x=(a+s)*f,T=-2*f;else if(o===Qo)x=s*f,T=-1*f;else throw new Error("../math.Matrix4.makeOrthographic(): Invalid coordinate system: "+o);return c[0]=2*l,c[4]=0,c[8]=0,c[12]=-p,c[1]=0,c[5]=2*u,c[9]=0,c[13]=-m,c[2]=0,c[6]=0,c[10]=T,c[14]=-x,c[3]=0,c[7]=0,c[11]=0,c[15]=1,this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<16;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<16;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e[t+9]=n[9],e[t+10]=n[10],e[t+11]=n[11],e[t+12]=n[12],e[t+13]=n[13],e[t+14]=n[14],e[t+15]=n[15],e}}const wn=new G,Ct=new Et,du=new G(0,0,0),pu=new G(1,1,1),Yt=new G,er=new G,lt=new G,ea=new Et,ta=new ie;class ui{constructor(e=0,t=0,n=0,i=ui.DEFAULT_ORDER){this.isEuler=!0,this._x=e,this._y=t,this._z=n,this._order=i}get x(){return this._x}set x(e){this._x=e,this._onChangeCallback()}get y(){return this._y}set y(e){this._y=e,this._onChangeCallback()}get z(){return this._z}set z(e){this._z=e,this._onChangeCallback()}get order(){return this._order}set order(e){this._order=e,this._onChangeCallback()}set(e,t,n,i=this._order){return this._x=e,this._y=t,this._z=n,this._order=i,this._onChangeCallback(),this}clone(){return new ui(this._x,this._y,this._z,this._order)}copy(e){return this._x=e._x,this._y=e._y,this._z=e._z,this._order=e._order,this._onChangeCallback(),this}setFromRotationMatrix(e,t=this._order,n=!0){const i=e.elements,s=i[0],a=i[4],o=i[8],c=i[1],l=i[5],u=i[9],f=i[2],p=i[6],m=i[10];switch(t){case"XYZ":this._y=Math.asin(Ot(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(-u,m),this._z=Math.atan2(-a,s)):(this._x=Math.atan2(p,l),this._z=0);break;case"YXZ":this._x=Math.asin(-Ot(u,-1,1)),Math.abs(u)<.9999999?(this._y=Math.atan2(o,m),this._z=Math.atan2(c,l)):(this._y=Math.atan2(-f,s),this._z=0);break;case"ZXY":this._x=Math.asin(Ot(p,-1,1)),Math.abs(p)<.9999999?(this._y=Math.atan2(-f,m),this._z=Math.atan2(-a,l)):(this._y=0,this._z=Math.atan2(c,s));break;case"ZYX":this._y=Math.asin(-Ot(f,-1,1)),Math.abs(f)<.9999999?(this._x=Math.atan2(p,m),this._z=Math.atan2(c,s)):(this._x=0,this._z=Math.atan2(-a,l));break;case"YZX":this._z=Math.asin(Ot(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-u,l),this._y=Math.atan2(-f,s)):(this._x=0,this._y=Math.atan2(o,m));break;case"XZY":this._z=Math.asin(-Ot(a,-1,1)),Math.abs(a)<.9999999?(this._x=Math.atan2(p,l),this._y=Math.atan2(o,s)):(this._x=Math.atan2(-u,m),this._y=0);break;default:console.warn("../math.Euler: .setFromRotationMatrix() encountered an unknown order: "+t)}return this._order=t,n===!0&&this._onChangeCallback(),this}setFromQuaternion(e,t,n){return ea.makeRotationFromQuaternion(e),this.setFromRotationMatrix(ea,t,n)}setFromVector3(e,t=this._order){return this.set(e.x,e.y,e.z,t)}reorder(e){return ta.setFromEuler(this),this.setFromQuaternion(ta,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}}ui.DEFAULT_ORDER="XYZ";class Dn{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 Dn(this.x,this.y)}copy(e){return this.x=e.x,this.y=e.y,this}add(e){return this.x+=e.x,this.y+=e.y,this}addScalar(e){return this.x+=e,this.y+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this}subScalar(e){return this.x-=e,this.y-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this}multiply(e){return this.x*=e.x,this.y*=e.y,this}multiplyScalar(e){return this.x*=e,this.y*=e,this}divide(e){return this.x/=e.x,this.y/=e.y,this}divideScalar(e){return this.multiplyScalar(1/e)}applyMatrix3(e){const t=this.x,n=this.y,i=e.elements;return this.x=i[0]*t+i[3]*n+i[6],this.y=i[1]*t+i[4]*n+i[7],this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(e){return this.x*e.x+this.y*e.y}cross(e){return this.x*e.y-this.y*e.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(e){const t=Math.sqrt(this.lengthSq()*e.lengthSq());if(t===0)return Math.PI/2;const n=this.dot(e)/t;return Math.acos(Ot(n,-1,1))}distanceTo(e){return Math.sqrt(this.distanceToSquared(e))}distanceToSquared(e){const t=this.x-e.x,n=this.y-e.y;return t*t+n*n}manhattanDistanceTo(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this}equals(e){return e.x===this.x&&e.y===this.y}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e}rotateAround(e,t){const n=Math.cos(t),i=Math.sin(t),s=this.x-e.x,a=this.y-e.y;return this.x=s*n-a*i+e.x,this.y=s*i+a*n+e.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}Dn.isVector2=!0;class at{constructor(e=0,t=0,n=0,i=1){at.prototype.isVector4=!0,this.x=e,this.y=t,this.z=n,this.w=i}get width(){return this.z}set width(e){this.z=e}get height(){return this.w}set height(e){this.w=e}set(e,t,n,i){return this.x=e,this.y=t,this.z=n,this.w=i,this}setScalar(e){return this.x=e,this.y=e,this.z=e,this.w=e,this}setX(e){return this.x=e,this}setY(e){return this.y=e,this}setZ(e){return this.z=e,this}setW(e){return this.w=e,this}setComponent(e,t){switch(e){case 0:this.x=t;break;case 1:this.y=t;break;case 2:this.z=t;break;case 3:this.w=t;break;default:throw new Error("index is out of range: "+e)}return this}getComponent(e){switch(e){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+e)}}clone(){return new at(this.x,this.y,this.z,this.w)}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}add(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}addScalar(e){return this.x+=e,this.y+=e,this.z+=e,this.w+=e,this}addVectors(e,t){return this.x=e.x+t.x,this.y=e.y+t.y,this.z=e.z+t.z,this.w=e.w+t.w,this}addScaledVector(e,t){return this.x+=e.x*t,this.y+=e.y*t,this.z+=e.z*t,this.w+=e.w*t,this}sub(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}subScalar(e){return this.x-=e,this.y-=e,this.z-=e,this.w-=e,this}subVectors(e,t){return this.x=e.x-t.x,this.y=e.y-t.y,this.z=e.z-t.z,this.w=e.w-t.w,this}multiply(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this.w*=e.w,this}multiplyScalar(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}applyMatrix4(e){const t=this.x,n=this.y,i=this.z,s=this.w,a=e.elements;return this.x=a[0]*t+a[4]*n+a[8]*i+a[12]*s,this.y=a[1]*t+a[5]*n+a[9]*i+a[13]*s,this.z=a[2]*t+a[6]*n+a[10]*i+a[14]*s,this.w=a[3]*t+a[7]*n+a[11]*i+a[15]*s,this}divideScalar(e){return this.multiplyScalar(1/e)}setAxisAngleFromQuaternion(e){this.w=2*Math.acos(e.w);const t=Math.sqrt(1-e.w*e.w);return t<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=e.x/t,this.y=e.y/t,this.z=e.z/t),this}setAxisAngleFromRotationMatrix(e){let t,n,i,s;const c=e.elements,l=c[0],u=c[4],f=c[8],p=c[1],m=c[5],x=c[9],T=c[2],g=c[6],v=c[10];if(Math.abs(u-p)<.01&&Math.abs(f-T)<.01&&Math.abs(x-g)<.01){if(Math.abs(u+p)<.1&&Math.abs(f+T)<.1&&Math.abs(x+g)<.1&&Math.abs(l+m+v-3)<.1)return this.set(1,0,0,0),this;t=Math.PI;const b=(l+1)/2,M=(m+1)/2,C=(v+1)/2,P=(u+p)/4,E=(f+T)/4,z=(x+g)/4;return b>M&&b>C?b<.01?(n=0,i=.707106781,s=.707106781):(n=Math.sqrt(b),i=P/n,s=E/n):M>C?M<.01?(n=.707106781,i=0,s=.707106781):(i=Math.sqrt(M),n=P/i,s=z/i):C<.01?(n=.707106781,i=.707106781,s=0):(s=Math.sqrt(C),n=E/s,i=z/s),this.set(n,i,s,t),this}let _=Math.sqrt((g-x)*(g-x)+(f-T)*(f-T)+(p-u)*(p-u));return Math.abs(_)<.001&&(_=1),this.x=(g-x)/_,this.y=(f-T)/_,this.z=(p-u)/_,this.w=Math.acos((l+m+v-1)/2),this}min(e){return this.x=Math.min(this.x,e.x),this.y=Math.min(this.y,e.y),this.z=Math.min(this.z,e.z),this.w=Math.min(this.w,e.w),this}max(e){return this.x=Math.max(this.x,e.x),this.y=Math.max(this.y,e.y),this.z=Math.max(this.z,e.z),this.w=Math.max(this.w,e.w),this}clamp(e,t){return this.x=Math.max(e.x,Math.min(t.x,this.x)),this.y=Math.max(e.y,Math.min(t.y,this.y)),this.z=Math.max(e.z,Math.min(t.z,this.z)),this.w=Math.max(e.w,Math.min(t.w,this.w)),this}clampScalar(e,t){return this.x=Math.max(e,Math.min(t,this.x)),this.y=Math.max(e,Math.min(t,this.y)),this.z=Math.max(e,Math.min(t,this.z)),this.w=Math.max(e,Math.min(t,this.w)),this}clampLength(e,t){const n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(e,Math.min(t,n)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this}roundToZero(){return this.x=Math.trunc(this.x),this.y=Math.trunc(this.y),this.z=Math.trunc(this.z),this.w=Math.trunc(this.w),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z+this.w*e.w}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)}normalize(){return this.divideScalar(this.length()||1)}setLength(e){return this.normalize().multiplyScalar(e)}lerp(e,t){return this.x+=(e.x-this.x)*t,this.y+=(e.y-this.y)*t,this.z+=(e.z-this.z)*t,this.w+=(e.w-this.w)*t,this}lerpVectors(e,t,n){return this.x=e.x+(t.x-e.x)*n,this.y=e.y+(t.y-e.y)*n,this.z=e.z+(t.z-e.z)*n,this.w=e.w+(t.w-e.w)*n,this}equals(e){return e.x===this.x&&e.y===this.y&&e.z===this.z&&e.w===this.w}fromArray(e,t=0){return this.x=e[t],this.y=e[t+1],this.z=e[t+2],this.w=e[t+3],this}toArray(e=[],t=0){return e[t]=this.x,e[t+1]=this.y,e[t+2]=this.z,e[t+3]=this.w,e}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this.w=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z,yield this.w}}class It{constructor(e,t,n,i,s,a,o,c,l){It.prototype.isMatrix3=!0,this.elements=[1,0,0,0,1,0,0,0,1],e!==void 0&&this.set(e,t,n,i,s,a,o,c,l)}set(e,t,n,i,s,a,o,c,l){const u=this.elements;return u[0]=e,u[1]=i,u[2]=o,u[3]=t,u[4]=s,u[5]=c,u[6]=n,u[7]=a,u[8]=l,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(e){const t=this.elements,n=e.elements;return t[0]=n[0],t[1]=n[1],t[2]=n[2],t[3]=n[3],t[4]=n[4],t[5]=n[5],t[6]=n[6],t[7]=n[7],t[8]=n[8],this}extractBasis(e,t,n){return e.setFromMatrix3Column(this,0),t.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this}setFromMatrix4(e){const t=e.elements;return this.set(t[0],t[4],t[8],t[1],t[5],t[9],t[2],t[6],t[10]),this}multiply(e){return this.multiplyMatrices(this,e)}premultiply(e){return this.multiplyMatrices(e,this)}multiplyMatrices(e,t){const n=e.elements,i=t.elements,s=this.elements,a=n[0],o=n[3],c=n[6],l=n[1],u=n[4],f=n[7],p=n[2],m=n[5],x=n[8],T=i[0],g=i[3],v=i[6],_=i[1],b=i[4],M=i[7],C=i[2],P=i[5],E=i[8];return s[0]=a*T+o*_+c*C,s[3]=a*g+o*b+c*P,s[6]=a*v+o*M+c*E,s[1]=l*T+u*_+f*C,s[4]=l*g+u*b+f*P,s[7]=l*v+u*M+f*E,s[2]=p*T+m*_+x*C,s[5]=p*g+m*b+x*P,s[8]=p*v+m*M+x*E,this}multiplyScalar(e){const t=this.elements;return t[0]*=e,t[3]*=e,t[6]*=e,t[1]*=e,t[4]*=e,t[7]*=e,t[2]*=e,t[5]*=e,t[8]*=e,this}determinant(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8];return t*a*u-t*o*l-n*s*u+n*o*c+i*s*l-i*a*c}invert(){const e=this.elements,t=e[0],n=e[1],i=e[2],s=e[3],a=e[4],o=e[5],c=e[6],l=e[7],u=e[8],f=u*a-o*l,p=o*c-u*s,m=l*s-a*c,x=t*f+n*p+i*m;if(x===0)return this.set(0,0,0,0,0,0,0,0,0);const T=1/x;return e[0]=f*T,e[1]=(i*l-u*n)*T,e[2]=(o*n-i*a)*T,e[3]=p*T,e[4]=(u*t-i*c)*T,e[5]=(i*s-o*t)*T,e[6]=m*T,e[7]=(n*c-l*t)*T,e[8]=(a*t-n*s)*T,this}transpose(){let e;const t=this.elements;return e=t[1],t[1]=t[3],t[3]=e,e=t[2],t[2]=t[6],t[6]=e,e=t[5],t[5]=t[7],t[7]=e,this}getNormalMatrix(e){return this.setFromMatrix4(e).invert().transpose()}transposeIntoArray(e){const t=this.elements;return e[0]=t[0],e[1]=t[3],e[2]=t[6],e[3]=t[1],e[4]=t[4],e[5]=t[7],e[6]=t[2],e[7]=t[5],e[8]=t[8],this}setUvTransform(e,t,n,i,s,a,o){const c=Math.cos(s),l=Math.sin(s);return this.set(n*c,n*l,-n*(c*a+l*o)+a+e,-i*l,i*c,-i*(-l*a+c*o)+o+t,0,0,1),this}scale(e,t){return this.premultiply(ps.makeScale(e,t)),this}rotate(e){return this.premultiply(ps.makeRotation(-e)),this}translate(e,t){return this.premultiply(ps.makeTranslation(e,t)),this}makeTranslation(e,t){return e.isVector2?this.set(1,0,e.x,0,1,e.y,0,0,1):this.set(1,0,e,0,1,t,0,0,1),this}makeRotation(e){const t=Math.cos(e),n=Math.sin(e);return this.set(t,-n,0,n,t,0,0,0,1),this}makeScale(e,t){return this.set(e,0,0,0,t,0,0,0,1),this}equals(e){const t=this.elements,n=e.elements;for(let i=0;i<9;i++)if(t[i]!==n[i])return!1;return!0}fromArray(e,t=0){for(let n=0;n<9;n++)this.elements[n]=e[n+t];return this}toArray(e=[],t=0){const n=this.elements;return e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+3]=n[3],e[t+4]=n[4],e[t+5]=n[5],e[t+6]=n[6],e[t+7]=n[7],e[t+8]=n[8],e}clone(){return new It().fromArray(this.elements)}}const ps=new It;var et;(function(r){r[r.Random=0]="Random",r[r.Loop=1]="Loop",r[r.PingPong=2]="PingPong",r[r.Burst=3]="Burst"})(et||(et={}));function ji(r,e,t,n){let i;switch(et.Random===r?e=Math.random():et.Burst===r&&n.isBursting&&(e=n.burstParticleIndex/n.burstParticleCount),t>0?i=Math.floor(e/t)*t:i=e,r){case et.Loop:i=i%1;break;case et.PingPong:i=Math.abs(i%2-1);break}return i}class yn{constructor(e,t,n,i){this.p=[e,t,n,i]}genValue(e){const t=e*e,n=e*e*e,i=1-e,s=i*i,a=s*i;return this.p[0]*a+this.p[1]*s*e*3+this.p[2]*i*t*3+this.p[3]*n}derivativeCoefficients(e){const t=[];for(let n=e,i=n.length-1;i>0;i--){const s=[];for(let a=0;a<i;a++){const o=i*(n[a+1]-n[a]);s.push(o)}t.push(s),n=s}return t}getSlope(e){const t=this.derivativeCoefficients(this.p)[0],n=1-e,i=n*n,s=n*e*2,a=e*e;return i*t[0]+s*t[1]+a*t[2]}controlCurve(e,t){this.p[1]=e/3+this.p[0],this.p[2]=this.p[3]-t/3}hull(e){let t=this.p,n=[],i,s=0,a=0,o=0;const c=[];for(c[s++]=t[0],c[s++]=t[1],c[s++]=t[2],c[s++]=t[3];t.length>1;){for(n=[],a=0,o=t.length-1;a<o;a++)i=e*t[a]+(1-e)*t[a+1],c[s++]=i,n.push(i);t=n}return c}split(e){const t=this.hull(e);return{left:new yn(t[0],t[4],t[7],t[9]),right:new yn(t[9],t[8],t[6],t[3]),span:t}}clone(){return new yn(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 yn(e.p0,e.p1,e.p2,e.p3)}}const hi=r=>({r:r.x,g:r.y,b:r.z,a:r.w}),fi=r=>new at(r.r,r.g,r.b,r.a),mu=(r,e)=>{switch(e){case"Vector3":return new G(r.x,r.y,r.z);case"Vector4":return new at(r.x,r.y,r.z,r.w);case"Color":return new G(r.r,r.g,r.b);case"Number":return r;default:return r}},yu=(r,e)=>{switch(e){case"Vector3":return{x:r.x,y:r.y,z:r.z};case"Vector4":return{x:r.x,y:r.y,z:r.z,w:r.w};case"Color":return{r:r.x,g:r.y,b:r.z};case"Number":return r;default:return r}};class Ar{constructor(e,t){this.a=e,this.b=t,this.type="value"}startGen(e){}genColor(e,t){const n=Math.random();return t.copy(this.a).lerp(this.b,n)}toJSON(){return{type:"RandomColor",a:hi(this.a),b:hi(this.b)}}static fromJSON(e){return new Ar(fi(e.a),fi(e.b))}clone(){return new Ar(this.a.clone(),this.b.clone())}}class Fn{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:hi(this.a),b:hi(this.b)}}static fromJSON(e){return new Fn(fi(e.a),fi(e.b))}clone(){return new Fn(this.a.clone(),this.b.clone())}}class tn{constructor(e,t){this.subType=t,this.type="function",this.keys=e}findKey(e){let t=0,n=0,i=this.keys.length-1;for(;n+1<i;)if(t=Math.floor((n+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))n=t+1;else return t;for(let s=n;s<=i;s++)if(e>=this.getStartX(s)&&e<=this.getEndX(s))return s;return-1}getStartX(e){return this.keys[e][1]}getEndX(e){return e+1<this.keys.length?this.keys[e+1][1]:1}genValue(e,t){const n=this.findKey(t);return this.subType==="Number"?n===-1?this.keys[0][0]:n+1>=this.keys.length?this.keys[this.keys.length-1][0]:(this.keys[n+1][0]-this.keys[n][0])*((t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))+this.keys[n][0]:n===-1?e.copy(this.keys[0][0]):n+1>=this.keys.length?e.copy(this.keys[this.keys.length-1][0]):e.copy(this.keys[n][0]).lerp(this.keys[n+1][0],(t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))}toJSON(){return this.keys[0][0].constructor.name,{type:"CLinearFunction",subType:this.subType,keys:this.keys.map(([e,t])=>({value:yu(e,this.subType),pos:t}))}}static fromJSON(e){return new tn(e.keys.map(t=>[mu(t.value,e.subType),t.pos]),e.subType)}clone(){return this.subType==="Number"?new tn(this.keys.map(([e,t])=>[e,t]),this.subType):new tn(this.keys.map(([e,t])=>[e.clone(),t]),this.subType)}}const tr=new G;class gn{constructor(e=[[new G(0,0,0),0],[new G(1,1,1),0]],t=[[1,0],[1,1]]){this.type="function",this.color=new tn(e,"Color"),this.alpha=new tn(t,"Number")}genColor(e,t,n){return this.color.genValue(tr,n),t.set(tr.x,tr.y,tr.z,this.alpha.genValue(1,n))}toJSON(){return{type:"Gradient",color:this.color.toJSON(),alpha:this.alpha.toJSON()}}static fromJSON(e){if(e.functions){const t=e.functions.map(n=>[Fn.fromJSON(n.function).a,n.start]);return e.functions.length>0&&t.push([Fn.fromJSON(e.functions[e.functions.length-1].function).b,1]),new gn(t.map(n=>[new G(n[0].x,n[0].y,n[0].z),n[1]]),t.map(n=>[n[0].w,n[1]]))}else{const t=new gn;return t.alpha=tn.fromJSON(e.alpha),t.color=tn.fromJSON(e.color),t}}clone(){const e=new gn;return e.alpha=this.alpha.clone(),e.color=this.color.clone(),e}startGen(e){}}const ms=new at;class Or{constructor(e,t){this.indexCount=0,this.type="function",this.gradient1=e,this.gradient2=t}startGen(e){this.indexCount=e.length,e.push(Math.random())}genColor(e,t,n){return this.gradient1.genColor(e,t,n),this.gradient2.genColor(e,ms,n),e&&e[this.indexCount]!==void 0?t.lerp(ms,e[this.indexCount]):t.lerp(ms,Math.random()),t}toJSON(){return{type:"RandomColorBetweenGradient",gradient1:this.gradient1.toJSON(),gradient2:this.gradient2.toJSON()}}static fromJSON(e){return new Or(gn.fromJSON(e.gradient1),gn.fromJSON(e.gradient2))}clone(){return new Or(this.gradient1.clone(),this.gradient2.clone())}}class vn{constructor(e){this.color=e,this.type="value"}startGen(e){}genColor(e,t){return t.copy(this.color)}toJSON(){return{type:"ConstantColor",color:hi(this.color)}}static fromJSON(e){return new vn(fi(e.color))}clone(){return new vn(this.color.clone())}}function co(r){switch(r.type){case"ConstantColor":return vn.fromJSON(r);case"ColorRange":return Fn.fromJSON(r);case"RandomColor":return Ar.fromJSON(r);case"Gradient":return gn.fromJSON(r);case"RandomColorBetweenGradient":return Or.fromJSON(r);default:return new vn(new at(1,1,1,1))}}class ee{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 ee(e.value)}clone(){return new ee(this.value)}}class Sn{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),Jn.lerp(this.a,this.b,e[this.indexCount])}toJSON(){return{type:"IntervalValue",a:this.a,b:this.b}}static fromJSON(e){return new Sn(e.a,e.b)}clone(){return new Sn(this.a,this.b)}}class gu{constructor(){this.functions=new Array}findFunction(e){let t=0,n=0,i=this.functions.length-1;for(;n+1<i;)if(t=Math.floor((n+i)/2),e<this.getStartX(t))i=t-1;else if(e>this.getEndX(t))n=t+1;else return t;for(let s=n;s<=i;s++)if(e>=this.functions[s][1]&&e<=this.getEndX(s))return s;return-1}getStartX(e){return this.functions[e][1]}setStartX(e,t){e>0&&(this.functions[e][1]=t)}getEndX(e){return e+1<this.functions.length?this.functions[e+1][1]:1}setEndX(e,t){e+1<this.functions.length&&(this.functions[e+1][1]=t)}insertFunction(e,t){const n=this.findFunction(e);this.functions.splice(n+1,0,[t,e])}removeFunction(e){return this.functions.splice(e,1)[0][0]}getFunction(e){return this.functions[e][0]}setFunction(e,t){this.functions[e][0]=t}get numOfFunctions(){return this.functions.length}}class di extends gu{constructor(e=[[new yn(0,1/3,1/3*2,1),0]]){super(),this.type="function",this.functions=e}genValue(e,t=0){const n=this.findFunction(t);return n===-1?0:this.functions[n][0].genValue((t-this.getStartX(n))/(this.getEndX(n)-this.getStartX(n)))}toSVG(e,t){if(t<1)return"";let n=["M",0,this.functions[0][0].p[0]].join(" ");for(let i=1/t;i<=1;i+=1/t)n=[n,"L",i*e,this.genValue(void 0,i)].join(" ");return n}toJSON(){return{type:"PiecewiseBezier",functions:this.functions.map(([e,t])=>({function:e.toJSON(),start:t}))}}static fromJSON(e){return new di(e.functions.map(t=>[yn.fromJSON(t.function),t.start]))}clone(){return new di(this.functions.map(([e,t])=>[e.clone(),t]))}startGen(e){}}function Z(r){switch(r.type){case"ConstantValue":return ee.fromJSON(r);case"IntervalValue":return Sn.fromJSON(r);case"PiecewiseBezier":return di.fromJSON(r);default:return new ee(0)}}class pi{constructor(){this.indexCount=0,this.type="rotation"}startGen(e){this.indexCount=e.length,e.push(new ie);let t,n,i,s,a,o;do t=Math.random()*2-1,n=Math.random()*2-1,i=t*t+n*n;while(i>1);do s=Math.random()*2-1,a=Math.random()*2-1,o=s*s+a*a;while(o>1);const c=Math.sqrt((1-i)/o);e[this.indexCount].set(t,n,c*s,c*a)}genValue(e,t,n,i){return this.indexCount===-1&&this.startGen(e),t.copy(e[this.indexCount]),t}toJSON(){return{type:"RandomQuat"}}static fromJSON(e){return new pi}clone(){return new pi}}class mi{constructor(e,t){this.axis=e,this.angle=t,this.type="rotation"}startGen(e){this.angle.startGen(e)}genValue(e,t,n,i){return t.setFromAxisAngle(this.axis,this.angle.genValue(e,i)*n)}toJSON(){return{type:"AxisAngle",axis:{x:this.axis.x,y:this.axis.y,z:this.axis.z},angle:this.angle.toJSON()}}static fromJSON(e){return new mi(new G(e.axis.x,e.axis.y,e.axis.z),Z(e.angle))}clone(){return new mi(this.axis.clone(),this.angle.clone())}}class zr{constructor(e,t,n,i){this.angleX=e,this.angleY=t,this.angleZ=n,this.type="rotation",this.eular=new ui(0,0,0,i)}startGen(e){this.angleX.startGen(e),this.angleY.startGen(e),this.angleZ.startGen(e)}genValue(e,t,n,i){return this.eular.set(this.angleX.genValue(e,i)*n,this.angleY.genValue(e,i)*n,this.angleZ.genValue(e,i)*n),t.setFromEuler(this.eular)}toJSON(){return{type:"Euler",angleX:this.angleX.toJSON(),angleY:this.angleY.toJSON(),angleZ:this.angleZ.toJSON(),eulerOrder:this.eular.order}}static fromJSON(e){return new zr(Z(e.angleX),Z(e.angleY),Z(e.angleZ),e.eulerOrder)}clone(){return new zr(this.angleX,this.angleY,this.angleZ,this.eular.order)}}function oc(r){switch(r.type){case"AxisAngle":return mi.fromJSON(r);case"Euler":return zr.fromJSON(r);case"RandomQuat":return pi.fromJSON(r);default:return new pi}}class xn{constructor(e,t,n){this.x=e,this.y=t,this.z=n,this.type="vec3function"}startGen(e){this.x.startGen(e),this.y.startGen(e),this.z.startGen(e)}genValue(e,t,n){return t.set(this.x.genValue(e,n),this.y.genValue(e,n),this.z.genValue(e,n))}toJSON(){return{type:"Vector3Function",x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new xn(Z(e.x),Z(e.y),Z(e.z))}clone(){return new xn(this.x,this.y,this.z)}}function vu(r){return r.type==="Vector3Function"?xn.fromJSON(r):new xn(new ee(0),new ee(0),new ee(0))}function Ir(r){switch(r.type){case"ConstantValue":case"IntervalValue":case"PiecewiseBezier":return Z(r);case"AxisAngle":case"RandomQuat":case"Euler":return oc(r);case"Vector3Function":return vu(r);default:return new ee(0)}}class yi{constructor(e={}){var t,n,i,s,a,o,c;this.type="cone",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.angle=(s=e.angle)!==null&&s!==void 0?s:Math.PI/6,this.mode=(a=e.mode)!==null&&a!==void 0?a:et.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new ee(1),this.memory=[]}update(e,t){et.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Jn.lerp(1-this.thickness,1,Math.random()),s=n*this.arc,a=Math.sqrt(i),o=Math.sin(s),c=Math.cos(s);e.position.x=a*c,e.position.y=a*o,e.position.z=0;const l=this.angle*a;e.velocity.set(0,0,Math.cos(l)).addScaledVector(e.position,Math.sin(l)).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius)}toJSON(){return{type:"cone",radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new yi({radius:e.radius,arc:e.arc,thickness:e.thickness,angle:e.angle,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new yi({radius:this.radius,arc:this.arc,thickness:this.thickness,angle:this.angle,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class gi{constructor(e={}){var t,n,i,s,a,o;this.type="circle",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:et.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ee(1),this.memory=[]}update(e,t){this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Jn.lerp(1-this.thickness,1,Math.random()),s=n*this.arc;e.position.x=Math.cos(s),e.position.y=Math.sin(s),e.position.z=0,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*i)}toJSON(){return{type:"circle",radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,spread:this.spread,speed:this.speed.toJSON()}}static fromJSON(e){return new gi({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new gi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}function nr(r,e){return Math.floor(Math.random()*(e-r))+r}const Jr=new G(0,1,0),jr=new G(0,0,0),Su=new G(1,1,1),na=new G(0,0,1);class vi{constructor(e={}){var t,n,i,s,a,o,c;this.type="donut",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.donutRadius=(s=e.donutRadius)!==null&&s!==void 0?s:this.radius*.2,this.mode=(a=e.mode)!==null&&a!==void 0?a:et.Random,this.spread=(o=e.spread)!==null&&o!==void 0?o:0,this.speed=(c=e.speed)!==null&&c!==void 0?c:new ee(1),this.memory=[],this._m1=new Et}update(e,t){et.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=i*Math.PI*2,c=Math.sin(a),l=Math.cos(a);e.position.x=this.radius*l,e.position.y=this.radius*c,e.position.z=0,e.velocity.z=this.donutRadius*s*Math.sin(o),e.velocity.x=this.donutRadius*s*Math.cos(o)*l,e.velocity.y=this.donutRadius*s*Math.cos(o)*c,e.position.add(e.velocity),e.velocity.normalize().multiplyScalar(e.startSpeed),e.rotation instanceof ie&&(this._m1.lookAt(jr,e.velocity,Jr),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 vi({radius:e.radius,arc:e.arc,thickness:e.thickness,donutRadius:e.donutRadius,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new vi({radius:this.radius,arc:this.arc,thickness:this.thickness,donutRadius:this.donutRadius,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class Si{constructor(){this.type="point",this._m1=new Et}update(e,t){}initialize(e){const t=Math.random(),n=Math.random(),i=t*Math.PI*2,s=Math.acos(2*n-1),a=Math.cbrt(Math.random()),o=Math.sin(i),c=Math.cos(i),l=Math.sin(s),u=Math.cos(s);e.velocity.x=a*l*c,e.velocity.y=a*l*o,e.velocity.z=a*u,e.velocity.multiplyScalar(e.startSpeed),e.position.setScalar(0),e.rotation instanceof ie&&(this._m1.lookAt(jr,e.position,Jr),e.rotation.setFromRotationMatrix(this._m1))}toJSON(){return{type:"point"}}static fromJSON(e){return new Si}clone(){return new Si}}class Ln{constructor(e={}){var t,n,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:et.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ee(1),this.memory=[],this._m1=new Et}update(e,t){et.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=Math.acos(2*i-1),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),f=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=f,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof ie&&(this._m1.lookAt(jr,e.position,Jr),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 Ln({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new Ln({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class xi{constructor(e={}){var t,n,i,s,a,o;this.type="sphere",this.currentValue=0,this.radius=(t=e.radius)!==null&&t!==void 0?t:10,this.arc=(n=e.arc)!==null&&n!==void 0?n:2*Math.PI,this.thickness=(i=e.thickness)!==null&&i!==void 0?i:1,this.mode=(s=e.mode)!==null&&s!==void 0?s:et.Random,this.spread=(a=e.spread)!==null&&a!==void 0?a:0,this.speed=(o=e.speed)!==null&&o!==void 0?o:new ee(1),this.memory=[],this._m1=new Et}update(e,t){et.Random!=this.mode&&(this.currentValue+=this.speed.genValue(this.memory,e.emissionState.time/e.duration)*t)}initialize(e,t){const n=ji(this.mode,this.currentValue,this.spread,t),i=Math.random(),s=Jn.lerp(1-this.thickness,1,Math.random()),a=n*this.arc,o=Math.acos(i),c=Math.sin(a),l=Math.cos(a),u=Math.sin(o),f=Math.cos(o);e.position.x=u*l,e.position.y=u*c,e.position.z=f,e.velocity.copy(e.position).multiplyScalar(e.startSpeed),e.position.multiplyScalar(this.radius*s),e.rotation instanceof ie&&(this._m1.lookAt(jr,e.position,Jr),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 xi({radius:e.radius,arc:e.arc,thickness:e.thickness,mode:e.mode,speed:e.speed?Z(e.speed):void 0,spread:e.spread})}clone(){return new xi({radius:this.radius,arc:this.arc,thickness:this.thickness,mode:this.mode,speed:this.speed.clone(),spread:this.spread})}}class _i{constructor(e={}){var t,n,i,s;this.type="grid",this.width=(t=e.width)!==null&&t!==void 0?t:1,this.height=(n=e.height)!==null&&n!==void 0?n:1,this.column=(i=e.column)!==null&&i!==void 0?i:10,this.row=(s=e.row)!==null&&s!==void 0?s:10}initialize(e){const t=Math.floor(Math.random()*this.row),n=Math.floor(Math.random()*this.column);e.position.x=n*this.width/this.column-this.width/2,e.position.y=t*this.height/this.row-this.height/2,e.position.z=0,e.velocity.set(0,0,e.startSpeed)}toJSON(){return{type:"grid",width:this.width,height:this.height,column:this.column,row:this.row}}static fromJSON(e){return new _i(e)}clone(){return new _i({width:this.width,height:this.height,column:this.column,row:this.row})}update(e,t){}}const Fs={circle:{type:"circle",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:gi,loadJSON:gi.fromJSON},cone:{type:"cone",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:yi,loadJSON:yi.fromJSON},donut:{type:"donut",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["donutRadius",["number"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:vi,loadJSON:vi.fromJSON},point:{type:"point",params:[],constructor:Si,loadJSON:Si.fromJSON},sphere:{type:"sphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:Ln,loadJSON:Ln.fromJSON},hemisphere:{type:"hemisphere",params:[["radius",["number"]],["arc",["radian"]],["thickness",["number"]],["angle",["radian"]],["mode",["emitterMode"]],["spread",["number"]],["speed",["valueFunc"]]],constructor:xi,loadJSON:xi.fromJSON},grid:{type:"grid",params:[["width",["number"]],["height",["number"]],["rows",["number"]],["column",["number"]]],constructor:_i,loadJSON:_i.fromJSON}};function xu(r,e){return Fs[r.type].loadJSON(r,e)}class bi{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 bi(co(e.color))}clone(){return new bi(this.color.clone())}reset(){}}class Ti{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 Ti(Z(e.angularVelocity))}frameUpdate(e){}clone(){return new Ti(this.angularVelocity.clone())}reset(){}}class Mi{constructor(e){this.angularVelocity=e,this.type="Rotation3DOverLife",this.tempQuat=new ie,this.tempQuat2=new ie}initialize(e){e.rotation instanceof ie&&(e.angularVelocity=new ie,this.angularVelocity.startGen(e.memory))}update(e,t){e.rotation instanceof ie&&(this.angularVelocity.genValue(e.memory,this.tempQuat,t,e.age/e.life),e.rotation.multiply(this.tempQuat))}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON()}}static fromJSON(e){return new Mi(oc(e.angularVelocity))}frameUpdate(e){}clone(){return new Mi(this.angularVelocity.clone())}reset(){}}class Ci{initialize(e,t){this.ps=t,this.x.startGen(e.memory),this.y.startGen(e.memory),this.z.startGen(e.memory)}constructor(e,t,n){this.x=e,this.y=t,this.z=n,this.type="ForceOverLife",this._temp=new G,this._tempScale=new G,this._tempQ=new ie}update(e,t){this._temp.set(this.x.genValue(e.memory,e.age/e.life),this.y.genValue(e.memory,e.age/e.life),this.z.genValue(e.memory,e.age/e.life)),this.ps.worldSpace?e.velocity.addScaledVector(this._temp,t):(this._temp.multiply(this._tempScale).applyQuaternion(this._tempQ),e.velocity.addScaledVector(this._temp,t))}toJSON(){return{type:this.type,x:this.x.toJSON(),y:this.y.toJSON(),z:this.z.toJSON()}}static fromJSON(e){return new Ci(Z(e.x),Z(e.y),Z(e.z))}frameUpdate(e){if(this.ps&&!this.ps.worldSpace){const t=this._temp,n=this._tempQ,i=this._tempScale;this.ps.emitter.matrixWorld.decompose(t,n,i),n.invert(),i.set(1/i.x,1/i.y,1/i.z)}}clone(){return new Ci(this.x.clone(),this.y.clone(),this.z.clone())}reset(){}}class wi{initialize(e){this.size.startGen(e.memory)}constructor(e){this.size=e,this.type="SizeOverLife"}update(e){this.size instanceof xn?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 wi(Ir(e.size))}frameUpdate(e){}clone(){return new wi(this.size.clone())}reset(){}}class Pi{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 Pi(Z(e.speed))}frameUpdate(e){}clone(){return new Pi(this.speed.clone())}reset(){}}class Ei{constructor(e){this.frame=e,this.type="FrameOverLife"}initialize(e){this.frame.startGen(e.memory)}update(e,t){this.frame instanceof di&&(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 Ei(Z(e.frame))}clone(){return new Ei(this.frame.clone())}reset(){}}class ki{constructor(e,t=new G(0,1,0)){this.orbitSpeed=e,this.axis=t,this.type="OrbitOverLife",this.temp=new G,this.rotation=new ie}initialize(e){this.orbitSpeed.startGen(e.memory)}update(e,t){this.temp.copy(e.position).projectOnVector(this.axis),this.rotation.setFromAxisAngle(this.axis,this.orbitSpeed.genValue(e.memory,e.age/e.life)*t),e.position.sub(this.temp),e.position.applyQuaternion(this.rotation),e.position.add(this.temp)}frameUpdate(e){}toJSON(){return{type:this.type,orbitSpeed:this.orbitSpeed.toJSON(),axis:[this.axis.x,this.axis.y,this.axis.z]}}static fromJSON(e){return new ki(Z(e.orbitSpeed),e.axis?new G(e.axis[0],e.axis[1],e.axis[2]):void 0)}clone(){return new ki(this.orbitSpeed.clone())}reset(){}}class ys{constructor(e){this.data=e,this.next=null,this.prev=null}hasPrev(){return this.prev!==null}hasNext(){return this.next!==null}}class _u{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 ys(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 ys(e);this.head||(this.head=t),this.tail&&(this.tail.next=t,t.prev=this.tail),this.tail=t,this.length++}insertBefore(e,t){const n=new ys(t);n.next=e,n.prev=e.prev,n.prev!==null&&(n.prev.next=n),n.next.prev=n,e==this.head&&(this.head=n),this.length++}remove(e){if(this.head===null||this.tail===null)return;let t=this.head;for(e===this.head.data&&(this.head=this.head.next),e===this.tail.data&&(this.tail=this.tail.prev);t.next!==null&&t.data!==e;)t=t.next;t.data===e&&(t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.length--)}*values(){let e=this.head;for(;e!==null;)yield e.data,e=e.next}}class bu{constructor(){this.startSpeed=0,this.startColor=new at,this.startSize=new G(1,1,1),this.position=new G,this.velocity=new G,this.age=0,this.life=1,this.size=new G(1,1,1),this.speedModifier=1,this.rotation=0,this.color=new at,this.uvTile=0,this.memory=[]}get died(){return this.age>=this.life}reset(){this.memory.length=0}}class Tu{constructor(e,t,n){this.position=e,this.size=t,this.color=n}}class Br{constructor(){this.startSpeed=0,this.startColor=new at,this.startSize=new G(1,1,1),this.position=new G,this.velocity=new G,this.age=0,this.life=1,this.size=new G(1,1,1),this.length=100,this.speedModifier=1,this.color=new at,this.previous=new _u,this.uvTile=0,this.memory=[]}update(){for(this.age<=this.life?this.previous.push(new Tu(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 Ri{initialize(e){this.width.startGen(e.memory)}constructor(e){this.width=e,this.type="WidthOverLength"}update(e){if(e instanceof Br){const t=e.previous.values();for(let n=0;n<e.previous.length;n++){const i=t.next();i.value.size=this.width.genValue(e.memory,(e.previous.length-n)/e.length)}}}frameUpdate(e){}toJSON(){return{type:this.type,width:this.width.toJSON()}}static fromJSON(e){return new Ri(Z(e.width))}clone(){return new Ri(this.width.clone())}reset(){}}class Ai{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 Ai(new G(e.direction[0],e.direction[1],e.direction[2]),Z((t=e.magnitude)!==null&&t!==void 0?t:e.force))}clone(){return new Ai(this.direction.clone(),this.magnitude.clone())}reset(){}}class Oi{constructor(e,t){this.center=e,this.magnitude=t,this.type="GravityForce",this.temp=new G}initialize(e){}update(e,t){this.temp.copy(this.center).sub(e.position).normalize(),e.velocity.addScaledVector(this.temp,this.magnitude/e.position.distanceToSquared(this.center)*t)}frameUpdate(e){}toJSON(){return{type:this.type,center:[this.center.x,this.center.y,this.center.z],magnitude:this.magnitude}}static fromJSON(e){return new Oi(new G(e.center[0],e.center[1],e.center[2]),e.magnitude)}clone(){return new Oi(this.center.clone(),this.magnitude)}reset(){}}class zi{constructor(e){this.angle=e,this.type="ChangeEmitDirection",this._temp=new G,this._q=new ie,this.memory={data:[],dataCount:0}}initialize(e){const t=e.velocity.length();t!=0&&(e.velocity.normalize(),e.velocity.x===0&&e.velocity.y===0?this._temp.set(0,e.velocity.z,0):this._temp.set(-e.velocity.y,e.velocity.x,0),this.angle.startGen(this.memory),this._q.setFromAxisAngle(this._temp.normalize(),this.angle.genValue(this.memory)),this._temp.copy(e.velocity),e.velocity.applyQuaternion(this._q),this._q.setFromAxisAngle(this._temp,Math.random()*Math.PI*2),e.velocity.applyQuaternion(this._q),e.velocity.setLength(t))}update(e,t){}frameUpdate(e){}toJSON(){return{type:this.type,angle:this.angle.toJSON()}}static fromJSON(e){return new zi(Z(e.angle))}clone(){return new zi(this.angle)}reset(){}}var Nn;(function(r){r[r.Death=0]="Death",r[r.Birth=1]="Birth",r[r.Frame=2]="Frame"})(Nn||(Nn={}));class Ii{constructor(e,t,n,i=Nn.Frame,s=1){this.particleSystem=e,this.useVelocityAsBasis=t,this.subParticleSystem=n,this.mode=i,this.emitProbability=s,this.type="EmitSubParticleSystem",this.q_=new ie,this.v_=new G,this.v2_=new G,this.subEmissions=new Array,this.subParticleSystem&&this.subParticleSystem.system&&(this.subParticleSystem.system.onlyUsedByOther=!0)}initialize(e){}update(e,t){this.mode===Nn.Frame?this.emit(e,t):this.mode===Nn.Birth&&e.age===0?this.emit(e,t):this.mode===Nn.Death&&e.age+t>=e.life&&this.emit(e,t)}emit(e,t){if(!this.subParticleSystem||Math.random()>this.emitProbability)return;const n=new Et;this.setMatrixFromParticle(n,e),this.subEmissions.push({burstParticleCount:0,burstParticleIndex:0,isBursting:!1,burstIndex:0,burstWaveIndex:0,time:0,waitEmiting:0,matrix:n,travelDistance:0,particle:e})}frameUpdate(e){if(this.subParticleSystem)for(let t=0;t<this.subEmissions.length;t++)if(this.subEmissions[t].time>=this.subParticleSystem.system.duration)this.subEmissions[t]=this.subEmissions[this.subEmissions.length-1],this.subEmissions.length=this.subEmissions.length-1,t--;else{const n=this.subEmissions[t];n.particle&&n.particle.age<n.particle.life?this.setMatrixFromParticle(n.matrix,n.particle):n.particle=void 0,this.subParticleSystem.system.emit(e,n,n.matrix)}}toJSON(){return{type:this.type,subParticleSystem:this.subParticleSystem?this.subParticleSystem.uuid:"",useVelocityAsBasis:this.useVelocityAsBasis,mode:this.mode,emitProbability:this.emitProbability}}static fromJSON(e,t){return new Ii(t,e.useVelocityAsBasis,e.subParticleSystem,e.mode,e.emitProbability)}clone(){return new Ii(this.particleSystem,this.useVelocityAsBasis,this.subParticleSystem,this.mode,this.emitProbability)}reset(){}setMatrixFromParticle(e,t){let n;if(t.rotation===void 0||this.useVelocityAsBasis)if(t.velocity.x===0&&t.velocity.y===0&&(t.velocity.z===1||t.velocity.z===0))e.set(1,0,0,t.position.x,0,1,0,t.position.y,0,0,1,t.position.z,0,0,0,1);else{this.v_.copy(na).cross(t.velocity),this.v2_.copy(t.velocity).cross(this.v_);const i=this.v_.length(),s=this.v2_.length();e.set(this.v_.x/i,this.v2_.x/s,t.velocity.x,t.position.x,this.v_.y/i,this.v2_.y/s,t.velocity.y,t.position.y,this.v_.z/i,this.v2_.z/s,t.velocity.z,t.position.z,0,0,0,1)}else t.rotation instanceof ie?n=t.rotation:(this.q_.setFromAxisAngle(na,t.rotation),n=this.q_),e.compose(t.position,n,Su);this.particleSystem.worldSpace||e.multiplyMatrices(this.particleSystem.emitter.matrixWorld,e)}}const Mu=.5*(Math.sqrt(3)-1),$n=(3-Math.sqrt(3))/6,Cu=1/3,Rt=1/6,wu=(Math.sqrt(5)-1)/4,Ne=(5-Math.sqrt(5))/20,Oe=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]),Me=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 ac{constructor(e=Math.random){const t=typeof e=="function"?e:Eu(e);this.p=Pu(t),this.perm=new Uint8Array(512),this.permMod12=new Uint8Array(512);for(let n=0;n<512;n++)this.perm[n]=this.p[n&255],this.permMod12[n]=this.perm[n]%12}noise2D(e,t){const n=this.permMod12,i=this.perm;let s=0,a=0,o=0;const c=(e+t)*Mu,l=Math.floor(e+c),u=Math.floor(t+c),f=(l+u)*$n,p=l-f,m=u-f,x=e-p,T=t-m;let g,v;x>T?(g=1,v=0):(g=0,v=1);const _=x-g+$n,b=T-v+$n,M=x-1+2*$n,C=T-1+2*$n,P=l&255,E=u&255;let z=.5-x*x-T*T;if(z>=0){const N=n[P+i[E]]*3;z*=z,s=z*z*(Oe[N]*x+Oe[N+1]*T)}let I=.5-_*_-b*b;if(I>=0){const N=n[P+g+i[E+v]]*3;I*=I,a=I*I*(Oe[N]*_+Oe[N+1]*b)}let R=.5-M*M-C*C;if(R>=0){const N=n[P+1+i[E+1]]*3;R*=R,o=R*R*(Oe[N]*M+Oe[N+1]*C)}return 70*(s+a+o)}noise3D(e,t,n){const i=this.permMod12,s=this.perm;let a,o,c,l;const u=(e+t+n)*Cu,f=Math.floor(e+u),p=Math.floor(t+u),m=Math.floor(n+u),x=(f+p+m)*Rt,T=f-x,g=p-x,v=m-x,_=e-T,b=t-g,M=n-v;let C,P,E,z,I,R;_>=b?b>=M?(C=1,P=0,E=0,z=1,I=1,R=0):_>=M?(C=1,P=0,E=0,z=1,I=0,R=1):(C=0,P=0,E=1,z=1,I=0,R=1):b<M?(C=0,P=0,E=1,z=0,I=1,R=1):_<M?(C=0,P=1,E=0,z=0,I=1,R=1):(C=0,P=1,E=0,z=1,I=1,R=0);const N=_-C+Rt,O=b-P+Rt,U=M-E+Rt,L=_-z+2*Rt,J=b-I+2*Rt,$=M-R+2*Rt,K=_-1+3*Rt,W=b-1+3*Rt,me=M-1+3*Rt,ne=f&255,ue=p&255,re=m&255;let ge=.6-_*_-b*b-M*M;if(ge<0)a=0;else{const oe=i[ne+s[ue+s[re]]]*3;ge*=ge,a=ge*ge*(Oe[oe]*_+Oe[oe+1]*b+Oe[oe+2]*M)}let be=.6-N*N-O*O-U*U;if(be<0)o=0;else{const oe=i[ne+C+s[ue+P+s[re+E]]]*3;be*=be,o=be*be*(Oe[oe]*N+Oe[oe+1]*O+Oe[oe+2]*U)}let se=.6-L*L-J*J-$*$;if(se<0)c=0;else{const oe=i[ne+z+s[ue+I+s[re+R]]]*3;se*=se,c=se*se*(Oe[oe]*L+Oe[oe+1]*J+Oe[oe+2]*$)}let he=.6-K*K-W*W-me*me;if(he<0)l=0;else{const oe=i[ne+1+s[ue+1+s[re+1]]]*3;he*=he,l=he*he*(Oe[oe]*K+Oe[oe+1]*W+Oe[oe+2]*me)}return 32*(a+o+c+l)}noise4D(e,t,n,i){const s=this.perm;let a,o,c,l,u;const f=(e+t+n+i)*wu,p=Math.floor(e+f),m=Math.floor(t+f),x=Math.floor(n+f),T=Math.floor(i+f),g=(p+m+x+T)*Ne,v=p-g,_=m-g,b=x-g,M=T-g,C=e-v,P=t-_,E=n-b,z=i-M;let I=0,R=0,N=0,O=0;C>P?I++:R++,C>E?I++:N++,C>z?I++:O++,P>E?R++:N++,P>z?R++:O++,E>z?N++:O++;const U=I>=3?1:0,L=R>=3?1:0,J=N>=3?1:0,$=O>=3?1:0,K=I>=2?1:0,W=R>=2?1:0,me=N>=2?1:0,ne=O>=2?1:0,ue=I>=1?1:0,re=R>=1?1:0,ge=N>=1?1:0,be=O>=1?1:0,se=C-U+Ne,he=P-L+Ne,oe=E-J+Ne,Xe=z-$+Ne,Ve=C-K+2*Ne,Je=P-W+2*Ne,Ye=E-me+2*Ne,xe=z-ne+2*Ne,ye=C-ue+3*Ne,ae=P-re+3*Ne,ut=E-ge+3*Ne,ke=z-be+3*Ne,fe=C-1+4*Ne,it=P-1+4*Ne,vt=E-1+4*Ne,St=z-1+4*Ne,rt=p&255,xt=m&255,ht=x&255,ft=T&255;let _t=.6-C*C-P*P-E*E-z*z;if(_t<0)a=0;else{const Q=s[rt+s[xt+s[ht+s[ft]]]]%32*4;_t*=_t,a=_t*_t*(Me[Q]*C+Me[Q+1]*P+Me[Q+2]*E+Me[Q+3]*z)}let Re=.6-se*se-he*he-oe*oe-Xe*Xe;if(Re<0)o=0;else{const Q=s[rt+U+s[xt+L+s[ht+J+s[ft+$]]]]%32*4;Re*=Re,o=Re*Re*(Me[Q]*se+Me[Q+1]*he+Me[Q+2]*oe+Me[Q+3]*Xe)}let Ze=.6-Ve*Ve-Je*Je-Ye*Ye-xe*xe;if(Ze<0)c=0;else{const Q=s[rt+K+s[xt+W+s[ht+me+s[ft+ne]]]]%32*4;Ze*=Ze,c=Ze*Ze*(Me[Q]*Ve+Me[Q+1]*Je+Me[Q+2]*Ye+Me[Q+3]*xe)}let ct=.6-ye*ye-ae*ae-ut*ut-ke*ke;if(ct<0)l=0;else{const Q=s[rt+ue+s[xt+re+s[ht+ge+s[ft+be]]]]%32*4;ct*=ct,l=ct*ct*(Me[Q]*ye+Me[Q+1]*ae+Me[Q+2]*ut+Me[Q+3]*ke)}let Ke=.6-fe*fe-it*it-vt*vt-St*St;if(Ke<0)u=0;else{const Q=s[rt+1+s[xt+1+s[ht+1+s[ft+1]]]]%32*4;Ke*=Ke,u=Ke*Ke*(Me[Q]*fe+Me[Q+1]*it+Me[Q+2]*vt+Me[Q+3]*St)}return 27*(a+o+c+l+u)}}function Pu(r){const e=new Uint8Array(256);for(let t=0;t<256;t++)e[t]=t;for(let t=0;t<255;t++){const n=t+~~(r()*(256-t)),i=e[t];e[t]=e[n],e[n]=i}return e}function Eu(r){let e=0,t=0,n=0,i=1;const s=ku();return e=s(" "),t=s(" "),n=s(" "),e-=s(r),e<0&&(e+=1),t-=s(r),t<0&&(t+=1),n-=s(r),n<0&&(n+=1),function(){const a=2091639*e+i*23283064365386963e-26;return e=t,t=n,n=a-(i=a|0)}}function ku(){let r=4022871197;return function(e){e=e.toString();for(let t=0;t<e.length;t++){r+=e.charCodeAt(t);let n=.02519603282416938*r;r=n>>>0,n-=r,n*=r,r=n>>>0,n-=r,r+=n*4294967296}return(r>>>0)*23283064365386963e-26}}class Bi{constructor(e,t,n,i){this.scale=e,this.octaves=t,this.velocityMultiplier=n,this.timeScale=i,this.type="TurbulenceField",this.generator=new ac,this.timeOffset=new G,this.temp=new G,this.temp2=new G,this.timeOffset.x=Math.random()/this.scale.x*this.timeScale.x,this.timeOffset.y=Math.random()/this.scale.y*this.timeScale.y,this.timeOffset.z=Math.random()/this.scale.z*this.timeScale.z}initialize(e){}update(e,t){const n=e.position.x/this.scale.x,i=e.position.y/this.scale.y,s=e.position.z/this.scale.z;this.temp.set(0,0,0);let a=1;for(let o=0;o<this.octaves;o++)this.temp2.set(this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.x*a)/a,this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.y*a)/a,this.generator.noise4D(n*a,i*a,s*a,this.timeOffset.z*a)/a),this.temp.add(this.temp2),a*=2;this.temp.multiply(this.velocityMultiplier),e.velocity.addScaledVector(this.temp,t)}toJSON(){return{type:this.type,scale:[this.scale.x,this.scale.y,this.scale.z],octaves:this.octaves,velocityMultiplier:[this.velocityMultiplier.x,this.velocityMultiplier.y,this.velocityMultiplier.z],timeScale:[this.timeScale.x,this.timeScale.y,this.timeScale.z]}}frameUpdate(e){this.timeOffset.x+=e*this.timeScale.x,this.timeOffset.y+=e*this.timeScale.y,this.timeOffset.z+=e*this.timeScale.z}static fromJSON(e){return new Bi(new G(e.scale[0],e.scale[1],e.scale[2]),e.octaves,new G(e.velocityMultiplier[0],e.velocityMultiplier[1],e.velocityMultiplier[2]),new G(e.timeScale[0],e.timeScale[1],e.timeScale[2]))}clone(){return new Bi(this.scale.clone(),this.octaves,this.velocityMultiplier.clone(),this.timeScale.clone())}reset(){}}const At=[],gs=new G,vs=new ie;class Ni{constructor(e,t,n=new ee(1),i=new ee(0)){if(this.frequency=e,this.power=t,this.positionAmount=n,this.rotationAmount=i,this.type="Noise",this.duration=0,At.length===0)for(let s=0;s<100;s++)At.push(new ac)}initialize(e){e.lastPosNoise=new G,typeof e.rotation=="number"?e.lastRotNoise=0:e.lastRotNoise=new ie,e.generatorIndex=[nr(0,100),nr(0,100),nr(0,100),nr(0,100)],this.positionAmount.startGen(e.memory),this.rotationAmount.startGen(e.memory),this.frequency.startGen(e.memory),this.power.startGen(e.memory)}update(e,t){let n=this.frequency.genValue(e.memory,e.age/e.life),i=this.power.genValue(e.memory,e.age/e.life),s=this.positionAmount.genValue(e.memory,e.age/e.life),a=this.rotationAmount.genValue(e.memory,e.age/e.life);s>0&&e.lastPosNoise!==void 0&&(e.position.sub(e.lastPosNoise),gs.set(At[e.generatorIndex[0]].noise2D(0,e.age*n)*i*s,At[e.generatorIndex[1]].noise2D(0,e.age*n)*i*s,At[e.generatorIndex[2]].noise2D(0,e.age*n)*i*s),e.position.add(gs),e.lastPosNoise.copy(gs)),a>0&&e.lastRotNoise!==void 0&&(typeof e.rotation=="number"?(e.rotation-=e.lastRotNoise,e.rotation+=At[e.generatorIndex[3]].noise2D(0,e.age*n)*Math.PI*i*a):(e.lastRotNoise.invert(),e.rotation.multiply(e.lastRotNoise),vs.set(At[e.generatorIndex[0]].noise2D(0,e.age*n)*i*a,At[e.generatorIndex[1]].noise2D(0,e.age*n)*i*a,At[e.generatorIndex[2]].noise2D(0,e.age*n)*i*a,At[e.generatorIndex[3]].noise2D(0,e.age*n)*i*a).normalize(),e.rotation.multiply(vs),e.lastRotNoise.copy(vs)))}toJSON(){return{type:this.type,frequency:this.frequency.toJSON(),power:this.power.toJSON(),positionAmount:this.positionAmount.toJSON(),rotationAmount:this.rotationAmount.toJSON()}}frameUpdate(e){this.duration+=e}static fromJSON(e){return new Ni(Z(e.frequency),Z(e.power),Z(e.positionAmount),Z(e.rotationAmount))}clone(){return new Ni(this.frequency.clone(),this.power.clone(),this.positionAmount.clone(),this.rotationAmount.clone())}reset(){}}class Ui{constructor(e,t){this.color=e,this.speedRange=t,this.type="ColorBySpeed"}initialize(e){this.color.startGen(e.memory)}update(e,t){const n=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);this.color.genColor(e.memory,e.color,n),e.color.x*=e.startColor.x,e.color.y*=e.startColor.y,e.color.z*=e.startColor.z,e.color.w*=e.startColor.w}frameUpdate(e){}toJSON(){return{type:this.type,color:this.color.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Ui(co(e.color),Sn.fromJSON(e.speedRange))}clone(){return new Ui(this.color.clone(),this.speedRange.clone())}reset(){}}class Di{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 xn?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 Di(Ir(e.size),Sn.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Di(this.size.clone(),this.speedRange.clone())}reset(){}}class Fi{constructor(e,t){this.angularVelocity=e,this.speedRange=t,this.type="RotationBySpeed",this.tempQuat=new ie}initialize(e){typeof e.rotation=="number"&&this.angularVelocity.startGen(e.memory)}update(e,t){if(typeof e.rotation=="number"){const n=(e.startSpeed-this.speedRange.a)/(this.speedRange.b-this.speedRange.a);e.rotation+=t*this.angularVelocity.genValue(e.memory,n)}}toJSON(){return{type:this.type,angularVelocity:this.angularVelocity.toJSON(),speedRange:this.speedRange.toJSON()}}static fromJSON(e){return new Fi(Z(e.angularVelocity),Sn.fromJSON(e.speedRange))}frameUpdate(e){}clone(){return new Fi(this.angularVelocity.clone(),this.speedRange.clone())}reset(){}}class Li{initialize(e){this.speed.startGen(e.memory)}constructor(e,t){this.speed=e,this.dampen=t,this.type="LimitSpeedOverLife"}update(e,t){let n=e.velocity.length(),i=this.speed.genValue(e.memory,e.age/e.life);if(n>i){const s=(n-i)/n;e.velocity.multiplyScalar(1-s*this.dampen*t*20)}}toJSON(){return{type:this.type,speed:this.speed.toJSON(),dampen:this.dampen}}static fromJSON(e){return new Li(Z(e.speed),e.dampen)}frameUpdate(e){}clone(){return new Li(this.speed.clone(),this.dampen)}reset(){}}const Nr={ApplyForce:{type:"ApplyForce",constructor:Ai,params:[["direction",["vec3"]],["magnitude",["value"]]],loadJSON:Ai.fromJSON},Noise:{type:"Noise",constructor:Ni,params:[["frequency",["value"]],["power",["value"]],["positionAmount",["value"]],["rotationAmount",["value"]]],loadJSON:Ni.fromJSON},TurbulenceField:{type:"TurbulenceField",constructor:Bi,params:[["scale",["vec3"]],["octaves",["number"]],["velocityMultiplier",["vec3"]],["timeScale",["vec3"]]],loadJSON:Bi.fromJSON},GravityForce:{type:"GravityForce",constructor:Oi,params:[["center",["vec3"]],["magnitude",["number"]]],loadJSON:Oi.fromJSON},ColorOverLife:{type:"ColorOverLife",constructor:bi,params:[["color",["colorFunc"]]],loadJSON:bi.fromJSON},RotationOverLife:{type:"RotationOverLife",constructor:Ti,params:[["angularVelocity",["value","valueFunc"]]],loadJSON:Ti.fromJSON},Rotation3DOverLife:{type:"Rotation3DOverLife",constructor:Mi,params:[["angularVelocity",["rotationFunc"]]],loadJSON:Mi.fromJSON},SizeOverLife:{type:"SizeOverLife",constructor:wi,params:[["size",["value","valueFunc","vec3Func"]]],loadJSON:wi.fromJSON},ColorBySpeed:{type:"ColorBySpeed",constructor:Ui,params:[["color",["colorFunc"]],["speedRange",["range"]]],loadJSON:Ui.fromJSON},RotationBySpeed:{type:"RotationBySpeed",constructor:Fi,params:[["angularVelocity",["value","valueFunc"]],["speedRange",["range"]]],loadJSON:Fi.fromJSON},SizeBySpeed:{type:"SizeBySpeed",constructor:Di,params:[["size",["value","valueFunc","vec3Func"]],["speedRange",["range"]]],loadJSON:Di.fromJSON},SpeedOverLife:{type:"SpeedOverLife",constructor:Pi,params:[["speed",["value","valueFunc"]]],loadJSON:Pi.fromJSON},FrameOverLife:{type:"FrameOverLife",constructor:Ei,params:[["frame",["value","valueFunc"]]],loadJSON:Ei.fromJSON},ForceOverLife:{type:"ForceOverLife",constructor:Ci,params:[["x",["value","valueFunc"]],["y",["value","valueFunc"]],["z",["value","valueFunc"]]],loadJSON:Ci.fromJSON},OrbitOverLife:{type:"OrbitOverLife",constructor:ki,params:[["orbitSpeed",["value","valueFunc"]],["axis",["vec3"]]],loadJSON:ki.fromJSON},WidthOverLength:{type:"WidthOverLength",constructor:Ri,params:[["width",["value","valueFunc"]]],loadJSON:Ri.fromJSON},ChangeEmitDirection:{type:"ChangeEmitDirection",constructor:zi,params:[["angle",["value"]]],loadJSON:zi.fromJSON},EmitSubParticleSystem:{type:"EmitSubParticleSystem",constructor:Ii,params:[["particleSystem",["self"]],["useVelocityAsBasis",["boolean"]],["subParticleSystem",["particleSystem"]],["mode",["number"]],["emitProbability",["number"]]],loadJSON:Ii.fromJSON},LimitSpeedOverLife:{type:"LimitSpeedOverLife",constructor:Li,params:[["speed",["value","valueFunc"]],["dampen",["number"]]],loadJSON:Li.fromJSON}};function Ru(r,e){return Nr[r.type]?Nr[r.type].loadJSON(r,e):null}const Au=[];function Ou(r){if(!Au.find(t=>t.id===r.id)){for(const t of r.emitterShapes)Fs[t.type]||(Fs[t.type]=t);for(const t of r.behaviors)Nr[t.type]||(Nr[t.type]=t)}}var zu=`
2
2
  #ifdef SOFT_PARTICLES
3
3
 
4
4
  /* #ifdef LOGDEPTH
@@ -1113,4 +1113,4 @@ a=extmap-allow-mixed`)!==-1){const s=i.sdp.split(`
1113
1113
  isIOS:`).concat(this.isIOS,`
1114
1114
  isWebRTCSupported:`).concat(this.isWebRTCSupported(),`
1115
1115
  isBrowserSupported:`).concat(this.isBrowserSupported(),`
1116
- isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},r})()),va={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"},bh=(function(){function r(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=va,this.browser=Hn.getBrowser(),this.browserVersion=Hn.getVersion(),this.supports=(function(){var e={browser:Hn.isBrowserSupported(),webRTC:Hn.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(va),e.audioVideo=!0;var n=void 0;try{n=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!n.ordered;try{n.binaryType="blob",e.binaryBlob=!Hn.isIOS}catch{}}catch{}finally{n&&n.close()}}catch{}finally{t&&t.close()}return e})(),this.pack=aa.pack,this.unpack=aa.unpack,this._dataCount=1}return r.prototype.noop=function(){},r.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},r.prototype.chunk=function(e){for(var t=[],n=e.size,i=Math.ceil(n/te.chunkedMTU),s=0,a=0;a<n;){var o=Math.min(n,a+te.chunkedMTU),c=e.slice(a,o),l={__peerData:this._dataCount,n:s,data:c,total:i};t.push(l),a=o,s++}return this._dataCount++,t},r.prototype.blobToArrayBuffer=function(e,t){var n=new FileReader;return n.onload=function(i){i.target&&t(i.target.result)},n.readAsArrayBuffer(e),n},r.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t.buffer},r.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},r.prototype.isSecure=function(){return location.protocol==="https:"},r})(),te=new bh,Wc={};Bt(Wc,"Peer",()=>Xs,r=>Xs=r);var Gi={},Th=Object.prototype.hasOwnProperty,nt="~";function Ji(){}Object.create&&(Ji.prototype=Object.create(null),new Ji().__proto__||(nt=!1));function Mh(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function $c(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new Mh(t,n||r,i),a=nt?nt+e:e;return r._events[a]?r._events[a].fn?r._events[a]=[r._events[a],s]:r._events[a].push(s):(r._events[a]=s,r._eventsCount++),r}function Er(r,e){--r._eventsCount===0?r._events=new Ji:delete r._events[e]}function He(){this._events=new Ji,this._eventsCount=0}He.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Th.call(t,n)&&e.push(nt?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};He.prototype.listeners=function(e){var t=nt?nt+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,a=new Array(s);i<s;i++)a[i]=n[i].fn;return a};He.prototype.listenerCount=function(e){var t=nt?nt+e:e,n=this._events[t];return n?n.fn?1:n.length:0};He.prototype.emit=function(e,t,n,i,s,a){var o=nt?nt+e:e;if(!this._events[o])return!1;var c=this._events[o],l=arguments.length,u,f;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,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,s),!0;case 6:return c.fn.call(c.context,t,n,i,s,a),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var p=c.length,m;for(f=0;f<p;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,i);break;default:if(!u)for(m=1,u=new Array(l-1);m<l;m++)u[m-1]=arguments[m];c[f].fn.apply(c[f].context,u)}}return!0};He.prototype.on=function(e,t,n){return $c(this,e,t,n,!1)};He.prototype.once=function(e,t,n){return $c(this,e,t,n,!0)};He.prototype.removeListener=function(e,t,n,i){var s=nt?nt+e:e;if(!this._events[s])return this;if(!t)return Er(this,s),this;var a=this._events[s];if(a.fn)a.fn===t&&(!i||a.once)&&(!n||a.context===n)&&Er(this,s);else{for(var o=0,c=[],l=a.length;o<l;o++)(a[o].fn!==t||i&&!a[o].once||n&&a[o].context!==n)&&c.push(a[o]);c.length?this._events[s]=c.length===1?c[0]:c:Er(this,s)}return this};He.prototype.removeAllListeners=function(e){var t;return e?(t=nt?nt+e:e,this._events[t]&&Er(this,t)):(this._events=new Ji,this._eventsCount=0),this};He.prototype.off=He.prototype.removeListener;He.prototype.addListener=He.prototype.on;He.prefixed=nt;He.EventEmitter=He;Gi=He;var j={};Bt(j,"LogLevel",()=>ot,r=>ot=r);Bt(j,"default",()=>Sa,r=>Sa=r);var an=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},cn=function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},Ch="PeerJS: ",ot;(function(r){r[r.Disabled=0]="Disabled",r[r.Errors=1]="Errors",r[r.Warnings=2]="Warnings",r[r.All=3]="All"})(ot||(ot={}));var wh=(function(){function r(){this._logLevel=ot.Disabled}return Object.defineProperty(r.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),r.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=ot.All&&this._print.apply(this,cn([ot.All],an(e),!1))},r.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=ot.Warnings&&this._print.apply(this,cn([ot.Warnings],an(e),!1))},r.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=ot.Errors&&this._print.apply(this,cn([ot.Errors],an(e),!1))},r.prototype.setLogFunction=function(e){this._print=e},r.prototype._print=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var i=cn([Ch],an(t),!1);for(var s in i)i[s]instanceof Error&&(i[s]="("+i[s].name+") "+i[s].message);e>=ot.All?console.log.apply(console,cn([],an(i),!1)):e>=ot.Warnings?console.warn.apply(console,cn(["WARNING"],an(i),!1)):e>=ot.Errors&&console.error.apply(console,cn(["ERROR"],an(i),!1))},r})(),Sa=new wh,Hc={};Bt(Hc,"Socket",()=>xa,r=>xa=r);var Pt;(function(r){r.Data="data",r.Media="media"})(Pt||(Pt={}));var _e;(function(r){r.BrowserIncompatible="browser-incompatible",r.Disconnected="disconnected",r.InvalidID="invalid-id",r.InvalidKey="invalid-key",r.Network="network",r.PeerUnavailable="peer-unavailable",r.SslUnavailable="ssl-unavailable",r.ServerError="server-error",r.SocketError="socket-error",r.SocketClosed="socket-closed",r.UnavailableID="unavailable-id",r.WebRTC="webrtc"})(_e||(_e={}));var jt;(function(r){r.Binary="binary",r.BinaryUTF8="binary-utf8",r.JSON="json"})(jt||(jt={}));var $t;(function(r){r.Message="message",r.Disconnected="disconnected",r.Error="error",r.Close="close"})($t||($t={}));var Le;(function(r){r.Heartbeat="HEARTBEAT",r.Candidate="CANDIDATE",r.Offer="OFFER",r.Answer="ANSWER",r.Open="OPEN",r.Error="ERROR",r.IdTaken="ID-TAKEN",r.InvalidKey="INVALID-KEY",r.Leave="LEAVE",r.Expire="EXPIRE"})(Le||(Le={}));var po={};po=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 Ph=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Eh=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},kh=function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},Rh=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},xa=(function(r){Ph(e,r);function e(t,n,i,s,a,o){o===void 0&&(o=5e3);var c=r.call(this)||this;c.pingInterval=o,c._disconnected=!0,c._messagesQueue=[];var l=t?"wss://":"ws://";return c._baseUrl=l+n+":"+i+s+"peerjs?key="+a,c}return e.prototype.start=function(t,n){var i=this;this._id=t;var s="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(n);this._socket||!this._disconnected||(this._socket=new WebSocket(s+"&version="+po.version),this._disconnected=!1,this._socket.onmessage=function(a){var o;try{o=JSON.parse(a.data),j.default.log("Server message received:",o)}catch{j.default.log("Invalid server message",a.data);return}i.emit($t.Message,o)},this._socket.onclose=function(a){i._disconnected||(j.default.log("Socket closed.",a),i._cleanup(),i._disconnected=!0,i.emit($t.Disconnected))},this._socket.onopen=function(){i._disconnected||(i._sendQueuedMessages(),j.default.log("Socket open"),i._scheduleHeartbeat())})},e.prototype._scheduleHeartbeat=function(){var t=this;this._wsPingTimer=setTimeout(function(){t._sendHeartbeat()},this.pingInterval)},e.prototype._sendHeartbeat=function(){if(!this._wsOpen()){j.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:Le.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,n,i=kh([],Eh(this._messagesQueue),!1);this._messagesQueue=[];try{for(var s=Rh(i),a=s.next();!a.done;a=s.next()){var o=a.value;this.send(o)}}catch(c){t={error:c}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},e.prototype.send=function(t){if(!this._disconnected){if(!this._id){this._messagesQueue.push(t);return}if(!t.type){this.emit($t.Error,"Invalid message");return}if(this._wsOpen()){var n=JSON.stringify(t);this._socket.send(n)}}},e.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},e.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)},e})(Gi.EventEmitter),Hs={};Bt(Hs,"MediaConnection",()=>Ta,r=>Ta=r);var mo={};Bt(mo,"Negotiator",()=>_a,r=>_a=r);var Dr=function(){return Dr=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},Dr.apply(this,arguments)},sr=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(n.next(u))}catch(f){a(f)}}function c(u){try{l(n.throw(u))}catch(f){a(f)}}function l(u){u.done?s(u.value):i(u.value).then(o,c)}l((n=n.apply(r,e||[])).next())})},or=function(r,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(s=l[0]&2?i.return:l[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,l[1])).done)return s;switch(i=0,s&&(l=[l[0]&2,s.value]),l[0]){case 0:case 1:s=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,i=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!s||l[1]>s[0]&&l[1]<s[3])){t.label=l[1];break}if(l[0]===6&&t.label<s[1]){t.label=s[1],s=l;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(l);break}s[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(u){l=[6,u],i=0}finally{n=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},_a=(function(){function r(e){this.connection=e}return r.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===Pt.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===Pt.Data){var n=this.connection,i={ordered:!!e.reliable},s=t.createDataChannel(n.label,i);n.initialize(s)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},r.prototype._startPeerConnection=function(){j.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},r.prototype._setupListeners=function(e){var t=this,n=this.connection.peer,i=this.connection.connectionId,s=this.connection.type,a=this.connection.provider;j.default.log("Listening for ICE candidates."),e.onicecandidate=function(o){!o.candidate||!o.candidate.candidate||(j.default.log("Received ICE candidates for ".concat(n,":"),o.candidate),a.socket.send({type:Le.Candidate,payload:{candidate:o.candidate,type:s,connectionId:i},dst:n}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":j.default.log("iceConnectionState is failed, closing connections to "+n),t.connection.emit("error",new Error("Negotiation of connection to "+n+" failed.")),t.connection.close();break;case"closed":j.default.log("iceConnectionState is closed, closing connections to "+n),t.connection.emit("error",new Error("Connection to "+n+" closed.")),t.connection.close();break;case"disconnected":j.default.log("iceConnectionState changed to disconnected on the connection with "+n);break;case"completed":e.onicecandidate=te.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},j.default.log("Listening for data channel"),e.ondatachannel=function(o){j.default.log("Received data channel");var c=o.channel,l=a.getConnection(n,i);l.initialize(c)},j.default.log("Listening for remote stream"),e.ontrack=function(o){j.default.log("Received remote stream");var c=o.streams[0],l=a.getConnection(n,i);if(l.type===Pt.Media){var u=l;t._addStreamToMediaConnection(c,u)}}},r.prototype.cleanup=function(){j.default.log("Cleaning up PeerConnection to "+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!=="closed",n=!1;if(this.connection.type===Pt.Data){var i=this.connection,s=i.dataChannel;s&&(n=!!s.readyState&&s.readyState!=="closed")}(t||n)&&e.close()}},r.prototype._makeOffer=function(){return sr(this,void 0,Promise,function(){var e,t,n,i,s,a,o;return or(this,function(c){switch(c.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,c.label=1;case 1:return c.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:n=c.sent(),j.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),c.label=3;case 3:return c.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return c.sent(),j.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),i={sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:te.browser},this.connection.type===Pt.Data&&(s=this.connection,i=Dr(Dr({},i),{label:s.label,reliable:s.reliable,serialization:s.serialization})),t.socket.send({type:Le.Offer,payload:i,dst:this.connection.peer}),[3,6];case 5:return a=c.sent(),a!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(t.emitError(_e.WebRTC,a),j.default.log("Failed to setLocalDescription, ",a)),[3,6];case 6:return[3,8];case 7:return o=c.sent(),t.emitError(_e.WebRTC,o),j.default.log("Failed to createOffer, ",o),[3,8];case 8:return[2]}})})},r.prototype._makeAnswer=function(){return sr(this,void 0,Promise,function(){var e,t,n,i,s;return or(this,function(a){switch(a.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,a.label=1;case 1:return a.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:n=a.sent(),j.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),a.label=3;case 3:return a.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return a.sent(),j.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),t.socket.send({type:Le.Answer,payload:{sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,browser:te.browser},dst:this.connection.peer}),[3,6];case 5:return i=a.sent(),t.emitError(_e.WebRTC,i),j.default.log("Failed to setLocalDescription, ",i),[3,6];case 6:return[3,8];case 7:return s=a.sent(),t.emitError(_e.WebRTC,s),j.default.log("Failed to create answer, ",s),[3,8];case 8:return[2]}})})},r.prototype.handleSDP=function(e,t){return sr(this,void 0,Promise,function(){var n,i,s,a;return or(this,function(o){switch(o.label){case 0:t=new RTCSessionDescription(t),n=this.connection.peerConnection,i=this.connection.provider,j.default.log("Setting remote description",t),s=this,o.label=1;case 1:return o.trys.push([1,5,,6]),[4,n.setRemoteDescription(t)];case 2:return o.sent(),j.default.log("Set remoteDescription:".concat(e," for:").concat(this.connection.peer)),e!=="OFFER"?[3,4]:[4,s._makeAnswer()];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:return a=o.sent(),i.emitError(_e.WebRTC,a),j.default.log("Failed to setRemoteDescription, ",a),[3,6];case 6:return[2]}})})},r.prototype.handleCandidate=function(e){return sr(this,void 0,Promise,function(){var t,n,i,s,a,o;return or(this,function(c){switch(c.label){case 0:j.default.log("handleCandidate:",e),t=e.candidate,n=e.sdpMLineIndex,i=e.sdpMid,s=this.connection.peerConnection,a=this.connection.provider,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,s.addIceCandidate(new RTCIceCandidate({sdpMid:i,sdpMLineIndex:n,candidate:t}))];case 2:return c.sent(),j.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return o=c.sent(),a.emitError(_e.WebRTC,o),j.default.log("Failed to handleCandidate, ",o),[3,4];case 4:return[2]}})})},r.prototype._addTracksToConnection=function(e,t){if(j.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return j.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(n){t.addTrack(n,e)})},r.prototype._addStreamToMediaConnection=function(e,t){j.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},r})(),yo={};Bt(yo,"BaseConnection",()=>ba,r=>ba=r);var Ah=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),ba=(function(r){Ah(e,r);function e(t,n,i){var s=r.call(this)||this;return s.peer=t,s.provider=n,s.options=i,s._open=!1,s.metadata=i.metadata,s}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e})(Gi.EventEmitter),Oh=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Fr=function(){return Fr=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},Fr.apply(this,arguments)},zh=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ta=(function(r){Oh(e,r);function e(t,n,i){var s=r.call(this,t,n,i)||this;return s._localStream=s.options._stream,s.connectionId=s.options.connectionId||e.ID_PREFIX+te.randomToken(),s._negotiator=new mo.Negotiator(s),s._localStream&&s._negotiator.startConnection({_stream:s._localStream,originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return Pt.Media},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localStream",{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteStream",{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),e.prototype.addStream=function(t){j.default.log("Receiving stream",t),this._remoteStream=t,r.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var n=t.type,i=t.payload;switch(t.type){case Le.Answer:this._negotiator.handleSDP(n,i.sdp),this._open=!0;break;case Le.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:j.default.warn("Unrecognized message type:".concat(n," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,n){var i,s;if(n===void 0&&(n={}),this._localStream){j.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,n&&n.sdpTransform&&(this.options.sdpTransform=n.sdpTransform),this._negotiator.startConnection(Fr(Fr({},this.options._payload),{_stream:t}));var a=this.provider._getMessages(this.connectionId);try{for(var o=zh(a),c=o.next();!c.done;c=o.next()){var l=c.value;this.handleMessage(l)}}catch(u){i={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}this._open=!0},e.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,r.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e})(yo.BaseConnection),qs={};Bt(qs,"DataConnection",()=>Ca,r=>Ca=r);var qc={};Bt(qc,"EncodingQueue",()=>Ma,r=>Ma=r);var Ih=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Ma=(function(r){Ih(e,r);function e(){var t=r.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(n){t._processing=!1,n.target&&t.emit("done",n.target.result),t.doNextTask()},t.fileReader.onerror=function(n){j.default.error("EncodingQueue error:",n),t._processing=!1,t.destroy(),t.emit("error",n)},t}return Object.defineProperty(e.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),e.prototype.enque=function(t){this.queue.push(t),!this.processing&&this.doNextTask()},e.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},e.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},e})(Gi.EventEmitter),Bh=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Nh=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ca=(function(r){Bh(e,r);function e(t,n,i){var s=r.call(this,t,n,i)||this;return s.stringify=JSON.stringify,s.parse=JSON.parse,s._buffer=[],s._bufferSize=0,s._buffering=!1,s._chunkedData={},s._encodingQueue=new qc.EncodingQueue,s.connectionId=s.options.connectionId||e.ID_PREFIX+te.randomToken(),s.label=s.options.label||s.connectionId,s.serialization=s.options.serialization||jt.Binary,s.reliable=!!s.options.reliable,s._encodingQueue.on("done",function(a){s._bufferedSend(a)}),s._encodingQueue.on("error",function(){j.default.error("DC#".concat(s.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),s.close()}),s._negotiator=new mo.Negotiator(s),s._negotiator.startConnection(s.options._payload||{originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return Pt.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;(!te.supports.binaryBlob||te.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){j.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(n){j.default.log("DC#".concat(t.connectionId," dc onmessage:"),n.data),t._handleDataMessage(n)},this.dataChannel.onclose=function(){j.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var n=this,i=t.data,s=i.constructor,a=this.serialization===jt.Binary||this.serialization===jt.BinaryUTF8,o=i;if(a){if(s===Blob){te.blobToArrayBuffer(i,function(l){var u=te.unpack(l);n.emit("data",u)});return}else if(s===ArrayBuffer)o=te.unpack(i);else if(s===String){var c=te.binaryStringToArrayBuffer(i);o=te.unpack(c)}}else this.serialization===jt.JSON&&(o=this.parse(i));if(o.__peerData){this._handleChunk(o);return}r.prototype.emit.call(this,"data",o)},e.prototype._handleChunk=function(t){var n=t.__peerData,i=this._chunkedData[n]||{data:[],count:0,total:t.total};if(i.data[t.n]=t.data,i.count++,this._chunkedData[n]=i,i.total===i.count){delete this._chunkedData[n];var s=new Blob(i.data);this._handleDataMessage({data:s})}},e.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),this._encodingQueue=null),this.open&&(this._open=!1,r.prototype.emit.call(this,"close"))},e.prototype.send=function(t,n){if(!this.open){r.prototype.emit.call(this,"error",new Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===jt.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===jt.Binary||this.serialization===jt.BinaryUTF8){var i=te.pack(t);if(!n&&i.size>te.chunkedMTU){this._sendChunks(i);return}te.supports.binaryBlob?this._bufferedSend(i):this._encodingQueue.enque(i)}else this._bufferedSend(t)},e.prototype._bufferedSend=function(t){(this._buffering||!this._trySend(t))&&(this._buffer.push(t),this._bufferSize=this._buffer.length)},e.prototype._trySend=function(t){var n=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){n._buffering=!1,n._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(i){return j.default.error("DC#:".concat(this.connectionId," Error when sending:"),i),this._buffering=!0,this.close(),!1}return!0},e.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},e.prototype._sendChunks=function(t){var n,i,s=te.chunk(t);j.default.log("DC#".concat(this.connectionId," Try to send ").concat(s.length," chunks..."));try{for(var a=Nh(s),o=a.next();!o.done;o=a.next()){var c=o.value;this.send(c,!0)}}catch(l){n={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}},e.prototype.handleMessage=function(t){var n=t.payload;switch(t.type){case Le.Answer:this._negotiator.handleSDP(t.type,n.sdp);break;case Le.Candidate:this._negotiator.handleCandidate(n.candidate);break;default:j.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e})(yo.BaseConnection),Xc={};Bt(Xc,"API",()=>Ea,r=>Ea=r);var wa=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(n.next(u))}catch(f){a(f)}}function c(u){try{l(n.throw(u))}catch(f){a(f)}}function l(u){u.done?s(u.value):i(u.value).then(o,c)}l((n=n.apply(r,e||[])).next())})},Pa=function(r,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(s=l[0]&2?i.return:l[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,l[1])).done)return s;switch(i=0,s&&(l=[l[0]&2,s.value]),l[0]){case 0:case 1:s=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,i=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!s||l[1]>s[0]&&l[1]<s[3])){t.label=l[1];break}if(l[0]===6&&t.label<s[1]){t.label=s[1],s=l;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(l);break}s[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(u){l=[6,u],i=0}finally{n=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},Ea=(function(){function r(e){this._options=e}return r.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",n=this._options,i=n.host,s=n.port,a=n.path,o=n.key,c=new URL("".concat(t,"://").concat(i,":").concat(s).concat(a).concat(o,"/").concat(e));return c.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),c.searchParams.set("version",po.version),fetch(c.href,{referrerPolicy:this._options.referrerPolicy})},r.prototype.retrieveId=function(){return wa(this,void 0,Promise,function(){var e,t,n;return Pa(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=i.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=i.sent(),j.default.error("Error retrieving ID",t),n="",this._options.path==="/"&&this._options.host!==te.CLOUD_HOST&&(n=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+n);case 3:return[2]}})})},r.prototype.listAllPeers=function(){return wa(this,void 0,Promise,function(){var e,t,n;return Pa(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=i.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===te.CLOUD_HOST?t="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":t="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+t)):new Error("Error. Status:".concat(e.status));return[2,e.json()];case 2:throw n=i.sent(),j.default.error("Error retrieving list peers",n),new Error("Could not get list peers from the server."+n);case 3:return[2]}})})},r})(),Uh=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),ai=function(){return ai=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},ai.apply(this,arguments)},qn=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Dh=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},Xs=(function(r){Uh(e,r);function e(t,n){var i=r.call(this)||this;i._id=null,i._lastServerId=null,i._destroyed=!1,i._disconnected=!1,i._open=!1,i._connections=new Map,i._lostMessages=new Map;var s;return t&&t.constructor==Object?n=t:t&&(s=t.toString()),n=ai({debug:0,host:te.CLOUD_HOST,port:te.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:te.randomToken(),config:te.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},n),i._options=n,i._options.host==="/"&&(i._options.host=window.location.hostname),i._options.path&&(i._options.path[0]!=="/"&&(i._options.path="/"+i._options.path),i._options.path[i._options.path.length-1]!=="/"&&(i._options.path+="/")),i._options.secure===void 0&&i._options.host!==te.CLOUD_HOST?i._options.secure=te.isSecure():i._options.host==te.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&j.default.setLogFunction(i._options.logFunction),j.default.logLevel=i._options.debug||0,i._api=new Xc.API(n),i._socket=i._createServerConnection(),!te.supports.audioVideo&&!te.supports.data?(i._delayedAbort(_e.BrowserIncompatible,"The current browser does not support WebRTC"),i):s&&!te.validateId(s)?(i._delayedAbort(_e.InvalidID,'ID "'.concat(s,'" is invalid')),i):(s?i._initialize(s):i._api.retrieveId().then(function(a){return i._initialize(a)}).catch(function(a){return i._abort(_e.ServerError,a)}),i)}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){var t,n,i=Object.create(null);try{for(var s=qn(this._connections),a=s.next();!a.done;a=s.next()){var o=Dh(a.value,2),c=o[0],l=o[1];i[c]=l}}catch(u){t={error:u}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return i},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),e.prototype._createServerConnection=function(){var t=this,n=new Hc.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return n.on($t.Message,function(i){t._handleMessage(i)}),n.on($t.Error,function(i){t._abort(_e.SocketError,i)}),n.on($t.Disconnected,function(){t.disconnected||(t.emitError(_e.Network,"Lost connection to server."),t.disconnect())}),n.on($t.Close,function(){t.disconnected||t._abort(_e.SocketClosed,"Underlying socket is already closed.")}),n},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var n,i,s=t.type,a=t.payload,o=t.src;switch(s){case Le.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case Le.Error:this._abort(_e.ServerError,a.msg);break;case Le.IdTaken:this._abort(_e.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case Le.InvalidKey:this._abort(_e.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case Le.Leave:j.default.log("Received leave message from ".concat(o)),this._cleanupPeer(o),this._connections.delete(o);break;case Le.Expire:this.emitError(_e.PeerUnavailable,"Could not connect to peer ".concat(o));break;case Le.Offer:var x=a.connectionId,T=this.getConnection(o,x);if(T&&(T.close(),j.default.warn("Offer received for existing Connection ID:".concat(x))),a.type===Pt.Media){var c=new Hs.MediaConnection(o,this,{connectionId:x,_payload:a,metadata:a.metadata});T=c,this._addConnection(o,T),this.emit("call",c)}else if(a.type===Pt.Data){var l=new qs.DataConnection(o,this,{connectionId:x,_payload:a,metadata:a.metadata,label:a.label,serialization:a.serialization,reliable:a.reliable});T=l,this._addConnection(o,T),this.emit("connection",l)}else{j.default.warn("Received malformed connection type:".concat(a.type));return}var u=this._getMessages(x);try{for(var f=qn(u),p=f.next();!p.done;p=f.next()){var m=p.value;T.handleMessage(m)}}catch(g){n={error:g}}finally{try{p&&!p.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}break;default:if(!a){j.default.warn("You received a malformed message from ".concat(o," of type ").concat(s));return}var x=a.connectionId,T=this.getConnection(o,x);T&&T.peerConnection?T.handleMessage(t):x?this._storeMessage(x,t):j.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,n){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(n)},e.prototype._getMessages=function(t){var n=this._lostMessages.get(t);return n?(this._lostMessages.delete(t),n):[]},e.prototype.connect=function(t,n){if(n===void 0&&(n={}),this.disconnected){j.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),this.emitError(_e.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var i=new qs.DataConnection(t,this,n);return this._addConnection(t,i),i},e.prototype.call=function(t,n,i){if(i===void 0&&(i={}),this.disconnected){j.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),this.emitError(_e.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!n){j.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var s=new Hs.MediaConnection(t,this,ai(ai({},i),{_stream:n}));return this._addConnection(t,s),s},e.prototype._addConnection=function(t,n){j.default.log("add connection ".concat(n.type,":").concat(n.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(n)},e.prototype._removeConnection=function(t){var n=this._connections.get(t.peer);if(n){var i=n.indexOf(t);i!==-1&&n.splice(i,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,n){var i,s,a=this._connections.get(t);if(!a)return null;try{for(var o=qn(a),c=o.next();!c.done;c=o.next()){var l=c.value;if(l.connectionId===n)return l}}catch(u){i={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}return null},e.prototype._delayedAbort=function(t,n){var i=this;setTimeout(function(){i._abort(t,n)},0)},e.prototype._abort=function(t,n){j.default.error("Aborting!"),this.emitError(t,n),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,n){j.default.error("Error:",n);var i;typeof n=="string"?i=new Error(n):i=n,i.type=t,this.emit("error",i)},e.prototype.destroy=function(){this.destroyed||(j.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},e.prototype._cleanup=function(){var t,n;try{for(var i=qn(this._connections.keys()),s=i.next();!s.done;s=i.next()){var a=s.value;this._cleanupPeer(a),this._connections.delete(a)}}catch(o){t={error:o}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var n,i,s=this._connections.get(t);if(s)try{for(var a=qn(s),o=a.next();!o.done;o=a.next()){var c=o.value;c.close()}}catch(l){n={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;j.default.log("Disconnect peer with ID:".concat(t)),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=t,this._id=null,this.emit("disconnected",t)}},e.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)j.default.log("Attempting reconnection to server with ID ".concat(this._lastServerId)),this._disconnected=!1,this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(!this.disconnected&&!this.open)j.default.error("In a hurry? We're still trying to make the initial connection!");else throw new Error("Peer ".concat(this.id," cannot reconnect because it is not disconnected from the server!"))}},e.prototype.listAllPeers=function(t){var n=this;t===void 0&&(t=function(i){}),this._api.listAllPeers().then(function(i){return t(i)}).catch(function(i){return n._abort(_e.ServerError,i)})},e.DEFAULT_KEY="peerjs",e})(Gi.EventEmitter),Fh=Wc.Peer;const Lh=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return Xs},default:Fh,util:te},Symbol.toStringTag,{value:"Module"}));class Vh{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Base must be a positive integer or zero");if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=e,this.expMax=t,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}var ce;(function(r){r.open="open",r.close="close",r.error="error",r.message="message",r.retry="retry",r.reconnect="reconnect"})(ce||(ce={}));class Yc{constructor(e,t,n){var i,s,a,o,c,l,u,f,p,m,x,T,g,v,_;this._closedByUser=!1,this.handleOpenEvent=b=>this.handleEvent(ce.open,b),this.handleErrorEvent=b=>this.handleEvent(ce.error,b),this.handleCloseEvent=b=>this.handleEvent(ce.close,b),this.handleMessageEvent=b=>this.handleEvent(ce.message,b),this._url=e,this._protocols=t,this._options={buffer:n?.buffer,retry:{maxRetries:(i=n?.retry)===null||i===void 0?void 0:i.maxRetries,instantReconnect:(s=n?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=n?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=n?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(u=(l=n?.listeners)===null||l===void 0?void 0:l.close)!==null&&u!==void 0?u:[]],error:[...(p=(f=n?.listeners)===null||f===void 0?void 0:f.error)!==null&&p!==void 0?p:[]],message:[...(x=(m=n?.listeners)===null||m===void 0?void 0:m.message)!==null&&x!==void 0?x:[]],retry:[...(g=(T=n?.listeners)===null||T===void 0?void 0:T.retry)!==null&&g!==void 0?g:[]],reconnect:[...(_=(v=n?.listeners)===null||v===void 0?void 0:v.reconnect)!==null&&_!==void 0?_:[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,n){this._options.listeners[e].push({listener:t,options:n})}removeEventListener(e,t,n){const i=s=>s.listener!==t||s.options!==n;this._options.listeners[e]=this._options.listeners[e].filter(i)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(ce.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(ce.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(ce.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(ce.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(ce.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(ce.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(ce.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(ce.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const n=this._options.listeners[e],i=[];n.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&i.push({listener:s,options:a})}),this._options.listeners[e]=i}handleEvent(e,t){switch(e){case ce.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case ce.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const n={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},i=new CustomEvent(ce.reconnect,{detail:n});this.dispatchEvent(ce.reconnect,i),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case ce.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const e=n=>{const i=new CustomEvent(ce.retry,{detail:n});this.handleEvent(ce.retry,i)},t={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class Jh{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{maxRetries:e})}),this}get maxRetries(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.maxRetries}withInstantReconnect(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{instantReconnect:e})}),this}get instantReconnect(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.instantReconnect}withBackoff(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{backoff:e})}),this}get backoff(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){var e;return(e=this._options)===null||e===void 0?void 0:e.buffer}onOpen(e,t){return this.addListener(ce.open,e,t),this}onClose(e,t){return this.addListener(ce.close,e,t),this}onError(e,t){return this.addListener(ce.error,e,t),this}onMessage(e,t){return this.addListener(ce.message,e,t),this}onRetry(e,t){return this.addListener(ce.retry,e,t),this}onReconnect(e,t){return this.addListener(ce.reconnect,e,t),this}build(){return new Yc(this._url,this._protocols,this._options)}addListener(e,t,n){var i,s,a,o,c,l,u,f,p,m,x,T,g,v,_,b,M,C,P,E,z;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(i=this._options)===null||i===void 0?void 0:i.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(p=(f=(u=this._options)===null||u===void 0?void 0:u.listeners)===null||f===void 0?void 0:f.error)!==null&&p!==void 0?p:[],message:(T=(x=(m=this._options)===null||m===void 0?void 0:m.listeners)===null||x===void 0?void 0:x.message)!==null&&T!==void 0?T:[],retry:(_=(v=(g=this._options)===null||g===void 0?void 0:g.listeners)===null||v===void 0?void 0:v.retry)!==null&&_!==void 0?_:[],reconnect:(C=(M=(b=this._options)===null||b===void 0?void 0:b.listeners)===null||M===void 0?void 0:M.reconnect)!==null&&C!==void 0?C:[],[e]:[...(z=(E=(P=this._options)===null||P===void 0?void 0:P.listeners)===null||E===void 0?void 0:E[e])!==null&&z!==void 0?z:[],{listener:t,options:n}]}}),this}}const jh=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Vh,Websocket:Yc,WebsocketBuilder:Jh,get WebsocketEvent(){return ce}},Symbol.toStringTag,{value:"Module"})),go=0,Zc=1,Kc=2,Ys=2,ws=1.25,ka=1,We=32,Pe=We/4,Qc=65535,kr=Math.pow(2,-24),Wr=Symbol("SKIP_GENERATION"),el={strategy:go,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Wr]:!1};function Se(r,e,t){return t.min.x=e[r],t.min.y=e[r+1],t.min.z=e[r+2],t.max.x=e[r+3],t.max.y=e[r+4],t.max.z=e[r+5],t}function Ra(r){let e=-1,t=-1/0;for(let n=0;n<3;n++){const i=r[n+3]-r[n];i>t&&(t=i,e=n)}return e}function Aa(r,e){e.set(r)}function Oa(r,e,t){let n,i;for(let s=0;s<3;s++){const a=s+3;n=r[s],i=e[s],t[s]=n<i?n:i,n=r[a],i=e[a],t[a]=n>i?n:i}}function ar(r,e,t){for(let n=0;n<3;n++){const i=e[r+2*n],s=e[r+2*n+1],a=i-s,o=i+s;a<t[n]&&(t[n]=a),o>t[n+3]&&(t[n+3]=o)}}function Xn(r){const e=r[3]-r[0],t=r[4]-r[1],n=r[5]-r[2];return 2*(e*t+t*n+n*e)}function Ee(r,e){return e[r+15]===Qc}function $e(r,e){return e[r+6]}function tt(r,e){return e[r+14]}function Ie(r){return r+Pe}function Be(r,e){const t=e[r+6];return r+t*Pe}function vo(r,e){return e[r+7]}function Ps(r,e,t,n,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0,f=1/0,p=1/0,m=1/0,x=-1/0,T=-1/0,g=-1/0;const v=r.offset||0;for(let _=(e-v)*6,b=(e+t-v)*6;_<b;_+=6){const M=r[_+0],C=r[_+1],P=M-C,E=M+C;P<s&&(s=P),E>c&&(c=E),M<f&&(f=M),M>x&&(x=M);const z=r[_+2],I=r[_+3],R=z-I,N=z+I;R<a&&(a=R),N>l&&(l=N),z<p&&(p=z),z>T&&(T=z);const O=r[_+4],U=r[_+5],L=O-U,J=O+U;L<o&&(o=L),J>u&&(u=J),O<m&&(m=O),O>g&&(g=O)}n[0]=s,n[1]=a,n[2]=o,n[3]=c,n[4]=l,n[5]=u,i[0]=f,i[1]=p,i[2]=m,i[3]=x,i[4]=T,i[5]=g}const Jt=32,Gh=(r,e)=>r.candidate-e.candidate,Kt=new Array(Jt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),cr=new Float32Array(6);function Wh(r,e,t,n,i,s){let a=-1,o=0;if(s===go)a=Ra(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===Zc)a=Ra(r),a!==-1&&(o=$h(t,n,i,a));else if(s===Kc){const c=Xn(r);let l=ws*i;const u=t.offset||0,f=(n-u)*6,p=(n+i-u)*6;for(let m=0;m<3;m++){const x=e[m],v=(e[m+3]-x)/Jt;if(i<Jt/4){const _=[...Kt];_.length=i;let b=0;for(let C=f;C<p;C+=6,b++){const P=_[b];P.candidate=t[C+2*m],P.count=0;const{bounds:E,leftCacheBounds:z,rightCacheBounds:I}=P;for(let R=0;R<3;R++)I[R]=1/0,I[R+3]=-1/0,z[R]=1/0,z[R+3]=-1/0,E[R]=1/0,E[R+3]=-1/0;ar(C,t,E)}_.sort(Gh);let M=i;for(let C=0;C<M;C++){const P=_[C];for(;C+1<M&&_[C+1].candidate===P.candidate;)_.splice(C+1,1),M--}for(let C=f;C<p;C+=6){const P=t[C+2*m];for(let E=0;E<M;E++){const z=_[E];P>=z.candidate?ar(C,t,z.rightCacheBounds):(ar(C,t,z.leftCacheBounds),z.count++)}}for(let C=0;C<M;C++){const P=_[C],E=P.count,z=i-P.count,I=P.leftCacheBounds,R=P.rightCacheBounds;let N=0;E!==0&&(N=Xn(I)/c);let O=0;z!==0&&(O=Xn(R)/c);const U=ka+ws*(N*E+O*z);U<l&&(a=m,l=U,o=P.candidate)}}else{for(let M=0;M<Jt;M++){const C=Kt[M];C.count=0,C.candidate=x+v+M*v;const P=C.bounds;for(let E=0;E<3;E++)P[E]=1/0,P[E+3]=-1/0}for(let M=f;M<p;M+=6){let E=~~((t[M+2*m]-x)/v);E>=Jt&&(E=Jt-1);const z=Kt[E];z.count++,ar(M,t,z.bounds)}const _=Kt[Jt-1];Aa(_.bounds,_.rightCacheBounds);for(let M=Jt-2;M>=0;M--){const C=Kt[M],P=Kt[M+1];Oa(C.bounds,P.rightCacheBounds,C.rightCacheBounds)}let b=0;for(let M=0;M<Jt-1;M++){const C=Kt[M],P=C.count,E=C.bounds,I=Kt[M+1].rightCacheBounds;P!==0&&(b===0?Aa(E,cr):Oa(E,cr,cr)),b+=P;let R=0,N=0;b!==0&&(R=Xn(cr)/c);const O=i-b;O!==0&&(N=Xn(I)/c);const U=ka+ws*(R*b+N*O);U<l&&(a=m,l=U,o=C.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function $h(r,e,t,n){let i=0;const s=r.offset;for(let a=e,o=e+t;a<o;a++)i+=r[(a-s)*6+n*2];return i/t}class Es{constructor(){this.boundingData=new Float32Array(6)}}function Hh(r,e,t,n,i,s){let a=n,o=n+i-1;const c=s.pos,l=s.axis*2,u=t.offset||0;for(;;){for(;a<=o&&t[(a-u)*6+l]<c;)a++;for(;a<=o&&t[(o-u)*6+l]>=c;)o--;if(a<o){for(let f=0;f<e;f++){let p=r[a*e+f];r[a*e+f]=r[o*e+f],r[o*e+f]=p}for(let f=0;f<6;f++){const p=a-u,m=o-u,x=t[p*6+f];t[p*6+f]=t[m*6+f],t[m*6+f]=x}a++,o--}else return a}}let tl,Rr,Zs,nl;const qh=Math.pow(2,32);function Ks(r){return"count"in r?1:1+Ks(r.left)+Ks(r.right)}function Xh(r,e,t){return tl=new Float32Array(t),Rr=new Uint32Array(t),Zs=new Uint16Array(t),nl=new Uint8Array(t),Qs(r,e)}function Qs(r,e){const t=r/4,n=r/2,i="count"in e,s=e.boundingData;for(let a=0;a<6;a++)tl[t+a]=s[a];if(i)return e.buffer?(nl.set(new Uint8Array(e.buffer),r),r+e.buffer.byteLength):(Rr[t+6]=e.offset,Zs[n+14]=e.count,Zs[n+15]=Qc,r+We);{const{left:a,right:o,splitAxis:c}=e,l=r+We;let u=Qs(l,a);const f=r/We,m=u/We-f;if(m>qh)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Rr[t+6]=m,Rr[t+7]=c,Qs(u,o)}}function Yh(r,e,t,n,i){const{maxDepth:s,verbose:a,maxLeafSize:o,strategy:c,onProgress:l}=i,u=r.primitiveBuffer,f=r.primitiveBufferStride,p=new Float32Array(6);let m=!1;const x=new Es;return Ps(e,t,n,x.boundingData,p),g(x,t,n,p),x;function T(v){l&&l(v/n)}function g(v,_,b,M=null,C=0){if(!m&&C>=s&&(m=!0,a&&console.warn(`BVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`)),b<=o||C>=s)return T(_+b),v.offset=_,v.count=b,v;const P=Wh(v.boundingData,M,e,_,b,c);if(P.axis===-1)return T(_+b),v.offset=_,v.count=b,v;const E=Hh(u,f,e,_,b,P);if(E===_||E===_+b)T(_+b),v.offset=_,v.count=b;else{v.splitAxis=P.axis;const z=new Es,I=_,R=E-_;v.left=z,Ps(e,I,R,z.boundingData,p),g(z,I,R,p,C+1);const N=new Es,O=E,U=b-R;v.right=N,Ps(e,O,U,N.boundingData,p),g(N,O,U,p,C+1)}return v}}function Zh(r,e){const t=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=r.getRootRanges(e.range),i=n[0],s=n[n.length-1],a={offset:i.offset,count:s.offset+s.count-i.offset},o=new Float32Array(6*a.count);o.offset=a.offset,r.computePrimitiveBounds(a.offset,a.count,o),r._roots=n.map(c=>{const l=Yh(r,o,c.offset,c.count,e),u=Ks(l),f=new t(We*u);return Xh(0,l,f),f})}class So{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Kh{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const pe=new Kh;let nn,Un;const Pn=[],lr=new So(()=>new A.Box3);function Qh(r,e,t,n,i,s){nn=lr.getPrimitive(),Un=lr.getPrimitive(),Pn.push(nn,Un),pe.setBuffer(r._roots[e]);const a=eo(0,r.geometry,t,n,i,s);pe.clearBuffer(),lr.releasePrimitive(nn),lr.releasePrimitive(Un),Pn.pop(),Pn.pop();const o=Pn.length;return o>0&&(Un=Pn[o-1],nn=Pn[o-2]),a}function eo(r,e,t,n,i=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=pe;let u=r*2;if(Ee(u,c)){const p=$e(r,l),m=tt(u,c);return Se(r,o,nn),n(p,m,!1,a,s+r/Pe,nn)}else{let R=function(O){const{uint16Array:U,uint32Array:L}=pe;let J=O*2;for(;!Ee(J,U);)O=Ie(O),J=O*2;return $e(O,L)},N=function(O){const{uint16Array:U,uint32Array:L}=pe;let J=O*2;for(;!Ee(J,U);)O=Be(O,L),J=O*2;return $e(O,L)+tt(J,U)};const p=Ie(r),m=Be(r,l);let x=p,T=m,g,v,_,b;if(i&&(_=nn,b=Un,Se(x,o,_),Se(T,o,b),g=i(_),v=i(b),v<g)){x=m,T=p;const O=g;g=v,v=O,_=b}_||(_=nn,Se(x,o,_));const M=Ee(x*2,c),C=t(_,M,g,a+1,s+x/Pe);let P;if(C===Ys){const O=R(x),L=N(x)-O;P=n(O,L,!0,a+1,s+x/Pe,_)}else P=C&&eo(x,e,t,n,i,s,a+1);if(P)return!0;b=Un,Se(T,o,b);const E=Ee(T*2,c),z=t(b,E,v,a+1,s+T/Pe);let I;if(z===Ys){const O=R(T),L=N(T)-O;I=n(O,L,!0,a+1,s+T/Pe,b)}else I=z&&eo(T,e,t,n,i,s,a+1);return!!I}}const ci=new pe.constructor,Lr=new pe.constructor,en=new So(()=>new A.Box3),En=new A.Box3,kn=new A.Box3,ks=new A.Box3,Rs=new A.Box3;let As=!1;function ef(r,e,t,n){if(As)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");As=!0;const i=r._roots,s=e._roots;let a,o=0,c=0;const l=new A.Matrix4().copy(t).invert();for(let u=0,f=i.length;u<f;u++){ci.setBuffer(i[u]),c=0;const p=en.getPrimitive();Se(0,ci.float32Array,p),p.applyMatrix4(l);for(let m=0,x=s.length;m<x&&(Lr.setBuffer(s[m]),a=wt(0,0,t,l,n,o,c,0,0,p),Lr.clearBuffer(),c+=s[m].byteLength/We,!a);m++);if(en.releasePrimitive(p),ci.clearBuffer(),o+=i[u].byteLength/We,a)break}return As=!1,a}function wt(r,e,t,n,i,s=0,a=0,o=0,c=0,l=null,u=!1){let f,p;u?(f=Lr,p=ci):(f=ci,p=Lr);const m=f.float32Array,x=f.uint32Array,T=f.uint16Array,g=p.float32Array,v=p.uint32Array,_=p.uint16Array,b=r*2,M=e*2,C=Ee(b,T),P=Ee(M,_);let E=!1;if(P&&C)u?E=i($e(e,v),tt(e*2,_),$e(r,x),tt(r*2,T),c,a+e/Pe,o,s+r/Pe):E=i($e(r,x),tt(r*2,T),$e(e,v),tt(e*2,_),o,s+r/Pe,c,a+e/Pe);else if(P){const z=en.getPrimitive();Se(e,g,z),z.applyMatrix4(t);const I=Ie(r),R=Be(r,x);Se(I,m,En),Se(R,m,kn);const N=z.intersectsBox(En),O=z.intersectsBox(kn);E=N&&wt(e,I,n,t,i,a,s,c,o+1,z,!u)||O&&wt(e,R,n,t,i,a,s,c,o+1,z,!u),en.releasePrimitive(z)}else{const z=Ie(e),I=Be(e,v);Se(z,g,ks),Se(I,g,Rs);const R=l.intersectsBox(ks),N=l.intersectsBox(Rs);if(R&&N)E=wt(r,z,t,n,i,s,a,o,c+1,l,u)||wt(r,I,t,n,i,s,a,o,c+1,l,u);else if(R)if(C)E=wt(r,z,t,n,i,s,a,o,c+1,l,u);else{const O=en.getPrimitive();O.copy(ks).applyMatrix4(t);const U=Ie(r),L=Be(r,x);Se(U,m,En),Se(L,m,kn);const J=O.intersectsBox(En),$=O.intersectsBox(kn);E=J&&wt(z,U,n,t,i,a,s,c,o+1,O,!u)||$&&wt(z,L,n,t,i,a,s,c,o+1,O,!u),en.releasePrimitive(O)}else if(N)if(C)E=wt(r,I,t,n,i,s,a,o,c+1,l,u);else{const O=en.getPrimitive();O.copy(Rs).applyMatrix4(t);const U=Ie(r),L=Be(r,x);Se(U,m,En),Se(L,m,kn);const J=O.intersectsBox(En),$=O.intersectsBox(kn);E=J&&wt(I,U,n,t,i,a,s,c,o+1,O,!u)||$&&wt(I,L,n,t,i,a,s,c,o+1,O,!u),en.releasePrimitive(O)}}return E}const za=new A.Box3,Rn=new Float32Array(6);class il{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...el,...e},Zh(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,n,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0;for(let f=e,p=e+t;f<p;f++){this.writePrimitiveBounds(f,Rn,0);const[m,x,T,g,v,_]=Rn;m<s&&(s=m),g>c&&(c=g),x<a&&(a=x),v>l&&(l=v),T<o&&(o=T),_>u&&(u=_)}return n[i+0]=s,n[i+1]=a,n[i+2]=o,n[i+3]=c,n[i+4]=l,n[i+5]=u,n}computePrimitiveBounds(e,t,n){const i=n.offset||0;for(let s=e,a=e+t;s<a;s++){this.writePrimitiveBounds(s,Rn,0);const[o,c,l,u,f,p]=Rn,m=(o+u)/2,x=(c+f)/2,T=(l+p)/2,g=(u-o)/2,v=(f-c)/2,_=(p-l)/2,b=(s-i)*6;n[b+0]=m,n[b+1]=g+(Math.abs(m)+g)*kr,n[b+2]=x,n[b+3]=v+(Math.abs(x)+v)*kr,n[b+4]=T,n[b+5]=_+(Math.abs(T)+_)*kr}return n}shiftPrimitiveOffsets(e){const t=this._indirectBuffer;if(t)for(let n=0,i=t.length;n<i;n++)t[n]+=e;else{const n=this._roots;for(let i=0;i<n.length;i++){const s=n[i],a=new Uint32Array(s),o=new Uint16Array(s),c=s.byteLength/We;for(let l=0;l<c;l++){const u=Pe*l,f=2*u;Ee(f,o)&&(a[u+6]+=e)}}}}traverse(e,t=0){const n=this._roots[t],i=new Uint32Array(n),s=new Uint16Array(n);a(0);function a(o,c=0){const l=o*2,u=Ee(l,s);if(u){const f=i[o+6],p=s[l+14];e(c,u,new Float32Array(n,o*4,6),f,p)}else{const f=Ie(o),p=Be(o,i),m=vo(o,i);e(c,u,new Float32Array(n,o*4,6),m)||(a(f,c+1),a(p,c+1))}}}refit(){const e=this._roots;for(let t=0,n=e.length;t<n;t++){const i=e[t],s=new Uint32Array(i),a=new Uint16Array(i),o=new Float32Array(i),c=i.byteLength/We;for(let l=c-1;l>=0;l--){const u=l*Pe,f=u*2;if(Ee(f,a)){const m=$e(u,s),x=tt(f,a);this.writePrimitiveRangeBounds(m,x,Rn,0),o.set(Rn,u)}else{const m=Ie(u),x=Be(u,s);for(let T=0;T<3;T++){const g=o[m+T],v=o[m+T+3],_=o[x+T],b=o[x+T+3];o[u+T]=g<_?g:_,o[u+T+3]=v>b?v:b}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(n=>{Se(0,new Float32Array(n),za),e.union(za)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:i,intersectsPrimitive:s,scratchPrimitive:a,iterate:o}=e;if(i&&s){const f=i;i=(p,m,x,T,g)=>f(p,m,x,T,g)?!0:o(p,m,this,s,x,T,a)}else i||(s?i=(f,p,m,x)=>o(f,p,this,s,m,x,a):i=(f,p,m)=>m);let c=!1,l=0;const u=this._roots;for(let f=0,p=u.length;f<p;f++){const m=u[f];if(c=Qh(this,f,n,i,t,l),c)break;l+=m.byteLength/We}return c}bvhcast(e,t,n){let{intersectsRanges:i}=n;return ef(this,e,t,i)}}function tf(){return typeof SharedArrayBuffer<"u"}function xo(r){return r.index?r.index.count:r.attributes.position.count}function $r(r){return xo(r)/3}function nf(r,e=ArrayBuffer){return r>65535?new Uint32Array(new e(4*r)):new Uint16Array(new e(2*r))}function rf(r,e){if(!r.index){const t=r.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=nf(t,n);r.setIndex(new A.BufferAttribute(i,1));for(let s=0;s<t;s++)i[s]=s}}function sf(r,e,t){const n=xo(r)/t,i=e||r.drawRange,s=i.start/t,a=(i.start+i.count)/t,o=Math.max(0,s),c=Math.min(n,a)-o;return{offset:Math.floor(o),count:Math.floor(c)}}function of(r,e){return r.groups.map(t=>({offset:t.start/e,count:t.count/e}))}function Ia(r,e,t){const n=sf(r,e,t),i=of(r,t);if(!i.length)return[n];const s=[],a=n.offset,o=n.offset+n.count,c=xo(r)/t,l=[];for(const p of i){const{offset:m,count:x}=p,T=m,g=isFinite(x)?x:c-m,v=m+g;T<o&&v>a&&(l.push({pos:Math.max(a,T),isStart:!0}),l.push({pos:Math.min(o,v),isStart:!1}))}l.sort((p,m)=>p.pos!==m.pos?p.pos-m.pos:p.type==="end"?-1:1);let u=0,f=null;for(const p of l){const m=p.pos;u!==0&&m!==f&&s.push({offset:f,count:m-f}),u+=p.isStart?1:-1,f=m}return s}function rl(r,e){const t=r[r.length-1],n=t.offset+t.count>2**16,i=r.reduce((l,u)=>l+u.count,0),s=n?4:2,a=e?new SharedArrayBuffer(i*s):new ArrayBuffer(i*s),o=n?new Uint32Array(a):new Uint16Array(a);let c=0;for(let l=0;l<r.length;l++){const{offset:u,count:f}=r[l];for(let p=0;p<f;p++)o[c+p]=u+p;c+=f}return o}class sl extends il{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(t.useSharedArrayBuffer&&!tf())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?n=>this._indirectBuffer[n]:n=>n,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...el,...t},t[Wr]||this.init(t)}init(e){const{geometry:t,primitiveStride:n}=this;if(e.indirect){const i=Ia(t,e.range,n),s=rl(i,e.useSharedArrayBuffer);this._indirectBuffer=s}else rf(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new A.Box3))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Ia(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class qt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,i=-1/0;for(let s=0,a=e.length;s<a;s++){const c=e[s][t];n=c<n?c:n,i=c>i?c:i}this.min=n,this.max=i}setFromPoints(e,t){let n=1/0,i=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);n=c<n?c:n,i=c>i?c:i}this.min=n,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}qt.prototype.setFromBox=(function(){const r=new A.Vector3;return function(t,n){const i=n.min,s=n.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++){r.x=i.x*c+s.x*(1-c),r.y=i.y*l+s.y*(1-l),r.z=i.z*u+s.z*(1-u);const f=t.dot(r);a=Math.min(f,a),o=Math.max(f,o)}this.min=a,this.max=o}})();const af=(function(){const r=new A.Vector3,e=new A.Vector3,t=new A.Vector3;return function(i,s,a){const o=i.start,c=r,l=s.start,u=e;t.subVectors(o,l),r.subVectors(i.end,i.start),e.subVectors(s.end,s.start);const f=t.dot(u),p=u.dot(c),m=u.dot(u),x=t.dot(c),g=c.dot(c)*m-p*p;let v,_;g!==0?v=(f*p-x*m)/g:v=0,_=(f+v*p)/m,a.x=v,a.y=_}})(),_o=(function(){const r=new A.Vector2,e=new A.Vector3,t=new A.Vector3;return function(i,s,a,o){af(i,s,r);let c=r.x,l=r.y;if(c>=0&&c<=1&&l>=0&&l<=1){i.at(c,a),s.at(l,o);return}else if(c>=0&&c<=1){l<0?s.at(0,o):s.at(1,o),i.closestPointToPoint(o,!0,a);return}else if(l>=0&&l<=1){c<0?i.at(0,a):i.at(1,a),s.closestPointToPoint(a,!0,o);return}else{let u;c<0?u=i.start:u=i.end;let f;l<0?f=s.start:f=s.end;const p=e,m=t;if(i.closestPointToPoint(f,!0,e),s.closestPointToPoint(u,!0,t),p.distanceToSquared(f)<=m.distanceToSquared(u)){a.copy(p),o.copy(f);return}else{a.copy(u),o.copy(m);return}}}})(),cf=(function(){const r=new A.Vector3,e=new A.Vector3,t=new A.Plane,n=new A.Line3;return function(s,a){const{radius:o,center:c}=s,{a:l,b:u,c:f}=a;if(n.start=l,n.end=u,n.closestPointToPoint(c,!0,r).distanceTo(c)<=o||(n.start=l,n.end=f,n.closestPointToPoint(c,!0,r).distanceTo(c)<=o)||(n.start=u,n.end=f,n.closestPointToPoint(c,!0,r).distanceTo(c)<=o))return!0;const T=a.getPlane(t);if(Math.abs(T.distanceToPoint(c))<=o){const v=T.projectPoint(c,e);if(a.containsPoint(v))return!0}return!1}})(),lf=["x","y","z"],Gt=1e-15,Ba=Gt*Gt;function pt(r){return Math.abs(r)<Gt}class gt extends A.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new A.Vector3),this.satBounds=new Array(4).fill().map(()=>new qt),this.points=[this.a,this.b,this.c],this.plane=new A.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new A.Line3,this.needsUpdate=!0}intersectsSphere(e){return cf(e,this)}update(){const e=this.a,t=this.b,n=this.c,i=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,i);const l=s[1],u=a[1];l.subVectors(e,t),u.setFromPoints(l,i);const f=s[2],p=a[2];f.subVectors(t,n),p.setFromPoints(f,i);const m=s[3],x=a[3];m.subVectors(n,e),x.setFromPoints(m,i);const T=l.length(),g=f.length(),v=m.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,T<Gt?g<Gt||v<Gt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):g<Gt?v<Gt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):v<Gt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}gt.prototype.closestPointToSegment=(function(){const r=new A.Vector3,e=new A.Vector3,t=new A.Line3;return function(i,s=null,a=null){const{start:o,end:c}=i,l=this.points;let u,f=1/0;for(let p=0;p<3;p++){const m=(p+1)%3;t.start.copy(l[p]),t.end.copy(l[m]),_o(t,i,r,e),u=r.distanceToSquared(e),u<f&&(f=u,s&&s.copy(r),a&&a.copy(e))}return this.closestPointToPoint(o,r),u=o.distanceToSquared(r),u<f&&(f=u,s&&s.copy(r),a&&a.copy(o)),this.closestPointToPoint(c,r),u=c.distanceToSquared(r),u<f&&(f=u,s&&s.copy(r),a&&a.copy(c)),Math.sqrt(f)}})();gt.prototype.intersectsTriangle=(function(){const r=new gt,e=new qt,t=new qt,n=new A.Vector3,i=new A.Vector3,s=new A.Vector3,a=new A.Vector3,o=new A.Line3,c=new A.Line3,l=new A.Vector3,u=new A.Vector2,f=new A.Vector2;function p(b,M,C,P){const E=n;!b.isDegenerateIntoPoint&&!b.isDegenerateIntoSegment?E.copy(b.plane.normal):E.copy(M.plane.normal);const z=b.satBounds,I=b.satAxes;for(let O=1;O<4;O++){const U=z[O],L=I[O];if(e.setFromPoints(L,M.points),U.isSeparated(e)||(a.copy(E).cross(L),e.setFromPoints(a,b.points),t.setFromPoints(a,M.points),e.isSeparated(t)))return!1}const R=M.satBounds,N=M.satAxes;for(let O=1;O<4;O++){const U=R[O],L=N[O];if(e.setFromPoints(L,b.points),U.isSeparated(e)||(a.crossVectors(E,L),e.setFromPoints(a,b.points),t.setFromPoints(a,M.points),e.isSeparated(t)))return!1}return C&&(P||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),C.start.set(0,0,0),C.end.set(0,0,0)),!0}function m(b,M,C,P,E,z,I,R,N,O,U){let L=I/(I-R);O.x=P+(E-P)*L,U.start.subVectors(M,b).multiplyScalar(L).add(b),L=I/(I-N),O.y=P+(z-P)*L,U.end.subVectors(C,b).multiplyScalar(L).add(b)}function x(b,M,C,P,E,z,I,R,N,O,U){if(E>0)m(b.c,b.a,b.b,P,M,C,N,I,R,O,U);else if(z>0)m(b.b,b.a,b.c,C,M,P,R,I,N,O,U);else if(R*N>0||I!=0)m(b.a,b.b,b.c,M,C,P,I,R,N,O,U);else if(R!=0)m(b.b,b.a,b.c,C,M,P,R,I,N,O,U);else if(N!=0)m(b.c,b.a,b.b,P,M,C,N,I,R,O,U);else return!0;return!1}function T(b,M,C,P){const E=M.degenerateSegment,z=b.plane.distanceToPoint(E.start),I=b.plane.distanceToPoint(E.end);return pt(z)?pt(I)?p(b,M,C,P):(C&&(C.start.copy(E.start),C.end.copy(E.start)),b.containsPoint(E.start)):pt(I)?(C&&(C.start.copy(E.end),C.end.copy(E.end)),b.containsPoint(E.end)):b.plane.intersectLine(E,n)!=null?(C&&(C.start.copy(n),C.end.copy(n)),b.containsPoint(n)):!1}function g(b,M,C){const P=M.a;return pt(b.plane.distanceToPoint(P))&&b.containsPoint(P)?(C&&(C.start.copy(P),C.end.copy(P)),!0):!1}function v(b,M,C){const P=b.degenerateSegment,E=M.a;return P.closestPointToPoint(E,!0,n),E.distanceToSquared(n)<Ba?(C&&(C.start.copy(E),C.end.copy(E)),!0):!1}function _(b,M,C,P){if(b.isDegenerateIntoSegment)if(M.isDegenerateIntoSegment){const E=b.degenerateSegment,z=M.degenerateSegment,I=i,R=s;E.delta(I),z.delta(R);const N=n.subVectors(z.start,E.start),O=I.x*R.y-I.y*R.x;if(pt(O))return!1;const U=(N.x*R.y-N.y*R.x)/O,L=-(I.x*N.y-I.y*N.x)/O;if(U<0||U>1||L<0||L>1)return!1;const J=E.start.z+I.z*U,$=z.start.z+R.z*L;return pt(J-$)?(C&&(C.start.copy(E.start).addScaledVector(I,U),C.end.copy(E.start).addScaledVector(I,U)),!0):!1}else return M.isDegenerateIntoPoint?v(b,M,C):T(M,b,C,P);else{if(b.isDegenerateIntoPoint)return M.isDegenerateIntoPoint?M.a.distanceToSquared(b.a)<Ba?(C&&(C.start.copy(b.a),C.end.copy(b.a)),!0):!1:M.isDegenerateIntoSegment?v(M,b,C):g(M,b,C);if(M.isDegenerateIntoPoint)return g(b,M,C);if(M.isDegenerateIntoSegment)return T(b,M,C,P)}}return function(M,C=null,P=!1){this.needsUpdate&&this.update(),M.isExtendedTriangle?M.needsUpdate&&M.update():(r.copy(M),r.update(),M=r);const E=_(this,M,C,P);if(E!==void 0)return E;const z=this.plane,I=M.plane;let R=I.distanceToPoint(this.a),N=I.distanceToPoint(this.b),O=I.distanceToPoint(this.c);pt(R)&&(R=0),pt(N)&&(N=0),pt(O)&&(O=0);const U=R*N,L=R*O;if(U>0&&L>0)return!1;let J=z.distanceToPoint(M.a),$=z.distanceToPoint(M.b),K=z.distanceToPoint(M.c);pt(J)&&(J=0),pt($)&&($=0),pt(K)&&(K=0);const W=J*$,me=J*K;if(W>0&&me>0)return!1;i.copy(z.normal),s.copy(I.normal);const ne=i.cross(s);let ue=0,re=Math.abs(ne.x);const ge=Math.abs(ne.y);ge>re&&(re=ge,ue=1),Math.abs(ne.z)>re&&(ue=2);const se=lf[ue],he=this.a[se],oe=this.b[se],Xe=this.c[se],Ve=M.a[se],Je=M.b[se],Ye=M.c[se];if(x(this,he,oe,Xe,U,L,R,N,O,u,o))return p(this,M,C,P);if(x(M,Ve,Je,Ye,W,me,J,$,K,f,c))return p(this,M,C,P);if(u.y<u.x){const xe=u.y;u.y=u.x,u.x=xe,l.copy(o.start),o.start.copy(o.end),o.end.copy(l)}if(f.y<f.x){const xe=f.y;f.y=f.x,f.x=xe,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<f.x||f.y<u.x?!1:(C&&(f.x>u.x?C.start.copy(c.start):C.start.copy(o.start),f.y<u.y?C.end.copy(c.end):C.end.copy(o.end)),!0)}})();gt.prototype.distanceToPoint=(function(){const r=new A.Vector3;return function(t){return this.closestPointToPoint(t,r),t.distanceTo(r)}})();gt.prototype.distanceToTriangle=(function(){const r=new A.Vector3,e=new A.Vector3,t=["a","b","c"],n=new A.Line3,i=new A.Line3;return function(a,o=null,c=null){const l=o||c?n:null;if(this.intersectsTriangle(a,l))return(o||c)&&(o&&l.getCenter(o),c&&l.getCenter(c)),0;let u=1/0;for(let f=0;f<3;f++){let p;const m=t[f],x=a[m];this.closestPointToPoint(x,r),p=x.distanceToSquared(r),p<u&&(u=p,o&&o.copy(r),c&&c.copy(x));const T=this[m];a.closestPointToPoint(T,r),p=T.distanceToSquared(r),p<u&&(u=p,o&&o.copy(T),c&&c.copy(r))}for(let f=0;f<3;f++){const p=t[f],m=t[(f+1)%3];n.set(this[p],this[m]);for(let x=0;x<3;x++){const T=t[x],g=t[(x+1)%3];i.set(a[T],a[g]),_o(n,i,r,e);const v=r.distanceToSquared(e);v<u&&(u=v,o&&o.copy(r),c&&c.copy(e))}}return Math.sqrt(u)}})();class qe{constructor(e,t,n){this.isOrientedBox=!0,this.min=new A.Vector3,this.max=new A.Vector3,this.matrix=new A.Matrix4,this.invMatrix=new A.Matrix4,this.points=new Array(8).fill().map(()=>new A.Vector3),this.satAxes=new Array(3).fill().map(()=>new A.Vector3),this.satBounds=new Array(3).fill().map(()=>new qt),this.alignedSatBounds=new Array(3).fill().map(()=>new qt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}qe.prototype.update=(function(){return function(){const e=this.matrix,t=this.min,n=this.max,i=this.points;for(let l=0;l<=1;l++)for(let u=0;u<=1;u++)for(let f=0;f<=1;f++){const p=1*l|2*u|4*f,m=i[p];m.x=l?n.x:t.x,m.y=u?n.y:t.y,m.z=f?n.z:t.z,m.applyMatrix4(e)}const s=this.satBounds,a=this.satAxes,o=i[0];for(let l=0;l<3;l++){const u=a[l],f=s[l],p=1<<l,m=i[p];u.subVectors(o,m),f.setFromPoints(u,i)}const c=this.alignedSatBounds;c[0].setFromPointsField(i,"x"),c[1].setFromPointsField(i,"y"),c[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})();qe.prototype.intersectsBox=(function(){const r=new qt;return function(t){this.needsUpdate&&this.update();const n=t.min,i=t.max,s=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(r.min=n.x,r.max=i.x,o[0].isSeparated(r)||(r.min=n.y,r.max=i.y,o[1].isSeparated(r))||(r.min=n.z,r.max=i.z,o[2].isSeparated(r)))return!1;for(let c=0;c<3;c++){const l=a[c],u=s[c];if(r.setFromBox(l,t),u.isSeparated(r))return!1}return!0}})();qe.prototype.intersectsTriangle=(function(){const r=new gt,e=new Array(3),t=new qt,n=new qt,i=new A.Vector3;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(r.copy(a),r.update(),a=r);const o=this.satBounds,c=this.satAxes;e[0]=a.a,e[1]=a.b,e[2]=a.c;for(let p=0;p<3;p++){const m=o[p],x=c[p];if(t.setFromPoints(x,e),m.isSeparated(t))return!1}const l=a.satBounds,u=a.satAxes,f=this.points;for(let p=0;p<3;p++){const m=l[p],x=u[p];if(t.setFromPoints(x,f),m.isSeparated(t))return!1}for(let p=0;p<3;p++){const m=c[p];for(let x=0;x<4;x++){const T=u[x];if(i.crossVectors(m,T),t.setFromPoints(i,e),n.setFromPoints(i,f),t.isSeparated(n))return!1}}return!0}})();qe.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}})();qe.prototype.distanceToPoint=(function(){const r=new A.Vector3;return function(t){return this.closestPointToPoint(t,r),t.distanceTo(r)}})();qe.prototype.distanceToBox=(function(){const r=["x","y","z"],e=new Array(12).fill().map(()=>new A.Line3),t=new Array(12).fill().map(()=>new A.Line3),n=new A.Vector3,i=new A.Vector3;return function(a,o=0,c=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(c||l)&&(a.getCenter(i),this.closestPointToPoint(i,n),a.closestPointToPoint(n,i),c&&c.copy(n),l&&l.copy(i)),0;const u=o*o,f=a.min,p=a.max,m=this.points;let x=1/0;for(let g=0;g<8;g++){const v=m[g];i.copy(v).clamp(f,p);const _=v.distanceToSquared(i);if(_<x&&(x=_,c&&c.copy(v),l&&l.copy(i),_<u))return Math.sqrt(_)}let T=0;for(let g=0;g<3;g++)for(let v=0;v<=1;v++)for(let _=0;_<=1;_++){const b=(g+1)%3,M=(g+2)%3,C=v<<b|_<<M,P=1<<g|v<<b|_<<M,E=m[C],z=m[P];e[T].set(E,z);const R=r[g],N=r[b],O=r[M],U=t[T],L=U.start,J=U.end;L[R]=f[R],L[N]=v?f[N]:p[N],L[O]=_?f[O]:p[N],J[R]=p[R],J[N]=v?f[N]:p[N],J[O]=_?f[O]:p[N],T++}for(let g=0;g<=1;g++)for(let v=0;v<=1;v++)for(let _=0;_<=1;_++){i.x=g?p.x:f.x,i.y=v?p.y:f.y,i.z=_?p.z:f.z,this.closestPointToPoint(i,n);const b=i.distanceToSquared(n);if(b<x&&(x=b,c&&c.copy(n),l&&l.copy(i),b<u))return Math.sqrt(b)}for(let g=0;g<12;g++){const v=e[g];for(let _=0;_<12;_++){const b=t[_];_o(v,b,n,i);const M=n.distanceToSquared(i);if(M<x&&(x=M,c&&c.copy(n),l&&l.copy(i),M<u))return Math.sqrt(M)}}return Math.sqrt(x)}})();class uf extends So{constructor(){super(()=>new gt)}}const yt=new uf,Yn=new A.Vector3,Os=new A.Vector3;function hf(r,e,t={},n=0,i=1/0){const s=n*n,a=i*i;let o=1/0,c=null;if(r.shapecast({boundsTraverseOrder:u=>(Yn.copy(e).clamp(u.min,u.max),Yn.distanceToSquared(e)),intersectsBounds:(u,f,p)=>p<o&&p<a,intersectsTriangle:(u,f)=>{u.closestPointToPoint(e,Yn);const p=e.distanceToSquared(Yn);return p<o&&(Os.copy(Yn),o=p,c=f),p<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(Os):t.point=Os.clone(),t.distance=l,t.faceIndex=c,t}const ur=parseInt(A.REVISION)>=169,ff=parseInt(A.REVISION)<=161,ln=new A.Vector3,un=new A.Vector3,hn=new A.Vector3,hr=new A.Vector2,fr=new A.Vector2,dr=new A.Vector2,Na=new A.Vector3,Ua=new A.Vector3,Da=new A.Vector3,Zn=new A.Vector3;function df(r,e,t,n,i,s,a,o){let c;if(s===A.BackSide?c=r.intersectTriangle(n,t,e,!0,i):c=r.intersectTriangle(e,t,n,s!==A.DoubleSide,i),c===null)return null;const l=r.origin.distanceTo(i);return l<a||l>o?null:{distance:l,point:i.clone()}}function Fa(r,e,t,n,i,s,a,o,c,l,u){ln.fromBufferAttribute(e,s),un.fromBufferAttribute(e,a),hn.fromBufferAttribute(e,o);const f=df(r,ln,un,hn,Zn,c,l,u);if(f){if(n){hr.fromBufferAttribute(n,s),fr.fromBufferAttribute(n,a),dr.fromBufferAttribute(n,o),f.uv=new A.Vector2;const m=A.Triangle.getInterpolation(Zn,ln,un,hn,hr,fr,dr,f.uv);ur||(f.uv=m)}if(i){hr.fromBufferAttribute(i,s),fr.fromBufferAttribute(i,a),dr.fromBufferAttribute(i,o),f.uv1=new A.Vector2;const m=A.Triangle.getInterpolation(Zn,ln,un,hn,hr,fr,dr,f.uv1);ur||(f.uv1=m),ff&&(f.uv2=f.uv1)}if(t){Na.fromBufferAttribute(t,s),Ua.fromBufferAttribute(t,a),Da.fromBufferAttribute(t,o),f.normal=new A.Vector3;const m=A.Triangle.getInterpolation(Zn,ln,un,hn,Na,Ua,Da,f.normal);f.normal.dot(r.direction)>0&&f.normal.multiplyScalar(-1),ur||(f.normal=m)}const p={a:s,b:a,c:o,normal:new A.Vector3,materialIndex:0};if(A.Triangle.getNormal(ln,un,hn,p.normal),f.face=p,f.faceIndex=s,ur){const m=new A.Vector3;A.Triangle.getBarycoord(Zn,ln,un,hn,m),f.barycoord=m}}return f}function La(r){return r&&r.isMaterial?r.side:r}function Hr(r,e,t,n,i,s,a){const o=n*3;let c=o+0,l=o+1,u=o+2;const{index:f,groups:p}=r;r.index&&(c=f.getX(c),l=f.getX(l),u=f.getX(u));const{position:m,normal:x,uv:T,uv1:g}=r.attributes;if(Array.isArray(e)){const v=n*3;for(let _=0,b=p.length;_<b;_++){const{start:M,count:C,materialIndex:P}=p[_];if(v>=M&&v<M+C){const E=La(e[P]),z=Fa(t,m,x,T,g,c,l,u,E,s,a);if(z)if(z.faceIndex=n,z.face.materialIndex=P,i)i.push(z);else return z}}}else{const v=La(e),_=Fa(t,m,x,T,g,c,l,u,v,s,a);if(_)if(_.faceIndex=n,_.face.materialIndex=0,i)i.push(_);else return _}return null}function we(r,e,t,n){const i=r.a,s=r.b,a=r.c;let o=e,c=e+1,l=e+2;t&&(o=t.getX(o),c=t.getX(c),l=t.getX(l)),i.x=n.getX(o),i.y=n.getY(o),i.z=n.getZ(o),s.x=n.getX(c),s.y=n.getY(c),s.z=n.getZ(c),a.x=n.getX(l),a.y=n.getY(l),a.z=n.getZ(l)}function pf(r,e,t,n,i,s,a,o){const{geometry:c,_indirectBuffer:l}=r;for(let u=n,f=n+i;u<f;u++)Hr(c,e,t,u,s,a,o)}function mf(r,e,t,n,i,s,a){const{geometry:o,_indirectBuffer:c}=r;let l=1/0,u=null;for(let f=n,p=n+i;f<p;f++){let m;m=Hr(o,e,t,f,null,s,a),m&&m.distance<l&&(u=m,l=m.distance)}return u}function yf(r,e,t,n,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=r,f=e+r;u<f;u++){let p;if(p=u,we(a,p*3,c,l),a.needsUpdate=!0,n(a,p,i,s))return!0}return!1}function gf(r,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=r.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const u=r._roots;for(let p=0,m=u.length;p<m;p++)s=u[p],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),f(0,l),l+=s.byteLength;function f(p,m,x=!1){const T=p*2;if(Ee(T,o)){const g=$e(p,a),v=tt(T,o);let _=1/0,b=1/0,M=1/0,C=-1/0,P=-1/0,E=-1/0;for(let z=3*g,I=3*(g+v);z<I;z++){let R=n[z];const N=i.getX(R),O=i.getY(R),U=i.getZ(R);N<_&&(_=N),N>C&&(C=N),O<b&&(b=O),O>P&&(P=O),U<M&&(M=U),U>E&&(E=U)}return c[p+0]!==_||c[p+1]!==b||c[p+2]!==M||c[p+3]!==C||c[p+4]!==P||c[p+5]!==E?(c[p+0]=_,c[p+1]=b,c[p+2]=M,c[p+3]=C,c[p+4]=P,c[p+5]=E,!0):!1}else{const g=Ie(p),v=Be(p,a);let _=x,b=!1,M=!1;if(e){if(!_){const R=g/Pe+m/We,N=v/Pe+m/We;b=e.has(R),M=e.has(N),_=!b&&!M}}else b=!0,M=!0;const C=_||b,P=_||M;let E=!1;C&&(E=f(g,m,_));let z=!1;P&&(z=f(v,m,_));const I=E||z;if(I)for(let R=0;R<3;R++){const N=g+R,O=v+R,U=c[N],L=c[N+3],J=c[O],$=c[O+3];c[p+R]=U<J?U:J,c[p+R+3]=L>$?L:$}return I}}}function rn(r,e,t,n,i){let s,a,o,c,l,u;const f=1/t.direction.x,p=1/t.direction.y,m=1/t.direction.z,x=t.origin.x,T=t.origin.y,g=t.origin.z;let v=e[r],_=e[r+3],b=e[r+1],M=e[r+3+1],C=e[r+2],P=e[r+3+2];return f>=0?(s=(v-x)*f,a=(_-x)*f):(s=(_-x)*f,a=(v-x)*f),p>=0?(o=(b-T)*p,c=(M-T)*p):(o=(M-T)*p,c=(b-T)*p),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),m>=0?(l=(C-g)*m,u=(P-g)*m):(l=(P-g)*m,u=(C-g)*m),s>u||l>a)?!1:((l>s||s!==s)&&(s=l),(u<a||a!==a)&&(a=u),s<=i&&a>=n)}function vf(r,e,t,n,i,s,a,o){const{geometry:c,_indirectBuffer:l}=r;for(let u=n,f=n+i;u<f;u++){let p=l?l[u]:u;Hr(c,e,t,p,s,a,o)}}function Sf(r,e,t,n,i,s,a){const{geometry:o,_indirectBuffer:c}=r;let l=1/0,u=null;for(let f=n,p=n+i;f<p;f++){let m;m=Hr(o,e,t,c?c[f]:f,null,s,a),m&&m.distance<l&&(u=m,l=m.distance)}return u}function xf(r,e,t,n,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=r,f=e+r;u<f;u++){let p;if(p=t.resolveTriangleIndex(u),we(a,p*3,c,l),a.needsUpdate=!0,n(a,p,i,s))return!0}return!1}function _f(r,e,t,n,i,s,a){pe.setBuffer(r._roots[e]),to(0,r,t,n,i,s,a),pe.clearBuffer()}function to(r,e,t,n,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=pe,u=r*2;if(Ee(u,c)){const p=$e(r,l),m=tt(u,c);pf(e,t,n,p,m,i,s,a)}else{const p=Ie(r);rn(p,o,n,s,a)&&to(p,e,t,n,i,s,a);const m=Be(r,l);rn(m,o,n,s,a)&&to(m,e,t,n,i,s,a)}}const bf=["x","y","z"];function Tf(r,e,t,n,i,s){pe.setBuffer(r._roots[e]);const a=no(0,r,t,n,i,s);return pe.clearBuffer(),a}function no(r,e,t,n,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=pe;let l=r*2;if(Ee(l,o)){const f=$e(r,c),p=tt(l,o);return mf(e,t,n,f,p,i,s)}else{const f=vo(r,c),p=bf[f],x=n.direction[p]>=0;let T,g;x?(T=Ie(r),g=Be(r,c)):(T=Be(r,c),g=Ie(r));const _=rn(T,a,n,i,s)?no(T,e,t,n,i,s):null;if(_){const C=_.point[p];if(x?C<=a[g+f]:C>=a[g+f+3])return _}const M=rn(g,a,n,i,s)?no(g,e,t,n,i,s):null;return _&&M?_.distance<=M.distance?_:M:_||M||null}}const pr=new A.Box3,An=new gt,On=new gt,Kn=new A.Matrix4,Va=new qe,mr=new qe;function Mf(r,e,t,n){pe.setBuffer(r._roots[e]);const i=io(0,r,t,n);return pe.clearBuffer(),i}function io(r,e,t,n,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=pe;let c=r*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Va.set(t.boundingBox.min,t.boundingBox.max,n),i=Va),Ee(c,a)){const u=e.geometry,f=u.index,p=u.attributes.position,m=t.index,x=t.attributes.position,T=$e(r,o),g=tt(c,a);if(Kn.copy(n).invert(),t.boundsTree)return Se(r,s,mr),mr.matrix.copy(Kn),mr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:_=>mr.intersectsBox(_),intersectsTriangle:_=>{_.a.applyMatrix4(n),_.b.applyMatrix4(n),_.c.applyMatrix4(n),_.needsUpdate=!0;for(let b=T*3,M=(g+T)*3;b<M;b+=3)if(we(On,b,f,p),On.needsUpdate=!0,_.intersectsTriangle(On))return!0;return!1}});{const v=$r(t);for(let _=T*3,b=(g+T)*3;_<b;_+=3){we(An,_,f,p),An.a.applyMatrix4(Kn),An.b.applyMatrix4(Kn),An.c.applyMatrix4(Kn),An.needsUpdate=!0;for(let M=0,C=v*3;M<C;M+=3)if(we(On,M,m,x),On.needsUpdate=!0,An.intersectsTriangle(On))return!0}}}else{const u=Ie(r),f=Be(r,o);return Se(u,s,pr),!!(i.intersectsBox(pr)&&io(u,e,t,n,i)||(Se(f,s,pr),i.intersectsBox(pr)&&io(f,e,t,n,i)))}}const yr=new A.Matrix4,zs=new qe,Qn=new qe,Cf=new A.Vector3,wf=new A.Vector3,Pf=new A.Vector3,Ef=new A.Vector3;function kf(r,e,t,n={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),zs.set(e.boundingBox.min,e.boundingBox.max,t),zs.needsUpdate=!0;const o=r.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,f=e.index,p=yt.getPrimitive(),m=yt.getPrimitive();let x=Cf,T=wf,g=null,v=null;i&&(g=Pf,v=Ef);let _=1/0,b=null,M=null;return yr.copy(t).invert(),Qn.matrix.copy(yr),r.shapecast({boundsTraverseOrder:C=>zs.distanceToBox(C),intersectsBounds:(C,P,E)=>E<_&&E<a?(P&&(Qn.min.copy(C.min),Qn.max.copy(C.max),Qn.needsUpdate=!0),!0):!1,intersectsRange:(C,P)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:z=>Qn.distanceToBox(z),intersectsBounds:(z,I,R)=>R<_&&R<a,intersectsRange:(z,I)=>{for(let R=z,N=z+I;R<N;R++){we(m,3*R,f,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let O=C,U=C+P;O<U;O++){we(p,3*O,l,c),p.needsUpdate=!0;const L=p.distanceToTriangle(m,x,g);if(L<_&&(T.copy(x),v&&v.copy(g),_=L,b=O,M=R),L<s)return!0}}}});{const E=$r(e);for(let z=0,I=E;z<I;z++){we(m,3*z,f,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let R=C,N=C+P;R<N;R++){we(p,3*R,l,c),p.needsUpdate=!0;const O=p.distanceToTriangle(m,x,g);if(O<_&&(T.copy(x),v&&v.copy(g),_=O,b=R,M=z),O<s)return!0}}}}}),yt.releasePrimitive(p),yt.releasePrimitive(m),_===1/0?null:(n.point?n.point.copy(T):n.point=T.clone(),n.distance=_,n.faceIndex=b,i&&(i.point?i.point.copy(v):i.point=v.clone(),i.point.applyMatrix4(yr),T.applyMatrix4(yr),i.distance=T.sub(i.point).length(),i.faceIndex=M),n)}function Rf(r,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=r.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const u=r._roots;for(let p=0,m=u.length;p<m;p++)s=u[p],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),f(0,l),l+=s.byteLength;function f(p,m,x=!1){const T=p*2;if(Ee(T,o)){const g=$e(p,a),v=tt(T,o);let _=1/0,b=1/0,M=1/0,C=-1/0,P=-1/0,E=-1/0;for(let z=g,I=g+v;z<I;z++){const R=3*r.resolveTriangleIndex(z);for(let N=0;N<3;N++){let O=R+N;O=n?n[O]:O;const U=i.getX(O),L=i.getY(O),J=i.getZ(O);U<_&&(_=U),U>C&&(C=U),L<b&&(b=L),L>P&&(P=L),J<M&&(M=J),J>E&&(E=J)}}return c[p+0]!==_||c[p+1]!==b||c[p+2]!==M||c[p+3]!==C||c[p+4]!==P||c[p+5]!==E?(c[p+0]=_,c[p+1]=b,c[p+2]=M,c[p+3]=C,c[p+4]=P,c[p+5]=E,!0):!1}else{const g=Ie(p),v=Be(p,a);let _=x,b=!1,M=!1;if(e){if(!_){const R=g/Pe+m/We,N=v/Pe+m/We;b=e.has(R),M=e.has(N),_=!b&&!M}}else b=!0,M=!0;const C=_||b,P=_||M;let E=!1;C&&(E=f(g,m,_));let z=!1;P&&(z=f(v,m,_));const I=E||z;if(I)for(let R=0;R<3;R++){const N=g+R,O=v+R,U=c[N],L=c[N+3],J=c[O],$=c[O+3];c[p+R]=U<J?U:J,c[p+R+3]=L>$?L:$}return I}}}function Af(r,e,t,n,i,s,a){pe.setBuffer(r._roots[e]),ro(0,r,t,n,i,s,a),pe.clearBuffer()}function ro(r,e,t,n,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=pe,u=r*2;if(Ee(u,c)){const p=$e(r,l),m=tt(u,c);vf(e,t,n,p,m,i,s,a)}else{const p=Ie(r);rn(p,o,n,s,a)&&ro(p,e,t,n,i,s,a);const m=Be(r,l);rn(m,o,n,s,a)&&ro(m,e,t,n,i,s,a)}}const Of=["x","y","z"];function zf(r,e,t,n,i,s){pe.setBuffer(r._roots[e]);const a=so(0,r,t,n,i,s);return pe.clearBuffer(),a}function so(r,e,t,n,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=pe;let l=r*2;if(Ee(l,o)){const f=$e(r,c),p=tt(l,o);return Sf(e,t,n,f,p,i,s)}else{const f=vo(r,c),p=Of[f],x=n.direction[p]>=0;let T,g;x?(T=Ie(r),g=Be(r,c)):(T=Be(r,c),g=Ie(r));const _=rn(T,a,n,i,s)?so(T,e,t,n,i,s):null;if(_){const C=_.point[p];if(x?C<=a[g+f]:C>=a[g+f+3])return _}const M=rn(g,a,n,i,s)?so(g,e,t,n,i,s):null;return _&&M?_.distance<=M.distance?_:M:_||M||null}}const gr=new A.Box3,zn=new gt,In=new gt,ei=new A.Matrix4,Ja=new qe,vr=new qe;function If(r,e,t,n){pe.setBuffer(r._roots[e]);const i=oo(0,r,t,n);return pe.clearBuffer(),i}function oo(r,e,t,n,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=pe;let c=r*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Ja.set(t.boundingBox.min,t.boundingBox.max,n),i=Ja),Ee(c,a)){const u=e.geometry,f=u.index,p=u.attributes.position,m=t.index,x=t.attributes.position,T=$e(r,o),g=tt(c,a);if(ei.copy(n).invert(),t.boundsTree)return Se(r,s,vr),vr.matrix.copy(ei),vr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:_=>vr.intersectsBox(_),intersectsTriangle:_=>{_.a.applyMatrix4(n),_.b.applyMatrix4(n),_.c.applyMatrix4(n),_.needsUpdate=!0;for(let b=T,M=g+T;b<M;b++)if(we(In,3*e.resolveTriangleIndex(b),f,p),In.needsUpdate=!0,_.intersectsTriangle(In))return!0;return!1}});{const v=$r(t);for(let _=T,b=g+T;_<b;_++){const M=e.resolveTriangleIndex(_);we(zn,3*M,f,p),zn.a.applyMatrix4(ei),zn.b.applyMatrix4(ei),zn.c.applyMatrix4(ei),zn.needsUpdate=!0;for(let C=0,P=v*3;C<P;C+=3)if(we(In,C,m,x),In.needsUpdate=!0,zn.intersectsTriangle(In))return!0}}}else{const u=Ie(r),f=Be(r,o);return Se(u,s,gr),!!(i.intersectsBox(gr)&&oo(u,e,t,n,i)||(Se(f,s,gr),i.intersectsBox(gr)&&oo(f,e,t,n,i)))}}const Sr=new A.Matrix4,Is=new qe,ti=new qe,Bf=new A.Vector3,Nf=new A.Vector3,Uf=new A.Vector3,Df=new A.Vector3;function Ff(r,e,t,n={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Is.set(e.boundingBox.min,e.boundingBox.max,t),Is.needsUpdate=!0;const o=r.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,f=e.index,p=yt.getPrimitive(),m=yt.getPrimitive();let x=Bf,T=Nf,g=null,v=null;i&&(g=Uf,v=Df);let _=1/0,b=null,M=null;return Sr.copy(t).invert(),ti.matrix.copy(Sr),r.shapecast({boundsTraverseOrder:C=>Is.distanceToBox(C),intersectsBounds:(C,P,E)=>E<_&&E<a?(P&&(ti.min.copy(C.min),ti.max.copy(C.max),ti.needsUpdate=!0),!0):!1,intersectsRange:(C,P)=>{if(e.boundsTree){const E=e.boundsTree;return E.shapecast({boundsTraverseOrder:z=>ti.distanceToBox(z),intersectsBounds:(z,I,R)=>R<_&&R<a,intersectsRange:(z,I)=>{for(let R=z,N=z+I;R<N;R++){const O=E.resolveTriangleIndex(R);we(m,3*O,f,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let U=C,L=C+P;U<L;U++){const J=r.resolveTriangleIndex(U);we(p,3*J,l,c),p.needsUpdate=!0;const $=p.distanceToTriangle(m,x,g);if($<_&&(T.copy(x),v&&v.copy(g),_=$,b=U,M=R),$<s)return!0}}}})}else{const E=$r(e);for(let z=0,I=E;z<I;z++){we(m,3*z,f,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let R=C,N=C+P;R<N;R++){const O=r.resolveTriangleIndex(R);we(p,3*O,l,c),p.needsUpdate=!0;const U=p.distanceToTriangle(m,x,g);if(U<_&&(T.copy(x),v&&v.copy(g),_=U,b=R,M=z),U<s)return!0}}}}}),yt.releasePrimitive(p),yt.releasePrimitive(m),_===1/0?null:(n.point?n.point.copy(T):n.point=T.clone(),n.distance=_,n.faceIndex=b,i&&(i.point?i.point.copy(v):i.point=v.clone(),i.point.applyMatrix4(Sr),T.applyMatrix4(Sr),i.distance=T.sub(i.point).length(),i.faceIndex=M),n)}function ja(r,e,t){return r===null?null:(r.point.applyMatrix4(e.matrixWorld),r.distance=r.point.distanceTo(t.ray.origin),r.object=e,r)}const xr=new qe,_r=new A.Ray,Ga=new A.Vector3,Wa=new A.Matrix4,$a=new A.Vector3,Bs=["getX","getY","getZ"];class Vn extends sl{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,i=e._roots,s=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=i.map(c=>c.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=s?s.slice():null):(o.roots=i,o.index=a?a.array:null,o.indirectBuffer=s),o}static deserialize(e,t,n={}){n={setIndex:!0,indirect:!!e.indirectBuffer,...n};const{index:i,roots:s,indirectBuffer:a}=e;e.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),c(s));const o=new Vn(t,{...n,[Wr]:!0});if(o._roots=s,o._indirectBuffer=a||null,n.setIndex){const l=t.getIndex();if(l===null){const u=new A.BufferAttribute(e.index,1,!1);t.setIndex(u)}else l.array!==i&&(l.array.set(i),l.needsUpdate=!0)}return o;function c(l){for(let u=0;u<l.length;u++){const f=l[u],p=new Uint32Array(f),m=new Uint16Array(f);for(let x=0,T=f.byteLength/We;x<T;x++){const g=Pe*x,v=2*g;Ee(v,m)||(p[g+6]=p[g+6]/Pe-x)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),t={...t,maxLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){const i=this.geometry,s=this._indirectBuffer,a=i.attributes.position,o=i.index?i.index.array:null,l=(s?s[e]:e)*3;let u=l+0,f=l+1,p=l+2;o&&(u=o[u],f=o[f],p=o[p]);for(let m=0;m<3;m++){const x=a[Bs[m]](u),T=a[Bs[m]](f),g=a[Bs[m]](p);let v=x;T<v&&(v=T),g<v&&(v=g);let _=x;T>_&&(_=T),g>_&&(_=g),t[n+m]=v,t[n+m+3]=_}return t}computePrimitiveBounds(e,t,n){const i=this.geometry,s=this._indirectBuffer,a=i.attributes.position,o=i.index?i.index.array:null,c=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=a.array,u=a.offset||0;let f=3;a.isInterleavedBufferAttribute&&(f=a.data.stride);const p=["getX","getY","getZ"],m=n.offset;for(let x=e,T=e+t;x<T;x++){const v=(s?s[x]:x)*3,_=(x-m)*6;let b=v+0,M=v+1,C=v+2;o&&(b=o[b],M=o[M],C=o[C]),c||(b=b*f+u,M=M*f+u,C=C*f+u);for(let P=0;P<3;P++){let E,z,I;c?(E=a[p[P]](b),z=a[p[P]](M),I=a[p[P]](C)):(E=l[b+P],z=l[M+P],I=l[C+P]);let R=E;z<R&&(R=z),I<R&&(R=I);let N=E;z>N&&(N=z),I>N&&(N=I);const O=(N-R)/2,U=P*2;n[_+U+0]=R+O,n[_+U+1]=O+(Math.abs(R)+O)*kr}}return n}raycastObject3D(e,t,n=[]){const{material:i}=e;if(i===void 0)return;Wa.copy(e.matrixWorld).invert(),_r.copy(t.ray).applyMatrix4(Wa),$a.setFromMatrixScale(e.matrixWorld),Ga.copy(_r.direction).multiply($a);const s=Ga.length(),a=t.near/s,o=t.far/s;if(t.firstHitOnly===!0){let c=this.raycastFirst(_r,i,a,o);c=ja(c,e,t),c&&n.push(c)}else{const c=this.raycast(_r,i,a,o);for(let l=0,u=c.length;l<u;l++){const f=ja(c[l],e,t);f&&n.push(f)}}return n}refit(e=null){return(this.indirect?Rf:gf)(this,e)}raycast(e,t=A.FrontSide,n=0,i=1/0){const s=this._roots,a=[],o=this.indirect?Af:_f;for(let c=0,l=s.length;c<l;c++)o(this,c,t,e,a,n,i);return a}raycastFirst(e,t=A.FrontSide,n=0,i=1/0){const s=this._roots;let a=null;const o=this.indirect?zf:Tf;for(let c=0,l=s.length;c<l;c++){const u=o(this,c,t,e,n,i);u!=null&&(a==null||u.distance<a.distance)&&(a=u)}return a}intersectsGeometry(e,t){let n=!1;const i=this._roots,s=this.indirect?If:Mf;for(let a=0,o=i.length;a<o&&(n=s(this,a,e,t),!n);a++);return n}shapecast(e){const t=yt.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?xf:yf});return yt.releasePrimitive(t),n}bvhcast(e,t,n){let{intersectsRanges:i,intersectsTriangles:s}=n;const a=yt.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?x=>{const T=this.resolveTriangleIndex(x);we(a,T*3,o,c)}:x=>{we(a,x*3,o,c)},u=yt.getPrimitive(),f=e.geometry.index,p=e.geometry.attributes.position,m=e.indirect?x=>{const T=e.resolveTriangleIndex(x);we(u,T*3,f,p)}:x=>{we(u,x*3,f,p)};if(s){if(!(e instanceof Vn))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const x=(T,g,v,_,b,M,C,P)=>{for(let E=v,z=v+_;E<z;E++){m(E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let I=T,R=T+g;I<R;I++)if(l(I),a.needsUpdate=!0,s(a,u,I,E,b,M,C,P))return!0}return!1};if(i){const T=i;i=function(g,v,_,b,M,C,P,E){return T(g,v,_,b,M,C,P,E)?!0:x(g,v,_,b,M,C,P,E)}}else i=x}return super.bvhcast(e,t,{intersectsRanges:i})}intersectsBox(e,t){return xr.set(e.min,e.max,t),xr.needsUpdate=!0,this.shapecast({intersectsBounds:n=>xr.intersectsBox(n),intersectsTriangle:n=>xr.intersectsTriangle(n)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},i={},s=0,a=1/0){return(this.indirect?Ff:kf)(this,e,t,n,i,s,a)}closestPointToPoint(e,t={},n=0,i=1/0){return hf(this,e,t,n,i)}}const Bn={Mesh:A.Mesh.prototype.raycast,Line:A.Line.prototype.raycast,LineSegments:A.LineSegments.prototype.raycast,LineLoop:A.LineLoop.prototype.raycast,Points:A.Points.prototype.raycast,BatchedMesh:A.BatchedMesh.prototype.raycast},De=new A.Mesh,br=[];function Lf(r,e){if(this.isBatchedMesh)Vf.call(this,r,e);else{const{geometry:t}=this;if(t.boundsTree)t.boundsTree.raycastObject3D(this,r,e);else{let n;if(this instanceof A.Mesh)n=Bn.Mesh;else if(this instanceof A.LineSegments)n=Bn.LineSegments;else if(this instanceof A.LineLoop)n=Bn.LineLoop;else if(this instanceof A.Line)n=Bn.Line;else if(this instanceof A.Points)n=Bn.Points;else throw new Error("BVH: Fallback raycast function not found.");n.call(this,r,e)}}}function Vf(r,e){if(this.boundsTrees){const t=this.boundsTrees,n=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,s=this.matrixWorld;De.material=this.material,De.geometry=this.geometry;const a=De.geometry.boundsTree,o=De.geometry.drawRange;De.geometry.boundingSphere===null&&(De.geometry.boundingSphere=new A.Sphere);for(let c=0,l=n.length;c<l;c++){if(!this.getVisibleAt(c))continue;const u=n[c].geometryIndex;if(De.geometry.boundsTree=t[u],this.getMatrixAt(c,De.matrixWorld).premultiply(s),!De.geometry.boundsTree){this.getBoundingBoxAt(u,De.geometry.boundingBox),this.getBoundingSphereAt(u,De.geometry.boundingSphere);const f=i[u];De.geometry.setDrawRange(f.start,f.count)}De.raycast(r,br);for(let f=0,p=br.length;f<p;f++){const m=br[f];m.object=this,m.batchId=c,e.push(m)}br.length=0}De.geometry.boundsTree=a,De.geometry.drawRange=o,De.material=null,De.geometry=null}else Bn.BatchedMesh.call(this,r,e)}function Jf(r={}){const{type:e=Vn}=r;return this.boundsTree=new e(this,r),this.boundsTree}const fn=new A.Vector3,dn=new A.Vector3,pn=new A.Vector3,Ha=new A.Vector4,Tr=new A.Vector3,Ns=new A.Vector3,qa=new A.Vector4,Xa=new A.Vector4,Mr=new A.Matrix4,Ya=new A.Matrix4;function ni(r,e){if(!r&&!e)return;const t=r.count===e.count,n=r.normalized===e.normalized,i=r.array.constructor===e.array.constructor,s=r.itemSize===e.itemSize;if(!t||!n||!i||!s)throw new Error}function oi(r,e=null){const t=r.array.constructor,n=r.normalized,i=r.itemSize,s=e===null?r.count:e;return new A.BufferAttribute(new t(i*s),i,n)}function ol(r,e,t=0){if(r.isInterleavedBufferAttribute){const n=r.itemSize;for(let i=0,s=r.count;i<s;i++){const a=i+t;e.setX(a,r.getX(i)),n>=2&&e.setY(a,r.getY(i)),n>=3&&e.setZ(a,r.getZ(i)),n>=4&&e.setW(a,r.getW(i))}}else{const n=e.array,i=n.constructor,s=n.BYTES_PER_ELEMENT*r.itemSize*t;new i(n.buffer,s,r.array.length).set(r.array)}}function jf(r,e,t){const n=r.elements,i=e.elements;for(let s=0,a=i.length;s<a;s++)n[s]+=i[s]*t}function Za(r,e,t){const n=r.skeleton,i=r.geometry,s=n.bones,a=n.boneInverses;qa.fromBufferAttribute(i.attributes.skinIndex,e),Xa.fromBufferAttribute(i.attributes.skinWeight,e),Mr.elements.fill(0);for(let o=0;o<4;o++){const c=Xa.getComponent(o);if(c!==0){const l=qa.getComponent(o);Ya.multiplyMatrices(s[l].matrixWorld,a[l]),jf(Mr,Ya,c)}}return Mr.multiply(r.bindMatrix).premultiply(r.bindMatrixInverse),t.transformDirection(Mr),t}function Us(r,e,t,n,i){Tr.set(0,0,0);for(let s=0,a=r.length;s<a;s++){const o=e[s],c=r[s];o!==0&&(Ns.fromBufferAttribute(c,n),t?Tr.addScaledVector(Ns,o):Tr.addScaledVector(Ns.sub(i),o))}i.add(Tr)}function Gf(r,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new A.BufferGeometry){const n=r[0].index!==null,{useGroups:i=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(r[0].attributes)),c={};let l=0;t.clearGroups();for(let u=0;u<r.length;++u){const f=r[u];let p=0;if(n!==(f.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const m in f.attributes){if(!o.has(m))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+m+'" attribute exists among all geometries, or in none of them.');c[m]===void 0&&(c[m]=[]),c[m].push(f.attributes[m]),p++}if(p!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(i){let m;if(n)m=f.index.count;else if(f.attributes.position!==void 0)m=f.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,m,u),l+=m}}if(n){let u=!1;if(!t.index){let f=0;for(let p=0;p<r.length;++p)f+=r[p].index.count;t.setIndex(new A.BufferAttribute(new Uint32Array(f),1,!1)),u=!0}if(s||u){const f=t.index;let p=0,m=0;for(let x=0;x<r.length;++x){const T=r[x],g=T.index;if(a[x]!==!0)for(let v=0;v<g.count;++v)f.setX(p,g.getX(v)+m),p++;m+=T.attributes.position.count}}}for(const u in c){const f=c[u];if(!(u in t.attributes)){let x=0;for(const T in f)x+=f[T].count;t.setAttribute(u,oi(c[u][0],x))}const p=t.attributes[u];let m=0;for(let x=0,T=f.length;x<T;x++){const g=f[x];a[x]!==!0&&ol(g,p,m),m+=g.count}}return t}function Wf(r,e){if(r===null||e===null)return r===e;if(r.length!==e.length)return!1;for(let t=0,n=r.length;t<n;t++)if(r[t]!==e[t])return!1;return!0}function $f(r){const{index:e,attributes:t}=r;if(e)for(let n=0,i=e.count;n<i;n+=3){const s=e.getX(n),a=e.getX(n+2);e.setX(n,a),e.setX(n+2,s)}else for(const n in t){const i=t[n],s=i.itemSize;for(let a=0,o=i.count;a<o;a+=3)for(let c=0;c<s;c++){const l=i.getComponent(a,c),u=i.getComponent(a+2,c);i.setComponent(a,c,u),i.setComponent(a+2,c,l)}}return r}class Hf{constructor(e){this.matrixWorld=new A.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,n=e.skeleton,i=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=i,n){n.boneTexture||n.computeBoneTexture(),n.update();const s=n.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==s.length?this.boneMatrices=s.slice():this.boneMatrices.set(s)}else this.boneMatrices=null}didChange(){const e=this.mesh,t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&Wf(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===n)}}class qf{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(n=>{n.traverseVisible(i=>{i.isMesh&&t.push(i)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(t.length).fill().map(()=>new A.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 A.BufferGeometry){let t=[];const{meshes:n,useGroups:i,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=n.length;o<c;o++){const l=n[o],u=s[o],f=a.get(l);!f||f.didChange(l)?(this._convertToStaticGeometry(l,u),t.push(!1),f?f.update():a.set(l,new Hf(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 A.BufferAttribute(new Float32Array(0),4,!1))}else Gf(s,{useGroups:i,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new A.BufferGeometry){const n=e.geometry,i=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=n.attributes,c=t.attributes;!t.index&&n.index&&(t.index=n.index.clone()),c.position||t.setAttribute("position",oi(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",oi(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",oi(o.tangent)),ni(n.index,t.index),ni(o.position,c.position),s&&ni(o.normal,c.normal),a&&ni(o.tangent,c.tangent);const l=o.position,u=s?o.normal:null,f=a?o.tangent:null,p=n.morphAttributes.position,m=n.morphAttributes.normal,x=n.morphAttributes.tangent,T=n.morphTargetsRelative,g=e.morphTargetInfluences,v=new A.Matrix3;v.getNormalMatrix(e.matrixWorld),n.index&&t.index.array.set(n.index.array);for(let _=0,b=o.position.count;_<b;_++)fn.fromBufferAttribute(l,_),u&&dn.fromBufferAttribute(u,_),f&&(Ha.fromBufferAttribute(f,_),pn.fromBufferAttribute(f,_)),g&&(p&&Us(p,g,T,_,fn),m&&Us(m,g,T,_,dn),x&&Us(x,g,T,_,pn)),e.isSkinnedMesh&&(e.applyBoneTransform(_,fn),u&&Za(e,_,dn),f&&Za(e,_,pn)),i&&fn.applyMatrix4(e.matrixWorld),c.position.setXYZ(_,fn.x,fn.y,fn.z),u&&(i&&dn.applyNormalMatrix(v),c.normal.setXYZ(_,dn.x,dn.y,dn.z)),f&&(i&&pn.transformDirection(e.matrixWorld),c.tangent.setXYZW(_,pn.x,pn.y,pn.z,Ha.w));for(const _ in this.attributes){const b=this.attributes[_];b==="position"||b==="tangent"||b==="normal"||!(b in o)||(c[b]||t.setAttribute(b,oi(o[b])),ni(o[b],c[b]),ol(o[b],c[b]))}return e.matrixWorld.determinant()<0&&$f(t),t}}const Xf=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:Zc,BVH:il,CENTER:go,CONTAINED:Ys,ExtendedTriangle:gt,GeometryBVH:sl,MeshBVH:Vn,OrientedBox:qe,SAH:Kc,SKIP_GENERATION:Wr,StaticGeometryGenerator:qf,acceleratedRaycast:Lf,computeBoundsTree:Jf,generateIndirectBuffer:rl},Symbol.toStringTag,{value:"Module"}));class Yf{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 mt={node:"node",material:"material",camera:"camera",light:"light"},mn="KHR_animation_pointer",Zf={CUBICSPLINE:void 0,LINEAR:A.InterpolateLinear,STEP:A.InterpolateDiscrete};class Kf{constructor(e){this.name=mn,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,n=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",n)}loadAnimationTargetFromChannelWithAnimationPointer(e){ed();const t=e.target,n=t.extensions&&t.extensions[mn]&&t.path&&t.path==="pointer";if(!n)return null;let i,s=mt.node,a;if(n){const c=t.extensions[mn];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=mt.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=mt.light:l.startsWith("/cameras/")&&(s=mt.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case mt.material:const u=("/materials/"+a.toString()+"/").length,f=l.substring(0,u);switch(i=l.substring(u),i){case"pbrMetallicRoughness/baseColorFactor":i="color";break;case"pbrMetallicRoughness/roughnessFactor":i="roughness";break;case"pbrMetallicRoughness/metallicFactor":i="metalness";break;case"emissiveFactor":i="emissive";break;case"alphaCutoff":i="alphaTest";break;case"occlusionTexture/strength":i="aoMapIntensity";break;case"normalTexture/scale":i="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":i="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":i="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":i="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":i="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":i="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":i="transmission";break;case"extensions/KHR_materials_ior/ior":i="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":i="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":i="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":i="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":i="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":i="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":i="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":i="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":i="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":i="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":i="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":i="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":i="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":i="specularColor";break}l=f+i;break;case mt.node:const p=("/nodes/"+a.toString()+"/").length,m=l.substring(0,p);switch(i=l.substring(p),i){case"translation":i="position";break;case"rotation":i="quaternion";break;case"scale":i="scale";break;case"weights":i="morphTargetInfluences";break;case"extensions/KHR_node_visibility/visible":i="visible";break}l=m+i;break;case mt.light:const x=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(i=l.substring(x),i){case"color":break;case"intensity":break;case"spot/innerConeAngle":i="penumbra";break;case"spot/outerConeAngle":i="angle";break;case"range":i="distance";break}l="/lights/"+a.toString()+"/"+i;break;case mt.camera:const T=("/cameras/"+a.toString()+"/").length,g=l.substring(0,T);switch(i=l.substring(T),i){case"perspective/yfov":i="fov";break;case"perspective/znear":case"orthographic/znear":i="near";break;case"perspective/zfar":case"orthographic/zfar":i="far";break;case"perspective/aspect":i="aspect";break;case"orthographic/xmag":i="zoom";break;case"orthographic/ymag":i="zoom";break}l=g+i;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[mn].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===mt.node?o=this.parser.getDependency("node",a):s===mt.material?o=this.parser.getDependency("material",a):s===mt.light?o=this.parser.getDependency("light",a):s===mt.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,n,i,s){if(!(s.extensions&&s.extensions[mn]&&s.path&&s.path==="pointer"))return null;let o=s.extensions[mn].pointer;if(!o)return null;const c=[];o=o.replaceAll("/",".");const l=o.split(".");var f=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(l[2]=f,l[3]==="morphTargetInfluences"&&e.type==="Group"){for(const x of e.children)x instanceof A.SkinnedMesh&&x.morphTargetInfluences&&(l[3]=x.name,l[4]="morphTargetInfluences",m(this.parser));return c}m(this.parser);function p(x,T){try{const g=T.split(".").filter(Boolean),_=g[g.length-1].replace(/\[.*\]$/,"");return _ in x?typeof x[_]=="boolean":!1}catch{return!1}}function m(x){o=l.join(".");let T,g=!1;switch(n.itemSize){case 1:Object.prototype.toString.call(n.array)==="[object Uint8Array]"&&p(e,o)?(T=A.BooleanKeyframeTrack,g=!0):T=A.NumberKeyframeTrack;break;case 2:case 3:T=A.VectorKeyframeTrack;break;case 4:o.endsWith(".quaternion")?T=A.QuaternionKeyframeTrack:T=A.ColorKeyframeTrack;break}if(!T){console.warn("Unsupported output accessor format",n);return}const v=i.interpolation!==void 0?Zf[i.interpolation]:A.InterpolateLinear;let _=x._getArrayFromAccessor(n);o.endsWith(".fov")&&(_=_.map(M=>M/Math.PI*180)),g&&(_=_.map(M=>M>0));const b=new T(o,t.array,_,v);if(v==="CUBICSPLINE"&&x._createCubicSplineTrackInterpolant(b),c.push(b),o&&n.itemSize===4&&o.startsWith(".materials.")&&o.endsWith(".color")){const M=new Float32Array(_.length/4);for(let P=0,E=_.length/4;P<E;P+=1)M[P]=_[P*4+3];const C=new T(o.replace(".color",".opacity"),t.array,M,v);v==="CUBICSPLINE"&&x._createCubicSplineTrackInterpolant(b),c.push(C)}}return c}_tryResolveTargetId(e,t){let n="";return t==="node"?n=e.substring(7):t==="material"?n=e.substring(11):t==="light"?n=e.substring(39):t==="camera"&&(n=e.substring(9)),n=n.substring(0,n.indexOf("/")),Number.parseInt(n)}loadAnimation(e){const t=this,n=this.parser.json,i=this.parser,s=n.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],u=[],f=[];for(let p=0,m=s.channels.length;p<m;p++){const x=s.channels[p],T=s.samplers[x.sampler],g=x.target,v=s.parameters!==void 0?s.parameters[T.input]:T.input,_=s.parameters!==void 0?s.parameters[T.output]:T.output;let b=t.loadAnimationTargetFromChannelWithAnimationPointer(x);b||(b=t.loadAnimationTargetFromChannel(x)),o.push(b),c.push(i.getDependency("accessor",v)),l.push(i.getDependency("accessor",_)),u.push(T),f.push(g)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(u),Promise.all(f)]).then(function(p){const m=p[0],x=p[1],T=p[2],g=p[3],v=p[4],_=[];for(let b=0,M=m.length;b<M;b++){const C=m[b],P=x[b],E=T[b],z=g[b],I=v[b];if(C===void 0)continue;C.updateMatrix&&(C.updateMatrix(),C.matrixAutoUpdate=!0);let R=t.createAnimationTracksWithAnimationPointer(C,P,E,z,I);if(R||(R=i._createAnimationTracks(C,P,E,z,I)),R)for(let N=0;N<R.length;N++)_.push(R[N])}return new A.AnimationClip(a,void 0,_)})}}let Ka=!1,Qf=null;function ed(){if(Ka)return;Ka=!0;const r=Qf||=A.PropertyBinding.findNode;A.PropertyBinding.findNode=function(e,t){if(!t)return r(e,t);if(t.startsWith(".materials.")){const n=t.substring(11).substring(t.indexOf(".")),i=n.indexOf("."),s=i<0?n:n.substring(0,i);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(n.endsWith(".map")?a=a.map:n.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const n=t.split(".");let i;for(let s=1;s<n.length;s++){const a=n[s];if(a.length==36)i=e.getObjectByProperty("uuid",a);else if(i&&i[a]){const c=Number.parseInt(a);let l=a;c>=0&&(l=c),i=i[l]}else{const c=e.getObjectByName(a);c&&(i=c)}}if(!i){const s=r(e,n[2]);return s||console.warn(mn+": Property binding not found",t,e,e.name,n),s}return i}return r(e,t)}}const td=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Kf},Symbol.toStringTag,{value:"Module"}));exports.BatchedParticleRenderer=nh;exports.Builder=ao;exports.ByteBuffer=li;exports.ConstantColor=vn;exports.ConstantValue=ee;exports.Matrix4=Et;exports.MeshBVH=Vn;exports.MotionController=Hl;exports.ParticleSystem=Ur;exports.SIZE_PREFIX_LENGTH=ec;exports.TrailParticle=Br;exports.Vector4=at;exports.WorkerBase=Yf;exports._md5=kl;exports.bundler=Lh;exports.createNoise4D=rh;exports.fetchProfile=Jl;exports.index=jh;exports.index$1=Xf;exports.index$2=td;exports.md5=Qa;exports.v5=Ll;
1116
+ isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},r})()),va={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"},bh=(function(){function r(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=va,this.browser=Hn.getBrowser(),this.browserVersion=Hn.getVersion(),this.supports=(function(){var e={browser:Hn.isBrowserSupported(),webRTC:Hn.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(va),e.audioVideo=!0;var n=void 0;try{n=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!n.ordered;try{n.binaryType="blob",e.binaryBlob=!Hn.isIOS}catch{}}catch{}finally{n&&n.close()}}catch{}finally{t&&t.close()}return e})(),this.pack=aa.pack,this.unpack=aa.unpack,this._dataCount=1}return r.prototype.noop=function(){},r.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},r.prototype.chunk=function(e){for(var t=[],n=e.size,i=Math.ceil(n/te.chunkedMTU),s=0,a=0;a<n;){var o=Math.min(n,a+te.chunkedMTU),c=e.slice(a,o),l={__peerData:this._dataCount,n:s,data:c,total:i};t.push(l),a=o,s++}return this._dataCount++,t},r.prototype.blobToArrayBuffer=function(e,t){var n=new FileReader;return n.onload=function(i){i.target&&t(i.target.result)},n.readAsArrayBuffer(e),n},r.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t.buffer},r.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},r.prototype.isSecure=function(){return location.protocol==="https:"},r})(),te=new bh,Wc={};Bt(Wc,"Peer",()=>Xs,r=>Xs=r);var Gi={},Th=Object.prototype.hasOwnProperty,nt="~";function Ji(){}Object.create&&(Ji.prototype=Object.create(null),new Ji().__proto__||(nt=!1));function Mh(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function $c(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new Mh(t,n||r,i),a=nt?nt+e:e;return r._events[a]?r._events[a].fn?r._events[a]=[r._events[a],s]:r._events[a].push(s):(r._events[a]=s,r._eventsCount++),r}function Er(r,e){--r._eventsCount===0?r._events=new Ji:delete r._events[e]}function He(){this._events=new Ji,this._eventsCount=0}He.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)Th.call(t,n)&&e.push(nt?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};He.prototype.listeners=function(e){var t=nt?nt+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,a=new Array(s);i<s;i++)a[i]=n[i].fn;return a};He.prototype.listenerCount=function(e){var t=nt?nt+e:e,n=this._events[t];return n?n.fn?1:n.length:0};He.prototype.emit=function(e,t,n,i,s,a){var o=nt?nt+e:e;if(!this._events[o])return!1;var c=this._events[o],l=arguments.length,u,f;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,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,s),!0;case 6:return c.fn.call(c.context,t,n,i,s,a),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var p=c.length,m;for(f=0;f<p;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,i);break;default:if(!u)for(m=1,u=new Array(l-1);m<l;m++)u[m-1]=arguments[m];c[f].fn.apply(c[f].context,u)}}return!0};He.prototype.on=function(e,t,n){return $c(this,e,t,n,!1)};He.prototype.once=function(e,t,n){return $c(this,e,t,n,!0)};He.prototype.removeListener=function(e,t,n,i){var s=nt?nt+e:e;if(!this._events[s])return this;if(!t)return Er(this,s),this;var a=this._events[s];if(a.fn)a.fn===t&&(!i||a.once)&&(!n||a.context===n)&&Er(this,s);else{for(var o=0,c=[],l=a.length;o<l;o++)(a[o].fn!==t||i&&!a[o].once||n&&a[o].context!==n)&&c.push(a[o]);c.length?this._events[s]=c.length===1?c[0]:c:Er(this,s)}return this};He.prototype.removeAllListeners=function(e){var t;return e?(t=nt?nt+e:e,this._events[t]&&Er(this,t)):(this._events=new Ji,this._eventsCount=0),this};He.prototype.off=He.prototype.removeListener;He.prototype.addListener=He.prototype.on;He.prefixed=nt;He.EventEmitter=He;Gi=He;var j={};Bt(j,"LogLevel",()=>ot,r=>ot=r);Bt(j,"default",()=>Sa,r=>Sa=r);var an=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},cn=function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},Ch="PeerJS: ",ot;(function(r){r[r.Disabled=0]="Disabled",r[r.Errors=1]="Errors",r[r.Warnings=2]="Warnings",r[r.All=3]="All"})(ot||(ot={}));var wh=(function(){function r(){this._logLevel=ot.Disabled}return Object.defineProperty(r.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),r.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=ot.All&&this._print.apply(this,cn([ot.All],an(e),!1))},r.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=ot.Warnings&&this._print.apply(this,cn([ot.Warnings],an(e),!1))},r.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=ot.Errors&&this._print.apply(this,cn([ot.Errors],an(e),!1))},r.prototype.setLogFunction=function(e){this._print=e},r.prototype._print=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var i=cn([Ch],an(t),!1);for(var s in i)i[s]instanceof Error&&(i[s]="("+i[s].name+") "+i[s].message);e>=ot.All?console.log.apply(console,cn([],an(i),!1)):e>=ot.Warnings?console.warn.apply(console,cn(["WARNING"],an(i),!1)):e>=ot.Errors&&console.error.apply(console,cn(["ERROR"],an(i),!1))},r})(),Sa=new wh,Hc={};Bt(Hc,"Socket",()=>xa,r=>xa=r);var Pt;(function(r){r.Data="data",r.Media="media"})(Pt||(Pt={}));var _e;(function(r){r.BrowserIncompatible="browser-incompatible",r.Disconnected="disconnected",r.InvalidID="invalid-id",r.InvalidKey="invalid-key",r.Network="network",r.PeerUnavailable="peer-unavailable",r.SslUnavailable="ssl-unavailable",r.ServerError="server-error",r.SocketError="socket-error",r.SocketClosed="socket-closed",r.UnavailableID="unavailable-id",r.WebRTC="webrtc"})(_e||(_e={}));var jt;(function(r){r.Binary="binary",r.BinaryUTF8="binary-utf8",r.JSON="json"})(jt||(jt={}));var $t;(function(r){r.Message="message",r.Disconnected="disconnected",r.Error="error",r.Close="close"})($t||($t={}));var Le;(function(r){r.Heartbeat="HEARTBEAT",r.Candidate="CANDIDATE",r.Offer="OFFER",r.Answer="ANSWER",r.Open="OPEN",r.Error="ERROR",r.IdTaken="ID-TAKEN",r.InvalidKey="INVALID-KEY",r.Leave="LEAVE",r.Expire="EXPIRE"})(Le||(Le={}));var po={};po=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 Ph=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Eh=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},kh=function(r,e,t){if(t||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return r.concat(s||Array.prototype.slice.call(e))},Rh=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},xa=(function(r){Ph(e,r);function e(t,n,i,s,a,o){o===void 0&&(o=5e3);var c=r.call(this)||this;c.pingInterval=o,c._disconnected=!0,c._messagesQueue=[];var l=t?"wss://":"ws://";return c._baseUrl=l+n+":"+i+s+"peerjs?key="+a,c}return e.prototype.start=function(t,n){var i=this;this._id=t;var s="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(n);this._socket||!this._disconnected||(this._socket=new WebSocket(s+"&version="+po.version),this._disconnected=!1,this._socket.onmessage=function(a){var o;try{o=JSON.parse(a.data),j.default.log("Server message received:",o)}catch{j.default.log("Invalid server message",a.data);return}i.emit($t.Message,o)},this._socket.onclose=function(a){i._disconnected||(j.default.log("Socket closed.",a),i._cleanup(),i._disconnected=!0,i.emit($t.Disconnected))},this._socket.onopen=function(){i._disconnected||(i._sendQueuedMessages(),j.default.log("Socket open"),i._scheduleHeartbeat())})},e.prototype._scheduleHeartbeat=function(){var t=this;this._wsPingTimer=setTimeout(function(){t._sendHeartbeat()},this.pingInterval)},e.prototype._sendHeartbeat=function(){if(!this._wsOpen()){j.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:Le.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,n,i=kh([],Eh(this._messagesQueue),!1);this._messagesQueue=[];try{for(var s=Rh(i),a=s.next();!a.done;a=s.next()){var o=a.value;this.send(o)}}catch(c){t={error:c}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},e.prototype.send=function(t){if(!this._disconnected){if(!this._id){this._messagesQueue.push(t);return}if(!t.type){this.emit($t.Error,"Invalid message");return}if(this._wsOpen()){var n=JSON.stringify(t);this._socket.send(n)}}},e.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},e.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)},e})(Gi.EventEmitter),Hs={};Bt(Hs,"MediaConnection",()=>Ta,r=>Ta=r);var mo={};Bt(mo,"Negotiator",()=>_a,r=>_a=r);var Dr=function(){return Dr=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},Dr.apply(this,arguments)},sr=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(n.next(u))}catch(f){a(f)}}function c(u){try{l(n.throw(u))}catch(f){a(f)}}function l(u){u.done?s(u.value):i(u.value).then(o,c)}l((n=n.apply(r,e||[])).next())})},or=function(r,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(s=l[0]&2?i.return:l[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,l[1])).done)return s;switch(i=0,s&&(l=[l[0]&2,s.value]),l[0]){case 0:case 1:s=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,i=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!s||l[1]>s[0]&&l[1]<s[3])){t.label=l[1];break}if(l[0]===6&&t.label<s[1]){t.label=s[1],s=l;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(l);break}s[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(u){l=[6,u],i=0}finally{n=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},_a=(function(){function r(e){this.connection=e}return r.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===Pt.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===Pt.Data){var n=this.connection,i={ordered:!!e.reliable},s=t.createDataChannel(n.label,i);n.initialize(s)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},r.prototype._startPeerConnection=function(){j.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},r.prototype._setupListeners=function(e){var t=this,n=this.connection.peer,i=this.connection.connectionId,s=this.connection.type,a=this.connection.provider;j.default.log("Listening for ICE candidates."),e.onicecandidate=function(o){!o.candidate||!o.candidate.candidate||(j.default.log("Received ICE candidates for ".concat(n,":"),o.candidate),a.socket.send({type:Le.Candidate,payload:{candidate:o.candidate,type:s,connectionId:i},dst:n}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":j.default.log("iceConnectionState is failed, closing connections to "+n),t.connection.emit("error",new Error("Negotiation of connection to "+n+" failed.")),t.connection.close();break;case"closed":j.default.log("iceConnectionState is closed, closing connections to "+n),t.connection.emit("error",new Error("Connection to "+n+" closed.")),t.connection.close();break;case"disconnected":j.default.log("iceConnectionState changed to disconnected on the connection with "+n);break;case"completed":e.onicecandidate=te.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},j.default.log("Listening for data channel"),e.ondatachannel=function(o){j.default.log("Received data channel");var c=o.channel,l=a.getConnection(n,i);l.initialize(c)},j.default.log("Listening for remote stream"),e.ontrack=function(o){j.default.log("Received remote stream");var c=o.streams[0],l=a.getConnection(n,i);if(l.type===Pt.Media){var u=l;t._addStreamToMediaConnection(c,u)}}},r.prototype.cleanup=function(){j.default.log("Cleaning up PeerConnection to "+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!=="closed",n=!1;if(this.connection.type===Pt.Data){var i=this.connection,s=i.dataChannel;s&&(n=!!s.readyState&&s.readyState!=="closed")}(t||n)&&e.close()}},r.prototype._makeOffer=function(){return sr(this,void 0,Promise,function(){var e,t,n,i,s,a,o;return or(this,function(c){switch(c.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,c.label=1;case 1:return c.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:n=c.sent(),j.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),c.label=3;case 3:return c.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return c.sent(),j.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),i={sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:te.browser},this.connection.type===Pt.Data&&(s=this.connection,i=Dr(Dr({},i),{label:s.label,reliable:s.reliable,serialization:s.serialization})),t.socket.send({type:Le.Offer,payload:i,dst:this.connection.peer}),[3,6];case 5:return a=c.sent(),a!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(t.emitError(_e.WebRTC,a),j.default.log("Failed to setLocalDescription, ",a)),[3,6];case 6:return[3,8];case 7:return o=c.sent(),t.emitError(_e.WebRTC,o),j.default.log("Failed to createOffer, ",o),[3,8];case 8:return[2]}})})},r.prototype._makeAnswer=function(){return sr(this,void 0,Promise,function(){var e,t,n,i,s;return or(this,function(a){switch(a.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,a.label=1;case 1:return a.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:n=a.sent(),j.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),a.label=3;case 3:return a.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return a.sent(),j.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),t.socket.send({type:Le.Answer,payload:{sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,browser:te.browser},dst:this.connection.peer}),[3,6];case 5:return i=a.sent(),t.emitError(_e.WebRTC,i),j.default.log("Failed to setLocalDescription, ",i),[3,6];case 6:return[3,8];case 7:return s=a.sent(),t.emitError(_e.WebRTC,s),j.default.log("Failed to create answer, ",s),[3,8];case 8:return[2]}})})},r.prototype.handleSDP=function(e,t){return sr(this,void 0,Promise,function(){var n,i,s,a;return or(this,function(o){switch(o.label){case 0:t=new RTCSessionDescription(t),n=this.connection.peerConnection,i=this.connection.provider,j.default.log("Setting remote description",t),s=this,o.label=1;case 1:return o.trys.push([1,5,,6]),[4,n.setRemoteDescription(t)];case 2:return o.sent(),j.default.log("Set remoteDescription:".concat(e," for:").concat(this.connection.peer)),e!=="OFFER"?[3,4]:[4,s._makeAnswer()];case 3:o.sent(),o.label=4;case 4:return[3,6];case 5:return a=o.sent(),i.emitError(_e.WebRTC,a),j.default.log("Failed to setRemoteDescription, ",a),[3,6];case 6:return[2]}})})},r.prototype.handleCandidate=function(e){return sr(this,void 0,Promise,function(){var t,n,i,s,a,o;return or(this,function(c){switch(c.label){case 0:j.default.log("handleCandidate:",e),t=e.candidate,n=e.sdpMLineIndex,i=e.sdpMid,s=this.connection.peerConnection,a=this.connection.provider,c.label=1;case 1:return c.trys.push([1,3,,4]),[4,s.addIceCandidate(new RTCIceCandidate({sdpMid:i,sdpMLineIndex:n,candidate:t}))];case 2:return c.sent(),j.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return o=c.sent(),a.emitError(_e.WebRTC,o),j.default.log("Failed to handleCandidate, ",o),[3,4];case 4:return[2]}})})},r.prototype._addTracksToConnection=function(e,t){if(j.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return j.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(n){t.addTrack(n,e)})},r.prototype._addStreamToMediaConnection=function(e,t){j.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},r})(),yo={};Bt(yo,"BaseConnection",()=>ba,r=>ba=r);var Ah=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),ba=(function(r){Ah(e,r);function e(t,n,i){var s=r.call(this)||this;return s.peer=t,s.provider=n,s.options=i,s._open=!1,s.metadata=i.metadata,s}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e})(Gi.EventEmitter),Oh=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Fr=function(){return Fr=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},Fr.apply(this,arguments)},zh=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ta=(function(r){Oh(e,r);function e(t,n,i){var s=r.call(this,t,n,i)||this;return s._localStream=s.options._stream,s.connectionId=s.options.connectionId||e.ID_PREFIX+te.randomToken(),s._negotiator=new mo.Negotiator(s),s._localStream&&s._negotiator.startConnection({_stream:s._localStream,originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return Pt.Media},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localStream",{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteStream",{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),e.prototype.addStream=function(t){j.default.log("Receiving stream",t),this._remoteStream=t,r.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var n=t.type,i=t.payload;switch(t.type){case Le.Answer:this._negotiator.handleSDP(n,i.sdp),this._open=!0;break;case Le.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:j.default.warn("Unrecognized message type:".concat(n," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,n){var i,s;if(n===void 0&&(n={}),this._localStream){j.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,n&&n.sdpTransform&&(this.options.sdpTransform=n.sdpTransform),this._negotiator.startConnection(Fr(Fr({},this.options._payload),{_stream:t}));var a=this.provider._getMessages(this.connectionId);try{for(var o=zh(a),c=o.next();!c.done;c=o.next()){var l=c.value;this.handleMessage(l)}}catch(u){i={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}this._open=!0},e.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,r.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e})(yo.BaseConnection),qs={};Bt(qs,"DataConnection",()=>Ca,r=>Ca=r);var qc={};Bt(qc,"EncodingQueue",()=>Ma,r=>Ma=r);var Ih=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Ma=(function(r){Ih(e,r);function e(){var t=r.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(n){t._processing=!1,n.target&&t.emit("done",n.target.result),t.doNextTask()},t.fileReader.onerror=function(n){j.default.error("EncodingQueue error:",n),t._processing=!1,t.destroy(),t.emit("error",n)},t}return Object.defineProperty(e.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),e.prototype.enque=function(t){this.queue.push(t),!this.processing&&this.doNextTask()},e.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},e.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},e})(Gi.EventEmitter),Bh=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),Nh=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ca=(function(r){Bh(e,r);function e(t,n,i){var s=r.call(this,t,n,i)||this;return s.stringify=JSON.stringify,s.parse=JSON.parse,s._buffer=[],s._bufferSize=0,s._buffering=!1,s._chunkedData={},s._encodingQueue=new qc.EncodingQueue,s.connectionId=s.options.connectionId||e.ID_PREFIX+te.randomToken(),s.label=s.options.label||s.connectionId,s.serialization=s.options.serialization||jt.Binary,s.reliable=!!s.options.reliable,s._encodingQueue.on("done",function(a){s._bufferedSend(a)}),s._encodingQueue.on("error",function(){j.default.error("DC#".concat(s.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),s.close()}),s._negotiator=new mo.Negotiator(s),s._negotiator.startConnection(s.options._payload||{originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return Pt.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;(!te.supports.binaryBlob||te.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){j.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(n){j.default.log("DC#".concat(t.connectionId," dc onmessage:"),n.data),t._handleDataMessage(n)},this.dataChannel.onclose=function(){j.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var n=this,i=t.data,s=i.constructor,a=this.serialization===jt.Binary||this.serialization===jt.BinaryUTF8,o=i;if(a){if(s===Blob){te.blobToArrayBuffer(i,function(l){var u=te.unpack(l);n.emit("data",u)});return}else if(s===ArrayBuffer)o=te.unpack(i);else if(s===String){var c=te.binaryStringToArrayBuffer(i);o=te.unpack(c)}}else this.serialization===jt.JSON&&(o=this.parse(i));if(o.__peerData){this._handleChunk(o);return}r.prototype.emit.call(this,"data",o)},e.prototype._handleChunk=function(t){var n=t.__peerData,i=this._chunkedData[n]||{data:[],count:0,total:t.total};if(i.data[t.n]=t.data,i.count++,this._chunkedData[n]=i,i.total===i.count){delete this._chunkedData[n];var s=new Blob(i.data);this._handleDataMessage({data:s})}},e.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),this._encodingQueue=null),this.open&&(this._open=!1,r.prototype.emit.call(this,"close"))},e.prototype.send=function(t,n){if(!this.open){r.prototype.emit.call(this,"error",new Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===jt.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===jt.Binary||this.serialization===jt.BinaryUTF8){var i=te.pack(t);if(!n&&i.size>te.chunkedMTU){this._sendChunks(i);return}te.supports.binaryBlob?this._bufferedSend(i):this._encodingQueue.enque(i)}else this._bufferedSend(t)},e.prototype._bufferedSend=function(t){(this._buffering||!this._trySend(t))&&(this._buffer.push(t),this._bufferSize=this._buffer.length)},e.prototype._trySend=function(t){var n=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){n._buffering=!1,n._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(i){return j.default.error("DC#:".concat(this.connectionId," Error when sending:"),i),this._buffering=!0,this.close(),!1}return!0},e.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},e.prototype._sendChunks=function(t){var n,i,s=te.chunk(t);j.default.log("DC#".concat(this.connectionId," Try to send ").concat(s.length," chunks..."));try{for(var a=Nh(s),o=a.next();!o.done;o=a.next()){var c=o.value;this.send(c,!0)}}catch(l){n={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}},e.prototype.handleMessage=function(t){var n=t.payload;switch(t.type){case Le.Answer:this._negotiator.handleSDP(t.type,n.sdp);break;case Le.Candidate:this._negotiator.handleCandidate(n.candidate);break;default:j.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e})(yo.BaseConnection),Xc={};Bt(Xc,"API",()=>Ea,r=>Ea=r);var wa=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(a){a(s)})}return new(t||(t=Promise))(function(s,a){function o(u){try{l(n.next(u))}catch(f){a(f)}}function c(u){try{l(n.throw(u))}catch(f){a(f)}}function l(u){u.done?s(u.value):i(u.value).then(o,c)}l((n=n.apply(r,e||[])).next())})},Pa=function(r,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,a;return a={next:o(0),throw:o(1),return:o(2)},typeof Symbol=="function"&&(a[Symbol.iterator]=function(){return this}),a;function o(l){return function(u){return c([l,u])}}function c(l){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(s=l[0]&2?i.return:l[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,l[1])).done)return s;switch(i=0,s&&(l=[l[0]&2,s.value]),l[0]){case 0:case 1:s=l;break;case 4:return t.label++,{value:l[1],done:!1};case 5:t.label++,i=l[1],l=[0];continue;case 7:l=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(l[0]===6||l[0]===2)){t=0;continue}if(l[0]===3&&(!s||l[1]>s[0]&&l[1]<s[3])){t.label=l[1];break}if(l[0]===6&&t.label<s[1]){t.label=s[1],s=l;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(l);break}s[2]&&t.ops.pop(),t.trys.pop();continue}l=e.call(r,t)}catch(u){l=[6,u],i=0}finally{n=s=0}if(l[0]&5)throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}},Ea=(function(){function r(e){this._options=e}return r.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",n=this._options,i=n.host,s=n.port,a=n.path,o=n.key,c=new URL("".concat(t,"://").concat(i,":").concat(s).concat(a).concat(o,"/").concat(e));return c.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),c.searchParams.set("version",po.version),fetch(c.href,{referrerPolicy:this._options.referrerPolicy})},r.prototype.retrieveId=function(){return wa(this,void 0,Promise,function(){var e,t,n;return Pa(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=i.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=i.sent(),j.default.error("Error retrieving ID",t),n="",this._options.path==="/"&&this._options.host!==te.CLOUD_HOST&&(n=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+n);case 3:return[2]}})})},r.prototype.listAllPeers=function(){return wa(this,void 0,Promise,function(){var e,t,n;return Pa(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=i.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===te.CLOUD_HOST?t="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":t="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+t)):new Error("Error. Status:".concat(e.status));return[2,e.json()];case 2:throw n=i.sent(),j.default.error("Error retrieving list peers",n),new Error("Could not get list peers from the server."+n);case 3:return[2]}})})},r})(),Uh=(function(){var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])},r(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");r(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}})(),ai=function(){return ai=Object.assign||function(r){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i])}return r},ai.apply(this,arguments)},qn=function(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Dh=function(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var n=t.call(r),i,s=[],a;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(o){a={error:o}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(a)throw a.error}}return s},Xs=(function(r){Uh(e,r);function e(t,n){var i=r.call(this)||this;i._id=null,i._lastServerId=null,i._destroyed=!1,i._disconnected=!1,i._open=!1,i._connections=new Map,i._lostMessages=new Map;var s;return t&&t.constructor==Object?n=t:t&&(s=t.toString()),n=ai({debug:0,host:te.CLOUD_HOST,port:te.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:te.randomToken(),config:te.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},n),i._options=n,i._options.host==="/"&&(i._options.host=window.location.hostname),i._options.path&&(i._options.path[0]!=="/"&&(i._options.path="/"+i._options.path),i._options.path[i._options.path.length-1]!=="/"&&(i._options.path+="/")),i._options.secure===void 0&&i._options.host!==te.CLOUD_HOST?i._options.secure=te.isSecure():i._options.host==te.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&j.default.setLogFunction(i._options.logFunction),j.default.logLevel=i._options.debug||0,i._api=new Xc.API(n),i._socket=i._createServerConnection(),!te.supports.audioVideo&&!te.supports.data?(i._delayedAbort(_e.BrowserIncompatible,"The current browser does not support WebRTC"),i):s&&!te.validateId(s)?(i._delayedAbort(_e.InvalidID,'ID "'.concat(s,'" is invalid')),i):(s?i._initialize(s):i._api.retrieveId().then(function(a){return i._initialize(a)}).catch(function(a){return i._abort(_e.ServerError,a)}),i)}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){var t,n,i=Object.create(null);try{for(var s=qn(this._connections),a=s.next();!a.done;a=s.next()){var o=Dh(a.value,2),c=o[0],l=o[1];i[c]=l}}catch(u){t={error:u}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return i},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),e.prototype._createServerConnection=function(){var t=this,n=new Hc.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return n.on($t.Message,function(i){t._handleMessage(i)}),n.on($t.Error,function(i){t._abort(_e.SocketError,i)}),n.on($t.Disconnected,function(){t.disconnected||(t.emitError(_e.Network,"Lost connection to server."),t.disconnect())}),n.on($t.Close,function(){t.disconnected||t._abort(_e.SocketClosed,"Underlying socket is already closed.")}),n},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var n,i,s=t.type,a=t.payload,o=t.src;switch(s){case Le.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case Le.Error:this._abort(_e.ServerError,a.msg);break;case Le.IdTaken:this._abort(_e.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case Le.InvalidKey:this._abort(_e.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case Le.Leave:j.default.log("Received leave message from ".concat(o)),this._cleanupPeer(o),this._connections.delete(o);break;case Le.Expire:this.emitError(_e.PeerUnavailable,"Could not connect to peer ".concat(o));break;case Le.Offer:var x=a.connectionId,T=this.getConnection(o,x);if(T&&(T.close(),j.default.warn("Offer received for existing Connection ID:".concat(x))),a.type===Pt.Media){var c=new Hs.MediaConnection(o,this,{connectionId:x,_payload:a,metadata:a.metadata});T=c,this._addConnection(o,T),this.emit("call",c)}else if(a.type===Pt.Data){var l=new qs.DataConnection(o,this,{connectionId:x,_payload:a,metadata:a.metadata,label:a.label,serialization:a.serialization,reliable:a.reliable});T=l,this._addConnection(o,T),this.emit("connection",l)}else{j.default.warn("Received malformed connection type:".concat(a.type));return}var u=this._getMessages(x);try{for(var f=qn(u),p=f.next();!p.done;p=f.next()){var m=p.value;T.handleMessage(m)}}catch(g){n={error:g}}finally{try{p&&!p.done&&(i=f.return)&&i.call(f)}finally{if(n)throw n.error}}break;default:if(!a){j.default.warn("You received a malformed message from ".concat(o," of type ").concat(s));return}var x=a.connectionId,T=this.getConnection(o,x);T&&T.peerConnection?T.handleMessage(t):x?this._storeMessage(x,t):j.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,n){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(n)},e.prototype._getMessages=function(t){var n=this._lostMessages.get(t);return n?(this._lostMessages.delete(t),n):[]},e.prototype.connect=function(t,n){if(n===void 0&&(n={}),this.disconnected){j.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),this.emitError(_e.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var i=new qs.DataConnection(t,this,n);return this._addConnection(t,i),i},e.prototype.call=function(t,n,i){if(i===void 0&&(i={}),this.disconnected){j.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),this.emitError(_e.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!n){j.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var s=new Hs.MediaConnection(t,this,ai(ai({},i),{_stream:n}));return this._addConnection(t,s),s},e.prototype._addConnection=function(t,n){j.default.log("add connection ".concat(n.type,":").concat(n.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(n)},e.prototype._removeConnection=function(t){var n=this._connections.get(t.peer);if(n){var i=n.indexOf(t);i!==-1&&n.splice(i,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,n){var i,s,a=this._connections.get(t);if(!a)return null;try{for(var o=qn(a),c=o.next();!c.done;c=o.next()){var l=c.value;if(l.connectionId===n)return l}}catch(u){i={error:u}}finally{try{c&&!c.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}return null},e.prototype._delayedAbort=function(t,n){var i=this;setTimeout(function(){i._abort(t,n)},0)},e.prototype._abort=function(t,n){j.default.error("Aborting!"),this.emitError(t,n),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,n){j.default.error("Error:",n);var i;typeof n=="string"?i=new Error(n):i=n,i.type=t,this.emit("error",i)},e.prototype.destroy=function(){this.destroyed||(j.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},e.prototype._cleanup=function(){var t,n;try{for(var i=qn(this._connections.keys()),s=i.next();!s.done;s=i.next()){var a=s.value;this._cleanupPeer(a),this._connections.delete(a)}}catch(o){t={error:o}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var n,i,s=this._connections.get(t);if(s)try{for(var a=qn(s),o=a.next();!o.done;o=a.next()){var c=o.value;c.close()}}catch(l){n={error:l}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;j.default.log("Disconnect peer with ID:".concat(t)),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=t,this._id=null,this.emit("disconnected",t)}},e.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)j.default.log("Attempting reconnection to server with ID ".concat(this._lastServerId)),this._disconnected=!1,this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(!this.disconnected&&!this.open)j.default.error("In a hurry? We're still trying to make the initial connection!");else throw new Error("Peer ".concat(this.id," cannot reconnect because it is not disconnected from the server!"))}},e.prototype.listAllPeers=function(t){var n=this;t===void 0&&(t=function(i){}),this._api.listAllPeers().then(function(i){return t(i)}).catch(function(i){return n._abort(_e.ServerError,i)})},e.DEFAULT_KEY="peerjs",e})(Gi.EventEmitter),Fh=Wc.Peer;const Lh=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return Xs},default:Fh,util:te},Symbol.toStringTag,{value:"Module"}));class Vh{constructor(e,t){if(this._retries=0,!Number.isInteger(e)||e<0)throw new Error("Base must be a positive integer or zero");if(t!==void 0&&(!Number.isInteger(t)||t<0))throw new Error("ExpMax must be a undefined, a positive integer or zero");this.base=e,this.expMax=t,this.i=0}get retries(){return this._retries}get current(){return this.base*Math.pow(2,this.i)}next(){return this._retries++,this.i=this.expMax===void 0?this.i+1:Math.min(this.i+1,this.expMax),this.current}reset(){this._retries=0,this.i=0}}var ce;(function(r){r.open="open",r.close="close",r.error="error",r.message="message",r.retry="retry",r.reconnect="reconnect"})(ce||(ce={}));class Yc{constructor(e,t,n){var i,s,a,o,c,l,u,f,p,m,x,T,g,v,_;this._closedByUser=!1,this.handleOpenEvent=b=>this.handleEvent(ce.open,b),this.handleErrorEvent=b=>this.handleEvent(ce.error,b),this.handleCloseEvent=b=>this.handleEvent(ce.close,b),this.handleMessageEvent=b=>this.handleEvent(ce.message,b),this._url=e,this._protocols=t,this._options={buffer:n?.buffer,retry:{maxRetries:(i=n?.retry)===null||i===void 0?void 0:i.maxRetries,instantReconnect:(s=n?.retry)===null||s===void 0?void 0:s.instantReconnect,backoff:(a=n?.retry)===null||a===void 0?void 0:a.backoff},listeners:{open:[...(c=(o=n?.listeners)===null||o===void 0?void 0:o.open)!==null&&c!==void 0?c:[]],close:[...(u=(l=n?.listeners)===null||l===void 0?void 0:l.close)!==null&&u!==void 0?u:[]],error:[...(p=(f=n?.listeners)===null||f===void 0?void 0:f.error)!==null&&p!==void 0?p:[]],message:[...(x=(m=n?.listeners)===null||m===void 0?void 0:m.message)!==null&&x!==void 0?x:[]],retry:[...(g=(T=n?.listeners)===null||T===void 0?void 0:T.retry)!==null&&g!==void 0?g:[]],reconnect:[...(_=(v=n?.listeners)===null||v===void 0?void 0:v.reconnect)!==null&&_!==void 0?_:[]]}},this._underlyingWebsocket=this.tryConnect()}get url(){return this._url}get protocols(){return this._protocols}get buffer(){return this._options.buffer}get maxRetries(){return this._options.retry.maxRetries}get instantReconnect(){return this._options.retry.instantReconnect}get backoff(){return this._options.retry.backoff}get closedByUser(){return this._closedByUser}get lastConnection(){return this._lastConnection}get underlyingWebsocket(){return this._underlyingWebsocket}get readyState(){return this._underlyingWebsocket.readyState}get bufferedAmount(){return this._underlyingWebsocket.bufferedAmount}get extensions(){return this._underlyingWebsocket.extensions}get binaryType(){return this._underlyingWebsocket.binaryType}set binaryType(e){this._underlyingWebsocket.binaryType=e}send(e){this.closedByUser||(this._underlyingWebsocket.readyState===this._underlyingWebsocket.OPEN?this._underlyingWebsocket.send(e):this.buffer!==void 0&&this.buffer.add(e))}close(e,t){this.cancelScheduledConnectionRetry(),this._closedByUser=!0,this._underlyingWebsocket.close(e,t)}addEventListener(e,t,n){this._options.listeners[e].push({listener:t,options:n})}removeEventListener(e,t,n){const i=s=>s.listener!==t||s.options!==n;this._options.listeners[e]=this._options.listeners[e].filter(i)}tryConnect(){return this._underlyingWebsocket=new WebSocket(this.url,this.protocols),this._underlyingWebsocket.addEventListener(ce.open,this.handleOpenEvent),this._underlyingWebsocket.addEventListener(ce.close,this.handleCloseEvent),this._underlyingWebsocket.addEventListener(ce.error,this.handleErrorEvent),this._underlyingWebsocket.addEventListener(ce.message,this.handleMessageEvent),this._underlyingWebsocket}clearWebsocket(){this._underlyingWebsocket.removeEventListener(ce.open,this.handleOpenEvent),this._underlyingWebsocket.removeEventListener(ce.close,this.handleCloseEvent),this._underlyingWebsocket.removeEventListener(ce.error,this.handleErrorEvent),this._underlyingWebsocket.removeEventListener(ce.message,this.handleMessageEvent),this._underlyingWebsocket.close()}dispatchEvent(e,t){const n=this._options.listeners[e],i=[];n.forEach(({listener:s,options:a})=>{s(this,t),(a===void 0||a.once===void 0||!a.once)&&i.push({listener:s,options:a})}),this._options.listeners[e]=i}handleEvent(e,t){switch(e){case ce.close:this.dispatchEvent(e,t),this.scheduleConnectionRetryIfNeeded();break;case ce.open:if(this.backoff!==void 0&&this._lastConnection!==void 0){const n={retries:this.backoff.retries,lastConnection:new Date(this._lastConnection)},i=new CustomEvent(ce.reconnect,{detail:n});this.dispatchEvent(ce.reconnect,i),this.backoff.reset()}this._lastConnection=new Date,this.dispatchEvent(e,t),this.sendBufferedData();break;case ce.retry:this.dispatchEvent(e,t),this.clearWebsocket(),this.tryConnect();break;default:this.dispatchEvent(e,t);break}}sendBufferedData(){if(this.buffer!==void 0)for(let e=this.buffer.read();e!==void 0;e=this.buffer.read())this.send(e)}scheduleConnectionRetryIfNeeded(){if(this.closedByUser||this.backoff===void 0)return;const e=n=>{const i=new CustomEvent(ce.retry,{detail:n});this.handleEvent(ce.retry,i)},t={backoff:this._options.retry.instantReconnect===!0?0:this.backoff.next(),retries:this._options.retry.instantReconnect===!0?0:this.backoff.retries,lastConnection:this._lastConnection};(this._options.retry.maxRetries===void 0||t.retries<=this._options.retry.maxRetries)&&(this.retryTimeout=globalThis.setTimeout(()=>e(t),t.backoff))}cancelScheduledConnectionRetry(){globalThis.clearTimeout(this.retryTimeout)}}class Jh{constructor(e){this._url=e}get url(){return this._url}withProtocols(e){return this._protocols=e,this}get protocols(){return this._protocols}withMaxRetries(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{maxRetries:e})}),this}get maxRetries(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.maxRetries}withInstantReconnect(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{instantReconnect:e})}),this}get instantReconnect(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.instantReconnect}withBackoff(e){var t;return this._options=Object.assign(Object.assign({},this._options),{retry:Object.assign(Object.assign({},(t=this._options)===null||t===void 0?void 0:t.retry),{backoff:e})}),this}get backoff(){var e,t;return(t=(e=this._options)===null||e===void 0?void 0:e.retry)===null||t===void 0?void 0:t.backoff}withBuffer(e){return this._options=Object.assign(Object.assign({},this._options),{buffer:e}),this}get buffer(){var e;return(e=this._options)===null||e===void 0?void 0:e.buffer}onOpen(e,t){return this.addListener(ce.open,e,t),this}onClose(e,t){return this.addListener(ce.close,e,t),this}onError(e,t){return this.addListener(ce.error,e,t),this}onMessage(e,t){return this.addListener(ce.message,e,t),this}onRetry(e,t){return this.addListener(ce.retry,e,t),this}onReconnect(e,t){return this.addListener(ce.reconnect,e,t),this}build(){return new Yc(this._url,this._protocols,this._options)}addListener(e,t,n){var i,s,a,o,c,l,u,f,p,m,x,T,g,v,_,b,M,C,P,E,z;return this._options=Object.assign(Object.assign({},this._options),{listeners:{open:(a=(s=(i=this._options)===null||i===void 0?void 0:i.listeners)===null||s===void 0?void 0:s.open)!==null&&a!==void 0?a:[],close:(l=(c=(o=this._options)===null||o===void 0?void 0:o.listeners)===null||c===void 0?void 0:c.close)!==null&&l!==void 0?l:[],error:(p=(f=(u=this._options)===null||u===void 0?void 0:u.listeners)===null||f===void 0?void 0:f.error)!==null&&p!==void 0?p:[],message:(T=(x=(m=this._options)===null||m===void 0?void 0:m.listeners)===null||x===void 0?void 0:x.message)!==null&&T!==void 0?T:[],retry:(_=(v=(g=this._options)===null||g===void 0?void 0:g.listeners)===null||v===void 0?void 0:v.retry)!==null&&_!==void 0?_:[],reconnect:(C=(M=(b=this._options)===null||b===void 0?void 0:b.listeners)===null||M===void 0?void 0:M.reconnect)!==null&&C!==void 0?C:[],[e]:[...(z=(E=(P=this._options)===null||P===void 0?void 0:P.listeners)===null||E===void 0?void 0:E[e])!==null&&z!==void 0?z:[],{listener:t,options:n}]}}),this}}const jh=Object.freeze(Object.defineProperty({__proto__:null,ExponentialBackoff:Vh,Websocket:Yc,WebsocketBuilder:Jh,get WebsocketEvent(){return ce}},Symbol.toStringTag,{value:"Module"})),go=0,Zc=1,Kc=2,Ys=2,ws=1.25,ka=1,We=32,Pe=We/4,Qc=65535,kr=Math.pow(2,-24),Wr=Symbol("SKIP_GENERATION"),el={strategy:go,maxDepth:40,maxLeafSize:10,useSharedArrayBuffer:!1,setBoundingBox:!0,onProgress:null,indirect:!1,verbose:!0,range:null,[Wr]:!1};function Se(r,e,t){return t.min.x=e[r],t.min.y=e[r+1],t.min.z=e[r+2],t.max.x=e[r+3],t.max.y=e[r+4],t.max.z=e[r+5],t}function Ra(r){let e=-1,t=-1/0;for(let n=0;n<3;n++){const i=r[n+3]-r[n];i>t&&(t=i,e=n)}return e}function Aa(r,e){e.set(r)}function Oa(r,e,t){let n,i;for(let s=0;s<3;s++){const a=s+3;n=r[s],i=e[s],t[s]=n<i?n:i,n=r[a],i=e[a],t[a]=n>i?n:i}}function ar(r,e,t){for(let n=0;n<3;n++){const i=e[r+2*n],s=e[r+2*n+1],a=i-s,o=i+s;a<t[n]&&(t[n]=a),o>t[n+3]&&(t[n+3]=o)}}function Xn(r){const e=r[3]-r[0],t=r[4]-r[1],n=r[5]-r[2];return 2*(e*t+t*n+n*e)}function Ee(r,e){return e[r+15]===Qc}function $e(r,e){return e[r+6]}function tt(r,e){return e[r+14]}function Ie(r){return r+Pe}function Be(r,e){const t=e[r+6];return r+t*Pe}function vo(r,e){return e[r+7]}function Ps(r,e,t,n,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0,f=1/0,p=1/0,m=1/0,x=-1/0,T=-1/0,g=-1/0;const v=r.offset||0;for(let _=(e-v)*6,b=(e+t-v)*6;_<b;_+=6){const M=r[_+0],C=r[_+1],P=M-C,E=M+C;P<s&&(s=P),E>c&&(c=E),M<f&&(f=M),M>x&&(x=M);const z=r[_+2],I=r[_+3],R=z-I,N=z+I;R<a&&(a=R),N>l&&(l=N),z<p&&(p=z),z>T&&(T=z);const O=r[_+4],U=r[_+5],L=O-U,J=O+U;L<o&&(o=L),J>u&&(u=J),O<m&&(m=O),O>g&&(g=O)}n[0]=s,n[1]=a,n[2]=o,n[3]=c,n[4]=l,n[5]=u,i[0]=f,i[1]=p,i[2]=m,i[3]=x,i[4]=T,i[5]=g}const Jt=32,Gh=(r,e)=>r.candidate-e.candidate,Kt=new Array(Jt).fill().map(()=>({count:0,bounds:new Float32Array(6),rightCacheBounds:new Float32Array(6),leftCacheBounds:new Float32Array(6),candidate:0})),cr=new Float32Array(6);function Wh(r,e,t,n,i,s){let a=-1,o=0;if(s===go)a=Ra(e),a!==-1&&(o=(e[a]+e[a+3])/2);else if(s===Zc)a=Ra(r),a!==-1&&(o=$h(t,n,i,a));else if(s===Kc){const c=Xn(r);let l=ws*i;const u=t.offset||0,f=(n-u)*6,p=(n+i-u)*6;for(let m=0;m<3;m++){const x=e[m],v=(e[m+3]-x)/Jt;if(i<Jt/4){const _=[...Kt];_.length=i;let b=0;for(let C=f;C<p;C+=6,b++){const P=_[b];P.candidate=t[C+2*m],P.count=0;const{bounds:E,leftCacheBounds:z,rightCacheBounds:I}=P;for(let R=0;R<3;R++)I[R]=1/0,I[R+3]=-1/0,z[R]=1/0,z[R+3]=-1/0,E[R]=1/0,E[R+3]=-1/0;ar(C,t,E)}_.sort(Gh);let M=i;for(let C=0;C<M;C++){const P=_[C];for(;C+1<M&&_[C+1].candidate===P.candidate;)_.splice(C+1,1),M--}for(let C=f;C<p;C+=6){const P=t[C+2*m];for(let E=0;E<M;E++){const z=_[E];P>=z.candidate?ar(C,t,z.rightCacheBounds):(ar(C,t,z.leftCacheBounds),z.count++)}}for(let C=0;C<M;C++){const P=_[C],E=P.count,z=i-P.count,I=P.leftCacheBounds,R=P.rightCacheBounds;let N=0;E!==0&&(N=Xn(I)/c);let O=0;z!==0&&(O=Xn(R)/c);const U=ka+ws*(N*E+O*z);U<l&&(a=m,l=U,o=P.candidate)}}else{for(let M=0;M<Jt;M++){const C=Kt[M];C.count=0,C.candidate=x+v+M*v;const P=C.bounds;for(let E=0;E<3;E++)P[E]=1/0,P[E+3]=-1/0}for(let M=f;M<p;M+=6){let E=~~((t[M+2*m]-x)/v);E>=Jt&&(E=Jt-1);const z=Kt[E];z.count++,ar(M,t,z.bounds)}const _=Kt[Jt-1];Aa(_.bounds,_.rightCacheBounds);for(let M=Jt-2;M>=0;M--){const C=Kt[M],P=Kt[M+1];Oa(C.bounds,P.rightCacheBounds,C.rightCacheBounds)}let b=0;for(let M=0;M<Jt-1;M++){const C=Kt[M],P=C.count,E=C.bounds,I=Kt[M+1].rightCacheBounds;P!==0&&(b===0?Aa(E,cr):Oa(E,cr,cr)),b+=P;let R=0,N=0;b!==0&&(R=Xn(cr)/c);const O=i-b;O!==0&&(N=Xn(I)/c);const U=ka+ws*(R*b+N*O);U<l&&(a=m,l=U,o=C.candidate)}}}}else console.warn(`BVH: Invalid build strategy value ${s} used.`);return{axis:a,pos:o}}function $h(r,e,t,n){let i=0;const s=r.offset;for(let a=e,o=e+t;a<o;a++)i+=r[(a-s)*6+n*2];return i/t}class Es{constructor(){this.boundingData=new Float32Array(6)}}function Hh(r,e,t,n,i,s){let a=n,o=n+i-1;const c=s.pos,l=s.axis*2,u=t.offset||0;for(;;){for(;a<=o&&t[(a-u)*6+l]<c;)a++;for(;a<=o&&t[(o-u)*6+l]>=c;)o--;if(a<o){for(let f=0;f<e;f++){let p=r[a*e+f];r[a*e+f]=r[o*e+f],r[o*e+f]=p}for(let f=0;f<6;f++){const p=a-u,m=o-u,x=t[p*6+f];t[p*6+f]=t[m*6+f],t[m*6+f]=x}a++,o--}else return a}}let tl,Rr,Zs,nl;const qh=Math.pow(2,32);function Ks(r){return"count"in r?1:1+Ks(r.left)+Ks(r.right)}function Xh(r,e,t){return tl=new Float32Array(t),Rr=new Uint32Array(t),Zs=new Uint16Array(t),nl=new Uint8Array(t),Qs(r,e)}function Qs(r,e){const t=r/4,n=r/2,i="count"in e,s=e.boundingData;for(let a=0;a<6;a++)tl[t+a]=s[a];if(i)return e.buffer?(nl.set(new Uint8Array(e.buffer),r),r+e.buffer.byteLength):(Rr[t+6]=e.offset,Zs[n+14]=e.count,Zs[n+15]=Qc,r+We);{const{left:a,right:o,splitAxis:c}=e,l=r+We;let u=Qs(l,a);const f=r/We,m=u/We-f;if(m>qh)throw new Error("MeshBVH: Cannot store relative child node offset greater than 32 bits.");return Rr[t+6]=m,Rr[t+7]=c,Qs(u,o)}}function Yh(r,e,t,n,i){const{maxDepth:s,verbose:a,maxLeafSize:o,strategy:c,onProgress:l}=i,u=r.primitiveBuffer,f=r.primitiveBufferStride,p=new Float32Array(6);let m=!1;const x=new Es;return Ps(e,t,n,x.boundingData,p),g(x,t,n,p),x;function T(v){l&&l(v/n)}function g(v,_,b,M=null,C=0){if(!m&&C>=s&&(m=!0,a&&console.warn(`BVH: Max depth of ${s} reached when generating BVH. Consider increasing maxDepth.`)),b<=o||C>=s)return T(_+b),v.offset=_,v.count=b,v;const P=Wh(v.boundingData,M,e,_,b,c);if(P.axis===-1)return T(_+b),v.offset=_,v.count=b,v;const E=Hh(u,f,e,_,b,P);if(E===_||E===_+b)T(_+b),v.offset=_,v.count=b;else{v.splitAxis=P.axis;const z=new Es,I=_,R=E-_;v.left=z,Ps(e,I,R,z.boundingData,p),g(z,I,R,p,C+1);const N=new Es,O=E,U=b-R;v.right=N,Ps(e,O,U,N.boundingData,p),g(N,O,U,p,C+1)}return v}}function Zh(r,e){const t=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,n=r.getRootRanges(e.range),i=n[0],s=n[n.length-1],a={offset:i.offset,count:s.offset+s.count-i.offset},o=new Float32Array(6*a.count);o.offset=a.offset,r.computePrimitiveBounds(a.offset,a.count,o),r._roots=n.map(c=>{const l=Yh(r,o,c.offset,c.count,e),u=Ks(l),f=new t(We*u);return Xh(0,l,f),f})}class So{constructor(e){this._getNewPrimitive=e,this._primitives=[]}getPrimitive(){const e=this._primitives;return e.length===0?this._getNewPrimitive():e.pop()}releasePrimitive(e){this._primitives.push(e)}}class Kh{constructor(){this.float32Array=null,this.uint16Array=null,this.uint32Array=null;const e=[];let t=null;this.setBuffer=n=>{t&&e.push(t),t=n,this.float32Array=new Float32Array(n),this.uint16Array=new Uint16Array(n),this.uint32Array=new Uint32Array(n)},this.clearBuffer=()=>{t=null,this.float32Array=null,this.uint16Array=null,this.uint32Array=null,e.length!==0&&this.setBuffer(e.pop())}}}const pe=new Kh;let nn,Un;const Pn=[],lr=new So(()=>new A.Box3);function Qh(r,e,t,n,i,s){nn=lr.getPrimitive(),Un=lr.getPrimitive(),Pn.push(nn,Un),pe.setBuffer(r._roots[e]);const a=eo(0,r.geometry,t,n,i,s);pe.clearBuffer(),lr.releasePrimitive(nn),lr.releasePrimitive(Un),Pn.pop(),Pn.pop();const o=Pn.length;return o>0&&(Un=Pn[o-1],nn=Pn[o-2]),a}function eo(r,e,t,n,i=null,s=0,a=0){const{float32Array:o,uint16Array:c,uint32Array:l}=pe;let u=r*2;if(Ee(u,c)){const p=$e(r,l),m=tt(u,c);return Se(r,o,nn),n(p,m,!1,a,s+r/Pe,nn)}else{let R=function(O){const{uint16Array:U,uint32Array:L}=pe;let J=O*2;for(;!Ee(J,U);)O=Ie(O),J=O*2;return $e(O,L)},N=function(O){const{uint16Array:U,uint32Array:L}=pe;let J=O*2;for(;!Ee(J,U);)O=Be(O,L),J=O*2;return $e(O,L)+tt(J,U)};const p=Ie(r),m=Be(r,l);let x=p,T=m,g,v,_,b;if(i&&(_=nn,b=Un,Se(x,o,_),Se(T,o,b),g=i(_),v=i(b),v<g)){x=m,T=p;const O=g;g=v,v=O,_=b}_||(_=nn,Se(x,o,_));const M=Ee(x*2,c),C=t(_,M,g,a+1,s+x/Pe);let P;if(C===Ys){const O=R(x),L=N(x)-O;P=n(O,L,!0,a+1,s+x/Pe,_)}else P=C&&eo(x,e,t,n,i,s,a+1);if(P)return!0;b=Un,Se(T,o,b);const E=Ee(T*2,c),z=t(b,E,v,a+1,s+T/Pe);let I;if(z===Ys){const O=R(T),L=N(T)-O;I=n(O,L,!0,a+1,s+T/Pe,b)}else I=z&&eo(T,e,t,n,i,s,a+1);return!!I}}const ci=new pe.constructor,Lr=new pe.constructor,en=new So(()=>new A.Box3),En=new A.Box3,kn=new A.Box3,ks=new A.Box3,Rs=new A.Box3;let As=!1;function ef(r,e,t,n){if(As)throw new Error("MeshBVH: Recursive calls to bvhcast not supported.");As=!0;const i=r._roots,s=e._roots;let a,o=0,c=0;const l=new A.Matrix4().copy(t).invert();for(let u=0,f=i.length;u<f;u++){ci.setBuffer(i[u]),c=0;const p=en.getPrimitive();Se(0,ci.float32Array,p),p.applyMatrix4(l);for(let m=0,x=s.length;m<x&&(Lr.setBuffer(s[m]),a=wt(0,0,t,l,n,o,c,0,0,p),Lr.clearBuffer(),c+=s[m].byteLength/We,!a);m++);if(en.releasePrimitive(p),ci.clearBuffer(),o+=i[u].byteLength/We,a)break}return As=!1,a}function wt(r,e,t,n,i,s=0,a=0,o=0,c=0,l=null,u=!1){let f,p;u?(f=Lr,p=ci):(f=ci,p=Lr);const m=f.float32Array,x=f.uint32Array,T=f.uint16Array,g=p.float32Array,v=p.uint32Array,_=p.uint16Array,b=r*2,M=e*2,C=Ee(b,T),P=Ee(M,_);let E=!1;if(P&&C)u?E=i($e(e,v),tt(e*2,_),$e(r,x),tt(r*2,T),c,a+e/Pe,o,s+r/Pe):E=i($e(r,x),tt(r*2,T),$e(e,v),tt(e*2,_),o,s+r/Pe,c,a+e/Pe);else if(P){const z=en.getPrimitive();Se(e,g,z),z.applyMatrix4(t);const I=Ie(r),R=Be(r,x);Se(I,m,En),Se(R,m,kn);const N=z.intersectsBox(En),O=z.intersectsBox(kn);E=N&&wt(e,I,n,t,i,a,s,c,o+1,z,!u)||O&&wt(e,R,n,t,i,a,s,c,o+1,z,!u),en.releasePrimitive(z)}else{const z=Ie(e),I=Be(e,v);Se(z,g,ks),Se(I,g,Rs);const R=l.intersectsBox(ks),N=l.intersectsBox(Rs);if(R&&N)E=wt(r,z,t,n,i,s,a,o,c+1,l,u)||wt(r,I,t,n,i,s,a,o,c+1,l,u);else if(R)if(C)E=wt(r,z,t,n,i,s,a,o,c+1,l,u);else{const O=en.getPrimitive();O.copy(ks).applyMatrix4(t);const U=Ie(r),L=Be(r,x);Se(U,m,En),Se(L,m,kn);const J=O.intersectsBox(En),$=O.intersectsBox(kn);E=J&&wt(z,U,n,t,i,a,s,c,o+1,O,!u)||$&&wt(z,L,n,t,i,a,s,c,o+1,O,!u),en.releasePrimitive(O)}else if(N)if(C)E=wt(r,I,t,n,i,s,a,o,c+1,l,u);else{const O=en.getPrimitive();O.copy(Rs).applyMatrix4(t);const U=Ie(r),L=Be(r,x);Se(U,m,En),Se(L,m,kn);const J=O.intersectsBox(En),$=O.intersectsBox(kn);E=J&&wt(I,U,n,t,i,a,s,c,o+1,O,!u)||$&&wt(I,L,n,t,i,a,s,c,o+1,O,!u),en.releasePrimitive(O)}}return E}const za=new A.Box3,Rn=new Float32Array(6);class il{constructor(){this._roots=null,this.primitiveBuffer=null,this.primitiveBufferStride=null}init(e){e={...el,...e},Zh(this,e)}getRootRanges(){throw new Error("BVH: getRootRanges() not implemented")}writePrimitiveBounds(){throw new Error("BVH: writePrimitiveBounds() not implemented")}writePrimitiveRangeBounds(e,t,n,i){let s=1/0,a=1/0,o=1/0,c=-1/0,l=-1/0,u=-1/0;for(let f=e,p=e+t;f<p;f++){this.writePrimitiveBounds(f,Rn,0);const[m,x,T,g,v,_]=Rn;m<s&&(s=m),g>c&&(c=g),x<a&&(a=x),v>l&&(l=v),T<o&&(o=T),_>u&&(u=_)}return n[i+0]=s,n[i+1]=a,n[i+2]=o,n[i+3]=c,n[i+4]=l,n[i+5]=u,n}computePrimitiveBounds(e,t,n){const i=n.offset||0;for(let s=e,a=e+t;s<a;s++){this.writePrimitiveBounds(s,Rn,0);const[o,c,l,u,f,p]=Rn,m=(o+u)/2,x=(c+f)/2,T=(l+p)/2,g=(u-o)/2,v=(f-c)/2,_=(p-l)/2,b=(s-i)*6;n[b+0]=m,n[b+1]=g+(Math.abs(m)+g)*kr,n[b+2]=x,n[b+3]=v+(Math.abs(x)+v)*kr,n[b+4]=T,n[b+5]=_+(Math.abs(T)+_)*kr}return n}shiftPrimitiveOffsets(e){const t=this._indirectBuffer;if(t)for(let n=0,i=t.length;n<i;n++)t[n]+=e;else{const n=this._roots;for(let i=0;i<n.length;i++){const s=n[i],a=new Uint32Array(s),o=new Uint16Array(s),c=s.byteLength/We;for(let l=0;l<c;l++){const u=Pe*l,f=2*u;Ee(f,o)&&(a[u+6]+=e)}}}}traverse(e,t=0){const n=this._roots[t],i=new Uint32Array(n),s=new Uint16Array(n);a(0);function a(o,c=0){const l=o*2,u=Ee(l,s);if(u){const f=i[o+6],p=s[l+14];e(c,u,new Float32Array(n,o*4,6),f,p)}else{const f=Ie(o),p=Be(o,i),m=vo(o,i);e(c,u,new Float32Array(n,o*4,6),m)||(a(f,c+1),a(p,c+1))}}}refit(){const e=this._roots;for(let t=0,n=e.length;t<n;t++){const i=e[t],s=new Uint32Array(i),a=new Uint16Array(i),o=new Float32Array(i),c=i.byteLength/We;for(let l=c-1;l>=0;l--){const u=l*Pe,f=u*2;if(Ee(f,a)){const m=$e(u,s),x=tt(f,a);this.writePrimitiveRangeBounds(m,x,Rn,0),o.set(Rn,u)}else{const m=Ie(u),x=Be(u,s);for(let T=0;T<3;T++){const g=o[m+T],v=o[m+T+3],_=o[x+T],b=o[x+T+3];o[u+T]=g<_?g:_,o[u+T+3]=v>b?v:b}}}}}getBoundingBox(e){return e.makeEmpty(),this._roots.forEach(n=>{Se(0,new Float32Array(n),za),e.union(za)}),e}shapecast(e){let{boundsTraverseOrder:t,intersectsBounds:n,intersectsRange:i,intersectsPrimitive:s,scratchPrimitive:a,iterate:o}=e;if(i&&s){const f=i;i=(p,m,x,T,g)=>f(p,m,x,T,g)?!0:o(p,m,this,s,x,T,a)}else i||(s?i=(f,p,m,x)=>o(f,p,this,s,m,x,a):i=(f,p,m)=>m);let c=!1,l=0;const u=this._roots;for(let f=0,p=u.length;f<p;f++){const m=u[f];if(c=Qh(this,f,n,i,t,l),c)break;l+=m.byteLength/We}return c}bvhcast(e,t,n){let{intersectsRanges:i}=n;return ef(this,e,t,i)}}function tf(){return typeof SharedArrayBuffer<"u"}function xo(r){return r.index?r.index.count:r.attributes.position.count}function $r(r){return xo(r)/3}function nf(r,e=ArrayBuffer){return r>65535?new Uint32Array(new e(4*r)):new Uint16Array(new e(2*r))}function rf(r,e){if(!r.index){const t=r.attributes.position.count,n=e.useSharedArrayBuffer?SharedArrayBuffer:ArrayBuffer,i=nf(t,n);r.setIndex(new A.BufferAttribute(i,1));for(let s=0;s<t;s++)i[s]=s}}function sf(r,e,t){const n=xo(r)/t,i=e||r.drawRange,s=i.start/t,a=(i.start+i.count)/t,o=Math.max(0,s),c=Math.min(n,a)-o;return{offset:Math.floor(o),count:Math.floor(c)}}function of(r,e){return r.groups.map(t=>({offset:t.start/e,count:t.count/e}))}function Ia(r,e,t){const n=sf(r,e,t),i=of(r,t);if(!i.length)return[n];const s=[],a=n.offset,o=n.offset+n.count,c=xo(r)/t,l=[];for(const p of i){const{offset:m,count:x}=p,T=m,g=isFinite(x)?x:c-m,v=m+g;T<o&&v>a&&(l.push({pos:Math.max(a,T),isStart:!0}),l.push({pos:Math.min(o,v),isStart:!1}))}l.sort((p,m)=>p.pos!==m.pos?p.pos-m.pos:p.type==="end"?-1:1);let u=0,f=null;for(const p of l){const m=p.pos;u!==0&&m!==f&&s.push({offset:f,count:m-f}),u+=p.isStart?1:-1,f=m}return s}function rl(r,e){const t=r[r.length-1],n=t.offset+t.count>2**16,i=r.reduce((l,u)=>l+u.count,0),s=n?4:2,a=e?new SharedArrayBuffer(i*s):new ArrayBuffer(i*s),o=n?new Uint32Array(a):new Uint16Array(a);let c=0;for(let l=0;l<r.length;l++){const{offset:u,count:f}=r[l];for(let p=0;p<f;p++)o[c+p]=u+p;c+=f}return o}class sl extends il{get indirect(){return!!this._indirectBuffer}get primitiveStride(){return null}get primitiveBufferStride(){return this.indirect?1:this.primitiveStride}set primitiveBufferStride(e){}get primitiveBuffer(){return this.indirect?this._indirectBuffer:this.geometry.index.array}set primitiveBuffer(e){}constructor(e,t={}){if(e.isBufferGeometry){if(e.index&&e.index.isInterleavedBufferAttribute)throw new Error("BVH: InterleavedBufferAttribute is not supported for the index attribute.")}else throw new Error("BVH: Only BufferGeometries are supported.");if(t.useSharedArrayBuffer&&!tf())throw new Error("BVH: SharedArrayBuffer is not available.");super(),this.geometry=e,this.resolvePrimitiveIndex=t.indirect?n=>this._indirectBuffer[n]:n=>n,this.primitiveBuffer=null,this.primitiveBufferStride=null,this._indirectBuffer=null,t={...el,...t},t[Wr]||this.init(t)}init(e){const{geometry:t,primitiveStride:n}=this;if(e.indirect){const i=Ia(t,e.range,n),s=rl(i,e.useSharedArrayBuffer);this._indirectBuffer=s}else rf(t,e);super.init(e),!t.boundingBox&&e.setBoundingBox&&(t.boundingBox=this.getBoundingBox(new A.Box3))}getRootRanges(e){return this.indirect?[{offset:0,count:this._indirectBuffer.length}]:Ia(this.geometry,e,this.primitiveStride)}raycastObject3D(){throw new Error("BVH: raycastObject3D() not implemented")}}class qt{constructor(){this.min=1/0,this.max=-1/0}setFromPointsField(e,t){let n=1/0,i=-1/0;for(let s=0,a=e.length;s<a;s++){const c=e[s][t];n=c<n?c:n,i=c>i?c:i}this.min=n,this.max=i}setFromPoints(e,t){let n=1/0,i=-1/0;for(let s=0,a=t.length;s<a;s++){const o=t[s],c=e.dot(o);n=c<n?c:n,i=c>i?c:i}this.min=n,this.max=i}isSeparated(e){return this.min>e.max||e.min>this.max}}qt.prototype.setFromBox=(function(){const r=new A.Vector3;return function(t,n){const i=n.min,s=n.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++){r.x=i.x*c+s.x*(1-c),r.y=i.y*l+s.y*(1-l),r.z=i.z*u+s.z*(1-u);const f=t.dot(r);a=Math.min(f,a),o=Math.max(f,o)}this.min=a,this.max=o}})();const af=(function(){const r=new A.Vector3,e=new A.Vector3,t=new A.Vector3;return function(i,s,a){const o=i.start,c=r,l=s.start,u=e;t.subVectors(o,l),r.subVectors(i.end,i.start),e.subVectors(s.end,s.start);const f=t.dot(u),p=u.dot(c),m=u.dot(u),x=t.dot(c),g=c.dot(c)*m-p*p;let v,_;g!==0?v=(f*p-x*m)/g:v=0,_=(f+v*p)/m,a.x=v,a.y=_}})(),_o=(function(){const r=new A.Vector2,e=new A.Vector3,t=new A.Vector3;return function(i,s,a,o){af(i,s,r);let c=r.x,l=r.y;if(c>=0&&c<=1&&l>=0&&l<=1){i.at(c,a),s.at(l,o);return}else if(c>=0&&c<=1){l<0?s.at(0,o):s.at(1,o),i.closestPointToPoint(o,!0,a);return}else if(l>=0&&l<=1){c<0?i.at(0,a):i.at(1,a),s.closestPointToPoint(a,!0,o);return}else{let u;c<0?u=i.start:u=i.end;let f;l<0?f=s.start:f=s.end;const p=e,m=t;if(i.closestPointToPoint(f,!0,e),s.closestPointToPoint(u,!0,t),p.distanceToSquared(f)<=m.distanceToSquared(u)){a.copy(p),o.copy(f);return}else{a.copy(u),o.copy(m);return}}}})(),cf=(function(){const r=new A.Vector3,e=new A.Vector3,t=new A.Plane,n=new A.Line3;return function(s,a){const{radius:o,center:c}=s,{a:l,b:u,c:f}=a;if(n.start=l,n.end=u,n.closestPointToPoint(c,!0,r).distanceTo(c)<=o||(n.start=l,n.end=f,n.closestPointToPoint(c,!0,r).distanceTo(c)<=o)||(n.start=u,n.end=f,n.closestPointToPoint(c,!0,r).distanceTo(c)<=o))return!0;const T=a.getPlane(t);if(Math.abs(T.distanceToPoint(c))<=o){const v=T.projectPoint(c,e);if(a.containsPoint(v))return!0}return!1}})(),lf=["x","y","z"],Gt=1e-15,Ba=Gt*Gt;function pt(r){return Math.abs(r)<Gt}class gt extends A.Triangle{constructor(...e){super(...e),this.isExtendedTriangle=!0,this.satAxes=new Array(4).fill().map(()=>new A.Vector3),this.satBounds=new Array(4).fill().map(()=>new qt),this.points=[this.a,this.b,this.c],this.plane=new A.Plane,this.isDegenerateIntoSegment=!1,this.isDegenerateIntoPoint=!1,this.degenerateSegment=new A.Line3,this.needsUpdate=!0}intersectsSphere(e){return cf(e,this)}update(){const e=this.a,t=this.b,n=this.c,i=this.points,s=this.satAxes,a=this.satBounds,o=s[0],c=a[0];this.getNormal(o),c.setFromPoints(o,i);const l=s[1],u=a[1];l.subVectors(e,t),u.setFromPoints(l,i);const f=s[2],p=a[2];f.subVectors(t,n),p.setFromPoints(f,i);const m=s[3],x=a[3];m.subVectors(n,e),x.setFromPoints(m,i);const T=l.length(),g=f.length(),v=m.length();this.isDegenerateIntoPoint=!1,this.isDegenerateIntoSegment=!1,T<Gt?g<Gt||v<Gt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(e),this.degenerateSegment.end.copy(n)):g<Gt?v<Gt?this.isDegenerateIntoPoint=!0:(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(t),this.degenerateSegment.end.copy(e)):v<Gt&&(this.isDegenerateIntoSegment=!0,this.degenerateSegment.start.copy(n),this.degenerateSegment.end.copy(t)),this.plane.setFromNormalAndCoplanarPoint(o,e),this.needsUpdate=!1}}gt.prototype.closestPointToSegment=(function(){const r=new A.Vector3,e=new A.Vector3,t=new A.Line3;return function(i,s=null,a=null){const{start:o,end:c}=i,l=this.points;let u,f=1/0;for(let p=0;p<3;p++){const m=(p+1)%3;t.start.copy(l[p]),t.end.copy(l[m]),_o(t,i,r,e),u=r.distanceToSquared(e),u<f&&(f=u,s&&s.copy(r),a&&a.copy(e))}return this.closestPointToPoint(o,r),u=o.distanceToSquared(r),u<f&&(f=u,s&&s.copy(r),a&&a.copy(o)),this.closestPointToPoint(c,r),u=c.distanceToSquared(r),u<f&&(f=u,s&&s.copy(r),a&&a.copy(c)),Math.sqrt(f)}})();gt.prototype.intersectsTriangle=(function(){const r=new gt,e=new qt,t=new qt,n=new A.Vector3,i=new A.Vector3,s=new A.Vector3,a=new A.Vector3,o=new A.Line3,c=new A.Line3,l=new A.Vector3,u=new A.Vector2,f=new A.Vector2;function p(b,M,C,P){const E=n;!b.isDegenerateIntoPoint&&!b.isDegenerateIntoSegment?E.copy(b.plane.normal):E.copy(M.plane.normal);const z=b.satBounds,I=b.satAxes;for(let O=1;O<4;O++){const U=z[O],L=I[O];if(e.setFromPoints(L,M.points),U.isSeparated(e)||(a.copy(E).cross(L),e.setFromPoints(a,b.points),t.setFromPoints(a,M.points),e.isSeparated(t)))return!1}const R=M.satBounds,N=M.satAxes;for(let O=1;O<4;O++){const U=R[O],L=N[O];if(e.setFromPoints(L,b.points),U.isSeparated(e)||(a.crossVectors(E,L),e.setFromPoints(a,b.points),t.setFromPoints(a,M.points),e.isSeparated(t)))return!1}return C&&(P||console.warn("ExtendedTriangle.intersectsTriangle: Triangles are coplanar which does not support an output edge. Setting edge to 0, 0, 0."),C.start.set(0,0,0),C.end.set(0,0,0)),!0}function m(b,M,C,P,E,z,I,R,N,O,U){let L=I/(I-R);O.x=P+(E-P)*L,U.start.subVectors(M,b).multiplyScalar(L).add(b),L=I/(I-N),O.y=P+(z-P)*L,U.end.subVectors(C,b).multiplyScalar(L).add(b)}function x(b,M,C,P,E,z,I,R,N,O,U){if(E>0)m(b.c,b.a,b.b,P,M,C,N,I,R,O,U);else if(z>0)m(b.b,b.a,b.c,C,M,P,R,I,N,O,U);else if(R*N>0||I!=0)m(b.a,b.b,b.c,M,C,P,I,R,N,O,U);else if(R!=0)m(b.b,b.a,b.c,C,M,P,R,I,N,O,U);else if(N!=0)m(b.c,b.a,b.b,P,M,C,N,I,R,O,U);else return!0;return!1}function T(b,M,C,P){const E=M.degenerateSegment,z=b.plane.distanceToPoint(E.start),I=b.plane.distanceToPoint(E.end);return pt(z)?pt(I)?p(b,M,C,P):(C&&(C.start.copy(E.start),C.end.copy(E.start)),b.containsPoint(E.start)):pt(I)?(C&&(C.start.copy(E.end),C.end.copy(E.end)),b.containsPoint(E.end)):b.plane.intersectLine(E,n)!=null?(C&&(C.start.copy(n),C.end.copy(n)),b.containsPoint(n)):!1}function g(b,M,C){const P=M.a;return pt(b.plane.distanceToPoint(P))&&b.containsPoint(P)?(C&&(C.start.copy(P),C.end.copy(P)),!0):!1}function v(b,M,C){const P=b.degenerateSegment,E=M.a;return P.closestPointToPoint(E,!0,n),E.distanceToSquared(n)<Ba?(C&&(C.start.copy(E),C.end.copy(E)),!0):!1}function _(b,M,C,P){if(b.isDegenerateIntoSegment)if(M.isDegenerateIntoSegment){const E=b.degenerateSegment,z=M.degenerateSegment,I=i,R=s;E.delta(I),z.delta(R);const N=n.subVectors(z.start,E.start),O=I.x*R.y-I.y*R.x;if(pt(O))return!1;const U=(N.x*R.y-N.y*R.x)/O,L=-(I.x*N.y-I.y*N.x)/O;if(U<0||U>1||L<0||L>1)return!1;const J=E.start.z+I.z*U,$=z.start.z+R.z*L;return pt(J-$)?(C&&(C.start.copy(E.start).addScaledVector(I,U),C.end.copy(E.start).addScaledVector(I,U)),!0):!1}else return M.isDegenerateIntoPoint?v(b,M,C):T(M,b,C,P);else{if(b.isDegenerateIntoPoint)return M.isDegenerateIntoPoint?M.a.distanceToSquared(b.a)<Ba?(C&&(C.start.copy(b.a),C.end.copy(b.a)),!0):!1:M.isDegenerateIntoSegment?v(M,b,C):g(M,b,C);if(M.isDegenerateIntoPoint)return g(b,M,C);if(M.isDegenerateIntoSegment)return T(b,M,C,P)}}return function(M,C=null,P=!1){this.needsUpdate&&this.update(),M.isExtendedTriangle?M.needsUpdate&&M.update():(r.copy(M),r.update(),M=r);const E=_(this,M,C,P);if(E!==void 0)return E;const z=this.plane,I=M.plane;let R=I.distanceToPoint(this.a),N=I.distanceToPoint(this.b),O=I.distanceToPoint(this.c);pt(R)&&(R=0),pt(N)&&(N=0),pt(O)&&(O=0);const U=R*N,L=R*O;if(U>0&&L>0)return!1;let J=z.distanceToPoint(M.a),$=z.distanceToPoint(M.b),K=z.distanceToPoint(M.c);pt(J)&&(J=0),pt($)&&($=0),pt(K)&&(K=0);const W=J*$,me=J*K;if(W>0&&me>0)return!1;i.copy(z.normal),s.copy(I.normal);const ne=i.cross(s);let ue=0,re=Math.abs(ne.x);const ge=Math.abs(ne.y);ge>re&&(re=ge,ue=1),Math.abs(ne.z)>re&&(ue=2);const se=lf[ue],he=this.a[se],oe=this.b[se],Xe=this.c[se],Ve=M.a[se],Je=M.b[se],Ye=M.c[se];if(x(this,he,oe,Xe,U,L,R,N,O,u,o))return p(this,M,C,P);if(x(M,Ve,Je,Ye,W,me,J,$,K,f,c))return p(this,M,C,P);if(u.y<u.x){const xe=u.y;u.y=u.x,u.x=xe,l.copy(o.start),o.start.copy(o.end),o.end.copy(l)}if(f.y<f.x){const xe=f.y;f.y=f.x,f.x=xe,l.copy(c.start),c.start.copy(c.end),c.end.copy(l)}return u.y<f.x||f.y<u.x?!1:(C&&(f.x>u.x?C.start.copy(c.start):C.start.copy(o.start),f.y<u.y?C.end.copy(c.end):C.end.copy(o.end)),!0)}})();gt.prototype.distanceToPoint=(function(){const r=new A.Vector3;return function(t){return this.closestPointToPoint(t,r),t.distanceTo(r)}})();gt.prototype.distanceToTriangle=(function(){const r=new A.Vector3,e=new A.Vector3,t=["a","b","c"],n=new A.Line3,i=new A.Line3;return function(a,o=null,c=null){const l=o||c?n:null;if(this.intersectsTriangle(a,l))return(o||c)&&(o&&l.getCenter(o),c&&l.getCenter(c)),0;let u=1/0;for(let f=0;f<3;f++){let p;const m=t[f],x=a[m];this.closestPointToPoint(x,r),p=x.distanceToSquared(r),p<u&&(u=p,o&&o.copy(r),c&&c.copy(x));const T=this[m];a.closestPointToPoint(T,r),p=T.distanceToSquared(r),p<u&&(u=p,o&&o.copy(T),c&&c.copy(r))}for(let f=0;f<3;f++){const p=t[f],m=t[(f+1)%3];n.set(this[p],this[m]);for(let x=0;x<3;x++){const T=t[x],g=t[(x+1)%3];i.set(a[T],a[g]),_o(n,i,r,e);const v=r.distanceToSquared(e);v<u&&(u=v,o&&o.copy(r),c&&c.copy(e))}}return Math.sqrt(u)}})();class qe{constructor(e,t,n){this.isOrientedBox=!0,this.min=new A.Vector3,this.max=new A.Vector3,this.matrix=new A.Matrix4,this.invMatrix=new A.Matrix4,this.points=new Array(8).fill().map(()=>new A.Vector3),this.satAxes=new Array(3).fill().map(()=>new A.Vector3),this.satBounds=new Array(3).fill().map(()=>new qt),this.alignedSatBounds=new Array(3).fill().map(()=>new qt),this.needsUpdate=!1,e&&this.min.copy(e),t&&this.max.copy(t),n&&this.matrix.copy(n)}set(e,t,n){this.min.copy(e),this.max.copy(t),this.matrix.copy(n),this.needsUpdate=!0}copy(e){this.min.copy(e.min),this.max.copy(e.max),this.matrix.copy(e.matrix),this.needsUpdate=!0}}qe.prototype.update=(function(){return function(){const e=this.matrix,t=this.min,n=this.max,i=this.points;for(let l=0;l<=1;l++)for(let u=0;u<=1;u++)for(let f=0;f<=1;f++){const p=1*l|2*u|4*f,m=i[p];m.x=l?n.x:t.x,m.y=u?n.y:t.y,m.z=f?n.z:t.z,m.applyMatrix4(e)}const s=this.satBounds,a=this.satAxes,o=i[0];for(let l=0;l<3;l++){const u=a[l],f=s[l],p=1<<l,m=i[p];u.subVectors(o,m),f.setFromPoints(u,i)}const c=this.alignedSatBounds;c[0].setFromPointsField(i,"x"),c[1].setFromPointsField(i,"y"),c[2].setFromPointsField(i,"z"),this.invMatrix.copy(this.matrix).invert(),this.needsUpdate=!1}})();qe.prototype.intersectsBox=(function(){const r=new qt;return function(t){this.needsUpdate&&this.update();const n=t.min,i=t.max,s=this.satBounds,a=this.satAxes,o=this.alignedSatBounds;if(r.min=n.x,r.max=i.x,o[0].isSeparated(r)||(r.min=n.y,r.max=i.y,o[1].isSeparated(r))||(r.min=n.z,r.max=i.z,o[2].isSeparated(r)))return!1;for(let c=0;c<3;c++){const l=a[c],u=s[c];if(r.setFromBox(l,t),u.isSeparated(r))return!1}return!0}})();qe.prototype.intersectsTriangle=(function(){const r=new gt,e=new Array(3),t=new qt,n=new qt,i=new A.Vector3;return function(a){this.needsUpdate&&this.update(),a.isExtendedTriangle?a.needsUpdate&&a.update():(r.copy(a),r.update(),a=r);const o=this.satBounds,c=this.satAxes;e[0]=a.a,e[1]=a.b,e[2]=a.c;for(let p=0;p<3;p++){const m=o[p],x=c[p];if(t.setFromPoints(x,e),m.isSeparated(t))return!1}const l=a.satBounds,u=a.satAxes,f=this.points;for(let p=0;p<3;p++){const m=l[p],x=u[p];if(t.setFromPoints(x,f),m.isSeparated(t))return!1}for(let p=0;p<3;p++){const m=c[p];for(let x=0;x<4;x++){const T=u[x];if(i.crossVectors(m,T),t.setFromPoints(i,e),n.setFromPoints(i,f),t.isSeparated(n))return!1}}return!0}})();qe.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}})();qe.prototype.distanceToPoint=(function(){const r=new A.Vector3;return function(t){return this.closestPointToPoint(t,r),t.distanceTo(r)}})();qe.prototype.distanceToBox=(function(){const r=["x","y","z"],e=new Array(12).fill().map(()=>new A.Line3),t=new Array(12).fill().map(()=>new A.Line3),n=new A.Vector3,i=new A.Vector3;return function(a,o=0,c=null,l=null){if(this.needsUpdate&&this.update(),this.intersectsBox(a))return(c||l)&&(a.getCenter(i),this.closestPointToPoint(i,n),a.closestPointToPoint(n,i),c&&c.copy(n),l&&l.copy(i)),0;const u=o*o,f=a.min,p=a.max,m=this.points;let x=1/0;for(let g=0;g<8;g++){const v=m[g];i.copy(v).clamp(f,p);const _=v.distanceToSquared(i);if(_<x&&(x=_,c&&c.copy(v),l&&l.copy(i),_<u))return Math.sqrt(_)}let T=0;for(let g=0;g<3;g++)for(let v=0;v<=1;v++)for(let _=0;_<=1;_++){const b=(g+1)%3,M=(g+2)%3,C=v<<b|_<<M,P=1<<g|v<<b|_<<M,E=m[C],z=m[P];e[T].set(E,z);const R=r[g],N=r[b],O=r[M],U=t[T],L=U.start,J=U.end;L[R]=f[R],L[N]=v?f[N]:p[N],L[O]=_?f[O]:p[N],J[R]=p[R],J[N]=v?f[N]:p[N],J[O]=_?f[O]:p[N],T++}for(let g=0;g<=1;g++)for(let v=0;v<=1;v++)for(let _=0;_<=1;_++){i.x=g?p.x:f.x,i.y=v?p.y:f.y,i.z=_?p.z:f.z,this.closestPointToPoint(i,n);const b=i.distanceToSquared(n);if(b<x&&(x=b,c&&c.copy(n),l&&l.copy(i),b<u))return Math.sqrt(b)}for(let g=0;g<12;g++){const v=e[g];for(let _=0;_<12;_++){const b=t[_];_o(v,b,n,i);const M=n.distanceToSquared(i);if(M<x&&(x=M,c&&c.copy(n),l&&l.copy(i),M<u))return Math.sqrt(M)}}return Math.sqrt(x)}})();class uf extends So{constructor(){super(()=>new gt)}}const yt=new uf,Yn=new A.Vector3,Os=new A.Vector3;function hf(r,e,t={},n=0,i=1/0){const s=n*n,a=i*i;let o=1/0,c=null;if(r.shapecast({boundsTraverseOrder:u=>(Yn.copy(e).clamp(u.min,u.max),Yn.distanceToSquared(e)),intersectsBounds:(u,f,p)=>p<o&&p<a,intersectsTriangle:(u,f)=>{u.closestPointToPoint(e,Yn);const p=e.distanceToSquared(Yn);return p<o&&(Os.copy(Yn),o=p,c=f),p<s}}),o===1/0)return null;const l=Math.sqrt(o);return t.point?t.point.copy(Os):t.point=Os.clone(),t.distance=l,t.faceIndex=c,t}const ur=parseInt(A.REVISION)>=169,ff=parseInt(A.REVISION)<=161,ln=new A.Vector3,un=new A.Vector3,hn=new A.Vector3,hr=new A.Vector2,fr=new A.Vector2,dr=new A.Vector2,Na=new A.Vector3,Ua=new A.Vector3,Da=new A.Vector3,Zn=new A.Vector3;function df(r,e,t,n,i,s,a,o){let c;if(s===A.BackSide?c=r.intersectTriangle(n,t,e,!0,i):c=r.intersectTriangle(e,t,n,s!==A.DoubleSide,i),c===null)return null;const l=r.origin.distanceTo(i);return l<a||l>o?null:{distance:l,point:i.clone()}}function Fa(r,e,t,n,i,s,a,o,c,l,u){ln.fromBufferAttribute(e,s),un.fromBufferAttribute(e,a),hn.fromBufferAttribute(e,o);const f=df(r,ln,un,hn,Zn,c,l,u);if(f){if(n){hr.fromBufferAttribute(n,s),fr.fromBufferAttribute(n,a),dr.fromBufferAttribute(n,o),f.uv=new A.Vector2;const m=A.Triangle.getInterpolation(Zn,ln,un,hn,hr,fr,dr,f.uv);ur||(f.uv=m)}if(i){hr.fromBufferAttribute(i,s),fr.fromBufferAttribute(i,a),dr.fromBufferAttribute(i,o),f.uv1=new A.Vector2;const m=A.Triangle.getInterpolation(Zn,ln,un,hn,hr,fr,dr,f.uv1);ur||(f.uv1=m),ff&&(f.uv2=f.uv1)}if(t){Na.fromBufferAttribute(t,s),Ua.fromBufferAttribute(t,a),Da.fromBufferAttribute(t,o),f.normal=new A.Vector3;const m=A.Triangle.getInterpolation(Zn,ln,un,hn,Na,Ua,Da,f.normal);f.normal.dot(r.direction)>0&&f.normal.multiplyScalar(-1),ur||(f.normal=m)}const p={a:s,b:a,c:o,normal:new A.Vector3,materialIndex:0};if(A.Triangle.getNormal(ln,un,hn,p.normal),f.face=p,f.faceIndex=s,ur){const m=new A.Vector3;A.Triangle.getBarycoord(Zn,ln,un,hn,m),f.barycoord=m}}return f}function La(r){return r&&r.isMaterial?r.side:r}function Hr(r,e,t,n,i,s,a){const o=n*3;let c=o+0,l=o+1,u=o+2;const{index:f,groups:p}=r;r.index&&(c=f.getX(c),l=f.getX(l),u=f.getX(u));const{position:m,normal:x,uv:T,uv1:g}=r.attributes;if(Array.isArray(e)){const v=n*3;for(let _=0,b=p.length;_<b;_++){const{start:M,count:C,materialIndex:P}=p[_];if(v>=M&&v<M+C){const E=La(e[P]),z=Fa(t,m,x,T,g,c,l,u,E,s,a);if(z)if(z.faceIndex=n,z.face.materialIndex=P,i)i.push(z);else return z}}}else{const v=La(e),_=Fa(t,m,x,T,g,c,l,u,v,s,a);if(_)if(_.faceIndex=n,_.face.materialIndex=0,i)i.push(_);else return _}return null}function we(r,e,t,n){const i=r.a,s=r.b,a=r.c;let o=e,c=e+1,l=e+2;t&&(o=t.getX(o),c=t.getX(c),l=t.getX(l)),i.x=n.getX(o),i.y=n.getY(o),i.z=n.getZ(o),s.x=n.getX(c),s.y=n.getY(c),s.z=n.getZ(c),a.x=n.getX(l),a.y=n.getY(l),a.z=n.getZ(l)}function pf(r,e,t,n,i,s,a,o){const{geometry:c,_indirectBuffer:l}=r;for(let u=n,f=n+i;u<f;u++)Hr(c,e,t,u,s,a,o)}function mf(r,e,t,n,i,s,a){const{geometry:o,_indirectBuffer:c}=r;let l=1/0,u=null;for(let f=n,p=n+i;f<p;f++){let m;m=Hr(o,e,t,f,null,s,a),m&&m.distance<l&&(u=m,l=m.distance)}return u}function yf(r,e,t,n,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=r,f=e+r;u<f;u++){let p;if(p=u,we(a,p*3,c,l),a.needsUpdate=!0,n(a,p,i,s))return!0}return!1}function gf(r,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=r.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const u=r._roots;for(let p=0,m=u.length;p<m;p++)s=u[p],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),f(0,l),l+=s.byteLength;function f(p,m,x=!1){const T=p*2;if(Ee(T,o)){const g=$e(p,a),v=tt(T,o);let _=1/0,b=1/0,M=1/0,C=-1/0,P=-1/0,E=-1/0;for(let z=3*g,I=3*(g+v);z<I;z++){let R=n[z];const N=i.getX(R),O=i.getY(R),U=i.getZ(R);N<_&&(_=N),N>C&&(C=N),O<b&&(b=O),O>P&&(P=O),U<M&&(M=U),U>E&&(E=U)}return c[p+0]!==_||c[p+1]!==b||c[p+2]!==M||c[p+3]!==C||c[p+4]!==P||c[p+5]!==E?(c[p+0]=_,c[p+1]=b,c[p+2]=M,c[p+3]=C,c[p+4]=P,c[p+5]=E,!0):!1}else{const g=Ie(p),v=Be(p,a);let _=x,b=!1,M=!1;if(e){if(!_){const R=g/Pe+m/We,N=v/Pe+m/We;b=e.has(R),M=e.has(N),_=!b&&!M}}else b=!0,M=!0;const C=_||b,P=_||M;let E=!1;C&&(E=f(g,m,_));let z=!1;P&&(z=f(v,m,_));const I=E||z;if(I)for(let R=0;R<3;R++){const N=g+R,O=v+R,U=c[N],L=c[N+3],J=c[O],$=c[O+3];c[p+R]=U<J?U:J,c[p+R+3]=L>$?L:$}return I}}}function rn(r,e,t,n,i){let s,a,o,c,l,u;const f=1/t.direction.x,p=1/t.direction.y,m=1/t.direction.z,x=t.origin.x,T=t.origin.y,g=t.origin.z;let v=e[r],_=e[r+3],b=e[r+1],M=e[r+3+1],C=e[r+2],P=e[r+3+2];return f>=0?(s=(v-x)*f,a=(_-x)*f):(s=(_-x)*f,a=(v-x)*f),p>=0?(o=(b-T)*p,c=(M-T)*p):(o=(M-T)*p,c=(b-T)*p),s>c||o>a||((o>s||isNaN(s))&&(s=o),(c<a||isNaN(a))&&(a=c),m>=0?(l=(C-g)*m,u=(P-g)*m):(l=(P-g)*m,u=(C-g)*m),s>u||l>a)?!1:((l>s||s!==s)&&(s=l),(u<a||a!==a)&&(a=u),s<=i&&a>=n)}function vf(r,e,t,n,i,s,a,o){const{geometry:c,_indirectBuffer:l}=r;for(let u=n,f=n+i;u<f;u++){let p=l?l[u]:u;Hr(c,e,t,p,s,a,o)}}function Sf(r,e,t,n,i,s,a){const{geometry:o,_indirectBuffer:c}=r;let l=1/0,u=null;for(let f=n,p=n+i;f<p;f++){let m;m=Hr(o,e,t,c?c[f]:f,null,s,a),m&&m.distance<l&&(u=m,l=m.distance)}return u}function xf(r,e,t,n,i,s,a){const{geometry:o}=t,{index:c}=o,l=o.attributes.position;for(let u=r,f=e+r;u<f;u++){let p;if(p=t.resolveTriangleIndex(u),we(a,p*3,c,l),a.needsUpdate=!0,n(a,p,i,s))return!0}return!1}function _f(r,e,t,n,i,s,a){pe.setBuffer(r._roots[e]),to(0,r,t,n,i,s,a),pe.clearBuffer()}function to(r,e,t,n,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=pe,u=r*2;if(Ee(u,c)){const p=$e(r,l),m=tt(u,c);pf(e,t,n,p,m,i,s,a)}else{const p=Ie(r);rn(p,o,n,s,a)&&to(p,e,t,n,i,s,a);const m=Be(r,l);rn(m,o,n,s,a)&&to(m,e,t,n,i,s,a)}}const bf=["x","y","z"];function Tf(r,e,t,n,i,s){pe.setBuffer(r._roots[e]);const a=no(0,r,t,n,i,s);return pe.clearBuffer(),a}function no(r,e,t,n,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=pe;let l=r*2;if(Ee(l,o)){const f=$e(r,c),p=tt(l,o);return mf(e,t,n,f,p,i,s)}else{const f=vo(r,c),p=bf[f],x=n.direction[p]>=0;let T,g;x?(T=Ie(r),g=Be(r,c)):(T=Be(r,c),g=Ie(r));const _=rn(T,a,n,i,s)?no(T,e,t,n,i,s):null;if(_){const C=_.point[p];if(x?C<=a[g+f]:C>=a[g+f+3])return _}const M=rn(g,a,n,i,s)?no(g,e,t,n,i,s):null;return _&&M?_.distance<=M.distance?_:M:_||M||null}}const pr=new A.Box3,An=new gt,On=new gt,Kn=new A.Matrix4,Va=new qe,mr=new qe;function Mf(r,e,t,n){pe.setBuffer(r._roots[e]);const i=io(0,r,t,n);return pe.clearBuffer(),i}function io(r,e,t,n,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=pe;let c=r*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Va.set(t.boundingBox.min,t.boundingBox.max,n),i=Va),Ee(c,a)){const u=e.geometry,f=u.index,p=u.attributes.position,m=t.index,x=t.attributes.position,T=$e(r,o),g=tt(c,a);if(Kn.copy(n).invert(),t.boundsTree)return Se(r,s,mr),mr.matrix.copy(Kn),mr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:_=>mr.intersectsBox(_),intersectsTriangle:_=>{_.a.applyMatrix4(n),_.b.applyMatrix4(n),_.c.applyMatrix4(n),_.needsUpdate=!0;for(let b=T*3,M=(g+T)*3;b<M;b+=3)if(we(On,b,f,p),On.needsUpdate=!0,_.intersectsTriangle(On))return!0;return!1}});{const v=$r(t);for(let _=T*3,b=(g+T)*3;_<b;_+=3){we(An,_,f,p),An.a.applyMatrix4(Kn),An.b.applyMatrix4(Kn),An.c.applyMatrix4(Kn),An.needsUpdate=!0;for(let M=0,C=v*3;M<C;M+=3)if(we(On,M,m,x),On.needsUpdate=!0,An.intersectsTriangle(On))return!0}}}else{const u=Ie(r),f=Be(r,o);return Se(u,s,pr),!!(i.intersectsBox(pr)&&io(u,e,t,n,i)||(Se(f,s,pr),i.intersectsBox(pr)&&io(f,e,t,n,i)))}}const yr=new A.Matrix4,zs=new qe,Qn=new qe,Cf=new A.Vector3,wf=new A.Vector3,Pf=new A.Vector3,Ef=new A.Vector3;function kf(r,e,t,n={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),zs.set(e.boundingBox.min,e.boundingBox.max,t),zs.needsUpdate=!0;const o=r.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,f=e.index,p=yt.getPrimitive(),m=yt.getPrimitive();let x=Cf,T=wf,g=null,v=null;i&&(g=Pf,v=Ef);let _=1/0,b=null,M=null;return yr.copy(t).invert(),Qn.matrix.copy(yr),r.shapecast({boundsTraverseOrder:C=>zs.distanceToBox(C),intersectsBounds:(C,P,E)=>E<_&&E<a?(P&&(Qn.min.copy(C.min),Qn.max.copy(C.max),Qn.needsUpdate=!0),!0):!1,intersectsRange:(C,P)=>{if(e.boundsTree)return e.boundsTree.shapecast({boundsTraverseOrder:z=>Qn.distanceToBox(z),intersectsBounds:(z,I,R)=>R<_&&R<a,intersectsRange:(z,I)=>{for(let R=z,N=z+I;R<N;R++){we(m,3*R,f,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let O=C,U=C+P;O<U;O++){we(p,3*O,l,c),p.needsUpdate=!0;const L=p.distanceToTriangle(m,x,g);if(L<_&&(T.copy(x),v&&v.copy(g),_=L,b=O,M=R),L<s)return!0}}}});{const E=$r(e);for(let z=0,I=E;z<I;z++){we(m,3*z,f,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let R=C,N=C+P;R<N;R++){we(p,3*R,l,c),p.needsUpdate=!0;const O=p.distanceToTriangle(m,x,g);if(O<_&&(T.copy(x),v&&v.copy(g),_=O,b=R,M=z),O<s)return!0}}}}}),yt.releasePrimitive(p),yt.releasePrimitive(m),_===1/0?null:(n.point?n.point.copy(T):n.point=T.clone(),n.distance=_,n.faceIndex=b,i&&(i.point?i.point.copy(v):i.point=v.clone(),i.point.applyMatrix4(yr),T.applyMatrix4(yr),i.distance=T.sub(i.point).length(),i.faceIndex=M),n)}function Rf(r,e=null){e&&Array.isArray(e)&&(e=new Set(e));const t=r.geometry,n=t.index?t.index.array:null,i=t.attributes.position;let s,a,o,c,l=0;const u=r._roots;for(let p=0,m=u.length;p<m;p++)s=u[p],a=new Uint32Array(s),o=new Uint16Array(s),c=new Float32Array(s),f(0,l),l+=s.byteLength;function f(p,m,x=!1){const T=p*2;if(Ee(T,o)){const g=$e(p,a),v=tt(T,o);let _=1/0,b=1/0,M=1/0,C=-1/0,P=-1/0,E=-1/0;for(let z=g,I=g+v;z<I;z++){const R=3*r.resolveTriangleIndex(z);for(let N=0;N<3;N++){let O=R+N;O=n?n[O]:O;const U=i.getX(O),L=i.getY(O),J=i.getZ(O);U<_&&(_=U),U>C&&(C=U),L<b&&(b=L),L>P&&(P=L),J<M&&(M=J),J>E&&(E=J)}}return c[p+0]!==_||c[p+1]!==b||c[p+2]!==M||c[p+3]!==C||c[p+4]!==P||c[p+5]!==E?(c[p+0]=_,c[p+1]=b,c[p+2]=M,c[p+3]=C,c[p+4]=P,c[p+5]=E,!0):!1}else{const g=Ie(p),v=Be(p,a);let _=x,b=!1,M=!1;if(e){if(!_){const R=g/Pe+m/We,N=v/Pe+m/We;b=e.has(R),M=e.has(N),_=!b&&!M}}else b=!0,M=!0;const C=_||b,P=_||M;let E=!1;C&&(E=f(g,m,_));let z=!1;P&&(z=f(v,m,_));const I=E||z;if(I)for(let R=0;R<3;R++){const N=g+R,O=v+R,U=c[N],L=c[N+3],J=c[O],$=c[O+3];c[p+R]=U<J?U:J,c[p+R+3]=L>$?L:$}return I}}}function Af(r,e,t,n,i,s,a){pe.setBuffer(r._roots[e]),ro(0,r,t,n,i,s,a),pe.clearBuffer()}function ro(r,e,t,n,i,s,a){const{float32Array:o,uint16Array:c,uint32Array:l}=pe,u=r*2;if(Ee(u,c)){const p=$e(r,l),m=tt(u,c);vf(e,t,n,p,m,i,s,a)}else{const p=Ie(r);rn(p,o,n,s,a)&&ro(p,e,t,n,i,s,a);const m=Be(r,l);rn(m,o,n,s,a)&&ro(m,e,t,n,i,s,a)}}const Of=["x","y","z"];function zf(r,e,t,n,i,s){pe.setBuffer(r._roots[e]);const a=so(0,r,t,n,i,s);return pe.clearBuffer(),a}function so(r,e,t,n,i,s){const{float32Array:a,uint16Array:o,uint32Array:c}=pe;let l=r*2;if(Ee(l,o)){const f=$e(r,c),p=tt(l,o);return Sf(e,t,n,f,p,i,s)}else{const f=vo(r,c),p=Of[f],x=n.direction[p]>=0;let T,g;x?(T=Ie(r),g=Be(r,c)):(T=Be(r,c),g=Ie(r));const _=rn(T,a,n,i,s)?so(T,e,t,n,i,s):null;if(_){const C=_.point[p];if(x?C<=a[g+f]:C>=a[g+f+3])return _}const M=rn(g,a,n,i,s)?so(g,e,t,n,i,s):null;return _&&M?_.distance<=M.distance?_:M:_||M||null}}const gr=new A.Box3,zn=new gt,In=new gt,ei=new A.Matrix4,Ja=new qe,vr=new qe;function If(r,e,t,n){pe.setBuffer(r._roots[e]);const i=oo(0,r,t,n);return pe.clearBuffer(),i}function oo(r,e,t,n,i=null){const{float32Array:s,uint16Array:a,uint32Array:o}=pe;let c=r*2;if(i===null&&(t.boundingBox||t.computeBoundingBox(),Ja.set(t.boundingBox.min,t.boundingBox.max,n),i=Ja),Ee(c,a)){const u=e.geometry,f=u.index,p=u.attributes.position,m=t.index,x=t.attributes.position,T=$e(r,o),g=tt(c,a);if(ei.copy(n).invert(),t.boundsTree)return Se(r,s,vr),vr.matrix.copy(ei),vr.needsUpdate=!0,t.boundsTree.shapecast({intersectsBounds:_=>vr.intersectsBox(_),intersectsTriangle:_=>{_.a.applyMatrix4(n),_.b.applyMatrix4(n),_.c.applyMatrix4(n),_.needsUpdate=!0;for(let b=T,M=g+T;b<M;b++)if(we(In,3*e.resolveTriangleIndex(b),f,p),In.needsUpdate=!0,_.intersectsTriangle(In))return!0;return!1}});{const v=$r(t);for(let _=T,b=g+T;_<b;_++){const M=e.resolveTriangleIndex(_);we(zn,3*M,f,p),zn.a.applyMatrix4(ei),zn.b.applyMatrix4(ei),zn.c.applyMatrix4(ei),zn.needsUpdate=!0;for(let C=0,P=v*3;C<P;C+=3)if(we(In,C,m,x),In.needsUpdate=!0,zn.intersectsTriangle(In))return!0}}}else{const u=Ie(r),f=Be(r,o);return Se(u,s,gr),!!(i.intersectsBox(gr)&&oo(u,e,t,n,i)||(Se(f,s,gr),i.intersectsBox(gr)&&oo(f,e,t,n,i)))}}const Sr=new A.Matrix4,Is=new qe,ti=new qe,Bf=new A.Vector3,Nf=new A.Vector3,Uf=new A.Vector3,Df=new A.Vector3;function Ff(r,e,t,n={},i={},s=0,a=1/0){e.boundingBox||e.computeBoundingBox(),Is.set(e.boundingBox.min,e.boundingBox.max,t),Is.needsUpdate=!0;const o=r.geometry,c=o.attributes.position,l=o.index,u=e.attributes.position,f=e.index,p=yt.getPrimitive(),m=yt.getPrimitive();let x=Bf,T=Nf,g=null,v=null;i&&(g=Uf,v=Df);let _=1/0,b=null,M=null;return Sr.copy(t).invert(),ti.matrix.copy(Sr),r.shapecast({boundsTraverseOrder:C=>Is.distanceToBox(C),intersectsBounds:(C,P,E)=>E<_&&E<a?(P&&(ti.min.copy(C.min),ti.max.copy(C.max),ti.needsUpdate=!0),!0):!1,intersectsRange:(C,P)=>{if(e.boundsTree){const E=e.boundsTree;return E.shapecast({boundsTraverseOrder:z=>ti.distanceToBox(z),intersectsBounds:(z,I,R)=>R<_&&R<a,intersectsRange:(z,I)=>{for(let R=z,N=z+I;R<N;R++){const O=E.resolveTriangleIndex(R);we(m,3*O,f,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let U=C,L=C+P;U<L;U++){const J=r.resolveTriangleIndex(U);we(p,3*J,l,c),p.needsUpdate=!0;const $=p.distanceToTriangle(m,x,g);if($<_&&(T.copy(x),v&&v.copy(g),_=$,b=U,M=R),$<s)return!0}}}})}else{const E=$r(e);for(let z=0,I=E;z<I;z++){we(m,3*z,f,u),m.a.applyMatrix4(t),m.b.applyMatrix4(t),m.c.applyMatrix4(t),m.needsUpdate=!0;for(let R=C,N=C+P;R<N;R++){const O=r.resolveTriangleIndex(R);we(p,3*O,l,c),p.needsUpdate=!0;const U=p.distanceToTriangle(m,x,g);if(U<_&&(T.copy(x),v&&v.copy(g),_=U,b=R,M=z),U<s)return!0}}}}}),yt.releasePrimitive(p),yt.releasePrimitive(m),_===1/0?null:(n.point?n.point.copy(T):n.point=T.clone(),n.distance=_,n.faceIndex=b,i&&(i.point?i.point.copy(v):i.point=v.clone(),i.point.applyMatrix4(Sr),T.applyMatrix4(Sr),i.distance=T.sub(i.point).length(),i.faceIndex=M),n)}function ja(r,e,t){return r===null?null:(r.point.applyMatrix4(e.matrixWorld),r.distance=r.point.distanceTo(t.ray.origin),r.object=e,r)}const xr=new qe,_r=new A.Ray,Ga=new A.Vector3,Wa=new A.Matrix4,$a=new A.Vector3,Bs=["getX","getY","getZ"];class Vn extends sl{static serialize(e,t={}){t={cloneBuffers:!0,...t};const n=e.geometry,i=e._roots,s=e._indirectBuffer,a=n.getIndex(),o={version:1,roots:null,index:null,indirectBuffer:null};return t.cloneBuffers?(o.roots=i.map(c=>c.slice()),o.index=a?a.array.slice():null,o.indirectBuffer=s?s.slice():null):(o.roots=i,o.index=a?a.array:null,o.indirectBuffer=s),o}static deserialize(e,t,n={}){n={setIndex:!0,indirect:!!e.indirectBuffer,...n};const{index:i,roots:s,indirectBuffer:a}=e;e.version||(console.warn("MeshBVH.deserialize: Serialization format has been changed and will be fixed up. It is recommended to regenerate any stored serialized data."),c(s));const o=new Vn(t,{...n,[Wr]:!0});if(o._roots=s,o._indirectBuffer=a||null,n.setIndex){const l=t.getIndex();if(l===null){const u=new A.BufferAttribute(e.index,1,!1);t.setIndex(u)}else l.array!==i&&(l.array.set(i),l.needsUpdate=!0)}return o;function c(l){for(let u=0;u<l.length;u++){const f=l[u],p=new Uint32Array(f),m=new Uint16Array(f);for(let x=0,T=f.byteLength/We;x<T;x++){const g=Pe*x,v=2*g;Ee(v,m)||(p[g+6]=p[g+6]/Pe-x)}}}}get primitiveStride(){return 3}get resolveTriangleIndex(){return this.resolvePrimitiveIndex}constructor(e,t={}){t.maxLeafTris&&(console.warn('MeshBVH: "maxLeafTris" option has been deprecated. Use maxLeafSize, instead.'),t={...t,maxLeafSize:t.maxLeafTris}),super(e,t)}shiftTriangleOffsets(e){return super.shiftPrimitiveOffsets(e)}writePrimitiveBounds(e,t,n){const i=this.geometry,s=this._indirectBuffer,a=i.attributes.position,o=i.index?i.index.array:null,l=(s?s[e]:e)*3;let u=l+0,f=l+1,p=l+2;o&&(u=o[u],f=o[f],p=o[p]);for(let m=0;m<3;m++){const x=a[Bs[m]](u),T=a[Bs[m]](f),g=a[Bs[m]](p);let v=x;T<v&&(v=T),g<v&&(v=g);let _=x;T>_&&(_=T),g>_&&(_=g),t[n+m]=v,t[n+m+3]=_}return t}computePrimitiveBounds(e,t,n){const i=this.geometry,s=this._indirectBuffer,a=i.attributes.position,o=i.index?i.index.array:null,c=a.normalized;if(e<0||t+e-n.offset>n.length/6)throw new Error("MeshBVH: compute triangle bounds range is invalid.");const l=a.array,u=a.offset||0;let f=3;a.isInterleavedBufferAttribute&&(f=a.data.stride);const p=["getX","getY","getZ"],m=n.offset;for(let x=e,T=e+t;x<T;x++){const v=(s?s[x]:x)*3,_=(x-m)*6;let b=v+0,M=v+1,C=v+2;o&&(b=o[b],M=o[M],C=o[C]),c||(b=b*f+u,M=M*f+u,C=C*f+u);for(let P=0;P<3;P++){let E,z,I;c?(E=a[p[P]](b),z=a[p[P]](M),I=a[p[P]](C)):(E=l[b+P],z=l[M+P],I=l[C+P]);let R=E;z<R&&(R=z),I<R&&(R=I);let N=E;z>N&&(N=z),I>N&&(N=I);const O=(N-R)/2,U=P*2;n[_+U+0]=R+O,n[_+U+1]=O+(Math.abs(R)+O)*kr}}return n}raycastObject3D(e,t,n=[]){const{material:i}=e;if(i===void 0)return;Wa.copy(e.matrixWorld).invert(),_r.copy(t.ray).applyMatrix4(Wa),$a.setFromMatrixScale(e.matrixWorld),Ga.copy(_r.direction).multiply($a);const s=Ga.length(),a=t.near/s,o=t.far/s;if(t.firstHitOnly===!0){let c=this.raycastFirst(_r,i,a,o);c=ja(c,e,t),c&&n.push(c)}else{const c=this.raycast(_r,i,a,o);for(let l=0,u=c.length;l<u;l++){const f=ja(c[l],e,t);f&&n.push(f)}}return n}refit(e=null){return(this.indirect?Rf:gf)(this,e)}raycast(e,t=A.FrontSide,n=0,i=1/0){const s=this._roots,a=[],o=this.indirect?Af:_f;for(let c=0,l=s.length;c<l;c++)o(this,c,t,e,a,n,i);return a}raycastFirst(e,t=A.FrontSide,n=0,i=1/0){const s=this._roots;let a=null;const o=this.indirect?zf:Tf;for(let c=0,l=s.length;c<l;c++){const u=o(this,c,t,e,n,i);u!=null&&(a==null||u.distance<a.distance)&&(a=u)}return a}intersectsGeometry(e,t){let n=!1;const i=this._roots,s=this.indirect?If:Mf;for(let a=0,o=i.length;a<o&&(n=s(this,a,e,t),!n);a++);return n}shapecast(e){const t=yt.getPrimitive(),n=super.shapecast({...e,intersectsPrimitive:e.intersectsTriangle,scratchPrimitive:t,iterate:this.indirect?xf:yf});return yt.releasePrimitive(t),n}bvhcast(e,t,n){let{intersectsRanges:i,intersectsTriangles:s}=n;const a=yt.getPrimitive(),o=this.geometry.index,c=this.geometry.attributes.position,l=this.indirect?x=>{const T=this.resolveTriangleIndex(x);we(a,T*3,o,c)}:x=>{we(a,x*3,o,c)},u=yt.getPrimitive(),f=e.geometry.index,p=e.geometry.attributes.position,m=e.indirect?x=>{const T=e.resolveTriangleIndex(x);we(u,T*3,f,p)}:x=>{we(u,x*3,f,p)};if(s){if(!(e instanceof Vn))throw new Error('MeshBVH: "intersectsTriangles" callback can only be used with another MeshBVH.');const x=(T,g,v,_,b,M,C,P)=>{for(let E=v,z=v+_;E<z;E++){m(E),u.a.applyMatrix4(t),u.b.applyMatrix4(t),u.c.applyMatrix4(t),u.needsUpdate=!0;for(let I=T,R=T+g;I<R;I++)if(l(I),a.needsUpdate=!0,s(a,u,I,E,b,M,C,P))return!0}return!1};if(i){const T=i;i=function(g,v,_,b,M,C,P,E){return T(g,v,_,b,M,C,P,E)?!0:x(g,v,_,b,M,C,P,E)}}else i=x}return super.bvhcast(e,t,{intersectsRanges:i})}intersectsBox(e,t){return xr.set(e.min,e.max,t),xr.needsUpdate=!0,this.shapecast({intersectsBounds:n=>xr.intersectsBox(n),intersectsTriangle:n=>xr.intersectsTriangle(n)})}intersectsSphere(e){return this.shapecast({intersectsBounds:t=>e.intersectsBox(t),intersectsTriangle:t=>t.intersectsSphere(e)})}closestPointToGeometry(e,t,n={},i={},s=0,a=1/0){return(this.indirect?Ff:kf)(this,e,t,n,i,s,a)}closestPointToPoint(e,t={},n=0,i=1/0){return hf(this,e,t,n,i)}}const Bn={Mesh:A.Mesh.prototype.raycast,Line:A.Line.prototype.raycast,LineSegments:A.LineSegments.prototype.raycast,LineLoop:A.LineLoop.prototype.raycast,Points:A.Points.prototype.raycast,BatchedMesh:A.BatchedMesh.prototype.raycast},De=new A.Mesh,br=[];function Lf(r,e){if(this.isBatchedMesh)Vf.call(this,r,e);else{const{geometry:t}=this;if(t.boundsTree)t.boundsTree.raycastObject3D(this,r,e);else{let n;if(this instanceof A.Mesh)n=Bn.Mesh;else if(this instanceof A.LineSegments)n=Bn.LineSegments;else if(this instanceof A.LineLoop)n=Bn.LineLoop;else if(this instanceof A.Line)n=Bn.Line;else if(this instanceof A.Points)n=Bn.Points;else throw new Error("BVH: Fallback raycast function not found.");n.call(this,r,e)}}}function Vf(r,e){if(this.boundsTrees){const t=this.boundsTrees,n=this._drawInfo||this._instanceInfo,i=this._drawRanges||this._geometryInfo,s=this.matrixWorld;De.material=this.material,De.geometry=this.geometry;const a=De.geometry.boundsTree,o=De.geometry.drawRange;De.geometry.boundingSphere===null&&(De.geometry.boundingSphere=new A.Sphere);for(let c=0,l=n.length;c<l;c++){if(!this.getVisibleAt(c))continue;const u=n[c].geometryIndex;if(De.geometry.boundsTree=t[u],this.getMatrixAt(c,De.matrixWorld).premultiply(s),!De.geometry.boundsTree){this.getBoundingBoxAt(u,De.geometry.boundingBox),this.getBoundingSphereAt(u,De.geometry.boundingSphere);const f=i[u];De.geometry.setDrawRange(f.start,f.count)}De.raycast(r,br);for(let f=0,p=br.length;f<p;f++){const m=br[f];m.object=this,m.batchId=c,e.push(m)}br.length=0}De.geometry.boundsTree=a,De.geometry.drawRange=o,De.material=null,De.geometry=null}else Bn.BatchedMesh.call(this,r,e)}function Jf(r={}){const{type:e=Vn}=r;return this.boundsTree=new e(this,r),this.boundsTree}const fn=new A.Vector3,dn=new A.Vector3,pn=new A.Vector3,Ha=new A.Vector4,Tr=new A.Vector3,Ns=new A.Vector3,qa=new A.Vector4,Xa=new A.Vector4,Mr=new A.Matrix4,Ya=new A.Matrix4;function ni(r,e){if(!r&&!e)return;const t=r.count===e.count,n=r.normalized===e.normalized,i=r.array.constructor===e.array.constructor,s=r.itemSize===e.itemSize;if(!t||!n||!i||!s)throw new Error}function oi(r,e=null){const t=r.array.constructor,n=r.normalized,i=r.itemSize,s=e===null?r.count:e;return new A.BufferAttribute(new t(i*s),i,n)}function ol(r,e,t=0){if(r.isInterleavedBufferAttribute){const n=r.itemSize;for(let i=0,s=r.count;i<s;i++){const a=i+t;e.setX(a,r.getX(i)),n>=2&&e.setY(a,r.getY(i)),n>=3&&e.setZ(a,r.getZ(i)),n>=4&&e.setW(a,r.getW(i))}}else{const n=e.array,i=n.constructor,s=n.BYTES_PER_ELEMENT*r.itemSize*t;new i(n.buffer,s,r.array.length).set(r.array)}}function jf(r,e,t){const n=r.elements,i=e.elements;for(let s=0,a=i.length;s<a;s++)n[s]+=i[s]*t}function Za(r,e,t){const n=r.skeleton,i=r.geometry,s=n.bones,a=n.boneInverses;qa.fromBufferAttribute(i.attributes.skinIndex,e),Xa.fromBufferAttribute(i.attributes.skinWeight,e),Mr.elements.fill(0);for(let o=0;o<4;o++){const c=Xa.getComponent(o);if(c!==0){const l=qa.getComponent(o);Ya.multiplyMatrices(s[l].matrixWorld,a[l]),jf(Mr,Ya,c)}}return Mr.multiply(r.bindMatrix).premultiply(r.bindMatrixInverse),t.transformDirection(Mr),t}function Us(r,e,t,n,i){Tr.set(0,0,0);for(let s=0,a=r.length;s<a;s++){const o=e[s],c=r[s];o!==0&&(Ns.fromBufferAttribute(c,n),t?Tr.addScaledVector(Ns,o):Tr.addScaledVector(Ns.sub(i),o))}i.add(Tr)}function Gf(r,e={useGroups:!1,updateIndex:!1,skipAttributes:[]},t=new A.BufferGeometry){const n=r[0].index!==null,{useGroups:i=!1,updateIndex:s=!1,skipAttributes:a=[]}=e,o=new Set(Object.keys(r[0].attributes)),c={};let l=0;t.clearGroups();for(let u=0;u<r.length;++u){const f=r[u];let p=0;if(n!==(f.index!==null))throw new Error("StaticGeometryGenerator: All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them.");for(const m in f.attributes){if(!o.has(m))throw new Error('StaticGeometryGenerator: All geometries must have compatible attributes; make sure "'+m+'" attribute exists among all geometries, or in none of them.');c[m]===void 0&&(c[m]=[]),c[m].push(f.attributes[m]),p++}if(p!==o.size)throw new Error("StaticGeometryGenerator: Make sure all geometries have the same number of attributes.");if(i){let m;if(n)m=f.index.count;else if(f.attributes.position!==void 0)m=f.attributes.position.count;else throw new Error("StaticGeometryGenerator: The geometry must have either an index or a position attribute");t.addGroup(l,m,u),l+=m}}if(n){let u=!1;if(!t.index){let f=0;for(let p=0;p<r.length;++p)f+=r[p].index.count;t.setIndex(new A.BufferAttribute(new Uint32Array(f),1,!1)),u=!0}if(s||u){const f=t.index;let p=0,m=0;for(let x=0;x<r.length;++x){const T=r[x],g=T.index;if(a[x]!==!0)for(let v=0;v<g.count;++v)f.setX(p,g.getX(v)+m),p++;m+=T.attributes.position.count}}}for(const u in c){const f=c[u];if(!(u in t.attributes)){let x=0;for(const T in f)x+=f[T].count;t.setAttribute(u,oi(c[u][0],x))}const p=t.attributes[u];let m=0;for(let x=0,T=f.length;x<T;x++){const g=f[x];a[x]!==!0&&ol(g,p,m),m+=g.count}}return t}function Wf(r,e){if(r===null||e===null)return r===e;if(r.length!==e.length)return!1;for(let t=0,n=r.length;t<n;t++)if(r[t]!==e[t])return!1;return!0}function $f(r){const{index:e,attributes:t}=r;if(e)for(let n=0,i=e.count;n<i;n+=3){const s=e.getX(n),a=e.getX(n+2);e.setX(n,a),e.setX(n+2,s)}else for(const n in t){const i=t[n],s=i.itemSize;for(let a=0,o=i.count;a<o;a+=3)for(let c=0;c<s;c++){const l=i.getComponent(a,c),u=i.getComponent(a+2,c);i.setComponent(a,c,u),i.setComponent(a+2,c,l)}}return r}class Hf{constructor(e){this.matrixWorld=new A.Matrix4,this.geometryHash=null,this.boneMatrices=null,this.primitiveCount=-1,this.mesh=e,this.update()}update(){const e=this.mesh,t=e.geometry,n=e.skeleton,i=(t.index?t.index.count:t.attributes.position.count)/3;if(this.matrixWorld.copy(e.matrixWorld),this.geometryHash=t.attributes.position.version,this.primitiveCount=i,n){n.boneTexture||n.computeBoneTexture(),n.update();const s=n.boneMatrices;!this.boneMatrices||this.boneMatrices.length!==s.length?this.boneMatrices=s.slice():this.boneMatrices.set(s)}else this.boneMatrices=null}didChange(){const e=this.mesh,t=e.geometry,n=(t.index?t.index.count:t.attributes.position.count)/3;return!(this.matrixWorld.equals(e.matrixWorld)&&this.geometryHash===t.attributes.position.version&&Wf(e.skeleton&&e.skeleton.boneMatrices||null,this.boneMatrices)&&this.primitiveCount===n)}}class qf{constructor(e){Array.isArray(e)||(e=[e]);const t=[];e.forEach(n=>{n.traverseVisible(i=>{i.isMesh&&t.push(i)})}),this.meshes=t,this.useGroups=!0,this.applyWorldTransforms=!0,this.attributes=["position","normal","color","tangent","uv","uv2"],this._intermediateGeometry=new Array(t.length).fill().map(()=>new A.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 A.BufferGeometry){let t=[];const{meshes:n,useGroups:i,_intermediateGeometry:s,_diffMap:a}=this;for(let o=0,c=n.length;o<c;o++){const l=n[o],u=s[o],f=a.get(l);!f||f.didChange(l)?(this._convertToStaticGeometry(l,u),t.push(!1),f?f.update():a.set(l,new Hf(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 A.BufferAttribute(new Float32Array(0),4,!1))}else Gf(s,{useGroups:i,skipAttributes:t},e);for(const o in e.attributes)e.attributes[o].needsUpdate=!0;return e}_convertToStaticGeometry(e,t=new A.BufferGeometry){const n=e.geometry,i=this.applyWorldTransforms,s=this.attributes.includes("normal"),a=this.attributes.includes("tangent"),o=n.attributes,c=t.attributes;!t.index&&n.index&&(t.index=n.index.clone()),c.position||t.setAttribute("position",oi(o.position)),s&&!c.normal&&o.normal&&t.setAttribute("normal",oi(o.normal)),a&&!c.tangent&&o.tangent&&t.setAttribute("tangent",oi(o.tangent)),ni(n.index,t.index),ni(o.position,c.position),s&&ni(o.normal,c.normal),a&&ni(o.tangent,c.tangent);const l=o.position,u=s?o.normal:null,f=a?o.tangent:null,p=n.morphAttributes.position,m=n.morphAttributes.normal,x=n.morphAttributes.tangent,T=n.morphTargetsRelative,g=e.morphTargetInfluences,v=new A.Matrix3;v.getNormalMatrix(e.matrixWorld),n.index&&t.index.array.set(n.index.array);for(let _=0,b=o.position.count;_<b;_++)fn.fromBufferAttribute(l,_),u&&dn.fromBufferAttribute(u,_),f&&(Ha.fromBufferAttribute(f,_),pn.fromBufferAttribute(f,_)),g&&(p&&Us(p,g,T,_,fn),m&&Us(m,g,T,_,dn),x&&Us(x,g,T,_,pn)),e.isSkinnedMesh&&(e.applyBoneTransform(_,fn),u&&Za(e,_,dn),f&&Za(e,_,pn)),i&&fn.applyMatrix4(e.matrixWorld),c.position.setXYZ(_,fn.x,fn.y,fn.z),u&&(i&&dn.applyNormalMatrix(v),c.normal.setXYZ(_,dn.x,dn.y,dn.z)),f&&(i&&pn.transformDirection(e.matrixWorld),c.tangent.setXYZW(_,pn.x,pn.y,pn.z,Ha.w));for(const _ in this.attributes){const b=this.attributes[_];b==="position"||b==="tangent"||b==="normal"||!(b in o)||(c[b]||t.setAttribute(b,oi(o[b])),ni(o[b],c[b]),ol(o[b],c[b]))}return e.matrixWorld.determinant()<0&&$f(t),t}}const Xf=Object.freeze(Object.defineProperty({__proto__:null,AVERAGE:Zc,BVH:il,CENTER:go,CONTAINED:Ys,ExtendedTriangle:gt,GeometryBVH:sl,MeshBVH:Vn,OrientedBox:qe,SAH:Kc,SKIP_GENERATION:Wr,StaticGeometryGenerator:qf,acceleratedRaycast:Lf,computeBoundsTree:Jf,generateIndirectBuffer:rl},Symbol.toStringTag,{value:"Module"}));class Yf{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 mt={node:"node",material:"material",camera:"camera",light:"light"},mn="KHR_animation_pointer",Zf={CUBICSPLINE:void 0,LINEAR:A.InterpolateLinear,STEP:A.InterpolateDiscrete};class Kf{constructor(e){this.name=mn,this.parser=e,this.animationPointerResolver=null}setAnimationPointerResolver(e){return this.animationPointerResolver=e,this}loadAnimationTargetFromChannel(e){const t=e.target,n=t.node!==void 0?t.node:t.id;return this.parser.getDependency("node",n)}loadAnimationTargetFromChannelWithAnimationPointer(e){ed();const t=e.target,n=t.extensions&&t.extensions[mn]&&t.path&&t.path==="pointer";if(!n)return null;let i,s=mt.node,a;if(n){const c=t.extensions[mn];let l=c.pointer;if(!l){console.warn("Invalid path",c,t);return}if(l.startsWith("/materials/")?s=mt.material:l.startsWith("/extensions/KHR_lights_punctual/lights/")?s=mt.light:l.startsWith("/cameras/")&&(s=mt.camera),a=this._tryResolveTargetId(l,s),a===null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,l);return}switch(s){case mt.material:const u=("/materials/"+a.toString()+"/").length,f=l.substring(0,u);switch(i=l.substring(u),i){case"pbrMetallicRoughness/baseColorFactor":i="color";break;case"pbrMetallicRoughness/roughnessFactor":i="roughness";break;case"pbrMetallicRoughness/metallicFactor":i="metalness";break;case"emissiveFactor":i="emissive";break;case"alphaCutoff":i="alphaTest";break;case"occlusionTexture/strength":i="aoMapIntensity";break;case"normalTexture/scale":i="normalScale";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/scale":i="map/repeat";break;case"pbrMetallicRoughness/baseColorTexture/extensions/KHR_texture_transform/offset":i="map/offset";break;case"emissiveTexture/extensions/KHR_texture_transform/scale":i="emissiveMap/repeat";break;case"emissiveTexture/extensions/KHR_texture_transform/offset":i="emissiveMap/offset";break;case"extensions/KHR_materials_emissive_strength/emissiveStrength":i="emissiveIntensity";break;case"extensions/KHR_materials_transmission/transmissionFactor":i="transmission";break;case"extensions/KHR_materials_ior/ior":i="ior";break;case"extensions/KHR_materials_volume/thicknessFactor":i="thickness";break;case"extensions/KHR_materials_volume/attenuationColor":i="attenuationColor";break;case"extensions/KHR_materials_volume/attenuationDistance":i="attenuationDistance";break;case"extensions/KHR_materials_iridescence/iridescenceFactor":i="iridescence";break;case"extensions/KHR_materials_iridescence/iridescenceIor":i="iridescenceIOR";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMinimum":i="iridescenceThicknessRange[0]";break;case"extensions/KHR_materials_iridescence/iridescenceThicknessMaximum":i="iridescenceThicknessRange[1]";break;case"extensions/KHR_materials_clearcoat/clearcoatFactor":i="clearcoat";break;case"extensions/KHR_materials_clearcoat/clearcoatRoughnessFactor":i="clearcoatRoughness";break;case"extensions/KHR_materials_sheen/sheenColorFactor":i="sheenColor";break;case"extensions/KHR_materials_sheen/sheenRoughnessFactor":i="sheenRoughness";break;case"extensions/KHR_materials_specular/specularFactor":i="specularIntensity";break;case"extensions/KHR_materials_specular/specularColorFactor":i="specularColor";break}l=f+i;break;case mt.node:const p=("/nodes/"+a.toString()+"/").length,m=l.substring(0,p);switch(i=l.substring(p),i){case"translation":i="position";break;case"rotation":i="quaternion";break;case"scale":i="scale";break;case"weights":i="morphTargetInfluences";break;case"extensions/KHR_node_visibility/visible":i="visible";break}l=m+i;break;case mt.light:const x=("/extensions/KHR_lights_punctual/lights/"+a.toString()+"/").length;switch(i=l.substring(x),i){case"color":break;case"intensity":break;case"spot/innerConeAngle":i="penumbra";break;case"spot/outerConeAngle":i="angle";break;case"range":i="distance";break}l="/lights/"+a.toString()+"/"+i;break;case mt.camera:const T=("/cameras/"+a.toString()+"/").length,g=l.substring(0,T);switch(i=l.substring(T),i){case"perspective/yfov":i="fov";break;case"perspective/znear":case"orthographic/znear":i="near";break;case"perspective/zfar":case"orthographic/zfar":i="far";break;case"perspective/aspect":i="aspect";break;case"orthographic/xmag":i="zoom";break;case"orthographic/ymag":i="zoom";break}l=g+i;break}this.animationPointerResolver?.resolvePath&&(l=this.animationPointerResolver.resolvePath(l)),t.extensions[mn].pointer=l}if(a==null||isNaN(a)){console.warn("Failed resolving animation node id: "+a,t);return}let o;return s===mt.node?o=this.parser.getDependency("node",a):s===mt.material?o=this.parser.getDependency("material",a):s===mt.light?o=this.parser.getDependency("light",a):s===mt.camera?o=this.parser.getDependency("camera",a):console.error("Unhandled type",s),o}createAnimationTracksWithAnimationPointer(e,t,n,i,s){if(!(s.extensions&&s.extensions[mn]&&s.path&&s.path==="pointer"))return null;let o=s.extensions[mn].pointer;if(!o)return null;const c=[];o=o.replaceAll("/",".");const l=o.split(".");var f=e.name!==void 0&&e.name!==null?e.name:e.uuid;if(l[2]=f,l[3]==="morphTargetInfluences"&&e.type==="Group"){for(const x of e.children)x instanceof A.SkinnedMesh&&x.morphTargetInfluences&&(l[3]=x.name,l[4]="morphTargetInfluences",m(this.parser));return c}m(this.parser);function p(x,T){try{const g=T.split(".").filter(Boolean),_=g[g.length-1].replace(/\[.*\]$/,"");return _ in x?typeof x[_]=="boolean":!1}catch{return!1}}function m(x){o=l.join(".");let T,g=!1;switch(n.itemSize){case 1:Object.prototype.toString.call(n.array)==="[object Uint8Array]"&&p(e,o)?(T=A.BooleanKeyframeTrack,g=!0):T=A.NumberKeyframeTrack;break;case 2:case 3:T=A.VectorKeyframeTrack;break;case 4:o.endsWith(".quaternion")?T=A.QuaternionKeyframeTrack:T=A.ColorKeyframeTrack;break}if(!T){console.warn("Unsupported output accessor format",n);return}const v=i.interpolation!==void 0?Zf[i.interpolation]:A.InterpolateLinear;let _=x._getArrayFromAccessor(n);o.endsWith(".fov")&&(_=_.map(M=>M/Math.PI*180)),g&&(_=_.map(M=>M>0));const b=new T(o,t.array,_,v);if(v==="CUBICSPLINE"&&x._createCubicSplineTrackInterpolant(b),c.push(b),o&&n.itemSize===4&&o.startsWith(".materials.")&&o.endsWith(".color")){const M=new Float32Array(_.length/4);for(let P=0,E=_.length/4;P<E;P+=1)M[P]=_[P*4+3];const C=new T(o.replace(".color",".opacity"),t.array,M,v);v==="CUBICSPLINE"&&x._createCubicSplineTrackInterpolant(b),c.push(C)}}return c}_tryResolveTargetId(e,t){let n="";return t==="node"?n=e.substring(7):t==="material"?n=e.substring(11):t==="light"?n=e.substring(39):t==="camera"&&(n=e.substring(9)),n=n.substring(0,n.indexOf("/")),Number.parseInt(n)}loadAnimation(e){const t=this,n=this.parser.json,i=this.parser,s=n.animations[e],a=s.name?s.name:"animation_"+e,o=[],c=[],l=[],u=[],f=[];for(let p=0,m=s.channels.length;p<m;p++){const x=s.channels[p],T=s.samplers[x.sampler],g=x.target,v=s.parameters!==void 0?s.parameters[T.input]:T.input,_=s.parameters!==void 0?s.parameters[T.output]:T.output;let b=t.loadAnimationTargetFromChannelWithAnimationPointer(x);b||(b=t.loadAnimationTargetFromChannel(x)),o.push(b),c.push(i.getDependency("accessor",v)),l.push(i.getDependency("accessor",_)),u.push(T),f.push(g)}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(l),Promise.all(u),Promise.all(f)]).then(function(p){const m=p[0],x=p[1],T=p[2],g=p[3],v=p[4],_=[];for(let b=0,M=m.length;b<M;b++){const C=m[b],P=x[b],E=T[b],z=g[b],I=v[b];if(C===void 0)continue;C.updateMatrix&&(C.updateMatrix(),C.matrixAutoUpdate=!0);let R=t.createAnimationTracksWithAnimationPointer(C,P,E,z,I);if(R||(R=i._createAnimationTracks(C,P,E,z,I)),R)for(let N=0;N<R.length;N++)_.push(R[N])}return new A.AnimationClip(a,void 0,_)})}}let Ka=!1,Qf=null;function ed(){if(Ka)return;Ka=!0;const r=Qf||=A.PropertyBinding.findNode;A.PropertyBinding.findNode=function(e,t){if(!t)return r(e,t);if(t.startsWith(".materials.")){const n=t.substring(11).substring(t.indexOf(".")),i=n.indexOf("."),s=i<0?n:n.substring(0,i);let a=null;return e.traverse(o=>{a!==null||o.type!=="Mesh"&&o.type!=="SkinnedMesh"||o.material&&(o.material.uuid===s||o.material.name===s)&&(a=o.material,a!==null&&(n.endsWith(".map")?a=a.map:n.endsWith(".emissiveMap")&&(a=a.emissiveMap)))}),a}else if(t.startsWith(".nodes.")||t.startsWith(".lights.")||t.startsWith(".cameras.")){const n=t.split(".");let i;for(let s=1;s<n.length;s++){const a=n[s];if(a.length==36)i=e.getObjectByProperty("uuid",a);else if(i&&i[a]){const c=Number.parseInt(a);let l=a;c>=0&&(l=c),i=i[l]}else{const c=e.getObjectByName(a);c&&(i=c)}}if(!i){const s=r(e,n[2]);return s||console.warn(mn+": Property binding not found",t,e,e.name,n),s}return i}return r(e,t)}}const td=Object.freeze(Object.defineProperty({__proto__:null,GLTFAnimationPointerExtension:Kf},Symbol.toStringTag,{value:"Module"}));exports.BatchedParticleRenderer=nh;exports.Builder=ao;exports.ByteBuffer=li;exports.ConstantColor=vn;exports.ConstantValue=ee;exports.Matrix4=Et;exports.MeshBVH=Vn;exports.MotionController=Hl;exports.ParticleSystem=Ur;exports.SIZE_PREFIX_LENGTH=ec;exports.TrailParticle=Br;exports.Vector4=at;exports.WorkerBase=Yf;exports._md5=Ll;exports.bundler=Lh;exports.createNoise4D=rh;exports.fetchProfile=Jl;exports.index=jh;exports.index$1=Xf;exports.index$2=td;exports.md5=Qa;exports.v5=Bl;