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.2 to 0.3.3-beta.0

8

dist/shake-monitor.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}confirmPermissionGranted(){this.isPermissionGranted=!0;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)}start(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",this.onMotion,!1);return this}stop(){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)}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}}let defaultOptions={threshold:15,frequency:1E3};
class ShakeMonitor{constructor(a){this.listeners=[];this.isRunning=!1;this.lastAcceleration={};let {threshold:b,frequency:d}=Object.assign({},defaultOptions,a);this.threshold=b;this.frequency=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}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();return this}requestPermission(a=
document.documentElement){return this.motionMonitor.requestPermission(a)}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.frequency&&(this.listeners.forEach(a=>a()),this.lastTime=a)}reset(){this.lastTime=performance.now();this.lastAcceleration={}}onDeviceMotion(a){if(isAcceleration(a.accelerationIncludingGravity)){var {x:b,
y:d,z:c}=a.accelerationIncludingGravity;if(isAcceleration(this.lastAcceleration)){a=getDelta(this.lastAcceleration.x,b);var e=getDelta(this.lastAcceleration.y,d),f=getDelta(this.lastAcceleration.z,c);if(isShake(a,e,f,this.threshold))this.onShake()}this.lastAcceleration.x=b;this.lastAcceleration.y=d;this.lastAcceleration.z=c}else this.stop()}}function isShake(a,b,d,c){return a>c&&b>c||a>c&&d>c||b>c&&d>c}module.exports=ShakeMonitor
class ShakeMonitor{constructor(a){this.listeners=[];this.isRunning=!1;this.lastAcceleration={};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=
d}else this.stop()};let {threshold:b,frequency:d}=Object.assign({},defaultOptions,a);this.threshold=b;this.frequency=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}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}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.frequency&&(this.listeners.forEach(a=>a()),this.lastTime=a)}reset(){this.lastTime=performance.now();this.lastAcceleration={}}}function isShake(a,b,d,c){return a>c&&b>c||a>c&&d>c||b>c&&d>c}module.exports=ShakeMonitor
//# sourceMappingURL=shake-monitor.cjs.js.map
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 l{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}confirmPermissionGranted(){this.isPermissionGranted=!0;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)}start(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",this.onMotion,!1);return this}stop(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",
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)}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}}let m={threshold:15,frequency:1E3};
class n{constructor(a){this.listeners=[];this.isRunning=!1;this.lastAcceleration={};let {threshold:b,frequency:c}=Object.assign({},m,a);this.threshold=b;this.frequency=c;this.motionMonitor=(new l).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}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}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.frequency&&(this.listeners.forEach(a=>a()),this.lastTime=a)}reset(){this.lastTime=performance.now();this.lastAcceleration={}}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 h=Math.abs(this.lastAcceleration.y-c),k=Math.abs(this.lastAcceleration.z-d),e=this.threshold;if(a>e&&h>e||a>e&&k>e||h>e&&k>e)this.onShake()}this.lastAcceleration.x=b;this.lastAcceleration.y=c;this.lastAcceleration.z=d}else this.stop()}}export default n
class n{constructor(a){this.listeners=[];this.isRunning=!1;this.lastAcceleration={};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 h=Math.abs(this.lastAcceleration.y-c),k=Math.abs(this.lastAcceleration.z-d),e=this.threshold;if(a>e&&h>e||a>e&&k>e||h>e&&k>e)this.onShake()}this.lastAcceleration.x=b;this.lastAcceleration.y=c;this.lastAcceleration.z=d}else this.stop()};
let {threshold:b,frequency:c}=Object.assign({},m,a);this.threshold=b;this.frequency=c;this.motionMonitor=(new l).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}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}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.frequency&&(this.listeners.forEach(a=>a()),this.lastTime=a)}reset(){this.lastTime=performance.now();this.lastAcceleration={}}}export default n
//# sourceMappingURL=shake-monitor.esm.js.map

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

