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

aframe-keyboard-controls

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aframe-keyboard-controls - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

16

dist/aframe-keyboard-controls.js

@@ -154,8 +154,16 @@ /******/ (function(modules) { // webpackBootstrap

if (data.pitchAxisEnabled) {
if (keys.a || keys.ArrowLeft) { velocity[pitchAxis] -= pitchSign * acceleration * delta; }
if (keys.d || keys.ArrowRight) { velocity[pitchAxis] += pitchSign * acceleration * delta; }
if (keys.a || keys.Left || keys.ArrowLeft) {
velocity[pitchAxis] -= pitchSign * acceleration * delta;
}
if (keys.d || keys.Right || keys.ArrowRight) {
velocity[pitchAxis] += pitchSign * acceleration * delta;
}
}
if (data.rollAxisEnabled) {
if (keys.w || keys.ArrowUp) { velocity[rollAxis] -= rollSign * acceleration * delta; }
if (keys.s || keys.ArrowDown) { velocity[rollAxis] += rollSign * acceleration * delta; }
if (keys.w || keys.Up || keys.ArrowUp) {
velocity[rollAxis] -= rollSign * acceleration * delta;
}
if (keys.s || keys.Down || keys.ArrowDown) {
velocity[rollAxis] += rollSign * acceleration * delta;
}
}

@@ -162,0 +170,0 @@ }

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

!function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){!function(e){return e?void(e.aframeCore||e).registerComponent("keyboard-controls",n(1)):void console.error("Component attempted to register before AFRAME was available.")}(window.AFRAME)},function(e,t,n){n(2).polyfill();var o=.2,i="__keyboard-controls-proxy",r=window.KeyboardEvent;e.exports={schema:{easing:{"default":20},acceleration:{"default":65},enabled:{"default":!0},fly:{"default":!1},rollAxis:{"default":"z",oneOf:["x","y","z"]},pitchAxis:{"default":"x",oneOf:["x","y","z"]},rollAxisInverted:{"default":!1},rollAxisEnabled:{"default":!0},pitchAxisInverted:{"default":!1},pitchAxisEnabled:{"default":!0}},init:function(){this.velocity=new THREE.Vector3,this.localKeys={},this.listeners={keydown:this.onKeyDown.bind(this),keyup:this.onKeyUp.bind(this)};var e=this.el.sceneEl;e.addBehavior&&(e.addBehavior(this),this.attachEventListeners())},update:function(e){var t,n=this.data,i=n.acceleration,r=n.easing,s=this.velocity,a=this.prevTime=this.prevTime||Date.now(),l=window.performance.now(),c=(l-a)/1e3,d=this.getKeys(),u=n.pitchAxis,y=n.rollAxis,p=n.pitchAxisInverted?-1:1,h=n.rollAxisInverted?-1:1,f=this.el;if(this.prevTime=l,e||c>o)return s[u]=0,void(s[y]=0);s[u]-=s[u]*r*c,s[y]-=s[y]*r*c;var v=f.getComputedAttribute("position");n.enabled&&(n.pitchAxisEnabled&&((d.a||d.ArrowLeft)&&(s[u]-=p*i*c),(d.d||d.ArrowRight)&&(s[u]+=p*i*c)),n.rollAxisEnabled&&((d.w||d.ArrowUp)&&(s[y]-=h*i*c),(d.s||d.ArrowDown)&&(s[y]+=h*i*c))),t=this.getMovementVector(c),f.object3D.translateX(t.x),f.object3D.translateY(t.y),f.object3D.translateZ(t.z),f.setAttribute("position",{x:v.x+t.x,y:v.y+t.y,z:v.z+t.z})},getMovementVector:function(e){var t=new THREE.Vector3(0,0,0),n=new THREE.Euler(0,0,0,"YXZ");return function(e){var o=this.velocity,i=this.el.getAttribute("rotation");return t.copy(o),t.multiplyScalar(e),i?(this.data.fly||(i.x=0),n.set(THREE.Math.degToRad(i.x),THREE.Math.degToRad(i.y),0),t.applyEuler(n),t):t}}(),play:function(){this.attachEventListeners()},pause:function(){this.removeEventListeners()},tick:function(e){this.update()},remove:function(){this.pause()},attachEventListeners:function(){window.addEventListener("keydown",this.listeners.keydown,!1),window.addEventListener("keyup",this.listeners.keyup,!1)},removeEventListeners:function(){window.removeEventListener("keydown",this.listeners.keydown),window.removeEventListener("keyup",this.listeners.keyup)},onKeyDown:function(e){this.localKeys[e.key]=!0,this.emit(e)},onKeyUp:function(e){delete this.localKeys[e.key],this.emit(e)},emit:function(e){i in e&&this.el.emit(e.type,e),this.el.emit(e.type+":"+e.key,new r(e.type,e)),console.log(e.type+":"+e.key)},isPressed:function(e){return e in this.getKeys()},getKeys:function(){return this.isProxied()?this.el.sceneEl.components["proxy-controls"].getKeyboard():this.localKeys},isProxied:function(){var e=this.el.sceneEl.components["proxy-controls"];return e&&e.isConnected()}}},function(e,t,n){var o,i;!function(){function r(){if(!("KeyboardEvent"in window)||"key"in KeyboardEvent.prototype)return!1;var e={get:function(e){var t=a.keys[this.which||this.keyCode];return Array.isArray(t)&&(t=t[+this.shiftKey]),t}};return Object.defineProperty(KeyboardEvent.prototype,"key",e),e}var s,a={polyfill:r,keys:{3:"Cancel",6:"Help",8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",28:"Convert",29:"NonConvert",30:"Accept",31:"ModeChange",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",41:"Select",42:"Print",43:"Execute",44:"PrintScreen",45:"Insert",46:"Delete",48:["0",")"],49:["1","!"],50:["2","@"],51:["3","#"],52:["4","$"],53:["5","%"],54:["6","^"],55:["7","&"],56:["8","*"],57:["9","("],91:"OS",93:"ContextMenu",144:"NumLock",145:"ScrollLock",181:"VolumeMute",182:"VolumeDown",183:"VolumeUp",186:[";",":"],187:["=","+"],188:[",","<"],189:["-","_"],190:[".",">"],191:["/","?"],192:["`","~"],219:["[","{"],220:["\\","|"],221:["]","}"],222:["'",'"'],224:"Meta",225:"AltGraph",246:"Attn",247:"CrSel",248:"ExSel",249:"EraseEof",250:"Play",251:"ZoomOut"}};for(s=1;25>s;s++)a.keys[111+s]="F"+s;var l="";for(s=65;91>s;s++)l=String.fromCharCode(s),a.keys[s]=[l.toLowerCase(),l.toUpperCase()];o=a,i="function"==typeof o?o.call(t,n,t,e):o,!(void 0!==i&&(e.exports=i))}()}]);
!function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={exports:{},id:o,loaded:!1};return e[o].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){!function(e){return e?void(e.aframeCore||e).registerComponent("keyboard-controls",n(1)):void console.error("Component attempted to register before AFRAME was available.")}(window.AFRAME)},function(e,t,n){n(2).polyfill();var o=.2,i="__keyboard-controls-proxy",r=window.KeyboardEvent;e.exports={schema:{easing:{"default":20},acceleration:{"default":65},enabled:{"default":!0},fly:{"default":!1},rollAxis:{"default":"z",oneOf:["x","y","z"]},pitchAxis:{"default":"x",oneOf:["x","y","z"]},rollAxisInverted:{"default":!1},rollAxisEnabled:{"default":!0},pitchAxisInverted:{"default":!1},pitchAxisEnabled:{"default":!0}},init:function(){this.velocity=new THREE.Vector3,this.localKeys={},this.listeners={keydown:this.onKeyDown.bind(this),keyup:this.onKeyUp.bind(this)};var e=this.el.sceneEl;e.addBehavior&&(e.addBehavior(this),this.attachEventListeners())},update:function(e){var t,n=this.data,i=n.acceleration,r=n.easing,s=this.velocity,a=this.prevTime=this.prevTime||Date.now(),l=window.performance.now(),c=(l-a)/1e3,d=this.getKeys(),u=n.pitchAxis,y=n.rollAxis,p=n.pitchAxisInverted?-1:1,h=n.rollAxisInverted?-1:1,f=this.el;if(this.prevTime=l,e||c>o)return s[u]=0,void(s[y]=0);s[u]-=s[u]*r*c,s[y]-=s[y]*r*c;var v=f.getComputedAttribute("position");n.enabled&&(n.pitchAxisEnabled&&((d.a||d.Left||d.ArrowLeft)&&(s[u]-=p*i*c),(d.d||d.Right||d.ArrowRight)&&(s[u]+=p*i*c)),n.rollAxisEnabled&&((d.w||d.Up||d.ArrowUp)&&(s[y]-=h*i*c),(d.s||d.Down||d.ArrowDown)&&(s[y]+=h*i*c))),t=this.getMovementVector(c),f.object3D.translateX(t.x),f.object3D.translateY(t.y),f.object3D.translateZ(t.z),f.setAttribute("position",{x:v.x+t.x,y:v.y+t.y,z:v.z+t.z})},getMovementVector:function(e){var t=new THREE.Vector3(0,0,0),n=new THREE.Euler(0,0,0,"YXZ");return function(e){var o=this.velocity,i=this.el.getAttribute("rotation");return t.copy(o),t.multiplyScalar(e),i?(this.data.fly||(i.x=0),n.set(THREE.Math.degToRad(i.x),THREE.Math.degToRad(i.y),0),t.applyEuler(n),t):t}}(),play:function(){this.attachEventListeners()},pause:function(){this.removeEventListeners()},tick:function(e){this.update()},remove:function(){this.pause()},attachEventListeners:function(){window.addEventListener("keydown",this.listeners.keydown,!1),window.addEventListener("keyup",this.listeners.keyup,!1)},removeEventListeners:function(){window.removeEventListener("keydown",this.listeners.keydown),window.removeEventListener("keyup",this.listeners.keyup)},onKeyDown:function(e){this.localKeys[e.key]=!0,this.emit(e)},onKeyUp:function(e){delete this.localKeys[e.key],this.emit(e)},emit:function(e){i in e&&this.el.emit(e.type,e),this.el.emit(e.type+":"+e.key,new r(e.type,e)),console.log(e.type+":"+e.key)},isPressed:function(e){return e in this.getKeys()},getKeys:function(){return this.isProxied()?this.el.sceneEl.components["proxy-controls"].getKeyboard():this.localKeys},isProxied:function(){var e=this.el.sceneEl.components["proxy-controls"];return e&&e.isConnected()}}},function(e,t,n){var o,i;!function(){function r(){if(!("KeyboardEvent"in window)||"key"in KeyboardEvent.prototype)return!1;var e={get:function(e){var t=a.keys[this.which||this.keyCode];return Array.isArray(t)&&(t=t[+this.shiftKey]),t}};return Object.defineProperty(KeyboardEvent.prototype,"key",e),e}var s,a={polyfill:r,keys:{3:"Cancel",6:"Help",8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",28:"Convert",29:"NonConvert",30:"Accept",31:"ModeChange",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",41:"Select",42:"Print",43:"Execute",44:"PrintScreen",45:"Insert",46:"Delete",48:["0",")"],49:["1","!"],50:["2","@"],51:["3","#"],52:["4","$"],53:["5","%"],54:["6","^"],55:["7","&"],56:["8","*"],57:["9","("],91:"OS",93:"ContextMenu",144:"NumLock",145:"ScrollLock",181:"VolumeMute",182:"VolumeDown",183:"VolumeUp",186:[";",":"],187:["=","+"],188:[",","<"],189:["-","_"],190:[".",">"],191:["/","?"],192:["`","~"],219:["[","{"],220:["\\","|"],221:["]","}"],222:["'",'"'],224:"Meta",225:"AltGraph",246:"Attn",247:"CrSel",248:"ExSel",249:"EraseEof",250:"Play",251:"ZoomOut"}};for(s=1;25>s;s++)a.keys[111+s]="F"+s;var l="";for(s=65;91>s;s++)l=String.fromCharCode(s),a.keys[s]=[l.toLowerCase(),l.toUpperCase()];o=a,i="function"==typeof o?o.call(t,n,t,e):o,!(void 0!==i&&(e.exports=i))}()}]);

