forked from capnmidnight/Primrose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Primrose.min.js
7 lines (7 loc) · 217 KB
/
Primrose.min.js
1
2
3
4
5
6
7
console.info("[Primrose]:> primrose v0.31.4. see https://www.primrosevr.com for more information."),function(e){"use strict";function t(e,t,n,r){var o=t&&t.prototype instanceof i?t:i,s=Object.create(o.prototype),a=new d(r||[]);return s._invoke=u(e,n,a),s}function n(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}function i(){}function r(){}function o(){}function s(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function a(e){function t(i,r,o,s){var a=n(e[i],e,r);if("throw"!==a.type){var u=a.arg,h=u.value;return h&&"object"==typeof h&&g.call(h,"__await")?Promise.resolve(h.__await).then(function(e){t("next",e,o,s)},function(e){t("throw",e,o,s)}):Promise.resolve(h).then(function(e){u.value=e,o(u)},s)}s(a.arg)}function i(e,n){function i(){return new Promise(function(i,r){t(e,n,i,r)})}return r=r?r.then(i,i):i()}"object"==typeof process&&process.domain&&(t=process.domain.bind(t));var r;this._invoke=i}function u(e,t,i){var r=x;return function(o,s){if(r===E)throw new Error("Generator is already running");if(r===M){if("throw"===o)throw s;return p()}for(i.method=o,i.arg=s;;){var a=i.delegate;if(a){var u=h(a,i);if(u){if(u===T)continue;return u}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if(r===x)throw r=M,i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);r=E;var c=n(e,t,i);if("normal"===c.type){if(r=i.done?M:S,c.arg===T)continue;return{value:c.arg,done:i.done}}"throw"===c.type&&(r=M,i.method="throw",i.arg=c.arg)}}}function h(e,t){var i=e.iterator[t.method];if(i===m){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=m,h(e,t),"throw"===t.method))return T;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return T}var r=n(i,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,T;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=m),t.delegate=null,T):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,T)}function c(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function l(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function d(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(c,this),this.reset(!0)}function f(e){if(e){var t=e[_];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(g.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=m,t.done=!0,t};return i.next=i}}return{next:p}}function p(){return{value:m,done:!0}}var m,v=Object.prototype,g=v.hasOwnProperty,y="function"==typeof Symbol?Symbol:{},_=y.iterator||"@@iterator",w=y.toStringTag||"@@toStringTag",b="object"==typeof module,k=e.regeneratorRuntime;if(k)return void(b&&(module.exports=k));k=e.regeneratorRuntime=b?module.exports:{},k.wrap=t;var x="suspendedStart",S="suspendedYield",E="executing",M="completed",T={},O={};O[_]=function(){return this};var P=Object.getPrototypeOf,C=P&&P(P(f([])));C&&C!==v&&g.call(C,_)&&(O=C);var A=o.prototype=i.prototype=Object.create(O);r.prototype=A.constructor=o,o.constructor=r,o[w]=r.displayName="GeneratorFunction",k.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===r||"GeneratorFunction"===(t.displayName||t.name))},k.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,o):(e.__proto__=o,w in e||(e[w]="GeneratorFunction")),e.prototype=Object.create(A),e},k.awrap=function(e){return{__await:e}},s(a.prototype),k.AsyncIterator=a,k.async=function(e,n,i,r){var o=new a(t(e,n,i,r));return k.isGeneratorFunction(n)?o:o.next().then(function(e){return e.done?e.value:o.next()})},s(A),A[w]="Generator",A.toString=function(){return"[object Generator]"},k.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var i=t.pop();if(i in e)return n.value=i,n.done=!1,n}return n.done=!0,n}},k.values=f,d.prototype={constructor:d,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=m,this.done=!1,this.delegate=null,this.method="next",this.arg=m,this.tryEntries.forEach(l),!e)for(var t in this)"t"===t.charAt(0)&&g.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=m)},stop:function(){this.done=!0;var e=this.tryEntries[0],t=e.completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){function t(t,i){return o.type="throw",o.arg=e,n.next=t,i&&(n.method="next",n.arg=m),!!i}if(this.done)throw e;for(var n=this,i=this.tryEntries.length-1;i>=0;--i){var r=this.tryEntries[i],o=r.completion;if("root"===r.tryLoc)return t("end");if(r.tryLoc<=this.prev){var s=g.call(r,"catchLoc"),a=g.call(r,"finallyLoc");if(s&&a){if(this.prev<r.catchLoc)return t(r.catchLoc,!0);if(this.prev<r.finallyLoc)return t(r.finallyLoc)}else if(s){if(this.prev<r.catchLoc)return t(r.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<r.finallyLoc)return t(r.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&g.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var r=i;break}}r&&("break"===e||"continue"===e)&&r.tryLoc<=t&&t<=r.finallyLoc&&(r=null);var o=r?r.completion:{};return o.type=e,o.arg=t,r?(this.method="next",this.next=r.finallyLoc,T):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),T},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),l(n),T}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var i=n.completion;if("throw"===i.type){var r=i.arg;l(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:f(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=m),T}}}("object"==typeof global?global:"object"==typeof window?window:"object"==typeof self?self:this),function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("three")):"function"==typeof define&&define.amd?define(["three"],t):e.Primrose=t(e.THREE)}(this,function(e){"use strict";function t(){return 90===Math.abs(window.orientation)}function n(){return new e.Object3D}function i(e,t,n){return gt[e]?n&&n(gt[e]):gt[e]=t(),gt[e]}function r(t,n){return void 0===n&&"string"!=typeof t&&(n=t,t="none"),n=Object.assign({},{opacity:1,roughness:.5,metalness:0,color:16777215,useFog:!0,unshaded:!1,wireframe:!1,side:e.FrontSide},n),i("Primrose.material("+t+", "+n.color+", "+n.unshaded+", "+n.side+", "+n.opacity+", "+n.roughness+", "+n.metalness+", "+n.color+", "+n.emissive+", "+n.wireframe+", "+n.useFog+")",function(){var t={fog:n.useFog,transparent:n.transparent||void 0!==n.opacity&&n.opacity<1,opacity:n.opacity,side:n.side||e.FrontSide},i=e.MeshStandardMaterial;n.unshaded?(t.shading=e.FlatShading,i=e.MeshBasicMaterial):(t.roughness=n.roughness,t.metalness=n.metalness,void 0!==n.emissive&&(t.emissive=n.emissive));var r=new i(t);return("number"==typeof n.color||n.color instanceof Number)&&r.color.set(n.color),r.wireframe=n.wireframe,r})}function o(t,n,r){var o=null;return n instanceof Array&&6===n.length?o=new e.CubeTextureLoader:(n instanceof HTMLImageElement&&(n=n.src),"string"==typeof n&&(o=new e.TextureLoader)),o&&o.setCrossOrigin("anonymous"),i("Texture("+t+")",function(){return new Promise(function(t,i){o?o.load(n,t,r,i):t(new e.Texture(n))})})}function s(t,n,s){s||(s={}),s.txtRepeatX||(s.txtRepeatX=1),s.txtRepeatY||(s.txtRepeatY=1),s.anisotropy||(s.anisotropy=1);var a=void 0===n?"undefined":yt(n),u=null;if("object"===a)n.id?u=n.id:(Et.has(n)||(Et.set(n,"TextureAutoID"+Mt),++Mt),u=Et.get(n));else if("string"===a)u=n;else{var h=new Error("Couldn't figure out how to make a texture out of typeof '"+a+"', value "+n+".");if(!s.reject)throw h;s.reject(h)}var c="Primrose.textured("+u+", "+s.txtRepeatX+", "+s.txtRepeatY+", "+s.anisotropy+", "+s.scaleTextureWidth+", "+s.scaleTextureHeight+")",l=i(c,function(){if("string"==typeof n||n instanceof Array||6===n.length)return o(c,n,s.progress);var t=null;return n instanceof HTMLCanvasElement||n instanceof HTMLVideoElement||n instanceof HTMLImageElement?t=new e.Texture(n):n.isTexture?t=n:Promise.reject("Texture description couldn't be converted to a THREE.Texture object"),Promise.resolve(t)}),d=r(c,s),f=null;if(t.type.indexOf("Geometry")>-1?f=new e.Mesh(t,d):t.isMesh&&(f=t,f.material=d,t=f.geometry),s.shadow&&(f.receiveShadow=!0,f.castShadow=!0),s.scaleTextureWidth||s.scaleTextureHeight)if(t.attributes&&t.attributes.uv&&t.attributes.uv.array){var p,m=t.attributes.uv,v=m.array;if(s.scaleTextureWidth)for(p=0;p<v.length;p+=m.itemSize)v[p]*=s.scaleTextureWidth;if(s.scaleTextureHeight)for(p=1;p<v.length;p+=m.itemSize)v[p]=1-(1-v[p])*s.scaleTextureHeight}else console.trace(t,s);return s.promise=l.then(function(t){return s.txtRepeatX*s.txtRepeatY>1&&(t.wrapS=t.wrapT=e.RepeatWrapping,t.repeat.set(s.txtRepeatX,s.txtRepeatY)),t.anisotropy=s.anisotropy,t.isCubeTexture?d.envMap=t:t.isTexture&&(d.map=t),d.needsUpdate=!0,t.needsUpdate=!0,t}),f}function a(t,n,i){i=i||{},i.color=n;var o=r("",i),s=null;return t.type.indexOf("Geometry")>-1?s=new e.Mesh(t,o):t.isObject3D&&(s=t,s.material=o),i.shadow&&(s.receiveShadow=!0,s.castShadow=!0),i.resolve&&i.resolve(),s}function u(t,n,r,o,s,a){return void 0===n&&(n=t),void 0===r&&(r=t),i("BoxBufferGeometry("+t+", "+n+", "+r+", "+o+", "+s+", "+a+")",function(){return new e.BoxBufferGeometry(t,n,r,o,s,a)})}function h(e,t,n,i,r){return t=t||1,n=n||1,i=i||1,r=Object.assign({},{txtRepeatX:t,txtRepeatY:i,anisotropy:8,transparent:!0,opacity:1},r),("number"==typeof e?a:s)(u(t,n,i),e,r)}function c(e,t){return n().add(h(16711680,e,t,t)).add(h(65280,t,e,t)).add(h(255,t,t,e))}function l(e,t,n,i){function r(n){o=t(r,i),e(n?n-s:0),s=n}var o,s;return{start:function(){o||r()},stop:function(){o=n(o)}}}function d(e){return l(e,requestAnimationFrame,cancelAnimationFrame)}function f(e,t,n,i){function r(t){Boolean(e[n])===Boolean(i)&&t.stopImmediatePropagation(),delete e[n]}return e.addEventListener(t,r,!1),r}function p(e,t,n,i){function r(){return n[t]}function o(e){n[t]=e}i&&o(e[t]),Object.defineProperty(e,t,{get:r,set:o})}function m(e,t,n){n.addEventListener(t,function(){return e.dispatchEvent(new Event(t))})}function v(e,t){Promise.resolve().then(function(){e.dispatchEvent(new Event(t))})}function g(e){var t=new Audio;return m(e,"play",t),m(e,"playing",t),m(e,"pause",t),t.crossOrigin=e.crossOrigin,t.src=e.src||e.currentSrc||"data:",t}function y(e,t,n){(nt||0)+200<Date.now()&&(e[Ct]=!0,nt=Date.now()),n||(e.currentTime=t),Dt[++Lt%3]=100*t|0}function _(e){return e.driver.currentTime>=e.video.duration}function w(e){var t=this;t.video.readyState>=t.video.HAVE_FUTURE_DATA?(t.hasAudio||(t.driver.currentTime=t.video.currentTime+e*t.video.playbackRate/1e3,t.video.loop&&_(t)&&(t.driver.currentTime=0)),y(t.video,t.driver.currentTime)):t.video.networkState!==t.video.NETWORK_IDLE||t.video.buffered.length||t.video.load(),t.video.ended&&(delete t.video[Ct],t.video.pause(!0))}function b(){var e=this,t=e[Pt];if(e.webkitDisplayingFullscreen)return void e[At]();"data:"!==t.driver.src&&t.driver.src!==e.src&&(y(e,0,!0),t.driver.src=e.src),e.paused&&(t.paused=!1,e.buffered.length||e.load(),t.driver.play(),t.updater.start(),t.hasAudio||(v(e,"play"),t.video.readyState>=t.video.HAVE_ENOUGH_DATA&&v(e,"playing")))}function k(e){var t=this,n=t[Pt];n.driver.pause(),n.updater.stop(),t.webkitDisplayingFullscreen&&t[Rt](),n.paused&&!e||(n.paused=!0,n.hasAudio||v(t,"pause"),t.ended&&(t[Ct]=!0,v(t,"ended")))}function x(e,t){var n=e[Pt]={};n.paused=!0,n.hasAudio=t,n.video=e,n.updater=d(w.bind(n)),t?n.driver=g(e):(e.addEventListener("canplay",function(){e.paused||v(e,"playing")}),n.driver={src:e.src||e.currentSrc||"data:",muted:!0,paused:!0,pause:function(){n.driver.paused=!0},play:function(){n.driver.paused=!1,_(n)&&y(e,0)},get ended(){return _(n)}}),e.addEventListener("emptied",function(){var t=!n.driver.src||"data:"===n.driver.src;n.driver.src&&n.driver.src!==e.src&&(y(e,0,!0),n.driver.src=e.src,t?n.driver.play():n.updater.stop())},!1),e.addEventListener("webkitbeginfullscreen",function(){e.paused?t&&!n.driver.buffered.length&&n.driver.load():(e.pause(),e[At]())}),t&&(e.addEventListener("webkitendfullscreen",function(){n.driver.currentTime=e.currentTime}),e.addEventListener("seeking",function(){Dt.indexOf(100*e.currentTime|0)<0&&(n.driver.currentTime=e.currentTime)}))}function S(e){var t=e[Pt];e[At]=e.play,e[Rt]=e.pause,e.play=b,e.pause=k,p(e,"paused",t.driver),p(e,"muted",t.driver,!0),p(e,"playbackRate",t.driver,!0),p(e,"ended",t.driver),p(e,"loop",t.driver,!0),f(e,"seeking"),f(e,"seeked"),f(e,"timeupdate",Ct,!1),f(e,"ended",Ct,!1)}function E(e,t,n){void 0===t&&(t=!0),void 0===n&&(n=!0),n&&!Ot||e[Pt]||(x(e,t),S(e),e.classList.add("IIV"),!t&&e.autoplay&&e.play(),/iPhone|iPod|iPad/.test(navigator.platform)||console.warn("iphone-inline-video is not guaranteed to work in emulated environments"))}function M(e,t){t=t||{};var n=t.maxU||1,i=t.maxV||1,r=e.attributes||e._bufferGeometry&&e._bufferGeometry.attributes;if(r&&r.uv&&r.uv.array){for(var o=r.uv,s=o.array,a=0;a<s.length;a+=o.itemSize)s[a]*=n;for(var u=1;u<s.length;u+=o.itemSize)s[u]=1-(1-s[u])*i}else if(e.faceVertexUvs)for(var h=e.faceVertexUvs,c=0;c<h.length;++c)for(var l=h[c],d=0;d<l.length;++d)for(var f=l[d],p=0;p<f.length;++p){var m=f[p];m.x*=n,m.y=1-(1-m.y)*i}return e}function T(t,n,r){return void 0===t&&(t=1),void 0===n&&(n=t),r=Object.assign({},{s:1,t:1},r),i("PlaneBufferGeometry("+t+", "+n+", "+r.s+", "+r.t+", "+r.maxU+", "+r.maxV+")",function(){return M(new e.PlaneBufferGeometry(t,n,r.s,r.t),r)})}function O(e,t,n,r,o,s){void 0===r&&(r=Math.PI*Ft),void 0===o&&(o=Math.PI*Ft*.6);var a=1.5*Math.PI-.5*r,u=.5*(Math.PI-o);return s=s||{},i("InsideSphereGeometry("+e+", "+t+", "+n+", "+r+", "+o+")",function(){return M(new It(e,t,n,a,r,u,o,!0),s)})}function P(){Vt.forEach(function(e){e.eyeBlank(0),e.update()})}function C(e){Vt.forEach(function(t){return t.eyeBlank(e)})}function A(e){for(var t=document.querySelectorAll("video"),n=0;n<t.length;++n)R(t[n]);window.removeEventListener("touchend",A),window.removeEventListener("mouseup",A),window.removeEventListener("keyup",A)}function R(e){ht&&-1===Bt.indexOf(e)&&(Bt.push(e),E(e,!1))}function D(e,t){return t=Object.assign({width:1,height:.6,unshaded:!0,transparent:!0,opacity:.5},t),navigator.mediaDevices.enumerateDevices().catch(console.error.bind(console,"ERR [enumerating devices]:>")).then(function(t){return t.filter(function(e){return"videoinput"===e.kind})[e]}).catch(console.error.bind(console,"ERR [filtering devices]:>")).then(function(e){return navigator.mediaDevices.getUserMedia({video:{deviceId:e.deviceId,width:{ideal:1280},height:{ideal:768}}})}).catch(console.error.bind(console,"ERR [getting media access]:>")).then(function(e){return new zt(e,t).ready}).catch(console.error.bind(console,"ERR [creating image]:>"))}function L(t,n,r,o){return t=t||1,n=n||18,i("CircleBufferGeometry("+t+", "+n+", "+r+", "+o+")",function(){return new e.CircleBufferGeometry(t,n,r,o)})}function N(t,n,r){for(var o=new e.Geometry,s=0;s<t.length;++s)o.vertices.push(t[s]);var a=i("PointsMaterial("+n+", "+r+")",function(){return new e.PointsMaterial({color:n,size:r})});return new e.Points(o,a)}function I(t,n,r,o,s,a,u,h){return void 0===t&&(t=.5),void 0===n&&(n=.5),void 0===r&&(r=1),i("CylinderBufferGeometry("+t+", "+n+", "+r+", "+o+", "+s+", "+a+", "+u+", "+h+")",function(){return new e.CylinderBufferGeometry(t,n,r,o,s,a,u,h)})}function F(t,n,i,r){return new e.PointLight(t,n,i,r)}function V(t,n,i,r){return new e.Quaternion(t,n,i,r)}function U(e){return e}function j(e,t,n,i){var r=n&&e||0,o=n&&t||e,s=i&&n||1,a=i||n||t,u=null;a instanceof Function||(a=U);for(var h=r;h<o;h+=s){var c=a(h);null===u&&void 0!==c&&(u=[]),null!==u&&u.push(c)}if(null!==u)return u}function B(t,n,r,o,s,a){return void 0===t&&(t=.5),r=r||18,o=o||1,n=n||1,s=s||0,a=a||2*Math.PI,i("RingBufferGeometry("+t+", "+n+", "+r+", "+o+", "+s+", "+a+")",function(){return new e.RingBufferGeometry(t,n,r,o,s,a)})}function z(){return new e.Raycaster}function H(t,n,r){return i("SphereGeometry("+t+", "+n+", "+r+")",function(){return new e.SphereGeometry(t,n,r)})}function W(t,n){return new e.Vector2(t,n)}function G(t,n,i){return new e.Vector3(t,n,i)}function Q(t,n,i,r){return new e.Vector4(t,n,i,r)}function K(e,t){for(var n=0;n<t.length;++n)if(t[n]in e)return t[n]}function Y(e){window.localStorage&&window.localStorage.removeItem(e)}function q(e,t){if(window.localStorage){var n=window.localStorage.getItem(e);if(n)try{return JSON.parse(n)}catch(t){console.error("getSetting",e,n,void 0===n?"undefined":yt(n),t),console.error(t),console.error("getSetting",e,n,void 0===n?"undefined":yt(n))}}return t}function X(e){return{enumerable:!0,configurable:!0,get:"function"==typeof e?e:function(){return e},set:function(){throw new Error("This value is immutable and may only be read, not written.")}}}function Z(e){return!isNaN(e)&&Yt<e&&e<=qt}function J(e,t){return t?"function"==typeof t?{enumerable:!0,configurable:!0,get:function(){return e},set:function(n){if(n instanceof t)throw new Error("Value must be a "+t+": "+n);e=n}}:{enumerable:!0,configurable:!0,get:function(){return e},set:function(n){var i=void 0===n?"undefined":yt(n);if(i!==t)throw new Error("Value must be a "+t+". An "+i+" was provided instead: "+n);e=n}}:{enumerable:!0,configurable:!0,get:function(){return e},set:function(t){e=t}}}function $(e){var t=screen.orientation&&screen.orientation.type||screen.mozOrientation||"";return-1===t.indexOf("landscape")&&(t="landscape-primary"),screen.orientation&&screen.orientation.lock?screen.orientation.lock(t):screen.mozLockOrientation?screen.mozLockOrientation(t)?Promise.resolve(e):void 0:Promise.reject(new Error("Pointer lock not supported."))}function ee(){screen.orientation&&screen.orientation.unlock?screen.orientation.unlock():screen.mozUnlockOrientation&&screen.mozUnlockOrientation()}function te(e,t){if(window.localStorage&&t)try{window.localStorage.setItem(e,JSON.stringify(t))}catch(n){console.error("setSetting",e,t,void 0===t?"undefined":yt(t),n)}}function ne(){return lt?(Xt.unlock(),Promise.resolve()):Zt.exit().catch(function(e){return console.warn("PointerLock exit failed",e)})}function ie(){return ne().then(function(){return Kt.exit()}).catch(function(e){return console.warn("FullScreen failed",e)})}function re(e){return ht?Promise.resolve(e):lt?Xt.lock(e).catch(function(e){return console.warn("OrientationLock failed",e)}):Zt.request(e).catch(function(e){return console.warn("PointerLock failed",e)})}function oe(e){return Kt.request(e).catch(function(e){return console.warn("FullScreen failed",e)}).then(re)}function se(e,t,n,i){return new Promise(function(r,o){i=i||{},i.headers=i.headers||{},"POST"===e&&(i.headers["Content-Type"]=i.headers["Content-Type"]||t);var s=new XMLHttpRequest;s.onerror=function(e){return o(new Error("Request error: "+e.message))},s.onabort=function(e){return o(new Error("Request abort: "+e.message))},s.onload=function(){s.status<400?r(s.response):o(s)},s.open(e,n),t&&(s.responseType=t),s.onprogress=i.progress;for(var a in i.headers)s.setRequestHeader(a,i.headers[a]);s.withCredentials=!!i.withCredentials,i.data?s.send(JSON.stringify(i.data)):s.send()})}function ae(e,t,n){return se("GET",e||"text",t,n)}function ue(e,t){return ae("arraybuffer",e,t)}function he(e,t,n,i){var r=null;if(null===e?(r=document.createElement(t),r.id=e="auto_"+t+Date.now()):void 0===n||e instanceof n?r=e:"string"==typeof e&&(r=document.getElementById(e),null===r?(r=document.createElement(t),r.id=e,i&&document.body.appendChild(r)):r.tagName!==t.toUpperCase()&&(r=null)),null===r)throw new Error(e+" does not refer to a valid "+t+" element.");return r}function ce(e){return e&&e._listeners&&(e._listeners.gazecomplete&&e._listeners.gazecomplete.length>0||e._listeners.select&&e._listeners.select.length>0||e._listeners.click&&e._listeners.click.length>0)}function le(e,t){return function(n){return ni.loadObject(e[t]).then(function(e){return n[t]=e,n})}}function de(e){return e.traverse(function(e){e.geometry&&(e.geometry.computeBoundingSphere(),e.geometry.computeBoundingBox())}),e}function fe(e){return"Group"===e.type&&1===e.children.length&&e.children[0].isMesh?e.children[0]:e}function pe(e){return e.traverse(function(e){if(e.isMesh)for(var t in ti)e[t]=e[t]||ti[t](e)}),e}function me(e,t,n,i){var r=Math.tan(t?t.upDegrees*yi:_i),o=Math.tan(t?t.downDegrees*yi:_i),s=Math.tan(t?t.leftDegrees*yi:_i),a=Math.tan(t?t.rightDegrees*yi:_i),u=2/(s+a),h=2/(r+o);return e[0]=u,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=h,e[6]=0,e[7]=0,e[8]=-(s-a)*u*.5,e[9]=(r-o)*h*.5,e[10]=i/(n-i),e[11]=-1,e[12]=0,e[13]=0,e[14]=i*n/(n-i),e[15]=0,e}function ve(e,t,n){var i=t[0],r=t[1],o=t[2],s=t[3],a=i+i,u=r+r,h=o+o,c=i*a,l=i*u,d=i*h,f=r*u,p=r*h,m=o*h,v=s*a,g=s*u,y=s*h;return e[0]=1-(f+m),e[1]=l+y,e[2]=d-g,e[3]=0,e[4]=l-y,e[5]=1-(c+m),e[6]=p+v,e[7]=0,e[8]=d+g,e[9]=p-v,e[10]=1-(c+f),e[11]=0,e[12]=n[0],e[13]=n[1],e[14]=n[2],e[15]=1,e}function ge(e,t,n){var i,r,o,s,a,u,h,c,l,d,f,p,m=n[0],v=n[1],g=n[2];return t===e?(e[12]=t[0]*m+t[4]*v+t[8]*g+t[12],e[13]=t[1]*m+t[5]*v+t[9]*g+t[13],e[14]=t[2]*m+t[6]*v+t[10]*g+t[14],e[15]=t[3]*m+t[7]*v+t[11]*g+t[15]):(i=t[0],r=t[1],o=t[2],s=t[3],a=t[4],u=t[5],h=t[6],c=t[7],l=t[8],d=t[9],f=t[10],p=t[11],e[0]=i,e[1]=r,e[2]=o,e[3]=s,e[4]=a,e[5]=u,e[6]=h,e[7]=c,e[8]=l,e[9]=d,e[10]=f,e[11]=p,e[12]=i*m+a*v+l*g+t[12],e[13]=r*m+u*v+d*g+t[13],e[14]=o*m+h*v+f*g+t[14],e[15]=s*m+c*v+p*g+t[15]),e}function ye(e,t){var n=t[0],i=t[1],r=t[2],o=t[3],s=t[4],a=t[5],u=t[6],h=t[7],c=t[8],l=t[9],d=t[10],f=t[11],p=t[12],m=t[13],v=t[14],g=t[15],y=n*a-i*s,_=n*u-r*s,w=n*h-o*s,b=i*u-r*a,k=i*h-o*a,x=r*h-o*u,S=c*m-l*p,E=c*v-d*p,M=c*g-f*p,T=l*v-d*m,O=l*g-f*m,P=d*g-f*v,C=y*P-_*O+w*T+b*M-k*E+x*S;return C?(C=1/C,e[0]=(a*P-u*O+h*T)*C,e[1]=(r*O-i*P-o*T)*C,e[2]=(m*x-v*k+g*b)*C,e[3]=(d*k-l*x-f*b)*C,e[4]=(u*M-s*P-h*E)*C,e[5]=(n*P-r*M+o*E)*C,e[6]=(v*w-p*x-g*_)*C,e[7]=(c*x-d*w+f*_)*C,e[8]=(s*O-a*M+h*S)*C,e[9]=(i*M-n*O-o*S)*C,e[10]=(p*k-m*w+g*y)*C,e[11]=(l*w-c*k-f*y)*C,e[12]=(a*E-s*T-u*S)*C,e[13]=(n*T-i*E+r*S)*C,e[14]=(m*_-p*b-v*y)*C,e[15]=(c*b-l*_+d*y)*C,e):null}function _e(e,t,n,i,r){me(e,i?i.fieldOfView:null,r.depthNear,r.depthFar),ve(t,n.orientation||wi,n.position||bi),i&&ge(t,t,i.offset),ye(t,t)}function we(e,t,n){return!(!e||!t)&&(e.pose=t,e.timestamp=t.timestamp,_e(e.leftProjectionMatrix,e.leftViewMatrix,t,n.getEyeParameters("left"),n),_e(e.rightProjectionMatrix,e.rightViewMatrix,t,n.getEyeParameters("right"),n),!0)}function be(){return{position:[0,0,0],orientation:[0,0,0,1],linearVelocity:null,linearAcceleration:null,angularVelocity:null,angularAcceleration:null}}function ke(e,t,n){return 180*Math.atan(Math.tan(e*Math.PI/180)*t/n)/Math.PI}function xe(e,t){var n=he(e,"div",window.HTMLDivElement);return n.style.position="absolute",n.style.left=0,n.style.top=0,n.style.width=0,n.style.height=0,n.style.overflow="hidden",n.appendChild(t),n}function Se(){this.inputState={buttons:[],axes:[],ctrl:!1,alt:!1,shift:!1,meta:!1},this.lastInputState={buttons:[],axes:[],ctrl:!1,alt:!1,shift:!1,meta:!1}}function Ee(e){for(var t=0;t<In.MODIFIER_KEYS.length;++t){var n=In.MODIFIER_KEYS[t];if(Math.abs(e)===In[n.toLocaleUpperCase()])return Math.sign(e)*(t+1)}}function Me(e){var t=void 0===e?"undefined":yt(e),n=0,i=!1,r=1;if("number"===t)n=Math.abs(e)-1,i=e<0,r=e<0?-1:1;else{if("string"!==t)throw new Error("Cannot clone command spec. Element was type: "+t,e);"-"===e[0]&&(r=-1,e=e.substring(1)),n=this.axisNames.indexOf(e)}return{index:n,toggle:i,sign:r}}function Te(e,t){for(var n=0;n<this.inputState.buttons.length;++n)this[e].buttons[n]=this[t].buttons[n];for(var i=0;i<this.inputState.axes.length;++i)this[e].axes[i]=this[t].axes[i];for(var r=0;r<In.MODIFIER_KEYS.length;++r){var o=In.MODIFIER_KEYS[r];this[e][o]=this[t][o]}}function Oe(){Te.call(this,"inputState","lastInputState")}function Pe(){Te.call(this,"lastInputState","inputState")}function Ce(e,t,n){if(t.length>0){var i=t.shift();if(!n)for(var r=0;r<e.length;++r)e[0].vibrate(1,i);setTimeout(Ce,i,e,t,!n)}}function Ae(e,t){return ae("json",e,t)}function Re(){"VRDisplay"in window&&!("VRFrameData"in window)&&(window.VRFrameData=ki,"depthNear"in window.VRDisplay.prototype||(window.VRDisplay.prototype.depthNear=.01),"depthFar"in window.VRDisplay.prototype||(window.VRDisplay.prototype.depthFar=1e4),window.VRDisplay.prototype.getFrameData=function(e){return we(e,this.getPose(),this)})}function De(e){return gr||((vr||e.forceStereo)&&(Kt.addChangeListener(Le),mr.push(new ar(e))),gr=!0),new Promise(function(e,t){try{e(mr)}catch(e){t(e)}})}function Le(){var e=new CustomEvent("vrdisplaypresentchange",{detail:{vrdisplay:this}});window.dispatchEvent(e)}function Ne(e){var t=null;t=pr?navigator.getVRDisplays:function(){return Promise.resolve([])},navigator.getVRDisplays=function(){return t.call(navigator).then(function(t){return 0===t.length||"Mozilla/5.0 (Linux; Android 6.0.1; SM-G930V Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2664.0 Mobile Safari/537.36"===navigator.userAgent?(e.overrideOrientation=t[0],De(e)):t})},window.VRDisplay=window.VRDisplay||Si,Object.defineProperty(navigator,"vrEnabled",{get:function(){return vr&&(Kt.available||ht)}})}function Ie(e){if(!yr&&!st){var t=navigator.getVRDisplays;navigator.getVRDisplays=function(){return t.call(navigator).then(function(t){for(var n=!1,i=0;i<t.length&&!n;++i){n=t[i]instanceof Mi}return n||(e&&e.defaultFOV&&(Mi.DEFAULT_FOV=e.defaultFOV),t.unshift(new Mi(t[0]))),t})},yr=!0}}function Fe(e){var t=e&&e.replayData;if(t){var n=navigator.getVRDisplays;navigator.getVRDisplays=function(){return n.call(navigator).then(function(e){if(e.map(function(e){return e instanceof fr}).reduce(function(e,t){return e||t},!1))return e;return"object"===(void 0===t?"undefined":yt(t))?Promise.resolve(t):/\.json$/.test(t)?Ae(t):Promise.resolve(JSON.parse(t))})}}}function Ve(e){e=Object.assign({FORCE_ENABLE_VR:!1},e),Ne(e),Ie(e),Fe(e),Re()}function Ue(e,t,n){n=n||1,void 0===t&&(t=e,e=0);var i=t-e;return e+Math.pow(Math.random(),n)*i}function je(e,t,n){return Math.floor(Ue(e,t,n))}function Be(){return je(0,256)<<16|je(0,256)<<8|je(0,256)}function ze(e,t){e=e||document,t=t||{};for(var n=e.querySelectorAll("*"),i=0;i<n.length;++i){var r=n[i];r.id&&r.id.length>0&&(t[r.id]=r,r.parentElement&&(r.parentElement[r.id]=r))}return t}function He(e,t,n){return se("DELETE",e,t,n)}function We(e,t){return He("json",e,t)}function Ge(e,t){return ae("text",e,t)}function Qe(e,t,n){return se("POST",e,t,n)}function Ke(e,t){return Qe("json",e,t)}function Ye(e){if(so&&e){for(var t=e.sdp,n=t.split("\r\n"),i=null,r=0;r<n.length;r++)if(-1!==n[r].search("m=audio")){i=r;break}if(null===i)return t;for(var o=0;o<n.length;o++)if(-1!==n[o].search("opus/48000")){var s=qe(n[o],/:(\d+) opus\/48000/i);s&&(n[i]=Xe(n[i],s));break}n=Ze(n,i),e.sdp=n.join("\r\n")}return e}function qe(e,t){var n=e.match(t);return n&&2==n.length?n[1]:null}function Xe(e,t){for(var n=e.split(" "),i=[],r=0,o=0;o<n.length;o++)3===r&&(i[r++]=t),n[o]!==t&&(i[r++]=n[o]);return i.join(" ")}function Ze(e,t){for(var n=e[t].split(" "),i=e.length-1;i>=0;i--){var r=qe(e[i],/a=rtpmap:(\d+) CN\/\d+/i);if(r){var o=n.indexOf(r);-1!==o&&n.splice(o,1),e.splice(i,1)}}return e[t]=n.join(" "),e}function Je(){return(Math.random()*Math.log(Number.MAX_VALUE)).toString(36).replace(".","")}function $e(e){return e[je(e.length)]}function et(e,t,n){return e+je(0,(1+t-e)/n)*n}function tt(t,n){return(new e.Vector3).set(Ue(t,n),Ue(t,n),Ue(t,n))}var nt,it=!!window.opera||navigator.userAgent.indexOf(" OPR/")>=0,rt=!!window.chrome&&!it,ot=void 0!==window.InstallTrigger,st=navigator.userAgent.indexOf("Mobile VR")>-1,at=!!document.documentMode,ut=window.self!==window.top,ht=/iP(hone|od|ad)/.test(navigator.userAgent||""),ct=/Macintosh/.test(navigator.userAgent||""),lt=function(e){return/(android|bb\d+|meego).+|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|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|phone)|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.substring(0,4))}(navigator.userAgent||navigator.vendor||window.opera),dt=Object.prototype.toString.call(window.HTMLElement).indexOf("Constructor")>0,ft=it||rt||dt,pt=/Windows/.test(navigator.userAgent||""),mt={isChrome:rt,isFirefox:ot,isGearVR:st,isIE:at,isInIFrame:ut,isiOS:ht,isLandscape:t,isMacOS:ct,isMobile:lt,isOpera:it,isSafari:dt,isWebKit:ft,isWindows:pt},vt=Object.freeze({isChrome:rt,isFirefox:ot,isGearVR:st,isIE:at,isInIFrame:ut,isiOS:ht,isLandscape:t,isMacOS:ct,isMobile:lt,isOpera:it,isSafari:dt,isWebKit:ft,isWindows:pt,default:mt}),gt={},yt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},wt=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),bt=function e(t,n,i){null===t&&(t=Function.prototype);var r=Object.getOwnPropertyDescriptor(t,n);if(void 0===r){var o=Object.getPrototypeOf(t);return null===o?void 0:e(o,n,i)}if("value"in r)return r.value;var s=r.get;if(void 0!==s)return s.call(i)},kt=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},xt=function(e,t){
if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},St=function e(t,n,i,r){var o=Object.getOwnPropertyDescriptor(t,n);if(void 0===o){var s=Object.getPrototypeOf(t);null!==s&&e(s,n,i,r)}else if("value"in o&&o.writable)o.value=i;else{var a=o.set;void 0!==a&&a.call(r,i)}return i},Et=new WeakMap,Mt=0,Tt="undefined"==typeof Symbol?function(e){return"@"+(e||"@")+Math.random()}:Symbol,Ot="object-fit"in document.head.style&&/iPhone|iPod/i.test(navigator.userAgent)&&!matchMedia("(-webkit-video-playable-inline)").matches,Pt=Tt(),Ct=Tt(),At=Tt("nativeplay"),Rt=Tt("nativepause"),Dt=[],Lt=0;E.isWhitelisted=Ot;var Nt=function(e){function t(e,n){_t(this,t);var i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return i.isEntity=!0,i.name=e,i.options=n||{},i.ready=i._ready.then(function(){return i}),i.disabled=!1,i}return kt(t,e),wt(t,[{key:"_ready",get:function(){return Promise.resolve()}}]),t}(e.Object3D),It=function(t){function n(t,i,r,o,s,a,u){_t(this,n);var h=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this));h.type="InsideSphereGeometry",h.parameters={radius:t,widthSegments:i,heightSegments:r,phiStart:o,phiLength:s,thetaStart:a,thetaLength:u},t=t||50,i=Math.max(3,Math.floor(i)||8),r=Math.max(2,Math.floor(r)||6),o=void 0!==o?o:0,s=void 0!==s?s:2*Math.PI,a=void 0!==a?a:0,u=void 0!==u?u:Math.PI;var c,l,d=[],f=[];for(l=0;l<=r;l++){var p=[],m=[];for(c=i;c>=0;c--){var v=c/i,g=l/r,y=new e.Vector3;y.x=-t*Math.cos(o+v*s)*Math.sin(a+g*u),y.y=t*Math.cos(a+g*u),y.z=t*Math.sin(o+v*s)*Math.sin(a+g*u),h.vertices.push(y),p.push(h.vertices.length-1),m.push(new e.Vector2(1-v,1-g))}d.push(p),f.push(m)}for(l=0;l<r;l++)for(c=0;c<i;c++){var _=d[l][c+1],w=d[l][c],b=d[l+1][c],k=d[l+1][c+1],x=h.vertices[_].clone().normalize(),S=h.vertices[w].clone().normalize(),E=h.vertices[b].clone().normalize(),M=h.vertices[k].clone().normalize(),T=f[l][c+1].clone(),O=f[l][c].clone(),P=f[l+1][c].clone(),C=f[l+1][c+1].clone();Math.abs(h.vertices[_].y)===t?(T.x=(T.x+O.x)/2,h.faces.push(new e.Face3(_,b,k,[x,E,M])),h.faceVertexUvs[0].push([T,P,C])):Math.abs(h.vertices[b].y)===t?(P.x=(P.x+C.x)/2,h.faces.push(new e.Face3(_,w,b,[x,S,E])),h.faceVertexUvs[0].push([T,O,P])):(h.faces.push(new e.Face3(_,w,k,[x,S,M])),h.faceVertexUvs[0].push([T,O,C]),h.faces.push(new e.Face3(w,b,k,[S.clone(),E,M.clone()])),h.faceVertexUvs[0].push([O.clone(),P,C.clone()]))}h.computeFaceNormals();for(var A=0;A<h.faces.length;++A){var R=h.faces[A];R.normal.multiplyScalar(-1);for(var D=0;D<R.vertexNormals.length;++D)R.vertexNormals[D].multiplyScalar(-1)}return h.boundingSphere=new e.Sphere(new e.Vector3,t),h}return kt(n,t),n}(e.Geometry),Ft=.45,Vt=[],Ut=function(e){function t(e,n){_t(this,t),name=n&&n.id||e.join();var i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,name,n));return Vt.push(i),i._files=e,i._meshes=[],i._textures=[],i._currentImageIndex=0,i.options.geometry?i._geometry=i.options.geometry:i.options.radius?i._geometry=O(i.options.radius,72,36,2*Math.PI,Math.PI,n):(i.options.width||(i.options.width=.5),i.options.height||(i.options.height=.5),i._geometry=T(i.options.width,i.options.height,n)),i}return kt(t,e),wt(t,[{key:"eyeBlank",value:function(e){if(this._meshes&&this._meshes.length>0){this._currentImageIndex=e%this._meshes.length;for(var t=0;t<this._meshes.length;++t)this._meshes[t].visible=t===this._currentImageIndex}}},{key:"update",value:function(){}},{key:"_ready",get:function(){var e=this;return bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"_ready",this).then(function(){return e._loadFiles(e._files,e.options.progress)}).then(function(){return e._meshes.forEach(function(t){return e.add(t)})})}},{key:"blending",get:function(){return this._meshes&&this._meshes.length>0&&this._meshes[0]&&this._meshes[0].material.blending},set:function(e){this._meshes.forEach(function(t){return t.material.blending=e})}}]),t}(Nt),jt=0,Bt=[];window.addEventListener("touchend",A,!1),window.addEventListener("mouseup",A,!1),window.addEventListener("keyup",A,!1);var zt=function(t){function n(e,t){return _t(this,n),e instanceof Array||(e=[e]),t=Object.assign({},{id:"Primrose.Controls.Video["+jt+++"]"},t),xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e,t))}return kt(n,t),wt(n,[{key:"_loadFiles",value:function(t,n){var i=this;return this._elements=Array.prototype.map.call(t,function(t,r){var o=null;"string"==typeof t?(o=document.querySelector("video[src='"+t+"']"))||(o=document.createElement("video"),o.src=t):t instanceof HTMLVideoElement?o=t:"[object MediaStream]"!==t.toString()&&"[object LocalMediaStream]"!==t.toString()||(o=document.createElement("video"),o.srcObject=t),o.onprogress=n,o.onloadedmetadata=n,o.muted=!0,o.loop=!0,o.setAttribute("playsinline",""),o.setAttribute("webkit-playsinline",""),ht||(o.preload="auto");var a=Object.assign({},i.options);return i._meshes[r]=s(i._geometry,o,a),o.parentElement||(document.body.insertBefore(o,document.body.children[0]),R(o)),a.promise.then(function(t){i._textures[r]=t,console.log(t),t.minFilter=e.LinearFilter}),o}),Promise.resolve()}},{key:"play",value:function(){this._elements.length>0&&this._elements[0].play()}},{key:"update",value:function(){bt(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"update",this).call(this);for(var e=0;e<this._textures.length;++e)if(this._textures[e]){var t=this._elements[e];t.currentTime!==this._lastTime&&(this._textures[e].needsUpdate=!0,this._lastTime=t.currentTime)}}}]),n}(Ut),Ht={axis:c,box:u,brick:h,camera:D,circle:L,cloud:N,colored:a,cylinder:I,hub:n,light:F,material:r,quad:T,quat:V,range:j,ring:B,shell:O,raycaster:z,sphere:H,textured:s,v2:W,v3:G,v4:Q},Wt=Object.freeze({axis:c,box:u,brick:h,camera:D,circle:L,cloud:N,colored:a,cylinder:I,hub:n,light:F,material:r,quad:T,quat:V,range:j,ring:B,shell:O,raycaster:z,sphere:H,textured:s,v2:W,v3:G,v4:Q,default:Ht}),Gt=function(){function e(t,n,i,r,o,s){_t(this,e),this.name=t,this._elementName=K(document,n),this._requestMethodName=K(document.documentElement,o),this._exitMethodName=K(document,s),this._changeTimeout=null,this._changeEventName=K(document,i),this._errorEventName=K(document,r),this._changeEventName=this._changeEventName&&this._changeEventName.substring(2),this._errorEventName=this._errorEventName&&this._errorEventName.substring(2),this._events={change:this._changeEventName,error:this._errorEventName},this.exit=this.exit.bind(this),this.request=this.request.bind(this)}return wt(e,[{key:"addEventListener",value:function(e,t,n){this._events[e]&&document.addEventListener(this._events[e],t,n)}},{key:"removeEventListener",value:function(e,t){this._events[e]&&document.removeEventListener(this._events[e],t)}},{key:"addChangeListener",value:function(e,t){this.addEventListener("change",e,t)}},{key:"removeChangeListener",value:function(e){this.removeEventListener("change",e)}},{key:"addErrorListener",value:function(e,t){this.addEventListener("error",e,t)}},{key:"removeErrorListener",value:function(e){this.removeEventListener("error",e)}},{key:"_withChange",value:function(e){var t=this;return new Promise(function(n,i){var r=function(){setTimeout(a),n(t.element)},o=function(e){setTimeout(a),i(e)},s=function(){t._changeTimeout&&(clearTimeout(t._changeTimeout),t._changeTimeout=null)},a=function(){s(),t.removeChangeListener(r),t.removeErrorListener(o)};t.addChangeListener(r,!1),t.addErrorListener(o,!1),e()?r():(s(),t._changeTimeout=setTimeout(function(){return o(name+" state did not change in allotted time")},1e3))})}},{key:"request",value:function(e,t){var n=this;return this._withChange(function(){if(!n._requestMethodName)throw new Error("No "+n.name+" API support.");if(n.isActive)return!0;t?e[n._requestMethodName](t):e[n._requestMethodName]()})}},{key:"exit",value:function(){var e=this;return this._withChange(function(){if(!e._exitMethodName)throw new Error("No "+name+" API support.");if(!e.isActive)return!0;document[e._exitMethodName]()})}},{key:"element",get:function(){return document[this._elementName]}},{key:"isActive",get:function(){return!!this.element}}]),e}(),Qt=function(e){function t(){_t(this,t);var e=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Fullscreen",["fullscreenElement","msFullscreenElement","mozFullScreenElement","webkitFullscreenElement"],["onfullscreenchange","onmsfullscreenchange","onmozfullscreenchange","onwebkitfullscreenchange"],["onfullscreenerror","onmsfullscreenerror","onmozfullscreenerror","onwebkitfullscreenerror"],["requestFullscreen","msRequestFullscreen","mozRequestFullScreen","webkitRequestFullscreen"],["exitFullscreen","msExitFullscreen","mozExitFullScreen","webkitExitFullscreen"]));return e._fullScreenEnabledProperty=K(document,["fullscreenEnabled","msFullscreenEnabled","mozFullScreenEnabled","webkitFullscreenEnabled"]),e}return kt(t,e),wt(t,[{key:"available",get:function(){return!(!this._fullScreenEnabledProperty||!document[this._fullScreenEnabledProperty])}}]),t}(Gt),Kt=new Qt,Yt=.001,qt=1,Xt={lock:$,unlock:ee},Zt=new Gt("Pointer Lock",["pointerLockElement","mozPointerLockElement","webkitPointerLockElement"],["onpointerlockchange","onmozpointerlockchange","onwebkitpointerlockchange"],["onpointerlockerror","onmozpointerlockerror","onwebkitpointerlockerror"],["requestPointerLock","mozRequestPointerLock","webkitRequestPointerLock","webkitRequestPointerLock"],["exitPointerLock","mozExitPointerLock","webkitExitPointerLock","webkitExitPointerLock"]),Jt=function(e){function t(e){_t(this,t);var n,i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this)),r=e.toString(),o=r.match(/function\s+(\w+)\s*\(/),s=o[1];for(n in e.prototype)r+="\n\n"+s+".prototype."+n+" = "+e.prototype[n].toString()+";";r+="\n\n(function(){\n var instance = new "+s+"(true);",r+="\n if(instance.addEventListener){\n self.args = [null, null];\n for(var k in instance.listeners) {\n instance.addEventListener(k, function(eventName, args){\n self.args[0] = eventName;\n self.args[1] = args;\n postMessage(self.args);\n }.bind(this, k));\n }\n }",r+="\n\n onmessage = function(evt){\n var f = evt.data[0],\n t = instance[f];\n if(t){\n t.call(instance, evt.data[1]);\n }\n };\n\n})();",i.worker=t.createWorker(r,!1),i.args=[null,null],i.worker.onmessage=function(e){return i.emit(e.data[0],e.data[1])};for(n in e.prototype)"addEventListener"!==n&&"_"!==n[0]&&(i[n]=i.methodShim.bind(i,n));return i.ready=!0,i}return kt(t,e),wt(t,null,[{key:"createWorker",value:function(e,t){if("function"==typeof e&&(e=e.toString()),t){e=e.trim();var n=e.indexOf("{");e=e.substring(n+1,e.length-1)}var i=new Blob([e],{type:"text/javascript"}),r=URL.createObjectURL(i);return new Worker(r)}}]),wt(t,[{key:"methodShim",value:function(e,t){this.args[0]=e,this.args[1]=t,this.worker.postMessage(this.args)}}]),t}(e.EventDispatcher),$t={AsyncLockRequest:Gt,cache:i,deleteSetting:Y,findProperty:K,FullScreen:Kt,getSetting:q,identity:U,immutable:X,isTimestampDeltaValid:Z,mutable:J,Orientation:Xt,PointerLock:Zt,setSetting:te,standardExitFullScreenBehavior:ie,standardFullScreenBehavior:oe,standardLockBehavior:re,standardUnlockBehavior:ne,Workerize:Jt},en=Object.freeze({AsyncLockRequest:Gt,cache:i,deleteSetting:Y,findProperty:K,FullScreen:Kt,getSetting:q,identity:U,immutable:X,isTimestampDeltaValid:Z,mutable:J,Orientation:Xt,PointerLock:Zt,setSetting:te,standardExitFullScreenBehavior:ie,standardFullScreenBehavior:oe,standardLockBehavior:re,standardUnlockBehavior:ne,Workerize:Jt,default:$t});e.BufferGeometry.prototype.center=e.Geometry.prototype.center=function(){this.computeBoundingBox();var e=this.boundingBox,t=(e.max.x+e.min.x)/2,n=(e.max.y+e.min.y)/2,i=(e.max.z+e.min.z)/2;return this.offset(-t,-n,-i)},e.BufferGeometry.prototype.colored=e.Geometry.prototype.colored=e.Mesh.prototype.colored=function(e,t){return a(this,e,t)},e.CubeTextureLoader.prototype.load=function(t,n,i,r){var o=new e.CubeTexture,s=new e.ImageLoader(this.manager);s.setCrossOrigin(this.crossOrigin),s.setPath(this.path);for(var a=0,u=0;u<t.length;++u)s.load(t[u],function(e){o.images[u]=e,6===++a&&(o.needsUpdate=!0,n&&n(o))}.bind(null,u),i,r);return o},e.Object3D.prototype.emit=e.EventDispatcher.prototype.emit=function(e,t){t||(t={}),"object"!==(void 0===t?"undefined":yt(t))||t instanceof Event||(t.type=e,void 0===t.defaultPrevented&&(t.defaultPrevented=!1,t.preventDefault=function(){return t.defaultPrevented=!0})),this.dispatchEvent(t)},e.Object3D.prototype.dispatchEvent=e.EventDispatcher.prototype.dispatchEvent=function(e){if(void 0!==this._listeners){var t=this._listeners,n=t[e.type];if(void 0!==n){e instanceof Event||(e.target=this);var i=[],r=0,o=n.length;for(r=0;r<o;r++)i[r]=n[r];for(r=0;r<o;r++)i[r].call(this,e)}}},e.Object3D.prototype.watch=e.EventDispatcher.prototype.watch=function(e,t){var n=this;return t instanceof Array||(t=[t]),t.forEach(function(t){return e.addEventListener(t,n.dispatchEvent.bind(n))}),this},e.Object3D.prototype.route=e.EventDispatcher.prototype.route=function(e,t){var n=this;return e.forEach(function(e){return n.addEventListener(e,t)}),this},e.Object3D.prototype.on=e.EventDispatcher.prototype.on=function(e,t){return this.addEventListener(e,t),this},e.Matrix4.prototype.toString=function(e){void 0===e&&(e=10),this.transpose();var t=this.toArray();if(this.transpose(),void 0!==e)for(var n=0;n<t.length;++n);for(var i="",r=0;r<t.length;++r)r%4==0&&(i+="| "),-1===Math.sign(t[r])?i+="-":i+=" ",null!==t[r]&&void 0!==t[r]?i+=Math.abs(t[r]).toFixed(e):i+="undefined".substring(0,e),i+=r%4==3?" |\n":", ";return i};var tn=function(t){function n(t){_t(this,n);var i=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this));return i.manager=void 0!==t?t:e.DefaultLoadingManager,i}return kt(n,t),wt(n,[{key:"load",value:function(t,n,i,r){var o=this,s=new e.FileLoader(this.manager);s.setPath(this.path),s.load(t,function(e){n(o.parse(e))},i,r)}},{key:"setPath",value:function(e){this.path=e}},{key:"setTexturePath",value:function(e){this.texturePath=e}},{key:"setBaseUrl",value:function(e){console.warn("MTLLoader: .setBaseUrl() is deprecated. Use .setTexturePath( path ) for texture path or .setPath( path ) for general base path instead."),this.setTexturePath(e)}},{key:"setCrossOrigin",value:function(e){this.crossOrigin=e}},{key:"setMaterialOptions",value:function(e){this.materialOptions=e}},{key:"parse",value:function(e){for(var t=e.split("\n"),n={},i={},r=0;r<t.length;r++){var o=t[r];if(o=o.trim(),0!==o.length&&"#"!==o.charAt(0)){var s=o.indexOf(" "),a=s>=0?o.substring(0,s):o;a=a.toLowerCase();var u=s>=0?o.substring(s+1):"";if(u=u.trim(),"newmtl"===a)n={name:u},i[u]=n;else if(n)if("ka"===a||"kd"===a||"ks"===a){var h=u.split(/\s+/,3);n[a]=[parseFloat(h[0]),parseFloat(h[1]),parseFloat(h[2])]}else n[a]=u}}var c=new nn(this.texturePath||this.path,this.materialOptions);return c.setCrossOrigin(this.crossOrigin),c.setManager(this.manager),c.setMaterials(i),c}}]),n}(e.EventDispatcher),nn=function(){function t(n,i){_t(this,t),this.baseUrl=n||"",this.options=i,this.materialsInfo={},this.materials={},this.materialsArray=[],this.nameLookup={},this.side=this.options&&this.options.side?this.options.side:e.FrontSide,this.wrap=this.options&&this.options.wrap?this.options.wrap:e.RepeatWrapping}return wt(t,[{key:"setCrossOrigin",value:function(e){this.crossOrigin=e}},{key:"setManager",value:function(e){this.manager=e}},{key:"setMaterials",value:function(e){this.materialsInfo=this.convert(e),this.materials={},this.materialsArray=[],this.nameLookup={}}},{key:"convert",value:function(e){if(!this.options)return e;var t={};for(var n in e){var i=e[n],r={};t[n]=r;for(var o in i){var s=!0,a=i[o],u=o.toLowerCase();switch(u){case"kd":case"ka":case"ks":this.options&&this.options.normalizeRGB&&(a=[a[0]/255,a[1]/255,a[2]/255]),this.options&&this.options.ignoreZeroRGBs&&0===a[0]&&0===a[1]&&0===a[2]&&(s=!1)}s&&(r[u]=a)}}return t}},{key:"preload",value:function(){for(var e in this.materialsInfo)this.create(e)}},{key:"getIndex",value:function(e){return this.nameLookup[e]}},{key:"getAsArray",value:function(){var e=0;for(var t in this.materialsInfo)this.materialsArray[e]=this.create(t),this.nameLookup[t]=e,e++;return this.materialsArray}},{key:"create",value:function(e){return void 0===this.materials[e]&&this.createMaterial_(e),this.materials[e]}},{key:"createMaterial_",value:function(t){function n(e,t){if(!s[e]){var n=r.getTextureParams(t,s),i=r.loadTexture(a(r.baseUrl,n.url));i.repeat.copy(n.scale),i.offset.copy(n.offset),i.wrapS=r.wrap,i.wrapT=r.wrap,s[e]=i}}var i=e.MeshPhongMaterial,r=this,o=this.materialsInfo[t],s={name:t,side:this.side},a=function(e,t){return"string"!=typeof t||""===t?"":/^https?:\/\//i.test(t)?t:e+t};for(var u in o){var h=o[u];if(""!==h)switch(u.toLowerCase()){case"kd":s.color=(new e.Color).fromArray(h);break;case"ks":s.specular=(new e.Color).fromArray(h);break;case"map_kd":n("map",h);break;case"map_ks":n("specularMap",h);break;case"map_bump":case"bump":n("bumpMap",h);break;case"ns":s.shininess=parseFloat(h);break;case"d":h<1&&(s.opacity=h,s.transparent=!0);break;case"illum":h=parseFloat(h),h===tn.COLOR_ON_AND_AMBIENT_OFF&&(i=e.MeshBasicMaterial);break;case"Tr":h>0&&(s.opacity=1-h,s.transparent=!0)}}return i===e.MeshBasicMaterial&&["shininess","specular"].forEach(function(e){e in s&&delete s[e]}),this.materials[t]=new i(s),this.materials[t]}},{key:"getTextureParams",value:function(t,n){var i,r={scale:new e.Vector2(1,1),offset:new e.Vector2(0,0)},o=t.split(/\s+/);return i=o.indexOf("-bm"),i>=0&&(n.bumpScale=parseFloat(o[i+1]),o.splice(i,2)),i=o.indexOf("-s"),i>=0&&(r.scale.set(parseFloat(o[i+1]),parseFloat(o[i+2])),o.splice(i,4)),i=o.indexOf("-o"),i>=0&&(r.offset.set(parseFloat(o[i+1]),parseFloat(o[i+2])),o.splice(i,4)),r.url=o.join(" ").trim(),r}},{key:"loadTexture",value:function(t,n,i,r,o){var s,a=e.Loader.Handlers.get(t),u=void 0!==this.manager?this.manager:e.DefaultLoadingManager;return null===a&&(a=new e.TextureLoader(u)),a.setCrossOrigin&&a.setCrossOrigin(this.crossOrigin),s=a.load(t,i,r,o),void 0!==n&&(s.mapping=n),s}}]),t}();Object.assign(tn,{COLOR_ON_AND_AMBIENT_OFF:0,COLOR_ON_AND_AMBIENT_ON:1,HIGHLIGHT_ON:2,REFLECTION_ON_AND_RAY_TRACE_ON:3,TRANSPARENCY_GLASS_ON_REFLECTION_RAY_TRACE_ON:4,REFLECTION_FRESNEL_ON_AND_RAY_TRACE_ON:5,TRANSPARENCY_REFRACTION_ON_REFLECTION_FRESNEL_OFF_AND_RAY_TRACE_ON:6,TRANSPARENCY_REFRACTION_ON_REFLECTION_FRESNEL_ON_AND_RAY_TRACE_ON:7,REFLECTION_ON_AND_RAY_TRACE_OFF:8,TRANSPARENCY_GLASS_ON_REFLECTION_RAY_TRACE_OFF:9,CASTS_SHADOWS_ONTO_INVISIBLE_SURFACES:10}),e.Object3D.prototype.appendChild=function(e){return this.add(e)},Object.defineProperty(e.Object3D.prototype,"pickable",{get:function(){return this._listeners&&(this._listeners.enter&&this._listeners.enter.length>0||this._listeners.exit&&this._listeners.exit.length>0||this._listeners.select&&this._listeners.select.length>0||this._listeners.useraction&&this._listeners.useraction.length>0||this._listeners.pointerstart&&this._listeners.pointerstart.length>0||this._listeners.pointerend&&this._listeners.pointerend.length>0||this._listeners.pointermove&&this._listeners.pointermove.length>0||this._listeners.gazestart&&this._listeners.gazestart.length>0||this._listeners.gazecancel&&this._listeners.gazecancel.length>0||this._listeners.gazemove&&this._listeners.gazemove.length>0||this._listeners.gazecomplete&&this._listeners.gazecomplete.length>0)}}),e.Object3D.prototype.latLng=function(e,t,n){return e=-Math.PI*(e||0)/180,t=Math.PI*(t||0)/180,n=n||1.5,this.rotation.set(e,t,0,"XYZ"),this.position.set(0,0,-n),this.position.applyQuaternion(this.quaternion),this},e.Object3D.prototype.named=function(e){return this.name=e,this},e.Object3D.prototype.addTo=function(e){return e.add(this),this},e.Object3D.prototype.at=function(e,t,n){return this.position.set(e,t,n),this},e.Object3D.prototype.rot=function(e,t,n){return this.rotation.set(e,t,n),this},e.Object3D.prototype.scl=function(e,t,n){return this.scale.set(e,t,n),this},Object.defineProperty(e.Object3D.prototype,"visible",{get:function(){return this._visible},set:function(e){var t=this._visible;this._visible=e,t!==e&&this.emit("visiblechanged")}});var rn=function(){function t(n){_t(this,t),this.manager=void 0!==n?n:e.DefaultLoadingManager,this.materials=null,this.regexp={vertex_pattern:/^v\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,normal_pattern:/^vn\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,uv_pattern:/^vt\s+([\d|\.|\+|\-|e|E]+)\s+([\d|\.|\+|\-|e|E]+)/,face_vertex:/^f\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)(?:\s+(-?\d+))?/,face_vertex_uv:/^f\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+))?/,face_vertex_uv_normal:/^f\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)\s+(-?\d+)\/(-?\d+)\/(-?\d+)(?:\s+(-?\d+)\/(-?\d+)\/(-?\d+))?/,face_vertex_normal:/^f\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)\s+(-?\d+)\/\/(-?\d+)(?:\s+(-?\d+)\/\/(-?\d+))?/,object_pattern:/^[og]\s*(.+)?/,smoothing_pattern:/^s\s+(\d+|on|off)/,material_library_pattern:/^mtllib /,material_use_pattern:/^usemtl /}}return wt(t,[{key:"load",value:function(t,n,i,r){var o=this,s=new e.FileLoader(o.manager);s.setPath(this.path),s.load(t,function(e){n(o.parse(e))},i,r)}},{key:"setPath",value:function(e){this.path=e}},{key:"setMaterials",value:function(e){this.materials=e}},{key:"_createParserState",value:function(){var e=new on;return e.startObject("",!1),e}},{key:"parse",value:function(t){console.time("OBJLoader");var n=this._createParserState();-1!==t.indexOf("\r\n")&&(t=t.replace("\r\n","\n"));for(var i=t.split("\n"),r="",o="",s="",a=[],u="function"==typeof"".trimLeft,h=0,c=i.length;h<c;h++)if(r=i[h],r=u?r.trimLeft():r.trim(),0!==r.length&&"#"!==(o=r.charAt(0)))if("v"===o)if(" "===(s=r.charAt(1))&&null!==(a=this.regexp.vertex_pattern.exec(r)))n.vertices.push(parseFloat(a[1]),parseFloat(a[2]),parseFloat(a[3]));else if("n"===s&&null!==(a=this.regexp.normal_pattern.exec(r)))n.normals.push(parseFloat(a[1]),parseFloat(a[2]),parseFloat(a[3]));else{if("t"!==s||null===(a=this.regexp.uv_pattern.exec(r)))throw new Error("Unexpected vertex/normal/uv line: '"+r+"'");n.uvs.push(parseFloat(a[1]),parseFloat(a[2]))}else if("f"===o)if(null!==(a=this.regexp.face_vertex_uv_normal.exec(r)))n.addFace(a[1],a[4],a[7],a[10],a[2],a[5],a[8],a[11],a[3],a[6],a[9],a[12]);else if(null!==(a=this.regexp.face_vertex_uv.exec(r)))n.addFace(a[1],a[3],a[5],a[7],a[2],a[4],a[6],a[8]);else if(null!==(a=this.regexp.face_vertex_normal.exec(r)))n.addFace(a[1],a[3],a[5],a[7],void 0,void 0,void 0,void 0,a[2],a[4],a[6],a[8]);else{if(null===(a=this.regexp.face_vertex.exec(r)))throw new Error("Unexpected face line: '"+r+"'");n.addFace(a[1],a[2],a[3],a[4])}else if("l"===o){var l=r.substring(1).trim().split(" "),d=[],f=[];if(-1===r.indexOf("/"))d=l;else for(var p=0,m=l.length;p<m;p++){var v=l[p].split("/");""!==v[0]&&d.push(v[0]),""!==v[1]&&f.push(v[1])}n.addLineGeometry(d,f)}else if(null!==(a=this.regexp.object_pattern.exec(r))){var g=a[0].substr(1).trim();n.startObject(g)}else if(this.regexp.material_use_pattern.test(r))n.object.startMaterial(r.substring(7).trim(),n.materialLibraries);else if(this.regexp.material_library_pattern.test(r))n.materialLibraries.push(r.substring(7).trim());else{if(null===(a=this.regexp.smoothing_pattern.exec(r))){if("\0"===r)continue;throw new Error("Unexpected line: '"+r+"'")}var y=a[1].trim().toLowerCase();n.object.smooth="1"===y||"on"===y;var _=n.object.currentMaterial();_&&(_.smooth=n.object.smooth)}n.finalize();var w=new e.Group;w.materialLibraries=[].concat(n.materialLibraries);for(var h=0,c=n.objects.length;h<c;h++){var b=n.objects[h],k=b.geometry,x=b.materials,S="Line"===k.type;if(0!==k.vertices.length){var E=new e.BufferGeometry;E.addAttribute("position",new e.BufferAttribute(new Float32Array(k.vertices),3)),k.normals.length>0?E.addAttribute("normal",new e.BufferAttribute(new Float32Array(k.normals),3)):E.computeVertexNormals(),k.uvs.length>0&&E.addAttribute("uv",new e.BufferAttribute(new Float32Array(k.uvs),2));for(var M=[],T=0,O=x.length;T<O;T++){var P=x[T],_=void 0;if(null!==this.materials&&(_=this.materials.create(P.name),S&&_&&!_.isLineBasicMaterial)){var C=new e.LineBasicMaterial;C.copy(_),_=C}_||(_=S?new e.LineBasicMaterial:new e.MeshPhongMaterial,_.name=P.name),_.shading=P.smooth?e.SmoothShading:e.FlatShading,M.push(_)}var A;if(M.length>1){for(var T=0,O=x.length;T<O;T++){var P=x[T];E.addGroup(P.groupStart,P.groupCount,T)}var R=new e.MultiMaterial(M);A=S?new e.LineSegments(E,R):new e.Mesh(E,R)}else A=S?new e.LineSegments(E,M[0]):new e.Mesh(E,M[0]);A.name=b.name,w.add(A)}}return console.timeEnd("OBJLoader"),w}}]),t}(),on=function(){function e(){_t(this,e),this.objects=[],this.object={},this.vertices=[],this.normals=[],this.uvs=[],this.materialLibraries=[]}return wt(e,[{key:"startObject",value:function(e,t){if(this.object&&!1===this.object.fromDeclaration)return this.object.name=e,void(this.object.fromDeclaration=!1!==t);this.object&&"function"==typeof this.object._finalize&&this.object._finalize();var n=this.object&&"function"==typeof this.object.currentMaterial?this.object.currentMaterial():void 0;if(this.object=new sn(e,t),n&&n.name&&"function"==typeof n.clone){var i=n.clone(0);i.inherited=!0,this.object.materials.push(i)}this.objects.push(this.object)}},{key:"finalize",value:function(){this.object&&"function"==typeof this.object._finalize&&this.object._finalize()}},{key:"parseVertexIndex",value:function(e,t){var n=parseInt(e,10);return 3*(n>=0?n-1:n+t/3)}},{key:"parseNormalIndex",value:function(e,t){var n=parseInt(e,10);return 3*(n>=0?n-1:n+t/3)}},{key:"parseUVIndex",value:function(e,t){var n=parseInt(e,10);return 2*(n>=0?n-1:n+t/2)}},{key:"addVertex",value:function(e,t,n){var i=this.vertices,r=this.object.geometry.vertices;r.push(i[e+0]),r.push(i[e+1]),r.push(i[e+2]),r.push(i[t+0]),r.push(i[t+1]),r.push(i[t+2]),r.push(i[n+0]),r.push(i[n+1]),r.push(i[n+2])}},{key:"addVertexLine",value:function(e){var t=this.vertices,n=this.object.geometry.vertices;n.push(t[e+0]),n.push(t[e+1]),n.push(t[e+2])}},{key:"addNormal",value:function(e,t,n){var i=this.normals,r=this.object.geometry.normals;r.push(i[e+0]),r.push(i[e+1]),r.push(i[e+2]),r.push(i[t+0]),r.push(i[t+1]),r.push(i[t+2]),r.push(i[n+0]),r.push(i[n+1]),r.push(i[n+2])}},{key:"addUV",value:function(e,t,n){var i=this.uvs,r=this.object.geometry.uvs;r.push(i[e+0]),r.push(i[e+1]),r.push(i[t+0]),r.push(i[t+1]),r.push(i[n+0]),r.push(i[n+1])}},{key:"addUVLine",value:function(e){var t=this.uvs,n=this.object.geometry.uvs;n.push(t[e+0]),n.push(t[e+1])}},{key:"addFace",value:function(e,t,n,i,r,o,s,a,u,h,c,l){var d,f=this.vertices.length,p=this.parseVertexIndex(e,f),m=this.parseVertexIndex(t,f),v=this.parseVertexIndex(n,f);if(void 0===i?this.addVertex(p,m,v):(d=this.parseVertexIndex(i,f),this.addVertex(p,m,d),this.addVertex(m,v,d)),void 0!==r){var g=this.uvs.length;p=this.parseUVIndex(r,g),m=this.parseUVIndex(o,g),v=this.parseUVIndex(s,g),void 0===i?this.addUV(p,m,v):(d=this.parseUVIndex(a,g),this.addUV(p,m,d),this.addUV(m,v,d))}if(void 0!==u){var y=this.normals.length;p=this.parseNormalIndex(u,y),m=u===h?p:this.parseNormalIndex(h,y),v=u===c?p:this.parseNormalIndex(c,y),void 0===i?this.addNormal(p,m,v):(d=this.parseNormalIndex(l,y),this.addNormal(p,m,d),this.addNormal(m,v,d))}}},{key:"addLineGeometry",value:function(e,t){this.object.geometry.type="Line";for(var n=this.vertices.length,i=this.uvs.length,r=0,o=e.length;r<o;r++)this.addVertexLine(this.parseVertexIndex(e[r],n));for(var s=0,o=t.length;s<o;s++)this.addUVLine(this.parseUVIndex(t[s],i))}}]),e}(),sn=function(){function e(t,n){_t(this,e),this.name=t||"",this.fromDeclaration=!1!==n,this.geometry={vertices:[],normals:[],uvs:[]},this.materials=[],this.smooth=!0}return wt(e,[{key:"startMaterial",value:function(e,t){var n=this._finalize(!1);n&&(n.inherited||n.groupCount<=0)&&this.materials.splice(n.index,1);var i={index:this.materials.length,name:e||"",mtllib:Array.isArray(t)&&t.length>0?t[t.length-1]:"",smooth:void 0!==n?n.smooth:this.smooth,groupStart:void 0!==n?n.groupEnd:0,groupEnd:-1,groupCount:-1,inherited:!1,clone:function(e){return{index:"number"==typeof e?e:this.index,name:this.name,mtllib:this.mtllib,smooth:this.smooth,groupStart:this.groupEnd,groupEnd:-1,groupCount:-1,inherited:!1}}};return this.materials.push(i),i}},{key:"currentMaterial",value:function(){if(this.materials.length>0)return this.materials[this.materials.length-1]}},{key:"_finalize",value:function(e){var t=this.currentMaterial();return t&&-1===t.groupEnd&&(t.groupEnd=this.geometry.vertices.length/3,t.groupCount=t.groupEnd-t.groupStart,t.inherited=!1),!1!==e&&0===this.materials.length&&this.materials.push({name:"",smooth:this.smooth}),t}}]),e}();e.Geometry.prototype.offset=function(e,t,n){for(var i=this.vertices,r=0;r<i.length;++r){var o=i[r];o.x+=e,o.y+=t,o.z+=n}return this},e.BufferGeometry.prototype.offset=function(e,t,n){for(var i=this.attributes.position.array,r=this.attributes.position.itemSize,o=0;o<i.length;o+=r)i[o]+=e,i[o+1]+=t,i[o+2]+=n;return this},e.BufferGeometry.prototype.textured=e.Geometry.prototype.textured=e.Mesh.prototype.textured=function(e,t){return s(this,e,t)},e.Euler.prototype.toString=e.Quaternion.prototype.toString=e.Vector2.prototype.toString=e.Vector3.prototype.toString=e.Vector4.prototype.toString=function(e){var t=this.toArray();if(void 0!==e)for(var n=0;n<t.length;++n)null!==t[n]&&void 0!==t[n]?t[n]=t[n].toFixed(e):t[n]="undefined";return"<"+t.join(", ")+">"};var an={};e.Euler.prototype.debug=e.Quaternion.prototype.debug=e.Vector2.prototype.debug=e.Vector3.prototype.debug=e.Vector4.prototype.debug=e.Matrix3.prototype.debug=e.Matrix4.prototype.debug=function(e,t){var n=this.toString(t);return n!==an[e]&&(an[e]=n,console.trace(e+"\n"+n)),this};var un="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},hn=(function(e,t){t={exports:{}},e(t,t.exports),t.exports}(function(e){!function(t){function n(){}function i(e,t){return function(){e.apply(t,arguments)}}function r(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],c(e,this)}function o(e,t){for(;3===e._state;)e=e._value;if(0===e._state)return void e._deferreds.push(t);e._handled=!0,d(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null===n)return void(1===e._state?s:a)(t.promise,e._value);var i;try{i=n(e._value)}catch(e){return void a(t.promise,e)}s(t.promise,i)})}function s(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof r)return e._state=3,e._value=t,void u(e);if("function"==typeof n)return void c(i(n,t),e)}e._state=1,e._value=t,u(e)}catch(t){a(e,t)}}function a(e,t){e._state=2,e._value=t,u(e)}function u(e){2===e._state&&0===e._deferreds.length&&d(function(){e._handled||f(e._value)});for(var t=0,n=e._deferreds.length;t<n;t++)o(e,e._deferreds[t]);e._deferreds=null}function h(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function c(e,t){var n=!1;try{e(function(e){n||(n=!0,s(t,e))},function(e){n||(n=!0,a(t,e))})}catch(e){if(n)return;n=!0,a(t,e)}}var l=setTimeout,d="function"==typeof setImmediate&&setImmediate||function(e){l(e,0)},f=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};r.prototype.catch=function(e){return this.then(null,e)},r.prototype.then=function(e,t){var i=new this.constructor(n);return o(this,new h(e,t,i)),i},r.all=function(e){var t=Array.prototype.slice.call(e);return new r(function(e,n){function i(o,s){try{if(s&&("object"==typeof s||"function"==typeof s)){var a=s.then;if("function"==typeof a)return void a.call(s,function(e){i(o,e)},n)}t[o]=s,0==--r&&e(t)}catch(e){n(e)}}if(0===t.length)return e([])
;for(var r=t.length,o=0;o<t.length;o++)i(o,t[o])})},r.resolve=function(e){return e&&"object"==typeof e&&e.constructor===r?e:new r(function(t){t(e)})},r.reject=function(e){return new r(function(t,n){n(e)})},r.race=function(e){return new r(function(t,n){for(var i=0,r=e.length;i<r;i++)e[i].then(t,n)})},r._setImmediateFn=function(e){d=e},r._setUnhandledRejectionFn=function(e){f=e},e.exports?e.exports=r:t.Promise||(t.Promise=r)}(un)}),e.Math.DEG2RAD),cn=e.Math.RAD2DEG,ln=function(){function e(t){if(_t(this,e),"number"!=typeof t)throw new Error("Angle must be initialized with a number. Initial value was: "+t);this._value=t,this._delta=0,this._d1=null,this._d2=null,this._d3=null}return wt(e,[{key:"degrees",get:function(){return this._value},set:function(e){do{this._d1=e+this._delta-this._value,this._d2=Math.abs(this._d1+360),this._d3=Math.abs(this._d1-360),this._d1=Math.abs(this._d1),this._d2<this._d1&&this._d2<this._d3?this._delta+=360:this._d3<this._d1&&(this._delta-=360)}while(this._d1>this._d2||this._d1>this._d3);this._value=e+this._delta}},{key:"radians",get:function(){return this.degrees*hn},set:function(e){this.degrees=e*cn}}]),e}();window.AudioContext=window.AudioContext||window.webkitAudioContext;var dn=new e.Vector3,fn=new e.Vector3,pn=new e.Matrix4,mn=function(){function e(){var t=this;_t(this,e),this.ready=new Promise(function(n,i){try{if(e.isAvailable){var r=function(){try{t.sampleRate=t.context.sampleRate,t.mainVolume=t.context.createGain(),t.start(),n()}catch(e){i(e)}};if(ht){var o=function e(){try{t.context=t.context||new AudioContext;var n=t.context.createBufferSource();n.buffer=t.createRawSound([[0]]),n.connect(t.context.destination),n.start(),setTimeout(function(){n.playbackState!==n.PLAYING_STATE&&n.playbackState!==n.FINISHED_STATE||(window.removeEventListener("mouseup",e),window.removeEventListener("touchend",e),window.removeEventListener("keyup",e),r())},0)}catch(e){i(e)}};window.addEventListener("mouseup",o,!1),window.addEventListener("touchend",o,!1),window.addEventListener("keyup",o,!1)}else t.context=new AudioContext,r()}}catch(e){i(e)}})}return wt(e,null,[{key:"setAudioStream",value:function(e,t){var n=document.querySelectorAll("audio").length,i=he(t||"audioStream"+n,"audio",HTMLAudioElement,!0);return setAudioProperties(i),i.srcObject=e,i}},{key:"setAudioProperties",value:function(e){e.autoplay=!0,e.controls=!1,e.crossOrigin="anonymous",e.muted=!0,e.setAttribute("muted","")}}]),wt(e,[{key:"setVelocity",value:function(e,t,n){this.context&&this.context.listener.setVelocity(e,t,n)}},{key:"setPlayer",value:function(e){if(this.context&&this.context.listener){e.updateMatrixWorld(),pn.copy(e.matrixWorld);var t=pn.elements[12],n=pn.elements[13],i=pn.elements[14];this.context.listener.setPosition(t,n,i),dn.set(0,0,-1).applyMatrix4(pn).normalize(),fn.set(0,1,0).applyMatrix4(pn).normalize(),this.context.listener.setOrientation(dn.x,dn.y,dn.z,fn.x,fn.y,fn.z)}}},{key:"start",value:function(){this.mainVolume&&this.mainVolume.connect(this.context.destination),this.context.resume&&this.context.resume()}},{key:"stop",value:function(){this.context.suspend&&this.context.suspend(),this.mainVolume&&this.mainVolume.disconnect()}},{key:"loadURL",value:function(e){var t=this;return this.ready.then(function(){console.log("Loading "+e+" from URL"),ue(e)}).then(function(e){return new Promise(function(n,i){return t.context.decodeAudioData(e,n,i)})}).then(function(t){return console.log(e+" loaded"),t}).catch(function(t){console.error("Couldn't load "+e+". Reason: "+t)})}},{key:"createRawSound",value:function(e){if(1!==e.length&&2!==e.length)throw new Error("Incorrect number of channels. Expected 1 or 2, got "+e.length);var t=e[0].length;if(e.length>1&&e[1].length!==t)throw new Error("Second channel is not the same length as the first channel. Expected "+t+", but was "+e[1].length);for(var n=this.context.createBuffer(e.length,t,this.sampleRate||22050),i=0;i<e.length;++i)for(var r=n.getChannelData(i),o=0;o<t;++o)r[o]=e[i][o];return n}},{key:"create3DSound",value:function(e,t,n,i){return i.panner=this.context.createPanner(),i.panner.setPosition(e,t,n),i.panner.connect(this.mainVolume),i.volume.connect(i.panner),i}},{key:"createFixedSound",value:function(e){return e.volume.connect(this.mainVolume),e}},{key:"loadSource",value:function(e,t){var n=this;return this.ready.then(function(){return new Promise(function(i,r){console.log("Loading "+e),e instanceof Array||(e=[e]);var o=document.createElement("audio");o.autoplay=!0,o.preload="auto",o["webkit-playsinline"]=!0,o.playsinline=!0,o.loop=t,o.crossOrigin="anonymous",e.map(function(e){var t=document.createElement("source");return t.src=e,t}).forEach(o.appendChild.bind(o)),o.onerror=r,o.oncanplay=function(){o.oncanplay=null;var e={volume:n.context.createGain(),source:n.context.createMediaElementSource(o)};e.source.connect(e.volume),i(e)},o.play(),document.body.appendChild(o)})}).then(function(t){return console.log(e+" loaded"),t}).catch(function(t){console.error("Couldn't load "+e+". Reason: "+t)})}},{key:"load3DSound",value:function(e,t,n,i,r){return this.loadSource(e,t).then(this.create3DSound.bind(this,n,i,r))}},{key:"loadFixedSound",value:function(e,t){return this.loadSource(e,t).then(this.createFixedSound.bind(this))}}]),e}();mn.isAvailable=!!window.AudioContext&&!!AudioContext.prototype.createGain;var vn=function(){function e(t,n){_t(this,e),this.gn=t.createGain(),this.pnr=t.createPanner(),this.gn.connect(this.pnr),this.pnr.connect(n),this.gn.gain.value=0,this.ctx=t}return wt(e,[{key:"at",value:function(e,t,n,i,r,o){return e=e||0,t=t||0,n=n||0,void 0!==i&&null!==i||(i=0),r=r||0,o=o||0,this.pnr.setPosition(e,t,n),this.pnr.setOrientation(i,r,o),this}}]),e}(),gn=Math.pow(2,1/12),yn=function(e){function t(e,n,i){_t(this,t);var r=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.osc=e.createOscillator(),r.osc.type=i,r.osc.frequency.value=0,r.osc.connect(r.gn),r.osc.start(),r}return kt(t,e),wt(t,null,[{key:"piano",value:function(e){return 440*Math.pow(gn,e-49)}}]),wt(t,[{key:"on",value:function(e,n,i,r){void 0===i&&(i=0);var o=t.piano(parseFloat(e)+1),s=this.ctx.currentTime+i;return this.gn.gain.setValueAtTime(n,s),r?this.osc.frequency.exponentialRampToValueAtTime(o,s):this.osc.frequency.setValueAtTime(o,s),this}},{key:"off",value:function(e){void 0===e&&(e=0);var t=this.ctx.currentTime+e;return this.gn.gain.setValueAtTime(0,t),this.osc.frequency.setValueAtTime(0,t),this}},{key:"ready",get:function(){return 0===this.gn.gain.value}}]),t}(vn),_n=(navigator.maxTouchPoints||10)+1,wn=["sine","square","sawtooth","triangle"],bn=function(){function e(t,n){var i=this;_t(this,e),void 0===n&&(n=_n),this.oscillators={},this.isAvailable=!1,this.audio=t,this.audio.ready.then(function(){var e=i.audio.context;i.mainVolume=e.createGain(),i.mainVolume.connect(i.audio.mainVolume),i.mainVolume.gain.value=1,i.numNotes=n,wn.forEach(function(t){var n=i.oscillators[t]=[];i[t]=i.play.bind(i,t);for(var r=0;r<i.numNotes;++r)n.push(new yn(e,i.mainVolume,t))}),i.isAvailable=!0})}return wt(e,[{key:"getOsc",value:function(e){var t=this.oscillators[e],n=void 0;for(n=0;n<t.length&&!t[n].ready;++n);return t[n%this.numNotes]}},{key:"play",value:function(e,t,n,i,r){void 0===r&&(r=0);var o=this.getOsc(e).on(t,n,r);return r+=i,o.off(r),r=this.audio.context.currentTime+r-performance.now()/1e3,o}},{key:"type",get:function(){return this._type},set:function(e){var t=this;this.isAvailable&&(this._type=e,this.oscillators.forEach(function(e){return e.osc.type=t._type}))}}]),e}();bn.TYPES=wn;var kn=function(e){function t(e,n,i){_t(this,t);var r=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e.context,e.mainVolume));return r.audio=document.createElement("audio"),r.audio.autoplay=!0,r.audio.preload="auto",r.audio["webkit-playsinline"]=!0,r.audio.playsinline=!0,r.audio.loop=i,r.audio.crossOrigin="anonymous",console.log("Loading "+n),n instanceof Array||(n=[n]),n.map(function(e){var t=document.createElement("source");return t.src=e,t}).forEach(r.audio.appendChild.bind(r.audio)),r.ready=new Promise(function(e,t){r.audio.onerror=t,r.audio.oncanplay=function(){r.audio.oncanplay=null,r.node=r.ctx.createMediaElementSource(r.audio),r.node.connect(r.gn),r.gn.gain.setValueAtTime(0,r.ctx.currentTime),e(r)},r.audio.play()}),document.body.appendChild(r.audio),r}return kt(t,e),wt(t,[{key:"play",value:function(){return this.gn.gain.setValueAtTime(1,this.ctx.currentTime),this.audio.play(),this}}]),t}(vn),xn={remoteVoices:!0,volume:1,rate:1,pitch:1,voice:0},Sn=function(){function e(t){var n=this;if(_t(this,e),this.options=Object.assign({},xn,t),e.isAvailable){var i=function(){n.voices=speechSynthesis.getVoices().filter(function(e){return n.options.remoteVoices||e.default||e.localService}),n.voiceNames=n.voices.map(function(e){return e.name})};i(),speechSynthesis.onvoiceschanged=i}}return wt(e,[{key:"speak",value:function(t,n){var i=this;return e.isAvailable?new Promise(function(e,r){var o=new SpeechSynthesisUtterance;o.voice=i.voices[n&&n.voice||i.options.voice],o.volume=n&&n.volume||i.options.volume,o.rate=n&&n.rate||i.options.rate,o.pitch=n&&n.pitch||i.options.pitch,o.text=t,o.onend=e,o.onerror=r,speechSynthesis.speak(o)}):Promise.reject()}},{key:"speaking",get:function(){return e.isAvailable&&speechSynthesis.speaking}}],[{key:"isAvailable",get:function(){return!!window.speechSynthesis}}]),e}(),En={Audio3D:mn,Music:bn,Note:yn,PositionalSound:vn,Sound:kn,Speech:Sn},Mn=new e.Vector3(0,0,-1),Tn=.01,On=3*Tn,Pn=-1.25,Cn=.015,An=.03,Rn=new e.Vector3,Dn=new e.Euler,Ln=new e.Quaternion,Nn=function(t){function n(t,i,r,o,s,a,h){_t(this,n);var c=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,h));return c.isPointer=!0,c.devices=s.filter(U),c.triggerDevices=a&&a.filter(U)||c.devices.slice(),c.gazeTimeout=1e3*(c.options.gazeLength||1.5),c.unproject=null,c.picker=new e.Raycaster,c.showPointer=!0,c.color=i,c.highlight=r,c.velocity=new e.Vector3,c.mesh=u(Tn/o,Tn/o,On*o).colored(c.color,{unshaded:!0}).named(t+"-pointer").addTo(c).at(0,0,-1.5),c.gazeInner=L(Cn/2,10).colored(12632256,{unshaded:!0}).addTo(c).at(0,0,Pn),c.gazeReference=B(.5*Cn,.75*Cn,10,36,0,2*Math.PI).colored(16777215,{unshaded:!0}).addTo(c.gazeInner),c.gazeOuter=B(Cn,An,10,36,0,2*Math.PI).colored(16777215,{unshaded:!0}).addTo(c.gazeInner),c.gazeOuter.visible=!1,c.useGaze=c.options.useGaze,c.lastHit=null,c}return kt(n,t),wt(n,[{key:"addDevice",value:function(e,t){e&&this.devices.push(e),t&&this.triggerDevices.push(t)}},{key:"setSize",value:function(e,t){for(var n=2*devicePixelRatio/e,i=2*devicePixelRatio/t,r=0;r<this.devices.length;++r){var o=this.devices[r];o.commands.U.scale=n,o.commands.V.scale=i}}},{key:"update",value:function(){if(this.position.set(0,0,0),this.unproject){Ln.set(0,1,0,0),Rn.set(0,0,0);for(var e=0;e<this.devices.length;++e){var t=this.devices[e];t.enabled&&t.inPhysicalUse&&!t.commands.U.disabled&&!t.commands.V.disabled&&(Rn.x+=t.getValue("U")-1,Rn.y+=t.getValue("V")-1)}Rn.applyMatrix4(this.unproject).applyQuaternion(Ln),this.lookAt(Rn)}else{this.quaternion.set(0,0,0,1),Dn.set(0,0,0,"YXZ");for(var n=0;n<this.devices.length;++n){var i=this.devices[n];i.enabled&&(i.quaternion&&this.quaternion.multiply(i.quaternion),i.position&&this.position.add(i.position))}Ln.setFromEuler(Dn),this.quaternion.multiply(Ln)}this.updateMatrixWorld()}},{key:"_check",value:function(e){var t=e&&e.object,n=this.lastHit,i=n&&n.object;if(t||i){var o=n&&e&&(e.point.x!==n.point.x||e.point.y!==n.point.y||e.point.z!==n.point.z),s=n&&n.time&&performance.now()-n.time,a=t&&t.id,u=i&&i.id,h=a!==u,c={pointer:this,buttons:0,hit:e},l={pointer:this,buttons:0,hit:n};e?(this.gazeInner.position.z=.02-e.distance,e.time=performance.now(),this.mesh.material=r("",{color:this.highlight,unshaded:!0})):this.gazeInner.position.z=Pn,this.mesh.position.z=this.gazeInner.position.z-.02,o&&n.point.copy(e.point);for(var d=0,f=0;f<this.triggerDevices.length;++f){var p=this.triggerDevices[f];p.enabled&&(c.buttons|=p.getValue("buttons"),d|=p.getValue("dButtons"))}l.buttons=c.buttons,h&&(i&&this.emit("exit",l),t&&this.emit("enter",c));var m=!1;if(d?c.buttons?(t&&this.emit("pointerstart",c),n&&(n.time=performance.now())):t&&(m=!!e,this.emit("pointerend",c)):o&&t&&this.emit("pointermove",c),this.useGaze)if(h)null!==s&&s<this.gazeTimeout&&(this.gazeOuter.visible=!1,i&&this.emit("gazecancel",l)),e&&(this.gazeOuter.visible=!0,t&&this.emit("gazestart",c));else if(null!==s)if(s>=this.gazeTimeout)this.gazeOuter.visible=!1,t&&(m=!!e,this.emit("gazecomplete",c)),n.time=null;else if(ce(t)){var v=Math.round(36*s/this.gazeTimeout),g=2*Math.PI*v/36;this.gazeOuter.geometry=B(Cn,An,36,v,0,g),o&&t&&this.emit("gazemove",c)}else this.gazeOuter.visible=!1;return m&&this.emit("select",c),!h&&e&&n&&(e.time=n.time),!0}return!1}},{key:"resolvePicking",value:function(e){if(this.mesh.visible=!1,this.gazeInner.visible=!1,this.mesh.material=r("",{color:this.color,unshaded:!0}),this.showPointer){Rn.set(0,0,0).applyMatrix4(this.matrixWorld),Mn.set(0,0,-1).applyMatrix4(this.matrixWorld).sub(Rn),this.picker.set(Rn,Mn),this.gazeInner.visible=this.useGaze,this.mesh.visible=!this.useGaze;for(var t=this.picker.intersectObject(e,!0),n=0;n<t.length;++n){for(var i=t[n],o=i.object,s=o;s&&(!s.isEntity||s.isPointer);)s=s.parent;if(s||(s=o),s&&!s.pickable&&(s=null),i.object=s,s&&this._check(i))return this.lastHit=i,i.object._listeners.useraction}this._check(),this.lastHit=null}}},{key:"pickable",get:function(){return!1}},{key:"material",get:function(){return this.mesh.material},set:function(e){this.mesh.material=e,this.gazeInner.material=e,this.gazeOuter.material=e}}]),n}(Nt);Nn.EVENTS=["pointerstart","pointerend","pointermove","gazestart","gazemove","gazecomplete","gazecancel","exit","enter","select","useraction"];var In={ANY:Number.MAX_VALUE,MODIFIER_KEYS:["ctrl","shift","alt","meta","meta_l","meta_r"],SHIFT:16,CTRL:17,ALT:18,META:91,META_L:91,META_R:92,BACKSPACE:8,TAB:9,ENTER:13,SPACE:32,DELETE:46,PAUSEBREAK:19,CAPSLOCK:20,NUMLOCK:144,SCROLLLOCK:145,INSERT:45,ESCAPE:27,PAGEUP:33,PAGEDOWN:34,END:35,HOME:36,LEFTARROW:37,UPARROW:38,RIGHTARROW:39,DOWNARROW:40,SELECTKEY:93,NUMBER0:48,NUMBER1:49,NUMBER2:50,NUMBER3:51,NUMBER4:52,NUMBER5:53,NUMBER6:54,NUMBER7:55,NUMBER8:56,NUMBER9:57,A:65,B:66,C:67,D:68,E:69,F:70,G:71,H:72,I:73,J:74,K:75,L:76,M:77,N:78,O:79,P:80,Q:81,R:82,S:83,T:84,U:85,V:86,W:87,X:88,Y:89,Z:90,NUMPAD0:96,NUMPAD1:97,NUMPAD2:98,NUMPAD3:99,NUMPAD4:100,NUMPAD5:101,NUMPAD6:102,NUMPAD7:103,NUMPAD8:104,NUMPAD9:105,MULTIPLY:106,ADD:107,SUBTRACT:109,DECIMALPOINT:110,DIVIDE:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,VOLUME_DOWN:174,VOLUME_UP:175,TRACK_NEXT:176,TRACK_PREVIOUS:177};for(var Fn in In){var Vn=In[Fn];In.hasOwnProperty(Fn)&&"number"==typeof Vn&&(In[Vn]=Fn)}var Un=function(){function e(t,n){_t(this,e),this.set(t||0,n||0)}return wt(e,[{key:"set",value:function(e,t){this.x=e,this.y=t}},{key:"copy",value:function(e){e&&(this.x=e.x,this.y=e.y)}},{key:"clone",value:function(){return new e(this.x,this.y)}},{key:"toString",value:function(){return"(x:"+this.x+", y:"+this.y+")"}}]),e}(),jn=function(){function e(t,n){_t(this,e),this.set(t||0,n||0)}return wt(e,[{key:"set",value:function(e,t){this.width=e,this.height=t}},{key:"copy",value:function(e){e&&(this.width=e.width,this.height=e.height)}},{key:"clone",value:function(){return new e(this.width,this.height)}},{key:"toString",value:function(){return"<w:"+this.width+", h:"+this.height+">"}}]),e}(),Bn=function(){function e(t,n,i,r){_t(this,e),this.isRectangle=!0,this.point=new Un(t,n),this.size=new jn(i,r)}return wt(e,[{key:"set",value:function(e,t,n,i){this.point.set(e,t),this.size.set(n,i)}},{key:"copy",value:function(e){e&&(this.point.copy(e.point),this.size.copy(e.size))}},{key:"clone",value:function(){return new e(this.point.x,this.point.y,this.size.width,this.size.height)}},{key:"toString",value:function(){return"["+this.point.toString()+" x "+this.size.toString()+"]"}},{key:"overlap",value:function(t){var n=Math.max(this.left,t.left),i=Math.max(this.top,t.top),r=Math.min(this.right,t.right),o=Math.min(this.bottom,t.bottom);if(r>n&&o>i)return new e(n,i,r-n,o-i)}},{key:"x",get:function(){return this.point.x},set:function(e){this.point.x=e}},{key:"left",get:function(){return this.point.x},set:function(e){this.point.x=e}},{key:"width",get:function(){return this.size.width},set:function(e){this.size.width=e}},{key:"right",get:function(){return this.point.x+this.size.width},set:function(e){this.point.x=e-this.size.width}},{key:"y",get:function(){return this.point.y},set:function(e){this.point.y=e}},{key:"top",get:function(){return this.point.y},set:function(e){this.point.y=e}},{key:"height",get:function(){return this.size.height},set:function(e){this.size.height=e}},{key:"bottom",get:function(){return this.point.y+this.size.height},set:function(e){this.point.y=e-this.size.height}},{key:"area",get:function(){return this.width*this.height}}]),e}(),zn=0,Hn=function(e){function t(e){_t(this,t),e=Object.assign({},{id:"Primrose.Controls.Surface["+zn+++"]",bounds:new Bn},e),e.width&&(e.bounds.width=e.width),e.height&&(e.bounds.height=e.height);var n=null,i=null;if(e.id instanceof t)throw new Error("Object is already a Surface. Please don't try to wrap them.");if(e.id instanceof CanvasRenderingContext2D?(i=e.id,n=i.canvas):e.id instanceof HTMLCanvasElement?n=e.id:("string"==typeof e.id||e.id instanceof String)&&(n=document.getElementById(e.id),null===n?(n=document.createElement("canvas"),n.id=e.id):"CANVAS"!==n.tagName&&(n=null)),null===n)throw console.error(yt(e.id)),console.error(e.id),new Error(e.id+" does not refer to a valid canvas element.");var r=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,[n],e));return r.isSurface=!0,r.bounds=r.options.bounds,r.canvas=n,r.context=i||r.canvas.getContext("2d"),r._opacity=1,r.focused=!1,r.focusable=!0,r.style={},Object.defineProperties(r.style,{width:{get:function(){return r.bounds.width},set:function(e){r.bounds.width=e,r.resize()}},height:{get:function(){return r.bounds.height},set:function(e){r.bounds.height=e,r.resize()}},left:{get:function(){return r.bounds.left},set:function(e){r.bounds.left=e}},top:{get:function(){return r.bounds.top},set:function(e){r.bounds.top=e}},opacity:{get:function(){return r._opacity},set:function(e){r._opacity=e}},fontSize:{get:function(){return r.fontSize},set:function(e){r.fontSize=e}},backgroundColor:{get:function(){return r.backgroundColor},set:function(e){r.backgroundColor=e}},color:{get:function(){return r.color},set:function(e){r.color=e}}}),0===r.bounds.width&&(r.bounds.width=r.imageWidth,r.bounds.height=r.imageHeight),r.imageWidth=r.bounds.width,r.imageHeight=r.bounds.height,r.canvas.style.imageRendering=rt?"pixelated":"optimizespeed",r.context.imageSmoothingEnabled=!1,r.context.textBaseline="top",r.subSurfaces=[],r.render=r.render.bind(r),r.on("focus",r.render).on("blur",r.render).on("pointerstart",r.startUV.bind(r)).on("pointermove",r.moveUV.bind(r)).on("gazemove",r.moveUV.bind(r)).on("pointerend",r.endPointer.bind(r)).on("gazecomplete",function(e){r.startUV(e),setTimeout(function(){return r.endPointer(e)},100)}).on("keydown",r.keyDown.bind(r)).on("keyup",r.keyUp.bind(r)),r.render(),r}return kt(t,e),wt(t,[{key:"_loadFiles",value:function(e,t){var n=this;return Promise.all(e.map(function(e,t){var i=Object.assign({},n.options);return n._meshes[t]=n._geometry.textured(e,i),i.promise.then(function(e){return n._textures[t]=e})}))}},{key:"invalidate",value:function(e){e?e.isRectangle&&(e=e.clone()):(e=this.bounds.clone(),e.left=0,e.top=0);for(var n=0;n<this.subSurfaces.length;++n){var i=this.subSurfaces[n],r=e.overlap(i.bounds);if(r){var o=r.left-i.bounds.left,s=r.top-i.bounds.top;this.context.drawImage(i.canvas,o,s,r.width,r.height,r.x,r.y,r.width,r.height)}}this._textures[0]&&(this._textures[0].needsUpdate=!0),this._meshes[0]&&(this._meshes[0].material.needsUpdate=!0),this.parent instanceof t&&(e.left+=this.bounds.left,e.top+=this.bounds.top,this.parent.invalidate(e))}},{key:"render",value:function(){this.invalidate()}},{key:"resize",value:function(){this.setSize(this.surfaceWidth,this.surfaceHeight)}},{key:"setSize",value:function(e,t){var n=this.context.textBaseline,i=this.context.textAlign;this.imageWidth=e,this.imageHeight=t,this.context.textBaseline=n,this.context.textAlign=i}},{key:"add",value:function(e){if(e.isSurface)this.subSurfaces.push(e),this.invalidate();else{if(!e.isObject3D)throw new Error("Can only append other Surfaces to a Surface. You gave: "+e);bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"add",this).call(this,e)}}},{key:"mapUV",value:function(e){return e instanceof Array?{x:e[0]*this.imageWidth,y:(1-e[1])*this.imageHeight}:e.isVector2?{x:e.x*this.imageWidth,y:(1-e.y)*this.imageHeight}:void 0}},{key:"unmapUV",value:function(e){return[e.x/this.imageWidth,1-e.y/this.imageHeight]}},{key:"_findSubSurface",value:function(e,t,n){for(var i=this.inBounds(e,t),r=null,o=this.subSurfaces.length-1;o>=0;--o){var s=this.subSurfaces[o];!r&&s.inBounds(e-this.bounds.left,t-this.bounds.top)?r=s:s.focused&&s.blur()}return r||i&&this}},{key:"inBounds",value:function(e,t){return this.bounds.left<=e&&e<this.bounds.right&&this.bounds.top<=t&&t<this.bounds.bottom}},{key:"startPointer",value:function(e,t){if(this.inBounds(e,t)){var n=this._findSubSurface(e,t,function(e,t,n){return e.startPointer(t,n)});n?(this.focused||this.focus(),this.emit("click",{target:n,x:e,y:t}),n!==this&&n.startPointer(e-this.bounds.left,t-this.bounds.top)):this.focused&&this.blur()}}},{key:"movePointer",value:function(e,t){var n=this._findSubSurface(e,t,function(e,t,n){return e.startPointer(t,n)});n&&(this.emit("move",{target:n,x:e,y:t}),n!==this&&n.movePointer(e-this.bounds.left,t-this.bounds.top))}},{key:"_forFocusedSubSurface",value:function(e,t){var n=this.focusedElement;return!(!n||n===this)&&(n[e](t),!0)}},{key:"startUV",value:function(e){if(!this._forFocusedSubSurface("startUV",e)){var t=this.mapUV(e.hit.uv);this.startPointer(t.x,t.y)}}},{key:"moveUV",value:function(e){if(!this._forFocusedSubSurface("moveUV",e)){var t=this.mapUV(e.hit.uv);this.movePointer(t.x,t.y)}}},{key:"endPointer",value:function(e){this._forFocusedSubSurface("endPointer",e)}},{key:"focus",value:function(){this.focusable&&!this.focused&&(this.focused=!0,this.emit("focus"))}},{key:"blur",value:function(){if(this.focused){this.focused=!1;for(var e=0;e<this.subSurfaces.length;++e)this.subSurfaces[e].focused&&this.subSurfaces[e].blur();this.emit("blur")}}},{key:"keyDown",value:function(e){this._forFocusedSubSurface("keyDown",e)}},{key:"keyUp",value:function(e){this._forFocusedSubSurface("keyUp",e)}},{key:"readClipboard",value:function(e){this._forFocusedSubSurface("readClipboard",e)}},{key:"copySelectedText",value:function(e){this._forFocusedSubSurface("copySelectedText",e)}},{key:"cutSelectedText",value:function(e){this._forFocusedSubSurface("cutSelectedText",e)}},{key:"readWheel",value:function(e){this._forFocusedSubSurface("readWheel",e)}},{key:"pickable",get:function(){return!0}},{key:"imageWidth",get:function(){return this.canvas.width},set:function(e){this.canvas.width=e,this.bounds.width=e}},{key:"imageHeight",get:function(){return this.canvas.height},set:function(e){this.canvas.height=e,this.bounds.height=e}},{key:"elementWidth",get:function(){return this.canvas.clientWidth*devicePixelRatio},set:function(e){this.canvas.style.width=e/devicePixelRatio+"px"}},{key:"elementHeight",get:function(){return this.canvas.clientHeight*devicePixelRatio},set:function(e){this.canvas.style.height=e/devicePixelRatio+"px"}},{key:"surfaceWidth",get:function(){return this.canvas.parentElement?this.elementWidth:this.bounds.width}},{key:"surfaceHeight",get:function(){return this.canvas.parentElement?this.elementHeight:this.bounds.height}},{key:"resized",get:function(){return this.imageWidth!==this.surfaceWidth||this.imageHeight!==this.surfaceHeight}},{key:"environment",get:function(){for(var e=this;e;){if(e._environment)return e!==this&&(this._environment=e._environment),this._environment;e=e.parent}}},{key:"theme",get:function(){return null},set:function(e){for(var t=0;t<this.subSurfaces.length;++t)this.subSurfaces[t].theme=e}},{key:"lockMovement",get:function(){for(var e=!1,t=0;t<this.subSurfaces.length&&!e;++t)e=e||this.subSurfaces[t].lockMovement;return e}},{key:"focusedElement",get:function(){for(var e=null,t=this;t&&t.focused;){e=t;var n=t.subSurfaces;t=null;for(var i=0;i<n.length;++i){var r=n[i];r.focused&&(t=r)}}return e}}]),t}(Ut),Wn={name:"Light",fontFamily:"'Droid Sans Mono', 'Consolas', 'Lucida Console', 'Courier New', 'Courier', monospace",cursorColor:"black",fontSize:16,lineNumbers:{foreColor:"black"},regular:{backColor:"white",foreColor:"black",currentRowBackColor:"#f0f0f0",selectedBackColor:"#c0c0c0",unfocused:"rgba(0, 0, 255, 0.25)"},strings:{foreColor:"#aa9900",fontStyle:"italic"},regexes:{foreColor:"#aa0099",fontStyle:"italic"},numbers:{foreColor:"green"},comments:{foreColor:"grey",fontStyle:"italic"},keywords:{foreColor:"blue"},functions:{foreColor:"brown",fontWeight:"bold"},members:{foreColor:"green"},error:{foreColor:"red",fontStyle:"underline italic"}},Gn=0,Qn=function(e){function t(e){_t(this,t);var n=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,Object.assign({},{id:"Primrose.Controls.Label["+Gn+++"]"},e)));return n._lastFont=null,n._lastText=null,n._lastCharacterWidth=null,n._lastCharacterHeight=null,n._lastPadding=null,n._lastWidth=-1,n._lastHeight=-1,n._lastTextAlign=null,n.textAlign=n.options.textAlign,n.character=new jn,n.theme=n.options.theme,n.fontSize=n.options.fontSize||16,n.refreshCharacter(),n.backgroundColor=n.options.backgroundColor||n.theme.regular.backColor,n.color=n.options.color||n.theme.regular.foreColor,n.value=n.options.value,n}return kt(t,e),wt(t,[{key:"refreshCharacter",value:function(){this.character.height=this.fontSize,this.context.font=this.character.height+"px "+this.theme.fontFamily,this.character.width=this.context.measureText("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM").width/100}},{key:"_isChanged",value:function(){var e=this._lastText!==this.value,t=this.character.width!==this._lastCharacterWidth,n=this.character.height!==this._lastCharacterHeight,i=this.context.font!==this._lastFont,r=this.textAlign!==this._lastTextAlign;return this.resized||e||t||n||this.resized||i||r}},{key:"render",value:function(){if(this.resized&&this.resize(),this.theme&&this._isChanged){this._lastText=this.value,this._lastCharacterWidth=this.character.width,this._lastCharacterHeight=this.character.height,this._lastWidth=this.imageWidth,this._lastHeight=this.imageHeight,this._lastFont=this.context.font,this._lastTextAlign=this.textAlign,this.context.textAlign=this.textAlign||"left";var e=this.backgroundColor?"fillRect":"clearRect";if(this.theme.regular.backColor&&(this.context.fillStyle=this.backgroundColor),this.context[e](0,0,this.imageWidth,this.imageHeight),this.value)for(var t=this.value.split("\n"),n=0;n<t.length;++n){var i=t[n],r=(this.imageHeight-t.length*this.character.height)/2+n*this.character.height,o=null;switch(this.textAlign){case"right":o=this.imageWidth;break;case"center":o=this.imageWidth/2;break;default:o=0}var s=(this.theme.regular.fontWeight||"")+" "+(this.theme.regular.fontStyle||"")+" "+this.character.height+"px "+this.theme.fontFamily;this.context.font=s.trim(),this.context.fillStyle=this.color,this.context.fillText(i,o,r)}this.renderCanvasTrim(),this.invalidate()}}},{key:"renderCanvasTrim",value:function(){}},{key:"textAlign",get:function(){return this.context.textAlign},set:function(e){this.context.textAlign=e,this.render()}},{key:"value",get:function(){return this._value},set:function(e){e=e||"",this._value=e.replace(/\r\n/g,"\n"),this.render()}},{key:"theme",get:function(){return this._theme},set:function(e){this._theme=Object.assign({},Wn,e),this._theme.fontSize=this.fontSize,this.refreshCharacter(),this.render()}}]),t}(Hn),Kn=0,Yn=function(e){function t(e){_t(this,t);var n=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,Object.assign({},{id:"Primrose.Controls.Button2D["+Kn+++"]",textAlign:"center"},e)));return n._lastActivated=null,n}return kt(t,e),wt(t,[{key:"startPointer",value:function(e,t){this.focus(),this._activated=!0,this.render()}},{key:"endPointer",value:function(){this._activated&&(this._activated=!1,this.emit("click",{target:this}),this.render())}},{key:"_isChanged",value:function(){var e=this._activated!==this._lastActivated;return bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"_isChanged",this)||e}},{key:"renderCanvasTrim",value:function(){this.context.lineWidth=this._activated?4:2,this.context.strokeStyle=this.theme.regular.foreColor||Primrose.Text.Themes.Default.regular.foreColor,this.context.strokeRect(0,0,this.imageWidth,this.imageHeight)}}]),t}(Qn),qn=function(t){function n(t,i,r){_t(this,n);var o=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,i,Object.assign({},n.DEFAULTS,r)));return o.options.minDeflection=Math.cos(o.options.minDeflection),o.options.colorUnpressed=new e.Color(o.options.colorUnpressed),o.options.colorPressed=new e.Color(o.options.colorPressed),o.base=t.children[1],o.cap=t.children[0],o.cap.name=i,o.cap.material=o.cap.material.clone(),o.cap.button=o,o.cap.base=o.base,o.add(o.base),o.add(o.cap),o.color=o.cap.material.color,o.name=i,o.element=null,o}return kt(n,t),wt(n,[{key:"startUV",value:function(e){this.color.copy(this.options.colorPressed),this.element?this.element.click():this.emit("click",{source:this})}},{key:"endPointer",value:function(e){this.color.copy(this.options.colorUnpressed),this.emit("release",{source:this})}},{key:"consumeEvent",value:function(e){var t=this;switch(e.type){case"pointerstart":this.startUV();break;case"pointerend":this.endPointer(e);break;case"gazecomplete":this.startUV(),setTimeout(function(){return t.endPointer(e)},100)}}}]),n}(Nt);qn.DEFAULTS={maxThrow:.1,minDeflection:10,colorUnpressed:8323072,colorPressed:32512,toggle:!0};var Xn=0,Zn=function(){function e(t,n){_t(this,e),this.options=n,this.template=t}return wt(e,[{key:"create",value:function(e){var t="button"+ ++Xn,n=this.template.clone();return new qn(n,t,this.options,e)}}]),e}();Zn.DEFAULT=new Zn(a(u(1,1,1),16711680),{maxThrow:.1,minDeflection:10,colorUnpressed:8323072,colorPressed:32512,toggle:!0});var Jn=0,$n=function(e){function t(e,n){return _t(this,t),e instanceof Array||(e=[e]),n=Object.assign({},{id:"Primrose.Controls.Image["+Jn+++"]"},n),xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n))}return kt(t,e),wt(t,[{key:"_loadFiles",value:function(e,t){var n=this;return Promise.all(Array.prototype.map.call(e,function(e,i){var r=Object.assign({},n.options,{progress:t});return n._meshes[i]=n._geometry.textured(e,r).named(n.name+"-mesh-"+i),r.promise.then(function(e){return n._textures[i]=e})}))}}]),t}(Ut),ei=null,ti={isButton:function(e){return e.material&&e.material.name.match(/^button\d+$/)},isSolid:function(e){return!e.name.match(/^(water|sky)/)},isGround:function(e){return e.material&&e.material.name&&e.material.name.match(/\bground\b/)}},ni=function(){function t(e){_t(this,t),this.template=e}return wt(t,null,[{key:"loadModel",value:function(e,n,i){return t.loadObject(e,n,i).then(function(e){for(;e&&"Group"===e.type;)e=e.children[0];return new t(e)})}},{key:"loadObject",value:function(n,i,r){var o=n.match(/(\.(?:\w+))+$/),s=i&&"."+i||o[0];if(s){s=s.toLowerCase(),null===ei&&(ei={".json":e.ObjectLoader,".mtl":tn,".obj":rn,".typeface.json":e.FontLoader});var a=ei[s];if(a){var u=new a,h=n.substring(0,o.index),c=h+"_"+s.toLowerCase(),l=document.getElementById(c),d=Promise.resolve();if(".obj"===s){var f=n.replace(/(\.(?:\w+))+$/,".mtl");d=d.then(function(){return t.loadObject(f,"mtl",r)}).then(function(e){e.preload(),u.setMaterials(e)}).catch(console.error.bind(console,"Error loading MTL file: "+f))}else if(".mtl"===s){
var p=n.match(/((?:https?:\/\/)?(?:[^\/]+\/)+)(\w+)(\.(?:\w+))$/);if(p){var m=p[1];n=p[2]+p[3],u.setTexturePath(m),u.setPath(m)}}if(l){var v=l.innerHTML.split(/\r?\n/g).map(function(e){return e.trim()}).join("\n");d=d.then(function(){return u.parse(v)})}else u.setCrossOrigin&&u.setCrossOrigin("anonymous"),d=d.then(function(){return new Promise(function(e,t){return u.load(n,e,r,t)})});return".obj"===s&&(d=d.then(fe)),".json"===s&&(d=d.then(de)),".mtl"!==s&&".typeface.json"!==s&&(d=d.then(pe)),d=d.catch(console.error.bind(console,"MODEL_ERR",n))}return Promise.reject("There is no loader type for the file extension: "+s)}return Promise.reject("File path `"+n+"` does not have a file extension, and a type was not provided as a parameter, so we can't determine the type.")}},{key:"loadObjects",value:function(e){var t={},n=Promise.resolve(t);for(var i in e)e[i]&&(n=n.then(le(e,i)));return n}}]),wt(t,[{key:"clone",value:function(){var t=this,n=this.template.clone();return n.traverse(function(i){i.isSkinnedMesh&&(n.animation=new e.AnimationClip(i,i.geometry.animation),!t.template.originalAnimationClipData&&n.animation.data&&(t.template.originalAnimationClipData=n.animation.data),n.animation.data||(n.animation.data=t.template.originalAnimationClipData))}),pe(n),n}}]),t}(),ii=new e.Raycaster;ii.ray.direction.set(0,-1,0);var ri=function(e){function t(e){return _t(this,t),xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Ground",{transparent:!1,dim:e.drawDistance,texture:e.groundTexture,model:e.groundModel,shadow:e.enableShadows,progress:e.progress}))}return kt(t,e),wt(t,[{key:"moveTo",value:function(e){this.isInfinite&&this.position.set(Math.floor(e.x),0,Math.floor(e.z))}},{key:"getHeightAt",value:function(e){if(this.model){ii.ray.origin.copy(e),ii.ray.origin.y=100;var t=ii.intersectObject(this.model);if(t.length>0){return 100-t[0].distance}}}},{key:"_ready",get:function(){var e=this,t=this.options.dim,n=yt(this.options.texture),i=null;return this.model=null,this.isInfinite=null,this.options.model?i=ni.loadObject(this.options.model).then(function(t){e.model=t,e.isInfinite=!1}):("number"===n?(this.model=T(t,t).colored(this.options.texture,this.options).rot(-Math.PI/2,0,0),i=Promise.resolve()):"string"===n&&(this.model=new $n(this.options.texture,Object.assign({},this.options,{width:t,height:t,txtRepeatX:t,txtRepeatY:t,anisotropy:8})).rot(-Math.PI/2,0,0),i=this.model.ready),i?this.isInfinite=!0:i=Promise.reject("Couldn't figure out how to make the ground out of "+this.options.texture)),i=i.then(function(){e.model.receiveShadow=e.options.shadow,e.model.named(e.name+"-"+(e.options.model||e.options.texture)).addTo(e),e.watch(e.model,Nn.EVENTS)})}}]),t}(Nt),oi=function(t){function n(t){_t(this,n);var i=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"Sky",{transparent:!1,useFog:!1,unshaded:!0,skyRadius:t.drawDistance,texture:t.skyTexture,progress:t.progress,enableShadows:t.enableShadows,shadowMapSize:t.shadowMapSize,shadowCameraSize:t.shadowCameraSize,shadowRadius:t.shadowRadius}));return i._image=null,t.disableDefaultLighting?(i.ambient=null,i.sun=null):(i.ambient=new e.AmbientLight(16777215,.5).addTo(i),i.sun=new e.DirectionalLight(16777215,1).addTo(i).at(0,100,100),i.add(i.sun.target),i.options.enableShadows&&(i.sun.castShadow=!0,i.sun.shadow.mapSize.width=i.sun.shadow.mapSize.height=i.options.shadowMapSize,i.sun.shadow.radius=i.options.shadowRadius,i.sun.shadow.camera.top=i.sun.shadow.camera.right=i.options.shadowCameraSize,i.sun.shadow.camera.bottom=i.sun.shadow.camera.left=-i.options.shadowCameraSize,i.sun.shadow.camera.updateProjectionMatrix())),i}return kt(n,t),wt(n,[{key:"replace",value:function(e){return this.options.texture=e,this.children.splice(0),this._ready}},{key:"_ready",get:function(){var t=yt(this.options.texture);if("number"===t){var i=this.options.skyRadius/Math.sqrt(2);this.options.side=e.BackSide,this.add(u(i,i,i).colored(this.options.texture,this.options))}else("string"===t||this.options.texture instanceof Array&&6===this.options.texture.length&&"string"==typeof this.options.texture[0])&&(this._image=new $n(this.options.texture,this.options),this.add(this._image));return this._image&&this._image.ready||bt(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"_ready",this)}}]),n}(Nt),si=function(){function e(i){i=i.replace(t,function(t,n,i){return e(i)+n}).replace(n,"$2$1");for(var r="",o=i.length-1;o>=0;--o)r+=i[o];return r}var t=/(<%= allExceptCombiningMarks %>)(<%= combiningMarks %>+)/g,n=/(<%= highSurrogates %>)(<%= lowSurrogates %>)/g;return e}(),ai=function(){function e(t,n,i){_t(this,e),this.i=t||0,this.x=n||0,this.y=i||0,this.moved=!0}return wt(e,null,[{key:"min",value:function(e,t){return e.i<=t.i?e:t}},{key:"max",value:function(e,t){return e.i>t.i?e:t}}]),wt(e,[{key:"clone",value:function(){return new e(this.i,this.x,this.y)}},{key:"toString",value:function(){return"[i:"+this.i+" x:"+this.x+" y:"+this.y+"]"}},{key:"copy",value:function(e){this.i=e.i,this.x=e.x,this.y=e.y,this.moved=!1}},{key:"fullhome",value:function(){this.i=0,this.x=0,this.y=0,this.moved=!0}},{key:"fullend",value:function(e){this.i=0;for(var t=0,n=0;n<e.length;++n){t=e[n].length,this.i+=t}this.y=e.length-1,this.x=t,this.moved=!0}},{key:"skipleft",value:function(e){if(0===this.x)this.left(e);else{var t=this.x-1,n=e[this.y],i=si(n.substring(0,t)),r=i.match(/(\s|\W)+/),o=r?r.index+r[0].length+1:i.length;this.i-=o,this.x-=o}this.moved=!0}},{key:"left",value:function(e){if(this.i>0){if(--this.i,--this.x<0){--this.y;var t=e[this.y];this.x=t.length}this.reverseFromNewline(e)&&++this.i}this.moved=!0}},{key:"skipright",value:function(e){var t=e[this.y];if(this.x===t.length||"\n"===t[this.x])this.right(e);else{var n=this.x+1;t=t.substring(n);var i=t.match(/(\s|\W)+/),r=i?i.index+i[0].length+1:t.length-this.x;this.i+=r,this.x+=r,this.reverseFromNewline(e)}this.moved=!0}},{key:"fixCursor",value:function(e){this.x=this.i,this.y=0;for(var t=0,n=e[this.y];this.x>n.length;){if(this.x-=n.length,t+=n.length,this.y>=e.length-1){this.i=t,this.x=n.length,this.moved=!0;break}++this.y,n=e[this.y]}return this.moved}},{key:"right",value:function(e){this.advanceN(e,1)}},{key:"advanceN",value:function(e,t){var n=e[this.y];(this.y<e.length-1||this.x<n.length)&&(this.i+=t,this.fixCursor(e),n=e[this.y],this.x>0&&"\n"===n[this.x-1]&&(++this.y,this.x=0)),this.moved=!0}},{key:"home",value:function(){this.i-=this.x,this.x=0,this.moved=!0}},{key:"end",value:function(e){var t=e[this.y],n=t.length-this.x;this.i+=n,this.x+=n,this.reverseFromNewline(e),this.moved=!0}},{key:"up",value:function(e){if(this.y>0){--this.y;var t=e[this.y],n=Math.min(0,t.length-this.x);this.x+=n,this.i-=t.length-n,this.reverseFromNewline(e)}this.moved=!0}},{key:"down",value:function(e){if(this.y<e.length-1){++this.y;var t=e[this.y],n=e[this.y-1],i=Math.min(0,t.length-this.x);this.x+=i,this.i+=n.length+i,this.reverseFromNewline(e)}this.moved=!0}},{key:"incY",value:function(e,t){this.y=Math.max(0,Math.min(t.length-1,this.y+e));var n=t[this.y];this.x=Math.max(0,Math.min(n.length,this.x)),this.i=this.x;for(var i=0;i<this.y;++i)this.i+=t[i].length;this.reverseFromNewline(t),this.moved=!0}},{key:"setXY",value:function(e,t,n){this.y=Math.max(0,Math.min(n.length-1,t));var i=n[this.y];this.x=Math.max(0,Math.min(i.length,e)),this.i=this.x;for(var r=0;r<this.y;++r)this.i+=n[r].length;this.reverseFromNewline(n),this.moved=!0}},{key:"setI",value:function(e,t){this.i=e,this.fixCursor(t),this.moved=!0}},{key:"reverseFromNewline",value:function(e){var t=e[this.y];return this.x>0&&"\n"===t[this.x-1]&&(--this.x,--this.i,!0)}}]),e}(),ui=function e(t,n){_t(this,e),this.name=t,Object.assign(this,n)},hi=function(e){function t(e,n){_t(this,t);var i={NORMAL_LEFTARROW:function(e,t){e.cursorLeft(t,e.frontCursor)},NORMAL_SKIPLEFT:function(e,t){e.cursorSkipLeft(t,e.frontCursor)},NORMAL_RIGHTARROW:function(e,t){e.cursorRight(t,e.frontCursor)},NORMAL_SKIPRIGHT:function(e,t){e.cursorSkipRight(t,e.frontCursor)},NORMAL_HOME:function(e,t){e.cursorHome(t,e.frontCursor)},NORMAL_END:function(e,t){e.cursorEnd(t,e.frontCursor)},NORMAL_BACKSPACE:function(e,t){e.frontCursor.i===e.backCursor.i&&e.frontCursor.left(t),e.selectedText="",e.scrollIntoView(e.frontCursor)},NORMAL_ENTER:function(e,t,n){e.emit("change",{target:e})},NORMAL_DELETE:function(e,t){e.frontCursor.i===e.backCursor.i&&e.backCursor.right(t),e.selectedText="",e.scrollIntoView(e.frontCursor)},NORMAL_TAB:function(e,t){e.selectedText=e.tabString},SHIFT_LEFTARROW:function(e,t){e.cursorLeft(t,e.backCursor)},SHIFT_SKIPLEFT:function(e,t){e.cursorSkipLeft(t,e.backCursor)},SHIFT_RIGHTARROW:function(e,t){e.cursorRight(t,e.backCursor)},SHIFT_SKIPRIGHT:function(e,t){e.cursorSkipRight(t,e.backCursor)},SHIFT_HOME:function(e,t){e.cursorHome(t,e.backCursor)},SHIFT_END:function(e,t){e.cursorEnd(t,e.backCursor)},SHIFT_DELETE:function(e,t){e.frontCursor.i===e.backCursor.i&&(e.frontCursor.home(t),e.backCursor.end(t)),e.selectedText="",e.scrollIntoView(e.frontCursor)},CTRL_HOME:function(e,t){e.cursorFullHome(t,e.frontCursor)},CTRL_END:function(e,t){e.cursorFullEnd(t,e.frontCursor)},CTRLSHIFT_HOME:function(e,t){e.cursorFullHome(t,e.backCursor)},CTRLSHIFT_END:function(e,t){e.cursorFullEnd(t,e.backCursor)},SELECT_ALL:function(e,t){e.frontCursor.fullhome(t),e.backCursor.fullend(t)},REDO:function(e,t){e.redo(),e.scrollIntoView(e.frontCursor)},UNDO:function(e,t){e.undo(),e.scrollIntoView(e.frontCursor)}};if(n)for(var r in n)i[r]=n[r];return xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e||"Text editor commands",i))}return kt(t,e),t}(ui),ci=new hi("Text Area input commands",{NORMAL_UPARROW:function(e,t){e.cursorUp(t,e.frontCursor)},NORMAL_DOWNARROW:function(e,t){e.cursorDown(t,e.frontCursor)},NORMAL_PAGEUP:function(e,t){e.cursorPageUp(t,e.frontCursor)},NORMAL_PAGEDOWN:function(e,t){e.cursorPageDown(t,e.frontCursor)},NORMAL_ENTER:function(e,t,n){var i="",r=t[e.frontCursor.y];r.length>0&&"whitespace"===r[0].type&&(i=r[0].value),e.selectedText="\n"+i,e.scrollIntoView(e.frontCursor)},SHIFT_UPARROW:function(e,t){e.cursorUp(t,e.backCursor)},SHIFT_DOWNARROW:function(e,t){e.cursorDown(t,e.backCursor)},SHIFT_PAGEUP:function(e,t){e.cursorPageUp(t,e.backCursor)},SHIFT_PAGEDOWN:function(e,t){e.cursorPageDown(t,e.backCursor)},WINDOW_SCROLL_DOWN:function(e,t){e.scroll.y<t.length&&++e.scroll.y},WINDOW_SCROLL_UP:function(e,t){e.scroll.y>0&&--e.scroll.y}}),li=function(){function e(t,n){_t(this,e),this.name=t,this.test=n}return wt(e,[{key:"carveOutMatchedToken",value:function(e,t){var n=e[t];if("regular"===n.type){var i=this.test.exec(n.value);if(i){var r=i[i.length-1],o=i.input.indexOf(r),s=o+r.length;if(0===o){if(n.type=this.name,s<n.value.length){var a=n.splitAt(s);a.type="regular",e.splice(t+1,0,a)}}else{var u=n.splitAt(o);if(r.length<u.value.length){var h=u.splitAt(r.length);e.splice(t+1,0,h)}u.type=this.name,e.splice(t+1,0,u)}}}}}]),e}(),di=function(){function e(t,n,i,r){_t(this,e),this.value=t,this.type=n,this.index=i,this.line=r}return wt(e,[{key:"clone",value:function(){return new e(this.value,this.type,this.index,this.line)}},{key:"splitAt",value:function(t){var n=this.value.substring(t);return this.value=this.value.substring(0,t),new e(n,this.type,this.index+t,this.line)}},{key:"toString",value:function(){return"["+this.type+": "+this.value+"]"}}]),e}(),fi=function(){function e(t,n){function i(e){var t,n,i=null,r=null,o=0;for(t=0;t<e.length;++t)n=e[t],n.line=o,"newlines"===n.type&&++o,r?("stringDelim"!==n.type||n.value!==r||0!==t&&"\\"===e[t-1].value[e[t-1].value.length-1]||(r=null),"newlines"!==n.type&&(n.type="strings")):i?(("startBlockComments"===i&&"endBlockComments"===n.type||"startLineComments"===i&&"newlines"===n.type)&&(i=null),"newlines"!==n.type&&(n.type="comments")):"stringDelim"===n.type?(r=n.value,n.type="strings"):"startBlockComments"!==n.type&&"startLineComments"!==n.type||(i=n.type,n.type="comments");for(t=e.length-1;t>0;--t){var s=e[t-1];n=e[t],s.type===n.type&&"newlines"!==s.type&&(s.value+=n.value,e.splice(t,1))}}_t(this,e),this.name=t,this.grammar=n.map(function(e){return new li(e[0],e[1])}),this.tokenize=function(e){for(var t=[new di(e,"regular",0)],n=0;n<this.grammar.length;++n)for(var r=this.grammar[n],o=0;o<t.length;++o)r.carveOutMatchedToken(t,o);return i(t),t}}return wt(e,[{key:"toHTML",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Wn,n=this.tokenize(e),i=document.createElement("div"),r=0;r<n.length;++r){var o=n[r];if("newlines"===o.type)i.appendChild(document.createElement("br"));else{var s=t[o.type]||{},a=document.createElement("span");a.style.fontWeight=s.fontWeight||t.regular.fontWeight,a.style.fontStyle=s.fontStyle||t.regular.fontStyle||"",a.style.color=s.foreColor||t.regular.foreColor,a.style.backgroundColor=s.backColor||t.regular.backColor,a.style.fontFamily=s.fontFamily||t.fontFamily,a.appendChild(document.createTextNode(o.value)),i.appendChild(a)}}return i.innerHTML}}]),e}(),pi=new fi("JavaScript",[["newlines",/(?:\r\n|\r|\n)/],["startBlockComments",/\/\*/],["endBlockComments",/\*\//],["regexes",/(?:^|,|;|\(|\[|\{)(?:\s*)(\/(?:\\\/|[^\n\/])+\/)/],["stringDelim",/("|')/],["startLineComments",/\/\/.*$/m],["numbers",/-?(?:(?:\b\d*)?\.)?\b\d+\b/],["keywords",/\b(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|export|finally|for|function|if|import|in|instanceof|let|new|return|super|switch|this|throw|try|typeof|var|void|while|with)\b/],["functions",/(\w+)(?:\s*\()/],["members",/(\w+)\./],["members",/((\w+\.)+)(\w+)/]]),mi=ot?3:100,vi=0,gi=function(e){function t(e){_t(this,t),"string"==typeof e&&(e={value:e});var n=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,Object.assign({},{id:"Primrose.Controls.TextBox["+vi+++"]"},e)));n.isTextBox=!0,n.useCaching=!ot||!lt,["Left","Right","SkipLeft","SkipRight","Up","Down","Home","End","FullHome","FullEnd"].map(function(e){var t=e.toLowerCase();this["cursor"+e]=function(e,n){n[t](e),this.scrollIntoView(n)}}.bind(n)),n.tokens=null,n.lines=null,n._commandPack=null,n._tokenRows=null,n._tokenHashes=null,n._tabString=null,n._currentTouchID=null,n._lineCountWidth=null,n._lastFont=null,n._lastText=null,n._lastCharacterWidth=null,n._lastCharacterHeight=null,n._lastGridBounds=null,n._lastPadding=null,n._lastFrontCursor=null,n._lastBackCursor=null,n._lastWidth=-1,n._lastHeight=-1,n._lastScrollX=-1,n._lastScrollY=-1,n._lastFocused=!1,n._lastThemeName=null,n._lastPointer=new Un,n._browser=rt?"CHROMIUM":ot?"FIREFOX":at?"IE":it?"OPERA":dt?"SAFARI":"UNKNOWN",n._pointer=new Un,n._history=[],n._historyFrame=-1,n._topLeftGutter=new jn,n._bottomRightGutter=new jn,n._dragging=!1,n._scrolling=!1,n._wheelScrollSpeed=4;var i=new Bn(0,0,n.bounds.width,n.bounds.height);return n._fg=new Hn({id:n.id+"-fore",bounds:i}),n._fgCanvas=n._fg.canvas,n._fgfx=n._fg.context,n._bg=new Hn({id:n.id+"-back",bounds:i}),n._bgCanvas=n._bg.canvas,n._bgfx=n._bg.context,n._trim=new Hn({id:n.id+"-trim",bounds:i}),n._trimCanvas=n._trim.canvas,n._tgfx=n._trim.context,n._rowCache={},n._VSCROLL_WIDTH=2,n.tabWidth=n.options.tabWidth,n.showLineNumbers=!n.options.hideLineNumbers,n.showScrollBars=!n.options.hideScrollBars,n.wordWrap=!n.options.disableWordWrap,n.readOnly=!!n.options.readOnly,n.multiline=!n.options.singleLine,n.gridBounds=new Bn,n.frontCursor=new ai,n.backCursor=new ai,n.scroll=new Un,n.character=new jn,n.theme=n.options.theme,n.fontSize=n.options.fontSize,n.tokenizer=n.options.tokenizer,n.commandPack=n.options.commands||ci,n.value=n.options.value,n.padding=n.options.padding||1,n.addEventListener("visiblechanged",n.blur.bind(n)),n}return kt(t,e),wt(t,[{key:"cursorPageUp",value:function(e,t){t.incY(-this.gridBounds.height,e),this.scrollIntoView(t)}},{key:"cursorPageDown",value:function(e,t){t.incY(this.gridBounds.height,e),this.scrollIntoView(t)}},{key:"pushUndo",value:function(e){this._historyFrame<this._history.length-1&&this._history.splice(this._historyFrame+1),this._history.push(e),this._historyFrame=this._history.length-1,this.refreshTokens(),this.render()}},{key:"redo",value:function(){this._historyFrame<this._history.length-1&&++this._historyFrame,this.refreshTokens(),this.fixCursor(),this.render()}},{key:"undo",value:function(){this._historyFrame>0&&--this._historyFrame,this.refreshTokens(),this.fixCursor(),this.render()}},{key:"scrollIntoView",value:function(e){this.scroll.y+=this.minDelta(e.y,this.scroll.y,this.scroll.y+this.gridBounds.height),this.wordWrap||(this.scroll.x+=this.minDelta(e.x,this.scroll.x,this.scroll.x+this.gridBounds.width)),this.clampScroll()}},{key:"readWheel",value:function(e){this.focused&&((e.shiftKey||rt)&&(this.fontSize+=-e.deltaX/mi),e.shiftKey&&!rt||(this.scroll.y+=Math.floor(e.deltaY*this._wheelScrollSpeed/mi)),this.clampScroll(),this.render(),e.preventDefault())}},{key:"startPointer",value:function(e,n){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"startPointer",this).call(this,e,n)||(this._dragging=!0,this.setCursorXY(this.frontCursor,e,n))}},{key:"movePointer",value:function(e,t){this._dragging&&this.setCursorXY(this.backCursor,e,t)}},{key:"endPointer",value:function(){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"endPointer",this).call(this),this._dragging=!1,this._scrolling=!1}},{key:"copySelectedText",value:function(e){if(this.focused&&this.frontCursor.i!==this.backCursor.i){(e.clipboardData||window.clipboardData).setData(window.clipboardData?"Text":"text/plain",this.selectedText),e.returnValue=!1}}},{key:"cutSelectedText",value:function(e){this.focused&&(this.copySelectedText(e),this.readOnly||(this.selectedText=""))}},{key:"keyDown",value:function(e){if(this.focused&&!this.readOnly){var t=this.commandPack[e.altCmdName]||this.commandPack[e.cmdName]||e.altCmdText||e.cmdText;(t instanceof String||"string"==typeof t)&&(console.warn("This shouldn't have happened."),t=this.commandPack[t]||this.commandPack[t]||t),t&&(this.frontCursor.moved=!1,this.backCursor.moved=!1,t instanceof Function?t(this,this.lines):(t instanceof String||"string"==typeof t)&&(console.log(t),this.selectedText=t),e.resetDeadKeyState(),e.preventDefault(),this.frontCursor.moved&&!this.backCursor.moved&&this.backCursor.copy(this.frontCursor),this.clampScroll(),this.render())}}},{key:"readClipboard",value:function(e){if(this.focused&&!this.readOnly){e.returnValue=!1;var t=e.clipboardData||window.clipboardData,n=t.getData(window.clipboardData?"Text":"text/plain");n&&(this.selectedText=n)}}},{key:"resize",value:function(){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"resize",this).call(this),this._bg.setSize(this.surfaceWidth,this.surfaceHeight),this._fg.setSize(this.surfaceWidth,this.surfaceHeight),this._trim.setSize(this.surfaceWidth,this.surfaceHeight),this.theme&&(this.character.height=this.fontSize,this.context.font=this.character.height+"px "+this.theme.fontFamily,this.character.width=this.context.measureText("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM").width/100),this.render()}},{key:"pixel2cell",value:function(e){e.x,this.imageWidth,this.surfaceWidth,e.y,this.imageHeight,this.surfaceHeight;e.set(Math.round(e.x/this.character.width)+this.scroll.x-this.gridBounds.x,Math.floor(e.y/this.character.height-.25)+this.scroll.y)}},{key:"clampScroll",value:function(){if(this.scroll.y<0)this.scroll.y=0;else for(;0<this.scroll.y&&this.scroll.y>this.lines.length-this.gridBounds.height;)--this.scroll.y}},{key:"refreshTokens",value:function(){this.tokens=this.tokenizer.tokenize(this.value)}},{key:"fixCursor",value:function(){(this.frontCursor.fixCursor(this.lines)||this.backCursor.fixCursor(this.lines))&&this.render()}},{key:"setCursorXY",value:function(e,t,n){t=Math.round(t),n=Math.round(n),this._pointer.set(t,n),this.pixel2cell(this._pointer,this.scroll,this.gridBounds);var i=this._pointer.x-this.scroll.x,r=this._pointer.y-this.scroll.y,o=r>=this.gridBounds.height,s=i<0,a=this._pointer.x>=this.gridBounds.width;if(this._scrolling||o||s||a){if(this._scrolling||a&&!o){this._scrolling=!0;var u=this.lines.length-this.gridBounds.height;if(r>=0&&u>=0){var h=r*u/this.gridBounds.height;this.scroll.y=Math.floor(h)}}else if(o&&!s){for(var c=0,l=0;l<this.lines.length;++l)c=Math.max(c,this.lines[l].length);var d=c-this.gridBounds.width;if(i>=0&&d>=0){var f=i*d/this.gridBounds.width;this.scroll.x=Math.floor(f)}}}else e.setXY(this._pointer.x,this._pointer.y,this.lines),this.backCursor.copy(e);this._lastPointer.copy(this._pointer),this.render()}},{key:"setGutter",value:function(){this.showLineNumbers?this._topLeftGutter.width=1:this._topLeftGutter.width=0,this.showScrollBars?this.wordWrap?this._bottomRightGutter.set(this._VSCROLL_WIDTH,0):this._bottomRightGutter.set(this._VSCROLL_WIDTH,1):this._bottomRightGutter.set(0,0)}},{key:"refreshGridBounds",value:function(){this._lineCountWidth=0,this.showLineNumbers&&(this._lineCountWidth=Math.max(1,Math.ceil(Math.log(this._history[this._historyFrame].length)/Math.LN10)));var e=Math.floor(this._topLeftGutter.width+this._lineCountWidth+this.padding/this.character.width),t=Math.floor(this.padding/this.character.height),n=Math.floor((this.imageWidth-2*this.padding)/this.character.width)-e-this._bottomRightGutter.width,i=Math.floor((this.imageHeight-2*this.padding)/this.character.height)-t-this._bottomRightGutter.height;this.gridBounds.set(e,t,n,i)}},{key:"performLayout",value:function(){this._tokenRows=[[]],this._tokenHashes=[""],this.lines=[""];for(var e=0,t=this.tokens.slice(),n=0;n<t.length;++n){var i=t[n].clone(),r=this.gridBounds.width-e,o=this.wordWrap&&"newlines"!==i.type&&i.value.length>r,s="newlines"===i.type||o;if(o){var a=i.value.length>this.gridBounds.width?r:0;t.splice(n+1,0,i.splitAt(a))}i.value.length>0&&(this._tokenRows[this._tokenRows.length-1].push(i),this._tokenHashes[this._tokenHashes.length-1]+=JSON.stringify(i),this.lines[this.lines.length-1]+=i.value,e+=i.value.length),s&&(this._tokenRows.push([]),this._tokenHashes.push(""),this.lines.push(""),e=0)}}},{key:"minDelta",value:function(e,t,n){var i=e-t,r=e-n+5,o=0;return(i<0||r>=0)&&(o=Math.abs(i)<Math.abs(r)?i:r),o}},{key:"fillRect",value:function(e,t,n,i,r,o){e.fillStyle=t,e.fillRect(n*this.character.width,i*this.character.height,r*this.character.width+1,o*this.character.height+1)}},{key:"strokeRect",value:function(e,t,n,i,r,o){e.strokeStyle=t,e.strokeRect(n*this.character.width,i*this.character.height,r*this.character.width+1,o*this.character.height+1)}},{key:"renderCanvasBackground",value:function(){var e=ai.min(this.frontCursor,this.backCursor),t=ai.max(this.frontCursor,this.backCursor),n=new ai,i=new ai,r=this.theme.regular.backColor?"fillRect":"clearRect",o=0/this.character.height;this.theme.regular.backColor&&(this._bgfx.fillStyle=this.theme.regular.backColor),this._bgfx[r](0,0,this.imageWidth,this.imageHeight),this._bgfx.save(),this._bgfx.translate((this.gridBounds.x-this.scroll.x)*this.character.width+this.padding,-this.scroll.y*this.character.height+this.padding),this.focused&&this.fillRect(this._bgfx,this.theme.regular.currentRowBackColor||Wn.regular.currentRowBackColor,0,e.y+o,this.gridBounds.width,t.y-e.y+1);for(var s=0;s<this._tokenRows.length;++s){for(var a=this._tokenRows[s],u=0;u<a.length;++u){var h=a[u];if(i.x+=h.value.length,i.i+=h.value.length,this.scroll.y<=s&&s<this.scroll.y+this.gridBounds.height&&this.scroll.x<=i.x&&n.x<this.scroll.x+this.gridBounds.width){if(e.i<=i.i&&n.i<t.i){var c=ai.max(e,n),l=ai.min(t,i),d=l.i-c.i;this.fillRect(this._bgfx,this.theme.regular.selectedBackColor||Wn.regular.selectedBackColor,c.x,c.y+o,d,1)}}n.copy(i)}n.x=0,++n.y,i.copy(n)}if(this.focused){var f=this.theme.cursorColor||"black",p=1/this.character.width;this.fillRect(this._bgfx,f,e.x,e.y+o,p,1),this.fillRect(this._bgfx,f,t.x,t.y+o,p,1)}this._bgfx.restore()}},{key:"renderCanvasForeground",value:function(){var e=new ai,t=new ai;this._fgfx.clearRect(0,0,this.imageWidth,this.imageHeight),this._fgfx.save(),this._fgfx.translate((this.gridBounds.x-this.scroll.x)*this.character.width+this.padding,this.padding);for(var n=0;n<this._tokenRows.length;++n){for(var i=this.lines[n]+this.padding,r=this._tokenRows[n],o=!1,s=(n-this.scroll.y)*this.character.height,a=0;a<r.length;++a){var u=r[a];if(t.x+=u.value.length,t.i+=u.value.length,this.scroll.y<=n&&n<this.scroll.y+this.gridBounds.height&&this.scroll.x<=t.x&&e.x<this.scroll.x+this.gridBounds.width)if(this.useCaching&&void 0!==this._rowCache[i])0===a&&this._fgfx.putImageData(this._rowCache[i],this.padding,s+this.padding+0);else{var h=this.theme[u.type]||{},c=(h.fontWeight||this.theme.regular.fontWeight||"")+" "+(h.fontStyle||this.theme.regular.fontStyle||"")+" "+this.character.height+"px "+this.theme.fontFamily;this._fgfx.font=c.trim(),this._fgfx.fillStyle=h.foreColor||this.theme.regular.foreColor,this.drawText(this._fgfx,u.value,e.x*this.character.width,s),o=!0}e.copy(t)}e.x=0,++e.y,t.copy(e),this.useCaching&&o&&void 0===this._rowCache[i]&&(this._rowCache[i]=this._fgfx.getImageData(this.padding,s+this.padding+0,this.imageWidth-2*this.padding,this.character.height))}this._fgfx.restore()}},{key:"drawText",value:function(e,t,n,i){e.fillText(t,n,i)}},{key:"renderCanvasTrim",value:function(){var e=new ai,t=new ai,n=0;this._tgfx.clearRect(0,0,this.imageWidth,this.imageHeight),this._tgfx.save(),this._tgfx.translate(this.padding,this.padding),this._tgfx.save(),this._tgfx.lineWidth=2,this._tgfx.translate(0,-this.scroll.y*this.character.height);for(var i=0,r=-1;i<this._tokenRows.length;++i){for(var o=this._tokenRows[i],s=0;s<o.length;++s){var a=o[s];t.x+=a.value.length,t.i+=a.value.length,e.copy(t)}if(n=Math.max(n,t.x),e.x=0,++e.y,t.copy(e),this.showLineNumbers&&this.scroll.y<=i&&i<this.scroll.y+this.gridBounds.height){for(var u=o.length>0?o[0].line:r+1,h=u.toString();h.length<this._lineCountWidth;)h=" "+h;this.fillRect(this._tgfx,this.theme.regular.selectedBackColor||Wn.regular.selectedBackColor,0,i,this.gridBounds.x,1),this._tgfx.font="bold "+this.character.height+"px "+this.theme.fontFamily,u>r&&(this._tgfx.fillStyle=this.theme.regular.foreColor,this._tgfx.fillText(h,0,i*this.character.height)),r=u}}if(this._tgfx.restore(),this.showLineNumbers&&this.strokeRect(this._tgfx,this.theme.regular.foreColor||Wn.regular.foreColor,0,0,this.gridBounds.x,this.gridBounds.height),this.showScrollBars){var c=this.gridBounds.width*this.character.width-this.padding,l=this.gridBounds.height*this.character.height,d=this.scroll.x*c/n+this.gridBounds.x*this.character.width,f=this.scroll.y*l/this._tokenRows.length;this._tgfx.fillStyle=this.theme.regular.selectedBackColor||Wn.regular.selectedBackColor;var p;if(!this.wordWrap&&n>this.gridBounds.width){var m=c*(this.gridBounds.width/n),v=this.gridBounds.height*this.character.height;p=Math.max(this.character.width,m),this._tgfx.fillRect(d,v,p,this.character.height),this._tgfx.strokeRect(d,v,p,this.character.height)}if(this._tokenRows.length>this.gridBounds.height){var g=l*(this.gridBounds.height/this._tokenRows.length),y=this.image-this._VSCROLL_WIDTH*this.character.width-2*this.padding,_=Math.max(this.character.height,g);p=this._VSCROLL_WIDTH*this.character.width,this._tgfx.fillRect(y,f,p,_),this._tgfx.strokeRect(y,f,p,_)}}this._tgfx.lineWidth=2,this._tgfx.restore(),this._tgfx.strokeRect(1,1,this.imageWidth-2,this.imageHeight-2),this.focused||(this._tgfx.fillStyle=this.theme.regular.unfocused||Wn.regular.unfocused,this._tgfx.fillRect(0,0,this.imageWidth,this.imageHeight))}},{key:"render",value:function(){if(this.tokens&&this.theme){this.refreshGridBounds();var e=this.gridBounds.toString()!==this._lastGridBounds,t=this._lastText!==this.value,n=this.character.width!==this._lastCharacterWidth,i=this.character.height!==this._lastCharacterHeight,r=this.padding!==this._lastPadding,o=!this._lastFrontCursor||!this._lastBackCursor||this.frontCursor.i!==this._lastFrontCursor.i||this._lastBackCursor.i!==this.backCursor.i,s=this.scroll.x!==this._lastScrollX||this.scroll.y!==this._lastScrollY,a=(this.context.font,this._lastFont,this.theme.name!==this._lastThemeName),u=this.focused!==this._lastFocused,h=null,c=this.resized||e||t||n||i||r,l=c||o||s||a,d=l||t,f=l||u,p=d||l||f;if(c&&(this.performLayout(this.gridBounds),this._rowCache={}),p){if(o&&!(c||s||a||u)){var m=Math.min(this.frontCursor.y,this._lastFrontCursor.y,this.backCursor.y,this._lastBackCursor.y)-this.scroll.y+this.gridBounds.y,v=Math.max(this.frontCursor.y,this._lastFrontCursor.y,this.backCursor.y,this._lastBackCursor.y)-this.scroll.y+1;h=new Bn(0,m*this.character.height,this.bounds.width,(v-m)*this.character.height+2)}l&&this.renderCanvasBackground(),d&&this.renderCanvasForeground(),f&&this.renderCanvasTrim(),this.context.clearRect(0,0,this.imageWidth,this.imageHeight),this.context.drawImage(this._bgCanvas,0,0),this.context.drawImage(this._fgCanvas,0,0),this.context.drawImage(this._trimCanvas,0,0),this.invalidate(h)}this._lastGridBounds=this.gridBounds.toString(),this._lastText=this.value,this._lastCharacterWidth=this.character.width,this._lastCharacterHeight=this.character.height,this._lastWidth=this.imageWidth,this._lastHeight=this.imageHeight,this._lastPadding=this.padding,this._lastFrontCursor=this.frontCursor.clone(),this._lastBackCursor=this.backCursor.clone(),this._lastFocused=this.focused,this._lastFont=this.context.font,this._lastThemeName=this.theme.name,this._lastScrollX=this.scroll.x,this._lastScrollY=this.scroll.y}}},{key:"value",get:function(){return this._history[this._historyFrame].join("\n")},set:function(e){e=e||"",e=e.replace(/\r\n/g,"\n"),this.multiline||(e=e.replace(/\n/g,""));var t=e.split("\n");this.pushUndo(t),this.render(),this.emit("change",{target:this})}},{key:"selectedText",get:function(){var e=ai.min(this.frontCursor,this.backCursor),t=ai.max(this.frontCursor,this.backCursor);return this.value.substring(e.i,t.i)},set:function(e){if(e=e||"",e=e.replace(/\r\n/g,"\n"),this.frontCursor.i!==this.backCursor.i||e.length>0){var t=ai.min(this.frontCursor,this.backCursor),n=ai.max(this.frontCursor,this.backCursor),i=this.value,r=i.substring(0,t.i),o=i.substring(n.i),s=r+e+o;this.value=s,this.refreshGridBounds(),this.performLayout(),t.advanceN(this.lines,Math.max(0,e.length)),this.scrollIntoView(n),this.clampScroll(),n.copy(t),this.render()}}},{key:"padding",get:function(){return this._padding},set:function(e){this._padding=e,this.render()}},{key:"wordWrap",get:function(){return this._wordWrap},set:function(e){this._wordWrap=e||!1,this.setGutter()}},{key:"showLineNumbers",get:function(){return this._showLineNumbers},set:function(e){this._showLineNumbers=e,this.setGutter()}},{key:"showScrollBars",get:function(){return this._showScrollBars},set:function(e){this._showScrollBars=e,this.setGutter()}},{key:"theme",get:function(){return this._theme},set:function(e){this._theme=Object.assign({},Wn,e),this._theme.fontSize=this.fontSize,this._rowCache={},this.render()}},{key:"commandPack",get:function(){return this._commandPack},set:function(e){this._commandPack=e}},{key:"selectionStart",get:function(){return this.frontCursor.i},set:function(e){this.frontCursor.setI(e,this.lines)}},{key:"selectionEnd",get:function(){return this.backCursor.i},set:function(e){this.backCursor.setI(e,this.lines)}},{key:"selectionDirection",get:function(){return this.frontCursor.i<=this.backCursor.i?"forward":"backward"}},{key:"tokenizer",get:function(){return this._tokenizer},set:function(e){this._tokenizer=e||pi,this._history&&this._history.length>0&&(this.refreshTokens(),this.render())}},{key:"tabWidth",get:function(){return this._tabWidth},set:function(e){this._tabWidth=e||2,this._tabString="";for(var t=0;t<this._tabWidth;++t)this._tabString+=" "}},{key:"tabString",get:function(){return this._tabString}},{key:"fontSize",get:function(){return this._fontSize||16},set:function(e){e=e||16,this._fontSize=e,this.theme&&(this.theme.fontSize=this._fontSize,this.resize(),this.render())}},{key:"lockMovement",get:function(){return this.focused&&!this.readOnly}}]),t
}(Hn),yi=Math.PI/180,_i=.25*Math.PI,wi=new Float32Array([0,0,0,1]),bi=new Float32Array([0,0,0]),ki=function e(){_t(this,e),this.leftProjectionMatrix=new Float32Array(16),this.leftViewMatrix=new Float32Array(16),this.rightProjectionMatrix=new Float32Array(16),this.rightViewMatrix=new Float32Array(16),this.pose=null},xi=1e3,Si=function(){function e(t){_t(this,e),this._currentLayers=[],Object.defineProperties(this,{capabilities:X(Object.defineProperties({},{hasPosition:X(!1),hasOrientation:X(lt),hasExternalDisplay:X(!1),canPresent:X(!0),maxLayers:X(1)})),displayId:X(xi++),displayName:X(t),isConnected:X(!0),stageParameters:X(null),isPresenting:X(function(){return Kt.isActive}),depthNear:J(.01,"number"),depthFar:J(1e4,"number"),isPolyfilled:X(!0)}),this._frameData=null,this._poseData=null}return wt(e,[{key:"getFrameData",value:function(e){return this._frameData||(this._frameData=we(e,this.getPose(),this)),this._frameData}},{key:"getPose",value:function(){return this._poseData||(this._poseData=this._getPose()),this._poseData}},{key:"requestAnimationFrame",value:function(e){return window.requestAnimationFrame(e)}},{key:"cancelAnimationFrame",value:function(e){return window.cancelAnimationFrame(e)}},{key:"requestPresent",value:function(e){for(var t=0;t<this.capabilities.maxLayers&&t<e.length;++t)this._currentLayers[t]=e[t];return oe(e[0].source)}},{key:"exitPresent",value:function(){return this._currentLayers.splice(0),ie()}},{key:"getLayers",value:function(){return this._currentLayers.slice()}},{key:"submitFrame",value:function(e){this._frameData=null,this._poseData=null}}]),e}(),Ei=100,Mi=function(e){function t(e){_t(this,t);var n=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Full Screen"));return n._display=e,n}return kt(t,e),wt(t,null,[{key:"DEFAULT_FOV",get:function(){return Ei},set:function(e){Ei=e}}]),wt(t,[{key:"submitFrame",value:function(e){this._display&&this._display.isPolyfilled&&this._display.submitFrame(e)}},{key:"getPose",value:function(){var e=lt&&this._display;return e?e.getPose():be()}},{key:"resetPose",value:function(){var e=lt&&this._display;if(e)return e.resetPose()}},{key:"getEyeParameters",value:function(e){if("left"===e){var t=this.getLayers()[0],n=t&&t.source||document.body,i=n.clientWidth,r=n.clientHeight,o=void 0,s=void 0;return r>i?(o=Ei/2,s=ke(o,i,r)):(s=Ei/2,o=ke(s,r,i)),{renderWidth:i*devicePixelRatio,renderHeight:r*devicePixelRatio,offset:new Float32Array([0,0,0]),fieldOfView:{upDegrees:o,downDegrees:o,leftDegrees:s,rightDegrees:s}}}}}]),t}(Si),Ti=function e(){_t(this,e),this.value=null,this.pressed=!1,this.wasPressed=!1,this.fireAgain=!1,this.lt=0,this.ct=0,this.repeatCount=0},Oi=function(e){function t(e,n,i,r){_t(this,t);var o=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));o.name=e,o.commands={},o.commandNames=[],o.enabled=!0,o.paused=!1,o.ready=!0,o.inPhysicalUse=!1,Se.call(o);var s=function(e){for(var t=0;t<In.MODIFIER_KEYS.length;++t){var n=In.MODIFIER_KEYS[t];o.inputState[n]=e[n+"Key"]}};window.addEventListener("keydown",s,!1),window.addEventListener("keyup",s,!1),window.addEventListener("focus",s,!1),o.axisNames=i||[];for(var a=0;a<o.axisNames.length;++a)o.inputState.axes[a]=0;for(var u in n)o.addCommand(u,n[u]);for(var h=0;h<In.MODIFIER_KEYS.length;++h)o.inputState[In.MODIFIER_KEYS[h]]=!1;return o.userActionHandlers=null,r&&window.addEventListener(r,function(e){if(o.userActionHandlers)for(var t=0;t<o.userActionHandlers.length;++t)o.userActionHandlers[t](e)}),o}return kt(t,e),wt(t,[{key:"addCommand",value:function(e,t){t.name=e,t=this.cloneCommand(t),void 0===t.repetitions&&(t.repetitions=1),t.state=new Ti,this.commands[e]=t,this.commandNames.push(e)}},{key:"cloneCommand",value:function(e){return{name:e.name,disabled:!!e.disabled,dt:e.dt||0,deadzone:e.deadzone||0,threshold:e.threshold||0,repetitions:e.repetitions,scale:e.scale,offset:e.offset,min:e.min,max:e.max,integrate:!!e.integrate,delta:!!e.delta,axes:this.maybeClone(e.axes),commands:e.commands&&e.commands.slice()||[],buttons:this.maybeClone(e.buttons),metaKeys:this.maybeClone(e.metaKeys&&e.metaKeys.map(Ee)),commandDown:e.commandDown,commandUp:e.commandUp}}},{key:"maybeClone",value:function(e){var t=[];if(e)for(var n=0;n<e.length;++n)t[n]=Me.call(this,e[n]);return t}},{key:"update",value:function(e){if(this.enabled&&this.ready&&this.inPhysicalUse&&!this.paused&&e>0){this.inputState.buttons[In.ANY]=!1;for(var t in this.inputState.buttons)if(this.inputState.buttons[t]){this.inputState.buttons[In.ANY]=!0;break}var n=Pe;for(var i in this.commands){var r=this.commands[i];if(r.state.wasPressed=r.state.pressed,r.state.pressed=!1,!r.disabled){var o=!0,s=0;if(r.metaKeys)for(var a=0;a<r.metaKeys.length&&o;++a){var u=r.metaKeys[a];o=o&&(this.inputState[In.MODIFIER_KEYS[u.index]]&&!u.toggle||!this.inputState[In.MODIFIER_KEYS[u.index]]&&u.toggle)}if(o){if(r.buttons.length>0)for(var h=0;h<r.buttons.length;++h){var c=r.buttons[h],l=c.index+1,d=!!this.inputState.buttons[l],f=d?c.sign:0;o=o&&(d&&!c.toggle||!d&&c.toggle),Math.abs(f)>Math.abs(s)&&(s=f)}if(0===r.buttons.length||0!==s){if(r.axes.length>0){s=0;for(var p=0;p<r.axes.length;++p){var m=r.axes[p],v=m.sign*this.inputState.axes[m.index];Math.abs(v)>Math.abs(s)&&(s=v)}}else if(r.commands.length>0){s=0;for(var g=0;g<r.commands.length;++g){var y=this.getValue(r.commands[g]);Math.abs(y)>Math.abs(s)&&(s=y)}}if(void 0!==r.scale&&(s*=r.scale),void 0!==r.offset&&(s+=r.offset),r.deadzone&&Math.abs(s)<r.deadzone&&(s=0),r.integrate)s=this.getValue(r.name)+s*e;else if(r.delta){var _=s;void 0!==r.state.lv&&(s-=r.state.lv),r.state.lv=_}void 0!==r.min&&s<r.min&&(s=r.min,n=Oe),void 0!==r.max&&s>r.max&&(s=r.max,n=Oe),r.threshold&&(o=o&&s>r.threshold)}}r.state.pressed=o,r.state.value=s,r.state.lt+=e,r.state.fireAgain=r.state.pressed&&r.state.lt>=r.dt&&(-1===r.repetitions||r.state.repeatCount<r.repetitions),r.state.fireAgain?(r.state.lt=0,++r.state.repeatCount):r.state.pressed||(r.state.repeatCount=0)}}n.call(this),this.fireCommands()}}},{key:"zero",value:function(){Se.call(this);for(var e in this.commands)this.commands[e].state=new Ti}},{key:"fireCommands",value:function(){if(this.ready&&!this.paused)for(var e in this.commands){var t=this.commands[e];t.state.fireAgain&&t.commandDown&&t.commandDown(this.name),!t.state.pressed&&t.state.wasPressed&&t.commandUp&&t.commandUp(this.name)}}},{key:"setProperty",value:function(e,t,n){this.commands[t]&&(this.commands[t][e]=n)}},{key:"setDeadzone",value:function(e,t){this.setProperty("deadzone",e,t)}},{key:"setScale",value:function(e,t){this.setProperty("scale",e,t)}},{key:"setDT",value:function(e,t){this.setProperty("dt",e,t)}},{key:"setMin",value:function(e,t){this.setProperty("min",e,t)}},{key:"setMax",value:function(e,t){this.setProperty("max",e,t)}},{key:"addMetaKey",value:function(e,t){this.addToArray("metaKeys",e,Ee(t))}},{key:"addAxis",value:function(e,t){this.addToArray("axes",e,t)}},{key:"addButton",value:function(e,t){this.addToArray("buttons",e,t)}},{key:"removeMetaKey",value:function(e,t){this.removeFromArray("metaKeys",e,t)}},{key:"removeAxis",value:function(e,t){this.removeFromArray("axes",e,t)}},{key:"removeButton",value:function(e,t){this.removeFromArray("buttons",e,t)}},{key:"invertAxis",value:function(e,t){this.invertInArray("axes",e,t)}},{key:"invertButton",value:function(e,t){this.invertInArray("buttons",e,t)}},{key:"invertMetaKey",value:function(e,t){this.invertInArray("metaKeys",e,t)}},{key:"addToArray",value:function(e,t,n){this.commands[t]&&this.commands[t][e]&&this.commands[t][e].push(Me(n))}},{key:"removeFromArray",value:function(e,t,n){if(this.commands[t]&&this.commands[t][e]){--n;for(var i=this.commands[t][e],r=0;r<i.length;++r){if(i[r].index===n)return i.splice(r,1)}}}},{key:"invertInArray",value:function(e,t,n){if(this.commands[t]&&this.commands[t][e])for(var i=this.commands[t][e],r=(i.indexOf(n),0);r<i.length;++r){var o=i[r];if(o.index===n)return void(o.sign*=-1)}}},{key:"pause",value:function(e){this.paused=e}},{key:"isPaused",value:function(){return this.paused}},{key:"enable",value:function(e,t){void 0!==t&&null!==t||(t=e,e=null),e?this.setProperty("disabled",e,!t):this.enabled=t}},{key:"isEnabled",value:function(e){return e&&this.commands[e]&&!this.commands[e].disabled}},{key:"getAxis",value:function(e){var t=this.axisNames.indexOf(e);if(t>-1){return this.inputState.axes[t]||0}return null}},{key:"setAxis",value:function(e,t){var n=this.axisNames.indexOf(e);n>-1&&(this.inPhysicalUse||0!==t)&&(this.inputState.axes[n]=t)}},{key:"setButton",value:function(e,t){(this.inPhysicalUse||t)&&(this.inputState.buttons[e]=t)}},{key:"isDown",value:function(e){return this.enabled&&this.isEnabled(e)&&this.commands[e].state.pressed}},{key:"isUp",value:function(e){return this.enabled&&this.isEnabled(e)&&this.commands[e].state.pressed}},{key:"getValue",value:function(e){return this.enabled&&this.isEnabled(e)&&(this.commands[e].state.value||this.getAxis(e))||0}},{key:"setValue",value:function(e,t){var n=this.axisNames.indexOf(e);!this.commands[e]&&n>-1?this.setAxis(e,t):this.commands[e]&&!this.commands[e].disabled&&(this.commands[e].state.value=t)}},{key:"inPhysicalUse",get:function(){return this._inPhysicalUse},set:function(e){var t=this._inPhysicalUse;this._inPhysicalUse=e,!t&&e&&this.emit("activate")}}]),t}(e.EventDispatcher),Pi=function(){function e(t,n,i,r,o,s,a,u){_t(this,e),this.name=t;var h=o;o=o.length>0?o:"NORMAL",this[n+"_a"]="SELECT_ALL",this[n+"_c"]="COPY",this[n+"_x"]="CUT",this[n+"_v"]="PASTE",this[r]="REDO",this[n+"_z"]="UNDO",this[n+"_DOWNARROW"]="WINDOW_SCROLL_DOWN",this[n+"_UPARROW"]="WINDOW_SCROLL_UP",this[i+"_LEFTARROW"]="NORMAL_SKIPLEFT",this[i+"SHIFT_LEFTARROW"]="SHIFT_SKIPLEFT",this[i+"_RIGHTARROW"]="NORMAL_SKIPRIGHT",this[i+"SHIFT_RIGHTARROW"]="SHIFT_SKIPRIGHT",this[o+"_HOME"]="NORMAL_HOME",this[h+"SHIFT_HOME"]="SHIFT_HOME",this[o+"_END"]="NORMAL_END",this[h+"SHIFT_END"]="SHIFT_END",this[u+"_HOME"]="CTRL_HOME",this[u+"SHIFT_HOME"]="CTRLSHIFT_HOME",this[u+"_END"]="CTRL_END",this[u+"SHIFT_END"]="CTRLSHIFT_END"}return wt(e,[{key:"makeCommandName",value:function(e,t){var n=e.keyCode;if(n!==In.CTRL&&n!==In.ALT&&n!==In.META_L&&n!==In.META_R&&n!==In.SHIFT){var i=t.deadKeyState;return e.ctrlKey&&(i+="CTRL"),e.altKey&&(i+="ALT"),e.metaKey&&(i+="META"),e.shiftKey&&(i+="SHIFT"),i===t.deadKeyState&&(i+="NORMAL"),i+="_"+t.keyNames[n],this[i]||i}}}]),e}(),Ci=new Pi("Windows","CTRL","CTRL","CTRL_y","","HOME","END","CTRL","HOME","END"),Ai=new Pi("macOS","META","ALT","METASHIFT_z","META","LEFTARROW","RIGHTARROW","META","UPARROW","DOWNARROW"),Ri=function(){function e(t,n,i){function r(e,t,n){t.selectedText=e}_t(this,e),this.name=t,this.language=n;var o={NORMAL:{65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z"},SHIFT:{65:"A",66:"B",67:"C",68:"D",69:"E",70:"F",71:"G",72:"H",73:"I",74:"J",75:"K",76:"L",77:"M",78:"N",79:"O",80:"P",81:"Q",82:"R",83:"S",84:"T",85:"U",86:"V",87:"W",88:"X",89:"Y",90:"Z"}};for(var s in i)o[s]=Object.assign({},o[s],i[s]);for(var a,u,h,c=0;c<=9;++c)u=In["NUMPAD"+c],o.NORMAL[u]=c.toString();o.NORMAL[In.MULTIPLY]="*",o.NORMAL[In.ADD]="+",o.NORMAL[In.SUBTRACT]="-",o.NORMAL[In.DECIMALPOINT]=".",o.NORMAL[In.DIVIDE]="/",this.keyNames={},this.commandNames=[];for(a in In)u=In[a],isNaN(u)||(this.keyNames[u]=a);for(var l in o){var d=o[l];if("object"===(void 0===d?"undefined":yt(d)))for(u in d){if(u.indexOf("_")>-1){var f=u.split(" "),p=f[0];u=f[1],a=o.NORMAL[u],h=p+"_"+l+" "+a}else a=o.NORMAL[u],h=l+"_"+a;this.commandNames.push(h),this.keyNames[u]=a;var m=d[u];"function"!=typeof m&&(m=r.bind(null,m)),this[h]=m.bind(this)}}this.lastDeadKeyState=this.deadKeyState=""}return wt(e,[{key:"resetDeadKeyState",value:function(){this.deadKeyState===this.lastDeadKeyState&&(this.deadKeyState="")}}]),e}();Ri.DEAD=function(e){return function(t){this.lastDeadKeyState=this.deadKeyState,this.deadKeyState="DEAD"+e}};var Di=new Ri("Deutsch: QWERTZ","de",{deadKeys:[220,221,160,192],NORMAL:{32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",60:"<",63:"ß",160:Ri.DEAD(3),163:"#",171:"+",173:"-",186:"ü",187:"+",188:",",189:"-",190:".",191:"#",192:Ri.DEAD(4),219:"ß",220:Ri.DEAD(1),221:Ri.DEAD(2),222:"ä",226:"<"},DEAD1NORMAL:{65:"â",69:"ê",73:"î",79:"ô",85:"û",190:"."},DEAD2NORMAL:{65:"á",69:"é",73:"í",79:"ó",83:"s",85:"ú",89:"ý"},SHIFT:{32:" ",48:"=",49:"!",50:'"',51:"§",52:"$",53:"%",54:"&",55:"/",56:"(",57:")",60:">",63:"?",163:"'",171:"*",173:"_",186:"Ü",187:"*",188:";",189:"_",190:":",191:"'",192:"Ö",219:"?",222:"Ä",226:">"},CTRLALT:{48:"}",50:"²",51:"³",55:"{",56:"[",57:"]",60:"|",63:"\\",69:"€",77:"µ",81:"@",171:"~",187:"~",219:"\\",226:"|"},CTRLALTSHIFT:{63:"ẞ",219:"ẞ"},DEAD3NORMAL:{65:"a",69:"e",73:"i",79:"o",85:"u",190:"."},DEAD4NORMAL:{65:"a",69:"e",73:"i",79:"o",83:"s",85:"u",89:"y"}}),Li=new Ri("English: UK Extended","en-GB",{CTRLALT:{52:"€",65:"á",69:"é",73:"í",79:"ó",85:"ú",163:"\\",192:"¦",222:"\\",223:"¦"},CTRLALTSHIFT:{65:"Á",69:"É",73:"Í",79:"Ó",85:"Ú",222:"|"},NORMAL:{32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",163:"#",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"'",219:"[",220:"\\",221:"]",222:"#",223:"`"},SHIFT:{32:" ",48:")",49:"!",50:'"',51:"£",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",163:"~",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"@",219:"{",220:"|",221:"}",222:"~",223:"¬"}}),Ni=new Ri("English: USA","en-US",{NORMAL:{32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",219:"[",220:"\\",221:"]",222:"'"},SHIFT:{32:" ",48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",219:"{",220:"|",221:"}",222:'"'}}),Ii=new Ri("Français: AZERTY","fr",{deadKeys:[221,50,55],NORMAL:{32:" ",48:"à",49:"&",50:"é",51:'"',52:"'",53:"(",54:"-",55:"è",56:"_",57:"ç",186:"$",187:"=",188:",",190:";",191:":",192:"ù",219:")",220:"*",221:Ri.DEAD(1),222:"²",223:"!",226:"<"},SHIFT:{32:" ",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",186:"£",187:"+",188:"?",190:".",191:"/",192:"%",219:"°",220:"µ",223:"§",226:">"},CTRLALT:{48:"@",50:Ri.DEAD(2),51:"#",52:"{",53:"[",54:"|",55:Ri.DEAD(3),56:"\\",57:"^",69:"€",186:"¤",187:"}",219:"]"},DEAD1NORMAL:{65:"â",69:"ê",73:"î",79:"ô",85:"û"},DEAD2NORMAL:{65:"ã",78:"ñ",79:"õ"},DEAD3NORMAL:{48:"à",50:"é",55:"è",65:"à",69:"è",73:"ì",79:"ò",85:"ù"}}),Fi={CodePage:Ri,DE_QWERTZ:Di,EN_UKX:Li,EN_US:Ni,FR_AZERTY:Ii},Vi=function(e){function t(e,n){_t(this,t);var i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Keyboard",n));return i._operatingSystem=null,i.browser=rt?"CHROMIUM":ot?"FIREFOX":at?"IE":it?"OPERA":dt?"SAFARI":"UNKNOWN",i._codePage=null,i.resetDeadKeyState=function(){return i.codePage.resetDeadKeyState()},i}return kt(t,e),wt(t,[{key:"consumeEvent",value:function(e){this.inPhysicalUse=!0;var t="keydown"===e.type;this.setButton(e.keyCode,t),t&&(e.cmdName=this.operatingSystem.makeCommandName(e,this.codePage),e.altCmdName=this.browser+"_"+e.cmdName,e.cmdText=this.codePage[e.cmdName],e.altCmdText=this.codePage[e.altCmdName],e.resetDeadKeyState=this.resetDeadKeyState)}},{key:"operatingSystem",get:function(){return this._operatingSystem},set:function(e){this._operatingSystem=e||(ct?Ai:Ci)}},{key:"codePage",get:function(){return this._codePage},set:function(e){var t;if(this._codePage=e,!this._codePage){var n=navigator.languages&&navigator.languages[0]||navigator.language||navigator.userLanguage||navigator.browserLanguage;n&&"en"!==n||(n="en-US");for(t in Fi)if(e=Fi[t],e.language===n){this._codePage=e;break}this._codePage||(this._codePage=Fi.EN_US)}}}]),t}(Oi),Ui=function(e){function t(e,n){_t(this,t);var i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Mouse",n,["BUTTONS","X","Y","Z","W"],"mousedown"));i.timer=null;var r=function(n,r){i.inPhysicalUse=!0;for(var o=r.buttons,s=0;s<t.NUM_BUTTONS;++s){var a=!0&o;(a&&n||!a&&!n)&&i.setButton(s,n),o>>=1}i.setAxis("BUTTONS",r.buttons<<10),r.target===e&&r.preventDefault()};return e.addEventListener("mousedown",r.bind(i,!0),!1),e.addEventListener("mouseup",r.bind(i,!1),!1),e.addEventListener("contextmenu",function(e){return!(e.ctrlKey&&e.shiftKey)&&e.preventDefault()},!1),e.addEventListener("mousemove",function(e){if(r(!0,e),Zt.isActive){var t=e.movementX,n=e.movementY;void 0===t&&(t=e.webkitMovementX||e.mozMovementX||0,n=e.webkitMovementY||e.mozMovementY||0),i.setAxis("X",i.getAxis("X")+t),i.setAxis("Y",i.getAxis("Y")+n)}else i.setAxis("X",e.layerX),i.setAxis("Y",e.layerY)},!1),e.addEventListener("wheel",function(t){rt?(i.W+=t.deltaX,i.Z+=t.deltaY):t.shiftKey?i.W+=t.deltaY:i.Z+=t.deltaY,t.target===e&&t.preventDefault()},!1),i}return kt(t,e),t}(Oi);Ui.NUM_BUTTONS=3;var ji={position:[0,0,0],orientation:[0,0,0,1]},Bi=new e.Vector3,zi=new e.Quaternion(1,0,0,0),Hi=function(t){function n(t,i,r){_t(this,n);var o=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,i,r));return o.currentDevice=null,o.lastPose=null,o.currentPose=null,o.posePosition=new e.Vector3,o.poseQuaternion=new e.Quaternion,o.position=new e.Vector3,o.quaternion=new e.Quaternion,o.matrix=new e.Matrix4,o}return kt(n,t),wt(n,[{key:"update",value:function(e){if(bt(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"update",this).call(this,e),this.currentDevice){var t=this.currentPose||this.lastPose||ji;this.lastPose=t,this.inPhysicalUse=this.hasOrientation||this.inPhysicalUse;var i=this.currentPose&&this.currentPose.orientation,r=this.currentPose&&this.currentPose.position;i?(this.poseQuaternion.fromArray(i),lt&&at&&this.poseQuaternion.multiply(zi)):this.poseQuaternion.set(0,0,0,1),r?this.posePosition.fromArray(r):this.posePosition.set(0,0,0)}}},{key:"updateStage",value:function(e){this.matrix.makeRotationFromQuaternion(this.poseQuaternion),this.matrix.setPosition(this.posePosition),this.matrix.multiplyMatrices(e,this.matrix),this.matrix.decompose(this.position,this.quaternion,Bi)}},{key:"hasPose",get:function(){return!!this.currentPose}}]),n}(Oi),Wi=function(e){function t(e,n,i,r){_t(this,t);var o=t.ID(n),s=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,o,r,["LSX","LSY","RSX","RSY","IDK1","IDK2","Z","BUTTONS"]));return e.registerPad(o,s),s.currentDevice=n,s.axisOffset=i,s}return kt(t,e),wt(t,null,[{key:"ID",value:function(e){var t=e.id;return t="OpenVR Gamepad"===t?"Vive":0===t.indexOf("Rift")?"Rift":0===t.indexOf("Unknown")?"Unknown":"Gamepad",t=(t+"_"+(e.index||0)).replace(/\s+/g,"_")}},{key:"isMotionController",value:function(e){if(e){var t=e.capabilities||e.pose;return t&&t.hasOrientation}return!1}}]),wt(t,[{key:"getPose",value:function(){return this.currentPose}},{key:"checkDevice",value:function(e){this.inPhysicalUse=!0;var t,n,i=0;for(this.currentDevice=e,this.currentPose=this.hasOrientation&&this.currentDevice.pose,t=0,n=e.buttons.length;t<e.buttons.length;++t,++n){var r=e.buttons[t];this.setButton(t,r.pressed),r.pressed&&(i|=1<<t),this.setButton(n,r.touched),r.touched&&(i|=1<<n)}for(this.setAxis("BUTTONS",i),t=0;t<e.axes.length;++t){var o=this.axisNames[this.axisOffset*e.axes.length+t],s=e.axes[t];this.setAxis(o,s)}}},{key:"vibratePattern",value:function(e){this.currentDevice&&(this.currentDevice.vibrate?this.currentDevice.vibrate(e):this.currentDevice.haptics&&this.currentDevice.haptics.length>0&&Ce(this.currentDevice.haptics,e))}},{key:"hasOrientation",get:function(){return t.isMotionController(this.currentDevice)}},{key:"haptics",get:function(){return this.currentDevice&&this.currentDevice.haptics}}]),t}(Hi);Wi.XBOX_360_BUTTONS={A:1,B:2,X:3,Y:4,LEFT_BUMPER:5,RIGHT_BUMPER:6,LEFT_TRIGGER:7,RIGHT_TRIGGER:8,BACK:9,START:10,LEFT_STICK:11,RIGHT_STICK:12,UP_DPAD:13,DOWN_DPAD:14,LEFT_DPAD:15,RIGHT_DPAD:16},Wi.XBOX_ONE_BUTTONS={A:1,B:2,X:3,Y:4,LEFT_BUMPER:5,RIGHT_BUMPER:6,LEFT_TRIGGER:7,RIGHT_TRIGGER:8,BACK:9,START:10,LEFT_STICK:11,RIGHT_STICK:12,UP_DPAD:13,DOWN_DPAD:14,LEFT_DPAD:15,RIGHT_DPAD:16},Wi.VIVE_BUTTONS={TOUCHPAD_PRESSED:0,TRIGGER_PRESSED:1,GRIP_PRESSED:2,MENU_PRESSED:3,TOUCHPAD_TOUCHED:4,GRIP_TOUCHED:6,MENU_TOUCHED:7};var Gi=["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2910.0 Safari/537.36"];navigator.getGamepads=navigator.getGamepads||navigator.webkitGetGamepads;var Qi=function(e){function t(){_t(this,t);var e=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.currentDevices=[],e.currentDeviceIDs=[],e.currentManagers={},e}return kt(t,e),wt(t,null,[{key:"isAvailable",get:function(){return-1===Gi.indexOf(navigator.userAgent)&&!!navigator.getGamepads}}]),wt(t,[{key:"poll",value:function(){if(t.isAvailable){var e,n,i=navigator.getGamepads(),r=[],o=[],s=[],a=[];if(i)for(e=0;e<i.length;++e){var u=i[e];if(u){n=Wi.ID(u);var h=this.currentDeviceIDs.indexOf(n);r.push(u),o.push(n),-1===h?(s.push(u),this.currentDeviceIDs.push(n),this.currentDevices.push(u),delete this.currentManagers[n]):this.currentDevices[h]=u}}for(e=this.currentDeviceIDs.length-1;e>=0;--e){n=this.currentDeviceIDs[e];var c=this.currentManagers[n],l=this.currentDevices[e];-1===o.indexOf(n)?(a.push(n),this.currentDevices.splice(e,1),this.currentDeviceIDs.splice(e,1)):c&&c.checkDevice(l)}s.forEach(this.emit.bind(this,"gamepadconnected")),a.forEach(this.emit.bind(this,"gamepaddisconnected"))}}},{key:"registerPad",value:function(e,t){this.currentManagers[e]=t}},{key:"pads",get:function(){return this.currentDevices}}]),t}(e.EventDispatcher),Ki=(new e.Vector2,function(e){function t(e,n){_t(this,t);for(var i=["FINGERS"],r=0;r<10;++r)i.push("X"+r),i.push("Y"+r),i.push("LX"+r),i.push("LY"+r),i.push("DX"+r),i.push("DY"+r);var o=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Touch",n,i,"touchend")),s=function(t,n,i){o.inPhysicalUse=!0;for(var r=i.changedTouches,s=Number.MAX_VALUE,a=0;a<r.length;++a)s=Math.min(s,r[a].identifier);for(var u=0;u<r.length;++u){var h=r[u],c=h.identifier-s,l=h.pageX,d=h.pageY;if(o.setAxis("X"+c,l),o.setAxis("Y"+c,d),o.setButton("FINGER"+h.identifier,t),n){var f=o.getAxis("LX"+c),p=o.getAxis("LY"+c);o.setAxis("DX"+c,l-f),o.setAxis("DY"+c,d-p)}o.setAxis("LX"+c,l),o.setAxis("LY"+c,d)}r=i.touches;for(var m=0,v=0;v<r.length;++v){m|=1<<r[v].identifier}o.setAxis("FINGERS",m),i.target===e&&i.preventDefault()};return e.addEventListener("touchstart",s.bind(o,!0,!1),!1),e.addEventListener("touchend",s.bind(o,!1,!0),!1),e.addEventListener("touchmove",s.bind(o,!0,!0),!1),o}return kt(t,e),wt(t,[{key:"update",value:function(e){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"update",this).call(this,e);for(var n=0;n<10;++n){var i=this.getAxis("X"+n),r=this.getAxis("Y"+n),o=this.getAxis("LX"+n),s=this.getAxis("LY"+n);this.setAxis("DX"+n,i-o),this.setAxis("DY"+n,r-s),this.setAxis("LX"+n,i),this.setAxis("LY"+n,r)}}}]),t}(Oi)),Yi=function(e){function t(e){function n(){var e="Failed to initialize speech engine. Reason: "+u.message;return console.error(e),!1}function i(){return available?!s&&(s=!0,a.start(),!0):n()}function r(){return available?!!s&&(a.stop(),!0):n()}_t(this,t);var o=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Speech",e)),s=!1,a=null,u=null;o.check=function(){this.enabled&&!s?i():!this.enabled&&s&&r()},o.getErrorMessage=function(){return u};try{a=window.SpeechRecognition?new SpeechRecognition:new webkitSpeechRecognition,a.continuous=!0,a.interimResults=!0,a.lang="en-US";var h=!1;a.addEventListener("start",function(){console.log("speech started"),command=""}.bind(o),!0),a.addEventListener("error",function(e){h=!0,console.log("speech error",e),s=!1,command="speech error"}.bind(o),!0),a.addEventListener("end",function(e){console.log("speech ended",e),s=!1,command="speech ended",h&&(h=!1,this.enable(!0))}.bind(o),!0),a.addEventListener("result",function(e){var t=[],n=e.results[e.resultIndex],i=0,r=-1;if(n&&n.isFinal)for(var o=0;o<n.length;++o){var s=n[o];s.confidence>i&&(i=s.confidence,r=o)}i>.85&&t.push(n[r].transcript.trim()),t=t.join(" "),t!==this.inputState&&(this.inputState.text=t),this.update()}.bind(o),!0),available=!0}catch(e){console.error(e),u=e,available=!1}return o}return kt(t,e),wt(t,[{key:"cloneCommand",value:function(e){return{name:e.name,preamble:e.preamble,keywords:t.maybeClone(e.keywords),commandUp:e.commandUp,disabled:e.disabled}}},{key:"evalCommand",value:function(e,t,n,i){if(n&&this.inputState.text)for(var r=0;r<e.keywords.length;++r)0!==this.inputState.text.indexOf(e.keywords[r])||!e.preamble&&e.keywords[r].length!==this.inputState.text.length||(t.pressed=!0,t.value=this.inputState.text.substring(e.keywords[r].length).trim(),this.inputState.text=null)}},{key:"enable",value:function(e,n){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"enable",this).call(this,e,n),this.check()}}],[{key:"maybeClone",value:function(e){return e&&e.slice()||[]}}]),t}(Oi),qi=function(){function e(t,n){_t(this,e),this.set(t,n)}return wt(e,[{key:"set",value:function(e,t){this.sample=e,this.timestampS=t}},{key:"copy",value:function(e){this.set(e.sample,e.timestampS)}}]),e}(),Xi=function(){function t(n){_t(this,t),this.kFilter=n,this.currentAccelMeasurement=new qi,this.currentGyroMeasurement=new qi,this.previousGyroMeasurement=new qi,this.filterQ=ht?new e.Quaternion(-1,0,0,1):new e.Quaternion(1,0,0,1),this.previousFilterQ=new e.Quaternion,this.previousFilterQ.copy(this.filterQ),this.accelQ=new e.Quaternion,this.isOrientationInitialized=!1,this.estimatedGravity=new e.Vector3,this.measuredGravity=new e.Vector3,this.gyroIntegralQ=new e.Quaternion}return wt(t,[{key:"addAccelMeasurement",value:function(e,t){this.currentAccelMeasurement.set(e,t)}},{key:"addGyroMeasurement",value:function(e,t){this.currentGyroMeasurement.set(e,t),Z(t-this.previousGyroMeasurement.timestampS)&&this.run_(),this.previousGyroMeasurement.copy(this.currentGyroMeasurement)}},{key:"run_",value:function(){if(!this.isOrientationInitialized)return this.accelQ=this.accelToQuaternion_(this.currentAccelMeasurement.sample),this.previousFilterQ.copy(this.accelQ),void(this.isOrientationInitialized=!0);var t=this.currentGyroMeasurement.timestampS-this.previousGyroMeasurement.timestampS,n=this.gyroToQuaternionDelta_(this.currentGyroMeasurement.sample,t);this.gyroIntegralQ.multiply(n),this.filterQ.copy(this.previousFilterQ),this.filterQ.multiply(n);var i=new e.Quaternion;i.copy(this.filterQ),i.inverse(),this.estimatedGravity.set(0,0,-1),this.estimatedGravity.applyQuaternion(i),this.estimatedGravity.normalize(),this.measuredGravity.copy(this.currentAccelMeasurement.sample),this.measuredGravity.normalize();var r=new e.Quaternion;r.setFromUnitVectors(this.estimatedGravity,this.measuredGravity),r.inverse();var o=new e.Quaternion;o.copy(this.filterQ),o.multiply(r),this.filterQ.slerp(o,1-this.kFilter),this.previousFilterQ.copy(this.filterQ)}},{key:"getOrientation",value:function(){return this.filterQ}},{key:"accelToQuaternion_",value:function(t){var n=new e.Vector3;n.copy(t),n.normalize();var i=new e.Quaternion;return i.setFromUnitVectors(new e.Vector3(0,0,-1),n),i.inverse(),i}},{key:"gyroToQuaternionDelta_",value:function(t,n){var i=new e.Quaternion,r=new e.Vector3;return r.copy(t),r.normalize(),i.setFromAxisAngle(r,t.length()*n),i}}]),t}(),Zi=e.Math.DEG2RAD,Ji=new e.Vector3,$i=function(){function t(n){_t(this,t),this.predictionTimeS=n,this.previousQ=new e.Quaternion,this.previousTimestampS=null,this.deltaQ=new e.Quaternion}return wt(t,[{key:"getPrediction",value:function(e,t,n,i){if(!this.previousTimestampS)return this.previousQ.copy(e),this.previousTimestampS=n,e;Ji.copy(t),Ji.normalize();var r=t.length();if(r<20*Zi)return i.copy(e),void this.previousQ.copy(e);var o=(this.previousTimestampS,r*this.predictionTimeS);this.deltaQ.setFromAxisAngle(Ji,o),i.copy(this.previousQ),i.multiply(this.deltaQ),this.previousQ.copy(e),this.previousTimestampS=n}}]),t}(),er=ot&<,tr=e.Math.DEG2RAD,nr=function(){function n(i){_t(this,n),i=Object.assign({K_FILTER:.98,PREDICTION_TIME_S:.04},i),this.deviceId="webvr-polyfill:fused",this.deviceName="VR Position Device (webvr-polyfill:fused)",this.accelerometer=new e.Vector3,this.gyroscope=new e.Vector3,window.addEventListener("devicemotion",this.onDeviceMotionChange_.bind(this)),window.addEventListener("orientationchange",this.onScreenOrientationChange_.bind(this)),this.filter=new Xi(i.K_FILTER),this.posePredictor=new $i(i.PREDICTION_TIME_S),this.filterToWorldQ=new e.Quaternion,ht?this.filterToWorldQ.setFromAxisAngle(new e.Vector3(1,0,0),Math.PI/2):this.filterToWorldQ.setFromAxisAngle(new e.Vector3(1,0,0),-Math.PI/2),this.inverseWorldToScreenQ=new e.Quaternion,this.worldToScreenQ=new e.Quaternion,this.originalPoseAdjustQ=new e.Quaternion,this.originalPoseAdjustQ.setFromAxisAngle(new e.Vector3(0,0,1),-window.orientation*tr),this.setScreenTransform_(),t()&&this.filterToWorldQ.multiply(this.inverseWorldToScreenQ),this.resetQ=new e.Quaternion,this.orientationOut_=new Float32Array(4),this.predictedQ=new e.Quaternion,this.previousTimestampS=null}return wt(n,[{key:"getPosition",value:function(){return null}},{key:"getOrientation",value:function(){var t=this.filter.getOrientation();this.posePredictor.getPrediction(t,this.gyroscope,this.previousTimestampS,this.predictedQ);var n=new e.Quaternion;return n.copy(this.filterToWorldQ),n.multiply(this.resetQ),n.multiply(this.predictedQ),n.multiply(this.worldToScreenQ),this.orientationOut_[0]=n.x,this.orientationOut_[1]=n.y,this.orientationOut_[2]=n.z,this.orientationOut_[3]=n.w,this.orientationOut_}},{key:"getPose",value:function(){return{position:this.getPosition(),orientation:this.getOrientation(),linearVelocity:null,linearAcceleration:null,angularVelocity:null,angularAcceleration:null}}},{key:"resetPose",value:function(){this.resetQ.copy(this.filter.getOrientation()),this.resetQ.x=0,this.resetQ.y=0,this.resetQ.z*=-1,this.resetQ.normalize(),t()&&this.resetQ.multiply(this.inverseWorldToScreenQ),this.resetQ.multiply(this.originalPoseAdjustQ)}},{key:"onDeviceMotionChange_",value:function(e){var t=e.accelerationIncludingGravity,n=e.rotationRate,i=e.timeStamp/1e3;er&&(i/=1e3),Z(i-this.previousTimestampS)?(this.accelerometer.set(-t.x,-t.y,-t.z),this.gyroscope.set(n.alpha,n.beta,n.gamma),(ht||er)&&this.gyroscope.multiplyScalar(tr),this.filter.addAccelMeasurement(this.accelerometer,i),this.filter.addGyroMeasurement(this.gyroscope,i)):null!==this.previousTimestampS&&console.warn("Invalid timestamps detected. Time step between successive gyroscope sensor samples is very small or not monotonic"),this.previousTimestampS=i}},{key:"onScreenOrientationChange_",value:function(e){this.setScreenTransform_()}},{key:"setScreenTransform_",value:function(){switch(this.worldToScreenQ.set(0,0,0,1),window.orientation){case 0:break;case 90:this.worldToScreenQ.setFromAxisAngle(new e.Vector3(0,0,1),-Math.PI/2);break;case-90:this.worldToScreenQ.setFromAxisAngle(new e.Vector3(0,0,1),Math.PI/2)}this.inverseWorldToScreenQ.copy(this.worldToScreenQ),this.inverseWorldToScreenQ.inverse()}}]),n}(),ir={LEFT:"left",RIGHT:"right"},rr=.03,or=0,sr=0,ar=function(e){function n(e){_t(this,n);var t=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"Google Cardboard"));return t.DOMElement=null,t.poseSensor_=e&&e.overrideOrientation||new nr(e),t}return kt(n,e),wt(n,null,[{key:"IPD",get:function(){return rr},set:function(e){rr=e}},{key:"NECK_LENGTH",get:function(){return or},set:function(e){or=e}},{key:"NECK_DEPTH",get:function(){return sr},set:function(e){sr=e}}]),wt(n,[{key:"_getPose",value:function(){return this.poseSensor_.getPose()}},{key:"resetPose",value:function(){this.poseSensor_.resetPose()}},{key:"getEyeParameters",value:function(e){var n=[rr,or,sr];e==ir.LEFT&&(n[0]*=-1);var i=screen.width,r=screen.height;if(this.DOMElement)i=this.DOMElement.clientWidth,r=this.DOMElement.clientHeight;else if(ht&&t()){var o=i;i=r,r=o}return i*=devicePixelRatio,r*=devicePixelRatio,{fieldOfView:{upDegrees:40,
leftDegrees:40,rightDegrees:40,downDegrees:40},offset:n,renderWidth:.5*i,renderHeight:r}}}]),n}(Si),ur=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window;_t(this,t);var n=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n.root=e,n.frames=[],n.startT=null,n}return kt(t,e),wt(t,[{key:"update",value:function(e){null===this.startT&&(this.startT=e)}},{key:"reset",value:function(){this.frames.splice(0),this.startT=null}},{key:"length",get:function(){return this.frames.length}}]),t}(e.EventDispatcher),hr=function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:window;_t(this,e),this.path=t;var i=t.split("."),r=i[i.length-1],o=function(e){for(var t=n,r=0;r<i.length-1;++r){var o=i[r];if(void 0===t[o]||null===t[o]){if(!e){t=null;break}/^\d+$/.test(i[r+1])?t[o]=[]:t[o]={}}t=t[o]}return t};this.get=function(){var e=o(!1);return e&&e[r]},this.set=function(e){var t=o(!0);t&&(t[r]=e)}},cr=function(e){function t(e,n,i){_t(this,t);var r=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,i));return r.value=n,r}return kt(t,e),wt(t,[{key:"write",value:function(){this.value!==this.get()&&this.set(this.value)}}]),t}(hr),lr=function(){function e(t,n){_t(this,e),this.t=t,this.records=n}return wt(e,null,[{key:"parse",value:function(t,n,i){for(var r=[{path:"",value:n}],o=[];r.length>0;){var s=r.shift(),a=s.path,u=s.value;if("object"===(void 0===u?"undefined":yt(u)))for(var h in u){var c=a;a.length>0&&(c+="."),c+=h,r.push({path:c,value:u[h]})}else o.push(new cr(a,u,i))}return new e(t,o)}}]),wt(e,[{key:"write",value:function(){for(var e=0;e<this.records.length;++e)this.records[e].write()}}]),e}(),dr=function(e){function t(e){_t(this,t);var n=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.frameIndex=-1,n}return kt(t,e),wt(t,[{key:"parse",value:function(e){this.load(JSON.parse(e))}},{key:"load",value:function(e){var t=[];for(var n in e)t.push(lr.parse(n,e[n],this.root));this.append(t)}},{key:"reset",value:function(){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"reset",this).call(this),this.frameIndex=-1}},{key:"update",value:function(e){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"update",this).call(this,e),e+=this.minT-this.startT;for(var n=this.frameIndex;this.frameIndex<this.frames.length-1&&e>=this.frames[this.frameIndex+1].t;)++this.frameIndex;if(this.frameIndex!==n&&0<=this.frameIndex&&this.frameIndex<this.frames.length){var i=this.frames[this.frameIndex];i.write(),this.emit("frame",i)}}},{key:"append",value:function(e){e&&(this.frames.push.apply(this.frames,e),this.minT=this.frames.map(function(e){return e.t}).reduce(function(e,t){return Math.min(e,t)},Number.MAX_VALUE))}},{key:"reverse",value:function(){var e=this.frames.map(function(e){return e.t}).reduce(function(e,t){return Math.max(e,t)},Number.MIN_VALUE);this.frames.reverse();for(var t=0;t<this.frames.length;++t){var n=this.frames[t];n.t=e-n.t+this.minT}}},{key:"done",get:function(){return this.frameIndex>=this.frames.length-1}}]),t}(ur),fr=function(){function e(t){_t(this,e);var n=null,i=null,r=null;Object.defineProperties(this,{displayName:{get:function(){return"Mock "+i},set:function(e){return i=e}}});var o={currentDisplay:this,currentEyeParams:{left:{fieldOfView:{downDegrees:null,leftDegrees:null,rightDegrees:null,upDegrees:null},renderWidth:null,renderHeight:null,offset:null},right:{fieldOfView:{downDegrees:null,leftDegrees:null,rightDegrees:null,upDegrees:null},renderWidth:null,renderHeight:null,offset:null}},currentPose:{timestamp:null,orientation:null,position:null}};Object.defineProperties(o.currentPose,{timestamp:{get:function(){return n},set:function(e){return n=e}},timeStamp:{get:function(){return n},set:function(e){return n=e}}});var s=new dr(o);s.load(t),s.update(0),this.requestAnimationFrame=function(e){return window.requestAnimationFrame(function(t){null===r&&(r=t),s.update(t-r),e(t)})},this.getPose=function(){return o.currentPose},this.getEyeParameters=function(e){return o.currentEyeParams[e]},this.resetPose=function(){}}return wt(e,[{key:"cancelAnimationFrame",value:function(e){window.cancelAnimationFrame(e)}}]),e}(),pr="getVRDisplays"in navigator,mr=[],vr=lt&&!st,gr=!1,yr=!1,_r=function(t){function n(t){_t(this,n);var i=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,"VR"));return i.options=t,i.displays=[],i._transformers=[],i.lastLastTimerDevice=null,i.lastTimerDevice=null,i.timerDevice=null,i.timer=null,i.currentDeviceIndex=-1,i.movePlayer=new e.Matrix4,i.stage=null,i.lastStageWidth=null,i.lastStageDepth=null,i.isStereo=!1,Ve(t),null!==i.options.nonstandardIPD&&(ar.IPD=i.options.nonstandardIPD),null!==i.options.nonstandardNeckLength&&(ar.NECK_LENGTH=i.options.nonstandardNeckLength),null!==i.options.nonstandardNeckDepth&&(ar.NECK_DEPTH=i.options.nonstandardNeckDepth),i.ready=navigator.getVRDisplays().then(function(e){return i.displays.push.apply(i.displays,e),i.connect(0),i.displays}),i}return kt(n,t),wt(n,null,[{key:"isStereoDisplay",value:function(e){var t=e.getEyeParameters("left"),n=e.getEyeParameters("right");return!(!t||!n)}}]),wt(n,[{key:"connect",value:function(e){this.currentDevice=null,this.currentDeviceIndex=e,this.currentPose=null,0<=e&&e<=this.displays.length&&(this.currentDevice=this.displays[e],this.currentPose=this.currentDevice.getPose(),this.isStereo=n.isStereoDisplay(this.currentDevice))}},{key:"requestPresent",value:function(e){if(this.currentDevice){var t=e;e[0].source;t instanceof Array||(t=[t]),this.isNativeMobileWebVR&&this.isStereo&&(t=t[0]);var n=this.currentDevice.requestPresent(t);return!lt&&ot||(n=n.then(re)),n}return Promise.reject("No display")}},{key:"cancel",value:function(){var e=this,t=null;return this.isPresenting?(t=this.currentDevice.exitPresent(),this.currentDevice=null,this.currentDeviceIndex=-1,this.currentPose=null):t=Promise.resolve(),this.isNativeMobileWebVR&&(t=t.then(Xt.unlock)),t.then(Zt.exit).catch(function(e){return console.warn(e)}).then(function(){return e.connect(0)})}},{key:"zero",value:function(){bt(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"zero",this).call(this),this.currentDevice&&this.currentDevice.resetPose()}},{key:"update",value:function(e){var t,i,r;this.currentDevice?(this.currentPose=this.currentDevice.getPose(),r=this.currentDevice.stageParameters):r=null,bt(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"update",this).call(this,e),r?(this.movePlayer.fromArray(r.sittingToStandingTransform),t=r.sizeX,i=r.sizeZ):(this.movePlayer.makeTranslation(0,this.options.avatarHeight,0),t=0,i=0);var o={matrix:this.movePlayer,sizeX:t,sizeZ:i};this.stage&&o.sizeX===this.stage.sizeX&&o.sizeZ===this.stage.sizeZ||(this.stage=o)}},{key:"submitFrame",value:function(){this.currentDevice&&this.currentDevice.submitFrame(this.currentPose)}},{key:"startAnimation",value:function(e){if(this.currentDevice)return this.lastLastTimerDevice=this.lastTimerDevice,this.lastTimerDevice=this.timerDevice,this.timerDevice=this.currentDevice,this.timer=this.currentDevice.requestAnimationFrame(e),this.timer}},{key:"cancelAnimation",value:function(){this.timerDevice&&this.timer&&(this.timerDevice.cancelAnimationFrame(this.timer),this.timer=null)}},{key:"getTransforms",value:function(e,t){if(this.currentDevice)return this._transformers[this.currentDeviceIndex]||(this._transformers[this.currentDeviceIndex]=new wr(this.currentDevice)),this.currentDevice.depthNear=e,this.currentDevice.depthFar=t,this._transformers[this.currentDeviceIndex].getTransforms(e,t)}},{key:"isNativeMobileWebVR",get:function(){return this.isNativeWebVR&&rt&<}},{key:"isNativeWebVR",get:function(){return this.currentDevice&&!this.currentDevice.isPolyfilled}},{key:"hasStage",get:function(){return this.stage&&this.stage.sizeX*this.stage.sizeZ>0}},{key:"canMirror",get:function(){return this.currentDevice&&this.currentDevice.capabilities.hasExternalDisplay}},{key:"isPolyfilled",get:function(){return this.currentDevice&&this.currentDevice.isPolyfilled}},{key:"isPresenting",get:function(){return this.currentDevice&&this.currentDevice.isPresenting}},{key:"hasOrientation",get:function(){return this.currentDevice&&this.currentDevice.capabilities.hasOrientation}},{key:"currentCanvas",get:function(){if(this.isPresenting){var e=this.currentDevice.getLayers();if(e.length>0)return e[0].source}return null}}]),n}(Hi),wr=function(){function t(e){_t(this,t),this.display=e}return wt(t,null,[{key:"makeTransform",value:function(n,i,r){return{translation:(new e.Vector3).fromArray(n.offset),projection:t.fieldOfViewToProjectionMatrix(n.fieldOfView,i,r),viewport:{left:0,top:0,width:n.renderWidth,height:n.renderHeight}}}},{key:"fieldOfViewToProjectionMatrix",value:function(t,n,i){var r=Math.tan(t.upDegrees*Math.PI/180),o=Math.tan(t.downDegrees*Math.PI/180),s=Math.tan(t.leftDegrees*Math.PI/180),a=Math.tan(t.rightDegrees*Math.PI/180),u=2/(s+a),h=2/(r+o),c=new e.Matrix4;return c.elements[0]=u,c.elements[1]=0,c.elements[2]=0,c.elements[3]=0,c.elements[4]=0,c.elements[5]=h,c.elements[6]=0,c.elements[7]=0,c.elements[8]=-(s-a)*u*.5,c.elements[9]=(r-o)*h*.5,c.elements[10]=-(n+i)/(i-n),c.elements[11]=-1,c.elements[12]=0,c.elements[13]=0,c.elements[14]=-2*i*n/(i-n),c.elements[15]=0,c}}]),wt(t,[{key:"getTransforms",value:function(e,n){var i=this.display.getEyeParameters("left"),r=this.display.getEyeParameters("right"),o=[t.makeTransform(i,e,n)];r&&o.push(t.makeTransform(r,e,n));for(var s=1;s<o.length;++s)o[s].viewport.left=o[s-1].viewport.left+o[s-1].viewport.width;return o}}]),t}(),br=function(t){function n(t,i,r,o,s,u,h,c){_t(this,n);var l=xt(this,(n.__proto__||Object.getPrototypeOf(n)).call(this));l.time=0,l.userName=t,l.peeringError=null,l.peering=!1,l.peered=!1,l.stage=i.clone(),l.stage.traverse(function(e){"AvatarBelt"===e.name?a(e,Be()):"AvatarHead"===e.name&&(l.head=e)}),l.nameObject=a(text3D(.1,t),r);var d=l.nameObject.geometry.boundingBox.max;return l.nameObject.rotation.set(0,Math.PI,0),l.nameObject.position.set(d.x/2,d.y,0),l.head.add(l.nameObject),l.dStageQuaternion=new e.Quaternion,l.dHeadPosition=new e.Vector3,l.dHeadQuaternion=new e.Quaternion,l.lastStageQuaternion=new e.Quaternion,l.lastHeadPosition=new e.Vector3,l.lastHeadQuaternion=new e.Quaternion,l.headPosition={arr1:[],arr2:[],last:l.lastHeadPosition,delta:l.dHeadPosition,curr:l.head.position},l.headQuaternion={arr1:[],arr2:[],last:l.lastHeadQuaternion,delta:l.dHeadQuaternion,curr:l.head.quaternion},l.audioChannel=null,l.audioElement=null,l.audioStream=null,l.gain=null,l.panner=null,l.analyzer=null,l}return kt(n,t),wt(n,[{key:"setAudio",value:function(e,t){t instanceof Element?(this.audioElement=t,mn.setAudioProperties(this.audioElement),this.audioStream=e.context.createMediaElementSource(this.audioElement)):(this.audioElement=mn.setAudioStream(t,"audio"+this.userName),this.audioStream=e.context.createMediaStreamSource(t)),this.gain=e.context.createGain(),this.panner=e.context.createPanner(),this.audioStream.connect(this.gain),this.gain.connect(this.panner),this.panner.connect(e.mainVolume),this.panner.coneInnerAngle=180,this.panner.coneOuterAngle=360,this.panner.coneOuterGain=.1,this.panner.panningModel="HRTF",this.panner.distanceModel="exponential"}},{key:"unpeer",value:function(){this.audioChannel&&(this.audioChannel.close(),this.audioElement&&(document.body.removeChild(this.audioElement),this.panner&&(this.panner.disconnect(),this.gain.disconnect(),this.audioStream.disconnect())))}},{key:"_updateV",value:function(e,t,i){e.curr.toArray(e.arr1),e.delta.toArray(e.arr2);for(var r=0;r<e.arr1.length;++r)i&&(e.arr2[r]*=n.FADE_FACTOR),e.arr1[r]+=e.arr2[r]*t;e.curr.fromArray(e.arr1),e.delta.fromArray(e.arr2)}},{key:"_predict",value:function(e,t,i){e.delta.fromArray(t,i),e.delta.toArray(e.arr1),e.curr.toArray(e.arr2);for(var r=0;r<e.arr1.length;++r)e.arr1[r]=(e.arr1[r]-e.arr2[r])*n.NETWORK_DT_INV;e.delta.fromArray(e.arr1)}},{key:"update",value:function(e){this.time+=e;var t=this.time>=n.NETWORK_DT;this._updateV(this.headPosition,e,t),this._updateV(this.headQuaternion,e,t),this.stage.rotation.setFromQuaternion(this.headQuaternion.curr),this.stage.rotation.x=0,this.stage.rotation.z=0,this.stage.position.copy(this.headPosition.curr),this.stage.position.y=0,this.panner&&(this.panner.setPosition(this.stage.position.x,this.stage.position.y,this.stage.position.z),this.panner.setOrientation(Math.sin(this.stage.rotation.y),0,Math.cos(this.stage.rotation.y)))}},{key:"setState",value:function(e){this.time=0,this._predict(this.headPosition,e,1),this._predict(this.headQuaternion,e,4)}},{key:"toString",value:function(e){return this.stage.position.curr.toString(e)+" "+this.headPosition.curr.toString(e)}}]),n}(e.EventDispatcher);br.FADE_FACTOR=.5,br.NETWORK_DT=.1,br.NETWORK_DT_INV=1/br.NETWORK_DT;var kr=function(e){function t(e,n,i,r){_t(this,t);var o=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o.localUser=e,o.audio=n,o.factories=i,o.options=r,o.lastNetworkUpdate=0,o.oldState=[],o.users={},o.waitForLastUser=Promise.resolve(),o._socket=null,o.userName=null,o.microphone=null,o.audioHeap={},o}return kt(t,e),wt(t,[{key:"update",value:function(e){if(this._socket&&0===this.deviceIndex&&(this.lastNetworkUpdate+=e,this.lastNetworkUpdate>=br.NETWORK_DT)){this.lastNetworkUpdate-=br.NETWORK_DT;for(var t=0;t<this.localUser.newState.length;++t)if(this.oldState[t]!==this.localUser.newState[t]){this._socket.emit("userState",this.localUser.newState),this.oldState=this.localUser.newState;break}}for(var n in this.users){var i=this.users[n];i.update(e),this.audioHeap[n]&&(i.setAudio(this.audio,this.audioHeap[n]),delete this.audioHeap[n])}}},{key:"updateUser",value:function(e){var t=e[0];if(t!==this.userName){var n=this.users[t];n&&n.setState(e)}else this.deviceIndex>0&&(this.localUser.stage.position.fromArray(e,1),this.localUser.stage.quaternion.fromArray(e,4),this.localUser.head.position.fromArray(e,8),this.localUser.head.quaternion.fromArray(e,11))}},{key:"connect",value:function(e,t){this.userName=t.toLocaleUpperCase(),this.microphone||(this.microphone=navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).catch(console.warn.bind(console,"Can't get audio"))),this._socket||(this._socket=e,this._socket.on("userList",this.listUsers.bind(this)),this._socket.on("userJoin",this.addUser.bind(this)),this._socket.on("deviceAdded",this.addDevice.bind(this)),this._socket.on("deviceIndex",this.setDeviceIndex.bind(this)),this._socket.on("chat",this.receiveChat.bind(this)),this._socket.on("userState",this.updateUser.bind(this)),this._socket.on("userLeft",this.removeUser.bind(this)),this._socket.on("connection_lost",this.lostConnection.bind(this)),this._socket.emit("listUsers"),this._socket.emit("getDeviceIndex"))}},{key:"disconnect",value:function(){this.userName=null,this._socket.close(),this._socket=null}},{key:"addUser",value:function(e,t){console.log("User %s logging on.",e[0]);var n=e[0],i=new br(n,this.factories.avatar,this.options.foregroundColor,this.options.disableWebRTC,this.options.webRTC,this.microphone,this.userName,t);this.users[n]=i,this.updateUser(e),this.emit("addavatar",i)}},{key:"removeUser",value:function(e){console.log("User %s logging off.",e);var t=this.users[e];t&&(t.peered&&t.unpeer(),delete this.users[e],this.emit("removeavatar",t))}},{key:"listUsers",value:function(e){for(Object.keys(this.users).forEach(this.removeUser.bind(this));e.length>0;)this.addUser(e.shift(),!0);this.emit("authorizationsucceeded")}},{key:"receiveChat",value:function(e){console.log("chat",e)}},{key:"lostConnection",value:function(){this.deviceIndex=null}},{key:"addDevice",value:function(e){console.log("addDevice",e)}},{key:"setDeviceIndex",value:function(e){this.deviceIndex=e}},{key:"setAudioFromUser",value:function(e,t){this.audioHeap[e]=t}}]),t}(e.EventDispatcher),xr=new fi("PlainText",[["newlines",/(?:\r\n|\r|\n)/]]),Sr=new e.Vector3,Er=.4,Mr=function(){function t(n){var i=this;_t(this,t),this.enabled=!0,this._environment=n,this._startPoint=new e.Vector3,this._moveDistance=0,this._start=this._start.bind(this),this._exit=this._exit.bind(this),this._move=this._move.bind(this),this._end=this._end.bind(this),n.ground.on("exit",this._exit).on("gazecancel",this._exit).on("gazecomplete",this._exit).on("pointerend",this._exit).on("pointerstart",this._start).on("gazestart",this._start).on("pointermove",this._move).on("gazemove",this._move).on("select",this._end),this.disk=H(Er,128,3).colored(16711680,{unshaded:!0}).named("disk").addTo(n.scene),this.disk.geometry.computeBoundingBox(),this.disk.geometry.vertices.forEach(function(e){e.y=.1*(e.y-i.disk.geometry.boundingBox.min.y)}),this.disk.geometry.computeBoundingBox(),this.disk.visible=!1}return wt(t,[{key:"_exit",value:function(e){this.disk.visible=!1}},{key:"_start",value:function(e){this.enabled&&(this._updatePosition(e),this.disk.visible=!0,this._moveDistance=0)}},{key:"_move",value:function(e){this.enabled&&(this._updatePosition(e),this.disk.visible=this._moveDistance<.5)}},{key:"_end",value:function(e){this.enabled&&(this._updatePosition(e),this._moveDistance<.5&&this._environment.teleport(this.disk.position))}},{key:"_updatePosition",value:function(e){this._startPoint.copy(this.disk.position),this.disk.position.copy(e.hit.point).sub(this._environment.head.position);var t=this.disk.position.x*this.disk.position.x+this.disk.position.z*this.disk.position.z;if(t>25){var n=Math.sqrt(t),i=5/n,r=this.disk.position.y;this.disk.position.y=0,this.disk.position.multiplyScalar(i),this.disk.position.y=r}this.disk.position.add(this._environment.head.position);var o=Sr.copy(this.disk.position).sub(this._startPoint).length();this._moveDistance+=o}}]),t}(),Tr=[.5,.25,.333333,.5,1],Or=[16768964,15783358,15650483,14792857,15057560,16768178,15054983,15048819,15179373,14389349,13538940,13006934,12217417,10842711,15780041,14526624,12156013,11040108,11363410,6043702,13337666,12415548,7356729,10716778,8848384,7405825,4390912,5963777,3157550],Pr={NONE:0,VERYLOW:1,LOW:2,MEDIUM:3,HIGH:4,MAXIMUM:Tr.length-1},Cr=["Dahlia","Zinnia","Camellia","Ren","Lotus","Azalea","Kunal","Saffron","Jessamine","Basil","Indigo","Violet","Iris","Holly","Yarrow","Hazel","Cypress","Amaranth","Aster","Emerald","Ash","Boxwood","Birchwood","Ebony","Forsythia","Hawthorn","Hemlock","Locust","Juniper","Linden","Magnolia","Laurel","Oak","Alder","Sycamore","Blackhaw"],Ar={PIXEL_SCALES:Tr,SKINS:Or,SYS_FONTS:"-apple-system, '.SFNSText-Regular', 'San Francisco', 'Roboto', 'Segoe UI', 'Helvetica Neue', 'Lucida Grande', sans-serif",NAMES:Cr,Quality:Pr};console.info("[PrimroseVR v0.31.4]:> see https://www.primrosevr.com for more information.");var Rr=.001,Dr=new e.Vector3,Lr=new e.Vector3,Nr=new e.Euler,Ir=new e.Quaternion,Fr=Math.PI/3,Vr=function(t){function i(t){_t(this,i);var r=xt(this,(i.__proto__||Object.getPrototypeOf(i)).call(this));r.options=Object.assign({},i.DEFAULTS,t),r.options.foregroundColor=r.options.foregroundColor||function(e){var t=e.clone(),n=t.getHSL();for(n.h=n.h+.5,n.l=1-n.l;n.h>1;)n.h-=1;return t.setHSL(n.h,n.s,n.l),t}(new e.Color(r.options.backgroundColor)).getHex(),r.deltaTime=1,r.network=null,null!==r.options.nonstandardIPD&&(r.options.nonstandardIPD*=.5),r.audioQueue=[],r.zero=function(){if(!r.lockMovement){for(var e=0;e<r.managers.length;++e)r.managers[e].zero();r.quality===Pr.NONE&&(r.quality=Pr.HIGH)}};var o=0,h=function(e){if((e*=Rr)>0){e=1/Math.round(1/e),r.deltaTime=Math.min(r.deltaTime,e);var t=e/r.deltaTime;t>1?(o+=t,t>10&&(t=1)):o>0&&(o-=.1),o>=10&&(r.deltaTime=e,o=0),E(e);for(var n=0;n<t;++n){var i=r.hasGamepad;r.gamepadMgr&&r.gamepadMgr.poll();for(var s=0;s<r.managers.length;++s)r.managers[s].update(e);!i&&r.hasGamepad&&(r.Mouse.inPhysicalUse=!1),r.head.showPointer=r.VR.hasOrientation&&r.options.showHeadPointer,r.mousePointer.visible=r.VR.isPresenting,r.mousePointer.showPointer=!r.hasMotionControllers;for(var a=0,u=0,h=0,c=0,l=0;l<r.managers.length;++l){var f=r.managers[l];f.enabled&&("Mouse"!==f.name&&(a+=f.getValue("heading")),u+=f.getValue("pitch"),h+=f.getValue("strafe"),c+=f.getValue("drive"))}if(r.hasMouse||r.hasTouch){var p=null;if(r.VR.hasOrientation){p=r.mousePointer.rotation.y;var m=Fr*Math.floor(p/Fr+.5);0!==m&&(r.Mouse.commands.U.offset-=r.Mouse.getValue("U")-1),p=m+2*r.Mouse.commands.U.offset}else p=r.Mouse.getValue("heading");a+=p}r.VR.hasOrientation&&(u=0),Nr.set(u,a,0,"YXZ"),r.stage.quaternion.setFromEuler(Nr),r.velocity.set(h,0,c),Ir.copy(r.head.quaternion),Nr.setFromQuaternion(Ir),Nr.x=0,Nr.z=0,Ir.setFromEuler(Nr),r.moveStage(Lr.copy(r.velocity).multiplyScalar(e).applyQuaternion(Ir).add(r.head.position)),r.stage.position.y=r.ground.getHeightAt(r.stage.position)||0,r.stage.position.y+=r.options.avatarHeight;for(var v=0;v<r.motionDevices.length;++v)r.motionDevices[v].posePosition.y-=r.options.avatarHeight;r.stage.updateMatrix(),r.matrix.multiplyMatrices(r.stage.matrix,r.VR.stage.matrix);for(var g=0;g<r.motionDevices.length;++g)r.motionDevices[g].updateStage(r.matrix);for(var y=0;y<r.pointers.length;++y)r.pointers[y].update();if(r.newState=[],r.head.updateMatrix(),r.stage.rotation.x=0,r.stage.rotation.z=0,r.stage.quaternion.setFromEuler(r.stage.rotation),r.stage.updateMatrix(),r.head.position.toArray(r.newState,0),r.head.quaternion.toArray(r.newState,3),0===n){P();for(var _=null,w=0;w<r.pointers.length;++w)_=r.pointers[w].resolvePicking(r.scene);for(var b=0;b<r.managers.length;++b)r.managers[b].userActionHandlers=_;r.ground.moveTo(r.head.position),r.sky.position.copy(r.head.position),d()}try{r.emit("update")}catch(e){console.error("User update errored",e)}0===n&&r.network&&r.network.update(e)}}};r.turns=new ln(0);var c=new e.Euler,l=-Math.PI/4,d=(Math.PI,function(e){var t=r.vicinity.position.y,n=r.options.vicinityFollowRate,i=1-n;r.vicinity.position.lerp(r.head.position,n),r.vicinity.position.y=t,c.setFromQuaternion(r.head.quaternion),r.turns.radians=c.y,c.set(l,r.turns.radians,0,"YXZ"),r.ui.quaternion.setFromEuler(c),r.ui.position.y=r.ui.position.y*i+r.head.position.y*n}),f=function e(t){var n=t-v;v=t,h(n),p(),A(e)},p=function(){r.camera.position.set(0,0,0),r.camera.quaternion.set(0,0,0,1),r.audio.setPlayer(r.head.mesh),r.renderer.clear(!0,!0,!0);for(var e=r.VR.getTransforms(r.options.nearPlane,r.options.nearPlane+r.options.drawDistance),t=0;e&&t<e.length;++t){C(t);var n=e[t],i=n.viewport;r.renderer.setViewport(i.left*y,i.top*y,i.width*y,i.height*y),r.camera.projectionMatrix.copy(n.projection),r.mousePointer.unproject&&r.mousePointer.unproject.getInverse(n.projection),r.camera.translateOnAxis(n.translation,1),r.renderer.render(r.scene,r.camera),r.camera.translateOnAxis(n.translation,-1)}r.VR.submitFrame()},m=function(){var e=r.options.nearPlane,t=e+r.options.drawDistance,n=r.VR&&r.VR.getTransforms(e,t);if(n){for(var i=0,o=0,s=0;s<n.length;++s)i+=n[s].viewport.width,o=Math.max(o,n[s].viewport.height);r.mousePointer.setSize(i,o),i=Math.floor(i*y),o=Math.floor(o*y),r.renderer.domElement.width=i,r.renderer.domElement.height=o,r.timer||p()}},v=0,g=(new e.Quaternion,new e.Vector3,new e.Vector3,{scene:r.options.sceneModel,avatar:r.options.avatarModel,button:r.options.button&&"string"==typeof r.options.button.model&&r.options.button.model,font:r.options.font}),y=1;r.factories={avatar:null};var _=ni.loadObjects(g,r.options.progress.thunk).then(function(t){window.text3D=function(t,n,i){var r=new e.TextGeometry(i,{font:t,size:n,height:n/5,curveSegments:2});return r.computeBoundingSphere(),r.computeBoundingBox(),r}.bind(window,t.font),t.scene&&T(t.scene),t.avatar&&(r.factories.avatar=new ni(t.avatar)),t.button&&(r.buttonFactory=new Zn(t.button,r.options.button.options))}).catch(function(e){return console.error(e)}).then(function(){return r.buttonFactory=r.buttonFactory||Zn.DEFAULT});r.speech=new Sn(r.options.speech),r.audio=new mn,r.options.ambientSound&&r.audio.load3DSound(r.options.ambientSound,!0,-1,1,-1).then(function(e){e.source instanceof MediaElementAudioSourceNode||(e.volume.gain.value=.1,e.source.start())}).catch(console.error.bind(console,"Audio3D loadSource"));var w=null;w="complete"===document.readyState?Promise.resolve("already"):new Promise(function(e,t){document.addEventListener("readystatechange",function(t){"complete"===document.readyState&&e("had to wait for it")},!1)}),r.music=new bn(r.audio),r.currentControl=null;var b=null,k=null,x=null,S=null;r.fadeOut=function(){return x?Promise.reject("Currently fading in."):(b||(r.fader.visible=!0,r.fader.material.opacity=0,r.fader.material.needsUpdate=!0,b=new Promise(function(e,t){return k=function(t){b=null,k=null,e(t)}})),b)},r.fadeIn=function(){return b?Promise.reject("Currently fading out."):(x||(x=new Promise(function(e,t){return S=function(t){x=null,S=null,r.fader.visible=!1,e(t)}})),x)};var E=function(e){if(b||x){var t=r.fader.material,n=r.options.fadeRate*e;t.needsUpdate=!0,b?(t.opacity+=n,1<=t.opacity&&(t.opacity=1,k())):(t.opacity-=n,t.opacity<=0&&(t.opacity=0,S()))}};r.teleportAvailable=!0,r.transition=function(e,t,n){return n?(e(),Promise.resolve()):!t||t()?r.fadeOut().then(e).then(r.fadeIn).catch(console.warn.bind(console,"Error transitioning")):void 0},r.teleport=function(e,t){return r.transition(function(){return r.moveStage(e)},function(){return r.teleportAvailable&&Dr.copy(e).sub(r.head.position).length()>.2},t)};var M=function e(){r.currentControl&&(r.currentControl.removeEventListener("blur",e),r.Keyboard.enabled=!0,r.Mouse.commands.pitch.disabled=r.Mouse.commands.heading.disabled=r.VR.isPresenting,r.currentControl.blur(),r.currentControl=null)};r.consumeEvent=function(e){var t=e.hit&&e.hit.object,n="exit"===e.type||"NORMAL_ESCAPE"===e.cmdName;("select"===e.type||n)&&(t!==r.currentControl||n)&&(M(),!n&&t.isSurface&&(r.currentControl=t,r.currentControl.focus(),r.currentControl.addEventListener("blur",M),r.currentControl.lockMovement&&(r.Keyboard.enabled=!1,r.Mouse.commands.pitch.disabled=r.Mouse.commands.heading.disabled=!r.VR.isPresenting))),t?t.dispatchEvent(e):r.currentControl&&r.currentControl.dispatchEvent(e),r.dispatchEvent(e)},r.options.scene=r.scene=r.options.scene||new e.Scene,r.options.useFog&&(r.scene.fog=new e.FogExp2(r.options.backgroundColor,1/Math.sqrt(r.options.drawDistance))),r.camera=new e.PerspectiveCamera(75,1,r.options.nearPlane,r.options.nearPlane+r.options.drawDistance),r.sky=new oi(r.options).addTo(r.scene),r.ground=new ri(r.options).addTo(r.scene),r.teleporter=new Mr(r),r.vicinity=n().named("Vicinity").addTo(r.scene),r.ui=n().named("UI").addTo(r.vicinity);var T=function(e){return e.buttons=[],e.traverse(function(t){t.isButton&&e.buttons.push(new qn(t.parent,t.name)),t.name&&(e[t.name]=t)}),r.scene.add.apply(r.scene,e.children),r.scene.traverse(function(e){r.options.disableDefaultLighting&&e.material&&(e.material.map?s(e,e.material.map,{unshaded:!0}):a(e,e.material.color.getHex(),{unshaded:!0})),e.name&&(r.scene[e.name]=e)}),e.Camera&&(r.camera.position.copy(e.Camera.position),r.camera.quaternion.copy(e.Camera.quaternion)),e},O=null;r.timer=0;var A=function(e){O=r.VR.currentDevice||window,null!==r.timer&&(r.timer=O.requestAnimationFrame(e))};r.goFullScreen=function(e,t){if("Gaze"!==t){var n=null;return n="force"===t||r.VR.canMirror||r.VR.isNativeWebVR?r.renderer.domElement:r.options.fullScreenElement,r.VR.connect(e),r.VR.requestPresent([{source:n}]).catch(function(e){return console.error("whaaat",e)}).then(function(){return n.focus()})}},r.addAvatar=function(e){console.log(e),r.scene.add(e.stage),r.scene.add(e.head)},r.removeAvatar=function(e){r.scene.remove(e.stage),r.scene.remove(e.head)},Zt.addChangeListener(function(e){r.VR.isPresenting&&!Zt.isActive&&r.cancelVR()});var R=function(e){var t=!!r.VR.isPresenting,n=(t?"remove":"add")+"Button";r.Mouse[n]("dx",0),r.Mouse[n]("dy",0),r.Mouse.commands.U.disabled=r.Mouse.commands.V.disabled=t&&!r.VR.isStereo,r.Mouse.commands.heading.scale=t?-1:1,r.Mouse.commands.pitch.scale=t?-1:1,t||r.cancelVR(),m()},D=!0;if(r.start=function(){D&&r.ready.then(function(){r.audio.start(),v=performance.now()*Rr,r.VR.startAnimation(f)})},r.stop=function(e){r.VR.timer&&(D=D&&!0===e,r.VR.stopAnimation(),r.audio.stop(),D||console.log("stopped"))},r.pause=r.stop.bind(r,!0),window.addEventListener("vrdisplaypresentchange",R,!1),window.addEventListener("resize",m,!1),window.addEventListener("blur",r.pause,!1),window.addEventListener("stop",r.stop,!1),window.addEventListener("focus",r.start,!1),document.addEventListener("amazonPlatformReady",function(){document.addEventListener("pause",r.pause,!1),document.addEventListener("resume",r.start,!1)},!1),w=w.then(function(){r.options.renderer?r.renderer=r.options.renderer:(r.renderer=new e.WebGLRenderer({canvas:he(r.options.canvasElement,"canvas",HTMLCanvasElement),context:r.options.context,antialias:r.options.antialias,alpha:!0,logarithmicDepthBuffer:!1}),r.renderer.autoClear=!1,r.renderer.sortObjects=!0,r.renderer.setClearColor(r.options.backgroundColor),r.renderer.domElement.parentElement||document.body.appendChild(r.renderer.domElement)),r.options.fullScreenElement=document.querySelector(r.options.fullScreenElement)||r.renderer.domElement;for(var t=0,i=document.querySelectorAll("[tabIndex]"),o=0;o<i.length;++o)t=Math.max(t,i[o].tabIndex);if(r.renderer.domElement.tabIndex=t+1,r.renderer.domElement.addEventListener("webglcontextlost",r.pause,!1),r.renderer.domElement.addEventListener("webglcontextrestored",r.start,!1),r.managers=[],r.newState=[],r.pointers=[],r.motionDevices=[],r.velocity=new e.Vector3,r.matrix=new e.Matrix4,r.options.disableKeyboard||(r.addInputManager(new Vi(r,{strafeLeft:{buttons:[-In.A,-In.LEFTARROW]},strafeRight:{buttons:[In.D,In.RIGHTARROW]},strafe:{commands:["strafeLeft","strafeRight"]},driveForward:{buttons:[-In.W,-In.UPARROW]},driveBack:{buttons:[In.S,In.DOWNARROW]},drive:{commands:["driveForward","driveBack"]},select:{buttons:[In.ENTER]},dSelect:{buttons:[In.ENTER],delta:!0},zero:{buttons:[In.Z],metaKeys:[-In.CTRL,-In.ALT,-In.SHIFT,-In.META],commandUp:r.emit.bind(r,"zero")}})),r.Keyboard.operatingSystem=r.options.os,r.Keyboard.codePage=r.options.language),r.addInputManager(new Ki(r.options.fullScreenElement,{U:{axes:["X0"],min:0,max:2,offset:0},V:{axes:["Y0"],min:0,max:2},buttons:{axes:["FINGERS"]},dButtons:{axes:["FINGERS"],delta:!0},heading:{axes:["DX0"],integrate:!0},pitch:{axes:["DY0"],integrate:!0,min:.5*-Math.PI,max:.5*Math.PI}})),r.addInputManager(new Ui(r.options.fullScreenElement,{U:{axes:["X"],min:0,max:2,offset:0},V:{axes:["Y"],min:0,max:2},buttons:{axes:["BUTTONS"]},dButtons:{axes:["BUTTONS"],delta:!0},_dx:{axes:["X"],delta:!0,scale:.25},dx:{buttons:[0],commands:["_dx"]},heading:{commands:["dx"],integrate:!0},_dy:{axes:["Y"],delta:!0,scale:.25},dy:{buttons:[0],commands:["_dy"]},pitch:{commands:["dy"],integrate:!0,min:.5*-Math.PI,max:.5*Math.PI}})),r.Touch.addEventListener("activate",function(e){return r.Mouse.inPhysicalUse=!1}),r.Mouse.addEventListener("activate",function(e){return r.Touch.inPhysicalUse=!1}),r.addInputManager(new _r(r.options)),r.motionDevices.push(r.VR),!r.options.disableGamepad&&Qi.isAvailable&&(r.gamepadMgr=new Qi,r.gamepadMgr.addEventListener("gamepadconnected",function(e){var t=Wi.ID(e),n=null;if("Unknown"!==t&&"Rift"!==t)if(Wi.isMotionController(e)){for(var i=0,o=0;o<r.managers.length;++o)n=r.managers[o],n.currentPad&&n.currentPad.id===e.id&&++i;n=new Wi(r.gamepadMgr,e,i,{buttons:{axes:["BUTTONS"]},dButtons:{axes:["BUTTONS"],delta:!0},zero:{buttons:[Wi.VIVE_BUTTONS.GRIP_PRESSED],commandUp:r.emit.bind(r,"zero")}}),r.addInputManager(n),r.motionDevices.push(n);var s=8*(r.motionDevices.length-2),h=255<<s,c=16711680>>s,l=new Nn(t+"Pointer",h,1,c,[n],null,r.options);l.add(a(u(.1,.025,.2),h,{emissive:c})),l.route(Nn.EVENTS,r.consumeEvent.bind(r)),r.pointers.push(l),r.scene.add(l),r.emit("motioncontrollerfound",n)}else n=new Wi(r.gamepadMgr,e,0,{buttons:{axes:["BUTTONS"]},dButtons:{axes:["BUTTONS"],delta:!0},strafe:{axes:["LSX"],deadzone:.2},drive:{axes:["LSY"],deadzone:.2},heading:{axes:["RSX"],scale:-1,deadzone:.2,integrate:!0},dHeading:{commands:["heading"],delta:!0},pitch:{axes:["RSY"],scale:-1,
deadzone:.2,integrate:!0},zero:{buttons:[Wi.XBOX_ONE_BUTTONS.BACK],commandUp:r.emit.bind(r,"zero")}}),r.addInputManager(n),r.mousePointer.addDevice(n,n)}),r.gamepadMgr.addEventListener("gamepaddisconnected",r.removeInputManager.bind(r))),r.stage=n(),r.head=new Nn("GazePointer",16776960,255,.8,[r.VR],[r.Mouse,r.Touch,r.Keyboard],r.options).addTo(r.scene),r.head.route(Nn.EVENTS,r.consumeEvent.bind(r)),r.head.rotation.order="YXZ",r.head.useGaze=r.options.useGaze,r.pointers.push(r.head),r.mousePointer=new Nn("MousePointer",16711680,65280,1,[r.Mouse,r.Touch],null,r.options),r.mousePointer.route(Nn.EVENTS,r.consumeEvent.bind(r)),r.mousePointer.unproject=new e.Matrix4,r.pointers.push(r.mousePointer),r.head.add(r.mousePointer),r.VR.ready.then(function(e){return e.forEach(function(e,t){window.addEventListener("vrdisplayactivate",function(n){if(n.display===e){var i=function e(){window.removeEventListener("vrdisplaydeactivate",e),r.cancelVR()};window.addEventListener("vrdisplaydeactivate",i,!1),r.goFullScreen(t)}},!1)})}),r.fader=a(u(1,1,1),r.options.backgroundColor,{opacity:0,useFog:!1,transparent:!0,unshaded:!0,side:e.BackSide}),r.fader.visible=!1,r.head.add(r.fader),!r.options.disableKeyboard){var s=function(e){e.returnValue=!1},h=function(e){r.VR.isPresenting&&(e.keyCode!==In.ESCAPE||r.VR.isPolyfilled||r.cancelVR()),r.Keyboard.consumeEvent(e),r.consumeEvent(e)},c=function(e){r.Keyboard.consumeEvent(e),r.consumeEvent(e)},l=function(e){return function(t){r.currentControl&&(r.currentControl[e]?r.currentControl[e](t):console.warn("Couldn't find %s on %o",e,r.currentControl))}};window.addEventListener("keydown",h,!1),window.addEventListener("keyup",c,!1),window.addEventListener("paste",l("readClipboard"),!1),window.addEventListener("wheel",l("readWheel"),!1);var d=function(e){if(r.lockMovement){var t=r.Keyboard.operatingSystem.makeCommandName(e,r.Keyboard.codePage);"CUT"!==t&&"COPY"!==t||(p.style.display="block",p.focus())}},f=function(e){r.currentControl&&(r.currentControl[e.type+"SelectedText"](e),e.returnValue||e.preventDefault(),p.style.display="none",r.currentControl.focus())},p=he("primrose-surrogate-textarea","textarea",HTMLTextAreaElement),m=xe("primrose-surrogate-textarea-container",p);m.style.position="absolute",m.style.overflow="hidden",m.style.width=0,m.style.height=0,p.addEventListener("beforecopy",s,!1),p.addEventListener("copy",f,!1),p.addEventListener("beforecut",s,!1),p.addEventListener("cut",f,!1),document.body.insertBefore(m,document.body.children[0]),window.addEventListener("beforepaste",s,!1),window.addEventListener("keydown",d,!0)}return r.head.add(r.camera),Promise.all(r.managers.map(function(e){return e.ready}).filter(U))}),r._readyParts=[r.sky.ready,r.ground.ready,_,w],r.ready=Promise.all(r._readyParts).then(function(){r.renderer.domElement.style.cursor="default",r.options.enableShadows&&r.sky.sun&&(r.renderer.shadowMap.enabled=!0,r.renderer.shadowMap.type=e.PCFSoftShadowMap),r.VR.displays.forEach(function(e){void 0!==e.DOMElement&&(e.DOMElement=r.renderer.domElement)}),r.options.fullScreenButtonContainer&&r.insertFullScreenButtons(r.options.fullScreenButtonContainer),r.VR.connect(0),r.options.progress.hide(),r.emit("ready")}),r.start=function(){r.ready.then(function(){r.audio.start(),v=performance.now()*Rr,A(f)})},r.stop=function(){O&&(O.cancelAnimationFrame(r.timer),r.audio.stop(),r.timer=null)},Object.defineProperties(r,{quality:{get:function(){return r.options.quality},set:function(e){0<=e&&e<Tr.length&&(r.options.quality=e,y=Tr[e]),r.ready.then(m)}}}),r.quality=r.options.quality,window.alert.toString().indexOf("native code")>-1){var L=function(e,t){return t||(t=function(){}),function(){this.VR&&this.VR.isPresenting?t():e.apply(window,arguments)}.bind(r)};window.alert=L(window.alert),window.confirm=L(window.confirm),window.prompt=L(window.prompt)}return r.start(),r}return kt(i,t),wt(i,[{key:"connect",value:function(e,t){return this.network||(this.network=new kr(this,this.audio,this.factories,this.options),this.network.addEventListener("addavatar",this.addAvatar),this.network.addEventListener("removeavatar",this.removeAvatar)),this.network&&this.network.connect(e,t)}},{key:"disconnect",value:function(){return this.network&&this.network.disconnect()}},{key:"addInputManager",value:function(e){for(var t=this.managers.length-1;t>=0;--t)this.managers[t].name===e.name&&this.managers.splice(t,1);this.managers.push(e),this[e.name]=e}},{key:"removeInputManager",value:function(e){var t=this[e],n=this.managers.indexOf(t);n>-1&&(this.managers.splice(n,1),delete this[e]),console.log("removed",t)}},{key:"moveStage",value:function(e){Lr.copy(e).sub(this.head.position),this.stage.position.add(Lr)}},{key:"cancelVR",value:function(){this.VR.cancel(),this.Touch.commands.U.offset=this.Mouse.commands.U.offset=0}},{key:"setAudioFromUser",value:function(e,t){if(this.audioQueue.push([e,t]),this.network)for(;this.audioQueue.length>0;)this.network.setAudioFromUser.apply(this.network,this.audioQueue.shift())}},{key:"insertFullScreenButtons",value:function(e){var t=this,n=document.querySelector(e),i=function(e,t,i){var r=document.createElement("button");return r.type="button",r.title=e,r.appendChild(document.createTextNode(t)),r.addEventListener("click",i,!1),n.appendChild(r),r},r=this.displays.map(function(e,n){if(!ht||_r.isStereoDisplay(e)){var r=t.goFullScreen.bind(t,n),o=i(e.displayName,e.displayName,r),s=_r.isStereoDisplay(e);return o.className=s?"stereo":"mono",o}}).filter(U);return/(www\.)?primrosevr.com/.test(document.location.hostname)||this.options.disableAdvertising||r.push(i("Primrose","✿",function(){return open("https://www.primrosevr.com","_blank")})),r}},{key:"lockMovement",get:function(){return this.currentControl&&this.currentControl.lockMovement}},{key:"displays",get:function(){return this.VR.displays}},{key:"fieldOfView",get:function(){var e=this.VR.currentDevice,t=[e&&e.getEyeParameters("left"),e&&e.getEyeParameters("right")].filter(U);if(t.length>0)return t.reduce(function(e,t){return Math.max(e,t.fieldOfView.upDegrees+t.fieldOfView.downDegrees)},0)},set:function(e){this.options.defaultFOV=Mi.DEFAULT_FOV=e}},{key:"currentTime",get:function(){return this.audio.context.currentTime}},{key:"hasMotionControllers",get:function(){return!!(this.Vive_0&&this.Vive_0.enabled&&this.Vive_0.inPhysicalUse||this.Vive_1&&this.Vive_1.enabled&&this.Vive_1.inPhysicalUse)}},{key:"hasGamepad",get:function(){return!!(this.Gamepad_0&&this.Gamepad_0.enabled&&this.Gamepad_0.inPhysicalUse)}},{key:"hasMouse",get:function(){return!!(this.Mouse&&this.Mouse.enabled&&this.Mouse.inPhysicalUse)}},{key:"hasTouch",get:function(){return!!(this.Touch&&this.Touch.enabled&&this.Touch.inPhysicalUse)}}]),i}(e.EventDispatcher);Vr.DEFAULTS={antialias:!0,quality:Pr.MAXIMUM,useGaze:lt,useFog:!1,avatarHeight:1.65,walkSpeed:2,disableKeyboard:!1,enableShadows:!1,shadowMapSize:2048,shadowCameraSize:15,shadowRadius:1,progress:window.Preloader||{thunk:function(){},hide:function(){},resize:function(){}},fadeRate:5,vicinityFollowRate:.02,gravity:9.8,gazeLength:1.5,disableMirroring:!1,disableDefaultLighting:!1,backgroundColor:11517951,skyTexture:null,groundTexture:null,nearPlane:.01,drawDistance:100,defaultFOV:Mi.DEFAULT_FOV,ambientSound:null,canvasElement:"frontBuffer",renderer:null,context:null,scene:null,nonstandardNeckLength:null,nonstandardNeckDepth:null,showHeadPointer:!0,nonstandardIPD:null,disableAdvertising:!1};var Ur=0,jr=function(e){function t(e,n){_t(this,t),name=n&&n.id||"Primrose.Controls.Model["+Ur+++"]";var i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,name,n));return i._file=e,i._model=null,i}return kt(t,e),wt(t,[{key:"_ready",get:function(){var e=this;return bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"_ready",this).then(function(){return i(e._file,function(){return ni.loadModel(e._file,e.options.type,e.options.progress)}).then(function(t){return e._model=t.clone(),e.add(e._model),e})})}}]),t}(Nt),Br=function t(n,i,r,o,s,a,u){var h=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"center";_t(this,t),n=n.replace(/\r\n/g,"\n");var c=n.split("\n"),l=1e3*i,d=l*c.length,f=document.createElement("canvas"),p=f.getContext("2d");p.font=l+"px Arial";var m=p.measureText(n).width;f.width=m,f.height=d,p.font=.8*l+"px Arial","transparent"!==o&&(p.fillStyle=o,p.fillRect(0,0,f.width,f.height)),p.fillStyle=r;for(var v=0;v<c.length;++v)p.fillText(c[v],0,v*l);var g=new e.Texture(f);g.needsUpdate=!0;var y=new e.MeshBasicMaterial({map:g,transparent:"transparent"===o,useScreenCoordinates:!1,color:16777215,shading:e.FlatShading}),_=new e.PlaneGeometry(i*m/l,i*c.length);_.computeBoundingBox(),_.computeVertexNormals();var w=new e.Mesh(_,y);return"left"===h?s-=_.boundingBox.min.x:"right"===h&&(s+=_.boundingBox.min.x),w.position.set(s,a,u),w},zr=1,Hr=.8,Wr=zr/10,Gr=1-(1-Hr)/10,Qr=function(){function t(n,i){_t(this,t),n=n||16777215,i=i||0;var r=u(zr,Wr,Wr);this.totalBar=r.colored(i,{unshaded:!0,side:e.BackSide}),this.valueBar=r.colored(n,{unshaded:!0}).scl(0,Hr,Hr).addTo(this.totalBar),this.fileState=null,this.reset()}return wt(t,[{key:"reset",value:function(){this.fileState={},this.value=0}},{key:"onProgress",value:function(e){var t=e.target.responseURL||e.target.currentSrc;if(t&&void 0!==e.loaded){this.fileState[t]||(this.fileState[t]={});var n=this.fileState[t];n.loaded=e.loaded,n.total=e.total}var i=0,r=0;for(var o in this.fileState){var s=this.fileState[o];i+=s.total,r+=s.loaded}this.value=i>0?r/i:0}},{key:"visible",get:function(){return this.totalBar.visible},set:function(e){this.totalBar.visible=e}},{key:"position",get:function(){return this.totalBar.position}},{key:"quaternion",get:function(){return this.totalBar.quaternion}},{key:"value",get:function(){return this.valueBar.scale.x/Gr},set:function(e){this.valueBar.scale.x=e*Gr,this.valueBar.position.x=-zr*(1-e)*Gr/2}}]),t}(),Kr=new hi("Text Line input commands"),Yr=0,qr=function(e){function t(e){_t(this,t);var n=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,Object.assign({},{id:"Primrose.Controls.TextInput["+Yr+++"]",padding:5,singleLine:!0,disableWordWrap:!0,hideLineNumbers:!0,hideScrollBars:!0,tabWidth:1,tokenizer:xr,commands:Kr}),e));return n.passwordCharacter=n.options.passwordCharacter,n}return kt(t,e),wt(t,[{key:"drawText",value:function(e,n,i,r){if(this.passwordCharacter){for(var o="",s=0;s<n.length;++s)o+=this.passwordCharacter;n=o}bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"drawText",this).call(this,e,n,i,r)}},{key:"value",get:function(){return bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"value",this)},set:function(e){e=e||"",e=e.replace(/\r?\n/g,""),St(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"value",e,this)}},{key:"selectedText",get:function(){return bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"selectedText",this)},set:function(e){e=e||"",e=e.replace(/\r?\n/g,""),St(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"selectedText",e,this)}}]),t}(gi),Xr={Button2D:Yn,Button3D:qn,ButtonFactory:Zn,Entity:Nt,Ground:ri,Image:$n,Label:Qn,Model:jr,PlainText:Br,Progress:Qr,Sky:oi,Surface:Hn,TextBox:gi,TextInput:qr,Video:zt},Zr={CardboardVRDisplay:ar,frameDataFromPose:we,install:Ve,MockVRDisplay:fr,StandardMonitorVRDisplay:Mi,VRDisplay:Si,VRFrameData:ki},Jr={cascadeElement:he,findEverything:ze,makeHidingContainer:xe},$r={fixGeometry:M,InsideSphereGeometry:It,loadTexture:o,ModelFactory:ni},eo={del:He,delObject:We,get:ae,getBuffer:ue,getObject:Ae,getText:Ge,post:Qe,postObject:Ke,XHR:se},to=function(e){function t(e,n){_t(this,t);var i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,"Location",e,["LONGITUDE","LATITUDE","ALTITUDE","HEADING","SPEED"]));return i.options=Object.assign({},t.DEFAULTS,n),i.available=!!navigator.geolocation,i.available&&navigator.geolocation.watchPosition(i.setState.bind(i),function(){return i.available=!1},i.options),i}return kt(t,e),wt(t,[{key:"setState",value:function(e){this.inPhysicalUse=!0;for(var t in e.coords){var n=t.toUpperCase();this.axisNames.indexOf(n)>-1&&this.setAxis(n,e.coords[t])}this.update()}}]),t}(Oi);to.DEFAULTS={enableHighAccuracy:!0,maximumAge:3e4,timeout:25e3};var no={Gamepad:Wi,InputProcessor:Oi,Keyboard:Vi,Location:to,Mouse:Ui,PoseInputProcessor:Hi,Speech:Yi,Touch:Ki,VR:_r},io=[{urls:["stun:stun.l.google.com:19302","stun:stun1.l.google.com:19302","stun:stun2.l.google.com:19302","stun:stun3.l.google.com:19302","stun:stun4.l.google.com:19302"]}],ro=0,oo=function(e){function t(e,n,i,r,o,s){_t(this,t);var a=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this)),u=++ro,h=function(e,t,n){if(t<5){for(var i=["%s: "+n,t],r=3;r<arguments.length;++r)i.push(arguments[r]);console[e].apply(console,i)}return arguments[3]};a.myResult=null,a.theirResult=null,a._timeout=null,a._log=h.bind(null,"log"),a._error=h.bind(null,"error",0,""),a.fromUserName=n,a.fromUserIndex=i,a.toUserName=r,a.toUserIndex=o,a.rtc=null,a.goFirst=!s,a.progress={offer:{created:!1,received:!1},answer:{created:!1,received:!1}},window.addEventListener("unload",a.close.bind(a));var c=null,l=null,d=function(e){a._log(2,"Tearing down event handlers"),a.stopTimeout(),a.rtc.onsignalingstatechange=null,a.rtc.oniceconnectionstatechange=null,a.rtc.onnegotiationneeded=null,a.rtc.onicecandidate=null,a.teardown(),e&&a.close()},f=function(e){return a.complete&&(a._log(1,"Timeout avoided."),d(),c()),e};return a.peering_answer=function(e){return a._log(1,"description",e),a.recordProgress(e.item,"received"),a.rtc.setRemoteDescription(new RTCSessionDescription(e.item)).then(f).catch(a.peering_error)},a.descriptionCreated=function(e){return a.recordProgress(e,"created"),a.rtc.setLocalDescription(e).then(function(){return a.emit(e.type,e)}).then(f).catch(a.peering_error)},a.peering_error=function(e){a._error(e),a.emit("cancel",e),a._log(1,"Timeout avoided, but only because of an error."),d(!0),l(e)},a.peering_cancel=function(e){a._error(e),a._log(1,"Timeout avoided, but only because of an error."),d(!0),l(e)},a.peering_offer=function(e){a._log(1,"offer",e);var t=a.peering_answer(e);if(t)return t.then(function(){return a.rtc.createAnswer()}).then(a.descriptionCreated)},a.peering_ice=function(e){a._log(1,"ice",e);var t=new RTCIceCandidate(e.item);return a.rtc.addIceCandidate(t).catch(a._error)},a.peering_peer=function(e){a._log(1,"peering",e),a.hasRTC.then(function(){return a.issueRequest()})},a.hasRTC=Primrose.HTTP.getObject(e).then(function(e){e.iceServers.push.apply(e.iceServers,io);for(var t=e.iceServers.length-1;t>=0;--t){var n=e.iceServers[t];n.urls&&0!==n.urls.length?(n.url&&!n.urls&&(n.urls=[n.url],delete n.url),n.username&&n.credential&&(n.credentialType="token")):e.iceServers.splice(t,1)}e.iceCandidatePoolSize=100,a._log(1,e),a.rtc=new RTCPeerConnection(e),a.rtc.onsignalingstatechange=function(e){return a._log(1,"[%s] Signal State: %s",u,a.rtc.signalingState)},a.rtc.oniceconnectionstatechange=function(e){return a._log(1,"[%s] ICE Connection %s, Gathering %s",u,a.rtc.iceConnectionState,a.rtc.iceGatheringState)},a.rtc.onnegotiationneeded=function(e){return a.createOffer().then(a.descriptionCreated)},a.rtc.onicecandidate=function(e){e.candidate&&a.emit("ice",e.candidate)}}),a.ready=a.hasRTC.then(function(){return new Promise(function(e,t){c=e,l=t,a.emit("peer")})}),a}return kt(t,e),wt(t,[{key:"emit",value:function(e,n){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"emit",this).call(this,e,{fromUserName:this.fromUserName,fromUserIndex:this.fromUserIndex,toUserName:this.toUserName,toUserIndex:this.toUserIndex,item:n})}},{key:"startTimeout",value:function(){null===this._timeout&&(this._log(1,"Timing out in "+Math.floor(30)+" seconds."),this._timeout=setTimeout(this.peering_error.bind(this,"Gave up waiting on the peering connection."),3e4))}},{key:"stopTimeout",value:function(){null!==this._timeout&&(clearTimeout(this._timeout),this._timeout=null)}},{key:"createOffer",value:function(){return this.rtc.createOffer(this.offerOptions)}},{key:"recordProgress",value:function(e,t){this._log(2,"Logging progress [%s]: %s %s -> true",e.type,t,this.progress[e.type][t]),this.progress[e.type][t]=!0}},{key:"close",value:function(){this.rtc&&"closed"!==this.rtc.signalingState&&(this.rtc.close(),this.rtc=null)}},{key:"teardown",value:function(){throw new Error("Not implemented.")}},{key:"issueRequest",value:function(){throw new Error("Not implemented")}},{key:"complete",get:function(){return!this.rtc||"closed"===this.rtc.signalingState}}]),t}(e.EventDispatcher);oo.PEERING_EVENTS=["peer","cancel","offer","ice","answer"];var so=!0,ao=function(e){function t(e,n,i,r,o){_t(this,t),console.log("attempting to peer audio from %s to %s. %s goes first.",n,i,o?i:n);var s=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n,0,i,0,o));return s.outAudio=r,s.inAudio=null,s.startTimeout(),s}return kt(t,e),wt(t,[{key:"issueRequest",value:function(){var e=this;console.log("going first",this.goFirst);var t=function(){e._log(0,"adding stream",e.outAudio,e.rtc.addTrack),e.outAudio.then(function(t){e.rtc.addTrack?t.getAudioTracks().forEach(function(n){return e.rtc.addTrack(n,t)}):e.rtc.addStream(t),at&&e.createOffer().then(e.descriptionCreated)})},n=function(n){e.inAudio=n,e.goFirst||(e._log(0,"Creating the second stream from %s to %s",e.fromUserName,e.toUserName),e.stopTimeout(),e._log(1,"Restarting timeout."),e.startTimeout(),t())};"ontrack"in this.rtc?this.rtc.ontrack=function(e){return n(e.streams[0])}:this.rtc.onaddstream=function(e){return n(e.stream)},this.goFirst&&(this._log(0,"Creating the first stream from %s to %s",this.fromUserName,this.toUserName),t())}},{key:"teardown",value:function(){"ontrack"in this.rtc?this.rtc.ontrack=null:this.rtc.onaddstream=null}},{key:"createOffer",value:function(){return bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"createOffer",this).call(this).then(Ye)}},{key:"complete",get:function(){return this.goFirst?this._log(1,"[First]: offer created: %s, answer recv: %s -> offer recv: %s -> answer created: %s.",this.progress.offer.created,this.progress.answer.received,this.progress.offer.received,this.progress.answer.created,this.rtc.signalingState):this._log(1,"[Second]: offer recv: %s, answer created: %s -> offer created: %s -> answer recv: %s.",this.progress.offer.received,this.progress.answer.created,this.progress.offer.created,this.progress.answer.received,this.rtc.signalingState),bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"complete",this)||this.progress.offer.received&&this.progress.offer.created&&this.progress.answer.received&&this.progress.answer.created}}]),t}(oo),uo=function(e){function t(e,n,i,r,o,s){_t(this,t);var a=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n,i,r,o,s));return a.dataChannel=null,a}return kt(t,e),wt(t,[{key:"issueRequest",value:function(){var e=this;this.goFirst?(this._log(0,"Creating data channel"),this.dataChannel=this.rtc.createDataChannel()):this.ondatachannel=function(t){e._log(0,"Receving data channel"),e.dataChannel=t.channel}}},{key:"teardown",value:function(){this.rtc.ondatachannel=null}},{key:"complete",get:function(){return this.goFirst?this._log(1,"[First]: OC %s -> AR %s.",this.progress.offer.created,this.progress.answer.received):this._log(1,"[Second]: OC %s -> AR %s.",this.progress.offer.created,this.progress.answer.received),bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"complete",this)||this.goFirst&&this.progress.offer.created&&this.progress.answer.received||!this.goFirst&&this.progress.offer.received&&this.progress.answer.created}}]),t}(oo),ho={AudioChannel:ao,DataChannel:uo,Manager:kr,RemoteUser:br,WebRTCSocket:oo},co={color:Be,ID:Je,int:je,item:$e,number:Ue,steps:et,vector:tt},lo=function(e){function t(e,n){_t(this,t);var i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return i.read=function(){var e=i.get();return e!==i.lastValue?(i.lastValue=e,new cr(i.path,e,n)):null},i}return kt(t,e),t}(hr),fo=function(e){function t(e,n){_t(this,t);var i=xt(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,n));return i.watchers=e.map(function(e){return new lo(e,i.root)}),i}return kt(t,e),wt(t,[{key:"update",value:function(e){bt(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"update",this).call(this,e);var n=this.watchers.map(function(e){return e.read()}).filter(function(e){return e}),i=new lr(e-this.startT,n);this.frames.push(i),this.emit("frame",i)}},{key:"toJSON",value:function(){var e={};return this.frames.forEach(function(t){e[t.t]={};for(var n=0;n<t.records.length;++n){var i=t.records[n];if(null!==i.value){for(var r=i.path.split("."),o=r[r.length-1],s=e[t.t],a=0;a<r.length-1;++a){var u=r[a];void 0!==s[u]&&null!==s[u]||(/^\d+$/.test(r[a+1])?s[u]=[]:s[u]={}),s=s[u]}s[o]=i.value}}}),JSON.stringify(e)}}]),t}(ur),po={Automator:ur,Frame:lr,Obj:hr,Player:dr,Record:cr,Recorder:fo,Watcher:lo},mo={BasicTextInput:hi,CommandPack:ui,TextEditor:ci,TextInput:Kr},vo=eval,go=new fi("BASIC",[["newlines",/(?:\r\n|\r|\n)/],["lineNumbers",/^\d+\s+/],["startLineComments",/^REM\s/],["strings",/"(?:\\"|[^"])*"/],["strings",/'(?:\\'|[^'])*'/],["numbers",/-?(?:(?:\b\d*)?\.)?\b\d+\b/],["keywords",/\b(?:RESTORE|REPEAT|RETURN|LOAD|LABEL|DATA|READ|THEN|ELSE|FOR|DIM|LET|IF|TO|STEP|NEXT|WHILE|WEND|UNTIL|GOTO|GOSUB|ON|TAB|AT|END|STOP|PRINT|INPUT|RND|INT|CLS|CLK|LEN)\b/],["keywords",/^DEF FN/],["operators",/(?:\+|;|,|-|\*\*|\*|\/|>=|<=|=|<>|<|>|OR|AND|NOT|MOD|\(|\)|\[|\])/],["identifiers",/\w+\$?/]]),yo=go.tokenize;go.tokenize=function(e){return yo.call(this,e.toUpperCase())},go.interpret=function(e,t,n,i,r,o,s,a){function u(e){return new di(e.toString(),"numbers")}function h(e){return new di('"'+e.replace("\n","\\n").replace('"','\\"')+'"',"strings")}function c(e){if(e&&e.length>0){var t=e.shift();if(t){if(ie.hasOwnProperty(t.value))return ie[t.value](e);if(!isNaN(t.value))return v([t]);if(q[t.value]||e.length>0&&"operators"===e[0].type&&"="===e[0].value)return e.unshift(t),I(e);l("Unknown command. >>> "+t.value)}}return y()}function l(e){i("At line "+z[U]+": "+e)}function d(e){var t=z[e],n=B[t];return n&&n.slice()}function f(e){for(var t="",n=0;n<e.length;++n){var i=e[n],r=0;if("identifiers"===i.type&&"function"!=typeof q[i.value]&&n<e.length-1&&"("===e[n+1].value)for(var o=n+1;o<e.length;++o){var s=e[o];if("("===s.value?(0===r&&(s.value="["),++r):")"===s.value?0===--r&&(s.value="]"):","===s.value&&1===r&&(s.value="]["),0===r)break}t+=i.value}try{return vo(t)}catch(n){console.error(n),console.debug(e.join(", ")),console.error(t),l(n.message+": "+t)}}function p(e){var t,n=[],i=[n],r=0;for(t=0;t<e.length;++t){var o=e[t];"("===o.value?++r:")"===o.value&&--r,0===r&&","===o.value?(n=[],i.push(n)):n.push(o)}for(t=0;t<i.length;++t){n=i[t];var s=n.shift();if("identifiers"===s.type){var a,u=null;if(s=s.value,"("===n[0].value&&")"===n[n.length-1].value){var h=[];for(a=1;a<n.length-1;++a)"numbers"===n[a].type&&h.push(0|n[a].value);if(0===h.length)u=[];else{u=new Array(h[0]);var c=[u];for(a=1;a<h.length;++a)for(var d=h[a],f=0,p=c.length;f<p;++f)for(var m=c.shift(),v=0;v<m.length;++v)m[v]=new Array(d),a<h.length-1&&c.push(m[v])}}return q[s]=u,!0}l("Identifier expected: "+s.value)}}function m(e){var t="\n",i=0;e=e.map(function(n,r){return n=n.clone(),"operators"===n.type&&(","===n.value?0===i&&(n.value='+ ", " + '):";"===n.value?(n.value='+ " "',r<e.length-1?n.value+=" + ":t=""):"("===n.value?++i:")"===n.value&&--i),n});var r=f(e);return void 0===r&&(r=""),n(r+t),!0}function v(e){var t=parseFloat(f(e));for(U=-1;U<z.length-1&&z[U+1]<t;)++U;return!0}function g(e){var t,n=-1,i=-1;for(t=0;t<e.length;++t)"keywords"===e[t].type&&"THEN"===e[t].value?n=t:"keywords"===e[t].type&&"ELSE"===e[t].value&&(i=t);if(-1===n)l("Expected THEN clause.");else{var r=e.slice(0,n);for(t=0;t<r.length;++t){var o=r[t];"operators"===o.type&&"="===o.value&&(o.value="==")}var s,a;if(-1===i?s=e.slice(n+1):(s=e.slice(n+1,i),a=e.slice(i+1)),f(r))return c(s);if(a)return c(a)}return!0}function y(){return n("PROGRAM COMPLETE - PRESS RETURN TO FINISH."),t(function(){j=!0,a&&a()}),!1}function _(e){return e.push(V),e.push(u(z[U])),I(e)}function w(e){var n=e.pop();return e.length>0&&m(e),t(function(e){e=e.toUpperCase();var t=null;t=isNaN(e)?h(e):u(e),f([n,V,t]),r&&r()}),!1}function b(e){var t=[],n=null,i=[];try{for(;e.length>0&&("keywords"!==e[0].type||"GOTO"!==e[0].value);)t.push(e.shift());if(e.length>0){e.shift();for(var r=0;r<e.length;++r){var o=e[r];"operators"===o.type&&","===o.value||i.push(o)}if(0<=(n=f(t)-1)&&n<i.length)return v([i[n]])}}catch(e){console.error(e)}return!0}function k(e){return Q.push(u(z[U+1])),v(e)}function x(){return Q.push(u(z[U])),!0}function S(e){var t=!0,n=Q.pop();return n&&e&&(t=v([n])),t}function E(e){return S(!f(e))}function M(e){for(J=U+1;J<z.length;++J){if(d(J)[0].value===e)return J}return z.length}function T(e){return f(e)?Q.push(u(z[U])):U=M("WEND"),!0}function O(e){var t=z[U],n=[],i=[],r=[],o=[],s=[n,i,r,o],a=0,h=0;for(h=0;h<e.length;++h){var l=e[h];l.value===ne[a]?(0===a&&n.push(l),++a):s[a].push(l)}var d=1;o.length>0&&(d=f(o)),void 0===K[t]&&(K[t]=f(i));var p=f(r);return K[t]<=p?(n.push(u(K[t])),c(n),K[t]+=d,Q.push(u(z[U]))):(delete K[t],U=M("NEXT")),!0}function P(){return S(!0)}function C(e){return s(f(e)).then(r),!1}function A(){return!0}function R(e){for(;e.length>0;){var t=e.shift();"operators"!==t.type&&G.push(t.value)}return!0}function D(e){if(0===G.length){c(d(M("DATA")))}var t=G[Y];return++Y,e.push(V),e.push(u(t)),I(e)}function L(){return Y=0,!0}function N(e){for(var t=e.shift().value,n="",i="",r=!0,o=0;o<e.length;++o){var s=e[o];"operators"===s.type&&"="===s.value?r=!1:r?n+=s.value:i+=s.value}t="FN"+t;var a="(function "+t+n+"{ return "+i+"; })";return q[t]=vo(a),!0}function I(e){return f(e),!0}for(var F=this.tokenize(e),V=new di("=","operators"),U=0,j=!1,B={},z=[],H=[],W=[H],G=[],Q=[],K={},Y=0,q={INT:function(e){return 0|e},RND:function(){return Math.random()},CLK:function(){return Date.now()/36e5},LEN:function(e){return e.length},LINE:function(){return z[U]},TAB:function(e){for(var t="",n=0;n<e;++n)t+=" ";return t},POW:function(e,t){return Math.pow(e,t)}},X={OR:"||",AND:"&&",NOT:"!",MOD:"%","<>":"!="};F.length>0;){var Z=F.shift();"newlines"===Z.type?(H=[],W.push(H)):"regular"!==Z.type&&"comments"!==Z.type&&(Z.value=X[Z.value]||Z.value,H.push(Z))}for(var J=0;J<W.length;++J){var $=W[J];if($.length>0){var ee=z[z.length-1],te=$.shift();if("lineNumbers"!==te.type&&($.unshift(te),void 0===ee&&(ee=-1),te=u(ee+1)),te=parseFloat(te.value),ee&&te<=ee)throw new Error("expected line number greater than "+ee+", but received "+te+".");$.length>0&&(z.push(te),B[te]=$)}}var ne=["=","TO","STEP"],ie={DIM:p,LET:I,PRINT:m,GOTO:v,IF:g,INPUT:w,END:y,STOP:y,REM:A,"'":A,CLS:o,ON:b,GOSUB:k,RETURN:P,LOAD:C,DATA:R,READ:D,RESTORE:L,REPEAT:x,UNTIL:E,"DEF FN":N,WHILE:T,WEND:P,FOR:O,NEXT:P,LABEL:_};return function(){if(!j)for(var e=!0;e;){var t=d(U);e=c(t),++U}}};var _o=new fi("HTML",[["newlines",/(?:\r\n|\r|\n)/],["startBlockComments",/(?:<|<)!--/],["endBlockComments",/--(?:>|>)/],["stringDelim",/("|')/],["numbers",/-?(?:(?:\b\d*)?\.)?\b\d+\b/],["keywords",/(?:<|<)\/?(html|base|head|link|meta|style|title|address|article|aside|footer|header|h1|h2|h3|h4|h5|h6|hgroup|nav|section|dd|div|dl|dt|figcaption|figure|hr|li|main|ol|p|pre|ul|a|abbr|b|bdi|bdo|br|cite|code|data|dfn|em|i|kbd|mark|q|rp|rt|rtc|ruby|s|samp|small|span|strong|sub|sup|time|u|var|wbr|area|audio|img|map|track|video|embed|object|param|source|canvas|noscript|script|del|ins|caption|col|colgroup|table|tbody|td|tfoot|th|thead|tr|button|datalist|fieldset|form|input|label|legend|meter|optgroup|option|output|progress|select|textarea|details|dialog|menu|menuitem|summary|content|element|shadow|template|acronym|applet|basefont|big|blink|center|command|content|dir|font|frame|frameset|isindex|keygen|listing|marquee|multicol|nextid|noembed|plaintext|spacer|strike|tt|xmp)\b/],["members",/(\w+)=/]]),wo=new fi("TestResults",[["newlines",/(?:\r\n|\r|\n)/,!0],["numbers",/(\[)(o+)/,!0],["numbers",/(\d+ succeeded), 0 failed/,!0],["numbers",/^ Successes:/,!0],["functions",/(x+)\]/,!0],["functions",/[1-9]\d* failed/,!0],["functions",/^ Failures:/,!0],["comments",/(\d+ms:)(.*)/,!0],["keywords",/(Test results for )(\w+):/,!0],["strings",/ \w+/,!0]]),bo={Basic:go,Grammar:fi,HTML:_o,JavaScript:pi,PlainText:xr,TestResults:wo},ko={Linux:Ci,macOS:Ai,OperatingSystem:Pi,Windows:Ci},xo=function e(t,n){function i(e){e.selectionStart=e.selectionEnd=e.value.length,e.scrollIntoView(e.frontCursor)}function r(){g.running&&(s(),g.running=!1,v&&(t.tokenizer=l,t.value=c),i(t))}function o(){return n.selectionStart=n.selectionEnd=0,n.value="",!0}function s(){if(m.length>0){for(var e=m.split("\n"),t=0;t<f&&e.length>0;++t)p.push(e.shift());e.length>0&&p.push(" ----- more -----"),m=e.join("\n")}}function a(e){h=e,g.waitingForInput=!0,s()}function u(e){m+=e}_t(this,e),n=n||t;var h=null,c=null,l=null,d=0,f=40,p=[],m="",v=t===n,g=this;this.running=!1,this.waitingForInput=!1,this.sendInput=function(e){if(m.length>0)s();else{n.keyDown(e);var t=n.value.substring(d);h(t.trim()),h=null,this.waitingForInput=!1}},this.execute=function(){if(f=10,(l=t.tokenizer)&&l.interpret){this.running=!0;var e,i=function(){g.running&&setTimeout(e,1)};c=t.value,e=l.interpret(c,a,u,u,i,o,this.loadFile.bind(this),r),n.tokenizer=xr,o(),i()}},this.loadFile=function(e){return Ge(e.toLowerCase()).then(function(e){return ct&&(e=e.replace("CTRL+SHIFT+SPACE","CMD+OPT+E")),t.value=c=e,e})},this.update=function(){p.length>0&&(n.value+=p.shift()+"\n",i(n),d=n.selectionStart)}},So={name:"Dark",fontFamily:"'Droid Sans Mono', 'Consolas', 'Lucida Console', 'Courier New', 'Courier', monospace",cursorColor:"white",fontSize:16,lineNumbers:{foreColor:"white"},regular:{backColor:"black",foreColor:"#c0c0c0",currentRowBackColor:"#202020",selectedBackColor:"#404040",unfocused:"rgba(0, 0, 255, 0.25)"},strings:{foreColor:"#aa9900",fontStyle:"italic"},regexes:{foreColor:"#aa0099",fontStyle:"italic"},numbers:{foreColor:"green"},comments:{foreColor:"yellow",fontStyle:"italic"},keywords:{foreColor:"cyan"},functions:{foreColor:"brown",fontWeight:"bold"},members:{foreColor:"green"},error:{foreColor:"red",fontStyle:"underline italic"}},Eo={Dark:So,Default:Wn},Mo={CodePages:Fi,CommandPacks:mo,Cursor:ai,Grammars:bo,OperatingSystems:ko,Point:Un,Rectangle:Bn,Rule:li,Size:jn,Terminal:xo,Themes:Eo,Token:di},To={Teleporter:Mr},Oo={Angle:ln,Audio:En,BrowserEnvironment:Vr,Constants:Ar,Controls:Xr,Displays:Zr,DOM:Jr,Graphics:$r,HTTP:eo,Input:no,Keys:In,Network:ho,Pointer:Nn,Random:co,Replay:po,Text:Mo,Tools:To};return Object.assign(window,vt,Wt,en),Oo});