@needle-tools/engine 3.6.0-alpha → 3.6.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/needle-engine.js +12 -12
- package/dist/needle-engine.light.js +4965 -4965
- package/dist/needle-engine.light.min.js +5 -5
- package/dist/needle-engine.light.umd.cjs +5 -5
- package/dist/needle-engine.min.js +5 -5
- package/dist/needle-engine.umd.cjs +5 -5
- package/lib/engine/engine_context.js +2 -2
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine-components/Camera.js +0 -3
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +7 -3
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/package.json +1 -1
- package/plugins/vite/defines.js +5 -2
- package/src/engine/engine_context.ts +2 -2
- package/src/engine-components/Camera.ts +0 -4
- package/src/engine-components/OrbitControls.ts +6 -2
|
@@ -3333,11 +3333,11 @@ a=extmap-allow-mixed`)!==-1){const r=s.sdp.split(`
|
|
|
3333
3333
|
isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},n}()),YP={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"},Cj=function(){function n(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=YP,this.browser=Qp.getBrowser(),this.browserVersion=Qp.getVersion(),this.supports=function(){var e={browser:Qp.isBrowserSupported(),webRTC:Qp.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(YP),e.audioVideo=!0;var i=void 0;try{i=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!i.ordered;try{i.binaryType="blob",e.binaryBlob=!Qp.isIOS}catch{}}catch{}finally{i&&i.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=UP.pack,this.unpack=UP.unpack,this._dataCount=1}return n.prototype.noop=function(){},n.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},n.prototype.chunk=function(e){for(var t=[],i=e.size,s=Math.ceil(i/li.chunkedMTU),r=0,o=0;o<i;){var a=Math.min(i,o+li.chunkedMTU),l=e.slice(o,a),c={__peerData:this._dataCount,n:r,data:l,total:s};t.push(c),o=a,r++}return this._dataCount++,t},n.prototype.blobToArrayBuffer=function(e,t){var i=new FileReader;return i.onload=function(s){s.target&&t(s.target.result)},i.readAsArrayBuffer(e),i},n.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),i=0;i<e.length;i++)t[i]=e.charCodeAt(i)&255;return t.buffer},n.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},n.prototype.isSecure=function(){return location.protocol==="https:"},n}(),li=new Cj,aL={};La(aL,"Peer",()=>oR,n=>oR=n);var uA={},Sj=Object.prototype.hasOwnProperty,Hs="~";function mm(){}Object.create&&(mm.prototype=Object.create(null),new mm().__proto__||(Hs=!1));function Ej(n,e,t){this.fn=n,this.context=e,this.once=t||!1}function lL(n,e,t,i,s){if(typeof t!="function")throw new TypeError("The listener must be a function");var r=new Ej(t,i||n,s),o=Hs?Hs+e:e;return n._events[o]?n._events[o].fn?n._events[o]=[n._events[o],r]:n._events[o].push(r):(n._events[o]=r,n._eventsCount++),n}function Yy(n,e){--n._eventsCount===0?n._events=new mm:delete n._events[e]}function bs(){this._events=new mm,this._eventsCount=0}bs.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)Sj.call(t,i)&&e.push(Hs?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};bs.prototype.listeners=function(e){var t=Hs?Hs+e:e,i=this._events[t];if(!i)return[];if(i.fn)return[i.fn];for(var s=0,r=i.length,o=new Array(r);s<r;s++)o[s]=i[s].fn;return o};bs.prototype.listenerCount=function(e){var t=Hs?Hs+e:e,i=this._events[t];return i?i.fn?1:i.length:0};bs.prototype.emit=function(e,t,i,s,r,o){var a=Hs?Hs+e:e;if(!this._events[a])return!1;var l=this._events[a],c=arguments.length,h,d;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,i),!0;case 4:return l.fn.call(l.context,t,i,s),!0;case 5:return l.fn.call(l.context,t,i,s,r),!0;case 6:return l.fn.call(l.context,t,i,s,r,o),!0}for(d=1,h=new Array(c-1);d<c;d++)h[d-1]=arguments[d];l.fn.apply(l.context,h)}else{var f=l.length,p;for(d=0;d<f;d++)switch(l[d].once&&this.removeListener(e,l[d].fn,void 0,!0),c){case 1:l[d].fn.call(l[d].context);break;case 2:l[d].fn.call(l[d].context,t);break;case 3:l[d].fn.call(l[d].context,t,i);break;case 4:l[d].fn.call(l[d].context,t,i,s);break;default:if(!h)for(p=1,h=new Array(c-1);p<c;p++)h[p-1]=arguments[p];l[d].fn.apply(l[d].context,h)}}return!0};bs.prototype.on=function(e,t,i){return lL(this,e,t,i,!1)};bs.prototype.once=function(e,t,i){return lL(this,e,t,i,!0)};bs.prototype.removeListener=function(e,t,i,s){var r=Hs?Hs+e:e;if(!this._events[r])return this;if(!t)return Yy(this,r),this;var o=this._events[r];if(o.fn)o.fn===t&&(!s||o.once)&&(!i||o.context===i)&&Yy(this,r);else{for(var a=0,l=[],c=o.length;a<c;a++)(o[a].fn!==t||s&&!o[a].once||i&&o[a].context!==i)&&l.push(o[a]);l.length?this._events[r]=l.length===1?l[0]:l:Yy(this,r)}return this};bs.prototype.removeAllListeners=function(e){var t;return e?(t=Hs?Hs+e:e,this._events[t]&&Yy(this,t)):(this._events=new mm,this._eventsCount=0),this};bs.prototype.off=bs.prototype.removeListener;bs.prototype.addListener=bs.prototype.on;bs.prefixed=Hs;bs.EventEmitter=bs;uA=bs;var it={};La(it,"LogLevel",()=>$s,n=>$s=n);La(it,"default",()=>JP,n=>JP=n);var Th=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var i=t.call(n),s,r=[],o;try{for(;(e===void 0||e-- >0)&&!(s=i.next()).done;)r.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return r},Ph=function(n,e,t){if(t||arguments.length===2)for(var i=0,s=e.length,r;i<s;i++)(r||!(i in e))&&(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return n.concat(r||Array.prototype.slice.call(e))},Ij="PeerJS: ",$s;(function(n){n[n.Disabled=0]="Disabled",n[n.Errors=1]="Errors",n[n.Warnings=2]="Warnings",n[n.All=3]="All"})($s||($s={}));var Mj=function(){function n(){this._logLevel=$s.Disabled}return Object.defineProperty(n.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),n.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=$s.All&&this._print.apply(this,Ph([$s.All],Th(e),!1))},n.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=$s.Warnings&&this._print.apply(this,Ph([$s.Warnings],Th(e),!1))},n.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=$s.Errors&&this._print.apply(this,Ph([$s.Errors],Th(e),!1))},n.prototype.setLogFunction=function(e){this._print=e},n.prototype._print=function(e){for(var t=[],i=1;i<arguments.length;i++)t[i-1]=arguments[i];var s=Ph([Ij],Th(t),!1);for(var r in s)s[r]instanceof Error&&(s[r]="("+s[r].name+") "+s[r].message);e>=$s.All?console.log.apply(console,Ph([],Th(s),!1)):e>=$s.Warnings?console.warn.apply(console,Ph(["WARNING"],Th(s),!1)):e>=$s.Errors&&console.error.apply(console,Ph(["ERROR"],Th(s),!1))},n}(),JP=new Mj,cL={};La(cL,"Socket",()=>KP,n=>KP=n);var ko;(function(n){n.Data="data",n.Media="media"})(ko||(ko={}));var nn;(function(n){n.BrowserIncompatible="browser-incompatible",n.Disconnected="disconnected",n.InvalidID="invalid-id",n.InvalidKey="invalid-key",n.Network="network",n.PeerUnavailable="peer-unavailable",n.SslUnavailable="ssl-unavailable",n.ServerError="server-error",n.SocketError="socket-error",n.SocketClosed="socket-closed",n.UnavailableID="unavailable-id",n.WebRTC="webrtc"})(nn||(nn={}));var ol;(function(n){n.Binary="binary",n.BinaryUTF8="binary-utf8",n.JSON="json"})(ol||(ol={}));var Cl;(function(n){n.Message="message",n.Disconnected="disconnected",n.Error="error",n.Close="close"})(Cl||(Cl={}));var ts;(function(n){n.Heartbeat="HEARTBEAT",n.Candidate="CANDIDATE",n.Offer="OFFER",n.Answer="ANSWER",n.Open="OPEN",n.Error="ERROR",n.IdTaken="ID-TAKEN",n.InvalidKey="INVALID-KEY",n.Leave="LEAVE",n.Expire="EXPIRE"})(ts||(ts={}));var E1={};E1=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 Tj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),Pj=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var i=t.call(n),s,r=[],o;try{for(;(e===void 0||e-- >0)&&!(s=i.next()).done;)r.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return r},Rj=function(n,e,t){if(t||arguments.length===2)for(var i=0,s=e.length,r;i<s;i++)(r||!(i in e))&&(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return n.concat(r||Array.prototype.slice.call(e))},Bj=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},KP=function(n){Tj(e,n);function e(t,i,s,r,o,a){a===void 0&&(a=5e3);var l=n.call(this)||this;l.pingInterval=a,l._disconnected=!0,l._messagesQueue=[];var c=t?"wss://":"ws://";return l._baseUrl=c+i+":"+s+r+"peerjs?key="+o,l}return e.prototype.start=function(t,i){var s=this;this._id=t;var r="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(i);this._socket||!this._disconnected||(this._socket=new WebSocket(r+"&version="+E1.version),this._disconnected=!1,this._socket.onmessage=function(o){var a;try{a=JSON.parse(o.data),it.default.log("Server message received:",a)}catch{it.default.log("Invalid server message",o.data);return}s.emit(Cl.Message,a)},this._socket.onclose=function(o){s._disconnected||(it.default.log("Socket closed.",o),s._cleanup(),s._disconnected=!0,s.emit(Cl.Disconnected))},this._socket.onopen=function(){s._disconnected||(s._sendQueuedMessages(),it.default.log("Socket open"),s._scheduleHeartbeat())})},e.prototype._scheduleHeartbeat=function(){var t=this;this._wsPingTimer=setTimeout(function(){t._sendHeartbeat()},this.pingInterval)},e.prototype._sendHeartbeat=function(){if(!this._wsOpen()){it.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:ts.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,i,s=Rj([],Pj(this._messagesQueue),!1);this._messagesQueue=[];try{for(var r=Bj(s),o=r.next();!o.done;o=r.next()){var a=o.value;this.send(a)}}catch(l){t={error:l}}finally{try{o&&!o.done&&(i=r.return)&&i.call(r)}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(Cl.Error,"Invalid message");return}if(this._wsOpen()){var i=JSON.stringify(t);this._socket.send(i)}}},e.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},e.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)},e}(uA.EventEmitter),IS={};La(IS,"MediaConnection",()=>eR,n=>eR=n);var I1={};La(I1,"Negotiator",()=>ZP,n=>ZP=n);var H0=function(){return H0=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},H0.apply(this,arguments)},ty=function(n,e,t,i){function s(r){return r instanceof t?r:new t(function(o){o(r)})}return new(t||(t=Promise))(function(r,o){function a(h){try{c(i.next(h))}catch(d){o(d)}}function l(h){try{c(i.throw(h))}catch(d){o(d)}}function c(h){h.done?r(h.value):s(h.value).then(a,l)}c((i=i.apply(n,e||[])).next())})},iy=function(n,e){var t={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},i,s,r,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return l([c,h])}}function l(c){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,s&&(r=c[0]&2?s.return:c[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,c[1])).done)return r;switch(s=0,r&&(c=[c[0]&2,r.value]),c[0]){case 0:case 1:r=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,s=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(r=t.trys,!(r=r.length>0&&r[r.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!r||c[1]>r[0]&&c[1]<r[3])){t.label=c[1];break}if(c[0]===6&&t.label<r[1]){t.label=r[1],r=c;break}if(r&&t.label<r[2]){t.label=r[2],t.ops.push(c);break}r[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(n,t)}catch(h){c=[6,h],s=0}finally{i=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},ZP=function(){function n(e){this.connection=e}return n.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===ko.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===ko.Data){var i=this.connection,s={ordered:!!e.reliable},r=t.createDataChannel(i.label,s);i.initialize(r)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},n.prototype._startPeerConnection=function(){it.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},n.prototype._setupListeners=function(e){var t=this,i=this.connection.peer,s=this.connection.connectionId,r=this.connection.type,o=this.connection.provider;it.default.log("Listening for ICE candidates."),e.onicecandidate=function(a){!a.candidate||!a.candidate.candidate||(it.default.log("Received ICE candidates for ".concat(i,":"),a.candidate),o.socket.send({type:ts.Candidate,payload:{candidate:a.candidate,type:r,connectionId:s},dst:i}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":it.default.log("iceConnectionState is failed, closing connections to "+i),t.connection.emit("error",new Error("Negotiation of connection to "+i+" failed.")),t.connection.close();break;case"closed":it.default.log("iceConnectionState is closed, closing connections to "+i),t.connection.emit("error",new Error("Connection to "+i+" closed.")),t.connection.close();break;case"disconnected":it.default.log("iceConnectionState changed to disconnected on the connection with "+i);break;case"completed":e.onicecandidate=li.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},it.default.log("Listening for data channel"),e.ondatachannel=function(a){it.default.log("Received data channel");var l=a.channel,c=o.getConnection(i,s);c.initialize(l)},it.default.log("Listening for remote stream"),e.ontrack=function(a){it.default.log("Received remote stream");var l=a.streams[0],c=o.getConnection(i,s);if(c.type===ko.Media){var h=c;t._addStreamToMediaConnection(l,h)}}},n.prototype.cleanup=function(){it.default.log("Cleaning up PeerConnection to "+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!=="closed",i=!1;if(this.connection.type===ko.Data){var s=this.connection,r=s.dataChannel;r&&(i=!!r.readyState&&r.readyState!=="closed")}(t||i)&&e.close()}},n.prototype._makeOffer=function(){return ty(this,void 0,Promise,function(){var e,t,i,s,r,o,a;return iy(this,function(l){switch(l.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,l.label=1;case 1:return l.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:i=l.sent(),it.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(i.sdp=this.connection.options.sdpTransform(i.sdp)||i.sdp),l.label=3;case 3:return l.trys.push([3,5,,6]),[4,e.setLocalDescription(i)];case 4:return l.sent(),it.default.log("Set localDescription:",i,"for:".concat(this.connection.peer)),s={sdp:i,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:li.browser},this.connection.type===ko.Data&&(r=this.connection,s=H0(H0({},s),{label:r.label,reliable:r.reliable,serialization:r.serialization})),t.socket.send({type:ts.Offer,payload:s,dst:this.connection.peer}),[3,6];case 5:return o=l.sent(),o!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(t.emitError(nn.WebRTC,o),it.default.log("Failed to setLocalDescription, ",o)),[3,6];case 6:return[3,8];case 7:return a=l.sent(),t.emitError(nn.WebRTC,a),it.default.log("Failed to createOffer, ",a),[3,8];case 8:return[2]}})})},n.prototype._makeAnswer=function(){return ty(this,void 0,Promise,function(){var e,t,i,s,r;return iy(this,function(o){switch(o.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,o.label=1;case 1:return o.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:i=o.sent(),it.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(i.sdp=this.connection.options.sdpTransform(i.sdp)||i.sdp),o.label=3;case 3:return o.trys.push([3,5,,6]),[4,e.setLocalDescription(i)];case 4:return o.sent(),it.default.log("Set localDescription:",i,"for:".concat(this.connection.peer)),t.socket.send({type:ts.Answer,payload:{sdp:i,type:this.connection.type,connectionId:this.connection.connectionId,browser:li.browser},dst:this.connection.peer}),[3,6];case 5:return s=o.sent(),t.emitError(nn.WebRTC,s),it.default.log("Failed to setLocalDescription, ",s),[3,6];case 6:return[3,8];case 7:return r=o.sent(),t.emitError(nn.WebRTC,r),it.default.log("Failed to create answer, ",r),[3,8];case 8:return[2]}})})},n.prototype.handleSDP=function(e,t){return ty(this,void 0,Promise,function(){var i,s,r,o;return iy(this,function(a){switch(a.label){case 0:t=new RTCSessionDescription(t),i=this.connection.peerConnection,s=this.connection.provider,it.default.log("Setting remote description",t),r=this,a.label=1;case 1:return a.trys.push([1,5,,6]),[4,i.setRemoteDescription(t)];case 2:return a.sent(),it.default.log("Set remoteDescription:".concat(e," for:").concat(this.connection.peer)),e!=="OFFER"?[3,4]:[4,r._makeAnswer()];case 3:a.sent(),a.label=4;case 4:return[3,6];case 5:return o=a.sent(),s.emitError(nn.WebRTC,o),it.default.log("Failed to setRemoteDescription, ",o),[3,6];case 6:return[2]}})})},n.prototype.handleCandidate=function(e){return ty(this,void 0,Promise,function(){var t,i,s,r,o,a;return iy(this,function(l){switch(l.label){case 0:it.default.log("handleCandidate:",e),t=e.candidate,i=e.sdpMLineIndex,s=e.sdpMid,r=this.connection.peerConnection,o=this.connection.provider,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,r.addIceCandidate(new RTCIceCandidate({sdpMid:s,sdpMLineIndex:i,candidate:t}))];case 2:return l.sent(),it.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return a=l.sent(),o.emitError(nn.WebRTC,a),it.default.log("Failed to handleCandidate, ",a),[3,4];case 4:return[2]}})})},n.prototype._addTracksToConnection=function(e,t){if(it.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return it.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(i){t.addTrack(i,e)})},n.prototype._addStreamToMediaConnection=function(e,t){it.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},n}(),M1={};La(M1,"BaseConnection",()=>$P,n=>$P=n);var Dj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),$P=function(n){Dj(e,n);function e(t,i,s){var r=n.call(this)||this;return r.peer=t,r.provider=i,r.options=s,r._open=!1,r.metadata=s.metadata,r}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e}(uA.EventEmitter),kj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),V0=function(){return V0=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},V0.apply(this,arguments)},Oj=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},eR=function(n){kj(e,n);function e(t,i,s){var r=n.call(this,t,i,s)||this;return r._localStream=r.options._stream,r.connectionId=r.options.connectionId||e.ID_PREFIX+li.randomToken(),r._negotiator=new I1.Negotiator(r),r._localStream&&r._negotiator.startConnection({_stream:r._localStream,originator:!0}),r}return Object.defineProperty(e.prototype,"type",{get:function(){return ko.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){it.default.log("Receiving stream",t),this._remoteStream=t,n.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var i=t.type,s=t.payload;switch(t.type){case ts.Answer:this._negotiator.handleSDP(i,s.sdp),this._open=!0;break;case ts.Candidate:this._negotiator.handleCandidate(s.candidate);break;default:it.default.warn("Unrecognized message type:".concat(i," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,i){var s,r;if(i===void 0&&(i={}),this._localStream){it.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,i&&i.sdpTransform&&(this.options.sdpTransform=i.sdpTransform),this._negotiator.startConnection(V0(V0({},this.options._payload),{_stream:t}));var o=this.provider._getMessages(this.connectionId);try{for(var a=Oj(o),l=a.next();!l.done;l=a.next()){var c=l.value;this.handleMessage(c)}}catch(h){s={error:h}}finally{try{l&&!l.done&&(r=a.return)&&r.call(a)}finally{if(s)throw s.error}}this._open=!0},e.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,n.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e}(M1.BaseConnection),MS={};La(MS,"DataConnection",()=>iR,n=>iR=n);var hL={};La(hL,"EncodingQueue",()=>tR,n=>tR=n);var Lj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),tR=function(n){Lj(e,n);function e(){var t=n.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(i){t._processing=!1,i.target&&t.emit("done",i.target.result),t.doNextTask()},t.fileReader.onerror=function(i){it.default.error("EncodingQueue error:",i),t._processing=!1,t.destroy(),t.emit("error",i)},t}return Object.defineProperty(e.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),e.prototype.enque=function(t){this.queue.push(t),!this.processing&&this.doNextTask()},e.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},e.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},e}(uA.EventEmitter),Fj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),Uj=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},iR=function(n){Fj(e,n);function e(t,i,s){var r=n.call(this,t,i,s)||this;return r.stringify=JSON.stringify,r.parse=JSON.parse,r._buffer=[],r._bufferSize=0,r._buffering=!1,r._chunkedData={},r._encodingQueue=new hL.EncodingQueue,r.connectionId=r.options.connectionId||e.ID_PREFIX+li.randomToken(),r.label=r.options.label||r.connectionId,r.serialization=r.options.serialization||ol.Binary,r.reliable=!!r.options.reliable,r._encodingQueue.on("done",function(o){r._bufferedSend(o)}),r._encodingQueue.on("error",function(){it.default.error("DC#".concat(r.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),r.close()}),r._negotiator=new I1.Negotiator(r),r._negotiator.startConnection(r.options._payload||{originator:!0}),r}return Object.defineProperty(e.prototype,"type",{get:function(){return ko.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;(!li.supports.binaryBlob||li.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){it.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(i){it.default.log("DC#".concat(t.connectionId," dc onmessage:"),i.data),t._handleDataMessage(i)},this.dataChannel.onclose=function(){it.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var i=this,s=t.data,r=s.constructor,o=this.serialization===ol.Binary||this.serialization===ol.BinaryUTF8,a=s;if(o){if(r===Blob){li.blobToArrayBuffer(s,function(c){var h=li.unpack(c);i.emit("data",h)});return}else if(r===ArrayBuffer)a=li.unpack(s);else if(r===String){var l=li.binaryStringToArrayBuffer(s);a=li.unpack(l)}}else this.serialization===ol.JSON&&(a=this.parse(s));if(a.__peerData){this._handleChunk(a);return}n.prototype.emit.call(this,"data",a)},e.prototype._handleChunk=function(t){var i=t.__peerData,s=this._chunkedData[i]||{data:[],count:0,total:t.total};if(s.data[t.n]=t.data,s.count++,this._chunkedData[i]=s,s.total===s.count){delete this._chunkedData[i];var r=new Blob(s.data);this._handleDataMessage({data:r})}},e.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),this._encodingQueue=null),this.open&&(this._open=!1,n.prototype.emit.call(this,"close"))},e.prototype.send=function(t,i){if(!this.open){n.prototype.emit.call(this,"error",new Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===ol.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===ol.Binary||this.serialization===ol.BinaryUTF8){var s=li.pack(t);if(!i&&s.size>li.chunkedMTU){this._sendChunks(s);return}li.supports.binaryBlob?this._bufferedSend(s):this._encodingQueue.enque(s)}else this._bufferedSend(t)},e.prototype._bufferedSend=function(t){(this._buffering||!this._trySend(t))&&(this._buffer.push(t),this._bufferSize=this._buffer.length)},e.prototype._trySend=function(t){var i=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){i._buffering=!1,i._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(s){return it.default.error("DC#:".concat(this.connectionId," Error when sending:"),s),this._buffering=!0,this.close(),!1}return!0},e.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},e.prototype._sendChunks=function(t){var i,s,r=li.chunk(t);it.default.log("DC#".concat(this.connectionId," Try to send ").concat(r.length," chunks..."));try{for(var o=Uj(r),a=o.next();!a.done;a=o.next()){var l=a.value;this.send(l,!0)}}catch(c){i={error:c}}finally{try{a&&!a.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}},e.prototype.handleMessage=function(t){var i=t.payload;switch(t.type){case ts.Answer:this._negotiator.handleSDP(t.type,i.sdp);break;case ts.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:it.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e}(M1.BaseConnection),uL={};La(uL,"API",()=>rR,n=>rR=n);var nR=function(n,e,t,i){function s(r){return r instanceof t?r:new t(function(o){o(r)})}return new(t||(t=Promise))(function(r,o){function a(h){try{c(i.next(h))}catch(d){o(d)}}function l(h){try{c(i.throw(h))}catch(d){o(d)}}function c(h){h.done?r(h.value):s(h.value).then(a,l)}c((i=i.apply(n,e||[])).next())})},sR=function(n,e){var t={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},i,s,r,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return l([c,h])}}function l(c){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,s&&(r=c[0]&2?s.return:c[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,c[1])).done)return r;switch(s=0,r&&(c=[c[0]&2,r.value]),c[0]){case 0:case 1:r=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,s=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(r=t.trys,!(r=r.length>0&&r[r.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!r||c[1]>r[0]&&c[1]<r[3])){t.label=c[1];break}if(c[0]===6&&t.label<r[1]){t.label=r[1],r=c;break}if(r&&t.label<r[2]){t.label=r[2],t.ops.push(c);break}r[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(n,t)}catch(h){c=[6,h],s=0}finally{i=r=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},rR=function(){function n(e){this._options=e}return n.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",i=this._options,s=i.host,r=i.port,o=i.path,a=i.key,l=new URL("".concat(t,"://").concat(s,":").concat(r).concat(o).concat(a,"/").concat(e));return l.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),l.searchParams.set("version",E1.version),fetch(l.href,{referrerPolicy:this._options.referrerPolicy})},n.prototype.retrieveId=function(){return nR(this,void 0,Promise,function(){var e,t,i;return sR(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=s.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=s.sent(),it.default.error("Error retrieving ID",t),i="",this._options.path==="/"&&this._options.host!==li.CLOUD_HOST&&(i=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+i);case 3:return[2]}})})},n.prototype.listAllPeers=function(){return nR(this,void 0,Promise,function(){var e,t,i;return sR(this,function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=s.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===li.CLOUD_HOST?t="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":t="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+t)):new Error("Error. Status:".concat(e.status));return[2,e.json()];case 2:throw i=s.sent(),it.default.error("Error retrieving list peers",i),new Error("Could not get list peers from the server."+i);case 3:return[2]}})})},n}(),Nj=function(){var n=function(e,t){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,s){i.__proto__=s}||function(i,s){for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(i[r]=s[r])},n(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");n(e,t);function i(){this.constructor=e}e.prototype=t===null?Object.create(t):(i.prototype=t.prototype,new i)}}(),Pg=function(){return Pg=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},Pg.apply(this,arguments)},Hp=function(n){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&n[e],i=0;if(t)return t.call(n);if(n&&typeof n.length=="number")return{next:function(){return n&&i>=n.length&&(n=void 0),{value:n&&n[i++],done:!n}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},zj=function(n,e){var t=typeof Symbol=="function"&&n[Symbol.iterator];if(!t)return n;var i=t.call(n),s,r=[],o;try{for(;(e===void 0||e-- >0)&&!(s=i.next()).done;)r.push(s.value)}catch(a){o={error:a}}finally{try{s&&!s.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return r},oR=function(n){Nj(e,n);function e(t,i){var s=n.call(this)||this;s._id=null,s._lastServerId=null,s._destroyed=!1,s._disconnected=!1,s._open=!1,s._connections=new Map,s._lostMessages=new Map;var r;return t&&t.constructor==Object?i=t:t&&(r=t.toString()),i=Pg({debug:0,host:li.CLOUD_HOST,port:li.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:li.randomToken(),config:li.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},i),s._options=i,s._options.host==="/"&&(s._options.host=window.location.hostname),s._options.path&&(s._options.path[0]!=="/"&&(s._options.path="/"+s._options.path),s._options.path[s._options.path.length-1]!=="/"&&(s._options.path+="/")),s._options.secure===void 0&&s._options.host!==li.CLOUD_HOST?s._options.secure=li.isSecure():s._options.host==li.CLOUD_HOST&&(s._options.secure=!0),s._options.logFunction&&it.default.setLogFunction(s._options.logFunction),it.default.logLevel=s._options.debug||0,s._api=new uL.API(i),s._socket=s._createServerConnection(),!li.supports.audioVideo&&!li.supports.data?(s._delayedAbort(nn.BrowserIncompatible,"The current browser does not support WebRTC"),s):r&&!li.validateId(r)?(s._delayedAbort(nn.InvalidID,'ID "'.concat(r,'" is invalid')),s):(r?s._initialize(r):s._api.retrieveId().then(function(o){return s._initialize(o)}).catch(function(o){return s._abort(nn.ServerError,o)}),s)}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){var t,i,s=Object.create(null);try{for(var r=Hp(this._connections),o=r.next();!o.done;o=r.next()){var a=zj(o.value,2),l=a[0],c=a[1];s[l]=c}}catch(h){t={error:h}}finally{try{o&&!o.done&&(i=r.return)&&i.call(r)}finally{if(t)throw t.error}}return s},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),e.prototype._createServerConnection=function(){var t=this,i=new cL.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return i.on(Cl.Message,function(s){t._handleMessage(s)}),i.on(Cl.Error,function(s){t._abort(nn.SocketError,s)}),i.on(Cl.Disconnected,function(){t.disconnected||(t.emitError(nn.Network,"Lost connection to server."),t.disconnect())}),i.on(Cl.Close,function(){t.disconnected||t._abort(nn.SocketClosed,"Underlying socket is already closed.")}),i},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var i,s,r=t.type,o=t.payload,a=t.src;switch(r){case ts.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case ts.Error:this._abort(nn.ServerError,o.msg);break;case ts.IdTaken:this._abort(nn.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case ts.InvalidKey:this._abort(nn.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case ts.Leave:it.default.log("Received leave message from ".concat(a)),this._cleanupPeer(a),this._connections.delete(a);break;case ts.Expire:this.emitError(nn.PeerUnavailable,"Could not connect to peer ".concat(a));break;case ts.Offer:var g=o.connectionId,m=this.getConnection(a,g);if(m&&(m.close(),it.default.warn("Offer received for existing Connection ID:".concat(g))),o.type===ko.Media){var l=new IS.MediaConnection(a,this,{connectionId:g,_payload:o,metadata:o.metadata});m=l,this._addConnection(a,m),this.emit("call",l)}else if(o.type===ko.Data){var c=new MS.DataConnection(a,this,{connectionId:g,_payload:o,metadata:o.metadata,label:o.label,serialization:o.serialization,reliable:o.reliable});m=c,this._addConnection(a,m),this.emit("connection",c)}else{it.default.warn("Received malformed connection type:".concat(o.type));return}var h=this._getMessages(g);try{for(var d=Hp(h),f=d.next();!f.done;f=d.next()){var p=f.value;m.handleMessage(p)}}catch(A){i={error:A}}finally{try{f&&!f.done&&(s=d.return)&&s.call(d)}finally{if(i)throw i.error}}break;default:if(!o){it.default.warn("You received a malformed message from ".concat(a," of type ").concat(r));return}var g=o.connectionId,m=this.getConnection(a,g);m&&m.peerConnection?m.handleMessage(t):g?this._storeMessage(g,t):it.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,i){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(i)},e.prototype._getMessages=function(t){var i=this._lostMessages.get(t);return i?(this._lostMessages.delete(t),i):[]},e.prototype.connect=function(t,i){if(i===void 0&&(i={}),this.disconnected){it.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(nn.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var s=new MS.DataConnection(t,this,i);return this._addConnection(t,s),s},e.prototype.call=function(t,i,s){if(s===void 0&&(s={}),this.disconnected){it.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(nn.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!i){it.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var r=new IS.MediaConnection(t,this,Pg(Pg({},s),{_stream:i}));return this._addConnection(t,r),r},e.prototype._addConnection=function(t,i){it.default.log("add connection ".concat(i.type,":").concat(i.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(i)},e.prototype._removeConnection=function(t){var i=this._connections.get(t.peer);if(i){var s=i.indexOf(t);s!==-1&&i.splice(s,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,i){var s,r,o=this._connections.get(t);if(!o)return null;try{for(var a=Hp(o),l=a.next();!l.done;l=a.next()){var c=l.value;if(c.connectionId===i)return c}}catch(h){s={error:h}}finally{try{l&&!l.done&&(r=a.return)&&r.call(a)}finally{if(s)throw s.error}}return null},e.prototype._delayedAbort=function(t,i){var s=this;setTimeout(function(){s._abort(t,i)},0)},e.prototype._abort=function(t,i){it.default.error("Aborting!"),this.emitError(t,i),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,i){it.default.error("Error:",i);var s;typeof i=="string"?s=new Error(i):s=i,s.type=t,this.emit("error",s)},e.prototype.destroy=function(){this.destroyed||(it.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},e.prototype._cleanup=function(){var t,i;try{for(var s=Hp(this._connections.keys()),r=s.next();!r.done;r=s.next()){var o=r.value;this._cleanupPeer(o),this._connections.delete(o)}}catch(a){t={error:a}}finally{try{r&&!r.done&&(i=s.return)&&i.call(s)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var i,s,r=this._connections.get(t);if(r)try{for(var o=Hp(r),a=o.next();!a.done;a=o.next()){var l=a.value;l.close()}}catch(c){i={error:c}}finally{try{a&&!a.done&&(s=o.return)&&s.call(o)}finally{if(i)throw i.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;it.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)it.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)it.default.error("In a hurry? We're still trying to make the initial connection!");else throw new Error("Peer ".concat(this.id," cannot reconnect because it is not disconnected from the server!"))}},e.prototype.listAllPeers=function(t){var i=this;t===void 0&&(t=function(s){}),this._api.listAllPeers().then(function(s){return t(s)}).catch(function(s){return i._abort(nn.ServerError,s)})},e.DEFAULT_KEY="peerjs",e}(uA.EventEmitter),j0=aL.Peer;class Gj{constructor(){u(this,"_host");u(this,"_client");u(this,"_clientData");this.onEnable()}get isHost(){return this._host!==void 0}onEnable(){const e="HOST-5980e65c-8438-453e-8b35-f13c736dcd81";this.trySetupHost(e)}trySetupHost(e){let t=new j0(e);t.on("error",i=>{console.error(i),this._host=void 0,this.trySetupClient(e)}),t.on("open",i=>{this._host=new Hj(t)})}trySetupClient(e){this._client=new j0,this._client.on("error",t=>{console.error("Client error",t)}),this._client.on("open",t=>{console.log("client connected",t),this._clientData=this._client.connect(e,{metadata:{id:t}}),this._clientData.on("open",()=>{console.log("Connected to host")}),this._clientData.on("data",i=>{console.log("<<",i)})})}}class Qj{constructor(e){u(this,"_peer");this._peer=e}}class Hj extends Qj{constructor(t){var i;super(t);u(this,"_connections",[]);console.log("I AM THE HOST"),(i=this._peer)==null||i.on("connection",this.onConnection.bind(this)),this._peer.on("close",()=>{this.broadcast("BYE")}),setInterval(()=>{this.broadcast("HELLO")},2e3)}get isHost(){return!0}onConnection(t){console.log("host connection",t),t.on("open",()=>{this._connections.push(t),this.broadcastConnection(t)})}broadcastConnection(t){const i=this._connections.map(s=>{var r;return(r=s.metadata)==null?void 0:r.id}).filter(s=>s!==void 0);this.broadcast({type:"connection-list",connections:i})}broadcast(t){if(t!=null){console.log(">>",t);for(const i in this._peer.connections){const s=this._peer.connections[i];if(s)if(Array.isArray(s))for(const r of s)r&&r.send(t);else console.warn(s)}}}}var tr=(n=>(n[n.OnConnection=0]="OnConnection",n[n.OnRoomJoin=1]="OnRoomJoin",n[n.Queued=2]="Queued",n[n.Immediate=3]="Immediate",n))(tr||{});const aR="https://urls.needle.tools/default-networking-backend/index";let hc="wss://needle-tiny-starter.glitch.me/socket";const Ps=!!le("debugnet"),pg=!!(Ps||le("debugowner"));var dL=(n=>(n.ConnectionInfo="connection-start-info",n))(dL||{}),Ji=(n=>(n.Join="join-room",n.Leave="leave-room",n.JoinedRoom="joined-room",n.LeftRoom="left-room",n.UserJoinedRoom="user-joined-room",n.UserLeftRoom="user-left-room",n))(Ji||{});class Vj{constructor(){u(this,"room");u(this,"viewId");u(this,"allowEditing");u(this,"inRoom")}}class jj{constructor(){u(this,"room")}}class Wj{constructor(){u(this,"userId")}}var fL=(n=>(n.RequestHasOwner="request-has-owner",n.ResponseHasOwner="response-has-owner",n.RequestIsOwner="request-is-owner",n.ResponseIsOwner="response-is-owner",n.RequestOwnership="request-ownership",n.GainedOwnership="gained-ownership",n.RemoveOwnership="remove-ownership",n.LostOwnership="lost-ownership",n.GainedOwnershipBroadcast="gained-ownership-broadcast",n.LostOwnershipBroadcast="lost-ownership-broadcast",n))(fL||{});class db{constructor(e,t){u(this,"guid");u(this,"connection");u(this,"_hasOwnership",!1);u(this,"_isOwned");u(this,"_gainSubscription");u(this,"_lostSubscription");u(this,"_hasOwnerResponse");u(this,"_isWaitingForOwnershipResponseCallback",null);this.connection=e,this.guid=t,this._gainSubscription=this.onGainedOwnership.bind(this),this._lostSubscription=this.onLostOwnership.bind(this),e.beginListen("lost-ownership",this._lostSubscription),e.beginListen("gained-ownership-broadcast",this._gainSubscription),this._hasOwnerResponse=this.onHasOwnerResponse.bind(this),e.beginListen("response-has-owner",this._hasOwnerResponse)}get hasOwnership(){return this._hasOwnership}get isOwned(){return this._isOwned}get isConnected(){return this.connection.isConnected}updateIsOwned(){this.connection.send("request-has-owner",{guid:this.guid})}onHasOwnerResponse(e){e.guid===this.guid&&(this._isOwned=e.value)}requestOwnershipIfNotOwned(){return this._isWaitingForOwnershipResponseCallback!==null?this:(this._isWaitingForOwnershipResponseCallback=this.waitForHasOwnershipRequestResponse.bind(this),this.connection.beginListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this.connection.send("request-has-owner",{guid:this.guid}),this)}waitForHasOwnershipRequestResponse(e){e.guid===this.guid&&(this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this._isOwned=e.value,e.value||(pg&&console.log("request ownership",this.guid),this.requestOwnership()))}requestOwnershipAsync(){return new Promise((e,t)=>{this.requestOwnership();let i=0;const s=()=>{if(i++>10)return t("Timeout");setTimeout(()=>{this.hasOwnership?e(this):s()},100)};s()})}requestOwnership(){return pg&&console.log("Request ownership",this.guid),this.connection.send("request-ownership",{guid:this.guid}),this}freeOwnership(){return this.connection.send("remove-ownership",{guid:this.guid}),this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this}destroy(){this.connection.stopListen("gained-ownership",this._gainSubscription),this.connection.stopListen("lost-ownership",this._lostSubscription),this.connection.stopListen("response-has-owner",this._hasOwnerResponse),this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null)}onGainedOwnership(e){e.guid===this.guid&&(this._isOwned=!0,this.connection.connectionId===e.owner?(pg&&console.log("GAINED OWNERSHIP",this.guid),this._hasOwnership=!0):this._hasOwnership=!1)}onLostOwnership(e){e===this.guid&&(pg&&console.log("LOST OWNERSHIP",this.guid),this._hasOwnership=!1,this._isOwned=!1)}}class pL{constructor(e){u(this,"context");u(this,"_peer",null);u(this,"_usersInRoomCopy",[]);u(this,"_defaultMessagesBuffer",[]);u(this,"_defaultMessagesBufferArray",[]);u(this,"netWebSocketUrlProvider");u(this,"_listeners",{});u(this,"_listenersBinary",{});u(this,"connected",!1);u(this,"channelId");u(this,"_connectionId",null);u(this,"_ws");u(this,"_waitingForSocket",{});u(this,"_isInRoom",!1);u(this,"_currentRoomName",null);u(this,"_currentRoomViewId",null);u(this,"_currentRoomAllowEditing",!0);u(this,"_currentInRoom",[]);u(this,"_state",{});u(this,"_currentDelay",-1);u(this,"_connectingToWebsocketPromise",null);this.context=e}get peer(){return this._peer||(this._peer=new Gj),this._peer}tryGetState(e){return e==="invalid"?null:this._state[e]}get connectionId(){return this._connectionId}get isDebugEnabled(){return Ps}get isConnected(){return this.connected}get currentRoomName(){return this._currentRoomName}get allowEditing(){return this._currentRoomAllowEditing}get currentRoomViewId(){return this._currentRoomViewId}get isInRoom(){return this._isInRoom}get currentLatency(){return this._currentDelay}sendPing(){this.send("ping",{time:this.context.time.time})}userIsInRoom(e){return this._currentInRoom.indexOf(e)!==-1}usersInRoom(e=null){e||(e=this._usersInRoomCopy),e.length=0;for(const t of this._currentInRoom)e.push(t);return e}joinRoom(e,t=!1){this.connect(),Ps&&console.log("join: "+e),this.send("join-room",{room:e,viewOnly:t},tr.OnConnection)}leaveRoom(e=null){if(e||(e=this.currentRoomName),!e){console.error("Can not leave unknown room");return}this.send("leave-room",{room:e})}send(e,t=null,i=tr.Queued){if(t===null&&(t={}),i===tr.Queued){this._defaultMessagesBuffer.push({key:e,value:t});return}return this.sendWithWebsocket(e,t,i)}sendDeleteRemoteState(e){this.send("delete-state",{guid:e,dontSave:!0}),delete this._state[e]}sendDeleteRemoteStateAll(){this.send("delete-all-state"),this._state={}}sendBinary(e){var t;Ps&&console.log("<< bin",e.length),(t=this._ws)==null||t.send(e)}sendBufferedMessagesNow(){var i;if(!this._ws)return;this._defaultMessagesBufferArray.length=0;const e=Object.keys(this._defaultMessagesBuffer).length;for(const s in this._defaultMessagesBuffer){const r=this._defaultMessagesBuffer[s];if(e<=1){this.sendWithWebsocket(r.key,r.value,tr.Immediate);break}const o=this.toMessage(r.key,r.value);this._defaultMessagesBufferArray.push(o)}if(this._defaultMessagesBuffer.length=0,this._defaultMessagesBufferArray.length>0&&Ps&&console.log("SEND BUFFERED",this._defaultMessagesBufferArray.length),this._defaultMessagesBufferArray.length<=0)return;const t=JSON.stringify(this._defaultMessagesBufferArray);(i=this._ws)==null||i.send(t)}beginListen(e,t){return this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t),t}stopListening(e,t){return this.stopListen(e,t)}stopListen(e,t){if(!t||!this._listeners[e])return;const i=this._listeners[e].indexOf(t);i>=0&&this._listeners[e].splice(i,1)}beginListenBinary(e,t){return this._listenersBinary[e]||(this._listenersBinary[e]=[]),this._listenersBinary[e].push(t),t}stopListenBinary(e,t){if(!this._listenersBinary[e])return;const i=this._listenersBinary[e].indexOf(t);i>=0&&this._listenersBinary[e].splice(i,1)}registerProvider(e){this.netWebSocketUrlProvider=e}async connect(){var t;if(this.connected)return Promise.resolve(!0);Ps&&console.log("connecting");const e=(t=this.netWebSocketUrlProvider)==null?void 0:t.getWebsocketUrl();return e?hc=e:ck()&&(hc="wss://"+window.location.host+"/socket"),this.connectWebsocket()}disconnect(){var e;(e=this._ws)==null||e.close(),this._ws=void 0}connectWebsocket(){return this._connectingToWebsocketPromise?this._connectingToWebsocketPromise:this._connectingToWebsocketPromise=new Promise(async(e,t)=>{let i=!1;const s=o=>{i||(i=!0,e(o))};if(hc===void 0&&(console.log("Fetch default backend url: "+aR),hc=await(await fetch(aR)).text()),hc===void 0){s(!1);return}console.log(`⊡ Connecting to networking backend on
|
|
3334
3334
|
`+hc);const r=new yO.WebsocketBuilder(hc).onOpen(()=>{this._connectingToWebsocketPromise=null,this._ws=r,this.connected=!0,console.log(`⊞ Connected to networking backend
|
|
3335
3335
|
`+hc),s(!0),this.onSendQueued(tr.OnConnection)}).onClose(o=>{this._connectingToWebsocketPromise=null,this.connected=!1,this._isInRoom=!1,s(!1)}).onError((o,a)=>{console.error("⊠ Websocket error",o,a),s(!1)}).onMessage(this.onMessage.bind(this)).onRetry(()=>{console.log("Retry connecting to networking websocket")}).build()})}onMessage(e,t){const i=t.data;try{if(typeof i!="string"){i.size&&this.handleIncomingBinaryMessage(i);return}const s=JSON.parse(i);if(Array.isArray(s))for(const r of s)this.handleIncomingStringMessage(r);else this.handleIncomingStringMessage(s);return}catch{Ps&&i==="pong"&&console.log("<<",i)}}async handleIncomingBinaryMessage(e){const t=await e.arrayBuffer();var i=new Uint8Array(t);const s=new gm(i),r=s.getBufferIdentifier(),o=this._listenersBinary[r],a=rj(s),l=oj(a);if(l&&typeof l=="string"&&(this._state[l]=a),!o)return;const c=a??s;for(const h of o)h(c)}handleIncomingStringMessage(e){var s,r;if(Ps&&console.log("<<",e.key??e),e.key)switch(e.key){case"connection-start-info":if(e.data){const l=e.data;l&&(console.assert(l.id!==void 0&&l.id!==null&&l.id.length>0,"server did not send connection id",l.id),console.log("Your id is: "+l.id,this.context.alias??""),this._connectionId=l.id)}else console.warn("Expected connection id in "+e.key);break;case"joined-room":if(Ps&&console.log(e),e){this._isInRoom=!0;const l=e;this._currentRoomName=l.room,this._currentRoomViewId=l.viewId,this._currentRoomAllowEditing=l.allowEditing??!0,console.log("Room view id",this._currentRoomViewId),this._currentInRoom.length=0,this._currentInRoom.push(...l.inRoom),Ps&&console.log("joined room with",this._currentInRoom,this.context.alias??"")}this.onSendQueued(tr.OnRoomJoin);break;case"left-room":e.room===this.currentRoomName&&(this._isInRoom=!1,this._currentRoomName=null,this._currentInRoom.length=0);break;case"user-joined-room":if(e.data){const l=e.data;this._currentInRoom.push(l.userId),Ps&&console.log(l.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(e.data){const l=e.data,c=this._currentInRoom.indexOf(l.userId);c>=0&&(console.log(l.userId+" left",this.context.alias??""),this._currentInRoom.splice(c,1)),l.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":Ps&&console.log("RECEIVED all-room-state-deleted"),this._state={};break;case"ping":case"pong":const a=(s=e.data)==null?void 0:s.time;a&&(this._currentDelay=this.context.time.time-a),Ps&&console.log("Current latency: "+this._currentDelay.toFixed(1)+" sec","Clients in room: "+((r=this._currentInRoom)==null?void 0:r.length));break}const t=this._listeners[e.key];if(t)for(const o of t)o(e.data);const i=e.data;i&&(this._state[i.guid]=i)}toMessage(e,t){return{key:e,data:t}}sendWithWebsocket(e,t,i=tr.OnRoomJoin){if(!this._ws){const r=this._waitingForSocket[i]||[];r.push(()=>this.sendWithWebsocket(e,t,i)),this._waitingForSocket[i]=r;return}const s=JSON.stringify(this.toMessage(e,t));Ps&&console.log(">>",e),this._ws.send(s)}onSendQueued(e){const t=this._waitingForSocket[e];if(t){for(const i of t)i();t.length=0}}}function ef(n,e){try{e?n(e):n()}catch(t){return console.error(t),!1}return!0}(0,eval)(`
|
|
3336
|
-
if(!globalThis[""
|
|
3337
|
-
globalThis[""
|
|
3336
|
+
if(!globalThis["NEEDLE_ENGINE_VERSION"])
|
|
3337
|
+
globalThis["NEEDLE_ENGINE_VERSION"] = "0.0.0";
|
|
3338
3338
|
if(!globalThis[""undefined""])
|
|
3339
3339
|
globalThis[""undefined""] = "unknown";
|
|
3340
|
-
`);const gL="null",qj="undefined",Ml="needle_isActiveInHierarchy",Qh="builtin_components",Rg="needle_editor_guid",Xj=/^(?:[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 Yj(n){return typeof n=="string"&&Xj.test(n)}const $n=[];for(let n=0;n<256;++n)$n.push((n+256).toString(16).slice(1));function Jj(n,e=0){return($n[n[e+0]]+$n[n[e+1]]+$n[n[e+2]]+$n[n[e+3]]+"-"+$n[n[e+4]]+$n[n[e+5]]+"-"+$n[n[e+6]]+$n[n[e+7]]+"-"+$n[n[e+8]]+$n[n[e+9]]+"-"+$n[n[e+10]]+$n[n[e+11]]+$n[n[e+12]]+$n[n[e+13]]+$n[n[e+14]]+$n[n[e+15]]).toLowerCase()}function Kj(n){if(!Yj(n))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function Zj(n){n=unescape(encodeURIComponent(n));const e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}const $j="6ba7b810-9dad-11d1-80b4-00c04fd430c8",eW="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function tW(n,e,t){function i(s,r,o,a){var l;if(typeof s=="string"&&(s=Zj(s)),typeof r=="string"&&(r=Kj(r)),((l=r)===null||l===void 0?void 0:l.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+s.length);if(c.set(r),c.set(s,r.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,o){a=a||0;for(let h=0;h<16;++h)o[a+h]=c[h];return o}return Jj(c)}try{i.name=n}catch{}return i.DNS=$j,i.URL=eW,i}function iW(n,e,t,i){switch(n){case 0:return e&t^~e&i;case 1:return e^t^i;case 2:return e&t^e&i^t&i;case 3:return e^t^i}}function mw(n,e){return n<<e|n>>>32-e}function nW(n){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof n=="string"){const o=unescape(encodeURIComponent(n));n=[];for(let a=0;a<o.length;++a)n.push(o.charCodeAt(a))}else Array.isArray(n)||(n=Array.prototype.slice.call(n));n.push(128);const i=n.length/4+2,s=Math.ceil(i/16),r=new Array(s);for(let o=0;o<s;++o){const a=new Uint32Array(16);for(let l=0;l<16;++l)a[l]=n[o*64+l*4]<<24|n[o*64+l*4+1]<<16|n[o*64+l*4+2]<<8|n[o*64+l*4+3];r[o]=a}r[s-1][14]=(n.length-1)*8/Math.pow(2,32),r[s-1][14]=Math.floor(r[s-1][14]),r[s-1][15]=(n.length-1)*8&4294967295;for(let o=0;o<s;++o){const a=new Uint32Array(80);for(let p=0;p<16;++p)a[p]=r[o][p];for(let p=16;p<80;++p)a[p]=mw(a[p-3]^a[p-8]^a[p-14]^a[p-16],1);let l=t[0],c=t[1],h=t[2],d=t[3],f=t[4];for(let p=0;p<80;++p){const g=Math.floor(p/20),m=mw(l,5)+iW(g,c,h,d)+f+e[g]+a[p]>>>0;f=d,d=h,h=mw(c,30)>>>0,c=l,l=m}t[0]=t[0]+l>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+h>>>0,t[3]=t[3]+d>>>0,t[4]=t[4]+f>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const sW=tW("v5",80,nW),lR=sW;sn.registerCallback(to.ContextCreated,n=>{const e=n.context;_L(e),yL(e)});const W0=le("debugcomponents"),cR="eff8ba80-635d-11ec-90d6-0242ac120003";class Us{constructor(e){u(this,"_originalSeed");u(this,"_seed");typeof e=="string"&&(e=Us.hash(e)),this._originalSeed=e,this._seed=e}get seed(){return this._seed}set seed(e){this._seed=e}reset(){this._seed=this._originalSeed}generateUUID(e){if(typeof e=="string")return lR(e,cR);const t=this._seed;return this._seed-=1,lR(t.toString(),cR)}initialize(e){typeof e=="string"?this._seed=Us.hash(e):this._seed=e}static createFromString(e){return new Us(this.hash(e))}static hash(e){let t=0;for(let i=0;i<e.length;i++)t=e.charCodeAt(i)+((t<<5)-t);return t}}var mL=(n=>(n.NewInstanceCreated="new-instance-created",n.InstanceDestroyed="instance-destroyed",n))(mL||{});class AL{constructor(e){u(this,"guid");this.guid=e}}function fb(n,e,t=!0){if(!n)return;const i=n;if(kl(n,t),!e){console.warn("Can not send destroy: No networking connection provided",n.guid);return}if(!e.isConnected){console.warn("Can not send destroy: not connected",n.guid);return}let s=n.guid;if(!s&&i.uuid&&(s=i.uuid),!s){console.warn("Can not send destroy: failed to find guid",n);return}const r=new AL(s);e.send("instance-destroyed",r,tr.Queued)}function vL(n,e){const t=new AL(n);e.send("instance-destroyed",t,tr.Queued)}function yL(n){n.connection.beginListen("instance-destroyed",e=>{W0&&console.log("[Remote] Destroyed",n.scene,e);const t=mA(e.guid,n.scene);t&&kl(t)})}class rW{constructor(e,t,i){u(this,"filename");u(this,"hash");u(this,"size");this.filename=e,this.hash=t,this.size=i}}class oW{constructor(e,t){u(this,"guid");u(this,"originalGuid");u(this,"seed");u(this,"visible");u(this,"hostData");u(this,"dontSave");u(this,"parent");u(this,"position");u(this,"rotation");u(this,"scale");this.originalGuid=e,this.guid=t}}function T1(n,e,t,i){var l;const s=n;if(!s.guid)return console.warn("Can not instantiate: No guid",s),null;if(e.context||(e.context=_t.Current),!e.context)return console.error("Missing network instantiate options / reference to network connection in sync instantiate"),null;const r=e?{...e}:null,{instance:o,seed:a}=aW(s,e);if(o){const c=o;if(c.guid){W0&&console.log("[Local] new instance","gameobject:",o==null?void 0:o.guid);const h=new oW(s.guid,c.guid);h.seed=a,r&&(r.position&&(h.position={x:r.position.x,y:r.position.y,z:r.position.z}),r.rotation&&(h.rotation={x:r.rotation.x,y:r.rotation.y,z:r.rotation.z,w:r.rotation.w}),r.scale&&(h.scale={x:r.scale.x,y:r.scale.y,z:r.scale.z})),h.position||(h.position={x:c.position.x,y:c.position.y,z:c.position.z}),h.rotation||(h.rotation={x:c.quaternion.x,y:c.quaternion.y,z:c.quaternion.z,w:c.quaternion.w}),h.scale||(h.scale={x:c.scale.x,y:c.scale.y,z:c.scale.z}),h.visible=s.visible,r!=null&&r.parent&&(typeof r.parent=="string"?h.parent=r.parent:h.parent=r.parent.guid),h.hostData=t,i===!1&&(h.dontSave=!0),(l=e==null?void 0:e.context)==null||l.connection.send("new-instance-created",h)}else console.warn("Missing guid, can not send new instance event",c)}return o}function pb(){return Math.random()*9999999}function _L(n){n.connection.beginListen("new-instance-created",async e=>{const t=await lW(e.originalGuid,n.scene);if(!t){console.warn("could not find object that was instantiated: "+e.guid);return}const i=new Pa;e.position&&(i.position=new S(e.position.x,e.position.y,e.position.z)),e.rotation&&(i.rotation=new xe(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w)),e.scale&&(i.scale=new S(e.scale.x,e.scale.y,e.scale.z)),i.parent=e.parent,e.seed&&(i.idProvider=new Us(e.seed)),i.visible=e.visible,i.context=n,W0&&n.alias&&console.log("[Remote] instantiate in: "+n.alias);const s=AA(t,i);s&&(e.parent==="scene"&&n.scene.add(s),W0&&console.log("[Remote] new instance","gameobject:",s==null?void 0:s.guid,t))})}function aW(n,e){const t=pb(),i=e??new Pa;i.idProvider=new Us(t);const s=AA(n,i);return{seed:t,instance:s}}const bL={};function xL(n,e){bL[n]=e}async function lW(n,e){const t=bL[n];if(t!=null){const i=await t(n);if(i)return i}return wL(n,e)}function wL(n,e){if(e===null||!n)return null;if(e.guid===n)return e;if(e.children)for(const t of e.children){const i=wL(n,t);if(i)return i}return null}const CL=new Map;function cW(n,e){if(!n)return;if(!e){console.warn("No prototype found",n,n.prototype,n.constructor);return}let t=CL.get(e);t&&t.apply(n)}function hW(n){const e=uW(n.prototype);CL.set(n,e)}function uW(n){return new dW(n)}class dW{constructor(e){u(this,"$symbol");u(this,"extensions");u(this,"descriptors");this.$symbol=Symbol("prototype-extension"),this.extensions=Object.keys(e),this.descriptors=new Array;for(let t=0;t<this.extensions.length;t++){const i=this.extensions[t],s=Object.getOwnPropertyDescriptor(e,i);s&&this.descriptors.push(s)}}apply(e){if(!e[this.$symbol]){e[this.$symbol]=!0;for(let t=0;t<this.extensions.length;t++){const i=this.extensions[t],s=this.descriptors[t];s&&Object.defineProperty(e,i,s)}}}}var dA=(n=>(n.Added="component-added",n.Removing="removing-component",n))(dA||{});const hR=le("debugcomponentevents");class fA{static addComponentLifecylceEventListener(e,t){this.eventListeners.has(e)&&this.eventListeners.set(e,[]);let i=this.eventListeners.get(e);i||(i=[]),i.push(t),this.eventListeners.set(e,i),hR&&console.log("Added event listener for "+e,this.eventListeners)}static removeComponentLifecylceEventListener(e,t){const i=this.eventListeners.get(e);if(!i)return;const s=i.indexOf(t);s<0||i.splice(s,1)}static dispatchComponentLifecycleEvent(e,t){const i=this.eventListeners.get(e);if(hR&&console.log("Dispatching event "+e,i),!!i)for(const s of i)s(t)}}u(fA,"eventListeners",new Map);const Aw=le("debuggetcomponent");function fW(n){return n==null||n.isObject3D?n:n.object&&n.object.isObject3D?n.object:n}function P1(n,e){if(!n||!n.userData.components)return;const t=n.userData.components.indexOf(e);t<0||(fA.dispatchComponentLifecycleEvent(dA.Removing,e),e.gameObject=null,n.userData.components.splice(t,1))}function gb(n,e){const t=Vf(n,e);if(t)return t;const i=new e;return Iu(n,i)}const SL=new Us("addComponentIdProvider");function Iu(n,e,t=!0){n.userData||(n.userData={}),n.userData.components||(n.userData.components=[]),n.userData.components.push(e),e.gameObject=n,(e.guid===void 0||e.guid==="invalid")&&(e.guid=SL.generateUUID()),Ab(n),xb(e);try{t&&e.__internalAwake&&(kg(n),e.__internalAwake()),fA.dispatchComponentLifecycleEvent(dA.Added,e)}catch(i){console.error(i)}return e}function R1(n,e){if(e.gameObject===n)return e;if(e.gameObject&&e.gameObject.userData.components){const t=e.gameObject.userData.components.indexOf(e);e.gameObject.userData.components.splice(t,1)}if(!n.userData.components)n.userData.components=[];else if(n.userData.components.includes(e))return e;return n.userData.components.push(e),e.gameObject=n,(e.guid===void 0||e.guid==="invalid")&&(e.guid=SL.generateUUID()),xb(e),e}function EL(n){if(n.gameObject&&n.gameObject.userData.components){const e=n.gameObject.userData.components.indexOf(n);n.gameObject.userData.components.splice(e,1)}n.__internalDisable&&n.__internalDisable(),n.onDestroy&&n.onDestroy(),ml(n,n.context??_t.Current),n.__internalDestroy(),n.gameObject=null}let uR=!1;function IL(n,e,t){var i;if(n!=null){if(!n.isObject3D){console.error("Object is not object3D");return}if(!((i=n==null?void 0:n.userData)!=null&&i.components))return null;if(typeof e=="string"&&(uR||(uR=!0,console.warn(`Accessing components by name is not supported.
|
|
3340
|
+
`);const gL=NEEDLE_ENGINE_VERSION,qj="undefined",Ml="needle_isActiveInHierarchy",Qh="builtin_components",Rg="needle_editor_guid",Xj=/^(?:[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 Yj(n){return typeof n=="string"&&Xj.test(n)}const $n=[];for(let n=0;n<256;++n)$n.push((n+256).toString(16).slice(1));function Jj(n,e=0){return($n[n[e+0]]+$n[n[e+1]]+$n[n[e+2]]+$n[n[e+3]]+"-"+$n[n[e+4]]+$n[n[e+5]]+"-"+$n[n[e+6]]+$n[n[e+7]]+"-"+$n[n[e+8]]+$n[n[e+9]]+"-"+$n[n[e+10]]+$n[n[e+11]]+$n[n[e+12]]+$n[n[e+13]]+$n[n[e+14]]+$n[n[e+15]]).toLowerCase()}function Kj(n){if(!Yj(n))throw TypeError("Invalid UUID");let e;const t=new Uint8Array(16);return t[0]=(e=parseInt(n.slice(0,8),16))>>>24,t[1]=e>>>16&255,t[2]=e>>>8&255,t[3]=e&255,t[4]=(e=parseInt(n.slice(9,13),16))>>>8,t[5]=e&255,t[6]=(e=parseInt(n.slice(14,18),16))>>>8,t[7]=e&255,t[8]=(e=parseInt(n.slice(19,23),16))>>>8,t[9]=e&255,t[10]=(e=parseInt(n.slice(24,36),16))/1099511627776&255,t[11]=e/4294967296&255,t[12]=e>>>24&255,t[13]=e>>>16&255,t[14]=e>>>8&255,t[15]=e&255,t}function Zj(n){n=unescape(encodeURIComponent(n));const e=[];for(let t=0;t<n.length;++t)e.push(n.charCodeAt(t));return e}const $j="6ba7b810-9dad-11d1-80b4-00c04fd430c8",eW="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function tW(n,e,t){function i(s,r,o,a){var l;if(typeof s=="string"&&(s=Zj(s)),typeof r=="string"&&(r=Kj(r)),((l=r)===null||l===void 0?void 0:l.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+s.length);if(c.set(r),c.set(s,r.length),c=t(c),c[6]=c[6]&15|e,c[8]=c[8]&63|128,o){a=a||0;for(let h=0;h<16;++h)o[a+h]=c[h];return o}return Jj(c)}try{i.name=n}catch{}return i.DNS=$j,i.URL=eW,i}function iW(n,e,t,i){switch(n){case 0:return e&t^~e&i;case 1:return e^t^i;case 2:return e&t^e&i^t&i;case 3:return e^t^i}}function mw(n,e){return n<<e|n>>>32-e}function nW(n){const e=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof n=="string"){const o=unescape(encodeURIComponent(n));n=[];for(let a=0;a<o.length;++a)n.push(o.charCodeAt(a))}else Array.isArray(n)||(n=Array.prototype.slice.call(n));n.push(128);const i=n.length/4+2,s=Math.ceil(i/16),r=new Array(s);for(let o=0;o<s;++o){const a=new Uint32Array(16);for(let l=0;l<16;++l)a[l]=n[o*64+l*4]<<24|n[o*64+l*4+1]<<16|n[o*64+l*4+2]<<8|n[o*64+l*4+3];r[o]=a}r[s-1][14]=(n.length-1)*8/Math.pow(2,32),r[s-1][14]=Math.floor(r[s-1][14]),r[s-1][15]=(n.length-1)*8&4294967295;for(let o=0;o<s;++o){const a=new Uint32Array(80);for(let p=0;p<16;++p)a[p]=r[o][p];for(let p=16;p<80;++p)a[p]=mw(a[p-3]^a[p-8]^a[p-14]^a[p-16],1);let l=t[0],c=t[1],h=t[2],d=t[3],f=t[4];for(let p=0;p<80;++p){const g=Math.floor(p/20),m=mw(l,5)+iW(g,c,h,d)+f+e[g]+a[p]>>>0;f=d,d=h,h=mw(c,30)>>>0,c=l,l=m}t[0]=t[0]+l>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+h>>>0,t[3]=t[3]+d>>>0,t[4]=t[4]+f>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}const sW=tW("v5",80,nW),lR=sW;sn.registerCallback(to.ContextCreated,n=>{const e=n.context;_L(e),yL(e)});const W0=le("debugcomponents"),cR="eff8ba80-635d-11ec-90d6-0242ac120003";class Us{constructor(e){u(this,"_originalSeed");u(this,"_seed");typeof e=="string"&&(e=Us.hash(e)),this._originalSeed=e,this._seed=e}get seed(){return this._seed}set seed(e){this._seed=e}reset(){this._seed=this._originalSeed}generateUUID(e){if(typeof e=="string")return lR(e,cR);const t=this._seed;return this._seed-=1,lR(t.toString(),cR)}initialize(e){typeof e=="string"?this._seed=Us.hash(e):this._seed=e}static createFromString(e){return new Us(this.hash(e))}static hash(e){let t=0;for(let i=0;i<e.length;i++)t=e.charCodeAt(i)+((t<<5)-t);return t}}var mL=(n=>(n.NewInstanceCreated="new-instance-created",n.InstanceDestroyed="instance-destroyed",n))(mL||{});class AL{constructor(e){u(this,"guid");this.guid=e}}function fb(n,e,t=!0){if(!n)return;const i=n;if(kl(n,t),!e){console.warn("Can not send destroy: No networking connection provided",n.guid);return}if(!e.isConnected){console.warn("Can not send destroy: not connected",n.guid);return}let s=n.guid;if(!s&&i.uuid&&(s=i.uuid),!s){console.warn("Can not send destroy: failed to find guid",n);return}const r=new AL(s);e.send("instance-destroyed",r,tr.Queued)}function vL(n,e){const t=new AL(n);e.send("instance-destroyed",t,tr.Queued)}function yL(n){n.connection.beginListen("instance-destroyed",e=>{W0&&console.log("[Remote] Destroyed",n.scene,e);const t=mA(e.guid,n.scene);t&&kl(t)})}class rW{constructor(e,t,i){u(this,"filename");u(this,"hash");u(this,"size");this.filename=e,this.hash=t,this.size=i}}class oW{constructor(e,t){u(this,"guid");u(this,"originalGuid");u(this,"seed");u(this,"visible");u(this,"hostData");u(this,"dontSave");u(this,"parent");u(this,"position");u(this,"rotation");u(this,"scale");this.originalGuid=e,this.guid=t}}function T1(n,e,t,i){var l;const s=n;if(!s.guid)return console.warn("Can not instantiate: No guid",s),null;if(e.context||(e.context=_t.Current),!e.context)return console.error("Missing network instantiate options / reference to network connection in sync instantiate"),null;const r=e?{...e}:null,{instance:o,seed:a}=aW(s,e);if(o){const c=o;if(c.guid){W0&&console.log("[Local] new instance","gameobject:",o==null?void 0:o.guid);const h=new oW(s.guid,c.guid);h.seed=a,r&&(r.position&&(h.position={x:r.position.x,y:r.position.y,z:r.position.z}),r.rotation&&(h.rotation={x:r.rotation.x,y:r.rotation.y,z:r.rotation.z,w:r.rotation.w}),r.scale&&(h.scale={x:r.scale.x,y:r.scale.y,z:r.scale.z})),h.position||(h.position={x:c.position.x,y:c.position.y,z:c.position.z}),h.rotation||(h.rotation={x:c.quaternion.x,y:c.quaternion.y,z:c.quaternion.z,w:c.quaternion.w}),h.scale||(h.scale={x:c.scale.x,y:c.scale.y,z:c.scale.z}),h.visible=s.visible,r!=null&&r.parent&&(typeof r.parent=="string"?h.parent=r.parent:h.parent=r.parent.guid),h.hostData=t,i===!1&&(h.dontSave=!0),(l=e==null?void 0:e.context)==null||l.connection.send("new-instance-created",h)}else console.warn("Missing guid, can not send new instance event",c)}return o}function pb(){return Math.random()*9999999}function _L(n){n.connection.beginListen("new-instance-created",async e=>{const t=await lW(e.originalGuid,n.scene);if(!t){console.warn("could not find object that was instantiated: "+e.guid);return}const i=new Pa;e.position&&(i.position=new S(e.position.x,e.position.y,e.position.z)),e.rotation&&(i.rotation=new xe(e.rotation.x,e.rotation.y,e.rotation.z,e.rotation.w)),e.scale&&(i.scale=new S(e.scale.x,e.scale.y,e.scale.z)),i.parent=e.parent,e.seed&&(i.idProvider=new Us(e.seed)),i.visible=e.visible,i.context=n,W0&&n.alias&&console.log("[Remote] instantiate in: "+n.alias);const s=AA(t,i);s&&(e.parent==="scene"&&n.scene.add(s),W0&&console.log("[Remote] new instance","gameobject:",s==null?void 0:s.guid,t))})}function aW(n,e){const t=pb(),i=e??new Pa;i.idProvider=new Us(t);const s=AA(n,i);return{seed:t,instance:s}}const bL={};function xL(n,e){bL[n]=e}async function lW(n,e){const t=bL[n];if(t!=null){const i=await t(n);if(i)return i}return wL(n,e)}function wL(n,e){if(e===null||!n)return null;if(e.guid===n)return e;if(e.children)for(const t of e.children){const i=wL(n,t);if(i)return i}return null}const CL=new Map;function cW(n,e){if(!n)return;if(!e){console.warn("No prototype found",n,n.prototype,n.constructor);return}let t=CL.get(e);t&&t.apply(n)}function hW(n){const e=uW(n.prototype);CL.set(n,e)}function uW(n){return new dW(n)}class dW{constructor(e){u(this,"$symbol");u(this,"extensions");u(this,"descriptors");this.$symbol=Symbol("prototype-extension"),this.extensions=Object.keys(e),this.descriptors=new Array;for(let t=0;t<this.extensions.length;t++){const i=this.extensions[t],s=Object.getOwnPropertyDescriptor(e,i);s&&this.descriptors.push(s)}}apply(e){if(!e[this.$symbol]){e[this.$symbol]=!0;for(let t=0;t<this.extensions.length;t++){const i=this.extensions[t],s=this.descriptors[t];s&&Object.defineProperty(e,i,s)}}}}var dA=(n=>(n.Added="component-added",n.Removing="removing-component",n))(dA||{});const hR=le("debugcomponentevents");class fA{static addComponentLifecylceEventListener(e,t){this.eventListeners.has(e)&&this.eventListeners.set(e,[]);let i=this.eventListeners.get(e);i||(i=[]),i.push(t),this.eventListeners.set(e,i),hR&&console.log("Added event listener for "+e,this.eventListeners)}static removeComponentLifecylceEventListener(e,t){const i=this.eventListeners.get(e);if(!i)return;const s=i.indexOf(t);s<0||i.splice(s,1)}static dispatchComponentLifecycleEvent(e,t){const i=this.eventListeners.get(e);if(hR&&console.log("Dispatching event "+e,i),!!i)for(const s of i)s(t)}}u(fA,"eventListeners",new Map);const Aw=le("debuggetcomponent");function fW(n){return n==null||n.isObject3D?n:n.object&&n.object.isObject3D?n.object:n}function P1(n,e){if(!n||!n.userData.components)return;const t=n.userData.components.indexOf(e);t<0||(fA.dispatchComponentLifecycleEvent(dA.Removing,e),e.gameObject=null,n.userData.components.splice(t,1))}function gb(n,e){const t=Vf(n,e);if(t)return t;const i=new e;return Iu(n,i)}const SL=new Us("addComponentIdProvider");function Iu(n,e,t=!0){n.userData||(n.userData={}),n.userData.components||(n.userData.components=[]),n.userData.components.push(e),e.gameObject=n,(e.guid===void 0||e.guid==="invalid")&&(e.guid=SL.generateUUID()),Ab(n),xb(e);try{t&&e.__internalAwake&&(kg(n),e.__internalAwake()),fA.dispatchComponentLifecycleEvent(dA.Added,e)}catch(i){console.error(i)}return e}function R1(n,e){if(e.gameObject===n)return e;if(e.gameObject&&e.gameObject.userData.components){const t=e.gameObject.userData.components.indexOf(e);e.gameObject.userData.components.splice(t,1)}if(!n.userData.components)n.userData.components=[];else if(n.userData.components.includes(e))return e;return n.userData.components.push(e),e.gameObject=n,(e.guid===void 0||e.guid==="invalid")&&(e.guid=SL.generateUUID()),xb(e),e}function EL(n){if(n.gameObject&&n.gameObject.userData.components){const e=n.gameObject.userData.components.indexOf(n);n.gameObject.userData.components.splice(e,1)}n.__internalDisable&&n.__internalDisable(),n.onDestroy&&n.onDestroy(),ml(n,n.context??_t.Current),n.__internalDestroy(),n.gameObject=null}let uR=!1;function IL(n,e,t){var i;if(n!=null){if(!n.isObject3D){console.error("Object is not object3D");return}if(!((i=n==null?void 0:n.userData)!=null&&i.components))return null;if(typeof e=="string"&&(uR||(uR=!0,console.warn(`Accessing components by name is not supported.
|
|
3341
3341
|
Please use the component type instead. This may keep working in local development but it will fail when bundling your application.
|
|
3342
3342
|
|
|
3343
3343
|
You can import other modules your main module to get access to types
|
|
@@ -3833,7 +3833,7 @@ outputColor=vec4(color,inputColor.a);}`,aF=class extends Xo{constructor({blendFu
|
|
|
3833
3833
|
irradiance += 0.;
|
|
3834
3834
|
#else
|
|
3835
3835
|
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
3836
|
-
#endif`);Ye.lightmap.lightmapScaleOffset={value:new rt(1,1,0,0)};const X7=le("debugplayerview");var Ia=(n=>(n.Browser="browser",n.Headset="headset",n.Handheld="handheld",n))(Ia||{});class bF{constructor(e,t){u(this,"userId");u(this,"context");u(this,"viewDevice","browser");u(this,"removed",!1);u(this,"_object");this.userId=e,this.context=t}get currentObject(){return this._object}set currentObject(e){this._object=e}get isConnected(){return this.context.connection.userIsInRoom(this.userId)}}class xF{constructor(e){u(this,"context");u(this,"playerViews",new Map);this.context=e}setPlayerView(e,t,i){let s=this.playerViews.get(e);s||(s=new bF(e,this.context),this.playerViews.set(e,s)),s.viewDevice=i,s.currentObject=t,s.removed=!1}getPlayerView(e){if(!e)return;if(!this.context.connection.userIsInRoom(e)){this.playerViews.delete(e);return}return this.playerViews.get(e)}removePlayerView(e,t){const i=this.playerViews.get(e);(i==null?void 0:i.viewDevice)===t&&(X7&&console.log("REMOVE",e),i.removed=!0,this.playerViews.delete(e))}}const bw=le("debugSetup"),Y7=le("stats"),J7=le("debugactive"),K7=le("debugframerate"),Z7=le("debugcoroutine"),$7={};class eq{constructor(e){u(this,"name");u(this,"alias");u(this,"domElement");u(this,"renderer");u(this,"hash");this.domElement=e??document.body}}var Rr=(n=>(n[n.EarlyUpdate=0]="EarlyUpdate",n[n.Update=1]="Update",n[n.LateUpdate=2]="LateUpdate",n[n.OnBeforeRender=3]="OnBeforeRender",n[n.OnAfterRender=4]="OnAfterRender",n[n.PrePhysicsStep=9]="PrePhysicsStep",n[n.PostPhysicsStep=10]="PostPhysicsStep",n[n.Undefined=-1]="Undefined",n))(Rr||{}),ym=(n=>(n.ImmersiveVR="immersive-vr",n.ImmersiveAR="immersive-ar",n))(ym||{});function xb(n,e){if(!n)return;const t=(e==null?void 0:e.new_scripts)??_t.Current.new_scripts;t.includes(n)||t.push(n)}class _t{constructor(e){u(this,"name");u(this,"alias");u(this,"isManagedExternally",!1);u(this,"isPaused",!1);u(this,"runInBackground",!1);u(this,"targetFrameRate");u(this,"hash");u(this,"domElement");u(this,"_resolutionScaleFactor",1);u(this,"_boundingClientRectFrame",-1);u(this,"_boundingClientRect",null);u(this,"_domX");u(this,"_domY");u(this,"xrSessionMode");u(this,"_xrFrame",null);u(this,"_currentFrameEvent",-1);u(this,"scene");u(this,"renderer");u(this,"composer",null);u(this,"scripts",[]);u(this,"scripts_pausedChanged",[]);u(this,"scripts_earlyUpdate",[]);u(this,"scripts_update",[]);u(this,"scripts_lateUpdate",[]);u(this,"scripts_onBeforeRender",[]);u(this,"scripts_onAfterRender",[]);u(this,"scripts_WithCorroutines",[]);u(this,"coroutines",{});u(this,"mainCameraComponent");u(this,"post_setup_callbacks",[]);u(this,"pre_update_callbacks",[]);u(this,"pre_render_callbacks",[]);u(this,"post_render_callbacks",[]);u(this,"new_scripts",[]);u(this,"new_script_start",[]);u(this,"new_scripts_pre_setup_callbacks",[]);u(this,"new_scripts_post_setup_callbacks",[]);u(this,"application");u(this,"time");u(this,"input");u(this,"physics");u(this,"connection");u(this,"assets");u(this,"mainLight",null);u(this,"sceneLighting");u(this,"addressables");u(this,"lightmaps");u(this,"players");u(this,"_sizeChanged",!1);u(this,"_isCreated",!1);u(this,"_isCreating",!1);u(this,"_isVisible",!1);u(this,"_stats",Y7?R7():null);u(this,"_intersectionObserver",null);u(this,"_disposeCallbacks",[]);u(this,"_cameraStack",[]);u(this,"_onBeforeRenderListeners",new Map);u(this,"_onAfterRenderListeners",new Map);u(this,"_requireDepthTexture",!1);u(this,"_requireColorTexture",!1);u(this,"_renderTarget");u(this,"_isRendering",!1);u(this,"_accumulatedTime",0);u(this,"_framerateClock",new K_);u(this,"_dispatchReadyAfterFrame",!1);u(this,"_wasPaused",!1);var s,r;if(this.name=(e==null?void 0:e.name)||"",this.alias=e==null?void 0:e.alias,this.domElement=(e==null?void 0:e.domElement)||document.body,this.hash=e==null?void 0:e.hash,e!=null&&e.renderer)this.renderer=e.renderer,this.isManagedExternally=!0;else{const o={antialias:!0},a=(r=(s=e==null?void 0:e.domElement)==null?void 0:s.shadowRoot)==null?void 0:r.querySelector("canvas");a&&(o.canvas=a),this.renderer=new Df(o),this.renderer.toneMappingExposure=1,this.renderer.toneMapping=Ls,this.renderer.setClearColor(new _e("lightgrey"),0),this.renderer.antialias=!0,this.renderer.alpha=!1,this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=ME,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputEncoding=yt,this.renderer.physicallyCorrectLights=!0}this.scene=new Tr,sn.register(this),this.application=new _F(this),this.time=new vO,this.input=new lO(this),this.physics=new AO(this),this.connection=new pL(this),this.assets=new RL,this.sceneLighting=new vF(this),this.addressables=new mF(this),this.lightmaps=new q7(this),this.players=new xF(this);const t=()=>this._sizeChanged=!0;window.addEventListener("resize",t),this._disposeCallbacks.push(()=>window.removeEventListener("resize",t));const i=new ResizeObserver(o=>this._sizeChanged=!0);i.observe(this.domElement),this._disposeCallbacks.push(()=>i.disconnect()),this._intersectionObserver=new IntersectionObserver(o=>{this._isVisible=o[0].isIntersecting}),this._disposeCallbacks.push(()=>{var o;return(o=this._intersectionObserver)==null?void 0:o.disconnect()})}get version(){return gL}static get Current(){return sn.Current}static set Current(e){sn.Current=e}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(e){if(e!==this._resolutionScaleFactor&&typeof e=="number"){if(e<=0){console.error("Invalid resolution scale factor",e);return}this._resolutionScaleFactor=e,this.updateSize()}}calculateBoundingClientRect(){if(this.isInAR){this._domX=0,this._domY=0;return}this._boundingClientRectFrame!==this.time.frame&&(this._boundingClientRectFrame=this.time.frame,this._boundingClientRect=this.domElement.getBoundingClientRect(),this._domX=this._boundingClientRect.x,this._domY=this._boundingClientRect.y)}get domWidth(){return this.isInAR?window.innerWidth:this.domElement.clientWidth}get domHeight(){return this.isInAR?window.innerHeight:this.domElement.clientHeight}get domX(){return this.calculateBoundingClientRect(),this._domX}get domY(){return this.calculateBoundingClientRect(),this._domY}get isInXR(){var e;return((e=this.renderer.xr)==null?void 0:e.isPresenting)||!1}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){var e;return(e=this.renderer.xr)==null?void 0:e.getSession()}get xrFrame(){return this._xrFrame}get arOverlayElement(){const e=this.domElement;return typeof e.getAROverlayContainer=="function"?e.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this.mainCameraComponent){const e=this.mainCameraComponent;return e.cam||e.buildCamera(),e.cam}return null}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}internalOnUpdateVisible(){var e,t;(e=this._intersectionObserver)==null||e.disconnect(),(t=this._intersectionObserver)==null||t.observe(this.domElement)}updateSize(){var e,t,i;if(!this.isManagedExternally&&((e=this.renderer.xr)==null?void 0:e.isPresenting)===!1){this._sizeChanged=!1;const s=this.resolutionScaleFactor,r=this.domWidth*s,o=this.domHeight*s,a=this.mainCamera;this.updateAspect(a),this.renderer.setSize(r,o),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((t=this.composer.setSize)==null||t.call(this.composer,r,o),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((i=this.composer.setPixelRatio)==null||i.call(this.composer,window.devicePixelRatio)))}}updateAspect(e,t,i){if(!e)return;t===void 0&&(t=this.domWidth),i===void 0&&(i=this.domHeight);const s=e.aspect;e.aspect=t/i,s!==e.aspect&&e.updateProjectionMatrix()}async onCreate(e,t){try{return this._isCreating=!0,await this.internalOnCreate(e,t)}finally{this._isCreating=!1}}clear(){var e;(e=this.scene)!=null&&e.children.length&&(kl(this.scene,!0,!0),this.scene=new Tr),this.renderer&&(this.renderer.setClearAlpha(0),this.renderer.clear())}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var e,t,i;this.clear(),(e=this.renderer)==null||e.setAnimationLoop(null),this.isManagedExternally||(t=this.renderer)==null||t.dispose();for(const s of this._disposeCallbacks)try{s()}catch(r){console.error("Error in on dispose callback:",r,s)}(i=this.domElement)!=null&&i.parentElement&&this.domElement.parentElement.removeChild(this.domElement),sn.dispatchCallback(to.ContextDestroyed,this),sn.unregister(this)}registerCoroutineUpdate(e,t,i){return this.coroutines[i]||(this.coroutines[i]=[]),this.coroutines[i].push({comp:e,main:t}),t}unregisterCoroutineUpdate(e,t){if(!this.coroutines[t])return;const i=this.coroutines[t].findIndex(s=>s.main===e);i>=0&&this.coroutines[t].splice(i,1)}stopAllCoroutinesFrom(e){for(const t in this.coroutines){const i=this.coroutines[t];for(let s=i.length-1;s>=0;s--)i[s].comp===e&&i.splice(s,1)}}setCurrentCamera(e){var s;if(!e)return;if(e.cam||e.buildCamera(),!e.cam){console.warn("Camera component is missing camera",e);return}const t=this._cameraStack.indexOf(e);t>=0&&this._cameraStack.splice(t,1),this._cameraStack.push(e),this.mainCameraComponent=e;const i=e.cam;i.isPerspectiveCamera&&this.updateAspect(i),(s=this.mainCameraComponent)==null||s.applyClearFlagsIfIsActiveCamera()}removeCamera(e){if(!e)return;const t=this._cameraStack.indexOf(e);if(t>=0&&this._cameraStack.splice(t,1),this.mainCameraComponent===e&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const i=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(i)}}addBeforeRenderListener(e,t){var i;this._onBeforeRenderListeners.has(e.uuid)||(this._onBeforeRenderListeners.set(e.uuid,[]),e.onBeforeRender=this._createRenderCallbackWrapper(e,this._onBeforeRenderListeners)),(i=this._onBeforeRenderListeners.get(e.uuid))==null||i.push(t)}removeBeforeRenderListener(e,t){if(this._onBeforeRenderListeners.has(e.uuid)){const i=this._onBeforeRenderListeners.get(e.uuid),s=i.indexOf(t);s>=0&&i.splice(s,1)}}addAfterRenderListener(e,t){var i;this._onAfterRenderListeners.has(e.uuid)||(this._onAfterRenderListeners.set(e.uuid,[]),e.onAfterRender=this._createRenderCallbackWrapper(e,this._onAfterRenderListeners)),(i=this._onAfterRenderListeners.get(e.uuid))==null||i.push(t)}removeAfterRenderListener(e,t){if(this._onAfterRenderListeners.has(e.uuid)){const i=this._onAfterRenderListeners.get(e.uuid),s=i.indexOf(t);s>=0&&i.splice(s,1)}}_createRenderCallbackWrapper(e,t){return(i,s,r,o,a,l)=>{const c=t.get(e.uuid);if(c)for(let h=0;h<c.length;h++){const d=c[h];d(i,s,r,o,a,l)}}}get isRendering(){return this._isRendering}setRequireDepth(e){this._requireDepthTexture=e}setRequireColor(e){this._requireColorTexture=e}get depthTexture(){var e;return((e=this._renderTarget)==null?void 0:e.depthTexture)||null}get opaqueColorTexture(){var e;return((e=this._renderTarget)==null?void 0:e.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const e=getComputedStyle(this.domElement);return e.visibility!=="hidden"&&e.display!=="none"&&e.opacity!=="0"}async internalOnCreate(e,t){var s;this.clear(),(s=this.renderer)==null||s.setAnimationLoop(null),await jm(1),_t.Current=this,await sn.dispatchCallback(to.ContextCreationStart,this);let i=!0;try{_t.Current=this,e&&await e(this,t)}catch(r){console.error(r),i=!1}if(!i)return!1;this.internalOnUpdateVisible(),!this.isManagedExternally&&!this.domElement.shadowRoot&&this.domElement.prepend(this.renderer.domElement),_t.Current=this,_t.Current=this;for(let r=0;r<this.new_scripts.length;r++){const o=this.new_scripts[r];if(o.gameObject!==void 0&&o.gameObject!==null){o.gameObject.userData===void 0&&(o.gameObject.userData={}),o.gameObject.userData.components===void 0&&(o.gameObject.userData.components=[]);const a=o.gameObject.userData.components;a.includes(o)||a.push(o)}}if(this.post_setup_callbacks)for(let r=0;r<this.post_setup_callbacks.length;r++)_t.Current=this,await this.post_setup_callbacks[r](this);if(!this.mainCamera){_t.Current=this;let r=null;Au(this.scene,o=>{const a=o;if(a!=null&&a.isCamera){if(kg(a.gameObject),!a.activeAndEnabled)return;if(a.tag==="MainCamera")return r=a,!0;r=a}}),r?this.setCurrentCamera(r):(sn.dispatchCallback(to.MissingCamera,this),!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this))}if(_t.Current=this,q0(this),!this.isManagedExternally&&this.composer&&this.mainCamera){const r=new bb(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(r),this.composer.setSize(this.domWidth,this.domHeight)}return this._sizeChanged=!0,this._stats&&(this._stats.showPanel(1),this.domElement.appendChild(this._stats.dom)),bw&&Q0(this.scene,!0),this._isCreating=!1,this.restartRenderLoop(),this._dispatchReadyAfterFrame=!0,sn.dispatchCallback(to.ContextCreated,this)}restartRenderLoop(){if(!this.renderer)return console.error("Can not start render loop without renderer"),!1;if(this._isCreating)return console.warn("Can not start render loop while creating context"),!1;const e=this.render.bind(this);return this.renderer.setAnimationLoop(e),!0}render(e,t){if(Qs()||bw||TW())try{this.internalRender(e,t)}catch(i){(Qs()||bw)&&i instanceof Error&&jn("Exception during render-loop.<br/>See console for details.",Uo.Error),console.error(i),console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null),this.domElement.dispatchEvent(new CustomEvent("error",{detail:i}))}else this.internalRender(e,t)}internalRender(e,t){var i,s;if(this._xrFrame=t,this._currentFrameEvent=-1,this.isInXR===!1&&this.targetFrameRate!==void 0){if(this._accumulatedTime+=this._framerateClock.getDelta(),this._accumulatedTime<1/this.targetFrameRate)return;this._accumulatedTime=0}if((i=this._stats)==null||i.begin(),_t.Current=this,!this.onHandlePaused()){for(_t.Current=this,this.time.update(),K7&&console.log("FPS",this.time.smoothedFps.toFixed(0)),q0(this),e0(this.scene),VL(this);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);const r=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(r)}if(this.pre_update_callbacks)for(const r in this.pre_update_callbacks)this.pre_update_callbacks[r]();this._currentFrameEvent=0;for(let r=0;r<this.scripts_earlyUpdate.length;r++){const o=this.scripts_earlyUpdate[r];o.activeAndEnabled&&o.earlyUpdate!==void 0&&(_t.Current=this,o.earlyUpdate())}if(this.executeCoroutines(0),!this.onHandlePaused()){this._currentFrameEvent=1;for(let r=0;r<this.scripts_update.length;r++){const o=this.scripts_update[r];o.activeAndEnabled&&o.update!==void 0&&(_t.Current=this,o.update())}if(this.executeCoroutines(1),!this.onHandlePaused()){this._currentFrameEvent=2;for(let r=0;r<this.scripts_lateUpdate.length;r++){const o=this.scripts_lateUpdate[r];o.activeAndEnabled&&o.lateUpdate!==void 0&&(_t.Current=this,o.lateUpdate())}if(this.executeCoroutines(2),!this.onHandlePaused()){if(this.physics.engine){const o=this.time.deltaTime/1;for(let a=0;a<1;a++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(o),this._currentFrameEvent=10,this.executeCoroutines(10);this.physics.engine.postStep()}if(!this.onHandlePaused()){if(this.isVisibleToUser){this._currentFrameEvent=3;for(let r=0;r<this.scripts_onBeforeRender.length;r++){const o=this.scripts_onBeforeRender[r];o.activeAndEnabled&&o.onBeforeRender!==void 0&&(_t.Current=this,o.onBeforeRender(t))}if(this.executeCoroutines(3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(const r in this.pre_render_callbacks)this.pre_render_callbacks[r]();this.isManagedExternally||(BW(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4);for(let r=0;r<this.scripts_onAfterRender.length;r++){const o=this.scripts_onAfterRender[r];o.activeAndEnabled&&o.onAfterRender!==void 0&&(_t.Current=this,o.onAfterRender())}if(this.executeCoroutines(4),this.post_render_callbacks)for(const r in this.post_render_callbacks)this.post_render_callbacks[r]()}this._currentFrameEvent=-1,this.connection.sendBufferedMessagesNow(),(s=this._stats)==null||s.end(),this._dispatchReadyAfterFrame&&(this._dispatchReadyAfterFrame=!1,this.domElement.dispatchEvent(new CustomEvent("ready")))}}}}}}renderNow(e){return!e&&(e=this.mainCamera,!e)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):e&&this.renderer.render(this.scene,e),this._isRendering=!1,!0)}onHandlePaused(){const e=this.evaluatePaused();if(this._wasPaused!==e){J7&&console.log("Paused?",e,"context:"+this.alias);for(let t=0;t<this.scripts_pausedChanged.length;t++){const i=this.scripts_pausedChanged[t];i.activeAndEnabled&&i.onPausedChanged!==void 0&&(_t.Current=this,i.onPausedChanged(e,this._wasPaused))}}return this._wasPaused=e,e}evaluatePaused(){return this.isInXR?!1:this.isPaused?!0:this.runInBackground?!1:!this.isVisibleToUser}renderRequiredTextures(){if(!this.mainCamera||!this._requireDepthTexture&&!this._requireColorTexture)return;if(!this._renderTarget){if(this._renderTarget=new ai(this.domWidth,this.domHeight),this._requireDepthTexture){const i=new U_(this.domWidth,this.domHeight);this._renderTarget.depthTexture=i}this._requireColorTexture&&(this._renderTarget.texture=new Gt,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=ti,this._renderTarget.texture.magFilter=ti,this._renderTarget.texture.format=Ti)}const e=this._renderTarget;e.texture&&(e.texture.encoding=this.renderer.outputEncoding);const t=this.renderer.getRenderTarget();this.renderer.setRenderTarget(e),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(t)}executeCoroutines(e){if(this.coroutines[e]){const i=this.coroutines[e];for(let s=0;s<i.length;s++)try{const r=i[s];if(!r.comp||r.comp.destroyed||!r.main||r.comp.enabled===!1){Z7&&console.log("Removing coroutine",r.comp,r.comp.enabled),i.splice(s,1),--s;continue}const a=r.chained;if(a&&a.length>0){const d=a[a.length-1].next();if(d.done&&a.pop(),t(d)&&(r.chained||(r.chained=[]),r.chained.push(d.value)),!d.done)continue}const l=r.main.next();if(l.done===!0){i.splice(s,1),--s;continue}const c=l.value;if(t(c)){if(c.next().done)continue;r.chained||(r.chained=[]),r.chained.push(c)}}catch(r){console.error(r)}}function t(i){return!!(i&&i.next&&i.return)}}}const tq=le("debugaroverlay"),Hh="ar",PR="quit-ar";class iq{constructor(){u(this,"arContainer",null);u(this,"closeARCallback");u(this,"currentSession",null);u(this,"registeredCloseEventElements",[]);u(this,"_createdAROnlyElements",[]);u(this,"_reparentedObjects",[]);this.closeARCallback=this.onRequestedEndAR.bind(this)}get ARContainer(){return this.arContainer}requestEndAR(){this.onRequestedEndAR()}onBegin(e,t,i){this.currentSession=i,this.arContainer=t,e.domElement.querySelectorAll(`.${Hh}`).forEach(o=>{var a;o&&o!==this.arContainer&&(this._reparentedObjects.push({el:o,previousParent:o.parentElement}),(a=this.arContainer)==null||a.appendChild(o))});const r=t.getElementsByClassName(PR);if(!r||r.length<=0)console.warn(`Missing quit AR elements, creating fallback X button. Use class name '${PR}' to override.`),this.createFallbackCloseARButton(this.arContainer);else for(let o=0;o<r.length;o++){const a=r[o];a&&(a.addEventListener("click",this.closeARCallback),this.registeredCloseEventElements.push(a))}}onEnd(e){var t;for(const i of this._createdAROnlyElements)i.remove&&i.remove();for(const i of this._reparentedObjects){const s=i.el;(t=i.previousParent)==null||t.appendChild(s)}this._reparentedObjects.length=0,EE()&&setTimeout(()=>{const i=e.renderer.domElement;i&&e.domElement.insertBefore(i,e.domElement.firstChild);const s=document.querySelectorAll("*");for(var r=0;r<s.length;r++){const o=s[r];o&&o._displayChanged!==void 0&&o._displayWas!==void 0&&(o.style.display=o._displayWas)}},10)}findOrCreateARContainer(e){if(e.classList.contains(Hh))return e;if(e.children)for(let s=0;s<e.children.length;s++){const r=e.children[s];if(!(!r||!r.classList)&&r.classList.contains(Hh))return r}const t=document.getElementsByClassName(Hh);if(t&&t.length>0)return t[0];tq&&console.log("No overlay container found in document - generating new ony");const i=document.createElement("div");return i.classList.add(Hh),i.style.position="absolute",i.style.width="100%",i.style.height="100%",i.style.display="flex",i.style.visibility="visible",e.appendChild(i)}onRequestedEndAR(){if(this.currentSession){this.currentSession.end(),this.currentSession=null;for(const e of this.registeredCloseEventElements)e.removeEventListener("click",this.closeARCallback);this.registeredCloseEventElements.length=0}}createFallbackCloseARButton(e){var t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width","38px"),t.setAttribute("height","38px"),t.style.position="absolute",t.style.right="20px",t.style.top="40px",t.style.zIndex="9999",t.style.pointerEvents="auto",t.addEventListener("click",this.closeARCallback),e.appendChild(t),this._createdAROnlyElements.push(t);var i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),i.setAttribute("stroke","#ddd"),i.setAttribute("stroke-width","3px"),t.appendChild(i),this._createdAROnlyElements.push(i)}}class $ extends Ie{constructor(){super(...arguments);u(this,"guid")}static isDestroyed(t){return D1(t)}static setActive(t,i,s=!0){t&&(Dg(t,i),e0(t),i&&s&&VL(_t.Current,t))}static isActiveSelf(t){return Wf(t)}static isActiveInHierarchy(t){return FL(t)}static markAsInstancedRendered(t,i){UL(t,i)}static isUsingInstancing(t){return vb(t)}static foreachComponent(t,i,s=!0){return Au(t,i,s)}static instantiateSynced(t,i){return t?T1(t,i):null}static instantiate(t,i=null){return AA(t,i)}static destroySynced(t,i,s=!0){if(!t)return;const r=t;i=i??_t.Current,fb(r,i.connection,s)}static destroy(t,i=!0,s=!0){return kl(t,i,s)}static add(t,i,s){if(!(!t||!i)){if(t===i){console.warn("Can not add object to self",t);return}s||(s=_t.Current),i.add(t),Dg(t,!0),e0(t),s?$.foreachComponent(t,r=>{O1(r,s),!r.__internalDidAwakeAndStart&&s.new_script_start.includes(r)===!1&&s.new_script_start.push(r)},!0):console.warn("Missing context")}}static remove(t){var i;t&&((i=t.parent)==null||i.remove(t),Dg(t,!1),e0(t),$.foreachComponent(t,s=>{PW(s)},!0))}static invokeOnChildren(t,i,...s){this.invoke(t,i,!0,s)}static invoke(t,i,s=!1,...r){t&&this.foreachComponent(t,o=>{const a=o[i];a&&typeof a=="function"&&(a==null||a.call(o,...r))},s)}static addNewComponent(t,i,s=!0){const r=new i;return Iu(t,r,s),r}static addComponent(t,i){return this.moveComponent(t,i)}static moveComponent(t,i){return R1(t,i)}static removeComponent(t){return P1(t.gameObject,t),t}static getOrAddComponent(t,i){return gb(t,i)}static getComponent(t,i){return t===null?null:Vf(t,i)}static getComponents(t,i,s=null){return t===null?s??[]:pA(t,i,s)}static findByGuid(t,i){return mA(t,i)}static findObjectOfType(t,i,s=!0){return ML(t,i??_t.Current,s)}static findObjectsOfType(t,i){const s=[];return TL(t,s,i),s}static getComponentInChildren(t,i){return jf(t,i)}static getComponentsInChildren(t,i,s=null){return gA(t,i,s??void 0)}static getComponentInParent(t,i){return Am(t,i)}static getComponentsInParent(t,i,s=null){return mb(t,i,s)}static getAllComponents(t){var r;return[...(r=t.userData)==null?void 0:r.components]}static*iterateComponents(t){var s;const i=(s=t==null?void 0:t.userData)==null?void 0:s.components;if(i&&Array.isArray(i))for(let r=0;r<i.length;r++)yield i[r]}}var Xi;let sh=(Xi=class{constructor(){u(this,"__context");u(this,"__name");u(this,"gameObject");u(this,"guid","invalid");u(this,"sourceId");u(this,"__didAwake",!1);u(this,"__didStart",!1);u(this,"__didEnable",!1);u(this,"__isEnabled");u(this,"__destroyed",!1);u(this,"_worldPosition");u(this,"_worldQuaternion");u(this,"_worldEuler");u(this,"_worldRotation");u(this,"_eventListeners",new Map);this.__internalNewInstanceCreated()}get isComponent(){return!0}get context(){return this.__context??_t.Current}set context(e){this.__context=e}get scene(){return this.context.scene}get layer(){var e,t;return(t=(e=this.gameObject)==null?void 0:e.userData)==null?void 0:t.layer}get name(){var e,t;return(e=this.gameObject)!=null&&e.name?this.gameObject.name:(t=this.gameObject)==null?void 0:t.userData.name}set name(e){this.gameObject?(this.gameObject.userData||(this.gameObject.userData={}),this.gameObject.userData.name=e,this.__name=e):this.__name=e}get tag(){var e;return(e=this.gameObject)==null?void 0:e.userData.tag}set tag(e){this.gameObject&&(this.gameObject.userData.tag=e)}get static(){var e;return(e=this.gameObject)==null?void 0:e.userData.static}get hideFlags(){var e;return(e=this.gameObject)==null?void 0:e.userData.hideFlags}get activeAndEnabled(){return!(this.destroyed||this.__isEnabled===!1||!this.__isActiveInHierarchy)}get __isActive(){return this.gameObject.visible}get __isActiveInHierarchy(){if(!this.gameObject)return!1;const e=this.gameObject[Ml];return e===void 0?!0:e}set __isActiveInHierarchy(e){this.gameObject&&(this.gameObject[Ml]=e)}awake(){}onEnable(){}onDisable(){}onDestroy(){this.__destroyed=!0}startCoroutine(e,t=Rr.Update){return this.context.registerCoroutineUpdate(this,e,t)}stopCoroutine(e,t=Rr.Update){this.context.unregisterCoroutineUpdate(e,t)}get destroyed(){return this.__destroyed}destroy(){this.__destroyed||this.__internalDestroy()}get __internalDidAwakeAndStart(){return this.__didAwake&&this.__didStart}__internalNewInstanceCreated(){this.__didAwake=!1,this.__didStart=!1,this.__didEnable=!1,this.__isEnabled=void 0,this.__destroyed=!1}__internalAwake(){this.__didAwake||(this.__didAwake=!0,this.awake())}__internalStart(){this.__didStart||(this.__didStart=!0,this.start&&this.start())}__internalEnable(e){return this.__destroyed?(Qs()&&console.warn("[Needle Engine Dev] Trying to enable destroyed component"),!1):this.__didAwake?this.__didEnable?(e!==!0&&(this.__isEnabled=!0),!1):(this.__didEnable=!0,this.__isEnabled=!0,this.onEnable(),!0):!1}__internalDisable(e){if(this.__didAwake){if(!this.__didEnable){e!==!0&&(this.__isEnabled=!1);return}this.__didEnable=!1,this.__isEnabled=!1,this.onDisable()}}__internalDestroy(){var e;this.__destroyed||(this.__destroyed=!0,(e=this.destroy)==null||e.call(this),this.dispatchEvent(new CustomEvent("destroyed",{detail:this})),EL(this))}get enabled(){return typeof this.__isEnabled=="boolean"?this.__isEnabled:!0}set enabled(e){if(this.__destroyed){Qs()&&console.warn(`[Needle Engine Dev] Trying to ${e?"enable":"disable"} destroyed component`);return}if(typeof e=="number"&&(e>=.5?e=!0:e=!1),!this.__didAwake){this.__isEnabled=e;return}e?this.__internalEnable():this.__internalDisable()}get worldPosition(){return this._worldPosition||(this._worldPosition=new S),wt(this.gameObject,this._worldPosition),this._worldPosition}set worldPosition(e){ln(this.gameObject,e)}setWorldPosition(e,t,i){Xi._worldPositionBuffer.set(e,t,i),this.worldPosition=Xi._worldPositionBuffer}get worldQuaternion(){return this._worldQuaternion||(this._worldQuaternion=new xe),Dn(this.gameObject,this._worldQuaternion)}set worldQuaternion(e){cr(this.gameObject,e)}setWorldQuaternion(e,t,i,s){Xi._worldQuaternionBuffer.set(e,t,i,s),this.worldQuaternion=Xi._worldQuaternionBuffer}get worldEuler(){return this._worldEuler||(this._worldEuler=new bn),this._worldEuler.setFromQuaternion(this.worldQuaternion),this._worldEuler}set worldEuler(e){var t;this._worldQuaternion||(this._worldQuaternion=new xe),(t=this._worldQuaternion)==null||t.setFromEuler(e),this.worldQuaternion=this._worldQuaternion}get worldRotation(){const e=this.worldEuler;this._worldRotation||(this._worldRotation=new S);const t=this._worldRotation;return t.set(e.x,e.y,e.z),t.x=Ze.toDegrees(t.x),t.y=Ze.toDegrees(t.y),t.z=Ze.toDegrees(t.z),t}set worldRotation(e){this.setWorldRotation(e.x,e.y,e.z,!0)}setWorldRotation(e,t,i,s=!0){s&&(e=Ze.toRadians(e),t=Ze.toRadians(t),i=Ze.toRadians(i)),Xi._worldEulerBuffer.set(e,t,i),Xi._worldQuaternionBuffer.setFromEuler(Xi._worldEulerBuffer),this.worldQuaternion=Xi._worldQuaternionBuffer}get forward(){return Xi._forward.set(0,0,-1).applyQuaternion(this.worldQuaternion)}get right(){return Xi._right.set(1,0,0).applyQuaternion(this.worldQuaternion)}get up(){return Xi._up.set(0,1,0).applyQuaternion(this.worldQuaternion)}addEventListener(e,t){this._eventListeners[e]=this._eventListeners[e]||[],this._eventListeners[e].push(t)}removeEventListener(e,t){if(!this._eventListeners[e])return;const i=this._eventListeners[e].indexOf(t);i>=0&&this._eventListeners[e].splice(i,1)}dispatchEvent(e){if(!this._eventListeners[e.type])return!1;const t=this._eventListeners[e.type];for(let i=0;i<t.length;i++)t[i](e);return!1}},u(Xi,"_worldPositionBuffer",new S),u(Xi,"_worldQuaternionBuffer",new xe),u(Xi,"_worldEulerBuffer",new bn),u(Xi,"_tempQuaternionBuffer2",new xe),u(Xi,"_forward",new S),u(Xi,"_right",new S),u(Xi,"_up",new S),Xi);class Ce extends sh{}const nq=Object.freeze(Object.defineProperty({__proto__:null,Behaviour:Ce,Component:sh,GameObject:$},Symbol.toStringTag,{value:"Module"})),sq='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 160 187.74"><defs><linearGradient id="a" x1="89.64" y1="184.81" x2="90.48" y2="21.85" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#62d399"/><stop offset=".51" stop-color="#acd842"/><stop offset=".9" stop-color="#d7db0a"/></linearGradient><linearGradient id="b" x1="69.68" y1="178.9" x2="68.08" y2="16.77" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#0ba398"/><stop offset=".5" stop-color="#4ca352"/><stop offset="1" stop-color="#76a30a"/></linearGradient><linearGradient id="c" x1="36.6" y1="152.17" x2="34.7" y2="84.19" gradientUnits="userSpaceOnUse"><stop offset=".19" stop-color="#36a382"/><stop offset=".54" stop-color="#49a459"/><stop offset="1" stop-color="#76a30b"/></linearGradient><linearGradient id="d" x1="15.82" y1="153.24" x2="18" y2="90.86" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#267880"/><stop offset=".51" stop-color="#457a5c"/><stop offset="1" stop-color="#717516"/></linearGradient><linearGradient id="e" x1="135.08" y1="135.43" x2="148.93" y2="63.47" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#b0d939"/><stop offset="1" stop-color="#eadb04"/></linearGradient><linearGradient id="f" x1="-4163.25" y1="2285.12" x2="-4160.81" y2="2215.34" gradientTransform="rotate(20 4088.49 13316.712)" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#74af52"/><stop offset=".48" stop-color="#99be32"/><stop offset="1" stop-color="#c0c40a"/></linearGradient><symbol id="g" viewBox="0 0 160 187.74"><path style="fill:url(#a)" d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75z"/><path style="fill:url(#b)" d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98z"/><path style="fill:url(#c)" d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z"/><path style="fill:url(#d)" d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04z"/><path style="fill:#9c3" d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5z"/><path style="fill:url(#e)" d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59z"/><path style="fill:url(#f)" d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z"/><path style="fill:#ffe113" d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1z"/><path style="fill:#f3e600" d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75z"/></symbol></defs><use width="160" height="187.74" xlink:href="#g"/></svg>',rq=new Blob([sq],{type:"image/svg+xml;charset=utf-8"}),oq=URL.createObjectURL(rq),wF=oq,eu=le("debuglicense"),V1="basic";eu&&console.log("License Type: "+V1);function Gc(){switch(V1){case"pro":case"enterprise":return!0}return!1}function CF(){switch(V1){case"indie":return!0}return!1}function SF(){return Gc()||CF()}sn.registerCallback(to.ContextRegistered,n=>{aq(n.context)});async function aq(n){try{if(Gc()!==!0)return xw(n)}catch(e){return eu&&console.log("License check failed",e),xw(n)}eu&&xw(n)}const EF="needle-license-element",DS=5e3,kS=200;function xw(n){cq(),n.domElement.addEventListener("ready",()=>{setTimeout(()=>{lq(n)},1e3)}),dq()}function lq(n){const e=hq(),t=uq(),i=setInterval(()=>{if(!e)return;const l=n.domElement.shadowRoot||n.domElement;e.parentNode!==l&&(l.appendChild(e),t&&l.appendChild(t))},100);let s=`<img class="logo" src="${wF}" style="width: 40px; height: 40px; margin-right: 2px; vertical-align: middle; margin-bottom: 2px;"/>`;const r=document.createElement("div");r.innerHTML=s,r.classList.add("logo"),e.appendChild(r);const o=document.createElement("div");o.classList.add("text"),e.appendChild(o),e.title="Needle Engine",SF()||(e.title+=" non commercial version"),e.addEventListener("click",()=>{globalThis.open("https://needle.tools","_blank")});const a=DS+kS;setTimeout(()=>{clearInterval(i),e==null||e.remove(),t==null||t.remove()},a)}let RR=0;async function cq(n){const e=Date.now();if(e-RR<2e3)return;RR=e;const i=`
|
|
3836
|
+
#endif`);Ye.lightmap.lightmapScaleOffset={value:new rt(1,1,0,0)};const X7=le("debugplayerview");var Ia=(n=>(n.Browser="browser",n.Headset="headset",n.Handheld="handheld",n))(Ia||{});class bF{constructor(e,t){u(this,"userId");u(this,"context");u(this,"viewDevice","browser");u(this,"removed",!1);u(this,"_object");this.userId=e,this.context=t}get currentObject(){return this._object}set currentObject(e){this._object=e}get isConnected(){return this.context.connection.userIsInRoom(this.userId)}}class xF{constructor(e){u(this,"context");u(this,"playerViews",new Map);this.context=e}setPlayerView(e,t,i){let s=this.playerViews.get(e);s||(s=new bF(e,this.context),this.playerViews.set(e,s)),s.viewDevice=i,s.currentObject=t,s.removed=!1}getPlayerView(e){if(!e)return;if(!this.context.connection.userIsInRoom(e)){this.playerViews.delete(e);return}return this.playerViews.get(e)}removePlayerView(e,t){const i=this.playerViews.get(e);(i==null?void 0:i.viewDevice)===t&&(X7&&console.log("REMOVE",e),i.removed=!0,this.playerViews.delete(e))}}const bw=le("debugSetup"),Y7=le("stats"),J7=le("debugactive"),K7=le("debugframerate"),Z7=le("debugcoroutine"),$7={};class eq{constructor(e){u(this,"name");u(this,"alias");u(this,"domElement");u(this,"renderer");u(this,"hash");this.domElement=e??document.body}}var Rr=(n=>(n[n.EarlyUpdate=0]="EarlyUpdate",n[n.Update=1]="Update",n[n.LateUpdate=2]="LateUpdate",n[n.OnBeforeRender=3]="OnBeforeRender",n[n.OnAfterRender=4]="OnAfterRender",n[n.PrePhysicsStep=9]="PrePhysicsStep",n[n.PostPhysicsStep=10]="PostPhysicsStep",n[n.Undefined=-1]="Undefined",n))(Rr||{}),ym=(n=>(n.ImmersiveVR="immersive-vr",n.ImmersiveAR="immersive-ar",n))(ym||{});function xb(n,e){if(!n)return;const t=(e==null?void 0:e.new_scripts)??_t.Current.new_scripts;t.includes(n)||t.push(n)}class _t{constructor(e){u(this,"name");u(this,"alias");u(this,"isManagedExternally",!1);u(this,"isPaused",!1);u(this,"runInBackground",!1);u(this,"targetFrameRate");u(this,"hash");u(this,"domElement");u(this,"_resolutionScaleFactor",1);u(this,"_boundingClientRectFrame",-1);u(this,"_boundingClientRect",null);u(this,"_domX");u(this,"_domY");u(this,"xrSessionMode");u(this,"_xrFrame",null);u(this,"_currentFrameEvent",-1);u(this,"scene");u(this,"renderer");u(this,"composer",null);u(this,"scripts",[]);u(this,"scripts_pausedChanged",[]);u(this,"scripts_earlyUpdate",[]);u(this,"scripts_update",[]);u(this,"scripts_lateUpdate",[]);u(this,"scripts_onBeforeRender",[]);u(this,"scripts_onAfterRender",[]);u(this,"scripts_WithCorroutines",[]);u(this,"coroutines",{});u(this,"mainCameraComponent");u(this,"post_setup_callbacks",[]);u(this,"pre_update_callbacks",[]);u(this,"pre_render_callbacks",[]);u(this,"post_render_callbacks",[]);u(this,"new_scripts",[]);u(this,"new_script_start",[]);u(this,"new_scripts_pre_setup_callbacks",[]);u(this,"new_scripts_post_setup_callbacks",[]);u(this,"application");u(this,"time");u(this,"input");u(this,"physics");u(this,"connection");u(this,"assets");u(this,"mainLight",null);u(this,"sceneLighting");u(this,"addressables");u(this,"lightmaps");u(this,"players");u(this,"_sizeChanged",!1);u(this,"_isCreated",!1);u(this,"_isCreating",!1);u(this,"_isVisible",!1);u(this,"_stats",Y7?R7():null);u(this,"_intersectionObserver",null);u(this,"_disposeCallbacks",[]);u(this,"_cameraStack",[]);u(this,"_onBeforeRenderListeners",new Map);u(this,"_onAfterRenderListeners",new Map);u(this,"_requireDepthTexture",!1);u(this,"_requireColorTexture",!1);u(this,"_renderTarget");u(this,"_isRendering",!1);u(this,"_accumulatedTime",0);u(this,"_framerateClock",new K_);u(this,"_dispatchReadyAfterFrame",!1);u(this,"_wasPaused",!1);var s,r;if(this.name=(e==null?void 0:e.name)||"",this.alias=e==null?void 0:e.alias,this.domElement=(e==null?void 0:e.domElement)||document.body,this.hash=e==null?void 0:e.hash,e!=null&&e.renderer)this.renderer=e.renderer,this.isManagedExternally=!0;else{const o={antialias:!0},a=(r=(s=e==null?void 0:e.domElement)==null?void 0:s.shadowRoot)==null?void 0:r.querySelector("canvas");a&&(o.canvas=a),this.renderer=new Df(o),this.renderer.toneMappingExposure=1,this.renderer.toneMapping=Ls,this.renderer.setClearColor(new _e("lightgrey"),0),this.renderer.antialias=!0,this.renderer.alpha=!1,this.renderer.shadowMap.enabled=!0,this.renderer.shadowMap.type=ME,this.renderer.setSize(this.domWidth,this.domHeight),this.renderer.outputEncoding=yt,this.renderer.physicallyCorrectLights=!0}this.scene=new Tr,sn.register(this),this.application=new _F(this),this.time=new vO,this.input=new lO(this),this.physics=new AO(this),this.connection=new pL(this),this.assets=new RL,this.sceneLighting=new vF(this),this.addressables=new mF(this),this.lightmaps=new q7(this),this.players=new xF(this);const t=()=>this._sizeChanged=!0;window.addEventListener("resize",t),this._disposeCallbacks.push(()=>window.removeEventListener("resize",t));const i=new ResizeObserver(o=>this._sizeChanged=!0);i.observe(this.domElement),this._disposeCallbacks.push(()=>i.disconnect()),this._intersectionObserver=new IntersectionObserver(o=>{this._isVisible=o[0].isIntersecting}),this._disposeCallbacks.push(()=>{var o;return(o=this._intersectionObserver)==null?void 0:o.disconnect()})}get version(){return gL}static get Current(){return sn.Current}static set Current(e){sn.Current=e}get resolutionScaleFactor(){return this._resolutionScaleFactor}set resolutionScaleFactor(e){if(e!==this._resolutionScaleFactor&&typeof e=="number"){if(e<=0){console.error("Invalid resolution scale factor",e);return}this._resolutionScaleFactor=e,this.updateSize()}}calculateBoundingClientRect(){if(this.isInAR){this._domX=0,this._domY=0;return}this._boundingClientRectFrame!==this.time.frame&&(this._boundingClientRectFrame=this.time.frame,this._boundingClientRect=this.domElement.getBoundingClientRect(),this._domX=this._boundingClientRect.x,this._domY=this._boundingClientRect.y)}get domWidth(){return this.isInAR?window.innerWidth:this.domElement.clientWidth}get domHeight(){return this.isInAR?window.innerHeight:this.domElement.clientHeight}get domX(){return this.calculateBoundingClientRect(),this._domX}get domY(){return this.calculateBoundingClientRect(),this._domY}get isInXR(){var e;return((e=this.renderer.xr)==null?void 0:e.isPresenting)||!1}get isInVR(){return this.xrSessionMode==="immersive-vr"}get isInAR(){return this.xrSessionMode==="immersive-ar"}get xrSession(){var e;return(e=this.renderer.xr)==null?void 0:e.getSession()}get xrFrame(){return this._xrFrame}get arOverlayElement(){const e=this.domElement;return typeof e.getAROverlayContainer=="function"?e.getAROverlayContainer():this.domElement}get currentFrameEvent(){return this._currentFrameEvent}get mainCamera(){if(this.mainCameraComponent){const e=this.mainCameraComponent;return e.cam||e.buildCamera(),e.cam}return null}get rendererData(){return this.sceneLighting}get isCreated(){return this._isCreated}internalOnUpdateVisible(){var e,t;(e=this._intersectionObserver)==null||e.disconnect(),(t=this._intersectionObserver)==null||t.observe(this.domElement)}updateSize(){var e,t,i;if(!this.isManagedExternally&&((e=this.renderer.xr)==null?void 0:e.isPresenting)===!1){this._sizeChanged=!1;const s=this.resolutionScaleFactor,r=this.domWidth*s,o=this.domHeight*s,a=this.mainCamera;this.updateAspect(a),this.renderer.setSize(r,o),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.domElement.style.width="100%",this.renderer.domElement.style.height="100%",this.composer&&((t=this.composer.setSize)==null||t.call(this.composer,r,o),"setPixelRatio"in this.composer&&typeof this.composer.setPixelRatio=="function"&&((i=this.composer.setPixelRatio)==null||i.call(this.composer,window.devicePixelRatio)))}}updateAspect(e,t,i){if(!e)return;t===void 0&&(t=this.domWidth),i===void 0&&(i=this.domHeight);const s=e.aspect;e.aspect=t/i,s!==e.aspect&&e.updateProjectionMatrix()}async onCreate(e,t){try{return this._isCreating=!0,await this.internalOnCreate(e,t)}finally{this._isCreating=!1}}clear(){var e;(e=this.scene)!=null&&e.children.length&&(kl(this.scene,!0,!0),this.scene=new Tr),this.renderer&&(this.renderer.setClearAlpha(0),this.renderer.clear())}dispose(){this.internalOnDestroy()}onDestroy(){this.internalOnDestroy()}internalOnDestroy(){var e,t,i;this.clear(),(e=this.renderer)==null||e.setAnimationLoop(null),this.isManagedExternally||(t=this.renderer)==null||t.dispose();for(const s of this._disposeCallbacks)try{s()}catch(r){console.error("Error in on dispose callback:",r,s)}(i=this.domElement)!=null&&i.parentElement&&this.domElement.parentElement.removeChild(this.domElement),sn.dispatchCallback(to.ContextDestroyed,this),sn.unregister(this)}registerCoroutineUpdate(e,t,i){return this.coroutines[i]||(this.coroutines[i]=[]),this.coroutines[i].push({comp:e,main:t}),t}unregisterCoroutineUpdate(e,t){if(!this.coroutines[t])return;const i=this.coroutines[t].findIndex(s=>s.main===e);i>=0&&this.coroutines[t].splice(i,1)}stopAllCoroutinesFrom(e){for(const t in this.coroutines){const i=this.coroutines[t];for(let s=i.length-1;s>=0;s--)i[s].comp===e&&i.splice(s,1)}}setCurrentCamera(e){var s;if(!e)return;if(e.cam||e.buildCamera(),!e.cam){console.warn("Camera component is missing camera",e);return}const t=this._cameraStack.indexOf(e);t>=0&&this._cameraStack.splice(t,1),this._cameraStack.push(e),this.mainCameraComponent=e;const i=e.cam;i.isPerspectiveCamera&&this.updateAspect(i),(s=this.mainCameraComponent)==null||s.applyClearFlagsIfIsActiveCamera()}removeCamera(e){if(!e)return;const t=this._cameraStack.indexOf(e);if(t>=0&&this._cameraStack.splice(t,1),this.mainCameraComponent===e&&(this.mainCameraComponent=void 0,this._cameraStack.length>0)){const i=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(i)}}addBeforeRenderListener(e,t){var i;this._onBeforeRenderListeners.has(e.uuid)||(this._onBeforeRenderListeners.set(e.uuid,[]),e.onBeforeRender=this._createRenderCallbackWrapper(e,this._onBeforeRenderListeners)),(i=this._onBeforeRenderListeners.get(e.uuid))==null||i.push(t)}removeBeforeRenderListener(e,t){if(this._onBeforeRenderListeners.has(e.uuid)){const i=this._onBeforeRenderListeners.get(e.uuid),s=i.indexOf(t);s>=0&&i.splice(s,1)}}addAfterRenderListener(e,t){var i;this._onAfterRenderListeners.has(e.uuid)||(this._onAfterRenderListeners.set(e.uuid,[]),e.onAfterRender=this._createRenderCallbackWrapper(e,this._onAfterRenderListeners)),(i=this._onAfterRenderListeners.get(e.uuid))==null||i.push(t)}removeAfterRenderListener(e,t){if(this._onAfterRenderListeners.has(e.uuid)){const i=this._onAfterRenderListeners.get(e.uuid),s=i.indexOf(t);s>=0&&i.splice(s,1)}}_createRenderCallbackWrapper(e,t){return(i,s,r,o,a,l)=>{const c=t.get(e.uuid);if(c)for(let h=0;h<c.length;h++){const d=c[h];d(i,s,r,o,a,l)}}}get isRendering(){return this._isRendering}setRequireDepth(e){this._requireDepthTexture=e}setRequireColor(e){this._requireColorTexture=e}get depthTexture(){var e;return((e=this._renderTarget)==null?void 0:e.depthTexture)||null}get opaqueColorTexture(){var e;return((e=this._renderTarget)==null?void 0:e.texture)||null}get isVisibleToUser(){if(this.isInXR)return!0;if(!this._isVisible)return!1;const e=getComputedStyle(this.domElement);return e.visibility!=="hidden"&&e.display!=="none"&&e.opacity!=="0"}async internalOnCreate(e,t){var s;this.clear(),(s=this.renderer)==null||s.setAnimationLoop(null),await jm(1),_t.Current=this,await sn.dispatchCallback(to.ContextCreationStart,this);let i=!0;try{_t.Current=this,e&&await e(this,t)}catch(r){console.error(r),i=!1}if(!i)return!1;this.internalOnUpdateVisible(),!this.isManagedExternally&&!this.domElement.shadowRoot&&this.domElement.prepend(this.renderer.domElement),_t.Current=this,_t.Current=this;for(let r=0;r<this.new_scripts.length;r++){const o=this.new_scripts[r];if(o.gameObject!==void 0&&o.gameObject!==null){o.gameObject.userData===void 0&&(o.gameObject.userData={}),o.gameObject.userData.components===void 0&&(o.gameObject.userData.components=[]);const a=o.gameObject.userData.components;a.includes(o)||a.push(o)}}if(this.post_setup_callbacks)for(let r=0;r<this.post_setup_callbacks.length;r++)_t.Current=this,await this.post_setup_callbacks[r](this);if(!this.mainCamera){_t.Current=this;let r=null;Au(this.scene,o=>{const a=o;if(a!=null&&a.isCamera){if(kg(a.gameObject),!a.activeAndEnabled)return;if(a.tag==="MainCamera")return r=a,!0;r=a}}),r?this.setCurrentCamera(r):!sn.dispatchCallback(to.MissingCamera,this)&&!this.mainCamera&&!this.isManagedExternally&&console.warn("Missing camera in main scene",this)}if(_t.Current=this,q0(this),!this.isManagedExternally&&this.composer&&this.mainCamera){const r=new bb(this.scene,this.mainCamera);this.renderer.setSize(this.domWidth,this.domHeight),this.composer.addPass(r),this.composer.setSize(this.domWidth,this.domHeight)}return this._sizeChanged=!0,this._stats&&(this._stats.showPanel(1),this.domElement.appendChild(this._stats.dom)),bw&&Q0(this.scene,!0),this._isCreating=!1,this.restartRenderLoop(),this._dispatchReadyAfterFrame=!0,sn.dispatchCallback(to.ContextCreated,this)}restartRenderLoop(){if(!this.renderer)return console.error("Can not start render loop without renderer"),!1;if(this._isCreating)return console.warn("Can not start render loop while creating context"),!1;const e=this.render.bind(this);return this.renderer.setAnimationLoop(e),!0}render(e,t){if(Qs()||bw||TW())try{this.internalRender(e,t)}catch(i){(Qs()||bw)&&i instanceof Error&&jn("Exception during render-loop.<br/>See console for details.",Uo.Error),console.error(i),console.warn("Stopping render loop due to error"),this.renderer.setAnimationLoop(null),this.domElement.dispatchEvent(new CustomEvent("error",{detail:i}))}else this.internalRender(e,t)}internalRender(e,t){var i,s;if(this._xrFrame=t,this._currentFrameEvent=-1,this.isInXR===!1&&this.targetFrameRate!==void 0){if(this._accumulatedTime+=this._framerateClock.getDelta(),this._accumulatedTime<1/this.targetFrameRate)return;this._accumulatedTime=0}if((i=this._stats)==null||i.begin(),_t.Current=this,!this.onHandlePaused()){for(_t.Current=this,this.time.update(),K7&&console.log("FPS",this.time.smoothedFps.toFixed(0)),q0(this),e0(this.scene),VL(this);this._cameraStack.length>0&&(!this.mainCameraComponent||this.mainCameraComponent.destroyed);){this._cameraStack.splice(this._cameraStack.length-1,1);const r=this._cameraStack[this._cameraStack.length-1];this.setCurrentCamera(r)}if(this.pre_update_callbacks)for(const r in this.pre_update_callbacks)this.pre_update_callbacks[r]();this._currentFrameEvent=0;for(let r=0;r<this.scripts_earlyUpdate.length;r++){const o=this.scripts_earlyUpdate[r];o.activeAndEnabled&&o.earlyUpdate!==void 0&&(_t.Current=this,o.earlyUpdate())}if(this.executeCoroutines(0),!this.onHandlePaused()){this._currentFrameEvent=1;for(let r=0;r<this.scripts_update.length;r++){const o=this.scripts_update[r];o.activeAndEnabled&&o.update!==void 0&&(_t.Current=this,o.update())}if(this.executeCoroutines(1),!this.onHandlePaused()){this._currentFrameEvent=2;for(let r=0;r<this.scripts_lateUpdate.length;r++){const o=this.scripts_lateUpdate[r];o.activeAndEnabled&&o.lateUpdate!==void 0&&(_t.Current=this,o.lateUpdate())}if(this.executeCoroutines(2),!this.onHandlePaused()){if(this.physics.engine){const o=this.time.deltaTime/1;for(let a=0;a<1;a++)this._currentFrameEvent=9,this.executeCoroutines(9),this.physics.engine.step(o),this._currentFrameEvent=10,this.executeCoroutines(10);this.physics.engine.postStep()}if(!this.onHandlePaused()){if(this.isVisibleToUser){this._currentFrameEvent=3;for(let r=0;r<this.scripts_onBeforeRender.length;r++){const o=this.scripts_onBeforeRender[r];o.activeAndEnabled&&o.onBeforeRender!==void 0&&(_t.Current=this,o.onBeforeRender(t))}if(this.executeCoroutines(3),this._sizeChanged&&this.updateSize(),this.pre_render_callbacks)for(const r in this.pre_render_callbacks)this.pre_render_callbacks[r]();this.isManagedExternally||(BW(this),this._currentFrameEvent=-1,this.renderNow(),this._currentFrameEvent=4);for(let r=0;r<this.scripts_onAfterRender.length;r++){const o=this.scripts_onAfterRender[r];o.activeAndEnabled&&o.onAfterRender!==void 0&&(_t.Current=this,o.onAfterRender())}if(this.executeCoroutines(4),this.post_render_callbacks)for(const r in this.post_render_callbacks)this.post_render_callbacks[r]()}this._currentFrameEvent=-1,this.connection.sendBufferedMessagesNow(),(s=this._stats)==null||s.end(),this._dispatchReadyAfterFrame&&(this._dispatchReadyAfterFrame=!1,this.domElement.dispatchEvent(new CustomEvent("ready")))}}}}}}renderNow(e){return!e&&(e=this.mainCamera,!e)?!1:(this._isRendering=!0,this.renderRequiredTextures(),this.composer&&!this.isInXR?this.composer.render(this.time.deltaTime):e&&this.renderer.render(this.scene,e),this._isRendering=!1,!0)}onHandlePaused(){const e=this.evaluatePaused();if(this._wasPaused!==e){J7&&console.log("Paused?",e,"context:"+this.alias);for(let t=0;t<this.scripts_pausedChanged.length;t++){const i=this.scripts_pausedChanged[t];i.activeAndEnabled&&i.onPausedChanged!==void 0&&(_t.Current=this,i.onPausedChanged(e,this._wasPaused))}}return this._wasPaused=e,e}evaluatePaused(){return this.isInXR?!1:this.isPaused?!0:this.runInBackground?!1:!this.isVisibleToUser}renderRequiredTextures(){if(!this.mainCamera||!this._requireDepthTexture&&!this._requireColorTexture)return;if(!this._renderTarget){if(this._renderTarget=new ai(this.domWidth,this.domHeight),this._requireDepthTexture){const i=new U_(this.domWidth,this.domHeight);this._renderTarget.depthTexture=i}this._requireColorTexture&&(this._renderTarget.texture=new Gt,this._renderTarget.texture.generateMipmaps=!1,this._renderTarget.texture.minFilter=ti,this._renderTarget.texture.magFilter=ti,this._renderTarget.texture.format=Ti)}const e=this._renderTarget;e.texture&&(e.texture.encoding=this.renderer.outputEncoding);const t=this.renderer.getRenderTarget();this.renderer.setRenderTarget(e),this.renderer.render(this.scene,this.mainCamera),this.renderer.setRenderTarget(t)}executeCoroutines(e){if(this.coroutines[e]){const i=this.coroutines[e];for(let s=0;s<i.length;s++)try{const r=i[s];if(!r.comp||r.comp.destroyed||!r.main||r.comp.enabled===!1){Z7&&console.log("Removing coroutine",r.comp,r.comp.enabled),i.splice(s,1),--s;continue}const a=r.chained;if(a&&a.length>0){const d=a[a.length-1].next();if(d.done&&a.pop(),t(d)&&(r.chained||(r.chained=[]),r.chained.push(d.value)),!d.done)continue}const l=r.main.next();if(l.done===!0){i.splice(s,1),--s;continue}const c=l.value;if(t(c)){if(c.next().done)continue;r.chained||(r.chained=[]),r.chained.push(c)}}catch(r){console.error(r)}}function t(i){return!!(i&&i.next&&i.return)}}}const tq=le("debugaroverlay"),Hh="ar",PR="quit-ar";class iq{constructor(){u(this,"arContainer",null);u(this,"closeARCallback");u(this,"currentSession",null);u(this,"registeredCloseEventElements",[]);u(this,"_createdAROnlyElements",[]);u(this,"_reparentedObjects",[]);this.closeARCallback=this.onRequestedEndAR.bind(this)}get ARContainer(){return this.arContainer}requestEndAR(){this.onRequestedEndAR()}onBegin(e,t,i){this.currentSession=i,this.arContainer=t,e.domElement.querySelectorAll(`.${Hh}`).forEach(o=>{var a;o&&o!==this.arContainer&&(this._reparentedObjects.push({el:o,previousParent:o.parentElement}),(a=this.arContainer)==null||a.appendChild(o))});const r=t.getElementsByClassName(PR);if(!r||r.length<=0)console.warn(`Missing quit AR elements, creating fallback X button. Use class name '${PR}' to override.`),this.createFallbackCloseARButton(this.arContainer);else for(let o=0;o<r.length;o++){const a=r[o];a&&(a.addEventListener("click",this.closeARCallback),this.registeredCloseEventElements.push(a))}}onEnd(e){var t;for(const i of this._createdAROnlyElements)i.remove&&i.remove();for(const i of this._reparentedObjects){const s=i.el;(t=i.previousParent)==null||t.appendChild(s)}this._reparentedObjects.length=0,EE()&&setTimeout(()=>{const i=e.renderer.domElement;i&&e.domElement.insertBefore(i,e.domElement.firstChild);const s=document.querySelectorAll("*");for(var r=0;r<s.length;r++){const o=s[r];o&&o._displayChanged!==void 0&&o._displayWas!==void 0&&(o.style.display=o._displayWas)}},10)}findOrCreateARContainer(e){if(e.classList.contains(Hh))return e;if(e.children)for(let s=0;s<e.children.length;s++){const r=e.children[s];if(!(!r||!r.classList)&&r.classList.contains(Hh))return r}const t=document.getElementsByClassName(Hh);if(t&&t.length>0)return t[0];tq&&console.log("No overlay container found in document - generating new ony");const i=document.createElement("div");return i.classList.add(Hh),i.style.position="absolute",i.style.width="100%",i.style.height="100%",i.style.display="flex",i.style.visibility="visible",e.appendChild(i)}onRequestedEndAR(){if(this.currentSession){this.currentSession.end(),this.currentSession=null;for(const e of this.registeredCloseEventElements)e.removeEventListener("click",this.closeARCallback);this.registeredCloseEventElements.length=0}}createFallbackCloseARButton(e){var t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttribute("width","38px"),t.setAttribute("height","38px"),t.style.position="absolute",t.style.right="20px",t.style.top="40px",t.style.zIndex="9999",t.style.pointerEvents="auto",t.addEventListener("click",this.closeARCallback),e.appendChild(t),this._createdAROnlyElements.push(t);var i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d","M 12,12 L 28,28 M 28,12 12,28"),i.setAttribute("stroke","#ddd"),i.setAttribute("stroke-width","3px"),t.appendChild(i),this._createdAROnlyElements.push(i)}}class $ extends Ie{constructor(){super(...arguments);u(this,"guid")}static isDestroyed(t){return D1(t)}static setActive(t,i,s=!0){t&&(Dg(t,i),e0(t),i&&s&&VL(_t.Current,t))}static isActiveSelf(t){return Wf(t)}static isActiveInHierarchy(t){return FL(t)}static markAsInstancedRendered(t,i){UL(t,i)}static isUsingInstancing(t){return vb(t)}static foreachComponent(t,i,s=!0){return Au(t,i,s)}static instantiateSynced(t,i){return t?T1(t,i):null}static instantiate(t,i=null){return AA(t,i)}static destroySynced(t,i,s=!0){if(!t)return;const r=t;i=i??_t.Current,fb(r,i.connection,s)}static destroy(t,i=!0,s=!0){return kl(t,i,s)}static add(t,i,s){if(!(!t||!i)){if(t===i){console.warn("Can not add object to self",t);return}s||(s=_t.Current),i.add(t),Dg(t,!0),e0(t),s?$.foreachComponent(t,r=>{O1(r,s),!r.__internalDidAwakeAndStart&&s.new_script_start.includes(r)===!1&&s.new_script_start.push(r)},!0):console.warn("Missing context")}}static remove(t){var i;t&&((i=t.parent)==null||i.remove(t),Dg(t,!1),e0(t),$.foreachComponent(t,s=>{PW(s)},!0))}static invokeOnChildren(t,i,...s){this.invoke(t,i,!0,s)}static invoke(t,i,s=!1,...r){t&&this.foreachComponent(t,o=>{const a=o[i];a&&typeof a=="function"&&(a==null||a.call(o,...r))},s)}static addNewComponent(t,i,s=!0){const r=new i;return Iu(t,r,s),r}static addComponent(t,i){return this.moveComponent(t,i)}static moveComponent(t,i){return R1(t,i)}static removeComponent(t){return P1(t.gameObject,t),t}static getOrAddComponent(t,i){return gb(t,i)}static getComponent(t,i){return t===null?null:Vf(t,i)}static getComponents(t,i,s=null){return t===null?s??[]:pA(t,i,s)}static findByGuid(t,i){return mA(t,i)}static findObjectOfType(t,i,s=!0){return ML(t,i??_t.Current,s)}static findObjectsOfType(t,i){const s=[];return TL(t,s,i),s}static getComponentInChildren(t,i){return jf(t,i)}static getComponentsInChildren(t,i,s=null){return gA(t,i,s??void 0)}static getComponentInParent(t,i){return Am(t,i)}static getComponentsInParent(t,i,s=null){return mb(t,i,s)}static getAllComponents(t){var r;return[...(r=t.userData)==null?void 0:r.components]}static*iterateComponents(t){var s;const i=(s=t==null?void 0:t.userData)==null?void 0:s.components;if(i&&Array.isArray(i))for(let r=0;r<i.length;r++)yield i[r]}}var Xi;let sh=(Xi=class{constructor(){u(this,"__context");u(this,"__name");u(this,"gameObject");u(this,"guid","invalid");u(this,"sourceId");u(this,"__didAwake",!1);u(this,"__didStart",!1);u(this,"__didEnable",!1);u(this,"__isEnabled");u(this,"__destroyed",!1);u(this,"_worldPosition");u(this,"_worldQuaternion");u(this,"_worldEuler");u(this,"_worldRotation");u(this,"_eventListeners",new Map);this.__internalNewInstanceCreated()}get isComponent(){return!0}get context(){return this.__context??_t.Current}set context(e){this.__context=e}get scene(){return this.context.scene}get layer(){var e,t;return(t=(e=this.gameObject)==null?void 0:e.userData)==null?void 0:t.layer}get name(){var e,t;return(e=this.gameObject)!=null&&e.name?this.gameObject.name:(t=this.gameObject)==null?void 0:t.userData.name}set name(e){this.gameObject?(this.gameObject.userData||(this.gameObject.userData={}),this.gameObject.userData.name=e,this.__name=e):this.__name=e}get tag(){var e;return(e=this.gameObject)==null?void 0:e.userData.tag}set tag(e){this.gameObject&&(this.gameObject.userData.tag=e)}get static(){var e;return(e=this.gameObject)==null?void 0:e.userData.static}get hideFlags(){var e;return(e=this.gameObject)==null?void 0:e.userData.hideFlags}get activeAndEnabled(){return!(this.destroyed||this.__isEnabled===!1||!this.__isActiveInHierarchy)}get __isActive(){return this.gameObject.visible}get __isActiveInHierarchy(){if(!this.gameObject)return!1;const e=this.gameObject[Ml];return e===void 0?!0:e}set __isActiveInHierarchy(e){this.gameObject&&(this.gameObject[Ml]=e)}awake(){}onEnable(){}onDisable(){}onDestroy(){this.__destroyed=!0}startCoroutine(e,t=Rr.Update){return this.context.registerCoroutineUpdate(this,e,t)}stopCoroutine(e,t=Rr.Update){this.context.unregisterCoroutineUpdate(e,t)}get destroyed(){return this.__destroyed}destroy(){this.__destroyed||this.__internalDestroy()}get __internalDidAwakeAndStart(){return this.__didAwake&&this.__didStart}__internalNewInstanceCreated(){this.__didAwake=!1,this.__didStart=!1,this.__didEnable=!1,this.__isEnabled=void 0,this.__destroyed=!1}__internalAwake(){this.__didAwake||(this.__didAwake=!0,this.awake())}__internalStart(){this.__didStart||(this.__didStart=!0,this.start&&this.start())}__internalEnable(e){return this.__destroyed?(Qs()&&console.warn("[Needle Engine Dev] Trying to enable destroyed component"),!1):this.__didAwake?this.__didEnable?(e!==!0&&(this.__isEnabled=!0),!1):(this.__didEnable=!0,this.__isEnabled=!0,this.onEnable(),!0):!1}__internalDisable(e){if(this.__didAwake){if(!this.__didEnable){e!==!0&&(this.__isEnabled=!1);return}this.__didEnable=!1,this.__isEnabled=!1,this.onDisable()}}__internalDestroy(){var e;this.__destroyed||(this.__destroyed=!0,(e=this.destroy)==null||e.call(this),this.dispatchEvent(new CustomEvent("destroyed",{detail:this})),EL(this))}get enabled(){return typeof this.__isEnabled=="boolean"?this.__isEnabled:!0}set enabled(e){if(this.__destroyed){Qs()&&console.warn(`[Needle Engine Dev] Trying to ${e?"enable":"disable"} destroyed component`);return}if(typeof e=="number"&&(e>=.5?e=!0:e=!1),!this.__didAwake){this.__isEnabled=e;return}e?this.__internalEnable():this.__internalDisable()}get worldPosition(){return this._worldPosition||(this._worldPosition=new S),wt(this.gameObject,this._worldPosition),this._worldPosition}set worldPosition(e){ln(this.gameObject,e)}setWorldPosition(e,t,i){Xi._worldPositionBuffer.set(e,t,i),this.worldPosition=Xi._worldPositionBuffer}get worldQuaternion(){return this._worldQuaternion||(this._worldQuaternion=new xe),Dn(this.gameObject,this._worldQuaternion)}set worldQuaternion(e){cr(this.gameObject,e)}setWorldQuaternion(e,t,i,s){Xi._worldQuaternionBuffer.set(e,t,i,s),this.worldQuaternion=Xi._worldQuaternionBuffer}get worldEuler(){return this._worldEuler||(this._worldEuler=new bn),this._worldEuler.setFromQuaternion(this.worldQuaternion),this._worldEuler}set worldEuler(e){var t;this._worldQuaternion||(this._worldQuaternion=new xe),(t=this._worldQuaternion)==null||t.setFromEuler(e),this.worldQuaternion=this._worldQuaternion}get worldRotation(){const e=this.worldEuler;this._worldRotation||(this._worldRotation=new S);const t=this._worldRotation;return t.set(e.x,e.y,e.z),t.x=Ze.toDegrees(t.x),t.y=Ze.toDegrees(t.y),t.z=Ze.toDegrees(t.z),t}set worldRotation(e){this.setWorldRotation(e.x,e.y,e.z,!0)}setWorldRotation(e,t,i,s=!0){s&&(e=Ze.toRadians(e),t=Ze.toRadians(t),i=Ze.toRadians(i)),Xi._worldEulerBuffer.set(e,t,i),Xi._worldQuaternionBuffer.setFromEuler(Xi._worldEulerBuffer),this.worldQuaternion=Xi._worldQuaternionBuffer}get forward(){return Xi._forward.set(0,0,-1).applyQuaternion(this.worldQuaternion)}get right(){return Xi._right.set(1,0,0).applyQuaternion(this.worldQuaternion)}get up(){return Xi._up.set(0,1,0).applyQuaternion(this.worldQuaternion)}addEventListener(e,t){this._eventListeners[e]=this._eventListeners[e]||[],this._eventListeners[e].push(t)}removeEventListener(e,t){if(!this._eventListeners[e])return;const i=this._eventListeners[e].indexOf(t);i>=0&&this._eventListeners[e].splice(i,1)}dispatchEvent(e){if(!this._eventListeners[e.type])return!1;const t=this._eventListeners[e.type];for(let i=0;i<t.length;i++)t[i](e);return!1}},u(Xi,"_worldPositionBuffer",new S),u(Xi,"_worldQuaternionBuffer",new xe),u(Xi,"_worldEulerBuffer",new bn),u(Xi,"_tempQuaternionBuffer2",new xe),u(Xi,"_forward",new S),u(Xi,"_right",new S),u(Xi,"_up",new S),Xi);class Ce extends sh{}const nq=Object.freeze(Object.defineProperty({__proto__:null,Behaviour:Ce,Component:sh,GameObject:$},Symbol.toStringTag,{value:"Module"})),sq='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 160 187.74"><defs><linearGradient id="a" x1="89.64" y1="184.81" x2="90.48" y2="21.85" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#62d399"/><stop offset=".51" stop-color="#acd842"/><stop offset=".9" stop-color="#d7db0a"/></linearGradient><linearGradient id="b" x1="69.68" y1="178.9" x2="68.08" y2="16.77" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#0ba398"/><stop offset=".5" stop-color="#4ca352"/><stop offset="1" stop-color="#76a30a"/></linearGradient><linearGradient id="c" x1="36.6" y1="152.17" x2="34.7" y2="84.19" gradientUnits="userSpaceOnUse"><stop offset=".19" stop-color="#36a382"/><stop offset=".54" stop-color="#49a459"/><stop offset="1" stop-color="#76a30b"/></linearGradient><linearGradient id="d" x1="15.82" y1="153.24" x2="18" y2="90.86" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#267880"/><stop offset=".51" stop-color="#457a5c"/><stop offset="1" stop-color="#717516"/></linearGradient><linearGradient id="e" x1="135.08" y1="135.43" x2="148.93" y2="63.47" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#b0d939"/><stop offset="1" stop-color="#eadb04"/></linearGradient><linearGradient id="f" x1="-4163.25" y1="2285.12" x2="-4160.81" y2="2215.34" gradientTransform="rotate(20 4088.49 13316.712)" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#74af52"/><stop offset=".48" stop-color="#99be32"/><stop offset="1" stop-color="#c0c40a"/></linearGradient><symbol id="g" viewBox="0 0 160 187.74"><path style="fill:url(#a)" d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75z"/><path style="fill:url(#b)" d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98z"/><path style="fill:url(#c)" d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z"/><path style="fill:url(#d)" d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04z"/><path style="fill:#9c3" d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5z"/><path style="fill:url(#e)" d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59z"/><path style="fill:url(#f)" d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z"/><path style="fill:#ffe113" d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1z"/><path style="fill:#f3e600" d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75z"/></symbol></defs><use width="160" height="187.74" xlink:href="#g"/></svg>',rq=new Blob([sq],{type:"image/svg+xml;charset=utf-8"}),oq=URL.createObjectURL(rq),wF=oq,eu=le("debuglicense"),V1="basic";eu&&console.log("License Type: "+V1);function Gc(){switch(V1){case"pro":case"enterprise":return!0}return!1}function CF(){switch(V1){case"indie":return!0}return!1}function SF(){return Gc()||CF()}sn.registerCallback(to.ContextRegistered,n=>{aq(n.context)});async function aq(n){try{if(Gc()!==!0)return xw(n)}catch(e){return eu&&console.log("License check failed",e),xw(n)}eu&&xw(n)}const EF="needle-license-element",DS=5e3,kS=200;function xw(n){cq(),n.domElement.addEventListener("ready",()=>{setTimeout(()=>{lq(n)},1e3)}),dq()}function lq(n){const e=hq(),t=uq(),i=setInterval(()=>{if(!e)return;const l=n.domElement.shadowRoot||n.domElement;e.parentNode!==l&&(l.appendChild(e),t&&l.appendChild(t))},100);let s=`<img class="logo" src="${wF}" style="width: 40px; height: 40px; margin-right: 2px; vertical-align: middle; margin-bottom: 2px;"/>`;const r=document.createElement("div");r.innerHTML=s,r.classList.add("logo"),e.appendChild(r);const o=document.createElement("div");o.classList.add("text"),e.appendChild(o),e.title="Needle Engine",SF()||(e.title+=" non commercial version"),e.addEventListener("click",()=>{globalThis.open("https://needle.tools","_blank")});const a=DS+kS;setTimeout(()=>{clearInterval(i),e==null||e.remove(),t==null||t.remove()},a)}let RR=0;async function cq(n){const e=Date.now();if(e-RR<2e3)return;RR=e;const i=`
|
|
3837
3837
|
font-size: 18px;
|
|
3838
3838
|
background-size: 20px;
|
|
3839
3839
|
background-position: left top;
|
|
@@ -4558,7 +4558,7 @@ void main() {
|
|
|
4558
4558
|
`){super("lineBreak",e,!0),this._newLineBreakability=null}update(e,t){this._needsProcess=!0}process(e){const t=e._whiteSpace._newLineBreakability;if(e._inlines._value)for(let i=0;i<e._inlines._value.length;i++){const s=e._inlines._value[i],r=s.char;let o=null;r!==void 0&&(t!=="nowrap"&&(this._value.includes(r)||r.match(/\s/g))&&(o="possible"),r.match(/\n/g)&&(o=t)),s.lineBreak=o}}get value(){return this._value}}class $U extends ui{constructor(){super("layouter",null,!1),this._value=null}update(e,t){this._value=e._parent.find(i=>i.isUI&&i.isText),this._needsProcess=!0}process(e){this._value&&(this._value._layouter._needsProcess=!0)}}class R$ extends Im{constructor(e){super("backgroundColor",e,!1),this._allowsInherit=!1,this._input=0}computeOutputValue(e){this._input==="inherit"?this._value.set(this.getInheritedInput(e)):this._value.set(this._input)}}class eN extends tU{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class tN extends iU{constructor(){super()}computeOutputValue(e){const t=this.getInheritedInput(e),i=B$[t];i?this._value=i:this._value=t}}const B$={light:"100",normal:"400",bold:"700",bolder:"900"};class iN extends cU{constructor(){super("fontFamily","inherit",!0),this._input="inherit",this._needsUpdate=!0,this._allowsInherit=!1}computeOutputValue(e){let t=this._inheritedInput;if(t==="inherit"&&(t=this.getInheritedInput(e)),t instanceof kb)this._value=t,e._font._needsUpdate=!0;else if(typeof t=="string"){const i=yu.getFontFamily(t);i?(this._value=i,e._font._needsUpdate=!0):console.warn(`(.style) fontFamily, the font '${t}' is not registered. Aborted.`)}else console.warn("(.style) fontFamily requires a registered fontFamily instance, or the id of a registered fontFamily."),console.warn("If you want to set a specific font, please use .font property instead.")}get value(){return this._value}}class jI extends uU{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited,this._whiteSpacedContent="",this._stringCollapser=this.emptyStrategyLogic,this._inlineCollapser=this.emptyStrategyLogic,this._inlineWrapper=this.emptyStrategyLogic}_computeFromInherited(e){switch(super._computeFromInherited(e),this._newLineBreakability=D$(this._value),this._value){case"nowrap":case"normal":this._stringCollapser=k$;break;case"pre-line":this._stringCollapser=nN;break;default:this._stringCollapser=O$}switch(this._value){case"pre-line":case"nowrap":case"normal":this._inlineCollapser=z$;break;case"pre-wrap":this._inlineCollapser=N$;break;default:this._inlineCollapser=G$}switch(this._value){case"pre-line":case"pre-wrap":case"normal":this._inlineWrapper=L$;break;case"pre":this._inlineWrapper=F$;break;default:this._inlineWrapper=U$}this._needsProcess=!0}process(e){e.isInline&&!e.isInlineBlock&&(this._whiteSpacedContent=this._stringCollapser(e._textContent._value),e._glyphs._needsProcess=!0)}}const kB={" ":" ","\n":`
|
|
4559
4559
|
`,"\r":"\r"," ":" "},D$=function(n){switch(n){case"pre":case"pre-wrap":case"pre-line":return"mandatory"}return null};function k$(n){return nN(n.replace(/\n/g," "))}function nN(n){return n.replace(/[ ]{2,}/g," ")}function O$(n){return n}function L$(n,e,t,i){const s=n[e];if(s.lineBreak==="mandatory"||t+s.xadvance+s.xoffset+s.kerning>i.INNER_WIDTH)return!0;const r=oN(n,e,i);return Q$(n[e-1],t,r,i)}function F$(n,e,t,i){return n[e].lineBreak==="mandatory"}function U$(){return!1}function N$(n){if(!n[0])return 0;const e=n[0],t=n[n.length-1];return e.char&&e.char===`
|
|
4560
4560
|
`&&n.length>1&&rN([e],n[1]),t.char&&t.char===`
|
|
4561
|
-
`&&n.length>1&&sN([t],n[n.length-2]),e.offsetX}function z$(n){if(!n[0])return 0;let e=[],t;for(let i=0;i<n.length;i++){const s=n[i];if(s.char&&kB[s.char]&&n.length>i){e.push(s),t=n[i+1];continue}break}rN(e,t),e=[],t=null;for(let i=n.length-1;i>0;i--){const s=n[i];if(s.char&&kB[s.char]&&i>0){e.push(s),t=n[i-1];continue}break}return sN(e,t),n[0].offsetX}function G$(n){return n[0]?n[0].offsetX:0}function sN(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX+e.cumulativeWidth,i.cumulativeWidth=0}}function rN(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX,i.cumulativeWidth=0}}function oN(n,e,t,i){if(i=i||0,!n[e])return i;const s=n[e];return s.lineBreak?i+s.xadvance:oN(n,e+1,t,i+s.xadvance+s.xoffset+s.kerning+t.LETTERSPACING)}function Q$(n,e,t,i){return!n||!n.char||e+t<i.INNER_WIDTH?!1:i.BREAKON.indexOf(n.char)>-1}class aN extends dU{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._fontSize._needsProcess=!0,e._layouter._needsProcess=!0}}class lN extends Li{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(e){this._value=this._inheritedInput,e._font._fontVariant&&(e._bounds._needsProcess=!0,e._layouter._needsProcess=!0)}process(e){if(!e._font._fontVariant||!e._font._fontVariant.isReady)return;const t=this._value/e._font._fontVariant.typographic.size,i=e._inlines._value;for(let s=0;s<i.length;s++){const r=i[s];r.resetOffsets(),r.fontSize=this._value,r.fontFactor=t}}get value(){return this._value}}class cN extends fU{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(e,t){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(e)),e._layouter._needsUpdate=!0}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class H$ extends cN{constructor(){super(),this._value="inherit"}}class V$ extends Ob{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._parent._value._layouter._needsProcess=!1}process(e){if(this._value!=="none"){const t=e._whiteSpace._whiteSpacedContent,i=e._inlines._value;for(let s=1;s<i.length;s++){const r=t[s-1]+t[s];i[s].kerning=e._font._fontVariant.getKerningAmount(r)}}}}class hN extends ui{constructor(){super("children",null,!1),this._uis=[]}update(e,t){}process(e){}_compute(e){}dispose(){}}function j$(n,e=!1){const t=n[0].index!==null,i=new Set(Object.keys(n[0].attributes)),s=new Set(Object.keys(n[0].morphAttributes)),r={},o={},a=n[0].morphTargetsRelative,l=new Ke.BufferGeometry;let c=0;for(let h=0;h<n.length;++h){const d=n[h];let f=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const p in d.attributes){if(!i.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;r[p]===void 0&&(r[p]=[]),r[p].push(d.attributes[p]),f++}if(f!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const p in d.morphAttributes){if(!s.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;o[p]===void 0&&(o[p]=[]),o[p].push(d.morphAttributes[p])}if(l.userData.mergedUserData=l.userData.mergedUserData||[],l.userData.mergedUserData.push(d.userData),e){let p;if(t)p=d.index.count;else if(d.attributes.position!==void 0)p=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(c,p,h),c+=p}}if(t){let h=0;const d=[];for(let f=0;f<n.length;++f){const p=n[f].index;for(let g=0;g<p.count;++g)d.push(p.getX(g)+h);h+=n[f].attributes.position.count}l.setIndex(d)}for(const h in r){const d=OB(r[h]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,d)}for(const h in o){const d=o[h][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let f=0;f<d;++f){const p=[];for(let m=0;m<o[h].length;++m)p.push(o[h][m][f]);const g=OB(p);if(!g)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(g)}}return l}function OB(n){let e,t,i,s=0;for(let a=0;a<n.length;++a){const l=n[a];if(l.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(e===void 0&&(e=l.array.constructor),e!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=l.itemSize),t!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(i===void 0&&(i=l.normalized),i!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;s+=l.array.length}const r=new e(s);let o=0;for(let a=0;a<n.length;++a)r.set(n[a].array,o),o+=n[a].array.length;return new Ke.BufferAttribute(r,t,i)}class W$ extends ui{constructor(){super("renderer")}render(e){if(!e._inlines._value||!e._inlines._value.length)return;const t=e._inlines._value.map(s=>e._font._fontVariant.getGeometricGlyph(s,e).translate(s.offsetX,s.offsetY,0)),i=j$(t);e.setFontMesh(new Ke.Mesh(i,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class q$ extends _I{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class If extends RA{constructor(t={}){const i={};If.definePropertiesValues(i,t);super(i,t);u(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0});If.init(this)}add(t){const i=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(i.push(r),r.position.z=.005):console.warn("Block element can only contain Box elements.",r)}return super.add(...i)}set textContent(t){this._textContent.value=t}get textContent(){return this._textContent._value}set invertAlpha(t){this._invertAlpha.value=t}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(t,i){t.children||(t.children=hN),t.textContent||(t.textContent=I$),t.glyphs||(t.glyphs=T$),t.inlines||(t.inlines=M$),t.layouter||(t.layouter=$U),t.renderer||(t.renderer=W$),t.fontFamily||(t.fontFamily=iN),t.fontWeight||(t.fontWeight=tN),t.fontStyle||(t.fontStyle=eN),t.fontSize||(t.fontSize=lN),t.color||(t.color=P$),t.backgroundColor||(t.backgroundColor=R$),t.lineBreak||(t.lineBreak=ZU),t.letterSpacing||(t.letterSpacing=aN),t.whiteSpace||(t.whiteSpace=jI),t.segments||(t.segments=H$),t.textAlign||(t.textAlign=q$),t.fontKerning||(t.fontKerning=V$)}static init(t){Object.defineProperties(t,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class X$ extends eU{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this._needsUpdate=!1;for(let i=e.children.length-1;i>=0;i--){const s=e.children[i];s.isUI&&(e.remove(s),s.clear())}e._children._uis=[],this._value&&e.add(new If({name:"anonymousInline",textContent:this._value}))}}class Y$ extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class J$ extends ui{constructor(){super("layouter",null,!1),this._value=null}update(e,t){}process(e){let t=e._width._value;e._width._auto?t=1/0:t=e._bounds._innerWidth;const i=e._lineHeight._value,s=new Y$(new DB);let r=0;e._children._inlines.forEach(d=>{if(!d._inlines.value)return;this._resetInlines(d);const f=d._fontSize._value,p=d._letterSpacing._value*f,g=d._whiteSpace._value,m=d._lineBreak._value,A={WHITESPACE:g,LETTERSPACING:p,BREAKON:m,INNER_WIDTH:t},v=d._whiteSpace._inlineWrapper;r+=d._margin._value.w+d._padding._value.w,d._inlines.value.forEach((b,y,_)=>{const C=s[s.length-1];if(v(_,y,r,A)){if(s.push(new DB(b)),b.offsetX=b.xoffset,b.width===0){r=0;return}b.cumulativeWidth=b.xadvance+p,r=b.cumulativeWidth;return}s[s.length-1].push(b),b.offsetX=r+b.xoffset+b.kerning,b.cumulativeWidth=b.xadvance+b.kerning+p,r+=b.cumulativeWidth,C.length-1===1&&C[C.length-2].width===0&&(b.offsetX-=b.xoffset,r-=b.xoffset)}),r+=d._margin._value.y+d._padding._value.y});const o=e._whiteSpace._inlineCollapser;let a=0,l=0,c=0;s.forEach((d,f)=>{const p=o(d);let g=0,m=0;if(d.forEach(A=>{g=Math.max(g,A.lineHeight),m=Math.max(m,A.lineBase),A.offsetX-=p}),d.lineHeight=g,d.lineBase=m,f===0?c=-(g*i-g)*.5:c-=s[f-1].lineHeight*i,d.y=c,d.x=0,d.forEach(A=>{A.offsetY=c-A.anchor,A.lineHeight<d.lineHeight&&(A.offsetY-=d.lineBase-A.lineBase)}),l+=d.lineHeight*i,d.width=0,d[0]){const A=d[d.length-1];d.width=A.offsetX+A.cumulativeWidth+A.paddingRight+A.marginRight+d[0].offsetX,a=Math.max(a,d.width)}}),s.height=l,s.width=a,this._value=s,t===1/0&&e._bounds.setChildrenWidth(e,s.width),e._height._auto&&e._bounds.setChildrenHeight(e,s.height);const h=e._parent._value;h&&(h._autoSize._needsProcess=!0,h._flexDirection._needsProcess=!0),e._inlineJustificator._needsProcess=!0,e._textAlign._needsProcess=!0,e._overflow._needsUpdate=!0}_resetInlines(e){e._fontSize.process(e)}}class K$ extends _I{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput,this._needsProcess=!0}process(e){Z$(e),e._renderer._needsRender=!0}}function Z$(n){const e=n._layouter._value,t=n._textAlign._value,i=n._bounds._innerWidth;for(let s=0;s<e.length;s++){const r=e[s],o=$$(n,r,s===e.length-1),a=n._padding._value,l=n._borderWidth._value,c=(-a.w+a.y)/2+(-l.w+l.y)/2;r.x+=o;for(let h=0;h<r.length;h++)r[h].offsetX+=o-c}if(t.indexOf("justify")===0)for(let s=0;s<e.length;s++){const r=e[s];if(t.indexOf("-")!==-1&&s===e.length-1)return;const o=i-r.width;if(o<=0)return;let a=0;for(let d=1;d<r.length-1;d++)a+=r[d].char===" "?1:0;const l=o/a;let c=1;t==="justify-right"&&(r.reverse(),c=-1);let h=0;for(let d=1;d<=r.length-1;d++){const f=r[d];f.offsetX+=h*c,h+=f.char===" "?l:0}t==="justify-right"&&r.reverse()}}function $$(n,e,t){switch(n._textAlign._value){case"justify-left":case"justify":case"left":return-n._bounds._innerWidth/2;case"justify-right":case"right":return-e.width+n._bounds._innerWidth/2;case"center":return-e.width/2;case"justify-center":return t?-e.width/2:-n._bounds._innerWidth/2;default:console.warn(`textAlign: '${n._textAlign._value}' is not valid`)}}class eee extends bI{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput}}class tee extends hU{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class iee extends Ob{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e)}}class nee extends YU{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class see extends ui{constructor(){super("children",null,!1);u(this,"_sortOrder",(t,i)=>t._order._value<i._order._value?-1:t._order._value>i._order._value?1:this._uis.indexOf(t)<this._uis.indexOf(i)?-1:1);this._uis=[],this._inlines=[],this._boxes=[]}update(t,i){this._compute(t),this._needsProcess=!0}process(t){this._compute(t),t._overflow._needsRender=!0}_compute(t){this._uis=t.children.filter(i=>i.visible&&i.isUI),this._inlines=this._uis.filter(i=>i.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class ree extends ui{constructor(){super("autosize")}process(e){if(e._layouter._value&&e._layouter._value.length){const t=e._layouter._value,i=e._padding._value,s=e._borderWidth._value;e._width._auto&&e._bounds.setOffsetWidth(e,t.width+i.w+i.y+s.w+s.y),e._height._auto&&e._bounds.setOffsetHeight(e,t.height+i.x+i.z+s.x+s.z)}}}class oee extends KU{constructor(){super("renderer"),this._needsUpdate=!1}render(e){super.render(e);for(const t of e._children._inlines)t._renderer.render(t);e.performAfterUpdate()}}class Bm extends Pm{constructor(e={},t={}){Bm.definePropertiesValues(t,e),super(t,e),Bm.init(this)}add(e){const t=[];let i=!1;for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(r.isInline&&(i=!0),t.push(r)):console.warn("Block element can only contain Box elements.",r)}return t.length>0&&super.add(...t),i&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(e){this._textContent.value=e}get textContent(){return super.textContent}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(e,t){e.flexDirection=eee,e.justifyContent=xI,e.alignItems=yI,e.bounds=nee,e.autoSize=ree,e.renderer=oee,e.children||(e.children=see),e.textContent||(e.textContent=X$),e.layouter||(e.layouter=J$),e.lineHeight||(e.lineHeight=tee),e.textAlign||(e.textAlign=K$),e.whiteSpace||(e.whiteSpace=jI),e.fontKerning||(e.fontKerning=iee),e.segments||(e.segments=cN),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class aee extends ui{constructor(){super("inlines",null,!1),this._value=[]}process(e){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}}class lee extends ui{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new JU(e)),e._backgroundMesh.position.x=e._inlines._value[0].offsetX+e._inlines._value[0].width/2,e._backgroundMesh.position.y=e._inlines._value[0].offsetY+e._inlines._value[0].lineBase/2,e._bounds.render(e)}}class cee extends ui{constructor(){super("bounds",null,!1),this._size=new Ke.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(e,t){this.output(t),this._needsProcess=!0}process(e){this._offsetWidth=this._innerWidth=e._inlines._value[0].width,this._offsetHeight=this._innerHeight=e._inlines._value[0].height,this._needsRender=!0,e._borderWidth._needsRender=!0,e._borderRadius._needsRender=!0}render(e){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(e){e.size=this._size}}class Dm extends RA{constructor(e={}){const t={};Dm.definePropertiesValues(t,e),super(t,e),Dm.init(this)}clear(){for(const e of this._inlines._value)e.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new Ke.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let i=0;i<arguments.length;i++){const s=arguments[i];s.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",s):(t.push(s),s.position.z=.005)}return super.add(...t)}static definePropertiesValues(e,t){e.children||(e.children=hN),e.bounds||(e.bounds=cee),e.inlines||(e.inlines=aee),e.layouter||(e.layouter=$U),e.renderer||(e.renderer=lee),e.fontFamily||(e.fontFamily=iN),e.fontWeight||(e.fontWeight=tN),e.fontStyle||(e.fontStyle=eN),e.fontSize||(e.fontSize=lN),e.backgroundColor||(e.backgroundColor=K3),e.lineBreak||(e.lineBreak=ZU),e.letterSpacing||(e.letterSpacing=aN),e.whiteSpace||(e.whiteSpace=jI),e.fontKerning||(e.fontKerning=Ob),t.backgroundSize||(t.backgroundSize="cover"),t.width||(t.width="100%"),t.height||(t.height="100%"),t.boxSizing||(t.boxSizing="border-box")}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),e._inlines._value=[new hee(e)],e.backgroundMaterial=new XU,e._renderer.render(e)}}class hee extends rU{constructor(e){super(),this._uiElement=e}get xadvance(){const e=this._uiElement._padding._value,t=this._uiElement._width;return t._relative?t._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.w+e.y+t.value}get width(){const e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get height(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get anchor(){return this.height}get lineHeight(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get lineBase(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}clear(){this._uiElement=null}}class uN{constructor(e){this._subject=e}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const dN=()=>u_.update(),fN={BaseProperty:ui,Block:Rm,Text:Bm,Inline:If,InlineBlock:Dm,MeshUIBaseElement:RA,FontLibrary:yu,update:dN,MSDFFontMaterialUtils:Jr,ShaderChunkUI:qU,Behavior:uN,FontVariant:IA};typeof global<"u"&&(global.ThreeMeshUI=fN);const uee=fN;var dee=wn.w8,pN=wn.cg,WI=wn.gO,fee=wn.wb,nE=wn.zV,pee=wn.HS,gee=wn.Ec,d0=wn.gF,mee=wn.ol,Aee=wn.pz,vee=wn.tx,yee=wn.hj,_ee=wn.FV,bee=wn.sV,gN=wn.xv,xee=wn.mx,wee=wn.gE,Cee=wn.ZP,mN=wn.Vx;const LB=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:dee,Behavior:pN,Block:WI,DefaultValues:fee,FontLibrary:nE,FontVariant:pee,InheritableProperty:gee,Inline:d0,InlineBlock:mee,InlineGlyph:Aee,MSDFFontMaterialUtils:vee,MaterialTransformers:yee,MeshUIBaseElement:_ee,ShaderChunkUI:bee,Text:gN,TypographicFont:xee,TypographicGlyph:wee,default:Cee,update:mN},Symbol.toStringTag,{value:"Module"}));WI.prototype.interactable={get(){return this.interactive},set(n){this.interactable=n}};const vl=Symbol("shadowDomOwner");class Ho extends Ce{constructor(){super(...arguments);u(this,"shadowComponent",null);u(this,"_controlsChildLayout",!0);u(this,"_root");u(this,"_parentComponent")}isRoot(){var t;return((t=this.Root)==null?void 0:t.gameObject)===this.gameObject}get canvas(){const t=this.Root;return t!=null&&t.isCanvas?t:null}markDirty(){sr.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(t){this._controlsChildLayout=t,this.shadowComponent&&(this.shadowComponent.autoLayout=t)}get Root(){return this._root===void 0&&(this._root=$.getComponentInParent(this.gameObject,BA)),this._root}get Canvas(){return this.canvas}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(t,i){var o;this.removeShadowComponent();const s=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=$.getComponentInParent(s,Ho),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}t.name=this.name+" ("+(this.constructor.name??"UI")+")",t.autoLayout=this._parentComponent.controlsChildLayout,t[vl]=this,this.setShadowComponentOwner(t);let r=!1;if(((o=this.Root)==null?void 0:o.gameObject)===this.gameObject)this.gameObject.add(t);else{let a=this._parentComponent.shadowComponent;a&&(a==null||a.add(t),r=!0)}this.shadowComponent=t,i&&i.shadowComponent&&this.shadowComponent&&i.shadowComponent.add(this.shadowComponent),hA&&t.add(new Gf(.5)),this.onAfterAddedToScene(),r&&mN()}set(t){}setShadowComponentOwner(t){if(t&&(t[vl]===void 0||t[vl]===this)&&(t[vl]=this,t.children))for(const i of t.children)this.setShadowComponentOwner(i)}traverseOwnedShadowComponents(t,i,s){if(t&&t[vl]===i){s(t);for(const r of t.children)this.traverseOwnedShadowComponents(r,i,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(t){this.shadowComponent&&(this.shadowComponent.interactable=t)}}class BA extends Ho{awake(){super.awake()}}class Mf{static getObject(e){const t=e[vl];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const i=this.tryFindCanvasGroup(e);if((i==null?void 0:i.isCanvasGroup)===!0&&(t&&(t.canvasGroup=i),i.blocksRaycasts===!1||i.interactable===!1))return!1;const s=Au(e,r=>{if(r.isGraphic===!0)return r},!1);return t&&(s==null?void 0:s.isGraphic)===!0&&(t.graphic=s),!((s==null?void 0:s.raycastTarget)===!1||(s==null?void 0:s.layer)===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=Au(e,i=>{const s=i;if(s.blocksRaycasts!==void 0&&s.interactable!==void 0)return s},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}const gg=le("debugwebxrcontroller");var of=(n=>(n[n.PhysicalDevice=0]="PhysicalDevice",n[n.Touch=1]="Touch",n))(of||{}),hl=(n=>(n.SelectStart="select-start",n.SelectEnd="select-end",n.Update="update",n))(hl||{});class zb extends Ce{}const Gn=class extends Ce{constructor(){super(...arguments);u(this,"webXR");u(this,"index",-1);u(this,"controllerModel");u(this,"controller");u(this,"controllerGrip");u(this,"hand");u(this,"handPointerModel");u(this,"grabbed",null);u(this,"input",null);u(this,"type",0);u(this,"showRaycastLine",!0);u(this,"_wristQuaternion",null);u(this,"movementVector",new S);u(this,"worldRot",new xe);u(this,"joystick",new q);u(this,"didRotate",!1);u(this,"didTeleport",!1);u(this,"didChangeScale",!1);u(this,"lastHit",null);u(this,"raycastLine",null);u(this,"_raycastHitPoint",null);u(this,"_connnectedCallback",null);u(this,"_disconnectedCallback",null);u(this,"_selectStartEvt",null);u(this,"_selectEndEvt",null);u(this,"_selectionPressed",!1);u(this,"_selectionPressedLastFrame",!1);u(this,"_selectionStartTime",0);u(this,"_selectionEndTime",0);u(this,"_useSmoothing",!0);u(this,"_isConnected",!1);u(this,"rayRotation",new xe);u(this,"_pinchStartTime");u(this,"selectStartCallback",null);u(this,"lastSelectStartObject",null);u(this,"_didNotEndSelection",!1);u(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const t=new rn(this.geometry),i=t.material;return i.color=this.raycastColor,t.layers.set(2),t.name="line",t.scale.z=1,t}static CreateRaycastHitPoint(){const t=new po(.5,22,22),i=new vi({color:this.raycastColor}),s=new ve(t,i);return s.visible=!1,s.layers.set(2),s}static Create(t,i,s,r){const o=s?$.addNewComponent(s,Gn,!1):new Gn;o.webXR=t,o.index=i,o.type=r;const a=t.context;o.controller=a.renderer.xr.getController(i),o.controllerGrip=a.renderer.xr.getControllerGrip(i),o.controllerModel=this.Factory.createControllerModel(o.controller),o.controllerGrip.add(o.controllerModel),o.hand=a.renderer.xr.getHand(i);const l=new Yf;yA(l,a),o.webXR.handModelPath&&o.webXR.handModelPath!==""?l.setPath($c(t.sourceId,o.webXR.handModelPath)):l.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const c=new KY(o.hand,l);return o.hand.add(c),o.hand.traverse(h=>h.layers.set(2)),o.handPointerModel=new sJ(o.hand,o.controller),o.controller.addEventListener("connected",h=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2),setTimeout(()=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2)},1e3)}),o.hand.addEventListener("connected",h=>{var f;if(h.data.hand){t.Rig&&t.Rig.add(o.hand),o.type=0,o.handPointerModel.traverse(g=>g.layers.set(2)),(f=o.handPointerModel.pointerObject)==null||f.traverse(g=>g.layers.set(2));const p=o.hand.joints;if(p)for(const g of Object.keys(p)){const m=p[g];m.parent||o.hand.add(m)}}}),o}static addEventListener(t,i){const s=this.eventSubs[t]??[];s.push(i),this.eventSubs[t]=s}static removeEventListener(t,i){if(!i)return;const s=this.eventSubs[t]??[],r=s.indexOf(i);r>=0&&s.splice(r,1),this.eventSubs[t]=s}get isUsingHands(){var i;const t=(i=this.input)==null?void 0:i.hand;return t!=null}get wrist(){if(!this.hand)return null;const t=this.hand.joints;return t?t.wrist:null}getWristQuaternion(){const t=this.wrist;return t?(this._wristQuaternion||(this._wristQuaternion=new xe),Dn(t).multiply(this._wristQuaternion.setFromEuler(new bn(-Math.PI/4,0,0)))):null}get selectionDown(){return this._selectionPressed&&!this._selectionPressedLastFrame}get selectionUp(){return!this._selectionPressed&&this._selectionPressedLastFrame}get selectionPressed(){return this._selectionPressed}get selectionClick(){return this._selectionEndTime-this._selectionStartTime<.3}get raycastHitPoint(){return this._raycastHitPoint}get useSmoothing(){return this._useSmoothing}awake(){if(!this.controller){console.warn("Missing Controller!!!",this);return}this._connnectedCallback=this.onSourceConnected.bind(this),this._disconnectedCallback=this.onSourceDisconnected.bind(this),this._selectStartEvt=this.onSelectStart.bind(this),this._selectEndEvt=this.onSelectEnd.bind(this),this.type===1&&(this.controllerGrip.addEventListener("connected",this._connnectedCallback),this.controllerGrip.addEventListener("disconnected",this._disconnectedCallback),this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt))}onDestroy(){var t,i,s;this.type===1&&(this.controllerGrip.removeEventListener("connected",this._connnectedCallback),this.controllerGrip.removeEventListener("disconnected",this._disconnectedCallback),this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),(t=this.hand)==null||t.clear(),(i=this.controllerGrip)==null||i.clear(),(s=this.controller)==null||s.clear()}onEnable(){var t,i,s,r,o;this.hand&&(this.hand.name="Hand"),this.controllerGrip&&(this.controllerGrip.name="ControllerGrip"),this.controller&&(this.controller.name="Controller"),this.raycastLine&&(this.raycastLine.name="RaycastLine;"),this.webXR.Controllers.indexOf(this)<0&&this.webXR.Controllers.push(this),this.raycastLine||(this.raycastLine=Gn.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Gn.CreateRaycastHitPoint()),(t=this.webXR.Rig)==null||t.add(this.hand),(i=this.webXR.Rig)==null||i.add(this.controllerGrip),(s=this.webXR.Rig)==null||s.add(this.controller),(r=this.webXR.Rig)==null||r.add(this.raycastLine),(o=this.raycastLine)==null||o.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),gg&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var i,s,r,o,a;(i=this.hand)==null||i.removeFromParent(),(s=this.controllerGrip)==null||s.removeFromParent(),(r=this.controller)==null||r.removeFromParent(),(o=this.raycastLine)==null||o.removeFromParent(),(a=this._raycastHitPoint)==null||a.removeFromParent();const t=this.webXR.Controllers.indexOf(this);t>=0&&this.webXR.Controllers.splice(t,1)}onSourceConnected(t){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,t);return}this._isConnected=!0,this.input=t.data,this.type===1&&(this.onSelectStart(),this.createPointerEvent("down"))}onSourceDisconnected(t){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",t);return}this._isConnected=!1,this.type===1&&(this.onSelectEnd(),this.createPointerEvent("up")),this.input=null}createPointerEvent(t){switch(t){case"down":this.context.input.createPointerDown({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break;case"move":break;case"up":this.context.input.createPointerUp({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break}}update(){this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const t=Gn.eventSubs.update;if(t&&t.length>0)for(const r of t)r(this);let i=1;this.type===0?i=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(i=this.context.time.deltaTime/.3),this.rayRotation.slerp(Dn(this.controller),this.useSmoothing?i:1);const s=wt(this.controller);if(this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine){const r=this.showRaycastLine&&this.type!==1;if(this.type===1)this.raycastLine.visible=!1;else if(this.isUsingHands){this.raycastLine.visible=!this.grabbed&&r,ln(this.raycastLine,s);const o=this.hand.joints;if(o&&o.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const l=this.getWristQuaternion();l&&this.rayRotation.copy(l)}cr(this.raycastLine,this.rayRotation)}else this.raycastLine.visible=r,cr(this.raycastLine,this.rayRotation),ln(this.raycastLine,s)}this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(t){var r,o;if(this.lastHit=null,!t||t.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=t.inputSources[this.index]),!this.input)return;const i=this.webXR.Rig;if(!i)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const s=(o=(r=this.input)==null?void 0:r.gamepad)==null?void 0:o.buttons;switch(this.input.handedness){case"left":const a=3*Gn.MovementSpeedFactor,l=2,c=Ze.clamp01(this.joystick.length()*2),h=this.joystick.x>0?1:-1;let d=Math.pow(this.joystick.x,l);d*=h,d*=c;const f=this.joystick.y>0?1:-1;let p=Math.pow(this.joystick.y,l);p*=f,d*=c,i.getWorldQuaternion(this.worldRot),this.movementVector.set(d,0,p),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(a*this.context.time.deltaTime),i.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(i,s);break;case"right":const g=this.joystick.x,m=Math.abs(g);if(m<.4)this.didRotate=!1;else if(m>.5&&!this.didRotate){const A=g>0?-1:1;i.rotateY(Ze.toRadians(30*A)),this.didRotate=!0}this.runTeleport(i,s);break}}runTeleport(t,i){var l,c,h;let s=-this.joystick.y;if((l=this.hand)!=null&&l.visible&&!this.grabbed){const d=this.handPointerModel.isPinched();d&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),d&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(s=this.handPointerModel.isPinched()?1:0),d||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;let r=s>.5&&this.webXR.IsInVR,o=this.webXR.Rig?((h=(c=this.webXR.Rig)==null?void 0:c.scale)==null?void 0:h.x)<.999:!1,a=null;if(i&&this.input&&!this.input.hand)for(let d=0;d<i.length;d++){const f=i[d];if(d===4)if(f.pressed&&!this.didChangeScale&&this.webXR.IsInVR){this.didChangeScale=!0;const p=this.webXR.Rig;if(p)if(o){o=!1,p.scale.set(1,1,1),a=1,Gn.MovementSpeedFactor=1;const g=this.context.mainCamera;Gn.PreviousCameraFarDistance&&(g.far=Gn.PreviousCameraFarDistance)}else{o=!0,r=!0,a=.1,Gn.MovementSpeedFactor=a*2;const g=this.context.mainCamera;Gn.PreviousCameraFarDistance=g.far,g.far/=a}}else f.pressed||(this.didChangeScale=!1)}if(r){if(!this.didTeleport){const d=this.raycast();if(this.didTeleport=!0,d&&d.length>0){const f=d[0];if(o||this.isValidTeleportTarget(f.object)){const p=f.point;ln(t,p)}}}}else s<.1&&(this.didTeleport=!1);a!==null&&(t.scale.set(a,a,a),t.updateMatrixWorld())}isValidTeleportTarget(t){return $.getComponentInParent(t,zb)!=null}updateStick(t){var i;!t||!t.gamepad||((i=t.gamepad.axes)==null?void 0:i.length)<4||(this.joystick.x=t.gamepad.axes[2],this.joystick.y=t.gamepad.axes[3])}updateLastHit(){var r;const t=this.raycast(),i=t?t[0]:null;this.lastHit=i;let s=1;if(this.webXR.Rig&&(s/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=s*(((r=this.lastHit)==null?void 0:r.distance)??9999);const o=this.raycastLine.material;i!=null?o.color=Gn.raycastColor:o.color=Gn.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const o=Ze.clamp(this.lastHit.distance*.01*s,.015,.1);this._raycastHitPoint.scale.set(o,o,o)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return i}onSelectStart(){this.context.connection.allowEditing&&(this.selectStartCallback=()=>this.onHandleSelectStart())}onHandleSelectStart(){this.selectStartCallback=null,this._selectionPressed=!0,this._selectionStartTime=this.context.time.time,this._selectionEndTime=1e3;let t=null,i=!1;if(this.isUsingHands?(t=this.overlap(),t.length<=0?(t=this.raycast(),i=!1):i=!0):t=this.raycast(),gg&&console.log("onHandleSelectStart","close grab? "+i,"intersections",t),t&&t.length>0)for(const s of t){const r=s.object;this.lastSelectStartObject=r;const o={selected:r,grab:r},a=Gn.eventSubs["select-start"];if(a&&a.length>0)for(const l of a)l(this,o);o.grab!==r&&gg&&console.log("Grabbed object changed","original",r,"new",o.grab),o.grab&&(this.grabbed=ro.TryTake(this,o.grab,s,i));break}else{const s=Gn.eventSubs["select-start"],r={selected:null,grab:null};if(s&&s.length>0)for(const o of s)o(this,r)}}onSelectEnd(){var s;if(this.isUsingHands&&this.handPointerModel.pinched){this._didNotEndSelection=!0;return}if(!this._selectionPressed)return;this.selectStartCallback=null,this._selectionPressed=!1,this._selectionEndTime=this.context.time.time;const t={grab:((s=this.grabbed)==null?void 0:s.selected)??this.lastSelectStartObject},i=Gn.eventSubs["select-end"];if(i&&i.length>0)for(const r of i)r(this,t);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(t){return!(!t||$.isActiveInHierarchy(t)===!1||Mf.isInteractable(t)===!1)}setControllerLayers(t,i){var s,r;if(t&&(t.layers.set(i),t.children))for(const o of t.children)((s=this.grabbed)==null?void 0:s.selected)===o||((r=this.grabbed)==null?void 0:r.selectedMesh)===o||this.setControllerLayers(o,i)}getRay(){const t=new Gl;return t.origin.copy(wt(this.controller)),t.direction.set(0,0,-1).applyQuaternion(this.rayRotation),t}overlap(){const t=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(gg&&(!this.closeGrabBoundingBoxHelper&&t&&(this.closeGrabBoundingBoxHelper=new eb(t,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&t&&this.closeGrabBoundingBoxHelper.setFromObject(t)),!t)return new Array;const i=wt(t).clone();return this.context.physics.sphereOverlap(i,.02)}raycast(){const t=new qo;t.layerMask=new ho,t.layerMask.enableAll(),t.layerMask.disable(2),t.ray=this.getRay();const i=this.context.physics.raycast(t);for(let s=0;s<i.length;s++){const r=i[s],o=r.object;if(!this.testIsVisible(o)){i.splice(s,1),s--;continue}r.object=Mf.getObject(o);break}return i}};let Yi=Gn;u(Yi,"Factory",new mJ),u(Yi,"raycastColor",new _e(.9,.3,.3)),u(Yi,"raycastNoHitColor",new _e(.6,.6,.6)),u(Yi,"geometry",new vt().setFromPoints([new S(0,0,0),new S(0,0,-1)])),u(Yi,"handModels",{}),u(Yi,"eventSubs",{}),u(Yi,"PreviousCameraFarDistance"),u(Yi,"MovementSpeedFactor",1);var f_=(n=>(n.WillTake="WillTake",n.DidTake="DidTake",n.WillFree="WillFree",n.DidFree="DidFree",n))(f_||{});const Rs=class{constructor(){u(this,"sync",null);u(this,"selected",null);u(this,"selectedParent",null);u(this,"selectedMesh",null);u(this,"controller",null);u(this,"grabTime",0);u(this,"grabUUID","");u(this,"isCloseGrab",!1);u(this,"originalMaterial",null);u(this,"usageMarker",null);u(this,"rigidbodies",null);u(this,"didReparent",!1);u(this,"grabDistance",0);u(this,"interactable",null);u(this,"positionSource",null);u(this,"grabPoint",new S);u(this,"localPositionOffsetToGrab",null);u(this,"localPositionOffsetToGrab_worldSpace",new S);u(this,"localQuaternionToGrab",new xe(0,0,0,1));u(this,"targetDir",null);u(this,"quaternionLerp",null);u(this,"controllerDir",new S);u(this,"controllerWorldPos",new S);u(this,"lastControllerWorldPos",new S);u(this,"controllerPosDelta",new S);u(this,"totalChangeAlongDirection",0);u(this,"rigPositionLastFrame",new S)}static AddEventListener(e,t){return Rs.Events[e]||(Rs.Events[e]=[]),Rs.Events[e].push(t),t}static RemoveEventListener(e,t){if(!t||!Rs.Events[e])return;const i=Rs.Events[e].indexOf(t);i>=0&&Rs.Events[e].splice(i,1)}static Register(e){this.Current.find(t=>t===e)||this.Current.push(e)}static Remove(e){const t=this.Current.indexOf(e);t>=0&&this.Current.splice(t,1)}static TryTake(e,t,i,s){const r=$.getComponentInParent(t,rp);if(r)t=r.gameObject;else return gg&&console.warn("Prevented taking object that is not interactable",t),null;let o=t;const a=$.getComponentInParent(t,Jc);a&&(a.requestOwnership(),o=a.gameObject);for(const c of this.Current)if(c.selected===o)return c.controller===e||(c.free(),c.Take(e,o,t,a,r,i,s)),c;const l=new Rs;return l.Take(e,o,t,a,r,i,s),l}Take(e,t,i,s,r,o,a){var p,g;if(console.assert(t!==null,"Expected object to be taken but was",t),e.isUsingHands?this.positionSource=a?e.wrist:e.controller:this.positionSource=e.controller,!this.positionSource)return console.warn("No position source"),this;const l={controller:e,take:t,hit:i,sync:s,interactable:r};(p=Rs.Events.WillTake)==null||p.forEach(m=>m(this,l));const c=i;c!=null&&c.material&&(this.originalMaterial=c.material,Array.isArray(c.material)||(c.material=c.material.clone(),c.material&&c.material.emissive&&(c.material.emissive.b=.2))),this.selected=t,this.selectedParent||(this.selectedParent=t.parent),this.selectedMesh=c,this.controller=e,this.interactable=r,this.isCloseGrab=a,this.didReparent=!1,this.sync=s,this.grabTime=e.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=$.addNewComponent(this.selected,op),this.rigidbodies=$.getComponentsInChildren(this.selected,Hi),wt(this.positionSource,this.lastControllerWorldPos);const h=()=>a?this.lastControllerWorldPos.clone():o.point.clone();this.grabDistance=h().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(h());const d=e.isUsingHands&&a?this.controller.getWristQuaternion().clone():e.rayRotation.clone();Dn(this.selected,this.localQuaternionToGrab).premultiply(d.invert());const f=this.controller.webXR.Rig;return f&&this.rigPositionLastFrame.copy(wt(f)),Ns.Add(e.context,this.selected),Rs.Register(this),this.sync&&(this.sync.fastMode=!0),(g=Rs.Events.DidTake)==null||g.forEach(m=>m(this,l)),this}free(){var s,r,o,a;if(!this.selected)return;const e={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(s=Rs.Events.WillFree)==null||s.forEach(l=>l(this,e)),Ns.Remove(this.controller.context,this.selected),Rs.Remove(this),this.sync&&(this.sync.fastMode=!1);const t=this.selectedMesh;t&&this.originalMaterial&&t.material&&(t.material=this.originalMaterial);const i=this.selected;if(this.didReparent&&i.parent){const l=this.selectedParent;l?l.attach(i):(r=this.controller)==null||r.context.scene.attach(i)}if((o=this.usageMarker)==null||o.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const l of this.rigidbodies)l.wakeUp(),l.setVelocity(l.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(a=Rs.Events.DidFree)==null||a.forEach(l=>l(this,e))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),wt(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const e=this.controller.webXR.Rig;if(e){const i=wt(e),s=this.rigPositionLastFrame.sub(i);this.controllerPosDelta.add(s),this.rigPositionLastFrame.copy(i)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var e;if(this.rigidbodies)for(const t of this.rigidbodies)t.resetVelocities();if(this.sync&&this.controller&&this.controller.context.connection.isInRoom&&this.controller.context.time.time-this.grabTime>3&&this.sync.hasOwnership()===!1&&(console.log("no ownership, will leave",this.sync.guid),this.free()),!(this.interactable&&!this.interactable.canGrab)){if(!this.didReparent&&this.selected&&this.controller){const t=((e=this.controller.webXR.Rig)==null?void 0:e.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let i=1;this.controller.type===0&&(i=Math.max(0,1+this.totalChangeAlongDirection*2/t),i=i*i*i),this.grabDistance/t<.8&&(i=1),this.targetDir||(this.targetDir=new S),this.targetDir.set(0,0,-this.grabDistance*i);const s=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),r=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=r.clone()),this.quaternionLerp.slerp(r,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),cr(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(s),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(wt(this.selected)),s.sub(this.localPositionOffsetToGrab_worldSpace)),ln(this.selected,s)}if(this.rigidbodies!=null)for(const t of this.rigidbodies)t.wakeUp();rr.markDirty(this.selected,!0)}}};let ro=Rs;u(ro,"Events",{}),u(ro,"Current",[]);var See=Object.defineProperty,Eee=Object.getOwnPropertyDescriptor,qI=(n,e,t,i)=>{for(var s=i>1?void 0:i?Eee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&See(e,t,s),s};class Ru extends Ce{constructor(){super(...arguments);u(this,"objectBounds",!1);u(this,"color");u(this,"isGizmo",!0);u(this,"_gizmoObject",null);u(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!hA||(this._gizmoObject||(this.objectBounds&&this.gameObject.isMesh===!0?this._gizmoObject=new eb(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=P3(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),Rr.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){var t;for(;this._boxHelper;)(t=this._boxHelper)==null||t.update(),yield}}qI([w()],Ru.prototype,"objectBounds",2);qI([w(_e)],Ru.prototype,"color",2);qI([w()],Ru.prototype,"isGizmo",2);const Iee=le("debugrig");class Gb extends Ce{awake(){if(Iee){const e=new Ie;e.position.y+=.5,this.gameObject.add(e);const t=e.addNewComponent(Ru);t&&(t.isGizmo=!1)}}}class af{constructor(){u(this,"bb",null);u(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}w(){return this.bb.readFloat32(this.bb_pos+12)}static sizeOf(){return 16}static createVec4(e,t,i,s,r){return e.prep(4,16),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(i),e.writeFloat32(t),e.offset()}}class As{constructor(){u(this,"bb",null);u(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsVrUserStateBuffer(e,t){return(t||new As).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsVrUserStateBuffer(e,t){return e.setPosition(e.position()+hb),(t||new As).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}time(){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):this.bb.createLong(0,0)}avatarId(e){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__string(this.bb_pos+t,e):null}position(e){const t=this.bb.__offset(this.bb_pos,10);return t?(e||new Mr).__init(this.bb_pos+t,this.bb):null}rotation(e){const t=this.bb.__offset(this.bb_pos,12);return t?(e||new af).__init(this.bb_pos+t,this.bb):null}scale(){const e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readFloat32(this.bb_pos+e):0}posLeftHand(e){const t=this.bb.__offset(this.bb_pos,16);return t?(e||new Mr).__init(this.bb_pos+t,this.bb):null}posRightHand(e){const t=this.bb.__offset(this.bb_pos,18);return t?(e||new Mr).__init(this.bb_pos+t,this.bb):null}rotLeftHand(e){const t=this.bb.__offset(this.bb_pos,20);return t?(e||new af).__init(this.bb_pos+t,this.bb):null}rotRightHand(e){const t=this.bb.__offset(this.bb_pos,22);return t?(e||new af).__init(this.bb_pos+t,this.bb):null}static startVrUserStateBuffer(e){e.startObject(10)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addTime(e,t){e.addFieldInt64(1,t,e.createLong(0,0))}static addAvatarId(e,t){e.addFieldOffset(2,t,0)}static addPosition(e,t){e.addFieldStruct(3,t,0)}static addRotation(e,t){e.addFieldStruct(4,t,0)}static addScale(e,t){e.addFieldFloat32(5,t,0)}static addPosLeftHand(e,t){e.addFieldStruct(6,t,0)}static addPosRightHand(e,t){e.addFieldStruct(7,t,0)}static addRotLeftHand(e,t){e.addFieldStruct(8,t,0)}static addRotRightHand(e,t){e.addFieldStruct(9,t,0)}static endVrUserStateBuffer(e){return e.endObject()}static finishVrUserStateBufferBuffer(e,t){e.finish(t)}static finishSizePrefixedVrUserStateBufferBuffer(e,t){e.finish(t,void 0,!0)}}const FB=le("debugxr"),Zp=le("debugavatar"),XI="VRUS";C1(XI,As.getRootAsVrUserStateBuffer);function sE(){return new Date().getTime()}function Mee(n){let e=n&4294967295,t=n/Math.pow(2,32)&1048575;return Ea.create(e,t)}const $g=class{constructor(e){u(this,"guid");u(this,"time");u(this,"avatarId");u(this,"position",new S);u(this,"rotation",new rt);u(this,"scale",1);u(this,"posLeftHand",new S);u(this,"posRightHand",new S);u(this,"rotLeftHand",new xe);u(this,"rotRightHand",new xe);this.guid=e}update(e,t,i,s,r){var h,d,f,p,g,m;this.time=sE(),this.avatarId=r,this.position.set(t.x,t.y,t.z),e&&this.position.applyMatrix4(e.matrixWorld);let o=$g.quat0;const a=$g.quat1;o.set(i.x,i.y,i.z,i.w),o=o.multiplyQuaternions(o,$g.invertRotation),e&&(e.getWorldQuaternion(a),o.multiplyQuaternions(a,o)),this.rotation.set(o.x,o.y,o.z,o.w),this.scale=e.scale.x;const l=(h=s.LeftController)==null?void 0:h.controllerGrip;l&&(l.getWorldPosition(this.posLeftHand),l.getWorldQuaternion(this.rotLeftHand));const c=(d=s.RightController)==null?void 0:d.controllerGrip;if(c&&(c.getWorldPosition(this.posRightHand),c.getWorldQuaternion(this.rotRightHand)),(p=(f=s.LeftController)==null?void 0:f.hand)!=null&&p.visible){const A=s.LeftController.wrist;A&&(A.getWorldPosition(this.posLeftHand),A.getWorldQuaternion(this.rotLeftHand))}if((m=(g=s.RightController)==null?void 0:g.hand)!=null&&m.visible){const A=s.RightController.wrist;A&&(A.getWorldPosition(this.posRightHand),A.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(e,t){e.clear();const i=e.createString(this.guid),s=e.createString(this.avatarId);As.startVrUserStateBuffer(e),As.addGuid(e,i),As.addTime(e,Mee(this.time)),As.addAvatarId(e,s),As.addPosition(e,Mr.createVec3(e,this.position.x,this.position.y,this.position.z)),As.addRotation(e,af.createVec4(e,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),As.addScale(e,this.scale),As.addPosLeftHand(e,Mr.createVec3(e,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),As.addPosRightHand(e,Mr.createVec3(e,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),As.addRotLeftHand(e,af.createVec4(e,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),As.addRotRightHand(e,af.createVec4(e,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const r=As.endVrUserStateBuffer(e);e.finish(r,XI);const o=e.asUint8Array();t.sendBinary(o)}setFromBuffer(e,t){if(!e)return;this.guid=e,this.time=t.time().toFloat64();const i=t.avatarId();i&&(this.avatarId=i);const s=t.position();s&&this.position.set(s.x(),s.y(),s.z());const r=t.rotation();r&&this.rotation.set(r.x(),r.y(),r.z(),r.w());const o=t.posLeftHand();o&&this.posLeftHand.set(o.x(),o.y(),o.z());const a=t.posRightHand();a&&this.posRightHand.set(a.x(),a.y(),a.z());const l=t.rotLeftHand();l&&this.rotLeftHand.set(l.x(),l.y(),l.z(),l.w());const c=t.rotRightHand();c&&this.rotRightHand.set(c.x(),c.y(),c.z(),c.w()),this.scale=t.scale()}};let Lo=$g;u(Lo,"invertRotation",new xe().setFromAxisAngle(new S(0,1,0),Math.PI)),u(Lo,"quat0",new xe),u(Lo,"quat1",new xe);class km extends Ce{constructor(){super(...arguments);u(this,"webXR",null);u(this,"debugAvatarUser",null);u(this,"voip",null);u(this,"tempState",new Lo(""));u(this,"_removeAvatarsList",[]);u(this,"eventSub_ConnectionEvent",null);u(this,"eventSub_WebXRStartEvent",null);u(this,"eventSub_WebXREndEvent",null);u(this,"eventSub_WebXRUpdateEvent",null);u(this,"avatars",{});u(this,"localAvatar",null);u(this,"k_LocalAvatarNoNetworkingGuid","local");u(this,"ownership",null);u(this,"xrState",null);u(this,"builder",new Qf(1024))}async awake(){if(this.webXR||(this.webXR=$.getComponent(this.gameObject,Ct)),this.webXR||(this.webXR=$.findObjectOfType(Ct,this.context)),!this.webXR&&(console.log("Missing webxr component"),this.webXR=$.findObjectOfType(Ct,this.context),!this.webXR)){console.error("Could not find webxr component");return}if(this.voip||(this.voip=$.findObjectOfType(Vl,this.context)),Zp){const t="debug-avatar-"+Zp,i=new wa(this.context,t,this.webXR);if(this.debugAvatarUser=i,typeof Zp=="string"&&Zp.length>0)if(await i.setAvatarOverride(Zp)){const s=new Lo(t);s.position.y+=1;const r=.5;s.posLeftHand.y+=r,s.posLeftHand.x+=r,s.posRightHand.y+=r,s.posRightHand.x-=r,i.tryUpdate(s,0)}else i.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=$.getComponent(this.gameObject,Ct),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),Ct.addEventListener(Ei.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),Ct.addEventListener(Ei.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Ct.addEventListener(Ei.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen(Ji.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",t=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",t=>{const i=t.id!==null&&t.id!==void 0;if(i&&(console.log("webxr user left evt"),i)){const s=this.avatars[t.id];s==null||s.destroy(),this.avatars[t.id]=void 0}}),this.context.connection.beginListenBinary(XI,t=>{const i=t.guid();if(!i)return;const s=t.time().toFloat64(),r=this.tempState;r.setFromBuffer(i,t);const o=this.onTryGetAvatar(i,s);o==null||o.tryUpdate(r,s)}),this.context.connection.beginListen("vr-session-update",t=>{const i=t.guid,s=t.time,r=this.onTryGetAvatar(i,s);r==null||r.tryUpdate(t,s)})}onTryGetAvatar(t,i){if(t===this.context.connection.connectionId)return null;const s=new Date().getTime()-i;if(s>5e3)return FB&&console.log("old data",s,t),null;let r=this.avatars[t];if(r===void 0)try{console.log("create new avatar");const o=new wa(this.context,t,this.webXR);r=o,this.avatars[t]=o}catch(o){this.avatars[t]=null,console.error(o)}return r}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen(Ji.JoinedRoom,this.eventSub_ConnectionEvent),Ct.removeEventListener(Ei.XRStarted,this.eventSub_WebXRStartEvent),Ct.removeEventListener(Ei.XRUpdate,this.eventSub_WebXRUpdateEvent),Ct.removeEventListener(Ei.XRStopped,this.eventSub_WebXREndEvent)}update(){const t=sE();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=t),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const i in this.avatars){const s=this.avatars[i];s&&s.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const t=sE();for(const i in this.avatars){const s=this.avatars[i];if(!s){this._removeAvatarsList.push(i);continue}t-s.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),s.destroy(),this.avatars[i]=void 0)}for(const i of this._removeAvatarsList)delete this.avatars[i];this._removeAvatarsList.length=0}buildLocalAvatar(){var i;if(this.localAvatar)return;const t=((i=this.context.connection)==null?void 0:i.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new wa(this.context,t,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var t,i,s;FB&&console.log("Hey you are connected as "+this.context.connection.connectionId),((t=this.localAvatar)==null?void 0:t.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null)}onXRSessionStart(t){var i,s,r;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null,this.avatars)for(const o in this.avatars)(r=this.avatars[o])==null||r.updateFlags()}onXRSessionEnded(t){var i;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(t){this.xrState??(this.xrState=new Lo(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new db(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:i,xr:s,rig:r}=t,o=i.getViewerPose(s.getReferenceSpace());if(!o)return;const a=o==null?void 0:o.transform,l=a.position,c=a.orientation;this.xrState.update(r,l,c,this.webXR,this.getAvatarId()),this.localAvatar&&(this.context.connection.connectionId&&(this.localAvatar.guid=this.context.connection.connectionId),this.localAvatar.tryUpdate(this.xrState,0)),!(this.ownership&&!this.ownership.hasOwnership&&this.context.connection.isConnected&&(this.context.time.frameCount%120===0&&this.ownership.requestOwnership(),!this.ownership.hasOwnership))&&(!this.context.connection.isConnected||!this.context.connection.connectionId||this.xrState.sendAsBuffer(this.builder,this.context.connection))}getAvatarId(){return le("avatar")??null}}var Tee=Object.defineProperty,Pee=Object.getOwnPropertyDescriptor,hp=(n,e,t,i)=>{for(var s=i>1?void 0:i?Pee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Tee(e,t,s),s};async function AN(){return EE()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function vN(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let f0=!1,p0=!1;AN().then(n=>f0=n);vN().then(n=>p0=n);var Ei=(n=>(n.XRStarted="xrStarted",n.XRStopped="xrStopped",n.XRUpdate="xrUpdate",n.RequestVRSession="requestVRSession",n.ModifyAROptions="modify-ar-options",n))(Ei||{}),Sd;const Mn=(Sd=class extends Ce{constructor(){super(...arguments);u(this,"enableVR",!0);u(this,"enableAR",!0);u(this,"defaultAvatar");u(this,"handModelPath","");u(this,"createVRButton",!0);u(this,"createARButton",!0);u(this,"controllers",[]);u(this,"rig");u(this,"isInit",!1);u(this,"_requestedAR",!1);u(this,"_requestedVR",!1);u(this,"_isInAR",!1);u(this,"_isInVR",!1);u(this,"_arButton");u(this,"_vrButton");u(this,"webAR",null);u(this,"_transformOrientation",new xe);u(this,"_currentHeadPose",null);u(this,"_originalCameraParent",null);u(this,"_originalCameraPosition",new S);u(this,"_originalCameraRotation",new xe);u(this,"_originalXRRigParent",null);u(this,"_originalXRRigPosition",new S);u(this,"_originalXRRigRotation",new xe);u(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(f0||p0)}static get IsARSupported(){return f0}static get IsVRSupported(){return p0}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(e,t){return this.events.addEventListener(e,t),t}static removeEventListener(e,t){return this.events.removeEventListener(e,t),t}static dispatchEvent(e,t){this.events.dispatchEvent({type:e,detail:t})}static createVRButton(e,t){Mn.XRSupported?e.__internalAwake():console.warn("WebXR is not supported on this device");const i={optionalFeatures:Mn.OptionalFeatures_VR},s=zg.createButton(e.context.renderer,i);return s.classList.add("webxr-ar-button"),s.classList.add("webxr-button"),this.resetButtonStyles(s),((t==null?void 0:t.registerClick)??!0)&&s.addEventListener("click",e.onClickedVRButton.bind(e)),s}static createARButton(e,t){var o;e.__internalAwake();const i=(o=e.webAR)==null?void 0:o.getAROverlayContainer(),s={optionalFeatures:[...this.OptionalFeatures_AR]};i?(s.domOverlay={root:i},s.optionalFeatures.push("dom-overlay"),s.optionalFeatures.push("hit-test")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const r=zY.createButton(e.context.renderer,s,this.onModifyAROptions.bind(this));return r.classList.add("webxr-ar-button"),r.classList.add("webxr-button"),Mn.resetButtonStyles(r),((t==null?void 0:t.registerClick)??!0)&&r.addEventListener("click",e.onClickedARButton.bind(e)),r}static onModifyAROptions(e){Mn.dispatchEvent("modify-ar-options",e)}static resetButtonStyles(e){e&&(e.style.position="",e.style.bottom="",e.style.left="")}endSession(){const e=this.context.renderer.xr.getSession();e&&e.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var e,t;return this.controllers.length>0&&((e=this.controllers[0].input)==null?void 0:e.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((t=this.controllers[1].input)==null?void 0:t.handedness)==="left"?this.controllers[1]:null}get RightController(){var e,t;return this.controllers.length>0&&((e=this.controllers[0].input)==null?void 0:e.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((t=this.controllers[1].input)==null?void 0:t.handedness)==="right"?this.controllers[1]:null}get ARButton(){return this._arButton}get VRButton(){return this._vrButton}get IsInVR(){return this._isInVR}get IsInAR(){return this._isInAR}awake(){if(this.defaultAvatar&&typeof this.defaultAvatar=="string"&&(this.defaultAvatar=Xn.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!$.findObjectOfType(km,this.context)){const e=$.addNewComponent(this.gameObject,km,!1);e.webXR=this}this.webAR=new au(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(Wo("WebXR only works on https"),console.warn("WebXR only works on https. https://engine.needle.tools/docs/xr.html"))}onEnable(){if(this.isInit||!this.enableAR&&!this.enableVR)return;this.isInit=!0,this.context.renderer.xr.enabled=!0,Mn.XRSupported;let e,t;const i=document.createElement("div");i.classList.add("webxr-buttons"),this.context.domElement.append(i),this.enableAR&&this.createARButton&&f0&&(e=Mn.createARButton(this),this._arButton=e,i.appendChild(e)),this.createVRButton&&this.enableVR&&p0&&(t=Mn.createVRButton(this),this._vrButton=t,i.appendChild(t)),setTimeout(()=>{Mn.resetButtonStyles(t),Mn.resetButtonStyles(e)},1e3)}get TransformOrientation(){return this._transformOrientation}get HeadPose(){return this._currentHeadPose}onBeforeRender(e){var i;if(!e)return;const t=this.context.renderer.xr.getSession();if(t){const s=e.getViewerPose(this.context.renderer.xr.getReferenceSpace());if(!s)return;this._currentHeadPose=s;const r=s==null?void 0:s.transform;r&&this._transformOrientation.set(r.orientation.x,r.orientation.y,r.orientation.z,r.orientation.w),Mn._isInXr===!1&&t&&this.onEnterXR(t,e);for(const o of this.controllers)o.onUpdate(t);this._isInAR&&((i=this.webAR)==null||i.onUpdate(t,e))}Mn.events.dispatchEvent({type:"xrUpdate",frame:e,xr:this.context.renderer.xr,rig:this.rig})}onClickedARButton(){this._isInAR||(this._requestedAR=!0,this._requestedVR=!1,this.captureStateBeforeXR())}onClickedVRButton(){if(!this._isInVR){if(this._requestedVR){this.onExitXR(null);return}this._requestedAR=!1,this._requestedVR=!0,this.captureStateBeforeXR(),this.ensureRig();for(let e=0;e<2;e++)Yi.Create(this,e,this.gameObject,of.PhysicalDevice);Mn.events.dispatchEvent({type:"requestVRSession"})}}captureStateBeforeXR(){this.context.mainCamera&&(this._originalCameraPosition.copy(wt(this.context.mainCamera)),this._originalCameraRotation.copy(Dn(this.context.mainCamera)),this._originalCameraParent=this.context.mainCamera.parent),this.Rig&&(this._originalXRRigParent=this.Rig.parent,this._originalXRRigPosition.copy(this.Rig.position),this._originalXRRigRotation.copy(this.Rig.quaternion))}ensureRig(){if(!this.rig){const e=$.findObjectOfType(Gb,this.context);e?this.rig=e.gameObject:(this.rig=new io,this.rig.rotateY(Math.PI),this.rig.name="XRRig",this.context.scene.add(this.rig))}}onEnterXR(e,t){var o,a;console.log("[XR] session begin",e),Mn._isInXr=!0,this.ensureRig();const i=this.context.renderer.xr.getReferenceSpace();if(i&&this.rig){const l=t.getViewerPose(i),c=l==null?void 0:l.transform.orientation;if(c){const h=new xe(c.x,c.y,c.z,c.w),d=new bn().setFromQuaternion(h);this.rig.rotateY(d.y)}}const s=this.context.renderer.xr;if(this.context.mainCamera){const l=s.getCamera(this.context.mainCamera),c=(o=this.context.mainCameraComponent)==null?void 0:o.cullingMask;if(c!==void 0){for(const h of l.cameras)h.layers.mask=c;l.layers.mask=c}else{for(const h of l.cameras)h.layers.enableAll();l.layers.enableAll()}this.rig.add(this.context.mainCamera),this._requestedAR&&this.context.scene.add(this.rig)}const r=this._requestedAR?vn.AR:vn.VR;switch(so.Global.Set(r),r){case vn.AR:this.context.xrSessionMode=ym.ImmersiveAR,this._isInAR=!0,(a=this.webAR)==null||a.onBegin(e);break;case vn.VR:this.context.xrSessionMode=ym.ImmersiveVR,this._isInVR=!0,this.onEnterVR(e);break}e.addEventListener("end",()=>{console.log("[XR] session end"),Mn._isInXr=!1,this.onExitXR(e)}),this.onEnterXR_HandleMirrorWindow(e),Mn.events.dispatchEvent({type:"xrStarted",session:e})}onExitXR(e){var i,s,r;const t=this._isInAR;this._isInAR&&e&&((i=this.webAR)==null||i.onEnd(e)),this._isInAR=!1,this._isInVR=!1,this._requestedAR=!1,this._requestedVR=!1,this.context.xrSessionMode=void 0,this.xrMirrorWindow&&(this.xrMirrorWindow.close(),this.xrMirrorWindow=null),this.destroyControllers(),this.context.mainCamera&&((s=this._originalCameraParent)==null||s.add(this.context.mainCamera),ln(this.context.mainCamera,this._originalCameraPosition),cr(this.context.mainCamera,this._originalCameraRotation),this.context.mainCamera.scale.set(1,1,1)),t&&((r=this._originalXRRigParent)==null||r.add(this.rig),this.rig.position.copy(this._originalXRRigPosition),this.rig.quaternion.copy(this._originalXRRigRotation)),so.Global.Set(vn.Browser|vn.ThirdPerson),Mn.events.dispatchEvent({type:"xrStopped",session:e})}onEnterVR(e){}destroyControllers(){var e;for(let t=this.controllers.length-1;t>=0;t-=1)(e=this.controllers[t])==null||e.destroy();this.controllers.length=0}onEnterXR_HandleMirrorWindow(e){le("mirror")&&setTimeout(()=>{if(!Mn.IsInWebXR)return;const t=new URL(window.location.href);im(t.searchParams,r_,1),im(t.searchParams,"isMirror",1);const i=t.toString();this.xrMirrorWindow=window.open(i,"webxr sync","popup=yes"),this.xrMirrorWindow&&(this.xrMirrorWindow.onload=()=>{this.xrMirrorWindow&&(this.xrMirrorWindow.onbeforeunload=()=>{Mn.IsInWebXR&&e.end()})})},1e3)}},u(Sd,"_isInXr",!1),u(Sd,"events",new Ln),u(Sd,"_optionalFeatures_VR",["local-floor","bounded-floor","hand-tracking","high-fixed-foveation-level","layers"]),u(Sd,"_optionalFeatures_AR",["anchors","local-floor","hand-tracking","layers"]),Sd);let Ct=Mn;hp([w()],Ct.prototype,"enableVR",2);hp([w()],Ct.prototype,"enableAR",2);hp([w(Xn)],Ct.prototype,"defaultAvatar",2);hp([w()],Ct.prototype,"handModelPath",2);hp([w()],Ct.prototype,"createVRButton",2);hp([w()],Ct.prototype,"createARButton",2);const Kd=class{constructor(e){u(this,"_webxr");u(this,"reticle",null);u(this,"reticleParent",null);u(this,"hitTestSource",null);u(this,"reticleActive",!0);u(this,"previousBackground",null);u(this,"previousEnvironment",null);u(this,"sessionRoot",null);u(this,"_previousParent",null);u(this,"arDomOverlay",null);u(this,"arOverlayElement",null);u(this,"noHitTestAvailable",!1);u(this,"didPlaceARSessionRoot",!1);this._webxr=e}get webxr(){return this._webxr}get context(){return this.webxr.context}getAROverlayContainer(){this.arDomOverlay=this.webxr.context.domElement;const e=this.arDomOverlay;return e.getAROverlayContainer?this.arOverlayElement=e.getAROverlayContainer():this.arOverlayElement=this.arDomOverlay,this.arOverlayElement}setReticleActive(e){this.reticleActive=e}async onBegin(e){var o,a,l,c;const t=this.webxr.context;this.reticleActive=!0,this.didPlaceARSessionRoot=!1,this.getAROverlayContainer();const i=(o=navigator.userAgent)!=null&&o.includes("OculusBrowser")?of.PhysicalDevice:of.Touch,s=i===of.Touch?4:2;for(let h=0;h<s;h++)Yi.Create(this.webxr,h,this.webxr.gameObject,i);(!this.sessionRoot||this.sessionRoot.destroyed||!this.sessionRoot.activeAndEnabled)&&(this.sessionRoot=$.findObjectOfType(ch,t)),this.previousBackground=t.scene.background,this.previousEnvironment=t.scene.environment,t.scene.background=null,e.requestReferenceSpace("viewer").then(h=>{var d,f;(f=(d=e.requestHitTestSource)==null?void 0:d.call(e,{space:h}))==null||f.then(p=>{this.hitTestSource=p}).catch(p=>{this.noHitTestAvailable=!0,console.warn("WebXR: Hit test not supported",p)})}),!this.reticle&&this.sessionRoot&&(this.reticle=new ve(new Uf(.07,.09,32).rotateX(-Math.PI/2),new vi),this.reticle.name="AR Placement reticle",this.reticle.matrixAutoUpdate=!1,this.reticle.visible=!1,this.reticleParent=new Ie,this.reticleParent.name="AR Reticle Parent",this.reticleParent.matrixAutoUpdate=!1,this.reticleParent.add(this.reticle),this.webxr.scene?(this.context.scene.add(this.reticleParent),this.context.scene.visible=!0):console.warn("Could not found WebXR Rig")),this._previousParent=this.webxr.gameObject,Kd.tempWebXRObject||(Kd.tempWebXRObject=new Ie),this.context.scene.add(Kd.tempWebXRObject),$.addComponent(Kd.tempWebXRObject,this.webxr),this.sessionRoot?(this.sessionRoot.webAR=this,(a=this.sessionRoot)==null||a.onBegin(e)):console.warn("No WebARSessionRoot found in scene");const r=this.context.domElement;(l=r==null?void 0:r.onEnterAR)==null||l.call(r,e,this.arOverlayElement),(c=this.context.mainCameraComponent)==null||c.applyClearFlagsIfIsActiveCamera()}onEnd(e){var s,r;this._previousParent&&($.addComponent(this._previousParent,this.webxr),this._previousParent=null),this.hitTestSource=null;const t=this.webxr.context;t.scene.background=this.previousBackground,t.scene.environment=this.previousEnvironment,this.sessionRoot&&this.sessionRoot.onEnd(this.webxr.Rig,e);const i=this.context.domElement;(s=i.onExitAR)==null||s.call(i,e),(r=this.context.mainCameraComponent)==null||r.applyClearFlagsIfIsActiveCamera()}onUpdate(e,t){var s,r;if(this.noHitTestAvailable===!0){if(this.reticle&&(this.reticle.visible=!1),!this.didPlaceARSessionRoot){this.didPlaceARSessionRoot=!0;const o=this.webxr.Rig,a=Ree.clone();(s=this.sessionRoot)==null||s.placeAt(o,a)}return}if(!this.hitTestSource)return;const i=t.getHitTestResults(this.hitTestSource);if(i.length){const o=i[0],a=this.webxr.context.renderer.xr.getReferenceSpace();if(a){const l=o.getPose(a);if(this.sessionRoot){const c=this.sessionRoot.onUpdate(this.webxr.Rig,e,l);this.didPlaceARSessionRoot=c}if(this.reticle&&(this.reticle.visible=this.reticleActive,this.reticleActive&&l)){const c=l.transform.matrix;this.reticle.matrix.fromArray(c),this.webxr.Rig&&this.reticle.matrix.premultiply(this.webxr.Rig.matrix)}}}else(r=this.sessionRoot)==null||r.onUpdate(this.webxr.Rig,e,null),this.reticle&&(this.reticle.visible=!1)}};let au=Kd;u(au,"tempWebXRObject");const Ree=new He().identity().makeTranslation(0,0,0);class iu{constructor(e,t){u(this,"used",!1);u(this,"inputSource");u(this,"object");u(this,"pointerId");u(this,"isDown");u(this,"isUp");u(this,"isPressed");u(this,"isClicked");u(this,"input");u(this,"event");this.event=t,this.input=e}use(){this.used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId)}stopPropagation(){var e;(e=this.event)==null||e.stopImmediatePropagation()}Use(){this.use()}StopPropagation(){var e;(e=this.event)==null||e.stopImmediatePropagation()}}class up extends Ce{awake(){sr.createIfNoneExists(this.context)}onEnable(){var e;(e=sr.get(this.context))==null||e.register(this)}onDisable(){var e;(e=sr.get(this.context))==null||e.unregister(this)}performRaycast(e=null){return null}}class _u extends up{constructor(){super(...arguments);u(this,"targets",null);u(this,"raycastHits",[])}start(){this.targets=[this.gameObject]}performRaycast(t=null){return this.targets?(t??(t=new qo),t.targets=this.targets,t.results=this.raycastHits,this.context.physics.raycast(t)):null}}class YI extends _u{}const mg=le("debugeventsystem");var rE=(n=>(n.BeforeHandleInput="BeforeHandleInput",n.AfterHandleInput="AfterHandleInput",n))(rE||{});const ha=class extends Ce{constructor(){super();u(this,"raycaster",[]);u(this,"_selectStartFn");u(this,"_selectEndFn");u(this,"_selectUpdateFn");u(this,"_handleEventFn");u(this,"lastPointerEvent",null);u(this,"objectsHoveredThisFrame",[]);u(this,"objectsHoveredLastFrame",[]);u(this,"raisedPointerDownEvents",[]);u(this,"raisedPointerDownObjects",[]);u(this,"_didMove",!1);u(this,"_tempComponentsArray",[]);u(this,"_sortedHits",[]);u(this,"_sortingBuffer",[]);u(this,"_noDepthTestingResults",[]);u(this,"handleEventsArray",[]);u(this,"out",{});u(this,"currentActiveMeshUIComponents",[]);ha.systems.push(this)}static createIfNoneExists(t){this.didSearchEventSystem||(this.didSearchEventSystem=!0,ha.systems.length<=0&&ha.systems.push(...$.findObjectsOfType(ha,t)));for(const s of ha.systems)if(s.context===t)return;const i=new Ie;$.addNewComponent(i,ha),t.scene.add(i)}static get systems(){const t=_t.Current;return this._eventSystemMap.has(t)||this._eventSystemMap.set(t,[]),this._eventSystemMap.get(t)}static get(t){const i=this._eventSystemMap.get(t);return i&&i.length>0?i[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(t,i){ul.update(t,i)}static markUIDirty(t){ul.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.objectsHoveredThisFrame.length>0}onDestroy(){ha.systems.splice(ha.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!$.findObjectOfType(up,this.context)){const i=$.addNewComponent(this.context.scene,_u);this.raycaster.push(i),Qs()&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found",this)}}register(t){var i;t&&this.raycaster&&!this.raycaster.includes(t)&&((i=this.raycaster)==null||i.push(t))}unregister(t){var s,r;const i=(s=this.raycaster)==null?void 0:s.indexOf(t);i!==void 0&&i!==-1&&((r=this.raycaster)==null||r.splice(i,1))}onEnable(){const t=new Map;this._selectStartFn??(this._selectStartFn=(s,r)=>{if(!r.grab)return;ul.resetLastSelected();const o=new iu(this.context.input);o.inputSource=s,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=!1,t.set(s,r.grab),r.grab&&!this.handleEvents(r.grab,o)&&(r.grab=null)}),this._selectEndFn??(this._selectEndFn=(s,r)=>{var l;if(!r.grab)return;const o=new iu(this.context.input);o.inputSource=s,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=s.selectionClick,this.handleEvents(r.grab,o);const a=t.get(s);if(t.set(s,null),a)for(let c=0;c<this.raisedPointerDownEvents.length;c++){const h=this.raisedPointerDownEvents[c];this.raisedPointerDownObjects[c]===a&&h&&((l=h.onPointerUp)==null||l.call(h,o),this.raisedPointerDownEvents.splice(c,1),this.raisedPointerDownObjects.splice(c,1),c--)}});const i=new qo;this._selectUpdateFn??(this._selectUpdateFn=s=>{i.ray=s.getRay();const r=this.performRaycast(i);if(!r)return;const o=new iu(this.context.input);o.inputSource=s,this.handleIntersections(r,o)}),Yi.addEventListener(hl.SelectStart,this._selectStartFn),Yi.addEventListener(hl.SelectEnd,this._selectEndFn),Yi.addEventListener(hl.Update,this._selectUpdateFn),this._handleEventFn??(this._handleEventFn=this.onHandleEvents.bind(this)),this.context.pre_update_callbacks.push(this._handleEventFn)}onDisable(){Yi.removeEventListener(hl.SelectStart,this._selectStartFn),Yi.removeEventListener(hl.SelectEnd,this._selectEndFn),Yi.removeEventListener(hl.Update,this._selectUpdateFn),this.context.pre_update_callbacks.splice(this.context.pre_update_callbacks.indexOf(this._handleEventFn),1)}onHandleEvents(){if(this.objectsHoveredThisFrame.length=0,this.resetMeshUIStates(),Ct.IsInWebXR||this.context.input.isKeyPressed("AltLeft")||this.context.input.isKeyPressed("AltRight"))return;if(!this._didMove){const a=this.context.input.getPointerPositionRC(0);if(a&&a.x===0&&a.y===0)return;this._didMove=!0}let t=0;for(const a of this.context.input.foreachPointerId()){const l=this.context.input.getPointerDown(a),c=this.context.input.getPointerUp(a);if(l||c){t=a;break}}const i=this.context.input.getPointerEvent(t),s=new iu(this.context.input,i);s.inputSource=this.context.input,s.pointerId=t,s.isClicked=this.context.input.getPointerClicked(t),s.isDown=this.context.input.getPointerDown(t),s.isUp=this.context.input.getPointerUp(t),s.isPressed=this.context.input.getPointerPressed(t),mg&&s.isClicked&&console.log("CLICK",t);const r=this.performRaycast(null);if(!r)return;this.lastPointerEvent=s;const o={sender:this,args:s,hasActiveUI:this.currentActiveMeshUIComponents.length>0};mg&&s.isClicked&&jn("EventSystem: "+s.pointerId+" - "+this.context.time.frame+" - Up:"+s.isUp+", Down:"+s.isDown),this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:o})),this.handleIntersections(r,s),this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:o}))}onBeforeRender(){if(this.lastPointerEvent)this.lastPointerEvent.used=!1;else return;if(this.lastPointerEvent.isUp){for(const i of this.raisedPointerDownEvents)i.onPointerUp&&i.onPointerUp(this.lastPointerEvent);this.raisedPointerDownEvents.length=0,this.raisedPointerDownObjects.length=0}for(const i of this.objectsHoveredLastFrame)if(this.objectsHoveredThisFrame.indexOf(i)<0){this._tempComponentsArray.length=0;const s=$.getComponentsInParent(i,Ce,this._tempComponentsArray);this.lastPointerEvent.object=i;for(let r=0;r<s.length;r++){const o=s[r];if(!o.gameObject||o.destroyed)continue;const a=o;a.onPointerExit&&a.onPointerExit(this.lastPointerEvent)}}const t=this.objectsHoveredLastFrame;this.objectsHoveredLastFrame=this.objectsHoveredThisFrame,this.objectsHoveredThisFrame=t}performRaycast(t){if(!this.raycaster)return null;this._sortedHits.length=0;for(const i of this.raycaster){if(!i.activeAndEnabled)continue;const s=i.performRaycast(t);s&&s.length>0&&this._sortedHits.push(...s)}return this._sortedHits.sort((i,s)=>i.distance-s.distance),this._sortedHits}handleIntersections(t,i){if(!t||t.length<=0)return!1;t=this.sortCandidates(t);for(const s of t){const{object:r}=s;if(this.handleEvents(r,i))return!0}return!1}sortCandidates(t){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let i=0;i<t.length;i++){const s=t[i],r=s.object;if(r.material&&r.material.depthTest===!1){this._noDepthTestingResults.push(s);continue}this._sortingBuffer.push(s)}for(const i of this._sortingBuffer)this._noDepthTestingResults.push(i);return this._noDepthTestingResults}handleEvents(t,i){if(!this.testIsVisible(t))return i.isClicked&&mg&&console.log("not allowed",t),!1;const s=t;i.object=t,this.lastPointerEvent=i;const r=t.parent;let o=!1;const a=i.isClicked??!1;let l=null;if(r&&r.isUI){const c=(i.isPressed||i.isClicked)??!1;if(r[vl]){const h=r[vl].gameObject;if(h){if(!Mf.isInteractable(h,this.out))return!1;l=this.out.canvasGroup??null,this.handleMeshUIIntersection(t,c),t=h,o=!0}}if(!o&&this.handleMeshUiObjectWithoutShadowDom(r,c))return!0}if(a&&mg&&console.log(this.context.time.frame,t),this.objectsHoveredThisFrame.push(t),l===null||l.interactable){const c=this.objectsHoveredLastFrame.indexOf(t)>=0;this.handleEventsArray.length=0;const h=$.getComponentsInParent(t,Ce,this.handleEventsArray);for(let d=0;d<h.length;d++){if(i.used)return!0;if(h[d].destroyed)continue;const f=h[d];if(f.interactable!==!1){if(f.onPointerEnter&&(c||f.onPointerEnter(i)),f.onPointerMove&&f.onPointerMove(i),i.isDown&&f.onPointerDown&&!this.raisedPointerDownEvents.includes(f)&&(f.onPointerDown(i),this.raisedPointerDownEvents.push(f),this.raisedPointerDownObjects.push(s)),i.isUp&&f.onPointerUp){const p=this.raisedPointerDownEvents.indexOf(f);p!==-1&&this.raisedPointerDownEvents.splice(p,1),f.onPointerUp(i)}i.isClicked&&f.onPointerClick&&f.onPointerClick(i)}}}return!0}handleMeshUiObjectWithoutShadowDom(t,i){return!t||!t.isUI?!0:this.handleMeshUIIntersection(t,i)}handleMeshUIIntersection(t,i){const s=ul.updateState(t,i);return s&&this.currentActiveMeshUIComponents.push(s),s!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&ul.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let t=0;t<this.currentActiveMeshUIComponents.length;t++){const i=this.currentActiveMeshUIComponents[t];ul.resetState(i)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(t){return t?$.isActiveSelf(t)?this.testIsVisible(t.parent):!1:!0}};let sr=ha;u(sr,"_eventSystemMap",new Map),u(sr,"didSearchEventSystem",!1);class ul{static markDirty(){this.needsUpdate=!0}static update(e,t){const i=t.time.frameCount;for(const s of this.lastUpdateFrame)if(s.context===t){if(i===s.frame)return;s.frame=i;let r=this.needsUpdate||i<1;s.nextUpdate===t.time.frameCount&&(r=!0),r&&(mg&&console.log("Update threemeshui"),this.needsUpdate=!1,e.update());return}this.lastUpdateFrame=[{context:t,frame:i,nextUpdate:i}],e.update()}static updateState(e,t){let i=null;if(e&&(i=this.findBlockInParent(e),i&&i!==this.lastSelected)){if(i.interactable===!1)return null;this.needsUpdate=!0}return i}static resetLastSelected(){const e=this.lastSelected;e&&(this.lastSelected=null,this.resetState(e))}static resetState(e){e&&(this.needsUpdate=!0)}static findBlockInParent(e){return e?e.isBlock?e:this.findBlockInParent(e.parent):null}}u(ul,"lastSelected",null),u(ul,"lastUpdateFrame",[]),u(ul,"needsUpdate",!1);const g0=Symbol("cameraController");function Bee(n){return n[g0]}function UB(n,e,t){t?n[g0]=e:n[g0]===e&&(n[g0]=null)}var Dee=Object.defineProperty,kee=Object.getOwnPropertyDescriptor,Oee=(n,e,t,i)=>{for(var s=i>1?void 0:i?kee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Dee(e,t,s),s};const Ay=le("freecam"),NB=le("debugcamerafit"),Lee={LEFT:"",UP:"",RIGHT:"",BOTTOM:""};let Jw;class ql extends Ce{constructor(){super(...arguments);u(this,"autoRotate",!1);u(this,"autoRotateSpeed",1);u(this,"enableKeys",!0);u(this,"enableDamping",!0);u(this,"dampingFactor",.1);u(this,"enableZoom",!0);u(this,"minZoom",0);u(this,"maxZoom",1/0);u(this,"enablePan",!0);u(this,"lookAtConstraint",null);u(this,"lookAtConstraint01",1);u(this,"middleClickToFocus",!0);u(this,"doubleClickToFocus",!0);u(this,"useSlerp",!0);u(this,"debugLog",!1);u(this,"targetLerpSpeed",5);u(this,"_lookTargetPosition");u(this,"_controls",null);u(this,"_cameraObject",null);u(this,"_lerpToTargetPosition",!1);u(this,"_lerpCameraToTarget",!1);u(this,"_cameraTargetPosition",null);u(this,"_inputs",0);u(this,"_enableTime",0);u(this,"_startedListeningToKeyEvents",!1);u(this,"_eventSystem");u(this,"_afterHandleInputFn");u(this,"_camera",null);u(this,"_syncedTransform");u(this,"targetElement",null);u(this,"_shouldDisable",!1);u(this,"_haveAttachedKeyboardEvents",!1)}get isCameraController(){return!0}get controls(){return this._controls}get controllerObject(){return this._cameraObject}onStartInteraction(t){var i;(i=this.controls)==null||i.addEventListener("start",t)}awake(){this._lookTargetPosition=new S,this._startedListeningToKeyEvents=!1}start(){if(this._controls){const t=$.getComponent(this.gameObject,Oi);if(t&&!this.setFromTargetPosition()){this.debugLog&&console.log("NO TARGET");const s=wt(t.cam).length(),r=new S(0,0,-s).applyMatrix4(t.cam.matrixWorld);this.setTarget(r,!0)}}this.startCoroutine(this.startRaycastDelayed()),this._eventSystem=sr.get(this.context)??void 0,this._eventSystem&&(this._afterHandleInputFn=this.afterHandleInput.bind(this),this._eventSystem.addEventListener(rE.AfterHandleInput,this._afterHandleInputFn))}onDestroy(){var t,i;(t=this._controls)==null||t.dispose(),(i=this._eventSystem)==null||i.removeEventListener(rE.AfterHandleInput,this._afterHandleInputFn)}onEnable(){this._enableTime=this.context.time.time;const t=$.getComponent(this.gameObject,Oi);this._camera=t;const i=t==null?void 0:t.cam;if(i&&UB(i,this,!0),!this._controls){console.assert(i!=null,"Missing camera",this),i&&(this._cameraObject=i);const s=this.targetElement??this.context.domElement;this._controls=new NY(i,s),Jw===void 0&&(Jw={...this._controls.keys})}this._controls&&(Ay&&(this.enablePan=!0,this.enableZoom=!0,this.middleClickToFocus=!0,xu()&&(this.doubleClickToFocus=!0)),this._controls.enableDamping=this.enableDamping,this._controls.keys=this.enableKeys?Jw:Lee,this._controls.autoRotate=this.autoRotate,this._controls.autoRotateSpeed=this.autoRotateSpeed,this._controls.enableZoom=this.enableZoom,this._controls.addEventListener("start",this.onControlsChangeStarted.bind(this)),(i==null?void 0:i.type)==="PerspectiveCamera"?Ay||(this._controls.minDistance=this.minZoom,this._controls.maxDistance=this.maxZoom):Ay||(this._controls.minZoom=this.minZoom,this._controls.maxZoom=this.maxZoom),this._controls.dampingFactor=this.dampingFactor,this._controls.enablePan=this.enablePan,this._startedListeningToKeyEvents||(this._startedListeningToKeyEvents=!0,this._controls.listenToKeyEvents(window.document.body))),this._syncedTransform=$.getComponent(this.gameObject,Jc)??void 0}onDisable(){var t;(t=this._camera)!=null&&t.cam&&UB(this._camera.cam,this,!1),this._controls&&(this._controls.enabled=!1,this._controls.autoRotate=!1)}onControlsChangeStarted(){this._syncedTransform&&this._syncedTransform.requestOwnership()}afterHandleInput(t){t.detail.args.pointerId===0&&(t.detail.args.isDown?this._controls&&this._eventSystem&&(this._shouldDisable=this._eventSystem.hasActiveUI):(!t.detail.args.isPressed||t.detail.args.isUp)&&(this._shouldDisable=!1))}*startRaycastDelayed(){if(yield,!this.setFromTargetPosition()){const t=new qo;t.screenPoint=new q(0,0),t.lineThreshold=.1;const i=this.context.physics.raycast(t);i.length>0&&this.setTarget(i[0].point,!0)}}onBeforeRender(){var i,s,r;if(!this._controls||this._cameraObject!==this.context.mainCamera)return;(this.context.input.getPointerDown(0)||this.context.input.getPointerDown(1)||this.context.input.getPointerDown(2))&&(this._inputs+=1),this._inputs>0&&(this.autoRotate=!1,this._controls.autoRotate=!1,this._lerpCameraToTarget=!1,this._lerpToTargetPosition=!1),this._inputs=0;let t=this.middleClickToFocus&&this.context.input.getPointerClicked(1);if(t||(t=this.doubleClickToFocus&&this.context.input.getPointerDoubleClicked(0)&&this.context.time.time-this._enableTime>.3),t?this.setTargetFromRaycast():(this.context.input.getPointerDown(0)||this.context.input.mouseWheelChanged)&&(this._lerpToTargetPosition=!1,this._lerpCameraToTarget=!1),this._lerpToTargetPosition||this._lerpCameraToTarget){const o=this.context.time.deltaTime*this.targetLerpSpeed;if(this._lerpCameraToTarget&&this._cameraTargetPosition&&this._cameraObject){if(this.useSlerp){const a=(i=this._cameraObject)==null?void 0:i.position;cO(a,this._cameraTargetPosition,o)}else(s=this._cameraObject)==null||s.position.lerp(this._cameraTargetPosition,o);this._cameraObject.position.distanceTo(this._cameraTargetPosition)<1e-4&&(this._lerpCameraToTarget=!1)}this._lerpToTargetPosition&&(this.lerpTarget(this._lookTargetPosition,o),this._lookTargetPosition.distanceTo(this._controls.target)<1e-5&&(this._lerpToTargetPosition=!1))}!Ay&&((r=this.lookAtConstraint)!=null&&r.locked)&&this.setFromTargetPosition(0,this.lookAtConstraint01),this._controls&&!this.context.isInXR&&(this.debugLog&&(this._controls.domElement=this.context.renderer.domElement),this._controls.enabled=!this._shouldDisable&&this._camera===this.context.mainCameraComponent,this._controls.update())}setCameraTarget(t,i=!1){var s;t?(this._lerpCameraToTarget=!0,this._cameraTargetPosition=t.clone(),i&&this._cameraTargetPosition&&((s=this.controllerObject)==null||s.position.copy(this._cameraTargetPosition))):this._lerpCameraToTarget=!1}setFromTargetPosition(t=0,i=1){var r;if(!this._controls)return!1;const s=(r=this.lookAtConstraint)==null?void 0:r.sources;if(s&&s.length>0){const o=s[t];if(o)return o.getWorldPosition(this._lookTargetPosition),this.lerpTarget(this._lookTargetPosition,i),!0}return!1}setTarget(t=null,i=!1){this._controls&&(t!==null&&this._lookTargetPosition.copy(t),i?this._controls.target.copy(this._lookTargetPosition):this._lerpToTargetPosition=!0)}lerpTarget(t,i){this._controls&&this._controls.target.lerp(t,i)}distanceToTarget(t){return this._controls?this._controls.target.distanceTo(t):-1}setTargetFromRaycast(){var i,s;if(!this.controls)return;const t=this.context.physics.raycast();for(const r of t)if(r.distance>0&&$.isActiveInHierarchy(r.object)){if(this._lookTargetPosition.copy(r.point),this._lerpToTargetPosition=!0,this._cameraTargetPosition=null,this.context.mainCamera){this._lerpCameraToTarget=!0;const o=wt(this.context.mainCamera);this._cameraTargetPosition=o.clone().sub(this.controls.target).add(this._lookTargetPosition),(s=(i=this._cameraObject)==null?void 0:i.parent)==null||s.worldToLocal(this._cameraTargetPosition)}break}}fitCamera(t,i=1.1){const s=this._cameraObject,r=this._controls;if(t!=null&&t.length||(t=this.context.scene.children),!s||!r)return;const o=new S,a=new S,l=new _s;l.makeEmpty();for(const A of t)A instanceof uS||l.expandByObject(A,!0);s.updateMatrixWorld(),s.updateProjectionMatrix(),l.getCenter(a),l.applyMatrix4(s.matrixWorldInverse),l.getSize(o),l.setFromCenterAndSize(a,o);const c=s.fov,h=2*Math.atan(Math.tan(c*Math.PI/360/2)*s.aspect)/Math.PI*360,d=o.y/(2*Math.atan(Math.PI*c/360)),f=o.x/(2*Math.atan(Math.PI*h/360)),p=i*Math.max(d,f)+o.z/2;NB&&console.log("Fit camera to objects",d,f,"distance",p);const g=wt(s),m=r.target.clone().sub(g).normalize().multiplyScalar(p);if(r.maxDistance=p*10,r.minDistance=p*.01,r.target.copy(a),s.near=p/100,s.far=p*100,s.updateMatrixWorld(),s.updateProjectionMatrix(),ln(s,r.target.clone().sub(m)),NB){const A=new uS(l);this.context.scene.add(A),fO(A,tb(s)),this._haveAttachedKeyboardEvents||(this._haveAttachedKeyboardEvents=!0,document.body.addEventListener("keydown",v=>{v.code==="KeyF"&&this.fitCamera(t)}))}r.update()}}Oee([w(EA)],ql.prototype,"lookAtConstraint",2);var Fee=Object.defineProperty,Uee=Object.getOwnPropertyDescriptor,mo=(n,e,t,i)=>{for(var s=i>1?void 0:i?Uee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Fee(e,t,s),s},yN=(n=>(n[n.Skybox=1]="Skybox",n[n.SolidColor=2]="SolidColor",n[n.Uninitialized=4]="Uninitialized",n))(yN||{});const Ag=le("debugcam"),zB=le("debugscreenpointtoray");var Ly;const vg=(Ly=class extends Ce{constructor(){super(...arguments);u(this,"_nearClipPlane",.1);u(this,"_farClipPlane",1e3);u(this,"orthographic",!1);u(this,"orthographicSize",5);u(this,"ARBackgroundAlpha",0);u(this,"_cullingMask",4294967295);u(this,"_backgroundBlurriness");u(this,"_backgroundIntensity");u(this,"_targetTexture",null);u(this,"_backgroundColor");u(this,"_fov");u(this,"_cam",null);u(this,"_clearFlags",2);u(this,"_skybox")}get isCamera(){return!0}get aspect(){return this._cam instanceof $t?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._cam instanceof $t?this._cam.fov:this._fov}set fieldOfView(e){const t=this._fov!=e;if(this._fov=e,t&&this._cam&&this._cam instanceof $t){if(this._fov===void 0){console.error("Can not set undefined fov on PerspectiveCamera");return}this._cam.fov=this._fov,this._cam.updateProjectionMatrix()}}get nearClipPlane(){return this._nearClipPlane}set nearClipPlane(e){const t=this._nearClipPlane!=e;this._nearClipPlane=e,this._cam&&t&&(this._cam.near=e,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(e){const t=this._farClipPlane!=e;this._farClipPlane=e,this._cam&&t&&(this._cam.far=e,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(e){e!==this._clearFlags&&(this._clearFlags=e,this.applyClearFlagsIfIsActiveCamera())}set cullingMask(e){this._cullingMask=e,this._cam&&(this._cam.layers.mask=e)}get cullingMask(){return this._cam?this._cam.layers.mask:this._cullingMask}set backgroundBlurriness(e){e!==this._backgroundBlurriness&&(e===void 0?this._backgroundBlurriness=void 0:this._backgroundBlurriness=Math.min(Math.max(e,0),1),this.applyClearFlagsIfIsActiveCamera())}get backgroundBlurriness(){return this._backgroundBlurriness}set backgroundIntensity(e){e!==this._backgroundIntensity&&(e===void 0?this._backgroundIntensity=void 0:this._backgroundIntensity=Math.min(Math.max(e,0),10),this.applyClearFlagsIfIsActiveCamera())}get backgroundIntensity(){return this._backgroundIntensity}get backgroundColor(){return this._backgroundColor??null}set backgroundColor(e){if(e){if(this._backgroundColor)this._backgroundColor.copy(e);else{if(!e.clone)return;this._backgroundColor=e.clone()}e.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}set targetTexture(e){this._targetTexture=e}get targetTexture(){return this._targetTexture}get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}screenPointToRay(e,t,i){let s=this.cam;const r=vg._origin;r.set(e,t,-1),this.context.input.convertScreenspaceToRaycastSpace(r),zB&&console.log("screenPointToRay",e.toFixed(2),t.toFixed(2),"now:",r.x.toFixed(2),r.y.toFixed(2),"isInXR:"+this.context.isInXR),r.z=-1,r.unproject(s);const o=vg._direction.set(r.x,r.y,r.z),a=wt(s);return o.sub(a),o.normalize(),i?(i.set(a,o),i):new Gl(a.clone(),o.clone())}awake(){this.sourceId||console.warn("Camera has no source - the camera should be exported inside a gltf",this.name),zB&&window.addEventListener("pointerdown",e=>{const t=e.clientX,i=e.clientY;console.log("touch",t.toFixed(2),i.toFixed(2));const s=this.screenPointToRay(t,i),r="#"+Math.floor(Math.random()*16777215).toString(16);xa.DrawRay(s.origin,s.direction,r,10)})}onEnable(){Ag&&console.log(this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&(this.context.setCurrentCamera(this),zee(this)),this.applyClearFlagsIfIsActiveCamera()}onDisable(){this.context.removeCamera(this)}onBeforeRender(){if(this._cam&&this._targetTexture){this.context.isManagedExternally&&(this._warnedAboutExternalRenderer||(this._warnedAboutExternalRenderer=!0,console.warn("Rendering with external renderer is not supported yet. This may not work or throw errors. Please remove the the target texture from your camera: "+this.name,this.targetTexture))),this.context.composer;const e=this.context.renderer;e&&this._targetTexture.render(this.context.scene,this._cam,e)}}buildCamera(){if(this._cam)return;const e=this.gameObject.isCamera;let t=null;if(e?(t=this.gameObject,t==null||t.layers.enableAll(),t instanceof $t&&(this._fov=t.fov)):t=this.gameObject.children[0],t&&t.isCamera)t.type==="PerspectiveCamera"&&(this._fov&&(t.fov=this._fov),t.near=this._nearClipPlane,t.far=this._farClipPlane,t.updateProjectionMatrix());else if(!this.orthographic)t=new $t(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),this.fieldOfView&&(t.fov=this.fieldOfView),this.gameObject.add(t);else{const i=this.orthographicSize*100;t=new Rf(window.innerWidth/-i,window.innerWidth/i,window.innerHeight/i,window.innerHeight/-i,this._nearClipPlane,this._farClipPlane),this.gameObject.add(t)}this._cam=t,this._cam.layers.mask=this._cullingMask,this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){this.context.mainCameraComponent===this&&this.applyClearFlags()}applyClearFlags(){if(!this._cam){Ag&&console.log("Camera does not exist (apply clear flags)");return}switch(Ag&&jn("apply Camera clear flags: "+this._clearFlags),this._clearFlags){case 1:if(vg.backgroundShouldBeTransparent(this.context)&&(!this.ARBackgroundAlpha||this.ARBackgroundAlpha<.001)){this.context.scene.background=null,this.context.renderer.setClearColor(0,0);return}this.enableSkybox(),this._backgroundBlurriness!==void 0&&(this.context.scene.backgroundBlurriness=this._backgroundBlurriness),this._backgroundIntensity!==void 0&&(this.context.scene.backgroundIntensity=this._backgroundIntensity);break;case 2:if(this._backgroundColor){let e=this._backgroundColor.alpha;vg.backgroundShouldBeTransparent(this.context)&&(e=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,e)}break;case 4:this.context.scene.background=null,this.context.renderer.setClearColor(0,0);break}}enableSkybox(){this._skybox||(this._skybox=new Nee(this)),this._skybox.enable()}static backgroundShouldBeTransparent(e){var r,o,a,l;const t=(r=e.renderer.xr)==null?void 0:r.getSession();if(!t)return!1;const i=t.environmentBlendMode;Ag&&jn("Environment blend mode: "+i+" on "+navigator.userAgent);const s=i==="additive"||i==="alpha-blend";if(e.xrSessionMode===ym.ImmersiveAR&&i==="opaque"){if((o=navigator.userAgent)!=null&&o.includes("OculusBrowser"))return!0;if((a=navigator.userAgent)!=null&&a.includes("Mozilla")&&((l=navigator.userAgent)!=null&&l.includes("Mobile WebXRViewer/v2")))return!0}return s}},u(Ly,"_origin",new S),u(Ly,"_direction",new S),Ly);let Oi=vg;mo([w()],Oi.prototype,"fieldOfView",1);mo([w()],Oi.prototype,"nearClipPlane",1);mo([w()],Oi.prototype,"farClipPlane",1);mo([w()],Oi.prototype,"clearFlags",1);mo([w()],Oi.prototype,"orthographic",2);mo([w()],Oi.prototype,"orthographicSize",2);mo([w()],Oi.prototype,"ARBackgroundAlpha",2);mo([w()],Oi.prototype,"cullingMask",1);mo([w()],Oi.prototype,"backgroundBlurriness",1);mo([w()],Oi.prototype,"backgroundIntensity",1);mo([w(xi)],Oi.prototype,"backgroundColor",1);mo([w(Hc)],Oi.prototype,"targetTexture",1);class Nee{constructor(e){u(this,"_camera");u(this,"_skybox");this._camera=e}get context(){var e;return(e=this._camera)==null?void 0:e.context}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?this.context.scene.background!==this._skybox&&(Ag&&console.log("Set skybox",this._camera,this._skybox),this._skybox.encoding=yt,this._skybox.mapping=oo,this.context.scene.background=this._skybox):console.warn("Failed to load/find skybox texture",this._camera.sourceId,this.context.lightmaps)}}function zee(n){le("freecam")&&n.context.mainCameraComponent===n&&$.getOrAddComponent(n.gameObject,ql)}class Tf extends Ce{constructor(){super(...arguments);u(this,"_listener",null)}get listener(){return this._listener==null&&(this._listener=new A1),this._listener}awake(){xn.registerWaitForAllowAudio(()=>{if(this.destroyed)return;const t=this.listener;if(t==null||t.parent)return;const i=$.getComponentInParent(this.gameObject,Oi);i?i.cam.add(t):this.gameObject.add(t)})}}var Gee=Object.defineProperty,Qee=Object.getOwnPropertyDescriptor,Qb=(n,e,t,i)=>{for(var s=i>1?void 0:i?Qee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Gee(e,t,s),s};class DA{constructor(){u(this,"guid")}}Qb([w()],DA.prototype,"guid",2);class dp{constructor(){u(this,"signal");u(this,"reaction")}}Qb([w(DA)],dp.prototype,"signal",2);Qb([w(ar)],dp.prototype,"reaction",2);var CC;const rl=(CC=class extends Ce{constructor(){super(...arguments);u(this,"events")}static invoke(e){if(rl.receivers[e]){const t=rl.receivers[e];if(!t)return;for(const i of t)i.invoke(e)}}onEnable(){if(this.events)for(const e of this.events)rl.receivers[e.signal.guid]||(rl.receivers[e.signal.guid]=[]),rl.receivers[e.signal.guid].push(this)}onDisable(){if(this.events){for(const e of this.events)if(rl.receivers[e.signal.guid]){const t=rl.receivers[e.signal.guid].indexOf(this);t>=0&&rl.receivers[e.signal.guid].splice(t,1)}}}invoke(e){if(!this.events||!Array.isArray(this.events))return;let t=typeof e=="object"?e.guid:e;for(const i of this.events)if(i.signal.guid===t)try{if(i.reaction){if(!i.reaction.invoke){console.warn("Missing invoke - possibly a serialization error",i,this);continue}}else{console.warn("Missing reaction for signal",i,this);continue}i.reaction.invoke()}catch(s){console.error(s)}}},u(CC,"receivers",{}),CC);let fp=rl;Qb([w(dp)],fp.prototype,"events",2);var Ar=(n=>(n.Activation="ActivationTrack",n.Animation="AnimationTrack",n.Audio="AudioTrack",n.Control="ControlTrack",n.Marker="MarkerTrack",n.Signal="SignalTrack",n))(Ar||{}),Ec=(n=>(n[n.None=0]="None",n[n.Hold=1]="Hold",n[n.Loop=2]="Loop",n[n.PingPong=3]="PingPong",n[n.Continue=4]="Continue",n))(Ec||{}),JI=(n=>(n.Signal="SignalEmitter",n))(JI||{});const $p=le("debugtimeline"),C_=class extends Ce{constructor(){super(...arguments);u(this,"playableAsset");u(this,"playOnAwake");u(this,"extrapolationMode",1);u(this,"waitForAudio",!0);u(this,"_visibilityChangeEvt");u(this,"_clonedPlayableAsset",!1);u(this,"_speed",1);u(this,"_guidsMap");u(this,"_isPlaying",!1);u(this,"_internalUpdateRoutine");u(this,"_isPaused",!1);u(this,"_time",0);u(this,"_duration",0);u(this,"_weight",1);u(this,"_animationTracks",[]);u(this,"_audioTracks",[]);u(this,"_signalTracks",[]);u(this,"_controlTracks",[]);u(this,"_customTracks",[]);u(this,"_allTracks",[this._animationTracks,this._audioTracks,this._signalTracks,this._controlTracks,this._customTracks])}static registerCreateTrack(t,i){this.createTrackFunctions[t]=i}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get time(){return this._time}set time(t){typeof t=="number"&&!Number.isNaN(t)?this._time=t:($p||zs())&&console.error("INVALID TIMELINE.TIME VALUE",t,this.name)}get duration(){return this._duration}set duration(t){this._duration=t}get weight(){return this._weight}set weight(t){this._weight=t}get speed(){return this._speed}set speed(t){this._speed=t}awake(){var t,i,s;$p&&console.log(this,(t=this.playableAsset)==null?void 0:t.tracks),this.rebuildGraph(),this.isValid()||console.warn("PlayableDirector is not valid",this.playableAsset,(i=this.playableAsset)==null?void 0:i.tracks,Array.isArray((s=this.playableAsset)==null?void 0:s.tracks),this)}onEnable(){var t,i;for(const s of this._audioTracks)(t=s.onEnable)==null||t.call(s);for(const s of this._customTracks)(i=s.onEnable)==null||i.call(s);this.playOnAwake&&this.play(),this._visibilityChangeEvt||(this._visibilityChangeEvt=()=>{switch(document.visibilityState){case"hidden":this.setAudioTracksAllowPlaying(!1);break;case"visible":this.setAudioTracksAllowPlaying(!0);break}}),window.addEventListener("visibilitychange",this._visibilityChangeEvt)}onDisable(){var t,i;this.stop();for(const s of this._audioTracks)(t=s.onDisable)==null||t.call(s);for(const s of this._customTracks)(i=s.onDisable)==null||i.call(s);this._visibilityChangeEvt&&window.removeEventListener("visibilitychange",this._visibilityChangeEvt)}onDestroy(){var t;for(const i of this._allTracks)for(const s of i)(t=s.onDestroy)==null||t.call(s)}rebuildGraph(){this.isValid()&&(this.resolveBindings(),this.updateTimelineDuration(),this.setupAndCreateTrackHandlers())}async play(){if(!this.isValid())return;const t=this._isPaused==!0;if(this._isPaused=!1,t&&this.invokePauseChangedMethodsOnTracks(),!this._isPlaying){if(this._isPlaying=!0,this.waitForAudio){const i=[];for(const s of this._audioTracks){const r=s.loadAudio(this._time,1,0);r&&i.push(r)}if(i.length>0&&(await Promise.all(i),!this._isPlaying))return;for(;this._audioTracks.length>0&&this._isPlaying&&!xn.userInteractionRegistered&&this.waitForAudio;)await jm(200)}this._internalUpdateRoutine=this.startCoroutine(this.internalUpdate())}}pause(){this.isValid()&&(this._isPlaying=!1,!this._isPaused&&(this._isPaused=!0,this.evaluate(),this.invokePauseChangedMethodsOnTracks()))}stop(){for(const s of this._audioTracks)s.stop();const t=this._isPaused==!0,i=this._isPlaying;this._isPlaying&&(this._time=0,this._isPlaying=!1,this._isPaused=!1,this.evaluate(),t&&this.invokePauseChangedMethodsOnTracks()),this._isPlaying=!1,this._isPaused=!1,t&&!i&&this.invokePauseChangedMethodsOnTracks(),this._internalUpdateRoutine&&this.stopCoroutine(this._internalUpdateRoutine),this._internalUpdateRoutine=null}evaluate(){if(!this.isValid())return;let t=this._time;switch(this.extrapolationMode){case 0:this._speed>0?t=Math.min(t,this._duration):this._speed<0&&(t=Math.max(t,0)),this._time=t;break;case 1:t%=this._duration,this._time=t;break;case 2:if(t>this._duration){this.stop();return}break}this.internalEvaluate(t)}isValid(){return this.playableAsset&&this.playableAsset.tracks&&Array.isArray(this.playableAsset.tracks)}*forEachTrack(){for(const t of this._allTracks)for(const i of t)yield i}get audioTracks(){return this._audioTracks}resolveGuids(t){this._guidsMap=t}invokePauseChangedMethodsOnTracks(){var t;for(const i of this.forEachTrack())(t=i.onPauseChanged)==null||t.call(i)}*internalUpdate(){for(;this._isPlaying&&this.activeAndEnabled;)!this._isPaused&&this._isPlaying&&(this._time+=this.context.time.deltaTime*this.speed,this.evaluate()),yield}internalEvaluate(t){for(const i of this.playableAsset.tracks)if(!i.muted)switch(i.type){case Ar.Activation:for(let s=0;s<i.outputs.length;s++){const r=i.outputs[s];if(typeof r=="object"){let o=!1;for(const l of i.clips)l.start<=t&&t<=l.end&&(o=!0);const a=r;a.visible!==void 0&&(a.visible=o)}}break}for(const i of this._animationTracks)i.evaluate(t);for(const i of this._audioTracks)i.evaluate(t);for(const i of this._signalTracks)i.evaluate(t);for(const i of this._controlTracks)i.evaluate(t);for(const i of this._customTracks)i.evaluate(t)}resolveBindings(){if(this._clonedPlayableAsset||(this._clonedPlayableAsset=!0,this.playableAsset=E_(this.playableAsset)),!this.playableAsset||!this.playableAsset.tracks)return;const t=this.findRoot(this.gameObject);for(const i of this.playableAsset.tracks){for(let s=i.outputs.length-1;s>=0;s--){let r=i.outputs[s];if(typeof r=="string"){this._guidsMap&&this._guidsMap[r]&&(r=this._guidsMap[r]);const o=$.findByGuid(r,t);o===null||typeof o!="object"?(i.outputs.splice(s,1),console.warn("Failed to resolve binding",r,i.name,i.type)):($p&&console.log("Resolved binding",r,"to",o),i.outputs[s]=o)}else if(r===null){if(i.outputs.splice(s,1),C_.createTrackFunctions[i.type])continue;i.type!==Ar.Audio&&i.type!==Ar.Control&&i.type!==Ar.Marker&&i.type!==Ar.Signal&&console.warn("Missing binding",r,i.name,i.type,this.name,this.playableAsset.name)}}if(i.type===Ar.Control)for(let s=0;s<i.clips.length;s++){const r=i.clips[s];let o=r.asset.sourceObject;if(typeof o=="string"){this._guidsMap&&this._guidsMap[o]&&(o=this._guidsMap[o]);const a=$.findByGuid(o,t);a===null||typeof a!="object"?console.warn("Failed to resolve sourceObject binding",o,i.name,r):($p&&console.log("Resolved binding",o,"to",a),r.asset.sourceObject=a)}}}}findRoot(t){return t.parent?this.findRoot(t.parent):t}updateTimelineDuration(){if(this._duration=0,!(!this.playableAsset||!this.playableAsset.tracks)){for(const t of this.playableAsset.tracks)if(t.muted!==!0){for(const i of t.clips)i.end>this._duration&&(this._duration=i.end);for(const i of t.markers)i.time>this._duration&&(this._duration=i.time+.001)}}}setupAndCreateTrackHandlers(){var i,s;if(this._animationTracks.length=0,this._audioTracks.length=0,this._signalTracks.length=0,!this.playableAsset)return;const t=$.findObjectOfType(Tf,this.context);for(const r of this.playableAsset.tracks){const o=r.type,a=C_.createTrackFunctions[o];if(a!=null){const l=a(this,r);if(typeof l.evaluate=="function"){l.director=this,l.track=r,this._customTracks.push(l);continue}}if(r.type===Ar.Animation){if(r.clips.length<=0){$p&&console.warn("Animation track has no clips",r);continue}for(let l=r.outputs.length-1;l>=0;l--){let c=r.outputs[l];if(c instanceof Ie){const d=$.getOrAddComponent(c,hr);d&&(c=d)}const h=(i=c==null?void 0:c.gameObject)==null?void 0:i.animations;if(h){const d=new Hb;d.trackOffset=r.trackOffset,d.director=this,d.track=r;for(let f=0;f<r.clips.length;f++){const p=r.clips[f],g=p.asset;if(!g){console.error("MISSING anim model?","clip#"+f,p,r,this.playableAsset,this.name);continue}const m=g.clip;let A=m;if((typeof A=="string"||typeof A=="number")&&(A=h.find(b=>b.name===m)),!A){console.warn("Could not find animationClip for model",p,r.name,this.name,(s=this.playableAsset)==null?void 0:s.name);continue}d.mixer||(d.mixer=new $_(c.gameObject)),d.clips.push(A),d.mixer.uncacheAction(A),d.createHooks(p.asset,A);const v=d.mixer.clipAction(A);d.actions.push(v),d.models.push(p)}this._animationTracks.push(d)}}}else if(r.type===Ar.Audio){if(r.clips.length<=0)continue;const l=new hu;if(l.director=this,l.track=r,this._audioTracks.push(l),!t)continue;l.listener=t.listener;for(let c=0;c<r.clips.length;c++){const h=r.clips[c];l.addModel(h)}}else if(r.type===Ar.Marker){const l=new Om;l.director=this,l.track=r;for(const c of r.markers)switch(c.type){case JI.Signal:l.models.push(c),l.didTrigger.push(!1);break}if(l!==null&&l.models.length>0){const c=$.getComponent(this.gameObject,fp);c&&(l.receivers.push(c),this._signalTracks.push(l))}}else if(r.type===Ar.Signal){const l=new Om;l.director=this,l.track=r;for(const c of r.markers)l.models.push(c),l.didTrigger.push(!1);for(const c of r.outputs)l.receivers.push(c);this._signalTracks.push(l)}else if(r.type===Ar.Control){const l=new Vb;l.director=this,l.track=r;for(const c of r.clips)l.models.push(c);l.resolveSourceObjects(this.context),this._controlTracks.push(l)}}}setAudioTracksAllowPlaying(t){for(const i of this._audioTracks)i.onAllowAudioChanged(t)}};let lu=C_;u(lu,"createTrackFunctions",{});const cu=le("debugtimeline");class kA{constructor(){u(this,"director");u(this,"track")}get muted(){return this.track.muted}set muted(e){var t;e!==this.track.muted&&(this.track.muted=e,(t=this.onMuteChanged)==null||t.call(this))}*forEachClip(e=!1){var t;if((t=this.track)!=null&&t.clips)if(e)for(let i=this.track.clips.length-1;i>=0;i--)yield this.track.clips[i];else for(const i of this.track.clips)yield i}getClipTime(e,t){return t.clipIn+(e-t.start)*t.timeScale}getClipTimeNormalized(e,t){return(e-t.start)/t.duration}evaluateWeight(e,t,i,s=!0){if(t<0||t>=i.length)return 0;const r=i[t];if(s||e>=r.start&&e<=r.end){let o=1,a=!1;if(r.easeInDuration>0){const l=Math.min((e-r.start)/r.easeInDuration,1);o*=l}if(r.easeOutDuration>0&&!a){const l=Math.min((r.end-e)/r.easeOutDuration,1);o*=l}return o}return 0}}class Hee{constructor(e){u(this,"clip");u(this,"rootPositionOffset");u(this,"rootQuaternionOffset");u(this,"rootStartPosition");u(this,"rootEndPosition");u(this,"rootStartQuaternion");u(this,"rootEndQuaternion");const t=e.getClip();this.clip=t;const i=e.getRoot(),s=i.name+".position",r=i.name+".quaternion";cu&&console.log(t.name,t.tracks,s);for(const o of t.tracks)if(!(o.times.length<=0)){if(o.name.endsWith(s))this.rootStartPosition=new S().fromArray(o.values,0),this.rootEndPosition=new S().fromArray(o.values,o.values.length-3),this.rootPositionOffset=this.rootEndPosition.clone().sub(this.rootStartPosition),cu&&console.log(this.rootPositionOffset);else if(o.name.endsWith(r)&&(this.rootStartQuaternion=new xe().fromArray(o.values,0),this.rootEndQuaternion=new xe().fromArray(o.values,o.values.length-4),this.rootQuaternionOffset=this.rootEndQuaternion.clone().multiply(this.rootStartQuaternion),cu)){const a=new bn().setFromQuaternion(this.rootQuaternionOffset);console.log("ROT",a)}}}get hasOffsets(){return this.rootPositionOffset!==void 0||this.rootQuaternionOffset!==void 0}}class Hb extends kA{constructor(){super(...arguments);u(this,"models",[]);u(this,"trackOffset");u(this,"target");u(this,"mixer");u(this,"clips",[]);u(this,"actions",[]);u(this,"_actionOffsets",[]);u(this,"_didBind",!1);u(this,"_animator",null);u(this,"_animatorWasEnabled",!1);u(this,"_useclipOffsets",!0);u(this,"_totalOffsetPosition",new S);u(this,"_totalOffsetRotation",new xe);u(this,"_totalOffsetPosition2",new S);u(this,"_totalOffsetRotation2",new xe);u(this,"_summedPos",new S);u(this,"_tempPos",new S);u(this,"_summedRot",new xe);u(this,"_tempRot",new xe);u(this,"_clipRotQuat",new xe)}onPauseChanged(){this._animator&&this._animatorWasEnabled!==void 0&&(this._animator.enabled=this.director.isPlaying===!1?this._animatorWasEnabled:!1)}createHooks(t,i){var h,d;if(((h=i.tracks)==null?void 0:h.length)<=0){console.warn("No tracks in AnimationClip",i);return}const s=i.tracks[0].name.split("."),r=s[s.length-2],o=r+".position",a=r+".quaternion";let l=!1,c=!1;for(const f of i.tracks)f.name.endsWith(o)?(l=!0,this.createPositionInterpolant(i,t,f)):f.name.endsWith(a)&&(c=!0,this.createRotationInterpolant(i,t,f));if(!l||!c){const f=(d=this.mixer)==null?void 0:d.getRoot(),p=i.tracks[0],g=p.name.lastIndexOf("."),m=p.name.substring(0,g),A=m.substring(m.lastIndexOf(".")+1),v=f.getObjectByName(A);if(v)if(l){if(!c){const b=i.tracks[0].name.substring(0,g)+".quaternion";cu&&console.warn("Create quaternion track",A,v);const y=v.quaternion,_=new Oa(b,[0,i.duration],[y.x,y.y,y.z,y.w,y.x,y.y,y.z,y.w]);i.tracks.push(_),this.createRotationInterpolant(i,t,_)}}else{const b=m+".position";cu&&console.warn("Create position track",A,v);const y=v.position,_=new Yc(b,[0,i.duration],[y.x,y.y,y.z,y.x,y.y,y.z]);i.tracks.push(_),this.createPositionInterpolant(i,t,_)}}}bind(){if(!this._didBind){this._didBind=!0,cu&&console.log(this.models),this.mixer?this.target=this.mixer.getRoot():console.warn("No mixer was assigned to animation track");for(const t of this.actions){const i=new Hee(t);this._actionOffsets.push(i)}this.target&&(this._animator=$.getComponent(this.target,hr)??null,this._animator?(this._animatorWasEnabled=this._animator.enabled,this._animator.enabled=!1):this._animatorWasEnabled=!1);for(const t of this.models){const i=t.asset,s=i.position,r=i.rotation;s&&s.x!==void 0&&(s.isVector3||(i.position=new S(s.x,s.y,s.z)),r.isQuaternion||(i.rotation=new xe(r.x,r.y,r.z,r.w)))}this.ensureTrackOffsets()}}ensureTrackOffsets(){if(this.trackOffset){const t=this.trackOffset.position;t&&(t.isVector3||(this.trackOffset.position=new S(t.x,t.y,t.z)));const i=this.trackOffset.rotation;i&&(i.isQuaternion||(this.trackOffset.rotation=new xe(i.x,i.y,i.z,i.w)))}}evaluate(t){if(this.track.muted||!this.mixer)return;this.bind(),this._animator&&this.director.isPlaying&&this.director.weight>0&&(this._animator.enabled=!1),this._totalOffsetPosition.set(0,0,0),this._totalOffsetRotation.set(0,0,0,1),this._totalOffsetPosition2.set(0,0,0),this._totalOffsetRotation2.set(0,0,0,1);let i=0,s=0,r=!1,o=!1;for(let a=0;a<this.clips.length;a++){const l=this.models[a],c=this.actions[a],h=l.asset;c.weight=0;const d=t>=l.start&&t<=l.end,f=l.preExtrapolationMode,p=l.postExtrapolationMode,g=a<this.clips.length-1?this.models[a+1]:null;let m=d,A=!1;if(!m&&!r&&l.end<t&&p!==Ec.None?(!g||g.start>t)&&(m=!0,r=!0):a==0&&!m&&!o&&l.start>t&&f!==Ec.None&&(!g||g.start<t)&&(m=!0,A=!0,o=!0),m){let v=1;v*=this.evaluateWeight(t,a,this.models,m),v*=this.director.weight;let b=d;A&&f!==Ec.Hold&&(t+=l.start,b=!0);let y=this.getClipTime(t,l),_=0;const C=h.duration;if(A&&f===Ec.Hold&&(y=0),b){if(h.loop)for(_+=Math.floor(y/(C+1e-6));y>C;)y-=C}else if(!d)switch(p){case Ec.Loop:y%=C;break;case Ec.PingPong:const x=Math.floor(y/C)%2!==0;y%=C,x&&(y=C-y);break}l.reversed===!0?c.time=c.getClip().duration-y:c.time=y,c.timeScale=0;const E=v;if(c.weight=E,c.clampWhenFinished=!0,c.isRunning()||c.play(),this._useclipOffsets){const T=i==0?this._totalOffsetPosition:this._totalOffsetPosition2,x=i==0?this._totalOffsetRotation:this._totalOffsetRotation2;i<1&&(s=1-v),i+=1;const M=this._summedPos.set(0,0,0),P=this._tempPos.set(0,0,0),k=this._summedRot.identity(),G=this._tempRot.identity(),z=h.rotation;z&&(this._clipRotQuat.identity(),this._clipRotQuat.slerp(z,v));const L=this._actionOffsets[a];if(L.hasOffsets)for(let H=0;H<_;H++)L.rootPositionOffset?P.copy(L.rootPositionOffset):P.set(0,0,0),P.applyQuaternion(k),this._clipRotQuat&&P.applyQuaternion(this._clipRotQuat),L.rootQuaternionOffset&&(G.copy(L.rootQuaternionOffset),k.multiply(G)),M.add(P);this._clipRotQuat&&x.multiply(this._clipRotQuat),x.multiply(k),h.position&&M.add(h.position),T.add(M)}}}this._useclipOffsets&&(this._totalOffsetPosition.lerp(this._totalOffsetPosition2,s),this._totalOffsetRotation.slerp(this._totalOffsetRotation2,s)),this.mixer.update(t)}createRotationInterpolant(t,i,s){var l;const r=s.createInterpolant.bind(s),o=new xe;this.ensureTrackOffsets();const a=(l=this.trackOffset)==null?void 0:l.rotation;s.createInterpolant=()=>{const c=r(),h=c.evaluate.bind(c);return c.evaluate=d=>{const f=h(d);return o.set(f[0],f[1],f[2],f[3]),o.premultiply(this._totalOffsetRotation),a&&o.premultiply(a),f[0]=o.x,f[1]=o.y,f[2]=o.z,f[3]=o.w,f},c}}createPositionInterpolant(t,i,s){var h,d;const r=s.createInterpolant.bind(s),o=new S;this.ensureTrackOffsets();const a=(h=this.trackOffset)==null?void 0:h.rotation,l=(d=this.trackOffset)==null?void 0:d.position;let c;s.createInterpolant=()=>{const f=r(),p=f.evaluate.bind(f);return f.evaluate=g=>{var A,v;const m=p(g);return o.set(m[0],m[1],m[2]),i.removeStartOffset&&(c===void 0?(c=null,c=(v=(A=this._actionOffsets.find(b=>b.clip===t))==null?void 0:A.rootStartPosition)==null?void 0:v.clone()):c!=null&&c.isVector3&&o.sub(c)),o.applyQuaternion(this._totalOffsetRotation),o.add(this._totalOffsetPosition),a&&o.applyQuaternion(a),l&&(o.x-=l.x,o.y+=l.y,o.z+=l.z),m[0]=o.x,m[1]=o.y,m[2]=o.z,m},f}}}const Vee=le("mutetimeline"),Zd=class extends kA{constructor(){super(...arguments);u(this,"models",[]);u(this,"listener");u(this,"audio",[]);u(this,"audioContextTimeOffset",[]);u(this,"lastTime",0);u(this,"_audioLoader",null)}getAudioFilePath(t){const i=this.director.sourceId;return $c(i,t)}onAllowAudioChanged(t){for(let i=0;i<this.models.length;i++){const s=this.models[i];this.audio[i].setVolume(t?s.asset.volume:0)}}addModel(t){const i=new Z_(this.listener);this.audio.push(i),this.models.push(t)}onDisable(){for(const t of this.audio)t.isPlaying&&t.stop()}onMuteChanged(){if(this.muted)for(let t=0;t<this.audio.length;t++){const i=this.audio[t];i!=null&&i.isPlaying&&i.stop()}}stop(){for(let t=0;t<this.audio.length;t++){const i=this.audio[t];i!=null&&i.isPlaying&&i.stop()}}evaluate(t){if(Vee||this.track.muted||this.director.speed<0)return;const i=this.director.context.application.muted,s=i?.1:0;for(let r=0;r<this.models.length;r++){const o=this.models[r],a=this.audio[r];if((!a||!a.buffer)&&this.isInTimeRange(o,t-1,t+1)&&this.handleAudioLoading(o,a),xn.userInteractionRegistered!==!1&&!(a===null||!a.buffer))if(a.playbackRate=this.director.context.time.timeScale,a.loop=o.asset.loop,t>=o.start&&t<=o.end&&t<this.director.duration){if(this.director.isPlaying==!1){if(a.isPlaying&&a.stop(),this.lastTime===t)continue}else if(!a.isPlaying)a.offset=o.clipIn+(t-o.start)*o.timeScale,a.play(s);else{const c=o.clipIn+(t-o.start)*o.timeScale,h=a.context.currentTime-a._startedAt+a.offset;Math.abs(c-h)>.3&&(a.offset=c,a.stop(),a.play(s))}let l=o.asset.volume;if(i&&(l=0),o.easeInDuration>0){const c=Math.min((t-o.start)/o.easeInDuration,1);l*=c}if(o.easeOutDuration>0){const c=Math.min((o.end-t)/o.easeOutDuration,1);l*=c}a.setVolume(l*this.director.weight)}else a.isPlaying&&a.stop()}this.lastTime=t}loadAudio(t,i=0,s=0){let r=null;const o=t-s,a=t+i;for(const l of this.models)if(this.isInTimeRange(l,o,a)){const c=this.audio[this.models.indexOf(l)],h=this.handleAudioLoading(l,c);h!==null&&(r===null&&(r=[]),r.push(h))}return r!==null?Promise.all(r):null}isInTimeRange(t,i,s){return i<=t.start&&s>=t.end||i>=t.start&&i<=t.end||s>=t.start&&s<=t.end}static dispose(){Zd._currentlyLoading.clear()}handleAudioLoading(t,i){this._audioLoader||(this._audioLoader=new F0);const s=this.getAudioFilePath(t.asset.clip);if(Zd._currentlyLoading.get(s)){const o=Zd._currentlyLoading.get(s);return o.then(a=>{a&&i.setBuffer(a)}),o}cu&&console.warn("LOAD audio track",s,this.director.sourceId);const r=new Promise((o,a)=>{this._audioLoader.load(s,l=>{i.setBuffer(l),o(l)},void 0,l=>{console.error("Error loading audio",l),o(null)})});return Zd._currentlyLoading.set(s,r),r}};let hu=Zd;u(hu,"_currentlyLoading",new Map);class Om extends kA{constructor(){super(...arguments);u(this,"models",[]);u(this,"didTrigger",[]);u(this,"receivers",[])}evaluate(t){var i;if(!this.track.muted)for(let s=0;s<this.models.length;s++){const r=this.models[s],o=this.didTrigger[s],a=r.time-t;let l=!1;if(r.retroActive)l=a<=1e-6;else{const c=Math.abs(a);c>=1e-5&&c<.1&&(l=!0)}if(l){if(!o)if(this.didTrigger[s]=!0,((i=this.receivers)==null?void 0:i.length)<=0)fp.invoke(r.asset);else for(const c of this.receivers)c&&c.invoke(r.asset)}else r.emitOnce||(this.didTrigger[s]=!1)}}}class Vb extends kA{constructor(){super(...arguments);u(this,"models",[]);u(this,"timelines",[]);u(this,"_previousActiveModel",null)}resolveSourceObjects(t){for(let i=this.models.length-1;i>=0;i--){const r=this.models[i].asset;if(!r.sourceObject||typeof r.sourceObject!="object"){console.log("no source object, removing model",i,r),this.models.splice(i,1);continue}else{const o=$.getComponent(r.sourceObject,lu);this.timelines.push(o),o&&r.updateDirector&&(o.playOnAwake=!1)}}}evaluate(t){var i;this._previousActiveModel=null;for(let s=0;s<this.models.length;s++){const r=this.models[s],o=r.asset;if(t>=r.start&&t<=r.end){this._previousActiveModel=r;const a=this.getClipTime(t,r);if(o.controlActivation){const l=o.sourceObject;l.visible=!0}if(o.updateDirector){const l=this.timelines[s];l&&(l.isPlaying&&l.pause(),l.time=a,l.evaluate())}}else{const a=(i=this._previousActiveModel)==null?void 0:i.asset;if(o.controlActivation){const l=o.sourceObject;(a==null?void 0:a.sourceObject)!==l&&(l.visible=!1)}}}}}var jee=Object.defineProperty,Wee=Object.getOwnPropertyDescriptor,_N=(n,e,t,i)=>{for(var s=i>1?void 0:i?Wee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&jee(e,t,s),s};class Ft{constructor(e){u(this,"_active",!0);u(this,"_value");u(this,"_valueRaw");u(this,"_defaultValue");u(this,"valueProcessor");u(this,"onValueChanged");this._value=e,this._defaultValue=e}get overrideState(){return this._active}set overrideState(e){if(this._active===e)return;this._active=e;const t=e?this._valueRaw:this._defaultValue;this.processValue(t,!0)}get value(){return this._valueRaw}set value(e){this.processValue(e,!1)}set defaultValue(e){this._defaultValue=e}__init(){this.processValue(this._valueRaw,!0)}processValue(e,t){if(e==null||!t&&this.testIfValueChanged(e)===!1)return;const i=this._value;!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,e=this._defaultValue,this._valueRaw=e):(this._valueRaw=e,this._active&&this.valueProcessor&&(e=this.valueProcessor(e)),this._value=e),this.onValueChanged&&this.onValueChanged(e,i,this)}testIfValueChanged(e){return this._valueRaw!==e}}_N([w()],Ft.prototype,"overrideState",1);_N([w()],Ft.prototype,"value",1);var qee=Object.defineProperty,Xee=Object.getOwnPropertyDescriptor,Yee=(n,e,t,i)=>{for(var s=i>1?void 0:i?Xee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&qee(e,t,s),s};const Jee=le("debugpost");class js extends sh{constructor(){super(...arguments);u(this,"active",!0);u(this,"_result")}onEnable(){this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){this.active=!1}init(){}apply(){var t;return this._result||(this._result=(t=this.onCreateEffect)==null?void 0:t.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){Jee&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(t=>t.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const t=Object.keys(this);for(const i of t){const s=this[i];s instanceof Ft&&s.__init()}}onAfterDeserialize(t,i){if(typeof t=="object"){const s=this.$serializedTypes;if(s){for(const r of Object.keys(s))if(s[r]===Ft){const a=t[r];if(a!==void 0){const l=this[r];l.value=a}}}}}onEditorModification(t){const i=t.propertyName;if(this[i]instanceof Ft){const s=t.value;return this[i].value=s,!0}}}Yee([w()],js.prototype,"active",2);var Kee=Object.defineProperty,Zee=Object.getOwnPropertyDescriptor,$ee=(n,e,t,i)=>{for(var s=i>1?void 0:i?Zee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Kee(e,t,s),s};const ete=le("debugpost"),oE={};function Na(n,e){oE[n]=e}function tte(n){return n.__type in oE?oE[n.__type]:(ete&&n.__type&&console.warn("Unknown postprocessing type",n.__type,n),js)}class OA{constructor(){u(this,"components")}init(){var e;(e=this.components)==null||e.forEach(t=>t.init())}}$ee([Xf([n=>tte(n),js])],OA.prototype,"components",2);var ite=Object.defineProperty,nte=Object.getOwnPropertyDescriptor,ste=(n,e,t,i)=>{for(var s=i>1?void 0:i?nte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&ite(e,t,s),s};class LA extends js{constructor(){super(...arguments);u(this,"preset")}get typeName(){return"Antialiasing"}onCreateEffect(){const t=new S7({preset:Ed.HIGH,edgeDetectionMode:L1.DEPTH});return this.preset.onValueChanged=i=>{t.applyPreset(i)},t}}ste([w(Ft)],LA.prototype,"preset",2);Na("Antialiasing",LA);class jb{constructor(){u(this,"files",[])}get extensionName(){return"Audio"}onExportObject(e,t,i){const s=$.getComponents(e,xn);if(s.length)for(const r of s){if(!r.playOnAwake)continue;const o=r.clip.split("/").pop();this.files.includes(r.clip)||this.files.push(r.clip),t.addEventListener("serialize",(a,l)=>{a.appendLine(),a.beginBlock(`def SpatialAudio "${t.name}"`),a.appendLine(`uniform asset filePath = @audio/${o}@`),a.appendLine(`uniform token auralMode = "${r.spatialBlend>0?"spatial":"nonSpatial"}"`),a.appendLine(`uniform token playbackMode = "${r.loop?"loopFromStage":"onceFromStart"}"`),a.appendLine(`uniform float gain = ${r.volume}`),a.closeBlock()})}}async onAfterSerialize(e){console.warn("onAfterSerialize",this);for(const t of this.files){const i=t.split("/").pop(),o=await(await(await fetch(t)).blob()).arrayBuffer(),a=new Uint8Array(o);e.files["audio/"+i]=a}}}var rte=Object.defineProperty,ote=Object.getOwnPropertyDescriptor,bN=(n,e,t,i)=>{for(var s=i>1?void 0:i?ote(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&rte(e,t,s),s};const ate=le("debugmouth");class FA extends Ce{constructor(){super(...arguments);u(this,"idle",[]);u(this,"talking",[]);u(this,"marker",null);u(this,"voip",null);u(this,"lastMouthChangeTime",0);u(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=$.findObjectOfType(Vl,this.context),this.marker||(this.marker=$.getComponentInParent(this.gameObject,Wn))},3e3)}update(){var s;if(!this.voip||this.context.time.frameCount%10!==0)return;let t=((s=this.marker)==null?void 0:s.connectionId)??null;if(!t){ate&&(t=null);return}const i=this.voip.getFrequency(t)??0;this.updateLips(i)}updateLips(t){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&t>30){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,i)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,i)}}}setMouthShapeActive(t,i){if(t){t!=this.idle?this.idle.map(s=>s.visible=!1):this.talking.map(s=>s.visible=!1);for(let s=0;s<t.length;s++){const r=t[s];r&&(r.visible=s===i)}}}}bN([w(Ie)],FA.prototype,"idle",2);bN([w(Ie)],FA.prototype,"talking",2);class KI extends Ce{constructor(){super(...arguments);u(this,"voip",null);u(this,"marker",null);u(this,"_startPosition",null)}awake(){this.voip=$.findObjectOfType(Vl,this.context),this.marker=$.getComponentInParent(this.gameObject,Wn)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const t=this.marker.connectionId,i=this.voip.getFrequency(t);if(i==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());let s=i/100;this.gameObject.position.y=this._startPosition.y+s*.07}}var lte=Object.defineProperty,cte=Object.getOwnPropertyDescriptor,Wb=(n,e,t,i)=>{for(var s=i>1?void 0:i?cte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&<e(e,t,s),s};class Bu extends Ce{constructor(){super(...arguments);u(this,"eyes",[]);u(this,"lastBlinkTime",0);u(this,"blinkLength",0);u(this,"eyesOpen",!0);u(this,"state",null)}awake(){this.state=$.getComponentInParent(this.gameObject,ss)}update(){if(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)return;if(this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const i of this.eyes)i&&(i.visible=this.eyesOpen)}}}Wb([w(Ie)],Bu.prototype,"eyes",2);Wb([w()],Bu.prototype,"lastBlinkTime",2);Wb([w()],Bu.prototype,"blinkLength",2);Wb([w()],Bu.prototype,"eyesOpen",2);var hte=Object.defineProperty,ute=Object.getOwnPropertyDescriptor,ZI=(n,e,t,i)=>{for(var s=i>1?void 0:i?ute(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&hte(e,t,s),s},SC;const xN=(SC=class extends Ce{constructor(){super(...arguments);u(this,"head",null);u(this,"eyes",null);u(this,"target",null);u(this,"brain",null);u(this,"vec",new S);u(this,"currentTargetPoint",new S)}awake(){this.brain||(this.brain=$.getComponentInParent(this.gameObject,Sm)),this.brain||(console.log("No look at brain found, adding it now"),this.brain=$.addNewComponent(this.gameObject,Sm)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const e=this.target;if(e&&this.head){const t=this.eyes;if(t){const i=wt(e);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const s=wt(this.head),r=this.vec.copy(this.currentTargetPoint).sub(s).normalize();if(r.length()<.1)return;const o=xN.forward;if(o.set(0,0,1),o.applyQuaternion(Dn(this.head)),o.dot(r)>.45)for(let l=0;l<t.length;l++)t[l].lookAt(this.currentTargetPoint)}}}},u(SC,"forward",new S(0,0,1)),SC);let pp=xN;ZI([w(Ie)],pp.prototype,"head",2);ZI([w(Ie)],pp.prototype,"eyes",2);ZI([w(Ie)],pp.prototype,"target",2);var dte=Object.defineProperty,fte=Object.getOwnPropertyDescriptor,$I=(n,e,t,i)=>{for(var s=i>1?void 0:i?fte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&dte(e,t,s),s};class gp extends Ce{constructor(){super(...arguments);u(this,"length",1);u(this,"depthTest",!0);u(this,"isGizmo",!0);u(this,"_axes",null)}onEnable(){if(this.isGizmo&&!hA)return;this._axes||(this._axes=new Gf(this.length)),this.gameObject.add(this._axes);const t=this._axes.material;t&&t.depthTest!==void 0&&(t.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}$I([w()],gp.prototype,"length",2);$I([w()],gp.prototype,"depthTest",2);$I([w()],gp.prototype,"isGizmo",2);class eM extends Ce{constructor(){super(...arguments);u(this,"from");u(this,"to");u(this,"hint");u(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;let t=wt(this.to).clone(),i=wt(this.from).clone(),s=t.distanceTo(i),r=t.clone();r.sub(i);let o=i.clone();o.add(t),o.multiplyScalar(.5);let a=wt(this.hint).clone();a.sub(o);let l=new S;l.crossVectors(a,r),l.crossVectors(r,l),l.normalize();let c=s*.5,h=Math.max(this.desiredDistance,c),d=Math.sqrt(h*h-c*c),f=l.clone();f.multiplyScalar(d),f.add(o),ln(this.gameObject,f);let p=o.clone();p.sub(l),this.gameObject.lookAt(p)}}class qb{constructor(){u(this,"behaviours",[]);u(this,"behaviourComponents",[]);u(this,"behaviourComponentsCopy",[])}get extensionName(){return"Behaviour"}addBehavior(e){this.behaviours.push(e)}onBeforeBuildDocument(e){e.root.traverse(t=>{$.foreachComponent(t,i=>{var r;const s=i;(typeof s.createBehaviours=="function"||typeof s.beforeCreateDocument=="function"||typeof s.afterCreateDocument=="function")&&(this.behaviourComponents.push(s),(r=s.beforeCreateDocument)==null||r.call(s,this,e))},!1)})}onExportObject(e,t,i){var s;for(const r of this.behaviourComponents)(s=r.createBehaviours)==null||s.call(r,this,t,i)}onAfterBuildDocument(e){for(const t of this.behaviourComponents)typeof t.afterCreateDocument=="function"&&t.afterCreateDocument(this,e);this.behaviourComponentsCopy=this.behaviourComponents.slice(),this.behaviourComponents.length=0}onAfterHierarchy(e,t){var i;if((i=this.behaviours)!=null&&i.length){t.beginBlock('def Scope "Behaviors"');for(const s of this.behaviours)s.writeTo(this,e.document,t);t.closeBlock()}}async onAfterSerialize(e){console.log("onAfterSerialize",this.behaviourComponentsCopy);for(const t of this.behaviourComponentsCopy)console.log("behaviour",t),typeof t.afterSerialize=="function"&&(console.log("beh has afterSerialize",t),t.afterSerialize.constructor.name==="AsyncFunction"?await t.afterSerialize(this,e):t.afterSerialize(this,e))}}var pte=Object.defineProperty,gte=Object.getOwnPropertyDescriptor,tM=(n,e,t,i)=>{for(var s=i>1?void 0:i?gte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&pte(e,t,s),s};class Du extends js{constructor(){super(...arguments);u(this,"threshold");u(this,"intensity");u(this,"scatter");u(this,"selectiveBloom",!0)}get typeName(){return"Bloom"}init(){this.threshold.defaultValue=1,this.intensity.defaultValue=0,this.scatter.defaultValue=.2,this.selectiveBloom?(this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>1*Math.PI*(1-t)):(this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>100*(1-t))}onCreateEffect(){let t;if(this.selectiveBloom){const i=t=new rF(this.context.scene,this.context.mainCamera,{blendFunction:Lt.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,intensity:this.intensity.value});i.inverted=!0}else t=new z1;return this.intensity.onValueChanged=i=>{t.intensity=i},this.threshold.onValueChanged=i=>{t.luminanceMaterial.threshold=i},this.scatter.onValueChanged=i=>{t.luminancePass.enabled=!0,t.luminanceMaterial.smoothing=i},t}}tM([w(Ft)],Du.prototype,"threshold",2);tM([w(Ft)],Du.prototype,"intensity",2);tM([w(Ft)],Du.prototype,"scatter",2);Na("Bloom",Du);var mte=Object.defineProperty,Ate=Object.getOwnPropertyDescriptor,Jo=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ate(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&mte(e,t,s),s};class za extends Ce{constructor(){super(...arguments);u(this,"attachedRigidbody",null);u(this,"isTrigger",!1);u(this,"sharedMaterial")}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Hi))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Hi))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Hi))}onDisable(){var t;(t=this.context.physics.engine)==null||t.removeBody(this)}}Jo([w(Hi)],za.prototype,"attachedRigidbody",2);Jo([w()],za.prototype,"isTrigger",2);Jo([w()],za.prototype,"sharedMaterial",2);class UA extends za{constructor(){super(...arguments);u(this,"radius",.5);u(this,"center",new S(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addSphereCollider(this,this.center,this.radius)}}Jo([w()],UA.prototype,"radius",2);Jo([w(S)],UA.prototype,"center",2);class NA extends za{constructor(){super(...arguments);u(this,"size",new S(1,1,1));u(this,"center",new S(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addBoxCollider(this,this.center,this.size)}}Jo([w(S)],NA.prototype,"size",2);Jo([w(S)],NA.prototype,"center",2);class zA extends za{constructor(){super(...arguments);u(this,"sharedMesh");u(this,"convex",!1)}onEnable(){var t,i,s,r,o;if(super.onEnable(),(t=this.sharedMesh)!=null&&t.isMesh||this.gameObject instanceof ve&&(this.sharedMesh=this.gameObject),(i=this.sharedMesh)!=null&&i.isMesh)(s=this.context.physics.engine)==null||s.addMeshCollider(this,this.sharedMesh,this.convex,ns(this.gameObject));else{const a=this.sharedMesh;if(a!=null&&a.isGroup){console.warn(`MeshCollider mesh is a group "${(r=this.sharedMesh)==null?void 0:r.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);for(const l in a.children){const c=a.children[l];c.isMesh&&((o=this.context.physics.engine)==null||o.addMeshCollider(this,c,this.convex,ns(this.gameObject)))}}}}}Jo([w()],zA.prototype,"convex",2);class Zc extends za{constructor(){super(...arguments);u(this,"center",new S(0,0,0));u(this,"radius",.5);u(this,"height",2)}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addCapsuleCollider(this,this.center,this.height,this.radius)}}Jo([w(S)],Zc.prototype,"center",2);Jo([w()],Zc.prototype,"radius",2);Jo([w()],Zc.prototype,"height",2);function iM(n){const e=n[vl];return e||(n.parent?iM(n.parent):null)}function p_(n,e){if(!n)return;const t=n.material;if((t==null?void 0:t.isMaterial)===!0){const i=n.parent;i&&i.isText,t.side=e.doubleSided??!0?Ii:Gs,t.shadowSide=e.doubleSided?Ii:Gs,n.castShadow=e.castShadows?e.castShadows:!1,n.receiveShadow=e.receiveShadows?e.receiveShadows:!1}for(const i of n.children)p_(i,e)}function Rd(n,e,t){n[e]===void 0&&console.warn("Field",e,"is undefined on",n);const i=Proxy.revocable(n[e],{set(o,a,l,c){const h=o[a],d=Reflect.set(o,a,l,c);return t(l,h),d}}),s=i.revoke,r=n[e];return i.revoke=()=>{n[e]=r,s()},n[e]=i.proxy,i}const GB=Symbol("Scheduled action");function vte(n,e,t=Rr.OnBeforeRender){let i=n[GB];i||(i=n[GB]={});const s=e.name;i[t]||(i[t]={});const r=i[t];if(r[s])return;function*a(){e==null||e.call(n),r[s]=null}const l=n.startCoroutine(a(),t);r[s]=l}var yte=Object.defineProperty,_te=Object.getOwnPropertyDescriptor,ku=(n,e,t,i)=>{for(var s=i>1?void 0:i?_te(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&yte(e,t,s),s};const Kw=le("debugui"),Zw=le("debuguilayout");class nM{constructor(){u(this,"width");u(this,"height")}}class sM{constructor(){u(this,"x");u(this,"y");u(this,"width");u(this,"height")}}const ta=new S,eg=new He,vy=new xe,wN=class extends Ho{constructor(){super(...arguments);u(this,"offset",.01);u(this,"_anchoredPosition");u(this,"sizeDelta",new q(100,100));u(this,"pivot",new q(.5,.5));u(this,"anchorMin",new q(0,0));u(this,"anchorMax",new q(1,1));u(this,"offsetMin",new q(0,0));u(this,"offsetMax",new q(0,0));u(this,"lastMatrix");u(this,"rectBlock");u(this,"_transformNeedsUpdate",!1);u(this,"_initialPosition");u(this,"_parentRectTransform");u(this,"_lastUpdateFrame",-1);u(this,"_lastAnchoring");u(this,"_createdBlocks",[]);u(this,"_createdTextBlocks",[])}get parent(){return this._parentRectTransform}get translation(){return this.gameObject.position}get rotation(){return this.gameObject.quaternion}get scale(){return this.gameObject.scale}get anchoredPosition(){return this._anchoredPosition||(this._anchoredPosition=new q),this._anchoredPosition}set anchoredPosition(e){this._anchoredPosition=e}get width(){if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const e=this._parentRectTransform.width,t=this.anchorMax.x-this.anchorMin.x;let i=e*t;return i+=this.sizeDelta.x,i}return this.sizeDelta.x}get height(){if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const e=this._parentRectTransform.height,t=this.anchorMax.y-this.anchorMin.y;let i=e*t;return i+=this.sizeDelta.y,i}return this.sizeDelta.y}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new q),this.lastMatrix=new He,this.rectBlock=new Ie,this.rectBlock.position.z=.1,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,this.onApplyTransform("RectTransform awake"),Rd(this,"_anchoredPosition",()=>{this.markDirty()}),Rd(this,"sizeDelta",()=>{this.markDirty()}),Rd(this,"pivot",()=>{this.markDirty()}),Rd(this,"anchorMin",()=>{this.markDirty()}),Rd(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var e;super.onEnable(),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(e=this.Canvas)==null||e.registerTransform(this)}onDisable(){var e;super.onDisable(),this.removeShadowComponent(),(e=this.Canvas)==null||e.unregisterTransform(this)}onParentRectTransformChanged(e){this._transformNeedsUpdate||this.onApplyTransform(Zw?`${e.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(Zw&&console.warn("RectTransform markDirty()",this.name),this._transformNeedsUpdate=!0,this._lastUpdateFrame=-1)}updateTransform(){(this._transformNeedsUpdate||!this.lastMatrix.equals(this.gameObject.matrix))&&this.canUpdate()&&this.onApplyTransform(this._transformNeedsUpdate?"Marked dirty":"Matrix changed")}canUpdate(){return this._transformNeedsUpdate&&this.activeAndEnabled&&this._lastUpdateFrame!==this.context.time.frame}onApplyTransform(e){if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const t=this.shadowComponent;if(!t)return;this.gameObject.parent?this._parentRectTransform=$.getComponentInParent(this.gameObject.parent,wN):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,Zw&&console.warn("RectTransform → ApplyTransform",this.name+" because "+e),this.isRoot()?this.Root.screenspace||(t.rotation.y=Math.PI):(t.matrix.identity(),t.matrixAutoUpdate=!1,ta.set(0,0,0),this.applyPivot(ta),t.matrix.setPosition(ta.x,ta.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(vy.copy(this.gameObject.quaternion),vy.x*=-1,vy.z*=-1,eg.makeRotationFromQuaternion(vy),t.matrix.premultiply(eg)),ta.set(0,0,0),this.applyAnchoring(ta),ta.z+=this.offset,eg.identity(),eg.setPosition(ta.x,ta.y,ta.z),t.matrix.premultiply(eg),t.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const i=!0;for(const s of k1(this.gameObject,Ho,i,1)){if(s===this||!s.activeAndEnabled)continue;const r=s;r.onParentRectTransformChanged&&r.onParentRectTransformChanged(this)}}applyAnchoring(e){this._lastAnchoring||(this._lastAnchoring=new q);const t=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=t.x,this.gameObject.position.y+=t.y,this._lastAnchoring.copy(this._anchoredPosition),e.x+=this._initialPosition.x-this.gameObject.position.x,e.y+=this._initialPosition.y-this.gameObject.position.y,e.z+=this._initialPosition.z-this.gameObject.position.z;const i=this._parentRectTransform;if(i){let s=0;const r=1-this.anchorMax.y-this.anchorMin.y;s-=i.height*.5*r,e.y+=s;let o=0;const a=1-this.anchorMax.x-this.anchorMin.x;o-=i.width*.5*a,e.x+=o}}applyPivot(e){if(this.pivot&&!this.isRoot()){const t=this.pivot.x-.5;e.x-=t*this.sizeDelta.x*this.gameObject.scale.x;const i=this.pivot.y-.5;e.y-=i*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const e={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:this.offset,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(e),e}ensureValidSize(e,t=1e-4){return e.width<=0&&(e.width=t),e.height<=0&&(e.height=1e-4),e}createNewBlock(e){e={...this.getBasicOptions(),...e},Kw&&console.log(this.name,e);const t=new WI(e);return this._createdBlocks.push(t),t}createNewText(e){Kw&&console.log(e),e={...this.getBasicOptions(),...e},Kw&&console.log(this.name,e);const t=new gN(e);return this._createdTextBlocks.push(t),t}};let xs=wN;ku([w(q)],xs.prototype,"anchoredPosition",1);ku([w(q)],xs.prototype,"sizeDelta",2);ku([w(q)],xs.prototype,"pivot",2);ku([w(q)],xs.prototype,"anchorMin",2);ku([w(q)],xs.prototype,"anchorMax",2);ku([w(q)],xs.prototype,"offsetMin",2);ku([w(q)],xs.prototype,"offsetMax",2);class bte extends pN{constructor(e,t={}){super(e),e._simpleState__activeStates=[],e._simpleState__normalStyles={},e._simpleState__states=t,e._simpleState__statesProperties={};for(const i in t)for(const s in t[i])e._simpleState__statesProperties[s]||(e._simpleState__statesProperties[s]=[]),e._simpleState__statesProperties[s].push(i);for(const i of e._components)e._simpleState__statesProperties[i.id]&&(e._simpleState__normalStyles[i.id]=i.inline?i.inline:i._value);e.__overridedSet=e.set,e.set=this.storeSet.bind(e),e.renderStates=this.renderStates.bind(e),e.setupState=this.setupState.bind(e),e.setState=this.setState.bind(e),e.activatePseudoState=this.activatePseudoState.bind(e),e.deactivatePseudoState=this.deactivatePseudoState.bind(e),e.togglePseudoState=this.togglePseudoState.bind(e)}act(){}attach(){}detach(){}setupState(e,t){this._simpleState__states[e]=t;const i=[];for(const s in t)this._simpleState__statesProperties[s]||(this._simpleState__statesProperties[s]=[],i.push(s)),this._simpleState__statesProperties[s].push(e);for(const s of this._components)i.indexOf(s.id)>-1&&(this._simpleState__normalStyles[s.id]=s.inline?s.inline:s._value)}renderStates(){let e={...this._simpleState__normalStyles};for(const t in this._simpleState__states)this._simpleState__activeStates.indexOf(t)>-1&&(e={...e,...this._simpleState__states[t]});this.set(e,!1)}storeSet(e,t=!0){if(t)for(const i in e)this._simpleState__statesProperties[i]&&(this._simpleState__normalStyles[i]=e[i]);this.__overridedSet(e)}activatePseudoState(e){this._simpleState__activeStates.indexOf(e)===-1&&(this._simpleState__activeStates.push(e),this.renderStates())}deactivatePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1&&(this._simpleState__activeStates.splice(t,1),this.renderStates())}togglePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1?this._simpleState__activeStates.splice(t,1):this._simpleState__activeStates.push(e),this.renderStates()}setState(e){Array.isArray(e)?this._simpleState__activeStates=e:this._simpleState__activeStates=[e],this.renderStates()}}var xte=Object.defineProperty,wte=Object.getOwnPropertyDescriptor,CN=(n,e,t,i)=>{for(var s=i>1?void 0:i?wte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&xte(e,t,s),s};class mp extends Ce{constructor(){super(...arguments);u(this,"effectColor");u(this,"effectDistance")}}CN([w(xi)],mp.prototype,"effectColor",2);CN([w(q)],mp.prototype,"effectDistance",2);var Cte=Object.defineProperty,Ste=Object.getOwnPropertyDescriptor,SN=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ste(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Cte(e,t,s),s};const yy={backgroundColor:new _e(1,1,1),backgroundOpacity:1,borderColor:new _e(1,1,1),borderOpacity:1};var EC;const m0=(EC=class extends Ho{constructor(){super(...arguments);u(this,"_alphaFactor",1);u(this,"raycastTarget",!0);u(this,"uiObject",null);u(this,"_color",null);u(this,"_rect",null);u(this,"_stateManager",null);u(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new xi(1,1,1,1)),this._color}set color(e){(!this._color||this._color.r!==e.r||this._color.g!==e.g||this._color.b!==e.b||this._color.alpha!==e.alpha)&&(this._color||(this._color=new xi(1,1,1,1)),this._color.copy(e))}setAlphaFactor(e){this._alphaFactor=e,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(yy.backgroundColor=this._color,yy.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(yy,this._alphaFactor),this.uiObject.set(yy),this.markDirty())}get m_Color(){return this._color}get rectTransform(){return this._rect||(this._rect=$.getComponent(this.gameObject,xs)),this._rect}onParentRectTransformChanged(){var e;(e=this.uiObject)==null||e.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone())}setState(e){this.makePanel(),this.uiObject&&(this.uiObject.setState(e),this==null||this.markDirty())}setupState(e){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new bte(this.uiObject)),this.uiObject.setupState(e.state,e.attributes))}setOptions(e){this.makePanel(),this.uiObject&&this.uiObject.set(e)}awake(){super.awake(),this.makePanel(),Rd(this,"_color",()=>vte(this,this.onColorChanged))}onEnable(){var e;super.onEnable(),this.uiObject&&((e=this.rectTransform.shadowComponent)==null||e.add(this.uiObject),this.addShadowComponent(this.uiObject,this.rectTransform))}onDisable(){super.onDisable(),this.uiObject&&this.removeShadowComponent()}makePanel(){if(this.uiObject||this._currentlyCreatingPanel)return;this._currentlyCreatingPanel=!0;const e={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:1};this.onBeforeCreate(e),this.applyEffects(e),this.onCreate(e),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated()}onBeforeCreate(e){}onCreate(e){this.uiObject=this.rectTransform.createNewBlock(e),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(e,t=1){var s;const i=(s=this.gameObject)==null?void 0:s.getComponent(mp);i&&(i.effectDistance&&(e.borderWidth=Math.max(Math.abs(i.effectDistance.x),Math.abs(i.effectDistance.y))),i.effectColor&&(e.borderColor=i.effectColor,e.borderOpacity=i.effectColor.alpha*t))}async setTexture(e){if(this.setOptions({backgroundOpacity:0}),e){if(e.encoding===yt)if(m0.textureCache.has(e))e=m0.textureCache.get(e);else{const t=e.clone();t.encoding=cn,m0.textureCache.set(e,t),e=t}this.setOptions({backgroundImage:e,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"})}else this.setOptions({backgroundImage:null,borderRadius:0,backgroundOpacity:this.color.alpha})}onAfterAddedToScene(){super.onAfterAddedToScene(),this.shadowComponent&&(this.shadowComponent.offset=this.shadowComponent.position.z)}},u(EC,"textureCache",new Map),EC);let Ou=m0;SN([w(xi)],Ou.prototype,"color",1);SN([w()],Ou.prototype,"raycastTarget",2);class GA extends Ou{constructor(){super(...arguments);u(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var Ete=Object.defineProperty,Ite=Object.getOwnPropertyDescriptor,Xb=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ite(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Ete(e,t,s),s};let rM=class{constructor(){u(this,"texture",null);u(this,"rect")}};Xb([w(Gt)],rM.prototype,"texture",2);let Ap=class extends GA{constructor(){super(...arguments);u(this,"_sprite");u(this,"pixelsPerUnitMultiplier",1)}set image(t){this.sprite?this.sprite.texture=t:(this.sprite=new rM,this.sprite.texture=t),this.onAfterCreated()}get image(){return this.sprite?this.sprite.texture:null}get sprite(){return this._sprite}set sprite(t){this._sprite!==t&&(this._sprite=t,this.onAfterCreated())}isBuiltinSprite(){var t,i,s,r,o,a,l,c;switch((i=(t=this.sprite)==null?void 0:t.texture)==null?void 0:i.name){case"InputFieldBackground":case"UISprite":case"Background":case"Knob":return!0}return((o=(r=(s=this.sprite)==null?void 0:s.texture)==null?void 0:r.image)==null?void 0:o.width)===32&&((c=(l=(a=this.sprite)==null?void 0:a.texture)==null?void 0:l.image)==null?void 0:c.height)===32}onBeforeCreate(t){var i,s;super.onBeforeCreate(t),this.isBuiltinSprite()&&(t.borderRadius=5/this.pixelsPerUnitMultiplier,((s=(i=this.sprite)==null?void 0:i.texture)==null?void 0:s.name)==="Knob"&&(t.borderRadius=999))}onAfterCreated(){var t;this.__didAwake&&(super.onAfterCreated(),!this.isBuiltinSprite()&&this.setTexture((t=this.sprite)==null?void 0:t.texture))}};Xb([w(rM)],Ap.prototype,"sprite",1);Xb([w()],Ap.prototype,"pixelsPerUnitMultiplier",2);class Yb extends GA{constructor(){super(...arguments);u(this,"_mainTexture")}get mainTexture(){return this._mainTexture}set mainTexture(t){this._mainTexture!==t&&(this._mainTexture=t,this.onAfterCreated())}onAfterCreated(){this.__didAwake&&(super.onAfterCreated(),this.setTexture(this.mainTexture))}}Xb([w(Gt)],Yb.prototype,"mainTexture",1);var Mte=Object.defineProperty,Tte=Object.getOwnPropertyDescriptor,Dr=(n,e,t,i)=>{for(var s=i>1?void 0:i?Tte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Mte(e,t,s),s};const yd=le("debugbutton");class Lu{constructor(){u(this,"colorMultiplier");u(this,"disabledColor");u(this,"fadeDuration");u(this,"highlightedColor");u(this,"normalColor");u(this,"pressedColor");u(this,"selectedColor")}}Dr([w()],Lu.prototype,"colorMultiplier",2);Dr([w(xi)],Lu.prototype,"disabledColor",2);Dr([w()],Lu.prototype,"fadeDuration",2);Dr([w(xi)],Lu.prototype,"highlightedColor",2);Dr([w(xi)],Lu.prototype,"normalColor",2);Dr([w(xi)],Lu.prototype,"pressedColor",2);Dr([w(xi)],Lu.prototype,"selectedColor",2);class Xl extends Ce{constructor(){super(...arguments);u(this,"onClick");u(this,"_isHovered",!1);u(this,"colors");u(this,"transition");u(this,"animationTriggers");u(this,"animator");u(this,"_interactable",!0);u(this,"_requestedAnimatorTrigger");u(this,"_isInit",!1);u(this,"_image")}onPointerEnter(t){var i,s;yd&&console.log("Button Enter",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator),this._isHovered=!0,this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.highlightedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("hovered")),this.context.input.setCursorPointer())}onPointerExit(){var t,i;yd&&console.log("Button Exit",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this._isHovered=!1,this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((i=this._image)==null||i.setState("normal")),this.context.input.setCursorNormal())}onPointerDown(t){var i,s;yd&&console.log("Button Down",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.pressedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("pressed")))}onPointerUp(t){var i,s;yd&&console.warn("Button Up",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator,this._isHovered),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this._isHovered?this.animationTriggers.highlightedTrigger:this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState(this._isHovered?"hovered":"normal")))}onPointerClick(t){var i;this.interactable&&(yd&&(console.warn("Button Click",this.onClick),jn("CLICKED button "+this.name+" at "+this.context.time.frameCount)),(i=this.onClick)==null||i.invoke())}set interactable(t){this._interactable=t,this._image&&(this._image.setInteractable(t),t?this._image.setState("normal"):this._image.setState("disabled"))}get interactable(){return this._interactable}set_interactable(t){this.interactable=t}awake(){super.awake(),yd&&console.log(this),this._isInit=!1,this.init()}start(){var t;(t=this._image)==null||t.setInteractable(this.interactable)}onEnable(){super.onEnable()}*setAnimatorTriggerAtEndOfFrame(t){var i;this._requestedAnimatorTrigger=t,yield,yield,this._requestedAnimatorTrigger==t&&((i=this.animator)==null||i.SetTrigger(t))}init(){this._isInit||(this._isInit=!0,this._image=$.getComponent(this.gameObject,Ap),this._image&&(this.stateSetup(this._image),this.interactable?this._image.setState("normal"):this._image.setState("disabled")))}stateSetup(t){var p,g,m,A,v;t.setInteractable(this.interactable);const i=this.getFinalColor(t.color,(p=this.colors)==null?void 0:p.normalColor),s={state:"normal",attributes:{backgroundColor:i,backgroundOpacity:i.alpha}};t.setupState(s);const r=this.getFinalColor(t.color,(g=this.colors)==null?void 0:g.highlightedColor),o={state:"hovered",attributes:{backgroundColor:r,backgroundOpacity:r.alpha}};t.setupState(o);const a=this.getFinalColor(t.color,(m=this.colors)==null?void 0:m.pressedColor),l={state:"pressed",attributes:{backgroundColor:a,backgroundOpacity:a.alpha}};t.setupState(l);const c=this.getFinalColor(t.color,(A=this.colors)==null?void 0:A.selectedColor),h={state:"selected",attributes:{backgroundColor:c,backgroundOpacity:c.alpha}};t.setupState(h);const d=this.getFinalColor(t.color,(v=this.colors)==null?void 0:v.disabledColor),f={state:"disabled",attributes:{backgroundColor:d,backgroundOpacity:d.alpha}};t.setupState(f)}getFinalColor(t,i){return i?t.clone().multiply(i):t.clone()}}Dr([w(ar)],Xl.prototype,"onClick",2);Dr([w()],Xl.prototype,"colors",2);Dr([w()],Xl.prototype,"transition",2);Dr([w()],Xl.prototype,"animationTriggers",2);Dr([w(hr)],Xl.prototype,"animator",2);Dr([w()],Xl.prototype,"interactable",1);var Pte=Object.defineProperty,Rte=Object.getOwnPropertyDescriptor,Cn=(n,e,t,i)=>{for(var s=i>1?void 0:i?Rte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Pte(e,t,s),s};const QB=le("debuguilayout");class uh{constructor(){u(this,"left",0);u(this,"right",0);u(this,"top",0);u(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Cn([w()],uh.prototype,"left",2);Cn([w()],uh.prototype,"right",2);Cn([w()],uh.prototype,"top",2);Cn([w()],uh.prototype,"bottom",2);class kr extends Ce{constructor(){super(...arguments);u(this,"_rectTransform",null);u(this,"_needsUpdate",!1);u(this,"childAlignment",0);u(this,"reverseArrangement",!1);u(this,"spacing",0);u(this,"padding");u(this,"minWidth",0);u(this,"minHeight",0);u(this,"flexibleHeight",0);u(this,"flexibleWidth",0);u(this,"preferredHeight",0);u(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(t){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(QB&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){QB&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(xs);const t=this.gameObject.getComponentInParent(ws);t&&t.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const t=this.gameObject.getComponentInParent(ws);t&&t.unregisterLayoutGroup(this)}set m_Spacing(t){t!==this.spacing&&(this._needsUpdate=!0,this.spacing=t)}get m_Spacing(){return this.spacing}}Cn([w()],kr.prototype,"childAlignment",2);Cn([w()],kr.prototype,"reverseArrangement",2);Cn([w()],kr.prototype,"spacing",2);Cn([w(uh)],kr.prototype,"padding",2);Cn([w()],kr.prototype,"minWidth",2);Cn([w()],kr.prototype,"minHeight",2);Cn([w()],kr.prototype,"flexibleHeight",2);Cn([w()],kr.prototype,"flexibleWidth",2);Cn([w()],kr.prototype,"preferredHeight",2);Cn([w()],kr.prototype,"preferredWidth",2);class dh extends kr{constructor(){super(...arguments);u(this,"childControlHeight",!0);u(this,"childControlWidth",!0);u(this,"childForceExpandHeight",!1);u(this,"childForceExpandWidth",!1);u(this,"childScaleHeight",!1);u(this,"childScaleWidth",!1)}onCalculateLayout(t){var x;const i=this.primaryAxis,s=t.width;let r=s;const o=t.height;let a=o;r-=this.padding.horizontal,a-=this.padding.vertical,i==="x"?this.padding.horizontal:this.padding.vertical;const l=i==="x",c=l?"y":"x",h=l?this.childControlWidth:this.childControlHeight,d=l?this.childControlHeight:this.childControlWidth,f=l?this.childForceExpandWidth:this.childForceExpandHeight,p=l?this.childForceExpandHeight:this.childForceExpandWidth,g=l?a:r,m=l?s:o,A=.5*(l?this.childAlignment%3:Math.floor(this.childAlignment/3));let v=0;l?v+=this.padding.left:v+=this.padding.top;let b=0,y=0;for(let M=0;M<this.gameObject.children.length;M++){const P=this.gameObject.children[M],k=$.getComponent(P,xs);k!=null&&k.activeAndEnabled&&(y+=1,l?b+=k.width:b+=k.height)}let _=0;const C=this.spacing*(y-1);if(f||h){let M=0;l?M=r-=C:M=a-=C,y>0&&(_=M/y)}let E=0;E+=this.padding.left,E-=this.padding.right,A!==0&&(v=m-b,v*=A,v-=C*A,l?(v-=this.padding.right*A,v+=this.padding.left*(1-A),v<this.padding.left&&(v=this.padding.left)):(v-=this.padding.bottom*A,v+=this.padding.top*(1-A),v<this.padding.top&&(v=this.padding.top)));let T=1;for(let M=0;M<this.gameObject.children.length;M++){const P=this.gameObject.children[M],k=$.getComponent(P,xs);if(k!=null&&k.activeAndEnabled){(x=k.pivot)==null||x.set(.5,.5),k.anchorMin.set(0,1),k.anchorMax.set(0,1);const G=s*.5+E*.5;k.anchoredPosition.x!==G&&(k.anchoredPosition.x=G);const z=o*-.5;k.anchoredPosition.y!==z&&(k.anchoredPosition.y=z),p&&d&&k.sizeDelta[c]!==g&&(k.sizeDelta[c]=g),f&&h&&k.sizeDelta[i]!==_&&(k.sizeDelta[i]=_);const L=l?k.width:k.height;let H=L*.5;if(v+=H,f){let K=_*T-_*.5;K>v&&(v=K-_*.5+L+this.padding.left,v-=H)}let Z=v;i==="y"&&(Z=-Z),k.anchoredPosition[i]!==Z&&(k.anchoredPosition[i]=Z),v+=H,v+=this.spacing,T+=1}}}}Cn([w()],dh.prototype,"childControlHeight",2);Cn([w()],dh.prototype,"childControlWidth",2);Cn([w()],dh.prototype,"childForceExpandHeight",2);Cn([w()],dh.prototype,"childForceExpandWidth",2);Cn([w()],dh.prototype,"childScaleHeight",2);Cn([w()],dh.prototype,"childScaleWidth",2);class oM extends dh{get primaryAxis(){return"y"}}class aM extends dh{get primaryAxis(){return"x"}}class lM extends kr{onCalculateLayout(){}}var Bte=Object.defineProperty,Dte=Object.getOwnPropertyDescriptor,Ga=(n,e,t,i)=>{for(var s=i>1?void 0:i?Dte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Bte(e,t,s),s};const $w=le("debuguilayout"),EN=class extends BA{constructor(){super(...arguments);u(this,"_renderOnTop");u(this,"_depthWrite",!1);u(this,"_doubleSided",!0);u(this,"_castShadows",!1);u(this,"_receiveShadows",!1);u(this,"_renderMode",-1);u(this,"_rootCanvas");u(this,"_scaleFactor",1);u(this,"worldCamera");u(this,"planeDistance",-1);u(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this));u(this,"previousParent",null);u(this,"_lastMatrixWorld",null);u(this,"_rectTransforms",[]);u(this,"_layoutGroups",new Map);u(this,"onBeforeRenderRoutine",()=>{var e,t;this.previousParent=this.gameObject.parent,this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(e=this.shadowComponent)==null||e.updateMatrixWorld(!0),(t=this.shadowComponent)==null||t.updateWorldMatrix(!0,!0),sr.ensureUpdateMeshUI(LB,this.context))});u(this,"onAfterRenderRoutine",()=>{var e,t;if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const i=this.context.mainCamera;i==null||i.add(this.gameObject)}else this.previousParent.add(this.gameObject);this.context.renderer.autoClear=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(e=this.shadowComponent)==null||e.updateMatrixWorld(!0),sr.ensureUpdateMeshUI(LB,this.context),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=!0,this.previousParent.add(this.gameObject)}(t=this._lastMatrixWorld)==null||t.copy(this.gameObject.matrixWorld)});u(this,"_updateRenderSettingsRoutine");u(this,"_activeRenderMode",-1);u(this,"_lastWidth",-1);u(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(e){e!==this._renderOnTop&&(this._renderOnTop=e,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(e){this._depthWrite!==e&&(this._depthWrite=e,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(e){this._doubleSided!==e&&(this._doubleSided=e,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(e){this._castShadows!==e&&(this._castShadows=e,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(e){this._receiveShadows!==e&&(this._receiveShadows=e,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(e){this._renderMode!==e&&(this._renderMode=e,this.onRenderSettingsChanged())}set rootCanvas(e){this._rootCanvas instanceof EN||(this._rootCanvas=e)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(e){this._scaleFactor=e}awake(){var e;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,$w&&console.log("Canvas.Awake()",((e=this.previousParent)==null?void 0:e.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new He,this.onUpdateRenderMode(),document.addEventListener("resize",this._boundRenderSettingsChanged),this.context.pre_render_callbacks.push(this.onBeforeRenderRoutine),this.context.post_render_callbacks.push(this.onAfterRenderRoutine)}onDisable(){super.onDisable(),document.removeEventListener("resize",this._boundRenderSettingsChanged);const e=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);e!==-1&&this.context.pre_render_callbacks.splice(e,1);const t=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);t!==-1&&this.context.post_render_callbacks.splice(t,1)}registerTransform(e){this._rectTransforms.push(e)}unregisterTransform(e){const t=this._rectTransforms.indexOf(e);t!==-1&&this._rectTransforms.splice(t,1)}registerLayoutGroup(e){const t=e.gameObject;this._layoutGroups.set(t,e)}unregisterLayoutGroup(e){const t=e.gameObject;this._layoutGroups.delete(t)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new He);const e=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);$w&&e&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);let t=!1;for(const i of this._rectTransforms){e&&i.markDirty();let s=this._layoutGroups.get(i.gameObject);i.isDirty&&!s&&(s=i.gameObject.getComponentInParent(kr)),(i.isDirty||s!=null&&s.isDirty)&&($w&&!t&&console.log("CANVAS UPDATE ### "+i.name+" ##################################### "+this.context.time.frame),s==null||s.updateLayout(),i.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),Rr.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),p_(this.shadowComponent,this);for(const e of $.getComponentsInChildren(this.gameObject,Ho))p_(e.shadowComponent,this)}}onUpdateRenderMode(e=!1){if(!e&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let t=this.context.mainCameraComponent,i=10;switch(t&&t.nearClipPlane>0&&t.farClipPlane>0&&(i=Ze.lerp(t.nearClipPlane,t.farClipPlane,.15)),this._renderMode===1&&(this.worldCamera&&(t=this.worldCamera),this.planeDistance>0&&(i=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!t)return;const s=i+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-s,this.gameObject.quaternion.identity();const r=this.gameObject.getComponent(xs);let o=!1;r.sizeDelta.x!==this.context.domWidth&&(o=!0),r.sizeDelta.y!==this.context.domHeight&&(o=!0);const a=t.fieldOfView*Math.PI/180,l=2*Math.tan(a/2)*Math.abs(s);this.gameObject.scale.x=l/this.context.domHeight,this.gameObject.scale.y=l/this.context.domHeight,this.gameObject.scale.z=.01,o&&(r.sizeDelta.x=this.context.domWidth,r.sizeDelta.y=this.context.domHeight,r==null||r.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let ws=EN;Ga([w()],ws.prototype,"renderOnTop",1);Ga([w()],ws.prototype,"depthWrite",1);Ga([w()],ws.prototype,"doubleSided",1);Ga([w()],ws.prototype,"castShadows",1);Ga([w()],ws.prototype,"receiveShadows",1);Ga([w()],ws.prototype,"renderMode",1);Ga([w(ws)],ws.prototype,"rootCanvas",1);Ga([w()],ws.prototype,"scaleFactor",1);Ga([w(Oi)],ws.prototype,"worldCamera",2);Ga([w()],ws.prototype,"planeDistance",2);var kte=Object.defineProperty,Ote=Object.getOwnPropertyDescriptor,cM=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ote(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&kte(e,t,s),s};class vp extends Ce{constructor(){super(...arguments);u(this,"_alpha",1);u(this,"interactable",!0);u(this,"blocksRaycasts",!0);u(this,"_isDirty",!1);u(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(t){t!==this._alpha&&(this._alpha=t,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),Rr.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){for(const t of $.getComponentsInChildren(this.gameObject,Ho,this._buffer)){const i=t;i.setAlphaFactor&&i.setAlphaFactor(this._alpha)}}}cM([w()],vp.prototype,"alpha",1);cM([w()],vp.prototype,"interactable",2);cM([w()],vp.prototype,"blocksRaycasts",2);var Lte=Object.defineProperty,Fte=Object.getOwnPropertyDescriptor,Fi=(n,e,t,i)=>{for(var s=i>1?void 0:i?Fte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Lte(e,t,s),s};class Fu extends Ce{constructor(){super(...arguments);u(this,"object");u(this,"target");u(this,"duration",1);u(this,"relativeMotion",!1);u(this,"coroutine",null);u(this,"targetPos",new S);u(this,"targetRot",new xe);u(this,"targetScale",new S)}*moveToTarget(){if(!this.target||!this.object)return;const t=wt(this.object).clone(),i=wt(this.target).clone(),s=Dn(this.object).clone(),r=Dn(this.target).clone(),o=ns(this.object).clone(),a=ns(this.target).clone(),l=t.distanceTo(i),c=s.angleTo(r),h=o.distanceTo(a);if(l<.01&&c<.01&&h<.01){ln(this.object,i),cr(this.object,r),vS(this.object,a),this.coroutine=null;return}let d=0,f=0;for(;d<1;)d+=this.context.time.deltaTime/this.duration,d>1&&(d=1),f=d<.5?4*d*d*d:1-Math.pow(-2*d+2,3)/2,this.targetPos.lerpVectors(t,i,f),this.targetRot.slerpQuaternions(s,r,f),this.targetScale.lerpVectors(o,a,f),ln(this.object,this.targetPos),cr(this.object,this.targetRot),vS(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const t=this.object.position.clone(),i=this.object.quaternion.clone(),s=this.object.scale.clone(),r=this.target.position.clone(),o=this.target.quaternion.clone(),a=this.target.scale.clone();r.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(r),this.targetRot.copy(this.object.quaternion).multiply(o),this.targetScale.copy(this.object.scale).multiply(a);let l=0,c=0;for(;l<1;)l+=this.context.time.deltaTime/this.duration,l>1&&(l=1),c=l<.5?4*l*l*l:1-Math.pow(-2*l+2,3)/2,this.object.position.lerpVectors(t,this.targetPos,c),this.object.quaternion.slerpQuaternions(i,this.targetRot,c),this.object.scale.lerpVectors(s,this.targetScale,c),yield;this.coroutine=null}onPointerClick(){this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}beforeCreateDocument(t){var i;if(this.target&&this.object&&this.gameObject){const s=new rs("Move to "+((i=this.target)==null?void 0:i.name),lr.tapTrigger(this.gameObject),oi.transformAction(this.object,this.target,this.duration,this.relativeMotion?YS.Relative:YS.Absolute));t.addBehavior(s)}}}Fi([w(Ie)],Fu.prototype,"object",2);Fi([w(Ie)],Fu.prototype,"target",2);Fi([w()],Fu.prototype,"duration",2);Fi([w()],Fu.prototype,"relativeMotion",2);var IC;const Bd=(IC=class extends Ce{constructor(){super(...arguments);u(this,"materialToSwitch");u(this,"variantMaterial");u(this,"_objectsWithThisMaterial",[]);u(this,"selfModel");u(this,"targetModels",[])}awake(){if(this.variantMaterial&&this.materialToSwitch){const e=$.findObjectsOfType(Ki);for(const t of e)t.sharedMaterial===this.materialToSwitch&&this._objectsWithThisMaterial.push(t)}}onPointerClick(){if(this.variantMaterial)for(const e of this._objectsWithThisMaterial)e.sharedMaterial=this.variantMaterial}createBehaviours(e,t,i){this._objectsWithThisMaterial.find(r=>r.gameObject.uuid===t.uuid)&&this.targetModels.push(t),this.gameObject.uuid===t.uuid&&(this.selfModel=t,this.materialToSwitch&&(Bd._materialTriggersPerId[this.materialToSwitch.uuid]||(Bd._materialTriggersPerId[this.materialToSwitch.uuid]=[]),Bd._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(e,t){if(!this.materialToSwitch)return;const i=Bd._materialTriggersPerId[this.materialToSwitch.uuid];if(i){const s={};for(const o of i){const a=o.createVariants();a&&a.length>0&&(s[o.selfModel.uuid]=a)}const r=[];for(const o of i){for(const a in s)a!==o.selfModel.uuid&&r.push(s[a]);o.createAndAttachBehaviors(e,s[o.selfModel.uuid],r)}}delete Bd._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(e,t,i){const s=[],r=[];for(const o of this.targetModels){const a=oi.fadeAction(o,0,!1);r.push(a)}for(const o of i)r.push(oi.fadeAction(o,0,!1));for(const o of t)s.push(oi.fadeAction(o,0,!1)),r.push(oi.fadeAction(o,0,!0));e.addBehavior(new rs("Select "+this.selfModel.name,lr.tapTrigger(this.selfModel),oi.parallel(...r))),e.addBehavior(new rs("Start hidden "+this.selfModel.name,lr.sceneStartTrigger(),oi.parallel(...s)))}createVariants(){if(!this.variantMaterial)return null;const e=[];for(const t of this.targetModels){const i=t.clone();i.name+=" variant_"+this.variantMaterial.name,i.name=i.name.replace(/\s/g,"_"),i.material=this.variantMaterial,i.geometry=t.geometry,i.matrix=t.matrix,(!t.parent||!t.parent.isEmpty())&&no.createEmptyParent(t),t.parent&&t.parent.add(i),e.push(i)}return e}},u(IC,"_materialTriggersPerId",{}),IC);let QA=Bd;Fi([w(Bt)],QA.prototype,"materialToSwitch",2);Fi([w(Bt)],QA.prototype,"variantMaterial",2);class yp extends Ce{constructor(){super(...arguments);u(this,"target");u(this,"toggleOnClick",!1);u(this,"targetState",!0);u(this,"hideSelf",!0);u(this,"selfModel");u(this,"otherModel");u(this,"toggleModel");u(this,"stateBeforeCreatingDocument",!1)}onPointerClick(){!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(t,i,s){i.uuid===this.gameObject.uuid&&(this.selfModel=i)}beforeCreateDocument(){this.stateBeforeCreatingDocument=this.gameObject.visible,this.gameObject.visible=!0}afterCreateDocument(t,i){if(this.target){if(this.otherModel=i.document.findById(this.target.uuid),this.selfModel&&this.otherModel){let s=this.hideSelf;this.targetState,this.toggleOnClick&&(s=!0,this.target.visible,(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&L3.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.clone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel));const r=[];if(s&&r.push(oi.fadeAction(this.selfModel,0,!1)),this.toggleModel&&r.push(oi.fadeAction(this.toggleModel,0,!0)),r.push(oi.fadeAction(this.otherModel,0,this.targetState)),t.addBehavior(new rs("Toggle_"+this.selfModel.name+"_hideSelf",lr.tapTrigger(this.selfModel),oi.sequence(...r))),this.toggleOnClick&&this.toggleModel){const o=[];o.push(oi.fadeAction(this.toggleModel,0,!1)),o.push(oi.fadeAction(this.selfModel,0,!0)),o.push(oi.fadeAction(this.otherModel,0,!this.targetState)),t.addBehavior(new rs("Toggle_"+this.selfModel.name+"_toggleSelf",lr.tapTrigger(this.toggleModel),oi.sequence(...o))),t.addBehavior(new rs("HideOnStart_"+this.gameObject.name,lr.sceneStartTrigger(),oi.fadeAction(this.toggleModel,0,!1)))}}this.gameObject.visible=this.stateBeforeCreatingDocument}}}Fi([w(Ie)],yp.prototype,"target",2);Fi([w()],yp.prototype,"targetState",2);Fi([w()],yp.prototype,"hideSelf",2);class hM extends Ce{start(){this.gameObject.visible=!1}createBehaviours(e,t,i){t.uuid===this.gameObject.uuid&&e.addBehavior(new rs("HideOnStart_"+this.gameObject.name,lr.sceneStartTrigger(),oi.fadeAction(t,0,!1)))}beforeCreateDocument(){this.gameObject.visible=!0}afterCreateDocument(){this.gameObject.visible=!1}}class _p extends Ce{constructor(){super(...arguments);u(this,"target");u(this,"duration",.5);u(this,"motionType",pI.bounce)}beforeCreateDocument(){}createBehaviours(t,i,s){if(this.target&&i.uuid===this.gameObject.uuid){const r=new rs("emphasize "+this.name,lr.tapTrigger(this.gameObject),oi.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));t.addBehavior(r)}}afterCreateDocument(t,i){}}Fi([w()],_p.prototype,"target",2);Fi([w()],_p.prototype,"duration",2);Fi([w()],_p.prototype,"motionType",2);class bp extends Ce{constructor(){super(...arguments);u(this,"target");u(this,"clip","");u(this,"toggleOnClick",!1)}onPointerClick(){if(!(!this.target&&!this.clip)){if(!this.target){const t=this.gameObject.addNewComponent(xn);t&&(t.spatialBlend=1,t.volume=1,t.loop=!1,this.target=t)}this.target&&(this.target.isPlaying&&this.toggleOnClick?this.target.stop():(!this.toggleOnClick&&this.target.isPlaying&&this.target.stop(),this.clip?this.target.play(this.clip):this.target.play()))}}createBehaviours(t,i,s){if(!(!this.target&&!this.clip)&&i.uuid===this.gameObject.uuid){const r=this.clip?this.clip:this.target?this.target.clip:void 0;if(!r)return;const o=this.target?this.target.gameObject:this.gameObject,a=r.split("/").pop(),l=this.target?this.target.volume:1,c=this.target&&this.target.spatialBlend==0?JS.NonSpatial:JS.Spatial,h=new rs("playAudio "+this.name,lr.tapTrigger(this.gameObject),oi.playAudioAction(o,"audio/"+a,Q3.Play,l,c));t.addBehavior(h)}}async afterSerialize(t,i){if(!this.target&&!this.clip)return;const s=this.clip?this.clip:this.target?this.target.clip:void 0;if(!s)return;const r=s.split("/").pop(),l=await(await(await fetch(this.clip)).blob()).arrayBuffer(),c=new Uint8Array(l);i.files["audio/"+r]=c}}Fi([w(xn)],bp.prototype,"target",2);Fi([w(URL)],bp.prototype,"clip",2);Fi([w()],bp.prototype,"toggleOnClick",2);var MC;const Dd=(MC=class extends Ce{constructor(){super(...arguments);u(this,"target");u(this,"animator");u(this,"stateName");u(this,"stateNameAfterPlaying");u(this,"loopAfterPlaying",!1);u(this,"selfModel");u(this,"stateAnimationModel");u(this,"stateAnimation");u(this,"stateAfterPlayingAnimationModel");u(this,"stateAfterPlayingAnimation")}onPointerClick(){var e;this.target&&this.stateName&&((e=this.animator)==null||e.play(this.stateName,0,0,.1))}createBehaviours(e,t,i){t.uuid===this.gameObject.uuid&&(this.selfModel=t)}onAfterHierarchy(){Dd.animationActions=[]}afterCreateDocument(e,t){if(!this.stateAnimation||!this.stateAnimationModel)return;t.document.traverse(s=>{var r,o;if(s.uuid===((r=this.target)==null?void 0:r.uuid)&&this.stateAnimation){const a=[];let l=Dd.animationActions.find(h=>h.affectedObjects==s&&h.start==this.stateAnimation.start&&h.duration==this.stateAnimation.duration);if(l||(l=oi.startAnimationAction(s,this.stateAnimation.start,this.stateAnimation.duration),Dd.animationActions.push(l)),a.push(l),this.stateAfterPlayingAnimation&&this.stateAfterPlayingAnimationModel){let h=Dd.animationActions.find(f=>f.affectedObjects==s&&f.start==this.stateAfterPlayingAnimation.start&&f.duration==this.stateAfterPlayingAnimation.duration);h||(h=oi.startAnimationAction(s,this.stateAfterPlayingAnimation.start,this.stateAfterPlayingAnimation.duration),Dd.animationActions.push(h));const d=oi.sequence(h);this.loopAfterPlaying&&d.makeLooping(),a.push(d)}const c=new rs("tap "+this.name+" for "+this.stateName+" on "+((o=this.target)==null?void 0:o.name),lr.tapTrigger(this.selfModel),oi.sequence(...a));e.addBehavior(c)}})}createAnimation(e,t,i){var s,r,o,a;if(this.target&&this.animator){const l=(r=(s=this.animator)==null?void 0:s.runtimeAnimatorController)==null?void 0:r.findState(this.stateName);this.stateAnimationModel=t,this.stateAnimation=e.registerAnimation(this.target,l==null?void 0:l.motion.clip);const c=(a=(o=this.animator)==null?void 0:o.runtimeAnimatorController)==null?void 0:a.findState(this.stateNameAfterPlaying);this.stateAfterPlayingAnimationModel=t,this.stateAfterPlayingAnimation=e.registerAnimation(this.target,c==null?void 0:c.motion.clip)}}},u(MC,"animationActions",[]),MC);let fh=Dd;Fi([w(Ie)],fh.prototype,"target",2);Fi([w(hr)],fh.prototype,"animator",2);Fi([w()],fh.prototype,"stateName",2);Fi([w()],fh.prototype,"stateNameAfterPlaying",2);Fi([w()],fh.prototype,"loopAfterPlaying",2);class xp extends Ce{constructor(){super(...arguments);u(this,"target")}getType(){}getDuration(){}}Fi([w(Ie)],xp.prototype,"target",2);class HA extends Ce{constructor(){super(...arguments);u(this,"target")}}Fi([w(xp)],HA.prototype,"target",2);class VA extends xp{constructor(){super(...arguments);u(this,"type",1);u(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}Fi([w()],VA.prototype,"type",2);Fi([w()],VA.prototype,"duration",2);class uM extends HA{}var Ute=Object.defineProperty,Nte=Object.getOwnPropertyDescriptor,Yl=(n,e,t,i)=>{for(var s=i>1?void 0:i?Nte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Ute(e,t,s),s};class Uu extends Ce{constructor(){super(...arguments);u(this,"center",new S(0,0,0));u(this,"radius",.5);u(this,"height",2);u(this,"_rigidbody",null);u(this,"_activeGroundCollisions",new Set)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(Hi),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(Hi)),this.rigidbody)}onEnable(){let t=this.rigidbody,i=this.gameObject.getComponent(Zc);i||(i=this.gameObject.addNewComponent(Zc)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height,this.gameObject.rotation.x=0,this.gameObject.rotation.z=0,t.lockRotationX=!0,t.lockRotationY=!0,t.lockRotationZ=!0}move(t){this.gameObject.position.add(t)}onCollisionEnter(t){for(const i of t.contacts)if(i.normal.y>.1){this._activeGroundCollisions.add(t);break}}onCollisionExit(t){this._activeGroundCollisions.delete(t)}get isGrounded(){return this._activeGroundCollisions.size>0}}Yl([w(S)],Uu.prototype,"center",2);Yl([w()],Uu.prototype,"radius",2);Yl([w()],Uu.prototype,"height",2);class Jl extends Ce{constructor(){super(...arguments);u(this,"controller");u(this,"movementSpeed",2);u(this,"rotationSpeed",2);u(this,"jumpForce",1);u(this,"doubleJumpForce",2);u(this,"animator");u(this,"lookForward",!0);u(this,"_currentSpeed",new S(0,0,0));u(this,"_currentAngularSpeed",new S(0,0,0));u(this,"_temp",new S(0,0,0));u(this,"_jumpCount",0);u(this,"_currentRotation");u(this,"_raycastOptions",new qo)}awake(){this._currentRotation=new xe}update(){var c,h,d,f,p,g,m,A,v,b,y;(c=this.controller)!=null&&c.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((h=this.animator)==null||h.setBool("doubleJump",!1)));const t=this.context.input.isKeyPressed("w"),i=this.context.input.isKeyPressed("s"),s=this.context.input.isKeyPressed("a"),r=this.context.input.isKeyPressed("d"),o=this.context.input.isKeyDown(" "),a=(t?1:0)+(i?-1:0);this._currentSpeed.z+=a*this.movementSpeed*this.context.time.deltaTime,(d=this.animator)==null||d.setBool("running",a!=0),(p=this.animator)==null||p.setBool("jumping",((f=this.controller)==null?void 0:f.isGrounded)===!0&&o),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp);const l=(s?1:0)+(r?-1:0);if(this._currentAngularSpeed.y+=Ze.toRadians(l*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const _=this.context.mainCameraComponent.forward;_.y=0,_.normalize(),this._currentRotation.setFromUnitVectors(new S(0,0,1),_),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&o&&this.jumpForce>0){let _=(g=this.controller)==null?void 0:g.isGrounded;if(this.doubleJumpForce>0&&!((m=this.controller)!=null&&m.isGrounded)&&this._jumpCount===1&&(_=!0,(A=this.animator)==null||A.setBool("doubleJump",!0)),_){this._jumpCount+=1;const C=this.controller.rigidbody,E=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;C.applyImpulse(new S(0,1,0).multiplyScalar(E))}}if(this.controller){const _=(v=this.controller)==null?void 0:v.rigidbody.getVelocity().y;if(_<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new Gl),this._raycastOptions.ray.origin.copy(wt(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const C=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const E=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(C),(E.length&&E[0].distance>2||_<-10)&&((b=this.animator)==null||b.setBool("falling",!0))}else(y=this.animator)==null||y.setBool("falling",!1)}}}Yl([w(Uu)],Jl.prototype,"controller",2);Yl([w()],Jl.prototype,"movementSpeed",2);Yl([w()],Jl.prototype,"rotationSpeed",2);Yl([w()],Jl.prototype,"jumpForce",2);Yl([w()],Jl.prototype,"doubleJumpForce",2);Yl([w(hr)],Jl.prototype,"animator",2);var zte=Object.defineProperty,Gte=Object.getOwnPropertyDescriptor,Qte=(n,e,t,i)=>{for(var s=i>1?void 0:i?Gte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&zte(e,t,s),s};class jA extends js{constructor(){super(...arguments);u(this,"intensity")}get typeName(){return"ChromaticAberration"}init(){this.intensity.defaultValue=0}onCreateEffect(){const t=new tF;return t.offset=new q(0,0),t.radialModulation=!0,t.modulationOffset=.15,this.intensity.valueProcessor=i=>i*.02,this.intensity.onValueChanged=i=>{t.offset.x=-i,t.offset.y=i},t}}Qte([w(Ft)],jA.prototype,"intensity",2);Na("ChromaticAberration",jA);var Hte=Object.defineProperty,Vte=Object.getOwnPropertyDescriptor,Jb=(n,e,t,i)=>{for(var s=i>1?void 0:i?Vte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Hte(e,t,s),s};class ph extends js{constructor(){super(...arguments);u(this,"postExposure");u(this,"contrast");u(this,"hueShift");u(this,"saturation")}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=t=>(t=Math.pow(2,t),t),this.postExposure.defaultValue=0,this.contrast.valueProcessor=t=>{let i=1;return t>0?i=200:t<0&&(i=100),t/i},this.contrast.defaultValue=0,this.hueShift.valueProcessor=t=>Math.PI*t/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=t=>t<0?t/100:t/(100*Math.PI),this.saturation.defaultValue=0}unapply(){this.context.renderer.toneMappingExposure=1}onCreateEffect(){this.context.renderer.toneMapping===Ls&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=rm);const t=new eF;this.postExposure.onValueChanged=s=>{this.context.renderer.toneMapping===Ls&&(this.context.renderer.toneMapping=rm),this.context.renderer.toneMappingExposure=s},this.contrast.onValueChanged=s=>{t.contrast=s};const i=new nF;return this.hueShift.onValueChanged=s=>i.hue=s,this.saturation.onValueChanged=s=>i.saturation=s,[i,t]}}Jb([w(Ft)],ph.prototype,"postExposure",2);Jb([w(Ft)],ph.prototype,"contrast",2);Jb([w(Ft)],ph.prototype,"hueShift",2);Jb([w(Ft)],ph.prototype,"saturation",2);Na("ColorAdjustments",ph);const jte=(Math.sqrt(5)-1)/4,Kn=(5-Math.sqrt(5))/20,_y=n=>Math.floor(n)|0,by=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function Wte(n=Math.random){const e=qte(n),t=new Float64Array(e).map(o=>by[o%32*4]),i=new Float64Array(e).map(o=>by[o%32*4+1]),s=new Float64Array(e).map(o=>by[o%32*4+2]),r=new Float64Array(e).map(o=>by[o%32*4+3]);return function(a,l,c,h){let d,f,p,g,m;const A=(a+l+c+h)*jte,v=_y(a+A),b=_y(l+A),y=_y(c+A),_=_y(h+A),C=(v+b+y+_)*Kn,E=v-C,T=b-C,x=y-C,M=_-C,P=a-E,k=l-T,G=c-x,z=h-M;let L=0,H=0,Z=0,K=0;P>k?L++:H++,P>G?L++:Z++,P>z?L++:K++,k>G?H++:Z++,k>z?H++:K++,G>z?Z++:K++;const J=L>=3?1:0,ue=H>=3?1:0,he=Z>=3?1:0,Pe=K>=3?1:0,ge=L>=2?1:0,ie=H>=2?1:0,ae=Z>=2?1:0,we=K>=2?1:0,V=L>=1?1:0,Le=H>=1?1:0,Re=Z>=1?1:0,qe=K>=1?1:0,ye=P-J+Kn,at=k-ue+Kn,pe=G-he+Kn,fe=z-Pe+Kn,De=P-ge+2*Kn,$e=k-ie+2*Kn,We=G-ae+2*Kn,ft=z-we+2*Kn,ct=P-V+3*Kn,st=k-Le+3*Kn,Ht=G-Re+3*Kn,kt=z-qe+3*Kn,U=P-1+4*Kn,D=k-1+4*Kn,ce=G-1+4*Kn,Ee=z-1+4*Kn,Be=v&255,Ve=b&255,lt=y&255,Qe=_&255;let O=.6-P*P-k*k-G*G-z*z;if(O<0)d=0;else{const Fe=Be+e[Ve+e[lt+e[Qe]]];O*=O,d=O*O*(t[Fe]*P+i[Fe]*k+s[Fe]*G+r[Fe]*z)}let Ae=.6-ye*ye-at*at-pe*pe-fe*fe;if(Ae<0)f=0;else{const Fe=Be+J+e[Ve+ue+e[lt+he+e[Qe+Pe]]];Ae*=Ae,f=Ae*Ae*(t[Fe]*ye+i[Fe]*at+s[Fe]*pe+r[Fe]*fe)}let Je=.6-De*De-$e*$e-We*We-ft*ft;if(Je<0)p=0;else{const Fe=Be+ge+e[Ve+ie+e[lt+ae+e[Qe+we]]];Je*=Je,p=Je*Je*(t[Fe]*De+i[Fe]*$e+s[Fe]*We+r[Fe]*ft)}let Ne=.6-ct*ct-st*st-Ht*Ht-kt*kt;if(Ne<0)g=0;else{const Fe=Be+V+e[Ve+Le+e[lt+Re+e[Qe+qe]]];Ne*=Ne,g=Ne*Ne*(t[Fe]*ct+i[Fe]*st+s[Fe]*Ht+r[Fe]*kt)}let je=.6-U*U-D*D-ce*ce-Ee*Ee;if(je<0)m=0;else{const Fe=Be+1+e[Ve+1+e[lt+1+e[Qe+1]]];je*=je,m=je*je*(t[Fe]*U+i[Fe]*D+s[Fe]*ce+r[Fe]*Ee)}return 27*(d+f+p+g+m)}}function qte(n){const t=new Uint8Array(512);for(let i=0;i<512/2;i++)t[i]=i;for(let i=0;i<512/2-1;i++){const s=i+~~(n()*(256-i)),r=t[i];t[i]=t[s],t[s]=r}for(let i=256;i<512;i++)t[i]=t[i-256];return t}var Xte=Object.defineProperty,Yte=Object.getOwnPropertyDescriptor,Y=(n,e,t,i)=>{for(var s=i>1?void 0:i?Yte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Xte(e,t,s),s};const xy=le("debugparticles");var Aa=(n=>(n[n.Billboard=0]="Billboard",n[n.Stretch=1]="Stretch",n[n.HorizontalBillboard=2]="HorizontalBillboard",n[n.VerticalBillboard=3]="VerticalBillboard",n[n.Mesh=4]="Mesh",n))(Aa||{});class gh{constructor(){u(this,"alphaKeys");u(this,"colorKeys")}get duration(){return 1}evaluate(e,t){let i,s=0,r=null,o=0;for(let a=0;a<this.alphaKeys.length;a++){const l=this.alphaKeys[a];(l.time<e||!i)&&(i=l,s=a)}for(let a=0;a<this.colorKeys.length;a++){const l=this.colorKeys[a];(l.time<e||!r)&&(r=l,o=a)}if(r)if(o+1<this.colorKeys.length){const l=this.colorKeys[o+1],c=Ze.remap(e,r.time,l.time,0,1);t.r=Ze.lerp(r.color.r,l.color.r,c),t.g=Ze.lerp(r.color.g,l.color.g,c),t.b=Ze.lerp(r.color.b,l.color.b,c)}else t.r=r.color.r,t.g=r.color.g,t.b=r.color.b;if(i)if(s+1<this.alphaKeys.length){const l=this.alphaKeys[s+1],c=Ze.remap(e,i.time,l.time,0,1);t.alpha=Ze.lerp(i.alpha,l.alpha,c)}else t.alpha=i.alpha;return t}}Y([w()],gh.prototype,"alphaKeys",2);Y([w()],gh.prototype,"colorKeys",2);var Kb=(n=>(n[n.Local=0]="Local",n[n.World=1]="World",n[n.Custom=2]="Custom",n))(Kb||{}),IN=(n=>(n[n.Sphere=0]="Sphere",n[n.SphereShell=1]="SphereShell",n[n.Hemisphere=2]="Hemisphere",n[n.HemisphereShell=3]="HemisphereShell",n[n.Cone=4]="Cone",n[n.Box=5]="Box",n[n.Mesh=6]="Mesh",n[n.ConeShell=7]="ConeShell",n[n.ConeVolume=8]="ConeVolume",n[n.ConeVolumeShell=9]="ConeVolumeShell",n[n.Circle=10]="Circle",n[n.CircleEdge=11]="CircleEdge",n[n.SingleSidedEdge=12]="SingleSidedEdge",n[n.MeshRenderer=13]="MeshRenderer",n[n.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",n[n.BoxShell=15]="BoxShell",n[n.BoxEdge=16]="BoxEdge",n[n.Donut=17]="Donut",n[n.Rectangle=18]="Rectangle",n[n.Sprite=19]="Sprite",n[n.SpriteRenderer=20]="SpriteRenderer",n))(IN||{});class ot{constructor(){u(this,"mode");u(this,"constant");u(this,"constantMin");u(this,"constantMax");u(this,"curve");u(this,"curveMin");u(this,"curveMax");u(this,"curveMultiplier")}evaluate(e,t){const i=t===void 0?Math.random():t;switch(this.mode){case 0:return this.constant;case 1:return e=Ze.clamp01(e),this.curve.evaluate(e)*this.curveMultiplier;case 2:const s=e*this.curveMin.duration,r=e*this.curveMax.duration;return Ze.lerp(this.curveMin.evaluate(s),this.curveMax.evaluate(r),i%1)*this.curveMultiplier;case 3:return Ze.lerp(this.constantMin,this.constantMax,i%1);default:this.curveMax.evaluate(e)*this.curveMultiplier;break}return 0}getMax(){switch(this.mode){case 0:return this.constant;case 1:return this.getMaxFromCurve(this.curve)*this.curveMultiplier;case 2:return Math.max(this.getMaxFromCurve(this.curveMin),this.getMaxFromCurve(this.curveMax))*this.curveMultiplier;case 3:return Math.max(this.constantMin,this.constantMax);default:return 0}}getMaxFromCurve(e){if(!e)return 0;let t=Number.MIN_VALUE;for(let i=0;i<e.keys.length;i++){const s=e.keys[i];s.value>t&&(t=s.value)}return t}}Y([w()],ot.prototype,"mode",2);Y([w()],ot.prototype,"constant",2);Y([w()],ot.prototype,"constantMin",2);Y([w()],ot.prototype,"constantMax",2);Y([w(Tu)],ot.prototype,"curve",2);Y([w(Tu)],ot.prototype,"curveMin",2);Y([w(Tu)],ot.prototype,"curveMax",2);Y([w()],ot.prototype,"curveMultiplier",2);var Fy;const Mo=(Fy=class{constructor(){u(this,"mode");u(this,"color");u(this,"colorMin");u(this,"colorMax");u(this,"gradient");u(this,"gradientMin");u(this,"gradientMax")}evaluate(n,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.color;case 1:return this.gradient.evaluate(n,Mo._temp),Mo._temp;case 2:return Mo._temp.lerpColors(this.colorMin,this.colorMax,t);case 3:return this.gradientMin.evaluate(n,Mo._temp),this.gradientMax.evaluate(n,Mo._temp2),Mo._temp.lerp(Mo._temp2,t)}return Mo._temp.set(16711935),Mo._temp.alpha=1,Mo._temp}},u(Fy,"_temp",new xi(0,0,0,1)),u(Fy,"_temp2",new xi(0,0,0,1)),Fy);let ur=Mo;Y([w(xi)],ur.prototype,"color",2);Y([w(xi)],ur.prototype,"colorMin",2);Y([w(xi)],ur.prototype,"colorMax",2);Y([w(gh)],ur.prototype,"gradient",2);Y([w(gh)],ur.prototype,"gradientMin",2);Y([w(gh)],ur.prototype,"gradientMax",2);class cs{constructor(){u(this,"cullingMode");u(this,"duration");u(this,"emitterVelocityMode");u(this,"flipRotation");u(this,"gravityModifier");u(this,"gravityModifierMultiplier");u(this,"loop");u(this,"maxParticles");u(this,"playOnAwake");u(this,"prewarm");u(this,"ringBufferLoopRange");u(this,"ringBufferMode");u(this,"scalingMode");u(this,"simulationSpace");u(this,"simulationSpeed");u(this,"startColor");u(this,"startDelay");u(this,"startDelayMultiplier");u(this,"startLifetime");u(this,"startLifetimeMultiplier");u(this,"startRotation");u(this,"startRotationMultiplier");u(this,"startRotation3D");u(this,"startRotationX");u(this,"startRotationXMultiplier");u(this,"startRotationY");u(this,"startRotationYMultiplier");u(this,"startRotationZ");u(this,"startRotationZMultiplier");u(this,"startSize");u(this,"startSize3D");u(this,"startSizeMultiplier");u(this,"startSizeX");u(this,"startSizeXMultiplier");u(this,"startSizeY");u(this,"startSizeYMultiplier");u(this,"startSizeZ");u(this,"startSizeZMultiplier");u(this,"startSpeed");u(this,"startSpeedMultiplier");u(this,"stopAction");u(this,"useUnscaledTime")}}Y([w(ot)],cs.prototype,"gravityModifier",2);Y([w(ur)],cs.prototype,"startColor",2);Y([w(ot)],cs.prototype,"startDelay",2);Y([w(ot)],cs.prototype,"startLifetime",2);Y([w(ot)],cs.prototype,"startRotation",2);Y([w(ot)],cs.prototype,"startRotationX",2);Y([w(ot)],cs.prototype,"startRotationY",2);Y([w(ot)],cs.prototype,"startRotationZ",2);Y([w(ot)],cs.prototype,"startSize",2);Y([w(ot)],cs.prototype,"startSizeX",2);Y([w(ot)],cs.prototype,"startSizeY",2);Y([w(ot)],cs.prototype,"startSizeZ",2);Y([w(ot)],cs.prototype,"startSpeed",2);class Lm{constructor(){u(this,"cycleCount");u(this,"maxCount");u(this,"minCount");u(this,"probability");u(this,"repeatInterval");u(this,"time");u(this,"count");u(this,"_performed",0)}reset(){this._performed=0}run(e){if(e<=this.time)return this.reset(),0;let t=0;if(this.cycleCount===0||this._performed<this.cycleCount){const i=this.time+this.repeatInterval*this._performed;if(e>=i&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:t=this.count.constant;break;case 3:t=Ze.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:t=this.count.curve.evaluate(Math.random());break;case 2:const s=Math.random();t=Ze.lerp(this.count.curveMin.evaluate(s),this.count.curveMax.evaluate(s),Math.random());break}}return t}}class Qa{constructor(){u(this,"enabled");u(this,"bursts");u(this,"rateOverTime");u(this,"rateOverTimeMultiplier");u(this,"rateOverDistance");u(this,"rateOverDistanceMultiplier");u(this,"system")}get burstCount(){var e;return((e=this.bursts)==null?void 0:e.length)??0}reset(){var e;(e=this.bursts)==null||e.forEach(t=>t.reset())}getBurst(){let e=0;if(this.burstCount>0)for(let t=0;t<this.burstCount;t++){const i=this.bursts[t];i.time>=this.system.time&&i.reset(),e+=Math.round(i.run(this.system.time))}return e}}Y([w()],Qa.prototype,"enabled",2);Y([w()],Qa.prototype,"bursts",2);Y([w(ot)],Qa.prototype,"rateOverTime",2);Y([w()],Qa.prototype,"rateOverTimeMultiplier",2);Y([w(ot)],Qa.prototype,"rateOverDistance",2);Y([w()],Qa.prototype,"rateOverDistanceMultiplier",2);class WA{constructor(){u(this,"enabled");u(this,"color")}}Y([w(ur)],WA.prototype,"color",2);class mh{constructor(){u(this,"enabled");u(this,"separateAxes");u(this,"size");u(this,"sizeMultiplier");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier");u(this,"_time",0);u(this,"_temp",new S)}evaluate(e,t,i){if(t||(t=this._temp),!this.enabled)return t.x=t.y=t.z=1,t;if(this.separateAxes)t.x=this.x.evaluate(e,i)*this.xMultiplier,t.y=this.y.evaluate(e,i)*this.yMultiplier,t.z=this.z.evaluate(e,i)*this.zMultiplier;else{const s=this.size.evaluate(e,i)*this.sizeMultiplier;t.x=s}return t}}Y([w(ot)],mh.prototype,"size",2);Y([w(ot)],mh.prototype,"x",2);Y([w(ot)],mh.prototype,"y",2);Y([w(ot)],mh.prototype,"z",2);var Uy;const yg=(Uy=class{constructor(){u(this,"shapeType",5);u(this,"enabled",!0);u(this,"alignToDirection",!1);u(this,"angle",0);u(this,"arc",360);u(this,"arcSpread");u(this,"arcSpeedMultiplier");u(this,"arcMode");u(this,"boxThickness");u(this,"position");u(this,"rotation");u(this,"_rotation",new bn);u(this,"scale");u(this,"radius");u(this,"radiusThickness");u(this,"sphericalDirectionAmount");u(this,"randomDirectionAmount");u(this,"randomPositionAmount");u(this,"system");u(this,"_space");u(this,"_worldSpaceMatrix",new He);u(this,"_worldSpaceMatrixInverse",new He);u(this,"_vector",new S(0,0,0));u(this,"_temp",new S(0,0,0));u(this,"_dir",new S);u(this,"_loopTime",0);u(this,"_loopDirection",1);xy&&console.log(this)}get type(){return IN[this.shapeType]}initialize(n){this.getPosition(),n.position.copy(this._vector)}toJSON(){return this}clone(){return new yg}update(n,e,t,i){this.system=n,this._space=t,t===1&&(this._worldSpaceMatrix.copy(i.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(n){const e=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return e&&(this._rotation.x=Ze.toRadians(this.rotation.x),this._rotation.y=Ze.toRadians(this.rotation.y),this._rotation.z=Ze.toRadians(this.rotation.z),this._rotation.order="ZYX",n.applyEuler(this._rotation)),e}get vector(){return this._vector}getPosition(){this._vector.set(0,0,0);const n=this._temp.copy(this.position),e=this._space===1;e&&n.applyQuaternion(this.system.worldQuaternion);let t=this.radius;if(e&&(t*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:xy&&xa.DrawBox(this.position,this.scale,14540253,1),this._vector.x=Math.random()*this.scale.x-this.scale.x/2,this._vector.y=Math.random()*this.scale.y-this.scale.y/2,this._vector.z=Math.random()*this.scale.z-this.scale.z/2,this._vector.add(n);break;case 4:this.randomConePoint(this.position,this.angle,t,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,t,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,t,this.radiusThickness,this.arc,this._vector);break;default:this._vector.set(0,0,0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),e&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),xy&&xa.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(n){var e;if(!this.enabled)return this._dir.set(0,0,1),this._dir;switch(this.shapeType){case 5:this._dir.set(0,0,1);break;case 4:this._dir.set(0,0,1);break;case 10:case 0:const t=n.x,i=n.y,s=n.z;this._dir.set(t,i,s),(e=this.system)!=null&&e.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;default:this._dir.set(0,0,1);break}return this._space===1&&this._dir.applyQuaternion(this.system.worldQuaternion),this.applyRotation(this._dir),this._dir.normalize(),this.spherizeDirection(this._dir,this.sphericalDirectionAmount),this.randomizeDirection(this._dir,this.randomDirectionAmount),xy&&(xa.DrawSphere(n,.01,8925952,.5,!0),xa.DrawDirection(n,this._dir,8925952,.5,!0)),this._dir}randomizePosition(n,e){if(e<=0)return;const t=yg._tempVec;t.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),t.x*=e*this.scale.x,t.y*=e*this.scale.y,t.z*=e*this.scale.z,n.add(t)}randomizeDirection(n,e){if(e===0)return;const t=yg._randomQuat,i=yg._tempVec;i.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),t.setFromAxisAngle(i,e*Math.random()*Math.PI),n.applyQuaternion(t)}spherizeDirection(n,e){if(e===0)return;const t=Math.random()*Math.PI*2,i=Math.acos(1-Math.random()*2),s=Math.sin(i)*Math.cos(t),r=Math.sin(i)*Math.sin(t),o=Math.cos(i),a=new S(s,r,o);n.lerp(a,e)}randomSpherePoint(n,e,t,i,s){const r=Math.random(),o=Math.random(),a=2*Math.PI*r*(i/360),l=Math.acos(2*o-1),c=Ze.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,h=n.x+this.scale.x*(-c*Math.sin(l)*Math.cos(a)),d=n.y+this.scale.y*(c*Math.sin(l)*Math.sin(a)),f=n.z+this.scale.z*(c*Math.cos(l));s.x=h,s.y=d,s.z=f}randomCirclePoint(n,e,t,i,s){const r=Math.random(),o=2*Math.PI*r*(i/360),a=Ze.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,l=n.x+this.scale.x*a*Math.cos(o),c=n.y+this.scale.y*a*Math.sin(o),h=n.z;s.x=l,s.y=c,s.z=h}randomConePoint(n,e,t,i,s,r,o){let a=0,l=0;switch(r){case 0:a=Math.random(),l=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:a=.5,l=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let c=2*Math.PI*a*(s/360);switch(r){case 2:case 1:c+=Math.PI+.5,c+=this._loopTime*Math.PI*2,c%=Ze.toRadians(s);break}const h=Math.acos(2*l-1),d=Ze.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*t,f=n.x+-d*Math.sin(h)*Math.cos(c),p=n.y+d*Math.sin(h)*Math.sin(c),g=n.z;o.x=f*this.scale.x,o.y=p*this.scale.y,o.z=g*this.scale.z}},u(Uy,"_randomQuat",new xe),u(Uy,"_tempVec",new S),Uy);let dn=yg;Y([w()],dn.prototype,"shapeType",2);Y([w()],dn.prototype,"enabled",2);Y([w()],dn.prototype,"alignToDirection",2);Y([w()],dn.prototype,"angle",2);Y([w()],dn.prototype,"arc",2);Y([w()],dn.prototype,"arcSpread",2);Y([w()],dn.prototype,"arcSpeedMultiplier",2);Y([w()],dn.prototype,"arcMode",2);Y([w(S)],dn.prototype,"boxThickness",2);Y([w(S)],dn.prototype,"position",2);Y([w(S)],dn.prototype,"rotation",2);Y([w(S)],dn.prototype,"scale",2);Y([w()],dn.prototype,"radius",2);Y([w()],dn.prototype,"radiusThickness",2);Y([w()],dn.prototype,"sphericalDirectionAmount",2);Y([w()],dn.prototype,"randomDirectionAmount",2);Y([w()],dn.prototype,"randomPositionAmount",2);class di{constructor(){u(this,"damping");u(this,"enabled");u(this,"frequency");u(this,"octaveCount");u(this,"octaveMultiplier");u(this,"octaveScale");u(this,"positionAmount");u(this,"quality");u(this,"remap");u(this,"remapEnabled");u(this,"remapMultiplier");u(this,"remapX");u(this,"remapXMultiplier");u(this,"remapY");u(this,"remapYMultiplier");u(this,"remapZ");u(this,"remapZMultiplier");u(this,"scrollSpeedMultiplier");u(this,"separateAxes");u(this,"strengthMultiplier");u(this,"strengthX");u(this,"strengthXMultiplier");u(this,"strengthY");u(this,"strengthYMultiplier");u(this,"strengthZ");u(this,"strengthZMultiplier");u(this,"_noise");u(this,"_time",0);u(this,"_temp",new S)}update(e){this._time+=e.time.deltaTime*this.scrollSpeedMultiplier}apply(e,t,i,s,r,o){if(!this.enabled)return;this._noise||(this._noise=Wte(()=>0));const a=this._temp.set(t.x,t.y,t.z).multiplyScalar(this.frequency),l=this._noise(a.x,a.y,a.z,this._time),c=this._noise(a.x,a.y,a.z,this._time+1e3*this.frequency),h=this._noise(a.x,a.y,a.z,this._time+2e3*this.frequency);this._temp.set(l,c,h).normalize();const d=r/o;let f=this.positionAmount.evaluate(d);this.separateAxes?(this._temp.x*=f*this.strengthXMultiplier,this._temp.y*=f*this.strengthYMultiplier,this._temp.z*=f*this.strengthZMultiplier):(this.strengthX&&(f*=this.strengthX.evaluate(d)*1.5),this._temp.multiplyScalar(f)),i.x+=this._temp.x,i.y+=this._temp.y,i.z+=this._temp.z}}Y([w()],di.prototype,"damping",2);Y([w()],di.prototype,"enabled",2);Y([w()],di.prototype,"frequency",2);Y([w()],di.prototype,"octaveCount",2);Y([w()],di.prototype,"octaveMultiplier",2);Y([w()],di.prototype,"octaveScale",2);Y([w(ot)],di.prototype,"positionAmount",2);Y([w()],di.prototype,"quality",2);Y([w(ot)],di.prototype,"remap",2);Y([w()],di.prototype,"remapEnabled",2);Y([w()],di.prototype,"remapMultiplier",2);Y([w(ot)],di.prototype,"remapX",2);Y([w()],di.prototype,"remapXMultiplier",2);Y([w(ot)],di.prototype,"remapY",2);Y([w()],di.prototype,"remapYMultiplier",2);Y([w(ot)],di.prototype,"remapZ",2);Y([w()],di.prototype,"remapZMultiplier",2);Y([w()],di.prototype,"scrollSpeedMultiplier",2);Y([w()],di.prototype,"separateAxes",2);Y([w()],di.prototype,"strengthMultiplier",2);Y([w(ot)],di.prototype,"strengthX",2);Y([w()],di.prototype,"strengthXMultiplier",2);Y([w(ot)],di.prototype,"strengthY",2);Y([w()],di.prototype,"strengthYMultiplier",2);Y([w(ot)],di.prototype,"strengthZ",2);Y([w()],di.prototype,"strengthZMultiplier",2);class Ui{constructor(){u(this,"enabled");u(this,"attachRibbonToTransform",!1);u(this,"colorOverLifetime");u(this,"colorOverTrail");u(this,"dieWithParticles",!0);u(this,"inheritParticleColor",!0);u(this,"lifetime");u(this,"lifetimeMultiplier");u(this,"minVertexDistance",.2);u(this,"mode",0);u(this,"ratio",1);u(this,"ribbonCount",1);u(this,"shadowBias",0);u(this,"sizeAffectsLifetime",!1);u(this,"sizeAffectsWidth",!1);u(this,"splitSubEmitterRibbons",!1);u(this,"textureMode",0);u(this,"widthOverTrail");u(this,"widthOverTrailMultiplier");u(this,"worldSpace",!1)}getWidth(e,t,i){let s=this.widthOverTrail.evaluate(i);return i===0&&(s=e),e*=s,e}getColor(e,t,i){const s=this.colorOverTrail.evaluate(i),r=this.colorOverLifetime.evaluate(t);e.x*=s.r*r.r,e.y*=s.g*r.g,e.z*=s.b*r.b,e.w*=s.alpha*r.alpha}}Y([w()],Ui.prototype,"enabled",2);Y([w()],Ui.prototype,"attachRibbonToTransform",2);Y([w(ur)],Ui.prototype,"colorOverLifetime",2);Y([w(ur)],Ui.prototype,"colorOverTrail",2);Y([w()],Ui.prototype,"dieWithParticles",2);Y([w()],Ui.prototype,"inheritParticleColor",2);Y([w(ot)],Ui.prototype,"lifetime",2);Y([w()],Ui.prototype,"lifetimeMultiplier",2);Y([w()],Ui.prototype,"minVertexDistance",2);Y([w()],Ui.prototype,"mode",2);Y([w()],Ui.prototype,"ratio",2);Y([w()],Ui.prototype,"ribbonCount",2);Y([w()],Ui.prototype,"shadowBias",2);Y([w()],Ui.prototype,"sizeAffectsLifetime",2);Y([w()],Ui.prototype,"sizeAffectsWidth",2);Y([w()],Ui.prototype,"splitSubEmitterRibbons",2);Y([w()],Ui.prototype,"textureMode",2);Y([w(ot)],Ui.prototype,"widthOverTrail",2);Y([w()],Ui.prototype,"widthOverTrailMultiplier",2);Y([w()],Ui.prototype,"worldSpace",2);class Vi{constructor(){u(this,"enabled");u(this,"space",0);u(this,"orbitalX");u(this,"orbitalY");u(this,"orbitalZ");u(this,"orbitalXMultiplier");u(this,"orbitalYMultiplier");u(this,"orbitalZMultiplier");u(this,"orbitalOffsetX");u(this,"orbitalOffsetY");u(this,"orbitalOffsetZ");u(this,"speedModifier");u(this,"speedModifierMultiplier");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier");u(this,"_system");u(this,"_temp",new S);u(this,"_temp2",new S);u(this,"_temp3",new S);u(this,"_hasOrbital",!1);u(this,"_index",0);u(this,"_orbitalMatrix",new He)}update(e){this._system=e}init(e){this._index==0&&(e.debug=!0),this._index+=1,e.orbitx=this.orbitalX.evaluate(Math.random()),e.orbity=this.orbitalY.evaluate(Math.random()),e.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=e.orbitx!=0||e.orbity!=0||e.orbitz!=0}apply(e,t,i,s,r,o,a){var p;if(!this.enabled)return;const l=o/a,c=this.speedModifier.evaluate(l)*this.speedModifierMultiplier,h=this.x.evaluate(l),d=this.y.evaluate(l),f=this.z.evaluate(l);if(this._temp.set(-h,d,f),this._system,this._hasOrbital&&((p=this._system)==null?void 0:p.worldPos)){const m=this._temp2.set(i.x,i.y,i.z),A=this.orbitalXMultiplier,v=this.orbitalYMultiplier,b=this.orbitalZMultiplier,y=c*Math.PI*2*10,_=Math.cos(y*A),C=Math.sin(y*A),E=Math.cos(y*v),T=Math.sin(y*v),x=Math.cos(y*b),M=Math.sin(y*b),P=m.x*(E*x)+m.y*(E*M)+m.z*-T,k=m.x*(C*T*x-_*M)+m.y*(C*T*M+_*x)+m.z*(C*E),G=m.x*(_*T*x+C*M)+m.y*(_*T*M-C*x)+m.z*(_*E),z=this._temp3.set(m.x-P,m.y-k,m.z-G);z.normalize(),z.multiplyScalar(.2/r*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),s.x+=z.x,s.y+=z.y,s.z+=z.z}s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z,s.x*=c,s.y*=c,s.z*=c}}Y([w()],Vi.prototype,"enabled",2);Y([w()],Vi.prototype,"space",2);Y([w(ot)],Vi.prototype,"orbitalX",2);Y([w(ot)],Vi.prototype,"orbitalY",2);Y([w(ot)],Vi.prototype,"orbitalZ",2);Y([w()],Vi.prototype,"orbitalXMultiplier",2);Y([w()],Vi.prototype,"orbitalYMultiplier",2);Y([w()],Vi.prototype,"orbitalZMultiplier",2);Y([w()],Vi.prototype,"orbitalOffsetX",2);Y([w()],Vi.prototype,"orbitalOffsetY",2);Y([w()],Vi.prototype,"orbitalOffsetZ",2);Y([w(ot)],Vi.prototype,"speedModifier",2);Y([w()],Vi.prototype,"speedModifierMultiplier",2);Y([w(ot)],Vi.prototype,"x",2);Y([w()],Vi.prototype,"xMultiplier",2);Y([w(ot)],Vi.prototype,"y",2);Y([w()],Vi.prototype,"yMultiplier",2);Y([w(ot)],Vi.prototype,"z",2);Y([w()],Vi.prototype,"zMultiplier",2);class hs{constructor(){u(this,"animation");u(this,"enabled");u(this,"cycleCount");u(this,"frameOverTime");u(this,"frameOverTimeMultiplier");u(this,"numTilesX");u(this,"numTilesY");u(this,"startFrame");u(this,"startFrameMultiplier");u(this,"rowMode");u(this,"rowIndex");u(this,"spriteCount");u(this,"timeMode")}sampleOnceAtStart(){if(this.timeMode===0)switch(this.frameOverTime.mode){case 0:case 3:case 2:case 1:return!0}return!1}getStartIndex(){return this.sampleOnceAtStart()?Math.random()*(this.numTilesX*this.numTilesY):0}evaluate(e){if(!this.sampleOnceAtStart())return this.getIndex(e)}getIndex(e){const t=this.numTilesX*this.numTilesY;e=e*this.cycleCount;let i=this.frameOverTime.evaluate(e%1);return i*=this.frameOverTimeMultiplier,i*=t,i=i%t,i=Math.floor(i),i}}Y([w()],hs.prototype,"animation",2);Y([w()],hs.prototype,"enabled",2);Y([w()],hs.prototype,"cycleCount",2);Y([w(ot)],hs.prototype,"frameOverTime",2);Y([w()],hs.prototype,"frameOverTimeMultiplier",2);Y([w()],hs.prototype,"numTilesX",2);Y([w()],hs.prototype,"numTilesY",2);Y([w(ot)],hs.prototype,"startFrame",2);Y([w()],hs.prototype,"startFrameMultiplier",2);Y([w()],hs.prototype,"rowMode",2);Y([w()],hs.prototype,"rowIndex",2);Y([w()],hs.prototype,"spriteCount",2);Y([w()],hs.prototype,"timeMode",2);class Ao{constructor(){u(this,"enabled");u(this,"separateAxes");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier")}evaluate(e,t){return this.enabled?this.separateAxes?0:this.z.evaluate(e,t)*-1:0}}Y([w()],Ao.prototype,"enabled",2);Y([w()],Ao.prototype,"separateAxes",2);Y([w(ot)],Ao.prototype,"x",2);Y([w()],Ao.prototype,"xMultiplier",2);Y([w(ot)],Ao.prototype,"y",2);Y([w()],Ao.prototype,"yMultiplier",2);Y([w(ot)],Ao.prototype,"z",2);Y([w()],Ao.prototype,"zMultiplier",2);class Or{constructor(){u(this,"enabled");u(this,"range");u(this,"separateAxes");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier")}evaluate(e,t){if(!this.enabled)return 0;if(!this.separateAxes){const i=Ze.lerp(this.range.x,this.range.y,t);return this.z.evaluate(i)*-1}return 0}}Y([w()],Or.prototype,"enabled",2);Y([w()],Or.prototype,"range",2);Y([w()],Or.prototype,"separateAxes",2);Y([w(ot)],Or.prototype,"x",2);Y([w()],Or.prototype,"xMultiplier",2);Y([w(ot)],Or.prototype,"y",2);Y([w()],Or.prototype,"yMultiplier",2);Y([w(ot)],Or.prototype,"z",2);Y([w()],Or.prototype,"zMultiplier",2);class Sn{constructor(){u(this,"enabled");u(this,"dampen");u(this,"drag");u(this,"dragMultiplier");u(this,"limit");u(this,"limitMultiplier");u(this,"separateAxes");u(this,"limitX");u(this,"limitXMultiplier");u(this,"limitY");u(this,"limitYMultiplier");u(this,"limitZ");u(this,"limitZMultiplier");u(this,"multiplyDragByParticleSize",!1);u(this,"multiplyDragByParticleVelocity",!1);u(this,"space");u(this,"_temp",new S);u(this,"_temp2",new S)}apply(e,t,i,s,r,o,a){if(this.enabled){const l=this.limit.evaluate(r)*this.limitMultiplier;if(t.length()>l){this._temp.copy(t).normalize().multiplyScalar(l);let h=this.dampen*.5;t.x=Ze.lerp(t.x,this._temp.x,h),t.y=Ze.lerp(t.y,this._temp.y,h),t.z=Ze.lerp(t.z,this._temp.z,h),i.x=Ze.lerp(i.x,this._temp.x,h),i.y=Ze.lerp(i.y,this._temp.y,h),i.z=Ze.lerp(i.z,this._temp.z,h)}}}}Y([w()],Sn.prototype,"enabled",2);Y([w()],Sn.prototype,"dampen",2);Y([w(ot)],Sn.prototype,"drag",2);Y([w()],Sn.prototype,"dragMultiplier",2);Y([w(ot)],Sn.prototype,"limit",2);Y([w()],Sn.prototype,"limitMultiplier",2);Y([w()],Sn.prototype,"separateAxes",2);Y([w(ot)],Sn.prototype,"limitX",2);Y([w()],Sn.prototype,"limitXMultiplier",2);Y([w(ot)],Sn.prototype,"limitY",2);Y([w()],Sn.prototype,"limitYMultiplier",2);Y([w(ot)],Sn.prototype,"limitZ",2);Y([w()],Sn.prototype,"limitZMultiplier",2);Y([w()],Sn.prototype,"multiplyDragByParticleSize",2);Y([w()],Sn.prototype,"multiplyDragByParticleVelocity",2);Y([w()],Sn.prototype,"space",2);class Ah{constructor(){u(this,"enabled");u(this,"curve");u(this,"curveMultiplier");u(this,"mode");u(this,"system");u(this,"_lastWorldPosition");u(this,"_velocity",new S);u(this,"_temp",new S)}update(e){this.enabled&&this.system.worldspace!==!1&&(this._lastWorldPosition?(this._velocity.copy(this.system.worldPos).sub(this._lastWorldPosition).multiplyScalar(1/this.system.deltaTime),this._lastWorldPosition.copy(this.system.worldPos)):(this._velocity.set(0,0,0),this._lastWorldPosition=this.system.worldPos.clone()))}applyInitial(e){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const t=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(t),e.add(this._temp)}}applyCurrent(e,t,i){if(this.enabled&&this.system.worldspace!==!1&&this.mode===1){const s=this.curve.evaluate(t,i);this._temp.copy(this._velocity).multiplyScalar(s),e.add(this._temp)}}}Y([w()],Ah.prototype,"enabled",2);Y([w(ot)],Ah.prototype,"curve",2);Y([w()],Ah.prototype,"curveMultiplier",2);Y([w()],Ah.prototype,"mode",2);class Ws{constructor(){u(this,"enabled");u(this,"range");u(this,"separateAxes");u(this,"size");u(this,"sizeMultiplier");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier")}evaluate(e,t,i,s){const r=e.length(),o=Ze.remap(r,this.range.x,this.range.y,0,1),a=this.size.evaluate(o,i);return s*a}}Y([w()],Ws.prototype,"enabled",2);Y([w(q)],Ws.prototype,"range",2);Y([w()],Ws.prototype,"separateAxes",2);Y([w(ot)],Ws.prototype,"size",2);Y([w()],Ws.prototype,"sizeMultiplier",2);Y([w(ot)],Ws.prototype,"x",2);Y([w()],Ws.prototype,"xMultiplier",2);Y([w(ot)],Ws.prototype,"y",2);Y([w()],Ws.prototype,"yMultiplier",2);Y([w(ot)],Ws.prototype,"z",2);Y([w()],Ws.prototype,"zMultiplier",2);class Nu{constructor(){u(this,"enabled");u(this,"range");u(this,"color")}evaluate(e,t,i){const s=e.length(),r=Ze.remap(s,this.range.x,this.range.y,0,1),o=this.color.evaluate(r,t);i.x*=o.r,i.y*=o.g,i.z*=o.b,i.w*=o.alpha}}Y([w()],Nu.prototype,"enabled",2);Y([w(q)],Nu.prototype,"range",2);Y([w(ur)],Nu.prototype,"color",2);function Jte(n){const e=n.domElement.querySelector("link[rel='ar']");if(e)return e;const t=document.createElement("div");t.classList.add("menu"),t.classList.add("quicklook-menu"),t.style.display="none",t.style.visibility="hidden";const i=document.createElement("button");i.id="open-in-ar",i.innerText="Open in QuickLook",t.appendChild(i);const s=document.createElement("a");s.id="needle-usdz-link",s.style.display="none",s.rel="ar",s.href="",t.appendChild(s);const r=document.createElement("img");return r.id="button",s.appendChild(r),n.domElement.appendChild(t),s}function Kte(){var n=new Date;const e=n.getMonth()+1,t=n.getDate(),i=n.getHours(),s=n.getMinutes(),r=n.getSeconds(),o=(e<10?"0":"")+e,a=(t<10?"0":"")+t,l=(i<10?"0":"")+i,c=(s<10?"0":"")+s,h=(r<10?"0":"")+r;return n.getFullYear()+o+a+"-"+l+c+h}const wy=le("debugusdz");function Zte(n,e){const t=[],i=$.getComponentsInChildren(n,hr);let s=!1;wy&&console.log(i);for(const r of i){if(!r||!r.runtimeAnimatorController)continue;wy&&console.log(r);const o=[];for(const a of r.runtimeAnimatorController.enumerateActions()){wy&&console.log(a);const l=a.getClip();if(!s&&l.tracks.length>0){s=!0;const c=l.tracks[0],h=c.name.substring(0,c.name.lastIndexOf(".")),d=new Pr(h+".position",[0,.01],[0,0,0,0,0,0]),f=new Pr(h+".quaternion",[0,.01],[0,0,0,1,0,0,0,1]);o.push(new uo("rest",.01,[d,f]))}o.includes(l)||o.push(l)}t.push({root:r.gameObject,clips:o})}wy&&console.log(t);for(const r of t)for(const o of r.clips)e.registerAnimation(r.root,o)}var $te=Object.defineProperty,eie=Object.getOwnPropertyDescriptor,Kl=(n,e,t,i)=>{for(var s=i>1?void 0:i?eie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&$te(e,t,s),s};const eC=le("debugtext");var Tn=(n=>(n[n.UpperLeft=0]="UpperLeft",n[n.UpperCenter=1]="UpperCenter",n[n.UpperRight=2]="UpperRight",n[n.MiddleLeft=3]="MiddleLeft",n[n.MiddleCenter=4]="MiddleCenter",n[n.MiddleRight=5]="MiddleRight",n[n.LowerLeft=6]="LowerLeft",n[n.LowerCenter=7]="LowerCenter",n[n.LowerRight=8]="LowerRight",n))(Tn||{});class qs extends Ou{constructor(){super(...arguments);u(this,"alignment",0);u(this,"verticalOverflow",0);u(this,"horizontalOverflow",0);u(this,"lineSpacing",1);u(this,"supportRichText",!1);u(this,"font");u(this,"fontStyle",0);u(this,"_text","");u(this,"_fontSize",12);u(this,"_textMeshUi",null);u(this,"_didHandleTextRenderOnTop",!1)}setAlphaFactor(t){var i;super.setAlphaFactor(t),(i=this.uiObject)==null||i.set({fontOpacity:this.color.alpha*this.alphaFactor}),this.markDirty()}get text(){return this._text}set text(t){t!==this._text&&(this._text=t,this.feedText(this.text,this.supportRichText),this.markDirty())}set_text(t){this.text=t}get fontSize(){return this._fontSize}set fontSize(t){var i;this._fontSize=t,(i=this.uiObject)==null||i.set({fontSize:t})}onColorChanged(){var t;(t=this.uiObject)==null||t.set({color:this.color,fontOpacity:this.color.alpha})}onParentRectTransformChanged(){super.onParentRectTransformChanged(),this.uiObject&&this.updateOverflow()}onBeforeRender(){this.uiObject&&this.Root.screenspace&&this.updateOverflow()}updateOverflow(){var i;const t=(i=this.uiObject)==null?void 0:i._overflow;t&&(t._needsUpdate=!0,this.markDirty())}onCreate(t){eC&&console.log(this),this.horizontalOverflow==1&&(t.whiteSpace="pre"),this.verticalOverflow==0&&(this.context.renderer.localClippingEnabled=!0,t.overflow="hidden"),this.horizontalOverflow==1&&this.verticalOverflow==0,t.lineHeight=this.lineSpacing,delete t.backgroundOpacity,delete t.backgroundColor,eC&&(t.backgroundColor=16750848,t.backgroundOpacity=.5);const i=this.rectTransform;t={...t,...this.getTextOpts()},this.getAlignment(t),eC&&(t.backgroundColor=Math.random()*16777215,t.backgroundOpacity=.1),this.uiObject=i.createNewText(t),this.feedText(this.text,this.supportRichText)}onAfterAddedToScene(){super.onAfterAddedToScene(),this.handleTextRenderOnTop()}getTextOpts(){let t=this.fontSize;const i={color:this.color,fontOpacity:this.color.alpha,fontSize:t,fontKerning:"normal"};return this.setFont(i,this.fontStyle),i}onEnable(){super.onEnable(),this._didHandleTextRenderOnTop=!1,this.uiObject&&this.uiObject.addAfterUpdate(()=>{this.setShadowComponentOwner(this.uiObject),this.markDirty()}),setTimeout(()=>this.markDirty(),10)}getAlignment(t){switch(t.flexDirection="column",this.alignment){case 0:case 3:case 6:t.textAlign="left";break;case 1:case 4:case 7:t.textAlign="center";break;case 2:case 5:case 8:t.textAlign="right";break}switch(this.alignment){default:case 0:case 1:case 2:t.alignItems="start";break;case 3:case 4:case 5:t.alignItems="center";break;case 6:case 7:case 8:t.alignItems="end";break}return t}feedText(t,i){var s,r,o;if(!this.uiObject)return null;if(this._textMeshUi||(this._textMeshUi=[]),!i||t.length===0)this.uiObject.textContent=t;else{let a=this.getNextTag(t);if(a)a.startIndex>0&&this.uiObject.add(new d0({textContent:t.substring(0,a.startIndex),color:"inherit"}));else return this.uiObject.textContent=t;const l=[];for(;a;){const c=this.getNextTag(t,a.endIndex),h={fontFamily:(s=this.uiObject)==null?void 0:s.get("fontFamily"),color:"inherit",textContent:""};c?(h.textContent=this.getText(t,a,c),this.handleTag(a,h,l),(r=this.uiObject)==null||r.add(new d0(h))):(h.textContent=t.substring(a.endIndex),this.handleTag(a,h,l),(o=this.uiObject)==null||o.add(new d0(h))),a=c}}return null}handleTextRenderOnTop(){this._didHandleTextRenderOnTop||(this._didHandleTextRenderOnTop=!0,this.startCoroutine(this.renderOnTopCoroutine()))}*renderOnTopCoroutine(){if(!this.canvas)return;const t=[],i=this.canvas,s={renderOnTop:i.renderOnTop,depthWrite:i.depthWrite,doubleSided:i.doubleSided};for(;;){let r=!1;if(this._textMeshUi)for(let o=0;o<this._textMeshUi.length;o++){if(t[o]===!0)continue;r=!0;const a=this._textMeshUi[o];a.textContent&&(p_(a,s),t[o]=!0)}if(!r)break;yield}}handleTag(t,i,s){if(t.isEndTag){if(s.length>0){const r=s.pop();if(r)for(const o in r.previousValues){const a=r.previousValues[o];i[o]=a}}}else if(t.type.includes("color")){const r=new tC(t,{color:i.color});if(s.push(r),t.type.length>6){const o=parseInt("0x"+t.type.substring(7));i.color=o}else i.color=new _e(1,1,1)}else if(t.type=="b"){this.setFont(i,1);const r=new tC(t,{fontWeight:700});s.push(r)}else if(t.type=="i"){this.setFont(i,2);const r=new tC(t,{fontStyle:"italic"});s.push(r)}}getText(t,i,s){return t.substring(i.endIndex,s.startIndex)}getNextTag(t,i=0){const s=t.indexOf("<",i),r=t.indexOf(">",s);if(s>=0&&r>=0){const o=t.substring(s+1,r);return{type:o,startIndex:s,endIndex:r+1,isEndTag:o.startsWith("/")}}return null}setFont(t,i){if(!this.font)return;let s=this.font,r=nE.getFontFamily(s);r||(r=nE.addFontFamily(s)),t.fontFamily=r;const o=s.toLowerCase();switch(i){default:case 0:t.fontWeight=400,t.fontStyle="normal";break;case 1:t.fontWeight=700,t.fontStyle="normal",o.includes("-bold")||(s+="-bold");break;case 2:t.fontWeight=400,t.fontStyle="italic",o.includes("-italic")||(s+="-italic");break;case 3:t.fontStyle="italic",t.fontWeight=400,o.includes("-bold")||(s+="-bold"),o.includes("-italic")||(s+="-italic")}let a=r.getVariant(t.fontWeight,t.fontStyle);if(!a){let l=s;l!=null&&l.endsWith("-msdf.json")||(l+="-msdf.json");let c=s;c!=null&&c.endsWith(".png")||(c+=".png"),a=r.addVariant(t.fontWeight,t.fontStyle,l,c),a==null||a.addEventListener("ready",()=>{this.markDirty()})}}}Kl([w()],qs.prototype,"alignment",2);Kl([w()],qs.prototype,"verticalOverflow",2);Kl([w()],qs.prototype,"horizontalOverflow",2);Kl([w()],qs.prototype,"lineSpacing",2);Kl([w()],qs.prototype,"supportRichText",2);Kl([w(URL)],qs.prototype,"font",2);Kl([w()],qs.prototype,"fontStyle",2);Kl([w()],qs.prototype,"text",1);Kl([w()],qs.prototype,"fontSize",1);class tC{constructor(e,t){u(this,"tag");u(this,"previousValues");this.tag=e,this.previousValues=t}}class Oc{constructor(e){u(this,"id");u(this,"content","");u(this,"font",[]);u(this,"pointSize",144);u(this,"width");u(this,"height");u(this,"depth");u(this,"wrapMode");u(this,"horizontalAlignment");u(this,"verticalAlignment");u(this,"material");this.id=e}static getId(){return this.global_id++}setDepth(e){return this.depth=e,this}setPointSize(e){return this.pointSize=e,this}setHorizontalAlignment(e){return this.horizontalAlignment=e,this}setVerticalAlignment(e){return this.verticalAlignment=e,this}writeTo(e,t){var s;t.beginBlock(`def Preliminary_Text "${this.id}"`),this.content&&t.appendLine(`string content = "${this.content}"`),(!this.font||this.font.length<=0)&&(this.font||(this.font=[]),(s=this.font)==null||s.push("sans-serif"));const i=this.font.map(r=>`"${r}"`).join(", ");t.appendLine(`string[] font = [ ${i} ]`),t.appendLine(`double pointSize = ${this.pointSize}`),typeof this.width=="number"&&t.appendLine(`double width = ${this.width}`),typeof this.height=="number"&&t.appendLine(`double height = ${this.height}`),typeof this.depth=="number"&&t.appendLine(`double depth = ${this.depth}`),this.wrapMode&&t.appendLine(`token wrapMode = "${this.wrapMode}"`),this.horizontalAlignment&&t.appendLine(`token horizontalAlignment = "${this.horizontalAlignment}"`),this.verticalAlignment&&t.appendLine(`token verticalAlignment = "${this.verticalAlignment}"`),this.material!==void 0&&t.appendLine(`rel material:binding = </Materials/Material_${this.material.id}>`),t.closeBlock()}}u(Oc,"global_id",0);class Zb{static singleLine(e,t,i){const s=new Oc("text_"+Oc.getId());return s.content=e,t&&(s.pointSize=t),i&&(s.depth=i),s}static multiLine(e,t,i,s,r,o){const a=new Oc("text_"+Oc.getId());return a.content=e,a.width=t,a.height=i,a.horizontalAlignment=s,a.verticalAlignment=r,o!==void 0&&(a.wrapMode=o),a}}const tie=new He().makeRotationY(Math.PI);class $b{get extensionName(){return"text"}onExportObject(e,t,i){const s=$.getComponent(e,qs);if(s){const r=$.getComponent(e,xs);let o=100,a=100;r&&(o=r.width,a=r.height);const l=t.clone();l.matrix=tie.clone();const c=new _e().copySRGBToLinear(s.color);l.material=new Cu({color:c,emissive:c}),t.add(l),l.addEventListener("serialize",(h,d)=>{const f=Zb.multiLine(s.text,o,a,"center","bottom","flowing");this.setTextAlignment(f,s.alignment),this.setOverflow(f,s),l.material&&(f.material=l.material),f.pointSize=this.convertToTextSize(s.fontSize),f.depth=.001,f.writeTo(void 0,h)})}}convertToTextSize(e){return 1/.0502*144*e}setOverflow(e,t){t.horizontalOverflow?e.wrapMode="singleLine":e.wrapMode="flowing"}setTextAlignment(e,t){switch(t){case Tn.LowerLeft:case Tn.MiddleLeft:case Tn.UpperLeft:e.horizontalAlignment="left";break;case Tn.LowerCenter:case Tn.MiddleCenter:case Tn.UpperCenter:e.horizontalAlignment="center";break;case Tn.LowerRight:case Tn.MiddleRight:case Tn.UpperRight:e.horizontalAlignment="right";break}switch(t){case Tn.LowerLeft:case Tn.LowerCenter:case Tn.LowerRight:e.verticalAlignment="bottom";break;case Tn.MiddleLeft:case Tn.MiddleCenter:case Tn.MiddleRight:e.verticalAlignment="middle";break;case Tn.UpperLeft:case Tn.UpperCenter:case Tn.UpperRight:e.verticalAlignment="top";break}}}var iie=Object.defineProperty,nie=Object.getOwnPropertyDescriptor,vo=(n,e,t,i)=>{for(var s=i>1?void 0:i?nie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&iie(e,t,s),s};const ia=le("debugusdz");class vh{constructor(){u(this,"callToAction");u(this,"checkoutTitle");u(this,"checkoutSubtitle");u(this,"callToActionURL")}}vo([w()],vh.prototype,"callToAction",2);vo([w()],vh.prototype,"checkoutTitle",2);vo([w()],vh.prototype,"checkoutSubtitle",2);vo([w()],vh.prototype,"callToActionURL",2);class yo extends Ce{constructor(){super(...arguments);u(this,"objectToExport");u(this,"autoExportAnimations",!1);u(this,"exportFileName");u(this,"customUsdzFile");u(this,"customBranding");u(this,"anchoringType","plane");u(this,"planeAnchoringAlignment","horizontal");u(this,"interactive",!0);u(this,"extensions",[]);u(this,"link");u(this,"webxr");u(this,"webARSessionRoot");u(this,"lastCallback");u(this,"_quicklookButton");u(this,"_quicklookButtonContainer",null)}start(){var t,i,s,r;ia&&(console.log(this),console.log("Debug USDZ, press 't' to export"),window.addEventListener("keydown",o=>{switch(o.key){case"t":this.exportAsync();break}}),xu()&&setTimeout(()=>{this.exportAsync()},2e3)),(t=document.getElementById("open-in-ar"))==null||t.addEventListener("click",o=>{o.preventDefault(),this.exportAsync()}),this.objectToExport||(this.objectToExport=this.gameObject),!((s=(i=this.objectToExport)==null?void 0:i.children)!=null&&s.length)&&!((r=this.objectToExport)!=null&&r.isMesh)&&(this.objectToExport=this.context.scene),this.interactive&&(this.extensions.push(new qb),this.extensions.push(new jb),this.extensions.push(new $b))}onEnable(){const t=nm(),i=dl();(ia||t&&i)&&(this.addQuicklookButton(),this.webARSessionRoot=$.findObjectOfType(ch)??void 0,this.lastCallback=this.quicklookCallback.bind(this),this.link=Jte(this.context),this.link.addEventListener("message",this.lastCallback)),ia&&jn("USDZ Exporter enabled: "+this.name)}onDisable(){var s;(s=this.link)==null||s.removeEventListener("message",this.lastCallback);const t=nm(),i=dl();(ia||t&&i)&&this.removeQuicklookButton(),ia&&jn("USDZ Exporter disabled: "+this.name)}async exportAsync(){var p;let t=this.exportFileName??((p=this.objectToExport)==null?void 0:p.name)??this.name;if(Gc()||(t+="-MadeWithNeedle"),t+="-"+Kte(),this.customUsdzFile){const g=this.buildQuicklookOverlay();ia&&console.log(g);const m=g.callToAction?encodeURIComponent(g.callToAction):"",A=g.checkoutTitle?encodeURIComponent(g.checkoutTitle):"",v=g.checkoutSubtitle?encodeURIComponent(g.checkoutSubtitle):"";this.link.href=this.customUsdzFile+`#callToAction=${m}&checkoutTitle=${A}&checkoutSubtitle=${v}&callToActionURL=${g.callToActionURL}`,console.log(this.link.href),this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=t+".usdz",this.link.click();return}if(!this.objectToExport)return;if(this.webARSessionRoot){const g=this.webARSessionRoot.gameObject,m=1/this.webARSessionRoot.arScale;g.matrix.makeScale(m,m,m),this.webARSessionRoot.invertForward&&g.matrix.multiply(new He().makeRotationY(Math.PI))}const i=new gY,s=[...this.extensions],r=new Mb;s.push(r),this.autoExportAnimations&&Zte(this.objectToExport,r);const o={self:this,exporter:i,extensions:s,object:this.objectToExport};this.dispatchEvent(new CustomEvent("before-export",{detail:o})),i.debug=ia,this.anchoringType!=="plane"&&this.anchoringType!=="none"&&this.anchoringType!=="image"&&this.anchoringType!=="face"&&(this.anchoringType="plane"),this.planeAnchoringAlignment!=="horizontal"&&this.planeAnchoringAlignment!=="vertical"&&this.planeAnchoringAlignment!=="any"&&(this.planeAnchoringAlignment="horizontal");const a=await i.parse(this.objectToExport,{ar:{anchoring:{type:this.anchoringType},planeAnchoring:{alignment:this.planeAnchoringAlignment}},extensions:s,quickLookCompatible:!0}),l=new Blob([a],{type:"application/octet-stream"});this.dispatchEvent(new CustomEvent("after-export",{detail:o}));const c=this.buildQuicklookOverlay();ia&&console.log(c);const h=c.callToAction?encodeURIComponent(c.callToAction):"",d=c.checkoutTitle?encodeURIComponent(c.checkoutTitle):"",f=c.checkoutSubtitle?encodeURIComponent(c.checkoutSubtitle):"";this.link.href=URL.createObjectURL(l)+`#callToAction=${h}&checkoutTitle=${d}&checkoutSubtitle=${f}&callToActionURL=${c.callToActionURL}`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=t+".usdz",this.link.click()}quicklookCallback(t){if((t==null?void 0:t.data)=="_apple_ar_quicklook_button_tapped"){ia&&Wo("Quicklook closed via call to action button");var i=new CustomEvent("quicklook-button-tapped",{detail:this});if(this.dispatchEvent(i),!i.defaultPrevented){const s=new URLSearchParams(this.link.href);if(s){const r=s.get("callToActionURL");ia&&jn("Quicklook url: "+r),r&&(Gc()?globalThis.open(r,"_blank"):console.warn("Quicklook closed: custom redirects require a Needle Engine Pro license: https://needle.tools/pricing",r))}}}}buildQuicklookOverlay(){var i,s,r;const t={};return this.customBranding&&Object.assign(t,this.customBranding),Gc()||(console.log("Custom Quicklook banner text requires pro license: https://needle.tools/pricing"),t.callToAction="Close",t.checkoutTitle="🌵 Made with Needle",t.checkoutSubtitle="_"),(i=t.callToAction)!=null&&i.length||(t.callToAction="Close"),(s=t.checkoutTitle)!=null&&s.length||(t.checkoutTitle="🌵 Made with Needle"),(r=t.checkoutSubtitle)!=null&&r.length||(t.checkoutSubtitle="_"),this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:t})),t}async createQuicklookButton(){var t,i;if(!this.webxr)if(await jm(1),this.webxr=$.findObjectOfType(Ct)??void 0,this.webxr)if(this.webxr.VRButton&&((t=this.webxr.VRButton.parentElement)==null||t.removeChild(this.webxr.VRButton)),this.webxr.ARButton&&this._quicklookButton!==this.webxr.ARButton){this._quicklookButton=this.webxr.ARButton;const s=(i=this.webxr.ARButton.parentElement)==null?void 0:i.querySelector("a");s&&(s.href=""),this.webxr.ARButton.innerText="Open in Quicklook",this.webxr.ARButton.disabled=!1,this.webxr.ARButton.addEventListener("click",r=>{r.preventDefault(),this.exportAsync()}),this.webxr.ARButton.classList.add("quicklook-ar-button"),this._quicklookButtonContainer=this.webxr.ARButton.parentElement,this.dispatchEvent(new CustomEvent("created-button",{detail:this.webxr.ARButton}))}else{this.webxr.createARButton=!1,this.webxr.createVRButton=!1;let s=window.document.querySelector(".webxr-buttons");s||(s=document.createElement("div"),s.classList.add("webxr-buttons"));const r=document.createElement("button");r.innerText="Open in Quicklook",r.addEventListener("click",()=>{this.exportAsync()}),r.classList.add("webxr-ar-button"),r.classList.add("webxr-button"),r.classList.add("quicklook-ar-button"),s.appendChild(r),this._quicklookButtonContainer=s,this.dispatchEvent(new CustomEvent("created-button",{detail:r}))}else console.warn("Could not find WebXR component: will not create Quicklook button",_t.Current)}async addQuicklookButton(){await this.createQuicklookButton(),this._quicklookButton&&this._quicklookButtonContainer&&this._quicklookButtonContainer.appendChild(this._quicklookButton)}removeQuicklookButton(){var t;(t=this._quicklookButton)==null||t.remove()}}vo([w(Ie)],yo.prototype,"objectToExport",2);vo([w()],yo.prototype,"autoExportAnimations",2);vo([w()],yo.prototype,"exportFileName",2);vo([w(URL)],yo.prototype,"customUsdzFile",2);vo([w(vh)],yo.prototype,"customBranding",2);vo([w()],yo.prototype,"anchoringType",2);vo([w()],yo.prototype,"planeAnchoringAlignment",2);vo([w()],yo.prototype,"interactive",2);const HB=le("debugdeletable");class ex extends eo{}class dM extends Ce{constructor(){super(...arguments);u(this,"deleteBoxes",[])}awake(){this.deleteBoxes=$.findObjectsOfType(ex,this.context)}update(){for(const t of this.deleteBoxes){const i=this.gameObject;if(t.isInBox(i)===!0){const r=$.getComponentInParent(this.gameObject,op);r?HB&&console.warn("Can not delete object with usage marker",this.guid,r):(HB&&console.log("DESTROY",this.gameObject),fb(this.gameObject,this.context.connection))}}}}var sie=Object.defineProperty,rie=Object.getOwnPropertyDescriptor,zu=(n,e,t,i)=>{for(var s=i>1?void 0:i?rie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&sie(e,t,s),s};class Ko extends js{constructor(){super(...arguments);u(this,"mode");u(this,"focusDistance");u(this,"focalLength");u(this,"aperture");u(this,"gaussianMaxRadius");u(this,"resolutionScale");u(this,"bokehScale")}get typeName(){return"DepthOfField"}init(){this.focalLength.valueProcessor=i=>{const s=i/300,r=2;return Ze.lerp(r,.01,s)};const t=20;this.aperture.valueProcessor=i=>{const s=1-i/32;return Ze.lerp(1,t,s)}}onCreateEffect(){if(this.mode===0)return;const t=1/window.devicePixelRatio;if(this.resolutionScale===void 0){let s=1;xu()&&(s=.6),this.resolutionScale=new Ft(s*t)}const i=new iF(this.context.mainCamera,{worldFocusRange:.2,focalLength:1,bokehScale:20,resolutionScale:this.resolutionScale.value});return this.focusDistance.onValueChanged=s=>{i.circleOfConfusionMaterial.worldFocusDistance=s},this.focalLength.onValueChanged=s=>i.circleOfConfusionMaterial.worldFocusRange=s,this.aperture.onValueChanged=s=>i.bokehScale=s,this.resolutionScale&&(this.resolutionScale.onValueChanged=s=>i.resolution.scale=s),[i]}unapply(){}}zu([w()],Ko.prototype,"mode",2);zu([w(Ft)],Ko.prototype,"focusDistance",2);zu([w(Ft)],Ko.prototype,"focalLength",2);zu([w(Ft)],Ko.prototype,"aperture",2);zu([w(Ft)],Ko.prototype,"gaussianMaxRadius",2);zu([w(Ft)],Ko.prototype,"resolutionScale",2);zu([w(Ft)],Ko.prototype,"bokehScale",2);Na("DepthOfField",Ko);var oie=Object.defineProperty,aie=Object.getOwnPropertyDescriptor,lie=(n,e,t,i)=>{for(var s=i>1?void 0:i?aie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&oie(e,t,s),s};class tx extends Ce{constructor(){super(...arguments);u(this,"visibleOn")}onEnable(){this.apply()}apply(){this.test()||$.setActive(this.gameObject,!1)}test(){return this.visibleOn<0?!0:cie()?(this.visibleOn&2)!==0:(this.visibleOn&1)!==0}}lie([w()],tx.prototype,"visibleOn",2);let Cy;function cie(){if(Cy===!0||Cy===!1)return Cy;let n=!1;return function(e){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0,4)))&&(n=!0)}(navigator.userAgent||navigator.vendor||window.opera),Cy=n,n}class fM{get extensionName(){return"DocumentExtension"}onAfterBuildDocument(e){}}var MN=(n=>(n.SelectStart="selectstart",n.SelectEnd="selectend",n))(MN||{});const al=class extends rp{constructor(){super();u(this,"transformSelf",!0);u(this,"orbit",null);u(this,"selectStartEventListener",[]);u(this,"selectEndEventListener",[]);u(this,"_dragHelper",null);u(this,"_draggingRigidbodies",[]);u(this,"_waitingForDragStart",null);u(this,"_isDragging",!1);u(this,"_marker",null);u(this,"_dragDelta");u(this,"_didDrag",!1);u(this,"_activePointerId");this.selectStartEventListener=[],this.selectEndEventListener=[],this._dragDelta=new q}static get HasAnySelected(){return this._active>0}addDragEventListener(t,i){switch(t){case"selectstart":this.selectStartEventListener.push(i);break;case"selectend":this.selectEndEventListener.push(i);break}}start(){this.orbit=$.findObjectOfType(ql,this.context)}allowEdit(t=null){return this.context.connection.allowEditing}onPointerEnter(t){if(!this.allowEdit(this.gameObject)||Ct.IsInWebXR)return;const i=$.getComponentInParent(t.object,al);!i||i!==this||(al.lastHovered=t.object,this.context.domElement.style.cursor="pointer")}onPointerExit(t){this.allowEdit(this.gameObject)&&(Ct.IsInWebXR||al.lastHovered===t.object&&(this.context.domElement.style.cursor="auto"))}onPointerDown(t){this.allowEdit(this.gameObject)&&(Ct.IsInWebXR||(al._active+=1,this._dragDelta.set(0,0),this._didDrag=!1,this._waitingForDragStart=t,t.StopPropagation(),this.orbit&&(this.orbit.enabled=!1)))}onPointerUp(t){this._waitingForDragStart=null,this.allowEdit(this.gameObject)&&(al._active>0&&(al._active-=1),!Ct.IsInWebXR&&(this.onDragEnd(t),t.StopPropagation(),this.orbit&&(this.orbit.enabled=!0)))}update(){var t;if(!Ct.IsInWebXR){if(this._waitingForDragStart){if(!this._didDrag){const s=this.context.input.getPointerPositionDelta(0);if(s&&this._dragDelta.add(s),this._dragDelta.length()>2)this._didDrag=!0;else return}const i=this._waitingForDragStart;this._waitingForDragStart=null,this.onDragStart(i)}this._dragHelper&&this._dragHelper.hasSelected&&this.onUpdateDrag(),(((t=this._dragHelper)==null?void 0:t.hasSelected)===!1||this._activePointerId!==void 0&&this.context.input.getPointerPressed(this._activePointerId)===!1)&&this.onDragEnd(null)}}onDragStart(t){if(!this._dragHelper)if(this.context.mainCamera)this._dragHelper=new A0(this.context.mainCamera);else return;if(!t||!t.object)return;const i=$.getComponentInParent(t.object,al);if(!i||i!==this)return;let s=t.object;this.transformSelf&&(s=this.gameObject);const r={selected:s,attached:s};for(const c of this.selectStartEventListener)c(this,r);if(this._activePointerId=t.pointerId,!r.attached)return;r.attached,s=r.attached,this._isDragging=!0,this._dragHelper.setSelected(s,this.context),this.orbit&&(this.orbit.enabled=!1);const o=$.getComponentInChildren(s,Jc);o&&(o.fastMode=!0,o==null||o.requestOwnership()),this._marker=$.addNewComponent(s,op),this._draggingRigidbodies.length=0;const a=$.getComponentsInChildren(s,Hi);a&&this._draggingRigidbodies.push(...a);const l=I0();$.invokeOnChildren(this._dragHelper.selected,l("onDragStart"))}onUpdateDrag(){if(this._dragHelper){this._dragHelper.onUpdate(this.context);for(const t of this._draggingRigidbodies)t.wakeUp(),t.resetVelocities()}}onDragEnd(t){if(!this||!this._isDragging||(this._isDragging=!1,!this._dragHelper))return;for(const r of this._draggingRigidbodies)r.setVelocity(r.smoothedVelocity);this._draggingRigidbodies.length=0;const i=this._dragHelper.selected;if(this._dragHelper.setSelected(null,this.context),this.orbit&&(this.orbit.enabled=!0),t!=null&&t.object){const r=$.getComponentInChildren(t.object,Jc);r&&(r.fastMode=!1)}this._marker&&this._marker.destroy();for(const r of this.selectEndEventListener)r(this);const s=I0();$.invokeOnChildren(i,s("onDragEnd"))}};let Lc=al;u(Lc,"_active",0),u(Lc,"lastHovered");const $M=class{constructor(e){u(this,"_selected",null);u(this,"_context",null);u(this,"_camera");u(this,"_cameraPlane",new Zr);u(this,"_hasGroundPlane",!1);u(this,"_groundPlane",new Zr);u(this,"_groundOffset",new S);u(this,"_groundOffsetFactor",0);u(this,"_groundDistance",0);u(this,"_groundPlanePoint",new S);u(this,"_raycaster",new zf);u(this,"_cameraPlaneOffset",new S);u(this,"_intersection",new S);u(this,"_worldPosition",new S);u(this,"_inverseMatrix",new He);u(this,"_rbs",[]);u(this,"_groundLine");u(this,"_groundMarker");u(this,"_groundOffsetVector",new S(0,1,0));u(this,"_requireUpdateGroundPlane",!0);u(this,"_didDragOnGroundPlaneLastFrame",!1);this._camera=e;const t=new rn($M.geometry),i=t.material;i.color=new _e(.4,.4,.4),t.layers.set(2),t.name="line",t.scale.y=1,this._groundLine=t;const s=new po(.5,22,22),r=new vi({color:i.color}),o=new ve(s,r);o.visible=!1,o.layers.set(2),this._groundMarker=o}get hasSelected(){return this._selected!==null&&this._selected!==void 0}get selected(){return this._selected}setSelected(e,t){if(this._selected&&t)for(const i of this._rbs)i.wakeUp(),i.setVelocity(0,0,0);if(this._selected&&Ns.Remove(t,this._selected),this._selected=e,this._context=t,this._rbs.length=0,e?(t.scene.add(this._groundLine),t.scene.add(this._groundMarker)):(this._groundLine.removeFromParent(),this._groundMarker.removeFromParent()),this._selected){if(!t){console.error("DragHelper: no context");return}Ns.Add(t,this._selected,null),this._groundOffsetFactor=0,this._hasGroundPlane=!0,this._groundOffset.set(0,0,0),this._requireUpdateGroundPlane=!0,this.onUpdateScreenSpacePlane()}}onUpdate(e){var a,l,c,h,d;if(!this._context)return;const t="Space",i="KeyD",s=((a=this._context)==null?void 0:a.input.isKeyPressed(t))||((l=this._context)==null?void 0:l.input.isKeyPressed(i)),r=this._context.input.getTouchesPressedCount()>=2||s;if(r){const f=this._context.input.getPointerPositionDelta(0);f&&(this._groundOffsetVector.set(0,1,0),(c=this._selected)==null||c.rotateOnWorldAxis(this._groundOffsetVector,f.x*this._context.time.deltaTime))}const o=this._context.input.getPointerPositionRC(0);if(o&&(this._raycaster.setFromCamera(o,this._camera),this._selected)){this._groundOffsetVector.set(0,1,0);const f=wt(this._camera).clone().sub(wt(this._selected)).normalize(),p=Math.abs(f.dot(this._groundOffsetVector)),g=((h=this._context)==null?void 0:h.input.isKeyPressed(t))||((d=this._context)==null?void 0:d.input.isKeyPressed(i)),m=!r&&p>.2&&!g&&this._context.input.getPointerPressedCount()<=1,A=this._didDragOnGroundPlaneLastFrame!==m;if(this._didDragOnGroundPlaneLastFrame=m,this._hasGroundPlane||(this._requireUpdateGroundPlane=!0),(this._requireUpdateGroundPlane||!m||A)&&this.onUpdateGroundPlane(),this._requireUpdateGroundPlane=!1,this._hasGroundPlane)if(this._raycaster.ray.intersectPlane(this._groundPlane,this._intersection)){const v=this._intersection.y;if(this._groundPlanePoint.copy(this._intersection).sub(this._groundOffset),this._groundPlanePoint.y=v,m){this._groundOffsetVector.set(0,1,0);const b=this._intersection.sub(this._groundOffset).add(this._groundOffsetVector.multiplyScalar(this._groundOffsetFactor));this.onUpdateWorldPosition(b,this._groundPlanePoint,!1),this.onDidUpdate();return}}else this._groundPlanePoint.set(0,99999,0);A&&this.onUpdateScreenSpacePlane(),this._requireUpdateGroundPlane=!0,this._raycaster.ray.intersectPlane(this._cameraPlane,this._intersection)&&(this.onUpdateWorldPosition(this._intersection.sub(this._cameraPlaneOffset),this._groundPlanePoint,!0),this.onDidUpdate())}}onUpdateWorldPosition(e,t,i){if(this._selected){if(i){const s=wt(this._selected);s.y=e.y,e=s}if(ln(this._selected,e),ln(this._groundLine,e),this._hasGroundPlane?this._groundLine.scale.y=this._groundDistance:this._groundLine.scale.y=1e3,this._groundMarker.visible=t!==null,t){const s=wt(this._camera).distanceTo(t)*.01;this._groundMarker.scale.set(s,s,s),ln(this._groundMarker,t)}}}onUpdateScreenSpacePlane(){if(!this._selected||!this._context)return;const e=this._context.input.getPointerPositionRC(0);e&&(this._raycaster.setFromCamera(e,this._camera),this._cameraPlane.setFromNormalAndCoplanarPoint(this._camera.getWorldDirection(this._cameraPlane.normal),this._worldPosition.setFromMatrixPosition(this._selected.matrixWorld)),this._raycaster.ray.intersectPlane(this._cameraPlane,this._intersection)&&this._selected.parent&&(this._inverseMatrix.copy(this._selected.parent.matrixWorld).invert(),this._cameraPlaneOffset.copy(this._intersection).sub(this._worldPosition.setFromMatrixPosition(this._selected.matrixWorld))))}onUpdateGroundPlane(){if(!this._selected||!this._context)return;const e=wt(this._selected),t=new Gl(new S(0,.1,0).add(e),new S(0,-1,0)),i=new qo;i.ignore=[this._selected];const s=this._context.physics.raycastFromRay(t,i);for(let r=0;r<s.length;r++){const o=s[r];if(!o.face||this.contains(this._selected,o.object))continue;const a=new S(0,1,0);this._groundPlane.setFromNormalAndCoplanarPoint(a,o.point);break}this._hasGroundPlane=!0,this._groundPlane.setFromNormalAndCoplanarPoint(t.direction.multiplyScalar(-1),t.origin),this._raycaster.ray.intersectPlane(this._groundPlane,this._intersection),this._groundDistance=this._intersection.distanceTo(e),this._groundOffset.copy(this._intersection).sub(e)}onDidUpdate(){rr.markDirty(this._selected);for(const e of this._rbs)e.wakeUp(),e.resetForcesAndTorques(),e.setAngularVelocity(0,0,0)}contains(e,t){if(e===t)return!0;if(e.children){for(const i of e.children)if(this.contains(i,t))return!0}return!1}};let A0=$M;u(A0,"geometry",new vt().setFromPoints([new S(0,0,0),new S(0,-1,0)]));function pM(n,e,t){console.warn("Adding components on object has been temporarily disabled")}var TN=(n=>(n.File_Spawned="file-spawned",n))(TN||{});class PN{constructor(e,t,i,s,r,o,a,l){u(this,"guid");u(this,"file_name");u(this,"file_hash");u(this,"file_size");u(this,"position");u(this,"seed");u(this,"sender");u(this,"serverUrl");u(this,"parentGuid");u(this,"boundsSize");this.seed=t,this.guid=i,this.file_name=s,this.file_hash=r,this.file_size=o,this.position=a,this.sender=e,this.serverUrl=l}}async function aE(n,e,t){const i=n.name;return i.endsWith(".gltf")||i.endsWith(".glb")?new Promise((s,r)=>{const o=new FileReader;o.readAsArrayBuffer(n),o.onloadend=async a=>{const l=o.result,c=pb(),h=new Us(c),d=await Qo().parseSync(e,l,n.name,h);if(d&&d.scene){const f=d.scene;if(!f.guid){const p=new Us(c);f.guid=p.generateUUID()}t&&hie(e.connection,n,c,f,t),pM(),s(d)}}}):(console.warn("Unsupported file type: "+i),console.log(n),null)}async function RN(n,e){return new Promise(async(t,i)=>{const s=pb(),r=new Us(s),o=n.toString(),a=await Qo().loadSync(e,o,o,r);a&&a.scene?(a.scene,pM(),t(a)):console.warn("Unsupported file type: "+n.toString())})}sn.registerCallback(to.ContextCreated,n=>{BN(n.context)});function BN(n){n.connection.beginListen("file-spawned",async e=>{if(e.sender!==n.connection.connectionId){console.log("received file event",e),uie(e,n);let t=null;try{t=await Q1(e.file_name,e.file_hash,e.file_size,e.serverUrl)}finally{die(e)}if(t){const i=new Us(e.seed),s=await Qo().parseSync(n,t,null,i);if(s&&s.scene){const r=s.scene;if(pM(),e.parentGuid){const o=mA(e.parentGuid,n.scene);"add"in o&&o.add(r)}r.parent||n.scene.add(r),e.position!==null&&r.position.copy(e.position)}}else console.error("download didnt return file")}})}async function hie(n,e,t,i,s){if(!n.connectionId){console.error("Can not upload file - no connection id");return}if(!i.guid){console.error("Can not upload file - no guid",i,i.guid);return}const r=await fF(e,s);if(!r)return;if(!r.filename){console.error("Can not send upload event - no filename",e.name);return}if(!r.hash){console.error("Can not send upload event - no hash",e.name);return}const o=new PN(n.connectionId,t,i.guid,r.filename,r.hash,e.size,i.position,r.url??s);i.parent&&(o.parentGuid=i.parent.guid),n.send("file-spawned",o)}const lE={};function uie(n,e){const t=new gi,i=new ve(t,new vi({color:65280})),s=new eb(i,5592405);if(lE[n.guid]=s,e.scene.add(s),n.parentGuid){const r=mA(n.parentGuid,e.scene);r&&r.add(s)}n.position&&s.position.copy(n.position)}function die(n,e){const t=n.guid,i=lE[t];i&&(delete lE[t],i.removeFromParent())}var fie=Object.defineProperty,pie=Object.getOwnPropertyDescriptor,gM=(n,e,t,i)=>{for(var s=i>1?void 0:i?pie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&fie(e,t,s),s};const gie=le("debugnet"),cE=class extends Ce{constructor(){super(...arguments);u(this,"url",null);u(this,"urlParameterName",null);u(this,"localhost",null)}awake(){gie&&console.log(this),this.context.connection.registerProvider(this)}getWebsocketUrl(){let e=this.url?cE.GetUrl(this.url,this.localhost):null;if(this.urlParameterName){const r=le(this.urlParameterName);r&&typeof r=="string"&&(e=r)}if(!e)return null;const i=new RegExp("(((https?)|(?<socket_prefix>wss?))://)?(www.)?(?<url>.+)","gm").exec(e);return i!=null&&i.groups?(i==null?void 0:i.groups.socket_prefix)?e:"wss://"+(i==null?void 0:i.groups.url):null}static GetUrl(e,t){let i=e;const s=cE.IsLocalNetwork()&&t;return s&&(i=t),e!=null&&e.startsWith("/")&&(i=(s?i:window.location.origin)+e),i}static IsLocalNetwork(e=window.location.hostname){return zs(e)}};let Gu=cE;gM([w()],Gu.prototype,"url",2);gM([w()],Gu.prototype,"urlParameterName",2);gM([w()],Gu.prototype,"localhost",2);var mie=Object.defineProperty,Aie=Object.getOwnPropertyDescriptor,DN=(n,e,t,i)=>{for(var s=i>1?void 0:i?Aie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&mie(e,t,s),s};class qA extends Ce{constructor(){super(...arguments);u(this,"filesBackendUrl");u(this,"localhost");u(this,"_dragOver");u(this,"_drop")}onEnable(){this.filesBackendUrl=this.filesBackendUrl?Gu.GetUrl(this.filesBackendUrl,this.localhost):void 0,this._dragOver=this.onDrag.bind(this),this._drop=this.onDrop.bind(this),this.context.domElement.addEventListener("dragover",this._dragOver),this.context.domElement.addEventListener("drop",this._drop)}onDisable(){this.context.domElement.removeEventListener("dragover",this._dragOver),this.context.domElement.removeEventListener("drop",this._drop)}onDrag(t){t.preventDefault()}async addFiles(t){for(const i of t){if(!i)continue;console.log("Register file "+i.name+" to",this.filesBackendUrl,i);const s=await aE(i,this.context,this.filesBackendUrl);this.dispatchEvent(new CustomEvent("file-dropped",{detail:i})),s&&this.addObject(void 0,s)}}async onDrop(t){if(console.log(t),!t.dataTransfer)return;t.preventDefault();const i=t.dataTransfer.items;if(i)for(const s in i){const r=i[s];if(r.kind==="file"){const o=r.getAsFile();if(!o)continue;console.log("Register file "+o.name+" to",this.filesBackendUrl,o);const a=await aE(o,this.context,this.filesBackendUrl);this.dispatchEvent(new CustomEvent("file-dropped",{detail:o})),a&&this.addObject(t,a)}else r.kind==="string"&&r.type=="text/plain"&&r.getAsString(async o=>{console.log("dropped url",o);try{const a=new URL(o);if(!a)return;const l=await RN(a,this.context);l&&this.addObject(t,l)}catch{console.log("dropped string is not a valid URL!",o)}})}}async addObject(t,i){console.log("Dropped",i);const s=i.scene;if(t!==void 0){const r=new qo;r.setMask(16777215),r.screenPointFromOffset(t.offsetX,t.offsetY);const o=this.context.physics.raycast(r);if(o&&o.length>0)for(const a of o){s.position.copy(a.point);break}}this.gameObject.add(s),this.dispatchEvent(new CustomEvent("object-added",{detail:i}))}}DN([w()],qA.prototype,"filesBackendUrl",2);DN([w()],qA.prototype,"localhost",2);var vie=Object.defineProperty,yie=Object.getOwnPropertyDescriptor,ix=(n,e,t,i)=>{for(var s=i>1?void 0:i?yie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&vie(e,t,s),s};class Qu extends rp{constructor(){super(...arguments);u(this,"parent",null);u(this,"object",null);u(this,"limitCount",10);u(this,"limitInterval",60);u(this,"_currentCount",0);u(this,"_startPosition",null);u(this,"_startQuaternion",null)}awake(){var i,s;if(this.object){if(this.object===this.gameObject){console.error("Can not duplicate self");return}this.object.visible=!1,this._startPosition=((i=this.object.position)==null?void 0:i.clone())??new S(0,0,0),this._startQuaternion=((s=this.object.quaternion)==null?void 0:s.clone())??new xe(0,0,0,1)}const t=$.getComponentInParent(this.gameObject,Lc);t?t.addDragEventListener(MN.SelectStart,(r,o)=>{if(this._currentCount>=this.limitCount){o.attached=null;return}const a=this.handleDuplication(o.selected);a&&(console.assert(a!==o.selected,"Duplicated object is original"),o.attached=a)}):console.warn("Could no find drag controls in parent",this.name),Yi.addEventListener(hl.SelectStart,(r,o)=>{if(this._currentCount>=this.limitCount){o.grab=null;return}const a=this.handleDuplication(o.selected);a&&(o.grab=a)}),this.cloneLimitIntervalFn()}cloneLimitIntervalFn(){this.destroyed||(this._currentCount>0&&(this._currentCount-=1),setTimeout(()=>{this.cloneLimitIntervalFn()},this.limitInterval/this.limitCount*1e3))}handleDuplication(t){var i;if(this._currentCount>=this.limitCount||!this.object)return null;if(t===this.gameObject||this.handleMultiObject(t)){if(this.object===this.gameObject)return null;this.object.visible=!0,this._startPosition&&this.object.position.copy(this._startPosition),this._startQuaternion&&this.object.quaternion.copy(this._startQuaternion);const s=new Pa;this.parent||(this.parent=this.gameObject.parent),this.parent&&(s.parent=this.parent.guid??((i=this.parent.userData)==null?void 0:i.guid),s.keepWorldPosition=!0),s.position=this.worldPosition,s.rotation=this.worldQuaternion,s.context=this.context,this._currentCount+=1;const r=$.instantiateSynced(this.object,s);return console.assert(r!==this.object,"Duplicated object is original"),this.object.visible=!1,this._startPosition&&this.object.position.clone().copy(this._startPosition),this._startQuaternion&&this.object.quaternion.clone().copy(this._startQuaternion),r}return null}handleMultiObject(t){return this.gameObject.type==="Group"||this.gameObject.type==="Object3D"?this.isInChildren(this.gameObject,t):!1}isInChildren(t,i){if(!t)return!1;if(t===i)return!0;if(t.children){for(let s of t.children)if(this.isInChildren(s,i))return!0}return!1}}ix([w(Ie)],Qu.prototype,"parent",2);ix([w(Ie)],Qu.prototype,"object",2);ix([w()],Qu.prototype,"limitCount",2);ix([w()],Qu.prototype,"limitInterval",2);var kd=(n=>(n[n.PointerEnter=0]="PointerEnter",n[n.PointerExit=1]="PointerExit",n[n.PointerDown=2]="PointerDown",n[n.PointerUp=3]="PointerUp",n[n.PointerClick=4]="PointerClick",n[n.Drag=5]="Drag",n[n.Drop=6]="Drop",n[n.Scroll=7]="Scroll",n[n.UpdateSelected=8]="UpdateSelected",n[n.Select=9]="Select",n[n.Deselect=10]="Deselect",n[n.Move=11]="Move",n[n.InitializePotentialDrag=12]="InitializePotentialDrag",n[n.BeginDrag=13]="BeginDrag",n[n.EndDrag=14]="EndDrag",n[n.Submit=15]="Submit",n[n.Cancel=16]="Cancel",n))(kd||{}),_ie=Object.defineProperty,bie=Object.getOwnPropertyDescriptor,mM=(n,e,t,i)=>{for(var s=i>1?void 0:i?bie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&_ie(e,t,s),s};class AM{constructor(){u(this,"eventID");u(this,"callback")}}mM([w()],AM.prototype,"eventID",2);mM([w(ar)],AM.prototype,"callback",2);class nx extends Ce{constructor(){super(...arguments);u(this,"triggers")}invoke(t){if(this.triggers)for(const i of this.triggers)i.eventID===t&&i.callback.invoke()}onPointerClick(t){this.invoke(kd.PointerClick)}onPointerEnter(t){this.invoke(kd.PointerEnter)}onPointerExit(t){this.invoke(kd.PointerExit)}onPointerDown(t){this.invoke(kd.PointerDown)}onPointerUp(t){this.invoke(kd.PointerUp)}}mM([w(AM)],nx.prototype,"triggers",2);var xie=Object.defineProperty,wie=Object.getOwnPropertyDescriptor,vM=(n,e,t,i)=>{for(var s=i>1?void 0:i?wie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&xie(e,t,s),s};class yM extends Ce{constructor(){super(...arguments);u(this,"connectedBody");u(this,"_rigidBody",null)}get rigidBody(){return this._rigidBody}onEnable(){this._rigidBody||(this._rigidBody=this.gameObject.getComponent(Hi)),this.rigidBody&&this.connectedBody&&this.startCoroutine(this.create())}*create(){yield,this.rigidBody&&this.connectedBody&&this.createJoint(this.rigidBody,this.connectedBody)}}vM([w(Hi)],yM.prototype,"connectedBody",2);class _M extends yM{createJoint(e,t){var i;(i=this.context.physics.engine)==null||i.addFixedJoint(e,t)}}class XA extends yM{constructor(){super(...arguments);u(this,"anchor");u(this,"axis")}createJoint(t,i){var s;this.axis&&this.anchor&&((s=this.context.physics.engine)==null||s.addHingeJoint(t,i,this.anchor,this.axis))}}vM([w(S)],XA.prototype,"anchor",2);vM([w(S)],XA.prototype,"axis",2);const Cie={type:"change"};let Sie=class extends Ln{constructor(e,t){super(),this.object=e,this.domElement=t,this.movementSpeed=1,this.rollSpeed=.005,this.dragToLook=!1,this.autoForward=!1;const i=this,s=1e-6,r=new xe,o=new S;this.tmpQuaternion=new xe,this.status=0,this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0},this.moveVector=new S(0,0,0),this.rotationVector=new S(0,0,0),this.keydown=function(f){if(!f.altKey){switch(f.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=.1;break;case"KeyW":this.moveState.forward=1;break;case"KeyS":this.moveState.back=1;break;case"KeyA":this.moveState.left=1;break;case"KeyD":this.moveState.right=1;break;case"KeyR":this.moveState.up=1;break;case"KeyF":this.moveState.down=1;break;case"ArrowUp":this.moveState.pitchUp=1;break;case"ArrowDown":this.moveState.pitchDown=1;break;case"ArrowLeft":this.moveState.yawLeft=1;break;case"ArrowRight":this.moveState.yawRight=1;break;case"KeyQ":this.moveState.rollLeft=1;break;case"KeyE":this.moveState.rollRight=1;break}this.updateMovementVector(),this.updateRotationVector()}},this.keyup=function(f){switch(f.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=1;break;case"KeyW":this.moveState.forward=0;break;case"KeyS":this.moveState.back=0;break;case"KeyA":this.moveState.left=0;break;case"KeyD":this.moveState.right=0;break;case"KeyR":this.moveState.up=0;break;case"KeyF":this.moveState.down=0;break;case"ArrowUp":this.moveState.pitchUp=0;break;case"ArrowDown":this.moveState.pitchDown=0;break;case"ArrowLeft":this.moveState.yawLeft=0;break;case"ArrowRight":this.moveState.yawRight=0;break;case"KeyQ":this.moveState.rollLeft=0;break;case"KeyE":this.moveState.rollRight=0;break}this.updateMovementVector(),this.updateRotationVector()},this.pointerdown=function(f){if(this.dragToLook)this.status++;else{switch(f.button){case 0:this.moveState.forward=1;break;case 2:this.moveState.back=1;break}this.updateMovementVector()}},this.pointermove=function(f){if(!this.dragToLook||this.status>0){const p=this.getContainerDimensions(),g=p.size[0]/2,m=p.size[1]/2;this.moveState.yawLeft=-(f.pageX-p.offset[0]-g)/g,this.moveState.pitchDown=(f.pageY-p.offset[1]-m)/m,this.updateRotationVector()}},this.pointerup=function(f){if(this.dragToLook)this.status--,this.moveState.yawLeft=this.moveState.pitchDown=0;else{switch(f.button){case 0:this.moveState.forward=0;break;case 2:this.moveState.back=0;break}this.updateMovementVector()}this.updateRotationVector()},this.update=function(f){const p=f*i.movementSpeed,g=f*i.rollSpeed;i.object.translateX(i.moveVector.x*p),i.object.translateY(i.moveVector.y*p),i.object.translateZ(i.moveVector.z*p),i.tmpQuaternion.set(i.rotationVector.x*g,i.rotationVector.y*g,i.rotationVector.z*g,1).normalize(),i.object.quaternion.multiply(i.tmpQuaternion),(o.distanceToSquared(i.object.position)>s||8*(1-r.dot(i.object.quaternion))>s)&&(i.dispatchEvent(Cie),r.copy(i.object.quaternion),o.copy(i.object.position))},this.updateMovementVector=function(){const f=this.moveState.forward||this.autoForward&&!this.moveState.back?1:0;this.moveVector.x=-this.moveState.left+this.moveState.right,this.moveVector.y=-this.moveState.down+this.moveState.up,this.moveVector.z=-f+this.moveState.back},this.updateRotationVector=function(){this.rotationVector.x=-this.moveState.pitchDown+this.moveState.pitchUp,this.rotationVector.y=-this.moveState.yawRight+this.moveState.yawLeft,this.rotationVector.z=-this.moveState.rollRight+this.moveState.rollLeft},this.getContainerDimensions=function(){return this.domElement!=document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}},this.dispose=function(){this.domElement.removeEventListener("contextmenu",VB),this.domElement.removeEventListener("pointerdown",l),this.domElement.removeEventListener("pointermove",a),this.domElement.removeEventListener("pointerup",c),window.removeEventListener("keydown",h),window.removeEventListener("keyup",d)};const a=this.pointermove.bind(this),l=this.pointerdown.bind(this),c=this.pointerup.bind(this),h=this.keydown.bind(this),d=this.keyup.bind(this);this.domElement.addEventListener("contextmenu",VB),this.domElement.addEventListener("pointerdown",l),this.domElement.addEventListener("pointermove",a),this.domElement.addEventListener("pointerup",c),window.addEventListener("keydown",h),window.addEventListener("keyup",d),this.updateMovementVector(),this.updateRotationVector()}};function VB(n){n.preventDefault()}class bM extends Ce{constructor(){super(...arguments);u(this,"_controls",null)}onEnable(){var i;const t=(i=$.getComponent(this.gameObject,Oi))==null?void 0:i.cam;this._controls=new Sie(t,this.context.renderer.domElement),this._controls.rollSpeed=.5,this._controls.movementSpeed=3,this._controls.dragToLook=!0}onDisable(){var t;(t=this._controls)==null||t.dispose(),this._controls=null}update(){this._controls&&this._controls.update(this.context.time.deltaTime)}}var Eie=Object.defineProperty,Iie=Object.getOwnPropertyDescriptor,xM=(n,e,t,i)=>{for(var s=i>1?void 0:i?Iie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Eie(e,t,s),s};class wp extends Ce{constructor(){super(...arguments);u(this,"_fog")}get fog(){return this._fog||(this._fog=new XE(0,0,50)),this._fog}get mode(){return 1}set near(t){this.fog.near=t}get near(){return this.fog.near}set far(t){this.fog.far=t}get far(){return this.fog.far}set color(t){this.fog.color.copy(t)}get color(){return this.fog.color}onEnable(){this.scene.fog=this.fog}onDisable(){this.scene.fog===this._fog&&(this.scene.fog=null)}}xM([w()],wp.prototype,"near",1);xM([w()],wp.prototype,"far",1);xM([w(_e)],wp.prototype,"color",1);let iC,nC,_d,Sy;function sC(n,e,t){nC||(nC=new Jn(2,2,1,1)),_d||(_d=new Xt({uniforms:{blitTexture:new be(n)},vertexShader:`
|
|
4561
|
+
`&&n.length>1&&sN([t],n[n.length-2]),e.offsetX}function z$(n){if(!n[0])return 0;let e=[],t;for(let i=0;i<n.length;i++){const s=n[i];if(s.char&&kB[s.char]&&n.length>i){e.push(s),t=n[i+1];continue}break}rN(e,t),e=[],t=null;for(let i=n.length-1;i>0;i--){const s=n[i];if(s.char&&kB[s.char]&&i>0){e.push(s),t=n[i-1];continue}break}return sN(e,t),n[0].offsetX}function G$(n){return n[0]?n[0].offsetX:0}function sN(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX+e.cumulativeWidth,i.cumulativeWidth=0}}function rN(n,e){if(e)for(let t=0;t<n.length;t++){const i=n[t];i.fontFactor=0,i.offsetX=e.offsetX,i.cumulativeWidth=0}}function oN(n,e,t,i){if(i=i||0,!n[e])return i;const s=n[e];return s.lineBreak?i+s.xadvance:oN(n,e+1,t,i+s.xadvance+s.xoffset+s.kerning+t.LETTERSPACING)}function Q$(n,e,t,i){return!n||!n.char||e+t<i.INNER_WIDTH?!1:i.BREAKON.indexOf(n.char)>-1}class aN extends dU{constructor(){super(),this._input="inherit",this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._fontSize._needsProcess=!0,e._layouter._needsProcess=!0}}class lN extends Li{constructor(){super("fontSize","inherit",!0),this._allowsInherit=!1}computeOutputValue(e){this._value=this._inheritedInput,e._font._fontVariant&&(e._bounds._needsProcess=!0,e._layouter._needsProcess=!0)}process(e){if(!e._font._fontVariant||!e._font._fontVariant.isReady)return;const t=this._value/e._font._fontVariant.typographic.size,i=e._inlines._value;for(let s=0;s<i.length;s++){const r=i[s];r.resetOffsets(),r.fontSize=this._value,r.fontFactor=t}}get value(){return this._value}}class cN extends fU{constructor(){super("segments",1,!1),this._notInheritedValue=void 0}update(e,t){this._notInheritedValue=this._value,this._notInheritedValue==="inherit"&&(this._notInheritedValue=this.getInheritedInput(e)),e._layouter._needsUpdate=!0}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}get value(){return this._value==="inherit"?this._notInheritedValue:this._value}}class H$ extends cN{constructor(){super(),this._value="inherit"}}class V$ extends Ob{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e),e._parent._value._layouter._needsProcess=!1}process(e){if(this._value!=="none"){const t=e._whiteSpace._whiteSpacedContent,i=e._inlines._value;for(let s=1;s<i.length;s++){const r=t[s-1]+t[s];i[s].kerning=e._font._fontVariant.getKerningAmount(r)}}}}class hN extends ui{constructor(){super("children",null,!1),this._uis=[]}update(e,t){}process(e){}_compute(e){}dispose(){}}function j$(n,e=!1){const t=n[0].index!==null,i=new Set(Object.keys(n[0].attributes)),s=new Set(Object.keys(n[0].morphAttributes)),r={},o={},a=n[0].morphTargetsRelative,l=new Ke.BufferGeometry;let c=0;for(let h=0;h<n.length;++h){const d=n[h];let f=0;if(t!==(d.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const p in d.attributes){if(!i.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+'. All geometries must have compatible attributes; make sure "'+p+'" attribute exists among all geometries, or in none of them.'),null;r[p]===void 0&&(r[p]=[]),r[p].push(d.attributes[p]),f++}if(f!==i.size)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". Make sure all geometries have the same number of attributes."),null;if(a!==d.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const p in d.morphAttributes){if(!s.has(p))return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". .morphAttributes must be consistent throughout all geometries."),null;o[p]===void 0&&(o[p]=[]),o[p].push(d.morphAttributes[p])}if(l.userData.mergedUserData=l.userData.mergedUserData||[],l.userData.mergedUserData.push(d.userData),e){let p;if(t)p=d.index.count;else if(d.attributes.position!==void 0)p=d.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed with geometry at index "+h+". The geometry must have either an index or a position attribute"),null;l.addGroup(c,p,h),c+=p}}if(t){let h=0;const d=[];for(let f=0;f<n.length;++f){const p=n[f].index;for(let g=0;g<p.count;++g)d.push(p.getX(g)+h);h+=n[f].attributes.position.count}l.setIndex(d)}for(const h in r){const d=OB(r[h]);if(!d)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+h+" attribute."),null;l.setAttribute(h,d)}for(const h in o){const d=o[h][0].length;if(d===0)break;l.morphAttributes=l.morphAttributes||{},l.morphAttributes[h]=[];for(let f=0;f<d;++f){const p=[];for(let m=0;m<o[h].length;++m)p.push(o[h][m][f]);const g=OB(p);if(!g)return console.error("THREE.BufferGeometryUtils: .mergeBufferGeometries() failed while trying to merge the "+h+" morphAttribute."),null;l.morphAttributes[h].push(g)}}return l}function OB(n){let e,t,i,s=0;for(let a=0;a<n.length;++a){const l=n[a];if(l.isInterleavedBufferAttribute)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. InterleavedBufferAttributes are not supported."),null;if(e===void 0&&(e=l.array.constructor),e!==l.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(t===void 0&&(t=l.itemSize),t!==l.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(i===void 0&&(i=l.normalized),i!==l.normalized)return console.error("THREE.BufferGeometryUtils: .mergeBufferAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;s+=l.array.length}const r=new e(s);let o=0;for(let a=0;a<n.length;++a)r.set(n[a].array,o),o+=n[a].array.length;return new Ke.BufferAttribute(r,t,i)}class W$ extends ui{constructor(){super("renderer")}render(e){if(!e._inlines._value||!e._inlines._value.length)return;const t=e._inlines._value.map(s=>e._font._fontVariant.getGeometricGlyph(s,e).translate(s.offsetX,s.offsetY,0)),i=j$(t);e.setFontMesh(new Ke.Mesh(i,e.fontMaterial)),e._fontMesh.renderOrder=1/0}}class q$ extends _I{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!1}computeOutputValue(e){this._value=this._inheritedInput,e._layouter._needsProcess=!0}}class If extends RA{constructor(t={}){const i={};If.definePropertiesValues(i,t);super(i,t);u(this,"_rebuildParentUI",()=>{super._rebuildParentUI(),this._layouter._needsUpdate=!0});If.init(this)}add(t){const i=[];for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(i.push(r),r.position.z=.005):console.warn("Block element can only contain Box elements.",r)}return super.add(...i)}set textContent(t){this._textContent.value=t}get textContent(){return this._textContent._value}set invertAlpha(t){this._invertAlpha.value=t}get invertAlpha(){return this._invertAlpha._value}static definePropertiesValues(t,i){t.children||(t.children=hN),t.textContent||(t.textContent=I$),t.glyphs||(t.glyphs=T$),t.inlines||(t.inlines=M$),t.layouter||(t.layouter=$U),t.renderer||(t.renderer=W$),t.fontFamily||(t.fontFamily=iN),t.fontWeight||(t.fontWeight=tN),t.fontStyle||(t.fontStyle=eN),t.fontSize||(t.fontSize=lN),t.color||(t.color=P$),t.backgroundColor||(t.backgroundColor=R$),t.lineBreak||(t.lineBreak=ZU),t.letterSpacing||(t.letterSpacing=aN),t.whiteSpace||(t.whiteSpace=jI),t.segments||(t.segments=H$),t.textAlign||(t.textAlign=q$),t.fontKerning||(t.fontKerning=V$)}static init(t){Object.defineProperties(t,{isInline:{configurable:!1,enumerable:!0,value:!0}})}}class X$ extends eU{constructor(){super("textContent",null,!1),this._needsUpdate=!1}set value(e){this._value!==e&&(this._value=e,this._needsUpdate=!0)}update(e,t){this._needsUpdate=!1;for(let i=e.children.length-1;i>=0;i--){const s=e.children[i];s.isUI&&(e.remove(s),s.clear())}e._children._uis=[],this._value&&e.add(new If({name:"anonymousInline",textContent:this._value}))}}class Y$ extends Array{constructor(...e){super(...e),this.width=0,this.height=0}}class J$ extends ui{constructor(){super("layouter",null,!1),this._value=null}update(e,t){}process(e){let t=e._width._value;e._width._auto?t=1/0:t=e._bounds._innerWidth;const i=e._lineHeight._value,s=new Y$(new DB);let r=0;e._children._inlines.forEach(d=>{if(!d._inlines.value)return;this._resetInlines(d);const f=d._fontSize._value,p=d._letterSpacing._value*f,g=d._whiteSpace._value,m=d._lineBreak._value,A={WHITESPACE:g,LETTERSPACING:p,BREAKON:m,INNER_WIDTH:t},v=d._whiteSpace._inlineWrapper;r+=d._margin._value.w+d._padding._value.w,d._inlines.value.forEach((b,y,_)=>{const C=s[s.length-1];if(v(_,y,r,A)){if(s.push(new DB(b)),b.offsetX=b.xoffset,b.width===0){r=0;return}b.cumulativeWidth=b.xadvance+p,r=b.cumulativeWidth;return}s[s.length-1].push(b),b.offsetX=r+b.xoffset+b.kerning,b.cumulativeWidth=b.xadvance+b.kerning+p,r+=b.cumulativeWidth,C.length-1===1&&C[C.length-2].width===0&&(b.offsetX-=b.xoffset,r-=b.xoffset)}),r+=d._margin._value.y+d._padding._value.y});const o=e._whiteSpace._inlineCollapser;let a=0,l=0,c=0;s.forEach((d,f)=>{const p=o(d);let g=0,m=0;if(d.forEach(A=>{g=Math.max(g,A.lineHeight),m=Math.max(m,A.lineBase),A.offsetX-=p}),d.lineHeight=g,d.lineBase=m,f===0?c=-(g*i-g)*.5:c-=s[f-1].lineHeight*i,d.y=c,d.x=0,d.forEach(A=>{A.offsetY=c-A.anchor,A.lineHeight<d.lineHeight&&(A.offsetY-=d.lineBase-A.lineBase)}),l+=d.lineHeight*i,d.width=0,d[0]){const A=d[d.length-1];d.width=A.offsetX+A.cumulativeWidth+A.paddingRight+A.marginRight+d[0].offsetX,a=Math.max(a,d.width)}}),s.height=l,s.width=a,this._value=s,t===1/0&&e._bounds.setChildrenWidth(e,s.width),e._height._auto&&e._bounds.setChildrenHeight(e,s.height);const h=e._parent._value;h&&(h._autoSize._needsProcess=!0,h._flexDirection._needsProcess=!0),e._inlineJustificator._needsProcess=!0,e._textAlign._needsProcess=!0,e._overflow._needsUpdate=!0}_resetInlines(e){e._fontSize.process(e)}}class K$ extends _I{constructor(){super(),this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput,this._needsProcess=!0}process(e){Z$(e),e._renderer._needsRender=!0}}function Z$(n){const e=n._layouter._value,t=n._textAlign._value,i=n._bounds._innerWidth;for(let s=0;s<e.length;s++){const r=e[s],o=$$(n,r,s===e.length-1),a=n._padding._value,l=n._borderWidth._value,c=(-a.w+a.y)/2+(-l.w+l.y)/2;r.x+=o;for(let h=0;h<r.length;h++)r[h].offsetX+=o-c}if(t.indexOf("justify")===0)for(let s=0;s<e.length;s++){const r=e[s];if(t.indexOf("-")!==-1&&s===e.length-1)return;const o=i-r.width;if(o<=0)return;let a=0;for(let d=1;d<r.length-1;d++)a+=r[d].char===" "?1:0;const l=o/a;let c=1;t==="justify-right"&&(r.reverse(),c=-1);let h=0;for(let d=1;d<=r.length-1;d++){const f=r[d];f.offsetX+=h*c,h+=f.char===" "?l:0}t==="justify-right"&&r.reverse()}}function $$(n,e,t){switch(n._textAlign._value){case"justify-left":case"justify":case"left":return-n._bounds._innerWidth/2;case"justify-right":case"right":return-e.width+n._bounds._innerWidth/2;case"center":return-e.width/2;case"justify-center":return t?-e.width/2:-n._bounds._innerWidth/2;default:console.warn(`textAlign: '${n._textAlign._value}' is not valid`)}}class eee extends bI{constructor(){super(),this._value=this._input="column",this._allowsInherit=!1,this._needsUpdate=!0}computeOutputValue(e){this._value=this._inheritedInput}}class tee extends hU{constructor(){super(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}}class iee extends Ob{constructor(){super(),this._value=this._input=this.getDefaultValue(),this._allowsInherit=!1,this.computeOutputValue=this._computeFromInherited}_computeFromInherited(e){super._computeFromInherited(e)}}class nee extends YU{constructor(){super(),this._innerWidth=1/0,this._innerHeight=0}}class see extends ui{constructor(){super("children",null,!1);u(this,"_sortOrder",(t,i)=>t._order._value<i._order._value?-1:t._order._value>i._order._value?1:this._uis.indexOf(t)<this._uis.indexOf(i)?-1:1);this._uis=[],this._inlines=[],this._boxes=[]}update(t,i){this._compute(t),this._needsProcess=!0}process(t){this._compute(t),t._overflow._needsRender=!0}_compute(t){this._uis=t.children.filter(i=>i.visible&&i.isUI),this._inlines=this._uis.filter(i=>i.isInline).sort(this._sortOrder)}dispose(){this._inlines=null}}class ree extends ui{constructor(){super("autosize")}process(e){if(e._layouter._value&&e._layouter._value.length){const t=e._layouter._value,i=e._padding._value,s=e._borderWidth._value;e._width._auto&&e._bounds.setOffsetWidth(e,t.width+i.w+i.y+s.w+s.y),e._height._auto&&e._bounds.setOffsetHeight(e,t.height+i.x+i.z+s.x+s.z)}}}class oee extends KU{constructor(){super("renderer"),this._needsUpdate=!1}render(e){super.render(e);for(const t of e._children._inlines)t._renderer.render(t);e.performAfterUpdate()}}class Bm extends Pm{constructor(e={},t={}){Bm.definePropertiesValues(t,e),super(t,e),Bm.init(this)}add(e){const t=[];let i=!1;for(let s=0;s<arguments.length;s++){const r=arguments[s];!r.isUI||r.isInline?(r.isInline&&(i=!0),t.push(r)):console.warn("Block element can only contain Box elements.",r)}return t.length>0&&super.add(...t),i&&(this._children._needsUpdate=!0,this._layouter._needsProcess=!0),this}set textContent(e){this._textContent.value=e}get textContent(){return super.textContent}set invertAlpha(e){this._invertAlpha.value=e}get invertAlpha(){return this._invertAlpha._value}get lines(){return this._layouter._value}static definePropertiesValues(e,t){e.flexDirection=eee,e.justifyContent=xI,e.alignItems=yI,e.bounds=nee,e.autoSize=ree,e.renderer=oee,e.children||(e.children=see),e.textContent||(e.textContent=X$),e.layouter||(e.layouter=J$),e.lineHeight||(e.lineHeight=tee),e.textAlign||(e.textAlign=K$),e.whiteSpace||(e.whiteSpace=jI),e.fontKerning||(e.fontKerning=iee),e.segments||(e.segments=cN),t.width||(t.width="100%"),t.fontSide||(t.fontSide=0)}static init(e){Object.defineProperties(e,{isText:{configurable:!1,enumerable:!0,value:!0}})}}class aee extends ui{constructor(){super("inlines",null,!1),this._value=[]}process(e){this._value[0].paddingLeft=e._padding._value.w,this._value[0].marginLeft=e._margin._value.w;const t=this._value.length-1;this._value[t].paddingRight=e._padding._value.y,this._value[t].marginRight=e._margin._value.y}}class lee extends ui{constructor(){super("renderer")}render(e){e._backgroundMesh||e.setBackgroundMesh(new JU(e)),e._backgroundMesh.position.x=e._inlines._value[0].offsetX+e._inlines._value[0].width/2,e._backgroundMesh.position.y=e._inlines._value[0].offsetY+e._inlines._value[0].lineBase/2,e._bounds.render(e)}}class cee extends ui{constructor(){super("bounds",null,!1),this._size=new Ke.Vector3(1,1,1),this._offsetWidth=0,this._offsetHeight=0,this._innerWidth=0,this._innerHeight=0}update(e,t){this.output(t),this._needsProcess=!0}process(e){this._offsetWidth=this._innerWidth=e._inlines._value[0].width,this._offsetHeight=this._innerHeight=e._inlines._value[0].height,this._needsRender=!0,e._borderWidth._needsRender=!0,e._borderRadius._needsRender=!0}render(e){this._size.x=this._offsetWidth,this._size.y=this._offsetHeight}output(e){e.size=this._size}}class Dm extends RA{constructor(e={}){const t={};Dm.definePropertiesValues(t,e),super(t,e),Dm.init(this)}clear(){for(const e of this._inlines._value)e.clear();return super.clear()}bindBackgroundMeshProperties(){this._backgroundMesh.raycast=()=>{},this._bounds._size=this._backgroundMesh.scale,this._bounds._needsUpdate=!0}unbindBackgroundMeshProperties(){this._bounds._size=new Ke.Vector3(1,1,1),this._bounds._needsUpdate=!0}add(e){const t=[];for(let i=0;i<arguments.length;i++){const s=arguments[i];s.isUI?console.warn("ThreeMeshUI::InlineBlockElement cannot contains UI Elements.",s):(t.push(s),s.position.z=.005)}return super.add(...t)}static definePropertiesValues(e,t){e.children||(e.children=hN),e.bounds||(e.bounds=cee),e.inlines||(e.inlines=aee),e.layouter||(e.layouter=$U),e.renderer||(e.renderer=lee),e.fontFamily||(e.fontFamily=iN),e.fontWeight||(e.fontWeight=tN),e.fontStyle||(e.fontStyle=eN),e.fontSize||(e.fontSize=lN),e.backgroundColor||(e.backgroundColor=K3),e.lineBreak||(e.lineBreak=ZU),e.letterSpacing||(e.letterSpacing=aN),e.whiteSpace||(e.whiteSpace=jI),e.fontKerning||(e.fontKerning=Ob),t.backgroundSize||(t.backgroundSize="cover"),t.width||(t.width="100%"),t.height||(t.height="100%"),t.boxSizing||(t.boxSizing="border-box")}static init(e){Object.defineProperties(e,{isInline:{configurable:!1,enumerable:!0,value:!0},isInlineBlock:{configurable:!1,enumerable:!0,value:!0}}),e._inlines._value=[new hee(e)],e.backgroundMaterial=new XU,e._renderer.render(e)}}class hee extends rU{constructor(e){super(),this._uiElement=e}get xadvance(){const e=this._uiElement._padding._value,t=this._uiElement._width;return t._relative?t._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.w+e.y+t.value}get width(){const e=this._uiElement._width;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get height(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get anchor(){return this.height}get lineHeight(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}get lineBase(){const e=this._uiElement._height;return e._relative?e._value*this._uiElement._fontSize.getInheritedInput(this._uiElement):e.value}clear(){this._uiElement=null}}class uN{constructor(e){this._subject=e}attach(){console.error(`Behavior::attach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}act(){throw new Error(`Behavior::act() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}detach(){console.error(`Behavior::detach() - Is abstract and therefore should be overridden in ${this.constructor.name}`)}clear(){}}const dN=()=>u_.update(),fN={BaseProperty:ui,Block:Rm,Text:Bm,Inline:If,InlineBlock:Dm,MeshUIBaseElement:RA,FontLibrary:yu,update:dN,MSDFFontMaterialUtils:Jr,ShaderChunkUI:qU,Behavior:uN,FontVariant:IA};typeof global<"u"&&(global.ThreeMeshUI=fN);const uee=fN;var dee=wn.w8,pN=wn.cg,WI=wn.gO,fee=wn.wb,nE=wn.zV,pee=wn.HS,gee=wn.Ec,d0=wn.gF,mee=wn.ol,Aee=wn.pz,vee=wn.tx,yee=wn.hj,_ee=wn.FV,bee=wn.sV,gN=wn.xv,xee=wn.mx,wee=wn.gE,Cee=wn.ZP,mN=wn.Vx;const LB=Object.freeze(Object.defineProperty({__proto__:null,BaseProperty:dee,Behavior:pN,Block:WI,DefaultValues:fee,FontLibrary:nE,FontVariant:pee,InheritableProperty:gee,Inline:d0,InlineBlock:mee,InlineGlyph:Aee,MSDFFontMaterialUtils:vee,MaterialTransformers:yee,MeshUIBaseElement:_ee,ShaderChunkUI:bee,Text:gN,TypographicFont:xee,TypographicGlyph:wee,default:Cee,update:mN},Symbol.toStringTag,{value:"Module"}));WI.prototype.interactable={get(){return this.interactive},set(n){this.interactable=n}};const vl=Symbol("shadowDomOwner");class Ho extends Ce{constructor(){super(...arguments);u(this,"shadowComponent",null);u(this,"_controlsChildLayout",!0);u(this,"_root");u(this,"_parentComponent")}isRoot(){var t;return((t=this.Root)==null?void 0:t.gameObject)===this.gameObject}get canvas(){const t=this.Root;return t!=null&&t.isCanvas?t:null}markDirty(){sr.markUIDirty(this.context)}get controlsChildLayout(){return this._controlsChildLayout}set controlsChildLayout(t){this._controlsChildLayout=t,this.shadowComponent&&(this.shadowComponent.autoLayout=t)}get Root(){return this._root===void 0&&(this._root=$.getComponentInParent(this.gameObject,BA)),this._root}get Canvas(){return this.canvas}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this.shadowComponent=null,this._root=void 0,this._parentComponent=void 0}onEnable(){super.onEnable()}addShadowComponent(t,i){var o;this.removeShadowComponent();const s=this.isRoot()?this.gameObject:this.gameObject.parent;if(this._parentComponent=$.getComponentInParent(s,Ho),!this._parentComponent){console.warn(`Component "${this.name}" doesn't have a UI parent anywhere. Do you have an UI element outside a Canvas? UI components must be a child of a Canvas component`,this);return}t.name=this.name+" ("+(this.constructor.name??"UI")+")",t.autoLayout=this._parentComponent.controlsChildLayout,t[vl]=this,this.setShadowComponentOwner(t);let r=!1;if(((o=this.Root)==null?void 0:o.gameObject)===this.gameObject)this.gameObject.add(t);else{let a=this._parentComponent.shadowComponent;a&&(a==null||a.add(t),r=!0)}this.shadowComponent=t,i&&i.shadowComponent&&this.shadowComponent&&i.shadowComponent.add(this.shadowComponent),hA&&t.add(new Gf(.5)),this.onAfterAddedToScene(),r&&mN()}set(t){}setShadowComponentOwner(t){if(t&&(t[vl]===void 0||t[vl]===this)&&(t[vl]=this,t.children))for(const i of t.children)this.setShadowComponentOwner(i)}traverseOwnedShadowComponents(t,i,s){if(t&&t[vl]===i){s(t);for(const r of t.children)this.traverseOwnedShadowComponents(r,i,s)}}removeShadowComponent(){this.shadowComponent&&this.shadowComponent.removeFromParent()}onAfterAddedToScene(){}setInteractable(t){this.shadowComponent&&(this.shadowComponent.interactable=t)}}class BA extends Ho{awake(){super.awake()}}class Mf{static getObject(e){const t=e[vl];return t&&(t.isComponent===!0?e=t.gameObject:e=t),e}static isInteractable(e,t){if(t&&(t.canvasGroup=void 0,t.graphic=void 0),e==null||!e.visible||(e=this.getObject(e),!e.visible))return!1;const i=this.tryFindCanvasGroup(e);if((i==null?void 0:i.isCanvasGroup)===!0&&(t&&(t.canvasGroup=i),i.blocksRaycasts===!1||i.interactable===!1))return!1;const s=Au(e,r=>{if(r.isGraphic===!0)return r},!1);return t&&(s==null?void 0:s.isGraphic)===!0&&(t.graphic=s),!((s==null?void 0:s.raycastTarget)===!1||(s==null?void 0:s.layer)===2)}static tryFindCanvasGroup(e){if(!e)return null;const t=Au(e,i=>{const s=i;if(s.blocksRaycasts!==void 0&&s.interactable!==void 0)return s},!1);return t!==void 0?t:this.tryFindCanvasGroup(e.parent)}}const gg=le("debugwebxrcontroller");var of=(n=>(n[n.PhysicalDevice=0]="PhysicalDevice",n[n.Touch=1]="Touch",n))(of||{}),hl=(n=>(n.SelectStart="select-start",n.SelectEnd="select-end",n.Update="update",n))(hl||{});class zb extends Ce{}const Gn=class extends Ce{constructor(){super(...arguments);u(this,"webXR");u(this,"index",-1);u(this,"controllerModel");u(this,"controller");u(this,"controllerGrip");u(this,"hand");u(this,"handPointerModel");u(this,"grabbed",null);u(this,"input",null);u(this,"type",0);u(this,"showRaycastLine",!0);u(this,"_wristQuaternion",null);u(this,"movementVector",new S);u(this,"worldRot",new xe);u(this,"joystick",new q);u(this,"didRotate",!1);u(this,"didTeleport",!1);u(this,"didChangeScale",!1);u(this,"lastHit",null);u(this,"raycastLine",null);u(this,"_raycastHitPoint",null);u(this,"_connnectedCallback",null);u(this,"_disconnectedCallback",null);u(this,"_selectStartEvt",null);u(this,"_selectEndEvt",null);u(this,"_selectionPressed",!1);u(this,"_selectionPressedLastFrame",!1);u(this,"_selectionStartTime",0);u(this,"_selectionEndTime",0);u(this,"_useSmoothing",!0);u(this,"_isConnected",!1);u(this,"rayRotation",new xe);u(this,"_pinchStartTime");u(this,"selectStartCallback",null);u(this,"lastSelectStartObject",null);u(this,"_didNotEndSelection",!1);u(this,"closeGrabBoundingBoxHelper")}static CreateRaycastLine(){const t=new rn(this.geometry),i=t.material;return i.color=this.raycastColor,t.layers.set(2),t.name="line",t.scale.z=1,t}static CreateRaycastHitPoint(){const t=new po(.5,22,22),i=new vi({color:this.raycastColor}),s=new ve(t,i);return s.visible=!1,s.layers.set(2),s}static Create(t,i,s,r){const o=s?$.addNewComponent(s,Gn,!1):new Gn;o.webXR=t,o.index=i,o.type=r;const a=t.context;o.controller=a.renderer.xr.getController(i),o.controllerGrip=a.renderer.xr.getControllerGrip(i),o.controllerModel=this.Factory.createControllerModel(o.controller),o.controllerGrip.add(o.controllerModel),o.hand=a.renderer.xr.getHand(i);const l=new Yf;yA(l,a),o.webXR.handModelPath&&o.webXR.handModelPath!==""?l.setPath($c(t.sourceId,o.webXR.handModelPath)):l.setPath("https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/");const c=new KY(o.hand,l);return o.hand.add(c),o.hand.traverse(h=>h.layers.set(2)),o.handPointerModel=new sJ(o.hand,o.controller),o.controller.addEventListener("connected",h=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2),setTimeout(()=>{o.setControllerLayers(o.controllerModel,2),o.setControllerLayers(o.controllerGrip,2),o.setControllerLayers(o.hand,2)},1e3)}),o.hand.addEventListener("connected",h=>{var f;if(h.data.hand){t.Rig&&t.Rig.add(o.hand),o.type=0,o.handPointerModel.traverse(g=>g.layers.set(2)),(f=o.handPointerModel.pointerObject)==null||f.traverse(g=>g.layers.set(2));const p=o.hand.joints;if(p)for(const g of Object.keys(p)){const m=p[g];m.parent||o.hand.add(m)}}}),o}static addEventListener(t,i){const s=this.eventSubs[t]??[];s.push(i),this.eventSubs[t]=s}static removeEventListener(t,i){if(!i)return;const s=this.eventSubs[t]??[],r=s.indexOf(i);r>=0&&s.splice(r,1),this.eventSubs[t]=s}get isUsingHands(){var i;const t=(i=this.input)==null?void 0:i.hand;return t!=null}get wrist(){if(!this.hand)return null;const t=this.hand.joints;return t?t.wrist:null}getWristQuaternion(){const t=this.wrist;return t?(this._wristQuaternion||(this._wristQuaternion=new xe),Dn(t).multiply(this._wristQuaternion.setFromEuler(new bn(-Math.PI/4,0,0)))):null}get selectionDown(){return this._selectionPressed&&!this._selectionPressedLastFrame}get selectionUp(){return!this._selectionPressed&&this._selectionPressedLastFrame}get selectionPressed(){return this._selectionPressed}get selectionClick(){return this._selectionEndTime-this._selectionStartTime<.3}get raycastHitPoint(){return this._raycastHitPoint}get useSmoothing(){return this._useSmoothing}awake(){if(!this.controller){console.warn("Missing Controller!!!",this);return}this._connnectedCallback=this.onSourceConnected.bind(this),this._disconnectedCallback=this.onSourceDisconnected.bind(this),this._selectStartEvt=this.onSelectStart.bind(this),this._selectEndEvt=this.onSelectEnd.bind(this),this.type===1&&(this.controllerGrip.addEventListener("connected",this._connnectedCallback),this.controllerGrip.addEventListener("disconnected",this._disconnectedCallback),this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.addEventListener("selectstart",this._selectStartEvt),this.controller.addEventListener("selectend",this._selectEndEvt))}onDestroy(){var t,i,s;this.type===1&&(this.controllerGrip.removeEventListener("connected",this._connnectedCallback),this.controllerGrip.removeEventListener("disconnected",this._disconnectedCallback),this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),this.type===0&&(this.controller.removeEventListener("selectstart",this._selectStartEvt),this.controller.removeEventListener("selectend",this._selectEndEvt)),(t=this.hand)==null||t.clear(),(i=this.controllerGrip)==null||i.clear(),(s=this.controller)==null||s.clear()}onEnable(){var t,i,s,r,o;this.hand&&(this.hand.name="Hand"),this.controllerGrip&&(this.controllerGrip.name="ControllerGrip"),this.controller&&(this.controller.name="Controller"),this.raycastLine&&(this.raycastLine.name="RaycastLine;"),this.webXR.Controllers.indexOf(this)<0&&this.webXR.Controllers.push(this),this.raycastLine||(this.raycastLine=Gn.CreateRaycastLine()),this._raycastHitPoint||(this._raycastHitPoint=Gn.CreateRaycastHitPoint()),(t=this.webXR.Rig)==null||t.add(this.hand),(i=this.webXR.Rig)==null||i.add(this.controllerGrip),(s=this.webXR.Rig)==null||s.add(this.controller),(r=this.webXR.Rig)==null||r.add(this.raycastLine),(o=this.raycastLine)==null||o.add(this._raycastHitPoint),this._raycastHitPoint.visible=!1,this.hand.add(this.handPointerModel),gg&&console.log("ADDED TO RIG",this.webXR.Rig)}onDisable(){var i,s,r,o,a;(i=this.hand)==null||i.removeFromParent(),(s=this.controllerGrip)==null||s.removeFromParent(),(r=this.controller)==null||r.removeFromParent(),(o=this.raycastLine)==null||o.removeFromParent(),(a=this._raycastHitPoint)==null||a.removeFromParent();const t=this.webXR.Controllers.indexOf(this);t>=0&&this.webXR.Controllers.splice(t,1)}onSourceConnected(t){if(this._isConnected){console.warn("Received connected event for controller that is already connected",this.index,t);return}this._isConnected=!0,this.input=t.data,this.type===1&&(this.onSelectStart(),this.createPointerEvent("down"))}onSourceDisconnected(t){if(!this._isConnected){console.warn("Received discnnected event for controller that is not connected",t);return}this._isConnected=!1,this.type===1&&(this.onSelectEnd(),this.createPointerEvent("up")),this.input=null}createPointerEvent(t){switch(t){case"down":this.context.input.createPointerDown({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break;case"move":break;case"up":this.context.input.createPointerUp({clientX:0,clientY:0,button:this.index,pointerType:"touch"});break}}update(){this.context.time.frameCount%60===0&&(this.setControllerLayers(this.controller,2),this.setControllerLayers(this.controllerGrip,2),this.setControllerLayers(this.hand,2));const t=Gn.eventSubs.update;if(t&&t.length>0)for(const r of t)r(this);let i=1;this.type===0?i=this.context.time.deltaTime/.1:this.isUsingHands&&this.handPointerModel.pinched&&(i=this.context.time.deltaTime/.3),this.rayRotation.slerp(Dn(this.controller),this.useSmoothing?i:1);const s=wt(this.controller);if(this.isUsingHands&&this.handPointerModel.cursorObject&&(this.handPointerModel.cursorObject.visible=!1),this.raycastLine){const r=this.showRaycastLine&&this.type!==1;if(this.type===1)this.raycastLine.visible=!1;else if(this.isUsingHands){this.raycastLine.visible=!this.grabbed&&r,ln(this.raycastLine,s);const o=this.hand.joints;if(o&&o.wrist&&this.grabbed&&this.grabbed.isCloseGrab){const l=this.getWristQuaternion();l&&this.rayRotation.copy(l)}cr(this.raycastLine,this.rayRotation)}else this.raycastLine.visible=r,cr(this.raycastLine,this.rayRotation),ln(this.raycastLine,s)}this.lastHit=this.updateLastHit(),this.grabbed&&this.grabbed.update(),this._selectionPressedLastFrame=this._selectionPressed,this.selectStartCallback&&this.selectStartCallback()}onUpdate(t){var r,o;if(this.lastHit=null,!t||t.inputSources.length<=this.index){this.input=null;return}if(this.type===0&&(this.input=t.inputSources[this.index]),!this.input)return;const i=this.webXR.Rig;if(!i)return;this._didNotEndSelection&&!this.handPointerModel.pinched&&(this._didNotEndSelection=!1,this.onSelectEnd()),this.updateStick(this.input);const s=(o=(r=this.input)==null?void 0:r.gamepad)==null?void 0:o.buttons;switch(this.input.handedness){case"left":const a=3*Gn.MovementSpeedFactor,l=2,c=Ze.clamp01(this.joystick.length()*2),h=this.joystick.x>0?1:-1;let d=Math.pow(this.joystick.x,l);d*=h,d*=c;const f=this.joystick.y>0?1:-1;let p=Math.pow(this.joystick.y,l);p*=f,d*=c,i.getWorldQuaternion(this.worldRot),this.movementVector.set(d,0,p),this.movementVector.applyQuaternion(this.webXR.TransformOrientation),this.movementVector.y=0,this.movementVector.applyQuaternion(this.worldRot),this.movementVector.multiplyScalar(a*this.context.time.deltaTime),i.position.add(this.movementVector),this.isUsingHands&&this.runTeleport(i,s);break;case"right":const g=this.joystick.x,m=Math.abs(g);if(m<.4)this.didRotate=!1;else if(m>.5&&!this.didRotate){const A=g>0?-1:1;i.rotateY(Ze.toRadians(30*A)),this.didRotate=!0}this.runTeleport(i,s);break}}runTeleport(t,i){var l,c,h;let s=-this.joystick.y;if((l=this.hand)!=null&&l.visible&&!this.grabbed){const d=this.handPointerModel.isPinched();d&&this._pinchStartTime===void 0&&(this._pinchStartTime=this.context.time.time),d&&this._pinchStartTime&&this.context.time.time-this._pinchStartTime>.8&&(s=this.handPointerModel.isPinched()?1:0),d||(this._pinchStartTime=void 0)}else this._pinchStartTime=void 0;let r=s>.5&&this.webXR.IsInVR,o=this.webXR.Rig?((h=(c=this.webXR.Rig)==null?void 0:c.scale)==null?void 0:h.x)<.999:!1,a=null;if(i&&this.input&&!this.input.hand)for(let d=0;d<i.length;d++){const f=i[d];if(d===4)if(f.pressed&&!this.didChangeScale&&this.webXR.IsInVR){this.didChangeScale=!0;const p=this.webXR.Rig;if(p)if(o){o=!1,p.scale.set(1,1,1),a=1,Gn.MovementSpeedFactor=1;const g=this.context.mainCamera;Gn.PreviousCameraFarDistance&&(g.far=Gn.PreviousCameraFarDistance)}else{o=!0,r=!0,a=.1,Gn.MovementSpeedFactor=a*2;const g=this.context.mainCamera;Gn.PreviousCameraFarDistance=g.far,g.far/=a}}else f.pressed||(this.didChangeScale=!1)}if(r){if(!this.didTeleport){const d=this.raycast();if(this.didTeleport=!0,d&&d.length>0){const f=d[0];if(o||this.isValidTeleportTarget(f.object)){const p=f.point;ln(t,p)}}}}else s<.1&&(this.didTeleport=!1);a!==null&&(t.scale.set(a,a,a),t.updateMatrixWorld())}isValidTeleportTarget(t){return $.getComponentInParent(t,zb)!=null}updateStick(t){var i;!t||!t.gamepad||((i=t.gamepad.axes)==null?void 0:i.length)<4||(this.joystick.x=t.gamepad.axes[2],this.joystick.y=t.gamepad.axes[3])}updateLastHit(){var r;const t=this.raycast(),i=t?t[0]:null;this.lastHit=i;let s=1;if(this.webXR.Rig&&(s/=this.webXR.Rig.scale.x),this.raycastLine){this.raycastLine.scale.z=s*(((r=this.lastHit)==null?void 0:r.distance)??9999);const o=this.raycastLine.material;i!=null?o.color=Gn.raycastColor:o.color=Gn.raycastNoHitColor}if(this._raycastHitPoint){if(this.lastHit!=null){this._raycastHitPoint.position.z=-1;const o=Ze.clamp(this.lastHit.distance*.01*s,.015,.1);this._raycastHitPoint.scale.set(o,o,o)}this._raycastHitPoint.visible=this.lastHit!==null&&this.lastHit!==void 0}return i}onSelectStart(){this.context.connection.allowEditing&&(this.selectStartCallback=()=>this.onHandleSelectStart())}onHandleSelectStart(){this.selectStartCallback=null,this._selectionPressed=!0,this._selectionStartTime=this.context.time.time,this._selectionEndTime=1e3;let t=null,i=!1;if(this.isUsingHands?(t=this.overlap(),t.length<=0?(t=this.raycast(),i=!1):i=!0):t=this.raycast(),gg&&console.log("onHandleSelectStart","close grab? "+i,"intersections",t),t&&t.length>0)for(const s of t){const r=s.object;this.lastSelectStartObject=r;const o={selected:r,grab:r},a=Gn.eventSubs["select-start"];if(a&&a.length>0)for(const l of a)l(this,o);o.grab!==r&&gg&&console.log("Grabbed object changed","original",r,"new",o.grab),o.grab&&(this.grabbed=ro.TryTake(this,o.grab,s,i));break}else{const s=Gn.eventSubs["select-start"],r={selected:null,grab:null};if(s&&s.length>0)for(const o of s)o(this,r)}}onSelectEnd(){var s;if(this.isUsingHands&&this.handPointerModel.pinched){this._didNotEndSelection=!0;return}if(!this._selectionPressed)return;this.selectStartCallback=null,this._selectionPressed=!1,this._selectionEndTime=this.context.time.time;const t={grab:((s=this.grabbed)==null?void 0:s.selected)??this.lastSelectStartObject},i=Gn.eventSubs["select-end"];if(i&&i.length>0)for(const r of i)r(this,t);this.grabbed&&(this.grabbed.free(),this.grabbed=null)}testIsVisible(t){return!(!t||$.isActiveInHierarchy(t)===!1||Mf.isInteractable(t)===!1)}setControllerLayers(t,i){var s,r;if(t&&(t.layers.set(i),t.children))for(const o of t.children)((s=this.grabbed)==null?void 0:s.selected)===o||((r=this.grabbed)==null?void 0:r.selectedMesh)===o||this.setControllerLayers(o,i)}getRay(){const t=new Gl;return t.origin.copy(wt(this.controller)),t.direction.set(0,0,-1).applyQuaternion(this.rayRotation),t}overlap(){const t=this.isUsingHands&&this.handPointerModel?this.handPointerModel.pointerObject:this.controllerGrip;if(gg&&(!this.closeGrabBoundingBoxHelper&&t&&(this.closeGrabBoundingBoxHelper=new eb(t,16776960),this.scene.add(this.closeGrabBoundingBoxHelper)),this.closeGrabBoundingBoxHelper&&t&&this.closeGrabBoundingBoxHelper.setFromObject(t)),!t)return new Array;const i=wt(t).clone();return this.context.physics.sphereOverlap(i,.02)}raycast(){const t=new qo;t.layerMask=new ho,t.layerMask.enableAll(),t.layerMask.disable(2),t.ray=this.getRay();const i=this.context.physics.raycast(t);for(let s=0;s<i.length;s++){const r=i[s],o=r.object;if(!this.testIsVisible(o)){i.splice(s,1),s--;continue}r.object=Mf.getObject(o);break}return i}};let Yi=Gn;u(Yi,"Factory",new mJ),u(Yi,"raycastColor",new _e(.9,.3,.3)),u(Yi,"raycastNoHitColor",new _e(.6,.6,.6)),u(Yi,"geometry",new vt().setFromPoints([new S(0,0,0),new S(0,0,-1)])),u(Yi,"handModels",{}),u(Yi,"eventSubs",{}),u(Yi,"PreviousCameraFarDistance"),u(Yi,"MovementSpeedFactor",1);var f_=(n=>(n.WillTake="WillTake",n.DidTake="DidTake",n.WillFree="WillFree",n.DidFree="DidFree",n))(f_||{});const Rs=class{constructor(){u(this,"sync",null);u(this,"selected",null);u(this,"selectedParent",null);u(this,"selectedMesh",null);u(this,"controller",null);u(this,"grabTime",0);u(this,"grabUUID","");u(this,"isCloseGrab",!1);u(this,"originalMaterial",null);u(this,"usageMarker",null);u(this,"rigidbodies",null);u(this,"didReparent",!1);u(this,"grabDistance",0);u(this,"interactable",null);u(this,"positionSource",null);u(this,"grabPoint",new S);u(this,"localPositionOffsetToGrab",null);u(this,"localPositionOffsetToGrab_worldSpace",new S);u(this,"localQuaternionToGrab",new xe(0,0,0,1));u(this,"targetDir",null);u(this,"quaternionLerp",null);u(this,"controllerDir",new S);u(this,"controllerWorldPos",new S);u(this,"lastControllerWorldPos",new S);u(this,"controllerPosDelta",new S);u(this,"totalChangeAlongDirection",0);u(this,"rigPositionLastFrame",new S)}static AddEventListener(e,t){return Rs.Events[e]||(Rs.Events[e]=[]),Rs.Events[e].push(t),t}static RemoveEventListener(e,t){if(!t||!Rs.Events[e])return;const i=Rs.Events[e].indexOf(t);i>=0&&Rs.Events[e].splice(i,1)}static Register(e){this.Current.find(t=>t===e)||this.Current.push(e)}static Remove(e){const t=this.Current.indexOf(e);t>=0&&this.Current.splice(t,1)}static TryTake(e,t,i,s){const r=$.getComponentInParent(t,rp);if(r)t=r.gameObject;else return gg&&console.warn("Prevented taking object that is not interactable",t),null;let o=t;const a=$.getComponentInParent(t,Jc);a&&(a.requestOwnership(),o=a.gameObject);for(const c of this.Current)if(c.selected===o)return c.controller===e||(c.free(),c.Take(e,o,t,a,r,i,s)),c;const l=new Rs;return l.Take(e,o,t,a,r,i,s),l}Take(e,t,i,s,r,o,a){var p,g;if(console.assert(t!==null,"Expected object to be taken but was",t),e.isUsingHands?this.positionSource=a?e.wrist:e.controller:this.positionSource=e.controller,!this.positionSource)return console.warn("No position source"),this;const l={controller:e,take:t,hit:i,sync:s,interactable:r};(p=Rs.Events.WillTake)==null||p.forEach(m=>m(this,l));const c=i;c!=null&&c.material&&(this.originalMaterial=c.material,Array.isArray(c.material)||(c.material=c.material.clone(),c.material&&c.material.emissive&&(c.material.emissive.b=.2))),this.selected=t,this.selectedParent||(this.selectedParent=t.parent),this.selectedMesh=c,this.controller=e,this.interactable=r,this.isCloseGrab=a,this.didReparent=!1,this.sync=s,this.grabTime=e.context.time.time,this.grabUUID=Date.now().toString(),this.usageMarker=$.addNewComponent(this.selected,op),this.rigidbodies=$.getComponentsInChildren(this.selected,Hi),wt(this.positionSource,this.lastControllerWorldPos);const h=()=>a?this.lastControllerWorldPos.clone():o.point.clone();this.grabDistance=h().distanceTo(this.lastControllerWorldPos),this.totalChangeAlongDirection=0,this.localPositionOffsetToGrab=this.selected.worldToLocal(h());const d=e.isUsingHands&&a?this.controller.getWristQuaternion().clone():e.rayRotation.clone();Dn(this.selected,this.localQuaternionToGrab).premultiply(d.invert());const f=this.controller.webXR.Rig;return f&&this.rigPositionLastFrame.copy(wt(f)),Ns.Add(e.context,this.selected),Rs.Register(this),this.sync&&(this.sync.fastMode=!0),(g=Rs.Events.DidTake)==null||g.forEach(m=>m(this,l)),this}free(){var s,r,o,a;if(!this.selected)return;const e={controller:this.controller,take:this.selected,hit:this.selected,sync:this.sync,interactable:null};(s=Rs.Events.WillFree)==null||s.forEach(l=>l(this,e)),Ns.Remove(this.controller.context,this.selected),Rs.Remove(this),this.sync&&(this.sync.fastMode=!1);const t=this.selectedMesh;t&&this.originalMaterial&&t.material&&(t.material=this.originalMaterial);const i=this.selected;if(this.didReparent&&i.parent){const l=this.selectedParent;l?l.attach(i):(r=this.controller)==null||r.context.scene.attach(i)}if((o=this.usageMarker)==null||o.destroy(),this.controller&&(this.controller.grabbed=null),this.selected=null,this.selectedParent=null,this.selectedMesh=null,this.sync=null,this.rigidbodies)for(const l of this.rigidbodies)l.wakeUp(),l.setVelocity(l.smoothedVelocity);this.rigidbodies=null,this.localPositionOffsetToGrab=null,this.quaternionLerp=null,(a=Rs.Events.DidFree)==null||a.forEach(l=>l(this,e))}controllerMovementSinceLastFrame(){if(!this.positionSource||!this.controller)return 0;this.controllerDir.set(0,0,-1),this.controllerDir.applyQuaternion(this.controller.rayRotation),wt(this.positionSource,this.controllerWorldPos),this.controllerPosDelta.copy(this.controllerWorldPos),this.controllerPosDelta.sub(this.lastControllerWorldPos),this.lastControllerWorldPos.copy(this.controllerWorldPos);const e=this.controller.webXR.Rig;if(e){const i=wt(e),s=this.rigPositionLastFrame.sub(i);this.controllerPosDelta.add(s),this.rigPositionLastFrame.copy(i)}return this.controllerDir.dot(this.controllerPosDelta)}update(){var e;if(this.rigidbodies)for(const t of this.rigidbodies)t.resetVelocities();if(this.sync&&this.controller&&this.controller.context.connection.isInRoom&&this.controller.context.time.time-this.grabTime>3&&this.sync.hasOwnership()===!1&&(console.log("no ownership, will leave",this.sync.guid),this.free()),!(this.interactable&&!this.interactable.canGrab)){if(!this.didReparent&&this.selected&&this.controller){const t=((e=this.controller.webXR.Rig)==null?void 0:e.scale.x)??1;this.totalChangeAlongDirection+=this.controllerMovementSinceLastFrame();let i=1;this.controller.type===0&&(i=Math.max(0,1+this.totalChangeAlongDirection*2/t),i=i*i*i),this.grabDistance/t<.8&&(i=1),this.targetDir||(this.targetDir=new S),this.targetDir.set(0,0,-this.grabDistance*i);const s=this.targetDir.applyQuaternion(this.controller.rayRotation).add(this.controllerWorldPos),r=this.controller.rayRotation.clone().multiplyQuaternions(this.controller.rayRotation,this.localQuaternionToGrab);this.quaternionLerp||(this.quaternionLerp=r.clone()),this.quaternionLerp.slerp(r,this.controller.useSmoothing?this.controller.context.time.deltaTime/.03:1),cr(this.selected,this.quaternionLerp),this.selected.updateWorldMatrix(!1,!1),this.grabPoint.copy(s),this.localPositionOffsetToGrab&&(this.localPositionOffsetToGrab_worldSpace.copy(this.localPositionOffsetToGrab),this.selected.localToWorld(this.localPositionOffsetToGrab_worldSpace).sub(wt(this.selected)),s.sub(this.localPositionOffsetToGrab_worldSpace)),ln(this.selected,s)}if(this.rigidbodies!=null)for(const t of this.rigidbodies)t.wakeUp();rr.markDirty(this.selected,!0)}}};let ro=Rs;u(ro,"Events",{}),u(ro,"Current",[]);var See=Object.defineProperty,Eee=Object.getOwnPropertyDescriptor,qI=(n,e,t,i)=>{for(var s=i>1?void 0:i?Eee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&See(e,t,s),s};class Ru extends Ce{constructor(){super(...arguments);u(this,"objectBounds",!1);u(this,"color");u(this,"isGizmo",!0);u(this,"_gizmoObject",null);u(this,"_boxHelper",null)}onEnable(){this.isGizmo&&!hA||(this._gizmoObject||(this.objectBounds&&this.gameObject.isMesh===!0?this._gizmoObject=new eb(this.gameObject,this.color??16776960):(this.objectBounds=!1,this._gizmoObject=P3(this.color??16776960))),this.objectBounds?(this.scene.add(this._gizmoObject),this._boxHelper=this._gizmoObject,this.startCoroutine(this.syncObjectBounds(),Rr.OnBeforeRender)):this.gameObject.add(this._gizmoObject))}onDisable(){this._gizmoObject&&this.gameObject.remove(this._gizmoObject)}*syncObjectBounds(){var t;for(;this._boxHelper;)(t=this._boxHelper)==null||t.update(),yield}}qI([w()],Ru.prototype,"objectBounds",2);qI([w(_e)],Ru.prototype,"color",2);qI([w()],Ru.prototype,"isGizmo",2);const Iee=le("debugrig");class Gb extends Ce{awake(){if(Iee){const e=new Ie;e.position.y+=.5,this.gameObject.add(e);const t=e.addNewComponent(Ru);t&&(t.isGizmo=!1)}}}class af{constructor(){u(this,"bb",null);u(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}x(){return this.bb.readFloat32(this.bb_pos)}y(){return this.bb.readFloat32(this.bb_pos+4)}z(){return this.bb.readFloat32(this.bb_pos+8)}w(){return this.bb.readFloat32(this.bb_pos+12)}static sizeOf(){return 16}static createVec4(e,t,i,s,r){return e.prep(4,16),e.writeFloat32(r),e.writeFloat32(s),e.writeFloat32(i),e.writeFloat32(t),e.offset()}}class As{constructor(){u(this,"bb",null);u(this,"bb_pos",0)}__init(e,t){return this.bb_pos=e,this.bb=t,this}static getRootAsVrUserStateBuffer(e,t){return(t||new As).__init(e.readInt32(e.position())+e.position(),e)}static getSizePrefixedRootAsVrUserStateBuffer(e,t){return e.setPosition(e.position()+hb),(t||new As).__init(e.readInt32(e.position())+e.position(),e)}guid(e){const t=this.bb.__offset(this.bb_pos,4);return t?this.bb.__string(this.bb_pos+t,e):null}time(){const e=this.bb.__offset(this.bb_pos,6);return e?this.bb.readInt64(this.bb_pos+e):this.bb.createLong(0,0)}avatarId(e){const t=this.bb.__offset(this.bb_pos,8);return t?this.bb.__string(this.bb_pos+t,e):null}position(e){const t=this.bb.__offset(this.bb_pos,10);return t?(e||new Mr).__init(this.bb_pos+t,this.bb):null}rotation(e){const t=this.bb.__offset(this.bb_pos,12);return t?(e||new af).__init(this.bb_pos+t,this.bb):null}scale(){const e=this.bb.__offset(this.bb_pos,14);return e?this.bb.readFloat32(this.bb_pos+e):0}posLeftHand(e){const t=this.bb.__offset(this.bb_pos,16);return t?(e||new Mr).__init(this.bb_pos+t,this.bb):null}posRightHand(e){const t=this.bb.__offset(this.bb_pos,18);return t?(e||new Mr).__init(this.bb_pos+t,this.bb):null}rotLeftHand(e){const t=this.bb.__offset(this.bb_pos,20);return t?(e||new af).__init(this.bb_pos+t,this.bb):null}rotRightHand(e){const t=this.bb.__offset(this.bb_pos,22);return t?(e||new af).__init(this.bb_pos+t,this.bb):null}static startVrUserStateBuffer(e){e.startObject(10)}static addGuid(e,t){e.addFieldOffset(0,t,0)}static addTime(e,t){e.addFieldInt64(1,t,e.createLong(0,0))}static addAvatarId(e,t){e.addFieldOffset(2,t,0)}static addPosition(e,t){e.addFieldStruct(3,t,0)}static addRotation(e,t){e.addFieldStruct(4,t,0)}static addScale(e,t){e.addFieldFloat32(5,t,0)}static addPosLeftHand(e,t){e.addFieldStruct(6,t,0)}static addPosRightHand(e,t){e.addFieldStruct(7,t,0)}static addRotLeftHand(e,t){e.addFieldStruct(8,t,0)}static addRotRightHand(e,t){e.addFieldStruct(9,t,0)}static endVrUserStateBuffer(e){return e.endObject()}static finishVrUserStateBufferBuffer(e,t){e.finish(t)}static finishSizePrefixedVrUserStateBufferBuffer(e,t){e.finish(t,void 0,!0)}}const FB=le("debugxr"),Zp=le("debugavatar"),XI="VRUS";C1(XI,As.getRootAsVrUserStateBuffer);function sE(){return new Date().getTime()}function Mee(n){let e=n&4294967295,t=n/Math.pow(2,32)&1048575;return Ea.create(e,t)}const $g=class{constructor(e){u(this,"guid");u(this,"time");u(this,"avatarId");u(this,"position",new S);u(this,"rotation",new rt);u(this,"scale",1);u(this,"posLeftHand",new S);u(this,"posRightHand",new S);u(this,"rotLeftHand",new xe);u(this,"rotRightHand",new xe);this.guid=e}update(e,t,i,s,r){var h,d,f,p,g,m;this.time=sE(),this.avatarId=r,this.position.set(t.x,t.y,t.z),e&&this.position.applyMatrix4(e.matrixWorld);let o=$g.quat0;const a=$g.quat1;o.set(i.x,i.y,i.z,i.w),o=o.multiplyQuaternions(o,$g.invertRotation),e&&(e.getWorldQuaternion(a),o.multiplyQuaternions(a,o)),this.rotation.set(o.x,o.y,o.z,o.w),this.scale=e.scale.x;const l=(h=s.LeftController)==null?void 0:h.controllerGrip;l&&(l.getWorldPosition(this.posLeftHand),l.getWorldQuaternion(this.rotLeftHand));const c=(d=s.RightController)==null?void 0:d.controllerGrip;if(c&&(c.getWorldPosition(this.posRightHand),c.getWorldQuaternion(this.rotRightHand)),(p=(f=s.LeftController)==null?void 0:f.hand)!=null&&p.visible){const A=s.LeftController.wrist;A&&(A.getWorldPosition(this.posLeftHand),A.getWorldQuaternion(this.rotLeftHand))}if((m=(g=s.RightController)==null?void 0:g.hand)!=null&&m.visible){const A=s.RightController.wrist;A&&(A.getWorldPosition(this.posRightHand),A.getWorldQuaternion(this.rotRightHand))}}sendAsBuffer(e,t){e.clear();const i=e.createString(this.guid),s=e.createString(this.avatarId);As.startVrUserStateBuffer(e),As.addGuid(e,i),As.addTime(e,Mee(this.time)),As.addAvatarId(e,s),As.addPosition(e,Mr.createVec3(e,this.position.x,this.position.y,this.position.z)),As.addRotation(e,af.createVec4(e,this.rotation.x,this.rotation.y,this.rotation.z,this.rotation.w)),As.addScale(e,this.scale),As.addPosLeftHand(e,Mr.createVec3(e,this.posLeftHand.x,this.posLeftHand.y,this.posLeftHand.z)),As.addPosRightHand(e,Mr.createVec3(e,this.posRightHand.x,this.posRightHand.y,this.posRightHand.z)),As.addRotLeftHand(e,af.createVec4(e,this.rotLeftHand.x,this.rotLeftHand.y,this.rotLeftHand.z,this.rotLeftHand.w)),As.addRotRightHand(e,af.createVec4(e,this.rotRightHand.x,this.rotRightHand.y,this.rotRightHand.z,this.rotRightHand.w));const r=As.endVrUserStateBuffer(e);e.finish(r,XI);const o=e.asUint8Array();t.sendBinary(o)}setFromBuffer(e,t){if(!e)return;this.guid=e,this.time=t.time().toFloat64();const i=t.avatarId();i&&(this.avatarId=i);const s=t.position();s&&this.position.set(s.x(),s.y(),s.z());const r=t.rotation();r&&this.rotation.set(r.x(),r.y(),r.z(),r.w());const o=t.posLeftHand();o&&this.posLeftHand.set(o.x(),o.y(),o.z());const a=t.posRightHand();a&&this.posRightHand.set(a.x(),a.y(),a.z());const l=t.rotLeftHand();l&&this.rotLeftHand.set(l.x(),l.y(),l.z(),l.w());const c=t.rotRightHand();c&&this.rotRightHand.set(c.x(),c.y(),c.z(),c.w()),this.scale=t.scale()}};let Lo=$g;u(Lo,"invertRotation",new xe().setFromAxisAngle(new S(0,1,0),Math.PI)),u(Lo,"quat0",new xe),u(Lo,"quat1",new xe);class km extends Ce{constructor(){super(...arguments);u(this,"webXR",null);u(this,"debugAvatarUser",null);u(this,"voip",null);u(this,"tempState",new Lo(""));u(this,"_removeAvatarsList",[]);u(this,"eventSub_ConnectionEvent",null);u(this,"eventSub_WebXRStartEvent",null);u(this,"eventSub_WebXREndEvent",null);u(this,"eventSub_WebXRUpdateEvent",null);u(this,"avatars",{});u(this,"localAvatar",null);u(this,"k_LocalAvatarNoNetworkingGuid","local");u(this,"ownership",null);u(this,"xrState",null);u(this,"builder",new Qf(1024))}async awake(){if(this.webXR||(this.webXR=$.getComponent(this.gameObject,Ct)),this.webXR||(this.webXR=$.findObjectOfType(Ct,this.context)),!this.webXR&&(console.log("Missing webxr component"),this.webXR=$.findObjectOfType(Ct,this.context),!this.webXR)){console.error("Could not find webxr component");return}if(this.voip||(this.voip=$.findObjectOfType(Vl,this.context)),Zp){const t="debug-avatar-"+Zp,i=new wa(this.context,t,this.webXR);if(this.debugAvatarUser=i,typeof Zp=="string"&&Zp.length>0)if(await i.setAvatarOverride(Zp)){const s=new Lo(t);s.position.y+=1;const r=.5;s.posLeftHand.y+=r,s.posLeftHand.x+=r,s.posRightHand.y+=r,s.posRightHand.x-=r,i.tryUpdate(s,0)}else i.destroy()}}onEnable(){if(!this.webXR&&(this.webXR=$.getComponent(this.gameObject,Ct),!this.webXR)){console.warn("Missing webxr component on "+this.gameObject.name);return}this.eventSub_WebXRStartEvent=this.onXRSessionStart.bind(this),Ct.addEventListener(Ei.XRStarted,this.eventSub_WebXRStartEvent),this.eventSub_WebXRUpdateEvent=this.onXRSessionUpdate.bind(this),Ct.addEventListener(Ei.XRUpdate,this.eventSub_WebXRUpdateEvent),this.eventSub_WebXREndEvent=this.onXRSessionEnded.bind(this),Ct.addEventListener(Ei.XRStopped,this.eventSub_WebXREndEvent),this.eventSub_ConnectionEvent=this.onConnected.bind(this),this.context.connection.beginListen(Ji.JoinedRoom,this.eventSub_ConnectionEvent),this.context.connection.beginListen("webxr-user-joined",t=>{console.log("webxr user joined evt")}),this.context.connection.beginListen("webxr-user-left",t=>{const i=t.id!==null&&t.id!==void 0;if(i&&(console.log("webxr user left evt"),i)){const s=this.avatars[t.id];s==null||s.destroy(),this.avatars[t.id]=void 0}}),this.context.connection.beginListenBinary(XI,t=>{const i=t.guid();if(!i)return;const s=t.time().toFloat64(),r=this.tempState;r.setFromBuffer(i,t);const o=this.onTryGetAvatar(i,s);o==null||o.tryUpdate(r,s)}),this.context.connection.beginListen("vr-session-update",t=>{const i=t.guid,s=t.time,r=this.onTryGetAvatar(i,s);r==null||r.tryUpdate(t,s)})}onTryGetAvatar(t,i){if(t===this.context.connection.connectionId)return null;const s=new Date().getTime()-i;if(s>5e3)return FB&&console.log("old data",s,t),null;let r=this.avatars[t];if(r===void 0)try{console.log("create new avatar");const o=new wa(this.context,t,this.webXR);r=o,this.avatars[t]=o}catch(o){this.avatars[t]=null,console.error(o)}return r}onDisable(){this.eventSub_ConnectionEvent&&this.context.connection.stopListen(Ji.JoinedRoom,this.eventSub_ConnectionEvent),Ct.removeEventListener(Ei.XRStarted,this.eventSub_WebXRStartEvent),Ct.removeEventListener(Ei.XRUpdate,this.eventSub_WebXRUpdateEvent),Ct.removeEventListener(Ei.XRStopped,this.eventSub_WebXREndEvent)}update(){const t=sE();this.debugAvatarUser&&(this.debugAvatarUser.lastUpdate=t),this.detectPotentiallyDisconnectedAvatarsAndRemove();for(const i in this.avatars){const s=this.avatars[i];s&&s.update()}}detectPotentiallyDisconnectedAvatarsAndRemove(){const t=sE();for(const i in this.avatars){const s=this.avatars[i];if(!s){this._removeAvatarsList.push(i);continue}t-s.lastUpdate>1e4&&(console.log("avatar timed out (didnt receive any updates in a while) - destroying it now"),s.destroy(),this.avatars[i]=void 0)}for(const i of this._removeAvatarsList)delete this.avatars[i];this._removeAvatarsList.length=0}buildLocalAvatar(){var i;if(this.localAvatar)return;const t=((i=this.context.connection)==null?void 0:i.connectionId)??this.k_LocalAvatarNoNetworkingGuid;this.localAvatar=new wa(this.context,t,this.webXR),this.localAvatar.isLocalAvatar=!0,this.localAvatar.setAvatarOverride(this.getAvatarId()),this.avatars[this.localAvatar.guid]=this.localAvatar}onConnected(){var t,i,s;FB&&console.log("Hey you are connected as "+this.context.connection.connectionId),((t=this.localAvatar)==null?void 0:t.guid)===this.k_LocalAvatarNoNetworkingGuid&&(this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0),this.localAvatar=null,this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null)}onXRSessionStart(t){var i,s,r;if(console.log("XR session started"),this.context.connection.send("webxr-user-joined",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null),this.xrState=null,(s=this.ownership)==null||s.freeOwnership(),this.ownership=null,this.avatars)for(const o in this.avatars)(r=this.avatars[o])==null||r.updateFlags()}onXRSessionEnded(t){var i;console.log("XR session ended"),this.context.connection.send("webxr-user-left",{id:this.context.connection.connectionId,mode:"vr"}),this.localAvatar&&((i=this.localAvatar)==null||i.destroy(),this.avatars[this.localAvatar.guid]=void 0,this.localAvatar=null)}onXRSessionUpdate(t){this.xrState??(this.xrState=new Lo(this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership??(this.ownership=new db(this.context.connection,this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid)),this.ownership.guid=this.context.connection.connectionId??this.k_LocalAvatarNoNetworkingGuid,this.buildLocalAvatar();const{frame:i,xr:s,rig:r}=t,o=i.getViewerPose(s.getReferenceSpace());if(!o)return;const a=o==null?void 0:o.transform,l=a.position,c=a.orientation;this.xrState.update(r,l,c,this.webXR,this.getAvatarId()),this.localAvatar&&(this.context.connection.connectionId&&(this.localAvatar.guid=this.context.connection.connectionId),this.localAvatar.tryUpdate(this.xrState,0)),!(this.ownership&&!this.ownership.hasOwnership&&this.context.connection.isConnected&&(this.context.time.frameCount%120===0&&this.ownership.requestOwnership(),!this.ownership.hasOwnership))&&(!this.context.connection.isConnected||!this.context.connection.connectionId||this.xrState.sendAsBuffer(this.builder,this.context.connection))}getAvatarId(){return le("avatar")??null}}var Tee=Object.defineProperty,Pee=Object.getOwnPropertyDescriptor,hp=(n,e,t,i)=>{for(var s=i>1?void 0:i?Pee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Tee(e,t,s),s};async function AN(){return EE()?!0:"xr"in navigator?await navigator.xr.isSessionSupported("immersive-ar")===!0:!1}async function vN(){return"xr"in navigator?await navigator.xr.isSessionSupported("immersive-vr")===!0:!1}let f0=!1,p0=!1;AN().then(n=>f0=n);vN().then(n=>p0=n);var Ei=(n=>(n.XRStarted="xrStarted",n.XRStopped="xrStopped",n.XRUpdate="xrUpdate",n.RequestVRSession="requestVRSession",n.ModifyAROptions="modify-ar-options",n))(Ei||{}),Sd;const Mn=(Sd=class extends Ce{constructor(){super(...arguments);u(this,"enableVR",!0);u(this,"enableAR",!0);u(this,"defaultAvatar");u(this,"handModelPath","");u(this,"createVRButton",!0);u(this,"createARButton",!0);u(this,"controllers",[]);u(this,"rig");u(this,"isInit",!1);u(this,"_requestedAR",!1);u(this,"_requestedVR",!1);u(this,"_isInAR",!1);u(this,"_isInVR",!1);u(this,"_arButton");u(this,"_vrButton");u(this,"webAR",null);u(this,"_transformOrientation",new xe);u(this,"_currentHeadPose",null);u(this,"_originalCameraParent",null);u(this,"_originalCameraPosition",new S);u(this,"_originalCameraRotation",new xe);u(this,"_originalXRRigParent",null);u(this,"_originalXRRigPosition",new S);u(this,"_originalXRRigRotation",new xe);u(this,"xrMirrorWindow",null)}static get IsInWebXR(){return this._isInXr}static get XRSupported(){return"xr"in navigator&&(f0||p0)}static get IsARSupported(){return f0}static get IsVRSupported(){return p0}static get OptionalFeatures_VR(){return this._optionalFeatures_VR}static get OptionalFeatures_AR(){return this._optionalFeatures_AR}static addEventListener(e,t){return this.events.addEventListener(e,t),t}static removeEventListener(e,t){return this.events.removeEventListener(e,t),t}static dispatchEvent(e,t){this.events.dispatchEvent({type:e,detail:t})}static createVRButton(e,t){Mn.XRSupported?e.__internalAwake():console.warn("WebXR is not supported on this device");const i={optionalFeatures:Mn.OptionalFeatures_VR},s=zg.createButton(e.context.renderer,i);return s.classList.add("webxr-ar-button"),s.classList.add("webxr-button"),this.resetButtonStyles(s),((t==null?void 0:t.registerClick)??!0)&&s.addEventListener("click",e.onClickedVRButton.bind(e)),s}static createARButton(e,t){var o;e.__internalAwake();const i=(o=e.webAR)==null?void 0:o.getAROverlayContainer(),s={optionalFeatures:[...this.OptionalFeatures_AR]};i?(s.domOverlay={root:i},s.optionalFeatures.push("dom-overlay"),s.optionalFeatures.push("hit-test")):console.warn("No dom overlay root found, HTML overlays on top of screen-based AR will not work.");const r=zY.createButton(e.context.renderer,s,this.onModifyAROptions.bind(this));return r.classList.add("webxr-ar-button"),r.classList.add("webxr-button"),Mn.resetButtonStyles(r),((t==null?void 0:t.registerClick)??!0)&&r.addEventListener("click",e.onClickedARButton.bind(e)),r}static onModifyAROptions(e){Mn.dispatchEvent("modify-ar-options",e)}static resetButtonStyles(e){e&&(e.style.position="",e.style.bottom="",e.style.left="")}endSession(){const e=this.context.renderer.xr.getSession();e&&e.end()}get Rig(){return this.rig||this.ensureRig(),this.rig}get Controllers(){return this.controllers}get LeftController(){var e,t;return this.controllers.length>0&&((e=this.controllers[0].input)==null?void 0:e.handedness)==="left"?this.controllers[0]:this.controllers.length>1&&((t=this.controllers[1].input)==null?void 0:t.handedness)==="left"?this.controllers[1]:null}get RightController(){var e,t;return this.controllers.length>0&&((e=this.controllers[0].input)==null?void 0:e.handedness)==="right"?this.controllers[0]:this.controllers.length>1&&((t=this.controllers[1].input)==null?void 0:t.handedness)==="right"?this.controllers[1]:null}get ARButton(){return this._arButton}get VRButton(){return this._vrButton}get IsInVR(){return this._isInVR}get IsInAR(){return this._isInAR}awake(){if(this.defaultAvatar&&typeof this.defaultAvatar=="string"&&(this.defaultAvatar=Xn.getOrCreate(this.sourceId??"/",this.defaultAvatar,this.context)),!$.findObjectOfType(km,this.context)){const e=$.addNewComponent(this.gameObject,km,!1);e.webXR=this}this.webAR=new au(this)}start(){location.protocol=="http:"&&location.host.indexOf("localhost")<0&&(Wo("WebXR only works on https"),console.warn("WebXR only works on https. https://engine.needle.tools/docs/xr.html"))}onEnable(){if(this.isInit||!this.enableAR&&!this.enableVR)return;this.isInit=!0,this.context.renderer.xr.enabled=!0,Mn.XRSupported;let e,t;const i=document.createElement("div");i.classList.add("webxr-buttons"),this.context.domElement.append(i),this.enableAR&&this.createARButton&&f0&&(e=Mn.createARButton(this),this._arButton=e,i.appendChild(e)),this.createVRButton&&this.enableVR&&p0&&(t=Mn.createVRButton(this),this._vrButton=t,i.appendChild(t)),setTimeout(()=>{Mn.resetButtonStyles(t),Mn.resetButtonStyles(e)},1e3)}get TransformOrientation(){return this._transformOrientation}get HeadPose(){return this._currentHeadPose}onBeforeRender(e){var i;if(!e)return;const t=this.context.renderer.xr.getSession();if(t){const s=e.getViewerPose(this.context.renderer.xr.getReferenceSpace());if(!s)return;this._currentHeadPose=s;const r=s==null?void 0:s.transform;r&&this._transformOrientation.set(r.orientation.x,r.orientation.y,r.orientation.z,r.orientation.w),Mn._isInXr===!1&&t&&this.onEnterXR(t,e);for(const o of this.controllers)o.onUpdate(t);this._isInAR&&((i=this.webAR)==null||i.onUpdate(t,e))}Mn.events.dispatchEvent({type:"xrUpdate",frame:e,xr:this.context.renderer.xr,rig:this.rig})}onClickedARButton(){this._isInAR||(this._requestedAR=!0,this._requestedVR=!1,this.captureStateBeforeXR())}onClickedVRButton(){if(!this._isInVR){if(this._requestedVR){this.onExitXR(null);return}this._requestedAR=!1,this._requestedVR=!0,this.captureStateBeforeXR(),this.ensureRig();for(let e=0;e<2;e++)Yi.Create(this,e,this.gameObject,of.PhysicalDevice);Mn.events.dispatchEvent({type:"requestVRSession"})}}captureStateBeforeXR(){this.context.mainCamera&&(this._originalCameraPosition.copy(wt(this.context.mainCamera)),this._originalCameraRotation.copy(Dn(this.context.mainCamera)),this._originalCameraParent=this.context.mainCamera.parent),this.Rig&&(this._originalXRRigParent=this.Rig.parent,this._originalXRRigPosition.copy(this.Rig.position),this._originalXRRigRotation.copy(this.Rig.quaternion))}ensureRig(){if(!this.rig){const e=$.findObjectOfType(Gb,this.context);e?this.rig=e.gameObject:(this.rig=new io,this.rig.rotateY(Math.PI),this.rig.name="XRRig",this.context.scene.add(this.rig))}}onEnterXR(e,t){var o,a;console.log("[XR] session begin",e),Mn._isInXr=!0,this.ensureRig();const i=this.context.renderer.xr.getReferenceSpace();if(i&&this.rig){const l=t.getViewerPose(i),c=l==null?void 0:l.transform.orientation;if(c){const h=new xe(c.x,c.y,c.z,c.w),d=new bn().setFromQuaternion(h);this.rig.rotateY(d.y)}}const s=this.context.renderer.xr;if(this.context.mainCamera){const l=s.getCamera(this.context.mainCamera),c=(o=this.context.mainCameraComponent)==null?void 0:o.cullingMask;if(c!==void 0){for(const h of l.cameras)h.layers.mask=c;l.layers.mask=c}else{for(const h of l.cameras)h.layers.enableAll();l.layers.enableAll()}this.rig.add(this.context.mainCamera),this._requestedAR&&this.context.scene.add(this.rig)}const r=this._requestedAR?vn.AR:vn.VR;switch(so.Global.Set(r),r){case vn.AR:this.context.xrSessionMode=ym.ImmersiveAR,this._isInAR=!0,(a=this.webAR)==null||a.onBegin(e);break;case vn.VR:this.context.xrSessionMode=ym.ImmersiveVR,this._isInVR=!0,this.onEnterVR(e);break}e.addEventListener("end",()=>{console.log("[XR] session end"),Mn._isInXr=!1,this.onExitXR(e)}),this.onEnterXR_HandleMirrorWindow(e),Mn.events.dispatchEvent({type:"xrStarted",session:e})}onExitXR(e){var i,s,r;const t=this._isInAR;this._isInAR&&e&&((i=this.webAR)==null||i.onEnd(e)),this._isInAR=!1,this._isInVR=!1,this._requestedAR=!1,this._requestedVR=!1,this.context.xrSessionMode=void 0,this.xrMirrorWindow&&(this.xrMirrorWindow.close(),this.xrMirrorWindow=null),this.destroyControllers(),this.context.mainCamera&&((s=this._originalCameraParent)==null||s.add(this.context.mainCamera),ln(this.context.mainCamera,this._originalCameraPosition),cr(this.context.mainCamera,this._originalCameraRotation),this.context.mainCamera.scale.set(1,1,1)),t&&((r=this._originalXRRigParent)==null||r.add(this.rig),this.rig.position.copy(this._originalXRRigPosition),this.rig.quaternion.copy(this._originalXRRigRotation)),so.Global.Set(vn.Browser|vn.ThirdPerson),Mn.events.dispatchEvent({type:"xrStopped",session:e})}onEnterVR(e){}destroyControllers(){var e;for(let t=this.controllers.length-1;t>=0;t-=1)(e=this.controllers[t])==null||e.destroy();this.controllers.length=0}onEnterXR_HandleMirrorWindow(e){le("mirror")&&setTimeout(()=>{if(!Mn.IsInWebXR)return;const t=new URL(window.location.href);im(t.searchParams,r_,1),im(t.searchParams,"isMirror",1);const i=t.toString();this.xrMirrorWindow=window.open(i,"webxr sync","popup=yes"),this.xrMirrorWindow&&(this.xrMirrorWindow.onload=()=>{this.xrMirrorWindow&&(this.xrMirrorWindow.onbeforeunload=()=>{Mn.IsInWebXR&&e.end()})})},1e3)}},u(Sd,"_isInXr",!1),u(Sd,"events",new Ln),u(Sd,"_optionalFeatures_VR",["local-floor","bounded-floor","hand-tracking","high-fixed-foveation-level","layers"]),u(Sd,"_optionalFeatures_AR",["anchors","local-floor","hand-tracking","layers"]),Sd);let Ct=Mn;hp([w()],Ct.prototype,"enableVR",2);hp([w()],Ct.prototype,"enableAR",2);hp([w(Xn)],Ct.prototype,"defaultAvatar",2);hp([w()],Ct.prototype,"handModelPath",2);hp([w()],Ct.prototype,"createVRButton",2);hp([w()],Ct.prototype,"createARButton",2);const Kd=class{constructor(e){u(this,"_webxr");u(this,"reticle",null);u(this,"reticleParent",null);u(this,"hitTestSource",null);u(this,"reticleActive",!0);u(this,"previousBackground",null);u(this,"previousEnvironment",null);u(this,"sessionRoot",null);u(this,"_previousParent",null);u(this,"arDomOverlay",null);u(this,"arOverlayElement",null);u(this,"noHitTestAvailable",!1);u(this,"didPlaceARSessionRoot",!1);this._webxr=e}get webxr(){return this._webxr}get context(){return this.webxr.context}getAROverlayContainer(){this.arDomOverlay=this.webxr.context.domElement;const e=this.arDomOverlay;return e.getAROverlayContainer?this.arOverlayElement=e.getAROverlayContainer():this.arOverlayElement=this.arDomOverlay,this.arOverlayElement}setReticleActive(e){this.reticleActive=e}async onBegin(e){var o,a,l,c;const t=this.webxr.context;this.reticleActive=!0,this.didPlaceARSessionRoot=!1,this.getAROverlayContainer();const i=(o=navigator.userAgent)!=null&&o.includes("OculusBrowser")?of.PhysicalDevice:of.Touch,s=i===of.Touch?4:2;for(let h=0;h<s;h++)Yi.Create(this.webxr,h,this.webxr.gameObject,i);(!this.sessionRoot||this.sessionRoot.destroyed||!this.sessionRoot.activeAndEnabled)&&(this.sessionRoot=$.findObjectOfType(ch,t)),this.previousBackground=t.scene.background,this.previousEnvironment=t.scene.environment,t.scene.background=null,e.requestReferenceSpace("viewer").then(h=>{var d,f;(f=(d=e.requestHitTestSource)==null?void 0:d.call(e,{space:h}))==null||f.then(p=>{this.hitTestSource=p}).catch(p=>{this.noHitTestAvailable=!0,console.warn("WebXR: Hit test not supported",p)})}),!this.reticle&&this.sessionRoot&&(this.reticle=new ve(new Uf(.07,.09,32).rotateX(-Math.PI/2),new vi),this.reticle.name="AR Placement reticle",this.reticle.matrixAutoUpdate=!1,this.reticle.visible=!1,this.reticleParent=new Ie,this.reticleParent.name="AR Reticle Parent",this.reticleParent.matrixAutoUpdate=!1,this.reticleParent.add(this.reticle),this.webxr.scene?(this.context.scene.add(this.reticleParent),this.context.scene.visible=!0):console.warn("Could not found WebXR Rig")),this._previousParent=this.webxr.gameObject,Kd.tempWebXRObject||(Kd.tempWebXRObject=new Ie),this.context.scene.add(Kd.tempWebXRObject),$.addComponent(Kd.tempWebXRObject,this.webxr),this.sessionRoot?(this.sessionRoot.webAR=this,(a=this.sessionRoot)==null||a.onBegin(e)):console.warn("No WebARSessionRoot found in scene");const r=this.context.domElement;(l=r==null?void 0:r.onEnterAR)==null||l.call(r,e,this.arOverlayElement),(c=this.context.mainCameraComponent)==null||c.applyClearFlagsIfIsActiveCamera()}onEnd(e){var s,r;this._previousParent&&($.addComponent(this._previousParent,this.webxr),this._previousParent=null),this.hitTestSource=null;const t=this.webxr.context;t.scene.background=this.previousBackground,t.scene.environment=this.previousEnvironment,this.sessionRoot&&this.sessionRoot.onEnd(this.webxr.Rig,e);const i=this.context.domElement;(s=i.onExitAR)==null||s.call(i,e),(r=this.context.mainCameraComponent)==null||r.applyClearFlagsIfIsActiveCamera()}onUpdate(e,t){var s,r;if(this.noHitTestAvailable===!0){if(this.reticle&&(this.reticle.visible=!1),!this.didPlaceARSessionRoot){this.didPlaceARSessionRoot=!0;const o=this.webxr.Rig,a=Ree.clone();(s=this.sessionRoot)==null||s.placeAt(o,a)}return}if(!this.hitTestSource)return;const i=t.getHitTestResults(this.hitTestSource);if(i.length){const o=i[0],a=this.webxr.context.renderer.xr.getReferenceSpace();if(a){const l=o.getPose(a);if(this.sessionRoot){const c=this.sessionRoot.onUpdate(this.webxr.Rig,e,l);this.didPlaceARSessionRoot=c}if(this.reticle&&(this.reticle.visible=this.reticleActive,this.reticleActive&&l)){const c=l.transform.matrix;this.reticle.matrix.fromArray(c),this.webxr.Rig&&this.reticle.matrix.premultiply(this.webxr.Rig.matrix)}}}else(r=this.sessionRoot)==null||r.onUpdate(this.webxr.Rig,e,null),this.reticle&&(this.reticle.visible=!1)}};let au=Kd;u(au,"tempWebXRObject");const Ree=new He().identity().makeTranslation(0,0,0);class iu{constructor(e,t){u(this,"used",!1);u(this,"inputSource");u(this,"object");u(this,"pointerId");u(this,"isDown");u(this,"isUp");u(this,"isPressed");u(this,"isClicked");u(this,"input");u(this,"event");this.event=t,this.input=e}use(){this.used=!0,this.pointerId!==void 0&&this.input.setPointerUsed(this.pointerId)}stopPropagation(){var e;(e=this.event)==null||e.stopImmediatePropagation()}Use(){this.use()}StopPropagation(){var e;(e=this.event)==null||e.stopImmediatePropagation()}}class up extends Ce{awake(){sr.createIfNoneExists(this.context)}onEnable(){var e;(e=sr.get(this.context))==null||e.register(this)}onDisable(){var e;(e=sr.get(this.context))==null||e.unregister(this)}performRaycast(e=null){return null}}class _u extends up{constructor(){super(...arguments);u(this,"targets",null);u(this,"raycastHits",[])}start(){this.targets=[this.gameObject]}performRaycast(t=null){return this.targets?(t??(t=new qo),t.targets=this.targets,t.results=this.raycastHits,this.context.physics.raycast(t)):null}}class YI extends _u{}const mg=le("debugeventsystem");var rE=(n=>(n.BeforeHandleInput="BeforeHandleInput",n.AfterHandleInput="AfterHandleInput",n))(rE||{});const ha=class extends Ce{constructor(){super();u(this,"raycaster",[]);u(this,"_selectStartFn");u(this,"_selectEndFn");u(this,"_selectUpdateFn");u(this,"_handleEventFn");u(this,"lastPointerEvent",null);u(this,"objectsHoveredThisFrame",[]);u(this,"objectsHoveredLastFrame",[]);u(this,"raisedPointerDownEvents",[]);u(this,"raisedPointerDownObjects",[]);u(this,"_didMove",!1);u(this,"_tempComponentsArray",[]);u(this,"_sortedHits",[]);u(this,"_sortingBuffer",[]);u(this,"_noDepthTestingResults",[]);u(this,"handleEventsArray",[]);u(this,"out",{});u(this,"currentActiveMeshUIComponents",[]);ha.systems.push(this)}static createIfNoneExists(t){this.didSearchEventSystem||(this.didSearchEventSystem=!0,ha.systems.length<=0&&ha.systems.push(...$.findObjectsOfType(ha,t)));for(const s of ha.systems)if(s.context===t)return;const i=new Ie;$.addNewComponent(i,ha),t.scene.add(i)}static get systems(){const t=_t.Current;return this._eventSystemMap.has(t)||this._eventSystemMap.set(t,[]),this._eventSystemMap.get(t)}static get(t){const i=this._eventSystemMap.get(t);return i&&i.length>0?i[0]:null}static get instance(){return this.systems[0]}static ensureUpdateMeshUI(t,i){ul.update(t,i)}static markUIDirty(t){ul.markDirty()}get hasActiveUI(){return this.currentActiveMeshUIComponents.length>0}get isHoveringObjects(){return this.objectsHoveredThisFrame.length>0}onDestroy(){ha.systems.splice(ha.systems.indexOf(this),1)}start(){if(this.raycaster.length<=0&&!$.findObjectOfType(up,this.context)){const i=$.addNewComponent(this.context.scene,_u);this.raycaster.push(i),Qs()&&console.warn("Added an ObjectRaycaster to the scene because no raycaster was found",this)}}register(t){var i;t&&this.raycaster&&!this.raycaster.includes(t)&&((i=this.raycaster)==null||i.push(t))}unregister(t){var s,r;const i=(s=this.raycaster)==null?void 0:s.indexOf(t);i!==void 0&&i!==-1&&((r=this.raycaster)==null||r.splice(i,1))}onEnable(){const t=new Map;this._selectStartFn??(this._selectStartFn=(s,r)=>{if(!r.grab)return;ul.resetLastSelected();const o=new iu(this.context.input);o.inputSource=s,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=!1,t.set(s,r.grab),r.grab&&!this.handleEvents(r.grab,o)&&(r.grab=null)}),this._selectEndFn??(this._selectEndFn=(s,r)=>{var l;if(!r.grab)return;const o=new iu(this.context.input);o.inputSource=s,o.isDown=s.selectionDown,o.isUp=s.selectionUp,o.isPressed=s.selectionPressed,o.isClicked=s.selectionClick,this.handleEvents(r.grab,o);const a=t.get(s);if(t.set(s,null),a)for(let c=0;c<this.raisedPointerDownEvents.length;c++){const h=this.raisedPointerDownEvents[c];this.raisedPointerDownObjects[c]===a&&h&&((l=h.onPointerUp)==null||l.call(h,o),this.raisedPointerDownEvents.splice(c,1),this.raisedPointerDownObjects.splice(c,1),c--)}});const i=new qo;this._selectUpdateFn??(this._selectUpdateFn=s=>{i.ray=s.getRay();const r=this.performRaycast(i);if(!r)return;const o=new iu(this.context.input);o.inputSource=s,this.handleIntersections(r,o)}),Yi.addEventListener(hl.SelectStart,this._selectStartFn),Yi.addEventListener(hl.SelectEnd,this._selectEndFn),Yi.addEventListener(hl.Update,this._selectUpdateFn),this._handleEventFn??(this._handleEventFn=this.onHandleEvents.bind(this)),this.context.pre_update_callbacks.push(this._handleEventFn)}onDisable(){Yi.removeEventListener(hl.SelectStart,this._selectStartFn),Yi.removeEventListener(hl.SelectEnd,this._selectEndFn),Yi.removeEventListener(hl.Update,this._selectUpdateFn),this.context.pre_update_callbacks.splice(this.context.pre_update_callbacks.indexOf(this._handleEventFn),1)}onHandleEvents(){if(this.objectsHoveredThisFrame.length=0,this.resetMeshUIStates(),Ct.IsInWebXR||this.context.input.isKeyPressed("AltLeft")||this.context.input.isKeyPressed("AltRight"))return;if(!this._didMove){const a=this.context.input.getPointerPositionRC(0);if(a&&a.x===0&&a.y===0)return;this._didMove=!0}let t=0;for(const a of this.context.input.foreachPointerId()){const l=this.context.input.getPointerDown(a),c=this.context.input.getPointerUp(a);if(l||c){t=a;break}}const i=this.context.input.getPointerEvent(t),s=new iu(this.context.input,i);s.inputSource=this.context.input,s.pointerId=t,s.isClicked=this.context.input.getPointerClicked(t),s.isDown=this.context.input.getPointerDown(t),s.isUp=this.context.input.getPointerUp(t),s.isPressed=this.context.input.getPointerPressed(t),mg&&s.isClicked&&console.log("CLICK",t);const r=this.performRaycast(null);if(!r)return;this.lastPointerEvent=s;const o={sender:this,args:s,hasActiveUI:this.currentActiveMeshUIComponents.length>0};mg&&s.isClicked&&jn("EventSystem: "+s.pointerId+" - "+this.context.time.frame+" - Up:"+s.isUp+", Down:"+s.isDown),this.dispatchEvent(new CustomEvent("BeforeHandleInput",{detail:o})),this.handleIntersections(r,s),this.dispatchEvent(new CustomEvent("AfterHandleInput",{detail:o}))}onBeforeRender(){if(this.lastPointerEvent)this.lastPointerEvent.used=!1;else return;if(this.lastPointerEvent.isUp){for(const i of this.raisedPointerDownEvents)i.onPointerUp&&i.onPointerUp(this.lastPointerEvent);this.raisedPointerDownEvents.length=0,this.raisedPointerDownObjects.length=0}for(const i of this.objectsHoveredLastFrame)if(this.objectsHoveredThisFrame.indexOf(i)<0){this._tempComponentsArray.length=0;const s=$.getComponentsInParent(i,Ce,this._tempComponentsArray);this.lastPointerEvent.object=i;for(let r=0;r<s.length;r++){const o=s[r];if(!o.gameObject||o.destroyed)continue;const a=o;a.onPointerExit&&a.onPointerExit(this.lastPointerEvent)}}const t=this.objectsHoveredLastFrame;this.objectsHoveredLastFrame=this.objectsHoveredThisFrame,this.objectsHoveredThisFrame=t}performRaycast(t){if(!this.raycaster)return null;this._sortedHits.length=0;for(const i of this.raycaster){if(!i.activeAndEnabled)continue;const s=i.performRaycast(t);s&&s.length>0&&this._sortedHits.push(...s)}return this._sortedHits.sort((i,s)=>i.distance-s.distance),this._sortedHits}handleIntersections(t,i){if(!t||t.length<=0)return!1;t=this.sortCandidates(t);for(const s of t){const{object:r}=s;if(this.handleEvents(r,i))return!0}return!1}sortCandidates(t){this._sortingBuffer.length=0,this._noDepthTestingResults.length=0;for(let i=0;i<t.length;i++){const s=t[i],r=s.object;if(r.material&&r.material.depthTest===!1){this._noDepthTestingResults.push(s);continue}this._sortingBuffer.push(s)}for(const i of this._sortingBuffer)this._noDepthTestingResults.push(i);return this._noDepthTestingResults}handleEvents(t,i){if(!this.testIsVisible(t))return i.isClicked&&mg&&console.log("not allowed",t),!1;const s=t;i.object=t,this.lastPointerEvent=i;const r=t.parent;let o=!1;const a=i.isClicked??!1;let l=null;if(r&&r.isUI){const c=(i.isPressed||i.isClicked)??!1;if(r[vl]){const h=r[vl].gameObject;if(h){if(!Mf.isInteractable(h,this.out))return!1;l=this.out.canvasGroup??null,this.handleMeshUIIntersection(t,c),t=h,o=!0}}if(!o&&this.handleMeshUiObjectWithoutShadowDom(r,c))return!0}if(a&&mg&&console.log(this.context.time.frame,t),this.objectsHoveredThisFrame.push(t),l===null||l.interactable){const c=this.objectsHoveredLastFrame.indexOf(t)>=0;this.handleEventsArray.length=0;const h=$.getComponentsInParent(t,Ce,this.handleEventsArray);for(let d=0;d<h.length;d++){if(i.used)return!0;if(h[d].destroyed)continue;const f=h[d];if(f.interactable!==!1){if(f.onPointerEnter&&(c||f.onPointerEnter(i)),f.onPointerMove&&f.onPointerMove(i),i.isDown&&f.onPointerDown&&!this.raisedPointerDownEvents.includes(f)&&(f.onPointerDown(i),this.raisedPointerDownEvents.push(f),this.raisedPointerDownObjects.push(s)),i.isUp&&f.onPointerUp){const p=this.raisedPointerDownEvents.indexOf(f);p!==-1&&this.raisedPointerDownEvents.splice(p,1),f.onPointerUp(i)}i.isClicked&&f.onPointerClick&&f.onPointerClick(i)}}}return!0}handleMeshUiObjectWithoutShadowDom(t,i){return!t||!t.isUI?!0:this.handleMeshUIIntersection(t,i)}handleMeshUIIntersection(t,i){const s=ul.updateState(t,i);return s&&this.currentActiveMeshUIComponents.push(s),s!==null}resetMeshUIStates(){if(this.context.input.getPointerPressedCount()>0&&ul.resetLastSelected(),!(!this.currentActiveMeshUIComponents||this.currentActiveMeshUIComponents.length<=0)){for(let t=0;t<this.currentActiveMeshUIComponents.length;t++){const i=this.currentActiveMeshUIComponents[t];ul.resetState(i)}this.currentActiveMeshUIComponents.length=0}}testIsVisible(t){return t?$.isActiveSelf(t)?this.testIsVisible(t.parent):!1:!0}};let sr=ha;u(sr,"_eventSystemMap",new Map),u(sr,"didSearchEventSystem",!1);class ul{static markDirty(){this.needsUpdate=!0}static update(e,t){const i=t.time.frameCount;for(const s of this.lastUpdateFrame)if(s.context===t){if(i===s.frame)return;s.frame=i;let r=this.needsUpdate||i<1;s.nextUpdate===t.time.frameCount&&(r=!0),r&&(mg&&console.log("Update threemeshui"),this.needsUpdate=!1,e.update());return}this.lastUpdateFrame=[{context:t,frame:i,nextUpdate:i}],e.update()}static updateState(e,t){let i=null;if(e&&(i=this.findBlockInParent(e),i&&i!==this.lastSelected)){if(i.interactable===!1)return null;this.needsUpdate=!0}return i}static resetLastSelected(){const e=this.lastSelected;e&&(this.lastSelected=null,this.resetState(e))}static resetState(e){e&&(this.needsUpdate=!0)}static findBlockInParent(e){return e?e.isBlock?e:this.findBlockInParent(e.parent):null}}u(ul,"lastSelected",null),u(ul,"lastUpdateFrame",[]),u(ul,"needsUpdate",!1);const g0=Symbol("cameraController");function Bee(n){return n[g0]}function UB(n,e,t){t?n[g0]=e:n[g0]===e&&(n[g0]=null)}var Dee=Object.defineProperty,kee=Object.getOwnPropertyDescriptor,Oee=(n,e,t,i)=>{for(var s=i>1?void 0:i?kee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Dee(e,t,s),s};const Ay=le("freecam"),NB=le("debugcamerafit"),Lee={LEFT:"",UP:"",RIGHT:"",BOTTOM:""};let Jw;class ql extends Ce{constructor(){super(...arguments);u(this,"autoRotate",!1);u(this,"autoRotateSpeed",1);u(this,"enableKeys",!0);u(this,"enableDamping",!0);u(this,"dampingFactor",.1);u(this,"enableZoom",!0);u(this,"minZoom",0);u(this,"maxZoom",1/0);u(this,"enablePan",!0);u(this,"lookAtConstraint",null);u(this,"lookAtConstraint01",1);u(this,"middleClickToFocus",!0);u(this,"doubleClickToFocus",!0);u(this,"useSlerp",!0);u(this,"debugLog",!1);u(this,"targetLerpSpeed",5);u(this,"_lookTargetPosition");u(this,"_controls",null);u(this,"_cameraObject",null);u(this,"_lerpToTargetPosition",!1);u(this,"_lerpCameraToTarget",!1);u(this,"_cameraTargetPosition",null);u(this,"_inputs",0);u(this,"_enableTime",0);u(this,"_startedListeningToKeyEvents",!1);u(this,"_eventSystem");u(this,"_afterHandleInputFn");u(this,"_camera",null);u(this,"_syncedTransform");u(this,"targetElement",null);u(this,"onControlsChangeStarted",()=>{this._syncedTransform&&this._syncedTransform.requestOwnership()});u(this,"_shouldDisable",!1);u(this,"_haveAttachedKeyboardEvents",!1)}get isCameraController(){return!0}get controls(){return this._controls}get controllerObject(){return this._cameraObject}onStartInteraction(t){var i;(i=this.controls)==null||i.addEventListener("start",t)}awake(){this._lookTargetPosition=new S,this._startedListeningToKeyEvents=!1}start(){if(this._controls){const t=$.getComponent(this.gameObject,Oi);if(t&&!this.setFromTargetPosition()){this.debugLog&&console.log("NO TARGET");const s=wt(t.cam).length(),r=new S(0,0,-s).applyMatrix4(t.cam.matrixWorld);this.setTarget(r,!0)}}this.startCoroutine(this.startRaycastDelayed()),this._eventSystem=sr.get(this.context)??void 0,this._eventSystem&&(this._afterHandleInputFn=this.afterHandleInput.bind(this),this._eventSystem.addEventListener(rE.AfterHandleInput,this._afterHandleInputFn))}onDestroy(){var t,i;(t=this._controls)==null||t.dispose(),(i=this._eventSystem)==null||i.removeEventListener(rE.AfterHandleInput,this._afterHandleInputFn)}onEnable(){this._enableTime=this.context.time.time;const t=$.getComponent(this.gameObject,Oi);this._camera=t;const i=t==null?void 0:t.cam;if(i&&UB(i,this,!0),!this._controls){console.assert(i!=null,"Missing camera",this),i&&(this._cameraObject=i);const s=this.targetElement??this.context.domElement,r=i==null?void 0:i.quaternion.clone();this._controls=new NY(i,s),i==null||i.quaternion.copy(r),Jw===void 0&&(Jw={...this._controls.keys})}this._controls&&(Ay&&(this.enablePan=!0,this.enableZoom=!0,this.middleClickToFocus=!0,xu()&&(this.doubleClickToFocus=!0)),this._controls.enableDamping=this.enableDamping,this._controls.keys=this.enableKeys?Jw:Lee,this._controls.autoRotate=this.autoRotate,this._controls.autoRotateSpeed=this.autoRotateSpeed,this._controls.enableZoom=this.enableZoom,this._controls.addEventListener("start",this.onControlsChangeStarted),(i==null?void 0:i.type)==="PerspectiveCamera"?Ay||(this._controls.minDistance=this.minZoom,this._controls.maxDistance=this.maxZoom):Ay||(this._controls.minZoom=this.minZoom,this._controls.maxZoom=this.maxZoom),this._controls.dampingFactor=this.dampingFactor,this._controls.enablePan=this.enablePan,this._startedListeningToKeyEvents||(this._startedListeningToKeyEvents=!0,this._controls.listenToKeyEvents(window.document.body))),this._syncedTransform=$.getComponent(this.gameObject,Jc)??void 0}onDisable(){var t;(t=this._camera)!=null&&t.cam&&UB(this._camera.cam,this,!1),this._controls&&(this._controls.enabled=!1,this._controls.autoRotate=!1,this._controls.removeEventListener("start",this.onControlsChangeStarted))}afterHandleInput(t){t.detail.args.pointerId===0&&(t.detail.args.isDown?this._controls&&this._eventSystem&&(this._shouldDisable=this._eventSystem.hasActiveUI):(!t.detail.args.isPressed||t.detail.args.isUp)&&(this._shouldDisable=!1))}*startRaycastDelayed(){if(yield,!this.setFromTargetPosition()){const t=new qo;t.screenPoint=new q(0,0),t.lineThreshold=.1;const i=this.context.physics.raycast(t);i.length>0&&this.setTarget(i[0].point,!0)}}onBeforeRender(){var i,s,r;if(!this._controls||this._cameraObject!==this.context.mainCamera)return;(this.context.input.getPointerDown(0)||this.context.input.getPointerDown(1)||this.context.input.getPointerDown(2))&&(this._inputs+=1),this._inputs>0&&(this.autoRotate=!1,this._controls.autoRotate=!1,this._lerpCameraToTarget=!1,this._lerpToTargetPosition=!1),this._inputs=0;let t=this.middleClickToFocus&&this.context.input.getPointerClicked(1);if(t||(t=this.doubleClickToFocus&&this.context.input.getPointerDoubleClicked(0)&&this.context.time.time-this._enableTime>.3),t?this.setTargetFromRaycast():(this.context.input.getPointerDown(0)||this.context.input.mouseWheelChanged)&&(this._lerpToTargetPosition=!1,this._lerpCameraToTarget=!1),this._lerpToTargetPosition||this._lerpCameraToTarget){const o=this.context.time.deltaTime*this.targetLerpSpeed;if(this._lerpCameraToTarget&&this._cameraTargetPosition&&this._cameraObject){if(this.useSlerp){const a=(i=this._cameraObject)==null?void 0:i.position;cO(a,this._cameraTargetPosition,o)}else(s=this._cameraObject)==null||s.position.lerp(this._cameraTargetPosition,o);this._cameraObject.position.distanceTo(this._cameraTargetPosition)<1e-4&&(this._lerpCameraToTarget=!1)}this._lerpToTargetPosition&&(this.lerpTarget(this._lookTargetPosition,o),this._lookTargetPosition.distanceTo(this._controls.target)<1e-5&&(this._lerpToTargetPosition=!1))}!Ay&&((r=this.lookAtConstraint)!=null&&r.locked)&&this.setFromTargetPosition(0,this.lookAtConstraint01),this._controls&&!this.context.isInXR&&(this.debugLog&&(this._controls.domElement=this.context.renderer.domElement),this._controls.enabled=!this._shouldDisable&&this._camera===this.context.mainCameraComponent,this._controls.update())}setCameraTarget(t,i=!1){var s;t?(this._lerpCameraToTarget=!0,this._cameraTargetPosition=t.clone(),i&&this._cameraTargetPosition&&((s=this.controllerObject)==null||s.position.copy(this._cameraTargetPosition))):this._lerpCameraToTarget=!1}setFromTargetPosition(t=0,i=1){var r;if(!this._controls)return!1;const s=(r=this.lookAtConstraint)==null?void 0:r.sources;if(s&&s.length>0){const o=s[t];if(o)return o.getWorldPosition(this._lookTargetPosition),this.lerpTarget(this._lookTargetPosition,i),!0}return!1}setTarget(t=null,i=!1){this._controls&&(t!==null&&this._lookTargetPosition.copy(t),i?this._controls.target.copy(this._lookTargetPosition):this._lerpToTargetPosition=!0)}lerpTarget(t,i){this._controls&&this._controls.target.lerp(t,i)}distanceToTarget(t){return this._controls?this._controls.target.distanceTo(t):-1}setTargetFromRaycast(){var i,s;if(!this.controls)return;const t=this.context.physics.raycast();for(const r of t)if(r.distance>0&&$.isActiveInHierarchy(r.object)){if(this._lookTargetPosition.copy(r.point),this._lerpToTargetPosition=!0,this._cameraTargetPosition=null,this.context.mainCamera){this._lerpCameraToTarget=!0;const o=wt(this.context.mainCamera);this._cameraTargetPosition=o.clone().sub(this.controls.target).add(this._lookTargetPosition),(s=(i=this._cameraObject)==null?void 0:i.parent)==null||s.worldToLocal(this._cameraTargetPosition)}break}}fitCamera(t,i=1.1){const s=this._cameraObject,r=this._controls;if(t!=null&&t.length||(t=this.context.scene.children),!s||!r)return;const o=new S,a=new S,l=new _s;l.makeEmpty();for(const A of t)A instanceof uS||l.expandByObject(A,!0);s.updateMatrixWorld(),s.updateProjectionMatrix(),l.getCenter(a),l.applyMatrix4(s.matrixWorldInverse),l.getSize(o),l.setFromCenterAndSize(a,o);const c=s.fov,h=2*Math.atan(Math.tan(c*Math.PI/360/2)*s.aspect)/Math.PI*360,d=o.y/(2*Math.atan(Math.PI*c/360)),f=o.x/(2*Math.atan(Math.PI*h/360)),p=i*Math.max(d,f)+o.z/2;NB&&console.log("Fit camera to objects",d,f,"distance",p);const g=wt(s),m=r.target.clone().sub(g).normalize().multiplyScalar(p);if(r.maxDistance=p*10,r.minDistance=p*.01,r.target.copy(a),s.near=p/100,s.far=p*100,s.updateMatrixWorld(),s.updateProjectionMatrix(),ln(s,r.target.clone().sub(m)),NB){const A=new uS(l);this.context.scene.add(A),fO(A,tb(s)),this._haveAttachedKeyboardEvents||(this._haveAttachedKeyboardEvents=!0,document.body.addEventListener("keydown",v=>{v.code==="KeyF"&&this.fitCamera(t)}))}r.update()}}Oee([w(EA)],ql.prototype,"lookAtConstraint",2);var Fee=Object.defineProperty,Uee=Object.getOwnPropertyDescriptor,mo=(n,e,t,i)=>{for(var s=i>1?void 0:i?Uee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Fee(e,t,s),s},yN=(n=>(n[n.Skybox=1]="Skybox",n[n.SolidColor=2]="SolidColor",n[n.Uninitialized=4]="Uninitialized",n))(yN||{});const Ag=le("debugcam"),zB=le("debugscreenpointtoray");var Ly;const vg=(Ly=class extends Ce{constructor(){super(...arguments);u(this,"_nearClipPlane",.1);u(this,"_farClipPlane",1e3);u(this,"orthographic",!1);u(this,"orthographicSize",5);u(this,"ARBackgroundAlpha",0);u(this,"_cullingMask",4294967295);u(this,"_backgroundBlurriness");u(this,"_backgroundIntensity");u(this,"_targetTexture",null);u(this,"_backgroundColor");u(this,"_fov");u(this,"_cam",null);u(this,"_clearFlags",2);u(this,"_skybox")}get isCamera(){return!0}get aspect(){return this._cam instanceof $t?this._cam.aspect:this.context.domWidth/this.context.domHeight}get fieldOfView(){return this._cam instanceof $t?this._cam.fov:this._fov}set fieldOfView(e){const t=this._fov!=e;if(this._fov=e,t&&this._cam&&this._cam instanceof $t){if(this._fov===void 0){console.error("Can not set undefined fov on PerspectiveCamera");return}this._cam.fov=this._fov,this._cam.updateProjectionMatrix()}}get nearClipPlane(){return this._nearClipPlane}set nearClipPlane(e){const t=this._nearClipPlane!=e;this._nearClipPlane=e,this._cam&&t&&(this._cam.near=e,this._cam.updateProjectionMatrix())}get farClipPlane(){return this._farClipPlane}set farClipPlane(e){const t=this._farClipPlane!=e;this._farClipPlane=e,this._cam&&t&&(this._cam.far=e,this._cam.updateProjectionMatrix())}get clearFlags(){return this._clearFlags}set clearFlags(e){e!==this._clearFlags&&(this._clearFlags=e,this.applyClearFlagsIfIsActiveCamera())}set cullingMask(e){this._cullingMask=e,this._cam&&(this._cam.layers.mask=e)}get cullingMask(){return this._cam?this._cam.layers.mask:this._cullingMask}set backgroundBlurriness(e){e!==this._backgroundBlurriness&&(e===void 0?this._backgroundBlurriness=void 0:this._backgroundBlurriness=Math.min(Math.max(e,0),1),this.applyClearFlagsIfIsActiveCamera())}get backgroundBlurriness(){return this._backgroundBlurriness}set backgroundIntensity(e){e!==this._backgroundIntensity&&(e===void 0?this._backgroundIntensity=void 0:this._backgroundIntensity=Math.min(Math.max(e,0),10),this.applyClearFlagsIfIsActiveCamera())}get backgroundIntensity(){return this._backgroundIntensity}get backgroundColor(){return this._backgroundColor??null}set backgroundColor(e){if(e){if(this._backgroundColor)this._backgroundColor.copy(e);else{if(!e.clone)return;this._backgroundColor=e.clone()}e.alpha===void 0&&(this._backgroundColor.alpha=1),this.applyClearFlagsIfIsActiveCamera()}}set targetTexture(e){this._targetTexture=e}get targetTexture(){return this._targetTexture}get cam(){return this.activeAndEnabled&&this.buildCamera(),this._cam}screenPointToRay(e,t,i){let s=this.cam;const r=vg._origin;r.set(e,t,-1),this.context.input.convertScreenspaceToRaycastSpace(r),zB&&console.log("screenPointToRay",e.toFixed(2),t.toFixed(2),"now:",r.x.toFixed(2),r.y.toFixed(2),"isInXR:"+this.context.isInXR),r.z=-1,r.unproject(s);const o=vg._direction.set(r.x,r.y,r.z),a=wt(s);return o.sub(a),o.normalize(),i?(i.set(a,o),i):new Gl(a.clone(),o.clone())}awake(){zB&&window.addEventListener("pointerdown",e=>{const t=e.clientX,i=e.clientY;console.log("touch",t.toFixed(2),i.toFixed(2));const s=this.screenPointToRay(t,i),r="#"+Math.floor(Math.random()*16777215).toString(16);xa.DrawRay(s.origin,s.direction,r,10)})}onEnable(){Ag&&console.log(this),this.buildCamera(),(this.tag=="MainCamera"||!this.context.mainCameraComponent)&&(this.context.setCurrentCamera(this),zee(this)),this.applyClearFlagsIfIsActiveCamera()}onDisable(){this.context.removeCamera(this)}onBeforeRender(){if(this._cam&&this._targetTexture){this.context.isManagedExternally&&(this._warnedAboutExternalRenderer||(this._warnedAboutExternalRenderer=!0,console.warn("Rendering with external renderer is not supported yet. This may not work or throw errors. Please remove the the target texture from your camera: "+this.name,this.targetTexture))),this.context.composer;const e=this.context.renderer;e&&this._targetTexture.render(this.context.scene,this._cam,e)}}buildCamera(){if(this._cam)return;const e=this.gameObject.isCamera;let t=null;if(e?(t=this.gameObject,t==null||t.layers.enableAll(),t instanceof $t&&(this._fov=t.fov)):t=this.gameObject.children[0],t&&t.isCamera)t.type==="PerspectiveCamera"&&(this._fov&&(t.fov=this._fov),t.near=this._nearClipPlane,t.far=this._farClipPlane,t.updateProjectionMatrix());else if(!this.orthographic)t=new $t(this.fieldOfView,window.innerWidth/window.innerHeight,this._nearClipPlane,this._farClipPlane),this.fieldOfView&&(t.fov=this.fieldOfView),this.gameObject.add(t);else{const i=this.orthographicSize*100;t=new Rf(window.innerWidth/-i,window.innerWidth/i,window.innerHeight/i,window.innerHeight/-i,this._nearClipPlane,this._farClipPlane),this.gameObject.add(t)}this._cam=t,this._cam.layers.mask=this._cullingMask,this.tag=="MainCamera"&&this.context.setCurrentCamera(this)}applyClearFlagsIfIsActiveCamera(){this.context.mainCameraComponent===this&&this.applyClearFlags()}applyClearFlags(){if(!this._cam){Ag&&console.log("Camera does not exist (apply clear flags)");return}switch(Ag&&jn("apply Camera clear flags: "+this._clearFlags),this._clearFlags){case 1:if(vg.backgroundShouldBeTransparent(this.context)&&(!this.ARBackgroundAlpha||this.ARBackgroundAlpha<.001)){this.context.scene.background=null,this.context.renderer.setClearColor(0,0);return}this.enableSkybox(),this._backgroundBlurriness!==void 0&&(this.context.scene.backgroundBlurriness=this._backgroundBlurriness),this._backgroundIntensity!==void 0&&(this.context.scene.backgroundIntensity=this._backgroundIntensity);break;case 2:if(this._backgroundColor){let e=this._backgroundColor.alpha;vg.backgroundShouldBeTransparent(this.context)&&(e=this.ARBackgroundAlpha??0),this.context.scene.background=null,this.context.renderer.setClearColor(this._backgroundColor,e)}break;case 4:this.context.scene.background=null,this.context.renderer.setClearColor(0,0);break}}enableSkybox(){this._skybox||(this._skybox=new Nee(this)),this._skybox.enable()}static backgroundShouldBeTransparent(e){var r,o,a,l;const t=(r=e.renderer.xr)==null?void 0:r.getSession();if(!t)return!1;const i=t.environmentBlendMode;Ag&&jn("Environment blend mode: "+i+" on "+navigator.userAgent);const s=i==="additive"||i==="alpha-blend";if(e.xrSessionMode===ym.ImmersiveAR&&i==="opaque"){if((o=navigator.userAgent)!=null&&o.includes("OculusBrowser"))return!0;if((a=navigator.userAgent)!=null&&a.includes("Mozilla")&&((l=navigator.userAgent)!=null&&l.includes("Mobile WebXRViewer/v2")))return!0}return s}},u(Ly,"_origin",new S),u(Ly,"_direction",new S),Ly);let Oi=vg;mo([w()],Oi.prototype,"fieldOfView",1);mo([w()],Oi.prototype,"nearClipPlane",1);mo([w()],Oi.prototype,"farClipPlane",1);mo([w()],Oi.prototype,"clearFlags",1);mo([w()],Oi.prototype,"orthographic",2);mo([w()],Oi.prototype,"orthographicSize",2);mo([w()],Oi.prototype,"ARBackgroundAlpha",2);mo([w()],Oi.prototype,"cullingMask",1);mo([w()],Oi.prototype,"backgroundBlurriness",1);mo([w()],Oi.prototype,"backgroundIntensity",1);mo([w(xi)],Oi.prototype,"backgroundColor",1);mo([w(Hc)],Oi.prototype,"targetTexture",1);class Nee{constructor(e){u(this,"_camera");u(this,"_skybox");this._camera=e}get context(){var e;return(e=this._camera)==null?void 0:e.context}enable(){this._skybox=this.context.lightmaps.tryGetSkybox(this._camera.sourceId),this._skybox?this.context.scene.background!==this._skybox&&(Ag&&console.log("Set skybox",this._camera,this._skybox),this._skybox.encoding=yt,this._skybox.mapping=oo,this.context.scene.background=this._skybox):console.warn("Failed to load/find skybox texture",this._camera.sourceId,this.context.lightmaps)}}function zee(n){le("freecam")&&n.context.mainCameraComponent===n&&$.getOrAddComponent(n.gameObject,ql)}class Tf extends Ce{constructor(){super(...arguments);u(this,"_listener",null)}get listener(){return this._listener==null&&(this._listener=new A1),this._listener}awake(){xn.registerWaitForAllowAudio(()=>{if(this.destroyed)return;const t=this.listener;if(t==null||t.parent)return;const i=$.getComponentInParent(this.gameObject,Oi);i?i.cam.add(t):this.gameObject.add(t)})}}var Gee=Object.defineProperty,Qee=Object.getOwnPropertyDescriptor,Qb=(n,e,t,i)=>{for(var s=i>1?void 0:i?Qee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Gee(e,t,s),s};class DA{constructor(){u(this,"guid")}}Qb([w()],DA.prototype,"guid",2);class dp{constructor(){u(this,"signal");u(this,"reaction")}}Qb([w(DA)],dp.prototype,"signal",2);Qb([w(ar)],dp.prototype,"reaction",2);var CC;const rl=(CC=class extends Ce{constructor(){super(...arguments);u(this,"events")}static invoke(e){if(rl.receivers[e]){const t=rl.receivers[e];if(!t)return;for(const i of t)i.invoke(e)}}onEnable(){if(this.events)for(const e of this.events)rl.receivers[e.signal.guid]||(rl.receivers[e.signal.guid]=[]),rl.receivers[e.signal.guid].push(this)}onDisable(){if(this.events){for(const e of this.events)if(rl.receivers[e.signal.guid]){const t=rl.receivers[e.signal.guid].indexOf(this);t>=0&&rl.receivers[e.signal.guid].splice(t,1)}}}invoke(e){if(!this.events||!Array.isArray(this.events))return;let t=typeof e=="object"?e.guid:e;for(const i of this.events)if(i.signal.guid===t)try{if(i.reaction){if(!i.reaction.invoke){console.warn("Missing invoke - possibly a serialization error",i,this);continue}}else{console.warn("Missing reaction for signal",i,this);continue}i.reaction.invoke()}catch(s){console.error(s)}}},u(CC,"receivers",{}),CC);let fp=rl;Qb([w(dp)],fp.prototype,"events",2);var Ar=(n=>(n.Activation="ActivationTrack",n.Animation="AnimationTrack",n.Audio="AudioTrack",n.Control="ControlTrack",n.Marker="MarkerTrack",n.Signal="SignalTrack",n))(Ar||{}),Ec=(n=>(n[n.None=0]="None",n[n.Hold=1]="Hold",n[n.Loop=2]="Loop",n[n.PingPong=3]="PingPong",n[n.Continue=4]="Continue",n))(Ec||{}),JI=(n=>(n.Signal="SignalEmitter",n))(JI||{});const $p=le("debugtimeline"),C_=class extends Ce{constructor(){super(...arguments);u(this,"playableAsset");u(this,"playOnAwake");u(this,"extrapolationMode",1);u(this,"waitForAudio",!0);u(this,"_visibilityChangeEvt");u(this,"_clonedPlayableAsset",!1);u(this,"_speed",1);u(this,"_guidsMap");u(this,"_isPlaying",!1);u(this,"_internalUpdateRoutine");u(this,"_isPaused",!1);u(this,"_time",0);u(this,"_duration",0);u(this,"_weight",1);u(this,"_animationTracks",[]);u(this,"_audioTracks",[]);u(this,"_signalTracks",[]);u(this,"_controlTracks",[]);u(this,"_customTracks",[]);u(this,"_allTracks",[this._animationTracks,this._audioTracks,this._signalTracks,this._controlTracks,this._customTracks])}static registerCreateTrack(t,i){this.createTrackFunctions[t]=i}get isPlaying(){return this._isPlaying}get isPaused(){return this._isPaused}get time(){return this._time}set time(t){typeof t=="number"&&!Number.isNaN(t)?this._time=t:($p||zs())&&console.error("INVALID TIMELINE.TIME VALUE",t,this.name)}get duration(){return this._duration}set duration(t){this._duration=t}get weight(){return this._weight}set weight(t){this._weight=t}get speed(){return this._speed}set speed(t){this._speed=t}awake(){var t,i,s;$p&&console.log(this,(t=this.playableAsset)==null?void 0:t.tracks),this.rebuildGraph(),this.isValid()||console.warn("PlayableDirector is not valid",this.playableAsset,(i=this.playableAsset)==null?void 0:i.tracks,Array.isArray((s=this.playableAsset)==null?void 0:s.tracks),this)}onEnable(){var t,i;for(const s of this._audioTracks)(t=s.onEnable)==null||t.call(s);for(const s of this._customTracks)(i=s.onEnable)==null||i.call(s);this.playOnAwake&&this.play(),this._visibilityChangeEvt||(this._visibilityChangeEvt=()=>{switch(document.visibilityState){case"hidden":this.setAudioTracksAllowPlaying(!1);break;case"visible":this.setAudioTracksAllowPlaying(!0);break}}),window.addEventListener("visibilitychange",this._visibilityChangeEvt)}onDisable(){var t,i;this.stop();for(const s of this._audioTracks)(t=s.onDisable)==null||t.call(s);for(const s of this._customTracks)(i=s.onDisable)==null||i.call(s);this._visibilityChangeEvt&&window.removeEventListener("visibilitychange",this._visibilityChangeEvt)}onDestroy(){var t;for(const i of this._allTracks)for(const s of i)(t=s.onDestroy)==null||t.call(s)}rebuildGraph(){this.isValid()&&(this.resolveBindings(),this.updateTimelineDuration(),this.setupAndCreateTrackHandlers())}async play(){if(!this.isValid())return;const t=this._isPaused==!0;if(this._isPaused=!1,t&&this.invokePauseChangedMethodsOnTracks(),!this._isPlaying){if(this._isPlaying=!0,this.waitForAudio){const i=[];for(const s of this._audioTracks){const r=s.loadAudio(this._time,1,0);r&&i.push(r)}if(i.length>0&&(await Promise.all(i),!this._isPlaying))return;for(;this._audioTracks.length>0&&this._isPlaying&&!xn.userInteractionRegistered&&this.waitForAudio;)await jm(200)}this._internalUpdateRoutine=this.startCoroutine(this.internalUpdate())}}pause(){this.isValid()&&(this._isPlaying=!1,!this._isPaused&&(this._isPaused=!0,this.evaluate(),this.invokePauseChangedMethodsOnTracks()))}stop(){for(const s of this._audioTracks)s.stop();const t=this._isPaused==!0,i=this._isPlaying;this._isPlaying&&(this._time=0,this._isPlaying=!1,this._isPaused=!1,this.evaluate(),t&&this.invokePauseChangedMethodsOnTracks()),this._isPlaying=!1,this._isPaused=!1,t&&!i&&this.invokePauseChangedMethodsOnTracks(),this._internalUpdateRoutine&&this.stopCoroutine(this._internalUpdateRoutine),this._internalUpdateRoutine=null}evaluate(){if(!this.isValid())return;let t=this._time;switch(this.extrapolationMode){case 0:this._speed>0?t=Math.min(t,this._duration):this._speed<0&&(t=Math.max(t,0)),this._time=t;break;case 1:t%=this._duration,this._time=t;break;case 2:if(t>this._duration){this.stop();return}break}this.internalEvaluate(t)}isValid(){return this.playableAsset&&this.playableAsset.tracks&&Array.isArray(this.playableAsset.tracks)}*forEachTrack(){for(const t of this._allTracks)for(const i of t)yield i}get audioTracks(){return this._audioTracks}resolveGuids(t){this._guidsMap=t}invokePauseChangedMethodsOnTracks(){var t;for(const i of this.forEachTrack())(t=i.onPauseChanged)==null||t.call(i)}*internalUpdate(){for(;this._isPlaying&&this.activeAndEnabled;)!this._isPaused&&this._isPlaying&&(this._time+=this.context.time.deltaTime*this.speed,this.evaluate()),yield}internalEvaluate(t){for(const i of this.playableAsset.tracks)if(!i.muted)switch(i.type){case Ar.Activation:for(let s=0;s<i.outputs.length;s++){const r=i.outputs[s];if(typeof r=="object"){let o=!1;for(const l of i.clips)l.start<=t&&t<=l.end&&(o=!0);const a=r;a.visible!==void 0&&(a.visible=o)}}break}for(const i of this._animationTracks)i.evaluate(t);for(const i of this._audioTracks)i.evaluate(t);for(const i of this._signalTracks)i.evaluate(t);for(const i of this._controlTracks)i.evaluate(t);for(const i of this._customTracks)i.evaluate(t)}resolveBindings(){if(this._clonedPlayableAsset||(this._clonedPlayableAsset=!0,this.playableAsset=E_(this.playableAsset)),!this.playableAsset||!this.playableAsset.tracks)return;const t=this.findRoot(this.gameObject);for(const i of this.playableAsset.tracks){for(let s=i.outputs.length-1;s>=0;s--){let r=i.outputs[s];if(typeof r=="string"){this._guidsMap&&this._guidsMap[r]&&(r=this._guidsMap[r]);const o=$.findByGuid(r,t);o===null||typeof o!="object"?(i.outputs.splice(s,1),console.warn("Failed to resolve binding",r,i.name,i.type)):($p&&console.log("Resolved binding",r,"to",o),i.outputs[s]=o)}else if(r===null){if(i.outputs.splice(s,1),C_.createTrackFunctions[i.type])continue;i.type!==Ar.Audio&&i.type!==Ar.Control&&i.type!==Ar.Marker&&i.type!==Ar.Signal&&console.warn("Missing binding",r,i.name,i.type,this.name,this.playableAsset.name)}}if(i.type===Ar.Control)for(let s=0;s<i.clips.length;s++){const r=i.clips[s];let o=r.asset.sourceObject;if(typeof o=="string"){this._guidsMap&&this._guidsMap[o]&&(o=this._guidsMap[o]);const a=$.findByGuid(o,t);a===null||typeof a!="object"?console.warn("Failed to resolve sourceObject binding",o,i.name,r):($p&&console.log("Resolved binding",o,"to",a),r.asset.sourceObject=a)}}}}findRoot(t){return t.parent?this.findRoot(t.parent):t}updateTimelineDuration(){if(this._duration=0,!(!this.playableAsset||!this.playableAsset.tracks)){for(const t of this.playableAsset.tracks)if(t.muted!==!0){for(const i of t.clips)i.end>this._duration&&(this._duration=i.end);for(const i of t.markers)i.time>this._duration&&(this._duration=i.time+.001)}}}setupAndCreateTrackHandlers(){var i,s;if(this._animationTracks.length=0,this._audioTracks.length=0,this._signalTracks.length=0,!this.playableAsset)return;const t=$.findObjectOfType(Tf,this.context);for(const r of this.playableAsset.tracks){const o=r.type,a=C_.createTrackFunctions[o];if(a!=null){const l=a(this,r);if(typeof l.evaluate=="function"){l.director=this,l.track=r,this._customTracks.push(l);continue}}if(r.type===Ar.Animation){if(r.clips.length<=0){$p&&console.warn("Animation track has no clips",r);continue}for(let l=r.outputs.length-1;l>=0;l--){let c=r.outputs[l];if(c instanceof Ie){const d=$.getOrAddComponent(c,hr);d&&(c=d)}const h=(i=c==null?void 0:c.gameObject)==null?void 0:i.animations;if(h){const d=new Hb;d.trackOffset=r.trackOffset,d.director=this,d.track=r;for(let f=0;f<r.clips.length;f++){const p=r.clips[f],g=p.asset;if(!g){console.error("MISSING anim model?","clip#"+f,p,r,this.playableAsset,this.name);continue}const m=g.clip;let A=m;if((typeof A=="string"||typeof A=="number")&&(A=h.find(b=>b.name===m)),!A){console.warn("Could not find animationClip for model",p,r.name,this.name,(s=this.playableAsset)==null?void 0:s.name);continue}d.mixer||(d.mixer=new $_(c.gameObject)),d.clips.push(A),d.mixer.uncacheAction(A),d.createHooks(p.asset,A);const v=d.mixer.clipAction(A);d.actions.push(v),d.models.push(p)}this._animationTracks.push(d)}}}else if(r.type===Ar.Audio){if(r.clips.length<=0)continue;const l=new hu;if(l.director=this,l.track=r,this._audioTracks.push(l),!t)continue;l.listener=t.listener;for(let c=0;c<r.clips.length;c++){const h=r.clips[c];l.addModel(h)}}else if(r.type===Ar.Marker){const l=new Om;l.director=this,l.track=r;for(const c of r.markers)switch(c.type){case JI.Signal:l.models.push(c),l.didTrigger.push(!1);break}if(l!==null&&l.models.length>0){const c=$.getComponent(this.gameObject,fp);c&&(l.receivers.push(c),this._signalTracks.push(l))}}else if(r.type===Ar.Signal){const l=new Om;l.director=this,l.track=r;for(const c of r.markers)l.models.push(c),l.didTrigger.push(!1);for(const c of r.outputs)l.receivers.push(c);this._signalTracks.push(l)}else if(r.type===Ar.Control){const l=new Vb;l.director=this,l.track=r;for(const c of r.clips)l.models.push(c);l.resolveSourceObjects(this.context),this._controlTracks.push(l)}}}setAudioTracksAllowPlaying(t){for(const i of this._audioTracks)i.onAllowAudioChanged(t)}};let lu=C_;u(lu,"createTrackFunctions",{});const cu=le("debugtimeline");class kA{constructor(){u(this,"director");u(this,"track")}get muted(){return this.track.muted}set muted(e){var t;e!==this.track.muted&&(this.track.muted=e,(t=this.onMuteChanged)==null||t.call(this))}*forEachClip(e=!1){var t;if((t=this.track)!=null&&t.clips)if(e)for(let i=this.track.clips.length-1;i>=0;i--)yield this.track.clips[i];else for(const i of this.track.clips)yield i}getClipTime(e,t){return t.clipIn+(e-t.start)*t.timeScale}getClipTimeNormalized(e,t){return(e-t.start)/t.duration}evaluateWeight(e,t,i,s=!0){if(t<0||t>=i.length)return 0;const r=i[t];if(s||e>=r.start&&e<=r.end){let o=1,a=!1;if(r.easeInDuration>0){const l=Math.min((e-r.start)/r.easeInDuration,1);o*=l}if(r.easeOutDuration>0&&!a){const l=Math.min((r.end-e)/r.easeOutDuration,1);o*=l}return o}return 0}}class Hee{constructor(e){u(this,"clip");u(this,"rootPositionOffset");u(this,"rootQuaternionOffset");u(this,"rootStartPosition");u(this,"rootEndPosition");u(this,"rootStartQuaternion");u(this,"rootEndQuaternion");const t=e.getClip();this.clip=t;const i=e.getRoot(),s=i.name+".position",r=i.name+".quaternion";cu&&console.log(t.name,t.tracks,s);for(const o of t.tracks)if(!(o.times.length<=0)){if(o.name.endsWith(s))this.rootStartPosition=new S().fromArray(o.values,0),this.rootEndPosition=new S().fromArray(o.values,o.values.length-3),this.rootPositionOffset=this.rootEndPosition.clone().sub(this.rootStartPosition),cu&&console.log(this.rootPositionOffset);else if(o.name.endsWith(r)&&(this.rootStartQuaternion=new xe().fromArray(o.values,0),this.rootEndQuaternion=new xe().fromArray(o.values,o.values.length-4),this.rootQuaternionOffset=this.rootEndQuaternion.clone().multiply(this.rootStartQuaternion),cu)){const a=new bn().setFromQuaternion(this.rootQuaternionOffset);console.log("ROT",a)}}}get hasOffsets(){return this.rootPositionOffset!==void 0||this.rootQuaternionOffset!==void 0}}class Hb extends kA{constructor(){super(...arguments);u(this,"models",[]);u(this,"trackOffset");u(this,"target");u(this,"mixer");u(this,"clips",[]);u(this,"actions",[]);u(this,"_actionOffsets",[]);u(this,"_didBind",!1);u(this,"_animator",null);u(this,"_animatorWasEnabled",!1);u(this,"_useclipOffsets",!0);u(this,"_totalOffsetPosition",new S);u(this,"_totalOffsetRotation",new xe);u(this,"_totalOffsetPosition2",new S);u(this,"_totalOffsetRotation2",new xe);u(this,"_summedPos",new S);u(this,"_tempPos",new S);u(this,"_summedRot",new xe);u(this,"_tempRot",new xe);u(this,"_clipRotQuat",new xe)}onPauseChanged(){this._animator&&this._animatorWasEnabled!==void 0&&(this._animator.enabled=this.director.isPlaying===!1?this._animatorWasEnabled:!1)}createHooks(t,i){var h,d;if(((h=i.tracks)==null?void 0:h.length)<=0){console.warn("No tracks in AnimationClip",i);return}const s=i.tracks[0].name.split("."),r=s[s.length-2],o=r+".position",a=r+".quaternion";let l=!1,c=!1;for(const f of i.tracks)f.name.endsWith(o)?(l=!0,this.createPositionInterpolant(i,t,f)):f.name.endsWith(a)&&(c=!0,this.createRotationInterpolant(i,t,f));if(!l||!c){const f=(d=this.mixer)==null?void 0:d.getRoot(),p=i.tracks[0],g=p.name.lastIndexOf("."),m=p.name.substring(0,g),A=m.substring(m.lastIndexOf(".")+1),v=f.getObjectByName(A);if(v)if(l){if(!c){const b=i.tracks[0].name.substring(0,g)+".quaternion";cu&&console.warn("Create quaternion track",A,v);const y=v.quaternion,_=new Oa(b,[0,i.duration],[y.x,y.y,y.z,y.w,y.x,y.y,y.z,y.w]);i.tracks.push(_),this.createRotationInterpolant(i,t,_)}}else{const b=m+".position";cu&&console.warn("Create position track",A,v);const y=v.position,_=new Yc(b,[0,i.duration],[y.x,y.y,y.z,y.x,y.y,y.z]);i.tracks.push(_),this.createPositionInterpolant(i,t,_)}}}bind(){if(!this._didBind){this._didBind=!0,cu&&console.log(this.models),this.mixer?this.target=this.mixer.getRoot():console.warn("No mixer was assigned to animation track");for(const t of this.actions){const i=new Hee(t);this._actionOffsets.push(i)}this.target&&(this._animator=$.getComponent(this.target,hr)??null,this._animator?(this._animatorWasEnabled=this._animator.enabled,this._animator.enabled=!1):this._animatorWasEnabled=!1);for(const t of this.models){const i=t.asset,s=i.position,r=i.rotation;s&&s.x!==void 0&&(s.isVector3||(i.position=new S(s.x,s.y,s.z)),r.isQuaternion||(i.rotation=new xe(r.x,r.y,r.z,r.w)))}this.ensureTrackOffsets()}}ensureTrackOffsets(){if(this.trackOffset){const t=this.trackOffset.position;t&&(t.isVector3||(this.trackOffset.position=new S(t.x,t.y,t.z)));const i=this.trackOffset.rotation;i&&(i.isQuaternion||(this.trackOffset.rotation=new xe(i.x,i.y,i.z,i.w)))}}evaluate(t){if(this.track.muted||!this.mixer)return;this.bind(),this._animator&&this.director.isPlaying&&this.director.weight>0&&(this._animator.enabled=!1),this._totalOffsetPosition.set(0,0,0),this._totalOffsetRotation.set(0,0,0,1),this._totalOffsetPosition2.set(0,0,0),this._totalOffsetRotation2.set(0,0,0,1);let i=0,s=0,r=!1,o=!1;for(let a=0;a<this.clips.length;a++){const l=this.models[a],c=this.actions[a],h=l.asset;c.weight=0;const d=t>=l.start&&t<=l.end,f=l.preExtrapolationMode,p=l.postExtrapolationMode,g=a<this.clips.length-1?this.models[a+1]:null;let m=d,A=!1;if(!m&&!r&&l.end<t&&p!==Ec.None?(!g||g.start>t)&&(m=!0,r=!0):a==0&&!m&&!o&&l.start>t&&f!==Ec.None&&(!g||g.start<t)&&(m=!0,A=!0,o=!0),m){let v=1;v*=this.evaluateWeight(t,a,this.models,m),v*=this.director.weight;let b=d;A&&f!==Ec.Hold&&(t+=l.start,b=!0);let y=this.getClipTime(t,l),_=0;const C=h.duration;if(A&&f===Ec.Hold&&(y=0),b){if(h.loop)for(_+=Math.floor(y/(C+1e-6));y>C;)y-=C}else if(!d)switch(p){case Ec.Loop:y%=C;break;case Ec.PingPong:const x=Math.floor(y/C)%2!==0;y%=C,x&&(y=C-y);break}l.reversed===!0?c.time=c.getClip().duration-y:c.time=y,c.timeScale=0;const E=v;if(c.weight=E,c.clampWhenFinished=!0,c.isRunning()||c.play(),this._useclipOffsets){const T=i==0?this._totalOffsetPosition:this._totalOffsetPosition2,x=i==0?this._totalOffsetRotation:this._totalOffsetRotation2;i<1&&(s=1-v),i+=1;const M=this._summedPos.set(0,0,0),P=this._tempPos.set(0,0,0),k=this._summedRot.identity(),G=this._tempRot.identity(),z=h.rotation;z&&(this._clipRotQuat.identity(),this._clipRotQuat.slerp(z,v));const L=this._actionOffsets[a];if(L.hasOffsets)for(let H=0;H<_;H++)L.rootPositionOffset?P.copy(L.rootPositionOffset):P.set(0,0,0),P.applyQuaternion(k),this._clipRotQuat&&P.applyQuaternion(this._clipRotQuat),L.rootQuaternionOffset&&(G.copy(L.rootQuaternionOffset),k.multiply(G)),M.add(P);this._clipRotQuat&&x.multiply(this._clipRotQuat),x.multiply(k),h.position&&M.add(h.position),T.add(M)}}}this._useclipOffsets&&(this._totalOffsetPosition.lerp(this._totalOffsetPosition2,s),this._totalOffsetRotation.slerp(this._totalOffsetRotation2,s)),this.mixer.update(t)}createRotationInterpolant(t,i,s){var l;const r=s.createInterpolant.bind(s),o=new xe;this.ensureTrackOffsets();const a=(l=this.trackOffset)==null?void 0:l.rotation;s.createInterpolant=()=>{const c=r(),h=c.evaluate.bind(c);return c.evaluate=d=>{const f=h(d);return o.set(f[0],f[1],f[2],f[3]),o.premultiply(this._totalOffsetRotation),a&&o.premultiply(a),f[0]=o.x,f[1]=o.y,f[2]=o.z,f[3]=o.w,f},c}}createPositionInterpolant(t,i,s){var h,d;const r=s.createInterpolant.bind(s),o=new S;this.ensureTrackOffsets();const a=(h=this.trackOffset)==null?void 0:h.rotation,l=(d=this.trackOffset)==null?void 0:d.position;let c;s.createInterpolant=()=>{const f=r(),p=f.evaluate.bind(f);return f.evaluate=g=>{var A,v;const m=p(g);return o.set(m[0],m[1],m[2]),i.removeStartOffset&&(c===void 0?(c=null,c=(v=(A=this._actionOffsets.find(b=>b.clip===t))==null?void 0:A.rootStartPosition)==null?void 0:v.clone()):c!=null&&c.isVector3&&o.sub(c)),o.applyQuaternion(this._totalOffsetRotation),o.add(this._totalOffsetPosition),a&&o.applyQuaternion(a),l&&(o.x-=l.x,o.y+=l.y,o.z+=l.z),m[0]=o.x,m[1]=o.y,m[2]=o.z,m},f}}}const Vee=le("mutetimeline"),Zd=class extends kA{constructor(){super(...arguments);u(this,"models",[]);u(this,"listener");u(this,"audio",[]);u(this,"audioContextTimeOffset",[]);u(this,"lastTime",0);u(this,"_audioLoader",null)}getAudioFilePath(t){const i=this.director.sourceId;return $c(i,t)}onAllowAudioChanged(t){for(let i=0;i<this.models.length;i++){const s=this.models[i];this.audio[i].setVolume(t?s.asset.volume:0)}}addModel(t){const i=new Z_(this.listener);this.audio.push(i),this.models.push(t)}onDisable(){for(const t of this.audio)t.isPlaying&&t.stop()}onMuteChanged(){if(this.muted)for(let t=0;t<this.audio.length;t++){const i=this.audio[t];i!=null&&i.isPlaying&&i.stop()}}stop(){for(let t=0;t<this.audio.length;t++){const i=this.audio[t];i!=null&&i.isPlaying&&i.stop()}}evaluate(t){if(Vee||this.track.muted||this.director.speed<0)return;const i=this.director.context.application.muted,s=i?.1:0;for(let r=0;r<this.models.length;r++){const o=this.models[r],a=this.audio[r];if((!a||!a.buffer)&&this.isInTimeRange(o,t-1,t+1)&&this.handleAudioLoading(o,a),xn.userInteractionRegistered!==!1&&!(a===null||!a.buffer))if(a.playbackRate=this.director.context.time.timeScale,a.loop=o.asset.loop,t>=o.start&&t<=o.end&&t<this.director.duration){if(this.director.isPlaying==!1){if(a.isPlaying&&a.stop(),this.lastTime===t)continue}else if(!a.isPlaying)a.offset=o.clipIn+(t-o.start)*o.timeScale,a.play(s);else{const c=o.clipIn+(t-o.start)*o.timeScale,h=a.context.currentTime-a._startedAt+a.offset;Math.abs(c-h)>.3&&(a.offset=c,a.stop(),a.play(s))}let l=o.asset.volume;if(i&&(l=0),o.easeInDuration>0){const c=Math.min((t-o.start)/o.easeInDuration,1);l*=c}if(o.easeOutDuration>0){const c=Math.min((o.end-t)/o.easeOutDuration,1);l*=c}a.setVolume(l*this.director.weight)}else a.isPlaying&&a.stop()}this.lastTime=t}loadAudio(t,i=0,s=0){let r=null;const o=t-s,a=t+i;for(const l of this.models)if(this.isInTimeRange(l,o,a)){const c=this.audio[this.models.indexOf(l)],h=this.handleAudioLoading(l,c);h!==null&&(r===null&&(r=[]),r.push(h))}return r!==null?Promise.all(r):null}isInTimeRange(t,i,s){return i<=t.start&&s>=t.end||i>=t.start&&i<=t.end||s>=t.start&&s<=t.end}static dispose(){Zd._currentlyLoading.clear()}handleAudioLoading(t,i){this._audioLoader||(this._audioLoader=new F0);const s=this.getAudioFilePath(t.asset.clip);if(Zd._currentlyLoading.get(s)){const o=Zd._currentlyLoading.get(s);return o.then(a=>{a&&i.setBuffer(a)}),o}cu&&console.warn("LOAD audio track",s,this.director.sourceId);const r=new Promise((o,a)=>{this._audioLoader.load(s,l=>{i.setBuffer(l),o(l)},void 0,l=>{console.error("Error loading audio",l),o(null)})});return Zd._currentlyLoading.set(s,r),r}};let hu=Zd;u(hu,"_currentlyLoading",new Map);class Om extends kA{constructor(){super(...arguments);u(this,"models",[]);u(this,"didTrigger",[]);u(this,"receivers",[])}evaluate(t){var i;if(!this.track.muted)for(let s=0;s<this.models.length;s++){const r=this.models[s],o=this.didTrigger[s],a=r.time-t;let l=!1;if(r.retroActive)l=a<=1e-6;else{const c=Math.abs(a);c>=1e-5&&c<.1&&(l=!0)}if(l){if(!o)if(this.didTrigger[s]=!0,((i=this.receivers)==null?void 0:i.length)<=0)fp.invoke(r.asset);else for(const c of this.receivers)c&&c.invoke(r.asset)}else r.emitOnce||(this.didTrigger[s]=!1)}}}class Vb extends kA{constructor(){super(...arguments);u(this,"models",[]);u(this,"timelines",[]);u(this,"_previousActiveModel",null)}resolveSourceObjects(t){for(let i=this.models.length-1;i>=0;i--){const r=this.models[i].asset;if(!r.sourceObject||typeof r.sourceObject!="object"){console.log("no source object, removing model",i,r),this.models.splice(i,1);continue}else{const o=$.getComponent(r.sourceObject,lu);this.timelines.push(o),o&&r.updateDirector&&(o.playOnAwake=!1)}}}evaluate(t){var i;this._previousActiveModel=null;for(let s=0;s<this.models.length;s++){const r=this.models[s],o=r.asset;if(t>=r.start&&t<=r.end){this._previousActiveModel=r;const a=this.getClipTime(t,r);if(o.controlActivation){const l=o.sourceObject;l.visible=!0}if(o.updateDirector){const l=this.timelines[s];l&&(l.isPlaying&&l.pause(),l.time=a,l.evaluate())}}else{const a=(i=this._previousActiveModel)==null?void 0:i.asset;if(o.controlActivation){const l=o.sourceObject;(a==null?void 0:a.sourceObject)!==l&&(l.visible=!1)}}}}}var jee=Object.defineProperty,Wee=Object.getOwnPropertyDescriptor,_N=(n,e,t,i)=>{for(var s=i>1?void 0:i?Wee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&jee(e,t,s),s};class Ft{constructor(e){u(this,"_active",!0);u(this,"_value");u(this,"_valueRaw");u(this,"_defaultValue");u(this,"valueProcessor");u(this,"onValueChanged");this._value=e,this._defaultValue=e}get overrideState(){return this._active}set overrideState(e){if(this._active===e)return;this._active=e;const t=e?this._valueRaw:this._defaultValue;this.processValue(t,!0)}get value(){return this._valueRaw}set value(e){this.processValue(e,!1)}set defaultValue(e){this._defaultValue=e}__init(){this.processValue(this._valueRaw,!0)}processValue(e,t){if(e==null||!t&&this.testIfValueChanged(e)===!1)return;const i=this._value;!this._active&&this._defaultValue!==void 0?(this._value=this._defaultValue,e=this._defaultValue,this._valueRaw=e):(this._valueRaw=e,this._active&&this.valueProcessor&&(e=this.valueProcessor(e)),this._value=e),this.onValueChanged&&this.onValueChanged(e,i,this)}testIfValueChanged(e){return this._valueRaw!==e}}_N([w()],Ft.prototype,"overrideState",1);_N([w()],Ft.prototype,"value",1);var qee=Object.defineProperty,Xee=Object.getOwnPropertyDescriptor,Yee=(n,e,t,i)=>{for(var s=i>1?void 0:i?Xee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&qee(e,t,s),s};const Jee=le("debugpost");class js extends sh{constructor(){super(...arguments);u(this,"active",!0);u(this,"_result")}onEnable(){this.__internalDidAwakeAndStart&&(this.active=!0)}onDisable(){this.active=!1}init(){}apply(){var t;return this._result||(this._result=(t=this.onCreateEffect)==null?void 0:t.call(this)),this._result&&this.initParameters(),this._result}unapply(){}dispose(){Jee&&console.warn("DISPOSE",this),this._result&&(Array.isArray(this._result)?this._result.forEach(t=>t.dispose()):this._result.dispose()),this._result=void 0}initParameters(){const t=Object.keys(this);for(const i of t){const s=this[i];s instanceof Ft&&s.__init()}}onAfterDeserialize(t,i){if(typeof t=="object"){const s=this.$serializedTypes;if(s){for(const r of Object.keys(s))if(s[r]===Ft){const a=t[r];if(a!==void 0){const l=this[r];l.value=a}}}}}onEditorModification(t){const i=t.propertyName;if(this[i]instanceof Ft){const s=t.value;return this[i].value=s,!0}}}Yee([w()],js.prototype,"active",2);var Kee=Object.defineProperty,Zee=Object.getOwnPropertyDescriptor,$ee=(n,e,t,i)=>{for(var s=i>1?void 0:i?Zee(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Kee(e,t,s),s};const ete=le("debugpost"),oE={};function Na(n,e){oE[n]=e}function tte(n){return n.__type in oE?oE[n.__type]:(ete&&n.__type&&console.warn("Unknown postprocessing type",n.__type,n),js)}class OA{constructor(){u(this,"components")}init(){var e;(e=this.components)==null||e.forEach(t=>t.init())}}$ee([Xf([n=>tte(n),js])],OA.prototype,"components",2);var ite=Object.defineProperty,nte=Object.getOwnPropertyDescriptor,ste=(n,e,t,i)=>{for(var s=i>1?void 0:i?nte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&ite(e,t,s),s};class LA extends js{constructor(){super(...arguments);u(this,"preset")}get typeName(){return"Antialiasing"}onCreateEffect(){const t=new S7({preset:Ed.HIGH,edgeDetectionMode:L1.DEPTH});return this.preset.onValueChanged=i=>{t.applyPreset(i)},t}}ste([w(Ft)],LA.prototype,"preset",2);Na("Antialiasing",LA);class jb{constructor(){u(this,"files",[])}get extensionName(){return"Audio"}onExportObject(e,t,i){const s=$.getComponents(e,xn);if(s.length)for(const r of s){if(!r.playOnAwake)continue;const o=r.clip.split("/").pop();this.files.includes(r.clip)||this.files.push(r.clip),t.addEventListener("serialize",(a,l)=>{a.appendLine(),a.beginBlock(`def SpatialAudio "${t.name}"`),a.appendLine(`uniform asset filePath = @audio/${o}@`),a.appendLine(`uniform token auralMode = "${r.spatialBlend>0?"spatial":"nonSpatial"}"`),a.appendLine(`uniform token playbackMode = "${r.loop?"loopFromStage":"onceFromStart"}"`),a.appendLine(`uniform float gain = ${r.volume}`),a.closeBlock()})}}async onAfterSerialize(e){console.warn("onAfterSerialize",this);for(const t of this.files){const i=t.split("/").pop(),o=await(await(await fetch(t)).blob()).arrayBuffer(),a=new Uint8Array(o);e.files["audio/"+i]=a}}}var rte=Object.defineProperty,ote=Object.getOwnPropertyDescriptor,bN=(n,e,t,i)=>{for(var s=i>1?void 0:i?ote(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&rte(e,t,s),s};const ate=le("debugmouth");class FA extends Ce{constructor(){super(...arguments);u(this,"idle",[]);u(this,"talking",[]);u(this,"marker",null);u(this,"voip",null);u(this,"lastMouthChangeTime",0);u(this,"mouthChangeLength",0)}awake(){setTimeout(()=>{this.voip=$.findObjectOfType(Vl,this.context),this.marker||(this.marker=$.getComponentInParent(this.gameObject,Wn))},3e3)}update(){var s;if(!this.voip||this.context.time.frameCount%10!==0)return;let t=((s=this.marker)==null?void 0:s.connectionId)??null;if(!t){ate&&(t=null);return}const i=this.voip.getFrequency(t)??0;this.updateLips(i)}updateLips(t){if(this.context.time.time-this.lastMouthChangeTime>this.mouthChangeLength){if(this.mouthChangeLength=.05+Math.random()*.1,this.talking&&this.talking.length>0&&t>30){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.talking.length);this.setMouthShapeActive(this.talking,i)}else if(this.idle.length>0&&this.context.time.time-this.lastMouthChangeTime>.5){this.lastMouthChangeTime=this.context.time.time;const i=Math.floor(Math.random()*this.idle.length);this.setMouthShapeActive(this.idle,i)}}}setMouthShapeActive(t,i){if(t){t!=this.idle?this.idle.map(s=>s.visible=!1):this.talking.map(s=>s.visible=!1);for(let s=0;s<t.length;s++){const r=t[s];r&&(r.visible=s===i)}}}}bN([w(Ie)],FA.prototype,"idle",2);bN([w(Ie)],FA.prototype,"talking",2);class KI extends Ce{constructor(){super(...arguments);u(this,"voip",null);u(this,"marker",null);u(this,"_startPosition",null)}awake(){this.voip=$.findObjectOfType(Vl,this.context),this.marker=$.getComponentInParent(this.gameObject,Wn)}update(){if(!this.voip||!this.marker||this.context.time.frameCount%10!==0)return;const t=this.marker.connectionId,i=this.voip.getFrequency(t);if(i==null)return;this._startPosition||(this._startPosition=this.gameObject.position.clone());let s=i/100;this.gameObject.position.y=this._startPosition.y+s*.07}}var lte=Object.defineProperty,cte=Object.getOwnPropertyDescriptor,Wb=(n,e,t,i)=>{for(var s=i>1?void 0:i?cte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&<e(e,t,s),s};class Bu extends Ce{constructor(){super(...arguments);u(this,"eyes",[]);u(this,"lastBlinkTime",0);u(this,"blinkLength",0);u(this,"eyesOpen",!0);u(this,"state",null)}awake(){this.state=$.getComponentInParent(this.gameObject,ss)}update(){if(!this.gameObject||!this.gameObject.visible||!this.eyes||!Array.isArray(this.eyes)||this.eyes.length===0)return;if(this.context.time.time-this.lastBlinkTime>this.blinkLength){if(this.lastBlinkTime=this.context.time.time,this.state&&!this.state.isOn||!this.activeAndEnabled)return;if(this.eyesOpen=!this.eyesOpen,this.blinkLength=Math.random(),this.eyesOpen?(this.blinkLength*=3,this.blinkLength+=.5,Math.random()<.1&&(this.blinkLength=.1+Math.random()*.2)):(this.blinkLength*=Math.random()*.2,this.blinkLength+=.1),Math.random()<.1&&(this.blinkLength*=3),this.blinkLength=Math.max(.2,this.blinkLength),this.blinkLength=Math.min(3,this.blinkLength),this.eyes)for(const i of this.eyes)i&&(i.visible=this.eyesOpen)}}}Wb([w(Ie)],Bu.prototype,"eyes",2);Wb([w()],Bu.prototype,"lastBlinkTime",2);Wb([w()],Bu.prototype,"blinkLength",2);Wb([w()],Bu.prototype,"eyesOpen",2);var hte=Object.defineProperty,ute=Object.getOwnPropertyDescriptor,ZI=(n,e,t,i)=>{for(var s=i>1?void 0:i?ute(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&hte(e,t,s),s},SC;const xN=(SC=class extends Ce{constructor(){super(...arguments);u(this,"head",null);u(this,"eyes",null);u(this,"target",null);u(this,"brain",null);u(this,"vec",new S);u(this,"currentTargetPoint",new S)}awake(){this.brain||(this.brain=$.getComponentInParent(this.gameObject,Sm)),this.brain||(console.log("No look at brain found, adding it now"),this.brain=$.addNewComponent(this.gameObject,Sm)),this.brain&&this.target&&(this.brain.controlledTarget=this.target)}update(){const e=this.target;if(e&&this.head){const t=this.eyes;if(t){const i=wt(e);this.currentTargetPoint.lerp(i,this.context.time.deltaTime/.1);const s=wt(this.head),r=this.vec.copy(this.currentTargetPoint).sub(s).normalize();if(r.length()<.1)return;const o=xN.forward;if(o.set(0,0,1),o.applyQuaternion(Dn(this.head)),o.dot(r)>.45)for(let l=0;l<t.length;l++)t[l].lookAt(this.currentTargetPoint)}}}},u(SC,"forward",new S(0,0,1)),SC);let pp=xN;ZI([w(Ie)],pp.prototype,"head",2);ZI([w(Ie)],pp.prototype,"eyes",2);ZI([w(Ie)],pp.prototype,"target",2);var dte=Object.defineProperty,fte=Object.getOwnPropertyDescriptor,$I=(n,e,t,i)=>{for(var s=i>1?void 0:i?fte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&dte(e,t,s),s};class gp extends Ce{constructor(){super(...arguments);u(this,"length",1);u(this,"depthTest",!0);u(this,"isGizmo",!0);u(this,"_axes",null)}onEnable(){if(this.isGizmo&&!hA)return;this._axes||(this._axes=new Gf(this.length)),this.gameObject.add(this._axes);const t=this._axes.material;t&&t.depthTest!==void 0&&(t.depthTest=this.depthTest)}onDisable(){this._axes&&this.gameObject.remove(this._axes)}}$I([w()],gp.prototype,"length",2);$I([w()],gp.prototype,"depthTest",2);$I([w()],gp.prototype,"isGizmo",2);class eM extends Ce{constructor(){super(...arguments);u(this,"from");u(this,"to");u(this,"hint");u(this,"desiredDistance",1)}onEnable(){}update(){if(!this.from||!this.to||!this.hint)return;let t=wt(this.to).clone(),i=wt(this.from).clone(),s=t.distanceTo(i),r=t.clone();r.sub(i);let o=i.clone();o.add(t),o.multiplyScalar(.5);let a=wt(this.hint).clone();a.sub(o);let l=new S;l.crossVectors(a,r),l.crossVectors(r,l),l.normalize();let c=s*.5,h=Math.max(this.desiredDistance,c),d=Math.sqrt(h*h-c*c),f=l.clone();f.multiplyScalar(d),f.add(o),ln(this.gameObject,f);let p=o.clone();p.sub(l),this.gameObject.lookAt(p)}}class qb{constructor(){u(this,"behaviours",[]);u(this,"behaviourComponents",[]);u(this,"behaviourComponentsCopy",[])}get extensionName(){return"Behaviour"}addBehavior(e){this.behaviours.push(e)}onBeforeBuildDocument(e){e.root.traverse(t=>{$.foreachComponent(t,i=>{var r;const s=i;(typeof s.createBehaviours=="function"||typeof s.beforeCreateDocument=="function"||typeof s.afterCreateDocument=="function")&&(this.behaviourComponents.push(s),(r=s.beforeCreateDocument)==null||r.call(s,this,e))},!1)})}onExportObject(e,t,i){var s;for(const r of this.behaviourComponents)(s=r.createBehaviours)==null||s.call(r,this,t,i)}onAfterBuildDocument(e){for(const t of this.behaviourComponents)typeof t.afterCreateDocument=="function"&&t.afterCreateDocument(this,e);this.behaviourComponentsCopy=this.behaviourComponents.slice(),this.behaviourComponents.length=0}onAfterHierarchy(e,t){var i;if((i=this.behaviours)!=null&&i.length){t.beginBlock('def Scope "Behaviors"');for(const s of this.behaviours)s.writeTo(this,e.document,t);t.closeBlock()}}async onAfterSerialize(e){console.log("onAfterSerialize",this.behaviourComponentsCopy);for(const t of this.behaviourComponentsCopy)console.log("behaviour",t),typeof t.afterSerialize=="function"&&(console.log("beh has afterSerialize",t),t.afterSerialize.constructor.name==="AsyncFunction"?await t.afterSerialize(this,e):t.afterSerialize(this,e))}}var pte=Object.defineProperty,gte=Object.getOwnPropertyDescriptor,tM=(n,e,t,i)=>{for(var s=i>1?void 0:i?gte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&pte(e,t,s),s};class Du extends js{constructor(){super(...arguments);u(this,"threshold");u(this,"intensity");u(this,"scatter");u(this,"selectiveBloom",!0)}get typeName(){return"Bloom"}init(){this.threshold.defaultValue=1,this.intensity.defaultValue=0,this.scatter.defaultValue=.2,this.selectiveBloom?(this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>1*Math.PI*(1-t)):(this.threshold.valueProcessor=t=>t,this.intensity.valueProcessor=t=>t,this.scatter.valueProcessor=t=>100*(1-t))}onCreateEffect(){let t;if(this.selectiveBloom){const i=t=new rF(this.context.scene,this.context.mainCamera,{blendFunction:Lt.ADD,mipmapBlur:!0,luminanceThreshold:this.threshold.value,luminanceSmoothing:this.scatter.value,intensity:this.intensity.value});i.inverted=!0}else t=new z1;return this.intensity.onValueChanged=i=>{t.intensity=i},this.threshold.onValueChanged=i=>{t.luminanceMaterial.threshold=i},this.scatter.onValueChanged=i=>{t.luminancePass.enabled=!0,t.luminanceMaterial.smoothing=i},t}}tM([w(Ft)],Du.prototype,"threshold",2);tM([w(Ft)],Du.prototype,"intensity",2);tM([w(Ft)],Du.prototype,"scatter",2);Na("Bloom",Du);var mte=Object.defineProperty,Ate=Object.getOwnPropertyDescriptor,Jo=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ate(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&mte(e,t,s),s};class za extends Ce{constructor(){super(...arguments);u(this,"attachedRigidbody",null);u(this,"isTrigger",!1);u(this,"sharedMaterial")}get isCollider(){return!0}awake(){super.awake(),this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Hi))}start(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Hi))}onEnable(){this.attachedRigidbody||(this.attachedRigidbody=this.gameObject.getComponentInParent(Hi))}onDisable(){var t;(t=this.context.physics.engine)==null||t.removeBody(this)}}Jo([w(Hi)],za.prototype,"attachedRigidbody",2);Jo([w()],za.prototype,"isTrigger",2);Jo([w()],za.prototype,"sharedMaterial",2);class UA extends za{constructor(){super(...arguments);u(this,"radius",.5);u(this,"center",new S(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addSphereCollider(this,this.center,this.radius)}}Jo([w()],UA.prototype,"radius",2);Jo([w(S)],UA.prototype,"center",2);class NA extends za{constructor(){super(...arguments);u(this,"size",new S(1,1,1));u(this,"center",new S(0,0,0))}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addBoxCollider(this,this.center,this.size)}}Jo([w(S)],NA.prototype,"size",2);Jo([w(S)],NA.prototype,"center",2);class zA extends za{constructor(){super(...arguments);u(this,"sharedMesh");u(this,"convex",!1)}onEnable(){var t,i,s,r,o;if(super.onEnable(),(t=this.sharedMesh)!=null&&t.isMesh||this.gameObject instanceof ve&&(this.sharedMesh=this.gameObject),(i=this.sharedMesh)!=null&&i.isMesh)(s=this.context.physics.engine)==null||s.addMeshCollider(this,this.sharedMesh,this.convex,ns(this.gameObject));else{const a=this.sharedMesh;if(a!=null&&a.isGroup){console.warn(`MeshCollider mesh is a group "${(r=this.sharedMesh)==null?void 0:r.name}", adding all children as colliders. This is currently not fully supported (colliders can not be removed from world again)`,this);for(const l in a.children){const c=a.children[l];c.isMesh&&((o=this.context.physics.engine)==null||o.addMeshCollider(this,c,this.convex,ns(this.gameObject)))}}}}}Jo([w()],zA.prototype,"convex",2);class Zc extends za{constructor(){super(...arguments);u(this,"center",new S(0,0,0));u(this,"radius",.5);u(this,"height",2)}onEnable(){var t;super.onEnable(),(t=this.context.physics.engine)==null||t.addCapsuleCollider(this,this.center,this.height,this.radius)}}Jo([w(S)],Zc.prototype,"center",2);Jo([w()],Zc.prototype,"radius",2);Jo([w()],Zc.prototype,"height",2);function iM(n){const e=n[vl];return e||(n.parent?iM(n.parent):null)}function p_(n,e){if(!n)return;const t=n.material;if((t==null?void 0:t.isMaterial)===!0){const i=n.parent;i&&i.isText,t.side=e.doubleSided??!0?Ii:Gs,t.shadowSide=e.doubleSided?Ii:Gs,n.castShadow=e.castShadows?e.castShadows:!1,n.receiveShadow=e.receiveShadows?e.receiveShadows:!1}for(const i of n.children)p_(i,e)}function Rd(n,e,t){n[e]===void 0&&console.warn("Field",e,"is undefined on",n);const i=Proxy.revocable(n[e],{set(o,a,l,c){const h=o[a],d=Reflect.set(o,a,l,c);return t(l,h),d}}),s=i.revoke,r=n[e];return i.revoke=()=>{n[e]=r,s()},n[e]=i.proxy,i}const GB=Symbol("Scheduled action");function vte(n,e,t=Rr.OnBeforeRender){let i=n[GB];i||(i=n[GB]={});const s=e.name;i[t]||(i[t]={});const r=i[t];if(r[s])return;function*a(){e==null||e.call(n),r[s]=null}const l=n.startCoroutine(a(),t);r[s]=l}var yte=Object.defineProperty,_te=Object.getOwnPropertyDescriptor,ku=(n,e,t,i)=>{for(var s=i>1?void 0:i?_te(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&yte(e,t,s),s};const Kw=le("debugui"),Zw=le("debuguilayout");class nM{constructor(){u(this,"width");u(this,"height")}}class sM{constructor(){u(this,"x");u(this,"y");u(this,"width");u(this,"height")}}const ta=new S,eg=new He,vy=new xe,wN=class extends Ho{constructor(){super(...arguments);u(this,"offset",.01);u(this,"_anchoredPosition");u(this,"sizeDelta",new q(100,100));u(this,"pivot",new q(.5,.5));u(this,"anchorMin",new q(0,0));u(this,"anchorMax",new q(1,1));u(this,"offsetMin",new q(0,0));u(this,"offsetMax",new q(0,0));u(this,"lastMatrix");u(this,"rectBlock");u(this,"_transformNeedsUpdate",!1);u(this,"_initialPosition");u(this,"_parentRectTransform");u(this,"_lastUpdateFrame",-1);u(this,"_lastAnchoring");u(this,"_createdBlocks",[]);u(this,"_createdTextBlocks",[])}get parent(){return this._parentRectTransform}get translation(){return this.gameObject.position}get rotation(){return this.gameObject.quaternion}get scale(){return this.gameObject.scale}get anchoredPosition(){return this._anchoredPosition||(this._anchoredPosition=new q),this._anchoredPosition}set anchoredPosition(e){this._anchoredPosition=e}get width(){if(this.anchorMin.x!==this.anchorMax.x&&this._parentRectTransform){const e=this._parentRectTransform.width,t=this.anchorMax.x-this.anchorMin.x;let i=e*t;return i+=this.sizeDelta.x,i}return this.sizeDelta.x}get height(){if(this.anchorMin.y!==this.anchorMax.y&&this._parentRectTransform){const e=this._parentRectTransform.height,t=this.anchorMax.y-this.anchorMin.y;let i=e*t;return i+=this.sizeDelta.y,i}return this.sizeDelta.y}awake(){super.awake(),this._anchoredPosition||(this._anchoredPosition=new q),this.lastMatrix=new He,this.rectBlock=new Ie,this.rectBlock.position.z=.1,this.rectBlock.name=this.name,this._initialPosition=this.gameObject.position.clone(),this._initialPosition.z=0,this.onApplyTransform("RectTransform awake"),Rd(this,"_anchoredPosition",()=>{this.markDirty()}),Rd(this,"sizeDelta",()=>{this.markDirty()}),Rd(this,"pivot",()=>{this.markDirty()}),Rd(this,"anchorMin",()=>{this.markDirty()}),Rd(this,"anchorMax",()=>{this.markDirty()})}onEnable(){var e;super.onEnable(),this.addShadowComponent(this.rectBlock),this._transformNeedsUpdate=!0,(e=this.Canvas)==null||e.registerTransform(this)}onDisable(){var e;super.onDisable(),this.removeShadowComponent(),(e=this.Canvas)==null||e.unregisterTransform(this)}onParentRectTransformChanged(e){this._transformNeedsUpdate||this.onApplyTransform(Zw?`${e.name} changed`:void 0)}get isDirty(){return this._transformNeedsUpdate||(this._transformNeedsUpdate=!this.lastMatrix.equals(this.gameObject.matrix)),this._transformNeedsUpdate}markDirty(){this._transformNeedsUpdate||(Zw&&console.warn("RectTransform markDirty()",this.name),this._transformNeedsUpdate=!0,this._lastUpdateFrame=-1)}updateTransform(){(this._transformNeedsUpdate||!this.lastMatrix.equals(this.gameObject.matrix))&&this.canUpdate()&&this.onApplyTransform(this._transformNeedsUpdate?"Marked dirty":"Matrix changed")}canUpdate(){return this._transformNeedsUpdate&&this.activeAndEnabled&&this._lastUpdateFrame!==this.context.time.frame}onApplyTransform(e){if(this.context.time.frameCount===this._lastUpdateFrame)return;this._lastUpdateFrame=this.context.time.frameCount;const t=this.shadowComponent;if(!t)return;this.gameObject.parent?this._parentRectTransform=$.getComponentInParent(this.gameObject.parent,wN):this._parentRectTransform=void 0,this._transformNeedsUpdate=!1,Zw&&console.warn("RectTransform → ApplyTransform",this.name+" because "+e),this.isRoot()?this.Root.screenspace||(t.rotation.y=Math.PI):(t.matrix.identity(),t.matrixAutoUpdate=!1,ta.set(0,0,0),this.applyPivot(ta),t.matrix.setPosition(ta.x,ta.y,0),(this.gameObject.quaternion.x||this.gameObject.quaternion.y||this.gameObject.quaternion.z)&&(vy.copy(this.gameObject.quaternion),vy.x*=-1,vy.z*=-1,eg.makeRotationFromQuaternion(vy),t.matrix.premultiply(eg)),ta.set(0,0,0),this.applyAnchoring(ta),ta.z+=this.offset,eg.identity(),eg.setPosition(ta.x,ta.y,ta.z),t.matrix.premultiply(eg),t.matrix.scale(this.gameObject.scale)),this.lastMatrix.copy(this.gameObject.matrix);const i=!0;for(const s of k1(this.gameObject,Ho,i,1)){if(s===this||!s.activeAndEnabled)continue;const r=s;r.onParentRectTransformChanged&&r.onParentRectTransformChanged(this)}}applyAnchoring(e){this._lastAnchoring||(this._lastAnchoring=new q);const t=this._lastAnchoring.sub(this._anchoredPosition);this.gameObject.position.x+=t.x,this.gameObject.position.y+=t.y,this._lastAnchoring.copy(this._anchoredPosition),e.x+=this._initialPosition.x-this.gameObject.position.x,e.y+=this._initialPosition.y-this.gameObject.position.y,e.z+=this._initialPosition.z-this.gameObject.position.z;const i=this._parentRectTransform;if(i){let s=0;const r=1-this.anchorMax.y-this.anchorMin.y;s-=i.height*.5*r,e.y+=s;let o=0;const a=1-this.anchorMax.x-this.anchorMin.x;o-=i.width*.5*a,e.x+=o}}applyPivot(e){if(this.pivot&&!this.isRoot()){const t=this.pivot.x-.5;e.x-=t*this.sizeDelta.x*this.gameObject.scale.x;const i=this.pivot.y-.5;e.y-=i*this.sizeDelta.y*this.gameObject.scale.y}}getBasicOptions(){const e={width:this.sizeDelta.x,height:this.sizeDelta.y,offset:this.offset,backgroundOpacity:0,borderWidth:0,borderRadius:0,borderOpacity:0,letterSpacing:-.03};return this.ensureValidSize(e),e}ensureValidSize(e,t=1e-4){return e.width<=0&&(e.width=t),e.height<=0&&(e.height=1e-4),e}createNewBlock(e){e={...this.getBasicOptions(),...e},Kw&&console.log(this.name,e);const t=new WI(e);return this._createdBlocks.push(t),t}createNewText(e){Kw&&console.log(e),e={...this.getBasicOptions(),...e},Kw&&console.log(this.name,e);const t=new gN(e);return this._createdTextBlocks.push(t),t}};let xs=wN;ku([w(q)],xs.prototype,"anchoredPosition",1);ku([w(q)],xs.prototype,"sizeDelta",2);ku([w(q)],xs.prototype,"pivot",2);ku([w(q)],xs.prototype,"anchorMin",2);ku([w(q)],xs.prototype,"anchorMax",2);ku([w(q)],xs.prototype,"offsetMin",2);ku([w(q)],xs.prototype,"offsetMax",2);class bte extends pN{constructor(e,t={}){super(e),e._simpleState__activeStates=[],e._simpleState__normalStyles={},e._simpleState__states=t,e._simpleState__statesProperties={};for(const i in t)for(const s in t[i])e._simpleState__statesProperties[s]||(e._simpleState__statesProperties[s]=[]),e._simpleState__statesProperties[s].push(i);for(const i of e._components)e._simpleState__statesProperties[i.id]&&(e._simpleState__normalStyles[i.id]=i.inline?i.inline:i._value);e.__overridedSet=e.set,e.set=this.storeSet.bind(e),e.renderStates=this.renderStates.bind(e),e.setupState=this.setupState.bind(e),e.setState=this.setState.bind(e),e.activatePseudoState=this.activatePseudoState.bind(e),e.deactivatePseudoState=this.deactivatePseudoState.bind(e),e.togglePseudoState=this.togglePseudoState.bind(e)}act(){}attach(){}detach(){}setupState(e,t){this._simpleState__states[e]=t;const i=[];for(const s in t)this._simpleState__statesProperties[s]||(this._simpleState__statesProperties[s]=[],i.push(s)),this._simpleState__statesProperties[s].push(e);for(const s of this._components)i.indexOf(s.id)>-1&&(this._simpleState__normalStyles[s.id]=s.inline?s.inline:s._value)}renderStates(){let e={...this._simpleState__normalStyles};for(const t in this._simpleState__states)this._simpleState__activeStates.indexOf(t)>-1&&(e={...e,...this._simpleState__states[t]});this.set(e,!1)}storeSet(e,t=!0){if(t)for(const i in e)this._simpleState__statesProperties[i]&&(this._simpleState__normalStyles[i]=e[i]);this.__overridedSet(e)}activatePseudoState(e){this._simpleState__activeStates.indexOf(e)===-1&&(this._simpleState__activeStates.push(e),this.renderStates())}deactivatePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1&&(this._simpleState__activeStates.splice(t,1),this.renderStates())}togglePseudoState(e){const t=this._simpleState__activeStates.indexOf(e);t>-1?this._simpleState__activeStates.splice(t,1):this._simpleState__activeStates.push(e),this.renderStates()}setState(e){Array.isArray(e)?this._simpleState__activeStates=e:this._simpleState__activeStates=[e],this.renderStates()}}var xte=Object.defineProperty,wte=Object.getOwnPropertyDescriptor,CN=(n,e,t,i)=>{for(var s=i>1?void 0:i?wte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&xte(e,t,s),s};class mp extends Ce{constructor(){super(...arguments);u(this,"effectColor");u(this,"effectDistance")}}CN([w(xi)],mp.prototype,"effectColor",2);CN([w(q)],mp.prototype,"effectDistance",2);var Cte=Object.defineProperty,Ste=Object.getOwnPropertyDescriptor,SN=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ste(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Cte(e,t,s),s};const yy={backgroundColor:new _e(1,1,1),backgroundOpacity:1,borderColor:new _e(1,1,1),borderOpacity:1};var EC;const m0=(EC=class extends Ho{constructor(){super(...arguments);u(this,"_alphaFactor",1);u(this,"raycastTarget",!0);u(this,"uiObject",null);u(this,"_color",null);u(this,"_rect",null);u(this,"_stateManager",null);u(this,"_currentlyCreatingPanel",!1)}get isGraphic(){return!0}get color(){return this._color||(this._color=new xi(1,1,1,1)),this._color}set color(e){(!this._color||this._color.r!==e.r||this._color.g!==e.g||this._color.b!==e.b||this._color.alpha!==e.alpha)&&(this._color||(this._color=new xi(1,1,1,1)),this._color.copy(e))}setAlphaFactor(e){this._alphaFactor=e,this.onColorChanged()}get alphaFactor(){return this._alphaFactor}onColorChanged(){this.uiObject&&(yy.backgroundColor=this._color,yy.backgroundOpacity=this._color.alpha*this._alphaFactor,this.applyEffects(yy,this._alphaFactor),this.uiObject.set(yy),this.markDirty())}get m_Color(){return this._color}get rectTransform(){return this._rect||(this._rect=$.getComponent(this.gameObject,xs)),this._rect}onParentRectTransformChanged(){var e;(e=this.uiObject)==null||e.set({width:this.rectTransform.width,height:this.rectTransform.height}),this.markDirty()}__internalNewInstanceCreated(){super.__internalNewInstanceCreated(),this._rect=null,this.uiObject=null,this._color&&(this._color=this._color.clone())}setState(e){this.makePanel(),this.uiObject&&(this.uiObject.setState(e),this==null||this.markDirty())}setupState(e){this.makePanel(),this.uiObject&&(this._stateManager||(this._stateManager=new bte(this.uiObject)),this.uiObject.setupState(e.state,e.attributes))}setOptions(e){this.makePanel(),this.uiObject&&this.uiObject.set(e)}awake(){super.awake(),this.makePanel(),Rd(this,"_color",()=>vte(this,this.onColorChanged))}onEnable(){var e;super.onEnable(),this.uiObject&&((e=this.rectTransform.shadowComponent)==null||e.add(this.uiObject),this.addShadowComponent(this.uiObject,this.rectTransform))}onDisable(){super.onDisable(),this.uiObject&&this.removeShadowComponent()}makePanel(){if(this.uiObject||this._currentlyCreatingPanel)return;this._currentlyCreatingPanel=!0;const e={backgroundColor:this.color,backgroundOpacity:this.color.alpha,offset:1};this.onBeforeCreate(e),this.applyEffects(e),this.onCreate(e),this.controlsChildLayout=!1,this._currentlyCreatingPanel=!1,this.onAfterCreated()}onBeforeCreate(e){}onCreate(e){this.uiObject=this.rectTransform.createNewBlock(e),this.uiObject.name=this.name}onAfterCreated(){}applyEffects(e,t=1){var s;const i=(s=this.gameObject)==null?void 0:s.getComponent(mp);i&&(i.effectDistance&&(e.borderWidth=Math.max(Math.abs(i.effectDistance.x),Math.abs(i.effectDistance.y))),i.effectColor&&(e.borderColor=i.effectColor,e.borderOpacity=i.effectColor.alpha*t))}async setTexture(e){if(this.setOptions({backgroundOpacity:0}),e){if(e.encoding===yt)if(m0.textureCache.has(e))e=m0.textureCache.get(e);else{const t=e.clone();t.encoding=cn,m0.textureCache.set(e,t),e=t}this.setOptions({backgroundImage:e,borderRadius:0,backgroundOpacity:this.color.alpha,backgroundSize:"stretch"})}else this.setOptions({backgroundImage:null,borderRadius:0,backgroundOpacity:this.color.alpha})}onAfterAddedToScene(){super.onAfterAddedToScene(),this.shadowComponent&&(this.shadowComponent.offset=this.shadowComponent.position.z)}},u(EC,"textureCache",new Map),EC);let Ou=m0;SN([w(xi)],Ou.prototype,"color",1);SN([w()],Ou.prototype,"raycastTarget",2);class GA extends Ou{constructor(){super(...arguments);u(this,"_flippedObject",!1)}onAfterCreated(){this.uiObject&&!this._flippedObject&&(this._flippedObject=!0,this.uiObject.scale.y*=-1)}}var Ete=Object.defineProperty,Ite=Object.getOwnPropertyDescriptor,Xb=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ite(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Ete(e,t,s),s};let rM=class{constructor(){u(this,"texture",null);u(this,"rect")}};Xb([w(Gt)],rM.prototype,"texture",2);let Ap=class extends GA{constructor(){super(...arguments);u(this,"_sprite");u(this,"pixelsPerUnitMultiplier",1)}set image(t){this.sprite?this.sprite.texture=t:(this.sprite=new rM,this.sprite.texture=t),this.onAfterCreated()}get image(){return this.sprite?this.sprite.texture:null}get sprite(){return this._sprite}set sprite(t){this._sprite!==t&&(this._sprite=t,this.onAfterCreated())}isBuiltinSprite(){var t,i,s,r,o,a,l,c;switch((i=(t=this.sprite)==null?void 0:t.texture)==null?void 0:i.name){case"InputFieldBackground":case"UISprite":case"Background":case"Knob":return!0}return((o=(r=(s=this.sprite)==null?void 0:s.texture)==null?void 0:r.image)==null?void 0:o.width)===32&&((c=(l=(a=this.sprite)==null?void 0:a.texture)==null?void 0:l.image)==null?void 0:c.height)===32}onBeforeCreate(t){var i,s;super.onBeforeCreate(t),this.isBuiltinSprite()&&(t.borderRadius=5/this.pixelsPerUnitMultiplier,((s=(i=this.sprite)==null?void 0:i.texture)==null?void 0:s.name)==="Knob"&&(t.borderRadius=999))}onAfterCreated(){var t;this.__didAwake&&(super.onAfterCreated(),!this.isBuiltinSprite()&&this.setTexture((t=this.sprite)==null?void 0:t.texture))}};Xb([w(rM)],Ap.prototype,"sprite",1);Xb([w()],Ap.prototype,"pixelsPerUnitMultiplier",2);class Yb extends GA{constructor(){super(...arguments);u(this,"_mainTexture")}get mainTexture(){return this._mainTexture}set mainTexture(t){this._mainTexture!==t&&(this._mainTexture=t,this.onAfterCreated())}onAfterCreated(){this.__didAwake&&(super.onAfterCreated(),this.setTexture(this.mainTexture))}}Xb([w(Gt)],Yb.prototype,"mainTexture",1);var Mte=Object.defineProperty,Tte=Object.getOwnPropertyDescriptor,Dr=(n,e,t,i)=>{for(var s=i>1?void 0:i?Tte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Mte(e,t,s),s};const yd=le("debugbutton");class Lu{constructor(){u(this,"colorMultiplier");u(this,"disabledColor");u(this,"fadeDuration");u(this,"highlightedColor");u(this,"normalColor");u(this,"pressedColor");u(this,"selectedColor")}}Dr([w()],Lu.prototype,"colorMultiplier",2);Dr([w(xi)],Lu.prototype,"disabledColor",2);Dr([w()],Lu.prototype,"fadeDuration",2);Dr([w(xi)],Lu.prototype,"highlightedColor",2);Dr([w(xi)],Lu.prototype,"normalColor",2);Dr([w(xi)],Lu.prototype,"pressedColor",2);Dr([w(xi)],Lu.prototype,"selectedColor",2);class Xl extends Ce{constructor(){super(...arguments);u(this,"onClick");u(this,"_isHovered",!1);u(this,"colors");u(this,"transition");u(this,"animationTriggers");u(this,"animator");u(this,"_interactable",!0);u(this,"_requestedAnimatorTrigger");u(this,"_isInit",!1);u(this,"_image")}onPointerEnter(t){var i,s;yd&&console.log("Button Enter",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator),this._isHovered=!0,this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.highlightedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("hovered")),this.context.input.setCursorPointer())}onPointerExit(){var t,i;yd&&console.log("Button Exit",(t=this.animationTriggers)==null?void 0:t.highlightedTrigger,this.animator),this._isHovered=!1,this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((i=this._image)==null||i.setState("normal")),this.context.input.setCursorNormal())}onPointerDown(t){var i,s;yd&&console.log("Button Down",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this.animationTriggers.pressedTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState("pressed")))}onPointerUp(t){var i,s;yd&&console.warn("Button Up",(i=this.animationTriggers)==null?void 0:i.highlightedTrigger,this.animator,this._isHovered),this.interactable&&(this.transition==3&&this.animationTriggers&&this.animator?this.animator.setTrigger(this._isHovered?this.animationTriggers.highlightedTrigger:this.animationTriggers.normalTrigger):this.transition===1&&this.colors&&((s=this._image)==null||s.setState(this._isHovered?"hovered":"normal")))}onPointerClick(t){var i;this.interactable&&(yd&&(console.warn("Button Click",this.onClick),jn("CLICKED button "+this.name+" at "+this.context.time.frameCount)),(i=this.onClick)==null||i.invoke())}set interactable(t){this._interactable=t,this._image&&(this._image.setInteractable(t),t?this._image.setState("normal"):this._image.setState("disabled"))}get interactable(){return this._interactable}set_interactable(t){this.interactable=t}awake(){super.awake(),yd&&console.log(this),this._isInit=!1,this.init()}start(){var t;(t=this._image)==null||t.setInteractable(this.interactable)}onEnable(){super.onEnable()}*setAnimatorTriggerAtEndOfFrame(t){var i;this._requestedAnimatorTrigger=t,yield,yield,this._requestedAnimatorTrigger==t&&((i=this.animator)==null||i.SetTrigger(t))}init(){this._isInit||(this._isInit=!0,this._image=$.getComponent(this.gameObject,Ap),this._image&&(this.stateSetup(this._image),this.interactable?this._image.setState("normal"):this._image.setState("disabled")))}stateSetup(t){var p,g,m,A,v;t.setInteractable(this.interactable);const i=this.getFinalColor(t.color,(p=this.colors)==null?void 0:p.normalColor),s={state:"normal",attributes:{backgroundColor:i,backgroundOpacity:i.alpha}};t.setupState(s);const r=this.getFinalColor(t.color,(g=this.colors)==null?void 0:g.highlightedColor),o={state:"hovered",attributes:{backgroundColor:r,backgroundOpacity:r.alpha}};t.setupState(o);const a=this.getFinalColor(t.color,(m=this.colors)==null?void 0:m.pressedColor),l={state:"pressed",attributes:{backgroundColor:a,backgroundOpacity:a.alpha}};t.setupState(l);const c=this.getFinalColor(t.color,(A=this.colors)==null?void 0:A.selectedColor),h={state:"selected",attributes:{backgroundColor:c,backgroundOpacity:c.alpha}};t.setupState(h);const d=this.getFinalColor(t.color,(v=this.colors)==null?void 0:v.disabledColor),f={state:"disabled",attributes:{backgroundColor:d,backgroundOpacity:d.alpha}};t.setupState(f)}getFinalColor(t,i){return i?t.clone().multiply(i):t.clone()}}Dr([w(ar)],Xl.prototype,"onClick",2);Dr([w()],Xl.prototype,"colors",2);Dr([w()],Xl.prototype,"transition",2);Dr([w()],Xl.prototype,"animationTriggers",2);Dr([w(hr)],Xl.prototype,"animator",2);Dr([w()],Xl.prototype,"interactable",1);var Pte=Object.defineProperty,Rte=Object.getOwnPropertyDescriptor,Cn=(n,e,t,i)=>{for(var s=i>1?void 0:i?Rte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Pte(e,t,s),s};const QB=le("debuguilayout");class uh{constructor(){u(this,"left",0);u(this,"right",0);u(this,"top",0);u(this,"bottom",0)}get vertical(){return this.top+this.bottom}get horizontal(){return this.left+this.right}}Cn([w()],uh.prototype,"left",2);Cn([w()],uh.prototype,"right",2);Cn([w()],uh.prototype,"top",2);Cn([w()],uh.prototype,"bottom",2);class kr extends Ce{constructor(){super(...arguments);u(this,"_rectTransform",null);u(this,"_needsUpdate",!1);u(this,"childAlignment",0);u(this,"reverseArrangement",!1);u(this,"spacing",0);u(this,"padding");u(this,"minWidth",0);u(this,"minHeight",0);u(this,"flexibleHeight",0);u(this,"flexibleWidth",0);u(this,"preferredHeight",0);u(this,"preferredWidth",0)}get rectTransform(){return this._rectTransform}onParentRectTransformChanged(t){this._needsUpdate=!0}get isDirty(){return this._needsUpdate}get isLayoutGroup(){return!0}updateLayout(){this._rectTransform&&(QB&&console.warn("Layout Update",this.context.time.frame,this.name),this._needsUpdate=!1,this.onCalculateLayout(this._rectTransform))}start(){this._needsUpdate=!0}onEnable(){QB&&console.log(this.name,this),this._rectTransform=this.gameObject.getComponent(xs);const t=this.gameObject.getComponentInParent(ws);t&&t.registerLayoutGroup(this),this._needsUpdate=!0}onDisable(){const t=this.gameObject.getComponentInParent(ws);t&&t.unregisterLayoutGroup(this)}set m_Spacing(t){t!==this.spacing&&(this._needsUpdate=!0,this.spacing=t)}get m_Spacing(){return this.spacing}}Cn([w()],kr.prototype,"childAlignment",2);Cn([w()],kr.prototype,"reverseArrangement",2);Cn([w()],kr.prototype,"spacing",2);Cn([w(uh)],kr.prototype,"padding",2);Cn([w()],kr.prototype,"minWidth",2);Cn([w()],kr.prototype,"minHeight",2);Cn([w()],kr.prototype,"flexibleHeight",2);Cn([w()],kr.prototype,"flexibleWidth",2);Cn([w()],kr.prototype,"preferredHeight",2);Cn([w()],kr.prototype,"preferredWidth",2);class dh extends kr{constructor(){super(...arguments);u(this,"childControlHeight",!0);u(this,"childControlWidth",!0);u(this,"childForceExpandHeight",!1);u(this,"childForceExpandWidth",!1);u(this,"childScaleHeight",!1);u(this,"childScaleWidth",!1)}onCalculateLayout(t){var x;const i=this.primaryAxis,s=t.width;let r=s;const o=t.height;let a=o;r-=this.padding.horizontal,a-=this.padding.vertical,i==="x"?this.padding.horizontal:this.padding.vertical;const l=i==="x",c=l?"y":"x",h=l?this.childControlWidth:this.childControlHeight,d=l?this.childControlHeight:this.childControlWidth,f=l?this.childForceExpandWidth:this.childForceExpandHeight,p=l?this.childForceExpandHeight:this.childForceExpandWidth,g=l?a:r,m=l?s:o,A=.5*(l?this.childAlignment%3:Math.floor(this.childAlignment/3));let v=0;l?v+=this.padding.left:v+=this.padding.top;let b=0,y=0;for(let M=0;M<this.gameObject.children.length;M++){const P=this.gameObject.children[M],k=$.getComponent(P,xs);k!=null&&k.activeAndEnabled&&(y+=1,l?b+=k.width:b+=k.height)}let _=0;const C=this.spacing*(y-1);if(f||h){let M=0;l?M=r-=C:M=a-=C,y>0&&(_=M/y)}let E=0;E+=this.padding.left,E-=this.padding.right,A!==0&&(v=m-b,v*=A,v-=C*A,l?(v-=this.padding.right*A,v+=this.padding.left*(1-A),v<this.padding.left&&(v=this.padding.left)):(v-=this.padding.bottom*A,v+=this.padding.top*(1-A),v<this.padding.top&&(v=this.padding.top)));let T=1;for(let M=0;M<this.gameObject.children.length;M++){const P=this.gameObject.children[M],k=$.getComponent(P,xs);if(k!=null&&k.activeAndEnabled){(x=k.pivot)==null||x.set(.5,.5),k.anchorMin.set(0,1),k.anchorMax.set(0,1);const G=s*.5+E*.5;k.anchoredPosition.x!==G&&(k.anchoredPosition.x=G);const z=o*-.5;k.anchoredPosition.y!==z&&(k.anchoredPosition.y=z),p&&d&&k.sizeDelta[c]!==g&&(k.sizeDelta[c]=g),f&&h&&k.sizeDelta[i]!==_&&(k.sizeDelta[i]=_);const L=l?k.width:k.height;let H=L*.5;if(v+=H,f){let K=_*T-_*.5;K>v&&(v=K-_*.5+L+this.padding.left,v-=H)}let Z=v;i==="y"&&(Z=-Z),k.anchoredPosition[i]!==Z&&(k.anchoredPosition[i]=Z),v+=H,v+=this.spacing,T+=1}}}}Cn([w()],dh.prototype,"childControlHeight",2);Cn([w()],dh.prototype,"childControlWidth",2);Cn([w()],dh.prototype,"childForceExpandHeight",2);Cn([w()],dh.prototype,"childForceExpandWidth",2);Cn([w()],dh.prototype,"childScaleHeight",2);Cn([w()],dh.prototype,"childScaleWidth",2);class oM extends dh{get primaryAxis(){return"y"}}class aM extends dh{get primaryAxis(){return"x"}}class lM extends kr{onCalculateLayout(){}}var Bte=Object.defineProperty,Dte=Object.getOwnPropertyDescriptor,Ga=(n,e,t,i)=>{for(var s=i>1?void 0:i?Dte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Bte(e,t,s),s};const $w=le("debuguilayout"),EN=class extends BA{constructor(){super(...arguments);u(this,"_renderOnTop");u(this,"_depthWrite",!1);u(this,"_doubleSided",!0);u(this,"_castShadows",!1);u(this,"_receiveShadows",!1);u(this,"_renderMode",-1);u(this,"_rootCanvas");u(this,"_scaleFactor",1);u(this,"worldCamera");u(this,"planeDistance",-1);u(this,"_boundRenderSettingsChanged",this.onRenderSettingsChanged.bind(this));u(this,"previousParent",null);u(this,"_lastMatrixWorld",null);u(this,"_rectTransforms",[]);u(this,"_layoutGroups",new Map);u(this,"onBeforeRenderRoutine",()=>{var e,t;this.previousParent=this.gameObject.parent,this.renderOnTop||this.screenspace?this.gameObject.removeFromParent():(this.onUpdateRenderMode(),this.handleLayoutUpdates(),(e=this.shadowComponent)==null||e.updateMatrixWorld(!0),(t=this.shadowComponent)==null||t.updateWorldMatrix(!0,!0),sr.ensureUpdateMeshUI(LB,this.context))});u(this,"onAfterRenderRoutine",()=>{var e,t;if((this.screenspace||this.renderOnTop)&&this.previousParent&&this.context.mainCamera){if(this.screenspace){const i=this.context.mainCamera;i==null||i.add(this.gameObject)}else this.previousParent.add(this.gameObject);this.context.renderer.autoClear=!1,this.context.renderer.clearDepth(),this.onUpdateRenderMode(!0),this.handleLayoutUpdates(),(e=this.shadowComponent)==null||e.updateMatrixWorld(!0),sr.ensureUpdateMeshUI(LB,this.context),this.context.renderer.render(this.gameObject,this.context.mainCamera),this.context.renderer.autoClear=!0,this.previousParent.add(this.gameObject)}(t=this._lastMatrixWorld)==null||t.copy(this.gameObject.matrixWorld)});u(this,"_updateRenderSettingsRoutine");u(this,"_activeRenderMode",-1);u(this,"_lastWidth",-1);u(this,"_lastHeight",-1)}get isCanvas(){return!0}get screenspace(){return this.renderMode!==2}set renderOnTop(e){e!==this._renderOnTop&&(this._renderOnTop=e,this.onRenderSettingsChanged())}get renderOnTop(){return this._renderOnTop!==void 0?this._renderOnTop:!!(this.screenspace&&this._renderMode===0)}set depthWrite(e){this._depthWrite!==e&&(this._depthWrite=e,this.onRenderSettingsChanged())}get depthWrite(){return this._depthWrite}set doubleSided(e){this._doubleSided!==e&&(this._doubleSided=e,this.onRenderSettingsChanged())}get doubleSided(){return this._doubleSided}set castShadows(e){this._castShadows!==e&&(this._castShadows=e,this.onRenderSettingsChanged())}get castShadows(){return this._castShadows}set receiveShadows(e){this._receiveShadows!==e&&(this._receiveShadows=e,this.onRenderSettingsChanged())}get receiveShadows(){return this._receiveShadows}get renderMode(){return this._renderMode}set renderMode(e){this._renderMode!==e&&(this._renderMode=e,this.onRenderSettingsChanged())}set rootCanvas(e){this._rootCanvas instanceof EN||(this._rootCanvas=e)}get rootCanvas(){return this._rootCanvas}get scaleFactor(){return this._scaleFactor}set scaleFactor(e){this._scaleFactor=e}awake(){var e;this.shadowComponent=this.gameObject,this.previousParent=this.gameObject.parent,$w&&console.log("Canvas.Awake()",((e=this.previousParent)==null?void 0:e.name)+"/"+this.gameObject.name),super.awake()}start(){this.onUpdateRenderMode()}onEnable(){super.onEnable(),this._updateRenderSettingsRoutine=void 0,this._lastMatrixWorld=new He,this.onUpdateRenderMode(),document.addEventListener("resize",this._boundRenderSettingsChanged),this.context.pre_render_callbacks.push(this.onBeforeRenderRoutine),this.context.post_render_callbacks.push(this.onAfterRenderRoutine)}onDisable(){super.onDisable(),document.removeEventListener("resize",this._boundRenderSettingsChanged);const e=this.context.pre_render_callbacks.indexOf(this.onBeforeRenderRoutine);e!==-1&&this.context.pre_render_callbacks.splice(e,1);const t=this.context.post_render_callbacks.indexOf(this.onAfterRenderRoutine);t!==-1&&this.context.post_render_callbacks.splice(t,1)}registerTransform(e){this._rectTransforms.push(e)}unregisterTransform(e){const t=this._rectTransforms.indexOf(e);t!==-1&&this._rectTransforms.splice(t,1)}registerLayoutGroup(e){const t=e.gameObject;this._layoutGroups.set(t,e)}unregisterLayoutGroup(e){const t=e.gameObject;this._layoutGroups.delete(t)}handleLayoutUpdates(){this._lastMatrixWorld===null&&(this._lastMatrixWorld=new He);const e=!this._lastMatrixWorld.equals(this.gameObject.matrixWorld);$w&&e&&console.log("Canvas Layout changed",this.context.time.frameCount,this.name);let t=!1;for(const i of this._rectTransforms){e&&i.markDirty();let s=this._layoutGroups.get(i.gameObject);i.isDirty&&!s&&(s=i.gameObject.getComponentInParent(kr)),(i.isDirty||s!=null&&s.isDirty)&&($w&&!t&&console.log("CANVAS UPDATE ### "+i.name+" ##################################### "+this.context.time.frame),s==null||s.updateLayout(),i.updateTransform())}}applyRenderSettings(){this.onRenderSettingsChanged()}onRenderSettingsChanged(){this._updateRenderSettingsRoutine||(this._updateRenderSettingsRoutine=this.startCoroutine(this._updateRenderSettingsDelayed(),Rr.OnBeforeRender))}*_updateRenderSettingsDelayed(){if(yield,this._updateRenderSettingsRoutine=void 0,this.shadowComponent){this.onUpdateRenderMode(),p_(this.shadowComponent,this);for(const e of $.getComponentsInChildren(this.gameObject,Ho))p_(e.shadowComponent,this)}}onUpdateRenderMode(e=!1){if(!e&&this._renderMode===this._activeRenderMode&&this._lastWidth===this.context.domWidth&&this._lastHeight===this.context.domHeight)return;this._activeRenderMode=this._renderMode;let t=this.context.mainCameraComponent,i=10;switch(t&&t.nearClipPlane>0&&t.farClipPlane>0&&(i=Ze.lerp(t.nearClipPlane,t.farClipPlane,.15)),this._renderMode===1&&(this.worldCamera&&(t=this.worldCamera),this.planeDistance>0&&(i=this.planeDistance)),this._renderMode){case 0:case 1:if(this._lastWidth=this.context.domWidth,this._lastHeight=this.context.domHeight,!t)return;const s=i+.01;this.gameObject.position.x=0,this.gameObject.position.y=0,this.gameObject.position.z=-s,this.gameObject.quaternion.identity();const r=this.gameObject.getComponent(xs);let o=!1;r.sizeDelta.x!==this.context.domWidth&&(o=!0),r.sizeDelta.y!==this.context.domHeight&&(o=!0);const a=t.fieldOfView*Math.PI/180,l=2*Math.tan(a/2)*Math.abs(s);this.gameObject.scale.x=l/this.context.domHeight,this.gameObject.scale.y=l/this.context.domHeight,this.gameObject.scale.z=.01,o&&(r.sizeDelta.x=this.context.domWidth,r.sizeDelta.y=this.context.domHeight,r==null||r.markDirty());break;case 2:this._lastWidth=-1,this._lastHeight=-1;break}}};let ws=EN;Ga([w()],ws.prototype,"renderOnTop",1);Ga([w()],ws.prototype,"depthWrite",1);Ga([w()],ws.prototype,"doubleSided",1);Ga([w()],ws.prototype,"castShadows",1);Ga([w()],ws.prototype,"receiveShadows",1);Ga([w()],ws.prototype,"renderMode",1);Ga([w(ws)],ws.prototype,"rootCanvas",1);Ga([w()],ws.prototype,"scaleFactor",1);Ga([w(Oi)],ws.prototype,"worldCamera",2);Ga([w()],ws.prototype,"planeDistance",2);var kte=Object.defineProperty,Ote=Object.getOwnPropertyDescriptor,cM=(n,e,t,i)=>{for(var s=i>1?void 0:i?Ote(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&kte(e,t,s),s};class vp extends Ce{constructor(){super(...arguments);u(this,"_alpha",1);u(this,"interactable",!0);u(this,"blocksRaycasts",!0);u(this,"_isDirty",!1);u(this,"_buffer",[])}get alpha(){return this._alpha}set alpha(t){t!==this._alpha&&(this._alpha=t,this.markDirty())}get isCanvasGroup(){return!0}markDirty(){this._isDirty||(this._isDirty=!0,this.startCoroutine(this.applyChangesDelayed(),Rr.OnBeforeRender))}*applyChangesDelayed(){this._isDirty=!1,this.applyChangesNow()}applyChangesNow(){for(const t of $.getComponentsInChildren(this.gameObject,Ho,this._buffer)){const i=t;i.setAlphaFactor&&i.setAlphaFactor(this._alpha)}}}cM([w()],vp.prototype,"alpha",1);cM([w()],vp.prototype,"interactable",2);cM([w()],vp.prototype,"blocksRaycasts",2);var Lte=Object.defineProperty,Fte=Object.getOwnPropertyDescriptor,Fi=(n,e,t,i)=>{for(var s=i>1?void 0:i?Fte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Lte(e,t,s),s};class Fu extends Ce{constructor(){super(...arguments);u(this,"object");u(this,"target");u(this,"duration",1);u(this,"relativeMotion",!1);u(this,"coroutine",null);u(this,"targetPos",new S);u(this,"targetRot",new xe);u(this,"targetScale",new S)}*moveToTarget(){if(!this.target||!this.object)return;const t=wt(this.object).clone(),i=wt(this.target).clone(),s=Dn(this.object).clone(),r=Dn(this.target).clone(),o=ns(this.object).clone(),a=ns(this.target).clone(),l=t.distanceTo(i),c=s.angleTo(r),h=o.distanceTo(a);if(l<.01&&c<.01&&h<.01){ln(this.object,i),cr(this.object,r),vS(this.object,a),this.coroutine=null;return}let d=0,f=0;for(;d<1;)d+=this.context.time.deltaTime/this.duration,d>1&&(d=1),f=d<.5?4*d*d*d:1-Math.pow(-2*d+2,3)/2,this.targetPos.lerpVectors(t,i,f),this.targetRot.slerpQuaternions(s,r,f),this.targetScale.lerpVectors(o,a,f),ln(this.object,this.targetPos),cr(this.object,this.targetRot),vS(this.object,this.targetScale),yield;this.coroutine=null}*moveRelative(){if(!this.target||!this.object)return;const t=this.object.position.clone(),i=this.object.quaternion.clone(),s=this.object.scale.clone(),r=this.target.position.clone(),o=this.target.quaternion.clone(),a=this.target.scale.clone();r.applyQuaternion(this.object.quaternion),this.targetPos.copy(this.object.position).add(r),this.targetRot.copy(this.object.quaternion).multiply(o),this.targetScale.copy(this.object.scale).multiply(a);let l=0,c=0;for(;l<1;)l+=this.context.time.deltaTime/this.duration,l>1&&(l=1),c=l<.5?4*l*l*l:1-Math.pow(-2*l+2,3)/2,this.object.position.lerpVectors(t,this.targetPos,c),this.object.quaternion.slerpQuaternions(i,this.targetRot,c),this.object.scale.lerpVectors(s,this.targetScale,c),yield;this.coroutine=null}onPointerClick(){this.coroutine&&this.stopCoroutine(this.coroutine),this.relativeMotion?this.coroutine=this.startCoroutine(this.moveRelative()):this.coroutine=this.startCoroutine(this.moveToTarget())}beforeCreateDocument(t){var i;if(this.target&&this.object&&this.gameObject){const s=new rs("Move to "+((i=this.target)==null?void 0:i.name),lr.tapTrigger(this.gameObject),oi.transformAction(this.object,this.target,this.duration,this.relativeMotion?YS.Relative:YS.Absolute));t.addBehavior(s)}}}Fi([w(Ie)],Fu.prototype,"object",2);Fi([w(Ie)],Fu.prototype,"target",2);Fi([w()],Fu.prototype,"duration",2);Fi([w()],Fu.prototype,"relativeMotion",2);var IC;const Bd=(IC=class extends Ce{constructor(){super(...arguments);u(this,"materialToSwitch");u(this,"variantMaterial");u(this,"_objectsWithThisMaterial",[]);u(this,"selfModel");u(this,"targetModels",[])}awake(){if(this.variantMaterial&&this.materialToSwitch){const e=$.findObjectsOfType(Ki);for(const t of e)t.sharedMaterial===this.materialToSwitch&&this._objectsWithThisMaterial.push(t)}}onPointerClick(){if(this.variantMaterial)for(const e of this._objectsWithThisMaterial)e.sharedMaterial=this.variantMaterial}createBehaviours(e,t,i){this._objectsWithThisMaterial.find(r=>r.gameObject.uuid===t.uuid)&&this.targetModels.push(t),this.gameObject.uuid===t.uuid&&(this.selfModel=t,this.materialToSwitch&&(Bd._materialTriggersPerId[this.materialToSwitch.uuid]||(Bd._materialTriggersPerId[this.materialToSwitch.uuid]=[]),Bd._materialTriggersPerId[this.materialToSwitch.uuid].push(this)))}afterCreateDocument(e,t){if(!this.materialToSwitch)return;const i=Bd._materialTriggersPerId[this.materialToSwitch.uuid];if(i){const s={};for(const o of i){const a=o.createVariants();a&&a.length>0&&(s[o.selfModel.uuid]=a)}const r=[];for(const o of i){for(const a in s)a!==o.selfModel.uuid&&r.push(s[a]);o.createAndAttachBehaviors(e,s[o.selfModel.uuid],r)}}delete Bd._materialTriggersPerId[this.materialToSwitch.uuid]}createAndAttachBehaviors(e,t,i){const s=[],r=[];for(const o of this.targetModels){const a=oi.fadeAction(o,0,!1);r.push(a)}for(const o of i)r.push(oi.fadeAction(o,0,!1));for(const o of t)s.push(oi.fadeAction(o,0,!1)),r.push(oi.fadeAction(o,0,!0));e.addBehavior(new rs("Select "+this.selfModel.name,lr.tapTrigger(this.selfModel),oi.parallel(...r))),e.addBehavior(new rs("Start hidden "+this.selfModel.name,lr.sceneStartTrigger(),oi.parallel(...s)))}createVariants(){if(!this.variantMaterial)return null;const e=[];for(const t of this.targetModels){const i=t.clone();i.name+=" variant_"+this.variantMaterial.name,i.name=i.name.replace(/\s/g,"_"),i.material=this.variantMaterial,i.geometry=t.geometry,i.matrix=t.matrix,(!t.parent||!t.parent.isEmpty())&&no.createEmptyParent(t),t.parent&&t.parent.add(i),e.push(i)}return e}},u(IC,"_materialTriggersPerId",{}),IC);let QA=Bd;Fi([w(Bt)],QA.prototype,"materialToSwitch",2);Fi([w(Bt)],QA.prototype,"variantMaterial",2);class yp extends Ce{constructor(){super(...arguments);u(this,"target");u(this,"toggleOnClick",!1);u(this,"targetState",!0);u(this,"hideSelf",!0);u(this,"selfModel");u(this,"otherModel");u(this,"toggleModel");u(this,"stateBeforeCreatingDocument",!1)}onPointerClick(){!this.toggleOnClick&&this.hideSelf&&(this.gameObject.visible=!1),this.target&&(this.target.visible=this.toggleOnClick?!this.target.visible:this.targetState)}createBehaviours(t,i,s){i.uuid===this.gameObject.uuid&&(this.selfModel=i)}beforeCreateDocument(){this.stateBeforeCreatingDocument=this.gameObject.visible,this.gameObject.visible=!0}afterCreateDocument(t,i){if(this.target){if(this.otherModel=i.document.findById(this.target.uuid),this.selfModel&&this.otherModel){let s=this.hideSelf;this.targetState,this.toggleOnClick&&(s=!0,this.target.visible,(!this.selfModel.parent||this.selfModel.parent.isEmpty())&&L3.createEmptyParent(this.selfModel),this.toggleModel=this.selfModel.clone(),this.toggleModel.name+="_toggle",this.selfModel.parent.add(this.toggleModel));const r=[];if(s&&r.push(oi.fadeAction(this.selfModel,0,!1)),this.toggleModel&&r.push(oi.fadeAction(this.toggleModel,0,!0)),r.push(oi.fadeAction(this.otherModel,0,this.targetState)),t.addBehavior(new rs("Toggle_"+this.selfModel.name+"_hideSelf",lr.tapTrigger(this.selfModel),oi.sequence(...r))),this.toggleOnClick&&this.toggleModel){const o=[];o.push(oi.fadeAction(this.toggleModel,0,!1)),o.push(oi.fadeAction(this.selfModel,0,!0)),o.push(oi.fadeAction(this.otherModel,0,!this.targetState)),t.addBehavior(new rs("Toggle_"+this.selfModel.name+"_toggleSelf",lr.tapTrigger(this.toggleModel),oi.sequence(...o))),t.addBehavior(new rs("HideOnStart_"+this.gameObject.name,lr.sceneStartTrigger(),oi.fadeAction(this.toggleModel,0,!1)))}}this.gameObject.visible=this.stateBeforeCreatingDocument}}}Fi([w(Ie)],yp.prototype,"target",2);Fi([w()],yp.prototype,"targetState",2);Fi([w()],yp.prototype,"hideSelf",2);class hM extends Ce{start(){this.gameObject.visible=!1}createBehaviours(e,t,i){t.uuid===this.gameObject.uuid&&e.addBehavior(new rs("HideOnStart_"+this.gameObject.name,lr.sceneStartTrigger(),oi.fadeAction(t,0,!1)))}beforeCreateDocument(){this.gameObject.visible=!0}afterCreateDocument(){this.gameObject.visible=!1}}class _p extends Ce{constructor(){super(...arguments);u(this,"target");u(this,"duration",.5);u(this,"motionType",pI.bounce)}beforeCreateDocument(){}createBehaviours(t,i,s){if(this.target&&i.uuid===this.gameObject.uuid){const r=new rs("emphasize "+this.name,lr.tapTrigger(this.gameObject),oi.emphasize(this.target,this.duration,this.motionType,void 0,"basic"));t.addBehavior(r)}}afterCreateDocument(t,i){}}Fi([w()],_p.prototype,"target",2);Fi([w()],_p.prototype,"duration",2);Fi([w()],_p.prototype,"motionType",2);class bp extends Ce{constructor(){super(...arguments);u(this,"target");u(this,"clip","");u(this,"toggleOnClick",!1)}onPointerClick(){if(!(!this.target&&!this.clip)){if(!this.target){const t=this.gameObject.addNewComponent(xn);t&&(t.spatialBlend=1,t.volume=1,t.loop=!1,this.target=t)}this.target&&(this.target.isPlaying&&this.toggleOnClick?this.target.stop():(!this.toggleOnClick&&this.target.isPlaying&&this.target.stop(),this.clip?this.target.play(this.clip):this.target.play()))}}createBehaviours(t,i,s){if(!(!this.target&&!this.clip)&&i.uuid===this.gameObject.uuid){const r=this.clip?this.clip:this.target?this.target.clip:void 0;if(!r)return;const o=this.target?this.target.gameObject:this.gameObject,a=r.split("/").pop(),l=this.target?this.target.volume:1,c=this.target&&this.target.spatialBlend==0?JS.NonSpatial:JS.Spatial,h=new rs("playAudio "+this.name,lr.tapTrigger(this.gameObject),oi.playAudioAction(o,"audio/"+a,Q3.Play,l,c));t.addBehavior(h)}}async afterSerialize(t,i){if(!this.target&&!this.clip)return;const s=this.clip?this.clip:this.target?this.target.clip:void 0;if(!s)return;const r=s.split("/").pop(),l=await(await(await fetch(this.clip)).blob()).arrayBuffer(),c=new Uint8Array(l);i.files["audio/"+r]=c}}Fi([w(xn)],bp.prototype,"target",2);Fi([w(URL)],bp.prototype,"clip",2);Fi([w()],bp.prototype,"toggleOnClick",2);var MC;const Dd=(MC=class extends Ce{constructor(){super(...arguments);u(this,"target");u(this,"animator");u(this,"stateName");u(this,"stateNameAfterPlaying");u(this,"loopAfterPlaying",!1);u(this,"selfModel");u(this,"stateAnimationModel");u(this,"stateAnimation");u(this,"stateAfterPlayingAnimationModel");u(this,"stateAfterPlayingAnimation")}onPointerClick(){var e;this.target&&this.stateName&&((e=this.animator)==null||e.play(this.stateName,0,0,.1))}createBehaviours(e,t,i){t.uuid===this.gameObject.uuid&&(this.selfModel=t)}onAfterHierarchy(){Dd.animationActions=[]}afterCreateDocument(e,t){if(!this.stateAnimation||!this.stateAnimationModel)return;t.document.traverse(s=>{var r,o;if(s.uuid===((r=this.target)==null?void 0:r.uuid)&&this.stateAnimation){const a=[];let l=Dd.animationActions.find(h=>h.affectedObjects==s&&h.start==this.stateAnimation.start&&h.duration==this.stateAnimation.duration);if(l||(l=oi.startAnimationAction(s,this.stateAnimation.start,this.stateAnimation.duration),Dd.animationActions.push(l)),a.push(l),this.stateAfterPlayingAnimation&&this.stateAfterPlayingAnimationModel){let h=Dd.animationActions.find(f=>f.affectedObjects==s&&f.start==this.stateAfterPlayingAnimation.start&&f.duration==this.stateAfterPlayingAnimation.duration);h||(h=oi.startAnimationAction(s,this.stateAfterPlayingAnimation.start,this.stateAfterPlayingAnimation.duration),Dd.animationActions.push(h));const d=oi.sequence(h);this.loopAfterPlaying&&d.makeLooping(),a.push(d)}const c=new rs("tap "+this.name+" for "+this.stateName+" on "+((o=this.target)==null?void 0:o.name),lr.tapTrigger(this.selfModel),oi.sequence(...a));e.addBehavior(c)}})}createAnimation(e,t,i){var s,r,o,a;if(this.target&&this.animator){const l=(r=(s=this.animator)==null?void 0:s.runtimeAnimatorController)==null?void 0:r.findState(this.stateName);this.stateAnimationModel=t,this.stateAnimation=e.registerAnimation(this.target,l==null?void 0:l.motion.clip);const c=(a=(o=this.animator)==null?void 0:o.runtimeAnimatorController)==null?void 0:a.findState(this.stateNameAfterPlaying);this.stateAfterPlayingAnimationModel=t,this.stateAfterPlayingAnimation=e.registerAnimation(this.target,c==null?void 0:c.motion.clip)}}},u(MC,"animationActions",[]),MC);let fh=Dd;Fi([w(Ie)],fh.prototype,"target",2);Fi([w(hr)],fh.prototype,"animator",2);Fi([w()],fh.prototype,"stateName",2);Fi([w()],fh.prototype,"stateNameAfterPlaying",2);Fi([w()],fh.prototype,"loopAfterPlaying",2);class xp extends Ce{constructor(){super(...arguments);u(this,"target")}getType(){}getDuration(){}}Fi([w(Ie)],xp.prototype,"target",2);class HA extends Ce{constructor(){super(...arguments);u(this,"target")}}Fi([w(xp)],HA.prototype,"target",2);class VA extends xp{constructor(){super(...arguments);u(this,"type",1);u(this,"duration",1)}getType(){switch(this.type){case 1:return"hide";case 0:return"show"}}getDuration(){return this.duration}}Fi([w()],VA.prototype,"type",2);Fi([w()],VA.prototype,"duration",2);class uM extends HA{}var Ute=Object.defineProperty,Nte=Object.getOwnPropertyDescriptor,Yl=(n,e,t,i)=>{for(var s=i>1?void 0:i?Nte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Ute(e,t,s),s};class Uu extends Ce{constructor(){super(...arguments);u(this,"center",new S(0,0,0));u(this,"radius",.5);u(this,"height",2);u(this,"_rigidbody",null);u(this,"_activeGroundCollisions",new Set)}get rigidbody(){return this._rigidbody?this._rigidbody:(this._rigidbody=this.gameObject.getComponent(Hi),this._rigidbody||(this._rigidbody=this.gameObject.addNewComponent(Hi)),this.rigidbody)}onEnable(){let t=this.rigidbody,i=this.gameObject.getComponent(Zc);i||(i=this.gameObject.addNewComponent(Zc)),i.center.copy(this.center),i.radius=this.radius,i.height=this.height,this.gameObject.rotation.x=0,this.gameObject.rotation.z=0,t.lockRotationX=!0,t.lockRotationY=!0,t.lockRotationZ=!0}move(t){this.gameObject.position.add(t)}onCollisionEnter(t){for(const i of t.contacts)if(i.normal.y>.1){this._activeGroundCollisions.add(t);break}}onCollisionExit(t){this._activeGroundCollisions.delete(t)}get isGrounded(){return this._activeGroundCollisions.size>0}}Yl([w(S)],Uu.prototype,"center",2);Yl([w()],Uu.prototype,"radius",2);Yl([w()],Uu.prototype,"height",2);class Jl extends Ce{constructor(){super(...arguments);u(this,"controller");u(this,"movementSpeed",2);u(this,"rotationSpeed",2);u(this,"jumpForce",1);u(this,"doubleJumpForce",2);u(this,"animator");u(this,"lookForward",!0);u(this,"_currentSpeed",new S(0,0,0));u(this,"_currentAngularSpeed",new S(0,0,0));u(this,"_temp",new S(0,0,0));u(this,"_jumpCount",0);u(this,"_currentRotation");u(this,"_raycastOptions",new qo)}awake(){this._currentRotation=new xe}update(){var c,h,d,f,p,g,m,A,v,b,y;(c=this.controller)!=null&&c.isGrounded&&(this._jumpCount=0,this.doubleJumpForce>0&&((h=this.animator)==null||h.setBool("doubleJump",!1)));const t=this.context.input.isKeyPressed("w"),i=this.context.input.isKeyPressed("s"),s=this.context.input.isKeyPressed("a"),r=this.context.input.isKeyPressed("d"),o=this.context.input.isKeyDown(" "),a=(t?1:0)+(i?-1:0);this._currentSpeed.z+=a*this.movementSpeed*this.context.time.deltaTime,(d=this.animator)==null||d.setBool("running",a!=0),(p=this.animator)==null||p.setBool("jumping",((f=this.controller)==null?void 0:f.isGrounded)===!0&&o),this._temp.copy(this._currentSpeed),this._temp.applyQuaternion(this.gameObject.quaternion),this.controller?this.controller.move(this._temp):this.gameObject.position.add(this._temp);const l=(s?1:0)+(r?-1:0);if(this._currentAngularSpeed.y+=Ze.toRadians(l*this.rotationSpeed)*this.context.time.deltaTime,this.lookForward&&Math.abs(this._currentAngularSpeed.y)<.01){const _=this.context.mainCameraComponent.forward;_.y=0,_.normalize(),this._currentRotation.setFromUnitVectors(new S(0,0,1),_),this.gameObject.quaternion.slerp(this._currentRotation,this.context.time.deltaTime*10)}if(this.gameObject.rotateY(this._currentAngularSpeed.y),this._currentSpeed.multiplyScalar(1-this.context.time.deltaTime*10),this._currentAngularSpeed.y*=1-this.context.time.deltaTime*10,this.controller&&o&&this.jumpForce>0){let _=(g=this.controller)==null?void 0:g.isGrounded;if(this.doubleJumpForce>0&&!((m=this.controller)!=null&&m.isGrounded)&&this._jumpCount===1&&(_=!0,(A=this.animator)==null||A.setBool("doubleJump",!0)),_){this._jumpCount+=1;const C=this.controller.rigidbody,E=this._jumpCount===2?this.doubleJumpForce:this.jumpForce;C.applyImpulse(new S(0,1,0).multiplyScalar(E))}}if(this.controller){const _=(v=this.controller)==null?void 0:v.rigidbody.getVelocity().y;if(_<-1){this._raycastOptions.ray||(this._raycastOptions.ray=new Gl),this._raycastOptions.ray.origin.copy(wt(this.gameObject)),this._raycastOptions.ray.direction.set(0,-1,0);const C=this.layer;this.gameObject.layers.disableAll(),this.gameObject.layers.set(2);const E=this.context.physics.raycast(this._raycastOptions);this.gameObject.layers.set(C),(E.length&&E[0].distance>2||_<-10)&&((b=this.animator)==null||b.setBool("falling",!0))}else(y=this.animator)==null||y.setBool("falling",!1)}}}Yl([w(Uu)],Jl.prototype,"controller",2);Yl([w()],Jl.prototype,"movementSpeed",2);Yl([w()],Jl.prototype,"rotationSpeed",2);Yl([w()],Jl.prototype,"jumpForce",2);Yl([w()],Jl.prototype,"doubleJumpForce",2);Yl([w(hr)],Jl.prototype,"animator",2);var zte=Object.defineProperty,Gte=Object.getOwnPropertyDescriptor,Qte=(n,e,t,i)=>{for(var s=i>1?void 0:i?Gte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&zte(e,t,s),s};class jA extends js{constructor(){super(...arguments);u(this,"intensity")}get typeName(){return"ChromaticAberration"}init(){this.intensity.defaultValue=0}onCreateEffect(){const t=new tF;return t.offset=new q(0,0),t.radialModulation=!0,t.modulationOffset=.15,this.intensity.valueProcessor=i=>i*.02,this.intensity.onValueChanged=i=>{t.offset.x=-i,t.offset.y=i},t}}Qte([w(Ft)],jA.prototype,"intensity",2);Na("ChromaticAberration",jA);var Hte=Object.defineProperty,Vte=Object.getOwnPropertyDescriptor,Jb=(n,e,t,i)=>{for(var s=i>1?void 0:i?Vte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Hte(e,t,s),s};class ph extends js{constructor(){super(...arguments);u(this,"postExposure");u(this,"contrast");u(this,"hueShift");u(this,"saturation")}get typeName(){return"ColorAdjustments"}init(){this.postExposure.valueProcessor=t=>(t=Math.pow(2,t),t),this.postExposure.defaultValue=0,this.contrast.valueProcessor=t=>{let i=1;return t>0?i=200:t<0&&(i=100),t/i},this.contrast.defaultValue=0,this.hueShift.valueProcessor=t=>Math.PI*t/180,this.hueShift.defaultValue=0,this.saturation.valueProcessor=t=>t<0?t/100:t/(100*Math.PI),this.saturation.defaultValue=0}unapply(){this.context.renderer.toneMappingExposure=1}onCreateEffect(){this.context.renderer.toneMapping===Ls&&this.postExposure.overrideState&&(this.context.renderer.toneMapping=rm);const t=new eF;this.postExposure.onValueChanged=s=>{this.context.renderer.toneMapping===Ls&&(this.context.renderer.toneMapping=rm),this.context.renderer.toneMappingExposure=s},this.contrast.onValueChanged=s=>{t.contrast=s};const i=new nF;return this.hueShift.onValueChanged=s=>i.hue=s,this.saturation.onValueChanged=s=>i.saturation=s,[i,t]}}Jb([w(Ft)],ph.prototype,"postExposure",2);Jb([w(Ft)],ph.prototype,"contrast",2);Jb([w(Ft)],ph.prototype,"hueShift",2);Jb([w(Ft)],ph.prototype,"saturation",2);Na("ColorAdjustments",ph);const jte=(Math.sqrt(5)-1)/4,Kn=(5-Math.sqrt(5))/20,_y=n=>Math.floor(n)|0,by=new Float64Array([0,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,1,0,1,1,1,0,1,-1,1,0,-1,1,1,0,-1,-1,-1,0,1,1,-1,0,1,-1,-1,0,-1,1,-1,0,-1,-1,1,1,0,1,1,1,0,-1,1,-1,0,1,1,-1,0,-1,-1,1,0,1,-1,1,0,-1,-1,-1,0,1,-1,-1,0,-1,1,1,1,0,1,1,-1,0,1,-1,1,0,1,-1,-1,0,-1,1,1,0,-1,1,-1,0,-1,-1,1,0,-1,-1,-1,0]);function Wte(n=Math.random){const e=qte(n),t=new Float64Array(e).map(o=>by[o%32*4]),i=new Float64Array(e).map(o=>by[o%32*4+1]),s=new Float64Array(e).map(o=>by[o%32*4+2]),r=new Float64Array(e).map(o=>by[o%32*4+3]);return function(a,l,c,h){let d,f,p,g,m;const A=(a+l+c+h)*jte,v=_y(a+A),b=_y(l+A),y=_y(c+A),_=_y(h+A),C=(v+b+y+_)*Kn,E=v-C,T=b-C,x=y-C,M=_-C,P=a-E,k=l-T,G=c-x,z=h-M;let L=0,H=0,Z=0,K=0;P>k?L++:H++,P>G?L++:Z++,P>z?L++:K++,k>G?H++:Z++,k>z?H++:K++,G>z?Z++:K++;const J=L>=3?1:0,ue=H>=3?1:0,he=Z>=3?1:0,Pe=K>=3?1:0,ge=L>=2?1:0,ie=H>=2?1:0,ae=Z>=2?1:0,we=K>=2?1:0,V=L>=1?1:0,Le=H>=1?1:0,Re=Z>=1?1:0,qe=K>=1?1:0,ye=P-J+Kn,at=k-ue+Kn,pe=G-he+Kn,fe=z-Pe+Kn,De=P-ge+2*Kn,$e=k-ie+2*Kn,We=G-ae+2*Kn,ft=z-we+2*Kn,ct=P-V+3*Kn,st=k-Le+3*Kn,Ht=G-Re+3*Kn,kt=z-qe+3*Kn,U=P-1+4*Kn,D=k-1+4*Kn,ce=G-1+4*Kn,Ee=z-1+4*Kn,Be=v&255,Ve=b&255,lt=y&255,Qe=_&255;let O=.6-P*P-k*k-G*G-z*z;if(O<0)d=0;else{const Fe=Be+e[Ve+e[lt+e[Qe]]];O*=O,d=O*O*(t[Fe]*P+i[Fe]*k+s[Fe]*G+r[Fe]*z)}let Ae=.6-ye*ye-at*at-pe*pe-fe*fe;if(Ae<0)f=0;else{const Fe=Be+J+e[Ve+ue+e[lt+he+e[Qe+Pe]]];Ae*=Ae,f=Ae*Ae*(t[Fe]*ye+i[Fe]*at+s[Fe]*pe+r[Fe]*fe)}let Je=.6-De*De-$e*$e-We*We-ft*ft;if(Je<0)p=0;else{const Fe=Be+ge+e[Ve+ie+e[lt+ae+e[Qe+we]]];Je*=Je,p=Je*Je*(t[Fe]*De+i[Fe]*$e+s[Fe]*We+r[Fe]*ft)}let Ne=.6-ct*ct-st*st-Ht*Ht-kt*kt;if(Ne<0)g=0;else{const Fe=Be+V+e[Ve+Le+e[lt+Re+e[Qe+qe]]];Ne*=Ne,g=Ne*Ne*(t[Fe]*ct+i[Fe]*st+s[Fe]*Ht+r[Fe]*kt)}let je=.6-U*U-D*D-ce*ce-Ee*Ee;if(je<0)m=0;else{const Fe=Be+1+e[Ve+1+e[lt+1+e[Qe+1]]];je*=je,m=je*je*(t[Fe]*U+i[Fe]*D+s[Fe]*ce+r[Fe]*Ee)}return 27*(d+f+p+g+m)}}function qte(n){const t=new Uint8Array(512);for(let i=0;i<512/2;i++)t[i]=i;for(let i=0;i<512/2-1;i++){const s=i+~~(n()*(256-i)),r=t[i];t[i]=t[s],t[s]=r}for(let i=256;i<512;i++)t[i]=t[i-256];return t}var Xte=Object.defineProperty,Yte=Object.getOwnPropertyDescriptor,Y=(n,e,t,i)=>{for(var s=i>1?void 0:i?Yte(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Xte(e,t,s),s};const xy=le("debugparticles");var Aa=(n=>(n[n.Billboard=0]="Billboard",n[n.Stretch=1]="Stretch",n[n.HorizontalBillboard=2]="HorizontalBillboard",n[n.VerticalBillboard=3]="VerticalBillboard",n[n.Mesh=4]="Mesh",n))(Aa||{});class gh{constructor(){u(this,"alphaKeys");u(this,"colorKeys")}get duration(){return 1}evaluate(e,t){let i,s=0,r=null,o=0;for(let a=0;a<this.alphaKeys.length;a++){const l=this.alphaKeys[a];(l.time<e||!i)&&(i=l,s=a)}for(let a=0;a<this.colorKeys.length;a++){const l=this.colorKeys[a];(l.time<e||!r)&&(r=l,o=a)}if(r)if(o+1<this.colorKeys.length){const l=this.colorKeys[o+1],c=Ze.remap(e,r.time,l.time,0,1);t.r=Ze.lerp(r.color.r,l.color.r,c),t.g=Ze.lerp(r.color.g,l.color.g,c),t.b=Ze.lerp(r.color.b,l.color.b,c)}else t.r=r.color.r,t.g=r.color.g,t.b=r.color.b;if(i)if(s+1<this.alphaKeys.length){const l=this.alphaKeys[s+1],c=Ze.remap(e,i.time,l.time,0,1);t.alpha=Ze.lerp(i.alpha,l.alpha,c)}else t.alpha=i.alpha;return t}}Y([w()],gh.prototype,"alphaKeys",2);Y([w()],gh.prototype,"colorKeys",2);var Kb=(n=>(n[n.Local=0]="Local",n[n.World=1]="World",n[n.Custom=2]="Custom",n))(Kb||{}),IN=(n=>(n[n.Sphere=0]="Sphere",n[n.SphereShell=1]="SphereShell",n[n.Hemisphere=2]="Hemisphere",n[n.HemisphereShell=3]="HemisphereShell",n[n.Cone=4]="Cone",n[n.Box=5]="Box",n[n.Mesh=6]="Mesh",n[n.ConeShell=7]="ConeShell",n[n.ConeVolume=8]="ConeVolume",n[n.ConeVolumeShell=9]="ConeVolumeShell",n[n.Circle=10]="Circle",n[n.CircleEdge=11]="CircleEdge",n[n.SingleSidedEdge=12]="SingleSidedEdge",n[n.MeshRenderer=13]="MeshRenderer",n[n.SkinnedMeshRenderer=14]="SkinnedMeshRenderer",n[n.BoxShell=15]="BoxShell",n[n.BoxEdge=16]="BoxEdge",n[n.Donut=17]="Donut",n[n.Rectangle=18]="Rectangle",n[n.Sprite=19]="Sprite",n[n.SpriteRenderer=20]="SpriteRenderer",n))(IN||{});class ot{constructor(){u(this,"mode");u(this,"constant");u(this,"constantMin");u(this,"constantMax");u(this,"curve");u(this,"curveMin");u(this,"curveMax");u(this,"curveMultiplier")}evaluate(e,t){const i=t===void 0?Math.random():t;switch(this.mode){case 0:return this.constant;case 1:return e=Ze.clamp01(e),this.curve.evaluate(e)*this.curveMultiplier;case 2:const s=e*this.curveMin.duration,r=e*this.curveMax.duration;return Ze.lerp(this.curveMin.evaluate(s),this.curveMax.evaluate(r),i%1)*this.curveMultiplier;case 3:return Ze.lerp(this.constantMin,this.constantMax,i%1);default:this.curveMax.evaluate(e)*this.curveMultiplier;break}return 0}getMax(){switch(this.mode){case 0:return this.constant;case 1:return this.getMaxFromCurve(this.curve)*this.curveMultiplier;case 2:return Math.max(this.getMaxFromCurve(this.curveMin),this.getMaxFromCurve(this.curveMax))*this.curveMultiplier;case 3:return Math.max(this.constantMin,this.constantMax);default:return 0}}getMaxFromCurve(e){if(!e)return 0;let t=Number.MIN_VALUE;for(let i=0;i<e.keys.length;i++){const s=e.keys[i];s.value>t&&(t=s.value)}return t}}Y([w()],ot.prototype,"mode",2);Y([w()],ot.prototype,"constant",2);Y([w()],ot.prototype,"constantMin",2);Y([w()],ot.prototype,"constantMax",2);Y([w(Tu)],ot.prototype,"curve",2);Y([w(Tu)],ot.prototype,"curveMin",2);Y([w(Tu)],ot.prototype,"curveMax",2);Y([w()],ot.prototype,"curveMultiplier",2);var Fy;const Mo=(Fy=class{constructor(){u(this,"mode");u(this,"color");u(this,"colorMin");u(this,"colorMax");u(this,"gradient");u(this,"gradientMin");u(this,"gradientMax")}evaluate(n,e){const t=e===void 0?Math.random():e;switch(this.mode){case 0:return this.color;case 1:return this.gradient.evaluate(n,Mo._temp),Mo._temp;case 2:return Mo._temp.lerpColors(this.colorMin,this.colorMax,t);case 3:return this.gradientMin.evaluate(n,Mo._temp),this.gradientMax.evaluate(n,Mo._temp2),Mo._temp.lerp(Mo._temp2,t)}return Mo._temp.set(16711935),Mo._temp.alpha=1,Mo._temp}},u(Fy,"_temp",new xi(0,0,0,1)),u(Fy,"_temp2",new xi(0,0,0,1)),Fy);let ur=Mo;Y([w(xi)],ur.prototype,"color",2);Y([w(xi)],ur.prototype,"colorMin",2);Y([w(xi)],ur.prototype,"colorMax",2);Y([w(gh)],ur.prototype,"gradient",2);Y([w(gh)],ur.prototype,"gradientMin",2);Y([w(gh)],ur.prototype,"gradientMax",2);class cs{constructor(){u(this,"cullingMode");u(this,"duration");u(this,"emitterVelocityMode");u(this,"flipRotation");u(this,"gravityModifier");u(this,"gravityModifierMultiplier");u(this,"loop");u(this,"maxParticles");u(this,"playOnAwake");u(this,"prewarm");u(this,"ringBufferLoopRange");u(this,"ringBufferMode");u(this,"scalingMode");u(this,"simulationSpace");u(this,"simulationSpeed");u(this,"startColor");u(this,"startDelay");u(this,"startDelayMultiplier");u(this,"startLifetime");u(this,"startLifetimeMultiplier");u(this,"startRotation");u(this,"startRotationMultiplier");u(this,"startRotation3D");u(this,"startRotationX");u(this,"startRotationXMultiplier");u(this,"startRotationY");u(this,"startRotationYMultiplier");u(this,"startRotationZ");u(this,"startRotationZMultiplier");u(this,"startSize");u(this,"startSize3D");u(this,"startSizeMultiplier");u(this,"startSizeX");u(this,"startSizeXMultiplier");u(this,"startSizeY");u(this,"startSizeYMultiplier");u(this,"startSizeZ");u(this,"startSizeZMultiplier");u(this,"startSpeed");u(this,"startSpeedMultiplier");u(this,"stopAction");u(this,"useUnscaledTime")}}Y([w(ot)],cs.prototype,"gravityModifier",2);Y([w(ur)],cs.prototype,"startColor",2);Y([w(ot)],cs.prototype,"startDelay",2);Y([w(ot)],cs.prototype,"startLifetime",2);Y([w(ot)],cs.prototype,"startRotation",2);Y([w(ot)],cs.prototype,"startRotationX",2);Y([w(ot)],cs.prototype,"startRotationY",2);Y([w(ot)],cs.prototype,"startRotationZ",2);Y([w(ot)],cs.prototype,"startSize",2);Y([w(ot)],cs.prototype,"startSizeX",2);Y([w(ot)],cs.prototype,"startSizeY",2);Y([w(ot)],cs.prototype,"startSizeZ",2);Y([w(ot)],cs.prototype,"startSpeed",2);class Lm{constructor(){u(this,"cycleCount");u(this,"maxCount");u(this,"minCount");u(this,"probability");u(this,"repeatInterval");u(this,"time");u(this,"count");u(this,"_performed",0)}reset(){this._performed=0}run(e){if(e<=this.time)return this.reset(),0;let t=0;if(this.cycleCount===0||this._performed<this.cycleCount){const i=this.time+this.repeatInterval*this._performed;if(e>=i&&(this._performed+=1,Math.random()<this.probability))switch(this.count.mode){case 0:t=this.count.constant;break;case 3:t=Ze.lerp(this.count.constantMin,this.count.constantMax,Math.random());break;case 1:t=this.count.curve.evaluate(Math.random());break;case 2:const s=Math.random();t=Ze.lerp(this.count.curveMin.evaluate(s),this.count.curveMax.evaluate(s),Math.random());break}}return t}}class Qa{constructor(){u(this,"enabled");u(this,"bursts");u(this,"rateOverTime");u(this,"rateOverTimeMultiplier");u(this,"rateOverDistance");u(this,"rateOverDistanceMultiplier");u(this,"system")}get burstCount(){var e;return((e=this.bursts)==null?void 0:e.length)??0}reset(){var e;(e=this.bursts)==null||e.forEach(t=>t.reset())}getBurst(){let e=0;if(this.burstCount>0)for(let t=0;t<this.burstCount;t++){const i=this.bursts[t];i.time>=this.system.time&&i.reset(),e+=Math.round(i.run(this.system.time))}return e}}Y([w()],Qa.prototype,"enabled",2);Y([w()],Qa.prototype,"bursts",2);Y([w(ot)],Qa.prototype,"rateOverTime",2);Y([w()],Qa.prototype,"rateOverTimeMultiplier",2);Y([w(ot)],Qa.prototype,"rateOverDistance",2);Y([w()],Qa.prototype,"rateOverDistanceMultiplier",2);class WA{constructor(){u(this,"enabled");u(this,"color")}}Y([w(ur)],WA.prototype,"color",2);class mh{constructor(){u(this,"enabled");u(this,"separateAxes");u(this,"size");u(this,"sizeMultiplier");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier");u(this,"_time",0);u(this,"_temp",new S)}evaluate(e,t,i){if(t||(t=this._temp),!this.enabled)return t.x=t.y=t.z=1,t;if(this.separateAxes)t.x=this.x.evaluate(e,i)*this.xMultiplier,t.y=this.y.evaluate(e,i)*this.yMultiplier,t.z=this.z.evaluate(e,i)*this.zMultiplier;else{const s=this.size.evaluate(e,i)*this.sizeMultiplier;t.x=s}return t}}Y([w(ot)],mh.prototype,"size",2);Y([w(ot)],mh.prototype,"x",2);Y([w(ot)],mh.prototype,"y",2);Y([w(ot)],mh.prototype,"z",2);var Uy;const yg=(Uy=class{constructor(){u(this,"shapeType",5);u(this,"enabled",!0);u(this,"alignToDirection",!1);u(this,"angle",0);u(this,"arc",360);u(this,"arcSpread");u(this,"arcSpeedMultiplier");u(this,"arcMode");u(this,"boxThickness");u(this,"position");u(this,"rotation");u(this,"_rotation",new bn);u(this,"scale");u(this,"radius");u(this,"radiusThickness");u(this,"sphericalDirectionAmount");u(this,"randomDirectionAmount");u(this,"randomPositionAmount");u(this,"system");u(this,"_space");u(this,"_worldSpaceMatrix",new He);u(this,"_worldSpaceMatrixInverse",new He);u(this,"_vector",new S(0,0,0));u(this,"_temp",new S(0,0,0));u(this,"_dir",new S);u(this,"_loopTime",0);u(this,"_loopDirection",1);xy&&console.log(this)}get type(){return IN[this.shapeType]}initialize(n){this.getPosition(),n.position.copy(this._vector)}toJSON(){return this}clone(){return new yg}update(n,e,t,i){this.system=n,this._space=t,t===1&&(this._worldSpaceMatrix.copy(i.matrixWorld),this._worldSpaceMatrix.elements[0]=1,this._worldSpaceMatrix.elements[5]=1,this._worldSpaceMatrix.elements[10]=1,this._worldSpaceMatrixInverse.copy(this._worldSpaceMatrix).invert())}applyRotation(n){const e=this.rotation.x!==0||this.rotation.y!==0||this.rotation.z!==0;return e&&(this._rotation.x=Ze.toRadians(this.rotation.x),this._rotation.y=Ze.toRadians(this.rotation.y),this._rotation.z=Ze.toRadians(this.rotation.z),this._rotation.order="ZYX",n.applyEuler(this._rotation)),e}get vector(){return this._vector}getPosition(){this._vector.set(0,0,0);const n=this._temp.copy(this.position),e=this._space===1;e&&n.applyQuaternion(this.system.worldQuaternion);let t=this.radius;if(e&&(t*=this.system.worldScale.x),this.enabled){switch(this.shapeType){case 5:xy&&xa.DrawBox(this.position,this.scale,14540253,1),this._vector.x=Math.random()*this.scale.x-this.scale.x/2,this._vector.y=Math.random()*this.scale.y-this.scale.y/2,this._vector.z=Math.random()*this.scale.z-this.scale.z/2,this._vector.add(n);break;case 4:this.randomConePoint(this.position,this.angle,t,this.radiusThickness,this.arc,this.arcMode,this._vector);break;case 0:this.randomSpherePoint(this.position,t,this.radiusThickness,this.arc,this._vector);break;case 10:this.randomCirclePoint(this.position,t,this.radiusThickness,this.arc,this._vector);break;default:this._vector.set(0,0,0);break}this.randomizePosition(this._vector,this.randomPositionAmount)}this.applyRotation(this._vector),e&&(this._vector.applyQuaternion(this.system.worldQuaternion),this._vector.add(this.system.worldPos)),xy&&xa.DrawSphere(this._vector,.03,16711680,.5,!0)}getDirection(n){var e;if(!this.enabled)return this._dir.set(0,0,1),this._dir;switch(this.shapeType){case 5:this._dir.set(0,0,1);break;case 4:this._dir.set(0,0,1);break;case 10:case 0:const t=n.x,i=n.y,s=n.z;this._dir.set(t,i,s),(e=this.system)!=null&&e.worldspace?this._dir.sub(this.system.worldPos):this._dir.sub(this.position);break;default:this._dir.set(0,0,1);break}return this._space===1&&this._dir.applyQuaternion(this.system.worldQuaternion),this.applyRotation(this._dir),this._dir.normalize(),this.spherizeDirection(this._dir,this.sphericalDirectionAmount),this.randomizeDirection(this._dir,this.randomDirectionAmount),xy&&(xa.DrawSphere(n,.01,8925952,.5,!0),xa.DrawDirection(n,this._dir,8925952,.5,!0)),this._dir}randomizePosition(n,e){if(e<=0)return;const t=yg._tempVec;t.set(Math.random()*2-1,Math.random()*2-1,Math.random()*2-1),t.x*=e*this.scale.x,t.y*=e*this.scale.y,t.z*=e*this.scale.z,n.add(t)}randomizeDirection(n,e){if(e===0)return;const t=yg._randomQuat,i=yg._tempVec;i.set(Math.random()-.5,Math.random()-.5,Math.random()-.5).normalize(),t.setFromAxisAngle(i,e*Math.random()*Math.PI),n.applyQuaternion(t)}spherizeDirection(n,e){if(e===0)return;const t=Math.random()*Math.PI*2,i=Math.acos(1-Math.random()*2),s=Math.sin(i)*Math.cos(t),r=Math.sin(i)*Math.sin(t),o=Math.cos(i),a=new S(s,r,o);n.lerp(a,e)}randomSpherePoint(n,e,t,i,s){const r=Math.random(),o=Math.random(),a=2*Math.PI*r*(i/360),l=Math.acos(2*o-1),c=Ze.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,h=n.x+this.scale.x*(-c*Math.sin(l)*Math.cos(a)),d=n.y+this.scale.y*(c*Math.sin(l)*Math.sin(a)),f=n.z+this.scale.z*(c*Math.cos(l));s.x=h,s.y=d,s.z=f}randomCirclePoint(n,e,t,i,s){const r=Math.random(),o=2*Math.PI*r*(i/360),a=Ze.lerp(1,1-Math.pow(1-Math.random(),Math.PI),t)*e,l=n.x+this.scale.x*a*Math.cos(o),c=n.y+this.scale.y*a*Math.sin(o),h=n.z;s.x=l,s.y=c,s.z=h}randomConePoint(n,e,t,i,s,r,o){let a=0,l=0;switch(r){case 0:a=Math.random(),l=Math.random();break;case 2:this._loopTime>1&&(this._loopDirection=-1),this._loopTime<0&&(this._loopDirection=1);case 1:a=.5,l=Math.random(),this._loopTime+=this.system.deltaTime*this._loopDirection;break}let c=2*Math.PI*a*(s/360);switch(r){case 2:case 1:c+=Math.PI+.5,c+=this._loopTime*Math.PI*2,c%=Ze.toRadians(s);break}const h=Math.acos(2*l-1),d=Ze.lerp(1,1-Math.pow(1-Math.random(),Math.PI),i)*t,f=n.x+-d*Math.sin(h)*Math.cos(c),p=n.y+d*Math.sin(h)*Math.sin(c),g=n.z;o.x=f*this.scale.x,o.y=p*this.scale.y,o.z=g*this.scale.z}},u(Uy,"_randomQuat",new xe),u(Uy,"_tempVec",new S),Uy);let dn=yg;Y([w()],dn.prototype,"shapeType",2);Y([w()],dn.prototype,"enabled",2);Y([w()],dn.prototype,"alignToDirection",2);Y([w()],dn.prototype,"angle",2);Y([w()],dn.prototype,"arc",2);Y([w()],dn.prototype,"arcSpread",2);Y([w()],dn.prototype,"arcSpeedMultiplier",2);Y([w()],dn.prototype,"arcMode",2);Y([w(S)],dn.prototype,"boxThickness",2);Y([w(S)],dn.prototype,"position",2);Y([w(S)],dn.prototype,"rotation",2);Y([w(S)],dn.prototype,"scale",2);Y([w()],dn.prototype,"radius",2);Y([w()],dn.prototype,"radiusThickness",2);Y([w()],dn.prototype,"sphericalDirectionAmount",2);Y([w()],dn.prototype,"randomDirectionAmount",2);Y([w()],dn.prototype,"randomPositionAmount",2);class di{constructor(){u(this,"damping");u(this,"enabled");u(this,"frequency");u(this,"octaveCount");u(this,"octaveMultiplier");u(this,"octaveScale");u(this,"positionAmount");u(this,"quality");u(this,"remap");u(this,"remapEnabled");u(this,"remapMultiplier");u(this,"remapX");u(this,"remapXMultiplier");u(this,"remapY");u(this,"remapYMultiplier");u(this,"remapZ");u(this,"remapZMultiplier");u(this,"scrollSpeedMultiplier");u(this,"separateAxes");u(this,"strengthMultiplier");u(this,"strengthX");u(this,"strengthXMultiplier");u(this,"strengthY");u(this,"strengthYMultiplier");u(this,"strengthZ");u(this,"strengthZMultiplier");u(this,"_noise");u(this,"_time",0);u(this,"_temp",new S)}update(e){this._time+=e.time.deltaTime*this.scrollSpeedMultiplier}apply(e,t,i,s,r,o){if(!this.enabled)return;this._noise||(this._noise=Wte(()=>0));const a=this._temp.set(t.x,t.y,t.z).multiplyScalar(this.frequency),l=this._noise(a.x,a.y,a.z,this._time),c=this._noise(a.x,a.y,a.z,this._time+1e3*this.frequency),h=this._noise(a.x,a.y,a.z,this._time+2e3*this.frequency);this._temp.set(l,c,h).normalize();const d=r/o;let f=this.positionAmount.evaluate(d);this.separateAxes?(this._temp.x*=f*this.strengthXMultiplier,this._temp.y*=f*this.strengthYMultiplier,this._temp.z*=f*this.strengthZMultiplier):(this.strengthX&&(f*=this.strengthX.evaluate(d)*1.5),this._temp.multiplyScalar(f)),i.x+=this._temp.x,i.y+=this._temp.y,i.z+=this._temp.z}}Y([w()],di.prototype,"damping",2);Y([w()],di.prototype,"enabled",2);Y([w()],di.prototype,"frequency",2);Y([w()],di.prototype,"octaveCount",2);Y([w()],di.prototype,"octaveMultiplier",2);Y([w()],di.prototype,"octaveScale",2);Y([w(ot)],di.prototype,"positionAmount",2);Y([w()],di.prototype,"quality",2);Y([w(ot)],di.prototype,"remap",2);Y([w()],di.prototype,"remapEnabled",2);Y([w()],di.prototype,"remapMultiplier",2);Y([w(ot)],di.prototype,"remapX",2);Y([w()],di.prototype,"remapXMultiplier",2);Y([w(ot)],di.prototype,"remapY",2);Y([w()],di.prototype,"remapYMultiplier",2);Y([w(ot)],di.prototype,"remapZ",2);Y([w()],di.prototype,"remapZMultiplier",2);Y([w()],di.prototype,"scrollSpeedMultiplier",2);Y([w()],di.prototype,"separateAxes",2);Y([w()],di.prototype,"strengthMultiplier",2);Y([w(ot)],di.prototype,"strengthX",2);Y([w()],di.prototype,"strengthXMultiplier",2);Y([w(ot)],di.prototype,"strengthY",2);Y([w()],di.prototype,"strengthYMultiplier",2);Y([w(ot)],di.prototype,"strengthZ",2);Y([w()],di.prototype,"strengthZMultiplier",2);class Ui{constructor(){u(this,"enabled");u(this,"attachRibbonToTransform",!1);u(this,"colorOverLifetime");u(this,"colorOverTrail");u(this,"dieWithParticles",!0);u(this,"inheritParticleColor",!0);u(this,"lifetime");u(this,"lifetimeMultiplier");u(this,"minVertexDistance",.2);u(this,"mode",0);u(this,"ratio",1);u(this,"ribbonCount",1);u(this,"shadowBias",0);u(this,"sizeAffectsLifetime",!1);u(this,"sizeAffectsWidth",!1);u(this,"splitSubEmitterRibbons",!1);u(this,"textureMode",0);u(this,"widthOverTrail");u(this,"widthOverTrailMultiplier");u(this,"worldSpace",!1)}getWidth(e,t,i){let s=this.widthOverTrail.evaluate(i);return i===0&&(s=e),e*=s,e}getColor(e,t,i){const s=this.colorOverTrail.evaluate(i),r=this.colorOverLifetime.evaluate(t);e.x*=s.r*r.r,e.y*=s.g*r.g,e.z*=s.b*r.b,e.w*=s.alpha*r.alpha}}Y([w()],Ui.prototype,"enabled",2);Y([w()],Ui.prototype,"attachRibbonToTransform",2);Y([w(ur)],Ui.prototype,"colorOverLifetime",2);Y([w(ur)],Ui.prototype,"colorOverTrail",2);Y([w()],Ui.prototype,"dieWithParticles",2);Y([w()],Ui.prototype,"inheritParticleColor",2);Y([w(ot)],Ui.prototype,"lifetime",2);Y([w()],Ui.prototype,"lifetimeMultiplier",2);Y([w()],Ui.prototype,"minVertexDistance",2);Y([w()],Ui.prototype,"mode",2);Y([w()],Ui.prototype,"ratio",2);Y([w()],Ui.prototype,"ribbonCount",2);Y([w()],Ui.prototype,"shadowBias",2);Y([w()],Ui.prototype,"sizeAffectsLifetime",2);Y([w()],Ui.prototype,"sizeAffectsWidth",2);Y([w()],Ui.prototype,"splitSubEmitterRibbons",2);Y([w()],Ui.prototype,"textureMode",2);Y([w(ot)],Ui.prototype,"widthOverTrail",2);Y([w()],Ui.prototype,"widthOverTrailMultiplier",2);Y([w()],Ui.prototype,"worldSpace",2);class Vi{constructor(){u(this,"enabled");u(this,"space",0);u(this,"orbitalX");u(this,"orbitalY");u(this,"orbitalZ");u(this,"orbitalXMultiplier");u(this,"orbitalYMultiplier");u(this,"orbitalZMultiplier");u(this,"orbitalOffsetX");u(this,"orbitalOffsetY");u(this,"orbitalOffsetZ");u(this,"speedModifier");u(this,"speedModifierMultiplier");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier");u(this,"_system");u(this,"_temp",new S);u(this,"_temp2",new S);u(this,"_temp3",new S);u(this,"_hasOrbital",!1);u(this,"_index",0);u(this,"_orbitalMatrix",new He)}update(e){this._system=e}init(e){this._index==0&&(e.debug=!0),this._index+=1,e.orbitx=this.orbitalX.evaluate(Math.random()),e.orbity=this.orbitalY.evaluate(Math.random()),e.orbitz=this.orbitalZ.evaluate(Math.random()),this._hasOrbital=e.orbitx!=0||e.orbity!=0||e.orbitz!=0}apply(e,t,i,s,r,o,a){var p;if(!this.enabled)return;const l=o/a,c=this.speedModifier.evaluate(l)*this.speedModifierMultiplier,h=this.x.evaluate(l),d=this.y.evaluate(l),f=this.z.evaluate(l);if(this._temp.set(-h,d,f),this._system,this._hasOrbital&&((p=this._system)==null?void 0:p.worldPos)){const m=this._temp2.set(i.x,i.y,i.z),A=this.orbitalXMultiplier,v=this.orbitalYMultiplier,b=this.orbitalZMultiplier,y=c*Math.PI*2*10,_=Math.cos(y*A),C=Math.sin(y*A),E=Math.cos(y*v),T=Math.sin(y*v),x=Math.cos(y*b),M=Math.sin(y*b),P=m.x*(E*x)+m.y*(E*M)+m.z*-T,k=m.x*(C*T*x-_*M)+m.y*(C*T*M+_*x)+m.z*(C*E),G=m.x*(_*T*x+C*M)+m.y*(_*T*M-C*x)+m.z*(_*E),z=this._temp3.set(m.x-P,m.y-k,m.z-G);z.normalize(),z.multiplyScalar(.2/r*Math.max(this.orbitalXMultiplier,this.orbitalYMultiplier,this.orbitalZMultiplier)),s.x+=z.x,s.y+=z.y,s.z+=z.z}s.x+=this._temp.x,s.y+=this._temp.y,s.z+=this._temp.z,s.x*=c,s.y*=c,s.z*=c}}Y([w()],Vi.prototype,"enabled",2);Y([w()],Vi.prototype,"space",2);Y([w(ot)],Vi.prototype,"orbitalX",2);Y([w(ot)],Vi.prototype,"orbitalY",2);Y([w(ot)],Vi.prototype,"orbitalZ",2);Y([w()],Vi.prototype,"orbitalXMultiplier",2);Y([w()],Vi.prototype,"orbitalYMultiplier",2);Y([w()],Vi.prototype,"orbitalZMultiplier",2);Y([w()],Vi.prototype,"orbitalOffsetX",2);Y([w()],Vi.prototype,"orbitalOffsetY",2);Y([w()],Vi.prototype,"orbitalOffsetZ",2);Y([w(ot)],Vi.prototype,"speedModifier",2);Y([w()],Vi.prototype,"speedModifierMultiplier",2);Y([w(ot)],Vi.prototype,"x",2);Y([w()],Vi.prototype,"xMultiplier",2);Y([w(ot)],Vi.prototype,"y",2);Y([w()],Vi.prototype,"yMultiplier",2);Y([w(ot)],Vi.prototype,"z",2);Y([w()],Vi.prototype,"zMultiplier",2);class hs{constructor(){u(this,"animation");u(this,"enabled");u(this,"cycleCount");u(this,"frameOverTime");u(this,"frameOverTimeMultiplier");u(this,"numTilesX");u(this,"numTilesY");u(this,"startFrame");u(this,"startFrameMultiplier");u(this,"rowMode");u(this,"rowIndex");u(this,"spriteCount");u(this,"timeMode")}sampleOnceAtStart(){if(this.timeMode===0)switch(this.frameOverTime.mode){case 0:case 3:case 2:case 1:return!0}return!1}getStartIndex(){return this.sampleOnceAtStart()?Math.random()*(this.numTilesX*this.numTilesY):0}evaluate(e){if(!this.sampleOnceAtStart())return this.getIndex(e)}getIndex(e){const t=this.numTilesX*this.numTilesY;e=e*this.cycleCount;let i=this.frameOverTime.evaluate(e%1);return i*=this.frameOverTimeMultiplier,i*=t,i=i%t,i=Math.floor(i),i}}Y([w()],hs.prototype,"animation",2);Y([w()],hs.prototype,"enabled",2);Y([w()],hs.prototype,"cycleCount",2);Y([w(ot)],hs.prototype,"frameOverTime",2);Y([w()],hs.prototype,"frameOverTimeMultiplier",2);Y([w()],hs.prototype,"numTilesX",2);Y([w()],hs.prototype,"numTilesY",2);Y([w(ot)],hs.prototype,"startFrame",2);Y([w()],hs.prototype,"startFrameMultiplier",2);Y([w()],hs.prototype,"rowMode",2);Y([w()],hs.prototype,"rowIndex",2);Y([w()],hs.prototype,"spriteCount",2);Y([w()],hs.prototype,"timeMode",2);class Ao{constructor(){u(this,"enabled");u(this,"separateAxes");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier")}evaluate(e,t){return this.enabled?this.separateAxes?0:this.z.evaluate(e,t)*-1:0}}Y([w()],Ao.prototype,"enabled",2);Y([w()],Ao.prototype,"separateAxes",2);Y([w(ot)],Ao.prototype,"x",2);Y([w()],Ao.prototype,"xMultiplier",2);Y([w(ot)],Ao.prototype,"y",2);Y([w()],Ao.prototype,"yMultiplier",2);Y([w(ot)],Ao.prototype,"z",2);Y([w()],Ao.prototype,"zMultiplier",2);class Or{constructor(){u(this,"enabled");u(this,"range");u(this,"separateAxes");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier")}evaluate(e,t){if(!this.enabled)return 0;if(!this.separateAxes){const i=Ze.lerp(this.range.x,this.range.y,t);return this.z.evaluate(i)*-1}return 0}}Y([w()],Or.prototype,"enabled",2);Y([w()],Or.prototype,"range",2);Y([w()],Or.prototype,"separateAxes",2);Y([w(ot)],Or.prototype,"x",2);Y([w()],Or.prototype,"xMultiplier",2);Y([w(ot)],Or.prototype,"y",2);Y([w()],Or.prototype,"yMultiplier",2);Y([w(ot)],Or.prototype,"z",2);Y([w()],Or.prototype,"zMultiplier",2);class Sn{constructor(){u(this,"enabled");u(this,"dampen");u(this,"drag");u(this,"dragMultiplier");u(this,"limit");u(this,"limitMultiplier");u(this,"separateAxes");u(this,"limitX");u(this,"limitXMultiplier");u(this,"limitY");u(this,"limitYMultiplier");u(this,"limitZ");u(this,"limitZMultiplier");u(this,"multiplyDragByParticleSize",!1);u(this,"multiplyDragByParticleVelocity",!1);u(this,"space");u(this,"_temp",new S);u(this,"_temp2",new S)}apply(e,t,i,s,r,o,a){if(this.enabled){const l=this.limit.evaluate(r)*this.limitMultiplier;if(t.length()>l){this._temp.copy(t).normalize().multiplyScalar(l);let h=this.dampen*.5;t.x=Ze.lerp(t.x,this._temp.x,h),t.y=Ze.lerp(t.y,this._temp.y,h),t.z=Ze.lerp(t.z,this._temp.z,h),i.x=Ze.lerp(i.x,this._temp.x,h),i.y=Ze.lerp(i.y,this._temp.y,h),i.z=Ze.lerp(i.z,this._temp.z,h)}}}}Y([w()],Sn.prototype,"enabled",2);Y([w()],Sn.prototype,"dampen",2);Y([w(ot)],Sn.prototype,"drag",2);Y([w()],Sn.prototype,"dragMultiplier",2);Y([w(ot)],Sn.prototype,"limit",2);Y([w()],Sn.prototype,"limitMultiplier",2);Y([w()],Sn.prototype,"separateAxes",2);Y([w(ot)],Sn.prototype,"limitX",2);Y([w()],Sn.prototype,"limitXMultiplier",2);Y([w(ot)],Sn.prototype,"limitY",2);Y([w()],Sn.prototype,"limitYMultiplier",2);Y([w(ot)],Sn.prototype,"limitZ",2);Y([w()],Sn.prototype,"limitZMultiplier",2);Y([w()],Sn.prototype,"multiplyDragByParticleSize",2);Y([w()],Sn.prototype,"multiplyDragByParticleVelocity",2);Y([w()],Sn.prototype,"space",2);class Ah{constructor(){u(this,"enabled");u(this,"curve");u(this,"curveMultiplier");u(this,"mode");u(this,"system");u(this,"_lastWorldPosition");u(this,"_velocity",new S);u(this,"_temp",new S)}update(e){this.enabled&&this.system.worldspace!==!1&&(this._lastWorldPosition?(this._velocity.copy(this.system.worldPos).sub(this._lastWorldPosition).multiplyScalar(1/this.system.deltaTime),this._lastWorldPosition.copy(this.system.worldPos)):(this._velocity.set(0,0,0),this._lastWorldPosition=this.system.worldPos.clone()))}applyInitial(e){if(this.enabled&&this.system.worldspace!==!1&&this.mode===0){const t=this.curve.evaluate(Math.random(),Math.random());this._temp.copy(this._velocity).multiplyScalar(t),e.add(this._temp)}}applyCurrent(e,t,i){if(this.enabled&&this.system.worldspace!==!1&&this.mode===1){const s=this.curve.evaluate(t,i);this._temp.copy(this._velocity).multiplyScalar(s),e.add(this._temp)}}}Y([w()],Ah.prototype,"enabled",2);Y([w(ot)],Ah.prototype,"curve",2);Y([w()],Ah.prototype,"curveMultiplier",2);Y([w()],Ah.prototype,"mode",2);class Ws{constructor(){u(this,"enabled");u(this,"range");u(this,"separateAxes");u(this,"size");u(this,"sizeMultiplier");u(this,"x");u(this,"xMultiplier");u(this,"y");u(this,"yMultiplier");u(this,"z");u(this,"zMultiplier")}evaluate(e,t,i,s){const r=e.length(),o=Ze.remap(r,this.range.x,this.range.y,0,1),a=this.size.evaluate(o,i);return s*a}}Y([w()],Ws.prototype,"enabled",2);Y([w(q)],Ws.prototype,"range",2);Y([w()],Ws.prototype,"separateAxes",2);Y([w(ot)],Ws.prototype,"size",2);Y([w()],Ws.prototype,"sizeMultiplier",2);Y([w(ot)],Ws.prototype,"x",2);Y([w()],Ws.prototype,"xMultiplier",2);Y([w(ot)],Ws.prototype,"y",2);Y([w()],Ws.prototype,"yMultiplier",2);Y([w(ot)],Ws.prototype,"z",2);Y([w()],Ws.prototype,"zMultiplier",2);class Nu{constructor(){u(this,"enabled");u(this,"range");u(this,"color")}evaluate(e,t,i){const s=e.length(),r=Ze.remap(s,this.range.x,this.range.y,0,1),o=this.color.evaluate(r,t);i.x*=o.r,i.y*=o.g,i.z*=o.b,i.w*=o.alpha}}Y([w()],Nu.prototype,"enabled",2);Y([w(q)],Nu.prototype,"range",2);Y([w(ur)],Nu.prototype,"color",2);function Jte(n){const e=n.domElement.querySelector("link[rel='ar']");if(e)return e;const t=document.createElement("div");t.classList.add("menu"),t.classList.add("quicklook-menu"),t.style.display="none",t.style.visibility="hidden";const i=document.createElement("button");i.id="open-in-ar",i.innerText="Open in QuickLook",t.appendChild(i);const s=document.createElement("a");s.id="needle-usdz-link",s.style.display="none",s.rel="ar",s.href="",t.appendChild(s);const r=document.createElement("img");return r.id="button",s.appendChild(r),n.domElement.appendChild(t),s}function Kte(){var n=new Date;const e=n.getMonth()+1,t=n.getDate(),i=n.getHours(),s=n.getMinutes(),r=n.getSeconds(),o=(e<10?"0":"")+e,a=(t<10?"0":"")+t,l=(i<10?"0":"")+i,c=(s<10?"0":"")+s,h=(r<10?"0":"")+r;return n.getFullYear()+o+a+"-"+l+c+h}const wy=le("debugusdz");function Zte(n,e){const t=[],i=$.getComponentsInChildren(n,hr);let s=!1;wy&&console.log(i);for(const r of i){if(!r||!r.runtimeAnimatorController)continue;wy&&console.log(r);const o=[];for(const a of r.runtimeAnimatorController.enumerateActions()){wy&&console.log(a);const l=a.getClip();if(!s&&l.tracks.length>0){s=!0;const c=l.tracks[0],h=c.name.substring(0,c.name.lastIndexOf(".")),d=new Pr(h+".position",[0,.01],[0,0,0,0,0,0]),f=new Pr(h+".quaternion",[0,.01],[0,0,0,1,0,0,0,1]);o.push(new uo("rest",.01,[d,f]))}o.includes(l)||o.push(l)}t.push({root:r.gameObject,clips:o})}wy&&console.log(t);for(const r of t)for(const o of r.clips)e.registerAnimation(r.root,o)}var $te=Object.defineProperty,eie=Object.getOwnPropertyDescriptor,Kl=(n,e,t,i)=>{for(var s=i>1?void 0:i?eie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&$te(e,t,s),s};const eC=le("debugtext");var Tn=(n=>(n[n.UpperLeft=0]="UpperLeft",n[n.UpperCenter=1]="UpperCenter",n[n.UpperRight=2]="UpperRight",n[n.MiddleLeft=3]="MiddleLeft",n[n.MiddleCenter=4]="MiddleCenter",n[n.MiddleRight=5]="MiddleRight",n[n.LowerLeft=6]="LowerLeft",n[n.LowerCenter=7]="LowerCenter",n[n.LowerRight=8]="LowerRight",n))(Tn||{});class qs extends Ou{constructor(){super(...arguments);u(this,"alignment",0);u(this,"verticalOverflow",0);u(this,"horizontalOverflow",0);u(this,"lineSpacing",1);u(this,"supportRichText",!1);u(this,"font");u(this,"fontStyle",0);u(this,"_text","");u(this,"_fontSize",12);u(this,"_textMeshUi",null);u(this,"_didHandleTextRenderOnTop",!1)}setAlphaFactor(t){var i;super.setAlphaFactor(t),(i=this.uiObject)==null||i.set({fontOpacity:this.color.alpha*this.alphaFactor}),this.markDirty()}get text(){return this._text}set text(t){t!==this._text&&(this._text=t,this.feedText(this.text,this.supportRichText),this.markDirty())}set_text(t){this.text=t}get fontSize(){return this._fontSize}set fontSize(t){var i;this._fontSize=t,(i=this.uiObject)==null||i.set({fontSize:t})}onColorChanged(){var t;(t=this.uiObject)==null||t.set({color:this.color,fontOpacity:this.color.alpha})}onParentRectTransformChanged(){super.onParentRectTransformChanged(),this.uiObject&&this.updateOverflow()}onBeforeRender(){this.uiObject&&this.Root.screenspace&&this.updateOverflow()}updateOverflow(){var i;const t=(i=this.uiObject)==null?void 0:i._overflow;t&&(t._needsUpdate=!0,this.markDirty())}onCreate(t){eC&&console.log(this),this.horizontalOverflow==1&&(t.whiteSpace="pre"),this.verticalOverflow==0&&(this.context.renderer.localClippingEnabled=!0,t.overflow="hidden"),this.horizontalOverflow==1&&this.verticalOverflow==0,t.lineHeight=this.lineSpacing,delete t.backgroundOpacity,delete t.backgroundColor,eC&&(t.backgroundColor=16750848,t.backgroundOpacity=.5);const i=this.rectTransform;t={...t,...this.getTextOpts()},this.getAlignment(t),eC&&(t.backgroundColor=Math.random()*16777215,t.backgroundOpacity=.1),this.uiObject=i.createNewText(t),this.feedText(this.text,this.supportRichText)}onAfterAddedToScene(){super.onAfterAddedToScene(),this.handleTextRenderOnTop()}getTextOpts(){let t=this.fontSize;const i={color:this.color,fontOpacity:this.color.alpha,fontSize:t,fontKerning:"normal"};return this.setFont(i,this.fontStyle),i}onEnable(){super.onEnable(),this._didHandleTextRenderOnTop=!1,this.uiObject&&this.uiObject.addAfterUpdate(()=>{this.setShadowComponentOwner(this.uiObject),this.markDirty()}),setTimeout(()=>this.markDirty(),10)}getAlignment(t){switch(t.flexDirection="column",this.alignment){case 0:case 3:case 6:t.textAlign="left";break;case 1:case 4:case 7:t.textAlign="center";break;case 2:case 5:case 8:t.textAlign="right";break}switch(this.alignment){default:case 0:case 1:case 2:t.alignItems="start";break;case 3:case 4:case 5:t.alignItems="center";break;case 6:case 7:case 8:t.alignItems="end";break}return t}feedText(t,i){var s,r,o;if(!this.uiObject)return null;if(this._textMeshUi||(this._textMeshUi=[]),!i||t.length===0)this.uiObject.textContent=t;else{let a=this.getNextTag(t);if(a)a.startIndex>0&&this.uiObject.add(new d0({textContent:t.substring(0,a.startIndex),color:"inherit"}));else return this.uiObject.textContent=t;const l=[];for(;a;){const c=this.getNextTag(t,a.endIndex),h={fontFamily:(s=this.uiObject)==null?void 0:s.get("fontFamily"),color:"inherit",textContent:""};c?(h.textContent=this.getText(t,a,c),this.handleTag(a,h,l),(r=this.uiObject)==null||r.add(new d0(h))):(h.textContent=t.substring(a.endIndex),this.handleTag(a,h,l),(o=this.uiObject)==null||o.add(new d0(h))),a=c}}return null}handleTextRenderOnTop(){this._didHandleTextRenderOnTop||(this._didHandleTextRenderOnTop=!0,this.startCoroutine(this.renderOnTopCoroutine()))}*renderOnTopCoroutine(){if(!this.canvas)return;const t=[],i=this.canvas,s={renderOnTop:i.renderOnTop,depthWrite:i.depthWrite,doubleSided:i.doubleSided};for(;;){let r=!1;if(this._textMeshUi)for(let o=0;o<this._textMeshUi.length;o++){if(t[o]===!0)continue;r=!0;const a=this._textMeshUi[o];a.textContent&&(p_(a,s),t[o]=!0)}if(!r)break;yield}}handleTag(t,i,s){if(t.isEndTag){if(s.length>0){const r=s.pop();if(r)for(const o in r.previousValues){const a=r.previousValues[o];i[o]=a}}}else if(t.type.includes("color")){const r=new tC(t,{color:i.color});if(s.push(r),t.type.length>6){const o=parseInt("0x"+t.type.substring(7));i.color=o}else i.color=new _e(1,1,1)}else if(t.type=="b"){this.setFont(i,1);const r=new tC(t,{fontWeight:700});s.push(r)}else if(t.type=="i"){this.setFont(i,2);const r=new tC(t,{fontStyle:"italic"});s.push(r)}}getText(t,i,s){return t.substring(i.endIndex,s.startIndex)}getNextTag(t,i=0){const s=t.indexOf("<",i),r=t.indexOf(">",s);if(s>=0&&r>=0){const o=t.substring(s+1,r);return{type:o,startIndex:s,endIndex:r+1,isEndTag:o.startsWith("/")}}return null}setFont(t,i){if(!this.font)return;let s=this.font,r=nE.getFontFamily(s);r||(r=nE.addFontFamily(s)),t.fontFamily=r;const o=s.toLowerCase();switch(i){default:case 0:t.fontWeight=400,t.fontStyle="normal";break;case 1:t.fontWeight=700,t.fontStyle="normal",o.includes("-bold")||(s+="-bold");break;case 2:t.fontWeight=400,t.fontStyle="italic",o.includes("-italic")||(s+="-italic");break;case 3:t.fontStyle="italic",t.fontWeight=400,o.includes("-bold")||(s+="-bold"),o.includes("-italic")||(s+="-italic")}let a=r.getVariant(t.fontWeight,t.fontStyle);if(!a){let l=s;l!=null&&l.endsWith("-msdf.json")||(l+="-msdf.json");let c=s;c!=null&&c.endsWith(".png")||(c+=".png"),a=r.addVariant(t.fontWeight,t.fontStyle,l,c),a==null||a.addEventListener("ready",()=>{this.markDirty()})}}}Kl([w()],qs.prototype,"alignment",2);Kl([w()],qs.prototype,"verticalOverflow",2);Kl([w()],qs.prototype,"horizontalOverflow",2);Kl([w()],qs.prototype,"lineSpacing",2);Kl([w()],qs.prototype,"supportRichText",2);Kl([w(URL)],qs.prototype,"font",2);Kl([w()],qs.prototype,"fontStyle",2);Kl([w()],qs.prototype,"text",1);Kl([w()],qs.prototype,"fontSize",1);class tC{constructor(e,t){u(this,"tag");u(this,"previousValues");this.tag=e,this.previousValues=t}}class Oc{constructor(e){u(this,"id");u(this,"content","");u(this,"font",[]);u(this,"pointSize",144);u(this,"width");u(this,"height");u(this,"depth");u(this,"wrapMode");u(this,"horizontalAlignment");u(this,"verticalAlignment");u(this,"material");this.id=e}static getId(){return this.global_id++}setDepth(e){return this.depth=e,this}setPointSize(e){return this.pointSize=e,this}setHorizontalAlignment(e){return this.horizontalAlignment=e,this}setVerticalAlignment(e){return this.verticalAlignment=e,this}writeTo(e,t){var s;t.beginBlock(`def Preliminary_Text "${this.id}"`),this.content&&t.appendLine(`string content = "${this.content}"`),(!this.font||this.font.length<=0)&&(this.font||(this.font=[]),(s=this.font)==null||s.push("sans-serif"));const i=this.font.map(r=>`"${r}"`).join(", ");t.appendLine(`string[] font = [ ${i} ]`),t.appendLine(`double pointSize = ${this.pointSize}`),typeof this.width=="number"&&t.appendLine(`double width = ${this.width}`),typeof this.height=="number"&&t.appendLine(`double height = ${this.height}`),typeof this.depth=="number"&&t.appendLine(`double depth = ${this.depth}`),this.wrapMode&&t.appendLine(`token wrapMode = "${this.wrapMode}"`),this.horizontalAlignment&&t.appendLine(`token horizontalAlignment = "${this.horizontalAlignment}"`),this.verticalAlignment&&t.appendLine(`token verticalAlignment = "${this.verticalAlignment}"`),this.material!==void 0&&t.appendLine(`rel material:binding = </Materials/Material_${this.material.id}>`),t.closeBlock()}}u(Oc,"global_id",0);class Zb{static singleLine(e,t,i){const s=new Oc("text_"+Oc.getId());return s.content=e,t&&(s.pointSize=t),i&&(s.depth=i),s}static multiLine(e,t,i,s,r,o){const a=new Oc("text_"+Oc.getId());return a.content=e,a.width=t,a.height=i,a.horizontalAlignment=s,a.verticalAlignment=r,o!==void 0&&(a.wrapMode=o),a}}const tie=new He().makeRotationY(Math.PI);class $b{get extensionName(){return"text"}onExportObject(e,t,i){const s=$.getComponent(e,qs);if(s){const r=$.getComponent(e,xs);let o=100,a=100;r&&(o=r.width,a=r.height);const l=t.clone();l.matrix=tie.clone();const c=new _e().copySRGBToLinear(s.color);l.material=new Cu({color:c,emissive:c}),t.add(l),l.addEventListener("serialize",(h,d)=>{const f=Zb.multiLine(s.text,o,a,"center","bottom","flowing");this.setTextAlignment(f,s.alignment),this.setOverflow(f,s),l.material&&(f.material=l.material),f.pointSize=this.convertToTextSize(s.fontSize),f.depth=.001,f.writeTo(void 0,h)})}}convertToTextSize(e){return 1/.0502*144*e}setOverflow(e,t){t.horizontalOverflow?e.wrapMode="singleLine":e.wrapMode="flowing"}setTextAlignment(e,t){switch(t){case Tn.LowerLeft:case Tn.MiddleLeft:case Tn.UpperLeft:e.horizontalAlignment="left";break;case Tn.LowerCenter:case Tn.MiddleCenter:case Tn.UpperCenter:e.horizontalAlignment="center";break;case Tn.LowerRight:case Tn.MiddleRight:case Tn.UpperRight:e.horizontalAlignment="right";break}switch(t){case Tn.LowerLeft:case Tn.LowerCenter:case Tn.LowerRight:e.verticalAlignment="bottom";break;case Tn.MiddleLeft:case Tn.MiddleCenter:case Tn.MiddleRight:e.verticalAlignment="middle";break;case Tn.UpperLeft:case Tn.UpperCenter:case Tn.UpperRight:e.verticalAlignment="top";break}}}var iie=Object.defineProperty,nie=Object.getOwnPropertyDescriptor,vo=(n,e,t,i)=>{for(var s=i>1?void 0:i?nie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&iie(e,t,s),s};const ia=le("debugusdz");class vh{constructor(){u(this,"callToAction");u(this,"checkoutTitle");u(this,"checkoutSubtitle");u(this,"callToActionURL")}}vo([w()],vh.prototype,"callToAction",2);vo([w()],vh.prototype,"checkoutTitle",2);vo([w()],vh.prototype,"checkoutSubtitle",2);vo([w()],vh.prototype,"callToActionURL",2);class yo extends Ce{constructor(){super(...arguments);u(this,"objectToExport");u(this,"autoExportAnimations",!1);u(this,"exportFileName");u(this,"customUsdzFile");u(this,"customBranding");u(this,"anchoringType","plane");u(this,"planeAnchoringAlignment","horizontal");u(this,"interactive",!0);u(this,"extensions",[]);u(this,"link");u(this,"webxr");u(this,"webARSessionRoot");u(this,"lastCallback");u(this,"_quicklookButton");u(this,"_quicklookButtonContainer",null)}start(){var t,i,s,r;ia&&(console.log(this),console.log("Debug USDZ, press 't' to export"),window.addEventListener("keydown",o=>{switch(o.key){case"t":this.exportAsync();break}}),xu()&&setTimeout(()=>{this.exportAsync()},2e3)),(t=document.getElementById("open-in-ar"))==null||t.addEventListener("click",o=>{o.preventDefault(),this.exportAsync()}),this.objectToExport||(this.objectToExport=this.gameObject),!((s=(i=this.objectToExport)==null?void 0:i.children)!=null&&s.length)&&!((r=this.objectToExport)!=null&&r.isMesh)&&(this.objectToExport=this.context.scene),this.interactive&&(this.extensions.push(new qb),this.extensions.push(new jb),this.extensions.push(new $b))}onEnable(){const t=nm(),i=dl();(ia||t&&i)&&(this.addQuicklookButton(),this.webARSessionRoot=$.findObjectOfType(ch)??void 0,this.lastCallback=this.quicklookCallback.bind(this),this.link=Jte(this.context),this.link.addEventListener("message",this.lastCallback)),ia&&jn("USDZ Exporter enabled: "+this.name)}onDisable(){var s;(s=this.link)==null||s.removeEventListener("message",this.lastCallback);const t=nm(),i=dl();(ia||t&&i)&&this.removeQuicklookButton(),ia&&jn("USDZ Exporter disabled: "+this.name)}async exportAsync(){var p;let t=this.exportFileName??((p=this.objectToExport)==null?void 0:p.name)??this.name;if(Gc()||(t+="-MadeWithNeedle"),t+="-"+Kte(),this.customUsdzFile){const g=this.buildQuicklookOverlay();ia&&console.log(g);const m=g.callToAction?encodeURIComponent(g.callToAction):"",A=g.checkoutTitle?encodeURIComponent(g.checkoutTitle):"",v=g.checkoutSubtitle?encodeURIComponent(g.checkoutSubtitle):"";this.link.href=this.customUsdzFile+`#callToAction=${m}&checkoutTitle=${A}&checkoutSubtitle=${v}&callToActionURL=${g.callToActionURL}`,console.log(this.link.href),this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=t+".usdz",this.link.click();return}if(!this.objectToExport)return;if(this.webARSessionRoot){const g=this.webARSessionRoot.gameObject,m=1/this.webARSessionRoot.arScale;g.matrix.makeScale(m,m,m),this.webARSessionRoot.invertForward&&g.matrix.multiply(new He().makeRotationY(Math.PI))}const i=new gY,s=[...this.extensions],r=new Mb;s.push(r),this.autoExportAnimations&&Zte(this.objectToExport,r);const o={self:this,exporter:i,extensions:s,object:this.objectToExport};this.dispatchEvent(new CustomEvent("before-export",{detail:o})),i.debug=ia,this.anchoringType!=="plane"&&this.anchoringType!=="none"&&this.anchoringType!=="image"&&this.anchoringType!=="face"&&(this.anchoringType="plane"),this.planeAnchoringAlignment!=="horizontal"&&this.planeAnchoringAlignment!=="vertical"&&this.planeAnchoringAlignment!=="any"&&(this.planeAnchoringAlignment="horizontal");const a=await i.parse(this.objectToExport,{ar:{anchoring:{type:this.anchoringType},planeAnchoring:{alignment:this.planeAnchoringAlignment}},extensions:s,quickLookCompatible:!0}),l=new Blob([a],{type:"application/octet-stream"});this.dispatchEvent(new CustomEvent("after-export",{detail:o}));const c=this.buildQuicklookOverlay();ia&&console.log(c);const h=c.callToAction?encodeURIComponent(c.callToAction):"",d=c.checkoutTitle?encodeURIComponent(c.checkoutTitle):"",f=c.checkoutSubtitle?encodeURIComponent(c.checkoutSubtitle):"";this.link.href=URL.createObjectURL(l)+`#callToAction=${h}&checkoutTitle=${d}&checkoutSubtitle=${f}&callToActionURL=${c.callToActionURL}`,this.lastCallback||(this.lastCallback=this.quicklookCallback.bind(this),this.link.addEventListener("message",this.lastCallback)),this.link.download=t+".usdz",this.link.click()}quicklookCallback(t){if((t==null?void 0:t.data)=="_apple_ar_quicklook_button_tapped"){ia&&Wo("Quicklook closed via call to action button");var i=new CustomEvent("quicklook-button-tapped",{detail:this});if(this.dispatchEvent(i),!i.defaultPrevented){const s=new URLSearchParams(this.link.href);if(s){const r=s.get("callToActionURL");ia&&jn("Quicklook url: "+r),r&&(Gc()?globalThis.open(r,"_blank"):console.warn("Quicklook closed: custom redirects require a Needle Engine Pro license: https://needle.tools/pricing",r))}}}}buildQuicklookOverlay(){var i,s,r;const t={};return this.customBranding&&Object.assign(t,this.customBranding),Gc()||(console.log("Custom Quicklook banner text requires pro license: https://needle.tools/pricing"),t.callToAction="Close",t.checkoutTitle="🌵 Made with Needle",t.checkoutSubtitle="_"),(i=t.callToAction)!=null&&i.length||(t.callToAction="Close"),(s=t.checkoutTitle)!=null&&s.length||(t.checkoutTitle="🌵 Made with Needle"),(r=t.checkoutSubtitle)!=null&&r.length||(t.checkoutSubtitle="_"),this.dispatchEvent(new CustomEvent("quicklook-overlay",{detail:t})),t}async createQuicklookButton(){var t,i;if(!this.webxr)if(await jm(1),this.webxr=$.findObjectOfType(Ct)??void 0,this.webxr)if(this.webxr.VRButton&&((t=this.webxr.VRButton.parentElement)==null||t.removeChild(this.webxr.VRButton)),this.webxr.ARButton&&this._quicklookButton!==this.webxr.ARButton){this._quicklookButton=this.webxr.ARButton;const s=(i=this.webxr.ARButton.parentElement)==null?void 0:i.querySelector("a");s&&(s.href=""),this.webxr.ARButton.innerText="Open in Quicklook",this.webxr.ARButton.disabled=!1,this.webxr.ARButton.addEventListener("click",r=>{r.preventDefault(),this.exportAsync()}),this.webxr.ARButton.classList.add("quicklook-ar-button"),this._quicklookButtonContainer=this.webxr.ARButton.parentElement,this.dispatchEvent(new CustomEvent("created-button",{detail:this.webxr.ARButton}))}else{this.webxr.createARButton=!1,this.webxr.createVRButton=!1;let s=window.document.querySelector(".webxr-buttons");s||(s=document.createElement("div"),s.classList.add("webxr-buttons"));const r=document.createElement("button");r.innerText="Open in Quicklook",r.addEventListener("click",()=>{this.exportAsync()}),r.classList.add("webxr-ar-button"),r.classList.add("webxr-button"),r.classList.add("quicklook-ar-button"),s.appendChild(r),this._quicklookButtonContainer=s,this.dispatchEvent(new CustomEvent("created-button",{detail:r}))}else console.warn("Could not find WebXR component: will not create Quicklook button",_t.Current)}async addQuicklookButton(){await this.createQuicklookButton(),this._quicklookButton&&this._quicklookButtonContainer&&this._quicklookButtonContainer.appendChild(this._quicklookButton)}removeQuicklookButton(){var t;(t=this._quicklookButton)==null||t.remove()}}vo([w(Ie)],yo.prototype,"objectToExport",2);vo([w()],yo.prototype,"autoExportAnimations",2);vo([w()],yo.prototype,"exportFileName",2);vo([w(URL)],yo.prototype,"customUsdzFile",2);vo([w(vh)],yo.prototype,"customBranding",2);vo([w()],yo.prototype,"anchoringType",2);vo([w()],yo.prototype,"planeAnchoringAlignment",2);vo([w()],yo.prototype,"interactive",2);const HB=le("debugdeletable");class ex extends eo{}class dM extends Ce{constructor(){super(...arguments);u(this,"deleteBoxes",[])}awake(){this.deleteBoxes=$.findObjectsOfType(ex,this.context)}update(){for(const t of this.deleteBoxes){const i=this.gameObject;if(t.isInBox(i)===!0){const r=$.getComponentInParent(this.gameObject,op);r?HB&&console.warn("Can not delete object with usage marker",this.guid,r):(HB&&console.log("DESTROY",this.gameObject),fb(this.gameObject,this.context.connection))}}}}var sie=Object.defineProperty,rie=Object.getOwnPropertyDescriptor,zu=(n,e,t,i)=>{for(var s=i>1?void 0:i?rie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&sie(e,t,s),s};class Ko extends js{constructor(){super(...arguments);u(this,"mode");u(this,"focusDistance");u(this,"focalLength");u(this,"aperture");u(this,"gaussianMaxRadius");u(this,"resolutionScale");u(this,"bokehScale")}get typeName(){return"DepthOfField"}init(){this.focalLength.valueProcessor=i=>{const s=i/300,r=2;return Ze.lerp(r,.01,s)};const t=20;this.aperture.valueProcessor=i=>{const s=1-i/32;return Ze.lerp(1,t,s)}}onCreateEffect(){if(this.mode===0)return;const t=1/window.devicePixelRatio;if(this.resolutionScale===void 0){let s=1;xu()&&(s=.6),this.resolutionScale=new Ft(s*t)}const i=new iF(this.context.mainCamera,{worldFocusRange:.2,focalLength:1,bokehScale:20,resolutionScale:this.resolutionScale.value});return this.focusDistance.onValueChanged=s=>{i.circleOfConfusionMaterial.worldFocusDistance=s},this.focalLength.onValueChanged=s=>i.circleOfConfusionMaterial.worldFocusRange=s,this.aperture.onValueChanged=s=>i.bokehScale=s,this.resolutionScale&&(this.resolutionScale.onValueChanged=s=>i.resolution.scale=s),[i]}unapply(){}}zu([w()],Ko.prototype,"mode",2);zu([w(Ft)],Ko.prototype,"focusDistance",2);zu([w(Ft)],Ko.prototype,"focalLength",2);zu([w(Ft)],Ko.prototype,"aperture",2);zu([w(Ft)],Ko.prototype,"gaussianMaxRadius",2);zu([w(Ft)],Ko.prototype,"resolutionScale",2);zu([w(Ft)],Ko.prototype,"bokehScale",2);Na("DepthOfField",Ko);var oie=Object.defineProperty,aie=Object.getOwnPropertyDescriptor,lie=(n,e,t,i)=>{for(var s=i>1?void 0:i?aie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&oie(e,t,s),s};class tx extends Ce{constructor(){super(...arguments);u(this,"visibleOn")}onEnable(){this.apply()}apply(){this.test()||$.setActive(this.gameObject,!1)}test(){return this.visibleOn<0?!0:cie()?(this.visibleOn&2)!==0:(this.visibleOn&1)!==0}}lie([w()],tx.prototype,"visibleOn",2);let Cy;function cie(){if(Cy===!0||Cy===!1)return Cy;let n=!1;return function(e){(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(e)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(e.substr(0,4)))&&(n=!0)}(navigator.userAgent||navigator.vendor||window.opera),Cy=n,n}class fM{get extensionName(){return"DocumentExtension"}onAfterBuildDocument(e){}}var MN=(n=>(n.SelectStart="selectstart",n.SelectEnd="selectend",n))(MN||{});const al=class extends rp{constructor(){super();u(this,"transformSelf",!0);u(this,"orbit",null);u(this,"selectStartEventListener",[]);u(this,"selectEndEventListener",[]);u(this,"_dragHelper",null);u(this,"_draggingRigidbodies",[]);u(this,"_waitingForDragStart",null);u(this,"_isDragging",!1);u(this,"_marker",null);u(this,"_dragDelta");u(this,"_didDrag",!1);u(this,"_activePointerId");this.selectStartEventListener=[],this.selectEndEventListener=[],this._dragDelta=new q}static get HasAnySelected(){return this._active>0}addDragEventListener(t,i){switch(t){case"selectstart":this.selectStartEventListener.push(i);break;case"selectend":this.selectEndEventListener.push(i);break}}start(){this.orbit=$.findObjectOfType(ql,this.context)}allowEdit(t=null){return this.context.connection.allowEditing}onPointerEnter(t){if(!this.allowEdit(this.gameObject)||Ct.IsInWebXR)return;const i=$.getComponentInParent(t.object,al);!i||i!==this||(al.lastHovered=t.object,this.context.domElement.style.cursor="pointer")}onPointerExit(t){this.allowEdit(this.gameObject)&&(Ct.IsInWebXR||al.lastHovered===t.object&&(this.context.domElement.style.cursor="auto"))}onPointerDown(t){this.allowEdit(this.gameObject)&&(Ct.IsInWebXR||(al._active+=1,this._dragDelta.set(0,0),this._didDrag=!1,this._waitingForDragStart=t,t.StopPropagation(),this.orbit&&(this.orbit.enabled=!1)))}onPointerUp(t){this._waitingForDragStart=null,this.allowEdit(this.gameObject)&&(al._active>0&&(al._active-=1),!Ct.IsInWebXR&&(this.onDragEnd(t),t.StopPropagation(),this.orbit&&(this.orbit.enabled=!0)))}update(){var t;if(!Ct.IsInWebXR){if(this._waitingForDragStart){if(!this._didDrag){const s=this.context.input.getPointerPositionDelta(0);if(s&&this._dragDelta.add(s),this._dragDelta.length()>2)this._didDrag=!0;else return}const i=this._waitingForDragStart;this._waitingForDragStart=null,this.onDragStart(i)}this._dragHelper&&this._dragHelper.hasSelected&&this.onUpdateDrag(),(((t=this._dragHelper)==null?void 0:t.hasSelected)===!1||this._activePointerId!==void 0&&this.context.input.getPointerPressed(this._activePointerId)===!1)&&this.onDragEnd(null)}}onDragStart(t){if(!this._dragHelper)if(this.context.mainCamera)this._dragHelper=new A0(this.context.mainCamera);else return;if(!t||!t.object)return;const i=$.getComponentInParent(t.object,al);if(!i||i!==this)return;let s=t.object;this.transformSelf&&(s=this.gameObject);const r={selected:s,attached:s};for(const c of this.selectStartEventListener)c(this,r);if(this._activePointerId=t.pointerId,!r.attached)return;r.attached,s=r.attached,this._isDragging=!0,this._dragHelper.setSelected(s,this.context),this.orbit&&(this.orbit.enabled=!1);const o=$.getComponentInChildren(s,Jc);o&&(o.fastMode=!0,o==null||o.requestOwnership()),this._marker=$.addNewComponent(s,op),this._draggingRigidbodies.length=0;const a=$.getComponentsInChildren(s,Hi);a&&this._draggingRigidbodies.push(...a);const l=I0();$.invokeOnChildren(this._dragHelper.selected,l("onDragStart"))}onUpdateDrag(){if(this._dragHelper){this._dragHelper.onUpdate(this.context);for(const t of this._draggingRigidbodies)t.wakeUp(),t.resetVelocities()}}onDragEnd(t){if(!this||!this._isDragging||(this._isDragging=!1,!this._dragHelper))return;for(const r of this._draggingRigidbodies)r.setVelocity(r.smoothedVelocity);this._draggingRigidbodies.length=0;const i=this._dragHelper.selected;if(this._dragHelper.setSelected(null,this.context),this.orbit&&(this.orbit.enabled=!0),t!=null&&t.object){const r=$.getComponentInChildren(t.object,Jc);r&&(r.fastMode=!1)}this._marker&&this._marker.destroy();for(const r of this.selectEndEventListener)r(this);const s=I0();$.invokeOnChildren(i,s("onDragEnd"))}};let Lc=al;u(Lc,"_active",0),u(Lc,"lastHovered");const $M=class{constructor(e){u(this,"_selected",null);u(this,"_context",null);u(this,"_camera");u(this,"_cameraPlane",new Zr);u(this,"_hasGroundPlane",!1);u(this,"_groundPlane",new Zr);u(this,"_groundOffset",new S);u(this,"_groundOffsetFactor",0);u(this,"_groundDistance",0);u(this,"_groundPlanePoint",new S);u(this,"_raycaster",new zf);u(this,"_cameraPlaneOffset",new S);u(this,"_intersection",new S);u(this,"_worldPosition",new S);u(this,"_inverseMatrix",new He);u(this,"_rbs",[]);u(this,"_groundLine");u(this,"_groundMarker");u(this,"_groundOffsetVector",new S(0,1,0));u(this,"_requireUpdateGroundPlane",!0);u(this,"_didDragOnGroundPlaneLastFrame",!1);this._camera=e;const t=new rn($M.geometry),i=t.material;i.color=new _e(.4,.4,.4),t.layers.set(2),t.name="line",t.scale.y=1,this._groundLine=t;const s=new po(.5,22,22),r=new vi({color:i.color}),o=new ve(s,r);o.visible=!1,o.layers.set(2),this._groundMarker=o}get hasSelected(){return this._selected!==null&&this._selected!==void 0}get selected(){return this._selected}setSelected(e,t){if(this._selected&&t)for(const i of this._rbs)i.wakeUp(),i.setVelocity(0,0,0);if(this._selected&&Ns.Remove(t,this._selected),this._selected=e,this._context=t,this._rbs.length=0,e?(t.scene.add(this._groundLine),t.scene.add(this._groundMarker)):(this._groundLine.removeFromParent(),this._groundMarker.removeFromParent()),this._selected){if(!t){console.error("DragHelper: no context");return}Ns.Add(t,this._selected,null),this._groundOffsetFactor=0,this._hasGroundPlane=!0,this._groundOffset.set(0,0,0),this._requireUpdateGroundPlane=!0,this.onUpdateScreenSpacePlane()}}onUpdate(e){var a,l,c,h,d;if(!this._context)return;const t="Space",i="KeyD",s=((a=this._context)==null?void 0:a.input.isKeyPressed(t))||((l=this._context)==null?void 0:l.input.isKeyPressed(i)),r=this._context.input.getTouchesPressedCount()>=2||s;if(r){const f=this._context.input.getPointerPositionDelta(0);f&&(this._groundOffsetVector.set(0,1,0),(c=this._selected)==null||c.rotateOnWorldAxis(this._groundOffsetVector,f.x*this._context.time.deltaTime))}const o=this._context.input.getPointerPositionRC(0);if(o&&(this._raycaster.setFromCamera(o,this._camera),this._selected)){this._groundOffsetVector.set(0,1,0);const f=wt(this._camera).clone().sub(wt(this._selected)).normalize(),p=Math.abs(f.dot(this._groundOffsetVector)),g=((h=this._context)==null?void 0:h.input.isKeyPressed(t))||((d=this._context)==null?void 0:d.input.isKeyPressed(i)),m=!r&&p>.2&&!g&&this._context.input.getPointerPressedCount()<=1,A=this._didDragOnGroundPlaneLastFrame!==m;if(this._didDragOnGroundPlaneLastFrame=m,this._hasGroundPlane||(this._requireUpdateGroundPlane=!0),(this._requireUpdateGroundPlane||!m||A)&&this.onUpdateGroundPlane(),this._requireUpdateGroundPlane=!1,this._hasGroundPlane)if(this._raycaster.ray.intersectPlane(this._groundPlane,this._intersection)){const v=this._intersection.y;if(this._groundPlanePoint.copy(this._intersection).sub(this._groundOffset),this._groundPlanePoint.y=v,m){this._groundOffsetVector.set(0,1,0);const b=this._intersection.sub(this._groundOffset).add(this._groundOffsetVector.multiplyScalar(this._groundOffsetFactor));this.onUpdateWorldPosition(b,this._groundPlanePoint,!1),this.onDidUpdate();return}}else this._groundPlanePoint.set(0,99999,0);A&&this.onUpdateScreenSpacePlane(),this._requireUpdateGroundPlane=!0,this._raycaster.ray.intersectPlane(this._cameraPlane,this._intersection)&&(this.onUpdateWorldPosition(this._intersection.sub(this._cameraPlaneOffset),this._groundPlanePoint,!0),this.onDidUpdate())}}onUpdateWorldPosition(e,t,i){if(this._selected){if(i){const s=wt(this._selected);s.y=e.y,e=s}if(ln(this._selected,e),ln(this._groundLine,e),this._hasGroundPlane?this._groundLine.scale.y=this._groundDistance:this._groundLine.scale.y=1e3,this._groundMarker.visible=t!==null,t){const s=wt(this._camera).distanceTo(t)*.01;this._groundMarker.scale.set(s,s,s),ln(this._groundMarker,t)}}}onUpdateScreenSpacePlane(){if(!this._selected||!this._context)return;const e=this._context.input.getPointerPositionRC(0);e&&(this._raycaster.setFromCamera(e,this._camera),this._cameraPlane.setFromNormalAndCoplanarPoint(this._camera.getWorldDirection(this._cameraPlane.normal),this._worldPosition.setFromMatrixPosition(this._selected.matrixWorld)),this._raycaster.ray.intersectPlane(this._cameraPlane,this._intersection)&&this._selected.parent&&(this._inverseMatrix.copy(this._selected.parent.matrixWorld).invert(),this._cameraPlaneOffset.copy(this._intersection).sub(this._worldPosition.setFromMatrixPosition(this._selected.matrixWorld))))}onUpdateGroundPlane(){if(!this._selected||!this._context)return;const e=wt(this._selected),t=new Gl(new S(0,.1,0).add(e),new S(0,-1,0)),i=new qo;i.ignore=[this._selected];const s=this._context.physics.raycastFromRay(t,i);for(let r=0;r<s.length;r++){const o=s[r];if(!o.face||this.contains(this._selected,o.object))continue;const a=new S(0,1,0);this._groundPlane.setFromNormalAndCoplanarPoint(a,o.point);break}this._hasGroundPlane=!0,this._groundPlane.setFromNormalAndCoplanarPoint(t.direction.multiplyScalar(-1),t.origin),this._raycaster.ray.intersectPlane(this._groundPlane,this._intersection),this._groundDistance=this._intersection.distanceTo(e),this._groundOffset.copy(this._intersection).sub(e)}onDidUpdate(){rr.markDirty(this._selected);for(const e of this._rbs)e.wakeUp(),e.resetForcesAndTorques(),e.setAngularVelocity(0,0,0)}contains(e,t){if(e===t)return!0;if(e.children){for(const i of e.children)if(this.contains(i,t))return!0}return!1}};let A0=$M;u(A0,"geometry",new vt().setFromPoints([new S(0,0,0),new S(0,-1,0)]));function pM(n,e,t){console.warn("Adding components on object has been temporarily disabled")}var TN=(n=>(n.File_Spawned="file-spawned",n))(TN||{});class PN{constructor(e,t,i,s,r,o,a,l){u(this,"guid");u(this,"file_name");u(this,"file_hash");u(this,"file_size");u(this,"position");u(this,"seed");u(this,"sender");u(this,"serverUrl");u(this,"parentGuid");u(this,"boundsSize");this.seed=t,this.guid=i,this.file_name=s,this.file_hash=r,this.file_size=o,this.position=a,this.sender=e,this.serverUrl=l}}async function aE(n,e,t){const i=n.name;return i.endsWith(".gltf")||i.endsWith(".glb")?new Promise((s,r)=>{const o=new FileReader;o.readAsArrayBuffer(n),o.onloadend=async a=>{const l=o.result,c=pb(),h=new Us(c),d=await Qo().parseSync(e,l,n.name,h);if(d&&d.scene){const f=d.scene;if(!f.guid){const p=new Us(c);f.guid=p.generateUUID()}t&&hie(e.connection,n,c,f,t),pM(),s(d)}}}):(console.warn("Unsupported file type: "+i),console.log(n),null)}async function RN(n,e){return new Promise(async(t,i)=>{const s=pb(),r=new Us(s),o=n.toString(),a=await Qo().loadSync(e,o,o,r);a&&a.scene?(a.scene,pM(),t(a)):console.warn("Unsupported file type: "+n.toString())})}sn.registerCallback(to.ContextCreated,n=>{BN(n.context)});function BN(n){n.connection.beginListen("file-spawned",async e=>{if(e.sender!==n.connection.connectionId){console.log("received file event",e),uie(e,n);let t=null;try{t=await Q1(e.file_name,e.file_hash,e.file_size,e.serverUrl)}finally{die(e)}if(t){const i=new Us(e.seed),s=await Qo().parseSync(n,t,null,i);if(s&&s.scene){const r=s.scene;if(pM(),e.parentGuid){const o=mA(e.parentGuid,n.scene);"add"in o&&o.add(r)}r.parent||n.scene.add(r),e.position!==null&&r.position.copy(e.position)}}else console.error("download didnt return file")}})}async function hie(n,e,t,i,s){if(!n.connectionId){console.error("Can not upload file - no connection id");return}if(!i.guid){console.error("Can not upload file - no guid",i,i.guid);return}const r=await fF(e,s);if(!r)return;if(!r.filename){console.error("Can not send upload event - no filename",e.name);return}if(!r.hash){console.error("Can not send upload event - no hash",e.name);return}const o=new PN(n.connectionId,t,i.guid,r.filename,r.hash,e.size,i.position,r.url??s);i.parent&&(o.parentGuid=i.parent.guid),n.send("file-spawned",o)}const lE={};function uie(n,e){const t=new gi,i=new ve(t,new vi({color:65280})),s=new eb(i,5592405);if(lE[n.guid]=s,e.scene.add(s),n.parentGuid){const r=mA(n.parentGuid,e.scene);r&&r.add(s)}n.position&&s.position.copy(n.position)}function die(n,e){const t=n.guid,i=lE[t];i&&(delete lE[t],i.removeFromParent())}var fie=Object.defineProperty,pie=Object.getOwnPropertyDescriptor,gM=(n,e,t,i)=>{for(var s=i>1?void 0:i?pie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&fie(e,t,s),s};const gie=le("debugnet"),cE=class extends Ce{constructor(){super(...arguments);u(this,"url",null);u(this,"urlParameterName",null);u(this,"localhost",null)}awake(){gie&&console.log(this),this.context.connection.registerProvider(this)}getWebsocketUrl(){let e=this.url?cE.GetUrl(this.url,this.localhost):null;if(this.urlParameterName){const r=le(this.urlParameterName);r&&typeof r=="string"&&(e=r)}if(!e)return null;const i=new RegExp("(((https?)|(?<socket_prefix>wss?))://)?(www.)?(?<url>.+)","gm").exec(e);return i!=null&&i.groups?(i==null?void 0:i.groups.socket_prefix)?e:"wss://"+(i==null?void 0:i.groups.url):null}static GetUrl(e,t){let i=e;const s=cE.IsLocalNetwork()&&t;return s&&(i=t),e!=null&&e.startsWith("/")&&(i=(s?i:window.location.origin)+e),i}static IsLocalNetwork(e=window.location.hostname){return zs(e)}};let Gu=cE;gM([w()],Gu.prototype,"url",2);gM([w()],Gu.prototype,"urlParameterName",2);gM([w()],Gu.prototype,"localhost",2);var mie=Object.defineProperty,Aie=Object.getOwnPropertyDescriptor,DN=(n,e,t,i)=>{for(var s=i>1?void 0:i?Aie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&mie(e,t,s),s};class qA extends Ce{constructor(){super(...arguments);u(this,"filesBackendUrl");u(this,"localhost");u(this,"_dragOver");u(this,"_drop")}onEnable(){this.filesBackendUrl=this.filesBackendUrl?Gu.GetUrl(this.filesBackendUrl,this.localhost):void 0,this._dragOver=this.onDrag.bind(this),this._drop=this.onDrop.bind(this),this.context.domElement.addEventListener("dragover",this._dragOver),this.context.domElement.addEventListener("drop",this._drop)}onDisable(){this.context.domElement.removeEventListener("dragover",this._dragOver),this.context.domElement.removeEventListener("drop",this._drop)}onDrag(t){t.preventDefault()}async addFiles(t){for(const i of t){if(!i)continue;console.log("Register file "+i.name+" to",this.filesBackendUrl,i);const s=await aE(i,this.context,this.filesBackendUrl);this.dispatchEvent(new CustomEvent("file-dropped",{detail:i})),s&&this.addObject(void 0,s)}}async onDrop(t){if(console.log(t),!t.dataTransfer)return;t.preventDefault();const i=t.dataTransfer.items;if(i)for(const s in i){const r=i[s];if(r.kind==="file"){const o=r.getAsFile();if(!o)continue;console.log("Register file "+o.name+" to",this.filesBackendUrl,o);const a=await aE(o,this.context,this.filesBackendUrl);this.dispatchEvent(new CustomEvent("file-dropped",{detail:o})),a&&this.addObject(t,a)}else r.kind==="string"&&r.type=="text/plain"&&r.getAsString(async o=>{console.log("dropped url",o);try{const a=new URL(o);if(!a)return;const l=await RN(a,this.context);l&&this.addObject(t,l)}catch{console.log("dropped string is not a valid URL!",o)}})}}async addObject(t,i){console.log("Dropped",i);const s=i.scene;if(t!==void 0){const r=new qo;r.setMask(16777215),r.screenPointFromOffset(t.offsetX,t.offsetY);const o=this.context.physics.raycast(r);if(o&&o.length>0)for(const a of o){s.position.copy(a.point);break}}this.gameObject.add(s),this.dispatchEvent(new CustomEvent("object-added",{detail:i}))}}DN([w()],qA.prototype,"filesBackendUrl",2);DN([w()],qA.prototype,"localhost",2);var vie=Object.defineProperty,yie=Object.getOwnPropertyDescriptor,ix=(n,e,t,i)=>{for(var s=i>1?void 0:i?yie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&vie(e,t,s),s};class Qu extends rp{constructor(){super(...arguments);u(this,"parent",null);u(this,"object",null);u(this,"limitCount",10);u(this,"limitInterval",60);u(this,"_currentCount",0);u(this,"_startPosition",null);u(this,"_startQuaternion",null)}awake(){var i,s;if(this.object){if(this.object===this.gameObject){console.error("Can not duplicate self");return}this.object.visible=!1,this._startPosition=((i=this.object.position)==null?void 0:i.clone())??new S(0,0,0),this._startQuaternion=((s=this.object.quaternion)==null?void 0:s.clone())??new xe(0,0,0,1)}const t=$.getComponentInParent(this.gameObject,Lc);t?t.addDragEventListener(MN.SelectStart,(r,o)=>{if(this._currentCount>=this.limitCount){o.attached=null;return}const a=this.handleDuplication(o.selected);a&&(console.assert(a!==o.selected,"Duplicated object is original"),o.attached=a)}):console.warn("Could no find drag controls in parent",this.name),Yi.addEventListener(hl.SelectStart,(r,o)=>{if(this._currentCount>=this.limitCount){o.grab=null;return}const a=this.handleDuplication(o.selected);a&&(o.grab=a)}),this.cloneLimitIntervalFn()}cloneLimitIntervalFn(){this.destroyed||(this._currentCount>0&&(this._currentCount-=1),setTimeout(()=>{this.cloneLimitIntervalFn()},this.limitInterval/this.limitCount*1e3))}handleDuplication(t){var i;if(this._currentCount>=this.limitCount||!this.object)return null;if(t===this.gameObject||this.handleMultiObject(t)){if(this.object===this.gameObject)return null;this.object.visible=!0,this._startPosition&&this.object.position.copy(this._startPosition),this._startQuaternion&&this.object.quaternion.copy(this._startQuaternion);const s=new Pa;this.parent||(this.parent=this.gameObject.parent),this.parent&&(s.parent=this.parent.guid??((i=this.parent.userData)==null?void 0:i.guid),s.keepWorldPosition=!0),s.position=this.worldPosition,s.rotation=this.worldQuaternion,s.context=this.context,this._currentCount+=1;const r=$.instantiateSynced(this.object,s);return console.assert(r!==this.object,"Duplicated object is original"),this.object.visible=!1,this._startPosition&&this.object.position.clone().copy(this._startPosition),this._startQuaternion&&this.object.quaternion.clone().copy(this._startQuaternion),r}return null}handleMultiObject(t){return this.gameObject.type==="Group"||this.gameObject.type==="Object3D"?this.isInChildren(this.gameObject,t):!1}isInChildren(t,i){if(!t)return!1;if(t===i)return!0;if(t.children){for(let s of t.children)if(this.isInChildren(s,i))return!0}return!1}}ix([w(Ie)],Qu.prototype,"parent",2);ix([w(Ie)],Qu.prototype,"object",2);ix([w()],Qu.prototype,"limitCount",2);ix([w()],Qu.prototype,"limitInterval",2);var kd=(n=>(n[n.PointerEnter=0]="PointerEnter",n[n.PointerExit=1]="PointerExit",n[n.PointerDown=2]="PointerDown",n[n.PointerUp=3]="PointerUp",n[n.PointerClick=4]="PointerClick",n[n.Drag=5]="Drag",n[n.Drop=6]="Drop",n[n.Scroll=7]="Scroll",n[n.UpdateSelected=8]="UpdateSelected",n[n.Select=9]="Select",n[n.Deselect=10]="Deselect",n[n.Move=11]="Move",n[n.InitializePotentialDrag=12]="InitializePotentialDrag",n[n.BeginDrag=13]="BeginDrag",n[n.EndDrag=14]="EndDrag",n[n.Submit=15]="Submit",n[n.Cancel=16]="Cancel",n))(kd||{}),_ie=Object.defineProperty,bie=Object.getOwnPropertyDescriptor,mM=(n,e,t,i)=>{for(var s=i>1?void 0:i?bie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&_ie(e,t,s),s};class AM{constructor(){u(this,"eventID");u(this,"callback")}}mM([w()],AM.prototype,"eventID",2);mM([w(ar)],AM.prototype,"callback",2);class nx extends Ce{constructor(){super(...arguments);u(this,"triggers")}invoke(t){if(this.triggers)for(const i of this.triggers)i.eventID===t&&i.callback.invoke()}onPointerClick(t){this.invoke(kd.PointerClick)}onPointerEnter(t){this.invoke(kd.PointerEnter)}onPointerExit(t){this.invoke(kd.PointerExit)}onPointerDown(t){this.invoke(kd.PointerDown)}onPointerUp(t){this.invoke(kd.PointerUp)}}mM([w(AM)],nx.prototype,"triggers",2);var xie=Object.defineProperty,wie=Object.getOwnPropertyDescriptor,vM=(n,e,t,i)=>{for(var s=i>1?void 0:i?wie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&xie(e,t,s),s};class yM extends Ce{constructor(){super(...arguments);u(this,"connectedBody");u(this,"_rigidBody",null)}get rigidBody(){return this._rigidBody}onEnable(){this._rigidBody||(this._rigidBody=this.gameObject.getComponent(Hi)),this.rigidBody&&this.connectedBody&&this.startCoroutine(this.create())}*create(){yield,this.rigidBody&&this.connectedBody&&this.createJoint(this.rigidBody,this.connectedBody)}}vM([w(Hi)],yM.prototype,"connectedBody",2);class _M extends yM{createJoint(e,t){var i;(i=this.context.physics.engine)==null||i.addFixedJoint(e,t)}}class XA extends yM{constructor(){super(...arguments);u(this,"anchor");u(this,"axis")}createJoint(t,i){var s;this.axis&&this.anchor&&((s=this.context.physics.engine)==null||s.addHingeJoint(t,i,this.anchor,this.axis))}}vM([w(S)],XA.prototype,"anchor",2);vM([w(S)],XA.prototype,"axis",2);const Cie={type:"change"};let Sie=class extends Ln{constructor(e,t){super(),this.object=e,this.domElement=t,this.movementSpeed=1,this.rollSpeed=.005,this.dragToLook=!1,this.autoForward=!1;const i=this,s=1e-6,r=new xe,o=new S;this.tmpQuaternion=new xe,this.status=0,this.moveState={up:0,down:0,left:0,right:0,forward:0,back:0,pitchUp:0,pitchDown:0,yawLeft:0,yawRight:0,rollLeft:0,rollRight:0},this.moveVector=new S(0,0,0),this.rotationVector=new S(0,0,0),this.keydown=function(f){if(!f.altKey){switch(f.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=.1;break;case"KeyW":this.moveState.forward=1;break;case"KeyS":this.moveState.back=1;break;case"KeyA":this.moveState.left=1;break;case"KeyD":this.moveState.right=1;break;case"KeyR":this.moveState.up=1;break;case"KeyF":this.moveState.down=1;break;case"ArrowUp":this.moveState.pitchUp=1;break;case"ArrowDown":this.moveState.pitchDown=1;break;case"ArrowLeft":this.moveState.yawLeft=1;break;case"ArrowRight":this.moveState.yawRight=1;break;case"KeyQ":this.moveState.rollLeft=1;break;case"KeyE":this.moveState.rollRight=1;break}this.updateMovementVector(),this.updateRotationVector()}},this.keyup=function(f){switch(f.code){case"ShiftLeft":case"ShiftRight":this.movementSpeedMultiplier=1;break;case"KeyW":this.moveState.forward=0;break;case"KeyS":this.moveState.back=0;break;case"KeyA":this.moveState.left=0;break;case"KeyD":this.moveState.right=0;break;case"KeyR":this.moveState.up=0;break;case"KeyF":this.moveState.down=0;break;case"ArrowUp":this.moveState.pitchUp=0;break;case"ArrowDown":this.moveState.pitchDown=0;break;case"ArrowLeft":this.moveState.yawLeft=0;break;case"ArrowRight":this.moveState.yawRight=0;break;case"KeyQ":this.moveState.rollLeft=0;break;case"KeyE":this.moveState.rollRight=0;break}this.updateMovementVector(),this.updateRotationVector()},this.pointerdown=function(f){if(this.dragToLook)this.status++;else{switch(f.button){case 0:this.moveState.forward=1;break;case 2:this.moveState.back=1;break}this.updateMovementVector()}},this.pointermove=function(f){if(!this.dragToLook||this.status>0){const p=this.getContainerDimensions(),g=p.size[0]/2,m=p.size[1]/2;this.moveState.yawLeft=-(f.pageX-p.offset[0]-g)/g,this.moveState.pitchDown=(f.pageY-p.offset[1]-m)/m,this.updateRotationVector()}},this.pointerup=function(f){if(this.dragToLook)this.status--,this.moveState.yawLeft=this.moveState.pitchDown=0;else{switch(f.button){case 0:this.moveState.forward=0;break;case 2:this.moveState.back=0;break}this.updateMovementVector()}this.updateRotationVector()},this.update=function(f){const p=f*i.movementSpeed,g=f*i.rollSpeed;i.object.translateX(i.moveVector.x*p),i.object.translateY(i.moveVector.y*p),i.object.translateZ(i.moveVector.z*p),i.tmpQuaternion.set(i.rotationVector.x*g,i.rotationVector.y*g,i.rotationVector.z*g,1).normalize(),i.object.quaternion.multiply(i.tmpQuaternion),(o.distanceToSquared(i.object.position)>s||8*(1-r.dot(i.object.quaternion))>s)&&(i.dispatchEvent(Cie),r.copy(i.object.quaternion),o.copy(i.object.position))},this.updateMovementVector=function(){const f=this.moveState.forward||this.autoForward&&!this.moveState.back?1:0;this.moveVector.x=-this.moveState.left+this.moveState.right,this.moveVector.y=-this.moveState.down+this.moveState.up,this.moveVector.z=-f+this.moveState.back},this.updateRotationVector=function(){this.rotationVector.x=-this.moveState.pitchDown+this.moveState.pitchUp,this.rotationVector.y=-this.moveState.yawRight+this.moveState.yawLeft,this.rotationVector.z=-this.moveState.rollRight+this.moveState.rollLeft},this.getContainerDimensions=function(){return this.domElement!=document?{size:[this.domElement.offsetWidth,this.domElement.offsetHeight],offset:[this.domElement.offsetLeft,this.domElement.offsetTop]}:{size:[window.innerWidth,window.innerHeight],offset:[0,0]}},this.dispose=function(){this.domElement.removeEventListener("contextmenu",VB),this.domElement.removeEventListener("pointerdown",l),this.domElement.removeEventListener("pointermove",a),this.domElement.removeEventListener("pointerup",c),window.removeEventListener("keydown",h),window.removeEventListener("keyup",d)};const a=this.pointermove.bind(this),l=this.pointerdown.bind(this),c=this.pointerup.bind(this),h=this.keydown.bind(this),d=this.keyup.bind(this);this.domElement.addEventListener("contextmenu",VB),this.domElement.addEventListener("pointerdown",l),this.domElement.addEventListener("pointermove",a),this.domElement.addEventListener("pointerup",c),window.addEventListener("keydown",h),window.addEventListener("keyup",d),this.updateMovementVector(),this.updateRotationVector()}};function VB(n){n.preventDefault()}class bM extends Ce{constructor(){super(...arguments);u(this,"_controls",null)}onEnable(){var i;const t=(i=$.getComponent(this.gameObject,Oi))==null?void 0:i.cam;this._controls=new Sie(t,this.context.renderer.domElement),this._controls.rollSpeed=.5,this._controls.movementSpeed=3,this._controls.dragToLook=!0}onDisable(){var t;(t=this._controls)==null||t.dispose(),this._controls=null}update(){this._controls&&this._controls.update(this.context.time.deltaTime)}}var Eie=Object.defineProperty,Iie=Object.getOwnPropertyDescriptor,xM=(n,e,t,i)=>{for(var s=i>1?void 0:i?Iie(e,t):e,r=n.length-1,o;r>=0;r--)(o=n[r])&&(s=(i?o(e,t,s):o(s))||s);return i&&s&&Eie(e,t,s),s};class wp extends Ce{constructor(){super(...arguments);u(this,"_fog")}get fog(){return this._fog||(this._fog=new XE(0,0,50)),this._fog}get mode(){return 1}set near(t){this.fog.near=t}get near(){return this.fog.near}set far(t){this.fog.far=t}get far(){return this.fog.far}set color(t){this.fog.color.copy(t)}get color(){return this.fog.color}onEnable(){this.scene.fog=this.fog}onDisable(){this.scene.fog===this._fog&&(this.scene.fog=null)}}xM([w()],wp.prototype,"near",1);xM([w()],wp.prototype,"far",1);xM([w(_e)],wp.prototype,"color",1);let iC,nC,_d,Sy;function sC(n,e,t){nC||(nC=new Jn(2,2,1,1)),_d||(_d=new Xt({uniforms:{blitTexture:new be(n)},vertexShader:`
|
|
4562
4562
|
varying vec2 vUv;
|
|
4563
4563
|
void main(){
|
|
4564
4564
|
vUv = uv;
|