🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

shake-monitor

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shake-monitor - npm Package Compare versions

Comparing version

to
0.3.0-beta.0

types/index.d.ts

12

dist/shake-monitor.cjs.js

@@ -1,6 +0,8 @@

'use strict';function isEmptyObject(a){return 0===Object.keys(a).length}function getDelta(a,b){return Math.abs(a-b)}function isFunc(a){return"function"===typeof a}function isDeviceMotionSupported(){return"DeviceMotionEvent"in window}function isListenerRequirePermission(){return isFunc(DeviceMotionEvent.requestPermission)}
function createMotionMonitor(a){let b=isDeviceMotionSupported(),c=!isListenerRequirePermission();return{start:function(){b&&c&&window.removeEventListener("devicemotion",a,!1)},stop:function(){b&&c&&window.removeEventListener("devicemotion",a,!1)},requestPermission:function(a=document.documentElement){return b?c?Promise.resolve(!0):new Promise(b=>{function d(){DeviceMotionEvent.requestPermission().then(e=>{(c="granted"===e)||console.warn("The permission to listen to DeviceMotionEvent was not granted");
a.removeEventListener("click",d);b(c)})}a.addEventListener("click",d)}):Promise.resolve(!1)},confirmPermission:function(){c=!0}}}let defaultOptions={threshold:15,frequency:1E3};
function createShakeMonitor(a){function b(){h&&(h=!1,g.stop(),k=performance.now(),f={});return this}function c(){let a=performance.now();a-k>m&&(e.forEach(a=>a()),k=a)}let {threshold:d,frequency:m}=Object.assign({},defaultOptions,a),g=createMotionMonitor(function(a){let {x:l,y:e,z:g}=a.accelerationIncludingGravity;if(null===l||null===e||null===g)b();else{if(!isEmptyObject(f)){a=getDelta(f.x,l);var h=getDelta(f.y,e),k=getDelta(f.z,g);isShake(a,h,k,d)&&c()}f.x=l;f.y=e;f.z=g}}),e=[],h=!1,k,f;return{subscribe:function(a){isFunc(a)&&
e.push(a);return this},unsubscribe:function(a){isFunc(a)&&(e=e.filter(b=>b!==a));return this},start:function(){h||(h=!0,g.start(),k=performance.now(),f={});return this},stop:b,requestPermission:function(a){return g.requestPermission(a)},confirmPermission:function(){g.confirmPermission();return this}}}function isShake(a,b,c,d){return a>d&&b>d||a>d&&c>d||b>d&&c>d}module.exports=createShakeMonitor
'use strict';function isAcceleration(a){if(null===a)return!0;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&&
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
//# sourceMappingURL=shake-monitor.cjs.js.map

@@ -1,6 +0,8 @@

function m(b){return"function"===typeof b}
function n(b){let f="DeviceMotionEvent"in window,g=!m(DeviceMotionEvent.requestPermission);return{start:function(){f&&g&&window.removeEventListener("devicemotion",b,!1)},stop:function(){f&&g&&window.removeEventListener("devicemotion",b,!1)},requestPermission:function(d=document.documentElement){return f?g?Promise.resolve(!0):new Promise(b=>{function c(){DeviceMotionEvent.requestPermission().then(f=>{(g="granted"===f)||console.warn("The permission to listen to DeviceMotionEvent was not granted");d.removeEventListener("click",
c);b(g)})}d.addEventListener("click",c)}):Promise.resolve(!1)},confirmPermission:function(){g=!0}}}let q={threshold:15,frequency:1E3};
export default function(b){function f(){k&&(k=!1,c.stop(),l=performance.now(),e={});return this}function g(){let a=performance.now();a-l>p&&(h.forEach(a=>a()),l=a)}let {threshold:d,frequency:p}=Object.assign({},q,b),c=n(function(a){let {x:b,y:c,z:h}=a.accelerationIncludingGravity;if(null===b||null===c||null===h)f();else{if(0!==Object.keys(e).length){a=Math.abs(e.x-b);var k=Math.abs(e.y-c),l=Math.abs(e.z-h);(a>d&&k>d||a>d&&l>d||k>d&&l>d)&&g()}e.x=b;e.y=c;e.z=h}}),h=[],k=!1,l,e;return{subscribe:function(a){m(a)&&
h.push(a);return this},unsubscribe:function(a){m(a)&&(h=h.filter(b=>b!==a));return this},start:function(){k||(k=!0,c.start(),l=performance.now(),e={});return this},stop:f,requestPermission:function(a){return c.requestPermission(a)},confirmPermission:function(){c.confirmPermission();return this}}}
function f(a){if(null===a)return!0;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",
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
//# sourceMappingURL=shake-monitor.esm.js.map

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

'use strict';(function(a,c){"object"===typeof exports&&"undefined"!==typeof module?module.exports=c():"function"===typeof define&&define.amd?define(c):(a="undefined"!==typeof globalThis?globalThis:a||self,a.ShakeMonitor=c())})(this,function(){function a(a){return"function"===typeof a}function c(c){let f="DeviceMotionEvent"in window,g=!a(DeviceMotionEvent.requestPermission);return{start:function(){f&&g&&window.removeEventListener("devicemotion",c,!1)},stop:function(){f&&g&&window.removeEventListener("devicemotion",
c,!1)},requestPermission:function(a=document.documentElement){return f?g?Promise.resolve(!0):new Promise(c=>{function d(){DeviceMotionEvent.requestPermission().then(f=>{(g="granted"===f)||console.warn("The permission to listen to DeviceMotionEvent was not granted");a.removeEventListener("click",d);c(g)})}a.addEventListener("click",d)}):Promise.resolve(!1)},confirmPermission:function(){g=!0}}}let q={threshold:15,frequency:1E3};return function(n){function f(){k&&(k=!1,d.stop(),m=performance.now(),e=
{});return this}function g(){let b=performance.now();b-m>p&&(h.forEach(b=>b()),m=b)}let {threshold:l,frequency:p}=Object.assign({},q,n),d=c(function(b){let {x:a,y:c,z:d}=b.accelerationIncludingGravity;if(null===a||null===c||null===d)f();else{if(0!==Object.keys(e).length){b=Math.abs(e.x-a);var h=Math.abs(e.y-c),k=Math.abs(e.z-d);(b>l&&h>l||b>l&&k>l||h>l&&k>l)&&g()}e.x=a;e.y=c;e.z=d}}),h=[],k=!1,m,e;return{subscribe:function(b){a(b)&&h.push(b);return this},unsubscribe:function(b){a(b)&&(h=h.filter(a=>
a!==b));return this},start:function(){k||(k=!0,d.start(),m=performance.now(),e={});return this},stop:f,requestPermission:function(a){return d.requestPermission(a)},confirmPermission:function(){d.confirmPermission();return this}}}})
'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!0;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})
//# sourceMappingURL=shake-monitor.umd.js.map
{
"name": "shake-monitor",
"version": "0.2.8",
"version": "0.3.0-beta.0",
"description": "shake-monitor",
"keywords": [
"CustomEvent"
"device shake",
"device shake detection",
"device motion"
],

@@ -12,2 +14,3 @@ "license": "MIT",

"browser": "dist/shake-monitor.umd.js",
"typings": "types",
"repository": {

@@ -23,3 +26,8 @@ "type": "git",

"rollup-plugin-commonjs": "10.1.0",
"rollup-plugin-node-resolve": "5.2.0"
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-typescript": "^1.0.1",
"ts-jest": "^26.5.0",
"tslib": "^2.1.0",
"typedoc": "^0.20.19",
"typescript": "^4.1.3"
},

@@ -31,3 +39,4 @@ "scripts": {

"files": [
"dist"
"dist",
"types"
],

@@ -42,4 +51,5 @@ "jest": {

"semi": true,
"singleQuote": true
"singleQuote": true,
"arrowParens": "avoid"
}
}

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