text: /**
   * skylark-sphere - A version of sphere that ported to running on skylarkjs
   * @author Hudaokeji, Inc.
   * @version v0.9.0
   * @link https://github.com/skylark-integration/skylark-sphere/
   * @license MIT
   */
  define(["./ctoc","../PSVUtils","../PSVAnimation"],function(t,e,o){"use strict";return t.prototype._bindEvents=function(){window.addEventListener("resize",this),this.config.mousemove&&(this.hud.container.style.cursor="move",this.config.mousemove_hover?(this.hud.container.addEventListener("mouseenter",this),this.hud.container.addEventListener("mouseleave",this)):(this.hud.container.addEventListener("mousedown",this),window.addEventListener("mouseup",this)),this.hud.container.addEventListener("touchstart",this),window.addEventListener("touchend",this),this.hud.container.addEventListener("mousemove",this),this.hud.container.addEventListener("touchmove",this)),t.SYSTEM.fullscreenEvent&&document.addEventListener(t.SYSTEM.fullscreenEvent,this),this.config.mousewheel&&this.hud.container.addEventListener(t.SYSTEM.mouseWheelEvent,this),this.on("_side-reached",function(t){this.isAutorotateEnabled()&&("left"!==t&&"right"!==t||this._reverseAutorotate())})},t.prototype._unbindEvents=function(){window.removeEventListener("resize",this),this.config.mousemove&&(this.hud.container.removeEventListener("mousedown",this),this.hud.container.removeEventListener("mouseenter",this),this.hud.container.removeEventListener("touchstart",this),window.removeEventListener("mouseup",this),window.removeEventListener("touchend",this),this.hud.container.removeEventListener("mouseleave",this),this.hud.container.removeEventListener("mousemove",this),this.hud.container.removeEventListener("touchmove",this)),t.SYSTEM.fullscreenEvent&&document.removeEventListener(t.SYSTEM.fullscreenEvent,this),this.config.mousewheel&&this.hud.container.removeEventListener(t.SYSTEM.mouseWheelEvent,this),this.off("_side-reached")},t.prototype.handleEvent=function(o){switch(o.type){case"resize":e.throttle(this._onResize(),50);break;case"keydown":this._onKeyDown(o);break;case"mousedown":case"mouseenter":this._onMouseDown(o);break;case"touchstart":this._onTouchStart(o);break;case"mouseup":case"mouseleave":this._onMouseUp(o);break;case"touchend":this._onTouchEnd(o);break;case"mousemove":this._onMouseMove(o);break;case"touchmove":this._onTouchMove(o);break;case t.SYSTEM.fullscreenEvent:this._fullscreenToggled();break;case t.SYSTEM.mouseWheelEvent:this._onMouseWheel(o)}},t.prototype._onResize=function(){this.container.clientWidth===this.prop.size.width&&this.container.clientHeight===this.prop.size.height||(this.prop.size.width=parseInt(this.container.clientWidth),this.prop.size.height=parseInt(this.container.clientHeight),this.prop.aspect=this.prop.size.width/this.prop.size.height,this.needsUpdate(),this.renderer&&(this.stereoEffect||this.renderer).setSize(this.prop.size.width,this.prop.size.height),this.trigger("size-updated",this.getSize()))},t.prototype._onKeyDown=function(t){var o=0,i=0,s=0,n=e.getEventKey(t);switch(this.config.keyboard[n]){case"rotateLatitudeUp":i=.01;break;case"rotateLatitudeDown":i=-.01;break;case"rotateLongitudeRight":o=.01;break;case"rotateLongitudeLeft":o=-.01;break;case"zoomIn":s=1;break;case"zoomOut":s=-1;break;case"toggleAutorotate":this.toggleAutorotate()}0!==s?this.zoom(this.prop.zoom_lvl+s*this.config.zoom_speed):0===i&&0===o||this.rotate({longitude:this.prop.position.longitude+o*this.prop.move_speed*this.prop.hFov,latitude:this.prop.position.latitude+i*this.prop.move_speed*this.prop.vFov})},t.prototype._onMouseDown=function(t){this._startMove(t)},t.prototype._onMouseUp=function(t){this._stopMove(t),this.isStereoEnabled()&&this.stopStereoView()},t.prototype._onMouseMove=function(t){0!==t.buttons?(t.preventDefault(),this._move(t)):this.config.mousemove_hover&&this._moveAbsolute(t)},t.prototype._onTouchStart=function(t){1===t.touches.length?this.config.touchmove_two_fingers||this._startMove(t.touches[0]):2===t.touches.length&&this._startMoveZoom(t)},t.prototype._onTouchEnd=function(t){1===t.touches.length?this._stopMoveZoom():0===t.touches.length&&(this._stopMove(t.changedTouches[0]),this.config.touchmove_two_fingers&&this.overlay.hideOverlay())},t.prototype._onTouchMove=function(e){1===e.touches.length?this.config.touchmove_two_fingers?this.overlay.showOverlay({image:t.ICONS["gesture.svg"],text:this.config.lang.two_fingers[0]}):(e.preventDefault(),this._move(e.touches[0])):2===e.touches.length&&(e.preventDefault(),this._moveZoom(e))},t.prototype._startMove=function(t){this.stopAutorotate(),this.stopAnimation().then(function(){this.prop.mouse_x=this.prop.start_mouse_x=parseInt(t.clientX),this.prop.mouse_y=this.prop.start_mouse_y=parseInt(t.clientY),this.prop.moving=!0,this.prop.zooming=!1,this.prop.mouse_history.length=0,this._logMouseMove(t)}.bind(this))},t.prototype._startMoveZoom=function(t){var e=[{x:parseInt(t.touches[0].clientX),y:parseInt(t.touches[0].clientY)},{x:parseInt(t.touches[1].clientX),y:parseInt(t.touches[1].clientY)}];this.prop.pinch_dist=Math.sqrt(Math.pow(e[0].x-e[1].x,2)+Math.pow(e[0].y-e[1].y,2)),this.prop.mouse_x=this.prop.start_mouse_x=(e[0].x+e[1].x)/2,this.prop.mouse_y=this.prop.start_mouse_x=(e[0].y+e[1].y)/2,this.prop.moving=!0,this.prop.zooming=!0},t.prototype._stopMove=function(o){e.getClosest(o.target,".psv-hud")&&this.prop.moving&&(Math.abs(o.clientX-this.prop.start_mouse_x)<t.MOVE_THRESHOLD&&Math.abs(o.clientY-this.prop.start_mouse_y)<t.MOVE_THRESHOLD?(this._click(o),this.prop.moving=!1):this.config.move_inertia&&!this.isGyroscopeEnabled()?(this._logMouseMove(o),this._stopMoveInertia(o)):this.prop.moving=!1,this.prop.mouse_history.length=0)},t.prototype._stopMoveZoom=function(){this.prop.mouse_history.length=0,this.prop.moving=!1,this.prop.zooming=!1},t.prototype._stopMoveInertia=function(e){var i=e.clientX-this.prop.mouse_history[0][1],s=e.clientY-this.prop.mouse_history[0][2],n=Math.sqrt(i*i+s*s);this.prop.animation_promise=new o({properties:{clientX:{start:e.clientX,end:e.clientX+i},clientY:{start:e.clientY,end:e.clientY+s}},duration:n*t.INERTIA_WINDOW/100,easing:"outCirc",onTick:function(t){this._move(t,!1)}.bind(this)}).finally(function(){this.prop.moving=!1}.bind(this))},t.prototype._click=function(o){var i=this.container.getBoundingClientRect(),s={target:o.target,client_x:o.clientX,client_y:o.clientY,viewer_x:parseInt(o.clientX-i.left),viewer_y:parseInt(o.clientY-i.top)},n=this.viewerCoordsToVector3({x:s.viewer_x,y:s.viewer_y});if(n){var r=this.vector3ToSphericalCoords(n);if(s.longitude=r.longitude,s.latitude=r.latitude,!this.prop.isCubemap){var h=this.sphericalCoordsToTextureCoords({longitude:s.longitude,latitude:s.latitude});s.texture_x=h.x,s.texture_y=h.y}this.prop.dblclick_timeout?(Math.abs(this.prop.dblclick_data.client_x-s.client_x)<t.MOVE_THRESHOLD&&Math.abs(this.prop.dblclick_data.client_y-s.client_y)<t.MOVE_THRESHOLD&&this.trigger("dblclick",this.prop.dblclick_data),clearTimeout(this.prop.dblclick_timeout),this.prop.dblclick_timeout=null,this.prop.dblclick_data=null):(this.trigger("click",s),this.prop.dblclick_data=e.clone(s),this.prop.dblclick_timeout=setTimeout(function(){this.prop.dblclick_timeout=null,this.prop.dblclick_data=null}.bind(this),t.DBLCLICK_DELAY))}},t.prototype._move=function(e,o){if(this.prop.moving){var i=parseInt(e.clientX),s=parseInt(e.clientY),n={longitude:(i-this.prop.mouse_x)/this.prop.size.width*this.prop.move_speed*this.prop.hFov*t.SYSTEM.pixelRatio,latitude:(s-this.prop.mouse_y)/this.prop.size.height*this.prop.move_speed*this.prop.vFov*t.SYSTEM.pixelRatio};this.isGyroscopeEnabled()?this.prop.gyro_alpha_offset+=n.longitude:this.rotate({longitude:this.prop.position.longitude-n.longitude,latitude:this.prop.position.latitude+n.latitude}),this.prop.mouse_x=i,this.prop.mouse_y=s,!1!==o&&this._logMouseMove(e)}},t.prototype._moveAbsolute=function(t){this.prop.moving&&this.rotate({longitude:((t.clientX-this.container.offsetLeft)/this.container.offsetWidth-.5)*e.TwoPI,latitude:-((t.clientY-this.container.offsetTop)/this.container.offsetHeight-.5)*Math.PI})},t.prototype._moveZoom=function(t){if(this.prop.zooming&&this.prop.moving){var e=[{x:parseInt(t.touches[0].clientX),y:parseInt(t.touches[0].clientY)},{x:parseInt(t.touches[1].clientX),y:parseInt(t.touches[1].clientY)}],o=Math.sqrt(Math.pow(e[0].x-e[1].x,2)+Math.pow(e[0].y-e[1].y,2)),i=80*(o-this.prop.pinch_dist)/this.prop.size.width;this.zoom(this.prop.zoom_lvl+i),this._move({clientX:(e[0].x+e[1].x)/2,clientY:(e[0].y+e[1].y)/2}),this.prop.pinch_dist=o}},t.prototype._onMouseWheel=function(t){t.preventDefault(),t.stopPropagation();var o=5*e.normalizeWheel(t).spinY;0!==o&&this.zoom(this.prop.zoom_lvl-o*this.config.mousewheel_factor)},t.prototype._fullscreenToggled=function(){var t=this.isFullscreenEnabled();this.config.keyboard&&(t?this.startKeyboardControl():this.stopKeyboardControl()),this.trigger("fullscreen-updated",t)},t.prototype._logMouseMove=function(e){var o=Date.now();this.prop.mouse_history.push([o,e.clientX,e.clientY]);for(var i=null,s=0;s<this.prop.mouse_history.length;)this.prop.mouse_history[0][s]<o-t.INERTIA_WINDOW?this.prop.mouse_history.splice(s,1):i&&this.prop.mouse_history[0][s]-i>t.INERTIA_WINDOW/10?(this.prop.mouse_history.splice(0,s),s=0,i=this.prop.mouse_history[0][s]):(s++,i=this.prop.mouse_history[0][s])},t});
  //# sourceMappingURL=../sourcemaps/_psv/events.js.map
  