'use strict';(function(c,b){"object"===typeof exports&&"undefined"!==typeof module?module.exports=b():"function"===typeof define&&define.amd?define(b):(c="undefined"!==typeof globalThis?globalThis:c||self,c.ShakeMonitor=b())})(this,function(){function c(a){if(null===a)return!1;let {x:d,y:b,z:c}=a;return"number"===typeof d&&"number"===typeof b&&"number"===typeof c}function b(a){return"function"===typeof a}class l{constructor(){this.listeners=[];this.onMotion=a=>{this.listeners.forEach(d=>d(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(d=>d!==a));return this}confirmPermissionGranted(){this.isPermissionGranted=!0;return this}requestPermission(a=document.documentElement){return this.isSupported?this.isPermissionGranted?Promise.resolve(!0):new Promise(d=>{let b=()=>{DeviceMotionEvent.requestPermission().then(c=>{(this.isPermissionGranted=
"granted"===c)||console.warn("The permission to listen to DeviceMotionEvent was not granted");a.removeEventListener("click",b);d(this.isPermissionGranted)})};a.addEventListener("click",b)}):Promise.resolve(!1)}start(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",this.onMotion,!1);return this}stop(){this.isSupported&&this.isPermissionGranted&&window.removeEventListener("devicemotion",this.onMotion,!1);return this}}let m={threshold:15,frequency:1E3};class n{constructor(a){this.listeners=
[];this.isRunning=!1;this.lastAcceleration={};let {threshold:d,frequency:b}=Object.assign({},m,a);this.threshold=d;this.frequency=b;this.motionMonitor=(new l).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}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}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.frequency&&(this.listeners.forEach(a=>a()),this.lastTime=a)}reset(){this.lastTime=performance.now();this.lastAcceleration={}}onDeviceMotion(a){if(c(a.accelerationIncludingGravity)){var {x:b,y:f,z:g}=a.accelerationIncludingGravity;if(c(this.lastAcceleration)){a=Math.abs(this.lastAcceleration.x-
b);var h=Math.abs(this.lastAcceleration.y-f),k=Math.abs(this.lastAcceleration.z-g),e=this.threshold;if(a>e&&h>e||a>e&&k>e||h>e&&k>e)this.onShake()}this.lastAcceleration.x=b;this.lastAcceleration.y=f;this.lastAcceleration.z=g}else this.stop()}}return n})
'use strict';(function(d,b){"object"===typeof exports&&"undefined"!==typeof module?module.exports=b():"function"===typeof define&&define.amd?define(b):(d="undefined"!==typeof globalThis?globalThis:d||self,d.ShakeMonitor=b())})(this,function(){function d(a){if(null===a)return!1;let {x:c,y:b,z:e}=a;return"number"===typeof c&&"number"===typeof b&&"number"===typeof e}function b(a){return"function"===typeof 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}confirmPermissionGranted(){this.isPermissionGranted=!0;return this}requestPermission(a=document.documentElement){return this.isSupported?this.isPermissionGranted?Promise.resolve(!0):new Promise(c=>{let b=()=>{DeviceMotionEvent.requestPermission().then(e=>{(this.isPermissionGranted=
"granted"===e)||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)}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}}let l={threshold:15,frequency:1E3};class f{constructor(a){this.listeners=
[];this.isRunning=!1;this.lastAcceleration={};this.onDeviceMotion=a=>{if(d(a.accelerationIncludingGravity)){var {x:b,y:c,z:e}=a.accelerationIncludingGravity;if(d(this.lastAcceleration)){a=Math.abs(this.lastAcceleration.x-b);var f=Math.abs(this.lastAcceleration.y-c),h=Math.abs(this.lastAcceleration.z-e),g=this.threshold;if(a>g&&f>g||a>g&&h>g||f>g&&h>g)this.onShake()}this.lastAcceleration.x=b;this.lastAcceleration.y=c;this.lastAcceleration.z=e}else this.stop()};let {threshold:b,frequency:f}=Object.assign({},
l,a);this.threshold=b;this.frequency=f;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}confirmPermissionGranted(){this.motionMonitor.confirmPermissionGranted();return this}requestPermission(a=document.documentElement){return this.motionMonitor.requestPermission(a)}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.frequency&&(this.listeners.forEach(a=>a()),this.lastTime=a)}reset(){this.lastTime=performance.now();this.lastAcceleration={}}}return f})
//# sourceMappingURL=shake-monitor.umd.js.map
{
"name": "shake-detector",
"version": "0.3.2",
"version": "0.3.3-beta.0",
"description": "Mobile device shakes detection",

@@ -35,4 +35,4 @@ "keywords": [

"build": "rollup -c rollup/prod.config.js",
"dev-build": "rollup -c rollup/dev.config.js -w",
"dev": "rollup -c rollup/dev.config.js",
"dev-build": "rollup -c rollup/dev.config.js",
"dev": "rollup -c rollup/dev.config.js -w",
"declarations": "tsc --emitDeclarationOnly",

@@ -39,0 +39,0 @@ "postversion": "npm run build && npm publish",

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