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

shake-detector

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shake-detector - npm Package Compare versions

Comparing version 0.3.7 to 0.3.8

6

dist/shake-detector.cjs.js
'use strict';function isAcceleration(a){if(null===a)return!1;let {x:b,y:d,z:c}=a;return isNumber(b)&&isNumber(d)&&isNumber(c)}function isNumber(a){return"number"===typeof a}function getDelta(a,b){return Math.abs(a-b)}function isFunc(a){return"function"===typeof a}function isDeviceMotionSupported(){return"DeviceMotionEvent"in window}function isPermissionRequired(){return isFunc(DeviceMotionEvent.requestPermission)}
class MotionMonitor{constructor(){this.listeners=[];this.onMotion=a=>{this.listeners.forEach(b=>b(a))};this.isSupported=isDeviceMotionSupported();this.isPermissionGranted=!isPermissionRequired()}subscribe(a){isFunc(a)&&this.listeners.push(a);return this}unsubscribe(a){isFunc(a)&&(this.listeners=this.listeners.filter(b=>b!==a));return this}requestPermission(a=document.documentElement){return this.isSupported?this.isPermissionGranted?Promise.resolve(!0):new Promise(b=>{let d=()=>{DeviceMotionEvent.requestPermission().then(c=>
{(this.isPermissionGranted="granted"===c)||console.warn("The permission to listen to DeviceMotionEvent was not granted");a.removeEventListener("click",d);b(this.isPermissionGranted)})};a.addEventListener("click",d)}):Promise.resolve(!1)}confirmPermissionGranted(){this.isPermissionGranted=!0;return this}start(){this.isSupported&&this.isPermissionGranted&&window.addEventListener("devicemotion",this.onMotion,!1);return this}stop(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",
this.onMotion,!1);return this}}
class MotionMonitor{constructor(){this.listeners=[];this.onMotion=a=>{this.listeners.forEach(b=>b(a))};(this.isSupported=isDeviceMotionSupported())||console.warn("DeviceMotionEvent event is not supported in your environment");this.isPermissionGranted=this.isSupported&&!isPermissionRequired()}subscribe(a){isFunc(a)&&this.listeners.push(a);return this}unsubscribe(a){isFunc(a)&&(this.listeners=this.listeners.filter(b=>b!==a));return this}requestPermission(a=document.documentElement){return this.isSupported?
this.isPermissionGranted?Promise.resolve(!0):new Promise(b=>{let d=()=>{DeviceMotionEvent.requestPermission().then(c=>{(this.isPermissionGranted="granted"===c)||console.warn("The permission to listen to DeviceMotionEvent was not granted");a.removeEventListener("click",d);b(this.isPermissionGranted)})};a.addEventListener("click",d)}):Promise.resolve(!1)}confirmPermissionGranted(){this.isPermissionGranted=!0;return this}start(){this.isSupported&&this.isPermissionGranted&&window.addEventListener("devicemotion",
this.onMotion,!1);return this}stop(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",this.onMotion,!1);return this}}
class ShakeDetector{constructor(a){this.listeners=[];this.lastAcceleration={};this.isRunning=!1;this.onDeviceMotion=a=>{if(isAcceleration(a.accelerationIncludingGravity)){var {x:b,y:c,z:d}=a.accelerationIncludingGravity;if(isAcceleration(this.lastAcceleration)){a=getDelta(this.lastAcceleration.x,b);var e=getDelta(this.lastAcceleration.y,c),f=getDelta(this.lastAcceleration.z,d);if(isShake(a,e,f,this.threshold))this.onShake()}this.lastAcceleration.x=b;this.lastAcceleration.y=c;this.lastAcceleration.z=

@@ -6,0 +6,0 @@ d}else this.stop()};let {threshold:b,debounceDelay:d}=Object.assign({},ShakeDetector.defaultOptions,a);this.threshold=b;this.debounceDelay=d;this.motionMonitor=(new MotionMonitor).subscribe(this.onDeviceMotion)}subscribe(a){isFunc(a)&&this.listeners.push(a);return this}unsubscribe(a){isFunc(a)&&(this.listeners=this.listeners.filter(b=>b!==a));return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();

function f(a){if(null===a)return!1;let {x:b,y:c,z:d}=a;return"number"===typeof b&&"number"===typeof c&&"number"===typeof d}function g(a){return"function"===typeof a}
class h{constructor(){this.listeners=[];this.onMotion=a=>{this.listeners.forEach(b=>b(a))};this.isSupported="DeviceMotionEvent"in window;this.isPermissionGranted=!g(DeviceMotionEvent.requestPermission)}subscribe(a){g(a)&&this.listeners.push(a);return this}unsubscribe(a){g(a)&&(this.listeners=this.listeners.filter(b=>b!==a));return this}requestPermission(a=document.documentElement){return this.isSupported?this.isPermissionGranted?Promise.resolve(!0):new Promise(b=>{let c=()=>{DeviceMotionEvent.requestPermission().then(d=>
{(this.isPermissionGranted="granted"===d)||console.warn("The permission to listen to DeviceMotionEvent was not granted");a.removeEventListener("click",c);b(this.isPermissionGranted)})};a.addEventListener("click",c)}):Promise.resolve(!1)}confirmPermissionGranted(){this.isPermissionGranted=!0;return this}start(){this.isSupported&&this.isPermissionGranted&&window.addEventListener("devicemotion",this.onMotion,!1);return this}stop(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",
this.onMotion,!1);return this}}
class h{constructor(){this.listeners=[];this.onMotion=a=>{this.listeners.forEach(b=>b(a))};(this.isSupported="DeviceMotionEvent"in window)||console.warn("DeviceMotionEvent event is not supported in your environment");this.isPermissionGranted=this.isSupported&&!g(DeviceMotionEvent.requestPermission)}subscribe(a){g(a)&&this.listeners.push(a);return this}unsubscribe(a){g(a)&&(this.listeners=this.listeners.filter(b=>b!==a));return this}requestPermission(a=document.documentElement){return this.isSupported?
this.isPermissionGranted?Promise.resolve(!0):new Promise(b=>{let c=()=>{DeviceMotionEvent.requestPermission().then(d=>{(this.isPermissionGranted="granted"===d)||console.warn("The permission to listen to DeviceMotionEvent was not granted");a.removeEventListener("click",c);b(this.isPermissionGranted)})};a.addEventListener("click",c)}):Promise.resolve(!1)}confirmPermissionGranted(){this.isPermissionGranted=!0;return this}start(){this.isSupported&&this.isPermissionGranted&&window.addEventListener("devicemotion",
this.onMotion,!1);return this}stop(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",this.onMotion,!1);return this}}
class m{constructor(a){this.listeners=[];this.lastAcceleration={};this.isRunning=!1;this.onDeviceMotion=a=>{if(f(a.accelerationIncludingGravity)){var {x:b,y:c,z:d}=a.accelerationIncludingGravity;if(f(this.lastAcceleration)){a=Math.abs(this.lastAcceleration.x-b);var k=Math.abs(this.lastAcceleration.y-c),l=Math.abs(this.lastAcceleration.z-d),e=this.threshold;if(a>e&&k>e||a>e&&l>e||k>e&&l>e)this.onShake()}this.lastAcceleration.x=b;this.lastAcceleration.y=c;this.lastAcceleration.z=d}else this.stop()};

@@ -6,0 +6,0 @@ let {threshold:b,debounceDelay:c}=Object.assign({},m.defaultOptions,a);this.threshold=b;this.debounceDelay=c;this.motionMonitor=(new h).subscribe(this.onDeviceMotion)}subscribe(a){g(a)&&this.listeners.push(a);return this}unsubscribe(a){g(a)&&(this.listeners=this.listeners.filter(b=>b!==a));return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();return this}start(){this.isRunning||

'use strict';(function(e,b){"object"===typeof exports&&"undefined"!==typeof module?module.exports=b():"function"===typeof define&&define.amd?define(b):(e="undefined"!==typeof globalThis?globalThis:e||self,e.ShakeDetector=b())})(this,function(){function e(a){if(null===a)return!1;let {x:c,y:b,z:f}=a;return"number"===typeof c&&"number"===typeof b&&"number"===typeof f}function b(a){return"function"===typeof a}function g(){let a=new CustomEvent(d.SHAKE_EVENT);window.dispatchEvent(a)}class k{constructor(){this.listeners=
[];this.onMotion=a=>{this.listeners.forEach(c=>c(a))};this.isSupported="DeviceMotionEvent"in window;this.isPermissionGranted=!b(DeviceMotionEvent.requestPermission)}subscribe(a){b(a)&&this.listeners.push(a);return this}unsubscribe(a){b(a)&&(this.listeners=this.listeners.filter(c=>c!==a));return this}requestPermission(a=document.documentElement){return this.isSupported?this.isPermissionGranted?Promise.resolve(!0):new Promise(c=>{let b=()=>{DeviceMotionEvent.requestPermission().then(f=>{(this.isPermissionGranted=
"granted"===f)||console.warn("The permission to listen to DeviceMotionEvent was not granted");a.removeEventListener("click",b);c(this.isPermissionGranted)})};a.addEventListener("click",b)}):Promise.resolve(!1)}confirmPermissionGranted(){this.isPermissionGranted=!0;return this}start(){this.isSupported&&this.isPermissionGranted&&window.addEventListener("devicemotion",this.onMotion,!1);return this}stop(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",this.onMotion,
!1);return this}}class d{constructor(a){this.listeners=[];this.lastAcceleration={};this.isRunning=!1;this.onDeviceMotion=a=>{if(e(a.accelerationIncludingGravity)){var {x:b,y:c,z:d}=a.accelerationIncludingGravity;if(e(this.lastAcceleration)){a=Math.abs(this.lastAcceleration.x-b);var f=Math.abs(this.lastAcceleration.y-c),g=Math.abs(this.lastAcceleration.z-d),h=this.threshold;if(a>h&&f>h||a>h&&g>h||f>h&&g>h)this.onShake()}this.lastAcceleration.x=b;this.lastAcceleration.y=c;this.lastAcceleration.z=d}else this.stop()};
let {threshold:b,debounceDelay:g}=Object.assign({},d.defaultOptions,a);this.threshold=b;this.debounceDelay=g;this.motionMonitor=(new k).subscribe(this.onDeviceMotion)}subscribe(a){b(a)&&this.listeners.push(a);return this}unsubscribe(a){b(a)&&(this.listeners=this.listeners.filter(b=>b!==a));return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();return this}start(){this.isRunning||
(this.isRunning=!0,this.motionMonitor.start(),this.reset());return this}stop(){this.isRunning&&(this.isRunning=!1,this.motionMonitor.stop(),this.reset());return this}onShake(){let a=performance.now();a-this.lastTime>this.debounceDelay&&(g(),this.listeners.forEach(a=>a()),this.lastTime=a)}reset(){this.lastTime=performance.now();this.lastAcceleration={}}}d.SHAKE_EVENT="shake-detected";d.defaultOptions={threshold:15,debounceDelay:1E3};return d})
[];this.onMotion=a=>{this.listeners.forEach(c=>c(a))};(this.isSupported="DeviceMotionEvent"in window)||console.warn("DeviceMotionEvent event is not supported in your environment");this.isPermissionGranted=this.isSupported&&!b(DeviceMotionEvent.requestPermission)}subscribe(a){b(a)&&this.listeners.push(a);return this}unsubscribe(a){b(a)&&(this.listeners=this.listeners.filter(c=>c!==a));return this}requestPermission(a=document.documentElement){return this.isSupported?this.isPermissionGranted?Promise.resolve(!0):
new Promise(c=>{let b=()=>{DeviceMotionEvent.requestPermission().then(f=>{(this.isPermissionGranted="granted"===f)||console.warn("The permission to listen to DeviceMotionEvent was not granted");a.removeEventListener("click",b);c(this.isPermissionGranted)})};a.addEventListener("click",b)}):Promise.resolve(!1)}confirmPermissionGranted(){this.isPermissionGranted=!0;return this}start(){this.isSupported&&this.isPermissionGranted&&window.addEventListener("devicemotion",this.onMotion,!1);return this}stop(){this.isSupported&&
this.isPermissionGranted&&window.removeEventListener("devicemotion",this.onMotion,!1);return this}}class d{constructor(a){this.listeners=[];this.lastAcceleration={};this.isRunning=!1;this.onDeviceMotion=a=>{if(e(a.accelerationIncludingGravity)){var {x:b,y:c,z:d}=a.accelerationIncludingGravity;if(e(this.lastAcceleration)){a=Math.abs(this.lastAcceleration.x-b);var f=Math.abs(this.lastAcceleration.y-c),g=Math.abs(this.lastAcceleration.z-d),h=this.threshold;if(a>h&&f>h||a>h&&g>h||f>h&&g>h)this.onShake()}this.lastAcceleration.x=
b;this.lastAcceleration.y=c;this.lastAcceleration.z=d}else this.stop()};let {threshold:b,debounceDelay:g}=Object.assign({},d.defaultOptions,a);this.threshold=b;this.debounceDelay=g;this.motionMonitor=(new k).subscribe(this.onDeviceMotion)}subscribe(a){b(a)&&this.listeners.push(a);return this}unsubscribe(a){b(a)&&(this.listeners=this.listeners.filter(b=>b!==a));return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();
return this}start(){this.isRunning||(this.isRunning=!0,this.motionMonitor.start(),this.reset());return this}stop(){this.isRunning&&(this.isRunning=!1,this.motionMonitor.stop(),this.reset());return this}onShake(){let a=performance.now();a-this.lastTime>this.debounceDelay&&(g(),this.listeners.forEach(a=>a()),this.lastTime=a)}reset(){this.lastTime=performance.now();this.lastAcceleration={}}}d.SHAKE_EVENT="shake-detected";d.defaultOptions={threshold:15,debounceDelay:1E3};return d})
//# sourceMappingURL=shake-detector.umd.js.map
{
"name": "shake-detector",
"version": "0.3.7",
"version": "0.3.8",
"description": "Mobile device shakes detection",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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