Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cognite/3d-camera-controls

Package Overview
Dependencies
Maintainers
14
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cognite/3d-camera-controls - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

2

lib/index.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.cognite=e():t.cognite=e()}(window,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(n,s,function(e){return t[e]}.bind(null,s));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="/",i(i.s=23)}([function(t,e,i){t.exports=!i(2)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,i){var n=i(13),s=i(12),a=i(10),r=Object.defineProperty;e.f=i(0)?Object.defineProperty:function(t,e,i){if(n(t),e=a(e,!0),n(i),s)try{return r(t,e,i)}catch(t){}if("get"in i||"set"in i)throw TypeError("Accessors not supported!");return"value"in i&&(t[e]=i.value),t}},function(t,e){var i=t.exports={version:"2.5.7"};"number"==typeof __e&&(__e=i)},function(t,e){var i=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=i)},function(t,e){t.exports={US:{8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause/break",20:"capslock",27:"escape",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",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",91:"leftwindow",92:"rightwindow",93:"select",96:"numpad-0",97:"numpad-1",98:"numpad-2",99:"numpad-3",100:"numpad-4",101:"numpad-5",102:"numpad-6",103:"numpad-7",104:"numpad-8",105:"numpad-9",106:"multiply",107:"add",109:"subtract",110:"decimalpoint",111:"divide",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scrolllock",186:"semicolon",187:"equals",188:"comma",189:"dash",190:"period",191:"forwardslash",192:"graveaccent",219:"openbracket",220:"backslash",221:"closebraket",222:"singlequote"}}},function(t,e,i){"use strict";function n(t){this.keys={};var e=this;for(var i in t)t.hasOwnProperty(i)&&(this.keys[t[i]]=0);window.addEventListener("keydown",function(i){if(t.hasOwnProperty(i.keyCode))return 0===e.keys[t[i.keyCode]]&&(e.keys[t[i.keyCode]]=2),!1}),window.addEventListener("keyup",function(i){if(t.hasOwnProperty(i.keyCode))return e.keys[t[i.keyCode]]=0,!1})}n.prototype.isPressed=function(t){return this.keys[t]>=1},n.prototype.consumePressed=function(t){var e=2===this.keys[t];return e&&(this.keys[t]=1),e},t.exports=n},function(t,e){var i={}.hasOwnProperty;t.exports=function(t,e){return i.call(t,e)}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,i){var n=i(1);t.exports=function(t,e){if(!n(t))return t;var i,s;if(e&&"function"==typeof(i=t.toString)&&!n(s=i.call(t)))return s;if("function"==typeof(i=t.valueOf)&&!n(s=i.call(t)))return s;if(!e&&"function"==typeof(i=t.toString)&&!n(s=i.call(t)))return s;throw TypeError("Can't convert object to primitive value")}},function(t,e,i){var n=i(1),s=i(5).document,a=n(s)&&n(s.createElement);t.exports=function(t){return a?s.createElement(t):{}}},function(t,e,i){t.exports=!i(0)&&!i(2)(function(){return 7!=Object.defineProperty(i(11)("div"),"a",{get:function(){return 7}}).a})},function(t,e,i){var n=i(1);t.exports=function(t){if(!n(t))throw TypeError(t+" is not an object!");return t}},function(t,e,i){var n=i(3),s=i(9);t.exports=i(0)?function(t,e,i){return n.f(t,e,s(1,i))}:function(t,e,i){return t[e]=i,t}},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,e,i){var n=i(15);t.exports=function(t,e,i){if(n(t),void 0===e)return t;switch(i){case 1:return function(i){return t.call(e,i)};case 2:return function(i,n){return t.call(e,i,n)};case 3:return function(i,n,s){return t.call(e,i,n,s)}}return function(){return t.apply(e,arguments)}}},function(t,e,i){var n=i(5),s=i(4),a=i(16),r=i(14),o=i(8),h=function(t,e,i){var c,u,d,l=t&h.F,p=t&h.G,f=t&h.S,m=t&h.P,g=t&h.B,v=t&h.W,y=p?s:s[e]||(s[e]={}),E=y.prototype,b=p?n:f?n[e]:(n[e]||{}).prototype;for(c in p&&(i=e),i)(u=!l&&b&&void 0!==b[c])&&o(y,c)||(d=u?b[c]:i[c],y[c]=p&&"function"!=typeof b[c]?i[c]:g&&u?a(d,n):v&&b[c]==d?function(t){var e=function(e,i,n){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(e);case 2:return new t(e,i)}return new t(e,i,n)}return t.apply(this,arguments)};return e.prototype=t.prototype,e}(d):m&&"function"==typeof d?a(Function.call,d):d,m&&((y.virtual||(y.virtual={}))[c]=d,t&h.R&&E&&!E[c]&&r(E,c,d)))};h.F=1,h.G=2,h.S=4,h.P=8,h.B=16,h.W=32,h.U=64,h.R=128,t.exports=h},function(t,e,i){var n=i(17);n(n.S+n.F*!i(0),"Object",{defineProperty:i(3).f})},function(t,e,i){i(18);var n=i(4).Object;t.exports=function(t,e,i){return n.defineProperty(t,e,i)}},function(t,e,i){t.exports={default:i(19),__esModule:!0}},function(t,e,i){"use strict";e.__esModule=!0;var n,s=i(20),a=(n=s)&&n.__esModule?n:{default:n};e.default=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),(0,a.default)(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}()},function(t,e,i){"use strict";e.__esModule=!0,e.default=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CameraControls=void 0;var n=a(i(22)),s=a(i(21));function a(t){return t&&t.__esModule?t:{default:t}}var r=i(7),o=i(6).US,h=void 0,c={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5,ROTATE_FP:6,FP_NAVIGATE:7},u=-1!==navigator.userAgent.toLowerCase().indexOf("firefox");e.CameraControls=function(){function t(e,i){var s=this;(0,n.default)(this,t),this.object=e,this.domElement=i,this.enabled=!0,this.minDistance=0,this.maxDistance=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.dampingFactor=.5,this.draggingDampingFactor=.1,this.minZoomDistance=.3,this.maxZoomDistance=1,this.panSpeed=1,this.minPanDistance=1,this.rotationSpeed=.005,this.enableKeyboardNavigation=!0,this.minDistToTarget=2,this.target=new h.Vector3,this.targetEnd=new h.Vector3,this.spherical=new h.Spherical,this.spherical.setFromVector3(this.object.position),this.sphericalEnd=(new h.Spherical).copy(this.spherical),this.state=c.NONE,this.keyboard=new r(o),this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.wasdKeys=["w","a","s","d"],this.mouse=new h.Vector2,this.plane=new h.Plane,this.line3=new h.Line3,this.v3=new h.Vector3,this.raycaster=new h.Raycaster,this.xColumn=new h.Vector3,this.yColumn=new h.Vector3,this.dragStart=new h.Vector2,this.dollyStart=new h.Vector2,this.onMouseDown=this.onMouseDown.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onMouseWheel=this.onMouseWheel.bind(this),this.onContextMenu=this.onContextMenu.bind(this),this.dragging=this.dragging.bind(this),this.startDragging=this.startDragging.bind(this),this.endDragging=this.endDragging.bind(this),this.needsUpdate=!0,this.update(),this.domElement?(this.domElement.addEventListener("mousedown",this.onMouseDown),this.domElement.addEventListener("touchstart",this.onTouchStart),this.domElement.addEventListener("wheel",this.onMouseWheel),this.domElement.addEventListener("DOMMouseScroll",this.onMouseWheel),this.domElement.addEventListener("contextmenu",this.onContextMenu),this.dispose=function(){s.domElement.removeEventListener("mousedown",s.onMouseDown),s.domElement.removeEventListener("touchstart",s.onTouchStart),s.domElement.removeEventListener("wheel",s.onMouseWheel),s.domElement.removeEventListener("DOMMouseScroll",s.onMouseWheel),s.domElement.removeEventListener("contextmenu",s.onContextMenu),document.removeEventListener("mousemove",s.dragging),document.removeEventListener("touchmove",s.dragging),document.removeEventListener("mouseup",s.endDragging),document.removeEventListener("touchend",s.endDragging)}):this.dispose=function(){}}return(0,s.default)(t,null,[{key:"install",value:function(t){h=t}}]),(0,s.default)(t,[{key:"onMouseDown",value:function(t){var e=this;if(this.enabled){t.preventDefault();var i=this.state;switch(this.elementRect=this.domElement.getBoundingClientRect(),t.button){case h.MOUSE.LEFT:var n=this.keyboard.isPressed("shift");if(this.state=n?c.ROTATE_FP:c.ROTATE,this.state===c.ROTATE)this.wasdKeys.filter(function(t){return e.keyboard.isPressed(t)}).length>0&&(this.state=c.ROTATE_FP);break;case h.MOUSE.MIDDLE:this.state=c.DOLLY;break;case h.MOUSE.RIGHT:this.state=c.PAN}i===c.NONE&&this.startDragging(t)}}},{key:"onTouchStart",value:function(t){if(this.enabled){t.preventDefault(),this.elementRect=this.domElement.getBoundingClientRect();var e=this.state;switch(t.touches.length){case 1:this.state=c.TOUCH_ROTATE;break;case 2:this.state=c.TOUCH_DOLLY;break;case 3:this.state=c.TOUCH_PAN}e===c.NONE&&this.startDragging(t)}}},{key:"onMouseWheel",value:function(t){if(this.enabled){t.preventDefault();var e=t.offsetX/this.domElement.clientWidth*2-1,i=-t.offsetY/this.domElement.clientHeight*2+1,n=0;if(t.wheelDelta)n=-t.wheelDelta/40;else if(t.detail)n=t.detail;else if(t.deltaY){var s=u?1:40;n=t.deltaY/s}n<0?this.dollyIn(e,i,1):this.dollyOut(e,i,1)}}},{key:"checkKeyboardEvents",value:function(){var t=this;if(this.enabled&&this.enableKeyboardNavigation){var e=this.keyboard,i=e.isPressed("shift"),n=i?1:.2,s=function(e,i){var s=t.getZoomDistance(!0,n);t.pan(e*s,i*s,!0)},a=!1;e.isPressed("w")&&(a=!0,this.dollyIn(0,0,n)),e.isPressed("s")&&(a=!0,this.dollyOut(0,0,n)),e.isPressed("a")&&(a=!0,s(1,0)),e.isPressed("d")&&(a=!0,s(-1,0));var r=i?10:5;e.isPressed("left")&&(a=!0,this.rotatetFP(r,0)),e.isPressed("up")&&(a=!0,this.rotatetFP(0,.5*r)),e.isPressed("down")&&(a=!0,this.rotatetFP(0,.5*-r)),e.isPressed("right")&&(a=!0,this.rotatetFP(-r,0)),a&&(this.needsUpdate=!0)}}},{key:"onContextMenu",value:function(t){this.enabled&&t.preventDefault()}},{key:"startDragging",value:function(t){if(this.enabled){t.preventDefault();var e=t.touches?t.touches[0]:t,i=e.clientX,n=e.clientY;if(this.dragStart.set(i,n),this.state===c.TOUCH_DOLLY){var s=i-t.touches[1].pageX,a=n-t.touches[1].pageY,r=Math.sqrt(s*s+a*a);this.dollyStart.set(0,r)}this.dampingFactor=this.draggingDampingFactor,document.addEventListener("mousemove",this.dragging,{passive:!1}),document.addEventListener("touchmove",this.dragging,{passive:!1}),document.addEventListener("mouseup",this.endDragging),document.addEventListener("touchend",this.endDragging)}}},{key:"dragging",value:function(t){if(this.enabled){t.preventDefault();var e=t.touches?t.touches[0]:t,i=e.clientX,n=e.clientY,s=this.dragStart.x-i,a=this.dragStart.y-n;switch(this.dragStart.set(i,n),this.state){case c.ROTATE:case c.TOUCH_ROTATE:var r=2*Math.PI*s/this.elementRect.width,o=2*Math.PI*a/this.elementRect.height;this.rotate(r,o,!0);break;case c.DOLLY:break;case c.TOUCH_DOLLY:var u=i-t.touches[1].pageX,d=n-t.touches[1].pageY,l=Math.sqrt(u*u+d*d),p=this.dollyStart.y-l,f=(i+t.touches[1].pageX)/2,m=(n+t.touches[1].pageY)/2,g=f/this.domElement.clientWidth*2-1,v=-m/this.domElement.clientHeight*2+1;p>0?this.dollyOut(g,v):p<0&&this.dollyIn(g,v),this.dollyStart.set(0,l);break;case c.PAN:case c.TOUCH_PAN:var y=this.v3.copy(this.object.position).sub(this.target).length()*Math.tan(this.object.fov/2*Math.PI/180),E=this.panSpeed*s*y/this.elementRect.height,b=this.panSpeed*a*y/this.elementRect.height;E=h.Math.clamp(E,-this.minPanDistance,this.minPanDistance),b=h.Math.clamp(b,-this.minPanDistance,this.minPanDistance),this.pan(E,b,!0);break;case c.ROTATE_FP:this.rotatetFP(s,a)}}}},{key:"endDragging",value:function(){this.enabled&&(this.dampingFactor=this.dampingFactor,this.state=c.NONE,document.removeEventListener("mousemove",this.dragging),document.removeEventListener("touchmove",this.dragging),document.removeEventListener("mouseup",this.endDragging),document.removeEventListener("touchend",this.endDragging))}},{key:"dollyIn",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;this.dolly(this.getZoomDistance(!0,i),!0,t,e)}},{key:"dollyOut",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;this.dolly(this.getZoomDistance(!1,i),!0,t,e)}},{key:"rotate",value:function(t,e,i){this.rotateTo(this.sphericalEnd.theta+t,this.sphericalEnd.phi+e,i)}},{key:"rotateTo",value:function(t,e,i){var n=Math.max(this.minAzimuthAngle,Math.min(this.maxAzimuthAngle,t)),s=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,e));this.sphericalEnd.theta=n,this.sphericalEnd.phi=s,this.sphericalEnd.radius=this.spherical.radius,this.sphericalEnd.makeSafe(),this.targetEnd.copy(this.target),i||(this.spherical.theta=this.sphericalEnd.theta,this.spherical.phi=this.sphericalEnd.phi),this.needsUpdate=!0}},{key:"rotatetFP",value:function(t,e){var i=this.object.clone();i.position.setFromSpherical(this.sphericalEnd).add(this.targetEnd),i.lookAt(this.targetEnd),i.rotateY(t*this.rotationSpeed),i.rotateX(e*this.rotationSpeed);var n=i.getWorldDirection();this.v3.subVectors(this.targetEnd,i.position);var s=this.targetEnd.distanceTo(i.position);this.targetEnd.addVectors(i.position,n.multiplyScalar(s)),this.sphericalEnd.setFromVector3(this.v3.subVectors(i.position,this.targetEnd)),function(t,e){for(var i=2*Math.PI,n=.5*i;Math.abs(t.theta-e.theta)>n;)t.theta+=t.theta<e.theta?i:-i}(this.sphericalEnd,this.spherical),this.needsUpdate=!0}},{key:"getZoomDistance",value:function(t,e){var i=this.sphericalEnd.radius,n=void 0,s=this.minDistToTarget,a=100*s;if(i<=this.minDistToTarget)n=this.minZoomDistance;else if(i>=a)n=this.maxZoomDistance;else{var r=(this.maxZoomDistance-this.minZoomDistance)/(a-s);n=this.minZoomDistance+r*(i-s)}return t&&(n=-n),n*=e}},{key:"dolly",value:function(t,e,i,n){this.dollyTo(this.sphericalEnd.radius+t,e,i,n)}},{key:"dollyTo",value:function(t,e,i,n){var s=h.Math.clamp(t,this.minDistance,this.maxDistance),a=this.sphericalEnd.radius-s;this.mouse.set(i,n);var r=this.object.clone();r.position.setFromSpherical(this.sphericalEnd).add(this.targetEnd),r.lookAt(this.targetEnd),this.raycaster.setFromCamera(this.mouse,r);var o=r.getWorldDirection(),c=this.plane;c.setFromNormalAndCoplanarPoint(o,this.targetEnd);var u=this.raycaster.ray.direction.clone().multiplyScalar(a);r.position.add(u);var d=this.line3,l=-c.distanceToPoint(r.position);d.set(r.position,r.position.clone().add(o.clone().multiplyScalar(2*l)));var p=c.intersectLine(d);this.targetEnd.copy(p),this.sphericalEnd.radius=this.targetEnd.distanceTo(r.position);var f=this.minDistToTarget-this.sphericalEnd.radius;if(f>0){var m=r.getWorldDirection();this.targetEnd.add(m.multiplyScalar(f)),this.sphericalEnd.radius=this.minDistToTarget}e||(this.spherical.radius=this.sphericalEnd.radius,this.update()),this.needsUpdate=!0}},{key:"pan",value:function(t,e,i){var n=this.object.clone();n.position.setFromSpherical(this.sphericalEnd).add(this.targetEnd),n.lookAt(this.targetEnd),n.updateMatrix(),this.xColumn.setFromMatrixColumn(n.matrix,0),this.yColumn.setFromMatrixColumn(n.matrix,1),this.xColumn.multiplyScalar(t),this.yColumn.multiplyScalar(-e);var s=this.v3.copy(this.xColumn).add(this.yColumn);this.targetEnd.add(s),i||this.target.copy(this.targetEnd),this.needsUpdate=!0}},{key:"moveTo",value:function(t,e,i,n){this.targetEnd.set(t,e,i),n||this.target.copy(this.targetEnd),this.needsUpdate=!0}},{key:"getState",value:function(){return this.state}},{key:"reset",value:function(t){this.targetEnd.copy(this.target0),this.sphericalEnd.setFromVector3(this.position0),this.sphericalEnd.theta=this.sphericalEnd.theta%(2*Math.PI),this.spherical.theta=this.spherical.theta%(2*Math.PI),t||(this.target.copy(this.targetEnd),this.spherical.copy(this.sphericalEnd)),this.needsUpdate=!0}},{key:"setCameraPosition",value:function(t,e){this.target0.copy(e),this.position0.copy(t.clone().sub(e)),this.reset()}},{key:"update",value:function(t){var e=1;null!=t&&(e=this.dampingFactor*t/.016);var i=this.sphericalEnd.theta-this.spherical.theta,n=this.sphericalEnd.phi-this.spherical.phi,s=this.sphericalEnd.radius-this.spherical.radius,a=(new h.Vector3).subVectors(this.targetEnd,this.target);Math.abs(i)>.001||Math.abs(n)>.001||Math.abs(s)>.001||Math.abs(a.x)>.001||Math.abs(a.y)>.001||Math.abs(a.z)>.001?(this.spherical.set(this.spherical.radius+s*e,this.spherical.phi+n*e,this.spherical.theta+i*e),this.target.add(a.multiplyScalar(e)),this.needsUpdate=!0):(this.spherical.copy(this.sphericalEnd),this.target.copy(this.targetEnd)),this.spherical.makeSafe(),this.object.position.setFromSpherical(this.spherical).add(this.target),this.object.lookAt(this.target),this.checkKeyboardEvents();var r=this.needsUpdate;return this.needsUpdate=!1,r}}]),t}()}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.cognite=e():t.cognite=e()}(window,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)i.d(n,s,function(e){return t[e]}.bind(null,s));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="/",i(i.s=23)}([function(t,e,i){t.exports=!i(2)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(t,e){t.exports=function(t){return"object"==typeof t?null!==t:"function"==typeof t}},function(t,e){t.exports=function(t){try{return!!t()}catch(t){return!0}}},function(t,e,i){var n=i(13),s=i(12),r=i(10),a=Object.defineProperty;e.f=i(0)?Object.defineProperty:function(t,e,i){if(n(t),e=r(e,!0),n(i),s)try{return a(t,e,i)}catch(t){}if("get"in i||"set"in i)throw TypeError("Accessors not supported!");return"value"in i&&(t[e]=i.value),t}},function(t,e){var i=t.exports={version:"2.5.7"};"number"==typeof __e&&(__e=i)},function(t,e){var i=t.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=i)},function(t,e){t.exports={US:{8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause/break",20:"capslock",27:"escape",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",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",91:"leftwindow",92:"rightwindow",93:"select",96:"numpad-0",97:"numpad-1",98:"numpad-2",99:"numpad-3",100:"numpad-4",101:"numpad-5",102:"numpad-6",103:"numpad-7",104:"numpad-8",105:"numpad-9",106:"multiply",107:"add",109:"subtract",110:"decimalpoint",111:"divide",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12",144:"numlock",145:"scrolllock",186:"semicolon",187:"equals",188:"comma",189:"dash",190:"period",191:"forwardslash",192:"graveaccent",219:"openbracket",220:"backslash",221:"closebraket",222:"singlequote"}}},function(t,e,i){"use strict";function n(t){this.keys={};var e=this;for(var i in t)t.hasOwnProperty(i)&&(this.keys[t[i]]=0);window.addEventListener("keydown",function(i){if(t.hasOwnProperty(i.keyCode))return 0===e.keys[t[i.keyCode]]&&(e.keys[t[i.keyCode]]=2),!1}),window.addEventListener("keyup",function(i){if(t.hasOwnProperty(i.keyCode))return e.keys[t[i.keyCode]]=0,!1})}n.prototype.isPressed=function(t){return this.keys[t]>=1},n.prototype.consumePressed=function(t){var e=2===this.keys[t];return e&&(this.keys[t]=1),e},t.exports=n},function(t,e){var i={}.hasOwnProperty;t.exports=function(t,e){return i.call(t,e)}},function(t,e){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},function(t,e,i){var n=i(1);t.exports=function(t,e){if(!n(t))return t;var i,s;if(e&&"function"==typeof(i=t.toString)&&!n(s=i.call(t)))return s;if("function"==typeof(i=t.valueOf)&&!n(s=i.call(t)))return s;if(!e&&"function"==typeof(i=t.toString)&&!n(s=i.call(t)))return s;throw TypeError("Can't convert object to primitive value")}},function(t,e,i){var n=i(1),s=i(5).document,r=n(s)&&n(s.createElement);t.exports=function(t){return r?s.createElement(t):{}}},function(t,e,i){t.exports=!i(0)&&!i(2)(function(){return 7!=Object.defineProperty(i(11)("div"),"a",{get:function(){return 7}}).a})},function(t,e,i){var n=i(1);t.exports=function(t){if(!n(t))throw TypeError(t+" is not an object!");return t}},function(t,e,i){var n=i(3),s=i(9);t.exports=i(0)?function(t,e,i){return n.f(t,e,s(1,i))}:function(t,e,i){return t[e]=i,t}},function(t,e){t.exports=function(t){if("function"!=typeof t)throw TypeError(t+" is not a function!");return t}},function(t,e,i){var n=i(15);t.exports=function(t,e,i){if(n(t),void 0===e)return t;switch(i){case 1:return function(i){return t.call(e,i)};case 2:return function(i,n){return t.call(e,i,n)};case 3:return function(i,n,s){return t.call(e,i,n,s)}}return function(){return t.apply(e,arguments)}}},function(t,e,i){var n=i(5),s=i(4),r=i(16),a=i(14),o=i(8),h=function(t,e,i){var c,u,d,l=t&h.F,p=t&h.G,f=t&h.S,m=t&h.P,g=t&h.B,v=t&h.W,y=p?s:s[e]||(s[e]={}),E=y.prototype,b=p?n:f?n[e]:(n[e]||{}).prototype;for(c in p&&(i=e),i)(u=!l&&b&&void 0!==b[c])&&o(y,c)||(d=u?b[c]:i[c],y[c]=p&&"function"!=typeof b[c]?i[c]:g&&u?r(d,n):v&&b[c]==d?function(t){var e=function(e,i,n){if(this instanceof t){switch(arguments.length){case 0:return new t;case 1:return new t(e);case 2:return new t(e,i)}return new t(e,i,n)}return t.apply(this,arguments)};return e.prototype=t.prototype,e}(d):m&&"function"==typeof d?r(Function.call,d):d,m&&((y.virtual||(y.virtual={}))[c]=d,t&h.R&&E&&!E[c]&&a(E,c,d)))};h.F=1,h.G=2,h.S=4,h.P=8,h.B=16,h.W=32,h.U=64,h.R=128,t.exports=h},function(t,e,i){var n=i(17);n(n.S+n.F*!i(0),"Object",{defineProperty:i(3).f})},function(t,e,i){i(18);var n=i(4).Object;t.exports=function(t,e,i){return n.defineProperty(t,e,i)}},function(t,e,i){t.exports={default:i(19),__esModule:!0}},function(t,e,i){"use strict";e.__esModule=!0;var n,s=i(20),r=(n=s)&&n.__esModule?n:{default:n};e.default=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),(0,r.default)(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}()},function(t,e,i){"use strict";e.__esModule=!0,e.default=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.CameraControls=void 0;var n=r(i(22)),s=r(i(21));function r(t){return t&&t.__esModule?t:{default:t}}var a=i(7),o=i(6).US,h=void 0,c={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_DOLLY:4,TOUCH_PAN:5,ROTATE_FP:6,FP_NAVIGATE:7},u=-1!==navigator.userAgent.toLowerCase().indexOf("firefox");e.CameraControls=function(){function t(e,i){var s=this;(0,n.default)(this,t),this.object=e,this.domElement=i,this.enabled=!0,this.minDistance=0,this.maxDistance=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.dampingFactor=.5,this.draggingDampingFactor=.1,this.minZoomDistance=.3,this.maxZoomDistance=1,this.panSpeed=30,this.minPanDistance=1,this.rotationSpeed=.005,this.enableKeyboardNavigation=!0,this.minDistToTarget=2,this.target=new h.Vector3,this.targetEnd=new h.Vector3,this.spherical=new h.Spherical,this.spherical.setFromVector3(this.object.position),this.sphericalEnd=(new h.Spherical).copy(this.spherical),this.state=c.NONE,this.keyboard=new a(o),this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.wasdKeys=["w","a","s","d"],this.mouse=new h.Vector2,this.plane=new h.Plane,this.line3=new h.Line3,this.v3=new h.Vector3,this.raycaster=new h.Raycaster,this.xColumn=new h.Vector3,this.yColumn=new h.Vector3,this.dragStart=new h.Vector2,this.dollyStart=new h.Vector2,this.onMouseDown=this.onMouseDown.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onMouseWheel=this.onMouseWheel.bind(this),this.onContextMenu=this.onContextMenu.bind(this),this.dragging=this.dragging.bind(this),this.startDragging=this.startDragging.bind(this),this.endDragging=this.endDragging.bind(this),this.needsUpdate=!0,this.update(),this.domElement?(this.domElement.addEventListener("mousedown",this.onMouseDown),this.domElement.addEventListener("touchstart",this.onTouchStart),this.domElement.addEventListener("wheel",this.onMouseWheel),this.domElement.addEventListener("DOMMouseScroll",this.onMouseWheel),this.domElement.addEventListener("contextmenu",this.onContextMenu),this.dispose=function(){s.domElement.removeEventListener("mousedown",s.onMouseDown),s.domElement.removeEventListener("touchstart",s.onTouchStart),s.domElement.removeEventListener("wheel",s.onMouseWheel),s.domElement.removeEventListener("DOMMouseScroll",s.onMouseWheel),s.domElement.removeEventListener("contextmenu",s.onContextMenu),document.removeEventListener("mousemove",s.dragging),document.removeEventListener("touchmove",s.dragging),document.removeEventListener("mouseup",s.endDragging),document.removeEventListener("touchend",s.endDragging)}):this.dispose=function(){}}return(0,s.default)(t,null,[{key:"install",value:function(t){h=t}}]),(0,s.default)(t,[{key:"onMouseDown",value:function(t){var e=this;if(this.enabled){t.preventDefault();var i=this.state;switch(this.elementRect=this.domElement.getBoundingClientRect(),t.button){case h.MOUSE.LEFT:var n=this.keyboard.isPressed("shift");if(this.state=n?c.ROTATE_FP:c.ROTATE,this.state===c.ROTATE)this.wasdKeys.filter(function(t){return e.keyboard.isPressed(t)}).length>0&&(this.state=c.ROTATE_FP);break;case h.MOUSE.MIDDLE:this.state=c.DOLLY;break;case h.MOUSE.RIGHT:this.state=c.PAN}i===c.NONE&&this.startDragging(t)}}},{key:"onTouchStart",value:function(t){if(this.enabled){t.preventDefault(),this.elementRect=this.domElement.getBoundingClientRect();var e=this.state;switch(t.touches.length){case 1:this.state=c.TOUCH_ROTATE;break;case 2:this.state=c.TOUCH_DOLLY;break;case 3:this.state=c.TOUCH_PAN}e===c.NONE&&this.startDragging(t)}}},{key:"onMouseWheel",value:function(t){if(this.enabled){t.preventDefault();var e=t.offsetX/this.domElement.clientWidth*2-1,i=-t.offsetY/this.domElement.clientHeight*2+1,n=0;if(t.wheelDelta)n=-t.wheelDelta/40;else if(t.detail)n=t.detail;else if(t.deltaY){var s=u?1:40;n=t.deltaY/s}n<0?this.dollyIn(e,i,Math.abs(n)):this.dollyOut(e,i,Math.abs(n))}}},{key:"checkKeyboardEvents",value:function(){var t=this;if(this.enabled&&this.enableKeyboardNavigation){var e=this.keyboard,i=e.isPressed("shift"),n=i?2:.6,s=function(e,i){var s=t.getZoomDistance(!0,n);t.pan(e*s,i*s,!0)},r=!1,a=function(){r=!0};e.isPressed("w")&&(a(),this.dollyIn(0,0,n)),e.isPressed("s")&&(a(),this.dollyOut(0,0,n)),e.isPressed("a")&&(a(),s(1,0)),e.isPressed("d")&&(a(),s(-1,0));var o=i?10:5;e.isPressed("left")&&(a(),this.rotatetFP(o,0)),e.isPressed("up")&&(a(),this.rotatetFP(0,.5*o)),e.isPressed("down")&&(a(),this.rotatetFP(0,.5*-o)),e.isPressed("right")&&(a(),this.rotatetFP(-o,0)),r&&(this.needsUpdate=!0)}}},{key:"onContextMenu",value:function(t){this.enabled&&t.preventDefault()}},{key:"startDragging",value:function(t){if(this.enabled){t.preventDefault();var e=t.touches?t.touches[0]:t,i=e.clientX,n=e.clientY;if(this.dragStart.set(i,n),this.state===c.TOUCH_DOLLY){var s=i-t.touches[1].pageX,r=n-t.touches[1].pageY,a=Math.sqrt(s*s+r*r);this.dollyStart.set(0,a)}this.dampingFactor=this.draggingDampingFactor,document.addEventListener("mousemove",this.dragging,{passive:!1}),document.addEventListener("touchmove",this.dragging,{passive:!1}),document.addEventListener("mouseup",this.endDragging),document.addEventListener("touchend",this.endDragging)}}},{key:"dragging",value:function(t){if(this.enabled){t.preventDefault();var e=t.touches?t.touches[0]:t,i=e.clientX,n=e.clientY,s=this.dragStart.x-i,r=this.dragStart.y-n;switch(this.dragStart.set(i,n),this.state){case c.ROTATE:case c.TOUCH_ROTATE:var a=2*Math.PI*s/this.elementRect.width,o=2*Math.PI*r/this.elementRect.height;this.rotate(a,o,!0);break;case c.DOLLY:break;case c.TOUCH_DOLLY:var h=i-t.touches[1].pageX,u=n-t.touches[1].pageY,d=Math.sqrt(h*h+u*u),l=this.dollyStart.y-d,p=(i+t.touches[1].pageX)/2,f=(n+t.touches[1].pageY)/2,m=p/this.domElement.clientWidth*2-1,g=-f/this.domElement.clientHeight*2+1;l>0?this.dollyOut(m,g):l<0&&this.dollyIn(m,g),this.dollyStart.set(0,d);break;case c.PAN:case c.TOUCH_PAN:var v=this.getZoomDistance(!0,1),y=-v*this.panSpeed*(s/this.elementRect.height),E=-v*this.panSpeed*(r/this.elementRect.height);this.pan(y,E,!0);break;case c.ROTATE_FP:this.rotatetFP(s,r)}}}},{key:"endDragging",value:function(){this.enabled&&(this.dampingFactor=this.dampingFactor,this.state=c.NONE,document.removeEventListener("mousemove",this.dragging),document.removeEventListener("touchmove",this.dragging),document.removeEventListener("mouseup",this.endDragging),document.removeEventListener("touchend",this.endDragging))}},{key:"dollyIn",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;this.dolly(this.getZoomDistance(!0,i),!0,t,e)}},{key:"dollyOut",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;this.dolly(this.getZoomDistance(!1,i),!0,t,e)}},{key:"rotate",value:function(t,e,i){this.rotateTo(this.sphericalEnd.theta+t,this.sphericalEnd.phi+e,i)}},{key:"rotateTo",value:function(t,e,i){var n=Math.max(this.minAzimuthAngle,Math.min(this.maxAzimuthAngle,t)),s=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,e));this.sphericalEnd.theta=n,this.sphericalEnd.phi=s,this.sphericalEnd.radius=this.spherical.radius,this.sphericalEnd.makeSafe(),this.targetEnd.copy(this.target),i||(this.spherical.theta=this.sphericalEnd.theta,this.spherical.phi=this.sphericalEnd.phi),this.needsUpdate=!0}},{key:"rotatetFP",value:function(t,e){var i=this.object.clone();i.position.setFromSpherical(this.sphericalEnd).add(this.targetEnd),i.lookAt(this.targetEnd),i.rotateY(t*this.rotationSpeed),i.rotateX(e*this.rotationSpeed);var n=i.getWorldDirection();this.v3.subVectors(this.targetEnd,i.position);var s=this.targetEnd.distanceTo(i.position);this.targetEnd.addVectors(i.position,n.multiplyScalar(s)),this.sphericalEnd.setFromVector3(this.v3.subVectors(i.position,this.targetEnd)),function(t,e){for(var i=2*Math.PI,n=.5*i;Math.abs(t.theta-e.theta)>n;)t.theta+=t.theta<e.theta?i:-i}(this.sphericalEnd,this.spherical),this.needsUpdate=!0}},{key:"getZoomDistance",value:function(t,e){var i=this.sphericalEnd.radius,n=void 0,s=this.minDistToTarget,r=100*s;if(i<=this.minDistToTarget)n=this.minZoomDistance;else if(i>=r)n=this.maxZoomDistance;else{var a=(this.maxZoomDistance-this.minZoomDistance)/(r-s);n=this.minZoomDistance+a*(i-s)}return t&&(n=-n),n*=e}},{key:"dolly",value:function(t,e,i,n){this.dollyTo(this.sphericalEnd.radius+t,e,i,n)}},{key:"dollyTo",value:function(t,e,i,n){var s=h.Math.clamp(t,this.minDistance,this.maxDistance),r=this.sphericalEnd.radius-s;this.mouse.set(i,n);var a=this.object.clone();a.position.setFromSpherical(this.sphericalEnd).add(this.targetEnd),a.lookAt(this.targetEnd),this.raycaster.setFromCamera(this.mouse,a);var o=a.getWorldDirection(),c=this.plane;c.setFromNormalAndCoplanarPoint(o,this.targetEnd);var u=this.raycaster.ray.direction.clone().multiplyScalar(r);a.position.add(u);var d=this.line3,l=-c.distanceToPoint(a.position);d.set(a.position,a.position.clone().add(o.clone().multiplyScalar(2*l)));var p=c.intersectLine(d);this.targetEnd.copy(p),this.sphericalEnd.radius=this.targetEnd.distanceTo(a.position);var f=this.minDistToTarget-this.sphericalEnd.radius;if(f>0){var m=a.getWorldDirection();this.targetEnd.add(m.multiplyScalar(f)),this.sphericalEnd.radius=this.minDistToTarget}e||(this.spherical.radius=this.sphericalEnd.radius,this.update()),this.needsUpdate=!0}},{key:"pan",value:function(t,e,i){var n=this.object.clone();n.position.setFromSpherical(this.sphericalEnd).add(this.targetEnd),n.lookAt(this.targetEnd),n.updateMatrix(),this.xColumn.setFromMatrixColumn(n.matrix,0),this.yColumn.setFromMatrixColumn(n.matrix,1),this.xColumn.multiplyScalar(t),this.yColumn.multiplyScalar(-e);var s=this.v3.copy(this.xColumn).add(this.yColumn);this.targetEnd.add(s),i||this.target.copy(this.targetEnd),this.needsUpdate=!0}},{key:"moveTo",value:function(t,e,i,n){this.targetEnd.set(t,e,i),n||this.target.copy(this.targetEnd),this.needsUpdate=!0}},{key:"getState",value:function(){return this.state}},{key:"reset",value:function(t){this.targetEnd.copy(this.target0),this.sphericalEnd.setFromVector3(this.position0),this.sphericalEnd.theta=this.sphericalEnd.theta%(2*Math.PI),this.spherical.theta=this.spherical.theta%(2*Math.PI),t||(this.target.copy(this.targetEnd),this.spherical.copy(this.sphericalEnd)),this.needsUpdate=!0}},{key:"setCameraPosition",value:function(t,e){this.target0.copy(e),this.position0.copy(t.clone().sub(e)),this.reset()}},{key:"update",value:function(t){var e=1;null!=t&&(e=this.dampingFactor*t/.016),e=h.Math.clamp(e,0,1);var i=this.sphericalEnd.theta-this.spherical.theta,n=this.sphericalEnd.phi-this.spherical.phi,s=this.sphericalEnd.radius-this.spherical.radius,r=(new h.Vector3).subVectors(this.targetEnd,this.target);Math.abs(i)>.001||Math.abs(n)>.001||Math.abs(s)>.001||Math.abs(r.x)>.001||Math.abs(r.y)>.001||Math.abs(r.z)>.001?(this.spherical.set(this.spherical.radius+s*e,this.spherical.phi+n*e,this.spherical.theta+i*e),this.target.add(r.multiplyScalar(e)),this.needsUpdate=!0):(this.spherical.copy(this.sphericalEnd),this.target.copy(this.targetEnd)),this.spherical.makeSafe(),this.object.position.setFromSpherical(this.spherical).add(this.target),this.object.lookAt(this.target),this.checkKeyboardEvents();var a=this.needsUpdate;return this.needsUpdate=!1,a}}]),t}()}])});
{
"name": "@cognite/3d-camera-controls",
"version": "1.0.0",
"version": "1.0.1",
"contributors": [

@@ -5,0 +5,0 @@ "Fredrik Anfinsen <fredrik.anfinsen@cognite.com>"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc