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

contro

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contro - npm Package Compare versions

Comparing version 2.0.1 to 2.1.0

6

dist/contro.esm.js

@@ -293,4 +293,6 @@ /*!

if (!this.isConnected()) {
this.gamepadIndex = gamepad.index;
store.preferGamepad = true;
if (gamepad.mapping === 'standard') {
this.gamepadIndex = gamepad.index;
store.preferGamepad = true;
}
}

@@ -297,0 +299,0 @@ });

@@ -299,4 +299,6 @@ /*!

if (!this.isConnected()) {
this.gamepadIndex = gamepad.index;
store.preferGamepad = true;
if (gamepad.mapping === 'standard') {
this.gamepadIndex = gamepad.index;
store.preferGamepad = true;
}
}

@@ -303,0 +305,0 @@ });

@@ -6,2 +6,2 @@ /*!

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Contro={})}(this,function(e){"use strict";function t(e){return 1===e.length?e.toLowerCase():(Object.keys(o).forEach(t=>{o[t].forEach(r=>{e.toLowerCase()===r.toLowerCase()&&(e=t)})}),e)}function r(e){return e in o?o[e][0]:1===e.length?e.toUpperCase():e}class s{constructor(e=0,t=0){this.x=e,this.y=t}}const n=["left","middle","right"];const o={" ":["Space","Spacebar","Space Bar"],AltGraph:["Alt Gr"],ArrowDown:["Down"],ArrowLeft:["Left"],ArrowRight:["Right"],ArrowUp:["Up"],Backspace:["Backspace"],Control:["Ctrl","Ctl"],Delete:["Delete","Del"],Enter:["Enter","Return"],Escape:["Escape","Esc"],Insert:["Insert","Ins"],PageDown:["Page Down","PgDown"],PageUp:["Page Up","PgUp"],Tab:["Tab"]},i={arrows:["Arrow keys",["ArrowUp","ArrowLeft","ArrowDown","ArrowRight"]],wasd:["WASD",["W","A","S","D"]]};const a=[["A"],["B"],["X"],["Y"],["Left Bumper","LB"],["Right Bumper","RB"],["Left Trigger","LT"],["Right Trigger","RT"],["Back","View"],["Start"],["Left Stick"],["Right Stick"],["Up","DpadUp"],["Down","DpadDown"],["Left","DpadLeft"],["Right","DpadRight"],["Home","Guide","Xbox"]],d={left:{xAxis:0,yAxis:1},right:{xAxis:2,yAxis:3}};let u={preferGamepad:!1};e.store=u,e.Mouse=class{constructor({canvas:e,doc:t=document}){this.pointerLocked=!1,this.pointerMovement=new s,this.pressedButtons=new Set,this.queuedButtons=new Set,this.scrollDistance=0,this.canvas=e,this.document=t;const r=this.canvas.addEventListener.bind(this.canvas);r("mousedown",e=>{u.preferGamepad=!1,this.pressedButtons.add(e.button),this.queuedButtons.add(e.button)}),r("mouseup",e=>{u.preferGamepad=!1,this.pressedButtons.delete(e.button),this.queuedButtons.delete(e.button)}),r("mousemove",e=>{u.preferGamepad=!1,this.pointerMovement.x+=e.movementX,this.pointerMovement.y+=e.movementY}),r("wheel",e=>{u.preferGamepad=!1;const t=e.deltaY;this.scrollDistance+=t})}parseButton(e){if("string"==typeof e){if(n.includes(e))return n.indexOf(e);throw new Error(`There is no mouse button called "${e}"!`)}if(e<n.length)return e;throw new Error(`There is no mouse button with the index ${e}!`)}button(e){const t=this;return e=this.parseButton(e),{label:["Left","Middle","Right"][e]+" Mouse Button",query(){return e=t.parseButton(e),this.hasOwnProperty("trigger")?t.pressedButtons.has(e):!!t.queuedButtons.has(e)&&(t.queuedButtons.delete(e),!0)},get trigger(){return delete this.trigger,this}}}pointer(){return{label:"Cursor",query:()=>{const e=this.pointerMovement;return this.pointerMovement=new s(0,0),e}}}wheel(){return{label:"Mouse wheel",query:()=>{const e=this.scrollDistance;return this.scrollDistance=0,e}}}lockPointer(){this.canvas.requestPointerLock()}unlockPointer(){this.document.exitPointerLock()}isPointerLocked(){return this.document.pointerLockElement===this.canvas}},e.Keyboard=class{constructor({doc:e=document}={}){this.pressedKeys=new Set,this.queuedKeys=new Set,this.document=e,this.document.addEventListener("keydown",e=>{u.preferGamepad=!1;let t=e.key;return t===t.toUpperCase()&&(t=t.toLowerCase()),this.pressedKeys.add(t),this.queuedKeys.add(t),!1}),this.document.addEventListener("keyup",e=>{u.preferGamepad=!1;let t=e.key;return t===t.toUpperCase()&&(t=t.toLowerCase()),this.pressedKeys.delete(t),this.queuedKeys.delete(t),!1})}key(e){const s=this;return e=t(e),{label:r(e),query(){return this.hasOwnProperty("trigger")?s.pressedKeys.has(e):s.queuedKeys.delete(e)},get trigger(){return delete this.trigger,this}}}directionalKeys(e,n){let o;if("string"==typeof e){if(!((e=e.toLowerCase())in i))throw new Error(`Directional key template "${e}" not found!`);{const t=i[e.toLowerCase()];o=t[0],e=t[1]}}else{if(4!==e.length)throw new Error("Directional key templates have to consist of four keys!");o=(e=e.map(e=>t(e))).map(e=>r(e)).join("")}return{label:n||o,query:()=>{const t=new s;return this.key(e[0]).query()&&(t.y-=1),this.key(e[1]).query()&&(t.x-=1),this.key(e[2]).query()&&(t.y+=1),this.key(e[3]).query()&&(t.x+=1),t}}}},e.Gamepad=class{constructor({win:e=window,nav:t=navigator}={}){this.pressedButtons=new Set,this.gamepadTimestamp=0,this.window=e,this.navigator=t,this.window.addEventListener("gamepadconnected",({gamepad:e})=>{this.isConnected()||(this.gamepadIndex=e.index,u.preferGamepad=!0)}),this.window.addEventListener("gamepaddisconnected",({gamepad:e})=>{this.gamepadIndex===e.index&&(this.gamepadIndex=void 0,u.preferGamepad=!1)})}isConnected(){return void 0!==this.gamepadIndex&&this.gamepad.connected}get gamepad(){const e=this.navigator.getGamepads()[this.gamepadIndex];return e.timestamp>this.gamepadTimestamp&&(u.preferGamepad=!0),this.gamepadTimestamp=e.timestamp,e}button(e){const t=this,r=function(e){if("number"==typeof e)return e;let t=0;for(const r of a){for(const s of r)if(e.toLowerCase()===s.toLowerCase())return t;t++}}(e);return{label:function(e){return a[e][0]}(r),fromGamepad:!0,query(){if(!t.isConnected())return!1;if(this.hasOwnProperty("trigger"))return t.gamepad.buttons[r].pressed;if(t.gamepad.buttons[r].pressed){if(!t.pressedButtons.has(r))return t.pressedButtons.add(r),!0}else t.pressedButtons.delete(r);return!1},get trigger(){return delete this.trigger,this}}}stick(e){if("string"==typeof e){if(!(e in d))throw new Error(`Gamepad stick "${e}" not found!`);e=d[e]}return new s(this.gamepad.axes[e.xAxis],this.gamepad.axes[e.yAxis])}},e.and=function(...e){if(e.length<2)throw new Error("Less than two controls specified!");return{label:e.map(e=>e.label).join(" + "),query:()=>{for(const t of e)if(!t.query())return!1;return!0}}},e.or=function(...e){if(e.length<2)throw new Error("Less than two controls specified!");return{get label(){return(0===e.filter(e=>e.fromGamepad).length?e[0]:u.preferGamepad?e.filter(e=>!0===e.fromGamepad)[0]:e.filter(e=>!0!==e.fromGamepad)[0]).label},query:()=>{let t;for(const r of e){const e=r.query();if(t=e,e)return e}if("boolean"==typeof t)return!1}}},Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.Contro={})}(this,function(e){"use strict";function t(e){return 1===e.length?e.toLowerCase():(Object.keys(o).forEach(t=>{o[t].forEach(r=>{e.toLowerCase()===r.toLowerCase()&&(e=t)})}),e)}function r(e){return e in o?o[e][0]:1===e.length?e.toUpperCase():e}class s{constructor(e=0,t=0){this.x=e,this.y=t}}const n=["left","middle","right"];const o={" ":["Space","Spacebar","Space Bar"],AltGraph:["Alt Gr"],ArrowDown:["Down"],ArrowLeft:["Left"],ArrowRight:["Right"],ArrowUp:["Up"],Backspace:["Backspace"],Control:["Ctrl","Ctl"],Delete:["Delete","Del"],Enter:["Enter","Return"],Escape:["Escape","Esc"],Insert:["Insert","Ins"],PageDown:["Page Down","PgDown"],PageUp:["Page Up","PgUp"],Tab:["Tab"]},i={arrows:["Arrow keys",["ArrowUp","ArrowLeft","ArrowDown","ArrowRight"]],wasd:["WASD",["W","A","S","D"]]};const a=[["A"],["B"],["X"],["Y"],["Left Bumper","LB"],["Right Bumper","RB"],["Left Trigger","LT"],["Right Trigger","RT"],["Back","View"],["Start"],["Left Stick"],["Right Stick"],["Up","DpadUp"],["Down","DpadDown"],["Left","DpadLeft"],["Right","DpadRight"],["Home","Guide","Xbox"]],d={left:{xAxis:0,yAxis:1},right:{xAxis:2,yAxis:3}};let u={preferGamepad:!1};e.store=u,e.Mouse=class{constructor({canvas:e,doc:t=document}){this.pointerLocked=!1,this.pointerMovement=new s,this.pressedButtons=new Set,this.queuedButtons=new Set,this.scrollDistance=0,this.canvas=e,this.document=t;const r=this.canvas.addEventListener.bind(this.canvas);r("mousedown",e=>{u.preferGamepad=!1,this.pressedButtons.add(e.button),this.queuedButtons.add(e.button)}),r("mouseup",e=>{u.preferGamepad=!1,this.pressedButtons.delete(e.button),this.queuedButtons.delete(e.button)}),r("mousemove",e=>{u.preferGamepad=!1,this.pointerMovement.x+=e.movementX,this.pointerMovement.y+=e.movementY}),r("wheel",e=>{u.preferGamepad=!1;const t=e.deltaY;this.scrollDistance+=t})}parseButton(e){if("string"==typeof e){if(n.includes(e))return n.indexOf(e);throw new Error(`There is no mouse button called "${e}"!`)}if(e<n.length)return e;throw new Error(`There is no mouse button with the index ${e}!`)}button(e){const t=this;return e=this.parseButton(e),{label:["Left","Middle","Right"][e]+" Mouse Button",query(){return e=t.parseButton(e),this.hasOwnProperty("trigger")?t.pressedButtons.has(e):!!t.queuedButtons.has(e)&&(t.queuedButtons.delete(e),!0)},get trigger(){return delete this.trigger,this}}}pointer(){return{label:"Cursor",query:()=>{const e=this.pointerMovement;return this.pointerMovement=new s(0,0),e}}}wheel(){return{label:"Mouse wheel",query:()=>{const e=this.scrollDistance;return this.scrollDistance=0,e}}}lockPointer(){this.canvas.requestPointerLock()}unlockPointer(){this.document.exitPointerLock()}isPointerLocked(){return this.document.pointerLockElement===this.canvas}},e.Keyboard=class{constructor({doc:e=document}={}){this.pressedKeys=new Set,this.queuedKeys=new Set,this.document=e,this.document.addEventListener("keydown",e=>{u.preferGamepad=!1;let t=e.key;return t===t.toUpperCase()&&(t=t.toLowerCase()),this.pressedKeys.add(t),this.queuedKeys.add(t),!1}),this.document.addEventListener("keyup",e=>{u.preferGamepad=!1;let t=e.key;return t===t.toUpperCase()&&(t=t.toLowerCase()),this.pressedKeys.delete(t),this.queuedKeys.delete(t),!1})}key(e){const s=this;return e=t(e),{label:r(e),query(){return this.hasOwnProperty("trigger")?s.pressedKeys.has(e):s.queuedKeys.delete(e)},get trigger(){return delete this.trigger,this}}}directionalKeys(e,n){let o;if("string"==typeof e){if(!((e=e.toLowerCase())in i))throw new Error(`Directional key template "${e}" not found!`);{const t=i[e.toLowerCase()];o=t[0],e=t[1]}}else{if(4!==e.length)throw new Error("Directional key templates have to consist of four keys!");o=(e=e.map(e=>t(e))).map(e=>r(e)).join("")}return{label:n||o,query:()=>{const t=new s;return this.key(e[0]).query()&&(t.y-=1),this.key(e[1]).query()&&(t.x-=1),this.key(e[2]).query()&&(t.y+=1),this.key(e[3]).query()&&(t.x+=1),t}}}},e.Gamepad=class{constructor({win:e=window,nav:t=navigator}={}){this.pressedButtons=new Set,this.gamepadTimestamp=0,this.window=e,this.navigator=t,this.window.addEventListener("gamepadconnected",({gamepad:e})=>{this.isConnected()||"standard"===e.mapping&&(this.gamepadIndex=e.index,u.preferGamepad=!0)}),this.window.addEventListener("gamepaddisconnected",({gamepad:e})=>{this.gamepadIndex===e.index&&(this.gamepadIndex=void 0,u.preferGamepad=!1)})}isConnected(){return void 0!==this.gamepadIndex&&this.gamepad.connected}get gamepad(){const e=this.navigator.getGamepads()[this.gamepadIndex];return e.timestamp>this.gamepadTimestamp&&(u.preferGamepad=!0),this.gamepadTimestamp=e.timestamp,e}button(e){const t=this,r=function(e){if("number"==typeof e)return e;let t=0;for(const r of a){for(const s of r)if(e.toLowerCase()===s.toLowerCase())return t;t++}}(e);return{label:function(e){return a[e][0]}(r),fromGamepad:!0,query(){if(!t.isConnected())return!1;if(this.hasOwnProperty("trigger"))return t.gamepad.buttons[r].pressed;if(t.gamepad.buttons[r].pressed){if(!t.pressedButtons.has(r))return t.pressedButtons.add(r),!0}else t.pressedButtons.delete(r);return!1},get trigger(){return delete this.trigger,this}}}stick(e){if("string"==typeof e){if(!(e in d))throw new Error(`Gamepad stick "${e}" not found!`);e=d[e]}return new s(this.gamepad.axes[e.xAxis],this.gamepad.axes[e.yAxis])}},e.and=function(...e){if(e.length<2)throw new Error("Less than two controls specified!");return{label:e.map(e=>e.label).join(" + "),query:()=>{for(const t of e)if(!t.query())return!1;return!0}}},e.or=function(...e){if(e.length<2)throw new Error("Less than two controls specified!");return{get label(){return(0===e.filter(e=>e.fromGamepad).length?e[0]:u.preferGamepad?e.filter(e=>!0===e.fromGamepad)[0]:e.filter(e=>!0!==e.fromGamepad)[0]).label},query:()=>{let t;for(const r of e){const e=r.query();if(t=e,e)return e}if("boolean"==typeof t)return!1}}},Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "contro",
"version": "2.0.1",
"version": "2.1.0",
"description": "Game controls done right.",

@@ -5,0 +5,0 @@ "main": "dist/contro.esm.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