@@ -91,8 +91,16 @@ require('keyboardevent-key-polyfill').polyfill();

if (data.pitchAxisEnabled) {
if (keys.a || keys.ArrowLeft) { velocity[pitchAxis] -= pitchSign * acceleration * delta; }
if (keys.d || keys.ArrowRight) { velocity[pitchAxis] += pitchSign * acceleration * delta; }
if (keys.a || keys.Left || keys.ArrowLeft) {
velocity[pitchAxis] -= pitchSign * acceleration * delta;
}
if (keys.d || keys.Right || keys.ArrowRight) {
velocity[pitchAxis] += pitchSign * acceleration * delta;
}
}
if (data.rollAxisEnabled) {
if (keys.w || keys.ArrowUp) { velocity[rollAxis] -= rollSign * acceleration * delta; }
if (keys.s || keys.ArrowDown) { velocity[rollAxis] += rollSign * acceleration * delta; }
if (keys.w || keys.Up || keys.ArrowUp) {
velocity[rollAxis] -= rollSign * acceleration * delta;
}
if (keys.s || keys.Down || keys.ArrowDown) {
velocity[rollAxis] += rollSign * acceleration * delta;
}
}

@@ -99,0 +107,0 @@ }

{
"name": "aframe-keyboard-controls",
"version": "0.1.4",
"version": "0.1.5",
"description": "Keyboard controls for A-Frame.",

@@ -5,0 +5,0 @@ "main": "keyboard-controls.js",

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